Thread LLVMContext through the constant folding APIs, which touches a lot of files.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74844 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index b110f4e..5f95f29 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -33,6 +33,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Pass.h"
+#include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
 #include "llvm/Constants.h"
@@ -195,7 +196,7 @@
   
 GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t,
                                          uint64_t resetval) : T(t) {
-  ConstantInt* Init = ConstantInt::get(T, resetval); 
+  ConstantInt* Init = M.getContext().getConstantInt(T, resetval); 
   ResetValue = Init;
   Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
                                Init, "RandomSteeringCounter", &M);
@@ -207,14 +208,16 @@
 
 void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
   BranchInst* t = cast<BranchInst>(bb->getTerminator());
+  LLVMContext* Context = bb->getContext();
   
   //decrement counter
   LoadInst* l = new LoadInst(Counter, "counter", t);
   
-  ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, ConstantInt::get(T, 0), 
+  ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
+                             Context->getConstantInt(T, 0), 
                              "countercc", t);
 
-  Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1),
+  Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
                                         "counternew", t);
   new StoreInst(nv, Counter, t);
   t->setCondition(s);
@@ -232,7 +235,7 @@
 GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t,
                                                uint64_t resetval) 
   : AI(0), T(t) {
-  ConstantInt* Init = ConstantInt::get(T, resetval);
+  ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
   ResetValue  = Init;
   Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
                                Init, "RandomSteeringCounter", &M);
@@ -279,14 +282,16 @@
 
 void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) {
   BranchInst* t = cast<BranchInst>(bb->getTerminator());
+  LLVMContext* Context = bb->getContext();
   
   //decrement counter
   LoadInst* l = new LoadInst(AI, "counter", t);
   
-  ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l, ConstantInt::get(T, 0), 
+  ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
+                             Context->getConstantInt(T, 0), 
                              "countercc", t);
 
-  Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1),
+  Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
                                         "counternew", t);
   new StoreInst(nv, AI, t);
   t->setCondition(s);
@@ -312,14 +317,15 @@
 
 void CycleCounter::ProcessChoicePoint(BasicBlock* bb) {
   BranchInst* t = cast<BranchInst>(bb->getTerminator());
+  LLVMContext* Context = bb->getContext();
   
   CallInst* c = CallInst::Create(F, "rdcc", t);
   BinaryOperator* b = 
-    BinaryOperator::CreateAnd(c, ConstantInt::get(Type::Int64Ty, rm),
+    BinaryOperator::CreateAnd(c, Context->getConstantInt(Type::Int64Ty, rm),
                               "mrdcc", t);
   
   ICmpInst *s = new ICmpInst(ICmpInst::ICMP_EQ, b,
-                             ConstantInt::get(Type::Int64Ty, 0), 
+                             Context->getConstantInt(Type::Int64Ty, 0), 
                              "mrdccc", t);
 
   t->setCondition(s);
@@ -345,16 +351,16 @@
   
   // Create the getelementptr constant expression
   std::vector<Constant*> Indices(2);
-  Indices[0] = Constant::getNullValue(Type::Int32Ty);
-  Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
-  Constant *ElementPtr = ConstantExpr::getGetElementPtr(CounterArray,
+  Indices[0] = Context->getNullValue(Type::Int32Ty);
+  Indices[1] = Context->getConstantInt(Type::Int32Ty, CounterNum);
+  Constant *ElementPtr = Context->getConstantExprGetElementPtr(CounterArray,
                                                         &Indices[0], 2);
   
   // Load, increment and store the value back.
   Value *OldVal = new LoadInst(ElementPtr, "OldCounter", InsertPos);
   profcode.insert(OldVal);
   Value *NewVal = BinaryOperator::CreateAdd(OldVal,
-                                            ConstantInt::get(Type::Int32Ty, 1),
+                                     Context->getConstantInt(Type::Int32Ty, 1),
                                             "NewCounter", InsertPos);
   profcode.insert(NewVal);
   profcode.insert(new StoreInst(NewVal, ElementPtr, InsertPos));
@@ -475,7 +481,7 @@
   //b:
   BranchInst::Create(cast<BasicBlock>(Translate(dst)), bbC);
   BranchInst::Create(dst, cast<BasicBlock>(Translate(dst)), 
-                     ConstantInt::get(Type::Int1Ty, true), bbCp);
+                     Context->getConstantInt(Type::Int1Ty, true), bbCp);
   //c:
   {
     TerminatorInst* iB = src->getTerminator();
@@ -532,7 +538,7 @@
     ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0),
                                               cast<BasicBlock>(
                                                 Translate(T->getSuccessor(0))),
-                                              ConstantInt::get(Type::Int1Ty,
+                                          Context->getConstantInt(Type::Int1Ty,
                                                                true)));
     
     //do whatever is needed now that the function is duplicated