本文整理汇总了C++中llvm类的典型用法代码示例。如果您正苦于以下问题:C++ llvm类的具体用法?C++ llvm怎么用?C++ llvm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了llvm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: maybe_print_statistics
static void maybe_print_statistics(llvm::Module *M, const char *prefix = nullptr)
{
if (!statistics)
return;
using namespace llvm;
uint64_t inum, bnum, fnum, gnum;
inum = bnum = fnum = gnum = 0;
for (auto I = M->begin(), E = M->end(); I != E; ++I) {
// don't count in declarations
if (I->size() == 0)
continue;
++fnum;
for (const BasicBlock& B : *I) {
++bnum;
inum += B.size();
}
}
for (auto I = M->global_begin(), E = M->global_end(); I != E; ++I)
++gnum;
if (prefix)
errs() << prefix;
errs() << "Globals/Functions/Blocks/Instr.: "
<< gnum << " " << fnum << " " << bnum << " " << inum << "\n";
}
示例2: utostr
std::string RewriteBlocks::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
const char *funcName,
std::string Tag) {
std::string StructRef = "struct " + Tag;
std::string S = "static void __";
S += funcName;
S += "_block_copy_" + utostr(i);
S += "(" + StructRef;
S += "*dst, " + StructRef;
S += "*src) {";
for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = ImportedBlockDecls.begin(),
E = ImportedBlockDecls.end(); I != E; ++I) {
S += "_Block_copy_assign(&dst->";
S += (*I)->getNameAsString();
S += ", src->";
S += (*I)->getNameAsString();
S += ");}";
}
S += "\nstatic void __";
S += funcName;
S += "_block_dispose_" + utostr(i);
S += "(" + StructRef;
S += "*src) {";
for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = ImportedBlockDecls.begin(),
E = ImportedBlockDecls.end(); I != E; ++I) {
S += "_Block_destroy(src->";
S += (*I)->getNameAsString();
S += ");";
}
S += "}\n";
return S;
}
示例3: switch
Interval FlatStoreManager::RegionToInterval(const MemRegion *R) {
switch (R->getKind()) {
case MemRegion::VarRegionKind: {
QualType T = cast<VarRegion>(R)->getValueType(Ctx);
uint64_t Size = Ctx.getTypeSize(T);
return Interval(0, Size-1);
}
default:
llvm_unreachable("Region kind unhandled.");
return Interval(0, 0);
}
}
示例4: InitializeNativeTarget
CodeGenerator::CodeGenerator() {
InitializeNativeTarget();
builder_=new IRBuilder<>(llvm::getGlobalContext());
module_=new Module("my cool jit", llvm::getGlobalContext());
fpm_=new FunctionPassManager (module_);
fpm_->add(llvm::createCFGSimplificationPass());
fpm_->add(llvm::createDeadCodeEliminationPass());
fpm_->add(llvm::createMemCpyOptPass());
engine_ = EngineBuilder(module_).create();
assert(engine_);
}
示例5: hash_value
uint64_t ExternalCommand::getSignature() {
// FIXME: Use a more appropriate hashing infrastructure.
using llvm::hash_combine;
llvm::hash_code code = hash_value(getName());
for (const auto* input: inputs) {
code = hash_combine(code, input->getName());
}
for (const auto* output: outputs) {
code = hash_combine(code, output->getName());
}
code = hash_combine(code, allowMissingInputs);
code = hash_combine(code, allowModifiedOutputs);
code = hash_combine(code, alwaysOutOfDate);
return size_t(code);
}
示例6: input
static StringRef input(StringRef scalar, void*, VMProtect &value) {
value = 0;
if (scalar.size() != 3)
return "segment access protection must be three chars (e.g. \"r-x\")";
switch (scalar[0]) {
case 'r':
value = llvm::MachO::VM_PROT_READ;
break;
case '-':
break;
default:
return "segment access protection first char must be 'r' or '-'";
}
switch (scalar[1]) {
case 'w':
value = value | llvm::MachO::VM_PROT_WRITE;
break;
case '-':
break;
default:
return "segment access protection second char must be 'w' or '-'";
}
switch (scalar[2]) {
case 'x':
value = value | llvm::MachO::VM_PROT_EXECUTE;
break;
case '-':
break;
default:
return "segment access protection third char must be 'x' or '-'";
}
// Return the empty string on success,
return StringRef();
}
示例7: addExportInfo
void Util::addExportInfo(const lld::File &atomFile, NormalizedFile &nFile) {
if (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT)
return;
for (SectionInfo *sect : _sectionInfos) {
for (const AtomInfo &info : sect->atomsAndOffsets) {
const DefinedAtom *atom = info.atom;
if (atom->scope() != Atom::scopeGlobal)
continue;
if (_ctx.exportRestrictMode()) {
if (!_ctx.exportSymbolNamed(atom->name()))
continue;
}
Export exprt;
exprt.name = atom->name();
exprt.offset = _atomToAddress[atom] - _ctx.baseAddress();
exprt.kind = EXPORT_SYMBOL_FLAGS_KIND_REGULAR;
if (atom->merge() == DefinedAtom::mergeAsWeak)
exprt.flags = EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;
else
exprt.flags = 0;
exprt.otherOffset = 0;
exprt.otherName = StringRef();
nFile.exportInfo.push_back(exprt);
}
}
}
示例8: writeModule
bool writeModule() {
// compose name if not given
std::string fl;
if (!options.outputFile.empty()) {
fl = options.outputFile;
} else {
fl = options.inputFile;
replace_suffix(fl, ".sliced");
}
// open stream to write to
std::ofstream ofs(fl);
llvm::raw_os_ostream ostream(ofs);
// write the module
errs() << "INFO: saving sliced module to: " << fl.c_str() << "\n";
#if (LLVM_VERSION_MAJOR > 6)
llvm::WriteBitcodeToFile(*M, ostream);
#else
llvm::WriteBitcodeToFile(M, ostream);
#endif
return true;
}
示例9: printArg
void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
CrashReportInfo *CrashInfo) const {
// Always quote the exe.
OS << ' ';
printArg(OS, Executable, /*Quote=*/true);
llvm::ArrayRef<const char *> Args = Arguments;
llvm::SmallVector<const char *, 128> ArgsRespFile;
if (ResponseFile != nullptr) {
buildArgvForResponseFile(ArgsRespFile);
Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name
}
bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty();
for (size_t i = 0, e = Args.size(); i < e; ++i) {
const char *const Arg = Args[i];
if (CrashInfo) {
if (int Skip = skipArgs(Arg, HaveCrashVFS)) {
i += Skip - 1;
continue;
}
auto Found = std::find_if(InputFilenames.begin(), InputFilenames.end(),
[&Arg](StringRef IF) { return IF == Arg; });
if (Found != InputFilenames.end() &&
(i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
// Replace the input file name with the crashinfo's file name.
OS << ' ';
StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
printArg(OS, ShortName.str().c_str(), Quote);
continue;
}
}
OS << ' ';
printArg(OS, Arg, Quote);
}
if (CrashInfo && HaveCrashVFS) {
OS << ' ';
printArg(OS, "-ivfsoverlay", Quote);
OS << ' ';
printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
}
if (ResponseFile != nullptr) {
OS << "\n Arguments passed via response file:\n";
writeResponseFile(OS);
// Avoiding duplicated newline terminator, since FileLists are
// newline-separated.
if (Creator.getResponseFilesSupport() != Tool::RF_FileList)
OS << "\n";
OS << " (end of response file)";
}
OS << Terminator;
}
示例10: mapping
static void mapping(IO &io, Export &exp) {
io.mapRequired("name", exp.name);
io.mapOptional("offset", exp.offset);
io.mapOptional("kind", exp.kind,
llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR);
if (!io.outputting() || exp.flags)
io.mapOptional("flags", exp.flags);
io.mapOptional("other", exp.otherOffset, Hex32(0));
io.mapOptional("other-name", exp.otherName, StringRef());
}
示例11: format
void
BinMapOutput::InnerSectionsSymbols(const BinGroups& groups)
{
for (BinGroups::const_iterator group = groups.begin(), end=groups.end();
group != end; ++group)
{
if (CountSymbols(m_object, &group->m_section) > 0)
{
StringRef name = group->m_section.getName();
m_os << "---- Section " << name << ' ';
for (size_t i=0; i<65-name.size(); ++i)
m_os << '-';
m_os << "\n\n";
m_os << format("%-*s", m_bytes*2+2, (const char*)"Real");
m_os << format("%-*s", m_bytes*2+2, (const char*)"Virtual");
m_os << "Name\n";
OutputSymbols(&group->m_section);
m_os << "\n\n";
}
// Recurse to loop through follow groups
InnerSectionsSymbols(group->m_follow_groups);
}
}
示例12: ShortName
std::string tesla::ShortName(const Location& Loc) {
return (Twine()
+ Loc.filename()
+ ":"
+ Twine(Loc.line())
+ "#"
+ Twine(Loc.counter())
).str();
}
示例13: verifyAndWriteModule
int verifyAndWriteModule()
{
if (!verifyModule()) {
errs() << "ERR: Verifying module failed, the IR is not valid\n";
errs() << "INFO: Saving anyway so that you can check it\n";
return 1;
}
if (!writeModule()) {
errs() << "Saving sliced module failed\n";
return 1;
}
// exit code
return 0;
}
示例14: SynthesizeBlockLiterals
void RewriteBlocks::SynthesizeBlockLiterals(SourceLocation FunLocStart,
const char *FunName) {
// Insert closures that were part of the function.
for (unsigned i = 0; i < Blocks.size(); i++) {
CollectBlockDeclRefInfo(Blocks[i]);
std::string Tag = "__" + std::string(FunName) + "_block_impl_" + utostr(i);
std::string CI = SynthesizeBlockImpl(Blocks[i], Tag,
ImportedBlockDecls.size() > 0);
InsertText(FunLocStart, CI.c_str(), CI.size());
std::string CF = SynthesizeBlockFunc(Blocks[i], i, FunName, Tag);
InsertText(FunLocStart, CF.c_str(), CF.size());
if (ImportedBlockDecls.size()) {
std::string HF = SynthesizeBlockHelperFuncs(Blocks[i], i, FunName, Tag);
InsertText(FunLocStart, HF.c_str(), HF.size());
}
BlockDeclRefs.clear();
BlockByRefDecls.clear();
BlockByCopyDecls.clear();
BlockCallExprs.clear();
ImportedBlockDecls.clear();
}
Blocks.clear();
RewrittenBlockExprs.clear();
}
示例15: optimize
void optimize( shared_ptr<module_vmcode> code, vector<optimization_options> opt_options )
{
Module* mod = code->get_vm_module();
FunctionPassManager fpm(mod);
for( optimization_options opt_option: opt_options ){
switch ( opt_option ){
case opt_verify:
for( Function& f: mod->getFunctionList() ){
if(!f.empty()){
verifyFunction(f, PrintMessageAction);
}
}
break;
case opt_preset_std_for_function:
// createStandardFunctionPasses( &fpm, 1 );
break;
}
}
fpm.doInitialization();
for( Function& f: mod->getFunctionList() ){
if(!f.empty()){
fpm.run(f);
}
}
}