#include "llvm/Analysis/RegionPass.h"
#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/CodeGen/CommandFlags.h"
-#include "llvm/InitializePasses.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LegacyPassNameParser.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IRReader/IRReader.h"
+#include "llvm/InitializePasses.h"
#include "llvm/LinkAllIR.h"
#include "llvm/LinkAllPasses.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/PassManager.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/PassNameParser.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
PM.add(P);
// If we are verifying all of the intermediate steps, add the verifier...
- if (VerifyEach) PM.add(createVerifierPass());
+ if (VerifyEach) {
+ PM.add(createVerifierPass());
+ PM.add(createDebugInfoVerifierPass());
+ }
}
/// AddOptimizationPasses - This routine adds optimization passes
/// OptLevel - Optimization Level
static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
unsigned OptLevel, unsigned SizeLevel) {
- FPM.add(createVerifierPass()); // Verify that input is correct
+ FPM.add(createVerifierPass()); // Verify that input is correct
+ MPM.add(createDebugInfoVerifierPass()); // Verify that debug info is correct
PassManagerBuilder Builder;
Builder.OptLevel = OptLevel;
if (DisableInline) {
// No inlining pass
} else if (OptLevel > 1) {
- unsigned Threshold = 225;
- if (SizeLevel == 1) // -Os
- Threshold = 75;
- else if (SizeLevel == 2) // -Oz
- Threshold = 25;
- if (OptLevel > 2)
- Threshold = 275;
- Builder.Inliner = createFunctionInliningPass(Threshold);
+ Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel);
} else {
Builder.Inliner = createAlwaysInlinerPass();
}
if (StripDebug)
addPass(PM, createStripSymbolsPass(true));
+ // Verify debug info only after it's (possibly) stripped.
+ PM.add(createDebugInfoVerifierPass());
+
if (DisableOptimizations) return;
// -std-compile-opts adds the same module passes as -O3.
if (StripDebug)
addPass(PM, createStripSymbolsPass(true));
+ // Verify debug info only after it's (possibly) stripped.
+ PM.add(createDebugInfoVerifierPass());
+
if (DisableOptimizations) return;
PassManagerBuilder Builder;
Error);
// Some modules don't specify a triple, and this is okay.
if (!TheTarget) {
- return 0;
+ return nullptr;
}
// Package up features to be passed to target/subtarget
GetCodeGenOptLevel());
}
+#ifdef LINK_POLLY_INTO_TOOLS
+namespace polly {
+void initializePollyPasses(llvm::PassRegistry &Registry);
+}
+#endif
+
//===----------------------------------------------------------------------===//
// main for opt
//
InitializeAllTargets();
InitializeAllTargetMCs();
+ InitializeAllAsmPrinters();
// Initialize passes
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeInstrumentation(Registry);
initializeTarget(Registry);
// For codegen passes, only passes that do IR to IR transformation are
- // supported. For now, just add CodeGenPrepare.
+ // supported.
initializeCodeGenPreparePass(Registry);
+ initializeAtomicExpandLoadLinkedPass(Registry);
+
+#ifdef LINK_POLLY_INTO_TOOLS
+ polly::initializePollyPasses(Registry);
+#endif
cl::ParseCommandLineOptions(argc, argv,
"llvm .bc -> .bc modular optimizer and analysis printer\n");
SMDiagnostic Err;
// Load the input module...
- OwningPtr<Module> M;
+ std::unique_ptr<Module> M;
M.reset(ParseIRFile(InputFilename, Err, Context));
- if (M.get() == 0) {
+ if (!M.get()) {
Err.print(argv[0], errs());
return 1;
}
M->setTargetTriple(Triple::normalize(TargetTriple));
// Figure out what stream we are supposed to write to...
- OwningPtr<tool_output_file> Out;
+ std::unique_ptr<tool_output_file> Out;
if (NoOutput) {
if (!OutputFilename.empty())
errs() << "WARNING: The -o (output filename) option is ignored when\n"
// Add an appropriate DataLayout instance for this module.
const DataLayout *DL = M.get()->getDataLayout();
- if (!DL && !DefaultDataLayout.empty())
- DL = new DataLayout(DefaultDataLayout);
+ if (!DL && !DefaultDataLayout.empty()) {
+ M->setDataLayout(DefaultDataLayout);
+ DL = M.get()->getDataLayout();
+ }
if (DL)
- Passes.add(new DataLayoutPass(*DL));
+ Passes.add(new DataLayoutPass(M.get()));
Triple ModuleTriple(M->getTargetTriple());
- TargetMachine *Machine = 0;
+ TargetMachine *Machine = nullptr;
if (ModuleTriple.getArch())
Machine = GetTargetMachine(Triple(ModuleTriple));
- OwningPtr<TargetMachine> TM(Machine);
+ std::unique_ptr<TargetMachine> TM(Machine);
// Add internal analysis passes from the target machine.
if (TM.get())
TM->addAnalysisPasses(Passes);
- OwningPtr<FunctionPassManager> FPasses;
+ std::unique_ptr<FunctionPassManager> FPasses;
if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
FPasses.reset(new FunctionPassManager(M.get()));
if (DL)
- FPasses->add(new DataLayoutPass(*DL));
+ FPasses->add(new DataLayoutPass(M.get()));
if (TM.get())
TM->addAnalysisPasses(*FPasses);
}
const PassInfo *PassInf = PassList[i];
- Pass *P = 0;
+ Pass *P = nullptr;
if (PassInf->getTargetMachineCtor())
P = PassInf->getTargetMachineCtor()(TM.get());
else if (PassInf->getNormalCtor())
}
// Check that the module is well formed on completion of optimization
- if (!NoVerify && !VerifyEach)
+ if (!NoVerify && !VerifyEach) {
Passes.add(createVerifierPass());
+ Passes.add(createDebugInfoVerifierPass());
+ }
// Write bitcode or assembly to the output as the last step...
if (!NoOutput && !AnalyzeOnly) {