aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation/TraceValues.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Instrumentation/TraceValues.cpp')
-rw-r--r--lib/Transforms/Instrumentation/TraceValues.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp
index aad63c848f..6e4fedcfa8 100644
--- a/lib/Transforms/Instrumentation/TraceValues.cpp
+++ b/lib/Transforms/Instrumentation/TraceValues.cpp
@@ -15,12 +15,55 @@
#include "llvm/Method.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
+#include "llvm/Pass.h"
#include "llvm/Assembly/Writer.h"
#include "Support/StringExtras.h"
#include <sstream>
using std::vector;
using std::string;
+namespace {
+ class InsertTraceCode : public MethodPass {
+ bool TraceBasicBlockExits, TraceMethodExits;
+ Method *PrintfMeth;
+ public:
+ InsertTraceCode(bool traceBasicBlockExits, bool traceMethodExits)
+ : TraceBasicBlockExits(traceBasicBlockExits),
+ TraceMethodExits(traceMethodExits) {}
+
+ // Add a prototype for printf if it is not already in the program.
+ //
+ bool doInitialization(Module *M);
+
+ //--------------------------------------------------------------------------
+ // Function InsertCodeToTraceValues
+ //
+ // Inserts tracing code for all live values at basic block and/or method
+ // exits as specified by `traceBasicBlockExits' and `traceMethodExits'.
+ //
+ static bool doit(Method *M, bool traceBasicBlockExits,
+ bool traceMethodExits, Method *Printf);
+
+ // runOnMethod - This method does the work. Always successful.
+ //
+ bool runOnMethod(Method *M) {
+ return doit(M, TraceBasicBlockExits, TraceMethodExits, PrintfMeth);
+ }
+ };
+} // end anonymous namespace
+
+
+Pass *createTraceValuesPassForMethod() { // Just trace methods
+ return new InsertTraceCode(false, true);
+}
+
+Pass *createTraceValuesPassForBasicBlocks() { // Trace BB's and methods
+ return new InsertTraceCode(true, true);
+}
+
+
+
+
// Add a prototype for printf if it is not already in the program.
//
bool InsertTraceCode::doInitialization(Module *M) {