[llvm-commits] [llvm] r121078 - /llvm/trunk/tools/opt/opt.cpp
Devang Patel
dpatel at apple.com
Mon Dec 6 16:33:43 PST 2010
Author: dpatel
Date: Mon Dec 6 18:33:43 2010
New Revision: 121078
URL: http://llvm.org/viewvc/llvm-project?rev=121078&view=rev
Log:
Add a simple breakpoint location printer. This will be used by upcoming "debug info in optimized code" quality test harness to set breakpoints at "interesting" locations.
Modified:
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=121078&r1=121077&r2=121078&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Mon Dec 6 18:33:43 2010
@@ -18,6 +18,7 @@
#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"
@@ -128,6 +129,10 @@
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"),
@@ -334,6 +339,41 @@
};
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;
+ }
+ 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);
@@ -509,6 +549,24 @@
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)
@@ -623,7 +681,7 @@
Passes.run(*M.get());
// Declare success.
- if (!NoOutput)
+ if (!NoOutput || PrintBreakpoints)
Out->keep();
return 0;
More information about the llvm-commits
mailing list