llvm.org GIT mirror llvm / f57fcf7
update the tutorial to use CreateFAdd to create fp operations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112733 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
4 changed file(s) with 9 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
221221
222222

In the example above, the LLVM builder class is starting to show its value.

223223 IRBuilder knows where to insert the newly created instruction, all you have to
224 do is specify what instruction to create (e.g. with CreateAdd), which
224 do is specify what instruction to create (e.g. with CreateFAdd), which
225225 operands to use (L and R here) and optionally provide a name
226226 for the generated instruction.

227227
10531053 if (L == 0 || R == 0) return 0;
10541054
10551055 switch (Op) {
1056 case '+': return Builder.CreateAdd(L, R, "addtmp");
1057 case '-': return Builder.CreateSub(L, R, "subtmp");
1058 case '*': return Builder.CreateMul(L, R, "multmp");
1056 case '+': return Builder.CreateFAdd(L, R, "addtmp");
1057 case '-': return Builder.CreateFSub(L, R, "subtmp");
1058 case '*': return Builder.CreateFMul(L, R, "multmp");
10591059 case '<':
10601060 L = Builder.CreateFCmpULT(L, R, "cmptmp");
10611061 // Convert bool 0/1 to double 0.0 or 1.0
799799 StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
800800 }
801801
802 Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
802 Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
803803
804804
805805
15161516 StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
15171517 }
15181518
1519 Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
1519 Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
15201520
15211521 // Compute the end condition.
15221522 Value *EndCond = End->Codegen();
15391539 StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));
15401540 }
15411541
1542 Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar");
1542 Value *NextVar = Builder.CreateFAdd(Variable, StepVal, "nextvar");
15431543
15441544 // Compute the end condition.
15451545 Value *EndCond = End->Codegen();
479479 // Reload, increment, and restore the alloca. This handles the case where
480480 // the body of the loop mutates the variable.
481481 Value *CurVar = Builder.CreateLoad(Alloca);
482 Value *NextVar = Builder.CreateAdd(CurVar, StepVal, "nextvar");
482 Value *NextVar = Builder.CreateFAdd(CurVar, StepVal, "nextvar");
483483 Builder.CreateStore(NextVar, Alloca);
484484 ...
485485
18321832 // Reload, increment, and restore the alloca. This handles the case where
18331833 // the body of the loop mutates the variable.
18341834 Value *CurVar = Builder.CreateLoad(Alloca, VarName.c_str());
1835 Value *NextVar = Builder.CreateAdd(CurVar, StepVal, "nextvar");
1835 Value *NextVar = Builder.CreateFAdd(CurVar, StepVal, "nextvar");
18361836 Builder.CreateStore(NextVar, Alloca);
18371837
18381838 // Convert condition to a bool by comparing equal to 0.0.