llvm.org GIT mirror llvm / 1d0be15
Push LLVMContexts through the IntegerType APIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78948 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 10 years ago
160 changed file(s) with 1997 addition(s) and 1610 deletion(s). Raw diff Collapse all Expand all
152152
153153
154154

                  
                
155 BasicBlock* block = BasicBlock::Create("entry", mul_add);
155 BasicBlock* block = BasicBlock::Create(getGlobalContext(), "entry", mul_add);
156156 IRBuilder<> builder(block);
157157
158158
9999
100100
101101

                  
                
102 BasicBlock* entry = BasicBlock::Create("entry", gcd);
103 BasicBlock* ret = BasicBlock::Create("return", gcd);
104 BasicBlock* cond_false = BasicBlock::Create("cond_false", gcd);
105 BasicBlock* cond_true = BasicBlock::Create("cond_true", gcd);
106 BasicBlock* cond_false_2 = BasicBlock::Create("cond_false", gcd);
102 BasicBlock* entry = BasicBlock::Create(getGlobalContext(), ("entry", gcd);
103 BasicBlock* ret = BasicBlock::Create(getGlobalContext(), ("return", gcd);
104 BasicBlock* cond_false = BasicBlock::Create(getGlobalContext(), ("cond_false", gcd);
105 BasicBlock* cond_true = BasicBlock::Create(getGlobalContext(), ("cond_true", gcd);
106 BasicBlock* cond_false_2 = BasicBlock::Create(getGlobalContext(), ("cond_false", gcd);
107107
108108
109109
205205 case '<':
206206 L = Builder.CreateFCmpULT(L, R, "cmptmp");
207207 // Convert bool 0/1 to double 0.0 or 1.0
208 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
208 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
209209 default: return ErrorV("invalid binary operator");
210210 }
211211 }
306306

                  
                
307307 Function *PrototypeAST::Codegen() {
308308 // Make the function type: double(double,double) etc.
309 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
310 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
309 std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
310 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
311311
312312 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
313313
438438
439439

                  
                
440440 // Create a new basic block to start insertion into.
441 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
441 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
442442 Builder.SetInsertPoint(BB);
443443
444444 if (Value *RetVal = Body->Codegen()) {
10541054 case '<':
10551055 L = Builder.CreateFCmpULT(L, R, "cmptmp");
10561056 // Convert bool 0/1 to double 0.0 or 1.0
1057 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
1057 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
10581058 default: return ErrorV("invalid binary operator");
10591059 }
10601060 }
10801080
10811081 Function *PrototypeAST::Codegen() {
10821082 // Make the function type: double(double,double) etc.
1083 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1084 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
1083 std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
1084 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
10851085
10861086 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
10871087
11261126 return 0;
11271127
11281128 // Create a new basic block to start insertion into.
1129 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
1129 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
11301130 Builder.SetInsertPoint(BB);
11311131
11321132 if (Value *RetVal = Body->Codegen()) {
889889 case '<':
890890 L = Builder.CreateFCmpULT(L, R, "cmptmp");
891891 // Convert bool 0/1 to double 0.0 or 1.0
892 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
892 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
893893 default: return ErrorV("invalid binary operator");
894894 }
895895 }
915915
916916 Function *PrototypeAST::Codegen() {
917917 // Make the function type: double(double,double) etc.
918 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
919 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
918 std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
919 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
920920
921921 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
922922
961961 return 0;
962962
963963 // Create a new basic block to start insertion into.
964 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
964 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
965965 Builder.SetInsertPoint(BB);
966966
967967 if (Value *RetVal = Body->Codegen()) {
378378
379379 // Create blocks for the then and else cases. Insert the 'then' block at the
380380 // end of the function.
381 BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction);
382 BasicBlock *ElseBB = BasicBlock::Create("else");
383 BasicBlock *MergeBB = BasicBlock::Create("ifcont");
381 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
382 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
383 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
384384
385385 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
386386
471471 // Emit merge block.
472472 TheFunction->getBasicBlockList().push_back(MergeBB);
473473 Builder.SetInsertPoint(MergeBB);
474 PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp");
474 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp");
475475
476476 PN->addIncoming(ThenV, ThenBB);
477477 PN->addIncoming(ElseV, ElseBB);
726726 // block.
727727 Function *TheFunction = Builder.GetInsertBlock()->getParent();
728728 BasicBlock *PreheaderBB = Builder.GetInsertBlock();
729 BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction);
729 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
730730
731731 // Insert an explicit fall through from the current block to the LoopBB.
732732 Builder.CreateBr(LoopBB);
744744 Builder.SetInsertPoint(LoopBB);
745745
746746 // Start the PHI node with an entry for Start.
747 PHINode *Variable = Builder.CreatePHI(Type::DoubleTy, VarName.c_str());
747 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
748748 Variable->addIncoming(StartVal, PreheaderBB);
749749
750750
827827

                  
                
828828 // Create the "after loop" block and insert it.
829829 BasicBlock *LoopEndBB = Builder.GetInsertBlock();
830 BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction);
830 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
831831
832832 // Insert the conditional branch into the end of LoopEndBB.
833833 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
855855 NamedValues.erase(VarName);
856856
857857 // for expr always returns 0.0.
858 return Constant::getNullValue(Type::DoubleTy);
858 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
859859 }
860860
861861
13801380 case '<':
13811381 L = Builder.CreateFCmpULT(L, R, "cmptmp");
13821382 // Convert bool 0/1 to double 0.0 or 1.0
1383 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
1383 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
13841384 default: return ErrorV("invalid binary operator");
13851385 }
13861386 }
14171417
14181418 // Create blocks for the then and else cases. Insert the 'then' block at the
14191419 // end of the function.
1420 BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction);
1421 BasicBlock *ElseBB = BasicBlock::Create("else");
1422 BasicBlock *MergeBB = BasicBlock::Create("ifcont");
1420 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
1421 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
1422 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
14231423
14241424 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
14251425
14471447 // Emit merge block.
14481448 TheFunction->getBasicBlockList().push_back(MergeBB);
14491449 Builder.SetInsertPoint(MergeBB);
1450 PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp");
1450 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp");
14511451
14521452 PN->addIncoming(ThenV, ThenBB);
14531453 PN->addIncoming(ElseV, ElseBB);
14791479 // block.
14801480 Function *TheFunction = Builder.GetInsertBlock()->getParent();
14811481 BasicBlock *PreheaderBB = Builder.GetInsertBlock();
1482 BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction);
1482 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
14831483
14841484 // Insert an explicit fall through from the current block to the LoopBB.
14851485 Builder.CreateBr(LoopBB);
14881488 Builder.SetInsertPoint(LoopBB);
14891489
14901490 // Start the PHI node with an entry for Start.
1491 PHINode *Variable = Builder.CreatePHI(Type::DoubleTy, VarName.c_str());
1491 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
14921492 Variable->addIncoming(StartVal, PreheaderBB);
14931493
14941494 // Within the loop, the variable is defined equal to the PHI node. If it
15251525
15261526 // Create the "after loop" block and insert it.
15271527 BasicBlock *LoopEndBB = Builder.GetInsertBlock();
1528 BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction);
1528 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
15291529
15301530 // Insert the conditional branch into the end of LoopEndBB.
15311531 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
15441544
15451545
15461546 // for expr always returns 0.0.
1547 return getGlobalContext().getNullValue(Type::DoubleTy);
1547 return getGlobalContext().getNullValue(Type::getDoubleTy(getGlobalContext()));
15481548 }
15491549
15501550 Function *PrototypeAST::Codegen() {
15511551 // Make the function type: double(double,double) etc.
1552 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1553 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
1552 std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
1553 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
15541554
15551555 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
15561556
15951595 return 0;
15961596
15971597 // Create a new basic block to start insertion into.
1598 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
1598 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
15991599 Builder.SetInsertPoint(BB);
16001600
16011601 if (Value *RetVal = Body->Codegen()) {
282282 case '<':
283283 L = Builder.CreateFCmpULT(L, R, "cmptmp");
284284 // Convert bool 0/1 to double 0.0 or 1.0
285 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
285 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
286286 default: break;
287287 }
288288
320320 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
321321
322322 // Create a new basic block to start insertion into.
323 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
323 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
324324 Builder.SetInsertPoint(BB);
325325
326326 if (Value *RetVal = Body->Codegen()) {
13971397 case '<':
13981398 L = Builder.CreateFCmpULT(L, R, "cmptmp");
13991399 // Convert bool 0/1 to double 0.0 or 1.0
1400 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
1400 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
14011401 default: break;
14021402 }
14031403
14421442
14431443 // Create blocks for the then and else cases. Insert the 'then' block at the
14441444 // end of the function.
1445 BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction);
1446 BasicBlock *ElseBB = BasicBlock::Create("else");
1447 BasicBlock *MergeBB = BasicBlock::Create("ifcont");
1445 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
1446 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
1447 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
14481448
14491449 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
14501450
14721472 // Emit merge block.
14731473 TheFunction->getBasicBlockList().push_back(MergeBB);
14741474 Builder.SetInsertPoint(MergeBB);
1475 PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp");
1475 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp");
14761476
14771477 PN->addIncoming(ThenV, ThenBB);
14781478 PN->addIncoming(ElseV, ElseBB);
15041504 // block.
15051505 Function *TheFunction = Builder.GetInsertBlock()->getParent();
15061506 BasicBlock *PreheaderBB = Builder.GetInsertBlock();
1507 BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction);
1507 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
15081508
15091509 // Insert an explicit fall through from the current block to the LoopBB.
15101510 Builder.CreateBr(LoopBB);
15131513 Builder.SetInsertPoint(LoopBB);
15141514
15151515 // Start the PHI node with an entry for Start.
1516 PHINode *Variable = Builder.CreatePHI(Type::DoubleTy, VarName.c_str());
1516 PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str());
15171517 Variable->addIncoming(StartVal, PreheaderBB);
15181518
15191519 // Within the loop, the variable is defined equal to the PHI node. If it
15501550
15511551 // Create the "after loop" block and insert it.
15521552 BasicBlock *LoopEndBB = Builder.GetInsertBlock();
1553 BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction);
1553 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
15541554
15551555 // Insert the conditional branch into the end of LoopEndBB.
15561556 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
15691569
15701570
15711571 // for expr always returns 0.0.
1572 return Constant::getNullValue(Type::DoubleTy);
1572 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
15731573 }
15741574
15751575 Function *PrototypeAST::Codegen() {
15761576 // Make the function type: double(double,double) etc.
1577 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1578 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
1577 std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
1578 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
15791579
15801580 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
15811581
16241624 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
16251625
16261626 // Create a new basic block to start insertion into.
1627 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
1627 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
16281628 Builder.SetInsertPoint(BB);
16291629
16301630 if (Value *RetVal = Body->Codegen()) {
423423 const std::string &VarName) {
424424 IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
425425 TheFunction->getEntryBlock().begin());
426 return TmpB.CreateAlloca(Type::DoubleTy, 0, VarName.c_str());
426 return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0, VarName.c_str());
427427 }
428428
429429
16171617 const std::string &VarName) {
16181618 IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
16191619 TheFunction->getEntryBlock().begin());
1620 return TmpB.CreateAlloca(Type::DoubleTy, 0, VarName.c_str());
1620 return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0, VarName.c_str());
16211621 }
16221622
16231623
16771677 case '<':
16781678 L = Builder.CreateFCmpULT(L, R, "cmptmp");
16791679 // Convert bool 0/1 to double 0.0 or 1.0
1680 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
1680 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp");
16811681 default: break;
16821682 }
16831683
17221722
17231723 // Create blocks for the then and else cases. Insert the 'then' block at the
17241724 // end of the function.
1725 BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction);
1726 BasicBlock *ElseBB = BasicBlock::Create("else");
1727 BasicBlock *MergeBB = BasicBlock::Create("ifcont");
1725 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
1726 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
1727 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
17281728
17291729 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
17301730
17521752 // Emit merge block.
17531753 TheFunction->getBasicBlockList().push_back(MergeBB);
17541754 Builder.SetInsertPoint(MergeBB);
1755 PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp");
1755 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp");
17561756
17571757 PN->addIncoming(ThenV, ThenBB);
17581758 PN->addIncoming(ElseV, ElseBB);
17951795 // Make the new basic block for the loop header, inserting after current
17961796 // block.
17971797 BasicBlock *PreheaderBB = Builder.GetInsertBlock();
1798 BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction);
1798 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
17991799
18001800 // Insert an explicit fall through from the current block to the LoopBB.
18011801 Builder.CreateBr(LoopBB);
18411841
18421842 // Create the "after loop" block and insert it.
18431843 BasicBlock *LoopEndBB = Builder.GetInsertBlock();
1844 BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction);
1844 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
18451845
18461846 // Insert the conditional branch into the end of LoopEndBB.
18471847 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
18571857
18581858
18591859 // for expr always returns 0.0.
1860 return Constant::getNullValue(Type::DoubleTy);
1860 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
18611861 }
18621862
18631863 Value *VarExprAST::Codegen() {
19091909
19101910 Function *PrototypeAST::Codegen() {
19111911 // Make the function type: double(double,double) etc.
1912 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1913 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
1912 std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
1913 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
19141914
19151915 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
19161916
19721972 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
19731973
19741974 // Create a new basic block to start insertion into.
1975 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
1975 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
19761976 Builder.SetInsertPoint(BB);
19771977
19781978 // Add all arguments to the symbol table and create their allocas.
5353 //Function prototypes
5454
5555 //declare void @llvm.memset.i32(i8 *, i8, i32, i32)
56 const Type *Tys[] = { Type::Int32Ty };
56 const Type *Tys[] = { Type::getInt32Ty(C) };
5757 Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset,
5858 Tys, 1);
5959
6060 //declare i32 @getchar()
6161 getchar_func = cast(module->
62 getOrInsertFunction("getchar", IntegerType::Int32Ty, NULL));
62 getOrInsertFunction("getchar", IntegerType::getInt32Ty(C), NULL));
6363
6464 //declare i32 @putchar(i32)
6565 putchar_func = cast(module->
66 getOrInsertFunction("putchar", IntegerType::Int32Ty,
67 IntegerType::Int32Ty, NULL));
66 getOrInsertFunction("putchar", IntegerType::getInt32Ty(C),
67 IntegerType::getInt32Ty(C), NULL));
6868
6969
7070 //Function header
7171
7272 //define void @brainf()
7373 brainf_func = cast(module->
74 getOrInsertFunction("brainf", Type::VoidTy, NULL));
75
76 builder = new IRBuilder<>(BasicBlock::Create(label, brainf_func));
74 getOrInsertFunction("brainf", Type::getVoidTy(C), NULL));
75
76 builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func));
7777
7878 //%arr = malloc i8, i32 %d
7979 ConstantInt *val_mem = ConstantInt::get(C, APInt(32, memtotal));
80 ptr_arr = builder->CreateMalloc(IntegerType::Int8Ty, val_mem, "arr");
80 ptr_arr = builder->CreateMalloc(IntegerType::getInt8Ty(C), val_mem, "arr");
8181
8282 //call void @llvm.memset.i32(i8 *%arr, i8 0, i32 %d, i32 1)
8383 {
109109 //Function footer
110110
111111 //brainf.end:
112 endbb = BasicBlock::Create(label, brainf_func);
112 endbb = BasicBlock::Create(C, label, brainf_func);
113113
114114 //free i8 *%arr
115115 new FreeInst(ptr_arr, endbb);
116116
117117 //ret void
118 ReturnInst::Create(endbb);
118 ReturnInst::Create(C, endbb);
119119
120120
121121
124124 {
125125 //@aberrormsg = internal constant [%d x i8] c"\00"
126126 Constant *msg_0 =
127 ConstantArray::get("Error: The head has left the tape.", true);
127 ConstantArray::get(C, "Error: The head has left the tape.", true);
128128
129129 GlobalVariable *aberrormsg = new GlobalVariable(
130130 *module,
136136
137137 //declare i32 @puts(i8 *)
138138 Function *puts_func = cast(module->
139 getOrInsertFunction("puts", IntegerType::Int32Ty,
140 PointerType::getUnqual(IntegerType::Int8Ty), NULL));
139 getOrInsertFunction("puts", IntegerType::getInt32Ty(C),
140 PointerType::getUnqual(IntegerType::getInt8Ty(C)), NULL));
141141
142142 //brainf.aberror:
143 aberrorbb = BasicBlock::Create(label, brainf_func);
143 aberrorbb = BasicBlock::Create(C, label, brainf_func);
144144
145145 //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
146146 {
147 Constant *zero_32 = Constant::getNullValue(IntegerType::Int32Ty);
147 Constant *zero_32 = Constant::getNullValue(IntegerType::getInt32Ty(C));
148148
149149 Constant *gep_params[] = {
150150 zero_32,
197197
198198 //%tape.%d = trunc i32 %tape.%d to i8
199199 Value *tape_1 = builder->
200 CreateTrunc(tape_0, IntegerType::Int8Ty, tapereg);
200 CreateTrunc(tape_0, IntegerType::getInt8Ty(C), tapereg);
201201
202202 //store i8 %tape.%d, i8 *%head.%d
203203 builder->CreateStore(tape_1, curhead);
211211
212212 //%tape.%d = sext i8 %tape.%d to i32
213213 Value *tape_1 = builder->
214 CreateSExt(tape_0, IntegerType::Int32Ty, tapereg);
214 CreateSExt(tape_0, IntegerType::getInt32Ty(C), tapereg);
215215
216216 //call i32 @putchar(i32 %tape.%d)
217217 Value *putchar_params[] = {
247247 CreateOr(test_0, test_1, testreg);
248248
249249 //br i1 %test.%d, label %main.%d, label %main.%d
250 BasicBlock *nextbb = BasicBlock::Create(label, brainf_func);
250 BasicBlock *nextbb = BasicBlock::Create(C, label, brainf_func);
251251 builder->CreateCondBr(test_2, aberrorbb, nextbb);
252252
253253 //main.%d:
273273 case SYM_LOOP:
274274 {
275275 //br label %main.%d
276 BasicBlock *testbb = BasicBlock::Create(label, brainf_func);
276 BasicBlock *testbb = BasicBlock::Create(C, label, brainf_func);
277277 builder->CreateBr(testbb);
278278
279279 //main.%d:
280280 BasicBlock *bb_0 = builder->GetInsertBlock();
281 BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func);
281 BasicBlock *bb_1 = BasicBlock::Create(C, label, brainf_func);
282282 builder->SetInsertPoint(bb_1);
283283
284284 // Make part of PHI instruction now, wait until end of loop to finish
285285 PHINode *phi_0 =
286 PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty),
286 PHINode::Create(PointerType::getUnqual(IntegerType::getInt8Ty(C)),
287287 headreg, testbb);
288288 phi_0->reserveOperandSpace(2);
289289 phi_0->addIncoming(curhead, bb_0);
431431 ConstantInt::get(C, APInt(8, 0)), testreg);
432432
433433 //br i1 %test.%d, label %main.%d, label %main.%d
434 BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
434 BasicBlock *bb_0 = BasicBlock::Create(C, label, brainf_func);
435435 BranchInst::Create(bb_0, oldbb, test_0, testbb);
436436
437437 //main.%d:
439439
440440 //%head.%d = phi i8 *[%head.%d, %main.%d]
441441 PHINode *phi_1 = builder->
442 CreatePHI(PointerType::getUnqual(IntegerType::Int8Ty), headreg);
442 CreatePHI(PointerType::getUnqual(IntegerType::getInt8Ty(C)), headreg);
443443 phi_1->reserveOperandSpace(1);
444444 phi_1->addIncoming(head_0, testbb);
445445 curhead = phi_1;
5757 void addMainFunction(Module *mod) {
5858 //define i32 @main(i32 %argc, i8 **%argv)
5959 Function *main_func = cast(mod->
60 getOrInsertFunction("main", IntegerType::Int32Ty, IntegerType::Int32Ty,
60 getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()),
61 IntegerType::getInt32Ty(mod->getContext()),
6162 PointerType::getUnqual(PointerType::getUnqual(
62 IntegerType::Int8Ty)), NULL));
63 IntegerType::getInt8Ty(mod->getContext()))), NULL));
6364 {
6465 Function::arg_iterator args = main_func->arg_begin();
6566 Value *arg_0 = args++;
6970 }
7071
7172 //main.0:
72 BasicBlock *bb = BasicBlock::Create("main.0", main_func);
73 BasicBlock *bb = BasicBlock::Create(mod->getContext(), "main.0", main_func);
7374
7475 //call void @brainf()
7576 {
7980 }
8081
8182 //ret i32 0
82 ReturnInst::Create(ConstantInt::get(getGlobalContext(), APInt(32, 0)), bb);
83 ReturnInst::Create(mod->getContext(),
84 ConstantInt::get(mod->getContext(), APInt(32, 0)), bb);
8385 }
8486
8587 int main(int argc, char **argv) {
3939 // Create the fib function and insert it into module M. This function is said
4040 // to return an int and take an int parameter.
4141 Function *FibF =
42 cast(M->getOrInsertFunction("fib", Type::Int32Ty, Type::Int32Ty,
42 cast(M->getOrInsertFunction("fib", Type::getInt32Ty(Context),
43 Type::getInt32Ty(Context),
4344 (Type *)0));
4445
4546 // Add a basic block to the function.
46 BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
47 BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF);
4748
4849 // Get pointers to the constants.
49 Value *One = ConstantInt::get(Type::Int32Ty, 1);
50 Value *Two = ConstantInt::get(Type::Int32Ty, 2);
50 Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1);
51 Value *Two = ConstantInt::get(Type::getInt32Ty(Context), 2);
5152
5253 // Get pointer to the integer argument of the add1 function...
5354 Argument *ArgX = FibF->arg_begin(); // Get the arg.
5455 ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
5556
5657 // Create the true_block.
57 BasicBlock *RetBB = BasicBlock::Create("return", FibF);
58 BasicBlock *RetBB = BasicBlock::Create(Context, "return", FibF);
5859 // Create an exit block.
59 BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
60 BasicBlock* RecurseBB = BasicBlock::Create(Context, "recurse", FibF);
6061
6162 // Create the "if (arg <= 2) goto exitbb"
6263 Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
6364 BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
6465
6566 // Create: ret int 1
66 ReturnInst::Create(One, RetBB);
67 ReturnInst::Create(Context, One, RetBB);
6768
6869 // create fib(x-1)
6970 Value *Sub = BinaryOperator::CreateSub(ArgX, One, "arg", RecurseBB);
8182 "addresult", RecurseBB);
8283
8384 // Create the return instruction and add it to the basic block
84 ReturnInst::Create(Sum, RecurseBB);
85 ReturnInst::Create(Context, Sum, RecurseBB);
8586
8687 return FibF;
8788 }
6060 // function will have a return type of "int" and take an argument of "int".
6161 // The '0' terminates the list of argument types.
6262 Function *Add1F =
63 cast(M->getOrInsertFunction("add1", Type::Int32Ty, Type::Int32Ty,
63 cast(M->getOrInsertFunction("add1", Type::getInt32Ty(Context),
64 Type::getInt32Ty(Context),
6465 (Type *)0));
6566
6667 // Add a basic block to the function. As before, it automatically inserts
6768 // because of the last argument.
68 BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
69 BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", Add1F);
6970
7071 // Get pointers to the constant `1'.
71 Value *One = ConstantInt::get(Type::Int32Ty, 1);
72 Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1);
7273
7374 // Get pointers to the integer argument of the add1 function...
7475 assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
7980 Instruction *Add = BinaryOperator::CreateAdd(One, ArgX, "addresult", BB);
8081
8182 // Create the return instruction and add it to the basic block
82 ReturnInst::Create(Add, BB);
83 ReturnInst::Create(Context, Add, BB);
8384
8485 // Now, function add1 is ready.
8586
8788 // Now we going to create function `foo', which returns an int and takes no
8889 // arguments.
8990 Function *FooF =
90 cast(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0));
91 cast(M->getOrInsertFunction("foo", Type::getInt32Ty(Context),
92 (Type *)0));
9193
9294 // Add a basic block to the FooF function.
93 BB = BasicBlock::Create("EntryBlock", FooF);
95 BB = BasicBlock::Create(Context, "EntryBlock", FooF);
9496
9597 // Get pointers to the constant `10'.
96 Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
98 Value *Ten = ConstantInt::get(Type::getInt32Ty(Context), 10);
9799
98100 // Pass Ten to the call call:
99101 CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB);
100102 Add1CallRes->setTailCall(true);
101103
102104 // Create the return instruction and add it to the basic block.
103 ReturnInst::Create(Add1CallRes, BB);
105 ReturnInst::Create(Context, Add1CallRes, BB);
104106
105107 // Now we create the JIT.
106108 ExecutionEngine* EE = EngineBuilder(M).create();
617617 const std::string &VarName) {
618618 IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
619619 TheFunction->getEntryBlock().begin());
620 return TmpB.CreateAlloca(Type::DoubleTy, 0, VarName.c_str());
620 return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0,
621 VarName.c_str());
621622 }
622623
623624
677678 case '<':
678679 L = Builder.CreateFCmpULT(L, R, "cmptmp");
679680 // Convert bool 0/1 to double 0.0 or 1.0
680 return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp");
681 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
682 "booltmp");
681683 default: break;
682684 }
683685
722724
723725 // Create blocks for the then and else cases. Insert the 'then' block at the
724726 // end of the function.
725 BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction);
726 BasicBlock *ElseBB = BasicBlock::Create("else");
727 BasicBlock *MergeBB = BasicBlock::Create("ifcont");
727 BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction);
728 BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else");
729 BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont");
728730
729731 Builder.CreateCondBr(CondV, ThenBB, ElseBB);
730732
752754 // Emit merge block.
753755 TheFunction->getBasicBlockList().push_back(MergeBB);
754756 Builder.SetInsertPoint(MergeBB);
755 PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp");
757 PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()),
758 "iftmp");
756759
757760 PN->addIncoming(ThenV, ThenBB);
758761 PN->addIncoming(ElseV, ElseBB);
794797
795798 // Make the new basic block for the loop header, inserting after current
796799 // block.
797 BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction);
800 BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction);
798801
799802 // Insert an explicit fall through from the current block to the LoopBB.
800803 Builder.CreateBr(LoopBB);
839842 "loopcond");
840843
841844 // Create the "after loop" block and insert it.
842 BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction);
845 BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction);
843846
844847 // Insert the conditional branch into the end of LoopEndBB.
845848 Builder.CreateCondBr(EndCond, LoopBB, AfterBB);
855858
856859
857860 // for expr always returns 0.0.
858 return Constant::getNullValue(Type::DoubleTy);
861 return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));
859862 }
860863
861864 Value *VarExprAST::Codegen() {
907910
908911 Function *PrototypeAST::Codegen() {
909912 // Make the function type: double(double,double) etc.
910 std::vector Doubles(Args.size(), Type::DoubleTy);
911 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
913 std::vector Doubles(Args.size(),
914 Type::getDoubleTy(getGlobalContext()));
915 FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
916 Doubles, false);
912917
913918 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
914919
970975 BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();
971976
972977 // Create a new basic block to start insertion into.
973 BasicBlock *BB = BasicBlock::Create("entry", TheFunction);
978 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
974979 Builder.SetInsertPoint(BB);
975980
976981 // Add all arguments to the symbol table and create their allocas.
3030
3131 // Create the main function: first create the type 'int ()'
3232 FunctionType *FT =
33 FunctionType::get(Type::Int32Ty, /*not vararg*/false);
33 FunctionType::get(Type::getInt32Ty(Context), /*not vararg*/false);
3434
3535 // By passing a module as the last parameter to the Function constructor,
3636 // it automatically gets appended to the Module.
3838
3939 // Add a basic block to the function... again, it automatically inserts
4040 // because of the last argument.
41 BasicBlock *BB = BasicBlock::Create("EntryBlock", F);
41 BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", F);
4242
4343 // Get pointers to the constant integers...
44 Value *Two = ConstantInt::get(Type::Int32Ty, 2);
45 Value *Three = ConstantInt::get(Type::Int32Ty, 3);
44 Value *Two = ConstantInt::get(Type::getInt32Ty(Context), 2);
45 Value *Three = ConstantInt::get(Type::getInt32Ty(Context), 3);
4646
4747 // Create the add instruction... does not insert...
4848 Instruction *Add = BinaryOperator::Create(Instruction::Add, Two, Three,
5252 BB->getInstList().push_back(Add);
5353
5454 // Create the return instruction and add it to the basic block
55 BB->getInstList().push_back(ReturnInst::Create(Add));
55 BB->getInstList().push_back(ReturnInst::Create(Context, Add));
5656
5757 // Output the bitcode file to stdout
5858 WriteBitcodeToFile(M, std::cout);
3535 // function will have a return type of "int" and take an argument of "int".
3636 // The '0' terminates the list of argument types.
3737 Function *Add1F =
38 cast(M->getOrInsertFunction("add1", Type::Int32Ty, Type::Int32Ty,
38 cast(M->getOrInsertFunction("add1",
39 Type::getInt32Ty(M->getContext()),
40 Type::getInt32Ty(M->getContext()),
3941 (Type *)0));
4042
4143 // Add a basic block to the function. As before, it automatically inserts
4244 // because of the last argument.
43 BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
45 BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", Add1F);
4446
4547 // Get pointers to the constant `1'.
46 Value *One = ConstantInt::get(Type::Int32Ty, 1);
48 Value *One = ConstantInt::get(Type::getInt32Ty(M->getContext()), 1);
4749
4850 // Get pointers to the integer argument of the add1 function...
4951 assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
5456 Instruction *Add = BinaryOperator::CreateAdd(One, ArgX, "addresult", BB);
5557
5658 // Create the return instruction and add it to the basic block
57 ReturnInst::Create(Add, BB);
59 ReturnInst::Create(M->getContext(), Add, BB);
5860
5961 // Now, function add1 is ready.
6062 return Add1F;
6466 // Create the fib function and insert it into module M. This function is said
6567 // to return an int and take an int parameter.
6668 Function *FibF =
67 cast(M->getOrInsertFunction("fib", Type::Int32Ty, Type::Int32Ty,
69 cast(M->getOrInsertFunction("fib",
70 Type::getInt32Ty(M->getContext()),
71 Type::getInt32Ty(M->getContext()),
6872 (Type *)0));
6973
7074 // Add a basic block to the function.
71 BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
75 BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF);
7276
7377 // Get pointers to the constants.
74 Value *One = ConstantInt::get(Type::Int32Ty, 1);
75 Value *Two = ConstantInt::get(Type::Int32Ty, 2);
78 Value *One = ConstantInt::get(Type::getInt32Ty(M->getContext()), 1);
79 Value *Two = ConstantInt::get(Type::getInt32Ty(M->getContext()), 2);
7680
7781 // Get pointer to the integer argument of the add1 function...
7882 Argument *ArgX = FibF->arg_begin(); // Get the arg.
7983 ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
8084
8185 // Create the true_block.
82 BasicBlock *RetBB = BasicBlock::Create("return", FibF);
86 BasicBlock *RetBB = BasicBlock::Create(M->getContext(), "return", FibF);
8387 // Create an exit block.
84 BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
88 BasicBlock* RecurseBB = BasicBlock::Create(M->getContext(), "recurse", FibF);
8589
8690 // Create the "if (arg < 2) goto exitbb"
8791 Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
8892 BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
8993
9094 // Create: ret int 1
91 ReturnInst::Create(One, RetBB);
95 ReturnInst::Create(M->getContext(), One, RetBB);
9296
9397 // create fib(x-1)
9498 Value *Sub = BinaryOperator::CreateSub(ArgX, One, "arg", RecurseBB);
103107 BinaryOperator::CreateAdd(CallFibX1, CallFibX2, "addresult", RecurseBB);
104108
105109 // Create the return instruction and add it to the basic block
106 ReturnInst::Create(Sum, RecurseBB);
110 ReturnInst::Create(M->getContext(), Sum, RecurseBB);
107111
108112 return FibF;
109113 }
8282 /// is automatically inserted at either the end of the function (if
8383 /// InsertBefore is null), or before the specified basic block.
8484 ///
85 explicit BasicBlock(const Twine &Name = "", Function *Parent = 0,
86 BasicBlock *InsertBefore = 0);
85 explicit BasicBlock(LLVMContext &C, const Twine &Name = "",
86 Function *Parent = 0, BasicBlock *InsertBefore = 0);
8787 public:
8888 /// getContext - Get the context in which this basic block lives,
8989 /// or null if it is not currently attached to a function.
9696 /// Create - Creates a new BasicBlock. If the Parent parameter is specified,
9797 /// the basic block is automatically inserted at either the end of the
9898 /// function (if InsertBefore is 0), or before the specified basic block.
99 static BasicBlock *Create(const Twine &Name = "", Function *Parent = 0,
100 BasicBlock *InsertBefore = 0) {
101 return new BasicBlock(Name, Parent, InsertBefore);
99 static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "",
100 Function *Parent = 0,BasicBlock *InsertBefore = 0) {
101 return new BasicBlock(Context, Name, Parent, InsertBefore);
102102 }
103103 ~BasicBlock();
104104
345345 /// of the array by one (you've been warned). However, in some situations
346346 /// this is not desired so if AddNull==false then the string is copied without
347347 /// null termination.
348 static Constant* get(const StringRef &Initializer, bool AddNull = true);
348 static Constant* get(LLVMContext &Context, const StringRef &Initializer,
349 bool AddNull = true);
349350
350351 /// Transparently provide more efficient getOperand methods.
351352 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
101101 /// that instance will be returned. Otherwise a new one will be created. Only
102102 /// one instance with a given NumBits value is ever created.
103103 /// @brief Get or create an IntegerType instance.
104 static const IntegerType* get(unsigned NumBits);
104 static const IntegerType* get(LLVMContext &C, unsigned NumBits);
105105
106106 /// @brief Get the number of bits in this IntegerType
107107 unsigned getBitWidth() const { return getSubclassData(); }
398398 ///
399399 static VectorType *getInteger(const VectorType *VTy) {
400400 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
401 const Type *EltTy = IntegerType::get(EltBits);
401 const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
402402 return VectorType::get(EltTy, VTy->getNumElements());
403403 }
404404
408408 ///
409409 static VectorType *getExtendedElementVectorType(const VectorType *VTy) {
410410 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
411 const Type *EltTy = IntegerType::get(EltBits * 2);
411 const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
412412 return VectorType::get(EltTy, VTy->getNumElements());
413413 }
414414
420420 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
421421 assert((EltBits & 1) == 0 &&
422422 "Cannot truncate vector element with odd bit-width");
423 const Type *EltTy = IntegerType::get(EltBits / 2);
423 const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
424424 return VectorType::get(EltTy, VTy->getNumElements());
425425 }
426426
707707 /// @brief Create a result type for fcmp/icmp
708708 static const Type* makeCmpResultType(const Type* opnd_type) {
709709 if (const VectorType* vt = dyn_cast(opnd_type)) {
710 return VectorType::get(Type::Int1Ty, vt->getNumElements());
710 return VectorType::get(Type::getInt1Ty(opnd_type->getContext()),
711 vt->getNumElements());
711712 }
712 return Type::Int1Ty;
713 return Type::getInt1Ty(opnd_type->getContext());
713714 }
714715 };
715716
20242024 //
20252025 // NOTE: If the Value* passed is of type void then the constructor behaves as
20262026 // if it was passed NULL.
2027 explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0);
2028 ReturnInst(Value *retVal, BasicBlock *InsertAtEnd);
2029 explicit ReturnInst(BasicBlock *InsertAtEnd);
2030 public:
2031 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
2032 return new(!!retVal) ReturnInst(retVal, InsertBefore);
2033 }
2034 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
2035 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
2036 }
2037 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
2038 return new(0) ReturnInst(InsertAtEnd);
2027 explicit ReturnInst(LLVMContext &C, Value *retVal = 0,
2028 Instruction *InsertBefore = 0);
2029 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
2030 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
2031 public:
2032 static ReturnInst* Create(LLVMContext &C, Value *retVal = 0,
2033 Instruction *InsertBefore = 0) {
2034 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
2035 }
2036 static ReturnInst* Create(LLVMContext &C, Value *retVal,
2037 BasicBlock *InsertAtEnd) {
2038 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
2039 }
2040 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
2041 return new(0) ReturnInst(C, InsertAtEnd);
20392042 }
20402043 virtual ~ReturnInst();
20412044
25902593 void *operator new(size_t s) {
25912594 return User::operator new(s, 0);
25922595 }
2593 explicit UnwindInst(Instruction *InsertBefore = 0);
2594 explicit UnwindInst(BasicBlock *InsertAtEnd);
2596 explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0);
2597 explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd);
25952598
25962599 virtual UnwindInst *clone(LLVMContext &Context) const;
25972600
26272630 void *operator new(size_t s) {
26282631 return User::operator new(s, 0);
26292632 }
2630 explicit UnreachableInst(Instruction *InsertBefore = 0);
2631 explicit UnreachableInst(BasicBlock *InsertAtEnd);
2633 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0);
2634 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
26322635
26332636 virtual UnreachableInst *clone(LLVMContext &Context) const;
26342637
2424 /// LLVMContext itself provides no locking guarantees, so you should be careful
2525 /// to have one context per thread.
2626 class LLVMContext {
27 // DO NOT IMPLEMENT
28 LLVMContext(LLVMContext&);
29 void operator=(LLVMContext&);
2730 public:
2831 LLVMContextImpl* pImpl;
2932 bool RemoveDeadMetadata();
4545 if (std::getenv("bar") != (char*) -1)
4646 return;
4747 llvm::Module* M = new llvm::Module("", llvm::getGlobalContext());
48 (void)new llvm::UnreachableInst();
48 (void)new llvm::UnreachableInst(llvm::getGlobalContext());
4949 (void) llvm::createVerifierPass();
5050 (void) new llvm::Mangler(*M,"");
5151 }
4343
4444 void resizeOperands(unsigned NumOps);
4545 public:
46 /// getType() specialization - Type is always MetadataTy.
47 ///
48 inline const Type *getType() const {
49 return Type::MetadataTy;
50 }
51
5246 /// isNullValue - Return true if this is the value that would be returned by
5347 /// getNullValue. This always returns false because getNullValue will never
5448 /// produce metadata.
7569
7670 StringRef Str;
7771 protected:
78 explicit MDString(const char *begin, unsigned l)
79 : MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
72 explicit MDString(LLVMContext &C, const char *begin, unsigned l)
73 : MetadataBase(Type::getMetadataTy(C), Value::MDStringVal), Str(begin, l) {}
8074
8175 public:
8276 // Do not allocate any space for operands.
118112
119113 friend struct ConstantCreator >;
120114 protected:
121 explicit MDNode(Value*const* Vals, unsigned NumVals);
115 explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
122116 public:
123117 // Do not allocate any space for operands.
124118 void *operator new(size_t s) {
155149 elem_iterator elem_begin() { return Node.begin(); }
156150 elem_iterator elem_end() { return Node.end(); }
157151
158 /// getType() specialization - Type is always MetadataTy.
159 ///
160 inline const Type *getType() const {
161 return Type::MetadataTy;
162 }
163
164152 /// isNullValue - Return true if this is the value that would be returned by
165153 /// getNullValue. This always returns false because getNullValue will never
166154 /// produce metadata.
216204 typedef SmallVectorImpl::iterator elem_iterator;
217205
218206 protected:
219 explicit NamedMDNode(const Twine &N, MetadataBase*const* Vals,
207 explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const* Vals,
220208 unsigned NumVals, Module *M = 0);
221209 public:
222210 // Do not allocate any space for operands.
223211 void *operator new(size_t s) {
224212 return User::operator new(s, 0);
225213 }
226 static NamedMDNode *Create(const Twine &N, MetadataBase*const*MDs,
214 static NamedMDNode *Create(LLVMContext &C, const Twine &N,
215 MetadataBase*const*MDs,
227216 unsigned NumMDs, Module *M = 0) {
228 return new NamedMDNode(N, MDs, NumMDs, M);
217 return new NamedMDNode(C, N, MDs, NumMDs, M);
229218 }
230219
231220 static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0);
270259 elem_iterator elem_begin() { return Node.begin(); }
271260 elem_iterator elem_end() { return Node.end(); }
272261
273 /// getType() specialization - Type is always MetadataTy.
274 ///
275 inline const Type *getType() const {
276 return Type::MetadataTy;
277 }
278
279262 /// isNullValue - Return true if this is the value that would be returned by
280263 /// getNullValue. This always returns false because getNullValue will never
281264 /// produce metadata.
128128
129129 /// CreateRetVoid - Create a 'ret void' instruction.
130130 ReturnInst *CreateRetVoid() {
131 return Insert(ReturnInst::Create());
131 return Insert(ReturnInst::Create(getGlobalContext()));
132132 }
133133
134134 /// @verbatim
135135 /// CreateRet - Create a 'ret ' instruction.
136136 /// @endverbatim
137137 ReturnInst *CreateRet(Value *V) {
138 return Insert(ReturnInst::Create(V));
138 return Insert(ReturnInst::Create(getGlobalContext(), V));
139139 }
140140
141141 /// CreateAggregateRet - Create a sequence of N insertvalue instructions,
150150 Value *V = UndefValue::get(RetType);
151151 for (unsigned i = 0; i != N; ++i)
152152 V = CreateInsertValue(V, retVals[i], i, "mrv");
153 return Insert(ReturnInst::Create(V));
153 return Insert(ReturnInst::Create(getGlobalContext(), V));
154154 }
155155
156156 /// CreateBr - Create an unconditional 'br label X' instruction.
181181 }
182182
183183 UnwindInst *CreateUnwind() {
184 return Insert(new UnwindInst());
184 return Insert(new UnwindInst(Context));
185185 }
186186
187187 UnreachableInst *CreateUnreachable() {
188 return Insert(new UnreachableInst());
188 return Insert(new UnreachableInst(Context));
189189 }
190190
191191 //===--------------------------------------------------------------------===//
405405 return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name);
406406 }
407407 Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
408 Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
408 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
409409
410410 if (Constant *PC = dyn_cast(Ptr))
411411 return Folder.CreateGetElementPtr(PC, &Idx, 1);
414414 }
415415 Value *CreateConstInBoundsGEP1_32(Value *Ptr, unsigned Idx0,
416416 const char *Name = "") {
417 Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
417 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
418418
419419 if (Constant *PC = dyn_cast(Ptr))
420420 return Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1);
424424 Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
425425 const char *Name = "") {
426426 Value *Idxs[] = {
427 ConstantInt::get(Type::Int32Ty, Idx0),
428 ConstantInt::get(Type::Int32Ty, Idx1)
427 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
428 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
429429 };
430430
431431 if (Constant *PC = dyn_cast(Ptr))
436436 Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
437437 const char *Name = "") {
438438 Value *Idxs[] = {
439 ConstantInt::get(Type::Int32Ty, Idx0),
440 ConstantInt::get(Type::Int32Ty, Idx1)
439 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
440 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
441441 };
442442
443443 if (Constant *PC = dyn_cast(Ptr))
446446 return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name);
447447 }
448448 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
449 Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
449 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
450450
451451 if (Constant *PC = dyn_cast(Ptr))
452452 return Folder.CreateGetElementPtr(PC, &Idx, 1);
455455 }
456456 Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
457457 const char *Name = "") {
458 Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
458 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
459459
460460 if (Constant *PC = dyn_cast(Ptr))
461461 return Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1);
465465 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
466466 const char *Name = "") {
467467 Value *Idxs[] = {
468 ConstantInt::get(Type::Int64Ty, Idx0),
469 ConstantInt::get(Type::Int64Ty, Idx1)
468 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
469 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
470470 };
471471
472472 if (Constant *PC = dyn_cast(Ptr))
477477 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
478478 const char *Name = "") {
479479 Value *Idxs[] = {
480 ConstantInt::get(Type::Int64Ty, Idx0),
481 ConstantInt::get(Type::Int64Ty, Idx1)
480 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
481 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
482482 };
483483
484484 if (Constant *PC = dyn_cast(Ptr))
490490 return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name);
491491 }
492492 Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
493 Constant *StrConstant = ConstantArray::get(Str, true);
493 Constant *StrConstant = ConstantArray::get(Context, Str, true);
494494 Module &M = *BB->getParent()->getParent();
495495 GlobalVariable *gv = new GlobalVariable(M,
496496 StrConstant->getType(),
505505 }
506506 Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
507507 Value *gv = CreateGlobalString(Str, Name);
508 Value *zero = ConstantInt::get(Type::Int32Ty, 0);
508 Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
509509 Value *Args[] = { zero, zero };
510510 return CreateInBoundsGEP(gv, Args, Args+2, Name);
511511 }
801801 assert(LHS->getType() == RHS->getType() &&
802802 "Pointer subtraction operand types must match!");
803803 const PointerType *ArgType = cast(LHS->getType());
804 Value *LHS_int = CreatePtrToInt(LHS, Type::Int64Ty);
805 Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
804 Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
805 Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
806806 Value *Difference = CreateSub(LHS_int, RHS_int);
807807 return CreateExactSDiv(Difference,
808808 ConstantExpr::getSizeOf(ArgType->getElementType()),
160160 public: \
161161 static const IntegerType *get(LLVMContext &Context) { \
162162 static const IntegerType *const result = \
163 IntegerType::get(sizeof(T) * CHAR_BIT); \
163 IntegerType::get(Context, sizeof(T) * CHAR_BIT); \
164164 return result; \
165165 } \
166166 }; \
189189 template
190190 class TypeBuilder, cross> {
191191 public:
192 static const IntegerType *get(LLVMContext &Context) {
193 static const IntegerType *const result = IntegerType::get(num_bits);
192 static const IntegerType *get(LLVMContext &C) {
193 static const IntegerType *const result = IntegerType::get(C, num_bits);
194194 return result;
195195 }
196196 };
197197
198198 template<> class TypeBuilder {
199199 public:
200 static const Type *get(LLVMContext&) {
201 return Type::FloatTy;
200 static const Type *get(LLVMContext& C) {
201 return Type::getFloatTy(C);
202202 }
203203 };
204204 template<> class TypeBuilder {};
205205
206206 template<> class TypeBuilder {
207207 public:
208 static const Type *get(LLVMContext&) {
209 return Type::DoubleTy;
208 static const Type *get(LLVMContext& C) {
209 return Type::getDoubleTy(C);
210210 }
211211 };
212212 template<> class TypeBuilder {};
213213
214214 template class TypeBuilder {
215215 public:
216 static const Type *get(LLVMContext&) { return Type::FloatTy; }
216 static const Type *get(LLVMContext& C) { return Type::getFloatTy(C); }
217217 };
218218 template class TypeBuilder {
219219 public:
220 static const Type *get(LLVMContext&) { return Type::DoubleTy; }
220 static const Type *get(LLVMContext& C) { return Type::getDoubleTy(C); }
221221 };
222222 template class TypeBuilder {
223223 public:
224 static const Type *get(LLVMContext&) { return Type::X86_FP80Ty; }
224 static const Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); }
225225 };
226226 template class TypeBuilder {
227227 public:
228 static const Type *get(LLVMContext&) { return Type::FP128Ty; }
228 static const Type *get(LLVMContext& C) { return Type::getFP128Ty(C); }
229229 };
230230 template class TypeBuilder {
231231 public:
232 static const Type *get(LLVMContext&) { return Type::PPC_FP128Ty; }
232 static const Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); }
233233 };
234234
235235 template class TypeBuilder {
236236 public:
237 static const Type *get(LLVMContext&) {
238 return Type::VoidTy;
237 static const Type *get(LLVMContext &C) {
238 return Type::getVoidTy(C);
239239 }
240240 };
241241
3333 class StructType;
3434 class StructLayout;
3535 class GlobalVariable;
36 class LLVMContext;
3637
3738 /// Enum used to categorize the alignment types stored by TargetAlignElem
3839 enum AlignTypeEnum {
228229 /// getIntPtrType - Return an unsigned integer type that is the same size or
229230 /// greater to the host pointer size.
230231 ///
231 const IntegerType *getIntPtrType() const;
232 const IntegerType *getIntPtrType(LLVMContext &C) const;
232233
233234 /// getIndexedOffset - return the offset from the beginning of the type for
234235 /// the specified indices. This is used to implement getelementptr.
305305 /// getVAArgsPromotedType - Return the type an argument of this type
306306 /// will be promoted to if passed through a variable argument
307307 /// function.
308 const Type *getVAArgsPromotedType() const;
308 const Type *getVAArgsPromotedType(LLVMContext &C) const;
309309
310310 /// getScalarType - If this is a vector type, return the element type,
311311 /// otherwise return this.
337337 //
338338
339339 /// getPrimitiveType - Return a type based on an identifier.
340 static const Type *getPrimitiveType(TypeID IDNumber);
340 static const Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber);
341341
342342 //===--------------------------------------------------------------------===//
343343 // These are the builtin types that are always available...
344344 //
345 static const Type *VoidTy, *LabelTy, *FloatTy, *DoubleTy, *MetadataTy;
346 static const Type *X86_FP80Ty, *FP128Ty, *PPC_FP128Ty;
347 static const IntegerType *Int1Ty, *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
345 static const Type *getVoidTy(LLVMContext &C);
346 static const Type *getLabelTy(LLVMContext &C);
347 static const Type *getFloatTy(LLVMContext &C);
348 static const Type *getDoubleTy(LLVMContext &C);
349 static const Type *getMetadataTy(LLVMContext &C);
350 static const Type *getX86_FP80Ty(LLVMContext &C);
351 static const Type *getFP128Ty(LLVMContext &C);
352 static const Type *getPPC_FP128Ty(LLVMContext &C);
353 static const IntegerType *getInt1Ty(LLVMContext &C);
354 static const IntegerType *getInt8Ty(LLVMContext &C);
355 static const IntegerType *getInt16Ty(LLVMContext &C);
356 static const IntegerType *getInt32Ty(LLVMContext &C);
357 static const IntegerType *getInt64Ty(LLVMContext &C);
348358
349359 /// Methods for support type inquiry through isa, cast, and dyn_cast:
350360 static inline bool classof(const Type *) { return true; }
501501 if (Constant *C1 = dyn_cast(V1))
502502 if (Constant *C2 = dyn_cast(V2)) {
503503 // Sign extend the constants to long types, if necessary
504 if (C1->getType() != Type::Int64Ty)
505 C1 = ConstantExpr::getSExt(C1, Type::Int64Ty);
506 if (C2->getType() != Type::Int64Ty)
507 C2 = ConstantExpr::getSExt(C2, Type::Int64Ty);
504 if (C1->getType() != Type::getInt64Ty(Context))
505 C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(Context));
506 if (C2->getType() != Type::getInt64Ty(Context))
507 C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(Context));
508508 return C1 == C2;
509509 }
510510 return false;
599599 if (Constant *G2OC = dyn_cast(const_cast(G2Oper))){
600600 if (G1OC->getType() != G2OC->getType()) {
601601 // Sign extend both operands to long.
602 if (G1OC->getType() != Type::Int64Ty)
603 G1OC = ConstantExpr::getSExt(G1OC, Type::Int64Ty);
604 if (G2OC->getType() != Type::Int64Ty)
605 G2OC = ConstantExpr::getSExt(G2OC, Type::Int64Ty);
602 if (G1OC->getType() != Type::getInt64Ty(Context))
603 G1OC = ConstantExpr::getSExt(G1OC, Type::getInt64Ty(Context));
604 if (G2OC->getType() != Type::getInt64Ty(Context))
605 G2OC = ConstantExpr::getSExt(G2OC, Type::getInt64Ty(Context));
606606 GEP1Ops[FirstConstantOper] = G1OC;
607607 GEP2Ops[FirstConstantOper] = G2OC;
608608 }
737737 const Type *ZeroIdxTy = GEPPointerTy;
738738 for (unsigned i = 0; i != FirstConstantOper; ++i) {
739739 if (!isa(ZeroIdxTy))
740 GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty);
740 GEP1Ops[i] = GEP2Ops[i] =
741 Constant::getNullValue(Type::getInt32Ty(Context));
741742
742743 if (const CompositeType *CT = dyn_cast(ZeroIdxTy))
743744 ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]);
779780 //
780781 if (const ArrayType *AT = dyn_cast(BasePtr1Ty))
781782 GEP1Ops[i] =
782 ConstantInt::get(Type::Int64Ty,AT->getNumElements()-1);
783 ConstantInt::get(Type::getInt64Ty(Context),
784 AT->getNumElements()-1);
783785 else if (const VectorType *VT = dyn_cast(BasePtr1Ty))
784786 GEP1Ops[i] =
785 ConstantInt::get(Type::Int64Ty,VT->getNumElements()-1);
787 ConstantInt::get(Type::getInt64Ty(Context),
788 VT->getNumElements()-1);
786789 }
787790 }
788791
5353 // its return value and doesn't unwind (a readonly function can leak bits
5454 // by throwing an exception or not depending on the input value).
5555 if (CS.onlyReadsMemory() && CS.doesNotThrow() &&
56 I->getType() == Type::VoidTy)
56 I->getType() == Type::getVoidTy(V->getContext()))
5757 break;
5858
5959 // Not captured if only passed via 'nocapture' arguments. Note that
150150
151151 uint64_t Offset = TD->getIndexedOffset(Ptr->getType(),
152152 (Value**)Ops+1, NumOps-1);
153 Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset+BasePtr);
153 Constant *C = ConstantInt::get(TD->getIntPtrType(Context), Offset+BasePtr);
154154 return ConstantExpr::getIntToPtr(C, ResultTy);
155155 }
156156
184184 // Fold to an vector of integers with same size as our FP type.
185185 unsigned FPWidth = DstEltTy->getPrimitiveSizeInBits();
186186 const Type *DestIVTy = VectorType::get(
187 IntegerType::get(FPWidth), NumDstElt);
187 IntegerType::get(Context, FPWidth), NumDstElt);
188188 // Recursively handle this integer conversion, if possible.
189189 C = FoldBitCast(C, DestIVTy, TD, Context);
190190 if (!C) return 0;
198198 if (SrcEltTy->isFloatingPoint()) {
199199 unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits();
200200 const Type *SrcIVTy = VectorType::get(
201 IntegerType::get(FPWidth), NumSrcElt);
201 IntegerType::get(Context, FPWidth), NumSrcElt);
202202 // Ask VMCore to do the conversion now that #elts line up.
203203 C = ConstantExpr::getBitCast(C, SrcIVTy);
204204 CV = dyn_cast(C);
479479 // around to know if bit truncation is happening.
480480 if (ConstantExpr *CE0 = dyn_cast(Ops[0])) {
481481 if (TD && Ops[1]->isNullValue()) {
482 const Type *IntPtrTy = TD->getIntPtrType();
482 const Type *IntPtrTy = TD->getIntPtrType(Context);
483483 if (CE0->getOpcode() == Instruction::IntToPtr) {
484484 // Convert the integer value to the right size to ensure we get the
485485 // proper extension or truncation.
504504
505505 if (ConstantExpr *CE1 = dyn_cast(Ops[1])) {
506506 if (TD && CE0->getOpcode() == CE1->getOpcode()) {
507 const Type *IntPtrTy = TD->getIntPtrType();
507 const Type *IntPtrTy = TD->getIntPtrType(Context);
508508
509509 if (CE0->getOpcode() == Instruction::IntToPtr) {
510510 // Convert the integer value to the right size to ensure we get the
653653 return 0;
654654 }
655655
656 if (Ty == Type::FloatTy)
656 if (Ty == Type::getFloatTy(Context))
657657 return ConstantFP::get(Context, APFloat((float)V));
658 if (Ty == Type::DoubleTy)
658 if (Ty == Type::getDoubleTy(Context))
659659 return ConstantFP::get(Context, APFloat(V));
660660 llvm_unreachable("Can only constant fold float/double");
661661 return 0; // dummy return to suppress warning
672672 return 0;
673673 }
674674
675 if (Ty == Type::FloatTy)
675 if (Ty == Type::getFloatTy(Context))
676676 return ConstantFP::get(Context, APFloat((float)V));
677 if (Ty == Type::DoubleTy)
677 if (Ty == Type::getDoubleTy(Context))
678678 return ConstantFP::get(Context, APFloat(V));
679679 llvm_unreachable("Can only constant fold float/double");
680680 return 0; // dummy return to suppress warning
693693 const Type *Ty = F->getReturnType();
694694 if (NumOperands == 1) {
695695 if (ConstantFP *Op = dyn_cast(Operands[0])) {
696 if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy)
696 if (Ty!=Type::getFloatTy(F->getContext()) &&
697 Ty!=Type::getDoubleTy(Context))
697698 return 0;
698699 /// Currently APFloat versions of these functions do not exist, so we use
699700 /// the host native double versions. Float versions are not called
700701 /// directly but for all these it is true (float)(f((double)arg)) ==
701702 /// f(arg). Long double not supported yet.
702 double V = Ty==Type::FloatTy ? (double)Op->getValueAPF().convertToFloat():
703 double V = Ty==Type::getFloatTy(F->getContext()) ?
704 (double)Op->getValueAPF().convertToFloat():
703705 Op->getValueAPF().convertToDouble();
704706 switch (Name[0]) {
705707 case 'a':
776778 }
777779 } else if (NumOperands == 2) {
778780 if (ConstantFP *Op1 = dyn_cast(Operands[0])) {
779 if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy)
781 if (Ty!=Type::getFloatTy(F->getContext()) &&
782 Ty!=Type::getDoubleTy(Context))
780783 return 0;
781 double Op1V = Ty==Type::FloatTy ?
784 double Op1V = Ty==Type::getFloatTy(F->getContext()) ?
782785 (double)Op1->getValueAPF().convertToFloat():
783786 Op1->getValueAPF().convertToDouble();
784787 if (ConstantFP *Op2 = dyn_cast(Operands[1])) {
785 double Op2V = Ty==Type::FloatTy ?
788 double Op2V = Ty==Type::getFloatTy(F->getContext()) ?
786789 (double)Op2->getValueAPF().convertToFloat():
787790 Op2->getValueAPF().convertToDouble();
788791
482482 Constant *DIFactory::GetTagConstant(unsigned TAG) {
483483 assert((TAG & LLVMDebugVersionMask) == 0 &&
484484 "Tag too large for debug encoding!");
485 return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion);
485 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
486486 }
487487
488488 Constant *DIFactory::GetStringConstant(const std::string &String) {
492492 // Return Constant if previously defined.
493493 if (Slot) return Slot;
494494
495 const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty);
495 const PointerType *DestTy = PointerType::getUnqual(Type::getInt8Ty(VMContext));
496496
497497 // If empty string then use a i8* null instead.
498498 if (String.empty())
499499 return Slot = ConstantPointerNull::get(DestTy);
500500
501501 // Construct string as an llvm constant.
502 Constant *ConstStr = ConstantArray::get(String);
502 Constant *ConstStr = ConstantArray::get(VMContext, String);
503503
504504 // Otherwise create and return a new string global.
505505 GlobalVariable *StrGV = new GlobalVariable(M, ConstStr->getType(), true,
541541 DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
542542 Constant *Elts[] = {
543543 GetTagConstant(dwarf::DW_TAG_subrange_type),
544 ConstantInt::get(Type::Int64Ty, Lo),
545 ConstantInt::get(Type::Int64Ty, Hi)
544 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
545 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
546546 };
547547
548548 Constant *Init = ConstantStruct::get(VMContext, Elts,
577577 Constant *Elts[] = {
578578 GetTagConstant(dwarf::DW_TAG_compile_unit),
579579 llvm::Constant::getNullValue(EmptyStructPtr),
580 ConstantInt::get(Type::Int32Ty, LangID),
580 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
581581 GetStringConstant(Filename),
582582 GetStringConstant(Directory),
583583 GetStringConstant(Producer),
584 ConstantInt::get(Type::Int1Ty, isMain),
585 ConstantInt::get(Type::Int1Ty, isOptimized),
584 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
585 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
586586 GetStringConstant(Flags),
587 ConstantInt::get(Type::Int32Ty, RunTimeVer)
587 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
588588 };
589589
590590 Constant *Init = ConstantStruct::get(VMContext, Elts,
603603 Constant *Elts[] = {
604604 GetTagConstant(dwarf::DW_TAG_enumerator),
605605 GetStringConstant(Name),
606 ConstantInt::get(Type::Int64Ty, Val)
606 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
607607 };
608608
609609 Constant *Init = ConstantStruct::get(VMContext, Elts,
632632 getCastToEmpty(Context),
633633 GetStringConstant(Name),
634634 getCastToEmpty(CompileUnit),
635 ConstantInt::get(Type::Int32Ty, LineNumber),
636 ConstantInt::get(Type::Int64Ty, SizeInBits),
637 ConstantInt::get(Type::Int64Ty, AlignInBits),
638 ConstantInt::get(Type::Int64Ty, OffsetInBits),
639 ConstantInt::get(Type::Int32Ty, Flags),
640 ConstantInt::get(Type::Int32Ty, Encoding)
635 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
636 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
637 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
638 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
639 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
640 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
641641 };
642642
643643 Constant *Init = ConstantStruct::get(VMContext, Elts,
668668 getCastToEmpty(Context),
669669 GetStringConstant(Name),
670670 getCastToEmpty(CompileUnit),
671 ConstantInt::get(Type::Int32Ty, LineNumber),
672 ConstantInt::get(Type::Int64Ty, SizeInBits),
673 ConstantInt::get(Type::Int64Ty, AlignInBits),
674 ConstantInt::get(Type::Int64Ty, OffsetInBits),
675 ConstantInt::get(Type::Int32Ty, Flags),
671 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
672 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
673 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
674 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
675 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
676676 getCastToEmpty(DerivedFrom)
677677 };
678678
706706 getCastToEmpty(Context),
707707 GetStringConstant(Name),
708708 getCastToEmpty(CompileUnit),
709 ConstantInt::get(Type::Int32Ty, LineNumber),
710 ConstantInt::get(Type::Int64Ty, SizeInBits),
711 ConstantInt::get(Type::Int64Ty, AlignInBits),
712 ConstantInt::get(Type::Int64Ty, OffsetInBits),
713 ConstantInt::get(Type::Int32Ty, Flags),
709 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
710 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
711 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
712 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
713 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
714714 getCastToEmpty(DerivedFrom),
715715 getCastToEmpty(Elements),
716 ConstantInt::get(Type::Int32Ty, RuntimeLang)
716 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
717717 };
718718
719719 Constant *Init = ConstantStruct::get(VMContext, Elts,
748748 GetStringConstant(DisplayName),
749749 GetStringConstant(LinkageName),
750750 getCastToEmpty(CompileUnit),
751 ConstantInt::get(Type::Int32Ty, LineNo),
751 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
752752 getCastToEmpty(Type),
753 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
754 ConstantInt::get(Type::Int1Ty, isDefinition)
753 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
754 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
755755 };
756756
757757 Constant *Init = ConstantStruct::get(VMContext, Elts,
781781 GetStringConstant(DisplayName),
782782 GetStringConstant(LinkageName),
783783 getCastToEmpty(CompileUnit),
784 ConstantInt::get(Type::Int32Ty, LineNo),
784 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
785785 getCastToEmpty(Type),
786 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
787 ConstantInt::get(Type::Int1Ty, isDefinition),
786 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
787 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
788788 ConstantExpr::getBitCast(Val, EmptyStructPtr)
789789 };
790790
810810 getCastToEmpty(Context),
811811 GetStringConstant(Name),
812812 getCastToEmpty(CompileUnit),
813 ConstantInt::get(Type::Int32Ty, LineNo),
813 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
814814 getCastToEmpty(Type)
815815 };
816816
862862
863863 // Invoke llvm.dbg.stoppoint
864864 Value *Args[] = {
865 ConstantInt::get(llvm::Type::Int32Ty, LineNo),
866 ConstantInt::get(llvm::Type::Int32Ty, ColNo),
865 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo),
866 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo),
867867 getCastToEmpty(CU)
868868 };
869869 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
9292 }
9393
9494 static inline const SCEV *GetZeroSCEV(ScalarEvolution *SE) {
95 return SE->getConstant(Type::Int32Ty, 0L);
95 return SE->getConstant(Type::getInt32Ty(SE->getContext()), 0L);
9696 }
9797
9898 //===----------------------------------------------------------------------===//
7272 ConstantRange X = getRange(Mul->getOperand(0), T, SE);
7373 if (X.isFullSet()) return FullSet;
7474
75 const IntegerType *Ty = IntegerType::get(X.getBitWidth());
76 const IntegerType *ExTy = IntegerType::get(X.getBitWidth() *
77 Mul->getNumOperands());
75 const IntegerType *Ty = IntegerType::get(SE.getContext(), X.getBitWidth());
76 const IntegerType *ExTy = IntegerType::get(SE.getContext(),
77 X.getBitWidth() * Mul->getNumOperands());
7878 ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth());
7979
8080 for (unsigned i = 1, e = Mul->getNumOperands(); i != e; ++i) {
4646 }
4747
4848 bool PointerTracking::doInitialization(Module &M) {
49 const Type *PTy = PointerType::getUnqual(Type::Int8Ty);
49 const Type *PTy = PointerType::getUnqual(Type::getInt8Ty(M.getContext()));
5050
5151 // Find calloc(i64, i64) or calloc(i32, i32).
5252 callocFunc = M.getFunction("calloc");
5454 const FunctionType *Ty = callocFunc->getFunctionType();
5555
5656 std::vector args, args2;
57 args.push_back(Type::Int64Ty);
58 args.push_back(Type::Int64Ty);
59 args2.push_back(Type::Int32Ty);
60 args2.push_back(Type::Int32Ty);
57 args.push_back(Type::getInt64Ty(M.getContext()));
58 args.push_back(Type::getInt64Ty(M.getContext()));
59 args2.push_back(Type::getInt32Ty(M.getContext()));
60 args2.push_back(Type::getInt32Ty(M.getContext()));
6161 const FunctionType *Calloc1Type =
6262 FunctionType::get(PTy, args, false);
6363 const FunctionType *Calloc2Type =
7272 const FunctionType *Ty = reallocFunc->getFunctionType();
7373 std::vector args, args2;
7474 args.push_back(PTy);
75 args.push_back(Type::Int64Ty);
75 args.push_back(Type::getInt64Ty(M.getContext()));
7676 args2.push_back(PTy);
77 args2.push_back(Type::Int32Ty);
77 args2.push_back(Type::getInt32Ty(M.getContext()));
7878
7979 const FunctionType *Realloc1Type =
8080 FunctionType::get(PTy, args, false);
103103 Constant *C = GV->getInitializer();
104104 if (const ArrayType *ATy = dyn_cast(C->getType())) {
105105 Ty = ATy->getElementType();
106 return SE->getConstant(Type::Int32Ty, ATy->getNumElements());
106 return SE->getConstant(Type::getInt32Ty(Ty->getContext()),
107 ATy->getNumElements());
107108 }
108109 }
109110 Ty = GV->getType();
110 return SE->getConstant(Type::Int32Ty, 1);
111 return SE->getConstant(Type::getInt32Ty(Ty->getContext()), 1);
111112 //TODO: implement more tracking for globals
112113 }
113114
116117 Function *F = dyn_cast(CS.getCalledValue()->stripPointerCasts());
117118 const Loop *L = LI->getLoopFor(CI->getParent());
118119 if (F == callocFunc) {
119 Ty = Type::Int8Ty;
120 Ty = Type::getInt8Ty(Ty->getContext());
120121 // calloc allocates arg0*arg1 bytes.
121122 return SE->getSCEVAtScope(SE->getMulExpr(SE->getSCEV(CS.getArgument(0)),
122123 SE->getSCEV(CS.getArgument(1))),
123124 L);
124125 } else if (F == reallocFunc) {
125 Ty = Type::Int8Ty;
126 Ty = Type::getInt8Ty(Ty->getContext());
126127 // realloc allocates arg1 bytes.
127128 return SE->getSCEVAtScope(CS.getArgument(1), L);
128129 }
162163 }
163164
164165 const SCEV *PointerTracking::getAllocationSizeInBytes(Value *V) const {
165 return computeAllocationCountForType(V, Type::Int8Ty);
166 return computeAllocationCountForType(V, Type::getInt8Ty(V->getContext()));
166167 }
167168
168169 // Helper for isLoopGuardedBy that checks the swapped and inverted predicate too
597597 MultiplyFactor = MultiplyFactor.trunc(W);
598598
599599 // Calculate the product, at width T+W
600 const IntegerType *CalculationTy = IntegerType::get(CalculationBits);
600 const IntegerType *CalculationTy = IntegerType::get(SE.getContext(),
601 CalculationBits);
601602 const SCEV *Dividend = SE.getTruncateOrZeroExtend(It, CalculationTy);
602603 for (unsigned i = 1; i != K; ++i) {
603604 const SCEV *S = SE.getMinusSCEV(It, SE.getIntegerSCEV(i, It->getType()));
759760 const SCEV *RecastedMaxBECount =
760761 getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType());
761762 if (MaxBECount == RecastedMaxBECount) {
762 const Type *WideTy = IntegerType::get(BitWidth * 2);
763 const Type *WideTy = IntegerType::get(getContext(), BitWidth * 2);
763764 // Check whether Start+Step*MaxBECount has no unsigned overflow.
764765 const SCEV *ZMul =
765766 getMulExpr(CastedMaxBECount,
898899 const SCEV *RecastedMaxBECount =
899900 getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType());
900901 if (MaxBECount == RecastedMaxBECount) {
901 const Type *WideTy = IntegerType::get(BitWidth * 2);
902 const Type *WideTy = IntegerType::get(getContext(), BitWidth * 2);
902903 // Check whether Start+Step*MaxBECount has no signed overflow.
903904 const SCEV *SMul =
904905 getMulExpr(CastedMaxBECount,
16361637 if (!RHSC->getValue()->getValue().isPowerOf2())
16371638 ++MaxShiftAmt;
16381639 const IntegerType *ExtTy =
1639 IntegerType::get(getTypeSizeInBits(Ty) + MaxShiftAmt);
1640 IntegerType::get(getContext(), getTypeSizeInBits(Ty) + MaxShiftAmt);
16401641 // {X,+,N}/C --> {X/C,+,N/C} if safe and N/C can be folded.
16411642 if (const SCEVAddRecExpr *AR = dyn_cast(LHS))
16421643 if (const SCEVConstant *Step =
20632064 return Ty;
20642065
20652066 assert(isa(Ty) && "Unexpected non-pointer non-integer type!");
2066 return TD->getIntPtrType();
2067 return TD->getIntPtrType(getContext());
20672068 }
20682069
20692070 const SCEV *ScalarEvolution::getCouldNotCompute() {
24312432 ///
24322433 const SCEV *ScalarEvolution::createNodeForGEP(Operator *GEP) {
24332434
2434 const Type *IntPtrTy = TD->getIntPtrType();
2435 const Type *IntPtrTy = TD->getIntPtrType(getContext());
24352436 Value *Base = GEP->getOperand(0);
24362437 // Don't attempt to analyze GEPs over unsized objects.
24372438 if (!cast(Base->getType())->getElementType()->isSized())
28252826 if (LZ != 0 && !((~A & ~KnownZero) & EffectiveMask))
28262827 return
28272828 getZeroExtendExpr(getTruncateExpr(getSCEV(U->getOperand(0)),
2828 IntegerType::get(BitWidth - LZ)),
2829 IntegerType::get(getContext(), BitWidth - LZ)),
28292830 U->getType());
28302831 }
28312832 break;
29242925 return getIntegerSCEV(0, U->getType()); // value is undefined
29252926 return
29262927 getSignExtendExpr(getTruncateExpr(getSCEV(L->getOperand(0)),
2927 IntegerType::get(Amt)),
2928 IntegerType::get(getContext(), Amt)),
29282929 U->getType());
29292930 }
29302931 break;
37473748
37483749 if (CondVal->getValue() == uint64_t(ExitWhen)) {
37493750 ++NumBruteForceTripCountsComputed;
3750 return getConstant(Type::Int32Ty, IterationNum);
3751 return getConstant(Type::getInt32Ty(getContext()), IterationNum);
37513752 }
37523753
37533754 // Compute the value of the PHI node for the next iteration.
46694670
46704671 // Check Add for unsigned overflow.
46714672 // TODO: More sophisticated things could be done here.
4672 const Type *WideTy = IntegerType::get(getTypeSizeInBits(Ty) + 1);
4673 const Type *WideTy = IntegerType::get(getContext(),
4674 getTypeSizeInBits(Ty) + 1);
46734675 const SCEV *EDiff = getZeroExtendExpr(Diff, WideTy);
46744676 const SCEV *ERoundUp = getZeroExtendExpr(RoundUp, WideTy);
46754677 const SCEV *OperandExtendedAdd = getAddExpr(EDiff, ERoundUp);
297297 uint64_t FullOffset = C->getValue()->getZExtValue();
298298 if (FullOffset < SL.getSizeInBytes()) {
299299 unsigned ElIdx = SL.getElementContainingOffset(FullOffset);
300 GepIndices.push_back(ConstantInt::get(Type::Int32Ty, ElIdx));
300 GepIndices.push_back(
301 ConstantInt::get(Type::getInt32Ty(Ty->getContext()), ElIdx));
301302 ElTy = STy->getTypeAtIndex(ElIdx);
302303 Ops[0] =
303304 SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx));
320321 // better than ptrtoint+arithmetic+inttoptr at least.
321322 if (!AnyNonZeroIndices) {
322323 V = InsertNoopCastOfTo(V,
323 Type::Int8Ty->getPointerTo(PTy->getAddressSpace()));
324 Type::getInt8Ty(Ty->getContext())->getPointerTo(PTy->getAddressSpace()));
324325 Value *Idx = expandCodeFor(SE.getAddExpr(Ops), Ty);
325326
326327 // Fold a GEP with constant operands.
459459 Align = TD->getABITypeAlignment(AI->getType()->getElementType());
460460 Align =
461461 std::max(Align,
462 (unsigned)TD->getABITypeAlignment(Type::DoubleTy));
462 (unsigned)TD->getABITypeAlignment(
463 Type::getDoubleTy(V->getContext())));
463464 Align =
464465 std::max(Align,
465 (unsigned)TD->getABITypeAlignment(Type::Int64Ty));
466 (unsigned)TD->getABITypeAlignment(
467 Type::getInt64Ty(V->getContext())));
466468 }
467469 }
468470
10331035 // Make sure the index-ee is a pointer to array of i8.
10341036 const PointerType *PT = cast(GEP->getOperand(0)->getType());
10351037 const ArrayType *AT = dyn_cast(PT->getElementType());
1036 if (AT == 0 || AT->getElementType() != Type::Int8Ty)
1038 if (AT == 0 || AT->getElementType() != Type::getInt8Ty(V->getContext()))
10371039 return false;
10381040
10391041 // Check to make sure that the first operand of the GEP is an integer and
10721074
10731075 // Must be a Constant Array
10741076 ConstantArray *Array = dyn_cast(GlobalInit);
1075 if (Array == 0 || Array->getType()->getElementType() != Type::Int8Ty)
1077 if (Array == 0 ||
1078 Array->getType()->getElementType() != Type::getInt8Ty(V->getContext()))
10761079 return false;
10771080
10781081 // Get the number of elements in the array
470470 Error("bitwidth for integer type out of range!");
471471 return lltok::Error;
472472 }
473 TyVal = IntegerType::get(NumBits);
473 TyVal = IntegerType::get(Context, NumBits);
474474 return lltok::Type;
475475 }
476476
578578 #define TYPEKEYWORD(STR, LLVMTY) \
579579 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
580580 TyVal = LLVMTY; return lltok::Type; }
581 TYPEKEYWORD("void", Type::VoidTy);
582 TYPEKEYWORD("float", Type::FloatTy);
583 TYPEKEYWORD("double", Type::DoubleTy);
584 TYPEKEYWORD("x86_fp80", Type::X86_FP80Ty);
585 TYPEKEYWORD("fp128", Type::FP128Ty);
586 TYPEKEYWORD("ppc_fp128", Type::PPC_FP128Ty);
587 TYPEKEYWORD("label", Type::LabelTy);
588 TYPEKEYWORD("metadata", Type::MetadataTy);
581 TYPEKEYWORD("void", Type::getVoidTy(Context));
582 TYPEKEYWORD("float", Type::getFloatTy(Context));
583 TYPEKEYWORD("double", Type::getDoubleTy(Context));
584 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
585 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
586 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
587 TYPEKEYWORD("label", Type::getLabelTy(Context));
588 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
589589 #undef TYPEKEYWORD
590590
591591 // Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
258258 LocTy TypeLoc = Lex.getLoc();
259259 Lex.Lex(); // eat kw_type
260260
261 PATypeHolder Ty(Type::VoidTy);
261 PATypeHolder Ty(Type::getVoidTy(Context));
262262 if (ParseType(Ty)) return true;
263263
264264 // See if this type was previously referenced.
285285 LocTy NameLoc = Lex.getLoc();
286286 Lex.Lex(); // eat LocalVar.
287287
288 PATypeHolder Ty(Type::VoidTy);
288 PATypeHolder Ty(Type::getVoidTy(Context));
289289
290290 if (ParseToken(lltok::equal, "expected '=' after name") ||
291291 ParseToken(lltok::kw_type, "expected 'type' after name") ||
485485 if (ParseToken(lltok::rbrace, "expected end of metadata node"))
486486 return true;
487487
488 NamedMDNode::Create(Name, Elts.data(), Elts.size(), M);
488 NamedMDNode::Create(Context, Name, Elts.data(), Elts.size(), M);
489489 return false;
490490 }
491491
503503 return true;
504504
505505 LocTy TyLoc;
506 PATypeHolder Ty(Type::VoidTy);
506 PATypeHolder Ty(Type::getVoidTy(Context));
507507 if (ParseType(Ty, TyLoc))
508508 return true;
509509
627627 bool ThreadLocal, IsConstant;
628628 LocTy TyLoc;
629629
630 PATypeHolder Ty(Type::VoidTy);
630 PATypeHolder Ty(Type::getVoidTy(Context));
631631 if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) ||
632632 ParseOptionalAddrSpace(AddrSpace) ||
633633 ParseGlobalType(IsConstant) ||
644644 return true;
645645 }
646646
647 if (isa(Ty) || Ty == Type::LabelTy)
647 if (isa(Ty) || Ty == Type::getLabelTy(Context))
648648 return Error(TyLoc, "invalid type for global variable");
649649
650650 GlobalVariable *GV = 0;
10641064 if (!UpRefs.empty())
10651065 return Error(UpRefs.back().Loc, "invalid unresolved type up reference");
10661066
1067 if (!AllowVoid && Result.get() == Type::VoidTy)
1067 if (!AllowVoid && Result.get() == Type::getVoidTy(Context))
10681068 return Error(TypeLoc, "void type only allowed for function results");
10691069
10701070 return false;
12261226
12271227 // TypeRec ::= TypeRec '*'
12281228 case lltok::star:
1229 if (Result.get() == Type::LabelTy)
1229 if (Result.get() == Type::getLabelTy(Context))
12301230 return TokError("basic block pointers are invalid");
1231 if (Result.get() == Type::VoidTy)
1231 if (Result.get() == Type::getVoidTy(Context))
12321232 return TokError("pointers to void are invalid; use i8* instead");
12331233 if (!PointerType::isValidElementType(Result.get()))
12341234 return TokError("pointer to this type is invalid");
12381238
12391239 // TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*'
12401240 case lltok::kw_addrspace: {
1241 if (Result.get() == Type::LabelTy)
1241 if (Result.get() == Type::getLabelTy(Context))
12421242 return TokError("basic block pointers are invalid");
1243 if (Result.get() == Type::VoidTy)
1243 if (Result.get() == Type::getVoidTy(Context))
12441244 return TokError("pointers to void are invalid; use i8* instead");
12451245 if (!PointerType::isValidElementType(Result.get()))
12461246 return TokError("pointer to this type is invalid");
12801280
12811281 // Parse the argument.
12821282 LocTy ArgLoc;
1283 PATypeHolder ArgTy(Type::VoidTy);
1283 PATypeHolder ArgTy(Type::getVoidTy(Context));
12841284 unsigned ArgAttrs1, ArgAttrs2;
12851285 Value *V;
12861286 if (ParseType(ArgTy, ArgLoc) ||
13211321 Lex.Lex();
13221322 } else {
13231323 LocTy TypeLoc = Lex.getLoc();
1324 PATypeHolder ArgTy(Type::VoidTy);
1324 PATypeHolder ArgTy(Type::getVoidTy(Context));
13251325 unsigned Attrs;
13261326 std::string Name;
13271327
13311331 if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
13321332 ParseOptionalAttrs(Attrs, 0)) return true;
13331333
1334 if (ArgTy == Type::VoidTy)
1334 if (ArgTy == Type::getVoidTy(Context))
13351335 return Error(TypeLoc, "argument can not have void type");
13361336
13371337 if (Lex.getKind() == lltok::LocalVar ||
13571357 if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) ||
13581358 ParseOptionalAttrs(Attrs, 0)) return true;
13591359
1360 if (ArgTy == Type::VoidTy)
1360 if (ArgTy == Type::getVoidTy(Context))
13611361 return Error(TypeLoc, "argument can not have void type");
13621362
13631363 if (Lex.getKind() == lltok::LocalVar ||
14351435 if (ParseTypeRec(Result)) return true;
14361436 ParamsList.push_back(Result);
14371437
1438 if (Result == Type::VoidTy)
1438 if (Result == Type::getVoidTy(Context))
14391439 return Error(EltTyLoc, "struct element can not have void type");
14401440 if (!StructType::isValidElementType(Result))
14411441 return Error(EltTyLoc, "invalid element type for struct");
14441444 EltTyLoc = Lex.getLoc();
14451445 if (ParseTypeRec(Result)) return true;
14461446
1447 if (Result == Type::VoidTy)
1447 if (Result == Type::getVoidTy(Context))
14481448 return Error(EltTyLoc, "struct element can not have void type");
14491449 if (!StructType::isValidElementType(Result))
14501450 return Error(EltTyLoc, "invalid element type for struct");
14801480 return true;
14811481
14821482 LocTy TypeLoc = Lex.getLoc();
1483 PATypeHolder EltTy(Type::VoidTy);
1483 PATypeHolder EltTy(Type::getVoidTy(Context));
14841484 if (ParseTypeRec(EltTy)) return true;
14851485
1486 if (EltTy == Type::VoidTy)
1486 if (EltTy == Type::getVoidTy(Context))
14871487 return Error(TypeLoc, "array and vector element type cannot be void");
14881488
14891489 if (ParseToken(isVector ? lltok::greater : lltok::rsquare,
15741574 // If we have the value in the symbol table or fwd-ref table, return it.
15751575 if (Val) {
15761576 if (Val->getType() == Ty) return Val;
1577 if (Ty == Type::LabelTy)
1577 if (Ty == Type::getLabelTy(F.getContext()))
15781578 P.Error(Loc, "'%" + Name + "' is not a basic block");
15791579 else
15801580 P.Error(Loc, "'%" + Name + "' defined with type '" +
15831583 }
15841584
15851585 // Don't make placeholders with invalid type.
1586 if (!Ty->isFirstClassType() && !isa(Ty) && Ty != Type::LabelTy) {
1586 if (!Ty->isFirstClassType() && !isa(Ty) &&
1587 Ty != Type::getLabelTy(F.getContext())) {
15871588 P.Error(Loc, "invalid use of a non-first-class type");
15881589 return 0;
15891590 }
15901591
15911592 // Otherwise, create a new forward reference for this value and remember it.
15921593 Value *FwdVal;
1593 if (Ty == Type::LabelTy)
1594 FwdVal = BasicBlock::Create(Name, &F);
1594 if (Ty == Type::getLabelTy(F.getContext()))
1595 FwdVal = BasicBlock::Create(F.getContext(), Name, &F);
15951596 else
15961597 FwdVal = new Argument(Ty, Name);
15971598
16161617 // If we have the value in the symbol table or fwd-ref table, return it.
16171618 if (Val) {
16181619 if (Val->getType() == Ty) return Val;
1619 if (Ty == Type::LabelTy)
1620 if (Ty == Type::getLabelTy(F.getContext()))
16201621 P.Error(Loc, "'%" + utostr(ID) + "' is not a basic block");
16211622 else
16221623 P.Error(Loc, "'%" + utostr(ID) + "' defined with type '" +
16241625 return 0;
16251626 }
16261627
1627 if (!Ty->isFirstClassType() && !isa(Ty) && Ty != Type::LabelTy) {
1628 if (!Ty->isFirstClassType() && !isa(Ty) &&
1629 Ty != Type::getLabelTy(F.getContext())) {
16281630 P.Error(Loc, "invalid use of a non-first-class type");
16291631 return 0;
16301632 }
16311633
16321634 // Otherwise, create a new forward reference for this value and remember it.
16331635 Value *FwdVal;
1634 if (Ty == Type::LabelTy)
1635 FwdVal = BasicBlock::Create("", &F);
1636 if (Ty == Type::getLabelTy(F.getContext()))
1637 FwdVal = BasicBlock::Create(F.getContext(), "", &F);
16361638 else
16371639 FwdVal = new Argument(Ty);
16381640
16461648 const std::string &NameStr,
16471649 LocTy NameLoc, Instruction *Inst) {
16481650 // If this instruction has void type, it cannot have a name or ID specified.
1649 if (Inst->getType() == Type::VoidTy) {
1651 if (Inst->getType() == Type::getVoidTy(F.getContext())) {
16501652 if (NameID != -1 || !NameStr.empty())
16511653 return P.Error(NameLoc, "instructions returning void cannot have a name");
16521654 return false;
17011703 /// forward reference record if needed.
17021704 BasicBlock *LLParser::PerFunctionState::GetBB(const std::string &Name,
17031705 LocTy Loc) {
1704 return cast_or_null(GetVal(Name, Type::LabelTy, Loc));
1706 return cast_or_null(GetVal(Name,
1707 Type::getLabelTy(F.getContext()), Loc));
17051708 }
17061709
17071710 BasicBlock *LLParser::PerFunctionState::GetBB(unsigned ID, LocTy Loc) {
1708 return cast_or_null(GetVal(ID, Type::LabelTy, Loc));
1711 return cast_or_null(GetVal(ID,
1712 Type::getLabelTy(F.getContext()), Loc));
17091713 }
17101714
17111715 /// DefineBB - Define the specified basic block, which is either named or
18981902 }
18991903 case lltok::kw_c: // c "foo"
19001904 Lex.Lex();
1901 ID.ConstantVal = ConstantArray::get(Lex.getStrVal(), false);
1905 ID.ConstantVal = ConstantArray::get(Context, Lex.getStrVal(), false);
19021906 if (ParseToken(lltok::StringConstant, "expected string")) return true;
19031907 ID.Kind = ValID::t_Constant;
19041908 return false;
19311935 case lltok::kw_inttoptr:
19321936 case lltok::kw_ptrtoint: {
19331937 unsigned Opc = Lex.getUIntVal();
1934 PATypeHolder DestTy(Type::VoidTy);
1938 PATypeHolder DestTy(Type::getVoidTy(Context));
19351939 Constant *SrcVal;
19361940 Lex.Lex();
19371941 if (ParseToken(lltok::lparen, "expected '(' after constantexpr cast") ||
22242228 // The lexer has no type info, so builds all float and double FP constants
22252229 // as double. Fix this here. Long double does not need this.
22262230 if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble &&
2227 Ty == Type::FloatTy) {
2231 Ty == Type::getFloatTy(Context)) {
22282232 bool Ignored;
22292233 ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven,
22302234 &Ignored);
22432247 return false;
22442248 case ValID::t_Undef:
22452249 // FIXME: LabelTy should not be a first-class type.
2246 if ((!Ty->isFirstClassType() || Ty == Type::LabelTy) &&
2250 if ((!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) &&
22472251 !isa(Ty))
22482252 return Error(ID.Loc, "invalid type for undef constant");
22492253 V = UndefValue::get(Ty);
22552259 return false;
22562260 case ValID::t_Zero:
22572261 // FIXME: LabelTy should not be a first-class type.
2258 if (!Ty->isFirstClassType() || Ty == Type::LabelTy)
2262 if (!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context))
22592263 return Error(ID.Loc, "invalid type for null constant");
22602264 V = Constant::getNullValue(Ty);
22612265 return false;
22682272 }
22692273
22702274 bool LLParser::ParseGlobalTypeAndValue(Constant *&V) {
2271 PATypeHolder Type(Type::VoidTy);
2275 PATypeHolder Type(Type::getVoidTy(Context));
22722276 return ParseType(Type) ||
22732277 ParseGlobalValue(Type, V);
22742278 }
23352339 }
23362340
23372341 bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState &PFS) {
2338 PATypeHolder T(Type::VoidTy);
2342 PATypeHolder T(Type::getVoidTy(Context));
23392343 return ParseType(T) ||
23402344 ParseValue(T, V, PFS);
23412345 }
23502354 unsigned Linkage;
23512355
23522356 unsigned Visibility, CC, RetAttrs;
2353 PATypeHolder RetType(Type::VoidTy);
2357 PATypeHolder RetType(Type::getVoidTy(Context));
23542358 LocTy RetTypeLoc = Lex.getLoc();
23552359 if (ParseOptionalLinkage(Linkage) ||
23562360 ParseOptionalVisibility(Visibility) ||
24592463 AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end());
24602464
24612465 if (PAL.paramHasAttr(1, Attribute::StructRet) &&
2462 RetType != Type::VoidTy)
2466 RetType != Type::getVoidTy(Context))
24632467 return Error(RetTypeLoc, "functions with 'sret' argument must return void");
24642468
24652469 const FunctionType *FT =
26302634 switch (Token) {
26312635 default: return Error(Loc, "expected instruction opcode");
26322636 // Terminator Instructions.
2633 case lltok::kw_unwind: Inst = new UnwindInst(); return false;
2634 case lltok::kw_unreachable: Inst = new UnreachableInst(); return false;
2637 case lltok::kw_unwind: Inst = new UnwindInst(Context); return false;
2638 case lltok::kw_unreachable: Inst = new UnreachableInst(Context); return false;
26352639 case lltok::kw_ret: return ParseRet(Inst, BB, PFS);
26362640 case lltok::kw_br: return ParseBr(Inst, PFS);
26372641 case lltok::kw_switch: return ParseSwitch(Inst, PFS);
27872791 /// ::= 'ret' TypeAndValue (',' TypeAndValue)+ [[obsolete: LLVM 3.0]]
27882792 bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
27892793 PerFunctionState &PFS) {
2790 PATypeHolder Ty(Type::VoidTy);
2794 PATypeHolder Ty(Type::getVoidTy(Context));
27912795 if (ParseType(Ty, true /*void allowed*/)) return true;
27922796
2793 if (Ty == Type::VoidTy) {
2794 Inst = ReturnInst::Create();
2797 if (Ty == Type::getVoidTy(Context)) {
2798 Inst = ReturnInst::Create(Context);
27952799 return false;
27962800 }
27972801
28172821 RV = I;
28182822 }
28192823 }
2820 Inst = ReturnInst::Create(RV);
2824 Inst = ReturnInst::Create(Context, RV);
28212825 return false;
28222826 }
28232827
28352839 return false;
28362840 }
28372841
2838 if (Op0->getType() != Type::Int1Ty)
2842 if (Op0->getType() != Type::getInt1Ty(Context))
28392843 return Error(Loc, "branch condition must have 'i1' type");
28402844
28412845 if (ParseToken(lltok::comma, "expected ',' after branch condition") ||
29102914 bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
29112915 LocTy CallLoc = Lex.getLoc();
29122916 unsigned CC, RetAttrs, FnAttrs;
2913 PATypeHolder RetType(Type::VoidTy);
2917 PATypeHolder RetType(Type::getVoidTy(Context));
29142918 LocTy RetTypeLoc;
29152919 ValID CalleeID;
29162920 SmallVector ArgList;
31033107 bool LLParser::ParseCast(Instruction *&Inst, PerFunctionState &PFS,
31043108 unsigned Opc) {
31053109 LocTy Loc; Value *Op;
3106 PATypeHolder DestTy(Type::VoidTy);
3110 PATypeHolder DestTy(Type::getVoidTy(Context));
31073111 if (ParseTypeAndValue(Op, Loc, PFS) ||
31083112 ParseToken(lltok::kw_to, "expected 'to' after cast value") ||
31093113 ParseType(DestTy))
31423146 /// ::= 'va_arg' TypeAndValue ',' Type
31433147 bool LLParser::ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS) {
31443148 Value *Op;
3145 PATypeHolder EltTy(Type::VoidTy);
3149 PATypeHolder EltTy(Type::getVoidTy(Context));
31463150 LocTy TypeLoc;
31473151 if (ParseTypeAndValue(Op, PFS) ||
31483152 ParseToken(lltok::comma, "expected ',' after vaarg operand") ||
32143218 /// ParsePHI
32153219 /// ::= 'phi' Type '[' Value ',' Value ']' (',' '[' Value ',' Valueß ']')*
32163220 bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) {
3217 PATypeHolder Ty(Type::VoidTy);
3221 PATypeHolder Ty(Type::getVoidTy(Context));
32183222 Value *Op0, *Op1;
32193223 LocTy TypeLoc = Lex.getLoc();
32203224
32223226 ParseToken(lltok::lsquare, "expected '[' in phi value list") ||
32233227 ParseValue(Ty, Op0, PFS) ||
32243228 ParseToken(lltok::comma, "expected ',' after insertelement value") ||
3225 ParseValue(Type::LabelTy, Op1, PFS) ||
3229 ParseValue(Type::getLabelTy(Context), Op1, PFS) ||
32263230 ParseToken(lltok::rsquare, "expected ']' in phi value list"))
32273231 return true;
32283232
32363240 if (ParseToken(lltok::lsquare, "expected '[' in phi value list") ||
32373241 ParseValue(Ty, Op0, PFS) ||
32383242 ParseToken(lltok::comma, "expected ',' after insertelement value") ||
3239 ParseValue(Type::LabelTy, Op1, PFS) ||
3243 ParseValue(Type::getLabelTy(Context), Op1, PFS) ||
32403244 ParseToken(lltok::rsquare, "expected ']' in phi value list"))
32413245 return true;
32423246 }
32583262 bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
32593263 bool isTail) {
32603264 unsigned CC, RetAttrs, FnAttrs;
3261 PATypeHolder RetType(Type::VoidTy);
3265 PATypeHolder RetType(Type::getVoidTy(Context));
32623266 LocTy RetTypeLoc;
32633267 ValID CalleeID;
32643268 SmallVector ArgList;
33573361 /// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalAlignment)?
33583362 bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
33593363 unsigned Opc) {
3360 PATypeHolder Ty(Type::VoidTy);
3364 PATypeHolder Ty(Type::getVoidTy(Context));
33613365 Value *Size = 0;
33623366 LocTy SizeLoc;
33633367 unsigned Alignment = 0;
33723376 }
33733377 }
33743378
3375 if (Size && Size->getType() != Type::Int32Ty)
3379 if (Size && Size->getType() != Type::getInt32Ty(Context))
33763380 return Error(SizeLoc, "element count must be i32");
33773381
33783382 if (Opc == Instruction::Malloc)
35393543 Lex.Lex();
35403544 V = 0;
35413545 } else {
3542 PATypeHolder Ty(Type::VoidTy);
3546 PATypeHolder Ty(Type::getVoidTy(Context));
35433547 if (ParseType(Ty)) return true;
35443548 if (Lex.getKind() == lltok::Metadata) {
35453549 Lex.Lex();
142142 }
143143 explicit ConstantPlaceHolder(const Type *Ty, LLVMContext& Context)
144144 : ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) {
145 Op<0>() = UndefValue::get(Type::Int32Ty);
145 Op<0>() = UndefValue::get(Type::getInt32Ty(Context));
146146 }
147147
148148 /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
338338 resize(Idx + 1);
339339
340340 if (Value *V = MDValuePtrs[Idx]) {
341 assert(V->getType() == Type::MetadataTy && "Type mismatch in value table!");
341 assert(V->getType() == Type::getMetadataTy(Context) && "Type mismatch in value table!");
342342 return V;
343343 }
344344
345345 // Create and return a placeholder, which will later be RAUW'd.
346 Value *V = new Argument(Type::MetadataTy);
346 Value *V = new Argument(Type::getMetadataTy(Context));
347347 MDValuePtrs[Idx] = V;
348348 return V;
349349 }
517517 TypeList.reserve(Record[0]);
518518 continue;
519519 case bitc::TYPE_CODE_VOID: // VOID
520 ResultTy = Type::VoidTy;
520 ResultTy = Type::getVoidTy(Context);
521521 break;
522522 case bitc::TYPE_CODE_FLOAT: // FLOAT
523 ResultTy = Type::FloatTy;
523 ResultTy = Type::getFloatTy(Context);
524524 break;
525525 case bitc::TYPE_CODE_DOUBLE: // DOUBLE
526 ResultTy = Type::DoubleTy;
526 ResultTy = Type::getDoubleTy(Context);
527527 break;
528528 case bitc::TYPE_CODE_X86_FP80: // X86_FP80
529 ResultTy = Type::X86_FP80Ty;
529 ResultTy = Type::getX86_FP80Ty(Context);
530530 break;
531531 case bitc::TYPE_CODE_FP128: // FP128
532 ResultTy = Type::FP128Ty;
532 ResultTy = Type::getFP128Ty(Context);
533533 break;
534534 case bitc::TYPE_CODE_PPC_FP128: // PPC_FP128
535 ResultTy = Type::PPC_FP128Ty;
535 ResultTy = Type::getPPC_FP128Ty(Context);
536536 break;
537537 case bitc::TYPE_CODE_LABEL: // LABEL
538 ResultTy = Type::LabelTy;
538 ResultTy = Type::getLabelTy(Context);
539539 break;
540540 case bitc::TYPE_CODE_OPAQUE: // OPAQUE
541541 ResultTy = 0;
542542 break;
543543 case bitc::TYPE_CODE_METADATA: // METADATA
544 ResultTy = Type::MetadataTy;
544 ResultTy = Type::getMetadataTy(Context);
545545 break;
546546 case bitc::TYPE_CODE_INTEGER: // INTEGER: [width]
547547 if (Record.size() < 1)
548548 return Error("Invalid Integer type record");
549549
550 ResultTy = IntegerType::get(Record[0]);
550 ResultTy = IntegerType::get(Context, Record[0]);
551551 break;
552552 case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or
553553 // [pointee type, address space]
791791 if (MetadataBase *B = dyn_cast(MD))
792792 Elts.push_back(B);
793793 }
794 Value *V = NamedMDNode::Create(Name.c_str(), Elts.data(), Elts.size(),
795 TheModule);
794 Value *V = NamedMDNode::Create(Context, Name.c_str(), Elts.data(),
795 Elts.size(), TheModule);
796796 MDValueList.AssignValue(V, NextValueNo++);
797797 break;
798798 }
804804 SmallVector Elts;
805805 for (unsigned i = 0; i != Size; i += 2) {
806806 const Type *Ty = getTypeByID(Record[i], false);
807 if (Ty == Type::MetadataTy)
807 if (Ty == Type::getMetadataTy(Context))
808808 Elts.push_back(MDValueList.getValueFwdRef(Record[i+1]));
809 else if (Ty != Type::VoidTy)
809 else if (Ty != Type::getVoidTy(Context))
810810 Elts.push_back(ValueList.getValueFwdRef(Record[i+1], Ty));
811811 else
812812 Elts.push_back(NULL);
899899 SmallVector Record;
900900
901901 // Read all the records for this value table.
902 const Type *CurTy = Type::Int32Ty;
902 const Type *CurTy = Type::getInt32Ty(Context);
903903 unsigned NextCstNo = ValueList.size();
904904 while (1) {
905905 unsigned Code = Stream.ReadCode();
960960 case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval]
961961 if (Record.empty())
962962 return Error("Invalid FLOAT record");
963 if (CurTy == Type::FloatTy)
963 if (CurTy == Type::getFloatTy(Context))
964964 V = ConstantFP::get(Context, APFloat(APInt(32, (uint32_t)Record[0])));
965 else if (CurTy == Type::DoubleTy)
965 else if (CurTy == Type::getDoubleTy(Context))
966966 V = ConstantFP::get(Context, APFloat(APInt(64, Record[0])));
967 else if (CurTy == Type::X86_FP80Ty) {
967 else if (CurTy == Type::getX86_FP80Ty(Context)) {
968968 // Bits are not stored the same way as a normal i80 APInt, compensate.
969969 uint64_t Rearrange[2];
970970 Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
971971 Rearrange[1] = Record[0] >> 48;
972972 V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange)));
973 } else if (CurTy == Type::FP128Ty)
973 } else if (CurTy == Type::getFP128Ty(Context))
974974 V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true));
975 else if (CurTy == Type::PPC_FP128Ty)
975 else if (CurTy == Type::getPPC_FP128Ty(Context))
976976 V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0])));
977977 else
978978 V = UndefValue::get(CurTy);
10801080 case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#]
10811081 if (Record.size() < 3) return Error("Invalid CE_SELECT record");
10821082 V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0],
1083 Type::Int1Ty),
1083 Type::getInt1Ty(Context)),
10841084 ValueList.getConstantFwdRef(Record[1],CurTy),
10851085 ValueList.getConstantFwdRef(Record[2],CurTy));
10861086 break;
10901090 dyn_cast_or_null(getTypeByID(Record[0]));
10911091 if (OpTy == 0) return Error("Invalid CE_EXTRACTELT record");
10921092 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
1093 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty);
1093 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context));
10941094 V = ConstantExpr::getExtractElement(Op0, Op1);
10951095 break;
10961096 }
11011101 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
11021102 Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
11031103 OpTy->getElementType());
1104 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty);
1104 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context));
11051105 V = ConstantExpr::getInsertElement(Op0, Op1, Op2);
11061106 break;
11071107 }
11111111 return Error("Invalid CE_SHUFFLEVEC record");
11121112 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
11131113 Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
1114 const Type *ShufTy = VectorType::get(Type::Int32Ty,
1114 const Type *ShufTy = VectorType::get(Type::getInt32Ty(Context),
11151115 OpTy->getNumElements());
11161116 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
11171117 V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
11241124 return Error("Invalid CE_SHUFVEC_EX record");
11251125 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
11261126 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
1127 const Type *ShufTy = VectorType::get(Type::Int32Ty,
1127 const Type *ShufTy = VectorType::get(Type::getInt32Ty(Context),
11281128 RTy->getNumElements());
11291129 Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
11301130 V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
15911591 // Create all the basic blocks for the function.
15921592 FunctionBBs.resize(Record[0]);
15931593 for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
1594 FunctionBBs[i] = BasicBlock::Create("", F);
1594 FunctionBBs[i] = BasicBlock::Create(Context, "", F);
15951595 CurBB = FunctionBBs[0];
15961596 continue;
15971597
16971697 Value *TrueVal, *FalseVal, *Cond;
16981698 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
16991699 getValue(Record, OpNum, TrueVal->getType(), FalseVal) ||
1700 getValue(Record, OpNum, Type::Int1Ty, Cond))
1700 getValue(Record, OpNum, Type::getInt1Ty(Context), Cond))
17011701 return Error("Invalid SELECT record");
17021702
17031703 I = SelectInst::Create(Cond, TrueVal, FalseVal);
17181718 if (const VectorType* vector_type =
17191719 dyn_cast(Cond->getType())) {
17201720 // expect
1721 if (vector_type->getElementType() != Type::Int1Ty)
1721 if (vector_type->getElementType() != Type::getInt1Ty(Context))
17221722 return Error("Invalid SELECT condition type");
17231723 } else {
17241724 // expect i1
1725 if (Cond->getType() != Type::Int1Ty)
1725 if (Cond->getType() != Type::getInt1Ty(Context))
17261726 return Error("Invalid SELECT condition type");
17271727 }
17281728
17341734 unsigned OpNum = 0;
17351735 Value *Vec, *Idx;
17361736 if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
1737 getValue(Record, OpNum, Type::Int32Ty, Idx))
1737 getValue(Record, OpNum, Type::getInt32Ty(Context), Idx))
17381738 return Error("Invalid EXTRACTELT record");
17391739 I = ExtractElementInst::Create(Vec, Idx);
17401740 break;
17461746 if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
17471747 getValue(Record, OpNum,
17481748 cast(Vec->getType())->getElementType(), Elt) ||
1749 getValue(Record, OpNum, Type::Int32Ty, Idx))
1749 getValue(Record, OpNum, Type::getInt32Ty(Context), Idx))
17501750 return Error("Invalid INSERTELT record");
17511751 I = InsertElementInst::Create(Vec, Elt, Idx);
17521752 break;
18011801 {
18021802 unsigned Size = Record.size();
18031803 if (Size == 0) {
1804 I = ReturnInst::Create();
1804 I = ReturnInst::Create(Context);
18051805 break;
18061806 }
18071807
18251825 ValueList.AssignValue(I, NextValueNo++);
18261826 RV = I;
18271827 }
1828 I = ReturnInst::Create(RV);
1828 I = ReturnInst::Create(Context, RV);
18291829 break;
18301830 }
18311831
1832 I = ReturnInst::Create(Vs[0]);
1832 I = ReturnInst::Create(Context, Vs[0]);
18331833 break;
18341834 }
18351835 case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#]
18431843 I = BranchInst::Create(TrueDest);
18441844 else {
18451845 BasicBlock *FalseDest = getBasicBlock(Record[1]);
1846 Value *Cond = getFnValueByID(Record[2], Type::Int1Ty);
1846 Value *Cond = getFnValueByID(Record[2], Type::getInt1Ty(Context));
18471847 if (FalseDest == 0 || Cond == 0)
18481848 return Error("Invalid BR record");
18491849 I = BranchInst::Create(TrueDest, FalseDest, Cond);
19221922 break;
19231923 }
19241924 case bitc::FUNC_CODE_INST_UNWIND: // UNWIND
1925 I = new UnwindInst();
1925 I = new UnwindInst(Context);
19261926 break;
19271927 case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE
1928 I = new UnreachableInst();
1928 I = new UnreachableInst(Context);
19291929 break;
19301930 case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...]
19311931 if (Record.size() < 1 || ((Record.size()-1)&1))
19511951 return Error("Invalid MALLOC record");
19521952 const PointerType *Ty =
19531953 dyn_cast_or_null(getTypeByID(Record[0]));
1954 Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
1954 Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context));
19551955 unsigned Align = Record[2];
19561956 if (!Ty || !Size) return Error("Invalid MALLOC record");
19571957 I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1);
19711971 return Error("Invalid ALLOCA record");
19721972 const PointerType *Ty =
19731973 dyn_cast_or_null(getTypeByID(Record[0]));
1974 Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
1974 Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context));
19751975 unsigned Align = Record[2];
19761976 if (!Ty || !Size) return Error("Invalid ALLOCA record");
19771977 I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
20882088 }
20892089
20902090 // Non-void values get registered in the value table for future use.
2091 if (I && I->getType() != Type::VoidTy)
2091 if (I && I->getType() != Type::getVoidTy(Context))
20922092 ValueList.AssignValue(I, NextValueNo++);
20932093 }
20942094
195195 private:
196196 const Type *getTypeByID(unsigned ID, bool isTypeTable = false);
197197 Value *getFnValueByID(unsigned ID, const Type *Ty) {
198 if (Ty == Type::MetadataTy)
198 if (Ty == Type::getMetadataTy(Context))
199199 return MDValueList.getValueFwdRef(ID);
200200 else
201201 return ValueList.getValueFwdRef(ID, Ty);
481481 Record.push_back(VE.getTypeID(N->getElement(i)->getType()));
482482 Record.push_back(VE.getValueID(N->getElement(i)));
483483 } else {
484 Record.push_back(VE.getTypeID(Type::VoidTy));
484 Record.push_back(VE.getTypeID(Type::getVoidTy(N->getContext())));
485485 Record.push_back(0);
486486 }
487487 }
662662 } else if (const ConstantFP *CFP = dyn_cast(C)) {
663663 Code = bitc::CST_CODE_FLOAT;
664664 const Type *Ty = CFP->getType();
665 if (Ty == Type::FloatTy || Ty == Type::DoubleTy) {
665 if (Ty == Type::getFloatTy(Ty->getContext()) ||
666 Ty == Type::getDoubleTy(Ty->getContext())) {
666667 Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue());
667 } else if (Ty == Type::X86_FP80Ty) {
668 } else if (Ty == Type::getX86_FP80Ty(Ty->getContext())) {
668669 // api needed to prevent premature destruction
669670 // bits are not in the same order as a normal i80 APInt, compensate.
670671 APInt api = CFP->getValueAPF().bitcastToAPInt();
671672 const uint64_t *p = api.getRawData();
672673 Record.push_back((p[1] << 48) | (p[0] >> 16));
673674 Record.push_back(p[0] & 0xffffLL);
674 } else if (Ty == Type::FP128Ty || Ty == Type::PPC_FP128Ty) {
675 } else if (Ty == Type::getFP128Ty(Ty->getContext()) ||
676 Ty == Type::getPPC_FP128Ty(Ty->getContext())) {
675677 APInt api = CFP->getValueAPF().bitcastToAPInt();
676678 const uint64_t *p = api.getRawData();
677679 Record.push_back(p[0]);
11381140 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
11391141 I != E; ++I) {
11401142 WriteInstruction(*I, InstID, VE, Stream, Vals);
1141 if (I->getType() != Type::VoidTy)
1143 if (I->getType() != Type::getVoidTy(F.getContext()))
11421144 ++InstID;
11431145 }
11441146
197197 if (*I)
198198 EnumerateValue(*I);
199199 else
200 EnumerateType(Type::VoidTy);
200 EnumerateType(Type::getVoidTy(MD->getContext()));
201201 }
202202 return;
203203 } else if (const NamedMDNode *N = dyn_cast(MD)) {
217217 }
218218
219219 void ValueEnumerator::EnumerateValue(const Value *V) {
220 assert(V->getType() != Type::VoidTy && "Can't insert void values!");
220 assert(V->getType() != Type::getVoidTy(V->getContext()) &&
221 "Can't insert void values!");
221222 if (const MetadataBase *MB = dyn_cast(V))
222223 return EnumerateMetadata(MB);
223224
357358 // Add all of the instructions.
358359 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
359360 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
360 if (I->getType() != Type::VoidTy)
361 if (I->getType() != Type::getVoidTy(F.getContext()))
361362 EnumerateValue(I);
362363 }
363364 }
870870 // Handle casts to pointers by changing them into casts to the appropriate
871871 // integer type. This promotes constant folding and simplifies this code.
872872 Constant *Op = CE->getOperand(0);
873 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
873 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
874 false/*ZExt*/);
874875 return EmitConstantValueOnly(Op);
875876 }
876877
10151016 unsigned AddrSpace) {
10161017 // FP Constants are printed as integer constants to avoid losing
10171018 // precision...
1019 LLVMContext &Context = CFP->getContext();
10181020 const TargetData *TD = TM.getTargetData();
1019 if (CFP->getType() == Type::DoubleTy) {
1021 if (CFP->getType() == Type::getDoubleTy(Context)) {
10201022 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
10211023 uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
10221024 if (TAI->getData64bitsDirective(AddrSpace)) {
10581060 O << '\n';
10591061 }
10601062 return;
1061 } else if (CFP->getType() == Type::FloatTy) {
1063 } else if (CFP->getType() == Type::getFloatTy(Context)) {
10621064 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
10631065 O << TAI->getData32bitsDirective(AddrSpace)
10641066 << CFP->getValueAPF().bitcastToAPInt().getZExtValue();
10681070 }
10691071 O << '\n';
10701072 return;
1071 } else if (CFP->getType() == Type::X86_FP80Ty) {
1073 } else if (CFP->getType() == Type::getX86_FP80Ty(Context)) {
10721074 // all long double variants are printed as hex
10731075 // api needed to prevent premature destruction
10741076 APInt api = CFP->getValueAPF().bitcastToAPInt();
11501152 }
11511153 O << '\n';
11521154 }
1153 EmitZeros(TD->getTypeAllocSize(Type::X86_FP80Ty) -
1154 TD->getTypeStoreSize(Type::X86_FP80Ty), AddrSpace);
1155 EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) -
1156 TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace);
11551157 return;
1156 } else if (CFP->getType() == Type::PPC_FP128Ty) {
1158 } else if (CFP->getType() == Type::getPPC_FP128Ty(Context)) {
11571159 // all long double variants are printed as hex
11581160 // api needed to prevent premature destruction
11591161 APInt api = CFP->getValueAPF().bitcastToAPInt();
141141 // edges to a new basic block which falls through into this one.
142142
143143 // Create the new basic block.
144 BasicBlock *NewBB = BasicBlock::Create(LPad->getName() + "_unwind_edge");
144 BasicBlock *NewBB = BasicBlock::Create(F->getContext(),
145 LPad->getName() + "_unwind_edge");
145146
146147 // Insert it into the function right before the original landing pad.
147148 LPad->getParent()->getBasicBlockList().insert(LPad, NewBB);
229230
230231 // Find the rewind function if we didn't already.
231232 if (!RewindFunction) {
232 std::vector Params(1, PointerType::getUnqual(Type::Int8Ty));
233 FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
233 std::vector Params(1,
234 PointerType::getUnqual(Type::getInt8Ty(TI->getContext())));
235 FunctionType *FTy = FunctionType::get(Type::getVoidTy(TI->getContext()),
236 Params, false);
234237 const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
235238 RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
236239 }
238241 // Create the call...
239242 CallInst::Create(RewindFunction, CreateReadOfExceptionValue(I), "", TI);
240243 // ...followed by an UnreachableInst.
241 new UnreachableInst(TI);
244 new UnreachableInst(TI->getContext(), TI);
242245
243246 // Nuke the unwind instruction.
244247 TI->eraseFromParent();
353356
354357 // Create the temporary if we didn't already.
355358 if (!ExceptionValueVar) {
356 ExceptionValueVar = new AllocaInst(PointerType::getUnqual(Type::Int8Ty),
357 "eh.value", F->begin()->begin());
359 ExceptionValueVar = new AllocaInst(PointerType::getUnqual(
360 Type::getInt8Ty(BB->getContext())), "eh.value", F->begin()->begin());
358361 ++NumStackTempsIntroduced;
359362 }
360363
439439 return;
440440 } else if (const ConstantFP *CFP = dyn_cast(CV)) {
441441 APInt Val = CFP->getValueAPF().bitcastToAPInt();
442 if (CFP->getType() == Type::DoubleTy)
442 if (CFP->getType() == Type::getDoubleTy(CV->getContext()))
443443 GblS.emitWord64(Val.getZExtValue());
444 else if (CFP->getType() == Type::FloatTy)
444 else if (CFP->getType() == Type::getFloatTy(CV->getContext()))
445445 GblS.emitWord32(Val.getZExtValue());
446 else if (CFP->getType() == Type::X86_FP80Ty) {
447 unsigned PadSize = TD->getTypeAllocSize(Type::X86_FP80Ty)-
448 TD->getTypeStoreSize(Type::X86_FP80Ty);
446 else if (CFP->getType() == Type::getX86_FP80Ty(CV->getContext())) {
447 unsigned PadSize =
448 TD->getTypeAllocSize(Type::getX86_FP80Ty(CV->getContext()))-
449 TD->getTypeStoreSize(Type::getX86_FP80Ty(CV->getContext()));
449450 GblS.emitWordFP80(Val.getRawData(), PadSize);
450 } else if (CFP->getType() == Type::PPC_FP128Ty)
451 } else if (CFP->getType() == Type::getPPC_FP128Ty(CV->getContext()))
451452 llvm_unreachable("PPC_FP128Ty global emission not implemented");
452453 return;
453454 } else if (const ConstantInt *CI = dyn_cast(CV)) {
525526 }
526527 case Instruction::IntToPtr: {
527528 Constant *Op = CE->getOperand(0);
528 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
529 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
530 false/*ZExt*/);
529531 return ResolveConstantExpr(Op);
530532 }
531533 case Instruction::PtrToInt: {
3939 switch((int)Fn->arg_begin()->getType()->getTypeID()) {
4040 case Type::FloatTyID:
4141 EnsureFunctionExists(M, FName, Fn->arg_begin(), Fn->arg_end(),
42 Type::FloatTy);
42 Type::getFloatTy(M.getContext()));
4343 break;
4444 case Type::DoubleTyID:
4545 EnsureFunctionExists(M, DName, Fn->arg_begin(), Fn->arg_end(),
46 Type::DoubleTy);
46 Type::getDoubleTy(M.getContext()));
4747 break;
4848 case Type::X86_FP80TyID:
4949 case Type::FP128TyID:
8282 }
8383
8484 void IntrinsicLowering::AddPrototypes(Module &M) {
85 LLVMContext &Context = M.getContext();
8586 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
8687 if (I->isDeclaration() && !I->use_empty())
8788 switch (I->getIntrinsicID()) {
8889 default: break;
8990 case Intrinsic::setjmp:
9091 EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(),
91 Type::Int32Ty);
92 Type::getInt32Ty(M.getContext()));
9293 break;
9394 case Intrinsic::longjmp:
9495 EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(),
95 Type::VoidTy);
96 Type::getVoidTy(M.getContext()));
9697 break;
9798 case Intrinsic::siglongjmp:
9899 EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(),
99 Type::VoidTy);
100 Type::getVoidTy(M.getContext()));
100101 break;
101102 case Intrinsic::memcpy:
102 M.getOrInsertFunction("memcpy", PointerType::getUnqual(Type::Int8Ty),
103 PointerType::getUnqual(Type::Int8Ty),
104 PointerType::getUnqual(Type::Int8Ty),
105 TD.getIntPtrType(), (Type *)0);
103 M.getOrInsertFunction("memcpy",
104 PointerType::getUnqual(Type::getInt8Ty(Context)),
105 PointerType::getUnqual(Type::getInt8Ty(Context)),
106 PointerType::getUnqual(Type::getInt8Ty(Context)),
107 TD.getIntPtrType(Context), (Type *)0);
106108 break;
107109 case Intrinsic::memmove:
108 M.getOrInsertFunction("memmove", PointerType::getUnqual(Type::Int8Ty),
109 PointerType::getUnqual(Type::Int8Ty),
110 PointerType::getUnqual(Type::Int8Ty),
111 TD.getIntPtrType(), (Type *)0);
110 M.getOrInsertFunction("memmove",
111 PointerType::getUnqual(Type::getInt8Ty(Context)),
112 PointerType::getUnqual(Type::getInt8Ty(Context)),
113 PointerType::getUnqual(Type::getInt8Ty(Context)),
114 TD.getIntPtrType(Context), (Type *)0);
112115 break;
113116 case Intrinsic::memset:
114 M.getOrInsertFunction("memset", PointerType::getUnqual(Type::Int8Ty),
115 PointerType::getUnqual(Type::Int8Ty),
116 Type::Int32Ty,
117 TD.getIntPtrType(), (Type *)0);
117 M.getOrInsertFunction("memset",
118 PointerType::getUnqual(Type::getInt8Ty(Context)),
119 PointerType::getUnqual(Type::getInt8Ty(Context)),
120 Type::getInt32Ty(M.getContext()),
121 TD.getIntPtrType(Context), (Type *)0);
118122 break;
119123 case Intrinsic::sqrt:
120124 EnsureFPIntrinsicsExist(M, I, "sqrtf", "sqrt", "sqrtl");
175179 Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24),
176180 "bswap.1");
177181 Tmp3 = Builder.CreateAnd(Tmp3,
178 ConstantInt::get(Type::Int32Ty, 0xFF0000),
182 ConstantInt::get(Type::getInt32Ty(Context), 0xFF0000),
179183 "bswap.and3");
180184 Tmp2 = Builder.CreateAnd(Tmp2,
181 ConstantInt::get(Type::Int32Ty, 0xFF00),
185 ConstantInt::get(Type::getInt32Ty(Context), 0xFF00),
182186 "bswap.and2");
183187 Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
184188 Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
206210 ConstantInt::get(V->getType(), 56),
207211 "bswap.1");
208212 Tmp7 = Builder.CreateAnd(Tmp7,
209 ConstantInt::get(Type::Int64Ty,
213 ConstantInt::get(Type::getInt64Ty(Context),
210214 0xFF000000000000ULL),
211215 "bswap.and7");
212216 Tmp6 = Builder.CreateAnd(Tmp6,
213 ConstantInt::get(Type::Int64Ty,
217 ConstantInt::get(Type::getInt64Ty(Context),
214218 0xFF0000000000ULL),
215219 "bswap.and6");
216220 Tmp5 = Builder.CreateAnd(Tmp5,
217 ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL),
221 ConstantInt::get(Type::getInt64Ty(Context),
222 0xFF00000000ULL),
218223 "bswap.and5");
219224 Tmp4 = Builder.CreateAnd(Tmp4,
220 ConstantInt::get(Type::Int64Ty, 0xFF000000ULL),
225 ConstantInt::get(Type::getInt64Ty(Context),
226 0xFF000000ULL),
221227 "bswap.and4");
222228 Tmp3 = Builder.CreateAnd(Tmp3,
223 ConstantInt::get(Type::Int64Ty, 0xFF0000ULL),
229 ConstantInt::get(Type::getInt64Ty(Context),
230 0xFF0000ULL),
224231 "bswap.and3");
225232 Tmp2 = Builder.CreateAnd(Tmp2,
226 ConstantInt::get(Type::Int64Ty, 0xFF00ULL),
233 ConstantInt::get(Type::getInt64Ty(Context),
234 0xFF00ULL),
227235 "bswap.and2");
228236 Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
229237 Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2");
302310 default: llvm_unreachable("Invalid type in intrinsic");
303311 case Type::FloatTyID:
304312 ReplaceCallWith(Fname, CI, CI->op_begin() + 1, CI->op_end(),
305 Type::FloatTy);
313 Type::getFloatTy(CI->getContext()));
306314 break;
307315 case Type::DoubleTyID:
308316 ReplaceCallWith(Dname, CI, CI->op_begin() + 1, CI->op_end(),
309 Type::DoubleTy);
317 Type::getDoubleTy(CI->getContext()));
310318 break;
311319 case Type::X86_FP80TyID:
312320 case Type::FP128TyID:
338346 // convert the call to an explicit setjmp or longjmp call.
339347 case Intrinsic::setjmp: {
340348 Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin() + 1, CI->op_end(),
341 <