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

@ -239,7 +239,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
DOUT << "inputs: " << inputs.size() << "\n";
DOUT << "outputs: " << outputs.size() << "\n";
LLVMContext *Context = header->getContext();
LLVMContext &Context = header->getContext();
// This function returns unsigned, outputs will go back by reference.
switch (NumExitBlocks) {
@ -267,7 +267,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
paramTy.push_back((*I)->getType());
else
paramTy.push_back(
header->getContext()->getPointerTypeUnqual((*I)->getType()));
header->getContext().getPointerTypeUnqual((*I)->getType()));
}
DOUT << "Function type: " << *RetTy << " f(";
@ -278,12 +278,12 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
PointerType *StructPtr =
Context->getPointerTypeUnqual(Context->getStructType(paramTy));
Context.getPointerTypeUnqual(Context.getStructType(paramTy));
paramTy.clear();
paramTy.push_back(StructPtr);
}
const FunctionType *funcType =
Context->getFunctionType(RetTy, paramTy, false);
Context.getFunctionType(RetTy, paramTy, false);
// Create the new function
Function *newFunction = Function::Create(funcType,
@ -305,8 +305,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
Value *RewriteVal;
if (AggregateArgs) {
Value *Idx[2];
Idx[0] = Context->getNullValue(Type::Int32Ty);
Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[1] = Context.getConstantInt(Type::Int32Ty, i);
std::string GEPname = "gep_" + inputs[i]->getName();
TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2,
@ -353,7 +353,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
void CodeExtractor::
emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Values &inputs, Values &outputs) {
LLVMContext *Context = codeReplacer->getContext();
LLVMContext &Context = codeReplacer->getContext();
// Emit a call to the new function, passing in: *pointer to struct (if
// aggregating parameters), or plan inputs and allocated memory for outputs
@ -387,7 +387,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
ArgTypes.push_back((*v)->getType());
// Allocate a struct at the beginning of this function
Type *StructArgTy = Context->getStructType(ArgTypes);
Type *StructArgTy = Context.getStructType(ArgTypes);
Struct =
new AllocaInst(StructArgTy, 0, "structArg",
codeReplacer->getParent()->begin()->begin());
@ -395,8 +395,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx[2];
Idx[0] = Context->getNullValue(Type::Int32Ty);
Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[1] = Context.getConstantInt(Type::Int32Ty, i);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_" + StructValues[i]->getName());
@ -421,8 +421,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Value *Output = 0;
if (AggregateArgs) {
Value *Idx[2];
Idx[0] = Context->getNullValue(Type::Int32Ty);
Idx[1] = Context->getConstantInt(Type::Int32Ty, FirstOut + i);
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[1] = Context.getConstantInt(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_reload_" + outputs[i]->getName());
@ -443,7 +443,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch =
SwitchInst::Create(Context->getNullValue(Type::Int16Ty),
SwitchInst::Create(Context.getNullValue(Type::Int16Ty),
codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new
@ -474,17 +474,17 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
case 0:
case 1: break; // No value needed.
case 2: // Conditional branch, return a bool
brVal = Context->getConstantInt(Type::Int1Ty, !SuccNum);
brVal = Context.getConstantInt(Type::Int1Ty, !SuccNum);
break;
default:
brVal = Context->getConstantInt(Type::Int16Ty, SuccNum);
brVal = Context.getConstantInt(Type::Int16Ty, SuccNum);
break;
}
ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
// Update the switch instruction.
TheSwitch->addCase(Context->getConstantInt(Type::Int16Ty, SuccNum),
TheSwitch->addCase(Context.getConstantInt(Type::Int16Ty, SuccNum),
OldTarget);
// Restore values just before we exit
@ -522,8 +522,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (DominatesDef) {
if (AggregateArgs) {
Value *Idx[2];
Idx[0] = Context->getNullValue(Type::Int32Ty);
Idx[1] = Context->getConstantInt(Type::Int32Ty,FirstOut+out);
Idx[0] = Context.getNullValue(Type::Int32Ty);
Idx[1] = Context.getConstantInt(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
"gep_" + outputs[out]->getName(),
@ -560,7 +560,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
} else {
// Otherwise we must have code extracted an unwind or something, just
// return whatever we want.
ReturnInst::Create(Context->getNullValue(OldFnRetTy), TheSwitch);
ReturnInst::Create(Context.getNullValue(OldFnRetTy), TheSwitch);
}
TheSwitch->eraseFromParent();