本文整理汇总了C++中TargetLibraryInfo::disableAllFunctions方法的典型用法代码示例。如果您正苦于以下问题:C++ TargetLibraryInfo::disableAllFunctions方法的具体用法?C++ TargetLibraryInfo::disableAllFunctions怎么用?C++ TargetLibraryInfo::disableAllFunctions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TargetLibraryInfo
的用法示例。
在下文中一共展示了TargetLibraryInfo::disableAllFunctions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TargetLibraryInfo
static TargetLibraryInfo *createTLI(llvm::Triple &TargetTriple,
const CodeGenOptions &CodeGenOpts) {
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
if (!CodeGenOpts.SimplifyLibCalls)
TLI->disableAllFunctions();
return TLI;
}
示例2: Optimize
void Optimize(llvm::Module *M, int OptLevel, int SizeLevel, int Verify) {
// Create a PassManager to hold and optimize the collection of passes we are
// about to build.
//
PassManager Passes;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
Passes.add(TLI);
// Add an appropriate DataLayout instance for this module.
const DataLayout *DL = M->getDataLayout();
if (DL)
Passes.add(new DataLayoutPass());
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = nullptr;
if (ModuleTriple.getArch())
Machine = GetTargetMachine(Triple(ModuleTriple), OptLevel);
std::unique_ptr<TargetMachine> TM(Machine);
// Add internal analysis passes from the target machine.
if (TM.get())
TM->addAnalysisPasses(Passes);
std::unique_ptr<FunctionPassManager> FPasses;
if (OptLevel > 0 || SizeLevel > 0) {
FPasses.reset(new FunctionPassManager(M));
if (DL)
FPasses->add(new DataLayoutPass());
if (TM.get())
TM->addAnalysisPasses(*FPasses);
}
AddOptimizationPasses(Passes, *FPasses, OptLevel, SizeLevel);
if (OptLevel > 0 || SizeLevel > 0) {
FPasses->doInitialization();
for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
FPasses->run(*F);
FPasses->doFinalization();
}
// Check that the module is well formed on completion of optimization
if (Verify) {
Passes.add(createVerifierPass());
Passes.add(createDebugInfoVerifierPass());
}
// Now that we have all of the passes ready, run them.
Passes.run(*M);
}
示例3: llvmToGen
bool llvmToGen(ir::Unit &unit, const char *fileName, int optLevel)
{
// Get the global LLVM context
llvm::LLVMContext& c = llvm::getGlobalContext();
std::string errInfo;
std::unique_ptr<llvm::raw_fd_ostream> o = NULL;
if (OCL_OUTPUT_LLVM_BEFORE_EXTRA_PASS || OCL_OUTPUT_LLVM)
o = std::unique_ptr<llvm::raw_fd_ostream>(new llvm::raw_fd_ostream(fileno(stdout), false));
// Get the module from its file
llvm::SMDiagnostic Err;
std::auto_ptr<Module> M;
M.reset(ParseIRFile(fileName, Err, c));
if (M.get() == 0) return false;
Module &mod = *M.get();
Triple TargetTriple(mod.getTargetTriple());
TargetLibraryInfo *libraryInfo = new TargetLibraryInfo(TargetTriple);
libraryInfo->disableAllFunctions();
runFuntionPass(mod, libraryInfo);
runModulePass(mod, libraryInfo, optLevel);
llvm::PassManager passes;
// Print the code before further optimizations
if (OCL_OUTPUT_LLVM_BEFORE_EXTRA_PASS)
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
passes.add(createPrintModulePass(*o));
#else
passes.add(createPrintModulePass(&*o));
#endif
passes.add(createIntrinsicLoweringPass());
passes.add(createFunctionInliningPass(200000));
passes.add(createScalarReplAggregatesPass()); // Break up allocas
passes.add(createRemoveGEPPass(unit));
passes.add(createConstantPropagationPass());
passes.add(createLowerSwitchPass());
passes.add(createPromoteMemoryToRegisterPass());
passes.add(createGVNPass()); // Remove redundancies
passes.add(createScalarizePass()); // Expand all vector ops
passes.add(createDeadInstEliminationPass()); // Remove simplified instructions
passes.add(createGenPass(unit));
// Print the code extra optimization passes
if (OCL_OUTPUT_LLVM)
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5
passes.add(createPrintModulePass(*o));
#else
passes.add(createPrintModulePass(&*o));
#endif
passes.run(mod);
return true;
}
示例4: TargetTriple
// Unfortunately, the LLVM C API doesn't provide a way to create the
// TargetLibraryInfo pass, so we use this method to do so.
extern "C" void
LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
LLVMModuleRef M,
bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple());
#if LLVM_VERSION_MINOR >= 7
TargetLibraryInfoImpl TLII(TargetTriple);
if (DisableSimplifyLibCalls)
TLII.disableAllFunctions();
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
#else
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
unwrap(PMB)->add(TLI);
#endif
}
示例5: AddEmitPasses
bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action,
formatted_raw_ostream &OS,
TargetMachine *TM) {
// Create the code generator passes.
PassManager *PM = getCodeGenPasses(TM);
// Add LibraryInfo.
llvm::Triple TargetTriple(TheModule->getTargetTriple());
TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple);
if (!CodeGenOpts.SimplifyLibCalls)
TLI->disableAllFunctions();
PM->add(TLI);
// Add TargetTransformInfo.
PM->add(new TargetTransformInfo(TM->getScalarTargetTransformInfo(),
TM->getVectorTargetTransformInfo()));
// Normal mode, emit a .s or .o file by running the code generator. Note,
// this also adds codegenerator level optimization passes.
TargetMachine::CodeGenFileType CGFT = TargetMachine::CGFT_AssemblyFile;
if (Action == Backend_EmitObj)
CGFT = TargetMachine::CGFT_ObjectFile;
else if (Action == Backend_EmitMCNull)
CGFT = TargetMachine::CGFT_Null;
else
assert(Action == Backend_EmitAssembly && "Invalid action!");
// Add ObjC ARC final-cleanup optimizations. This is done as part of the
// "codegen" passes so that it isn't run multiple times when there is
// inlining happening.
if (LangOpts.ObjCAutoRefCount &&
CodeGenOpts.OptimizationLevel > 0)
PM->add(createObjCARCContractPass());
if (TM->addPassesToEmitFile(*PM, OS, CGFT,
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
Diags.Report(diag::err_fe_unable_to_interface_with_target);
return false;
}
return true;
}
示例6: main
//.........这里部分代码省略.........
errs() << "WARNING: The -o (output filename) option is ignored when\n"
"the --disable-output option is used.\n";
} else {
// 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;
}
}
// If the output is set to be emitted to standard out, and standard out is a
// console, print out a warning message and refuse to do it. We don't
// impress anyone by spewing tons of binary goo to a terminal.
if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
NoOutput = true;
// Create a PassManager to hold and optimize the collection of passes we are
// about to build.
//
PassManager Passes;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
Passes.add(TLI);
// Add an appropriate DataLayout instance for this module.
DataLayout *TD = 0;
const std::string &ModuleDataLayout = M.get()->getDataLayout();
if (!ModuleDataLayout.empty())
TD = new DataLayout(ModuleDataLayout);
else if (!DefaultDataLayout.empty())
TD = new DataLayout(DefaultDataLayout);
if (TD)
Passes.add(TD);
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = 0;
if (ModuleTriple.getArch())
Machine = GetTargetMachine(Triple(ModuleTriple));
OwningPtr<TargetMachine> TM(Machine);
// Add internal analysis passes from the target machine.
if (TM.get())
TM->addAnalysisPasses(Passes);
OwningPtr<FunctionPassManager> FPasses;
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get()));
if (TD)
FPasses->add(new DataLayout(*TD));
}
if (PrintBreakpoints) {
// Default to standard output.
示例7: main
//.........这里部分代码省略.........
if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
NoOutput = true;
if (PassPipeline.getNumOccurrences() > 0) {
OutputKind OK = OK_NoOutput;
if (!NoOutput)
OK = OutputAssembly ? OK_OutputAssembly : OK_OutputBitcode;
VerifierKind VK = VK_VerifyInAndOut;
if (NoVerify)
VK = VK_NoVerifier;
else if (VerifyEach)
VK = VK_VerifyEachPass;
// The user has asked to use the new pass manager and provided a pipeline
// string. Hand off the rest of the functionality to the new code for that
// layer.
return runPassPipeline(argv[0], Context, *M, Out.get(), PassPipeline,
OK, VK)
? 0
: 1;
}
// Create a PassManager to hold and optimize the collection of passes we are
// about to build.
//
PassManager Passes;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
Passes.add(TLI);
// Add an appropriate DataLayout instance for this module.
const DataLayout *DL = M->getDataLayout();
if (!DL && !DefaultDataLayout.empty()) {
M->setDataLayout(DefaultDataLayout);
DL = M->getDataLayout();
}
if (DL)
Passes.add(new DataLayoutPass());
Triple ModuleTriple(M->getTargetTriple());
TargetMachine *Machine = nullptr;
if (ModuleTriple.getArch())
Machine = GetTargetMachine(Triple(ModuleTriple));
std::unique_ptr<TargetMachine> TM(Machine);
// Add internal analysis passes from the target machine.
if (TM)
TM->addAnalysisPasses(Passes);
std::unique_ptr<FunctionPassManager> FPasses;
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get()));
if (DL)
FPasses->add(new DataLayoutPass());
if (TM)
TM->addAnalysisPasses(*FPasses);
}
示例8: compileModule
//.........这里部分代码省略.........
RelocModel, CMModel, OLvl));
assert(target.get() && "Could not allocate target machine!");
assert(mod && "Should have exited after outputting help!");
TargetMachine &Target = *target.get();
if (DisableDotLoc)
Target.setMCUseLoc(false);
if (DisableCFI)
Target.setMCUseCFI(false);
if (EnableDwarfDirectory)
Target.setMCUseDwarfDirectory(true);
if (GenerateSoftFloatCalls)
FloatABIForCalls = FloatABI::Soft;
// Disable .loc support for older OS X versions.
if (TheTriple.isMacOSX() &&
TheTriple.isMacOSXVersionLT(10, 6))
Target.setMCUseLoc(false);
// Figure out where we are going to send the output.
OwningPtr<tool_output_file> Out
(GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]));
if (!Out) return 1;
// Build up all of the passes that we want to do to the module.
PassManager PM;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(TheTriple);
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
PM.add(TLI);
if (target.get()) {
PM.add(createNoTTIPass(target->getScalarTargetTransformInfo(),
target->getVectorTargetTransformInfo()));
}
// Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *TD = Target.getDataLayout())
PM.add(new DataLayout(*TD));
else
PM.add(new DataLayout(mod));
// Override default to generate verbose assembly.
Target.setAsmVerbosityDefault(true);
if (RelaxAll) {
if (FileType != TargetMachine::CGFT_ObjectFile)
errs() << argv[0]
<< ": warning: ignoring -mc-relax-all because filetype != obj";
else
Target.setMCRelaxAll(true);
}
{
formatted_raw_ostream FOS(Out->os());
AnalysisID StartAfterID = 0;
AnalysisID StopAfterID = 0;
const PassRegistry *PR = PassRegistry::getPassRegistry();
if (!StartAfter.empty()) {
const PassInfo *PI = PR->getPassInfo(StartAfter);
示例9: main
//===----------------------------------------------------------------------===//
// main for opt
//
int main(int argc, char **argv) {
sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
// Enable debug stream buffering.
EnableDebugBuffering = true;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
LLVMContext &Context = getGlobalContext();
// Initialize passes
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeCore(Registry);
initializeScalarOpts(Registry);
initializeIPO(Registry);
initializeAnalysis(Registry);
initializeIPA(Registry);
initializeTransformUtils(Registry);
initializeInstCombine(Registry);
initializeInstrumentation(Registry);
initializeTarget(Registry);
cl::ParseCommandLineOptions(argc, argv,
"llvm .bc -> .bc modular optimizer and analysis printer\n");
if (AnalyzeOnly && NoOutput) {
errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
return 1;
}
// Allocate a full target machine description only if necessary.
// FIXME: The choice of target should be controllable on the command line.
std::auto_ptr<TargetMachine> target;
SMDiagnostic Err;
// Load the input module...
std::auto_ptr<Module> M;
M.reset(ParseIRFile(InputFilename, Err, Context));
if (M.get() == 0) {
Err.Print(argv[0], errs());
return 1;
}
// Figure out what stream we are supposed to write to...
OwningPtr<tool_output_file> Out;
if (NoOutput) {
if (!OutputFilename.empty())
errs() << "WARNING: The -o (output filename) option is ignored when\n"
"the --disable-output option is used.\n";
} else {
// 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;
}
}
// If the output is set to be emitted to standard out, and standard out is a
// console, print out a warning message and refuse to do it. We don't
// impress anyone by spewing tons of binary goo to a terminal.
if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
NoOutput = true;
// Create a PassManager to hold and optimize the collection of passes we are
// about to build.
//
PassManager Passes;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
Passes.add(TLI);
// Add an appropriate TargetData instance for this module.
TargetData *TD = 0;
const std::string &ModuleDataLayout = M.get()->getDataLayout();
if (!ModuleDataLayout.empty())
TD = new TargetData(ModuleDataLayout);
else if (!DefaultDataLayout.empty())
TD = new TargetData(DefaultDataLayout);
if (TD)
Passes.add(TD);
OwningPtr<FunctionPassManager> FPasses;
//.........这里部分代码省略.........
示例10: compileModule
//.........这里部分代码省略.........
switch (OptLevel) {
default:
errs() << argv[0] << ": invalid optimization level.\n";
return 1;
case ' ': break;
case '0': OLvl = CodeGenOpt::None; break;
case '1': OLvl = CodeGenOpt::Less; break;
case '2': OLvl = CodeGenOpt::Default; break;
case '3': OLvl = CodeGenOpt::Aggressive; break;
}
TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
Options.DisableIntegratedAS = NoIntegratedAssembler;
Options.MCOptions.ShowMCEncoding = ShowMCEncoding;
Options.MCOptions.MCUseDwarfDirectory = EnableDwarfDirectory;
Options.MCOptions.AsmVerbose = AsmVerbose;
std::unique_ptr<TargetMachine> target(
TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr,
Options, RelocModel, CMModel, OLvl));
assert(target.get() && "Could not allocate target machine!");
// If we don't have a module then just exit now. We do this down
// here since the CPU/Feature help is underneath the target machine
// creation.
if (SkipModule)
return 0;
assert(mod && "Should have exited if we didn't have a module!");
TargetMachine &Target = *target.get();
if (GenerateSoftFloatCalls)
FloatABIForCalls = FloatABI::Soft;
// Figure out where we are going to send the output.
std::unique_ptr<tool_output_file> Out(
GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]));
if (!Out) return 1;
// Build up all of the passes that we want to do to the module.
PassManager PM;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(TheTriple);
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
PM.add(TLI);
// Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
mod->setDataLayout(DL);
PM.add(new DataLayoutPass(mod));
if (RelaxAll.getNumOccurrences() > 0 &&
FileType != TargetMachine::CGFT_ObjectFile)
errs() << argv[0]
<< ": warning: ignoring -mc-relax-all because filetype != obj";
{
formatted_raw_ostream FOS(Out->os());
AnalysisID StartAfterID = nullptr;
AnalysisID StopAfterID = nullptr;
const PassRegistry *PR = PassRegistry::getPassRegistry();
if (!StartAfter.empty()) {
const PassInfo *PI = PR->getPassInfo(StartAfter);
if (!PI) {
errs() << argv[0] << ": start-after pass is not registered.\n";
return 1;
}
StartAfterID = PI->getTypeInfo();
}
if (!StopAfter.empty()) {
const PassInfo *PI = PR->getPassInfo(StopAfter);
if (!PI) {
errs() << argv[0] << ": stop-after pass is not registered.\n";
return 1;
}
StopAfterID = PI->getTypeInfo();
}
// Ask the target to add backend passes as necessary.
if (Target.addPassesToEmitFile(PM, FOS, FileType, NoVerify,
StartAfterID, StopAfterID)) {
errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n";
return 1;
}
// Before executing passes, print the final values of the LLVM options.
cl::PrintOptionValues();
PM.run(*mod);
}
// Declare success.
Out->keep();
return 0;
}
示例11: AddEmitPasses
//.........这里部分代码省略.........
assert(CodeGenOpts.RelocationModel == "dynamic-no-pic" &&
"Invalid PIC model!");
RM = llvm::Reloc::DynamicNoPIC;
}
CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
switch (CodeGenOpts.OptimizationLevel) {
default: break;
case 0: OptLevel = CodeGenOpt::None; break;
case 3: OptLevel = CodeGenOpt::Aggressive; break;
}
llvm::TargetOptions Options;
// Set frame pointer elimination mode.
if (!CodeGenOpts.DisableFPElim) {
Options.NoFramePointerElim = false;
Options.NoFramePointerElimNonLeaf = false;
} else if (CodeGenOpts.OmitLeafFramePointer) {
Options.NoFramePointerElim = false;
Options.NoFramePointerElimNonLeaf = true;
} else {
Options.NoFramePointerElim = true;
Options.NoFramePointerElimNonLeaf = true;
}
if (CodeGenOpts.UseInitArray)
Options.UseInitArray = true;
// Set float ABI type.
if (CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp")
Options.FloatABIType = llvm::FloatABI::Soft;
else if (CodeGenOpts.FloatABI == "hard")
Options.FloatABIType = llvm::FloatABI::Hard;
else {
assert(CodeGenOpts.FloatABI.empty() && "Invalid float abi!");
Options.FloatABIType = llvm::FloatABI::Default;
}
Options.LessPreciseFPMADOption = CodeGenOpts.LessPreciseFPMAD;
Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath;
Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath;
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
Options.UseSoftFloat = CodeGenOpts.SoftFloat;
Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
Options.RealignStack = CodeGenOpts.StackRealignment;
Options.DisableTailCalls = CodeGenOpts.DisableTailCalls;
Options.TrapFuncName = CodeGenOpts.TrapFuncName;
Options.PositionIndependentExecutable = LangOpts.PIELevel != 0;
TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU,
FeaturesStr, Options,
RM, CM, OptLevel);
if (CodeGenOpts.RelaxAll)
TM->setMCRelaxAll(true);
if (CodeGenOpts.SaveTempLabels)
TM->setMCSaveTempLabels(true);
if (CodeGenOpts.NoDwarf2CFIAsm)
TM->setMCUseCFI(false);
if (!CodeGenOpts.NoDwarfDirectoryAsm)
TM->setMCUseDwarfDirectory(true);
if (CodeGenOpts.NoExecStack)
TM->setMCNoExecStack(true);
// Create the code generator passes.
PassManager *PM = getCodeGenPasses();
// Add LibraryInfo.
TargetLibraryInfo *TLI = new TargetLibraryInfo();
if (!CodeGenOpts.SimplifyLibCalls)
TLI->disableAllFunctions();
PM->add(TLI);
// Normal mode, emit a .s or .o file by running the code generator. Note,
// this also adds codegenerator level optimization passes.
TargetMachine::CodeGenFileType CGFT = TargetMachine::CGFT_AssemblyFile;
if (Action == Backend_EmitObj)
CGFT = TargetMachine::CGFT_ObjectFile;
else if (Action == Backend_EmitMCNull)
CGFT = TargetMachine::CGFT_Null;
else
assert(Action == Backend_EmitAssembly && "Invalid action!");
// Add ObjC ARC final-cleanup optimizations. This is done as part of the
// "codegen" passes so that it isn't run multiple times when there is
// inlining happening.
if (LangOpts.ObjCAutoRefCount &&
CodeGenOpts.OptimizationLevel > 0)
PM->add(createObjCARCContractPass());
if (TM->addPassesToEmitFile(*PM, OS, CGFT,
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
Diags.Report(diag::err_fe_unable_to_interface_with_target);
return false;
}
return true;
}
示例12: ldc_optimize_module
//////////////////////////////////////////////////////////////////////////////////////////
// This function runs optimization passes based on command line arguments.
// Returns true if any optimization passes were invoked.
bool ldc_optimize_module(llvm::Module *M)
{
// Create a PassManager to hold and optimize the collection of
// per-module passes we are about to build.
#if LDC_LLVM_VER >= 307
legacy::
#endif
PassManager mpm;
#if LDC_LLVM_VER >= 307
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl *tlii = new TargetLibraryInfoImpl(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (disableSimplifyLibCalls)
tlii->disableAllFunctions();
mpm.add(new TargetLibraryInfoWrapperPass(*tlii));
#else
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (disableSimplifyLibCalls)
tli->disableAllFunctions();
mpm.add(tli);
#endif
// Add an appropriate DataLayout instance for this module.
#if LDC_LLVM_VER >= 307
// The DataLayout is already set at the module (in module.cpp,
// method Module::genLLVMModule())
// FIXME: Introduce new command line switch default-data-layout to
// override the module data layout
#elif LDC_LLVM_VER == 306
mpm.add(new DataLayoutPass());
#elif LDC_LLVM_VER == 305
const DataLayout *DL = M->getDataLayout();
assert(DL && "DataLayout not set at module");
mpm.add(new DataLayoutPass(*DL));
#elif LDC_LLVM_VER >= 302
mpm.add(new DataLayout(M));
#else
mpm.add(new TargetData(M));
#endif
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine.
mpm.add(createTargetTransformInfoWrapperPass(gTargetMachine->getTargetIRAnalysis()));
#elif LDC_LLVM_VER >= 305
// Add internal analysis passes from the target machine.
gTargetMachine->addAnalysisPasses(mpm);
#endif
// Also set up a manager for the per-function passes.
#if LDC_LLVM_VER >= 307
legacy::
#endif
FunctionPassManager fpm(M);
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine.
fpm.add(createTargetTransformInfoWrapperPass(gTargetMachine->getTargetIRAnalysis()));
#elif LDC_LLVM_VER >= 306
fpm.add(new DataLayoutPass());
gTargetMachine->addAnalysisPasses(fpm);
#elif LDC_LLVM_VER == 305
fpm.add(new DataLayoutPass(M));
gTargetMachine->addAnalysisPasses(fpm);
#elif LDC_LLVM_VER >= 302
fpm.add(new DataLayout(M));
#else
fpm.add(new TargetData(M));
#endif
// If the -strip-debug command line option was specified, add it before
// anything else.
if (stripDebug)
mpm.add(createStripSymbolsPass(true));
bool defaultsAdded = false;
// Create a new optimization pass for each one specified on the command line
for (unsigned i = 0; i < passList.size(); ++i) {
if (optimizeLevel && optimizeLevel.getPosition() < passList.getPosition(i)) {
addOptimizationPasses(mpm, fpm, optLevel(), sizeLevel());
defaultsAdded = true;
}
const PassInfo *passInf = passList[i];
Pass *pass = 0;
if (passInf->getNormalCtor())
pass = passInf->getNormalCtor()();
else {
const char* arg = passInf->getPassArgument(); // may return null
if (arg)
error(Loc(), "Can't create pass '-%s' (%s)", arg, pass->getPassName());
//.........这里部分代码省略.........
示例13: ldc_optimize_module
////////////////////////////////////////////////////////////////////////////////
// This function runs optimization passes based on command line arguments.
// Returns true if any optimization passes were invoked.
bool ldc_optimize_module(llvm::Module *M) {
// Create a PassManager to hold and optimize the collection of
// per-module passes we are about to build.
#if LDC_LLVM_VER >= 307
legacy::
#endif
PassManager mpm;
#if LDC_LLVM_VER >= 307
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfoImpl *tlii =
new TargetLibraryInfoImpl(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (disableSimplifyLibCalls)
tlii->disableAllFunctions();
mpm.add(new TargetLibraryInfoWrapperPass(*tlii));
#else
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(M->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (disableSimplifyLibCalls) {
tli->disableAllFunctions();
}
mpm.add(tli);
#endif
// Add an appropriate DataLayout instance for this module.
#if LDC_LLVM_VER >= 307
// The DataLayout is already set at the module (in module.cpp,
// method Module::genLLVMModule())
// FIXME: Introduce new command line switch default-data-layout to
// override the module data layout
#elif LDC_LLVM_VER == 306
mpm.add(new DataLayoutPass());
#else
const DataLayout *DL = M->getDataLayout();
assert(DL &&
"DataLayout not set at module");
mpm.add(new DataLayoutPass(*DL));
#endif
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine.
mpm.add(createTargetTransformInfoWrapperPass(
gTargetMachine->getTargetIRAnalysis()));
#else
// Add internal analysis passes from the target machine.
gTargetMachine->addAnalysisPasses(mpm);
#endif
// Also set up a manager for the per-function passes.
#if LDC_LLVM_VER >= 307
legacy::
#endif
FunctionPassManager fpm(M);
#if LDC_LLVM_VER >= 307
// Add internal analysis passes from the target machine.
fpm.add(createTargetTransformInfoWrapperPass(
gTargetMachine->getTargetIRAnalysis()));
#elif LDC_LLVM_VER >= 306
fpm.add(new DataLayoutPass());
gTargetMachine->addAnalysisPasses(fpm);
#else
fpm.add(new DataLayoutPass(M));
gTargetMachine->addAnalysisPasses(fpm);
#endif
// If the -strip-debug command line option was specified, add it before
// anything else.
if (stripDebug) {
mpm.add(createStripSymbolsPass(true));
}
addOptimizationPasses(mpm, fpm, optLevel(), sizeLevel());
// Run per-function passes.
fpm.doInitialization();
for (auto &F : *M) {
fpm.run(F);
}
fpm.doFinalization();
// Run per-module passes.
mpm.run(*M);
// Verify the resulting module.
verifyModule(M);
// Report that we run some passes.
return true;
}
示例14: ldc_optimize_module
//////////////////////////////////////////////////////////////////////////////////////////
// This function runs optimization passes based on command line arguments.
// Returns true if any optimization passes were invoked.
bool ldc_optimize_module(llvm::Module* m)
{
// Create a PassManager to hold and optimize the collection of
// per-module passes we are about to build.
PassManager mpm;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *tli = new TargetLibraryInfo(Triple(m->getTargetTriple()));
// The -disable-simplify-libcalls flag actually disables all builtin optzns.
if (disableSimplifyLibCalls)
tli->disableAllFunctions();
mpm.add(tli);
// Add an appropriate TargetData instance for this module.
#if LDC_LLVM_VER >= 302
mpm.add(new DataLayout(m));
#else
mpm.add(new TargetData(m));
#endif
// Also set up a manager for the per-function passes.
FunctionPassManager fpm(m);
#if LDC_LLVM_VER >= 302
fpm.add(new DataLayout(m));
#else
fpm.add(new TargetData(m));
#endif
// If the -strip-debug command line option was specified, add it before
// anything else.
if (stripDebug)
mpm.add(createStripSymbolsPass(true));
bool defaultsAdded = false;
// Create a new optimization pass for each one specified on the command line
for (unsigned i = 0; i < passList.size(); ++i) {
if (optimizeLevel && optimizeLevel.getPosition() < passList.getPosition(i)) {
addOptimizationPasses(mpm, fpm, optLevel(), sizeLevel());
defaultsAdded = true;
}
const PassInfo *passInf = passList[i];
Pass *pass = 0;
if (passInf->getNormalCtor())
pass = passInf->getNormalCtor()();
else {
const char* arg = passInf->getPassArgument(); // may return null
if (arg)
error("Can't create pass '-%s' (%s)", arg, pass->getPassName());
else
error("Can't create pass (%s)", pass->getPassName());
llvm_unreachable("pass creation failed");
}
if (pass) {
addPass(mpm, pass);
}
}
// Add the default passes for the specified optimization level.
if (!defaultsAdded)
addOptimizationPasses(mpm, fpm, optLevel(), sizeLevel());
// Run per-function passes.
fpm.doInitialization();
for (llvm::Module::iterator F = m->begin(), E = m->end(); F != E; ++F)
fpm.run(*F);
fpm.doFinalization();
// Run per-module passes.
mpm.run(*m);
// Verify the resulting module.
verifyModule(m);
// Report that we run some passes.
return true;
}
示例15: CompileModule
// The following function is adapted from llc.cpp
int CompileModule(Module *mod, raw_string_ostream &os, bool emitBRIG,
int OptLevel) {
// Load the module to be compiled...
SMDiagnostic Err;
Triple TheTriple;
TheTriple = Triple(mod->getTargetTriple());
if (TheTriple.getTriple().empty())
TheTriple.setTriple(sys::getDefaultTargetTriple());
// Get the target specific parser.
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
Error);
if (!TheTarget) {
errs() << Error;
return 0;
}
// Package up features to be passed to target/subtarget
std::string FeaturesStr;
CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel) {
case 0: OLvl = CodeGenOpt::None; break;
case 1: OLvl = CodeGenOpt::Less; break;
case 2: OLvl = CodeGenOpt::Default; break;
case 3: OLvl = CodeGenOpt::Aggressive; break;
}
TargetOptions Options;
std::unique_ptr<TargetMachine> target(
TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr,
Options, RelocModel, CMModel, OLvl));
assert(target.get() && "Could not allocate target machine!");
assert(mod && "Should have exited if we didn't have a module!");
TargetMachine &Target = *target.get();
if (GenerateSoftFloatCalls)
FloatABIForCalls = FloatABI::Soft;
// Build up all of the passes that we want to do to the module.
PassManager PM;
// Add an appropriate TargetLibraryInfo pass for the module's triple.
TargetLibraryInfo *TLI = new TargetLibraryInfo(TheTriple);
if (DisableSimplifyLibCalls)
TLI->disableAllFunctions();
PM.add(TLI);
// Add the target data from the target machine, if it exists, or the module.
if (const DataLayout *DL = Target.getSubtargetImpl()->getDataLayout())
mod->setDataLayout(DL);
PM.add(new DataLayoutPass());
auto FileType = (emitBRIG
? TargetMachine::CGFT_ObjectFile
: TargetMachine::CGFT_AssemblyFile);
formatted_raw_ostream FOS(os);
// Ask the target to add backend passes as necessary.
bool Verify = false;
if (Target.addPassesToEmitFile(PM, FOS, FileType, Verify)) {
errs() << "target does not support generation of this"
<< " file type!\n";
return 0;
}
PM.run(*mod);
return 1;
}