Get rid of the Pass+Context magic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76702 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2009-07-22 00:24:57 +00:00
parent 7cf12c7efd
commit e922c02019
120 changed files with 835 additions and 786 deletions

View File

@@ -23,10 +23,10 @@
void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
GlobalValue *Array) {
LLVMContext *Context = MainFn->getContext();
LLVMContext &Context = MainFn->getContext();
const Type *ArgVTy =
Context->getPointerTypeUnqual(Context->getPointerTypeUnqual(Type::Int8Ty));
const PointerType *UIntPtr = Context->getPointerTypeUnqual(Type::Int32Ty);
Context.getPointerTypeUnqual(Context.getPointerTypeUnqual(Type::Int8Ty));
const PointerType *UIntPtr = Context.getPointerTypeUnqual(Type::Int32Ty);
Module &M = *MainFn->getParent();
Constant *InitFn = M.getOrInsertFunction(FnName, Type::Int32Ty, Type::Int32Ty,
ArgVTy, UIntPtr, Type::Int32Ty,
@@ -35,27 +35,27 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
// This could force argc and argv into programs that wouldn't otherwise have
// them, but instead we just pass null values in.
std::vector<Value*> Args(4);
Args[0] = Context->getNullValue(Type::Int32Ty);
Args[1] = Context->getNullValue(ArgVTy);
Args[0] = Context.getNullValue(Type::Int32Ty);
Args[1] = Context.getNullValue(ArgVTy);
// Skip over any allocas in the entry block.
BasicBlock *Entry = MainFn->begin();
BasicBlock::iterator InsertPos = Entry->begin();
while (isa<AllocaInst>(InsertPos)) ++InsertPos;
std::vector<Constant*> GEPIndices(2, Context->getNullValue(Type::Int32Ty));
std::vector<Constant*> GEPIndices(2, Context.getNullValue(Type::Int32Ty));
unsigned NumElements = 0;
if (Array) {
Args[2] = Context->getConstantExprGetElementPtr(Array, &GEPIndices[0],
Args[2] = Context.getConstantExprGetElementPtr(Array, &GEPIndices[0],
GEPIndices.size());
NumElements =
cast<ArrayType>(Array->getType()->getElementType())->getNumElements();
} else {
// If this profiling instrumentation doesn't have a constant array, just
// pass null.
Args[2] = Context->getConstantPointerNull(UIntPtr);
Args[2] = Context.getConstantPointerNull(UIntPtr);
}
Args[3] = Context->getConstantInt(Type::Int32Ty, NumElements);
Args[3] = Context.getConstantInt(Type::Int32Ty, NumElements);
Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(),
"newargc", InsertPos);
@@ -101,7 +101,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
GlobalValue *CounterArray) {
LLVMContext *Context = BB->getContext();
LLVMContext &Context = BB->getContext();
// Insert the increment after any alloca or PHI instructions...
BasicBlock::iterator InsertPos = BB->getFirstNonPHI();
@@ -110,16 +110,16 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
// Create the getelementptr constant expression
std::vector<Constant*> Indices(2);
Indices[0] = Context->getNullValue(Type::Int32Ty);
Indices[1] = Context->getConstantInt(Type::Int32Ty, CounterNum);
Indices[0] = Context.getNullValue(Type::Int32Ty);
Indices[1] = Context.getConstantInt(Type::Int32Ty, CounterNum);
Constant *ElementPtr =
Context->getConstantExprGetElementPtr(CounterArray, &Indices[0],
Context.getConstantExprGetElementPtr(CounterArray, &Indices[0],
Indices.size());
// Load, increment and store the value back.
Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos);
Value *NewVal = BinaryOperator::Create(Instruction::Add, OldVal,
Context->getConstantInt(Type::Int32Ty, 1),
Context.getConstantInt(Type::Int32Ty, 1),
"NewFuncCounter", InsertPos);
new StoreInst(NewVal, ElementPtr, InsertPos);
}