summaryrefslogtreecommitdiffstats
path: root/llvm/examples
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/examples')
-rw-r--r--llvm/examples/BrainF/BrainF.cpp18
-rw-r--r--llvm/examples/BrainF/BrainF.h6
-rw-r--r--llvm/examples/BrainF/BrainFDriver.cpp12
-rw-r--r--llvm/examples/Fibonacci/fibonacci.cpp5
-rw-r--r--llvm/examples/HowToUseJIT/HowToUseJIT.cpp8
-rw-r--r--llvm/examples/ParallelJIT/ParallelJIT.cpp15
6 files changed, 33 insertions, 31 deletions
diff --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp
index bcd75325e80..b4cbc780a04 100644
--- a/llvm/examples/BrainF/BrainF.cpp
+++ b/llvm/examples/BrainF/BrainF.cpp
@@ -72,19 +72,17 @@ void BrainF::header(LLVMContext& C) {
Tys);
//declare i32 @getchar()
- getchar_func = cast<Function>(module->
- getOrInsertFunction("getchar", IntegerType::getInt32Ty(C)));
+ getchar_func =
+ module->getOrInsertFunction("getchar", IntegerType::getInt32Ty(C));
//declare i32 @putchar(i32)
- putchar_func = cast<Function>(module->
- getOrInsertFunction("putchar", IntegerType::getInt32Ty(C),
- IntegerType::getInt32Ty(C)));
+ putchar_func = module->getOrInsertFunction(
+ "putchar", IntegerType::getInt32Ty(C), IntegerType::getInt32Ty(C));
//Function header
//define void @brainf()
- brainf_func = cast<Function>(module->
- getOrInsertFunction("brainf", Type::getVoidTy(C)));
+ brainf_func = module->getOrInsertFunction("brainf", Type::getVoidTy(C));
builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func));
@@ -153,9 +151,9 @@ void BrainF::header(LLVMContext& C) {
"aberrormsg");
//declare i32 @puts(i8 *)
- Function *puts_func = cast<Function>(module->
- getOrInsertFunction("puts", IntegerType::getInt32Ty(C),
- PointerType::getUnqual(IntegerType::getInt8Ty(C))));
+ FunctionCallee puts_func = module->getOrInsertFunction(
+ "puts", IntegerType::getInt32Ty(C),
+ PointerType::getUnqual(IntegerType::getInt8Ty(C)));
//brainf.aberror:
aberrorbb = BasicBlock::Create(C, label, brainf_func);
diff --git a/llvm/examples/BrainF/BrainF.h b/llvm/examples/BrainF/BrainF.h
index a2c04f8cb79..9d6848e5bc6 100644
--- a/llvm/examples/BrainF/BrainF.h
+++ b/llvm/examples/BrainF/BrainF.h
@@ -78,9 +78,9 @@ class BrainF {
CompileFlags comflag;
std::istream *in;
Module *module;
- Function *brainf_func;
- Function *getchar_func;
- Function *putchar_func;
+ FunctionCallee brainf_func;
+ FunctionCallee getchar_func;
+ FunctionCallee putchar_func;
Value *ptr_arr;
Value *ptr_arrmax;
BasicBlock *endbb;
diff --git a/llvm/examples/BrainF/BrainFDriver.cpp b/llvm/examples/BrainF/BrainFDriver.cpp
index 85c563d136d..2c63b254246 100644
--- a/llvm/examples/BrainF/BrainFDriver.cpp
+++ b/llvm/examples/BrainF/BrainFDriver.cpp
@@ -72,11 +72,13 @@ JIT("jit", cl::desc("Run program Just-In-Time"));
//Add main function so can be fully compiled
void addMainFunction(Module *mod) {
//define i32 @main(i32 %argc, i8 **%argv)
- Function *main_func = cast<Function>(mod->
- getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()),
- IntegerType::getInt32Ty(mod->getContext()),
- PointerType::getUnqual(PointerType::getUnqual(
- IntegerType::getInt8Ty(mod->getContext())))));
+ FunctionType *main_func_fty = FunctionType::get(
+ Type::getInt32Ty(mod->getContext()),
+ {Type::getInt32Ty(mod->getContext()),
+ Type::getInt8Ty(mod->getContext())->getPointerTo()->getPointerTo()});
+ Function *main_func =
+ Function::create(main_func_fty, Function::ExternalLinkage, "main", mod);
+
{
Function::arg_iterator args = main_func->arg_begin();
Value *arg_0 = &*args++;
diff --git a/llvm/examples/Fibonacci/fibonacci.cpp b/llvm/examples/Fibonacci/fibonacci.cpp
index c28ae765994..12393a414d0 100644
--- a/llvm/examples/Fibonacci/fibonacci.cpp
+++ b/llvm/examples/Fibonacci/fibonacci.cpp
@@ -51,9 +51,10 @@ using namespace llvm;
static Function *CreateFibFunction(Module *M, LLVMContext &Context) {
// Create the fib function and insert it into module M. This function is said
// to return an int and take an int parameter.
+ FunctionType *FibFTy = FunctionType::get(Type::getInt32Ty(Context),
+ {Type::getInt32Ty(Context)}, false);
Function *FibF =
- cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context),
- Type::getInt32Ty(Context)));
+ Function::Create(FibFTy, Function::ExternalLinkage, "fib", M);
// Add a basic block to the function.
BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF);
diff --git a/llvm/examples/HowToUseJIT/HowToUseJIT.cpp b/llvm/examples/HowToUseJIT/HowToUseJIT.cpp
index 29116131b16..30354d4cae6 100644
--- a/llvm/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/llvm/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -69,8 +69,9 @@ int main() {
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
Function *Add1F =
- cast<Function>(M->getOrInsertFunction("add1", Type::getInt32Ty(Context),
- Type::getInt32Ty(Context)));
+ Function::Create(FunctionType::get(Type::getInt32Ty(Context),
+ {Type::getInt32Ty(Context)}, false),
+ Function::ExternalLinkage, "add1", M);
// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
@@ -99,7 +100,8 @@ int main() {
// Now we're going to create function `foo', which returns an int and takes no
// arguments.
Function *FooF =
- cast<Function>(M->getOrInsertFunction("foo", Type::getInt32Ty(Context)));
+ Function::Create(FunctionType::get(Type::getInt32Ty(Context), {}, false),
+ Function::ExternalLinkage, "foo", M);
// Add a basic block to the FooF function.
BB = BasicBlock::Create(Context, "EntryBlock", FooF);
diff --git a/llvm/examples/ParallelJIT/ParallelJIT.cpp b/llvm/examples/ParallelJIT/ParallelJIT.cpp
index 8485848e0a7..b5815dd2f78 100644
--- a/llvm/examples/ParallelJIT/ParallelJIT.cpp
+++ b/llvm/examples/ParallelJIT/ParallelJIT.cpp
@@ -49,11 +49,10 @@ using namespace llvm;
static Function* createAdd1(Module *M) {
// Create the add1 function entry and insert this entry into module M. The
// function will have a return type of "int" and take an argument of "int".
- // The '0' terminates the list of argument types.
Function *Add1F =
- cast<Function>(M->getOrInsertFunction("add1",
- Type::getInt32Ty(M->getContext()),
- Type::getInt32Ty(M->getContext())));
+ Function::Create(FunctionType::get(Type::getInt32Ty(Context),
+ {Type::getInt32Ty(Context)}, false),
+ Function::ExternalLinkage, "add1", M);
// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
@@ -80,10 +79,10 @@ static Function* createAdd1(Module *M) {
static Function *CreateFibFunction(Module *M) {
// Create the fib function and insert it into module M. This function is said
// to return an int and take an int parameter.
- Function *FibF =
- cast<Function>(M->getOrInsertFunction("fib",
- Type::getInt32Ty(M->getContext()),
- Type::getInt32Ty(M->getContext())));
+ FunctionType *FibFTy = FunctionType::get(Type::getInt32Ty(Context),
+ {Type::getInt32Ty(Context)}, false);
+ Function *FibF =
+ Function::Create(FibFTy, Function::ExternalLinkage, "fib", M);
// Add a basic block to the function.
BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF);
OpenPOWER on IntegriCloud