Browse Source

These are legal for tail calls

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21723 91177308-0d34-0410-b5e6-96231b3b80d8
Chris Lattner 20 years ago
parent
commit
47968e4dfd
2 changed files with 5 additions and 1 deletions
  1. 3 0
      examples/Fibonacci/fibonacci.cpp
  2. 2 1
      examples/HowToUseJIT/HowToUseJIT.cpp

+ 3 - 0
examples/Fibonacci/fibonacci.cpp

@@ -65,10 +65,13 @@ static Function *CreateFibFunction(Module *M) {
   // create fib(x-1)
   // create fib(x-1)
   Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
   Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
   Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
   Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
+  CallFibX1->setTailCall(true);
 
 
   // create fib(x-2)
   // create fib(x-2)
   Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
   Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
   Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
   Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
+  CallFibX2->setTailCall(true);
+
 
 
   // fib(x-1)+fib(x-2)
   // fib(x-1)+fib(x-2)
   Value *Sum = BinaryOperator::createAdd(CallFibX1, CallFibX2,
   Value *Sum = BinaryOperator::createAdd(CallFibX1, CallFibX2,

+ 2 - 1
examples/HowToUseJIT/HowToUseJIT.cpp

@@ -87,7 +87,8 @@ int main() {
   // Pass Ten to the call call:
   // Pass Ten to the call call:
   std::vector<Value*> Params;
   std::vector<Value*> Params;
   Params.push_back(Ten);
   Params.push_back(Ten);
-  CallInst * Add1CallRes = new CallInst(Add1F, Params, "add1", BB);
+  CallInst *Add1CallRes = new CallInst(Add1F, Params, "add1", BB);
+  Add1CallRes->setTailCall(true);
 
 
   // Create the return instruction and add it to the basic block.
   // Create the return instruction and add it to the basic block.
   new ReturnInst(Add1CallRes, BB);
   new ReturnInst(Add1CallRes, BB);