Get rid of the Pass+Context magic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76702 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/DwarfEHPrepare.cpp b/lib/CodeGen/DwarfEHPrepare.cpp
index 3691ba0..43760af 100644
--- a/lib/CodeGen/DwarfEHPrepare.cpp
+++ b/lib/CodeGen/DwarfEHPrepare.cpp
@@ -314,7 +314,7 @@
   if (ExceptionValueVar && DT && DF && isAllocaPromotable(ExceptionValueVar)) {
     // Turn the exception temporary into registers and phi nodes if possible.
     std::vector<AllocaInst*> Allocas(1, ExceptionValueVar);
-    PromoteMemToReg(Allocas, *DT, *DF, Context);
+    PromoteMemToReg(Allocas, *DT, *DF, ExceptionValueVar->getContext());
     return true;
   }
   return false;
@@ -355,7 +355,7 @@
   // Create the temporary if we didn't already.
   if (!ExceptionValueVar) {
     ExceptionValueVar = new AllocaInst(
-                                    Context->getPointerTypeUnqual(Type::Int8Ty),
+                           BB->getContext().getPointerTypeUnqual(Type::Int8Ty),
                                        "eh.value", F->begin()->begin());
     ++NumStackTempsIntroduced;
   }
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index 455adc4..34cbf2f 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -320,7 +320,7 @@
 
 void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
   IRBuilder<> Builder(CI->getParent(), CI);
-  LLVMContext *Context = CI->getParent()->getContext();
+  LLVMContext &Context = CI->getContext();
 
   Function *Callee = CI->getCalledFunction();
   assert(Callee && "Cannot lower an indirect call!");
@@ -346,7 +346,7 @@
   }
   case Intrinsic::sigsetjmp:
      if (CI->getType() != Type::VoidTy)
-       CI->replaceAllUsesWith(Context->getNullValue(CI->getType()));
+       CI->replaceAllUsesWith(Context.getNullValue(CI->getType()));
      break;
 
   case Intrinsic::longjmp: {
@@ -362,15 +362,15 @@
     break;
   }
   case Intrinsic::ctpop:
-    CI->replaceAllUsesWith(LowerCTPOP(*Context, CI->getOperand(1), CI));
+    CI->replaceAllUsesWith(LowerCTPOP(Context, CI->getOperand(1), CI));
     break;
 
   case Intrinsic::bswap:
-    CI->replaceAllUsesWith(LowerBSWAP(*Context, CI->getOperand(1), CI));
+    CI->replaceAllUsesWith(LowerBSWAP(Context, CI->getOperand(1), CI));
     break;
     
   case Intrinsic::ctlz:
-    CI->replaceAllUsesWith(LowerCTLZ(*Context, CI->getOperand(1), CI));
+    CI->replaceAllUsesWith(LowerCTLZ(Context, CI->getOperand(1), CI));
     break;
 
   case Intrinsic::cttz: {
@@ -378,9 +378,9 @@
     Value *Src = CI->getOperand(1);
     Value *NotSrc = Builder.CreateNot(Src);
     NotSrc->setName(Src->getName() + ".not");
-    Value *SrcM1 = Context->getConstantInt(Src->getType(), 1);
+    Value *SrcM1 = Context.getConstantInt(Src->getType(), 1);
     SrcM1 = Builder.CreateSub(Src, SrcM1);
-    Src = LowerCTPOP(*Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
+    Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
     CI->replaceAllUsesWith(Src);
     break;
   }
@@ -393,7 +393,7 @@
                "save" : "restore") << " intrinsic.\n";
     Warned = true;
     if (Callee->getIntrinsicID() == Intrinsic::stacksave)
-      CI->replaceAllUsesWith(Context->getNullValue(CI->getType()));
+      CI->replaceAllUsesWith(Context.getNullValue(CI->getType()));
     break;
   }
     
@@ -414,7 +414,7 @@
   case Intrinsic::readcyclecounter: {
     cerr << "WARNING: this target does not support the llvm.readcyclecoun"
          << "ter intrinsic.  It is being lowered to a constant 0\n";
-    CI->replaceAllUsesWith(Context->getConstantInt(Type::Int64Ty, 0));
+    CI->replaceAllUsesWith(Context.getConstantInt(Type::Int64Ty, 0));
     break;
   }
 
@@ -428,13 +428,13 @@
   case Intrinsic::eh_exception:
   case Intrinsic::eh_selector_i32:
   case Intrinsic::eh_selector_i64:
-    CI->replaceAllUsesWith(Context->getNullValue(CI->getType()));
+    CI->replaceAllUsesWith(Context.getNullValue(CI->getType()));
     break;
 
   case Intrinsic::eh_typeid_for_i32:
   case Intrinsic::eh_typeid_for_i64:
     // Return something different to eh_selector.
-    CI->replaceAllUsesWith(Context->getConstantInt(CI->getType(), 1));
+    CI->replaceAllUsesWith(Context.getConstantInt(CI->getType(), 1));
     break;
 
   case Intrinsic::var_annotation:
@@ -506,7 +506,7 @@
   case Intrinsic::flt_rounds:
      // Lower to "round to the nearest"
      if (CI->getType() != Type::VoidTy)
-       CI->replaceAllUsesWith(Context->getConstantInt(CI->getType(), 1));
+       CI->replaceAllUsesWith(Context.getConstantInt(CI->getType(), 1));
      break;
   }
 
diff --git a/lib/CodeGen/SelectionDAG/CallingConvLower.cpp b/lib/CodeGen/SelectionDAG/CallingConvLower.cpp
index 2f4db28..e43af82 100644
--- a/lib/CodeGen/SelectionDAG/CallingConvLower.cpp
+++ b/lib/CodeGen/SelectionDAG/CallingConvLower.cpp
@@ -21,7 +21,7 @@
 using namespace llvm;
 
 CCState::CCState(unsigned CC, bool isVarArg, const TargetMachine &tm,
-                 SmallVector<CCValAssign, 16> &locs, LLVMContext *C)
+                 SmallVector<CCValAssign, 16> &locs, LLVMContext &C)
   : CallingConv(CC), IsVarArg(isVarArg), TM(tm),
     TRI(*TM.getRegisterInfo()), Locs(locs), Context(C) {
   // No stack is used.
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index d523e7f..547a7bf 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -92,7 +92,7 @@
   } else if (isa<ConstantPointerNull>(V)) {
     // Translate this as an integer zero so that it can be
     // local-CSE'd with actual integer zeros.
-    Reg = getRegForValue(Context->getNullValue(TD.getIntPtrType()));
+    Reg = getRegForValue(V->getContext().getNullValue(TD.getIntPtrType()));
   } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
     Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
 
@@ -108,7 +108,8 @@
       if (isExact) {
         APInt IntVal(IntBitWidth, 2, x);
 
-        unsigned IntegerReg = getRegForValue(Context->getConstantInt(IntVal));
+        unsigned IntegerReg =
+          getRegForValue(V->getContext().getConstantInt(IntVal));
         if (IntegerReg != 0)
           Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
       }
@@ -480,7 +481,7 @@
         UpdateValueMap(I, ResultReg);
       } else {
         unsigned ResultReg =
-          getRegForValue(Context->getNullValue(I->getType()));
+          getRegForValue(I->getContext().getNullValue(I->getType()));
         UpdateValueMap(I, ResultReg);
       }
       return true;
@@ -753,8 +754,7 @@
     TM(MF.getTarget()),
     TD(*TM.getTargetData()),
     TII(*TM.getInstrInfo()),
-    TLI(*TM.getTargetLowering()),
-    Context(mf.getFunction()->getContext()) {
+    TLI(*TM.getTargetLowering()) {
 }
 
 FastISel::~FastISel() {}
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 87ca13e..c2595bc 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -816,7 +816,7 @@
   MF = &mf;
   MMI = mmi;
   DW = dw;
-  Context = mf.getFunction()->getContext();  
+  Context = &mf.getFunction()->getContext();  
 }
 
 SelectionDAG::~SelectionDAG() {
diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp
index 77ec9c6..fe843f7 100644
--- a/lib/CodeGen/ShadowStackGC.cpp
+++ b/lib/CodeGen/ShadowStackGC.cpp
@@ -62,10 +62,10 @@
     Constant *GetFrameMap(Function &F);
     const Type* GetConcreteStackEntryType(Function &F);
     void CollectRoots(Function &F);
-    static GetElementPtrInst *CreateGEP(LLVMContext *Context, 
+    static GetElementPtrInst *CreateGEP(LLVMContext &Context, 
                                         IRBuilder<> &B, Value *BasePtr,
                                         int Idx1, const char *Name);
-    static GetElementPtrInst *CreateGEP(LLVMContext *Context,
+    static GetElementPtrInst *CreateGEP(LLVMContext &Context,
                                         IRBuilder<> &B, Value *BasePtr,
                                         int Idx1, int Idx2, const char *Name);
   };
@@ -95,7 +95,7 @@
 
   public:
     EscapeEnumerator(Function &F, const char *N = "cleanup")
-      : F(F), CleanupBBName(N), State(0), Builder(*F.getContext()) {}
+      : F(F), CleanupBBName(N), State(0), Builder(F.getContext()) {}
 
     IRBuilder<> *Next() {
       switch (State) {
@@ -188,7 +188,7 @@
 
 Constant *ShadowStackGC::GetFrameMap(Function &F) {
   // doInitialization creates the abstract type of this value.
-  LLVMContext *Context = F.getContext();
+  LLVMContext &Context = F.getContext();
 
   Type *VoidPtr = PointerType::getUnqual(Type::Int8Ty);
 
@@ -203,17 +203,17 @@
   }
 
   Constant *BaseElts[] = {
-    Context->getConstantInt(Type::Int32Ty, Roots.size(), false),
-    Context->getConstantInt(Type::Int32Ty, NumMeta, false),
+    Context.getConstantInt(Type::Int32Ty, Roots.size(), false),
+    Context.getConstantInt(Type::Int32Ty, NumMeta, false),
   };
 
   Constant *DescriptorElts[] = {
-    Context->getConstantStruct(BaseElts, 2),
-    Context->getConstantArray(Context->getArrayType(VoidPtr, NumMeta),
+    Context.getConstantStruct(BaseElts, 2),
+    Context.getConstantArray(Context.getArrayType(VoidPtr, NumMeta),
                        Metadata.begin(), NumMeta)
   };
 
-  Constant *FrameMap = Context->getConstantStruct(DescriptorElts, 2);
+  Constant *FrameMap = Context.getConstantStruct(DescriptorElts, 2);
 
   std::string TypeName("gc_map.");
   TypeName += utostr(NumMeta);
@@ -236,9 +236,9 @@
                                     GlobalVariable::InternalLinkage,
                                     FrameMap, "__gc_" + F.getName());
 
-  Constant *GEPIndices[2] = { Context->getConstantInt(Type::Int32Ty, 0),
-                              Context->getConstantInt(Type::Int32Ty, 0) };
-  return Context->getConstantExprGetElementPtr(GV, GEPIndices, 2);
+  Constant *GEPIndices[2] = { Context.getConstantInt(Type::Int32Ty, 0),
+                              Context.getConstantInt(Type::Int32Ty, 0) };
+  return Context.getConstantExprGetElementPtr(GV, GEPIndices, 2);
 }
 
 const Type* ShadowStackGC::GetConcreteStackEntryType(Function &F) {
@@ -340,11 +340,11 @@
 }
 
 GetElementPtrInst *
-ShadowStackGC::CreateGEP(LLVMContext *Context, IRBuilder<> &B, Value *BasePtr,
+ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
                          int Idx, int Idx2, const char *Name) {
-  Value *Indices[] = { Context->getConstantInt(Type::Int32Ty, 0),
-                       Context->getConstantInt(Type::Int32Ty, Idx),
-                       Context->getConstantInt(Type::Int32Ty, Idx2) };
+  Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0),
+                       Context.getConstantInt(Type::Int32Ty, Idx),
+                       Context.getConstantInt(Type::Int32Ty, Idx2) };
   Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name);
 
   assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
@@ -353,10 +353,10 @@
 }
 
 GetElementPtrInst *
-ShadowStackGC::CreateGEP(LLVMContext *Context, IRBuilder<> &B, Value *BasePtr,
+ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
                          int Idx, const char *Name) {
-  Value *Indices[] = { Context->getConstantInt(Type::Int32Ty, 0),
-                       Context->getConstantInt(Type::Int32Ty, Idx) };
+  Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0),
+                       Context.getConstantInt(Type::Int32Ty, Idx) };
   Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name);
 
   assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
@@ -366,7 +366,7 @@
 
 /// runOnFunction - Insert code to maintain the shadow stack.
 bool ShadowStackGC::performCustomLowering(Function &F) {
-  LLVMContext *Context = F.getContext();
+  LLVMContext &Context = F.getContext();
   
   // Find calls to llvm.gcroot.
   CollectRoots(F);
diff --git a/lib/CodeGen/UnreachableBlockElim.cpp b/lib/CodeGen/UnreachableBlockElim.cpp
index 003470d..27b9627 100644
--- a/lib/CodeGen/UnreachableBlockElim.cpp
+++ b/lib/CodeGen/UnreachableBlockElim.cpp
@@ -68,7 +68,7 @@
       BasicBlock *BB = I;
       DeadBlocks.push_back(BB);
       while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
-        PN->replaceAllUsesWith(Context->getNullValue(PN->getType()));
+        PN->replaceAllUsesWith(F.getContext().getNullValue(PN->getType()));
         BB->getInstList().pop_front();
       }
       for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)