Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 1 | //===- TraceValues.cpp - Value Tracing for debugging -------------*- C++ -*--=// |
| 2 | // |
| 3 | // Support for inserting LLVM code to print values at basic block and method |
| 4 | // exits. |
| 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 7 | |
| 8 | #include "llvm/Transforms/Instrumentation/TraceValues.h" |
| 9 | #include "llvm/GlobalVariable.h" |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 10 | #include "llvm/ConstantVals.h" |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 11 | #include "llvm/DerivedTypes.h" |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 12 | #include "llvm/iMemory.h" |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 13 | #include "llvm/iTerminators.h" |
| 14 | #include "llvm/iOther.h" |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 15 | #include "llvm/Method.h" |
| 16 | #include "llvm/Module.h" |
| 17 | #include "llvm/SymbolTable.h" |
Chris Lattner | bd0ef77 | 2002-02-26 21:46:54 +0000 | [diff] [blame] | 18 | #include "llvm/Pass.h" |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 19 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | cee8f9a | 2001-11-27 00:03:19 +0000 | [diff] [blame] | 20 | #include "Support/StringExtras.h" |
Chris Lattner | b81a0bf | 2001-10-18 20:06:03 +0000 | [diff] [blame] | 21 | #include <sstream> |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 22 | using std::vector; |
| 23 | using std::string; |
Vikram S. Adve | d889330 | 2001-10-28 21:37:25 +0000 | [diff] [blame] | 24 | |
Chris Lattner | bd0ef77 | 2002-02-26 21:46:54 +0000 | [diff] [blame] | 25 | namespace { |
| 26 | class InsertTraceCode : public MethodPass { |
| 27 | bool TraceBasicBlockExits, TraceMethodExits; |
| 28 | Method *PrintfMeth; |
| 29 | public: |
| 30 | InsertTraceCode(bool traceBasicBlockExits, bool traceMethodExits) |
| 31 | : TraceBasicBlockExits(traceBasicBlockExits), |
| 32 | TraceMethodExits(traceMethodExits) {} |
| 33 | |
| 34 | // Add a prototype for printf if it is not already in the program. |
| 35 | // |
| 36 | bool doInitialization(Module *M); |
| 37 | |
| 38 | //-------------------------------------------------------------------------- |
| 39 | // Function InsertCodeToTraceValues |
| 40 | // |
| 41 | // Inserts tracing code for all live values at basic block and/or method |
| 42 | // exits as specified by `traceBasicBlockExits' and `traceMethodExits'. |
| 43 | // |
| 44 | static bool doit(Method *M, bool traceBasicBlockExits, |
| 45 | bool traceMethodExits, Method *Printf); |
| 46 | |
| 47 | // runOnMethod - This method does the work. Always successful. |
| 48 | // |
| 49 | bool runOnMethod(Method *M) { |
| 50 | return doit(M, TraceBasicBlockExits, TraceMethodExits, PrintfMeth); |
| 51 | } |
| 52 | }; |
| 53 | } // end anonymous namespace |
| 54 | |
| 55 | |
| 56 | Pass *createTraceValuesPassForMethod() { // Just trace methods |
| 57 | return new InsertTraceCode(false, true); |
| 58 | } |
| 59 | |
| 60 | Pass *createTraceValuesPassForBasicBlocks() { // Trace BB's and methods |
| 61 | return new InsertTraceCode(true, true); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 67 | // Add a prototype for printf if it is not already in the program. |
| 68 | // |
Chris Lattner | f4de63f | 2002-01-21 07:31:50 +0000 | [diff] [blame] | 69 | bool InsertTraceCode::doInitialization(Module *M) { |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 70 | SymbolTable *ST = M->getSymbolTable(); |
| 71 | const Type *SBP = PointerType::get(Type::SByteTy); |
| 72 | const MethodType *MTy = |
| 73 | MethodType::get(Type::IntTy, vector<const Type*>(1, SBP), true); |
Vikram S. Adve | d889330 | 2001-10-28 21:37:25 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 75 | if (Value *Meth = ST->lookup(PointerType::get(MTy), "printf")) { |
| 76 | PrintfMeth = cast<Method>(Meth); |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | // Create a new method and add it to the module |
| 81 | PrintfMeth = new Method(MTy, false, "printf"); |
| 82 | M->getMethodList().push_back(PrintfMeth); |
| 83 | return true; |
Vikram S. Adve | d889330 | 2001-10-28 21:37:25 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 86 | |
| 87 | static inline GlobalVariable *getStringRef(Module *M, const string &str) { |
| 88 | // Create a constant internal string reference... |
| 89 | Constant *Init = ConstantArray::get(str); |
Vikram S. Adve | 524185a | 2002-03-18 03:40:25 +0000 | [diff] [blame] | 90 | |
| 91 | // Create the global variable and record it in the module |
| 92 | // The GV will be renamed to a unique name if needed. |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 93 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, true, Init, |
| 94 | "trstr"); |
Chris Lattner | b81a0bf | 2001-10-18 20:06:03 +0000 | [diff] [blame] | 95 | M->getGlobalList().push_back(GV); |
| 96 | return GV; |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Vikram S. Adve | bedb00d | 2001-10-18 13:49:22 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 100 | // |
| 101 | // Check if this instruction has any uses outside its basic block, |
| 102 | // or if it used by either a Call or Return instruction. |
| 103 | // |
| 104 | static inline bool LiveAtBBExit(const Instruction* I) { |
| 105 | const BasicBlock *BB = I->getParent(); |
| 106 | for (Value::use_const_iterator U = I->use_begin(); U != I->use_end(); ++U) |
| 107 | if (const Instruction *UI = dyn_cast<Instruction>(*U)) |
| 108 | if (UI->getParent() != BB || isa<ReturnInst>(UI)) |
| 109 | return true; |
| 110 | |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | static inline bool TraceThisOpCode(unsigned opCode) { |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 116 | // Explicitly test for opCodes *not* to trace so that any new opcodes will |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 117 | // be traced by default (VoidTy's are already excluded) |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 118 | // |
| 119 | return (opCode < Instruction::FirstOtherOp && |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 120 | opCode != Instruction::Alloca && |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 121 | opCode != Instruction::PHINode && |
| 122 | opCode != Instruction::Cast); |
| 123 | } |
| 124 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 125 | |
| 126 | static bool ShouldTraceValue(const Instruction *I) { |
| 127 | return |
| 128 | I->getType() != Type::VoidTy && LiveAtBBExit(I) && |
| 129 | TraceThisOpCode(I->getOpcode()); |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 132 | static string getPrintfCodeFor(const Value *V) { |
| 133 | if (V == 0) return ""; |
| 134 | switch (V->getType()->getPrimitiveID()) { |
| 135 | case Type::BoolTyID: |
| 136 | case Type::UByteTyID: case Type::UShortTyID: |
| 137 | case Type::UIntTyID: case Type::ULongTyID: |
| 138 | case Type::SByteTyID: case Type::ShortTyID: |
| 139 | case Type::IntTyID: case Type::LongTyID: |
| 140 | return "%d"; |
Chris Lattner | b81a0bf | 2001-10-18 20:06:03 +0000 | [diff] [blame] | 141 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 142 | case Type::FloatTyID: case Type::DoubleTyID: |
| 143 | return "%g"; |
Chris Lattner | b81a0bf | 2001-10-18 20:06:03 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 145 | case Type::LabelTyID: case Type::PointerTyID: |
| 146 | return "%p"; |
Vikram S. Adve | bedb00d | 2001-10-18 13:49:22 +0000 | [diff] [blame] | 147 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 148 | default: |
| 149 | assert(0 && "Illegal value to print out..."); |
| 150 | return ""; |
| 151 | } |
Vikram S. Adve | bedb00d | 2001-10-18 13:49:22 +0000 | [diff] [blame] | 152 | } |
Vikram S. Adve | bedb00d | 2001-10-18 13:49:22 +0000 | [diff] [blame] | 153 | |
| 154 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 155 | static void InsertPrintInst(Value *V, BasicBlock *BB, BasicBlock::iterator &BBI, |
| 156 | string Message, Method *Printf) { |
| 157 | // Escape Message by replacing all % characters with %% chars. |
| 158 | unsigned Offset = 0; |
| 159 | while ((Offset = Message.find('%', Offset)) != string::npos) { |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 160 | Message.replace(Offset, 2, "%%"); |
| 161 | Offset += 2; // Skip over the new %'s |
| 162 | } |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 163 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 164 | Module *Mod = BB->getParent()->getParent(); |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 165 | |
Chris Lattner | 4457163 | 2001-10-18 06:03:05 +0000 | [diff] [blame] | 166 | // Turn the marker string into a global variable... |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 167 | GlobalVariable *fmtVal = getStringRef(Mod, Message+getPrintfCodeFor(V)+"\n"); |
| 168 | |
| 169 | // Turn the format string into an sbyte * |
| 170 | Instruction *GEP = |
| 171 | new GetElementPtrInst(fmtVal, |
| 172 | vector<Value*>(2,ConstantUInt::get(Type::UIntTy, 0)), |
| 173 | "trstr"); |
| 174 | BBI = BB->getInstList().insert(BBI, GEP)+1; |
Chris Lattner | 4457163 | 2001-10-18 06:03:05 +0000 | [diff] [blame] | 175 | |
| 176 | // Insert the first print instruction to print the string flag: |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 177 | vector<Value*> PrintArgs; |
| 178 | PrintArgs.push_back(GEP); |
| 179 | if (V) PrintArgs.push_back(V); |
| 180 | Instruction *I = new CallInst(Printf, PrintArgs, "trace"); |
Chris Lattner | 4457163 | 2001-10-18 06:03:05 +0000 | [diff] [blame] | 181 | BBI = BB->getInstList().insert(BBI, I)+1; |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Chris Lattner | 4457163 | 2001-10-18 06:03:05 +0000 | [diff] [blame] | 184 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 185 | static void InsertVerbosePrintInst(Value *V, BasicBlock *BB, |
| 186 | BasicBlock::iterator &BBI, |
| 187 | const string &Message, Method *Printf) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 188 | std::ostringstream OutStr; |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 189 | if (V) WriteAsOperand(OutStr, V); |
| 190 | InsertPrintInst(V, BB, BBI, Message+OutStr.str()+" = ", Printf); |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 194 | // Insert print instructions at the end of the basic block *bb |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 195 | // for each value in valueVec[] that is live at the end of that basic block, |
| 196 | // or that is stored to memory in this basic block. |
| 197 | // If the value is stored to memory, we load it back before printing |
| 198 | // We also return all such loaded values in the vector valuesStoredInMethod |
| 199 | // for printing at the exit from the method. (Note that in each invocation |
| 200 | // of the method, this will only get the last value stored for each static |
| 201 | // store instruction). |
| 202 | // *bb must be the block in which the value is computed; |
| 203 | // this is not checked here. |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 204 | // |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 205 | static void TraceValuesAtBBExit(BasicBlock *BB, Method *Printf, |
| 206 | vector<Instruction*> *valuesStoredInMethod) { |
Vikram S. Adve | d889330 | 2001-10-28 21:37:25 +0000 | [diff] [blame] | 207 | // Get an iterator to point to the insertion location, which is |
| 208 | // just before the terminator instruction. |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 209 | // |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 210 | BasicBlock::iterator InsertPos = BB->end()-1; |
| 211 | assert((*InsertPos)->isTerminator()); |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 212 | |
Vikram S. Adve | d889330 | 2001-10-28 21:37:25 +0000 | [diff] [blame] | 213 | // If the terminator is a conditional branch, insert the trace code just |
| 214 | // before the instruction that computes the branch condition (just to |
| 215 | // avoid putting a call between the CC-setting instruction and the branch). |
| 216 | // Use laterInstrSet to mark instructions that come after the setCC instr |
| 217 | // because those cannot be traced at the location we choose. |
| 218 | // |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 219 | Instruction *SetCC = 0; |
| 220 | if (BranchInst *Branch = dyn_cast<BranchInst>(BB->getTerminator())) |
| 221 | if (!Branch->isUnconditional()) |
| 222 | if (Instruction *I = dyn_cast<Instruction>(Branch->getCondition())) |
| 223 | if (I->getParent() == BB) { |
| 224 | SetCC = I; |
| 225 | while (*InsertPos != SetCC) |
| 226 | --InsertPos; // Back up until we can insert before the setcc |
| 227 | } |
| 228 | |
| 229 | // Copy all of the instructions into a vector to avoid problems with Setcc |
| 230 | const vector<Instruction*> Insts(BB->begin(), InsertPos); |
| 231 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 232 | std::ostringstream OutStr; |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 233 | WriteAsOperand(OutStr, BB, false); |
| 234 | InsertPrintInst(0, BB, InsertPos, "LEAVING BB:" + OutStr.str(), Printf); |
| 235 | |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 236 | // Insert a print instruction for each value. |
| 237 | // |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 238 | for (vector<Instruction*>::const_iterator II = Insts.begin(), |
| 239 | IE = Insts.end(); II != IE; ++II) { |
| 240 | Instruction *I = *II; |
| 241 | if (StoreInst *SI = dyn_cast<StoreInst>(I)) { |
| 242 | assert(valuesStoredInMethod && |
| 243 | "Should not be printing a store instruction at method exit"); |
| 244 | LoadInst *LI = new LoadInst(SI->getPointerOperand(), SI->copyIndices(), |
| 245 | "reload"); |
| 246 | InsertPos = BB->getInstList().insert(InsertPos, LI) + 1; |
| 247 | valuesStoredInMethod->push_back(LI); |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 248 | } |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 249 | if (ShouldTraceValue(I)) |
| 250 | InsertVerbosePrintInst(I, BB, InsertPos, " ", Printf); |
| 251 | } |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 254 | static inline void InsertCodeToShowMethodEntry(Method *M, Method *Printf) { |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 255 | // Get an iterator to point to the insertion location |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 256 | BasicBlock *BB = M->getEntryNode(); |
| 257 | BasicBlock::iterator BBI = BB->begin(); |
| 258 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 259 | std::ostringstream OutStr; |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 260 | WriteAsOperand(OutStr, M, true); |
| 261 | InsertPrintInst(0, BB, BBI, "ENTERING METHOD: " + OutStr.str(), Printf); |
| 262 | |
Vikram S. Adve | 2ed5ccd | 2001-11-15 15:00:16 +0000 | [diff] [blame] | 263 | // Now print all the incoming arguments |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 264 | const Method::ArgumentListType &argList = M->getArgumentList(); |
| 265 | unsigned ArgNo = 0; |
Vikram S. Adve | 2ed5ccd | 2001-11-15 15:00:16 +0000 | [diff] [blame] | 266 | for (Method::ArgumentListType::const_iterator |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 267 | I = argList.begin(), E = argList.end(); I != E; ++I, ++ArgNo) { |
| 268 | InsertVerbosePrintInst(*I, BB, BBI, |
| 269 | " Arg #" + utostr(ArgNo), Printf); |
| 270 | } |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 274 | static inline void InsertCodeToShowMethodExit(BasicBlock *BB, Method *Printf) { |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 275 | // Get an iterator to point to the insertion location |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 276 | BasicBlock::iterator BBI = BB->end()-1; |
| 277 | ReturnInst *Ret = cast<ReturnInst>(*BBI); |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 278 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 279 | std::ostringstream OutStr; |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 280 | WriteAsOperand(OutStr, BB->getParent(), true); |
| 281 | InsertPrintInst(0, BB, BBI, "LEAVING METHOD: " + OutStr.str(), Printf); |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 282 | |
Vikram S. Adve | 2ed5ccd | 2001-11-15 15:00:16 +0000 | [diff] [blame] | 283 | // print the return value, if any |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 284 | if (BB->getParent()->getReturnType() != Type::VoidTy) |
| 285 | InsertPrintInst(Ret->getReturnValue(), BB, BBI, " Returning: ", Printf); |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 289 | bool InsertTraceCode::doit(Method *M, bool traceBasicBlockExits, |
| 290 | bool traceMethodEvents, Method *Printf) { |
Chris Lattner | fcc93d2 | 2002-01-31 00:51:24 +0000 | [diff] [blame] | 291 | if (!traceBasicBlockExits && !traceMethodEvents) |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 292 | return false; |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 293 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 294 | vector<Instruction*> valuesStoredInMethod; |
| 295 | vector<BasicBlock*> exitBlocks; |
| 296 | |
Chris Lattner | 29c1473 | 2001-12-14 16:26:05 +0000 | [diff] [blame] | 297 | if (traceMethodEvents) |
| 298 | InsertCodeToShowMethodEntry(M, Printf); |
| 299 | |
| 300 | for (Method::iterator BI = M->begin(); BI != M->end(); ++BI) { |
| 301 | BasicBlock *BB = *BI; |
| 302 | if (isa<ReturnInst>(BB->getTerminator())) |
| 303 | exitBlocks.push_back(BB); // record this as an exit block |
| 304 | |
| 305 | if (traceBasicBlockExits) |
| 306 | TraceValuesAtBBExit(BB, Printf, &valuesStoredInMethod); |
| 307 | } |
| 308 | |
| 309 | if (traceMethodEvents) |
| 310 | for (unsigned i=0; i < exitBlocks.size(); ++i) { |
| 311 | #if 0 |
| 312 | TraceValuesAtBBExit(valuesStoredInMethod, exitBlocks[i], module, |
| 313 | /*indent*/ 0, /*isMethodExit*/ true, |
| 314 | /*valuesStoredInMethod*/ NULL); |
| 315 | #endif |
| 316 | InsertCodeToShowMethodExit(exitBlocks[i], Printf); |
| 317 | } |
Vikram S. Adve | 631b9a3 | 2001-10-18 18:16:11 +0000 | [diff] [blame] | 318 | |
Chris Lattner | 8d9e377 | 2001-10-18 05:28:08 +0000 | [diff] [blame] | 319 | return true; |
Vikram S. Adve | df1892f | 2001-10-14 23:18:45 +0000 | [diff] [blame] | 320 | } |