本文整理汇总了C++中cl::opt::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ opt::empty方法的具体用法?C++ opt::empty怎么用?C++ opt::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cl::opt
的用法示例。
在下文中一共展示了opt::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyBinary
void CopyBinary(const ELFObjectFile<ELF64LE> &ObjFile) {
std::unique_ptr<FileOutputBuffer> Buffer;
std::unique_ptr<Object<ELF64LE>> Obj;
if (!OutputFormat.empty() && OutputFormat != "binary")
error("invalid output format '" + OutputFormat + "'");
if (!OutputFormat.empty() && OutputFormat == "binary")
Obj = llvm::make_unique<BinaryObject<ELF64LE>>(ObjFile);
else
Obj = llvm::make_unique<ELFObject<ELF64LE>>(ObjFile);
Obj->finalize();
ErrorOr<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(OutputFilename, Obj->totalSize(),
FileOutputBuffer::F_executable);
if (BufferOrErr.getError())
error("failed to open " + OutputFilename);
else
Buffer = std::move(*BufferOrErr);
std::error_code EC;
if (EC)
report_fatal_error(EC.message());
Obj->write(*Buffer);
if (auto EC = Buffer->commit())
reportError(OutputFilename, EC);
}
示例2: doImportingForModule
static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) {
if (SummaryFile.empty() && !Index)
report_fatal_error("error: -function-import requires -summary-file or "
"file from frontend\n");
std::unique_ptr<ModuleSummaryIndex> IndexPtr;
if (!SummaryFile.empty()) {
if (Index)
report_fatal_error("error: -summary-file and index from frontend\n");
Expected<std::unique_ptr<ModuleSummaryIndex>> IndexPtrOrErr =
getModuleSummaryIndexForFile(SummaryFile);
if (!IndexPtrOrErr) {
logAllUnhandledErrors(IndexPtrOrErr.takeError(), errs(),
"Error loading file '" + SummaryFile + "': ");
return false;
}
IndexPtr = std::move(*IndexPtrOrErr);
Index = IndexPtr.get();
}
// First step is collecting the import list.
FunctionImporter::ImportMapTy ImportList;
ComputeCrossModuleImportForModule(M.getModuleIdentifier(), *Index,
ImportList);
// Conservatively mark all internal values as promoted. This interface is
// only used when doing importing via the function importing pass. The pass
// is only enabled when testing importing via the 'opt' tool, which does
// not do the ThinLink that would normally determine what values to promote.
for (auto &I : *Index) {
for (auto &S : I.second) {
if (GlobalValue::isLocalLinkage(S->linkage()))
S->setLinkage(GlobalValue::ExternalLinkage);
}
}
// Next we need to promote to global scope and rename any local values that
// are potentially exported to other modules.
if (renameModuleForThinLTO(M, *Index, nullptr)) {
errs() << "Error renaming module\n";
return false;
}
// Perform the import now.
auto ModuleLoader = [&M](StringRef Identifier) {
return loadFile(Identifier, M.getContext());
};
FunctionImporter Importer(*Index, ModuleLoader);
Expected<bool> Result = Importer.importFunctions(
M, ImportList, !DontForceImportReferencedDiscardableSymbols);
// FIXME: Probably need to propagate Errors through the pass manager.
if (!Result) {
logAllUnhandledErrors(Result.takeError(), errs(),
"Error importing module: ");
return false;
}
return *Result;
}
示例3: out
ExecutionEngine * JIT_to_ExecutionEngine (Module * m) {
InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
PassRegistry * Registry = PassRegistry::getPassRegistry();
initializeCore(*Registry);
initializeCodeGen(*Registry);
initializeLowerIntrinsicsPass(*Registry);
std::string errMessage;
EngineBuilder builder{std::unique_ptr<Module>(m)};
builder.setErrorStr(&errMessage);
builder.setMCPU(sys::getHostCPUName());
TargetOptions opts = InitTargetOptionsFromCodeGenFlags();
builder.setTargetOptions(opts);
CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
switch (OptLevel) {
case '0': optLevel = CodeGenOpt::None; break;
case '1': optLevel = CodeGenOpt::Less; break;
case '2': optLevel = CodeGenOpt::Default; break;
case '3': optLevel = CodeGenOpt::Aggressive; break;
default: errs() << OptLevel << " is an invalid optimization level.\n";
}
builder.setOptLevel(optLevel);
if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
std::vector<std::string> attrs;
attrs.push_back("avx2");
builder.setMAttrs(attrs);
}
// builder.selectTarget();
if (LLVM_UNLIKELY(DumpGeneratedIR)) {
if (IROutputFilename.empty()) {
m->dump();
} else {
std::error_code error;
llvm::raw_fd_ostream out(IROutputFilename, error, sys::fs::OpenFlags::F_None);
m->print(out, nullptr);
}
}
ExecutionEngine * engine = builder.create();
ICGrepObjectCache * cache = nullptr;
if (engine == nullptr) {
throw std::runtime_error("Could not create ExecutionEngine: " + errMessage);
}
if (EnableObjectCache) {
if (ObjectCacheDir.empty())
// Default is $HOME/.cache/icgrep
cache = new ICGrepObjectCache();
else
cache = new ICGrepObjectCache(ObjectCacheDir);
engine->setObjectCache(cache);
}
return engine;
}
示例4: main
//===----------------------------------------------------------------------===//
int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
std::string ErrorInfo;
raw_fd_ostream OS(OutputFile.c_str(), ErrorInfo);
if (!ErrorInfo.empty())
errs() << ErrorInfo << "\n";
GCOVFile GF;
if (InputGCNO.empty())
errs() << " " << argv[0] << ": No gcov input file!\n";
OwningPtr<MemoryBuffer> GCNO_Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
errs() << InputGCNO << ": " << ec.message() << "\n";
return 1;
}
GCOVBuffer GCNO_GB(GCNO_Buff.get());
if (!GF.read(GCNO_GB)) {
errs() << "Invalid .gcno File!\n";
return 1;
}
if (!InputGCDA.empty()) {
OwningPtr<MemoryBuffer> GCDA_Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
errs() << InputGCDA << ": " << ec.message() << "\n";
return 1;
}
GCOVBuffer GCDA_GB(GCDA_Buff.get());
if (!GF.read(GCDA_GB)) {
errs() << "Invalid .gcda File!\n";
return 1;
}
}
if (DumpGCOV)
GF.dump();
FileInfo FI;
GF.collectLineCounts(FI);
FI.print(OS, InputGCNO, InputGCDA);
return 0;
}
示例5: TheTriple
static const Target *getTarget(const ObjectFile *Obj) {
// Figure out the target triple.
Triple TheTriple("unknown-unknown-unknown");
if (TripleName.empty()) {
if (Obj) {
TheTriple.setArch(Triple::ArchType(Obj->getArch()));
// TheTriple defaults to ELF, and COFF doesn't have an environment:
// the best we can do here is indicate that it is mach-o.
if (Obj->isMachO())
TheTriple.setObjectFormat(Triple::MachO);
}
} else {
TheTriple.setTriple(TripleName);
}
// Get the Target.
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget("", TheTriple, Error);
if (!TheTarget) {
errs() << ToolName << ": " << Error;
return 0;
}
// Update the triple name and return the found target.
TripleName = TheTriple.getTriple();
return TheTarget;
}
示例6: WriteOutputFile
static void WriteOutputFile(const Module *M) {
// Infer the output filename if needed.
if (OutputFilename.empty()) {
if (InputFilename == "-") {
OutputFilename = "-";
} else {
StringRef IFN = InputFilename;
OutputFilename = (IFN.endswith(".ll") ? IFN.drop_back(3) : IFN).str();
OutputFilename += ".bc";
}
}
std::error_code EC;
std::unique_ptr<ToolOutputFile> Out(
new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
if (EC) {
errs() << EC.message() << '\n';
exit(1);
}
if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
WriteBitcodeToFile(*M, Out->os(), PreserveBitcodeUseListOrder, nullptr,
EmitModuleHash);
// Declare success.
Out->keep();
}
示例7: createCombinedFunctionIndex
/// Create a combined index file from the input IR files and write it.
///
/// This is meant to enable testing of ThinLTO combined index generation,
/// currently available via the gold plugin via -thinlto.
static int createCombinedFunctionIndex(StringRef Command) {
FunctionInfoIndex CombinedIndex;
uint64_t NextModuleId = 0;
for (auto &Filename : InputFilenames) {
ErrorOr<std::unique_ptr<FunctionInfoIndex>> IndexOrErr =
getFunctionIndexForFile(Filename, diagnosticHandler);
if (std::error_code EC = IndexOrErr.getError()) {
std::string Error = EC.message();
errs() << Command << ": error loading file '" << Filename
<< "': " << Error << "\n";
return 1;
}
std::unique_ptr<FunctionInfoIndex> Index = std::move(IndexOrErr.get());
// Skip files without a function summary.
if (!Index)
continue;
CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
}
std::error_code EC;
assert(!OutputFilename.empty());
raw_fd_ostream OS(OutputFilename + ".thinlto.bc", EC,
sys::fs::OpenFlags::F_None);
if (EC) {
errs() << Command << ": error opening the file '" << OutputFilename
<< ".thinlto.bc': " << EC.message() << "\n";
return 1;
}
WriteFunctionSummaryToFile(CombinedIndex, OS);
OS.close();
return 0;
}
示例8: Choose
static unsigned Choose(unsigned n) {
ensure(n > 0);
++Depth;
if (!Fuzz) {
if (RT) {
ensure(Depth <= 99);
setpri();
}
for (unsigned i = 0; i < (n - 1); ++i) {
int ret = ::fork();
ensure(ret != -1);
if (ret == 0) {
Id = Shmem->NextId.fetch_add(1);
Choices += std::to_string(i) + " ";
return i;
}
if (RT)
ensure(0 == sem_wait(&Shmem->sem));
else
::wait(0);
}
Choices += std::to_string(n - 1) + " ";
return n - 1;
} else if (!ForcedChoiceStr.empty()) {
static unsigned Choice = 0;
return ForcedChoices[Choice++];
} else {
unsigned i = rand() % n;
Choices += std::to_string(i) + " ";
return i;
}
}
示例9: main
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
cl::ParseCommandLineOptions(argc, argv);
std::unique_ptr<CompilationDatabase> Compilations(
FixedCompilationDatabase::loadFromCommandLine(argc, argv));
if (!Compilations) { // Couldn't find a compilation DB from the command line
std::string ErrorMessage;
Compilations.reset(
!BuildPath.empty() ?
CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage) :
CompilationDatabase::autoDetectFromSource(SourcePaths[0], ErrorMessage)
);
// Still no compilation DB? - bail.
if (!Compilations)
llvm::report_fatal_error(ErrorMessage);
}
ClangTool Tool(*Compilations, SourcePaths);
InstContext IC;
ExprBuilderContext EBC;
CandidateMap CandMap;
std::vector<std::unique_ptr<llvm::Module>> OwnedMods;
std::unique_ptr<FrontendActionFactory> Factory(CreateExtractorActionFactory(
getGlobalContext(), IC, EBC, OwnedMods, CandMap));
Tool.run(Factory.get());
std::unique_ptr<Solver> S = GetSolverFromArgs();
return SolveCandidateMap(llvm::outs(), CandMap, S.get()) ? 0 : 1;
}
示例10: createCombinedFunctionIndex
/// Create a combined index file from the input IR files and write it.
///
/// This is meant to enable testing of ThinLTO combined index generation,
/// currently available via the gold plugin via -thinlto.
static int createCombinedFunctionIndex(StringRef Command) {
LLVMContext Context;
FunctionInfoIndex CombinedIndex;
uint64_t NextModuleId = 0;
for (auto &Filename : InputFilenames) {
std::string Error;
std::unique_ptr<FunctionInfoIndex> Index =
getFunctionIndexForFile(Filename, Error, Context);
if (!Index) {
errs() << Command << ": error loading file '" << Filename
<< "': " << Error << "\n";
return 1;
}
CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
}
std::error_code EC;
assert(!OutputFilename.empty());
raw_fd_ostream OS(OutputFilename + ".thinlto.bc", EC,
sys::fs::OpenFlags::F_None);
if (EC) {
errs() << Command << ": error opening the file '" << OutputFilename
<< ".thinlto.bc': " << EC.message() << "\n";
return 1;
}
WriteFunctionSummaryToFile(CombinedIndex, OS);
OS.close();
return 0;
}
示例11: FixedCompilationDatabase
CommonOptionsParser::CommonOptionsParser(
int &argc, const char **argv, cl::OptionCategory &Category,
llvm::cl::NumOccurrencesFlag OccurrencesFlag, const char *Overview) {
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);
static cl::opt<std::string> BuildPath("p", cl::desc("Build path"),
cl::Optional, cl::cat(Category));
static cl::list<std::string> SourcePaths(
cl::Positional, cl::desc("<source0> [... <sourceN>]"), OccurrencesFlag,
cl::cat(Category));
static cl::list<std::string> ArgsAfter(
"extra-arg",
cl::desc("Additional argument to append to the compiler command line"),
cl::cat(Category));
static cl::list<std::string> ArgsBefore(
"extra-arg-before",
cl::desc("Additional argument to prepend to the compiler command line"),
cl::cat(Category));
cl::HideUnrelatedOptions(Category);
std::string ErrorMessage;
Compilations =
FixedCompilationDatabase::loadFromCommandLine(argc, argv, ErrorMessage);
if (!Compilations && !ErrorMessage.empty())
llvm::errs() << ErrorMessage;
cl::ParseCommandLineOptions(argc, argv, Overview);
cl::PrintOptionValues();
SourcePathList = SourcePaths;
if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) &&
SourcePathList.empty())
return;
if (!Compilations) {
if (!BuildPath.empty()) {
Compilations =
CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage);
} else {
Compilations = CompilationDatabase::autoDetectFromSource(SourcePaths[0],
ErrorMessage);
}
if (!Compilations) {
llvm::errs() << "Error while trying to load a compilation database:\n"
<< ErrorMessage << "Running without flags.\n";
Compilations.reset(
new FixedCompilationDatabase(".", std::vector<std::string>()));
}
}
auto AdjustingCompilations =
llvm::make_unique<ArgumentsAdjustingCompilations>(
std::move(Compilations));
AdjustingCompilations->appendArgumentsAdjuster(
getInsertArgumentAdjuster(ArgsBefore, ArgumentInsertPosition::BEGIN));
AdjustingCompilations->appendArgumentsAdjuster(
getInsertArgumentAdjuster(ArgsAfter, ArgumentInsertPosition::END));
Compilations = std::move(AdjustingCompilations);
}
示例12: runOnModule
bool CheerpWritePass::runOnModule(Module& M)
{
cheerp::PointerAnalyzer &PA = getAnalysis<cheerp::PointerAnalyzer>();
cheerp::GlobalDepsAnalyzer &GDA = getAnalysis<cheerp::GlobalDepsAnalyzer>();
cheerp::Registerize ®isterize = getAnalysis<cheerp::Registerize>();
cheerp::SourceMapGenerator* sourceMapGenerator = NULL;
if (!SourceMap.empty())
{
std::string ErrorString;
sourceMapGenerator = new cheerp::SourceMapGenerator(SourceMap, SourceMapPrefix, M.getContext(), ErrorString);
if (!ErrorString.empty())
{
// An error occurred opening the source map file, bail out
delete sourceMapGenerator;
llvm::report_fatal_error(ErrorString.c_str(), false);
return false;
}
}
PA.fullResolve();
PA.computeConstantOffsets(M);
registerize.assignRegisters(M, PA);
cheerp::CheerpWriter writer(M, Out, PA, registerize, GDA, sourceMapGenerator, PrettyCode, NoRegisterize, !NoNativeJavaScriptMath, !NoJavaScriptMathImul);
writer.makeJS();
delete sourceMapGenerator;
return false;
}
示例13: runSpecificPasses
static void runSpecificPasses(StringRef Binary, llvm::Module *M,
llvm::TargetMachine *TM,
llvm::Triple &ModuleTriple) {
llvm::legacy::PassManager Passes;
llvm::TargetLibraryInfoImpl TLII(ModuleTriple);
Passes.add(new TargetLibraryInfoWrapperPass(TLII));
const llvm::DataLayout &DL = M->getDataLayout();
if (DL.isDefault() && !DefaultDataLayout.empty()) {
M->setDataLayout(DefaultDataLayout);
}
// Add internal analysis passes from the target machine.
Passes.add(createTargetTransformInfoWrapperPass(TM ? TM->getTargetIRAnalysis()
: TargetIRAnalysis()));
for (const llvm::PassInfo *PassInfo : PassList) {
llvm::Pass *P = nullptr;
if (PassInfo->getTargetMachineCtor())
P = PassInfo->getTargetMachineCtor()(TM);
else if (PassInfo->getNormalCtor())
P = PassInfo->getNormalCtor()();
else
errs() << Binary << ": cannot create pass: " << PassInfo->getPassName()
<< "\n";
if (P) {
addPass(Passes, P);
}
}
// Do it.
Passes.run(*M);
}
示例14: main
int main(int argc, char **argv) {
// Init LLVM, call llvm_shutdown() on exit, parse args, etc.
llvm::PrettyStackTraceProgram X(argc, argv);
cl::ParseCommandLineOptions(argc, argv, "llvm codegen stress-tester\n");
llvm_shutdown_obj Y;
std::auto_ptr<Module> M(new Module("/tmp/autogen.bc", getGlobalContext()));
Function *F = GenEmptyFunction(M.get());
FillFunction(F);
IntroduceControlFlow(F);
// Figure out what stream we are supposed to write to...
OwningPtr<tool_output_file> Out;
// Default to standard output.
if (OutputFilename.empty())
OutputFilename = "-";
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
raw_fd_ostream::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
}
PassManager Passes;
Passes.add(createVerifierPass());
Passes.add(createPrintModulePass(&Out->os()));
Passes.run(*M.get());
Out->keep();
return 0;
}
示例15: WriteOutputFile
static void WriteOutputFile(const Module *M) {
// Infer the output filename if needed.
if (OutputFilename.empty()) {
if (InputFilename == "-") {
OutputFilename = "-";
} else {
std::string IFN = InputFilename;
int Len = IFN.length();
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
// Source ends in .ll
OutputFilename = std::string(IFN.begin(), IFN.end()-3);
} else {
OutputFilename = IFN; // Append a .bc to it
}
OutputFilename += ".bc";
}
}
std::error_code EC;
std::unique_ptr<tool_output_file> Out(
new tool_output_file(OutputFilename, EC, sys::fs::F_None));
if (EC) {
errs() << EC.message() << '\n';
exit(1);
}
if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
WriteBitcodeToFile(M, Out->os(), PreserveBitcodeUseListOrder);
// Declare success.
Out->keep();
}