Rename include/llvm/Transforms/Instrumentation/TraceFunctions.h to Instrumentation.h
[oota-llvm.git] / lib / Transforms / Instrumentation / TraceValues.cpp
index f3fc7ba32271abbb8fe582524be0980447389b05..8c44d4d28ca88df6ee5567bc17b1f02b927fdbbc 100644 (file)
@@ -5,7 +5,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Transforms/Instrumentation/TraceValues.h"
+#include "llvm/Transforms/Instrumentation.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/iMemory.h"
@@ -26,8 +26,8 @@ DisablePtrHashing("tracedisablehashdisable", cl::Hidden,
                   cl::desc("Disable pointer hashing"));
 
 static cl::list<string>
-TraceFuncName("tracefunc", cl::desc("trace only specific functions"),
-              cl::value_desc("function"), cl::Hidden);
+TraceFuncNames("tracefunc", cl::desc("trace only specific functions"),
+              cl::value_desc("function"), cl::Hidden);
 
 static void TraceValuesAtBBExit(BasicBlock *BB,
                                 Function *Printf, Function* HashPtrToSeqNum,
@@ -37,13 +37,12 @@ static void TraceValuesAtBBExit(BasicBlock *BB,
 // or if the function is in the specified list.
 // 
 inline static bool
-TraceThisFunction(Function &func)
+TraceThisFunction(Function &F)
 {
-  if (TraceFuncName.size() == 0)
-    return true;
+  if (TraceFuncNames.empty()) return true;
 
-  return std::find(TraceFuncName.begin(), TraceFuncName.end(), func.getName())
-                  != TraceFuncName.end();
+  return std::find(TraceFuncNames.begin(), TraceFuncNames.end(), F.getName())
+                  != TraceFuncNames.end();
 }
 
 
@@ -78,7 +77,7 @@ namespace {
     bool runOnFunction(Function &F);
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.preservesCFG();
+      AU.setPreservesCFG();
     }
   };
 
@@ -179,7 +178,7 @@ static inline bool TraceThisOpCode(unsigned opCode) {
   // Explicitly test for opCodes *not* to trace so that any new opcodes will
   // be traced by default (VoidTy's are already excluded)
   // 
-  return (opCode  < Instruction::FirstOtherOp &&
+  return (opCode  < Instruction::OtherOpsBegin &&
           opCode != Instruction::Alloca &&
           opCode != Instruction::PHINode &&
           opCode != Instruction::Cast);
@@ -212,12 +211,17 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore,
                             string Message,
                             Function *Printf, Function* HashPtrToSeqNum) {
   // Escape Message by replacing all % characters with %% chars.
-  unsigned Offset = 0;
-  while ((Offset = Message.find('%', Offset)) != string::npos) {
-    Message.replace(Offset, 1, "%%");
-    Offset += 2;  // Skip over the new %'s
+  string Tmp;
+  std::swap(Tmp, Message);
+  string::iterator I = std::find(Tmp.begin(), Tmp.end(), '%');
+  while (I != Tmp.end()) {
+    Message.append(Tmp.begin(), I);
+    Message += "%%";
+    ++I; // Make sure to erase the % as well...
+    Tmp.erase(Tmp.begin(), I);
+    I = std::find(Tmp.begin(), Tmp.end(), '%');
   }
-
+  Message += Tmp;
   Module *Mod = BB->getParent()->getParent();
 
   // Turn the marker string into a global variable...
@@ -226,8 +230,8 @@ static void InsertPrintInst(Value *V, BasicBlock *BB, Instruction *InsertBefore,
   // Turn the format string into an sbyte *
   Instruction *GEP = 
     new GetElementPtrInst(fmtVal,
-                          vector<Value*>(2,ConstantUInt::get(Type::UIntTy, 0)),
-                          "trstr", InsertBefore);
+                          vector<Value*>(2,ConstantSInt::get(Type::LongTy, 0)),
+                          "trstrp", InsertBefore);
   
   // Insert a call to the hash function if this is a pointer value
   if (V && isa<PointerType>(V->getType()) && !DisablePtrHashing) {
@@ -345,7 +349,7 @@ static inline void InsertCodeToShowFunctionEntry(Function &F, Function *Printf,
   Instruction *InsertPos = BB.begin();
 
   std::ostringstream OutStr;
-  WriteAsOperand(OutStr, &F, true);
+  WriteAsOperand(OutStr, &F);
   InsertPrintInst(0, &BB, InsertPos, "ENTERING FUNCTION: " + OutStr.str(),
                   Printf, HashPtrToSeqNum);