Skip to content

Commit

Permalink
API changes for class Use size reduction, wave 1.
Browse files Browse the repository at this point in the history
Specifically, introduction of XXX::Create methods
for Users that have a potentially variable number of
Uses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49277 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ggreif committed Apr 6, 2008
1 parent d963ab1 commit 051a950
Show file tree
Hide file tree
Showing 73 changed files with 972 additions and 685 deletions.
28 changes: 14 additions & 14 deletions examples/BrainF/BrainF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void BrainF::header() {
brainf_func = cast<Function>(module->
getOrInsertFunction("brainf", Type::VoidTy, NULL));

builder = new LLVMBuilder(new BasicBlock(label, brainf_func));
builder = new LLVMBuilder(BasicBlock::Create(label, brainf_func));

//%arr = malloc i8, i32 %d
ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal));
Expand Down Expand Up @@ -110,13 +110,13 @@ void BrainF::header() {
//Function footer

//brainf.end:
endbb = new BasicBlock(label, brainf_func);
endbb = BasicBlock::Create(label, brainf_func);

//free i8 *%arr
new FreeInst(ptr_arr, endbb);

//ret void
new ReturnInst(endbb);
ReturnInst::Create(endbb);



Expand All @@ -141,7 +141,7 @@ void BrainF::header() {
PointerType::getUnqual(IntegerType::Int8Ty), NULL));

//brainf.aberror:
aberrorbb = new BasicBlock(label, brainf_func);
aberrorbb = BasicBlock::Create(label, brainf_func);

//call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
{
Expand All @@ -161,14 +161,14 @@ void BrainF::header() {
};

CallInst *puts_call =
new CallInst(puts_func,
puts_params, array_endof(puts_params),
"", aberrorbb);
CallInst::Create(puts_func,
puts_params, array_endof(puts_params),
"", aberrorbb);
puts_call->setTailCall(false);
}

//br label %brainf.end
new BranchInst(endbb, aberrorbb);
BranchInst::Create(endbb, aberrorbb);
}
}

Expand Down Expand Up @@ -247,7 +247,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
CreateOr(test_0, test_1, testreg);

//br i1 %test.%d, label %main.%d, label %main.%d
BasicBlock *nextbb = new BasicBlock(label, brainf_func);
BasicBlock *nextbb = BasicBlock::Create(label, brainf_func);
builder->CreateCondBr(test_2, aberrorbb, nextbb);

//main.%d:
Expand All @@ -273,16 +273,16 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
case SYM_LOOP:
{
//br label %main.%d
BasicBlock *testbb = new BasicBlock(label, brainf_func);
BasicBlock *testbb = BasicBlock::Create(label, brainf_func);
builder->CreateBr(testbb);

//main.%d:
BasicBlock *bb_0 = builder->GetInsertBlock();
BasicBlock *bb_1 = new BasicBlock(label, brainf_func);
BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func);
builder->SetInsertPoint(bb_1);

//Make part of PHI instruction now, wait until end of loop to finish
PHINode *phi_0 = new PHINode(PointerType::getUnqual(IntegerType::Int8Ty),
PHINode *phi_0 = PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty),
headreg, testbb);
phi_0->reserveOperandSpace(2);
phi_0->addIncoming(curhead, bb_0);
Expand Down Expand Up @@ -431,8 +431,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
testbb);

//br i1 %test.%d, label %main.%d, label %main.%d
BasicBlock *bb_0 = new BasicBlock(label, brainf_func);
new BranchInst(bb_0, oldbb, test_0, testbb);
BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
BranchInst::Create(bb_0, oldbb, test_0, testbb);

//main.%d:
builder->SetInsertPoint(bb_0);
Expand Down
8 changes: 4 additions & 4 deletions examples/BrainF/BrainFDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ void addMainFunction(Module *mod) {
}

//main.0:
BasicBlock *bb = new BasicBlock("main.0", main_func);
BasicBlock *bb = BasicBlock::Create("main.0", main_func);

//call void @brainf()
{
CallInst *brainf_call = new CallInst(mod->getFunction("brainf"),
"", bb);
CallInst *brainf_call = CallInst::Create(mod->getFunction("brainf"),
"", bb);
brainf_call->setTailCall(false);
}

//ret i32 0
new ReturnInst(ConstantInt::get(APInt(32, 0)), bb);
ReturnInst::Create(ConstantInt::get(APInt(32, 0)), bb);
}

int main(int argc, char **argv) {
Expand Down
16 changes: 8 additions & 8 deletions examples/Fibonacci/fibonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static Function *CreateFibFunction(Module *M) {
(Type *)0));

// Add a basic block to the function.
BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);

// Get pointers to the constants.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
Expand All @@ -54,25 +54,25 @@ static Function *CreateFibFunction(Module *M) {
ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.

// Create the true_block.
BasicBlock *RetBB = new BasicBlock("return", FibF);
BasicBlock *RetBB = BasicBlock::Create("return", FibF);
// Create an exit block.
BasicBlock* RecurseBB = new BasicBlock("recurse", FibF);
BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);

// Create the "if (arg <= 2) goto exitbb"
Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
new BranchInst(RetBB, RecurseBB, CondInst, BB);
BranchInst::Create(RetBB, RecurseBB, CondInst, BB);

// Create: ret int 1
new ReturnInst(One, RetBB);
ReturnInst::Create(One, RetBB);

// create fib(x-1)
Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
CallInst *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
CallInst *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB);
CallFibX1->setTailCall();

// create fib(x-2)
Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
CallInst *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
CallInst *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB);
CallFibX2->setTailCall();


Expand All @@ -81,7 +81,7 @@ static Function *CreateFibFunction(Module *M) {
"addresult", RecurseBB);

// Create the return instruction and add it to the basic block
new ReturnInst(Sum, RecurseBB);
ReturnInst::Create(Sum, RecurseBB);

return FibF;
}
Expand Down
10 changes: 5 additions & 5 deletions examples/HowToUseJIT/HowToUseJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main() {

// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);

// Get pointers to the constant `1'.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
Expand All @@ -72,7 +72,7 @@ int main() {
Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);

// Create the return instruction and add it to the basic block
new ReturnInst(Add, BB);
ReturnInst::Create(Add, BB);

// Now, function add1 is ready.

Expand All @@ -83,17 +83,17 @@ int main() {
cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0));

// Add a basic block to the FooF function.
BB = new BasicBlock("EntryBlock", FooF);
BB = BasicBlock::Create("EntryBlock", FooF);

// Get pointers to the constant `10'.
Value *Ten = ConstantInt::get(Type::Int32Ty, 10);

// Pass Ten to the call call:
CallInst *Add1CallRes = new CallInst(Add1F, Ten, "add1", BB);
CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB);
Add1CallRes->setTailCall(true);

// Create the return instruction and add it to the basic block.
new ReturnInst(Add1CallRes, BB);
ReturnInst::Create(Add1CallRes, BB);

// Now we create the JIT.
ExistingModuleProvider* MP = new ExistingModuleProvider(M);
Expand Down
6 changes: 3 additions & 3 deletions examples/ModuleMaker/ModuleMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ int main() {

// By passing a module as the last parameter to the Function constructor,
// it automatically gets appended to the Module.
Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
Function *F = Function::Create(FT, Function::ExternalLinkage, "main", M);

// Add a basic block to the function... again, it automatically inserts
// because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", F);
BasicBlock *BB = BasicBlock::Create("EntryBlock", F);

// Get pointers to the constant integers...
Value *Two = ConstantInt::get(Type::Int32Ty, 2);
Expand All @@ -50,7 +50,7 @@ int main() {
BB->getInstList().push_back(Add);

// Create the return instruction and add it to the basic block
BB->getInstList().push_back(new ReturnInst(Add));
BB->getInstList().push_back(ReturnInst::Create(Add));

// Output the bitcode file to stdout
WriteBitcodeToFile(M, std::cout);
Expand Down
20 changes: 10 additions & 10 deletions examples/ParallelJIT/ParallelJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static Function* createAdd1(Module *M) {

// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);

// Get pointers to the constant `1'.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
Expand All @@ -53,7 +53,7 @@ static Function* createAdd1(Module *M) {
Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);

// Create the return instruction and add it to the basic block
new ReturnInst(Add, BB);
ReturnInst::Create(Add, BB);

// Now, function add1 is ready.
return Add1F;
Expand All @@ -67,7 +67,7 @@ static Function *CreateFibFunction(Module *M) {
(Type *)0));

// Add a basic block to the function.
BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);

// Get pointers to the constants.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
Expand All @@ -78,31 +78,31 @@ static Function *CreateFibFunction(Module *M) {
ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.

// Create the true_block.
BasicBlock *RetBB = new BasicBlock("return", FibF);
BasicBlock *RetBB = BasicBlock::Create("return", FibF);
// Create an exit block.
BasicBlock* RecurseBB = new BasicBlock("recurse", FibF);
BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);

// Create the "if (arg < 2) goto exitbb"
Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
new BranchInst(RetBB, RecurseBB, CondInst, BB);
BranchInst::Create(RetBB, RecurseBB, CondInst, BB);

// Create: ret int 1
new ReturnInst(One, RetBB);
ReturnInst::Create(One, RetBB);

// create fib(x-1)
Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
Value *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB);

// create fib(x-2)
Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
Value *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB);

// fib(x-1)+fib(x-2)
Value *Sum =
BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB);

// Create the return instruction and add it to the basic block
new ReturnInst(Sum, RecurseBB);
ReturnInst::Create(Sum, RecurseBB);

return FibF;
}
Expand Down
17 changes: 11 additions & 6 deletions include/llvm/BasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,22 @@ private :
BasicBlock(const BasicBlock &); // Do not implement
void operator=(const BasicBlock &); // Do not implement

public:
/// Instruction iterators...
typedef InstListType::iterator iterator;
typedef InstListType::const_iterator const_iterator;

/// BasicBlock ctor - If the function parameter is specified, the basic block
/// is automatically inserted at either the end of the function (if
/// InsertBefore is null), or before the specified basic block.
///
explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
BasicBlock *InsertBefore = 0, BasicBlock *unwindDest = 0);
BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0);
public:
/// Instruction iterators...
typedef InstListType::iterator iterator;
typedef InstListType::const_iterator const_iterator;

// allocate space for exactly zero operands
static BasicBlock *Create(const std::string &Name = "", Function *Parent = 0,
BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0) {
return new(!!UnwindDest) BasicBlock(Name, Parent, InsertBefore, UnwindDest);
}
~BasicBlock();

/// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind
Expand Down
Loading

0 comments on commit 051a950

Please sign in to comment.