#include "llvm/CallGraphSCCPass.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Assembly/PrintModulePass.h"
+#include "llvm/Analysis/DebugInfo.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/RegionPass.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Support/PassNameParser.h"
-#include "llvm/System/Signals.h"
+#include "llvm/Support/Signals.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/IRReader.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/StandardPasses.h"
#include "llvm/Support/SystemUtils.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ToolOutputFile.h"
#include "llvm/LinkAllPasses.h"
#include "llvm/LinkAllVMCore.h"
#include <memory>
static cl::opt<bool>
AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
+static cl::opt<bool>
+PrintBreakpoints("print-breakpoints-for-testing",
+ cl::desc("Print select breakpoints location for testing"));
+
static cl::opt<std::string>
DefaultDataLayout("default-data-layout",
cl::desc("data layout string to use if not specified by module"),
}
virtual bool runOnSCC(CallGraphSCC &SCC) {
- if (!Quiet) {
+ if (!Quiet)
Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
- for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
- Function *F = (*I)->getFunction();
- if (F)
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
- F->getParent());
- }
- }
// Get and print pass...
+ for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
+ Function *F = (*I)->getFunction();
+ if (F)
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
+ F->getParent());
+ }
return false;
}
}
virtual bool runOnModule(Module &M) {
- if (!Quiet) {
+ if (!Quiet)
Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
- }
// Get and print pass...
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
return false;
}
}
virtual bool runOnFunction(Function &F) {
- if (!Quiet) {
+ if (!Quiet)
Out << "Printing analysis '" << PassToPrint->getPassName()
<< "' for function '" << F.getName() << "':\n";
- }
+
// Get and print pass...
getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
F.getParent());
virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
- if (!Quiet) {
+ if (!Quiet)
Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
- getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
- L->getHeader()->getParent()->getParent());
- }
+
// Get and print pass...
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
+ L->getHeader()->getParent()->getParent());
return false;
}
char LoopPassPrinter::ID = 0;
+struct RegionPassPrinter : public RegionPass {
+ static char ID;
+ const PassInfo *PassToPrint;
+ raw_ostream &Out;
+ std::string PassName;
+
+ RegionPassPrinter(const PassInfo *PI, raw_ostream &out) : RegionPass(ID),
+ PassToPrint(PI), Out(out) {
+ std::string PassToPrintName = PassToPrint->getPassName();
+ PassName = "LoopPass Printer: " + PassToPrintName;
+ }
+
+ virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
+ if (!Quiet) {
+ Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
+ << "region: '" << R->getNameStr() << "' in function '"
+ << R->getEntry()->getParent()->getNameStr() << "':\n";
+ }
+ // Get and print pass...
+ getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
+ R->getEntry()->getParent()->getParent());
+ return false;
+ }
+
+ virtual const char *getPassName() const { return "'Pass' Printer"; }
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequiredID(PassToPrint->getTypeInfo());
+ AU.setPreservesAll();
+ }
+};
+
+char RegionPassPrinter::ID = 0;
+
struct BasicBlockPassPrinter : public BasicBlockPass {
const PassInfo *PassToPrint;
raw_ostream &Out;
}
virtual bool runOnBasicBlock(BasicBlock &BB) {
- if (!Quiet) {
+ if (!Quiet)
Out << "Printing Analysis info for BasicBlock '" << BB.getName()
<< "': Pass " << PassToPrint->getPassName() << ":\n";
- }
// Get and print pass...
getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
};
char BasicBlockPassPrinter::ID = 0;
+
+struct BreakpointPrinter : public FunctionPass {
+ raw_ostream &Out;
+ static char ID;
+
+ BreakpointPrinter(raw_ostream &out)
+ : FunctionPass(ID), Out(out) {
+ }
+
+ virtual bool runOnFunction(Function &F) {
+ for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+ BasicBlock::const_iterator BI = I->end();
+ --BI;
+ do {
+ const Instruction *In = BI;
+ const DebugLoc DL = In->getDebugLoc();
+ if (!DL.isUnknown()) {
+ DIScope S(DL.getScope(getGlobalContext()));
+ Out << S.getFilename() << " " << DL.getLine() << "\n";
+ break;
+ }
+ --BI;
+ } while (BI != I->begin());
+ break;
+ }
+ BasicBlock &EntryBB = F.getEntryBlock();
+ for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+ BasicBlock *BB = I;
+ if (BB == &EntryBB) continue;
+ for (BasicBlock::iterator BI = I->begin(), BE = I->end(); BI != BE; ++BI)
+ if (CallInst *CI = dyn_cast<CallInst>(BI)) {
+ const DebugLoc DL = CI->getDebugLoc();
+ if (!DL.isUnknown()) {
+ DIScope S(DL.getScope(getGlobalContext()));
+ Out << S.getFilename() << " " << DL.getLine() << "\n";
+ }
+ }
+ }
+ return false;
+ }
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
+};
+
+char BreakpointPrinter::ID = 0;
+
inline void addPass(PassManagerBase &PM, Pass *P) {
// Add the pass to the pass manager...
PM.add(P);
if (DisableInline) {
// No inlining pass
} else if (OptLevel) {
- unsigned Threshold = 200;
+ unsigned Threshold = 225;
if (OptLevel > 2)
- Threshold = 250;
+ Threshold = 275;
InliningPass = createFunctionInliningPass(Threshold);
} else {
InliningPass = createAlwaysInlinerPass();
sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
- if (AnalyzeOnly && NoOutput) {
- errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
- return 1;
- }
-
// 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;
FPasses->add(new TargetData(*TD));
}
+ if (PrintBreakpoints) {
+ // Default to standard output.
+ if (!Out) {
+ 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;
+ }
+ }
+ Passes.add(new BreakpointPrinter(Out->os()));
+ NoOutput = true;
+ }
+
// If the -strip-debug command line option was specified, add it. If
// -std-compile-opts was also specified, it will handle StripDebug.
if (StripDebug && !StandardCompileOpts)
case PT_BasicBlock:
Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
break;
+ case PT_Region:
+ Passes.add(new RegionPassPrinter(PassInf, Out->os()));
+ break;
case PT_Loop:
Passes.add(new LoopPassPrinter(PassInf, Out->os()));
break;
Passes.run(*M.get());
// Declare success.
- if (!NoOutput)
+ if (!NoOutput || PrintBreakpoints)
Out->keep();
return 0;