diff options
160 files changed, 1985 insertions, 1598 deletions
diff --git a/docs/tutorial/JITTutorial1.html b/docs/tutorial/JITTutorial1.html index 5c65399c0c..3b7b8dea1a 100644 --- a/docs/tutorial/JITTutorial1.html +++ b/docs/tutorial/JITTutorial1.html @@ -153,7 +153,7 @@ function will interoperate properly with C code, which is a good thing.</p> <div class="doc_code"> <pre> - BasicBlock* block = BasicBlock::Create("entry", mul_add); + BasicBlock* block = BasicBlock::Create(getGlobalContext(), "entry", mul_add); IRBuilder<> builder(block); </pre> </div> diff --git a/docs/tutorial/JITTutorial2.html b/docs/tutorial/JITTutorial2.html index c2483e4d01..504d96597b 100644 --- a/docs/tutorial/JITTutorial2.html +++ b/docs/tutorial/JITTutorial2.html @@ -100,11 +100,11 @@ Module* makeLLVMModule() { <div class="doc_code"> <pre> - BasicBlock* entry = BasicBlock::Create("entry", gcd); - BasicBlock* ret = BasicBlock::Create("return", gcd); - BasicBlock* cond_false = BasicBlock::Create("cond_false", gcd); - BasicBlock* cond_true = BasicBlock::Create("cond_true", gcd); - BasicBlock* cond_false_2 = BasicBlock::Create("cond_false", gcd); + BasicBlock* entry = BasicBlock::Create(getGlobalContext(), ("entry", gcd); + BasicBlock* ret = BasicBlock::Create(getGlobalContext(), ("return", gcd); + BasicBlock* cond_false = BasicBlock::Create(getGlobalContext(), ("cond_false", gcd); + BasicBlock* cond_true = BasicBlock::Create(getGlobalContext(), ("cond_true", gcd); + BasicBlock* cond_false_2 = BasicBlock::Create(getGlobalContext(), ("cond_false", gcd); </pre> </div> diff --git a/docs/tutorial/LangImpl3.html b/docs/tutorial/LangImpl3.html index 5f1072f632..5978707e3b 100644 --- a/docs/tutorial/LangImpl3.html +++ b/docs/tutorial/LangImpl3.html @@ -206,7 +206,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); default: return ErrorV("invalid binary operator"); } } @@ -307,8 +307,8 @@ bodies and external function declarations. The code starts with:</p> <pre> Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); </pre> @@ -439,7 +439,7 @@ is an LLVM Function object that is ready to go for us.</p> <div class="doc_code"> <pre> // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); if (Value *RetVal = Body->Codegen()) { @@ -1055,7 +1055,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); default: return ErrorV("invalid binary operator"); } } @@ -1081,8 +1081,8 @@ Value *CallExprAST::Codegen() { Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); @@ -1127,7 +1127,7 @@ Function *FunctionAST::Codegen() { return 0; // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); if (Value *RetVal = Body->Codegen()) { diff --git a/docs/tutorial/LangImpl4.html b/docs/tutorial/LangImpl4.html index 5eb69d3357..2f1dd4af14 100644 --- a/docs/tutorial/LangImpl4.html +++ b/docs/tutorial/LangImpl4.html @@ -890,7 +890,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); default: return ErrorV("invalid binary operator"); } } @@ -916,8 +916,8 @@ Value *CallExprAST::Codegen() { Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); @@ -962,7 +962,7 @@ Function *FunctionAST::Codegen() { return 0; // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); if (Value *RetVal = Body->Codegen()) { diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html index 53bbcdc58e..acfee7b9b8 100644 --- a/docs/tutorial/LangImpl5.html +++ b/docs/tutorial/LangImpl5.html @@ -379,9 +379,9 @@ value as a 1-bit (bool) value.</p> // Create blocks for the then and else cases. Insert the 'then' block at the // end of the function. - BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction); - BasicBlock *ElseBB = BasicBlock::Create("else"); - BasicBlock *MergeBB = BasicBlock::Create("ifcont"); + BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction); + BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else"); + BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont"); Builder.CreateCondBr(CondV, ThenBB, ElseBB); </pre> @@ -472,7 +472,7 @@ are emitted, we can finish up with the merge code:</p> // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); Builder.SetInsertPoint(MergeBB); - PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp"); + PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -727,7 +727,7 @@ block, but remember that the body code itself could consist of multiple blocks // block. Function *TheFunction = Builder.GetInsertBlock()->getParent(); BasicBlock *PreheaderBB = Builder.GetInsertBlock(); - BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction); + BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction); // Insert an explicit fall through from the current block to the LoopBB. Builder.CreateBr(LoopBB); @@ -745,7 +745,7 @@ create an unconditional branch for the fall-through between the two blocks.</p> Builder.SetInsertPoint(LoopBB); // Start the PHI node with an entry for Start. - PHINode *Variable = Builder.CreatePHI(Type::DoubleTy, VarName.c_str()); + PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str()); Variable->addIncoming(StartVal, PreheaderBB); </pre> </div> @@ -828,7 +828,7 @@ statement.</p> <pre> // Create the "after loop" block and insert it. BasicBlock *LoopEndBB = Builder.GetInsertBlock(); - BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction); + BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction); // Insert the conditional branch into the end of LoopEndBB. Builder.CreateCondBr(EndCond, LoopBB, AfterBB); @@ -856,7 +856,7 @@ the loop again and exiting the loop. Any future code is emitted in the NamedValues.erase(VarName); // for expr always returns 0.0. - return Constant::getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::getDoubleTy(getGlobalContext())); } </pre> </div> @@ -1381,7 +1381,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); default: return ErrorV("invalid binary operator"); } } @@ -1418,9 +1418,9 @@ Value *IfExprAST::Codegen() { // Create blocks for the then and else cases. Insert the 'then' block at the // end of the function. - BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction); - BasicBlock *ElseBB = BasicBlock::Create("else"); - BasicBlock *MergeBB = BasicBlock::Create("ifcont"); + BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction); + BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else"); + BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont"); Builder.CreateCondBr(CondV, ThenBB, ElseBB); @@ -1448,7 +1448,7 @@ Value *IfExprAST::Codegen() { // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); Builder.SetInsertPoint(MergeBB); - PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp"); + PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -1480,7 +1480,7 @@ Value *ForExprAST::Codegen() { // block. Function *TheFunction = Builder.GetInsertBlock()->getParent(); BasicBlock *PreheaderBB = Builder.GetInsertBlock(); - BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction); + BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction); // Insert an explicit fall through from the current block to the LoopBB. Builder.CreateBr(LoopBB); @@ -1489,7 +1489,7 @@ Value *ForExprAST::Codegen() { Builder.SetInsertPoint(LoopBB); // Start the PHI node with an entry for Start. - PHINode *Variable = Builder.CreatePHI(Type::DoubleTy, VarName.c_str()); + PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str()); Variable->addIncoming(StartVal, PreheaderBB); // Within the loop, the variable is defined equal to the PHI node. If it @@ -1526,7 +1526,7 @@ Value *ForExprAST::Codegen() { // Create the "after loop" block and insert it. BasicBlock *LoopEndBB = Builder.GetInsertBlock(); - BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction); + BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction); // Insert the conditional branch into the end of LoopEndBB. Builder.CreateCondBr(EndCond, LoopBB, AfterBB); @@ -1545,13 +1545,13 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return getGlobalContext().getNullValue(Type::DoubleTy); + return getGlobalContext().getNullValue(Type::getDoubleTy(getGlobalContext())); } Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); @@ -1596,7 +1596,7 @@ Function *FunctionAST::Codegen() { return 0; // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); if (Value *RetVal = Body->Codegen()) { diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index d845eb86c1..33df2452b6 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -283,7 +283,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); <b>default: break;</b> } @@ -321,7 +321,7 @@ Function *FunctionAST::Codegen() { BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence();</b> // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); if (Value *RetVal = Body->Codegen()) { @@ -1398,7 +1398,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); default: break; } @@ -1443,9 +1443,9 @@ Value *IfExprAST::Codegen() { // Create blocks for the then and else cases. Insert the 'then' block at the // end of the function. - BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction); - BasicBlock *ElseBB = BasicBlock::Create("else"); - BasicBlock *MergeBB = BasicBlock::Create("ifcont"); + BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction); + BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else"); + BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont"); Builder.CreateCondBr(CondV, ThenBB, ElseBB); @@ -1473,7 +1473,7 @@ Value *IfExprAST::Codegen() { // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); Builder.SetInsertPoint(MergeBB); - PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp"); + PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -1505,7 +1505,7 @@ Value *ForExprAST::Codegen() { // block. Function *TheFunction = Builder.GetInsertBlock()->getParent(); BasicBlock *PreheaderBB = Builder.GetInsertBlock(); - BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction); + BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction); // Insert an explicit fall through from the current block to the LoopBB. Builder.CreateBr(LoopBB); @@ -1514,7 +1514,7 @@ Value *ForExprAST::Codegen() { Builder.SetInsertPoint(LoopBB); // Start the PHI node with an entry for Start. - PHINode *Variable = Builder.CreatePHI(Type::DoubleTy, VarName.c_str()); + PHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), VarName.c_str()); Variable->addIncoming(StartVal, PreheaderBB); // Within the loop, the variable is defined equal to the PHI node. If it @@ -1551,7 +1551,7 @@ Value *ForExprAST::Codegen() { // Create the "after loop" block and insert it. BasicBlock *LoopEndBB = Builder.GetInsertBlock(); - BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction); + BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction); // Insert the conditional branch into the end of LoopEndBB. Builder.CreateCondBr(EndCond, LoopBB, AfterBB); @@ -1570,13 +1570,13 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return Constant::getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::getDoubleTy(getGlobalContext())); } Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); @@ -1625,7 +1625,7 @@ Function *FunctionAST::Codegen() { BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence(); // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); if (Value *RetVal = Body->Codegen()) { diff --git a/docs/tutorial/LangImpl7.html b/docs/tutorial/LangImpl7.html index 691bfacb60..81386bc1ab 100644 --- a/docs/tutorial/LangImpl7.html +++ b/docs/tutorial/LangImpl7.html @@ -424,7 +424,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin()); - return TmpB.CreateAlloca(Type::DoubleTy, 0, VarName.c_str()); + return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0, VarName.c_str()); } </pre> </div> @@ -1618,7 +1618,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin()); - return TmpB.CreateAlloca(Type::DoubleTy, 0, VarName.c_str()); + return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0, VarName.c_str()); } @@ -1678,7 +1678,7 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), "booltmp"); default: break; } @@ -1723,9 +1723,9 @@ Value *IfExprAST::Codegen() { // Create blocks for the then and else cases. Insert the 'then' block at the // end of the function. - BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction); - BasicBlock *ElseBB = BasicBlock::Create("else"); - BasicBlock *MergeBB = BasicBlock::Create("ifcont"); + BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction); + BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else"); + BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont"); Builder.CreateCondBr(CondV, ThenBB, ElseBB); @@ -1753,7 +1753,7 @@ Value *IfExprAST::Codegen() { // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); Builder.SetInsertPoint(MergeBB); - PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp"); + PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -1796,7 +1796,7 @@ Value *ForExprAST::Codegen() { // Make the new basic block for the loop header, inserting after current // block. BasicBlock *PreheaderBB = Builder.GetInsertBlock(); - BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction); + BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction); // Insert an explicit fall through from the current block to the LoopBB. Builder.CreateBr(LoopBB); @@ -1842,7 +1842,7 @@ Value *ForExprAST::Codegen() { // Create the "after loop" block and insert it. BasicBlock *LoopEndBB = Builder.GetInsertBlock(); - BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction); + BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction); // Insert the conditional branch into the end of LoopEndBB. Builder.CreateCondBr(EndCond, LoopBB, AfterBB); @@ -1858,7 +1858,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return Constant::getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::getDoubleTy(getGlobalContext())); } Value *VarExprAST::Codegen() { @@ -1910,8 +1910,8 @@ Value *VarExprAST::Codegen() { Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); @@ -1973,7 +1973,7 @@ Function *FunctionAST::Codegen() { BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence(); // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); // Add all arguments to the symbol table and create their allocas. diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index 8651b6e918..5cf2b883bc 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -54,31 +54,31 @@ void BrainF::header(LLVMContext& C) { //Function prototypes //declare void @llvm.memset.i32(i8 *, i8, i32, i32) - const Type *Tys[] = { Type::Int32Ty }; + const Type *Tys[] = { Type::getInt32Ty(C) }; Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset, Tys, 1); //declare i32 @getchar() getchar_func = cast<Function>(module-> - getOrInsertFunction("getchar", IntegerType::Int32Ty, NULL)); + getOrInsertFunction("getchar", IntegerType::getInt32Ty(C), NULL)); //declare i32 @putchar(i32) putchar_func = cast<Function>(module-> - getOrInsertFunction("putchar", IntegerType::Int32Ty, - IntegerType::Int32Ty, NULL)); + getOrInsertFunction("putchar", IntegerType::getInt32Ty(C), + IntegerType::getInt32Ty(C), NULL)); //Function header //define void @brainf() brainf_func = cast<Function>(module-> - getOrInsertFunction("brainf", Type::VoidTy, NULL)); + getOrInsertFunction("brainf", Type::getVoidTy(C), NULL)); - builder = new IRBuilder<>(BasicBlock::Create(label, brainf_func)); + builder = new IRBuilder<>(BasicBlock::Create(C, label, brainf_func)); //%arr = malloc i8, i32 %d ConstantInt *val_mem = ConstantInt::get(C, APInt(32, memtotal)); - ptr_arr = builder->CreateMalloc(IntegerType::Int8Ty, val_mem, "arr"); + ptr_arr = builder->CreateMalloc(IntegerType::getInt8Ty(C), val_mem, "arr"); //call void @llvm.memset.i32(i8 *%arr, i8 0, i32 %d, i32 1) { @@ -110,13 +110,13 @@ void BrainF::header(LLVMContext& C) { //Function footer //brainf.end: - endbb = BasicBlock::Create(label, brainf_func); + endbb = BasicBlock::Create(C, label, brainf_func); //free i8 *%arr new FreeInst(ptr_arr, endbb); //ret void - ReturnInst::Create(endbb); + ReturnInst::Create(C, endbb); @@ -125,7 +125,7 @@ void BrainF::header(LLVMContext& C) { { //@aberrormsg = internal constant [%d x i8] c"\00" Constant *msg_0 = - ConstantArray::get("Error: The head has left the tape.", true); + ConstantArray::get(C, "Error: The head has left the tape.", true); GlobalVariable *aberrormsg = new GlobalVariable( *module, @@ -137,15 +137,15 @@ void BrainF::header(LLVMContext& C) { //declare i32 @puts(i8 *) Function *puts_func = cast<Function>(module-> - getOrInsertFunction("puts", IntegerType::Int32Ty, - PointerType::getUnqual(IntegerType::Int8Ty), NULL)); + getOrInsertFunction("puts", IntegerType::getInt32Ty(C), + PointerType::getUnqual(IntegerType::getInt8Ty(C)), NULL)); //brainf.aberror: - aberrorbb = BasicBlock::Create(label, brainf_func); + aberrorbb = BasicBlock::Create(C, label, brainf_func); //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0)) { - Constant *zero_32 = Constant::getNullValue(IntegerType::Int32Ty); + Constant *zero_32 = Constant::getNullValue(IntegerType::getInt32Ty(C)); Constant *gep_params[] = { zero_32, @@ -198,7 +198,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, //%tape.%d = trunc i32 %tape.%d to i8 Value *tape_1 = builder-> - CreateTrunc(tape_0, IntegerType::Int8Ty, tapereg); + CreateTrunc(tape_0, IntegerType::getInt8Ty(C), tapereg); //store i8 %tape.%d, i8 *%head.%d builder->CreateStore(tape_1, curhead); @@ -212,7 +212,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, //%tape.%d = sext i8 %tape.%d to i32 Value *tape_1 = builder-> - CreateSExt(tape_0, IntegerType::Int32Ty, tapereg); + CreateSExt(tape_0, IntegerType::getInt32Ty(C), tapereg); //call i32 @putchar(i32 %tape.%d) Value *putchar_params[] = { @@ -248,7 +248,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, CreateOr(test_0, test_1, testreg); //br i1 %test.%d, label %main.%d, label %main.%d - BasicBlock *nextbb = BasicBlock::Create(label, brainf_func); + BasicBlock *nextbb = BasicBlock::Create(C, label, brainf_func); builder->CreateCondBr(test_2, aberrorbb, nextbb); //main.%d: @@ -274,17 +274,17 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, case SYM_LOOP: { //br label %main.%d - BasicBlock *testbb = BasicBlock::Create(label, brainf_func); + BasicBlock *testbb = BasicBlock::Create(C, label, brainf_func); builder->CreateBr(testbb); //main.%d: BasicBlock *bb_0 = builder->GetInsertBlock(); - BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func); + BasicBlock *bb_1 = BasicBlock::Create(C, label, brainf_func); builder->SetInsertPoint(bb_1); // Make part of PHI instruction now, wait until end of loop to finish PHINode *phi_0 = - PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty), + PHINode::Create(PointerType::getUnqual(IntegerType::getInt8Ty(C)), headreg, testbb); phi_0->reserveOperandSpace(2); phi_0->addIncoming(curhead, bb_0); @@ -432,7 +432,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, ConstantInt::get(C, APInt(8, 0)), testreg); //br i1 %test.%d, label %main.%d, label %main.%d - BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func); + BasicBlock *bb_0 = BasicBlock::Create(C, label, brainf_func); BranchInst::Create(bb_0, oldbb, test_0, testbb); //main.%d: @@ -440,7 +440,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb, //%head.%d = phi i8 *[%head.%d, %main.%d] PHINode *phi_1 = builder-> - CreatePHI(PointerType::getUnqual(IntegerType::Int8Ty), headreg); + CreatePHI(PointerType::getUnqual(IntegerType::getInt8Ty(C)), headreg); phi_1->reserveOperandSpace(1); phi_1->addIncoming(head_0, testbb); curhead = phi_1; diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp index 8c62ae2900..f4f1e79b82 100644 --- a/examples/BrainF/BrainFDriver.cpp +++ b/examples/BrainF/BrainFDriver.cpp @@ -58,9 +58,10 @@ JIT("jit", cl::desc("Run program Just-In-Time")); void addMainFunction(Module *mod) { //define i32 @main(i32 %argc, i8 **%argv) Function *main_func = cast<Function>(mod-> - getOrInsertFunction("main", IntegerType::Int32Ty, IntegerType::Int32Ty, + getOrInsertFunction("main", IntegerType::getInt32Ty(mod->getContext()), + IntegerType::getInt32Ty(mod->getContext()), PointerType::getUnqual(PointerType::getUnqual( - IntegerType::Int8Ty)), NULL)); + IntegerType::getInt8Ty(mod->getContext()))), NULL)); { Function::arg_iterator args = main_func->arg_begin(); Value *arg_0 = args++; @@ -70,7 +71,7 @@ void addMainFunction(Module *mod) { } //main.0: - BasicBlock *bb = BasicBlock::Create("main.0", main_func); + BasicBlock *bb = BasicBlock::Create(mod->getContext(), "main.0", main_func); //call void @brainf() { @@ -80,7 +81,8 @@ void addMainFunction(Module *mod) { } //ret i32 0 - ReturnInst::Create(ConstantInt::get(getGlobalContext(), APInt(32, 0)), bb); + ReturnInst::Create(mod->getContext(), + ConstantInt::get(mod->getContext(), APInt(32, 0)), bb); } int main(int argc, char **argv) { diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index 48efd5a1cc..b1a4691a9f 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -40,31 +40,32 @@ static Function *CreateFibFunction(Module *M, LLVMContext &Context) { // Create the fib function and insert it into module M. This function is said // to return an int and take an int parameter. Function *FibF = - cast<Function>(M->getOrInsertFunction("fib", Type::Int32Ty, Type::Int32Ty, + cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context), + Type::getInt32Ty(Context), (Type *)0)); // Add a basic block to the function. - BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF); + BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FibF); // Get pointers to the constants. - Value *One = ConstantInt::get(Type::Int32Ty, 1); - Value *Two = ConstantInt::get(Type::Int32Ty, 2); + Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1); + Value *Two = ConstantInt::get(Type::getInt32Ty(Context), 2); // Get pointer to the integer argument of the add1 function... Argument *ArgX = FibF->arg_begin(); // Get the arg. ArgX->setName("AnArg"); // Give it a nice symbolic name for fun. // Create the true_block. - BasicBlock *RetBB = BasicBlock::Create("return", FibF); + BasicBlock *RetBB = BasicBlock::Create(Context, "return", FibF); // Create an exit block. - BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF); + BasicBlock* RecurseBB = BasicBlock::Create(Context, "recurse", FibF); // Create the "if (arg <= 2) goto exitbb" Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond"); BranchInst::Create(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 - ReturnInst::Create(One, RetBB); + ReturnInst::Create(Context, One, RetBB); // create fib(x-1) Value *Sub = BinaryOperator::CreateSub(ArgX, One, "arg", RecurseBB); @@ -82,7 +83,7 @@ static Function *CreateFibFunction(Module *M, LLVMContext &Context) { "addresult", RecurseBB); // Create the return instruction and add it to the basic block - ReturnInst::Create(Sum, RecurseBB); + ReturnInst::Create(Context, Sum, RecurseBB); return FibF; } diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index 7a99ed4473..ec9c2e6854 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -61,15 +61,16 @@ int main() { // function will have a return type of "int" and take an argument of "int". // The '0' terminates the list of argument types. Function *Add1F = - cast<Function>(M->getOrInsertFunction("add1", Type::Int32Ty, Type::Int32Ty, + cast<Function>(M->getOrInsertFunction("add1", Type::getInt32Ty(Context), + Type::getInt32Ty(Context), (Type *)0)); // Add a basic block to the function. As before, it automatically inserts // because of the last argument. - BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F); + BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", Add1F); // Get pointers to the constant `1'. - Value *One = ConstantInt::get(Type::Int32Ty, 1); + Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1); // Get pointers to the integer argument of the add1 function... assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg @@ -80,7 +81,7 @@ int main() { Instruction *Add = BinaryOperator::CreateAdd(One, ArgX, "addresult", BB); // Create the return instruction and add it to the basic block - ReturnInst::Create(Add, BB); + ReturnInst::Create(Context, Add, BB); // Now, function add1 is ready. @@ -88,20 +89,21 @@ int main() { // Now we going to create function `foo', which returns an int and takes no // arguments. Function *FooF = - cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0)); + cast<Function>(M->getOrInsertFunction("foo", Type::getInt32Ty(Context), + (Type *)0)); // Add a basic block to the FooF function. - BB = BasicBlock::Create("EntryBlock", FooF); + BB = BasicBlock::Create(Context, "EntryBlock", FooF); // Get pointers to the constant `10'. - Value *Ten = ConstantInt::get(Type::Int32Ty, 10); + Value *Ten = ConstantInt::get(Type::getInt32Ty(Context), 10); // Pass Ten to the call call: CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB); Add1CallRes->setTailCall(true); // Create the return instruction and add it to the basic block. - ReturnInst::Create(Add1CallRes, BB); + ReturnInst::Create(Context, Add1CallRes, BB); // Now we create the JIT. ExecutionEngine* EE = EngineBuilder(M).create(); diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp index 22b8285e92..3c1ce8b4d4 100644 --- a/examples/Kaleidoscope/toy.cpp +++ b/examples/Kaleidoscope/toy.cpp @@ -618,7 +618,8 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin()); - return TmpB.CreateAlloca(Type::DoubleTy, 0, VarName.c_str()); + return TmpB.CreateAlloca(Type::getDoubleTy(getGlobalContext()), 0, + VarName.c_str()); } @@ -678,7 +679,8 @@ Value *BinaryExprAST::Codegen() { case '<': L = Builder.CreateFCmpULT(L, R, "cmptmp"); // Convert bool 0/1 to double 0.0 or 1.0 - return Builder.CreateUIToFP(L, Type::DoubleTy, "booltmp"); + return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()), + "booltmp"); default: break; } @@ -723,9 +725,9 @@ Value *IfExprAST::Codegen() { // Create blocks for the then and else cases. Insert the 'then' block at the // end of the function. - BasicBlock *ThenBB = BasicBlock::Create("then", TheFunction); - BasicBlock *ElseBB = BasicBlock::Create("else"); - BasicBlock *MergeBB = BasicBlock::Create("ifcont"); + BasicBlock *ThenBB = BasicBlock::Create(getGlobalContext(), "then", TheFunction); + BasicBlock *ElseBB = BasicBlock::Create(getGlobalContext(), "else"); + BasicBlock *MergeBB = BasicBlock::Create(getGlobalContext(), "ifcont"); Builder.CreateCondBr(CondV, ThenBB, ElseBB); @@ -753,7 +755,8 @@ Value *IfExprAST::Codegen() { // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); Builder.SetInsertPoint(MergeBB); - PHINode *PN = Builder.CreatePHI(Type::DoubleTy, "iftmp"); + PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), + "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -795,7 +798,7 @@ Value *ForExprAST::Codegen() { // Make the new basic block for the loop header, inserting after current // block. - BasicBlock *LoopBB = BasicBlock::Create("loop", TheFunction); + BasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), "loop", TheFunction); // Insert an explicit fall through from the current block to the LoopBB. Builder.CreateBr(LoopBB); @@ -840,7 +843,7 @@ Value *ForExprAST::Codegen() { "loopcond"); // Create the "after loop" block and insert it. - BasicBlock *AfterBB = BasicBlock::Create("afterloop", TheFunction); + BasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), "afterloop", TheFunction); // Insert the conditional branch into the end of LoopEndBB. Builder.CreateCondBr(EndCond, LoopBB, AfterBB); @@ -856,7 +859,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return Constant::getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::getDoubleTy(getGlobalContext())); } Value *VarExprAST::Codegen() { @@ -908,8 +911,10 @@ Value *VarExprAST::Codegen() { Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. - std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy); - FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false); + std::vector<const Type*> Doubles(Args.size(), + Type::getDoubleTy(getGlobalContext())); + FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), + Doubles, false); Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule); @@ -971,7 +976,7 @@ Function *FunctionAST::Codegen() { BinopPrecedence[Proto->getOperatorName()] = Proto->getBinaryPrecedence(); // Create a new basic block to start insertion into. - BasicBlock *BB = BasicBlock::Create("entry", TheFunction); + BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction); Builder.SetInsertPoint(BB); // Add all arguments to the symbol table and create their allocas. diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index fc487af056..ded78c7b17 100644 --- a/examples/ModuleMaker/ModuleMaker.cpp +++ b/examples/ModuleMaker/ModuleMaker.cpp @@ -31,7 +31,7 @@ int main() { // Create the main function: first create the type 'int ()' FunctionType *FT = - FunctionType::get(Type::Int32Ty, /*not vararg*/false); + FunctionType::get(Type::getInt32Ty(Context), /*not vararg*/false); // By passing a module as the last parameter to the Function constructor, // it automatically gets appended to the Module. @@ -39,11 +39,11 @@ int main() { // Add a basic block to the function... again, it automatically inserts // because of the last argument. - BasicBlock *BB = BasicBlock::Create("EntryBlock", F); + BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", F); // Get pointers to the constant integers... - Value *Two = ConstantInt::get(Type::Int32Ty, 2); - Value *Three = ConstantInt::get(Type::Int32Ty, 3); + Value *Two = ConstantInt::get(Type::getInt32Ty(Context), 2); + Value *Three = ConstantInt::get(Type::getInt32Ty(Context), 3); // Create the add instruction... does not insert... Instruction *Add = BinaryOperator::Create(Instruction::Add, Two, Three, @@ -53,7 +53,7 @@ int main() { BB->getInstList().push_back(Add); // Create the return instruction and add it to the basic block - BB->getInstList().push_back(ReturnInst::Create(Add)); + BB->getInstList().push_back(ReturnInst::Create(Context, Add)); // Output the bitcode file to stdout WriteBitcodeToFile(M, std::cout); diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index 83e2640636..be40a28215 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -36,15 +36,17 @@ static Function* createAdd1(Module *M) { // function will have a return type of "int" and take an argument of "int". // The '0' terminates the list of argument types. Function *Add1F = - cast<Function>(M->getOrInsertFunction("add1", Type::Int32Ty, Type::Int32Ty, + cast<Function>(M->getOrInsertFunction("add1", + Type::getInt32Ty(M->getContext()), + Type::getInt32Ty(M->getContext()), (Type *)0)); // Add a basic block to the function. As before, it automatically inserts // because of the last argument. - BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F); + BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", Add1F); // Get pointers to the constant `1'. - Value *One = ConstantInt::get(Type::Int32Ty, 1); + Value *One = ConstantInt::get(Type::getInt32Ty(M->getContext()), 1); // Get pointers to the integer argument of the add1 function... assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg @@ -55,7 +57,7 @@ static Function* createAdd1(Module *M) { Instruction *Add = BinaryOperator::CreateAdd(One, ArgX, "addresult", BB); // Create the return instruction and add it to the basic block - ReturnInst::Create(Add, BB); + ReturnInst::Create(M->getContext(), Add, BB); // Now, function add1 is ready. return Add1F; @@ -65,31 +67,33 @@ static Function *CreateFibFunction(Module *M) { // Create the fib function and insert it into module M. This function is said // to return an int and take an int parameter. Function *FibF = - cast<Function>(M->getOrInsertFunction("fib", Type::Int32Ty, Type::Int32Ty, + cast<Function>(M->getOrInsertFunction("fib", + Type::getInt32Ty(M->getContext()), + Type::getInt32Ty(M->getContext()), (Type *)0)); // Add a basic block to the function. - BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF); + BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF); // Get pointers to the constants. - Value *One = ConstantInt::get(Type::Int32Ty, 1); - Value *Two = ConstantInt::get(Type::Int32Ty, 2); + Value *One = ConstantInt::get(Type::getInt32Ty(M->getContext()), 1); + Value *Two = ConstantInt::get(Type::getInt32Ty(M->getContext()), 2); // Get pointer to the integer argument of the add1 function... Argument *ArgX = FibF->arg_begin(); // Get the arg. ArgX->setName("AnArg"); // Give it a nice symbolic name for fun. // Create the true_block. - BasicBlock *RetBB = BasicBlock::Create("return", FibF); + BasicBlock *RetBB = BasicBlock::Create(M->getContext(), "return", FibF); // Create an exit block. - BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF); + BasicBlock* RecurseBB = BasicBlock::Create(M->getContext(), "recurse", FibF); // Create the "if (arg < 2) goto exitbb" Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond"); BranchInst::Create(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 - ReturnInst::Create(One, RetBB); + ReturnInst::Create(M->getContext(), One, RetBB); // create fib(x-1) Value *Sub = BinaryOperator::CreateSub(ArgX, One, "arg", RecurseBB); @@ -104,7 +108,7 @@ static Function *CreateFibFunction(Module *M) { BinaryOperator::CreateAdd(CallFibX1, CallFibX2, "addresult", RecurseBB); // Create the return instruction and add it to the basic block - ReturnInst::Create(Sum, RecurseBB); + ReturnInst::Create(M->getContext(), Sum, RecurseBB); return FibF; } diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index eabc1a0d2b..9138d28c68 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -83,8 +83,8 @@ private: /// is automatically inserted at either the end of the function (if /// InsertBefore is null), or before the specified basic block. /// - explicit BasicBlock(const Twine &Name = "", Function *Parent = 0, - BasicBlock *InsertBefore = 0); + explicit BasicBlock(LLVMContext &C, const Twine &Name = "", + Function *Parent = 0, BasicBlock *InsertBefore = 0); public: /// getContext - Get the context in which this basic block lives, /// or null if it is not currently attached to a function. @@ -97,9 +97,9 @@ public: /// Create - Creates a new BasicBlock. If the Parent parameter is specified, /// the basic block is automatically inserted at either the end of the /// function (if InsertBefore is 0), or before the specified basic block. - static BasicBlock *Create(const Twine &Name = "", Function *Parent = 0, - BasicBlock *InsertBefore = 0) { - return new BasicBlock(Name, Parent, InsertBefore); + static BasicBlock *Create(LLVMContext &Context, const Twine &Name = "", + Function *Parent = 0,BasicBlock *InsertBefore = 0) { + return new BasicBlock(Context, Name, Parent, InsertBefore); } ~BasicBlock(); diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index 30b48beb87..e26bb62c35 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -346,7 +346,8 @@ public: /// of the array by one (you've been warned). However, in some situations /// this is not desired so if AddNull==false then the string is copied without /// null termination. - static Constant* get(const StringRef &Initializer, bool AddNull = true); + static Constant* get(LLVMContext &Context, const StringRef &Initializer, + bool AddNull = true); /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index e7b226be7b..a8603acfbe 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -102,7 +102,7 @@ public: /// that instance will be returned. Otherwise a new one will be created. Only /// one instance with a given NumBits value is ever created. /// @brief Get or create an IntegerType instance. - static const IntegerType* get(unsigned NumBits); + static const IntegerType* get(LLVMContext &C, unsigned NumBits); /// @brief Get the number of bits in this IntegerType unsigned getBitWidth() const { return getSubclassData(); } @@ -399,7 +399,7 @@ public: /// static VectorType *getInteger(const VectorType *VTy) { unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); - const Type *EltTy = IntegerType::get(EltBits); + const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits); return VectorType::get(EltTy, VTy->getNumElements()); } @@ -409,7 +409,7 @@ public: /// static VectorType *getExtendedElementVectorType(const VectorType *VTy) { unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); - const Type *EltTy = IntegerType::get(EltBits * 2); + const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2); return VectorType::get(EltTy, VTy->getNumElements()); } @@ -421,7 +421,7 @@ public: unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); assert((EltBits & 1) == 0 && "Cannot truncate vector element with odd bit-width"); - const Type *EltTy = IntegerType::get(EltBits / 2); + const Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2); return VectorType::get(EltTy, VTy->getNumElements()); } diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index faff7986ec..560c32b73a 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -708,9 +708,10 @@ public: /// @brief Create a result type for fcmp/icmp static const Type* makeCmpResultType(const Type* opnd_type) { if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) { - return VectorType::get(Type::Int1Ty, vt->getNumElements()); + return VectorType::get(Type::getInt1Ty(opnd_type->getContext()), + vt->getNumElements()); } - return Type::Int1Ty; + return Type::getInt1Ty(opnd_type->getContext()); } }; diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 1e1cec1d12..33af5bcd7a 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -2025,18 +2025,21 @@ private: // // NOTE: If the Value* passed is of type void then the constructor behaves as // if it was passed NULL. - explicit ReturnInst(Value *retVal = 0, Instruction *InsertBefore = 0); - ReturnInst(Value *retVal, BasicBlock *InsertAtEnd); - explicit ReturnInst(BasicBlock *InsertAtEnd); + explicit ReturnInst(LLVMContext &C, Value *retVal = 0, + Instruction *InsertBefore = 0); + ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd); + explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd); public: - static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) { - return new(!!retVal) ReturnInst(retVal, InsertBefore); + static ReturnInst* Create(LLVMContext &C, Value *retVal = 0, + Instruction *InsertBefore = 0) { + return new(!!retVal) ReturnInst(C, retVal, InsertBefore); } - static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) { - return new(!!retVal) ReturnInst(retVal, InsertAtEnd); + static ReturnInst* Create(LLVMContext &C, Value *retVal, + BasicBlock *InsertAtEnd) { + return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd); } - static ReturnInst* Create(BasicBlock *InsertAtEnd) { - return new(0) ReturnInst(InsertAtEnd); + static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) { + return new(0) ReturnInst(C, InsertAtEnd); } virtual ~ReturnInst(); @@ -2591,8 +2594,8 @@ public: void *operator new(size_t s) { return User::operator new(s, 0); } - explicit UnwindInst(Instruction *InsertBefore = 0); - explicit UnwindInst(BasicBlock *InsertAtEnd); + explicit UnwindInst(LLVMContext &C, Instruction *InsertBefore = 0); + explicit UnwindInst(LLVMContext &C, BasicBlock *InsertAtEnd); virtual UnwindInst *clone(LLVMContext &Context) const; @@ -2628,8 +2631,8 @@ public: void *operator new(size_t s) { return User::operator new(s, 0); } - explicit UnreachableInst(Instruction *InsertBefore = 0); - explicit UnreachableInst(BasicBlock *InsertAtEnd); + explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = 0); + explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd); virtual UnreachableInst *clone(LLVMContext &Context) const; diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 95b4eaa294..56a640ea11 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -25,6 +25,9 @@ class LLVMContextImpl; /// LLVMContext itself provides no locking guarantees, so you should be careful /// to have one context per thread. class LLVMContext { + // DO NOT IMPLEMENT + LLVMContext(LLVMContext&); + void operator=(LLVMContext&); public: LLVMContextImpl* pImpl; bool RemoveDeadMetadata(); diff --git a/include/llvm/LinkAllVMCore.h b/include/llvm/LinkAllVMCore.h index e5a51971f1..0ee18d57a0 100644 --- a/include/llvm/LinkAllVMCore.h +++ b/include/llvm/LinkAllVMCore.h @@ -46,7 +46,7 @@ namespace { if (std::getenv("bar") != (char*) -1) return; llvm::Module* M = new llvm::Module("", llvm::getGlobalContext()); - (void)new llvm::UnreachableInst(); + (void)new llvm::UnreachableInst(llvm::getGlobalContext()); (void) llvm::createVerifierPass(); (void) new llvm::Mangler(*M,""); } diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 8533efddb0..f36de687d6 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -44,12 +44,6 @@ protected: void resizeOperands(unsigned NumOps); public: - /// getType() specialization - Type is always MetadataTy. - /// - inline const Type *getType() const { - return Type::MetadataTy; - } - /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. This always returns false because getNullValue will never /// produce metadata. @@ -76,8 +70,8 @@ class MDString : public MetadataBase { StringRef Str; protected: - explicit MDString(const char *begin, unsigned l) - : MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {} + explicit MDString(LLVMContext &C, const char *begin, unsigned l) + : MetadataBase(Type::getMetadataTy(C), Value::MDStringVal), Str(begin, l) {} public: // Do not allocate any space for operands. @@ -119,7 +113,7 @@ class MDNode : public MetadataBase { friend struct ConstantCreator<MDNode, Type, std::vector<Value*> >; protected: - explicit MDNode(Value*const* Vals, unsigned NumVals); + explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals); public: // Do not allocate any space for operands. void *operator new(size_t s) { @@ -156,12 +150,6 @@ public: elem_iterator elem_begin() { return Node.begin(); } elem_iterator elem_end() { return Node.end(); } - /// getType() specialization - Type is always MetadataTy. - /// - inline const Type *getType() const { - return Type::MetadataTy; - } - /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. This always returns false because getNullValue will never /// produce metadata. @@ -217,16 +205,17 @@ class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> { typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator; protected: - explicit NamedMDNode(const Twine &N, MetadataBase*const* Vals, + explicit NamedMDNode(LLVMContext &C, const Twine &N, MetadataBase*const* Vals, unsigned NumVals, Module *M = 0); public: // Do not allocate any space for operands. void *operator new(size_t s) { return User::operator new(s, 0); } - static NamedMDNode *Create(const Twine &N, MetadataBase*const*MDs, + static NamedMDNode *Create(LLVMContext &C, const Twine &N, + MetadataBase*const*MDs, unsigned NumMDs, Module *M = 0) { - return new NamedMDNode(N, MDs, NumMDs, M); + return new NamedMDNode(C, N, MDs, NumMDs, M); } static NamedMDNode *Create(const NamedMDNode *NMD, Module *M = 0); @@ -271,12 +260,6 @@ public: elem_iterator elem_begin() { return Node.begin(); } elem_iterator elem_end() { return Node.end(); } - /// getType() specialization - Type is always MetadataTy. - /// - inline const Type *getType() const { - return Type::MetadataTy; - } - /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. This always returns false because getNullValue will never /// produce metadata. diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 9e0073a378..e216d4c956 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -129,14 +129,14 @@ public: /// CreateRetVoid - Create a 'ret void' instruction. ReturnInst *CreateRetVoid() { - return Insert(ReturnInst::Create()); + return Insert(ReturnInst::Create(getGlobalContext())); } /// @verbatim /// CreateRet - Create a 'ret <val>' instruction. /// @endverbatim ReturnInst *CreateRet(Value *V) { - return Insert(ReturnInst::Create(V)); + return Insert(ReturnInst::Create(getGlobalContext(), V)); } /// CreateAggregateRet - Create a sequence of N insertvalue instructions, @@ -151,7 +151,7 @@ public: Value *V = UndefValue::get(RetType); for (unsigned i = 0; i != N; ++i) V = CreateInsertValue(V, retVals[i], i, "mrv"); - return Insert(ReturnInst::Create(V)); + return Insert(ReturnInst::Create(getGlobalContext(), V)); } /// CreateBr - Create an unconditional 'br label X' instruction. @@ -182,11 +182,11 @@ public: } UnwindInst *CreateUnwind() { - return Insert(new UnwindInst()); + return Insert(new UnwindInst(Context)); } UnreachableInst *CreateUnreachable() { - return Insert(new UnreachableInst()); + return Insert(new UnreachableInst(Context)); } //===--------------------------------------------------------------------===// @@ -406,7 +406,7 @@ public: return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idx), Name); } Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") { - Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0); + Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0); if (Constant *PC = dyn_cast<Constant>(Ptr)) return Folder.CreateGetElementPtr(PC, &Idx, 1); @@ -415,7 +415,7 @@ public: } Value *CreateConstInBoundsGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") { - Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0); + Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0); if (Constant *PC = dyn_cast<Constant>(Ptr)) return Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1); @@ -425,8 +425,8 @@ public: Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1, const char *Name = "") { Value *Idxs[] = { - ConstantInt::get(Type::Int32Ty, Idx0), - ConstantInt::get(Type::Int32Ty, Idx1) + ConstantInt::get(Type::getInt32Ty(Context), Idx0), + ConstantInt::get(Type::getInt32Ty(Context), Idx1) }; if (Constant *PC = dyn_cast<Constant>(Ptr)) @@ -437,8 +437,8 @@ public: Value *CreateConstInBoundsGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1, const char *Name = "") { Value *Idxs[] = { - ConstantInt::get(Type::Int32Ty, Idx0), - ConstantInt::get(Type::Int32Ty, Idx1) + ConstantInt::get(Type::getInt32Ty(Context), Idx0), + ConstantInt::get(Type::getInt32Ty(Context), Idx1) }; if (Constant *PC = dyn_cast<Constant>(Ptr)) @@ -447,7 +447,7 @@ public: return Insert(GetElementPtrInst::CreateInBounds(Ptr, Idxs, Idxs+2), Name); } Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") { - Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0); + Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0); if (Constant *PC = dyn_cast<Constant>(Ptr)) return Folder.CreateGetElementPtr(PC, &Idx, 1); @@ -456,7 +456,7 @@ public: } Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") { - Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0); + Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0); if (Constant *PC = dyn_cast<Constant>(Ptr)) return Folder.CreateInBoundsGetElementPtr(PC, &Idx, 1); @@ -466,8 +466,8 @@ public: Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const char *Name = "") { Value *Idxs[] = { - ConstantInt::get(Type::Int64Ty, Idx0), - ConstantInt::get(Type::Int64Ty, Idx1) + ConstantInt::get(Type::getInt64Ty(Context), Idx0), + ConstantInt::get(Type::getInt64Ty(Context), Idx1) }; if (Constant *PC = dyn_cast<Constant>(Ptr)) @@ -478,8 +478,8 @@ public: Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1, const char *Name = "") { Value *Idxs[] = { - ConstantInt::get(Type::Int64Ty, Idx0), - ConstantInt::get(Type::Int64Ty, Idx1) + ConstantInt::get(Type::getInt64Ty(Context), Idx0), + ConstantInt::get(Type::getInt64Ty(Context), Idx1) }; if (Constant *PC = dyn_cast<Constant>(Ptr)) @@ -491,7 +491,7 @@ public: return CreateConstInBoundsGEP2_32(Ptr, 0, Idx, Name); } Value *CreateGlobalString(const char *Str = "", const char *Name = "") { - Constant *StrConstant = ConstantArray::get(Str, true); + Constant *StrConstant = ConstantArray::get(Context, Str, true); Module &M = *BB->getParent()->getParent(); GlobalVariable *gv = new GlobalVariable(M, StrConstant->getType(), @@ -506,7 +506,7 @@ public: } Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") { Value *gv = CreateGlobalString(Str, Name); - Value *zero = ConstantInt::get(Type::Int32Ty, 0); + Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0); Value *Args[] = { zero, zero }; return CreateInBoundsGEP(gv, Args, Args+2, Name); } @@ -802,8 +802,8 @@ public: assert(LHS->getType() == RHS->getType() && "Pointer subtraction operand types must match!"); const PointerType *ArgType = cast<PointerType>(LHS->getType()); - Value *LHS_int = CreatePtrToInt(LHS, Type::Int64Ty); - Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty); + Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context)); + Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context)); Value *Difference = CreateSub(LHS_int, RHS_int); return CreateExactSDiv(Difference, ConstantExpr::getSizeOf(ArgType->getElementType()), diff --git a/include/llvm/Support/TypeBuilder.h b/include/llvm/Support/TypeBuilder.h index 1f85f1d125..64af647cdb 100644 --- a/include/llvm/Support/TypeBuilder.h +++ b/include/llvm/Support/TypeBuilder.h @@ -161,7 +161,7 @@ template<> class TypeBuilder<T, false> { \ public: \ static const IntegerType *get(LLVMContext &Context) { \ static const IntegerType *const result = \ - IntegerType::get(sizeof(T) * CHAR_BIT); \ + IntegerType::get(Context, sizeof(T) * CHAR_BIT); \ return result; \ } \ }; \ @@ -190,53 +190,53 @@ DEFINE_INTEGRAL_TYPEBUILDER(unsigned long long); template<uint32_t num_bits, bool cross> class TypeBuilder<types::i<num_bits>, cross> { public: - static const IntegerType *get(LLVMContext &Context) { - static const IntegerType *const result = IntegerType::get(num_bits); + static const IntegerType *get(LLVMContext &C) { + static const IntegerType *const result = IntegerType::get(C, num_bits); return result; } }; template<> class TypeBuilder<float, false> { public: - static const Type *get(LLVMContext&) { - return Type::FloatTy; + static const Type *get(LLVMContext& C) { + return Type::getFloatTy(C); } }; template<> class TypeBuilder<float, true> {}; template<> class TypeBuilder<double, false> { public: - static const Type *get(LLVMContext&) { - return Type::DoubleTy; + static const Type *get(LLVMContext& C) { + return Type::getDoubleTy(C); } }; template<> class TypeBuilder<double, true> {}; template<bool cross> class TypeBuilder<types::ieee_float, cross> { public: - static const Type *get(LLVMContext&) { return Type::FloatTy; } + static const Type *get(LLVMContext& C) { return Type::getFloatTy(C); } }; template<bool cross> class TypeBuilder<types::ieee_double, cross> { public: - static const Type *get(LLVMContext&) { return Type::DoubleTy; } + static const Type *get(LLVMContext& C) { return Type::getDoubleTy(C); } }; template<bool cross> class TypeBuilder<types::x86_fp80, cross> { public: - static const Type *get(LLVMContext&) { return Type::X86_FP80Ty; } + static const Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); } }; template<bool cross> class TypeBuilder<types::fp128, cross> { public: - static const Type *get(LLVMContext&) { return Type::FP128Ty; } + static const Type *get(LLVMContext& C) { return Type::getFP128Ty(C); } }; template<bool cross> class TypeBuilder<types::ppc_fp128, cross> { public: - static const Type *get(LLVMContext&) { return Type::PPC_FP128Ty; } + static const Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); } }; template<bool cross> class TypeBuilder<void, cross> { public: - static const Type *get(LLVMContext&) { - return Type::VoidTy; + static const Type *get(LLVMContext &C) { + return Type::getVoidTy(C); } }; diff --git a/include/llvm/Target/TargetData.h b/include/llvm/Target/TargetData.h index 60c2c323d7..23775be70f 100644 --- a/include/llvm/Target/TargetData.h +++ b/include/llvm/Target/TargetData.h @@ -34,6 +34,7 @@ class IntegerType; class StructType; class StructLayout; class GlobalVariable; +class LLVMContext; /// Enum used to categorize the alignment types stored by TargetAlignElem enum AlignTypeEnum { @@ -229,7 +230,7 @@ public: /// getIntPtrType - Return an unsigned integer type that is the same size or /// greater to the host pointer size. /// - const IntegerType *getIntPtrType() const; + const IntegerType *getIntPtrType(LLVMContext &C) const; /// getIndexedOffset - return the offset from the beginning of the type for /// the specified indices. This is used to implement getelementptr. diff --git a/include/llvm/Type.h b/include/llvm/Type.h index 5e09a61222..05a4e26c8b 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -306,7 +306,7 @@ public: /// getVAArgsPromotedType - Return the type an argument of this type /// will be promoted to if passed through a variable argument /// function. - const Type *getVAArgsPromotedType() const; + const Type *getVAArgsPromotedType(LLVMContext &C) const; /// getScalarType - If this is a vector type, return the element type, /// otherwise return this. @@ -338,14 +338,24 @@ public: // /// getPrimitiveType - Return a type based on an identifier. - static const Type *getPrimitiveType(TypeID IDNumber); + static const Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber); //===--------------------------------------------------------------------===// // These are the builtin types that are always available... // - static const Type *VoidTy, *LabelTy, *FloatTy, *DoubleTy, *MetadataTy; - static const Type *X86_FP80Ty, *FP128Ty, *PPC_FP128Ty; - static const IntegerType *Int1Ty, *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty; + static const Type *getVoidTy(LLVMContext &C); + static const Type *getLabelTy(LLVMContext &C); + static const Type *getFloatTy(LLVMContext &C); + static const Type *getDoubleTy(LLVMContext &C); + static const Type *getMetadataTy(LLVMContext &C); + static const Type *getX86_FP80Ty(LLVMContext &C); + static const Type *getFP128Ty(LLVMContext &C); + static const Type *getPPC_FP128Ty(LLVMContext &C); + static const IntegerType *getInt1Ty(LLVMContext &C); + static const IntegerType *getInt8Ty(LLVMContext &C); + static const IntegerType *getInt16Ty(LLVMContext &C); + static const IntegerType *getInt32Ty(LLVMContext &C); + static const IntegerType *getInt64Ty(LLVMContext &C); /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Type *) { return true; } diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index a89505549f..286f12a1ba 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -502,10 +502,10 @@ static bool IndexOperandsEqual(Value *V1, Value *V2, LLVMContext &Context) { if (Constant *C1 = dyn_cast<Constant>(V1)) if (Constant *C2 = dyn_cast<Constant>(V2)) { // Sign extend the constants to long types, if necessary - if (C1->getType() != Type::Int64Ty) - C1 = ConstantExpr::getSExt(C1, Type::Int64Ty); - if (C2->getType() != Type::Int64Ty) - C2 = ConstantExpr::getSExt(C2, Type::Int64Ty); + if (C1->getType() != Type::getInt64Ty(Context)) + C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(Context)); + if (C2->getType() != Type::getInt64Ty(Context)) + C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(Context)); return C1 == C2; } return false; @@ -600,10 +600,10 @@ BasicAliasAnalysis::CheckGEPInstructions( if (Constant *G2OC = dyn_cast<ConstantInt>(const_cast<Value*>(G2Oper))){ if (G1OC->getType() != G2OC->getType()) { // Sign extend both operands to long. - if (G1OC->getType() != Type::Int64Ty) - G1OC = ConstantExpr::getSExt(G1OC, Type::Int64Ty); - if (G2OC->getType() != Type::Int64Ty) - G2OC = ConstantExpr::getSExt(G2OC, Type::Int64Ty); + if (G1OC->getType() != Type::getInt64Ty(Context)) + G1OC = ConstantExpr::getSExt(G1OC, Type::getInt64Ty(Context)); + if (G2OC->getType() != Type::getInt64Ty(Context)) + G2OC = ConstantExpr::getSExt(G2OC, Type::getInt64Ty(Context)); GEP1Ops[FirstConstantOper] = G1OC; GEP2Ops[FirstConstantOper] = G2OC; } @@ -738,7 +738,8 @@ BasicAliasAnalysis::CheckGEPInstructions( const Type *ZeroIdxTy = GEPPointerTy; for (unsigned i = 0; i != FirstConstantOper; ++i) { if (!isa<StructType>(ZeroIdxTy)) - GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty); + GEP1Ops[i] = GEP2Ops[i] = + Constant::getNullValue(Type::getInt32Ty(Context)); if (const CompositeType *CT = dyn_cast<CompositeType>(ZeroIdxTy)) ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]); @@ -780,10 +781,12 @@ BasicAliasAnalysis::CheckGEPInstructions( // if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr1Ty)) GEP1Ops[i] = - ConstantInt::get(Type::Int64Ty,AT->getNumElements()-1); + ConstantInt::get(Type::getInt64Ty(Context), + AT->getNumElements()-1); else if (const VectorType *VT = dyn_cast<VectorType>(BasePtr1Ty)) GEP1Ops[i] = - ConstantInt::get(Type::Int64Ty,VT->getNumElements()-1); + ConstantInt::get(Type::getInt64Ty(Context), + VT->getNumElements()-1); } } diff --git a/lib/Analysis/CaptureTracking.cpp b/lib/Analysis/CaptureTracking.cpp index a19b8e4f94..b30ac719ae 100644 --- a/lib/Analysis/CaptureTracking.cpp +++ b/lib/Analysis/CaptureTracking.cpp @@ -54,7 +54,7 @@ bool llvm::PointerMayBeCaptured(const Value *V, bool ReturnCaptures) { // its return value and doesn't unwind (a readonly function can leak bits // by throwing an exception or not depending on the input value). if (CS.onlyReadsMemory() && CS.doesNotThrow() && - I->getType() == Type::VoidTy) + I->getType() == Type::getVoidTy(V->getContext())) break; // Not captured if only passed via 'nocapture' arguments. Note that diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 57e781615a..9234f2aaf9 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -151,7 +151,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps, uint64_t Offset = TD->getIndexedOffset(Ptr->getType(), (Value**)Ops+1, NumOps-1); - Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset+BasePtr); + Constant *C = ConstantInt::get(TD->getIntPtrType(Context), Offset+BasePtr); return ConstantExpr::getIntToPtr(C, ResultTy); } @@ -185,7 +185,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, // Fold to an vector of integers with same size as our FP type. unsigned FPWidth = DstEltTy->getPrimitiveSizeInBits(); const Type *DestIVTy = VectorType::get( - IntegerType::get(FPWidth), NumDstElt); + IntegerType::get(Context, FPWidth), NumDstElt); // Recursively handle this integer conversion, if possible. C = FoldBitCast(C, DestIVTy, TD, Context); if (!C) return 0; @@ -199,7 +199,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, if (SrcEltTy->isFloatingPoint()) { unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits(); const Type *SrcIVTy = VectorType::get( - IntegerType::get(FPWidth), NumSrcElt); + IntegerType::get(Context, FPWidth), NumSrcElt); // Ask VMCore to do the conversion now that #elts line up. C = ConstantExpr::getBitCast(C, SrcIVTy); CV = dyn_cast<ConstantVector>(C); @@ -480,7 +480,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, // around to know if bit truncation is happening. if (ConstantExpr *CE0 = dyn_cast<ConstantExpr>(Ops[0])) { if (TD && Ops[1]->isNullValue()) { - const Type *IntPtrTy = TD->getIntPtrType(); + const Type *IntPtrTy = TD->getIntPtrType(Context); if (CE0->getOpcode() == Instruction::IntToPtr) { // Convert the integer value to the right size to ensure we get the // proper extension or truncation. @@ -505,7 +505,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(Ops[1])) { if (TD && CE0->getOpcode() == CE1->getOpcode()) { - const Type *IntPtrTy = TD->getIntPtrType(); + const Type *IntPtrTy = TD->getIntPtrType(Context); if (CE0->getOpcode() == Instruction::IntToPtr) { // Convert the integer value to the right size to ensure we get the @@ -654,9 +654,9 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, return 0; } - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Context)) return ConstantFP::get(Context, APFloat((float)V)); - if (Ty == Type::DoubleTy) + if (Ty == Type::getDoubleTy(Context)) return ConstantFP::get(Context, APFloat(V)); llvm_unreachable("Can only constant fold float/double"); return 0; // dummy return to suppress warning @@ -673,9 +673,9 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double), return 0; } - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Context)) return ConstantFP::get(Context, APFloat((float)V)); - if (Ty == Type::DoubleTy) + if (Ty == Type::getDoubleTy(Context)) return ConstantFP::get(Context, APFloat(V)); llvm_unreachable("Can only constant fold float/double"); return 0; // dummy return to suppress warning @@ -694,13 +694,15 @@ llvm::ConstantFoldCall(Function *F, const Type *Ty = F->getReturnType(); if (NumOperands == 1) { if (ConstantFP *Op = dyn_cast<ConstantFP>(Operands[0])) { - if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy) + if (Ty!=Type::getFloatTy(F->getContext()) && + Ty!=Type::getDoubleTy(Context)) return 0; /// Currently APFloat versions of these functions do not exist, so we use /// the host native double versions. Float versions are not called /// directly but for all these it is true (float)(f((double)arg)) == /// f(arg). Long double not supported yet. - double V = Ty==Type::FloatTy ? (double)Op->getValueAPF().convertToFloat(): + double V = Ty==Type::getFloatTy(F->getContext()) ? + (double)Op->getValueAPF().convertToFloat(): Op->getValueAPF().convertToDouble(); switch (Name[0]) { case 'a': @@ -777,13 +779,14 @@ llvm::ConstantFoldCall(Function *F, } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) { - if (Ty!=Type::FloatTy && Ty!=Type::DoubleTy) + if (Ty!=Type::getFloatTy(F->getContext()) && + Ty!=Type::getDoubleTy(Context)) return 0; - double Op1V = Ty==Type::FloatTy ? + double Op1V = Ty==Type::getFloatTy(F->getContext()) ? (double)Op1->getValueAPF().convertToFloat(): Op1->getValueAPF().convertToDouble(); if (ConstantFP *Op2 = dyn_cast<ConstantFP>(Operands[1])) { - double Op2V = Ty==Type::FloatTy ? + double Op2V = Ty==Type::getFloatTy(F->getContext()) ? (double)Op2->getValueAPF().convertToFloat(): Op2->getValueAPF().convertToDouble(); diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 3d9c93378f..527dae2029 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -483,7 +483,7 @@ Constant *DIFactory::getCastToEmpty(DIDescriptor D) { Constant *DIFactory::GetTagConstant(unsigned TAG) { assert((TAG & LLVMDebugVersionMask) == 0 && "Tag too large for debug encoding!"); - return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); + return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion); } Constant *DIFactory::GetStringConstant(const std::string &String) { @@ -493,14 +493,14 @@ Constant *DIFactory::GetStringConstant(const std::string &String) { // Return Constant if previously defined. if (Slot) return Slot; - const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); + const PointerType *DestTy = PointerType::getUnqual(Type::getInt8Ty(VMContext)); // If empty string then use a i8* null instead. if (String.empty()) return Slot = ConstantPointerNull::get(DestTy); // Construct string as an llvm constant. - Constant *ConstStr = ConstantArray::get(String); + Constant *ConstStr = ConstantArray::get(VMContext, String); // Otherwise create and return a new string global. GlobalVariable *StrGV = new GlobalVariable(M, ConstStr->getType(), true, @@ -542,8 +542,8 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subrange_type), - ConstantInt::get(Type::Int64Ty, Lo), - ConstantInt::get(Type::Int64Ty, Hi) + ConstantInt::get(Type::getInt64Ty(VMContext), Lo), + ConstantInt::get(Type::getInt64Ty(VMContext), Hi) }; Constant *Init = ConstantStruct::get(VMContext, Elts, @@ -578,14 +578,14 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), llvm::Constant::getNullValue(EmptyStructPtr), - ConstantInt::get(Type::Int32Ty, LangID), + ConstantInt::get(Type::getInt32Ty(VMContext), LangID), GetStringConstant(Filename), GetStringConstant(Directory), GetStringConstant(Producer), - ConstantInt::get(Type::Int1Ty, isMain), - ConstantInt::get(Type::Int1Ty, isOptimized), + ConstantInt::get(Type::getInt1Ty(VMContext), isMain), + ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized), GetStringConstant(Flags), - ConstantInt::get(Type::Int32Ty, RunTimeVer) + ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer) }; Constant *Init = ConstantStruct::get(VMContext, Elts, @@ -604,7 +604,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){ Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_enumerator), GetStringConstant(Name), - ConstantInt::get(Type::Int64Ty, Val) + ConstantInt::get(Type::getInt64Ty(VMContext), Val) }; Constant *Init = ConstantStruct::get(VMContext, Elts, @@ -633,12 +633,12 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), - ConstantInt::get(Type::Int32Ty, Encoding) + ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), + ConstantInt::get(Type::getInt32Ty(VMContext), Flags), + ConstantInt::get(Type::getInt32Ty(VMContext), Encoding) }; Constant *Init = ConstantStruct::get(VMContext, Elts, @@ -669,11 +669,11 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), + ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), + ConstantInt::get(Type::getInt32Ty(VMContext), Flags), getCastToEmpty(DerivedFrom) }; @@ -707,14 +707,14 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNumber), - ConstantInt::get(Type::Int64Ty, SizeInBits), - ConstantInt::get(Type::Int64Ty, AlignInBits), - ConstantInt::get(Type::Int64Ty, OffsetInBits), - ConstantInt::get(Type::Int32Ty, Flags), + ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber), + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits), + ConstantInt::get(Type::getInt32Ty(VMContext), Flags), getCastToEmpty(DerivedFrom), getCastToEmpty(Elements), - ConstantInt::get(Type::Int32Ty, RuntimeLang) + ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang) }; Constant *Init = ConstantStruct::get(VMContext, Elts, @@ -749,10 +749,10 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), getCastToEmpty(Type), - ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition) + ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit), + ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition) }; Constant *Init = ConstantStruct::get(VMContext, Elts, @@ -782,10 +782,10 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), getCastToEmpty(Type), - ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition), + ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit), + ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition), ConstantExpr::getBitCast(Val, EmptyStructPtr) }; @@ -811,7 +811,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - ConstantInt::get(Type::Int32Ty, LineNo), + ConstantInt::get(Type::getInt32Ty(VMContext), LineNo), getCastToEmpty(Type) }; @@ -863,8 +863,8 @@ void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo, // Invoke llvm.dbg.stoppoint Value *Args[] = { - ConstantInt::get(llvm::Type::Int32Ty, LineNo), - ConstantInt::get(llvm::Type::Int32Ty, ColNo), + ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo), + ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo), getCastToEmpty(CU) }; CallInst::Create(StopPointFn, Args, Args+3, "", BB); diff --git a/lib/Analysis/LoopDependenceAnalysis.cpp b/lib/Analysis/LoopDependenceAnalysis.cpp index d37273c372..4045dd4de2 100644 --- a/lib/Analysis/LoopDependenceAnalysis.cpp +++ b/lib/Analysis/LoopDependenceAnalysis.cpp @@ -93,7 +93,7 @@ static AliasAnalysis::AliasResult UnderlyingObjectsAlias(AliasAnalysis *AA, } static inline const SCEV *GetZeroSCEV(ScalarEvolution *SE) { - return SE->getConstant(Type::Int32Ty, 0L); + return SE->getConstant(Type::getInt32Ty(SE->getContext()), 0L); } //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/LoopVR.cpp b/lib/Analysis/LoopVR.cpp index 921d6ce06e..bae02015c6 100644 --- a/lib/Analysis/LoopVR.cpp +++ b/lib/Analysis/LoopVR.cpp @@ -73,9 +73,9 @@ ConstantRange LoopVR::getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE ConstantRange X = getRange(Mul->getOperand(0), T, SE); if (X.isFullSet()) return FullSet; - const IntegerType *Ty = IntegerType::get(X.getBitWidth()); - const IntegerType *ExTy = IntegerType::get(X.getBitWidth() * - Mul->getNumOperands()); + const IntegerType *Ty = IntegerType::get(SE.getContext(), X.getBitWidth()); + const IntegerType *ExTy = IntegerType::get(SE.getContext(), + X.getBitWidth() * Mul->getNumOperands()); ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth()); for (unsigned i = 1, e = Mul->getNumOperands(); i != e; ++i) { diff --git a/lib/Analysis/PointerTracking.cpp b/lib/Analysis/PointerTracking.cpp index 1ae2fe6910..f2154f7388 100644 --- a/lib/Analysis/PointerTracking.cpp +++ b/lib/Analysis/PointerTracking.cpp @@ -47,7 +47,7 @@ void PointerTracking::getAnalysisUsage(AnalysisUsage &AU) const { } bool PointerTracking::doInitialization(Module &M) { - const Type *PTy = PointerType::getUnqual(Type::Int8Ty); + const Type *PTy = PointerType::getUnqual(Type::getInt8Ty(M.getContext())); // Find calloc(i64, i64) or calloc(i32, i32). callocFunc = M.getFunction("calloc"); @@ -55,10 +55,10 @@ bool PointerTracking::doInitialization(Module &M) { const FunctionType *Ty = callocFunc->getFunctionType(); std::vector<const Type*> args, args2; - args.push_back(Type::Int64Ty); - args.push_back(Type::Int64Ty); - args2.push_back(Type::Int32Ty); - args2.push_back(Type::Int32Ty); + args.push_back(Type::getInt64Ty(M.getContext())); + args.push_back(Type::getInt64Ty(M.getContext())); + args2.push_back(Type::getInt32Ty(M.getContext())); + args2.push_back(Type::getInt32Ty(M.getContext())); const FunctionType *Calloc1Type = FunctionType::get(PTy, args, false); const FunctionType *Calloc2Type = @@ -73,9 +73,9 @@ bool PointerTracking::doInitialization(Module &M) { const FunctionType *Ty = reallocFunc->getFunctionType(); std::vector<const Type*> args, args2; args.push_back(PTy); - args.push_back(Type::Int64Ty); + args.push_back(Type::getInt64Ty(M.getContext())); args2.push_back(PTy); - args2.push_back(Type::Int32Ty); + args2.push_back(Type::getInt32Ty(M.getContext())); const FunctionType *Realloc1Type = FunctionType::get(PTy, args, false); @@ -104,11 +104,12 @@ const SCEV *PointerTracking::computeAllocationCount(Value *P, Constant *C = GV->getInitializer(); if (const ArrayType *ATy = dyn_cast<ArrayType>(C->getType())) { Ty = ATy->getElementType(); - return SE->getConstant(Type::Int32Ty, ATy->getNumElements()); + return SE->getConstant(Type::getInt32Ty(Ty->getContext()), + ATy->getNumElements()); } } Ty = GV->getType(); - return SE->getConstant(Type::Int32Ty, 1); + return SE->getConstant(Type::getInt32Ty(Ty->getContext()), 1); //TODO: implement more tracking for globals } @@ -117,13 +118,13 @@ const SCEV *PointerTracking::computeAllocationCount(Value *P, Function *F = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts()); const Loop *L = LI->getLoopFor(CI->getParent()); if (F == callocFunc) { - Ty = Type::Int8Ty; + Ty = Type::getInt8Ty(Ty->getContext()); // calloc allocates arg0*arg1 bytes. return SE->getSCEVAtScope(SE->getMulExpr(SE->getSCEV(CS.getArgument(0)), SE->getSCEV(CS.getArgument(1))), L); } else if (F == reallocFunc) { - Ty = Type::Int8Ty; + Ty = Type::getInt8Ty(Ty->getContext()); // realloc allocates arg1 bytes. return SE->getSCEVAtScope(CS.getArgument(1), L); } @@ -163,7 +164,7 @@ const SCEV *PointerTracking::getAllocationElementCount(Value *V) const { } const SCEV *PointerTracking::getAllocationSizeInBytes(Value *V) const { - return computeAllocationCountForType(V, Type::Int8Ty); + return computeAllocationCountForType(V, Type::getInt8Ty(V->getContext())); } // Helper for isLoopGuardedBy that checks the swapped and inverted predicate too diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 72cb9b212f..8ce812cc06 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -598,7 +598,8 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K, MultiplyFactor = MultiplyFactor.trunc(W); // Calculate the product, at width T+W - const IntegerType *CalculationTy = IntegerType::get(CalculationBits); + const IntegerType *CalculationTy = IntegerType::get(SE.getContext(), + CalculationBits); const SCEV *Dividend = SE.getTruncateOrZeroExtend(It, CalculationTy); for (unsigned i = 1; i != K; ++i) { const SCEV *S = SE.getMinusSCEV(It, SE.getIntegerSCEV(i, It->getType())); @@ -760,7 +761,7 @@ const SCEV *ScalarEvolution::getZeroExtendExpr(const SCEV *Op, const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); if (MaxBECount == RecastedMaxBECount) { - const Type *WideTy = IntegerType::get(BitWidth * 2); + const Type *WideTy = IntegerType::get(getContext(), BitWidth * 2); // Check whether Start+Step*MaxBECount has no unsigned overflow. const SCEV *ZMul = getMulExpr(CastedMaxBECount, @@ -899,7 +900,7 @@ const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op, const SCEV *RecastedMaxBECount = getTruncateOrZeroExtend(CastedMaxBECount, MaxBECount->getType()); if (MaxBECount == RecastedMaxBECount) { - const Type *WideTy = IntegerType::get(BitWidth * 2); + const Type *WideTy = IntegerType::get(getContext(), BitWidth * 2); // Check whether Start+Step*MaxBECount has no signed overflow. const SCEV *SMul = getMulExpr(CastedMaxBECount, @@ -1637,7 +1638,7 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS, if (!RHSC->getValue()->getValue().isPowerOf2()) ++MaxShiftAmt; const IntegerType *ExtTy = - IntegerType::get(getTypeSizeInBits(Ty) + MaxShiftAmt); + IntegerType::get(getContext(), getTypeSizeInBits(Ty) + MaxShiftAmt); // {X,+,N}/C --> {X/C,+,N/C} if safe and N/C can be folded. if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(LHS)) if (const SCEVConstant *Step = @@ -2064,7 +2065,7 @@ const Type *ScalarEvolution::getEffectiveSCEVType(const Type *Ty) const { return Ty; assert(isa<PointerType>(Ty) && "Unexpected non-pointer non-integer type!"); - return TD->getIntPtrType(); + return TD->getIntPtrType(getContext()); } const SCEV *ScalarEvolution::getCouldNotCompute() { @@ -2432,7 +2433,7 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { /// const SCEV *ScalarEvolution::createNodeForGEP(Operator *GEP) { - const Type *IntPtrTy = TD->getIntPtrType(); + const Type *IntPtrTy = TD->getIntPtrType(getContext()); Value *Base = GEP->getOperand(0); // Don't attempt to analyze GEPs over unsized objects. if (!cast<PointerType>(Base->getType())->getElementType()->isSized()) @@ -2826,7 +2827,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { if (LZ != 0 && !((~A & ~KnownZero) & EffectiveMask)) return getZeroExtendExpr(getTruncateExpr(getSCEV(U->getOperand(0)), - IntegerType::get(BitWidth - LZ)), + IntegerType::get(getContext(), BitWidth - LZ)), U->getType()); } break; @@ -2925,7 +2926,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { return getIntegerSCEV(0, U->getType()); // value is undefined return getSignExtendExpr(getTruncateExpr(getSCEV(L->getOperand(0)), - IntegerType::get(Amt)), + IntegerType::get(getContext(), Amt)), U->getType()); } break; @@ -3748,7 +3749,7 @@ ScalarEvolution::ComputeBackedgeTakenCountExhaustively(const Loop *L, if (CondVal->getValue() == uint64_t(ExitWhen)) { ++NumBruteForceTripCountsComputed; - return getConstant(Type::Int32Ty, IterationNum); + return getConstant(Type::getInt32Ty(getContext()), IterationNum); } // Compute the value of the PHI node for the next iteration. @@ -4670,7 +4671,8 @@ const SCEV *ScalarEvolution::getBECount(const SCEV *Start, // Check Add for unsigned overflow. // TODO: More sophisticated things could be done here. - const Type *WideTy = IntegerType::get(getTypeSizeInBits(Ty) + 1); + const Type *WideTy = IntegerType::get(getContext(), + getTypeSizeInBits(Ty) + 1); const SCEV *EDiff = getZeroExtendExpr(Diff, WideTy); const SCEV *ERoundUp = getZeroExtendExpr(RoundUp, WideTy); const SCEV *OperandExtendedAdd = getAddExpr(EDiff, ERoundUp); diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 40bf0a1a02..3ec6fe42d4 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -298,7 +298,8 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, uint64_t FullOffset = C->getValue()->getZExtValue(); if (FullOffset < SL.getSizeInBytes()) { unsigned ElIdx = SL.getElementContainingOffset(FullOffset); - GepIndices.push_back(ConstantInt::get(Type::Int32Ty, ElIdx)); + GepIndices.push_back( + ConstantInt::get(Type::getInt32Ty(Ty->getContext()), ElIdx)); ElTy = STy->getTypeAtIndex(ElIdx); Ops[0] = SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx)); @@ -321,7 +322,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, // better than ptrtoint+arithmetic+inttoptr at least. if (!AnyNonZeroIndices) { V = InsertNoopCastOfTo(V, - Type::Int8Ty->getPointerTo(PTy->getAddressSpace())); + Type::getInt8Ty(Ty->getContext())->getPointerTo(PTy->getAddressSpace())); Value *Idx = expandCodeFor(SE.getAddExpr(Ops), Ty); // Fold a GEP with constant operands. diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index af8649499b..604d10c68b 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -460,10 +460,12 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask, Align = TD->getABITypeAlignment(AI->getType()->getElementType()); Align = std::max(Align, - (unsigned)TD->getABITypeAlignment(Type::DoubleTy)); + (unsigned)TD->getABITypeAlignment( + Type::getDoubleTy(V->getContext()))); Align = std::max(Align, - (unsigned)TD->getABITypeAlignment(Type::Int64Ty)); + (unsigned)TD->getABITypeAlignment( + Type::getInt64Ty(V->getContext()))); } } @@ -1034,7 +1036,7 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset, // Make sure the index-ee is a pointer to array of i8. const PointerType *PT = cast<PointerType>(GEP->getOperand(0)->getType()); const ArrayType *AT = dyn_cast<ArrayType>(PT->getElementType()); - if (AT == 0 || AT->getElementType() != Type::Int8Ty) + if (AT == 0 || AT->getElementType() != Type::getInt8Ty(V->getContext())) return false; // Check to make sure that the first operand of the GEP is an integer and @@ -1073,7 +1075,8 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset, // Must be a Constant Array ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit); - if (Array == 0 || Array->getType()->getElementType() != Type::Int8Ty) + if (Array == 0 || + Array->getType()->getElementType() != Type::getInt8Ty(V->getContext())) return false; // Get the number of elements in the array diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index c5e6424464..b98669efa3 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -471,7 +471,7 @@ lltok::Kind LLLexer::LexIdentifier() { Error("bitwidth for integer type out of range!"); return lltok::Error; } - TyVal = IntegerType::get(NumBits); + TyVal = IntegerType::get(Context, NumBits); return lltok::Type; } @@ -579,14 +579,14 @@ lltok::Kind LLLexer::LexIdentifier() { #define TYPEKEYWORD(STR, LLVMTY) \ if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \ TyVal = LLVMTY; return lltok::Type; } - TYPEKEYWORD("void", Type::VoidTy); - TYPEKEYWORD("float", Type::FloatTy); - TYPEKEYWORD("double", Type::DoubleTy); - TYPEKEYWORD("x86_fp80", Type::X86_FP80Ty); - TYPEKEYWORD("fp128", Type::FP128Ty); - TYPEKEYWORD("ppc_fp128", Type::PPC_FP128Ty); - TYPEKEYWORD("label", Type::LabelTy); - TYPEKEYWORD("metadata", Type::MetadataTy); + TYPEKEYWORD("void", Type::getVoidTy(Context)); + TYPEKEYWORD("float", Type::getFloatTy(Context)); + TYPEKEYWORD("double", Type::getDoubleTy(Context)); + TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context)); + TYPEKEYWORD("fp128", Type::getFP128Ty(Context)); + TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context)); + TYPEKEYWORD("label", Type::getLabelTy(Context)); + TYPEKEYWORD("metadata", Type::getMetadataTy(Context)); #undef TYPEKEYWORD // Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index ab686ced9b..c3fd31ed4c 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -259,7 +259,7 @@ bool LLParser::ParseUnnamedType() { LocTy TypeLoc = Lex.getLoc(); Lex.Lex(); // eat kw_type - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseType(Ty)) return true; // See if this type was previously referenced. @@ -286,7 +286,7 @@ bool LLParser::ParseNamedType() { LocTy NameLoc = Lex.getLoc(); Lex.Lex(); // eat LocalVar. - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseToken(lltok::equal, "expected '=' after name") || ParseToken(lltok::kw_type, "expected 'type' after name") || @@ -486,7 +486,7 @@ bool LLParser::ParseNamedMetadata() { if (ParseToken(lltok::rbrace, "expected end of metadata node")) return true; - NamedMDNode::Create(Name, Elts.data(), Elts.size(), M); + NamedMDNode::Create(Context, Name, Elts.data(), Elts.size(), M); return false; } @@ -504,7 +504,7 @@ bool LLParser::ParseStandaloneMetadata() { return true; LocTy TyLoc; - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseType(Ty, TyLoc)) return true; @@ -628,7 +628,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, bool ThreadLocal, IsConstant; LocTy TyLoc; - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) || ParseOptionalAddrSpace(AddrSpace) || ParseGlobalType(IsConstant) || @@ -645,7 +645,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, return true; } - if (isa<FunctionType>(Ty) || Ty == Type::LabelTy) + if (isa<FunctionType>(Ty) || Ty == Type::getLabelTy(Context)) return Error(TyLoc, "invalid type for global variable"); GlobalVariable *GV = 0; @@ -1065,7 +1065,7 @@ bool LLParser::ParseType(PATypeHolder &Result, bool AllowVoid) { if (!UpRefs.empty()) return Error(UpRefs.back().Loc, "invalid unresolved type up reference"); - if (!AllowVoid && Result.get() == Type::VoidTy) + if (!AllowVoid && Result.get() == Type::getVoidTy(Context)) return Error(TypeLoc, "void type only allowed for function results"); return false; @@ -1227,9 +1227,9 @@ bool LLParser::ParseTypeRec(PATypeHolder &Result) { // TypeRec ::= TypeRec '*' case lltok::star: - if (Result.get() == Type::LabelTy) + if (Result.get() == Type::getLabelTy(Context)) return TokError("basic block pointers are invalid"); - if (Result.get() == Type::VoidTy) + if (Result.get() == Type::getVoidTy(Context)) return TokError("pointers to void are invalid; use i8* instead"); if (!PointerType::isValidElementType(Result.get())) return TokError("pointer to this type is invalid"); @@ -1239,9 +1239,9 @@ bool LLParser::ParseTypeRec(PATypeHolder &Result) { // TypeRec ::= TypeRec 'addrspace' '(' uint32 ')' '*' case lltok::kw_addrspace: { - if (Result.get() == Type::LabelTy) + if (Result.get() == Type::getLabelTy(Context)) return TokError("basic block pointers are invalid"); - if (Result.get() == Type::VoidTy) + if (Result.get() == Type::getVoidTy(Context)) return TokError("pointers to void are invalid; use i8* instead"); if (!PointerType::isValidElementType(Result.get())) return TokError("pointer to this type is invalid"); @@ -1281,7 +1281,7 @@ bool LLParser::ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, // Parse the argument. LocTy ArgLoc; - PATypeHolder ArgTy(Type::VoidTy); + PATypeHolder ArgTy(Type::getVoidTy(Context)); unsigned ArgAttrs1, ArgAttrs2; Value *V; if (ParseType(ArgTy, ArgLoc) || @@ -1322,7 +1322,7 @@ bool LLParser::ParseArgumentList(std::vector<ArgInfo> &ArgList, Lex.Lex(); } else { LocTy TypeLoc = Lex.getLoc(); - PATypeHolder ArgTy(Type::VoidTy); + PATypeHolder ArgTy(Type::getVoidTy(Context)); unsigned Attrs; std::string Name; @@ -1332,7 +1332,7 @@ bool LLParser::ParseArgumentList(std::vector<ArgInfo> &ArgList, if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) || ParseOptionalAttrs(Attrs, 0)) return true; - if (ArgTy == Type::VoidTy) + if (ArgTy == Type::getVoidTy(Context)) return Error(TypeLoc, "argument can not have void type"); if (Lex.getKind() == lltok::LocalVar || @@ -1358,7 +1358,7 @@ bool LLParser::ParseArgumentList(std::vector<ArgInfo> &ArgList, if ((inType ? ParseTypeRec(ArgTy) : ParseType(ArgTy)) || ParseOptionalAttrs(Attrs, 0)) return true; - if (ArgTy == Type::VoidTy) + if (ArgTy == Type::getVoidTy(Context)) return Error(TypeLoc, "argument can not have void type"); if (Lex.getKind() == lltok::LocalVar || @@ -1436,7 +1436,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) { if (ParseTypeRec(Result)) return true; ParamsList.push_back(Result); - if (Result == Type::VoidTy) + if (Result == Type::getVoidTy(Context)) return Error(EltTyLoc, "struct element can not have void type"); if (!StructType::isValidElementType(Result)) return Error(EltTyLoc, "invalid element type for struct"); @@ -1445,7 +1445,7 @@ bool LLParser::ParseStructType(PATypeHolder &Result, bool Packed) { EltTyLoc = Lex.getLoc(); if (ParseTypeRec(Result)) return true; - if (Result == Type::VoidTy) + if (Result == Type::getVoidTy(Context)) return Error(EltTyLoc, "struct element can not have void type"); if (!StructType::isValidElementType(Result)) return Error(EltTyLoc, "invalid element type for struct"); @@ -1481,10 +1481,10 @@ bool LLParser::ParseArrayVectorType(PATypeHolder &Result, bool isVector) { return true; LocTy TypeLoc = Lex.getLoc(); - PATypeHolder EltTy(Type::VoidTy); + PATypeHolder EltTy(Type::getVoidTy(Context)); if (ParseTypeRec(EltTy)) return true; - if (EltTy == Type::VoidTy) + if (EltTy == Type::getVoidTy(Context)) return Error(TypeLoc, "array and vector element type cannot be void"); if (ParseToken(isVector ? lltok::greater : lltok::rsquare, @@ -1575,7 +1575,7 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) { if (Val->getType() == Ty) return Val; - if (Ty == Type::LabelTy) + if (Ty == Type::getLabelTy(F.getContext())) P.Error(Loc, "'%" + Name + "' is not a basic block"); else P.Error(Loc, "'%" + Name + "' defined with type '" + @@ -1584,15 +1584,16 @@ Value *LLParser::PerFunctionState::GetVal(const std::string &Name, } // Don't make placeholders with invalid type. - if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && Ty != Type::LabelTy) { + if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && + Ty != Type::getLabelTy(F.getContext())) { P.Error(Loc, "invalid use of a non-first-class type"); return 0; } // Otherwise, create a new forward reference for this value and remember it. Value *FwdVal; - if (Ty == Type::LabelTy) - FwdVal = BasicBlock::Create(Name, &F); + if (Ty == Type::getLabelTy(F.getContext())) + FwdVal = BasicBlock::Create(F.getContext(), Name, &F); else FwdVal = new Argument(Ty, Name); @@ -1617,7 +1618,7 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) { if (Val->getType() == Ty) return Val; - if (Ty == Type::LabelTy) + if (Ty == Type::getLabelTy(F.getContext())) P.Error(Loc, "'%" + utostr(ID) + "' is not a basic block"); else P.Error(Loc, "'%" + utostr(ID) + "' defined with type '" + @@ -1625,15 +1626,16 @@ Value *LLParser::PerFunctionState::GetVal(unsigned ID, const Type *Ty, return 0; } - if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && Ty != Type::LabelTy) { + if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty) && + Ty != Type::getLabelTy(F.getContext())) { P.Error(Loc, "invalid use of a non-first-class type"); return 0; } // Otherwise, create a new forward reference for this value and remember it. Value *FwdVal; - if (Ty == Type::LabelTy) - FwdVal = BasicBlock::Create("", &F); + if (Ty == Type::getLabelTy(F.getContext())) + FwdVal = BasicBlock::Create(F.getContext(), "", &F); else FwdVal = new Argument(Ty); @@ -1647,7 +1649,7 @@ bool LLParser::PerFunctionState::SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc, Instruction *Inst) { // If this instruction has void type, it cannot have a name or ID specified. - if (Inst->getType() == Type::VoidTy) { + if (Inst->getType() == Type::getVoidTy(F.getContext())) { if (NameID != -1 || !NameStr.empty()) return P.Error(NameLoc, "instructions returning void cannot have a name"); return false; @@ -1702,11 +1704,13 @@ bool LLParser::PerFunctionState::SetInstName(int NameID, /// forward reference record if needed. BasicBlock *LLParser::PerFunctionState::GetBB(const std::string &Name, LocTy Loc) { - return cast_or_null<BasicBlock>(GetVal(Name, Type::LabelTy, Loc)); + return cast_or_null<BasicBlock>(GetVal(Name, + Type::getLabelTy(F.getContext()), Loc)); } BasicBlock *LLParser::PerFunctionState::GetBB(unsigned ID, LocTy Loc) { - return cast_or_null<BasicBlock>(GetVal(ID, Type::LabelTy, Loc)); + return cast_or_null<BasicBlock>(GetVal(ID, + Type::getLabelTy(F.getContext()), Loc)); } /// DefineBB - Define the specified basic block, which is either named or @@ -1899,7 +1903,7 @@ bool LLParser::ParseValID(ValID &ID) { } case lltok::kw_c: // c "foo" Lex.Lex(); - ID.ConstantVal = ConstantArray::get(Lex.getStrVal(), false); + ID.ConstantVal = ConstantArray::get(Context, Lex.getStrVal(), false); if (ParseToken(lltok::StringConstant, "expected string")) return true; ID.Kind = ValID::t_Constant; return false; @@ -1932,7 +1936,7 @@ bool LLParser::ParseValID(ValID &ID) { case lltok::kw_inttoptr: case lltok::kw_ptrtoint: { unsigned Opc = Lex.getUIntVal(); - PATypeHolder DestTy(Type::VoidTy); + PATypeHolder DestTy(Type::getVoidTy(Context)); Constant *SrcVal; Lex.Lex(); if (ParseToken(lltok::lparen, "expected '(' after constantexpr cast") || @@ -2225,7 +2229,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, // The lexer has no type info, so builds all float and double FP constants // as double. Fix this here. Long double does not need this. if (&ID.APFloatVal.getSemantics() == &APFloat::IEEEdouble && - Ty == Type::FloatTy) { + Ty == Type::getFloatTy(Context)) { bool Ignored; ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored); @@ -2244,7 +2248,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, return false; case ValID::t_Undef: // FIXME: LabelTy should not be a first-class type. - if ((!Ty->isFirstClassType() || Ty == Type::LabelTy) && + if ((!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) && !isa<OpaqueType>(Ty)) return Error(ID.Loc, "invalid type for undef constant"); V = UndefValue::get(Ty); @@ -2256,7 +2260,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, return false; case ValID::t_Zero: // FIXME: LabelTy should not be a first-class type. - if (!Ty->isFirstClassType() || Ty == Type::LabelTy) + if (!Ty->isFirstClassType() || Ty == Type::getLabelTy(Context)) return Error(ID.Loc, "invalid type for null constant"); V = Constant::getNullValue(Ty); return false; @@ -2269,7 +2273,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, } bool LLParser::ParseGlobalTypeAndValue(Constant *&V) { - PATypeHolder Type(Type::VoidTy); + PATypeHolder Type(Type::getVoidTy(Context)); return ParseType(Type) || ParseGlobalValue(Type, V); } @@ -2336,7 +2340,7 @@ bool LLParser::ParseValue(const Type *Ty, Value *&V, PerFunctionState &PFS) { } bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState &PFS) { - PATypeHolder T(Type::VoidTy); + PATypeHolder T(Type::getVoidTy(Context)); return ParseType(T) || ParseValue(T, V, PFS); } @@ -2351,7 +2355,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) { unsigned Linkage; unsigned Visibility, CC, RetAttrs; - PATypeHolder RetType(Type::VoidTy); + PATypeHolder RetType(Type::getVoidTy(Context)); LocTy RetTypeLoc = Lex.getLoc(); if (ParseOptionalLinkage(Linkage) || ParseOptionalVisibility(Visibility) || @@ -2460,7 +2464,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) { AttrListPtr PAL = AttrListPtr::get(Attrs.begin(), Attrs.end()); if (PAL.paramHasAttr(1, Attribute::StructRet) && - RetType != Type::VoidTy) + RetType != Type::getVoidTy(Context)) return Error(RetTypeLoc, "functions with 'sret' argument must return void"); const FunctionType *FT = @@ -2631,8 +2635,8 @@ bool LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB, switch (Token) { default: return Error(Loc, "expected instruction opcode"); // Terminator Instructions. - case lltok::kw_unwind: Inst = new UnwindInst(); return false; - case lltok::kw_unreachable: Inst = new UnreachableInst(); return false; + case lltok::kw_unwind: Inst = new UnwindInst(Context); return false; + case lltok::kw_unreachable: Inst = new UnreachableInst(Context); return false; case lltok::kw_ret: return ParseRet(Inst, BB, PFS); case lltok::kw_br: return ParseBr(Inst, PFS); case lltok::kw_switch: return ParseSwitch(Inst, PFS); @@ -2788,11 +2792,11 @@ bool LLParser::ParseCmpPredicate(unsigned &P, unsigned Opc) { /// ::= 'ret' TypeAndValue (',' TypeAndValue)+ [[obsolete: LLVM 3.0]] bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS) { - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseType(Ty, true /*void allowed*/)) return true; - if (Ty == Type::VoidTy) { - Inst = ReturnInst::Create(); + if (Ty == Type::getVoidTy(Context)) { + Inst = ReturnInst::Create(Context); return false; } @@ -2818,7 +2822,7 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB, RV = I; } } - Inst = ReturnInst::Create(RV); + Inst = ReturnInst::Create(Context, RV); return false; } @@ -2836,7 +2840,7 @@ bool LLParser::ParseBr(Instruction *&Inst, PerFunctionState &PFS) { return false; } - if (Op0->getType() != Type::Int1Ty) + if (Op0->getType() != Type::getInt1Ty(Context)) return Error(Loc, "branch condition must have 'i1' type"); if (ParseToken(lltok::comma, "expected ',' after branch condition") || @@ -2911,7 +2915,7 @@ bool LLParser::ParseSwitch(Instruction *&Inst, PerFunctionState &PFS) { bool LLParser::ParseInvoke(Instruction *&Inst, PerFunctionState &PFS) { LocTy CallLoc = Lex.getLoc(); unsigned CC, RetAttrs, FnAttrs; - PATypeHolder RetType(Type::VoidTy); + PATypeHolder RetType(Type::getVoidTy(Context)); LocTy RetTypeLoc; ValID CalleeID; SmallVector<ParamInfo, 16> ArgList; @@ -3104,7 +3108,7 @@ bool LLParser::ParseCompare(Instruction *&Inst, PerFunctionState &PFS, bool LLParser::ParseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc) { LocTy Loc; Value *Op; - PATypeHolder DestTy(Type::VoidTy); + PATypeHolder DestTy(Type::getVoidTy(Context)); if (ParseTypeAndValue(Op, Loc, PFS) || ParseToken(lltok::kw_to, "expected 'to' after cast value") || ParseType(DestTy)) @@ -3143,7 +3147,7 @@ bool LLParser::ParseSelect(Instruction *&Inst, PerFunctionState &PFS) { /// ::= 'va_arg' TypeAndValue ',' Type bool LLParser::ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS) { Value *Op; - PATypeHolder EltTy(Type::VoidTy); + PATypeHolder EltTy(Type::getVoidTy(Context)); LocTy TypeLoc; if (ParseTypeAndValue(Op, PFS) || ParseToken(lltok::comma, "expected ',' after vaarg operand") || @@ -3215,7 +3219,7 @@ bool LLParser::ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS) { /// ParsePHI /// ::= 'phi' Type '[' Value ',' Value ']' (',' '[' Value ',' Valueß ']')* bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); Value *Op0, *Op1; LocTy TypeLoc = Lex.getLoc(); @@ -3223,7 +3227,7 @@ bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { ParseToken(lltok::lsquare, "expected '[' in phi value list") || ParseValue(Ty, Op0, PFS) || ParseToken(lltok::comma, "expected ',' after insertelement value") || - ParseValue(Type::LabelTy, Op1, PFS) || + ParseValue(Type::getLabelTy(Context), Op1, PFS) || ParseToken(lltok::rsquare, "expected ']' in phi value list")) return true; @@ -3237,7 +3241,7 @@ bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { if (ParseToken(lltok::lsquare, "expected '[' in phi value list") || ParseValue(Ty, Op0, PFS) || ParseToken(lltok::comma, "expected ',' after insertelement value") || - ParseValue(Type::LabelTy, Op1, PFS) || + ParseValue(Type::getLabelTy(Context), Op1, PFS) || ParseToken(lltok::rsquare, "expected ']' in phi value list")) return true; } @@ -3259,7 +3263,7 @@ bool LLParser::ParsePHI(Instruction *&Inst, PerFunctionState &PFS) { bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS, bool isTail) { unsigned CC, RetAttrs, FnAttrs; - PATypeHolder RetType(Type::VoidTy); + PATypeHolder RetType(Type::getVoidTy(Context)); LocTy RetTypeLoc; ValID CalleeID; SmallVector<ParamInfo, 16> ArgList; @@ -3358,7 +3362,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS, /// ::= 'alloca' Type (',' TypeAndValue)? (',' OptionalAlignment)? bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc) { - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); Value *Size = 0; LocTy SizeLoc; unsigned Alignment = 0; @@ -3373,7 +3377,7 @@ bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS, } } - if (Size && Size->getType() != Type::Int32Ty) + if (Size && Size->getType() != Type::getInt32Ty(Context)) return Error(SizeLoc, "element count must be i32"); if (Opc == Instruction::Malloc) @@ -3540,7 +3544,7 @@ bool LLParser::ParseMDNodeVector(SmallVectorImpl<Value*> &Elts) { Lex.Lex(); V = 0; } else { - PATypeHolder Ty(Type::VoidTy); + PATypeHolder Ty(Type::getVoidTy(Context)); if (ParseType(Ty)) return true; if (Lex.getKind() == lltok::Metadata) { Lex.Lex(); diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 5f184ec58d..168f32951d 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -143,7 +143,7 @@ namespace { } explicit ConstantPlaceHolder(const Type *Ty, LLVMContext& Context) : ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) { - Op<0>() = UndefValue::get(Type::Int32Ty); + Op<0>() = UndefValue::get(Type::getInt32Ty(Context)); } /// @brief Methods to support type inquiry through isa, cast, and dyn_cast. @@ -339,12 +339,12 @@ Value *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) { resize(Idx + 1); if (Value *V = MDValuePtrs[Idx]) { - assert(V->getType() == Type::MetadataTy && "Type mismatch in value table!"); + assert(V->getType() == Type::getMetadataTy(Context) && "Type mismatch in value table!"); return V; } // Create and return a placeholder, which will later be RAUW'd. - Value *V = new Argument(Type::MetadataTy); + Value *V = new Argument(Type::getMetadataTy(Context)); MDValuePtrs[Idx] = V; return V; } @@ -518,37 +518,37 @@ bool BitcodeReader::ParseTypeTable() { TypeList.reserve(Record[0]); continue; case bitc::TYPE_CODE_VOID: // VOID - ResultTy = Type::VoidTy; + ResultTy = Type::getVoidTy(Context); break; case bitc::TYPE_CODE_FLOAT: // FLOAT - ResultTy = Type::FloatTy; + ResultTy = Type::getFloatTy(Context); break; case bitc::TYPE_CODE_DOUBLE: // DOUBLE - ResultTy = Type::DoubleTy; + ResultTy = Type::getDoubleTy(Context); break; case bitc::TYPE_CODE_X86_FP80: // X86_FP80 - ResultTy = Type::X86_FP80Ty; + ResultTy = Type::getX86_FP80Ty(Context); break; case bitc::TYPE_CODE_FP128: // FP128 - ResultTy = Type::FP128Ty; + ResultTy = Type::getFP128Ty(Context); break; case bitc::TYPE_CODE_PPC_FP128: // PPC_FP128 - ResultTy = Type::PPC_FP128Ty; + ResultTy = Type::getPPC_FP128Ty(Context); break; case bitc::TYPE_CODE_LABEL: // LABEL - ResultTy = Type::LabelTy; + ResultTy = Type::getLabelTy(Context); break; case bitc::TYPE_CODE_OPAQUE: // OPAQUE ResultTy = 0; break; case bitc::TYPE_CODE_METADATA: // METADATA - ResultTy = Type::MetadataTy; + ResultTy = Type::getMetadataTy(Context); break; case bitc::TYPE_CODE_INTEGER: // INTEGER: [width] if (Record.size() < 1) return Error("Invalid Integer type record"); - ResultTy = IntegerType::get(Record[0]); + ResultTy = IntegerType::get(Context, Record[0]); break; case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or // [pointee type, address space] @@ -792,8 +792,8 @@ bool BitcodeReader::ParseMetadata() { if (MetadataBase *B = dyn_cast<MetadataBase>(MD)) Elts.push_back(B); } - Value *V = NamedMDNode::Create(Name.c_str(), Elts.data(), Elts.size(), - TheModule); + Value *V = NamedMDNode::Create(Context, Name.c_str(), Elts.data(), + Elts.size(), TheModule); MDValueList.AssignValue(V, NextValueNo++); break; } @@ -805,9 +805,9 @@ bool BitcodeReader::ParseMetadata() { SmallVector<Value*, 8> Elts; for (unsigned i = 0; i != Size; i += 2) { const Type *Ty = getTypeByID(Record[i], false); - if (Ty == Type::MetadataTy) + if (Ty == Type::getMetadataTy(Context)) Elts.push_back(MDValueList.getValueFwdRef(Record[i+1])); - else if (Ty != Type::VoidTy) + else if (Ty != Type::getVoidTy(Context)) Elts.push_back(ValueList.getValueFwdRef(Record[i+1], Ty)); else Elts.push_back(NULL); @@ -900,7 +900,7 @@ bool BitcodeReader::ParseConstants() { SmallVector<uint64_t, 64> Record; // Read all the records for this value table. - const Type *CurTy = Type::Int32Ty; + const Type *CurTy = Type::getInt32Ty(Context); unsigned NextCstNo = ValueList.size(); while (1) { unsigned Code = Stream.ReadCode(); @@ -961,19 +961,19 @@ bool BitcodeReader::ParseConstants() { case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval] if (Record.empty()) return Error("Invalid FLOAT record"); - if (CurTy == Type::FloatTy) + if (CurTy == Type::getFloatTy(Context)) V = ConstantFP::get(Context, APFloat(APInt(32, (uint32_t)Record[0]))); - else if (CurTy == Type::DoubleTy) + else if (CurTy == Type::getDoubleTy(Context)) V = ConstantFP::get(Context, APFloat(APInt(64, Record[0]))); - else if (CurTy == Type::X86_FP80Ty) { + else if (CurTy == Type::getX86_FP80Ty(Context)) { // Bits are not stored the same way as a normal i80 APInt, compensate. uint64_t Rearrange[2]; Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16); Rearrange[1] = Record[0] >> 48; V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange))); - } else if (CurTy == Type::FP128Ty) + } else if (CurTy == Type::getFP128Ty(Context)) V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true)); - else if (CurTy == Type::PPC_FP128Ty) + else if (CurTy == Type::getPPC_FP128Ty(Context)) V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]))); else V = UndefValue::get(CurTy); @@ -1081,7 +1081,7 @@ bool BitcodeReader::ParseConstants() { case bitc::CST_CODE_CE_SELECT: // CE_SELECT: [opval#, opval#, opval#] if (Record.size() < 3) return Error("Invalid CE_SELECT record"); V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0], - Type::Int1Ty), + Type::getInt1Ty(Context)), ValueList.getConstantFwdRef(Record[1],CurTy), ValueList.getConstantFwdRef(Record[2],CurTy)); break; @@ -1091,7 +1091,7 @@ bool BitcodeReader::ParseConstants() { dyn_cast_or_null<VectorType>(getTypeByID(Record[0])); if (OpTy == 0) return Error("Invalid CE_EXTRACTELT record"); Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy); - Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty); + Constant *Op1 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context)); V = ConstantExpr::getExtractElement(Op0, Op1); break; } @@ -1102,7 +1102,7 @@ bool BitcodeReader::ParseConstants() { Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy->getElementType()); - Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::Int32Ty); + Constant *Op2 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context)); V = ConstantExpr::getInsertElement(Op0, Op1, Op2); break; } @@ -1112,7 +1112,7 @@ bool BitcodeReader::ParseConstants() { return Error("Invalid CE_SHUFFLEVEC record"); Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy); - const Type *ShufTy = VectorType::get(Type::Int32Ty, + const Type *ShufTy = VectorType::get(Type::getInt32Ty(Context), OpTy->getNumElements()); Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy); V = ConstantExpr::getShuffleVector(Op0, Op1, Op2); @@ -1125,7 +1125,7 @@ bool BitcodeReader::ParseConstants() { return Error("Invalid CE_SHUFVEC_EX record"); Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy); - const Type *ShufTy = VectorType::get(Type::Int32Ty, + const Type *ShufTy = VectorType::get(Type::getInt32Ty(Context), RTy->getNumElements()); Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy); V = ConstantExpr::getShuffleVector(Op0, Op1, Op2); @@ -1592,7 +1592,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { // Create all the basic blocks for the function. FunctionBBs.resize(Record[0]); for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i) - FunctionBBs[i] = BasicBlock::Create("", F); + FunctionBBs[i] = BasicBlock::Create(Context, "", F); CurBB = FunctionBBs[0]; continue; @@ -1698,7 +1698,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { Value *TrueVal, *FalseVal, *Cond; if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) || getValue(Record, OpNum, TrueVal->getType(), FalseVal) || - getValue(Record, OpNum, Type::Int1Ty, Cond)) + getValue(Record, OpNum, Type::getInt1Ty(Context), Cond)) return Error("Invalid SELECT record"); I = SelectInst::Create(Cond, TrueVal, FalseVal); @@ -1719,11 +1719,11 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { if (const VectorType* vector_type = dyn_cast<const VectorType>(Cond->getType())) { // expect <n x i1> - if (vector_type->getElementType() != Type::Int1Ty) + if (vector_type->getElementType() != Type::getInt1Ty(Context)) return Error("Invalid SELECT condition type"); } else { // expect i1 - if (Cond->getType() != Type::Int1Ty) + if (Cond->getType() != Type::getInt1Ty(Context)) return Error("Invalid SELECT condition type"); } @@ -1735,7 +1735,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { unsigned OpNum = 0; Value *Vec, *Idx; if (getValueTypePair(Record, OpNum, NextValueNo, Vec) || - getValue(Record, OpNum, Type::Int32Ty, Idx)) + getValue(Record, OpNum, Type::getInt32Ty(Context), Idx)) return Error("Invalid EXTRACTELT record"); I = ExtractElementInst::Create(Vec, Idx); break; @@ -1747,7 +1747,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { if (getValueTypePair(Record, OpNum, NextValueNo, Vec) || getValue(Record, OpNum, cast<VectorType>(Vec->getType())->getElementType(), Elt) || - getValue(Record, OpNum, Type::Int32Ty, Idx)) + getValue(Record, OpNum, Type::getInt32Ty(Context), Idx)) return Error("Invalid INSERTELT record"); I = InsertElementInst::Create(Vec, Elt, Idx); break; @@ -1802,7 +1802,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { { unsigned Size = Record.size(); if (Size == 0) { - I = ReturnInst::Create(); + I = ReturnInst::Create(Context); break; } @@ -1826,11 +1826,11 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { ValueList.AssignValue(I, NextValueNo++); RV = I; } - I = ReturnInst::Create(RV); + I = ReturnInst::Create(Context, RV); break; } - I = ReturnInst::Create(Vs[0]); + I = ReturnInst::Create(Context, Vs[0]); break; } case bitc::FUNC_CODE_INST_BR: { // BR: [bb#, bb#, opval] or [bb#] @@ -1844,7 +1844,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { I = BranchInst::Create(TrueDest); else { BasicBlock *FalseDest = getBasicBlock(Record[1]); - Value *Cond = getFnValueByID(Record[2], Type::Int1Ty); + Value *Cond = getFnValueByID(Record[2], Type::getInt1Ty(Context)); if (FalseDest == 0 || Cond == 0) return Error("Invalid BR record"); I = BranchInst::Create(TrueDest, FalseDest, Cond); @@ -1923,10 +1923,10 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { break; } case bitc::FUNC_CODE_INST_UNWIND: // UNWIND - I = new UnwindInst(); + I = new UnwindInst(Context); break; case bitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE - I = new UnreachableInst(); + I = new UnreachableInst(Context); break; case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...] if (Record.size() < 1 || ((Record.size()-1)&1)) @@ -1952,7 +1952,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { return Error("Invalid MALLOC record"); const PointerType *Ty = dyn_cast_or_null<PointerType>(getTypeByID(Record[0])); - Value *Size = getFnValueByID(Record[1], Type::Int32Ty); + Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context)); unsigned Align = Record[2]; if (!Ty || !Size) return Error("Invalid MALLOC record"); I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1); @@ -1972,7 +1972,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { return Error("Invalid ALLOCA record"); const PointerType *Ty = dyn_cast_or_null<PointerType>(getTypeByID(Record[0])); - Value *Size = getFnValueByID(Record[1], Type::Int32Ty); + Value *Size = getFnValueByID(Record[1], Type::getInt32Ty(Context)); unsigned Align = Record[2]; if (!Ty || !Size) return Error("Invalid ALLOCA record"); I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1); @@ -2089,7 +2089,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) { } // Non-void values get registered in the value table for future use. - if (I && I->getType() != Type::VoidTy) + if (I && I->getType() != Type::getVoidTy(Context)) ValueList.AssignValue(I, NextValueNo++); } diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h index bd048885a6..a7853abbc9 100644 --- a/lib/Bitcode/Reader/BitcodeReader.h +++ b/lib/Bitcode/Reader/BitcodeReader.h @@ -196,7 +196,7 @@ public: private: const Type *getTypeByID(unsigned ID, bool isTypeTable = false); Value *getFnValueByID(unsigned ID, const Type *Ty) { - if (Ty == Type::MetadataTy) + if (Ty == Type::getMetadataTy(Context)) return MDValueList.getValueFwdRef(ID); else return ValueList.getValueFwdRef(ID, Ty); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index cb181d2810..07566a71c3 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -482,7 +482,7 @@ static void WriteMDNode(const MDNode *N, Record.push_back(VE.getTypeID(N->getElement(i)->getType())); Record.push_back(VE.getValueID(N->getElement(i))); } else { - Record.push_back(VE.getTypeID(Type::VoidTy)); + Record.push_back(VE.getTypeID(Type::getVoidTy(N->getContext()))); Record.push_back(0); } } @@ -663,16 +663,18 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) { Code = bitc::CST_CODE_FLOAT; const Type *Ty = CFP->getType(); - if (Ty == Type::FloatTy || Ty == Type::DoubleTy) { + if (Ty == Type::getFloatTy(Ty->getContext()) || + Ty == Type::getDoubleTy(Ty->getContext())) { Record.push_back(CFP->getValueAPF().bitcastToAPInt().getZExtValue()); - } else if (Ty == Type::X86_FP80Ty) { + } else if (Ty == Type::getX86_FP80Ty(Ty->getContext())) { // api needed to prevent premature destruction // bits are not in the same order as a normal i80 APInt, compensate. APInt api = CFP->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); Record.push_back((p[1] << 48) | (p[0] >> 16)); Record.push_back(p[0] & 0xffffLL); - } else if (Ty == Type::FP128Ty || Ty == Type::PPC_FP128Ty) { + } else if (Ty == Type::getFP128Ty(Ty->getContext()) || + Ty == Type::getPPC_FP128Ty(Ty->getContext())) { APInt api = CFP->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); Record.push_back(p[0]); @@ -1139,7 +1141,7 @@ static void WriteFunction(const Function &F, ValueEnumerator &VE, for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) { WriteInstruction(*I, InstID, VE, Stream, Vals); - if (I->getType() != Type::VoidTy) + if (I->getType() != Type::getVoidTy(F.getContext())) ++InstID; } diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 4712dea762..783022cac2 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -198,7 +198,7 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) { if (*I) EnumerateValue(*I); else - EnumerateType(Type::VoidTy); + EnumerateType(Type::getVoidTy(MD->getContext())); } return; } else if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) { @@ -218,7 +218,8 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) { } void ValueEnumerator::EnumerateValue(const Value *V) { - assert(V->getType() != Type::VoidTy && "Can't insert void values!"); + assert(V->getType() != Type::getVoidTy(V->getContext()) && + "Can't insert void values!"); if (const MetadataBase *MB = dyn_cast<MetadataBase>(V)) return EnumerateMetadata(MB); @@ -358,7 +359,7 @@ void ValueEnumerator::incorporateFunction(const Function &F) { // Add all of the instructions. for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) { - if (I->getType() != Type::VoidTy) + if (I->getType() != Type::getVoidTy(F.getContext())) EnumerateValue(I); } } diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 55ff0b716b..6d1c7da1e1 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -871,7 +871,8 @@ void AsmPrinter::EmitConstantValueOnly(const Constant *CV) { // Handle casts to pointers by changing them into casts to the appropriate // integer type. This promotes constant folding and simplifies this code. Constant *Op = CE->getOperand(0); - Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/); + Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()), + false/*ZExt*/); return EmitConstantValueOnly(Op); } @@ -1016,8 +1017,9 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace) { // FP Constants are printed as integer constants to avoid losing // precision... + LLVMContext &Context = CFP->getContext(); const TargetData *TD = TM.getTargetData(); - if (CFP->getType() == Type::DoubleTy) { + if (CFP->getType() == Type::getDoubleTy(Context)) { double Val = CFP->getValueAPF().convertToDouble(); // for comment only uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue(); if (TAI->getData64bitsDirective(AddrSpace)) { @@ -1059,7 +1061,7 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, O << '\n'; } return; - } else if (CFP->getType() == Type::FloatTy) { + } else if (CFP->getType() == Type::getFloatTy(Context)) { float Val = CFP->getValueAPF().convertToFloat(); // for comment only O << TAI->getData32bitsDirective(AddrSpace) << CFP->getValueAPF().bitcastToAPInt().getZExtValue(); @@ -1069,7 +1071,7 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, } O << '\n'; return; - } else if (CFP->getType() == Type::X86_FP80Ty) { + } else if (CFP->getType() == Type::getX86_FP80Ty(Context)) { // all long double variants are printed as hex // api needed to prevent premature destruction APInt api = CFP->getValueAPF().bitcastToAPInt(); @@ -1151,10 +1153,10 @@ void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP, } O << '\n'; } - EmitZeros(TD->getTypeAllocSize(Type::X86_FP80Ty) - - TD->getTypeStoreSize(Type::X86_FP80Ty), AddrSpace); + EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) - + TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace); return; - } else if (CFP->getType() == Type::PPC_FP128Ty) { + } else if (CFP->getType() == Type::getPPC_FP128Ty(Context)) { // all long double variants are printed as hex // api needed to prevent premature destruction APInt api = CFP->getValueAPF().bitcastToAPInt(); diff --git a/lib/CodeGen/DwarfEHPrepare.cpp b/lib/CodeGen/DwarfEHPrepare.cpp index 5bfb32870c..16581112b6 100644 --- a/lib/CodeGen/DwarfEHPrepare.cpp +++ b/lib/CodeGen/DwarfEHPrepare.cpp @@ -142,7 +142,8 @@ bool DwarfEHPrepare::NormalizeLandingPads() { // edges to a new basic block which falls through into this one. // Create the new basic block. - BasicBlock *NewBB = BasicBlock::Create(LPad->getName() + "_unwind_edge"); + BasicBlock *NewBB = BasicBlock::Create(F->getContext(), + LPad->getName() + "_unwind_edge"); // Insert it into the function right before the original landing pad. LPad->getParent()->getBasicBlockList().insert(LPad, NewBB); @@ -230,8 +231,10 @@ bool DwarfEHPrepare::LowerUnwinds() { // Find the rewind function if we didn't already. if (!RewindFunction) { - std::vector<const Type*> Params(1, PointerType::getUnqual(Type::Int8Ty)); - FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false); + std::vector<const Type*> Params(1, + PointerType::getUnqual(Type::getInt8Ty(TI->getContext()))); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(TI->getContext()), + Params, false); const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME); RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy); } @@ -239,7 +242,7 @@ bool DwarfEHPrepare::LowerUnwinds() { // Create the call... CallInst::Create(RewindFunction, CreateReadOfExceptionValue(I), "", TI); // ...followed by an UnreachableInst. - new UnreachableInst(TI); + new UnreachableInst(TI->getContext(), TI); // Nuke the unwind instruction. TI->eraseFromParent(); @@ -354,8 +357,8 @@ Instruction *DwarfEHPrepare::CreateValueLoad(BasicBlock *BB) { // Create the temporary if we didn't already. if (!ExceptionValueVar) { - ExceptionValueVar = new AllocaInst(PointerType::getUnqual(Type::Int8Ty), - "eh.value", F->begin()->begin()); + ExceptionValueVar = new AllocaInst(PointerType::getUnqual( + Type::getInt8Ty(BB->getContext())), "eh.value", F->begin()->begin()); ++NumStackTempsIntroduced; } diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 1518a34acb..e62079f947 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -440,15 +440,16 @@ void ELFWriter::EmitGlobalConstant(const Constant *CV, ELFSection &GblS) { return; } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { APInt Val = CFP->getValueAPF().bitcastToAPInt(); - if (CFP->getType() == Type::DoubleTy) + if (CFP->getType() == Type::getDoubleTy(CV->getContext())) GblS.emitWord64(Val.getZExtValue()); - else if (CFP->getType() == Type::FloatTy) + else if (CFP->getType() == Type::getFloatTy(CV->getContext())) GblS.emitWord32(Val.getZExtValue()); - else if (CFP->getType() == Type::X86_FP80Ty) { - unsigned PadSize = TD->getTypeAllocSize(Type::X86_FP80Ty)- - TD->getTypeStoreSize(Type::X86_FP80Ty); + else if (CFP->getType() == Type::getX86_FP80Ty(CV->getContext())) { + unsigned PadSize = + TD->getTypeAllocSize(Type::getX86_FP80Ty(CV->getContext()))- + TD->getTypeStoreSize(Type::getX86_FP80Ty(CV->getContext())); GblS.emitWordFP80(Val.getRawData(), PadSize); - } else if (CFP->getType() == Type::PPC_FP128Ty) + } else if (CFP->getType() == Type::getPPC_FP128Ty(CV->getContext())) llvm_unreachable("PPC_FP128Ty global emission not implemented"); return; } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { @@ -526,7 +527,8 @@ CstExprResTy ELFWriter::ResolveConstantExpr(const Constant *CV) { } case Instruction::IntToPtr: { Constant *Op = CE->getOperand(0); - Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/); + Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()), + false/*ZExt*/); return ResolveConstantExpr(Op); } case Instruction::PtrToInt: { diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 67e4e6f762..cf855f0e89 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -40,11 +40,11 @@ static void EnsureFPIntrinsicsExist(Module &M, Function *Fn, switch((int)Fn->arg_begin()->getType()->getTypeID()) { case Type::FloatTyID: EnsureFunctionExists(M, FName, Fn->arg_begin(), Fn->arg_end(), - Type::FloatTy); + Type::getFloatTy(M.getContext())); break; case Type::DoubleTyID: EnsureFunctionExists(M, DName, Fn->arg_begin(), Fn->arg_end(), - Type::DoubleTy); + Type::getDoubleTy(M.getContext())); break; case Type::X86_FP80TyID: case Type::FP128TyID: @@ -83,39 +83,43 @@ static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI, } void IntrinsicLowering::AddPrototypes(Module &M) { + LLVMContext &Context = M.getContext(); for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) if (I->isDeclaration() && !I->use_empty()) switch (I->getIntrinsicID()) { default: break; case Intrinsic::setjmp: EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(), - Type::Int32Ty); + Type::getInt32Ty(M.getContext())); break; case Intrinsic::longjmp: EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(), - Type::VoidTy); + Type::getVoidTy(M.getContext())); break; case Intrinsic::siglongjmp: EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(), - Type::VoidTy); + Type::getVoidTy(M.getContext())); break; case Intrinsic::memcpy: - M.getOrInsertFunction("memcpy", PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - TD.getIntPtrType(), (Type *)0); + M.getOrInsertFunction("memcpy", + PointerType::getUnqual(Type::getInt8Ty(Context)), + PointerType::getUnqual(Type::getInt8Ty(Context)), + PointerType::getUnqual(Type::getInt8Ty(Context)), + TD.getIntPtrType(Context), (Type *)0); break; case Intrinsic::memmove: - M.getOrInsertFunction("memmove", PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - TD.getIntPtrType(), (Type *)0); + M.getOrInsertFunction("memmove", + PointerType::getUnqual(Type::getInt8Ty(Context)), + PointerType::getUnqual(Type::getInt8Ty(Context)), + PointerType::getUnqual(Type::getInt8Ty(Context)), + TD.getIntPtrType(Context), (Type *)0); break; case Intrinsic::memset: - M.getOrInsertFunction("memset", PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - Type::Int32Ty, - TD.getIntPtrType(), (Type *)0); + M.getOrInsertFunction("memset", + PointerType::getUnqual(Type::getInt8Ty(Context)), + PointerType::getUnqual(Type::getInt8Ty(Context)), + Type::getInt32Ty(M.getContext()), + TD.getIntPtrType(Context), (Type *)0); break; case Intrinsic::sqrt: EnsureFPIntrinsicsExist(M, I, "sqrtf", "sqrt", "sqrtl"); @@ -176,10 +180,10 @@ static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) { Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24), "bswap.1"); Tmp3 = Builder.CreateAnd(Tmp3, - ConstantInt::get(Type::Int32Ty, 0xFF0000), + ConstantInt::get(Type::getInt32Ty(Context), 0xFF0000), "bswap.and3"); Tmp2 = Builder.CreateAnd(Tmp2, - ConstantInt::get(Type::Int32Ty, 0xFF00), + ConstantInt::get(Type::getInt32Ty(Context), 0xFF00), "bswap.and2"); Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1"); Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2"); @@ -207,24 +211,28 @@ static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) { ConstantInt::get(V->getType(), 56), "bswap.1"); Tmp7 = Builder.CreateAnd(Tmp7, - ConstantInt::get(Type::Int64Ty, + ConstantInt::get(Type::getInt64Ty(Context), 0xFF000000000000ULL), "bswap.and7"); Tmp6 = Builder.CreateAnd(Tmp6, - ConstantInt::get(Type::Int64Ty, + ConstantInt::get(Type::getInt64Ty(Context), 0xFF0000000000ULL), "bswap.and6"); Tmp5 = Builder.CreateAnd(Tmp5, - ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL), + ConstantInt::get(Type::getInt64Ty(Context), + 0xFF00000000ULL), "bswap.and5"); Tmp4 = Builder.CreateAnd(Tmp4, - ConstantInt::get(Type::Int64Ty, 0xFF000000ULL), + ConstantInt::get(Type::getInt64Ty(Context), + 0xFF000000ULL), "bswap.and4"); Tmp3 = Builder.CreateAnd(Tmp3, - ConstantInt::get(Type::Int64Ty, 0xFF0000ULL), + ConstantInt::get(Type::getInt64Ty(Context), + 0xFF0000ULL), "bswap.and3"); Tmp2 = Builder.CreateAnd(Tmp2, - ConstantInt::get(Type::Int64Ty, 0xFF00ULL), + ConstantInt::get(Type::getInt64Ty(Context), + 0xFF00ULL), "bswap.and2"); Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1"); Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2"); @@ -303,11 +311,11 @@ static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname, default: llvm_unreachable("Invalid type in intrinsic"); case Type::FloatTyID: ReplaceCallWith(Fname, CI, CI->op_begin() + 1, CI->op_end(), - Type::FloatTy); + Type::getFloatTy(CI->getContext())); break; case Type::DoubleTyID: ReplaceCallWith(Dname, CI, CI->op_begin() + 1, CI->op_end(), - Type::DoubleTy); + Type::getDoubleTy(CI->getContext())); break; case Type::X86_FP80TyID: case Type::FP128TyID: @@ -339,26 +347,26 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { // convert the call to an explicit setjmp or longjmp call. case Intrinsic::setjmp: { Value *V = ReplaceCallWith("setjmp", CI, CI->op_begin() + 1, CI->op_end(), - Type::Int32Ty); - if (CI->getType() != Type::VoidTy) + Type::getInt32Ty(Context)); + if (CI->getType() != Type::getVoidTy(Context)) CI->replaceAllUsesWith(V); break; } case Intrinsic::sigsetjmp: - if (CI->getType() != Type::VoidTy) + if (CI->getType() != Type::getVoidTy(Context)) CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); break; case Intrinsic::longjmp: { ReplaceCallWith("longjmp", CI, CI->op_begin() + 1, CI->op_end(), - Type::VoidTy); + Type::getVoidTy(Context)); break; } case Intrinsic::siglongjmp: { // Insert the call to abort ReplaceCallWith("abort", CI, CI->op_end(), CI->op_end(), - Type::VoidTy); + Type::getVoidTy(Context)); break; } case Intrinsic::ctpop: @@ -414,7 +422,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::readcyclecounter: { cerr << "WARNING: this target does not support the llvm.readcyclecoun" << "ter intrinsic. It is being lowered to a constant 0\n"; - CI->replaceAllUsesWith(ConstantInt::get(Type::Int64Ty, 0)); + CI->replaceAllUsesWith(ConstantInt::get(Type::getInt64Ty(Context), 0)); break; } @@ -441,7 +449,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { break; // Strip out annotate intrinsic case Intrinsic::memcpy: { - const IntegerType *IntPtr = TD.getIntPtrType(); + const IntegerType *IntPtr = TD.getIntPtrType(Context); Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr, /* isSigned */ false); Value *Ops[3]; @@ -452,7 +460,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { break; } case Intrinsic::memmove: { - const IntegerType *IntPtr = TD.getIntPtrType(); + const IntegerType *IntPtr = TD.getIntPtrType(Context); Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr, /* isSigned */ false); Value *Ops[3]; @@ -463,13 +471,13 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { break; } case Intrinsic::memset: { - const IntegerType *IntPtr = TD.getIntPtrType(); + const IntegerType *IntPtr = TD.getIntPtrType(Context); Value *Size = Builder.CreateIntCast(CI->getOperand(3), IntPtr, /* isSigned */ false); Value *Ops[3]; Ops[0] = CI->getOperand(1); // Extend the amount to i32. - Ops[1] = Builder.CreateIntCast(CI->getOperand(2), Type::Int32Ty, + Ops[1] = Builder.CreateIntCast(CI->getOperand(2), Type::getInt32Ty(Context), /* isSigned */ false); Ops[2] = Size; ReplaceCallWith("memset", CI, Ops, Ops+3, CI->getOperand(1)->getType()); @@ -505,7 +513,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { } case Intrinsic::flt_rounds: // Lower to "round to the nearest" - if (CI->getType() != Type::VoidTy) + if (CI->getType() != Type::getVoidTy(Context)) CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); break; } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 3b854a59a1..9efec1c1ca 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -100,7 +100,8 @@ MachineFunction::MachineFunction(Function *F, const TargetData &TD = *TM.getTargetData(); bool IsPic = TM.getRelocationModel() == Reloc::PIC_; unsigned EntrySize = IsPic ? 4 : TD.getPointerSize(); - unsigned TyAlignment = IsPic ? TD.getABITypeAlignment(Type::Int32Ty) + unsigned TyAlignment = IsPic ? + TD.getABITypeAlignment(Type::getInt32Ty(F->getContext())) : TD.getPointerABIAlignment(); JumpTableInfo = new (Allocator.Allocate<MachineJumpTableInfo>()) MachineJumpTableInfo(EntrySize, TyAlignment); diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index dd2fef7ff0..7d1f15c487 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -243,7 +243,7 @@ void MachineOperand::print(raw_ostream &OS, const TargetMachine *TM) const { OS << getImm(); break; case MachineOperand::MO_FPImmediate: - if (getFPImm()->getType() == Type::FloatTy) + if (getFPImm()->getType() == Type::getFloatTy(getFPImm()->getContext())) OS << getFPImm()->getValueAPF().convertToFloat(); else OS << getFPImm()->getValueAPF().convertToDouble(); diff --git a/lib/CodeGen/PseudoSourceValue.cpp b/lib/CodeGen/PseudoSourceValue.cpp index 81cbfb83d2..c44093606e 100644 --- a/lib/CodeGen/PseudoSourceValue.cpp +++ b/lib/CodeGen/PseudoSourceValue.cpp @@ -39,8 +39,13 @@ static const char *const PSVNames[] = { "ConstantPool" }; +// FIXME: THIS IS A HACK!!!! +// Eventually these should be uniqued on LLVMContext rather than in a managed +// static. For now, we can safely use the global context for the time being to +// squeak by. PseudoSourceValue::PseudoSourceValue() : - Value(PointerType::getUnqual(Type::Int8Ty), PseudoSourceValueVal) {} + Value(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())), + PseudoSourceValueVal) {} void PseudoSourceValue::dump() const { print(errs()); errs() << '\n'; diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index d0d4f198f6..9496ff2446 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -92,7 +92,8 @@ unsigned FastISel::getRegForValue(Value *V) { } else if (isa<ConstantPointerNull>(V)) { // Translate this as an integer zero so that it can be // local-CSE'd with actual integer zeros. - Reg = getRegForValue(Constant::getNullValue(TD.getIntPtrType())); + Reg = + getRegForValue(Constant::getNullValue(TD.getIntPtrType(V->getContext()))); } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) { Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF); diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index b4799f12e9..ab4ebefa30 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -1997,7 +1997,8 @@ SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) } if (TLI.isLittleEndian()) FF <<= 32; - Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); + Constant *FudgeFactor = ConstantInt::get( + Type::getInt64Ty(*DAG.getContext()), FF); SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); @@ -2275,7 +2276,7 @@ void SelectionDAGLegalize::ExpandNode(SDNode *Node, // If this operation is not supported, lower it to 'abort()' call TargetLowering::ArgListTy Args; std::pair<SDValue, SDValue> CallResult = - TLI.LowerCallTo(Node->getOperand(0), Type::VoidTy, + TLI.LowerCallTo(Node->getOperand(0), Type::getVoidTy(*DAG.getContext()), false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/true, DAG.getExternalSymbol("abort", TLI.getPointerTy()), diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 8dba404acf..afcbc0987b 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -789,7 +789,7 @@ void SelectionDAG::VerifyNode(SDNode *N) { /// unsigned SelectionDAG::getEVTAlignment(EVT VT) const { const Type *Ty = VT == MVT::iPTR ? - PointerType::get(Type::Int8Ty, 0) : + PointerType::get(Type::getInt8Ty(*getContext()), 0) : VT.getTypeForEVT(*getContext()); return TLI.getTargetData()->getABITypeAlignment(Ty); @@ -3383,13 +3383,13 @@ SDValue SelectionDAG::getMemcpy(SDValue Chain, DebugLoc dl, SDValue Dst, // Emit a library call. TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; - Entry.Ty = TLI.getTargetData()->getIntPtrType(); + Entry.Ty = TLI.getTargetData()->getIntPtrType(*getContext()); Entry.Node = Dst; Args.push_back(Entry); Entry.Node = Src; Args.push_back(Entry); Entry.Node = Size; Args.push_back(Entry); // FIXME: pass in DebugLoc std::pair<SDValue,SDValue> CallResult = - TLI.LowerCallTo(Chain, Type::VoidTy, + TLI.LowerCallTo(Chain, Type::getVoidTy(*getContext()), false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/false, getExternalSymbol(TLI.getLibcallName(RTLIB::MEMCPY), @@ -3431,13 +3431,13 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, DebugLoc dl, SDValue Dst, // Emit a library call. TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; - Entry.Ty = TLI.getTargetData()->getIntPtrType(); + Entry.Ty = TLI.getTargetData()->getIntPtrType(*getContext()); Entry.Node = Dst; Args.push_back(Entry); Entry.Node = Src; Args.push_back(Entry); Entry.Node = Size; Args.push_back(Entry); // FIXME: pass in DebugLoc std::pair<SDValue,SDValue> CallResult = - TLI.LowerCallTo(Chain, Type::VoidTy, + TLI.LowerCallTo(Chain, Type::getVoidTy(*getContext()), false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/false, getExternalSymbol(TLI.getLibcallName(RTLIB::MEMMOVE), @@ -3475,7 +3475,7 @@ SDValue SelectionDAG::getMemset(SDValue Chain, DebugLoc dl, SDValue Dst, return Result; // Emit a library call. - const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(); + const Type *IntPtrTy = TLI.getTargetData()->getIntPtrType(*getContext()); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Node = Dst; Entry.Ty = IntPtrTy; @@ -3485,13 +3485,17 @@ SDValue SelectionDAG::getMemset(SDValue Chain, DebugLoc dl, SDValue Dst, Src = getNode(ISD::TRUNCATE, dl, MVT::i32, Src); else Src = getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Src); - Entry.Node = Src; Entry.Ty = Type::Int32Ty; Entry.isSExt = true; + Entry.Node = Src; + Entry.Ty = Type::getInt32Ty(*getContext()); + Entry.isSExt = true; Args.push_back(Entry); - Entry.Node = Size; Entry.Ty = IntPtrTy; Entry.isSExt = false; + Entry.Node = Size; + Entry.Ty = IntPtrTy; + Entry.isSExt = false; Args.push_back(Entry); // FIXME: pass in DebugLoc std::pair<SDValue,SDValue> CallResult = - TLI.LowerCallTo(Chain, Type::VoidTy, + TLI.LowerCallTo(Chain, Type::getVoidTy(*getContext()), false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/false, getExternalSymbol(TLI.getLibcallName(RTLIB::MEMSET), diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index d9a22d935f..cf0ddd4243 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -137,7 +137,7 @@ static void ComputeValueVTs(const TargetLowering &TLI, const Type *Ty, return; } // Interpret void as zero return values. - if (Ty == Type::VoidTy) + if (Ty == Type::getVoidTy(Ty->getContext())) return; // Base case: we can get an EVT for this LLVM IR type. ValueVTs.push_back(TLI.getValueType(Ty)); @@ -2934,7 +2934,7 @@ void SelectionDAGLowering::visitTargetIntrinsic(CallInst &I, else if (!HasChain) Result = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, getCurDebugLoc(), VTs, &Ops[0], Ops.size()); - else if (I.getType() != Type::VoidTy) + else if (I.getType() != Type::getVoidTy(*DAG.getContext())) Result = DAG.getNode(ISD::INTRINSIC_W_CHAIN, getCurDebugLoc(), VTs, &Ops[0], Ops.size()); else @@ -2948,7 +2948,7 @@ void SelectionDAGLowering::visitTargetIntrinsic(CallInst &I, else DAG.setRoot(Chain); } - if (I.getType() != Type::VoidTy) { + if (I.getType() != Type::getVoidTy(*DAG.getContext())) { if (const VectorType *PTy = dyn_cast<VectorType>(I.getType())) { EVT VT = TLI.getValueType(PTy); Result = DAG.getNode(ISD::BIT_CONVERT, getCurDebugLoc(), VT, Result); @@ -4836,7 +4836,8 @@ public: /// getCallOperandValEVT - Return the EVT of the Value* that this operand /// corresponds to. If there is no Value* for this operand, it returns /// MVT::Other. - EVT getCallOperandValEVT(const TargetLowering &TLI, + EVT getCallOperandValEVT(LLVMContext &Context, + const TargetLowering &TLI, const TargetData *TD) const { if (CallOperandVal == 0) return MVT::Other; @@ -4862,7 +4863,7 @@ public: case 32: case 64: case 128: - OpTy = IntegerType::get(BitSize); + OpTy = IntegerType::get(Context, BitSize); break; } } @@ -5131,7 +5132,8 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) { // The return value of the call is this value. As such, there is no // corresponding argument. - assert(CS.getType() != Type::VoidTy && "Bad inline asm!"); + assert(CS.getType() != Type::getVoidTy(*DAG.getContext()) && + "Bad inline asm!"); if (const StructType *STy = dyn_cast<StructType>(CS.getType())) { OpVT = TLI.getValueType(STy->getElementType(ResNo)); } else { @@ -5160,7 +5162,7 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) { OpInfo.CallOperand = getValue(OpInfo.CallOperandVal); } - OpVT = OpInfo.getCallOperandValEVT(TLI, TD); + OpVT = OpInfo.getCallOperandValEVT(*DAG.getContext(), TLI, TD); } OpInfo.ConstraintVT = OpVT; @@ -5298,7 +5300,8 @@ void SelectionDAGLowering::visitInlineAsm(CallSite CS) { OpInfo.CallOperandVal)); } else { // This is the result value of the call. - assert(CS.getType() != Type::VoidTy && "Bad inline asm!"); + assert(CS.getType() != Type::getVoidTy(*DAG.getContext()) && + "Bad inline asm!"); // Concatenate this output onto the outputs list. RetValRegs.append(OpInfo.AssignedRegs); } @@ -5536,7 +5539,7 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) { TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Node = Src; - Entry.Ty = TLI.getTargetData()->getIntPtrType(); + Entry.Ty = TLI.getTargetData()->getIntPtrType(*DAG.getContext()); Args.push_back(Entry); bool isTailCall = PerformTailCallOpt && @@ -5557,13 +5560,14 @@ void SelectionDAGLowering::visitFree(FreeInst &I) { TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Node = getValue(I.getOperand(0)); - Entry.Ty = TLI.getTargetData()->getIntPtrType(); + Entry.Ty = TLI.getTargetData()->getIntPtrType(*DAG.getContext()); Args.push_back(Entry); EVT IntPtr = TLI.getPointerTy(); bool isTailCall = PerformTailCallOpt && isInTailCallPosition(&I, Attribute::None, TLI); std::pair<SDValue,SDValue> Result = - TLI.LowerCallTo(getRoot(), Type::VoidTy, false, false, false, false, + TLI.LowerCallTo(getRoot(), Type::getVoidTy(*DAG.getContext()), + false, false, false, false, 0, CallingConv::C, isTailCall, /*isReturnValueUsed=*/true, DAG.getExternalSymbol("free", IntPtr), Args, DAG, @@ -5822,7 +5826,7 @@ LowerArguments(BasicBlock *LLVMBB) { for (unsigned Value = 0, NumValues = ValueVTs.size(); Value != NumValues; ++Value) { EVT VT = ValueVTs[Value]; - const Type *ArgTy = VT.getTypeForEVT(*CurDAG->getContext()); + const Type *ArgTy = VT.getTypeForEVT(*DAG.getContext()); ISD::ArgFlagsTy Flags; unsigned OriginalAlignment = TD->getABITypeAlignment(ArgTy); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 3d1327f13e..87fc751c55 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -750,7 +750,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn, BI->dump(); } - if (BI->getType() != Type::VoidTy) { + if (BI->getType() != Type::getVoidTy(*CurDAG->getContext())) { unsigned &R = FuncInfo->ValueMap[BI]; if (!R) R = FuncInfo->CreateRegForValue(BI); diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 728dccfd69..767238e781 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -496,8 +496,7 @@ TargetLowering::TargetLowering(TargetMachine &tm,TargetLoweringObjectFile *tlof) IsLittleEndian = TD->isLittleEndian(); UsesGlobalOffsetTable = false; - ShiftAmountTy = PointerTy = - getValueType(TD->getIntPtrType()).getSimpleVT().SimpleTy; + ShiftAmountTy = PointerTy = MVT::getIntegerVT(8*TD->getPointerSize()); memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*)); memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray)); maxStoresPerMemset = maxStoresPerMemcpy = maxStoresPerMemmove = 8; @@ -704,7 +703,7 @@ const char *TargetLowering::getTargetNodeName(unsigned Opcode) const { MVT::SimpleValueType TargetLowering::getSetCCResultType(EVT VT) const { - return getValueType(TD->getIntPtrType()).getSimpleVT().SimpleTy; + return PointerTy.SimpleTy; } /// getVectorTypeBreakdown - Vector types are broken down into some number of diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index 514629bff7..5b4cc7fe26 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -138,8 +138,9 @@ namespace { return 0; // Create a cleanup block. - BasicBlock *CleanupBB = BasicBlock::Create(CleanupBBName, &F); - UnwindInst *UI = new UnwindInst(CleanupBB); + BasicBlock *CleanupBB = BasicBlock::Create(F.getContext(), + CleanupBBName, &F); + UnwindInst *UI = new UnwindInst(F.getContext(), CleanupBB); // Transform the 'call' instructions into 'invoke's branching to the // cleanup block. Go in reverse order to make prettier BB names. @@ -188,7 +189,7 @@ ShadowStackGC::ShadowStackGC() : Head(0), StackEntryTy(0) { Constant *ShadowStackGC::GetFrameMap(Function &F) { // doInitialization creates the abstract type of this value. - Type *VoidPtr = PointerType::getUnqual(Type::Int8Ty); + Type *VoidPtr = PointerType::getUnqual(Type::getInt8Ty(F.getContext())); // Truncate the ShadowStackDescriptor if some metadata is null. unsigned NumMeta = 0; @@ -201,8 +202,8 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) { } Constant *BaseElts[] = { - ConstantInt::get(Type::Int32Ty, Roots.size(), false), - ConstantInt::get(Type::Int32Ty, NumMeta, false), + ConstantInt::get(Type::getInt32Ty(F.getContext()), Roots.size(), false), + ConstantInt::get(Type::getInt32Ty(F.getContext()), NumMeta, false), }; Constant *DescriptorElts[] = { @@ -234,8 +235,10 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) { GlobalVariable::InternalLinkage, FrameMap, "__gc_" + F.getName()); - Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0), - ConstantInt::get(Type::Int32Ty, 0) }; + Constant *GEPIndices[2] = { + ConstantInt::get(Type::getInt32Ty(F.getContext()), 0), + ConstantInt::get(Type::getInt32Ty(F.getContext()), 0) + }; return ConstantExpr::getGetElementPtr(GV, GEPIndices, 2); } @@ -263,8 +266,10 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) { // void *Meta[]; // May be absent for roots without metadata. // }; std::vector<const Type*> EltTys; - EltTys.push_back(Type::Int32Ty); // 32 bits is ok up to a 32GB stack frame. :) - EltTys.push_back(Type::Int32Ty); // Specifies length of variable length array. + // 32 bits is ok up to a 32GB stack frame. :) + EltTys.push_back(Type::getInt32Ty(M.getContext())); + // Specifies length of variable length array. + EltTys.push_back(Type::getInt32Ty(M.getContext())); StructType *FrameMapTy = StructType::get(M.getContext(), EltTys); M.addTypeName("gc_map", FrameMapTy); PointerType *FrameMapPtrTy = PointerType::getUnqual(FrameMapTy); @@ -340,9 +345,9 @@ void ShadowStackGC::CollectRoots(Function &F) { GetElementPtrInst * ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr, int Idx, int Idx2, const char *Name) { - Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0), - ConstantInt::get(Type::Int32Ty, Idx), - ConstantInt::get(Type::Int32Ty, Idx2) }; + Value *Indices[] = { ConstantInt::get(Type::getInt32Ty(Context), 0), + ConstantInt::get(Type::getInt32Ty(Context), Idx), + ConstantInt::get(Type::getInt32Ty(Context), Idx2) }; Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name); assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant"); @@ -353,8 +358,8 @@ ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr, GetElementPtrInst * ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr, int Idx, const char *Name) { - Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0), - ConstantInt::get(Type::Int32Ty, Idx) }; + Value *Indices[] = { ConstantInt::get(Type::getInt32Ty(Context), 0), + ConstantInt::get(Type::getInt32Ty(Context), Idx) }; Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name); assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant"); diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp index 9043b89e35..350bc6e1ad 100644 --- a/lib/CodeGen/StackProtector.cpp +++ b/lib/CodeGen/StackProtector.cpp @@ -148,7 +148,8 @@ bool StackProtector::InsertStackProtectors() { // StackGuard = load __stack_chk_guard // call void @llvm.stackprotect.create(StackGuard, StackGuardSlot) // - PointerType *PtrTy = PointerType::getUnqual(Type::Int8Ty); + PointerType *PtrTy = PointerType::getUnqual( + Type::getInt8Ty(RI->getContext())); StackGuardVar = M->getOrInsertGlobal("__stack_chk_guard", PtrTy); BasicBlock &Entry = F->getEntryBlock(); @@ -215,10 +216,12 @@ bool StackProtector::InsertStackProtectors() { /// CreateFailBB - Create a basic block to jump to when the stack protector /// check fails. BasicBlock *StackProtector::CreateFailBB() { - BasicBlock *FailBB = BasicBlock::Create("CallStackCheckFailBlk", F); + BasicBlock *FailBB = BasicBlock::Create(F->getContext(), + "CallStackCheckFailBlk", F); Constant *StackChkFail = - M->getOrInsertFunction("__stack_chk_fail", Type::VoidTy, NULL); + M->getOrInsertFunction("__stack_chk_fail", + Type::getVoidTy(F->getContext()), NULL); CallInst::Create(StackChkFail, "", FailBB); - new UnreachableInst(FailBB); + new UnreachableInst(F->getContext(), FailBB); return FailBB; } diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 348190a75b..a20122d9f9 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -238,13 +238,13 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { // CreateArgv - Turn a vector of strings into a nice argv style array of // pointers to null terminated strings. // -static void *CreateArgv(ExecutionEngine *EE, +static void *CreateArgv(LLVMContext &C, ExecutionEngine *EE, const std::vector<std::string> &InputArgv) { unsigned PtrSize = EE->getTargetData()->getPointerSize(); char *Result = new char[(InputArgv.size()+1)*PtrSize]; DOUT << "JIT: ARGV = " << (void*)Result << "\n"; - const Type *SBytePtr = PointerType::getUnqual(Type::Int8Ty); + const Type *SBytePtr = PointerType::getUnqual(Type::getInt8Ty(C)); for (unsigned i = 0; i != InputArgv.size(); ++i) { unsigned Size = InputArgv[i].size()+1; @@ -340,7 +340,8 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, unsigned NumArgs = Fn->getFunctionType()->getNumParams(); const FunctionType *FTy = Fn->getFunctionType(); const Type* PPInt8Ty = - PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)); + PointerType::getUnqual(PointerType::getUnqual( + Type::getInt8Ty(Fn->getContext()))); switch (NumArgs) { case 3: if (FTy->getParamType(2) != PPInt8Ty) { @@ -353,13 +354,13 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, } // FALLS THROUGH case 1: - if (FTy->getParamType(0) != Type::Int32Ty) { + if (FTy->getParamType(0) != Type::getInt32Ty(Fn->getContext())) { llvm_report_error("Invalid type for first argument of main() supplied"); } // FALLS THROUGH case 0: if (!isa<IntegerType>(FTy->getReturnType()) && - FTy->getReturnType() != Type::VoidTy) { + FTy->getReturnType() != Type::getVoidTy(FTy->getContext())) { llvm_report_error("Invalid return type of main() supplied"); } break; @@ -370,14 +371,16 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, if (NumArgs) { GVArgs.push_back(GVArgc); // Arg #0 = argc. if (NumArgs > 1) { - GVArgs.push_back(PTOGV(CreateArgv(this, argv))); // Arg #1 = argv. + // Arg #1 = argv. + GVArgs.push_back(PTOGV(CreateArgv(Fn->getContext(), this, argv))); assert(!isTargetNullPtr(this, GVTOP(GVArgs[1])) && "argv[0] was null after CreateArgv"); if (NumArgs > 2) { std::vector<std::string> EnvVars; for (unsigned i = 0; envp[i]; ++i) EnvVars.push_back(envp[i]); - GVArgs.push_back(PTOGV(CreateArgv(this, EnvVars))); // Arg #2 = envp. + // Arg #2 = envp. + GVArgs.push_back(PTOGV(CreateArgv(Fn->getContext(), this, EnvVars))); } } } @@ -525,11 +528,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { } case Instruction::UIToFP: { GenericValue GV = getConstantValue(Op0); - if (CE->getType() == Type::FloatTy) + if (CE->getType() == Type::getFloatTy(CE->getContext())) GV.FloatVal = float(GV.IntVal.roundToDouble()); - else if (CE->getType() == Type::DoubleTy) + else if (CE->getType() == Type::getDoubleTy(CE->getContext())) GV.DoubleVal = GV.IntVal.roundToDouble(); - else if (CE->getType() == Type::X86_FP80Ty) { + else if (CE->getType() == Type::getX86_FP80Ty(Op0->getContext())) { const uint64_t zero[] = {0, 0}; APFloat apf = APFloat(APInt(80, 2, zero)); (void)apf.convertFromAPInt(GV.IntVal, @@ -541,11 +544,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { } case Instruction::SIToFP: { GenericValue GV = getConstantValue(Op0); - if (CE->getType() == Type::FloatTy) + if (CE->getType() == Type::getFloatTy(CE->getContext())) GV.FloatVal = float(GV.IntVal.signedRoundToDouble()); - else if (CE->getType() == Type::DoubleTy) + else if (CE->getType() == Type::getDoubleTy(CE->getContext())) GV.DoubleVal = GV.IntVal.signedRoundToDouble(); - else if (CE->getType() == Type::X86_FP80Ty) { + else if (CE->getType() == Type::getX86_FP80Ty(CE->getContext())) { const uint64_t zero[] = { 0, 0}; APFloat apf = APFloat(APInt(80, 2, zero)); (void)apf.convertFromAPInt(GV.IntVal, @@ -559,11 +562,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Instruction::FPToSI: { GenericValue GV = getConstantValue(Op0); uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth(); - if (Op0->getType() == Type::FloatTy) + if (Op0->getType() == Type::getFloatTy(Op0->getContext())) GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth); - else if (Op0->getType() == Type::DoubleTy) + else if (Op0->getType() == Type::getDoubleTy(Op0->getContext())) GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth); - else if (Op0->getType() == Type::X86_FP80Ty) { + else if (Op0->getType() == Type::getX86_FP80Ty(Op0->getContext())) { APFloat apf = APFloat(GV.IntVal); uint64_t v; bool ignored; @@ -596,17 +599,19 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { default: llvm_unreachable("Invalid bitcast operand"); case Type::IntegerTyID: assert(DestTy->isFloatingPoint() && "invalid bitcast"); - if (DestTy == Type::FloatTy) + if (DestTy == Type::getFloatTy(Op0->getContext())) GV.FloatVal = GV.IntVal.bitsToFloat(); - else if (DestTy == Type::DoubleTy) + else if (DestTy == Type::getDoubleTy(DestTy->getContext())) GV.DoubleVal = GV.IntVal.bitsToDouble(); break; case Type::FloatTyID: - assert(DestTy == Type::Int32Ty && "Invalid bitcast"); + assert(DestTy == Type::getInt32Ty(DestTy->getContext()) && + "Invalid bitcast"); GV.IntVal.floatToBits(GV.FloatVal); break; case Type::DoubleTyID: - assert(DestTy == Type::Int64Ty && "Invalid bitcast"); + assert(DestTy == Type::getInt64Ty(DestTy->getContext()) && + "Invalid bitcast"); GV.IntVal.doubleToBits(GV.DoubleVal); break; case Type::PointerTyID: diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 8d21d1f40b..45180c91f0 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -366,7 +366,7 @@ static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, } #define IMPLEMENT_UNORDERED(TY, X,Y) \ - if (TY == Type::FloatTy) { \ + if (TY == Type::getFloatTy(Ty->getContext())) { \ if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ Dest.IntVal = APInt(1,true); \ return Dest; \ @@ -422,7 +422,7 @@ static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Ty->getContext())) Dest.IntVal = APInt(1,(Src1.FloatVal == Src1.FloatVal && Src2.FloatVal == Src2.FloatVal)); else @@ -434,7 +434,7 @@ static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Ty->getContext())) Dest.IntVal = APInt(1,(Src1.FloatVal != Src1.FloatVal || Src2.FloatVal != Src2.FloatVal)); else @@ -602,7 +602,8 @@ void Interpreter::popStackAndReturnValueToCaller (const Type *RetTy, // fill in the return value... ExecutionContext &CallingSF = ECStack.back(); if (Instruction *I = CallingSF.Caller.getInstruction()) { - if (CallingSF.Caller.getType() != Type::VoidTy) // Save result... + // Save result... + if (CallingSF.Caller.getType() != Type::getVoidTy(RetTy->getContext())) SetValue(I, Result, CallingSF); if (InvokeInst *II = dyn_cast<InvokeInst> (I)) SwitchToNewBasicBlock (II->getNormalDest (), CallingSF); @@ -613,7 +614,7 @@ void Interpreter::popStackAndReturnValueToCaller (const Type *RetTy, void Interpreter::visitReturnInst(ReturnInst &I) { ExecutionContext &SF = ECStack.back(); - const Type *RetTy = Type::VoidTy; + const Type *RetTy = Type::getVoidTy(I.getContext()); GenericValue Result; // Save away the return value... (if we are not 'ret void') @@ -970,7 +971,8 @@ GenericValue Interpreter::executeZExtInst(Value *SrcVal, const Type *DstTy, GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { GenericValue Dest, Src = getOperandValue(SrcVal, SF); - assert(SrcVal->getType() == Type::DoubleTy && DstTy == Type::FloatTy && + assert(SrcVal->getType() == Type::getDoubleTy(SrcVal->getContext()) && + DstTy == Type::getFloatTy(SrcVal->getContext()) && "Invalid FPTrunc instruction"); Dest.FloatVal = (float) Src.DoubleVal; return Dest; @@ -979,7 +981,8 @@ GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, GenericValue Interpreter::executeFPExtInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { GenericValue Dest, Src = getOperandValue(SrcVal, SF); - assert(SrcVal->getType() == Type::FloatTy && DstTy == Type::DoubleTy && + assert(SrcVal->getType() == Type::getFloatTy(SrcVal->getContext()) && + DstTy == Type::getDoubleTy(SrcVal->getContext()) && "Invalid FPTrunc instruction"); Dest.DoubleVal = (double) Src.FloatVal; return Dest; @@ -1070,22 +1073,22 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy, assert(isa<PointerType>(SrcTy) && "Invalid BitCast"); Dest.PointerVal = Src.PointerVal; } else if (DstTy->isInteger()) { - if (SrcTy == Type::FloatTy) { + if (SrcTy == Type::getFloatTy(SrcVal->getContext())) { Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT); Dest.IntVal.floatToBits(Src.FloatVal); - } else if (SrcTy == Type::DoubleTy) { + } else if (SrcTy == Type::getDoubleTy(SrcVal->getContext())) { Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT); Dest.IntVal.doubleToBits(Src.DoubleVal); } else if (SrcTy->isInteger()) { Dest.IntVal = Src.IntVal; } else llvm_unreachable("Invalid BitCast"); - } else if (DstTy == Type::FloatTy) { + } else if (DstTy == Type::getFloatTy(SrcVal->getContext())) { if (SrcTy->isInteger()) Dest.FloatVal = Src.IntVal.bitsToFloat(); else Dest.FloatVal = Src.FloatVal; - } else if (DstTy == Type::DoubleTy) { + } else if (DstTy == Type::getDoubleTy(SrcVal->getContext())) { if (SrcTy->isInteger()) Dest.DoubleVal = Src.IntVal.bitsToDouble(); else diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index 37f6ef07f6..92fd817cde 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -418,7 +418,8 @@ GenericValue lle_X_printf(const FunctionType *FT, return GV; } -static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1, +static void ByteswapSCANFResults(LLVMContext &C, + const char *Fmt, void *Arg0, void *Arg1, void *Arg2, void *Arg3, void *Arg4, void *Arg5, void *Arg6, void *Arg7, void *Arg8) { void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 }; @@ -458,26 +459,26 @@ static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1, case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p': case 'd': if (Long || LongLong) { - Size = 8; Ty = Type::Int64Ty; + Size = 8; Ty = Type::getInt64Ty(C); } else if (Half) { - Size = 4; Ty = Type::Int16Ty; + Size = 4; Ty = Type::getInt16Ty(C); } else { - Size = 4; Ty = Type::Int32Ty; + Size = 4; Ty = Type::getInt32Ty(C); } break; case 'e': case 'g': case 'E': case 'f': if (Long || LongLong) { - Size = 8; Ty = Type::DoubleTy; + Size = 8; Ty = Type::getDoubleTy(C); } else { - Size = 4; Ty = Type::FloatTy; + Size = 4; Ty = Type::getFloatTy(C); } break; case 's': case 'c': case '[': // No byteswap needed Size = 1; - Ty = Type::Int8Ty; + Ty = Type::getInt8Ty(C); break; default: break; @@ -506,7 +507,8 @@ GenericValue lle_X_sscanf(const FunctionType *FT, GenericValue GV; GV.IntVal = APInt(32, sscanf(Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9])); - ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4], + ByteswapSCANFResults(FT->getContext(), + Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9], 0); return GV; } @@ -523,7 +525,8 @@ GenericValue lle_X_scanf(const FunctionType *FT, GenericValue GV; GV.IntVal = APInt(32, scanf( Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9])); - ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4], + ByteswapSCANFResults(FT->getContext(), + Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9]); return GV; } diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index b932c8cef1..3743350433 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -382,10 +382,11 @@ GenericValue JIT::runFunction(Function *F, // Handle some common cases first. These cases correspond to common `main' // prototypes. - if (RetTy == Type::Int32Ty || RetTy == Type::VoidTy) { + if (RetTy == Type::getInt32Ty(F->getContext()) || + RetTy == Type::getVoidTy(F->getContext())) { switch (ArgValues.size()) { case 3: - if (FTy->getParamType(0) == Type::Int32Ty && + if (FTy->getParamType(0) == Type::getInt32Ty(F->getContext()) && isa<PointerType>(FTy->getParamType(1)) && isa<PointerType>(FTy->getParamType(2))) { int (*PF)(int, char **, const char **) = @@ -400,7 +401,7 @@ GenericValue JIT::runFunction(Function *F, } break; case 2: - if (FTy->getParamType(0) == Type::Int32Ty && + if (FTy->getParamType(0) == Type::getInt32Ty(F->getContext()) && isa<PointerType>(FTy->getParamType(1))) { int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr; @@ -413,7 +414,7 @@ GenericValue JIT::runFunction(Function *F, break; case 1: if (FTy->getNumParams() == 1 && - FTy->getParamType(0) == Type::Int32Ty) { + FTy->getParamType(0) == Type::getInt32Ty(F->getContext())) { GenericValue rv; int (*PF)(int) = (int(*)(int))(intptr_t)FPtr; rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue())); @@ -474,7 +475,7 @@ GenericValue JIT::runFunction(Function *F, F->getParent()); // Insert a basic block. - BasicBlock *StubBB = BasicBlock::Create("", Stub); + BasicBlock *StubBB = BasicBlock::Create(F->getContext(), "", Stub); // Convert all of the GenericValue arguments over to constants. Note that we // currently don't support varargs. @@ -502,9 +503,11 @@ GenericValue JIT::runFunction(Function *F, case Type::PointerTyID: void *ArgPtr = GVTOP(AV); if (sizeof(void*) == 4) - C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr); + C = ConstantInt::get(Type::getInt32Ty(F->getContext()), + (int)(intptr_t)ArgPtr); else - C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr); + C = ConstantInt::get(Type::getInt64Ty(F->getContext()), + (intptr_t)ArgPtr); // Cast the integer to pointer C = ConstantExpr::getIntToPtr(C, ArgTy); break; @@ -516,10 +519,11 @@ GenericValue JIT::runFunction(Function *F, "", StubBB); TheCall->setCallingConv(F->getCallingConv()); TheCall->setTailCall(); - if (TheCall->getType() != Type::VoidTy) - ReturnInst::Create(TheCall, StubBB); // Return result of the call. + if (TheCall->getType() != Type::getVoidTy(F->getContext())) + // Return result of the call. + ReturnInst::Create(F->getContext(), TheCall, StubBB); else - ReturnInst::Create(StubBB); // Just return void. + ReturnInst::Create(F->getContext(), StubBB); // Just return void. // Finally, return the value returned by our nullary stub function. return runFunction(Stub, std::vector<GenericValue>()); diff --git a/lib/Target/ARM/ARMBaseRegisterInfo.cpp b/lib/Target/ARM/ARMBaseRegisterInfo.cpp index 98a08e12d6..309a5c6eb5 100644 --- a/lib/Target/ARM/ARMBaseRegisterInfo.cpp +++ b/lib/Target/ARM/ARMBaseRegisterInfo.cpp @@ -903,7 +903,8 @@ emitLoadConstPool(MachineBasicBlock &MBB, unsigned PredReg) const { MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); - Constant *C = ConstantInt::get(Type::Int32Ty, Val); + Constant *C = + ConstantInt::get(Type::getInt32Ty(MF.getFunction()->getContext()), Val); unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp)) diff --git a/lib/Target/ARM/ARMCodeEmitter.cpp b/lib/Target/ARM/ARMCodeEmitter.cpp index d5f9cd1314..6218fceac1 100644 --- a/lib/Target/ARM/ARMCodeEmitter.cpp +++ b/lib/Target/ARM/ARMCodeEmitter.cpp @@ -456,9 +456,9 @@ void Emitter<CodeEmitter>::emitConstPoolInstruction(const MachineInstr &MI) { uint32_t Val = *(uint32_t*)CI->getValue().getRawData(); emitWordLE(Val); } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { - if (CFP->getType() == Type::FloatTy) + if (CFP->getType() == Type::getFloatTy(CFP->getContext())) emitWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue()); - else if (CFP->getType() == Type::DoubleTy) + else if (CFP->getType() == Type::getDoubleTy(CFP->getContext())) emitDWordLE(CFP->getValueAPF().bitcastToAPInt().getZExtValue()); else { llvm_unreachable("Unable to handle this constantpool entry!"); diff --git a/lib/Target/ARM/ARMConstantPoolValue.cpp b/lib/Target/ARM/ARMConstantPoolValue.cpp index 8e85d3dec6..9697422c6d 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -29,19 +29,20 @@ ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id, GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj), Modifier(Modif), AddCurrentAddress(AddCA) {} -ARMConstantPoolValue::ARMConstantPoolValue(const char *s, unsigned id, +ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C, + const char *s, unsigned id, ARMCP::ARMCPKind k, unsigned char PCAdj, const char *Modif, bool AddCA) - : MachineConstantPoolValue((const Type*)Type::Int32Ty), + : MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)), GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj), Modifier(Modif), AddCurrentAddress(AddCA) {} ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, ARMCP::ARMCPKind k, const char *Modif) - : MachineConstantPoolValue((const Type*)Type::Int32Ty), + : MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())), GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0), Modifier(Modif) {} diff --git a/lib/Target/ARM/ARMConstantPoolValue.h b/lib/Target/ARM/ARMConstantPoolValue.h index 77516e58e0..13683a3007 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.h +++ b/lib/Target/ARM/ARMConstantPoolValue.h @@ -20,6 +20,7 @@ namespace llvm { class GlobalValue; +class LLVMContext; namespace ARMCP { enum ARMCPKind { @@ -47,7 +48,7 @@ public: ARMCP::ARMCPKind Kind = ARMCP::CPValue, unsigned char PCAdj = 0, const char *Modifier = NULL, bool AddCurrentAddress = false); - ARMConstantPoolValue(const char *s, unsigned id, + ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id, ARMCP::ARMCPKind Kind = ARMCP::CPValue, unsigned char PCAdj = 0, const char *Modifier = NULL, bool AddCurrentAddress = false); diff --git a/lib/Target/ARM/ARMISelDAGToDAG.cpp b/lib/Target/ARM/ARMISelDAGToDAG.cpp index 608488397e..9ca80ae1b9 100644 --- a/lib/Target/ARM/ARMISelDAGToDAG.cpp +++ b/lib/Target/ARM/ARMISelDAGToDAG.cpp @@ -952,7 +952,8 @@ SDNode *ARMDAGToDAGISel::Select(SDValue Op) { !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs. if (UseCP) { SDValue CPIdx = - CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val), + CurDAG->getTargetConstantPool(ConstantInt::get( + Type::getInt32Ty(*CurDAG->getContext()), Val), TLI.getPointerTy()); SDNode *ResNode; diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index 14cab0986b..a36fdbf247 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -985,7 +985,8 @@ ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, // tBX takes a register source operand. const char *Sym = S->getSymbol(); if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { - ARMConstantPoolValue *CPV = new ARMConstantPoolValue(Sym, ARMPCLabelIndex, + ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), + Sym, ARMPCLabelIndex, ARMCP::CPStub, 4); SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); @@ -1177,11 +1178,11 @@ ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, ArgListTy Args; ArgListEntry Entry; Entry.Node = Argument; - Entry.Ty = (const Type *) Type::Int32Ty; + Entry.Ty = (const Type *) Type::getInt32Ty(*DAG.getContext()); Args.push_back(Entry); // FIXME: is there useful debug info available here? std::pair<SDValue, SDValue> CallResult = - LowerCallTo(Chain, (const Type *) Type::Int32Ty, false, false, false, false, + LowerCallTo(Chain, (const Type *) Type::getInt32Ty(*DAG.getContext()), false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/true, DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); return CallResult.first; @@ -1322,7 +1323,8 @@ SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, EVT PtrVT = getPointerTy(); DebugLoc dl = Op.getDebugLoc(); unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; - ARMConstantPoolValue *CPV = new ARMConstantPoolValue("_GLOBAL_OFFSET_TABLE_", + ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), + "_GLOBAL_OFFSET_TABLE_", ARMPCLabelIndex, ARMCP::CPValue, PCAdj); SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); @@ -1411,7 +1413,8 @@ ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) { std::string LSDAName = "L_lsda_"; LSDAName += MF.getFunction()->getName(); ARMConstantPoolValue *CPV = - new ARMConstantPoolValue(LSDAName.c_str(), ARMPCLabelIndex, Kind, PCAdj); + new ARMConstantPoolValue(*DAG.getContext(), LSDAName.c_str(), + ARMPCLabelIndex, Kind, PCAdj); CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); SDValue Result = diff --git a/lib/Target/ARM/ARMLoadStoreOptimizer.cpp b/lib/Target/ARM/ARMLoadStoreOptimizer.cpp index 11d4887e25..3c6778fe8c 100644 --- a/lib/Target/ARM/ARMLoadStoreOptimizer.cpp +++ b/lib/Target/ARM/ARMLoadStoreOptimizer.cpp @@ -19,6 +19,7 @@ #include "ARMMachineFunctionInfo.h" #include "ARMRegisterInfo.h" #include "llvm/DerivedTypes.h" +#include "llvm/Function.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineInstr.h" @@ -1183,7 +1184,9 @@ ARMPreAllocLoadStoreOpt::CanFormLdStDWord(MachineInstr *Op0, MachineInstr *Op1, unsigned Align = Op0->memoperands_begin()->getAlignment(); unsigned ReqAlign = STI->hasV6Ops() - ? TD->getPrefTypeAlignment(Type::Int64Ty) : 8; // Pre-v6 need 8-byte align + ? TD->getPrefTypeAlignment( + Type::getInt64Ty(Op0->getParent()->getParent()->getFunction()->getContext())) + : 8; // Pre-v6 need 8-byte align if (Align < ReqAlign) return false; diff --git a/lib/Target/ARM/Thumb1RegisterInfo.cpp b/lib/Target/ARM/Thumb1RegisterInfo.cpp index b11d4c35ac..796057f9c5 100644 --- a/lib/Target/ARM/Thumb1RegisterInfo.cpp +++ b/lib/Target/ARM/Thumb1RegisterInfo.cpp @@ -58,7 +58,8 @@ void Thumb1RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB, unsigned PredReg) const { MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); - Constant *C = ConstantInt::get(Type::Int32Ty, Val); + Constant *C = ConstantInt::get( + Type::getInt32Ty(MBB.getParent()->getFunction()->getContext()), Val); unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); BuildMI(MBB, MBBI, dl, TII.get(ARM::tLDRcp)) diff --git a/lib/Target/ARM/Thumb2RegisterInfo.cpp b/lib/Target/ARM/Thumb2RegisterInfo.cpp index 98be2041fd..6c4c15dfe3 100644 --- a/lib/Target/ARM/Thumb2RegisterInfo.cpp +++ b/lib/Target/ARM/Thumb2RegisterInfo.cpp @@ -52,7 +52,8 @@ void Thumb2RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB, unsigned PredReg) const { MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); - Constant *C = ConstantInt::get(Type::Int32Ty, Val); + Constant *C = ConstantInt::get( + Type::getInt32Ty(MBB.getParent()->getFunction()->getContext()), Val); unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); BuildMI(MBB, MBBI, dl, TII.get(ARM::t2LDRpci)) diff --git a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp index c72e0f0481..ff1eefb8ce 100644 --- a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp +++ b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp @@ -305,7 +305,8 @@ SDNode *AlphaDAGToDAGISel::Select(SDValue Op) { // val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true break; //(zext (LDAH (LDA))) //Else use the constant pool - ConstantInt *C = ConstantInt::get(Type::Int64Ty, uval); + ConstantInt *C = ConstantInt::get( + Type::getInt64Ty(*CurDAG->getContext()), uval); SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64); SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, dl, MVT::i64, CPI, SDValue(getGlobalBaseReg(), 0)); diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 937a93f18a..f4418040e1 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -236,7 +236,7 @@ namespace { // Must be an expression, must be used exactly once. If it is dead, we // emit it inline where it would go. - if (I.getType() == Type::VoidTy || !I.hasOneUse() || + if (I.getType() == Type::getVoidTy(I.getContext()) || !I.hasOneUse() || isa<TerminatorInst>(I) || isa<CallInst>(I) || isa<PHINode>(I) || isa<LoadInst>(I) || isa<VAArgInst>(I) || isa<InsertElementInst>(I) || isa<InsertValueInst>(I)) @@ -772,7 +772,8 @@ void CWriter::printConstantArray(ConstantArray *CPA, bool Static) { // ubytes or an array of sbytes with positive values. // const Type *ETy = CPA->getType()->getElementType(); - bool isString = (ETy == Type::Int8Ty || ETy == Type::Int8Ty); + bool isString = (ETy == Type::getInt8Ty(CPA->getContext()) || + ETy == Type::getInt8Ty(CPA->getContext())); // Make sure the last character is a null char, as automatically added by C if (isString && (CPA->getNumOperands() == 0 || @@ -858,10 +859,11 @@ void CWriter::printConstantVector(ConstantVector *CP, bool Static) { static bool isFPCSafeToPrint(const ConstantFP *CFP) { bool ignored; // Do long doubles in hex for now. - if (CFP->getType() != Type::FloatTy && CFP->getType() != Type::DoubleTy) + if (CFP->getType() != Type::getFloatTy(CFP->getContext()) && + CFP->getType() != Type::getDoubleTy(CFP->getContext())) return false; APFloat APF = APFloat(CFP->getValueAPF()); // copy - if (CFP->getType() == Type::FloatTy) + if (CFP->getType() == Type::getFloatTy(CFP->getContext())) APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &ignored); #if HAVE_PRINTF_A && ENABLE_CBE_PRINTF_A char Buffer[100]; @@ -973,12 +975,12 @@ void CWriter::printConstant(Constant *CPV, bool Static) { Out << "("; printCast(CE->getOpcode(), CE->getOperand(0)->getType(), CE->getType()); if (CE->getOpcode() == Instruction::SExt && - CE->getOperand(0)->getType() == Type::Int1Ty) { + CE->getOperand(0)->getType() == Type::getInt1Ty(CPV->getContext())) { // Make sure we really sext from bool here by subtracting from 0 Out << "0-"; } printConstant(CE->getOperand(0), Static); - if (CE->getType() == Type::Int1Ty && + if (CE->getType() == Type::getInt1Ty(CPV->getContext()) && (CE->getOpcode() == Instruction::Trunc || CE->getOpcode() == Instruction::FPToUI || CE->getOpcode() == Instruction::FPToSI || @@ -1127,9 +1129,9 @@ void CWriter::printConstant(Constant *CPV, bool Static) { if (ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) { const Type* Ty = CI->getType(); - if (Ty == Type::Int1Ty) + if (Ty == Type::getInt1Ty(CPV->getContext())) Out << (CI->getZExtValue() ? '1' : '0'); - else if (Ty == Type::Int32Ty) + else if (Ty == Type::getInt32Ty(CPV->getContext())) Out << CI->getZExtValue() << 'u'; else if (Ty->getPrimitiveSizeInBits() > 32) Out << CI->getZExtValue() << "ull"; @@ -1156,15 +1158,17 @@ void CWriter::printConstant(Constant *CPV, bool Static) { if (I != FPConstantMap.end()) { // Because of FP precision problems we must load from a stack allocated // value that holds the value in hex. - Out << "(*(" << (FPC->getType() == Type::FloatTy ? "float" : - FPC->getType() == Type::DoubleTy ? "double" : + Out << "(*(" << (FPC->getType() == Type::getFloatTy(CPV->getContext()) ? + "float" : + FPC->getType() == Type::getDoubleTy(CPV->getContext()) ? + "double" : "long double") << "*)&FPConstant" << I->second << ')'; } else { double V; - if (FPC->getType() == Type::FloatTy) + if (FPC->getType() == Type::getFloatTy(CPV->getContext())) V = FPC->getValueAPF().convertToFloat(); - else if (FPC->getType() == Type::DoubleTy) + else if (FPC->getType() == Type::getDoubleTy(CPV->getContext())) V = FPC->getValueAPF().convertToDouble(); else { // Long double. Convert the number to double, discarding precision. @@ -1194,7 +1198,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) { std::string Num(&Buffer[0], &Buffer[6]); unsigned long Val = strtoul(Num.c_str(), 0, 16); - if (FPC->getType() == Type::FloatTy) + if (FPC->getType() == Type::getFloatTy(FPC->getContext())) Out << "LLVM_NAN" << (Val == QuietNaN ? "" : "S") << "F(\"" << Buffer << "\") /*nan*/ "; else @@ -1203,7 +1207,8 @@ void CWriter::printConstant(Constant *CPV, bool Static) { } else if (IsInf(V)) { // The value is Inf if (V < 0) Out << '-'; - Out << "LLVM_INF" << (FPC->getType() == Type::FloatTy ? "F" : "") + Out << "LLVM_INF" << + (FPC->getType() == Type::getFloatTy(FPC->getContext()) ? "F" : "") << " /*inf*/ "; } else { std::string Num; @@ -1366,7 +1371,7 @@ bool CWriter::printConstExprCast(const ConstantExpr* CE, bool Static) { } if (NeedsExplicitCast) { Out << "(("; - if (Ty->isInteger() && Ty != Type::Int1Ty) + if (Ty->isInteger() && Ty != Type::getInt1Ty(Ty->getContext())) printSimpleType(Out, Ty, TypeIsSigned); else printType(Out, Ty); // not integer, sign doesn't matter @@ -1464,8 +1469,11 @@ void CWriter::writeInstComputationInline(Instruction &I) { // We can't currently support integer types other than 1, 8, 16, 32, 64. // Validate this. const Type *Ty = I.getType(); - if (Ty->isInteger() && (Ty!=Type::Int1Ty && Ty!=Type::Int8Ty && - Ty!=Type::Int16Ty && Ty!=Type::Int32Ty && Ty!=Type::Int64Ty)) { + if (Ty->isInteger() && (Ty!=Type::getInt1Ty(I.getContext()) && + Ty!=Type::getInt8Ty(I.getContext()) && + Ty!=Type::getInt16Ty(I.getContext()) && + Ty!=Type::getInt32Ty(I.getContext()) && + Ty!=Type::getInt64Ty(I.getContext()))) { llvm_report_error("The C backend does not currently support integer " "types of widths other than 1, 8, 16, 32, 64.\n" "This is being tracked as PR 4158."); @@ -1475,7 +1483,8 @@ void CWriter::writeInstComputationInline(Instruction &I) { // a 1 bit value. This is important because we want "add i1 x, y" to return // "0" when x and y are true, not "2" for example. bool NeedBoolTrunc = false; - if (I.getType() == Type::Int1Ty && !isa<ICmpInst>(I) && !isa<FCmpInst>(I)) + if (I.getType() == Type::getInt1Ty(I.getContext()) && + !isa<ICmpInst>(I) && !isa<FCmpInst>(I)) NeedBoolTrunc = true; if (NeedBoolTrunc) @@ -1624,7 +1633,7 @@ void CWriter::writeOperandWithCast(Value* Operand, const ICmpInst &Cmp) { // If the operand was a pointer, convert to a large integer type. const Type* OpTy = Operand->getType(); if (isa<PointerType>(OpTy)) - OpTy = TD->getIntPtrType(); + OpTy = TD->getIntPtrType(Operand->getContext()); Out << "(("; printSimpleType(Out, OpTy, castIsSigned); @@ -2143,20 +2152,20 @@ void CWriter::printFloatingPointConstants(const Constant *C) { FPConstantMap[FPC] = FPCounter; // Number the FP constants - if (FPC->getType() == Type::DoubleTy) { + if (FPC->getType() == Type::getDoubleTy(FPC->getContext())) { double Val = FPC->getValueAPF().convertToDouble(); uint64_t i = FPC->getValueAPF().bitcastToAPInt().getZExtValue(); Out << "static const ConstantDoubleTy FPConstant" << FPCounter++ << " = 0x" << utohexstr(i) << "ULL; /* " << Val << " */\n"; - } else if (FPC->getType() == Type::FloatTy) { + } else if (FPC->getType() == Type::getFloatTy(FPC->getContext())) { float Val = FPC->getValueAPF().convertToFloat(); uint32_t i = (uint32_t)FPC->getValueAPF().bitcastToAPInt(). getZExtValue(); Out << "static const ConstantFloatTy FPConstant" << FPCounter++ << " = 0x" << utohexstr(i) << "U; /* " << Val << " */\n"; - } else if (FPC->getType() == Type::X86_FP80Ty) { + } else if (FPC->getType() == Type::getX86_FP80Ty(FPC->getContext())) { // api needed to prevent premature destruction APInt api = FPC->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); @@ -2164,7 +2173,7 @@ void CWriter::printFloatingPointConstants(const Constant *C) { << " = { 0x" << utohexstr(p[0]) << "ULL, 0x" << utohexstr((uint16_t)p[1]) << ",{0,0,0}" << "}; /* Long double constant */\n"; - } else if (FPC->getType() == Type::PPC_FP128Ty) { + } else if (FPC->getType() == Type::getPPC_FP128Ty(FPC->getContext())) { APInt api = FPC->getValueAPF().bitcastToAPInt(); const uint64_t *p = api.getRawData(); Out << "static const ConstantFP128Ty FPConstant" << FPCounter++ @@ -2409,7 +2418,8 @@ void CWriter::printFunction(Function &F) { printType(Out, AI->getAllocatedType(), false, GetValueName(AI)); Out << "; /* Address-exposed local */\n"; PrintedVar = true; - } else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) { + } else if (I->getType() != Type::getVoidTy(F.getContext()) && + !isInlinableInst(*I)) { Out << " "; printType(Out, I->getType(), false, GetValueName(&*I)); Out << ";\n"; @@ -2486,7 +2496,8 @@ void CWriter::printBasicBlock(BasicBlock *BB) { for (BasicBlock::iterator II = BB->begin(), E = --BB->end(); II != E; ++II) { if (!isInlinableInst(*II) && !isDirectAlloca(II)) { - if (II->getType() != Type::VoidTy && !isInlineAsm(*II)) + if (II->getType() != Type::getVoidTy(BB->getContext()) && + !isInlineAsm(*II)) outputLValue(II); else Out << " "; @@ -2661,8 +2672,9 @@ void CWriter::visitBinaryOperator(Instruction &I) { // We must cast the results of binary operations which might be promoted. bool needsCast = false; - if ((I.getType() == Type::Int8Ty) || (I.getType() == Type::Int16Ty) - || (I.getType() == Type::FloatTy)) { + if ((I.getType() == Type::getInt8Ty(I.getContext())) || + (I.getType() == Type::getInt16Ty(I.getContext())) + || (I.getType() == Type::getFloatTy(I.getContext()))) { needsCast = true; Out << "(("; printType(Out, I.getType(), false); @@ -2681,9 +2693,9 @@ void CWriter::visitBinaryOperator(Instruction &I) { Out << ")"; } else if (I.getOpcode() == Instruction::FRem) { // Output a call to fmod/fmodf instead of emitting a%b - if (I.getType() == Type::FloatTy) + if (I.getType() == Type::getFloatTy(I.getContext())) Out << "fmodf("; - else if (I.getType() == Type::DoubleTy) + else if (I.getType() == Type::getDoubleTy(I.getContext())) Out << "fmod("; else // all 3 flavors of long double Out << "fmodl("; @@ -2850,12 +2862,13 @@ void CWriter::visitCastInst(CastInst &I) { printCast(I.getOpcode(), SrcTy, DstTy); // Make a sext from i1 work by subtracting the i1 from 0 (an int). - if (SrcTy == Type::Int1Ty && I.getOpcode() == Instruction::SExt) + if (SrcTy == Type::getInt1Ty(I.getContext()) && + I.getOpcode() == Instruction::SExt) Out << "0-"; writeOperand(I.getOperand(0)); - if (DstTy == Type::Int1Ty && + if (DstTy == Type::getInt1Ty(I.getContext()) && (I.getOpcode() == Instruction::Trunc || I.getOpcode() == Instruction::FPToUI || I.getOpcode() == Instruction::FPToSI || @@ -3280,7 +3293,7 @@ void CWriter::visitInlineAsm(CallInst &CI) { std::vector<InlineAsm::ConstraintInfo> Constraints = as->ParseConstraints(); std::vector<std::pair<Value*, int> > ResultVals; - if (CI.getType() == Type::VoidTy) + if (CI.getType() == Type::getVoidTy(CI.getContext())) ; else if (const StructType *ST = dyn_cast<StructType>(CI.getType())) { for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index c467ead8bb..98baa95e86 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -221,7 +221,7 @@ namespace { void CppWriter::printCFP(const ConstantFP *CFP) { bool ignored; APFloat APF = APFloat(CFP->getValueAPF()); // copy - if (CFP->getType() == Type::FloatTy) + if (CFP->getType() == Type::getFloatTy(CFP->getContext())) APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &ignored); Out << "ConstantFP::get("; Out << "APFloat("; @@ -232,7 +232,7 @@ namespace { !strncmp(Buffer, "-0x", 3) || !strncmp(Buffer, "+0x", 3)) && APF.bitwiseIsEqual(APFloat(atof(Buffer)))) { - if (CFP->getType() == Type::DoubleTy) + if (CFP->getType() == Type::getDoubleTy(CFP->getContext())) Out << "BitsToDouble(" << Buffer << ")"; else Out << "BitsToFloat((float)" << Buffer << ")"; @@ -250,11 +250,11 @@ namespace { ((StrVal[0] == '-' || StrVal[0] == '+') && (StrVal[1] >= '0' && StrVal[1] <= '9'))) && (CFP->isExactlyValue(atof(StrVal.c_str())))) { - if (CFP->getType() == Type::DoubleTy) + if (CFP->getType() == Type::getDoubleTy(CFP->getContext())) Out << StrVal; else Out << StrVal << "f"; - } else if (CFP->getType() == Type::DoubleTy) + } else if (CFP->getType() == Type::getDoubleTy(CFP->getContext())) Out << "BitsToDouble(0x" << utohexstr(CFP->getValueAPF().bitcastToAPInt().getZExtValue()) << "ULL) /* " << StrVal << " */"; @@ -764,7 +764,9 @@ namespace { printCFP(CFP); Out << ";"; } else if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) { - if (CA->isString() && CA->getType()->getElementType() == Type::Int8Ty) { + if (CA->isString() && + CA->getType()->getElementType() == + Type::getInt8Ty(CA->getContext())) { Out << "Constant* " << constName << " = ConstantArray::get(\""; std::string tmp = CA->getAsString(); bool nullTerminate = false; diff --git a/lib/Target/MSIL/MSILWriter.cpp b/lib/Target/MSIL/MSILWriter.cpp index 226d146a0e..93e59f71d4 100644 --- a/lib/Target/MSIL/MSILWriter.cpp +++ b/lib/Target/MSIL/MSILWriter.cpp @@ -820,7 +820,8 @@ void MSILWriter::printIntrinsicCall(const IntrinsicInst* Inst) { // Save as pointer type "void*" printValueLoad(Inst->getOperand(1)); printSimpleInstruction("ldloca",Name.c_str()); - printIndirectSave(PointerType::getUnqual(IntegerType::get(8))); + printIndirectSave(PointerType::getUnqual( + IntegerType::get(Inst->getContext(), 8))); break; case Intrinsic::vaend: // Close argument list handle. @@ -1041,7 +1042,8 @@ void MSILWriter::printVAArgInstruction(const VAArgInst* Inst) { "instance typedref [mscorlib]System.ArgIterator::GetNextArg()"); printSimpleInstruction("refanyval","void*"); std::string Name = - "ldind."+getTypePostfix(PointerType::getUnqual(IntegerType::get(8)),false); + "ldind."+getTypePostfix(PointerType::getUnqual( + IntegerType::get(Inst->getContext(), 8)),false); printSimpleInstruction(Name.c_str()); } @@ -1237,7 +1239,7 @@ void MSILWriter::printBasicBlock(const BasicBlock* BB) { // Print instruction printInstruction(Inst); // Save result - if (Inst->getType()!=Type::VoidTy) { + if (Inst->getType()!=Type::getVoidTy(BB->getContext())) { // Do not save value after invoke, it done in "try" block if (Inst->getOpcode()==Instruction::Invoke) continue; printValueSave(Inst); @@ -1266,7 +1268,7 @@ void MSILWriter::printLocalVariables(const Function& F) { Ty = PointerType::getUnqual(AI->getAllocatedType()); Name = getValueName(AI); Out << "\t.locals (" << getTypeName(Ty) << Name << ")\n"; - } else if (I->getType()!=Type::VoidTy) { + } else if (I->getType()!=Type::getVoidTy(F.getContext())) { // Operation result. Ty = I->getType(); Name = getValueName(&*I); diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp index 11c4093634..569026fbb7 100644 --- a/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/lib/Target/PowerPC/PPCISelLowering.cpp @@ -1269,7 +1269,8 @@ SDValue PPCTargetLowering::LowerTRAMPOLINE(SDValue Op, SelectionDAG &DAG) { EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); bool isPPC64 = (PtrVT == MVT::i64); const Type *IntPtrTy = - DAG.getTargetLoweringInfo().getTargetData()->getIntPtrType(); + DAG.getTargetLoweringInfo().getTargetData()->getIntPtrType( + *DAG.getContext()); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; diff --git a/lib/Target/Target.cpp b/lib/Target/Target.cpp index ed544b73ea..cc6be9fa7a 100644 --- a/lib/Target/Target.cpp +++ b/lib/Target/Target.cpp @@ -41,7 +41,7 @@ unsigned LLVMPointerSize(LLVMTargetDataRef TD) { } LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef TD) { - return wrap(unwrap(TD)->getIntPtrType()); + return wrap(unwrap(TD)->getIntPtrType(getGlobalContext())); } unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef TD, LLVMTypeRef Ty) { diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 3f1979bc29..838c675d1b 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -541,8 +541,8 @@ unsigned char TargetData::getPreferredTypeAlignmentShift(const Type *Ty) const { /// getIntPtrType - Return an unsigned integer type that is the same size or /// greater to the host pointer size. -const IntegerType *TargetData::getIntPtrType() const { - return IntegerType::get(getPointerSizeInBits()); +const IntegerType *TargetData::getIntPtrType(LLVMContext &C) const { + return IntegerType::get(C, getPointerSizeInBits()); } @@ -556,7 +556,8 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy, Value* const* Indices, TI = gep_type_begin(ptrTy, Indices, Indices+NumIndices); for (unsigned CurIDX = 0; CurIDX != NumIndices; ++CurIDX, ++TI) { if (const StructType *STy = dyn_cast<StructType>(*TI)) { - assert(Indices[CurIDX]->getType() == Type::Int32Ty && + assert(Indices[CurIDX]->getType() == + Type::getInt32Ty(ptrTy->getContext()) && "Illegal struct idx"); unsigned FieldNo = cast<ConstantInt>(Indices[CurIDX])->getZExtValue(); diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index b98a9738c6..5e9a39f056 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -272,7 +272,7 @@ bool X86FastISel::X86FastEmitStore(EVT VT, Value *Val, const X86AddressMode &AM) { // Handle 'null' like i32/i64 0. if (isa<ConstantPointerNull>(Val)) - Val = Constant::getNullValue(TD.getIntPtrType()); + Val = Constant::getNullValue(TD.getIntPtrType(Val->getContext())); // If this is a store of a simple constant, fold the constant into the store. if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) { @@ -672,7 +672,7 @@ bool X86FastISel::X86FastEmitCompare(Value *Op0, Value *Op1, EVT VT) { // Handle 'null' like i32/i64 0. if (isa<ConstantPointerNull>(Op1)) - Op1 = Constant::getNullValue(TD.getIntPtrType()); + Op1 = Constant::getNullValue(TD.getIntPtrType(Op0->getContext())); // We have two options: compare with register or immediate. If the RHS of // the compare is an immediate that we can fold into this compare, use @@ -773,8 +773,8 @@ bool X86FastISel::X86SelectCmp(Instruction *I) { bool X86FastISel::X86SelectZExt(Instruction *I) { // Handle zero-extension from i1 to i8, which is common. - if (I->getType() == Type::Int8Ty && - I->getOperand(0)->getType() == Type::Int1Ty) { + if (I->getType() == Type::getInt8Ty(I->getContext()) && + I->getOperand(0)->getType() == Type::getInt1Ty(I->getContext())) { unsigned ResultReg = getRegForValue(I->getOperand(0)); if (ResultReg == 0) return false; // Set the high bits to zero. @@ -935,7 +935,7 @@ bool X86FastISel::X86SelectBranch(Instruction *I) { bool X86FastISel::X86SelectShift(Instruction *I) { unsigned CReg = 0, OpReg = 0, OpImm = 0; const TargetRegisterClass *RC = NULL; - if (I->getType() == Type::Int8Ty) { + if (I->getType() == Type::getInt8Ty(I->getContext())) { CReg = X86::CL; RC = &X86::GR8RegClass; switch (I->getOpcode()) { @@ -944,7 +944,7 @@ bool X86FastISel::X86SelectShift(Instruction *I) { case Instruction::Shl: OpReg = X86::SHL8rCL; OpImm = X86::SHL8ri; break; default: return false; } - } else if (I->getType() == Type::Int16Ty) { + } else if (I->getType() == Type::getInt16Ty(I->getContext())) { CReg = X86::CX; RC = &X86::GR16RegClass; switch (I->getOpcode()) { @@ -953,7 +953,7 @@ bool X86FastISel::X86SelectShift(Instruction *I) { case Instruction::Shl: OpReg = X86::SHL16rCL; OpImm = X86::SHL16ri; break; default: return false; } - } else if (I->getType() == Type::Int32Ty) { + } else if (I->getType() == Type::getInt32Ty(I->getContext())) { CReg = X86::ECX; RC = &X86::GR32RegClass; switch (I->getOpcode()) { @@ -962,7 +962,7 @@ bool X86FastISel::X86SelectShift(Instruction *I) { case Instruction::Shl: OpReg = X86::SHL32rCL; OpImm = X86::SHL32ri; break; default: return false; } - } else if (I->getType() == Type::Int64Ty) { + } else if (I->getType() == Type::getInt64Ty(I->getContext())) { CReg = X86::RCX; RC = &X86::GR64RegClass; switch (I->getOpcode()) { @@ -1044,9 +1044,10 @@ bool X86FastISel::X86SelectSelect(Instruction *I) { bool X86FastISel::X86SelectFPExt(Instruction *I) { // fpext from float to double. - if (Subtarget->hasSSE2() && I->getType() == Type::DoubleTy) { + if (Subtarget->hasSSE2() && + I->getType() == Type::getDoubleTy(I->getContext())) { Value *V = I->getOperand(0); - if (V->getType() == Type::FloatTy) { + if (V->getType() == Type::getFloatTy(I->getContext())) { unsigned OpReg = getRegForValue(V); if (OpReg == 0) return false; unsigned ResultReg = createResultReg(X86::FR64RegisterClass); @@ -1061,9 +1062,9 @@ bool X86FastISel::X86SelectFPExt(Instruction *I) { bool X86FastISel::X86SelectFPTrunc(Instruction *I) { if (Subtarget->hasSSE2()) { - if (I->getType() == Type::FloatTy) { + if (I->getType() == Type::getFloatTy(I->getContext())) { Value *V = I->getOperand(0); - if (V->getType() == Type::DoubleTy) { + if (V->getType() == Type::getDoubleTy(I->getContext())) { unsigned OpReg = getRegForValue(V); if (OpReg == 0) return false; unsigned ResultReg = createResultReg(X86::FR32RegisterClass); @@ -1230,7 +1231,7 @@ bool X86FastISel::X86SelectCall(Instruction *I) { // Handle *simple* calls for now. const Type *RetTy = CS.getType(); EVT RetVT; - if (RetTy == Type::VoidTy) + if (RetTy == Type::getVoidTy(I->getContext())) RetVT = MVT::isVoid; else if (!isTypeLegal(RetTy, RetVT, true)) return false; diff --git a/lib/Target/X86/X86FloatingPointRegKill.cpp b/lib/Target/X86/X86FloatingPointRegKill.cpp index 292f8f432d..3e0385c79c 100644 --- a/lib/Target/X86/X86FloatingPointRegKill.cpp +++ b/lib/Target/X86/X86FloatingPointRegKill.cpp @@ -118,9 +118,10 @@ bool FPRegKiller::runOnMachineFunction(MachineFunction &MF) { !ContainsFPCode && SI != E; ++SI) { for (BasicBlock::const_iterator II = SI->begin(); (PN = dyn_cast<PHINode>(II)); ++II) { - if (PN->getType()==Type::X86_FP80Ty || + if (PN->getType()==Type::getX86_FP80Ty(LLVMBB->getContext()) || (!Subtarget.hasSSE1() && PN->getType()->isFloatingPoint()) || - (!Subtarget.hasSSE2() && PN->getType()==Type::DoubleTy)) { + (!Subtarget.hasSSE2() && + PN->getType()==Type::getDoubleTy(LLVMBB->getContext()))) { ContainsFPCode = true; break; } diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 7507eb2a1b..ca6ff929a7 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -5831,7 +5831,7 @@ X86TargetLowering::EmitTargetCodeForMemset(SelectionDAG &DAG, DebugLoc dl, if (const char *bzeroEntry = V && V->isNullValue() ? Subtarget->getBZeroEntry() : 0) { EVT IntPtr = getPointerTy(); - const Type *IntPtrTy = TD->getIntPtrType(); + const Type *IntPtrTy = TD->getIntPtrType(*DAG.getContext()); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; Entry.Node = Dst; @@ -5840,7 +5840,8 @@ X86TargetLowering::EmitTargetCodeForMemset(SelectionDAG &DAG, DebugLoc dl, Entry.Node = Size; Args.push_back(Entry); std::pair<SDValue,SDValue> CallResult = - LowerCallTo(Chain, Type::VoidTy, false, false, false, false, + LowerCallTo(Chain, Type::getVoidTy(*DAG.getContext()), + false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/false, DAG.getExternalSymbol(bzeroEntry, IntPtr), Args, DAG, dl); return CallResult.second; @@ -7159,7 +7160,8 @@ bool X86TargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { bool X86TargetLowering::isZExtFree(const Type *Ty1, const Type *Ty2) const { // x86-64 implicitly zero-extends 32-bit results in 64-bit registers. - return Ty1 == Type::Int32Ty && Ty2 == Type::Int64Ty && Subtarget->is64Bit(); + return Ty1 == Type::getInt32Ty(Ty1->getContext()) && + Ty2 == Type::getInt64Ty(Ty1->getContext()) && Subtarget->is64Bit(); } bool X86TargetLowering::isZExtFree(EVT VT1, EVT VT2) const { @@ -8768,7 +8770,7 @@ bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const { return LowerToBSwap(CI); } // rorw $$8, ${0:w} --> llvm.bswap.i16 - if (CI->getType() == Type::Int16Ty && + if (CI->getType() == Type::getInt16Ty(CI->getContext()) && AsmPieces.size() == 3 && AsmPieces[0] == "rorw" && AsmPieces[1] == "$$8," && @@ -8778,7 +8780,8 @@ bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const { } break; case 3: - if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 && + if (CI->getType() == Type::getInt64Ty(CI->getContext()) && + Constraints.size() >= 2 && Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" && Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") { // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64 @@ -8896,7 +8899,8 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op, // 32-bit signed value if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { const ConstantInt *CI = C->getConstantIntValue(); - if (CI->isValueValidForType(Type::Int32Ty, C->getSExtValue())) { + if (CI->isValueValidForType(Type::getInt32Ty(*DAG.getContext()), + C->getSExtValue())) { // Widen to 64 bits here to get it sign extended. Result = DAG.getTargetConstant(C->getSExtValue(), MVT::i64); break; @@ -8910,7 +8914,8 @@ void X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op, // 32-bit unsigned value if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) { const ConstantInt *CI = C->getConstantIntValue(); - if (CI->isValueValidForType(Type::Int32Ty, C->getZExtValue())) { + if (CI->isValueValidForType(Type::getInt32Ty(*DAG.getContext()), + C->getZExtValue())) { Result = DAG.getTargetConstant(C->getZExtValue(), Op.getValueType()); break; } diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 297c4dd175..6e8561d8e4 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -2299,7 +2299,8 @@ MachineInstr* X86InstrInfo::foldMemoryOperandImpl(MachineFunction &MF, // Create a v4i32 constant-pool entry. MachineConstantPool &MCP = *MF.getConstantPool(); - const VectorType *Ty = VectorType::get(Type::Int32Ty, 4); + const VectorType *Ty = + VectorType::get(Type::getInt32Ty(MF.getFunction()->getContext()), 4); Constant *C = LoadMI->getOpcode() == X86::V_SET0 ? Constant::getNullValue(Ty) : Constant::getAllOnesValue(Ty); diff --git a/lib/Target/XCore/XCoreISelDAGToDAG.cpp b/lib/Target/XCore/XCoreISelDAGToDAG.cpp index 5d6702b4da..1a5f10291f 100644 --- a/lib/Target/XCore/XCoreISelDAGToDAG.cpp +++ b/lib/Target/XCore/XCoreISelDAGToDAG.cpp @@ -174,7 +174,8 @@ SDNode *XCoreDAGToDAGISel::Select(SDValue Op) { else if (! Predicate_immU16(N)) { unsigned Val = cast<ConstantSDNode>(N)->getZExtValue(); SDValue CPIdx = - CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val), + CurDAG->getTargetConstantPool(ConstantInt::get( + Type::getInt32Ty(*CurDAG->getContext()), Val), TLI.getPointerTy()); return CurDAG->getTargetNode(XCore::LDWCP_lru6, dl, MVT::i32, MVT::Other, CPIdx, diff --git a/lib/Target/XCore/XCoreISelLowering.cpp b/lib/Target/XCore/XCoreISelLowering.cpp index e9ca3f5983..0174778a1d 100644 --- a/lib/Target/XCore/XCoreISelLowering.cpp +++ b/lib/Target/XCore/XCoreISelLowering.cpp @@ -438,7 +438,7 @@ LowerLOAD(SDValue Op, SelectionDAG &DAG) } // Lower to a call to __misaligned_load(BasePtr). - const Type *IntPtrTy = getTargetData()->getIntPtrType(); + const Type *IntPtrTy = getTargetData()->getIntPtrType(*DAG.getContext()); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; @@ -496,7 +496,7 @@ LowerSTORE(SDValue Op, SelectionDAG &DAG) } // Lower to a call to __misaligned_store(BasePtr, Value). - const Type *IntPtrTy = getTargetData()->getIntPtrType(); + const Type *IntPtrTy = getTargetData()->getIntPtrType(*DAG.getContext()); TargetLowering::ArgListTy Args; TargetLowering::ArgListEntry Entry; @@ -508,7 +508,7 @@ LowerSTORE(SDValue Op, SelectionDAG &DAG) Args.push_back(Entry); std::pair<SDValue, SDValue> CallResult = - LowerCallTo(Chain, Type::VoidTy, false, false, + LowerCallTo(Chain, Type::getVoidTy(*DAG.getContext()), false, false, false, false, 0, CallingConv::C, false, /*isReturnValueUsed=*/true, DAG.getExternalSymbol("__misaligned_store", getPointerTy()), diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index f3e0b18573..e40372b04a 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -582,7 +582,7 @@ Function *ArgPromotion::DoPromotion(Function *F, bool ExtraArgHack = false; if (Params.empty() && FTy->isVarArg()) { ExtraArgHack = true; - Params.push_back(Type::Int32Ty); + Params.push_back(Type::getInt32Ty(F->getContext())); } // Construct the new function type using the new arguments. @@ -637,9 +637,10 @@ Function *ArgPromotion::DoPromotion(Function *F, // Emit a GEP and load for each element of the struct. const Type *AgTy = cast<PointerType>(I->getType())->getElementType(); const StructType *STy = cast<StructType>(AgTy); - Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 }; + Value *Idxs[2] = { + ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), 0 }; for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { - Idxs[1] = ConstantInt::get(Type::Int32Ty, i); + Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i); Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2, (*AI)->getName()+"."+utostr(i), Call); @@ -663,7 +664,9 @@ Function *ArgPromotion::DoPromotion(Function *F, IE = SI->end(); II != IE; ++II) { // Use i32 to index structs, and i64 for others (pointers/arrays). // This satisfies GEP constraints. - const Type *IdxTy = (isa<StructType>(ElTy) ? Type::Int32Ty : Type::Int64Ty); + const Type *IdxTy = (isa<StructType>(ElTy) ? + Type::getInt32Ty(F->getContext()) : + Type::getInt64Ty(F->getContext())); Ops.push_back(ConstantInt::get(IdxTy, *II)); // Keep track of the type we're currently indexing ElTy = cast<CompositeType>(ElTy)->getTypeAtIndex(*II); @@ -680,7 +683,7 @@ Function *ArgPromotion::DoPromotion(Function *F, } if (ExtraArgHack) - Args.push_back(Constant::getNullValue(Type::Int32Ty)); + Args.push_back(Constant::getNullValue(Type::getInt32Ty(F->getContext()))); // Push any varargs arguments on the list for (; AI != CS.arg_end(); ++AI, ++ArgIndex) { @@ -757,10 +760,11 @@ Function *ArgPromotion::DoPromotion(Function *F, const Type *AgTy = cast<PointerType>(I->getType())->getElementType(); Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt); const StructType *STy = cast<StructType>(AgTy); - Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 }; + Value *Idxs[2] = { + ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), 0 }; for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { - Idxs[1] = ConstantInt::get(Type::Int32Ty, i); + Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i); Value *Idx = GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2, TheAlloca->getName()+"."+Twine(i), @@ -844,7 +848,8 @@ Function *ArgPromotion::DoPromotion(Function *F, // Notify the alias analysis implementation that we inserted a new argument. if (ExtraArgHack) - AA.copyValue(Constant::getNullValue(Type::Int32Ty), NF->arg_begin()); + AA.copyValue(Constant::getNullValue(Type::getInt32Ty(F->getContext())), + NF->arg_begin()); // Tell the alias analysis that the old function is about to disappear. diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 0612119618..ad99eb4bf2 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -281,7 +281,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { /// for void functions and 1 for functions not returning a struct. It returns /// the number of struct elements for functions returning a struct. static unsigned NumRetVals(const Function *F) { - if (F->getReturnType() == Type::VoidTy) + if (F->getReturnType() == Type::getVoidTy(F->getContext())) return 0; else if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) return STy->getNumElements(); @@ -604,8 +604,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // -1 means unused, other numbers are the new index SmallVector<int, 5> NewRetIdxs(RetCount, -1); std::vector<const Type*> RetTypes; - if (RetTy == Type::VoidTy) { - NRetTy = Type::VoidTy; + if (RetTy == Type::getVoidTy(F->getContext())) { + NRetTy = Type::getVoidTy(F->getContext()); } else { const StructType *STy = dyn_cast<StructType>(RetTy); if (STy) @@ -645,7 +645,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { NRetTy = RetTypes.front(); else if (RetTypes.size() == 0) // No return types? Make it void, but only if we didn't use to return {}. - NRetTy = Type::VoidTy; + NRetTy = Type::getVoidTy(F->getContext()); } assert(NRetTy && "No new return type found?"); @@ -654,7 +654,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // values. Otherwise, ensure that we don't have any conflicting attributes // here. Currently, this should not be possible, but special handling might be // required when new return value attributes are added. - if (NRetTy == Type::VoidTy) + if (NRetTy == Type::getVoidTy(F->getContext())) RAttrs &= ~Attribute::typeIncompatible(NRetTy); else assert((RAttrs & Attribute::typeIncompatible(NRetTy)) == 0 @@ -702,7 +702,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { bool ExtraArgHack = false; if (Params.empty() && FTy->isVarArg() && FTy->getNumParams() != 0) { ExtraArgHack = true; - Params.push_back(Type::Int32Ty); + Params.push_back(Type::getInt32Ty(F->getContext())); } // Create the new function type based on the recomputed parameters. @@ -756,7 +756,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { } if (ExtraArgHack) - Args.push_back(UndefValue::get(Type::Int32Ty)); + Args.push_back(UndefValue::get(Type::getInt32Ty(F->getContext()))); // Push any varargs arguments on the list. Don't forget their attributes. for (CallSite::arg_iterator E = CS.arg_end(); I != E; ++I, ++i) { @@ -792,7 +792,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // Return type not changed? Just replace users then. Call->replaceAllUsesWith(New); New->takeName(Call); - } else if (New->getType() == Type::VoidTy) { + } else if (New->getType() == Type::getVoidTy(F->getContext())) { // Our return value has uses, but they will get removed later on. // Replace by null for now. Call->replaceAllUsesWith(Constant::getNullValue(Call->getType())); @@ -868,7 +868,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { Value *RetVal; - if (NFTy->getReturnType() == Type::VoidTy) { + if (NFTy->getReturnType() == Type::getVoidTy(F->getContext())) { RetVal = 0; } else { assert (isa<StructType>(RetTy)); @@ -899,7 +899,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { } // Replace the return instruction with one returning the new return // value (possibly 0 if we became void). - ReturnInst::Create(RetVal, RI); + ReturnInst::Create(F->getContext(), RetVal, RI); BB->getInstList().erase(RI); } diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp index f80a087c7c..3dd3a80a15 100644 --- a/lib/Transforms/IPO/ExtractGV.cpp +++ b/lib/Transforms/IPO/ExtractGV.cpp @@ -101,7 +101,8 @@ namespace { // by putting them in the used array { std::vector<Constant *> AUGs; - const Type *SBP= PointerType::getUnqual(Type::Int8Ty); + const Type *SBP= + PointerType::getUnqual(Type::getInt8Ty(M.getContext())); for (std::vector<GlobalValue*>::iterator GI = Named.begin(), GE = Named.end(); GI != GE; ++GI) { (*GI)->setLinkage(GlobalValue::ExternalLinkage); diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 82af99a7f9..ae3acad96f 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -488,7 +488,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, const StructLayout &Layout = *TD.getStructLayout(STy); for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { Constant *In = getAggregateConstantElement(Init, - ConstantInt::get(Type::Int32Ty, i), + ConstantInt::get(Type::getInt32Ty(Context), i), Context); assert(In && "Couldn't get element of initializer?"); GlobalVariable *NGV = new GlobalVariable(Context, @@ -523,7 +523,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, unsigned EltAlign = TD.getABITypeAlignment(STy->getElementType()); for (unsigned i = 0, e = NumElements; i != e; ++i) { Constant *In = getAggregateConstantElement(Init, - ConstantInt::get(Type::Int32Ty, i), + ConstantInt::get(Type::getInt32Ty(Context), i), Context); assert(In && "Couldn't get element of initializer?"); @@ -550,7 +550,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, DOUT << "PERFORMING GLOBAL SRA ON: " << *GV; - Constant *NullInt = Constant::getNullValue(Type::Int32Ty); + Constant *NullInt = Constant::getNullValue(Type::getInt32Ty(Context)); // Loop over all of the uses of the global, replacing the constantexpr geps, // with smaller constantexpr geps or direct references. @@ -828,10 +828,10 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, Type *NewTy = ArrayType::get(MI->getAllocatedType(), NElements->getZExtValue()); MallocInst *NewMI = - new MallocInst(NewTy, Constant::getNullValue(Type::Int32Ty), + new MallocInst(NewTy, Constant::getNullValue(Type::getInt32Ty(Context)), MI->getAlignment(), MI->getName(), MI); Value* Indices[2]; - Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty); + Indices[0] = Indices[1] = Constant::getNullValue(Type::getInt32Ty(Context)); Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2, NewMI->getName()+".el0", MI); MI->replaceAllUsesWith(NewGEP); @@ -863,7 +863,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, // If there is a comparison against null, we will insert a global bool to // keep track of whether the global was initialized yet or not. GlobalVariable *InitBool = - new GlobalVariable(Context, Type::Int1Ty, false, + new GlobalVariable(Context, Type::getInt1Ty(Context), false, GlobalValue::InternalLinkage, ConstantInt::getFalse(Context), GV->getName()+".init", GV->isThreadLocal()); @@ -1326,7 +1326,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI, // Create the block to check the first condition. Put all these blocks at the // end of the function as they are unlikely to be executed. - BasicBlock *NullPtrBlock = BasicBlock::Create("malloc_ret_null", + BasicBlock *NullPtrBlock = BasicBlock::Create(Context, "malloc_ret_null", OrigBB->getParent()); // Remove the uncond branch from OrigBB to ContBB, turning it into a cond @@ -1341,8 +1341,10 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI, Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal, Constant::getNullValue(GVVal->getType()), "tmp"); - BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent()); - BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent()); + BasicBlock *FreeBlock = BasicBlock::Create(Context, "free_it", + OrigBB->getParent()); + BasicBlock *NextBlock = BasicBlock::Create(Context, "next", + OrigBB->getParent()); BranchInst::Create(FreeBlock, NextBlock, Cmp, NullPtrBlock); // Fill in FreeBlock. @@ -1508,7 +1510,8 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, if (const ArrayType *AT = dyn_cast<ArrayType>(MI->getAllocatedType())) { MallocInst *NewMI = new MallocInst(AllocSTy, - ConstantInt::get(Type::Int32Ty, AT->getNumElements()), + ConstantInt::get(Type::getInt32Ty(Context), + AT->getNumElements()), "", MI); NewMI->takeName(MI); Value *Cast = new BitCastInst(NewMI, MI->getType(), "tmp", MI); @@ -1569,7 +1572,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, // between them is very expensive and unlikely to lead to later // simplification. In these cases, we typically end up with "cond ? v1 : v2" // where v1 and v2 both require constant pool loads, a big loss. - if (GVElType == Type::Int1Ty || GVElType->isFloatingPoint() || + if (GVElType == Type::getInt1Ty(Context) || GVElType->isFloatingPoint() || isa<PointerType>(GVElType) || isa<VectorType>(GVElType)) return false; @@ -1582,14 +1585,16 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, DOUT << " *** SHRINKING TO BOOL: " << *GV; // Create the new global, initializing it to false. - GlobalVariable *NewGV = new GlobalVariable(Context, Type::Int1Ty, false, + GlobalVariable *NewGV = new GlobalVariable(Context, + Type::getInt1Ty(Context), false, GlobalValue::InternalLinkage, ConstantInt::getFalse(Context), GV->getName()+".b", GV->isThreadLocal()); GV->getParent()->getGlobalList().insert(GV, NewGV); Constant *InitVal = GV->getInitializer(); - assert(InitVal->getType() != Type::Int1Ty && "No reason to shrink to bool!"); + assert(InitVal->getType() != Type::getInt1Ty(Context) && + "No reason to shrink to bool!"); // If initialized to zero and storing one into the global, we can use a cast // instead of a select to synthesize the desired value. @@ -1605,7 +1610,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, // Only do this if we weren't storing a loaded value. Value *StoreVal; if (StoringOther || SI->getOperand(0) == InitVal) - StoreVal = ConstantInt::get(Type::Int1Ty, StoringOther); + StoreVal = ConstantInt::get(Type::getInt1Ty(Context), StoringOther); else { // Otherwise, we are storing a previously loaded copy. To do this, // change the copy from copying the original value to just copying the @@ -1893,12 +1898,12 @@ GlobalVariable *GlobalOpt::FindGlobalCtors(Module &M) { if (!ATy) return 0; const StructType *STy = dyn_cast<StructType>(ATy->getElementType()); if (!STy || STy->getNumElements() != 2 || - STy->getElementType(0) != Type::Int32Ty) return 0; + STy->getElementType(0) != Type::getInt32Ty(M.getContext())) return 0; const PointerType *PFTy = dyn_cast<PointerType>(STy->getElementType(1)); if (!PFTy) return 0; const FunctionType *FTy = dyn_cast<FunctionType>(PFTy->getElementType()); - if (!FTy || FTy->getReturnType() != Type::VoidTy || FTy->isVarArg() || - FTy->getNumParams() != 0) + if (!FTy || FTy->getReturnType() != Type::getVoidTy(M.getContext()) || + FTy->isVarArg() || FTy->getNumParams() != 0) return 0; // Verify that the initializer is simple enough for us to handle. @@ -1947,7 +1952,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, LLVMContext &Context) { // If we made a change, reassemble the initializer list. std::vector<Constant*> CSVals; - CSVals.push_back(ConstantInt::get(Type::Int32Ty, 65535)); + CSVals.push_back(ConstantInt::get(Type::getInt32Ty(Context), 65535)); CSVals.push_back(0); // Create the new init list. @@ -1956,10 +1961,10 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, if (Ctors[i]) { CSVals[1] = Ctors[i]; } else { - const Type *FTy = FunctionType::get(Type::VoidTy, false); + const Type *FTy = FunctionType::get(Type::getVoidTy(Context), false); const PointerType *PFTy = PointerType::getUnqual(FTy); CSVals[1] = Constant::getNullValue(PFTy); - CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647); + CSVals[0] = ConstantInt::get(Type::getInt32Ty(Context), 2147483647); } CAList.push_back(ConstantStruct::get(Context, CSVals)); } diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index 4edecc2b23..bb2448610f 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -152,7 +152,7 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) { // callers will be updated to use the value they pass in directly instead of // using the return value. bool IPCP::PropagateConstantReturn(Function &F) { - if (F.getReturnType() == Type::VoidTy) + if (F.getReturnType() == Type::getVoidTy(F.getContext())) return false; // No return value. // If this function could be overridden later in the link stage, we can't diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp index 2086a16683..e7884ec634 100644 --- a/lib/Transforms/IPO/IndMemRemoval.cpp +++ b/lib/Transforms/IPO/IndMemRemoval.cpp @@ -55,8 +55,8 @@ bool IndMemRemPass::runOnModule(Module &M) { Function* FN = Function::Create(F->getFunctionType(), GlobalValue::LinkOnceAnyLinkage, "free_llvm_bounce", &M); - BasicBlock* bb = BasicBlock::Create("entry",FN); - Instruction* R = ReturnInst::Create(bb); + BasicBlock* bb = BasicBlock::Create(M.getContext(), "entry",FN); + Instruction* R = ReturnInst::Create(M.getContext(), bb); new FreeInst(FN->arg_begin(), R); ++NumBounce; NumBounceSites += F->getNumUses(); @@ -70,11 +70,12 @@ bool IndMemRemPass::runOnModule(Module &M) { GlobalValue::LinkOnceAnyLinkage, "malloc_llvm_bounce", &M); FN->setDoesNotAlias(0); - BasicBlock* bb = BasicBlock::Create("entry",FN); + BasicBlock* bb = BasicBlock::Create(M.getContext(), "entry",FN); Instruction* c = CastInst::CreateIntegerCast( - FN->arg_begin(), Type::Int32Ty, false, "c", bb); - Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb); - ReturnInst::Create(a, bb); + FN->arg_begin(), Type::getInt32Ty(M.getContext()), false, "c", bb); + Instruction* a = new MallocInst(Type::getInt8Ty(M.getContext()), + c, "m", bb); + ReturnInst::Create(M.getContext(), a, bb); ++NumBounce; NumBounceSites += F->getNumUses(); F->replaceAllUsesWith(FN); diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp index 568798bd3a..5dff47aa81 100644 --- a/lib/Transforms/IPO/LowerSetJmp.cpp +++ b/lib/Transforms/IPO/LowerSetJmp.cpp @@ -201,7 +201,7 @@ bool LowerSetJmp::runOnModule(Module& M) { // This function is always successful, unless it isn't. bool LowerSetJmp::doInitialization(Module& M) { - const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty); + const Type *SBPTy = PointerType::getUnqual(Type::getInt8Ty(M.getContext())); const Type *SBPPTy = PointerType::getUnqual(SBPTy); // N.B. See llvm/runtime/GCCLibraries/libexception/SJLJ-Exception.h for @@ -209,33 +209,40 @@ bool LowerSetJmp::doInitialization(Module& M) // void __llvm_sjljeh_init_setjmpmap(void**) InitSJMap = M.getOrInsertFunction("__llvm_sjljeh_init_setjmpmap", - Type::VoidTy, SBPPTy, (Type *)0); + Type::getVoidTy(M.getContext()), + SBPPTy, (Type *)0); // void __llvm_sjljeh_destroy_setjmpmap(void**) DestroySJMap = M.getOrInsertFunction("__llvm_sjljeh_destroy_setjmpmap", - Type::VoidTy, SBPPTy, (Type *)0); + Type::getVoidTy(M.getContext()), + SBPPTy, (Type *)0); // void __llvm_sjljeh_add_setjmp_to_map(void**, void*, unsigned) AddSJToMap = M.getOrInsertFunction("__llvm_sjljeh_add_setjmp_to_map", - Type::VoidTy, SBPPTy, SBPTy, - Type::Int32Ty, (Type *)0); + Type::getVoidTy(M.getContext()), + SBPPTy, SBPTy, + Type::getInt32Ty(M.getContext()), + (Type *)0); // void __llvm_sjljeh_throw_longjmp(int*, int) ThrowLongJmp = M.getOrInsertFunction("__llvm_sjljeh_throw_longjmp", - Type::VoidTy, SBPTy, Type::Int32Ty, + Type::getVoidTy(M.getContext()), SBPTy, + Type::getInt32Ty(M.getContext()), (Type *)0); // unsigned __llvm_sjljeh_try_catching_longjmp_exception(void **) TryCatchLJ = M.getOrInsertFunction("__llvm_sjljeh_try_catching_longjmp_exception", - Type::Int32Ty, SBPPTy, (Type *)0); + Type::getInt32Ty(M.getContext()), SBPPTy, (Type *)0); // bool __llvm_sjljeh_is_longjmp_exception() IsLJException = M.getOrInsertFunction("__llvm_sjljeh_is_longjmp_exception", - Type::Int1Ty, (Type *)0); + Type::getInt1Ty(M.getContext()), + (Type *)0); // int __llvm_sjljeh_get_longjmp_value() GetLJValue = M.getOrInsertFunction("__llvm_sjljeh_get_longjmp_value", - Type::Int32Ty, (Type *)0); + Type::getInt32Ty(M.getContext()), + (Type *)0); return true; } @@ -258,7 +265,8 @@ bool LowerSetJmp::IsTransformableFunction(const std::string& Name) { // throwing the exception for us. void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) { - const Type* SBPTy = PointerType::getUnqual(Type::Int8Ty); + const Type* SBPTy = + PointerType::getUnqual(Type::getInt8Ty(Inst->getContext())); // Create the call to "__llvm_sjljeh_throw_longjmp". This takes the // same parameters as "longjmp", except that the buffer is cast to a @@ -279,7 +287,7 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) if (SVP.first) BranchInst::Create(SVP.first->getParent(), Inst); else - new UnwindInst(Inst); + new UnwindInst(Inst->getContext(), Inst); // Remove all insts after the branch/unwind inst. Go from back to front to // avoid replaceAllUsesWith if possible. @@ -310,7 +318,8 @@ AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func) assert(Inst && "Couldn't find even ONE instruction in entry block!"); // Fill in the alloca and call to initialize the SJ map. - const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty); + const Type *SBPTy = + PointerType::getUnqual(Type::getInt8Ty(Func->getContext())); AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst); CallInst::Create(InitSJMap, Map, "", Inst); return SJMap[Func] = Map; @@ -325,12 +334,13 @@ BasicBlock* LowerSetJmp::GetRethrowBB(Function* Func) // The basic block we're going to jump to if we need to rethrow the // exception. - BasicBlock* Rethrow = BasicBlock::Create("RethrowExcept", Func); + BasicBlock* Rethrow = + BasicBlock::Create(Func->getContext(), "RethrowExcept", Func); // Fill in the "Rethrow" BB with a call to rethrow the exception. This // is the last instruction in the BB since at this point the runtime // should exit this function and go to the next function. - new UnwindInst(Rethrow); + new UnwindInst(Func->getContext(), Rethrow); return RethrowBBMap[Func] = Rethrow; } @@ -341,7 +351,8 @@ LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func, { if (SwitchValMap[Func].first) return SwitchValMap[Func]; - BasicBlock* LongJmpPre = BasicBlock::Create("LongJmpBlkPre", Func); + BasicBlock* LongJmpPre = + BasicBlock::Create(Func->getContext(), "LongJmpBlkPre", Func); // Keep track of the preliminary basic block for some of the other // transformations. @@ -353,7 +364,8 @@ LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func, // The "decision basic block" gets the number associated with the // setjmp call returning to switch on and the value returned by // longjmp. - BasicBlock* DecisionBB = BasicBlock::Create("LJDecisionBB", Func); + BasicBlock* DecisionBB = + BasicBlock::Create(Func->getContext(), "LJDecisionBB", Func); BranchInst::Create(DecisionBB, Rethrow, Cond, LongJmpPre); @@ -376,12 +388,14 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) Function* Func = ABlock->getParent(); // Add this setjmp to the setjmp map. - const Type* SBPTy = PointerType::getUnqual(Type::Int8Ty); + const Type* SBPTy = + PointerType::getUnqual(Type::getInt8Ty(Inst->getContext())); CastInst* BufPtr = new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst); std::vector<Value*> Args = make_vector<Value*>(GetSetJmpMap(Func), BufPtr, - ConstantInt::get(Type::Int32Ty,SetJmpIDMap[Func]++), 0); + ConstantInt::get(Type::getInt32Ty(Inst->getContext()), + SetJmpIDMap[Func]++), 0); CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst); // We are guaranteed that there are no values live across basic blocks @@ -424,14 +438,17 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) // This PHI node will be in the new block created from the // splitBasicBlock call. - PHINode* PHI = PHINode::Create(Type::Int32Ty, "SetJmpReturn", Inst); + PHINode* PHI = PHINode::Create(Type::getInt32Ty(Inst->getContext()), + "SetJmpReturn", Inst); // Coming from a call to setjmp, the return is 0. - PHI->addIncoming(Constant::getNullValue(Type::Int32Ty), ABlock); + PHI->addIncoming(Constant::getNullValue(Type::getInt32Ty(Inst->getContext())), + ABlock); // Add the case for this setjmp's number... SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func)); - SVP.first->addCase(ConstantInt::get(Type::Int32Ty, SetJmpIDMap[Func] - 1), + SVP.first->addCase(ConstantInt::get(Type::getInt32Ty(Inst->getContext()), + SetJmpIDMap[Func] - 1), SetJmpContBlock); // Value coming from the handling of the exception. @@ -503,7 +520,8 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II) BasicBlock* ExceptBB = II.getUnwindDest(); Function* Func = BB->getParent(); - BasicBlock* NewExceptBB = BasicBlock::Create("InvokeExcept", Func); + BasicBlock* NewExceptBB = BasicBlock::Create(II.getContext(), + "InvokeExcept", Func); // If this is a longjmp exception, then branch to the preliminary BB of // the longjmp exception handling. Otherwise, go to the old exception. diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index cb51bc3903..74a903b021 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -479,7 +479,7 @@ static LinkageCategory categorize(const Function *F) { static void ThunkGToF(Function *F, Function *G) { Function *NewG = Function::Create(G->getFunctionType(), G->getLinkage(), "", G->getParent()); - BasicBlock *BB = BasicBlock::Create("", NewG); + BasicBlock *BB = BasicBlock::Create(F->getContext(), "", NewG); std::vector<Value *> Args; unsigned i = 0; @@ -498,13 +498,13 @@ static void ThunkGToF(Function *F, Function *G) { CallInst *CI = CallInst::Create(F, Args.begin(), Args.end(), "", BB); CI->setTailCall(); CI->setCallingConv(F->getCallingConv()); - if (NewG->getReturnType() == Type::VoidTy) { - ReturnInst::Create(BB); + if (NewG->getReturnType() == Type::getVoidTy(F->getContext())) { + ReturnInst::Create(F->getContext(), BB); } else if (CI->getType() != NewG->getReturnType()) { Value *BCI = new BitCastInst(CI, NewG->getReturnType(), "", BB); - ReturnInst::Create(BCI, BB); + ReturnInst::Create(F->getContext(), BCI, BB); } else { - ReturnInst::Create(CI, BB); + ReturnInst::Create(F->getContext(), CI, BB); } NewG->copyAttributesFrom(G); diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index d2a6530cd9..5cc43a5fe4 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -215,7 +215,7 @@ bool PruneEH::SimplifyFunction(Function *F) { // Remove the uncond branch and add an unreachable. BB->getInstList().pop_back(); - new UnreachableInst(BB); + new UnreachableInst(BB->getContext(), BB); DeleteBasicBlock(New); // Delete the new BB. MadeChange = true; diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp index 0ef0991637..7b4ad27694 100644 --- a/lib/Transforms/IPO/RaiseAllocations.cpp +++ b/lib/Transforms/IPO/RaiseAllocations.cpp @@ -77,22 +77,26 @@ void RaiseAllocations::doInitialization(Module &M) { // Get the expected prototype for malloc const FunctionType *Malloc1Type = - FunctionType::get(PointerType::getUnqual(Type::Int8Ty), - std::vector<const Type*>(1, Type::Int64Ty), false); + FunctionType::get(PointerType::getUnqual(Type::getInt8Ty(M.getContext())), + std::vector<const Type*>(1, + Type::getInt64Ty(M.getContext())), false); // Chck to see if we got the expected malloc if (TyWeHave != Malloc1Type) { // Check to see if the prototype is wrong, giving us i8*(i32) * malloc // This handles the common declaration of: 'void *malloc(unsigned);' const FunctionType *Malloc2Type = - FunctionType::get(PointerType::getUnqual(Type::Int8Ty), - std::vector<const Type*>(1, Type::Int32Ty), false); + FunctionType::get(PointerType::getUnqual( + Type::getInt8Ty(M.getContext())), + std::vector<const Type*>(1, + Type::getInt32Ty(M.getContext())), false); if (TyWeHave != Malloc2Type) { // Check to see if the prototype is missing, giving us // i8*(...) * malloc // This handles the common declaration of: 'void *malloc();' const FunctionType *Malloc3Type = - FunctionType::get(PointerType::getUnqual(Type::Int8Ty), + FunctionType::get(PointerType::getUnqual( + Type::getInt8Ty(M.getContext())), true); if (TyWeHave != Malloc3Type) // Give up @@ -106,22 +110,24 @@ void RaiseAllocations::doInitialization(Module &M) { const FunctionType* TyWeHave = FreeFunc->getFunctionType(); // Get the expected prototype for void free(i8*) - const FunctionType *Free1Type = FunctionType::get(Type::VoidTy, - std::vector<const Type*>(1, PointerType::getUnqual(Type::Int8Ty)), - false); + const FunctionType *Free1Type = + FunctionType::get(Type::getVoidTy(M.getContext()), + std::vector<const Type*>(1, PointerType::getUnqual( + Type::getInt8Ty(M.getContext()))), + false); if (TyWeHave != Free1Type) { // Check to see if the prototype was forgotten, giving us // void (...) * free // This handles the common forward declaration of: 'void free();' - const FunctionType* Free2Type = FunctionType::get(Type::VoidTy, - true); + const FunctionType* Free2Type = + FunctionType::get(Type::getVoidTy(M.getContext()), true); if (TyWeHave != Free2Type) { // One last try, check to see if we can find free as // int (...)* free. This handles the case where NOTHING was declared. - const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty, - true); + const FunctionType* Free3Type = + FunctionType::get(Type::getInt32Ty(M.getContext()), true); if (TyWeHave != Free3Type) { // Give up. @@ -163,12 +169,15 @@ bool RaiseAllocations::runOnModule(Module &M) { // If no prototype was provided for malloc, we may need to cast the // source size. - if (Source->getType() != Type::Int32Ty) + if (Source->getType() != Type::getInt32Ty(M.getContext())) Source = - CastInst::CreateIntegerCast(Source, Type::Int32Ty, false/*ZExt*/, + CastInst::CreateIntegerCast(Source, + Type::getInt32Ty(M.getContext()), + false/*ZExt*/, "MallocAmtCast", I); - MallocInst *MI = new MallocInst(Type::Int8Ty, Source, "", I); + MallocInst *MI = new MallocInst(Type::getInt8Ty(M.getContext()), + Source, "", I); MI->takeName(I); I->replaceAllUsesWith(MI); @@ -220,7 +229,7 @@ bool RaiseAllocations::runOnModule(Module &M) { Value *Source = *CS.arg_begin(); if (!isa<PointerType>(Source->getType())) Source = new IntToPtrInst(Source, - PointerType::getUnqual(Type::Int8Ty), + PointerType::getUnqual(Type::getInt8Ty(M.getContext())), "FreePtrCast", I); new FreeInst(Source, I); @@ -230,7 +239,7 @@ bool RaiseAllocations::runOnModule(Module &M) { BranchInst::Create(II->getNormalDest(), I); // Delete the old call site - if (I->getType() != Type::VoidTy) + if (I->getType() != Type::getVoidTy(M.getContext())) I->replaceAllUsesWith(UndefValue::get(I->getType())); I->eraseFromParent(); Changed = true; diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index a2413597a3..743dbf7fa2 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -94,7 +94,8 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) { DEBUG(errs() << "SretPromotion: Looking at sret function " << F->getName() << "\n"); - assert (F->getReturnType() == Type::VoidTy && "Invalid function return type"); + assert (F->getReturnType() == Type::getVoidTy(F->getContext()) && + "Invalid function return type"); Function::arg_iterator AI = F->arg_begin(); const llvm::PointerType *FArgType = dyn_cast<PointerType>(AI->getType()); assert (FArgType && "Invalid sret parameter type"); @@ -124,7 +125,7 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) { ++BI; if (isa<ReturnInst>(I)) { Value *NV = new LoadInst(TheAlloca, "mrv.ld", I); - ReturnInst *NR = ReturnInst::Create(NV, I); + ReturnInst *NR = ReturnInst::Create(F->getContext(), NV, I); I->replaceAllUsesWith(NR); I->eraseFromParent(); } @@ -347,7 +348,7 @@ bool SRETPromotion::nestedStructType(const StructType *STy) { unsigned Num = STy->getNumElements(); for (unsigned i = 0; i < Num; i++) { const Type *Ty = STy->getElementType(i); - if (!Ty->isSingleValueType() && Ty != Type::VoidTy) + if (!Ty->isSingleValueType() && Ty != Type::getVoidTy(STy->getContext())) return true; } return false; diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp index 91020755c2..029b8fe0b9 100644 --- a/lib/Transforms/Instrumentation/BlockProfiling.cpp +++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp @@ -63,7 +63,8 @@ bool FunctionProfiler::runOnModule(Module &M) { if (!I->isDeclaration()) ++NumFunctions; - const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions); + const Type *ATy = ArrayType::get(Type::getInt32Ty(M.getContext()), + NumFunctions); GlobalVariable *Counters = new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage, Constant::getNullValue(ATy), "FuncProfCounters"); @@ -109,7 +110,7 @@ bool BlockProfiler::runOnModule(Module &M) { if (!I->isDeclaration()) NumBlocks += I->size(); - const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks); + const Type *ATy = ArrayType::get(Type::getInt32Ty(M.getContext()), NumBlocks); GlobalVariable *Counters = new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage, Constant::getNullValue(ATy), "BlockProfCounters"); diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp index 283f863dc3..2220bbfbe9 100644 --- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp +++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp @@ -68,7 +68,7 @@ bool EdgeProfiler::runOnModule(Module &M) { } } - const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges); + const Type *ATy = ArrayType::get(Type::getInt32Ty(M.getContext()), NumEdges); GlobalVariable *Counters = new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage, Constant::getNullValue(ATy), "EdgeProfCounters"); diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp index dc34bf70a3..88a1d2a07c 100644 --- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp +++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp @@ -23,18 +23,22 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, GlobalValue *Array) { + LLVMContext &Context = MainFn->getContext(); const Type *ArgVTy = - PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)); - const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty); + PointerType::getUnqual(PointerType::getUnqual(Type::getInt8Ty(Context))); + const PointerType *UIntPtr = + PointerType::getUnqual(Type::getInt32Ty(Context)); Module &M = *MainFn->getParent(); - Constant *InitFn = M.getOrInsertFunction(FnName, Type::Int32Ty, Type::Int32Ty, - ArgVTy, UIntPtr, Type::Int32Ty, + Constant *InitFn = M.getOrInsertFunction(FnName, Type::getInt32Ty(Context), + Type::getInt32Ty(Context), + ArgVTy, UIntPtr, + Type::getInt32Ty(Context), (Type *)0); // This could force argc and argv into programs that wouldn't otherwise have // them, but instead we just pass null values in. std::vector<Value*> Args(4); - Args[0] = Constant::getNullValue(Type::Int32Ty); + Args[0] = Constant::getNullValue(Type::getInt32Ty(Context)); Args[1] = Constant::getNullValue(ArgVTy); // Skip over any allocas in the entry block. @@ -42,7 +46,8 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, BasicBlock::iterator InsertPos = Entry->begin(); while (isa<AllocaInst>(InsertPos)) ++InsertPos; - std::vector<Constant*> GEPIndices(2, Constant::getNullValue(Type::Int32Ty)); + std::vector<Constant*> GEPIndices(2, + Constant::getNullValue(Type::getInt32Ty(Context))); unsigned NumElements = 0; if (Array) { Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0], @@ -54,7 +59,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, // pass null. Args[2] = ConstantPointerNull::get(UIntPtr); } - Args[3] = ConstantInt::get(Type::Int32Ty, NumElements); + Args[3] = ConstantInt::get(Type::getInt32Ty(Context), NumElements); Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(), "newargc", InsertPos); @@ -79,16 +84,18 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, AI = MainFn->arg_begin(); // If the program looked at argc, have it look at the return value of the // init call instead. - if (AI->getType() != Type::Int32Ty) { + if (AI->getType() != Type::getInt32Ty(Context)) { Instruction::CastOps opcode; if (!AI->use_empty()) { opcode = CastInst::getCastOpcode(InitCall, true, AI->getType(), true); AI->replaceAllUsesWith( CastInst::Create(opcode, InitCall, AI->getType(), "", InsertPos)); } - opcode = CastInst::getCastOpcode(AI, true, Type::Int32Ty, true); + opcode = CastInst::getCastOpcode(AI, true, + Type::getInt32Ty(Context), true); InitCall->setOperand(1, - CastInst::Create(opcode, AI, Type::Int32Ty, "argc.cast", InitCall)); + CastInst::Create(opcode, AI, Type::getInt32Ty(Context), + "argc.cast", InitCall)); } else { AI->replaceAllUsesWith(InitCall); InitCall->setOperand(1, AI); @@ -105,10 +112,12 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, while (isa<AllocaInst>(InsertPos)) ++InsertPos; + LLVMContext &Context = BB->getContext(); + // Create the getelementptr constant expression std::vector<Constant*> Indices(2); - Indices[0] = Constant::getNullValue(Type::Int32Ty); - Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); + Indices[0] = Constant::getNullValue(Type::getInt32Ty(Context)); + Indices[1] = ConstantInt::get(Type::getInt32Ty(Context), CounterNum); Constant *ElementPtr = ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], Indices.size()); @@ -116,7 +125,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, // Load, increment and store the value back. Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos); Value *NewVal = BinaryOperator::Create(Instruction::Add, OldVal, - ConstantInt::get(Type::Int32Ty, 1), + ConstantInt::get(Type::getInt32Ty(Context), 1), "NewFuncCounter", InsertPos); new StoreInst(NewVal, ElementPtr, InsertPos); } diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp index e2aa10924c..9997d9dca9 100644 --- a/lib/Transforms/Instrumentation/RSProfiling.cpp +++ b/lib/Transforms/Instrumentation/RSProfiling.cpp @@ -225,7 +225,8 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) { //reset counter BasicBlock* oldnext = t->getSuccessor(0); - BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(), + BasicBlock* resetblock = BasicBlock::Create(bb->getContext(), + "reset", oldnext->getParent(), oldnext); TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock); t->setSuccessor(0, resetblock); @@ -298,7 +299,8 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) { //reset counter BasicBlock* oldnext = t->getSuccessor(0); - BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(), + BasicBlock* resetblock = BasicBlock::Create(bb->getContext(), + "reset", oldnext->getParent(), oldnext); TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock); t->setSuccessor(0, resetblock); @@ -320,11 +322,12 @@ void CycleCounter::ProcessChoicePoint(BasicBlock* bb) { CallInst* c = CallInst::Create(F, "rdcc", t); BinaryOperator* b = - BinaryOperator::CreateAnd(c, ConstantInt::get(Type::Int64Ty, rm), + BinaryOperator::CreateAnd(c, + ConstantInt::get(Type::getInt64Ty(bb->getContext()), rm), "mrdcc", t); ICmpInst *s = new ICmpInst(t, ICmpInst::ICMP_EQ, b, - ConstantInt::get(Type::Int64Ty, 0), + ConstantInt::get(Type::getInt64Ty(bb->getContext()), 0), "mrdccc"); t->setCondition(s); @@ -350,8 +353,8 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu // Create the getelementptr constant expression std::vector<Constant*> Indices(2); - Indices[0] = Constant::getNullValue(Type::Int32Ty); - Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); + Indices[0] = Constant::getNullValue(Type::getInt32Ty(BB->getContext())); + Indices[1] = ConstantInt::get(Type::getInt32Ty(BB->getContext()), CounterNum); Constant *ElementPtr =ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], 2); @@ -359,7 +362,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu Value *OldVal = new LoadInst(ElementPtr, "OldCounter", InsertPos); profcode.insert(OldVal); Value *NewVal = BinaryOperator::CreateAdd(OldVal, - ConstantInt::get(Type::Int32Ty, 1), + ConstantInt::get(Type::getInt32Ty(BB->getContext()), 1), "NewCounter", InsertPos); profcode.insert(NewVal); profcode.insert(new StoreInst(NewVal, ElementPtr, InsertPos)); @@ -382,7 +385,8 @@ Value* ProfilerRS::Translate(Value* v) { if (bb == &bb->getParent()->getEntryBlock()) TransCache[bb] = bb; //don't translate entry block else - TransCache[bb] = BasicBlock::Create("dup_" + bb->getName(), + TransCache[bb] = BasicBlock::Create(v->getContext(), + "dup_" + bb->getName(), bb->getParent(), NULL); return TransCache[bb]; } else if (Instruction* i = dyn_cast<Instruction>(v)) { @@ -471,16 +475,16 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F) //a: Function::iterator BBN = src; ++BBN; - BasicBlock* bbC = BasicBlock::Create("choice", &F, BBN); + BasicBlock* bbC = BasicBlock::Create(F.getContext(), "choice", &F, BBN); //ChoicePoints.insert(bbC); BBN = cast<BasicBlock>(Translate(src)); - BasicBlock* bbCp = BasicBlock::Create("choice", &F, ++BBN); + BasicBlock* bbCp = BasicBlock::Create(F.getContext(), "choice", &F, ++BBN); ChoicePoints.insert(bbCp); //b: BranchInst::Create(cast<BasicBlock>(Translate(dst)), bbC); BranchInst::Create(dst, cast<BasicBlock>(Translate(dst)), - ConstantInt::get(Type::Int1Ty, true), bbCp); + ConstantInt::get(Type::getInt1Ty(src->getContext()), true), bbCp); //c: { TerminatorInst* iB = src->getTerminator(); @@ -536,8 +540,8 @@ bool ProfilerRS::runOnFunction(Function& F) { TerminatorInst* T = F.getEntryBlock().getTerminator(); ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0), cast<BasicBlock>( - Translate(T->getSuccessor(0))), - ConstantInt::get(Type::Int1Ty, true))); + Translate(T->getSuccessor(0))), + ConstantInt::get(Type::getInt1Ty(F.getContext()), true))); //do whatever is needed now that the function is duplicated c->PrepFunction(&F); @@ -560,10 +564,12 @@ bool ProfilerRS::runOnFunction(Function& F) { bool ProfilerRS::doInitialization(Module &M) { switch (RandomMethod) { case GBV: - c = new GlobalRandomCounter(M, Type::Int32Ty, (1 << 14) - 1); + c = new GlobalRandomCounter(M, Type::getInt32Ty(M.getContext()), + (1 << 14) - 1); break; case GBVO: - c = new GlobalRandomCounterOpt(M, Type::Int32Ty, (1 << 14) - 1); + c = new GlobalRandomCounterOpt(M, Type::getInt32Ty(M.getContext()), + (1 << 14) - 1); break; case HOSTCC: c = new CycleCounter(M, (1 << 14) - 1); diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 4fe9bcf17e..9a59dca412 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -599,7 +599,8 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr, } else { DEBUG(errs() << "CGP: SINKING nonlocal addrmode: " << AddrMode << " for " << *MemoryInst); - const Type *IntPtrTy = TLI->getTargetData()->getIntPtrType(); + const Type *IntPtrTy = + TLI->getTargetData()->getIntPtrType(AccessTy->getContext()); Value *Result = 0; // Start with the scale value. diff --git a/lib/Transforms/Scalar/CondPropagate.cpp b/lib/Transforms/Scalar/CondPropagate.cpp index c85d0317d6..88b5652726 100644 --- a/lib/Transforms/Scalar/CondPropagate.cpp +++ b/lib/Transforms/Scalar/CondPropagate.cpp @@ -124,7 +124,7 @@ void CondProp::SimplifyBlock(BasicBlock *BB) { // Succ is now dead, but we cannot delete it without potentially // invalidating iterators elsewhere. Just insert an unreachable // instruction in it and delete this block later on. - new UnreachableInst(Succ); + new UnreachableInst(BB->getContext(), Succ); DeadBlocks.push_back(Succ); MadeChange = true; } diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 21a5289193..c782f7da70 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1562,7 +1562,8 @@ bool GVN::performPRE(Function& F) { Instruction *CurInst = BI++; if (isa<AllocationInst>(CurInst) || isa<TerminatorInst>(CurInst) || - isa<PHINode>(CurInst) || (CurInst->getType() == Type::VoidTy) || + isa<PHINode>(CurInst) || + (CurInst->getType() == Type::getVoidTy(F.getContext())) || CurInst->mayReadFromMemory() || CurInst->mayHaveSideEffects() || isa<DbgInfoIntrinsic>(CurInst)) continue; diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index b33c805903..0f8a878376 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -634,7 +634,8 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) { // Check incoming value. ConstantFP *InitValue = dyn_cast<ConstantFP>(PH->getIncomingValue(IncomingEdge)); if (!InitValue) return; - uint64_t newInitValue = Type::Int32Ty->getPrimitiveSizeInBits(); + uint64_t newInitValue = + Type::getInt32Ty(PH->getContext())->getPrimitiveSizeInBits(); if (!convertToInt(InitValue->getValueAPF(), &newInitValue)) return; @@ -650,7 +651,8 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) { IncrVIndex = 0; IncrValue = dyn_cast<ConstantFP>(Incr->getOperand(IncrVIndex)); if (!IncrValue) return; - uint64_t newIncrValue = Type::Int32Ty->getPrimitiveSizeInBits(); + uint64_t newIncrValue = + Type::getInt32Ty(PH->getContext())->getPrimitiveSizeInBits(); if (!convertToInt(IncrValue->getValueAPF(), &newIncrValue)) return; @@ -681,7 +683,7 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) { EVIndex = 0; EV = dyn_cast<ConstantFP>(EC->getOperand(EVIndex)); if (!EV) return; - uint64_t intEV = Type::Int32Ty->getPrimitiveSizeInBits(); + uint64_t intEV = Type::getInt32Ty(PH->getContext())->getPrimitiveSizeInBits(); if (!convertToInt(EV->getValueAPF(), &intEV)) return; @@ -714,20 +716,22 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) { if (NewPred == CmpInst::BAD_ICMP_PREDICATE) return; // Insert new integer induction variable. - PHINode *NewPHI = PHINode::Create(Type::Int32Ty, + PHINode *NewPHI = PHINode::Create(Type::getInt32Ty(PH->getContext()), PH->getName()+".int", PH); - NewPHI->addIncoming(ConstantInt::get(Type::Int32Ty, newInitValue), + NewPHI->addIncoming(ConstantInt::get(Type::getInt32Ty(PH->getContext()), + newInitValue), PH->getIncomingBlock(IncomingEdge)); Value *NewAdd = BinaryOperator::CreateAdd(NewPHI, - ConstantInt::get(Type::Int32Ty, + ConstantInt::get(Type::getInt32Ty(PH->getContext()), newIncrValue), Incr->getName()+".int", Incr); NewPHI->addIncoming(NewAdd, PH->getIncomingBlock(BackEdge)); // The back edge is edge 1 of newPHI, whatever it may have been in the // original PHI. - ConstantInt *NewEV = ConstantInt::get(Type::Int32Ty, intEV); + ConstantInt *NewEV = ConstantInt::get(Type::getInt32Ty(PH->getContext()), + intEV); Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(1) : NewEV); Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(1)); ICmpInst *NewEC = new ICmpInst(EC->getParent()->getTerminator(), diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 04c225f746..7a98b482a2 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -435,7 +435,7 @@ static bool isOnlyUse(Value *V) { static const Type *getPromotedType(const Type *Ty) { if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) { if (ITy->getBitWidth() < 32) - return Type::Int32Ty; + return Type::getInt32Ty(Ty->getContext()); } return Ty; } @@ -473,12 +473,14 @@ isEliminableCastPair( unsigned Res = CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy, DstTy, - TD ? TD->getIntPtrType() : 0); + TD ? TD->getIntPtrType(CI->getContext()) : 0); // We don't want to form an inttoptr or ptrtoint that converts to an integer // type that differs from the pointer size. - if ((Res == Instruction::IntToPtr && SrcTy != TD->getIntPtrType()) || - (Res == Instruction::PtrToInt && DstTy != TD->getIntPtrType())) + if ((Res == Instruction::IntToPtr && + SrcTy != TD->getIntPtrType(CI->getContext())) || + (Res == Instruction::PtrToInt && + DstTy != TD->getIntPtrType(CI->getContext()))) Res = 0; return Instruction::CastOps(Res); @@ -1587,9 +1589,9 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, std::vector<Constant*> Elts; for (unsigned i = 0; i < VWidth; ++i) { if (UndefElts[i]) - Elts.push_back(UndefValue::get(Type::Int32Ty)); + Elts.push_back(UndefValue::get(Type::getInt32Ty(*Context))); else - Elts.push_back(ConstantInt::get(Type::Int32Ty, + Elts.push_back(ConstantInt::get(Type::getInt32Ty(*Context), Shuffle->getMaskValue(i))); } I->setOperand(2, ConstantVector::get(Elts)); @@ -1720,9 +1722,9 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, Value *RHS = II->getOperand(2); // Extract the element as scalars. LHS = InsertNewInstBefore(ExtractElementInst::Create(LHS, - ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II); + ConstantInt::get(Type::getInt32Ty(*Context), 0U, false), "tmp"), *II); RHS = InsertNewInstBefore(ExtractElementInst::Create(RHS, - ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II); + ConstantInt::get(Type::getInt32Ty(*Context), 0U, false), "tmp"), *II); switch (II->getIntrinsicID()) { default: llvm_unreachable("Case stmts out of sync!"); @@ -1741,7 +1743,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, Instruction *New = InsertElementInst::Create( UndefValue::get(II->getType()), TmpV, - ConstantInt::get(Type::Int32Ty, 0U, false), II->getName()); + ConstantInt::get(Type::getInt32Ty(*Context), 0U, false), II->getName()); InsertNewInstBefore(New, *II); AddSoonDeadInstToWorklist(*II, 0); return New; @@ -1912,7 +1914,7 @@ static Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI, if (isa<Constant>(TV) || isa<Constant>(FV)) { // Bool selects with constant operands can be folded to logical ops. - if (SI->getType() == Type::Int1Ty) return 0; + if (SI->getType() == Type::getInt1Ty(*IC->getContext())) return 0; Value *SelectTrueVal = FoldOperationIntoSelectOperand(Op, TV, IC); Value *SelectFalseVal = FoldOperationIntoSelectOperand(Op, FV, IC); @@ -2066,7 +2068,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { // zext(bool) + C -> bool ? C + 1 : C if (ZExtInst *ZI = dyn_cast<ZExtInst>(LHS)) - if (ZI->getSrcTy() == Type::Int1Ty) + if (ZI->getSrcTy() == Type::getInt1Ty(*Context)) return SelectInst::Create(ZI->getOperand(0), AddOne(CI), CI); } @@ -2109,9 +2111,9 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { const Type *MiddleType = 0; switch (Size) { default: break; - case 32: MiddleType = Type::Int32Ty; break; - case 16: MiddleType = Type::Int16Ty; break; - case 8: MiddleType = Type::Int8Ty; break; + case 32: MiddleType = Type::getInt32Ty(*Context); break; + case 16: MiddleType = Type::getInt16Ty(*Context); break; + case 8: MiddleType = Type::getInt8Ty(*Context); break; } if (MiddleType) { Instruction *NewTrunc = new TruncInst(XorLHS, MiddleType, "sext"); @@ -2121,7 +2123,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { } } - if (I.getType() == Type::Int1Ty) + if (I.getType() == Type::getInt1Ty(*Context)) return BinaryOperator::CreateXor(LHS, RHS); // X + X --> X << 1 @@ -2466,11 +2468,11 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { // C - zext(bool) -> bool ? C - 1 : C if (ZExtInst *ZI = dyn_cast<ZExtInst>(Op1)) - if (ZI->getSrcTy() == Type::Int1Ty) + if (ZI->getSrcTy() == Type::getInt1Ty(*Context)) return SelectInst::Create(ZI->getOperand(0), SubOne(C), C); } - if (I.getType() == Type::Int1Ty) + if (I.getType() == Type::getInt1Ty(*Context)) return BinaryOperator::CreateXor(Op0, Op1); if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1)) { @@ -2726,7 +2728,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { } } - if (I.getType() == Type::Int1Ty) + if (I.getType() == Type::getInt1Ty(*Context)) return BinaryOperator::CreateAnd(Op0, I.getOperand(1)); // If one of the operands of the multiply is a cast from a boolean value, then @@ -2735,11 +2737,11 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { // formed. CastInst *BoolCast = 0; if (ZExtInst *CI = dyn_cast<ZExtInst>(Op0)) - if (CI->getOperand(0)->getType() == Type::Int1Ty) + if (CI->getOperand(0)->getType() == Type::getInt1Ty(*Context)) BoolCast = CI; if (!BoolCast) if (ZExtInst *CI = dyn_cast<ZExtInst>(I.getOperand(1))) - if (CI->getOperand(0)->getType() == Type::Int1Ty) + if (CI->getOperand(0)->getType() == Type::getInt1Ty(*Context)) BoolCast = CI; if (BoolCast) { if (ICmpInst *SCI = dyn_cast<ICmpInst>(BoolCast->getOperand(0))) { @@ -2974,7 +2976,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // It can't be division by zero, hence it must be division by one. - if (I.getType() == Type::Int1Ty) + if (I.getType() == Type::getInt1Ty(*Context)) return ReplaceInstUsesWith(I, Op0); if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1)) { @@ -5335,7 +5337,7 @@ static bool AddWithOverflow(Constant *&Result, Constant *In1, if (const VectorType *VTy = dyn_cast<VectorType>(In1->getType())) { for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - Constant *Idx = ConstantInt::get(Type::Int32Ty, i); + Constant *Idx = ConstantInt::get(Type::getInt32Ty(*Context), i); if (HasAddOverflow(ExtractElement(Result, Idx, Context), ExtractElement(In1, Idx, Context), ExtractElement(In2, Idx, Context), @@ -5371,7 +5373,7 @@ static bool SubWithOverflow(Constant *&Result, Constant *In1, if (const VectorType *VTy = dyn_cast<VectorType>(In1->getType())) { for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - Constant *Idx = ConstantInt::get(Type::Int32Ty, i); + Constant *Idx = ConstantInt::get(Type::getInt32Ty(*Context), i); if (HasSubOverflow(ExtractElement(Result, Idx, Context), ExtractElement(In1, Idx, Context), ExtractElement(In2, Idx, Context), @@ -5392,7 +5394,7 @@ static bool SubWithOverflow(Constant *&Result, Constant *In1, static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) { TargetData &TD = *IC.getTargetData(); gep_type_iterator GTI = gep_type_begin(GEP); - const Type *IntPtrTy = TD.getIntPtrType(); + const Type *IntPtrTy = TD.getIntPtrType(I.getContext()); LLVMContext *Context = IC.getContext(); Value *Result = Constant::getNullValue(IntPtrTy); @@ -5542,7 +5544,8 @@ static Value *EvaluateGEPOffsetExpression(User *GEP, Instruction &I, // we don't need to bother extending: the extension won't affect where the // computation crosses zero. if (VariableIdx->getType()->getPrimitiveSizeInBits() > IntPtrWidth) - VariableIdx = new TruncInst(VariableIdx, TD.getIntPtrType(), + VariableIdx = new TruncInst(VariableIdx, + TD.getIntPtrType(VariableIdx->getContext()), VariableIdx->getName(), &I); return VariableIdx; } @@ -5563,7 +5566,7 @@ static Value *EvaluateGEPOffsetExpression(User *GEP, Instruction &I, return 0; // Okay, we can do this evaluation. Start by converting the index to intptr. - const Type *IntPtrTy = TD.getIntPtrType(); + const Type *IntPtrTy = TD.getIntPtrType(VariableIdx->getContext()); if (VariableIdx->getType() != IntPtrTy) VariableIdx = CastInst::CreateIntegerCast(VariableIdx, IntPtrTy, true /*SExt*/, @@ -5661,7 +5664,7 @@ Instruction *InstCombiner::FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, if (NumDifferences == 0) // SAME GEP? return ReplaceInstUsesWith(I, // No comparison is needed here. - ConstantInt::get(Type::Int1Ty, + ConstantInt::get(Type::getInt1Ty(*Context), ICmpInst::isTrueWhenEqual(Cond))); else if (NumDifferences == 1) { @@ -5923,7 +5926,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { } if (isa<UndefValue>(Op1)) // fcmp pred X, undef -> undef - return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty)); + return ReplaceInstUsesWith(I, UndefValue::get(Type::getInt1Ty(*Context))); // Handle fcmp with constant RHS if (Constant *RHSC = dyn_cast<Constant>(Op1)) { @@ -5993,11 +5996,11 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // icmp X, X if (Op0 == Op1) - return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, + return ReplaceInstUsesWith(I, ConstantInt::get(Type::getInt1Ty(*Context), I.isTrueWhenEqual())); if (isa<UndefValue>(Op1)) // X icmp undef -> undef - return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty)); + return ReplaceInstUsesWith(I, UndefValue::get(Type::getInt1Ty(*Context))); // icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value // addresses never equal each other! We already know that Op0 != Op1. @@ -6005,11 +6008,11 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { isa<ConstantPointerNull>(Op0)) && (isa<GlobalValue>(Op1) || isa<AllocaInst>(Op1) || isa<ConstantPointerNull>(Op1))) - return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, + return ReplaceInstUsesWith(I, ConstantInt::get(Type::getInt1Ty(*Context), !I.isTrueWhenEqual())); // icmp's with boolean values can always be turned into bitwise operations - if (Ty == Type::Int1Ty) { + if (Ty == Type::getInt1Ty(*Context)) { switch (I.getPredicate()) { default: llvm_unreachable("Invalid icmp instruction!"); case ICmpInst::ICMP_EQ: { // icmp eq i1 A, B -> ~(A^B) @@ -6348,7 +6351,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // can assume it is successful and remove the malloc. if (LHSI->hasOneUse() && isa<ConstantPointerNull>(RHSC)) { AddToWorkList(LHSI); - return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, + return ReplaceInstUsesWith(I, ConstantInt::get(Type::getInt1Ty(*Context), !I.isTrueWhenEqual())); } break; @@ -6933,7 +6936,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, ShAmt); if (Comp != RHS) {// Comparing against a bit that we know is zero. bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; - Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE); + Constant *Cst = ConstantInt::get(Type::getInt1Ty(*Context), IsICMP_NE); return ReplaceInstUsesWith(ICI, Cst); } @@ -6997,7 +7000,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (Comp != RHSV) { // Comparing against a bit that we know is zero. bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; - Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE); + Constant *Cst = ConstantInt::get(Type::getInt1Ty(*Context), IsICMP_NE); return ReplaceInstUsesWith(ICI, Cst); } @@ -7139,7 +7142,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Constant *NotCI = ConstantExpr::getNot(RHS); if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue()) return ReplaceInstUsesWith(ICI, - ConstantInt::get(Type::Int1Ty, + ConstantInt::get(Type::getInt1Ty(*Context), isICMP_NE)); } break; @@ -7150,7 +7153,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, // comparison can never succeed! if ((RHSV & ~BOC->getValue()) != 0) return ReplaceInstUsesWith(ICI, - ConstantInt::get(Type::Int1Ty, + ConstantInt::get(Type::getInt1Ty(*Context), isICMP_NE)); // If we have ((X & C) == C), turn it into ((X & C) != 0). @@ -7692,7 +7695,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, case 32 : case 64 : case 128: - SExtType = IntegerType::get(Ty->getBitWidth() - ShiftAmt1); + SExtType = IntegerType::get(*Context, Ty->getBitWidth() - ShiftAmt1); break; default: break; } @@ -7774,11 +7777,11 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, /// static Value *DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale, int &Offset, LLVMContext *Context) { - assert(Val->getType() == Type::Int32Ty && "Unexpected allocation size type!"); + assert(Val->getType() == Type::getInt32Ty(*Context) && "Unexpected allocation size type!"); if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) { Offset = CI->getZExtValue(); Scale = 0; - return ConstantInt::get(Type::Int32Ty, 0); + return ConstantInt::get(Type::getInt32Ty(*Context), 0); } else if (BinaryOperator *I = dyn_cast<BinaryOperator>(Val)) { if (ConstantInt *RHS = dyn_cast<ConstantInt>(I->getOperand(1))) { if (I->getOpcode() == Instruction::Shl) { @@ -7875,7 +7878,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI, Amt = NumElements; } else { // If the allocation size is constant, form a constant mul expression - Amt = ConstantInt::get(Type::Int32Ty, Scale); + Amt = ConstantInt::get(Type::getInt32Ty(*Context), Scale); if (isa<ConstantInt>(NumElements)) Amt = ConstantExpr::getMul(cast<ConstantInt>(NumElements), cast<ConstantInt>(Amt)); @@ -7887,7 +7890,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI, } if (int Offset = (AllocElTySize*ArrayOffset)/CastElTySize) { - Value *Off = ConstantInt::get(Type::Int32Ty, Offset, true); + Value *Off = ConstantInt::get(Type::getInt32Ty(*Context), Offset, true); Instruction *Tmp = BinaryOperator::CreateAdd(Amt, Off, "tmp"); Amt = InsertNewInstBefore(Tmp, AI); } @@ -8173,7 +8176,7 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset, // Start with the index over the outer type. Note that the type size // might be zero (even if the offset isn't zero) if the indexed type // is something like [0 x {int, int}] - const Type *IntPtrTy = TD->getIntPtrType(); + const Type *IntPtrTy = TD->getIntPtrType(*Context); int64_t FirstIdx = 0; if (int64_t TySize = TD->getTypeAllocSize(Ty)) { FirstIdx = Offset/TySize; @@ -8202,7 +8205,7 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset, "Offset must stay within the indexed type"); unsigned Elt = SL->getElementContainingOffset(Offset); - NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt)); + NewIndices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), Elt)); Offset -= SL->getElementOffset(Elt); Ty = STy->getElementType(Elt); @@ -8579,7 +8582,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI, if (Op1CV != 0 && (Op1CV != KnownZeroMask)) { // (X&4) == 2 --> false // (X&4) != 2 --> true - Constant *Res = ConstantInt::get(Type::Int1Ty, isNE); + Constant *Res = ConstantInt::get(Type::getInt1Ty(*Context), isNE); Res = ConstantExpr::getZExt(Res, CI.getType()); return ReplaceInstUsesWith(CI, Res); } @@ -8708,7 +8711,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { Value *Src = CI.getOperand(0); // Canonicalize sign-extend from i1 to a select. - if (Src->getType() == Type::Int1Ty) + if (Src->getType() == Type::getInt1Ty(*Context)) return SelectInst::Create(Src, Constant::getAllOnesValue(CI.getType()), Constant::getNullValue(CI.getType())); @@ -8796,12 +8799,12 @@ static Value *LookThroughFPExtensions(Value *V, LLVMContext *Context) { // that can accurately represent it. This allows us to turn // (float)((double)X+2.0) into x+2.0f. if (ConstantFP *CFP = dyn_cast<ConstantFP>(V)) { - if (CFP->getType() == Type::PPC_FP128Ty) + if (CFP->getType() == Type::getPPC_FP128Ty(*Context)) return V; // No constant folding of this. // See if the value can be truncated to float and then reextended. if (Value *V = FitsInFPType(CFP, APFloat::IEEEsingle, Context)) return V; - if (CFP->getType() == Type::DoubleTy) + if (CFP->getType() == Type::getDoubleTy(*Context)) return V; // Won't shrink. if (Value *V = FitsInFPType(CFP, APFloat::IEEEdouble, Context)) return V; @@ -8912,7 +8915,7 @@ Instruction *InstCombiner::visitPtrToInt(PtrToIntInst &CI) { if (TD && CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) { Value *P = InsertNewInstBefore(new PtrToIntInst(CI.getOperand(0), - TD->getIntPtrType(), + TD->getIntPtrType(CI.getContext()), "tmp"), CI); return new TruncInst(P, CI.getType()); } @@ -8930,7 +8933,7 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) { CI.getOperand(0)->getType()->getScalarSizeInBits() > TD->getPointerSizeInBits()) { Value *P = InsertNewInstBefore(new TruncInst(CI.getOperand(0), - TD->getIntPtrType(), + TD->getIntPtrType(CI.getContext()), "tmp"), CI); return new IntToPtrInst(P, CI.getType()); } @@ -8981,7 +8984,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { // If the source and destination are pointers, and this cast is equivalent // to a getelementptr X, 0, 0, 0... turn it into the appropriate gep. // This can enhance SROA and other transforms that want type-safe pointers. - Constant *ZeroUInt = Constant::getNullValue(Type::Int32Ty); + Constant *ZeroUInt = Constant::getNullValue(Type::getInt32Ty(*Context)); unsigned NumZeros = 0; while (SrcElTy != DstElTy && isa<CompositeType>(SrcElTy) && !isa<PointerType>(SrcElTy) && @@ -9007,7 +9010,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { Value *Elem = InsertCastBefore(Instruction::BitCast, Src, DestVTy->getElementType(), CI); return InsertElementInst::Create(UndefValue::get(DestTy), Elem, - Constant::getNullValue(Type::Int32Ty)); + Constant::getNullValue(Type::getInt32Ty(*Context))); } // FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast) } @@ -9017,7 +9020,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { if (SrcVTy->getNumElements() == 1) { if (!isa<VectorType>(DestTy)) { Instruction *Elem = - ExtractElementInst::Create(Src, Constant::getNullValue(Type::Int32Ty)); + ExtractElementInst::Create(Src, Constant::getNullValue(Type::getInt32Ty(*Context))); InsertNewInstBefore(Elem, CI); return CastInst::Create(Instruction::BitCast, Elem, DestTy); } @@ -9401,7 +9404,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { return ReplaceInstUsesWith(SI, FalseVal); } - if (SI.getType() == Type::Int1Ty) { + if (SI.getType() == Type::getInt1Ty(*Context)) { if (ConstantInt *C = dyn_cast<ConstantInt>(TrueVal)) { if (C->getZExtValue()) { // Change: A = select B, true, C --> A = or B, C @@ -9708,7 +9711,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) { // Use an integer load+store unless we can find something better. Type *NewPtrTy = - PointerType::getUnqual(IntegerType::get(Size<<3)); + PointerType::getUnqual(IntegerType::get(*Context, Size<<3)); // Memcpy forces the use of i8* for the source and destination. That means // that if you're using memcpy to move one double around, you'll get a cast @@ -9769,7 +9772,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { // Extract the length and alignment and fill if they are constant. ConstantInt *LenC = dyn_cast<ConstantInt>(MI->getLength()); ConstantInt *FillC = dyn_cast<ConstantInt>(MI->getValue()); - if (!LenC || !FillC || FillC->getType() != Type::Int8Ty) + if (!LenC || !FillC || FillC->getType() != Type::getInt8Ty(*Context)) return 0; uint64_t Len = LenC->getZExtValue(); Alignment = MI->getAlignment(); @@ -9779,7 +9782,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { // memset(s,c,n) -> store s, c (for n=1,2,4,8) if (Len <= 8 && isPowerOf2_32((uint32_t)Len)) { - const Type *ITy = IntegerType::get(Len*8); // n=1 -> i8. + const Type *ITy = IntegerType::get(*Context, Len*8); // n=1 -> i8. Value *Dest = MI->getDest(); Dest = InsertBitCastBefore(Dest, PointerType::getUnqual(ITy), *MI); @@ -9962,14 +9965,14 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { if (ExtractedElts[Idx] == 0) { Instruction *Elt = ExtractElementInst::Create(Idx < 16 ? Op0 : Op1, - ConstantInt::get(Type::Int32Ty, Idx&15, false), "tmp"); + ConstantInt::get(Type::getInt32Ty(*Context), Idx&15, false), "tmp"); InsertNewInstBefore(Elt, CI); ExtractedElts[Idx] = Elt; } // Insert this value into the result vector. Result = InsertElementInst::Create(Result, ExtractedElts[Idx], - ConstantInt::get(Type::Int32Ty, i, false), + ConstantInt::get(Type::getInt32Ty(*Context), i, false), "tmp"); InsertNewInstBefore(cast<Instruction>(Result), CI); } @@ -10073,7 +10076,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) { // If the call and callee calling conventions don't match, this call must // be unreachable, as the call is undefined. new StoreInst(ConstantInt::getTrue(*Context), - UndefValue::get(PointerType::getUnqual(Type::Int1Ty)), + UndefValue::get(PointerType::getUnqual(Type::getInt1Ty(*Context))), OldCall); if (!OldCall->use_empty()) OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType())); @@ -10087,7 +10090,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) { // undef so that we know that this code is not reachable, despite the fact // that we can't modify the CFG here. new StoreInst(ConstantInt::getTrue(*Context), - UndefValue::get(PointerType::getUnqual(Type::Int1Ty)), + UndefValue::get(PointerType::getUnqual(Type::getInt1Ty(*Context))), CS.getInstruction()); if (!CS.getInstruction()->use_empty()) @@ -10162,14 +10165,14 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // Conversion is ok if changing from one pointer type to another or from // a pointer to an integer of the same size. !((isa<PointerType>(OldRetTy) || !TD || - OldRetTy == TD->getIntPtrType()) && + OldRetTy == TD->getIntPtrType(Caller->getContext())) && (isa<PointerType>(NewRetTy) || !TD || - NewRetTy == TD->getIntPtrType()))) + NewRetTy == TD->getIntPtrType(Caller->getContext())))) return false; // Cannot transform this return value. if (!Caller->use_empty() && // void -> non-void is handled specially - NewRetTy != Type::VoidTy && !CastInst::isCastable(NewRetTy, OldRetTy)) + NewRetTy != Type::getVoidTy(*Context) && !CastInst::isCastable(NewRetTy, OldRetTy)) return false; // Cannot transform this return value. if (!CallerPAL.isEmpty() && !Caller->use_empty()) { @@ -10210,8 +10213,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // Converting from one pointer type to another or between a pointer and an // integer of the same size is safe even if we do not have a body. bool isConvertible = ActTy == ParamTy || - (TD && ((isa<PointerType>(ParamTy) || ParamTy == TD->getIntPtrType()) && - (isa<PointerType>(ActTy) || ActTy == TD->getIntPtrType()))); + (TD && ((isa<PointerType>(ParamTy) || + ParamTy == TD->getIntPtrType(Caller->getContext())) && + (isa<PointerType>(ActTy) || + ActTy == TD->getIntPtrType(Caller->getContext())))); if (Callee->isDeclaration() && !isConvertible) return false; } @@ -10302,7 +10307,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { if (Attributes FnAttrs = CallerPAL.getFnAttributes()) attrVec.push_back(AttributeWithIndex::get(~0, FnAttrs)); - if (NewRetTy == Type::VoidTy) + if (NewRetTy == Type::getVoidTy(*Context)) Caller->setName(""); // Void type should not have a name. const AttrListPtr &NewCallerPAL = AttrListPtr::get(attrVec.begin(), @@ -10328,7 +10333,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // Insert a cast of the return type as necessary. Value *NV = NC; if (OldRetTy != NV->getType() && !Caller->use_empty()) { - if (NV->getType() != Type::VoidTy) { + if (NV->getType() != Type::getVoidTy(*Context)) { Instruction::CastOps opcode = CastInst::getCastOpcode(NC, false, OldRetTy, false); NV = NC = CastInst::Create(opcode, NC, OldRetTy, "tmp"); @@ -10348,7 +10353,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { } } - if (Caller->getType() != Type::VoidTy && !Caller->use_empty()) + if (Caller->getType() != Type::getVoidTy(*Context) && !Caller->use_empty()) Caller->replaceAllUsesWith(NV); Caller->eraseFromParent(); RemoveFromWorkList(Caller); @@ -10494,7 +10499,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { setCallingConv(cast<CallInst>(Caller)->getCallingConv()); cast<CallInst>(NewCaller)->setAttributes(NewPAL); } - if (Caller->getType() != Type::VoidTy && !Caller->use_empty()) + if (Caller->getType() != Type::getVoidTy(*Context) && !Caller->use_empty()) Caller->replaceAllUsesWith(NewCaller); Caller->eraseFromParent(); RemoveFromWorkList(Caller); @@ -11044,10 +11049,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { Value *Op = *i; if (TD->getTypeSizeInBits(Op->getType()) > TD->getPointerSizeInBits()) { if (Constant *C = dyn_cast<Constant>(Op)) { - *i = ConstantExpr::getTrunc(C, TD->getIntPtrType()); + *i = ConstantExpr::getTrunc(C, TD->getIntPtrType(GEP.getContext())); MadeChange = true; } else { - Op = InsertCastBefore(Instruction::Trunc, Op, TD->getIntPtrType(), + Op = InsertCastBefore(Instruction::Trunc, Op, + TD->getIntPtrType(GEP.getContext()), GEP); *i = Op; MadeChange = true; @@ -11055,11 +11061,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } else if (TD->getTypeSizeInBits(Op->getType()) < TD->getPointerSizeInBits()) { if (Constant *C = dyn_cast<Constant>(Op)) { - *i = ConstantExpr::getSExt(C, TD->getIntPtrType()); + *i = ConstantExpr::getSExt(C, TD->getIntPtrType(GEP.getContext())); MadeChange = true; } else { - Op = InsertCastBefore(Instruction::SExt, Op, TD->getIntPtrType(), - GEP); + Op = InsertCastBefore(Instruction::SExt, Op, + TD->getIntPtrType(GEP.getContext()), GEP); *i = Op; MadeChange = true; } @@ -11127,7 +11133,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // Convert SO1 to GO1's type. SO1 = InsertCastToIntPtrTy(SO1, GO1->getType(), &GEP, this); } else { - const Type *PT = TD->getIntPtrType(); + const Type *PT = TD->getIntPtrType(GEP.getContext()); SO1 = InsertCastToIntPtrTy(SO1, PT, &GEP, this); GO1 = InsertCastToIntPtrTy(GO1, PT, &GEP, this); } @@ -11238,7 +11244,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()) == TD->getTypeAllocSize(ResElTy)) { Value *Idx[2]; - Idx[0] = Constant::getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::getInt32Ty(*Context)); Idx[1] = GEP.getOperand(1); GetElementPtrInst *NewGEP = GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()); @@ -11254,7 +11260,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // (where tmp = 8*tmp2) into: // getelementptr [100 x double]* %arr, i32 0, i32 %tmp2; bitcast - if (TD && isa<ArrayType>(SrcElTy) && ResElTy == Type::Int8Ty) { + if (TD && isa<ArrayType>(SrcElTy) && ResElTy == Type::getInt8Ty(*Context)) { uint64_t ArrayEltSize = TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()); @@ -11302,7 +11308,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // Insert the new GEP instruction. Value *Idx[2]; - Idx[0] = Constant::getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::getInt32Ty(*Context)); Idx[1] = NewIdx; Instruction *NewGEP = GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()); @@ -11399,7 +11405,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { // Now that I is pointing to the first non-allocation-inst in the block, // insert our getelementptr instruction... // - Value *NullIdx = Constant::getNullValue(Type::Int32Ty); + Value *NullIdx = Constant::getNullValue(Type::getInt32Ty(*Context)); Value *Idx[2]; Idx[0] = NullIdx; Idx[1] = NullIdx; @@ -11437,7 +11443,7 @@ Instruction *InstCombiner::visitFreeInst(FreeInst &FI) { if (isa<UndefValue>(Op)) { // Insert a new store to null because we cannot modify the CFG here. new StoreInst(ConstantInt::getTrue(*Context), - UndefValue::get(PointerType::getUnqual(Type::Int1Ty)), &FI); + UndefValue::get(PointerType::getUnqual(Type::getInt1Ty(*Context))), &FI); return EraseInstFromFunction(FI); } @@ -11532,7 +11538,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, if (Constant *CSrc = dyn_cast<Constant>(CastOp)) if (ASrcTy->getNumElements() != 0) { Value *Idxs[2]; - Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty); + Idxs[0] = Idxs[1] = Constant::getNullValue(Type::getInt32Ty(*Context)); CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2); SrcTy = cast<PointerType>(CastOp->getType()); SrcPTy = SrcTy->getElementType(); @@ -11726,7 +11732,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) { // constants. if (isa<ArrayType>(SrcPTy) || isa<StructType>(SrcPTy)) { // Index through pointer. - Constant *Zero = Constant::getNullValue(Type::Int32Ty); + Constant *Zero = Constant::getNullValue(Type::getInt32Ty(*IC.getContext())); NewGEPIndices.push_back(Zero); while (1) { @@ -12505,7 +12511,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) { return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType())); } return ExtractElementInst::Create(Src, - ConstantInt::get(Type::Int32Ty, SrcIdx, false)); + ConstantInt::get(Type::getInt32Ty(*Context), SrcIdx, false)); } } // FIXME: Canonicalize extractelement(bitcast) -> bitcast(extractelement) @@ -12524,15 +12530,15 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, unsigned NumElts = cast<VectorType>(V->getType())->getNumElements(); if (isa<UndefValue>(V)) { - Mask.assign(NumElts, UndefValue::get(Type::Int32Ty)); + Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(*Context))); return true; } else if (V == LHS) { for (unsigned i = 0; i != NumElts; ++i) - Mask.push_back(ConstantInt::get(Type::Int32Ty, i)); + Mask.push_back(ConstantInt::get(Type::getInt32Ty(*Context), i)); return true; } else if (V == RHS) { for (unsigned i = 0; i != NumElts; ++i) - Mask.push_back(ConstantInt::get(Type::Int32Ty, i+NumElts)); + Mask.push_back(ConstantInt::get(Type::getInt32Ty(*Context), i+NumElts)); return true; } else if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) { // If this is an insert of an extract from some other vector, include it. @@ -12549,7 +12555,7 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, // transitively ok. if (CollectSingleShuffleElements(VecOp, LHS, RHS, Mask, Context)) { // If so, update the mask to reflect the inserted undef. - Mask[InsertedIdx] = UndefValue::get(Type::Int32Ty); + Mask[InsertedIdx] = UndefValue::get(Type::getInt32Ty(*Context)); return true; } } else if (ExtractElementInst *EI = dyn_cast<ExtractElementInst>(ScalarOp)){ @@ -12566,11 +12572,11 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, // If so, update the mask to reflect the inserted value. if (EI->getOperand(0) == LHS) { Mask[InsertedIdx % NumElts] = - ConstantInt::get(Type::Int32Ty, ExtractedIdx); + ConstantInt::get(Type::getInt32Ty(*Context), ExtractedIdx); } else { assert(EI->getOperand(0) == RHS); Mask[InsertedIdx % NumElts] = - ConstantInt::get(Type::Int32Ty, ExtractedIdx+NumElts); + ConstantInt::get(Type::getInt32Ty(*Context), ExtractedIdx+NumElts); } return true; @@ -12595,10 +12601,10 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask, unsigned NumElts = cast<VectorType>(V->getType())->getNumElements(); if (isa<UndefValue>(V)) { - Mask.assign(NumElts, UndefValue::get(Type::Int32Ty)); + Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(*Context))); return V; } else if (isa<ConstantAggregateZero>(V)) { - Mask.assign(NumElts, ConstantInt::get(Type::Int32Ty, 0)); + Mask.assign(NumElts, ConstantInt::get(Type::getInt32Ty(*Context), 0)); return V; } else if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) { // If this is an insert of an extract from some other vector, include it. @@ -12619,7 +12625,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask, RHS = EI->getOperand(0); Value *V = CollectShuffleElements(VecOp, Mask, RHS, Context); Mask[InsertedIdx % NumElts] = - ConstantInt::get(Type::Int32Ty, NumElts+ExtractedIdx); + ConstantInt::get(Type::getInt32Ty(*Context), NumElts+ExtractedIdx); return V; } @@ -12629,7 +12635,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask, // Everything but the extracted element is replaced with the RHS. for (unsigned i = 0; i != NumElts; ++i) { if (i != InsertedIdx) - Mask[i] = ConstantInt::get(Type::Int32Ty, NumElts+i); + Mask[i] = ConstantInt::get(Type::getInt32Ty(*Context), NumElts+i); } return V; } @@ -12647,7 +12653,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask, // Otherwise, can't do anything fancy. Return an identity vector. for (unsigned i = 0; i != NumElts; ++i) - Mask.push_back(ConstantInt::get(Type::Int32Ty, i)); + Mask.push_back(ConstantInt::get(Type::getInt32Ty(*Context), i)); return V; } @@ -12691,14 +12697,14 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) { // Build a new shuffle mask. std::vector<Constant*> Mask; if (isa<UndefValue>(VecOp)) - Mask.assign(NumVectorElts, UndefValue::get(Type::Int32Ty)); + Mask.assign(NumVectorElts, UndefValue::get(Type::getInt32Ty(*Context))); else { assert(isa<ConstantAggregateZero>(VecOp) && "Unknown thing"); - Mask.assign(NumVectorElts, ConstantInt::get(Type::Int32Ty, + Mask.assign(NumVectorElts, ConstantInt::get(Type::getInt32Ty(*Context), NumVectorElts)); } Mask[InsertedIdx] = - ConstantInt::get(Type::Int32Ty, ExtractedIdx); + ConstantInt::get(Type::getInt32Ty(*Context), ExtractedIdx); return new ShuffleVectorInst(EI->getOperand(0), VecOp, ConstantVector::get(Mask)); } @@ -12763,15 +12769,15 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { std::vector<Constant*> Elts; for (unsigned i = 0, e = Mask.size(); i != e; ++i) { if (Mask[i] >= 2*e) - Elts.push_back(UndefValue::get(Type::Int32Ty)); + Elts.push_back(UndefValue::get(Type::getInt32Ty(*Context))); else { if ((Mask[i] >= e && isa<UndefValue>(RHS)) || (Mask[i] < e && isa<UndefValue>(LHS))) { Mask[i] = 2*e; // Turn into undef. - Elts.push_back(UndefValue::get(Type::Int32Ty)); + Elts.push_back(UndefValue::get(Type::getInt32Ty(*Context))); } else { Mask[i] = Mask[i] % e; // Force to LHS. - Elts.push_back(ConstantInt::get(Type::Int32Ty, Mask[i])); + Elts.push_back(ConstantInt::get(Type::getInt32Ty(*Context), Mask[i])); } } } @@ -12827,9 +12833,9 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { std::vector<Constant*> Elts; for (unsigned i = 0, e = NewMask.size(); i != e; ++i) { if (NewMask[i] >= LHSInNElts*2) { - Elts.push_back(UndefValue::get(Type::Int32Ty)); + Elts.push_back(UndefValue::get(Type::getInt32Ty(*Context))); } else { - Elts.push_back(ConstantInt::get(Type::Int32Ty, NewMask[i])); + Elts.push_back(ConstantInt::get(Type::getInt32Ty(*Context), NewMask[i])); } } return new ShuffleVectorInst(LHSSVI->getOperand(0), diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 6125f8b939..ff04cec281 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -435,7 +435,8 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB, << "' folding condition to '" << BranchDir << "': " << *BB->getTerminator()); ++NumFolds; - DestBI->setCondition(ConstantInt::get(Type::Int1Ty, BranchDir)); + DestBI->setCondition(ConstantInt::get(Type::getInt1Ty(BB->getContext()), + BranchDir)); ConstantFoldTerminator(BB); return true; } @@ -757,7 +758,8 @@ bool JumpThreading::ProcessBranchOnLogical(Value *V, BasicBlock *BB, // We can only do the simplification for phi nodes of 'false' with AND or // 'true' with OR. See if we have any entries in the phi for this. unsigned PredNo = ~0U; - ConstantInt *PredCst = ConstantInt::get(Type::Int1Ty, !isAnd); + ConstantInt *PredCst = ConstantInt::get(Type::getInt1Ty(BB->getContext()), + !isAnd); for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { if (PN->getIncomingValue(i) == PredCst) { PredNo = i; @@ -921,8 +923,9 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB, // account for entry from PredBB. DenseMap<Instruction*, Value*> ValueMapping; - BasicBlock *NewBB = - BasicBlock::Create(BB->getName()+".thread", BB->getParent(), BB); + BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), + BB->getName()+".thread", + BB->getParent(), BB); NewBB->moveAfter(PredBB); BasicBlock::iterator BI = BB->begin(); diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 02a33a7889..f4f20e4a52 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -510,7 +510,7 @@ void LICM::sink(Instruction &I) { // Firstly, we create a stack object to hold the value... AllocaInst *AI = 0; - if (I.getType() != Type::VoidTy) { + if (I.getType() != Type::getVoidTy(I.getContext())) { AI = new AllocaInst(I.getType(), 0, I.getName(), I.getParent()->getParent()->getEntryBlock().begin()); CurAST->add(AI); diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index f5e5d350de..792b7537e5 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -702,7 +702,8 @@ void LoopIndexSplit::removeBlocks(BasicBlock *DeadBB, Loop *LP, E = df_end(DN); DI != E; ++DI) { BasicBlock *BB = DI->getBlock(); WorkList.push_back(BB); - BB->replaceAllUsesWith(UndefValue::get(Type::LabelTy)); + BB->replaceAllUsesWith(UndefValue::get( + Type::getLabelTy(DeadBB->getContext()))); } while (!WorkList.empty()) { diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp index 8c5de3e9ce..687304a06d 100644 --- a/lib/Transforms/Scalar/LoopRotation.cpp +++ b/lib/Transforms/Scalar/LoopRotation.cpp @@ -435,7 +435,8 @@ void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) { // Right now original pre-header has two successors, new header and // exit block. Insert new block between original pre-header and // new header such that loop's new pre-header has only one successor. - BasicBlock *NewPreHeader = BasicBlock::Create("bb.nph", + BasicBlock *NewPreHeader = BasicBlock::Create(OrigHeader->getContext(), + "bb.nph", OrigHeader->getParent(), NewHeader); LoopInfo &LI = LPM.getAnalysis<LoopInfo>(); diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 0db3a964fa..9a5a226ebb 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -903,7 +903,8 @@ bool LoopStrengthReduce::ValidScale(bool HasBaseReg, int64_t Scale, for (unsigned i = 0, e = UsersToProcess.size(); i!=e; ++i) { // If this is a load or other access, pass the type of the access in. - const Type *AccessTy = Type::VoidTy; + const Type *AccessTy = + Type::getVoidTy(UsersToProcess[i].Inst->getContext()); if (isAddressUse(UsersToProcess[i].Inst, UsersToProcess[i].OperandValToReplace)) AccessTy = getAccessType(UsersToProcess[i].Inst); @@ -935,7 +936,8 @@ bool LoopStrengthReduce::ValidOffset(bool HasBaseReg, for (unsigned i=0, e = UsersToProcess.size(); i!=e; ++i) { // If this is a load or other access, pass the type of the access in. - const Type *AccessTy = Type::VoidTy; + const Type *AccessTy = + Type::getVoidTy(UsersToProcess[i].Inst->getContext()); if (isAddressUse(UsersToProcess[i].Inst, UsersToProcess[i].OperandValToReplace)) AccessTy = getAccessType(UsersToProcess[i].Inst); @@ -1534,7 +1536,9 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, if (TLI && HaveCommonExprs && AllUsesAreAddresses) { const SCEV *NewCommon = CommonExprs; const SCEV *Imm = SE->getIntegerSCEV(0, ReplacedTy); - MoveImmediateValues(TLI, Type::VoidTy, NewCommon, Imm, true, L, SE); + MoveImmediateValues(TLI, Type::getVoidTy( + L->getLoopPreheader()->getContext()), + NewCommon, Imm, true, L, SE); if (!Imm->isZero()) { bool DoSink = true; @@ -1549,7 +1553,8 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, if (GV || Offset) // Pass VoidTy as the AccessTy to be conservative, because // there could be multiple access types among all the uses. - DoSink = IsImmFoldedIntoAddrMode(GV, Offset, Type::VoidTy, + DoSink = IsImmFoldedIntoAddrMode(GV, Offset, + Type::getVoidTy(L->getLoopPreheader()->getContext()), UsersToProcess, TLI); if (DoSink) { @@ -1580,8 +1585,10 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, Value *CommonBaseV = Constant::getNullValue(ReplacedTy); const SCEV *RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy); - IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty), - SE->getIntegerSCEV(0, Type::Int32Ty), + IVExpr ReuseIV(SE->getIntegerSCEV(0, + Type::getInt32Ty(Preheader->getContext())), + SE->getIntegerSCEV(0, + Type::getInt32Ty(Preheader->getContext())), 0); /// Choose a strength-reduction strategy and prepare for it by creating @@ -1943,7 +1950,7 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond, NewCmpTy = NewCmpLHS->getType(); NewTyBits = SE->getTypeSizeInBits(NewCmpTy); - const Type *NewCmpIntTy = IntegerType::get(NewTyBits); + const Type *NewCmpIntTy = IntegerType::get(Cond->getContext(), NewTyBits); if (RequiresTypeConversion(NewCmpTy, CmpTy)) { // Check if it is possible to rewrite it using // an iv / stride of a smaller integer type. diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 57672f93ca..bbc99f6d44 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -511,7 +511,8 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val, // Insert a conditional branch on LIC to the two preheaders. The original // code is the true version and the new code is the false version. Value *BranchVal = LIC; - if (!isa<ConstantInt>(Val) || Val->getType() != Type::Int1Ty) + if (!isa<ConstantInt>(Val) || + Val->getType() != Type::getInt1Ty(LIC->getContext())) BranchVal = new ICmpInst(InsertPt, ICmpInst::ICMP_EQ, LIC, Val, "tmp"); else if (Val != ConstantInt::getTrue(Val->getContext())) // We want to enter the new loop when the condition is true. @@ -793,7 +794,7 @@ void LoopUnswitch::RemoveBlockIfDead(BasicBlock *BB, // dominates the latch). LPM->deleteSimpleAnalysisValue(Pred->getTerminator(), L); Pred->getTerminator()->eraseFromParent(); - new UnreachableInst(Pred); + new UnreachableInst(BB->getContext(), Pred); // The loop is now broken, remove it from LI. RemoveLoopFromHierarchy(L); @@ -907,12 +908,13 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, // If we know that LIC == Val, or that LIC == NotVal, just replace uses of LIC // in the loop with the appropriate one directly. - if (IsEqual || (isa<ConstantInt>(Val) && Val->getType() == Type::Int1Ty)) { + if (IsEqual || (isa<ConstantInt>(Val) && + Val->getType() == Type::getInt1Ty(Val->getContext()))) { Value *Replacement; if (IsEqual) Replacement = Val; else - Replacement = ConstantInt::get(Type::Int1Ty, + Replacement = ConstantInt::get(Type::getInt1Ty(Val->getContext()), !cast<ConstantInt>(Val)->getZExtValue()); for (unsigned i = 0, e = Users.size(); i != e; ++i) @@ -1024,10 +1026,11 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { break; case Instruction::And: if (isa<ConstantInt>(I->getOperand(0)) && - I->getOperand(0)->getType() == Type::Int1Ty) // constant -> RHS + // constant -> RHS + I->getOperand(0)->getType() == Type::getInt1Ty(I->getContext())) cast<BinaryOperator>(I)->swapOperands(); if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1))) - if (CB->getType() == Type::Int1Ty) { + if (CB->getType() == Type::getInt1Ty(I->getContext())) { if (CB->isOne()) // X & 1 -> X ReplaceUsesOfWith(I, I->getOperand(0), Worklist, L, LPM); else // X & 0 -> 0 @@ -1037,10 +1040,11 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { break; case Instruction::Or: if (isa<ConstantInt>(I->getOperand(0)) && - I->getOperand(0)->getType() == Type::Int1Ty) // constant -> RHS + // constant -> RHS + I->getOperand(0)->getType() == Type::getInt1Ty(I->getContext())) cast<BinaryOperator>(I)->swapOperands(); if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1))) - if (CB->getType() == Type::Int1Ty) { + if (CB->getType() == Type::getInt1Ty(I->getContext())) { if (CB->isOne()) // X | 1 -> 1 ReplaceUsesOfWith(I, I->getOperand(1), Worklist, L, LPM); else // X | 0 -> X diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 224a136648..1c8badcc99 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -38,15 +38,15 @@ STATISTIC(NumMemSetInfer, "Number of memsets inferred"); /// byte store (e.g. i16 0x1234), return null. static Value *isBytewiseValue(Value *V, LLVMContext& Context) { // All byte-wide stores are splatable, even of arbitrary variables. - if (V->getType() == Type::Int8Ty) return V; + if (V->getType() == Type::getInt8Ty(Context)) return V; // Constant float and double values can be handled as integer values if the // corresponding integer value is "byteable". An important case is 0.0. if (ConstantFP *CFP = dyn_cast<ConstantFP>(V)) { - if (CFP->getType() == Type::FloatTy) - V = ConstantExpr::getBitCast(CFP, Type::Int32Ty); - if (CFP->getType() == Type::DoubleTy) - V = ConstantExpr::getBitCast(CFP, Type::Int64Ty); + if (CFP->getType() == Type::getFloatTy(Context)) + V = ConstantExpr::getBitCast(CFP, Type::getInt32Ty(Context)); + if (CFP->getType() == Type::getDoubleTy(Context)) + V = ConstantExpr::getBitCast(CFP, Type::getInt64Ty(Context)); // Don't handle long double formats, which have strange constraints. } @@ -431,7 +431,7 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) { BasicBlock::iterator InsertPt = BI; if (MemSetF == 0) { - const Type *Tys[] = {Type::Int64Ty}; + const Type *Tys[] = {Type::getInt64Ty(SI->getContext())}; MemSetF = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 1); } @@ -440,7 +440,8 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) { StartPtr = Range.StartPtr; // Cast the start ptr to be i8* as memset requires. - const Type *i8Ptr = PointerType::getUnqual(Type::Int8Ty); + const Type *i8Ptr = + PointerType::getUnqual(Type::getInt8Ty(SI->getContext())); if (StartPtr->getType() != i8Ptr) StartPtr = new BitCastInst(StartPtr, i8Ptr, StartPtr->getName(), InsertPt); @@ -448,9 +449,10 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) { Value *Ops[] = { StartPtr, ByteVal, // Start, value // size - ConstantInt::get(Type::Int64Ty, Range.End-Range.Start), + ConstantInt::get(Type::getInt64Ty(SI->getContext()), + Range.End-Range.Start), // align - ConstantInt::get(Type::Int32Ty, Range.Alignment) + ConstantInt::get(Type::getInt32Ty(SI->getContext()), Range.Alignment) }; Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt); DEBUG(cerr << "Replace stores:\n"; diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index f9427bb693..8332f5667f 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -469,8 +469,8 @@ namespace { /// valueNumber - finds the value number for V under the Subtree. If /// there is no value number, returns zero. unsigned valueNumber(Value *V, DomTreeDFS::Node *Subtree) { - if (!(isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) - || V->getType() == Type::VoidTy) return 0; + if (!(isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) || + V->getType() == Type::getVoidTy(V->getContext())) return 0; VNMapType::iterator E = VNMap.end(); VNPair pair(V, 0, Subtree); @@ -496,7 +496,8 @@ namespace { unsigned newVN(Value *V) { assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) && "Bad Value for value numbering."); - assert(V->getType() != Type::VoidTy && "Won't value number a void value"); + assert(V->getType() != Type::getVoidTy(V->getContext()) && + "Won't value number a void value"); Values.push_back(V); @@ -1310,7 +1311,7 @@ namespace { TerminatorInst *TI = BB->getTerminator(); TI->replaceAllUsesWith(UndefValue::get(TI->getType())); TI->eraseFromParent(); - new UnreachableInst(BB); + new UnreachableInst(TI->getContext(), BB); ++NumBlocks; modified = true; } diff --git a/lib/Transforms/Scalar/Reg2Mem.cpp b/lib/Transforms/Scalar/Reg2Mem.cpp index e1075a650d..b0db3177d8 100644 --- a/lib/Transforms/Scalar/Reg2Mem.cpp +++ b/lib/Transforms/Scalar/Reg2Mem.cpp @@ -69,7 +69,8 @@ namespace { CastInst *AllocaInsertionPoint = CastInst::Create(Instruction::BitCast, - Constant::getNullValue(Type::Int32Ty), Type::Int32Ty, + Constant::getNullValue(Type::getInt32Ty(F.getContext())), + Type::getInt32Ty(F.getContext()), "reg2mem alloca point", I); // Find the escaped instructions. But don't create stack slots for diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 80629329b2..c0c44b56fe 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1184,7 +1184,7 @@ void SCCPSolver::visitCallSite(CallSite CS) { if (F == 0 || !F->hasLocalLinkage()) { CallOverdefined: // Void return and not tracking callee, just bail. - if (I->getType() == Type::VoidTy) return; + if (I->getType() == Type::getVoidTy(I->getContext())) return; // Otherwise, if we have a single return value case, and if the function is // a declaration, maybe we can constant fold it. @@ -1350,7 +1350,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { // Look for instructions which produce undef values. - if (I->getType() == Type::VoidTy) continue; + if (I->getType() == Type::getVoidTy(F.getContext())) continue; LatticeVal &LV = getValueState(I); if (!LV.isUndefined()) continue; @@ -1589,7 +1589,7 @@ bool SCCP::runOnFunction(Function &F) { // for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) { Instruction *Inst = BI++; - if (Inst->getType() == Type::VoidTy || + if (Inst->getType() == Type::getVoidTy(F.getContext()) || isa<TerminatorInst>(Inst)) continue; @@ -1760,12 +1760,12 @@ bool IPSCCP::runOnModule(Module &M) { if (&*BB != &F->front()) BlocksToErase.push_back(BB); else - new UnreachableInst(BB); + new UnreachableInst(M.getContext(), BB); } else { for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) { Instruction *Inst = BI++; - if (Inst->getType() == Type::VoidTy) + if (Inst->getType() == Type::getVoidTy(M.getContext())) continue; LatticeVal &IV = Values[Inst]; @@ -1842,7 +1842,7 @@ bool IPSCCP::runOnModule(Module &M) { for (DenseMap<Function*, LatticeVal>::const_iterator I = RV.begin(), E = RV.end(); I != E; ++I) if (!I->second.isOverdefined() && - I->first->getReturnType() != Type::VoidTy) { + I->first->getReturnType() != Type::getVoidTy(M.getContext())) { Function *F = I->first; for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index cacf3dbb4b..6857162dc4 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -306,7 +306,7 @@ bool SROA::performScalarRepl(Function &F) { DOUT << "CONVERT TO SCALAR INTEGER: " << *AI << "\n"; // Create and insert the integer alloca. - const Type *NewTy = IntegerType::get(AllocaSize*8); + const Type *NewTy = IntegerType::get(AI->getContext(), AllocaSize*8); NewAI = new AllocaInst(NewTy, 0, "", AI->getParent()->begin()); ConvertUsesToScalar(AI, NewAI, 0); } @@ -417,7 +417,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI, // expanded itself once the worklist is rerun. // SmallVector<Value*, 8> NewArgs; - NewArgs.push_back(Constant::getNullValue(Type::Int32Ty)); + NewArgs.push_back(Constant::getNullValue( + Type::getInt32Ty(AI->getContext()))); NewArgs.append(GEPI->op_begin()+3, GEPI->op_end()); RepValue = GetElementPtrInst::Create(AllocaToUse, NewArgs.begin(), NewArgs.end(), "", GEPI); @@ -764,7 +765,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, const Type *BytePtrTy = MI->getRawDest()->getType(); bool SROADest = MI->getRawDest() == BCInst; - Constant *Zero = Constant::getNullValue(Type::Int32Ty); + Constant *Zero = Constant::getNullValue(Type::getInt32Ty(MI->getContext())); for (unsigned i = 0, e = NewElts.size(); i != e; ++i) { // If this is a memcpy/memmove, emit a GEP of the other element address. @@ -772,7 +773,8 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, unsigned OtherEltAlign = MemAlignment; if (OtherPtr) { - Value *Idx[2] = { Zero, ConstantInt::get(Type::Int32Ty, i) }; + Value *Idx[2] = { Zero, + ConstantInt::get(Type::getInt32Ty(MI->getContext()), i) }; OtherElt = GetElementPtrInst::Create(OtherPtr, Idx, Idx + 2, OtherPtr->getNameStr()+"."+Twine(i), MI); @@ -873,7 +875,8 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, SROADest ? EltPtr : OtherElt, // Dest ptr SROADest ? OtherElt : EltPtr, // Src ptr ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size - ConstantInt::get(Type::Int32Ty, OtherEltAlign) // Align + // Align + ConstantInt::get(Type::getInt32Ty(MI->getContext()), OtherEltAlign) }; CallInst::Create(TheFn, Ops, Ops + 4, "", MI); } else { @@ -910,7 +913,8 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, // Handle tail padding by extending the operand if (TD->getTypeSizeInBits(SrcVal->getType()) != AllocaSizeBits) SrcVal = new ZExtInst(SrcVal, - IntegerType::get(AllocaSizeBits), "", SI); + IntegerType::get(SI->getContext(), AllocaSizeBits), + "", SI); DOUT << "PROMOTING STORE TO WHOLE ALLOCA: " << *AI << *SI; @@ -942,7 +946,8 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, if (FieldSizeBits != AllocaSizeBits) EltVal = new TruncInst(EltVal, - IntegerType::get(FieldSizeBits), "", SI); + IntegerType::get(SI->getContext(), FieldSizeBits), + "", SI); Value *DestField = NewElts[i]; if (EltVal->getType() == FieldTy) { // Storing to an integer field of this size, just do it. @@ -985,7 +990,8 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, // Truncate down to an integer of the right size. if (ElementSizeBits != AllocaSizeBits) EltVal = new TruncInst(EltVal, - IntegerType::get(ElementSizeBits),"",SI); + IntegerType::get(SI->getContext(), + ElementSizeBits),"",SI); Value *DestField = NewElts[i]; if (EltVal->getType() == ArrayEltTy) { // Storing to an integer field of this size, just do it. @@ -1040,7 +1046,7 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI, } Value *ResultVal = - Constant::getNullValue(IntegerType::get(AllocaSizeBits)); + Constant::getNullValue(IntegerType::get(LI->getContext(), AllocaSizeBits)); for (unsigned i = 0, e = NewElts.size(); i != e; ++i) { // Load the value from the alloca. If the NewElt is an aggregate, cast @@ -1053,7 +1059,8 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI, // Ignore zero sized fields like {}, they obviously contain no data. if (FieldSizeBits == 0) continue; - const IntegerType *FieldIntTy = IntegerType::get(FieldSizeBits); + const IntegerType *FieldIntTy = IntegerType::get(LI->getContext(), + FieldSizeBits); if (!isa<IntegerType>(FieldTy) && !FieldTy->isFloatingPoint() && !isa<VectorType>(FieldTy)) SrcField = new BitCastInst(SrcField, @@ -1186,7 +1193,8 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) { return; if (NumElements == 1) { - GEPI->setOperand(2, Constant::getNullValue(Type::Int32Ty)); + GEPI->setOperand(2, + Constant::getNullValue(Type::getInt32Ty(GEPI->getContext()))); return; } @@ -1198,12 +1206,12 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) { "isone"); // Insert the new GEP instructions, which are properly indexed. SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end()); - Indices[1] = Constant::getNullValue(Type::Int32Ty); + Indices[1] = Constant::getNullValue(Type::getInt32Ty(GEPI->getContext())); Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0), Indices.begin(), Indices.end(), GEPI->getName()+".0", GEPI); - Indices[1] = ConstantInt::get(Type::Int32Ty, 1); + Indices[1] = ConstantInt::get(Type::getInt32Ty(GEPI->getContext()), 1); Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0), Indices.begin(), Indices.end(), @@ -1263,7 +1271,7 @@ static void MergeInType(const Type *In, uint64_t Offset, const Type *&VecTy, unsigned AllocaSize, const TargetData &TD, LLVMContext &Context) { // If this could be contributing to a vector, analyze it. - if (VecTy != Type::VoidTy) { // either null or a vector type. + if (VecTy != Type::getVoidTy(Context)) { // either null or a vector type. // If the In type is a vector that is the same size as the alloca, see if it // matches the existing VecTy. @@ -1276,7 +1284,8 @@ static void MergeInType(const Type *In, uint64_t Offset, const Type *&VecTy, VecTy = VInTy; return; } - } else if (In == Type::FloatTy || In == Type::DoubleTy || + } else if (In == Type::getFloatTy(Context) || + In == Type::getDoubleTy(Context) || (isa<IntegerType>(In) && In->getPrimitiveSizeInBits() >= 8 && isPowerOf2_32(In->getPrimitiveSizeInBits()))) { // If we're accessing something that could be an element of a vector, see @@ -1297,7 +1306,7 @@ static void MergeInType(const Type *In, uint64_t Offset, const Type *&VecTy, // Otherwise, we have a case that we can't handle with an optimized vector // form. We can still turn this into a large integer. - VecTy = Type::VoidTy; + VecTy = Type::getVoidTy(Context); } /// CanConvertToScalar - V is a pointer. If we can convert the pointee and all @@ -1548,9 +1557,8 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType, assert(EltSize*Elt == Offset && "Invalid modulus in validity checking"); } // Return the element extracted out of it. - Value *V = Builder.CreateExtractElement(FromVal, - ConstantInt::get(Type::Int32Ty,Elt), - "tmp"); + Value *V = Builder.CreateExtractElement(FromVal, ConstantInt::get( + Type::getInt32Ty(FromVal->getContext()), Elt), "tmp"); if (V->getType() != ToType) V = Builder.CreateBitCast(V, ToType, "tmp"); return V; @@ -1613,10 +1621,12 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType, unsigned LIBitWidth = TD->getTypeSizeInBits(ToType); if (LIBitWidth < NTy->getBitWidth()) FromVal = - Builder.CreateTrunc(FromVal, IntegerType::get(LIBitWidth), "tmp"); + Builder.CreateTrunc(FromVal, IntegerType::get(FromVal->getContext(), + LIBitWidth), "tmp"); else if (LIBitWidth > NTy->getBitWidth()) FromVal = - Builder.CreateZExt(FromVal, IntegerType::get(LIBitWidth), "tmp"); + Builder.CreateZExt(FromVal, IntegerType::get(FromVal->getContext(), + LIBitWidth), "tmp"); // If the result is an integer, this is a trunc or bitcast. if (isa<IntegerType>(ToType)) { @@ -1668,7 +1678,7 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old, SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp"); SV = Builder.CreateInsertElement(Old, SV, - ConstantInt::get(Type::Int32Ty, Elt), + ConstantInt::get(Type::getInt32Ty(SV->getContext()), Elt), "tmp"); return SV; } @@ -1701,9 +1711,10 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old, unsigned SrcStoreWidth = TD->getTypeStoreSizeInBits(SV->getType()); unsigned DestStoreWidth = TD->getTypeStoreSizeInBits(AllocaType); if (SV->getType()->isFloatingPoint() || isa<VectorType>(SV->getType())) - SV = Builder.CreateBitCast(SV, IntegerType::get(SrcWidth), "tmp"); + SV = Builder.CreateBitCast(SV, + IntegerType::get(SV->getContext(),SrcWidth), "tmp"); else if (isa<PointerType>(SV->getType())) - SV = Builder.CreatePtrToInt(SV, TD->getIntPtrType(), "tmp"); + SV = Builder.CreatePtrToInt(SV, TD->getIntPtrType(SV->getContext()), "tmp"); // Zero extend or truncate the value if needed. if (SV->getType() != AllocaType) { diff --git a/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/lib/Transforms/Scalar/SimplifyCFGPass.cpp index 3ea6ddd67c..5de79c49cf 100644 --- a/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -65,7 +65,7 @@ static void ChangeToUnreachable(Instruction *I, LLVMContext &Context) { for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) (*SI)->removePredecessor(BB); - new UnreachableInst(I); + new UnreachableInst(I->getContext(), I); // All instructions after this are dead. BasicBlock::iterator BBI = I, BBE = BB->end(); diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 2ac980fbe6..64013d538f 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -126,7 +126,7 @@ public: /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*. Value *LibCallOptimization::CastToCStr(Value *V, IRBuilder<> &B) { return - B.CreateBitCast(V, PointerType::getUnqual(Type::Int8Ty), "cstr"); + B.CreateBitCast(V, PointerType::getUnqual(Type::getInt8Ty(*Context)), "cstr"); } /// EmitStrLen - Emit a call to the strlen function to the builder, for the @@ -139,8 +139,8 @@ Value *LibCallOptimization::EmitStrLen(Value *Ptr, IRBuilder<> &B) { Attribute::NoUnwind); Constant *StrLen =M->getOrInsertFunction("strlen", AttrListPtr::get(AWI, 2), - TD->getIntPtrType(), - PointerType::getUnqual(Type::Int8Ty), + TD->getIntPtrType(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), NULL); CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen"); if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts())) @@ -159,7 +159,7 @@ Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len, Tys[0] = Len->getType(); Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1); return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len, - ConstantInt::get(Type::Int32Ty, Align)); + ConstantInt::get(Type::getInt32Ty(*Context), Align)); } /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is @@ -171,9 +171,9 @@ Value *LibCallOptimization::EmitMemChr(Value *Ptr, Value *Val, AWI = AttributeWithIndex::get(~0u, Attribute::ReadOnly | Attribute::NoUnwind); Value *MemChr = M->getOrInsertFunction("memchr", AttrListPtr::get(&AWI, 1), - PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - Type::Int32Ty, TD->getIntPtrType(), + PointerType::getUnqual(Type::getInt8Ty(*Context)), + PointerType::getUnqual(Type::getInt8Ty(*Context)), + Type::getInt32Ty(*Context), TD->getIntPtrType(*Context), NULL); CallInst *CI = B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr"); @@ -194,10 +194,10 @@ Value *LibCallOptimization::EmitMemCmp(Value *Ptr1, Value *Ptr2, Attribute::NoUnwind); Value *MemCmp = M->getOrInsertFunction("memcmp", AttrListPtr::get(AWI, 3), - Type::Int32Ty, - PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), - TD->getIntPtrType(), NULL); + Type::getInt32Ty(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), + PointerType::getUnqual(Type::getInt8Ty(*Context)), + TD->getIntPtrType(*Context), NULL); CallInst *CI = B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B), Len, "memcmp"); @@ -215,7 +215,7 @@ Value *LibCallOptimization::EmitMemSet(Value *Dst, Value *Val, const Type *Tys[1]; Tys[0] = Len->getType(); Value *MemSet = Intrinsic::getDeclaration(M, IID, Tys, 1); - Value *Align = ConstantInt::get(Type::Int32Ty, 1); + Value *Align = ConstantInt::get(Type::getInt32Ty(*Context), 1); return B.CreateCall4(MemSet, CastToCStr(Dst, B), Val, Len, Align); } @@ -226,12 +226,12 @@ Value *LibCallOptimization::EmitMemSet(Value *Dst, Value *Val, Value *LibCallOptimization::EmitUnaryFloatFnCall(Value *Op, const char *Name, IRBuilder<> &B) { char NameBuffer[20]; - if (Op->getType() != Type::DoubleTy) { + if (Op->getType() != Type::getDoubleTy(*Context)) { // If we need to add a suffix, copy into NameBuffer. unsigned NameLen = strlen(Name); assert(NameLen < sizeof(NameBuffer)-2); memcpy(NameBuffer, Name, NameLen); - if (Op->getType() == Type::FloatTy) + if (Op->getType() == Type::getFloatTy(*Context)) NameBuffer[NameLen] = 'f'; // floorf else NameBuffer[NameLen] = 'l'; // floorl @@ -254,10 +254,10 @@ Value *LibCallOptimization::EmitUnaryFloatFnCall(Value *Op, const char *Name, /// is an integer. void LibCallOptimization::EmitPutChar(Value *Char, IRBuilder<> &B) { Module *M = Caller->getParent(); - Value *PutChar = M->getOrInsertFunction("putchar", Type::Int32Ty, - Type::Int32Ty, NULL); + Value *PutChar = M->getOrInsertFunction("putchar", Type::getInt32Ty(*Context), + Type::getInt32Ty(*Context), NULL); CallInst *CI = B.CreateCall(PutChar, - B.CreateIntCast(Char, Type::Int32Ty, "chari"), + B.CreateIntCast(Char, Type::getInt32Ty(*Context), "chari"), "putchar"); if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts())) @@ -273,8 +273,8 @@ void LibCallOptimization::EmitPutS(Value *Str, IRBuilder<> &B) { AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI, 2), - Type::Int32Ty, - PointerType::getUnqual(Type::Int8Ty), + Type::getInt32Ty(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), NULL); CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts"); if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts())) @@ -291,12 +291,12 @@ void LibCallOptimization::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B) { AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); Constant *F; if (isa<PointerType>(File->getType())) - F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI, 2), Type::Int32Ty, - Type::Int32Ty, File->getType(), NULL); + F = M->getOrInsertFunction("fputc", AttrListPtr::get(AWI, 2), Type::getInt32Ty(*Context), + Type::getInt32Ty(*Context), File->getType(), NULL); else - F = M->getOrInsertFunction("fputc", Type::Int32Ty, Type::Int32Ty, + F = M->getOrInsertFunction("fputc", Type::getInt32Ty(*Context), Type::getInt32Ty(*Context), File->getType(), NULL); - Char = B.CreateIntCast(Char, Type::Int32Ty, "chari"); + Char = B.CreateIntCast(Char, Type::getInt32Ty(*Context), "chari"); CallInst *CI = B.CreateCall2(F, Char, File, "fputc"); if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) @@ -313,12 +313,12 @@ void LibCallOptimization::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B) { AWI[2] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); Constant *F; if (isa<PointerType>(File->getType())) - F = M->getOrInsertFunction("fputs", AttrListPtr::get(AWI, 3), Type::Int32Ty, - PointerType::getUnqual(Type::Int8Ty), + F = M->getOrInsertFunction("fputs", AttrListPtr::get(AWI, 3), Type::getInt32Ty(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), File->getType(), NULL); else - F = M->getOrInsertFunction("fputs", Type::Int32Ty, - PointerType::getUnqual(Type::Int8Ty), + F = M->getOrInsertFunction("fputs", Type::getInt32Ty(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), File->getType(), NULL); CallInst *CI = B.CreateCall2(F, CastToCStr(Str, B), File, "fputs"); @@ -338,17 +338,17 @@ void LibCallOptimization::EmitFWrite(Value *Ptr, Value *Size, Value *File, Constant *F; if (isa<PointerType>(File->getType())) F = M->getOrInsertFunction("fwrite", AttrListPtr::get(AWI, 3), - TD->getIntPtrType(), - PointerType::getUnqual(Type::Int8Ty), - TD->getIntPtrType(), TD->getIntPtrType(), + TD->getIntPtrType(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), + TD->getIntPtrType(*Context), TD->getIntPtrType(*Context), File->getType(), NULL); else - F = M->getOrInsertFunction("fwrite", TD->getIntPtrType(), - PointerType::getUnqual(Type::Int8Ty), - TD->getIntPtrType(), TD->getIntPtrType(), + F = M->getOrInsertFunction("fwrite", TD->getIntPtrType(*Context), + PointerType::getUnqual(Type::getInt8Ty(*Context)), + TD->getIntPtrType(*Context), TD->getIntPtrType(*Context), File->getType(), NULL); CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size, - ConstantInt::get(TD->getIntPtrType(), 1), File); + ConstantInt::get(TD->getIntPtrType(*Context), 1), File); if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); @@ -449,7 +449,8 @@ static uint64_t GetStringLengthH(Value *V, SmallPtrSet<PHINode*, 32> &PHIs) { // Must be a Constant Array ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit); - if (!Array || Array->getType()->getElementType() != Type::Int8Ty) + if (!Array || + Array->getType()->getElementType() != Type::getInt8Ty(V->getContext())) return false; // Get the number of elements in the array @@ -528,7 +529,7 @@ struct VISIBILITY_HIDDEN ExitOpt : public LibCallOptimization { BasicBlock::iterator Dead = CI, E = OldTI; ++Dead; while (Dead != E) { BasicBlock::iterator Next = next(Dead); - if (Dead->getType() != Type::VoidTy) + if (Dead->getType() != Type::getVoidTy(*Context)) Dead->replaceAllUsesWith(UndefValue::get(Dead->getType())); Dead->eraseFromParent(); Dead = Next; @@ -555,7 +556,7 @@ struct VISIBILITY_HIDDEN StrCatOpt : public LibCallOptimization { // Verify the "strcat" function prototype. const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 2 || - FT->getReturnType() != PointerType::getUnqual(Type::Int8Ty) || + FT->getReturnType() != PointerType::getUnqual(Type::getInt8Ty(*Context)) || FT->getParamType(0) != FT->getReturnType() || FT->getParamType(1) != FT->getReturnType()) return 0; @@ -590,7 +591,7 @@ struct VISIBILITY_HIDDEN StrCatOpt : public LibCallOptimization { // We have enough information to now generate the memcpy call to do the // concatenation for us. Make a memcpy to copy the nul byte with align = 1. EmitMemCpy(CpyDst, Src, - ConstantInt::get(TD->getIntPtrType(), Len+1), 1, B); + ConstantInt::get(TD->getIntPtrType(*Context), Len+1), 1, B); } }; @@ -602,7 +603,7 @@ struct VISIBILITY_HIDDEN StrNCatOpt : public StrCatOpt { // Verify the "strncat" function prototype. const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 3 || - FT->getReturnType() != PointerType::getUnqual(Type::Int8Ty) || + FT->getReturnType() != PointerType::getUnqual(Type::getInt8Ty(*Context)) || FT->getParamType(0) != FT->getReturnType() || FT->getParamType(1) != FT->getReturnType() || !isa<IntegerType>(FT->getParamType(2))) @@ -647,7 +648,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { // Verify the "strchr" function prototype. const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 2 || - FT->getReturnType() != PointerType::getUnqual(Type::Int8Ty) || + FT->getReturnType() != PointerType::getUnqual(Type::getInt8Ty(*Context)) || FT->getParamType(0) != FT->getReturnType()) return 0; @@ -658,11 +659,11 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getOperand(2)); if (CharC == 0) { uint64_t Len = GetStringLength(SrcStr); - if (Len == 0 || FT->getParamType(1) != Type::Int32Ty) // memchr needs i32. + if (Len == 0 || FT->getParamType(1) != Type::getInt32Ty(*Context)) // memchr needs i32. return 0; return EmitMemChr(SrcStr, CI->getOperand(2), // include nul. - ConstantInt::get(TD->getIntPtrType(), Len), B); + ConstantInt::get(TD->getIntPtrType(*Context), Len), B); } // Otherwise, the character is a constant, see if the first argument is @@ -687,7 +688,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { } // strchr(s+n,c) -> gep(s+n+i,c) - Value *Idx = ConstantInt::get(Type::Int64Ty, i); + Value *Idx = ConstantInt::get(Type::getInt64Ty(*Context), i); return B.CreateGEP(SrcStr, Idx, "strchr"); } }; @@ -699,9 +700,9 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization { virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { // Verify the "strcmp" function prototype. const FunctionType *FT = Callee->getFunctionType(); - if (FT->getNumParams() != 2 || FT->getReturnType() != Type::Int32Ty || + if (FT->getNumParams() != 2 || FT->getReturnType() != Type::getInt32Ty(*Context) || FT->getParamType(0) != FT->getParamType(1) || - FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty)) + FT->getParamType(0) != PointerType::getUnqual(Type::getInt8Ty(*Context))) return 0; Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2); @@ -728,7 +729,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization { uint64_t Len2 = GetStringLength(Str2P); if (Len1 && Len2) { return EmitMemCmp(Str1P, Str2P, - ConstantInt::get(TD->getIntPtrType(), + ConstantInt::get(TD->getIntPtrType(*Context), std::min(Len1, Len2)), B); } @@ -743,9 +744,9 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization { virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { // Verify the "strncmp" function prototype. const FunctionType *FT = Callee->getFunctionType(); - if (FT->getNumParams() != 3 || FT->getReturnType() != Type::Int32Ty || + if (FT->getNumParams() != 3 || FT->getReturnType() != Type::getInt32Ty(*Context) || FT->getParamType(0) != FT->getParamType(1) || - FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty) || + FT->getParamType(0) != PointerType::getUnqual(Type::getInt8Ty(*Context)) || !isa<IntegerType>(FT->getParamType(2))) return 0; @@ -791,7 +792,7 @@ struct VISIBILITY_HIDDEN StrCpyOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 2 || FT->getReturnType() != FT->getParamType(0) || FT->getParamType(0) != FT->getParamType(1) || - FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty)) + FT->getParamType(0) != PointerType::getUnqual(Type::getInt8Ty(*Context))) return 0; Value *Dst = CI->getOperand(1), *Src = CI->getOperand(2); @@ -805,7 +806,7 @@ struct VISIBILITY_HIDDEN StrCpyOpt : public LibCallOptimization { // We have enough information to now generate the memcpy call to do the // concatenation for us. Make a memcpy to copy the nul byte with align = 1. EmitMemCpy(Dst, Src, - ConstantInt::get(TD->getIntPtrType(), Len), 1, B); + ConstantInt::get(TD->getIntPtrType(*Context), Len), 1, B); return Dst; } }; @@ -818,7 +819,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) || FT->getParamType(0) != FT->getParamType(1) || - FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty) || + FT->getParamType(0) != PointerType::getUnqual(Type::getInt8Ty(*Context)) || !isa<IntegerType>(FT->getParamType(2))) return 0; @@ -833,7 +834,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization { if (SrcLen == 0) { // strncpy(x, "", y) -> memset(x, '\0', y, 1) - EmitMemSet(Dst, ConstantInt::get(Type::Int8Ty, '\0'), LenOp, B); + EmitMemSet(Dst, ConstantInt::get(Type::getInt8Ty(*Context), '\0'), LenOp, B); return Dst; } @@ -850,7 +851,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization { // strncpy(x, s, c) -> memcpy(x, s, c, 1) [s and c are constant] EmitMemCpy(Dst, Src, - ConstantInt::get(TD->getIntPtrType(), Len), 1, B); + ConstantInt::get(TD->getIntPtrType(*Context), Len), 1, B); return Dst; } @@ -863,7 +864,7 @@ struct VISIBILITY_HIDDEN StrLenOpt : public LibCallOptimization { virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 1 || - FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty) || + FT->getParamType(0) != PointerType::getUnqual(Type::getInt8Ty(*Context)) || !isa<IntegerType>(FT->getReturnType())) return 0; @@ -912,7 +913,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() != 3 || !isa<PointerType>(FT->getParamType(0)) || !isa<PointerType>(FT->getParamType(1)) || - FT->getReturnType() != Type::Int32Ty) + FT->getReturnType() != Type::getInt32Ty(*Context)) return 0; Value *LHS = CI->getOperand(1), *RHS = CI->getOperand(2); @@ -938,7 +939,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization { // memcmp(S1,S2,4) != 0 -> (*(int*)LHS ^ *(int*)RHS) != 0 if ((Len == 2 || Len == 4) && IsOnlyUsedInZeroEqualityComparison(CI)) { const Type *PTy = PointerType::getUnqual(Len == 2 ? - Type::Int16Ty : Type::Int32Ty); + Type::getInt16Ty(*Context) : Type::getInt32Ty(*Context)); LHS = B.CreateBitCast(LHS, PTy, "tmp"); RHS = B.CreateBitCast(RHS, PTy, "tmp"); LoadInst *LHSV = B.CreateLoad(LHS, "lhsv"); @@ -960,7 +961,7 @@ struct VISIBILITY_HIDDEN MemCpyOpt : public LibCallOptimization { if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) || !isa<PointerType>(FT->getParamType(0)) || !isa<PointerType>(FT->getParamType(1)) || - FT->getParamType(2) != TD->getIntPtrType()) + FT->getParamType(2) != TD->getIntPtrType(*Context)) return 0; // memcpy(x, y, n) -> llvm.memcpy(x, y, n, 1) @@ -978,19 +979,19 @@ struct VISIBILITY_HIDDEN MemMoveOpt : public LibCallOptimization { if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) || !isa<PointerType>(FT->getParamType(0)) || !isa<PointerType>(FT->getParamType(1)) || - FT->getParamType(2) != TD->getIntPtrType()) + FT->getParamType(2) != TD->getIntPtrType(*Context)) return 0; // memmove(x, y, n) -> llvm.memmove(x, y, n, 1) Module *M = Caller->getParent(); Intrinsic::ID IID = Intrinsic::memmove; const Type *Tys[1]; - Tys[0] = TD->getIntPtrType(); + Tys[0] = TD->getIntPtrType(*Context); Value *MemMove = Intrinsic::getDeclaration(M, IID, Tys, 1); Value *Dst = CastToCStr(CI->getOperand(1), B); Value *Src = CastToCStr(CI->getOperand(2), B); Value *Size = CI->getOperand(3); - Value *Align = ConstantInt::get(Type::Int32Ty, 1); + Value *Align = ConstantInt::get(Type::getInt32Ty(*Context), 1); B.CreateCall4(MemMove, Dst, Src, Size, Align); return CI->getOperand(1); } @@ -1005,11 +1006,11 @@ struct VISIBILITY_HIDDEN MemSetOpt : public LibCallOptimization { if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) || !isa<PointerType>(FT->getParamType(0)) || !isa<IntegerType>(FT->getParamType(1)) || - FT->getParamType(2) != TD->getIntPtrType()) + FT->getParamType(2) != TD->getIntPtrType(*Context)) return 0; // memset(p, v, n) -> llvm.memset(p, v, n, 1) - Value *Val = B.CreateIntCast(CI->getOperand(2), Type::Int8Ty, false); + Value *Val = B.CreateIntCast(CI->getOperand(2), Type::getInt8Ty(*Context), false); EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), B); return CI->getOperand(1); } @@ -1088,28 +1089,28 @@ struct VISIBILITY_HIDDEN Exp2Opt : public LibCallOptimization { Value *LdExpArg = 0; if (SIToFPInst *OpC = dyn_cast<SIToFPInst>(Op)) { if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() <= 32) - LdExpArg = B.CreateSExt(OpC->getOperand(0), Type::Int32Ty, "tmp"); + LdExpArg = B.CreateSExt(OpC->getOperand(0), Type::getInt32Ty(*Context), "tmp"); } else if (UIToFPInst *OpC = dyn_cast<UIToFPInst>(Op)) { if (OpC->getOperand(0)->getType()->getPrimitiveSizeInBits() < 32) - LdExpArg = B.CreateZExt(OpC->getOperand(0), Type::Int32Ty, "tmp"); + LdExpArg = B.CreateZExt(OpC->getOperand(0), Type::getInt32Ty(*Context), "tmp"); } if (LdExpArg) { const char *Name; - if (Op->getType() == Type::FloatTy) + if (Op->getType() == Type::getFloatTy(*Context)) Name = "ldexpf"; - else if (Op->getType() == Type::DoubleTy) + else if (Op->getType() == Type::getDoubleTy(*Context)) Name = "ldexp"; else Name = "ldexpl"; Constant *One = ConstantFP::get(*Context, APFloat(1.0f)); - if (Op->getType() != Type::FloatTy) + if (Op->getType() != Type::getFloatTy(*Context)) One = ConstantExpr::getFPExtend(One, Op->getType()); Module *M = Caller->getParent(); Value *Callee = M->getOrInsertFunction(Name, Op->getType(), - Op->getType(), Type::Int32Ty,NULL); + Op->getType(), Type::getInt32Ty(*Context),NULL); CallInst *CI = B.CreateCall2(Callee, One, LdExpArg); if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); @@ -1126,19 +1127,19 @@ struct VISIBILITY_HIDDEN Exp2Opt : public LibCallOptimization { struct VISIBILITY_HIDDEN UnaryDoubleFPOpt : public LibCallOptimization { virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { const FunctionType *FT = Callee->getFunctionType(); - if (FT->getNumParams() != 1 || FT->getReturnType() != Type::DoubleTy || - FT->getParamType(0) != Type::DoubleTy) + if (FT->getNumParams() != 1 || FT->getReturnType() != Type::getDoubleTy(*Context) || + FT->getParamType(0) != Type::getDoubleTy(*Context)) return 0; // If this is something like 'floor((double)floatval)', convert to floorf. FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getOperand(1)); - if (Cast == 0 || Cast->getOperand(0)->getType() != Type::FloatTy) + if (Cast == 0 || Cast->getOperand(0)->getType() != Type::getFloatTy(*Context)) return 0; // floor((double)floatval) -> (double)floorf(floatval) Value *V = Cast->getOperand(0); V = EmitUnaryFloatFnCall(V, Callee->getName().data(), B); - return B.CreateFPExt(V, Type::DoubleTy); + return B.CreateFPExt(V, Type::getDoubleTy(*Context)); } }; @@ -1154,7 +1155,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); // Just make sure this has 2 arguments of the same FP type, which match the // result type. - if (FT->getNumParams() != 1 || FT->getReturnType() != Type::Int32Ty || + if (FT->getNumParams() != 1 || FT->getReturnType() != Type::getInt32Ty(*Context) || !isa<IntegerType>(FT->getParamType(0))) return 0; @@ -1164,7 +1165,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { if (CI->getValue() == 0) // ffs(0) -> 0. return Constant::getNullValue(CI->getType()); - return ConstantInt::get(Type::Int32Ty, // ffs(c) -> cttz(c)+1 + return ConstantInt::get(Type::getInt32Ty(*Context), // ffs(c) -> cttz(c)+1 CI->getValue().countTrailingZeros()+1); } @@ -1174,10 +1175,10 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { Intrinsic::cttz, &ArgType, 1); Value *V = B.CreateCall(F, Op, "cttz"); V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp"); - V = B.CreateIntCast(V, Type::Int32Ty, false, "tmp"); + V = B.CreateIntCast(V, Type::getInt32Ty(*Context), false, "tmp"); Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType), "tmp"); - return B.CreateSelect(Cond, V, ConstantInt::get(Type::Int32Ty, 0)); + return B.CreateSelect(Cond, V, ConstantInt::get(Type::getInt32Ty(*Context), 0)); } }; @@ -1189,14 +1190,14 @@ struct VISIBILITY_HIDDEN IsDigitOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); // We require integer(i32) if (FT->getNumParams() != 1 || !isa<IntegerType>(FT->getReturnType()) || - FT->getParamType(0) != Type::Int32Ty) + FT->getParamType(0) != Type::getInt32Ty(*Context)) return 0; // isdigit(c) -> (c-'0') <u 10 Value *Op = CI->getOperand(1); - Op = B.CreateSub(Op, ConstantInt::get(Type::Int32Ty, '0'), + Op = B.CreateSub(Op, ConstantInt::get(Type::getInt32Ty(*Context), '0'), "isdigittmp"); - Op = B.CreateICmpULT(Op, ConstantInt::get(Type::Int32Ty, 10), + Op = B.CreateICmpULT(Op, ConstantInt::get(Type::getInt32Ty(*Context), 10), "isdigit"); return B.CreateZExt(Op, CI->getType()); } @@ -1210,12 +1211,12 @@ struct VISIBILITY_HIDDEN IsAsciiOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); // We require integer(i32) if (FT->getNumParams() != 1 || !isa<IntegerType>(FT->getReturnType()) || - FT->getParamType(0) != Type::Int32Ty) + FT->getParamType(0) != Type::getInt32Ty(*Context)) return 0; // isascii(c) -> c <u 128 Value *Op = CI->getOperand(1); - Op = B.CreateICmpULT(Op, ConstantInt::get(Type::Int32Ty, 128), + Op = B.CreateICmpULT(Op, ConstantInt::get(Type::getInt32Ty(*Context), 128), "isascii"); return B.CreateZExt(Op, CI->getType()); } @@ -1251,7 +1252,7 @@ struct VISIBILITY_HIDDEN ToAsciiOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); // We require i32(i32) if (FT->getNumParams() != 1 || FT->getReturnType() != FT->getParamType(0) || - FT->getParamType(0) != Type::Int32Ty) + FT->getParamType(0) != Type::getInt32Ty(*Context)) return 0; // isascii(c) -> c & 0x7f @@ -1273,7 +1274,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { const FunctionType *FT = Callee->getFunctionType(); if (FT->getNumParams() < 1 || !isa<PointerType>(FT->getParamType(0)) || !(isa<IntegerType>(FT->getReturnType()) || - FT->getReturnType() == Type::VoidTy)) + FT->getReturnType() == Type::getVoidTy(*Context))) return 0; // Check for a fixed format string. @@ -1288,7 +1289,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { // printf("x") -> putchar('x'), even for '%'. if (FormatStr.size() == 1) { - EmitPutChar(ConstantInt::get(Type::Int32Ty, FormatStr[0]), B); + EmitPutChar(ConstantInt::get(Type::getInt32Ty(*Context), FormatStr[0]), B); return CI->use_empty() ? (Value*)CI : ConstantInt::get(CI->getType(), 1); } @@ -1299,7 +1300,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { // Create a string literal with no \n on it. We expect the constant merge // pass to be run after this pass, to merge duplicate strings. FormatStr.erase(FormatStr.end()-1); - Constant *C = ConstantArray::get(FormatStr, true); + Constant *C = ConstantArray::get(*Context, FormatStr, true); C = new GlobalVariable(*Callee->getParent(), C->getType(), true, GlobalVariable::InternalLinkage, C, "str"); EmitPutS(C, B); @@ -1354,7 +1355,7 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { // sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1) EmitMemCpy(CI->getOperand(1), CI->getOperand(2), // Copy the nul byte. - ConstantInt::get(TD->getIntPtrType(), FormatStr.size()+1),1,B); + ConstantInt::get(TD->getIntPtrType(*Context), FormatStr.size()+1),1,B); return ConstantInt::get(CI->getType(), FormatStr.size()); } @@ -1367,11 +1368,11 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { if (FormatStr[1] == 'c') { // sprintf(dst, "%c", chr) --> *(i8*)dst = chr; *((i8*)dst+1) = 0 if (!isa<IntegerType>(CI->getOperand(3)->getType())) return 0; - Value *V = B.CreateTrunc(CI->getOperand(3), Type::Int8Ty, "char"); + Value *V = B.CreateTrunc(CI->getOperand(3), Type::getInt8Ty(*Context), "char"); Value *Ptr = CastToCStr(CI->getOperand(1), B); B.CreateStore(V, Ptr); - Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::Int32Ty, 1), "nul"); - B.CreateStore(Constant::getNullValue(Type::Int8Ty), Ptr); + Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::getInt32Ty(*Context), 1), "nul"); + B.CreateStore(Constant::getNullValue(Type::getInt8Ty(*Context)), Ptr); return ConstantInt::get(CI->getType(), 1); } @@ -1444,7 +1445,7 @@ struct VISIBILITY_HIDDEN FPutsOpt : public LibCallOptimization { uint64_t Len = GetStringLength(CI->getOperand(1)); if (!Len) return 0; EmitFWrite(CI->getOperand(1), - ConstantInt::get(TD->getIntPtrType(), Len-1), + ConstantInt::get(TD->getIntPtrType(*Context), Len-1), CI->getOperand(2), B); return CI; // Known to have no uses (see above). } @@ -1473,7 +1474,7 @@ struct VISIBILITY_HIDDEN FPrintFOpt : public LibCallOptimization { if (FormatStr[i] == '%') // Could handle %% -> % if we cared. return 0; // We found a format specifier. - EmitFWrite(CI->getOperand(2), ConstantInt::get(TD->getIntPtrType(), + EmitFWrite(CI->getOperand(2), ConstantInt::get(TD->getIntPtrType(*Context), FormatStr.size()), CI->getOperand(1), B); return ConstantInt::get(CI->getType(), FormatStr.size()); diff --git a/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp index 34ee57c9b9..b84a1f04ca 100644 --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -394,7 +394,7 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry, // create the new entry block, allowing us to branch back to the old entry. if (OldEntry == 0) { OldEntry = &F->getEntryBlock(); - BasicBlock *NewEntry = BasicBlock::Create("", F, OldEntry); + BasicBlock *NewEntry = BasicBlock::Create(F->getContext(), "", F, OldEntry); NewEntry->takeName(OldEntry); OldEntry->setName("tailrecurse"); BranchInst::Create(OldEntry, NewEntry); diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 4e1015968d..3072cee61c 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -251,11 +251,11 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) { Value *RetVal = 0; // Create a value to return... if the function doesn't return null... - if (BB->getParent()->getReturnType() != Type::VoidTy) + if (BB->getParent()->getReturnType() != Type::getVoidTy(TI->getContext())) RetVal = Constant::getNullValue(BB->getParent()->getReturnType()); // Create the return... - NewTI = ReturnInst::Create(RetVal); + NewTI = ReturnInst::Create(TI->getContext(), RetVal); } break; @@ -360,8 +360,8 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, unsigned NumPreds, const char *Suffix, Pass *P) { // Create new basic block, insert right before the original block. - BasicBlock *NewBB = - BasicBlock::Create(BB->getName()+Suffix, BB->getParent(), BB); + BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), BB->getName()+Suffix, + BB->getParent(), BB); // The new block unconditionally branches to the old block. BranchInst *BI = BranchInst::Create(BB, NewBB); diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp index bef1119502..632aa2b723 100644 --- a/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -129,8 +129,8 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P, BasicBlock *DestBB = TI->getSuccessor(SuccNum); // Create a new basic block, linking it into the CFG. - BasicBlock *NewBB = BasicBlock::Create(TIBB->getName() + "." + - DestBB->getName() + "_crit_edge"); + BasicBlock *NewBB = BasicBlock::Create(TI->getContext(), + TIBB->getName() + "." + DestBB->getName() + "_crit_edge"); // Create our unconditional branch... BranchInst::Create(DestBB, NewBB); diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index 2b2fcb1052..a6df161740 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -35,7 +35,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, DenseMap<const Value*, Value*> &ValueMap, const char *NameSuffix, Function *F, ClonedCodeInfo *CodeInfo) { - BasicBlock *NewBB = BasicBlock::Create("", F); + BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "", F); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false; @@ -219,7 +219,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, // Nope, clone it now. BasicBlock *NewBB; - BBEntry = NewBB = BasicBlock::Create(); + BBEntry = NewBB = BasicBlock::Create(BB->getContext()); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false; diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index d4f0c8095a..c98317bf80 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -242,9 +242,9 @@ Function *CodeExtractor::constructFunction(const Values &inputs, // This function returns unsigned, outputs will go back by reference. switch (NumExitBlocks) { case 0: - case 1: RetTy = Type::VoidTy; break; - case 2: RetTy = Type::Int1Ty; break; - default: RetTy = Type::Int16Ty; break; + case 1: RetTy = Type::getVoidTy(header->getContext()); break; + case 2: RetTy = Type::getInt1Ty(header->getContext()); break; + default: RetTy = Type::getInt16Ty(header->getContext()); break; } std::vector<const Type*> paramTy; @@ -302,8 +302,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs, Value *RewriteVal; if (AggregateArgs) { Value *Idx[2]; - Idx[0] = Constant::getNullValue(Type::Int32Ty); - Idx[1] = ConstantInt::get(Type::Int32Ty, i); + Idx[0] = Constant::getNullValue(Type::getInt32Ty(header->getContext())); + Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), i); TerminatorInst *TI = newFunction->begin()->getTerminator(); GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2, @@ -353,6 +353,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // Emit a call to the new function, passing in: *pointer to struct (if // aggregating parameters), or plan inputs and allocated memory for outputs std::vector<Value*> params, StructValues, ReloadOutputs; + + LLVMContext &Context = newFunction->getContext(); // Add inputs as params, or to be filled into the struct for (Values::iterator i = inputs.begin(), e = inputs.end(); i != e; ++i) @@ -390,8 +392,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, for (unsigned i = 0, e = inputs.size(); i != e; ++i) { Value *Idx[2]; - Idx[0] = Constant::getNullValue(Type::Int32Ty); - Idx[1] = ConstantInt::get(Type::Int32Ty, i); + Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context)); + Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), i); GetElementPtrInst *GEP = GetElementPtrInst::Create(Struct, Idx, Idx + 2, "gep_" + StructValues[i]->getName()); @@ -416,8 +418,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Value *Output = 0; if (AggregateArgs) { Value *Idx[2]; - Idx[0] = Constant::getNullValue(Type::Int32Ty); - Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i); + Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context)); + Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), FirstOut + i); GetElementPtrInst *GEP = GetElementPtrInst::Create(Struct, Idx, Idx + 2, "gep_reload_" + outputs[i]->getName()); @@ -438,7 +440,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // Now we can emit a switch statement using the call as a value. SwitchInst *TheSwitch = - SwitchInst::Create(Constant::getNullValue(Type::Int16Ty), + SwitchInst::Create(Constant::getNullValue(Type::getInt16Ty(Context)), codeReplacer, 0, codeReplacer); // Since there may be multiple exits from the original region, make the new @@ -460,7 +462,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, if (!NewTarget) { // If we don't already have an exit stub for this non-extracted // destination, create one now! - NewTarget = BasicBlock::Create(OldTarget->getName() + ".exitStub", + NewTarget = BasicBlock::Create(Context, + OldTarget->getName() + ".exitStub", newFunction); unsigned SuccNum = switchVal++; @@ -469,17 +472,18 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, case 0: case 1: break; // No value needed. case 2: // Conditional branch, return a bool - brVal = ConstantInt::get(Type::Int1Ty, !SuccNum); + brVal = ConstantInt::get(Type::getInt1Ty(Context), !SuccNum); break; default: - brVal = ConstantInt::get(Type::Int16Ty, SuccNum); + brVal = ConstantInt::get(Type::getInt16Ty(Context), SuccNum); break; } - ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget); + ReturnInst *NTRet = ReturnInst::Create(Context, brVal, NewTarget); // Update the switch instruction. - TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum), + TheSwitch->addCase(ConstantInt::get(Type::getInt16Ty(Context), + SuccNum), OldTarget); // Restore values just before we exit @@ -517,8 +521,9 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, if (DominatesDef) { if (AggregateArgs) { Value *Idx[2]; - Idx[0] = Constant::getNullValue(Type::Int32Ty); - Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out); + Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context)); + Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), + FirstOut+out); GetElementPtrInst *GEP = GetElementPtrInst::Create(OAI, Idx, Idx + 2, "gep_" + outputs[out]->getName(), @@ -547,15 +552,16 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // this should be rewritten as a `ret' // Check if the function should return a value - if (OldFnRetTy == Type::VoidTy) { - ReturnInst::Create(0, TheSwitch); // Return void + if (OldFnRetTy == Type::getVoidTy(Context)) { + ReturnInst::Create(Context, 0, TheSwitch); // Return void } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) { // return what we have - ReturnInst::Create(TheSwitch->getCondition(), TheSwitch); + ReturnInst::Create(Context, TheSwitch->getCondition(), TheSwitch); } else { // Otherwise we must have code extracted an unwind or something, just // return whatever we want. - ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch); + ReturnInst::Create(Context, + Constant::getNullValue(OldFnRetTy), TheSwitch); } TheSwitch->eraseFromParent(); @@ -648,12 +654,14 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) { Function *oldFunction = header->getParent(); // This takes place of the original loop - BasicBlock *codeReplacer = BasicBlock::Create("codeRepl", oldFunction, + BasicBlock *codeReplacer = BasicBlock::Create(header->getContext(), + "codeRepl", oldFunction, header); // The new function needs a root node because other nodes can branch to the // head of the region, but the entry node of a function cannot have preds. - BasicBlock *newFuncRoot = BasicBlock::Create("newFuncRoot"); + BasicBlock *newFuncRoot = BasicBlock::Create(header->getContext(), + "newFuncRoot"); newFuncRoot->getInstList().push_back(BranchInst::Create(header)); // Find inputs to, outputs from the code region. diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index d6382af379..c0d10f4898 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -304,7 +304,8 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) && !CalledFunc->onlyReadsMemory()) { const Type *AggTy = cast<PointerType>(I->getType())->getElementType(); - const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); + const Type *VoidPtrTy = + PointerType::getUnqual(Type::getInt8Ty(Context)); // Create the alloca. If we have TargetData, use nice alignment. unsigned Align = 1; @@ -313,7 +314,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { I->getName(), &*Caller->begin()->begin()); // Emit a memcpy. - const Type *Tys[] = { Type::Int64Ty }; + const Type *Tys[] = { Type::getInt64Ty(Context) }; Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(), Intrinsic::memcpy, Tys, 1); @@ -324,14 +325,15 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { if (TD == 0) Size = ConstantExpr::getSizeOf(AggTy); else - Size = ConstantInt::get(Type::Int64Ty, + Size = ConstantInt::get(Type::getInt64Ty(Context), TD->getTypeStoreSize(AggTy)); // Always generate a memcpy of alignment 1 here because we don't know // the alignment of the src pointer. Other optimizations can infer // better alignment. Value *CallArgs[] = { - DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1) + DestCast, SrcCast, Size, + ConstantInt::get(Type::getInt32Ty(Context), 1) }; CallInst *TheMemCpy = CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall); @@ -490,7 +492,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { BB != E; ++BB) { TerminatorInst *Term = BB->getTerminator(); if (isa<UnwindInst>(Term)) { - new UnreachableInst(Term); + new UnreachableInst(Context, Term); BB->getInstList().erase(Term); } } diff --git a/lib/Transforms/Utils/InstructionNamer.cpp b/lib/Transforms/Utils/InstructionNamer.cpp index 4f8a160394..1fa51a3b6a 100644 --- a/lib/Transforms/Utils/InstructionNamer.cpp +++ b/lib/Transforms/Utils/InstructionNamer.cpp @@ -32,7 +32,7 @@ namespace { bool runOnFunction(Function &F) { for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE; ++AI) - if (!AI->hasName() && AI->getType() != Type::VoidTy) + if (!AI->hasName() && AI->getType() != Type::getVoidTy(F.getContext())) AI->setName("tmp"); for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { @@ -40,7 +40,7 @@ namespace { BB->setName("BB"); for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (!I->hasName() && I->getType() != Type::VoidTy) + if (!I->hasName() && I->getType() != Type::getVoidTy(F.getContext())) I->setName("tmp"); } return true; diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 69a208405d..c981a014cb 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -161,7 +161,7 @@ bool LoopSimplify::runOnFunction(Function &F) { TI->getSuccessor(i)->removePredecessor(BB); // Add a new unreachable instruction before the old terminator. - new UnreachableInst(TI); + new UnreachableInst(TI->getContext(), TI); // Delete the dead terminator. if (AA) AA->deleteValue(TI); @@ -586,7 +586,8 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader) { if (*I != Preheader) BackedgeBlocks.push_back(*I); // Create and insert the new backedge block... - BasicBlock *BEBlock = BasicBlock::Create(Header->getName()+".backedge", F); + BasicBlock *BEBlock = BasicBlock::Create(Header->getContext(), + Header->getName()+".backedge", F); BranchInst *BETerminator = BranchInst::Create(Header, BEBlock); // Move the new backedge block to right after the last backedge block. diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index ce7b04a497..bfeab3775b 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -87,12 +87,13 @@ Pass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) { // This function is always successful. // bool LowerAllocations::doInitialization(Module &M) { - const Type *BPTy = PointerType::getUnqual(Type::Int8Ty); + const Type *BPTy = PointerType::getUnqual(Type::getInt8Ty(M.getContext())); // Prototype malloc as "char* malloc(...)", because we don't know in // doInitialization whether size_t is int or long. FunctionType *FT = FunctionType::get(BPTy, true); MallocFunc = M.getOrInsertFunction("malloc", FT); - FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0); + FreeFunc = M.getOrInsertFunction("free" , Type::getVoidTy(M.getContext()), + BPTy, (Type *)0); return true; } @@ -106,7 +107,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { BasicBlock::InstListType &BBIL = BB.getInstList(); const TargetData &TD = getAnalysis<TargetData>(); - const Type *IntPtrTy = TD.getIntPtrType(); + const Type *IntPtrTy = TD.getIntPtrType(BB.getContext()); // Loop over all of the instructions, looking for malloc or free instructions for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) { @@ -116,7 +117,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { // malloc(type) becomes i8 *malloc(size) Value *MallocArg; if (LowerMallocArgToInteger) - MallocArg = ConstantInt::get(Type::Int64Ty, + MallocArg = ConstantInt::get(Type::getInt64Ty(BB.getContext()), TD.getTypeAllocSize(AllocTy)); else MallocArg = ConstantExpr::getSizeOf(AllocTy); @@ -151,7 +152,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { // Create a cast instruction to convert to the right type... Value *MCast; - if (MCall->getType() != Type::VoidTy) + if (MCall->getType() != Type::getVoidTy(BB.getContext())) MCast = new BitCastInst(MCall, MI->getType(), "", I); else MCast = Constant::getNullValue(MI->getType()); @@ -164,7 +165,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { } else if (FreeInst *FI = dyn_cast<FreeInst>(I)) { Value *PtrCast = new BitCastInst(FI->getOperand(0), - PointerType::getUnqual(Type::Int8Ty), "", I); + PointerType::getUnqual(Type::getInt8Ty(BB.getContext())), "", I); // Insert a call to the free function... CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall(); diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index d16ceb4280..b18a2307e1 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -115,7 +115,8 @@ FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) { // doInitialization - Make sure that there is a prototype for abort in the // current module. bool LowerInvoke::doInitialization(Module &M) { - const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); + const Type *VoidPtrTy = + PointerType::getUnqual(Type::getInt8Ty(M.getContext())); AbortMessage = 0; if (ExpensiveEHSupport) { // Insert a type for the linked list of jump buffers. @@ -164,7 +165,8 @@ bool LowerInvoke::doInitialization(Module &M) { } // We need the 'write' and 'abort' functions for both models. - AbortFn = M.getOrInsertFunction("abort", Type::VoidTy, (Type *)0); + AbortFn = M.getOrInsertFunction("abort", Type::getVoidTy(M.getContext()), + (Type *)0); #if 0 // "write" is Unix-specific.. code is going away soon anyway. WriteFn = M.getOrInsertFunction("write", Type::VoidTy, Type::Int32Ty, VoidPtrTy, Type::Int32Ty, (Type *)0); @@ -179,26 +181,30 @@ void LowerInvoke::createAbortMessage(Module *M) { // The abort message for expensive EH support tells the user that the // program 'unwound' without an 'invoke' instruction. Constant *Msg = - ConstantArray::get("ERROR: Exception thrown, but not caught!\n"); + ConstantArray::get(M->getContext(), + "ERROR: Exception thrown, but not caught!\n"); AbortMessageLength = Msg->getNumOperands()-1; // don't include \0 GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true, GlobalValue::InternalLinkage, Msg, "abortmsg"); - std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty)); + std::vector<Constant*> GEPIdx(2, + Constant::getNullValue(Type::getInt32Ty(M->getContext()))); AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2); } else { // The abort message for cheap EH support tells the user that EH is not // enabled. Constant *Msg = - ConstantArray::get("Exception handler needed, but not enabled." + ConstantArray::get(M->getContext(), + "Exception handler needed, but not enabled." "Recompile program with -enable-correct-eh-support.\n"); AbortMessageLength = Msg->getNumOperands()-1; // don't include \0 GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true, GlobalValue::InternalLinkage, Msg, "abortmsg"); - std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::Int32Ty)); + std::vector<Constant*> GEPIdx(2, Constant::getNullValue( + Type::getInt32Ty(M->getContext()))); AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2); } } @@ -250,8 +256,9 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) { // Insert a return instruction. This really should be a "barrier", as it // is unreachable. - ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 : - Constant::getNullValue(F.getReturnType()), UI); + ReturnInst::Create(F.getContext(), + F.getReturnType() == Type::getVoidTy(F.getContext()) ? + 0 : Constant::getNullValue(F.getReturnType()), UI); // Remove the unwind instruction now. BB->getInstList().erase(UI); @@ -266,7 +273,8 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) { void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo, AllocaInst *InvokeNum, SwitchInst *CatchSwitch) { - ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo); + ConstantInt *InvokeNoC = ConstantInt::get(Type::getInt32Ty(II->getContext()), + InvokeNo); // If the unwind edge has phi nodes, split the edge. if (isa<PHINode>(II->getUnwindDest()->begin())) { @@ -285,7 +293,8 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo, BasicBlock::iterator NI = II->getNormalDest()->getFirstNonPHI(); // nonvolatile. - new StoreInst(Constant::getNullValue(Type::Int32Ty), InvokeNum, false, NI); + new StoreInst(Constant::getNullValue(Type::getInt32Ty(II->getContext())), + InvokeNum, false, NI); // Add a switch case to our unwind block. CatchSwitch->addCase(InvokeNoC, II->getUnwindDest()); @@ -474,8 +483,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { "jblink", F.begin()->begin()); std::vector<Value*> Idx; - Idx.push_back(Constant::getNullValue(Type::Int32Ty)); - Idx.push_back(ConstantInt::get(Type::Int32Ty, 1)); + Idx.push_back(Constant::getNullValue(Type::getInt32Ty(F.getContext()))); + Idx.push_back(ConstantInt::get(Type::getInt32Ty(F.getContext()), 1)); OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), "OldBuf", EntryBB->getTerminator()); @@ -490,20 +499,21 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Create the catch block. The catch block is basically a big switch // statement that goes to all of the invoke catch blocks. - BasicBlock *CatchBB = BasicBlock::Create("setjmp.catch", &F); + BasicBlock *CatchBB = + BasicBlock::Create(F.getContext(), "setjmp.catch", &F); // Create an alloca which keeps track of which invoke is currently // executing. For normal calls it contains zero. - AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0, + AllocaInst *InvokeNum = new AllocaInst(Type::getInt32Ty(F.getContext()), 0, "invokenum",EntryBB->begin()); - new StoreInst(ConstantInt::get(Type::Int32Ty, 0), InvokeNum, true, - EntryBB->getTerminator()); + new StoreInst(ConstantInt::get(Type::getInt32Ty(F.getContext()), 0), + InvokeNum, true, EntryBB->getTerminator()); // Insert a load in the Catch block, and a switch on its value. By default, // we go to a block that just does an unwind (which is the correct action // for a standard call). - BasicBlock *UnwindBB = BasicBlock::Create("unwindbb", &F); - Unwinds.push_back(new UnwindInst(UnwindBB)); + BasicBlock *UnwindBB = BasicBlock::Create(F.getContext(), "unwindbb", &F); + Unwinds.push_back(new UnwindInst(F.getContext(), UnwindBB)); Value *CatchLoad = new LoadInst(InvokeNum, "invoke.num", true, CatchBB); SwitchInst *CatchSwitch = @@ -515,11 +525,12 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(), "setjmp.cont"); - Idx[1] = ConstantInt::get(Type::Int32Ty, 0); + Idx[1] = ConstantInt::get(Type::getInt32Ty(F.getContext()), 0); Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), "TheJmpBuf", EntryBB->getTerminator()); - JmpBufPtr = new BitCastInst(JmpBufPtr, PointerType::getUnqual(Type::Int8Ty), + JmpBufPtr = new BitCastInst(JmpBufPtr, + PointerType::getUnqual(Type::getInt8Ty(F.getContext())), "tmp", EntryBB->getTerminator()); Value *SJRet = CallInst::Create(SetJmpFn, JmpBufPtr, "sjret", EntryBB->getTerminator()); @@ -545,9 +556,10 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Create three new blocks, the block to load the jmpbuf ptr and compare // against null, the block to do the longjmp, and the error block for if it // is null. Add them at the end of the function because they are not hot. - BasicBlock *UnwindHandler = BasicBlock::Create("dounwind", &F); - BasicBlock *UnwindBlock = BasicBlock::Create("unwind", &F); - BasicBlock *TermBlock = BasicBlock::Create("unwinderror", &F); + BasicBlock *UnwindHandler = BasicBlock::Create(F.getContext(), + "dounwind", &F); + BasicBlock *UnwindBlock = BasicBlock::Create(F.getContext(), "unwind", &F); + BasicBlock *TermBlock = BasicBlock::Create(F.getContext(), "unwinderror", &F); // If this function contains an invoke, restore the old jumpbuf ptr. Value *BufPtr; @@ -568,18 +580,19 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Create the block to do the longjmp. // Get a pointer to the jmpbuf and longjmp. std::vector<Value*> Idx; - Idx.push_back(Constant::getNullValue(Type::Int32Ty)); - Idx.push_back(ConstantInt::get(Type::Int32Ty, 0)); + Idx.push_back(Constant::getNullValue(Type::getInt32Ty(F.getContext()))); + Idx.push_back(ConstantInt::get(Type::getInt32Ty(F.getContext()), 0)); Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf", UnwindBlock); - Idx[0] = new BitCastInst(Idx[0], PointerType::getUnqual(Type::Int8Ty), + Idx[0] = new BitCastInst(Idx[0], + PointerType::getUnqual(Type::getInt8Ty(F.getContext())), "tmp", UnwindBlock); - Idx[1] = ConstantInt::get(Type::Int32Ty, 1); + Idx[1] = ConstantInt::get(Type::getInt32Ty(F.getContext()), 1); CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock); - new UnreachableInst(UnwindBlock); + new UnreachableInst(F.getContext(), UnwindBlock); // Set up the term block ("throw without a catch"). - new UnreachableInst(TermBlock); + new UnreachableInst(F.getContext(), TermBlock); // Insert a new call to write(2, AbortMessage, AbortMessageLength); writeAbortMessage(TermBlock->getTerminator()); diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp index 4cc92e9824..974698d45c 100644 --- a/lib/Transforms/Utils/LowerSwitch.cpp +++ b/lib/Transforms/Utils/LowerSwitch.cpp @@ -155,7 +155,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, // Create a new node that checks if the value is < pivot. Go to the // left branch if it is and right branch if not. Function* F = OrigBlock->getParent(); - BasicBlock* NewNode = BasicBlock::Create("NodeBlock"); + BasicBlock* NewNode = BasicBlock::Create(Val->getContext(), "NodeBlock"); Function::iterator FI = OrigBlock; F->getBasicBlockList().insert(++FI, NewNode); @@ -177,7 +177,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val, BasicBlock* Default) { Function* F = OrigBlock->getParent(); - BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock"); + BasicBlock* NewLeaf = BasicBlock::Create(Val->getContext(), "LeafBlock"); Function::iterator FI = OrigBlock; F->getBasicBlockList().insert(++FI, NewLeaf); @@ -289,7 +289,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { // Create a new, empty default block so that the new hierarchy of // if-then statements go to this and the PHI nodes are happy. - BasicBlock* NewDefault = BasicBlock::Create("NewDefault"); + BasicBlock* NewDefault = BasicBlock::Create(SI->getContext(), "NewDefault"); F->getBasicBlockList().insert(Default, NewDefault); BranchInst::Create(Default, NewDefault); diff --git a/lib/Transforms/Utils/SSI.cpp b/lib/Transforms/Utils/SSI.cpp index 8178367dd4..63ca354793 100644 --- a/lib/Transforms/Utils/SSI.cpp +++ b/lib/Transforms/Utils/SSI.cpp @@ -421,7 +421,7 @@ bool SSIEverything::runOnFunction(Function &F) { for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B) for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E; ++I) - if (I->getType() != Type::VoidTy) + if (I->getType() != Type::getVoidTy(F.getContext())) Insts.push_back(I); ssi.createSSI(Insts); diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index d6d8f28e7e..bb0cf4234c 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -838,7 +838,8 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) { if (InfLoopBlock == 0) { // Insert it at the end of the function, because it's either code, // or it won't matter if it's hot. :) - InfLoopBlock = BasicBlock::Create("infloop", BB->getParent()); + InfLoopBlock = BasicBlock::Create(BB->getContext(), + "infloop", BB->getParent()); BranchInst::Create(InfLoopBlock, InfLoopBlock); } NewSI->setSuccessor(i, InfLoopBlock); @@ -930,7 +931,7 @@ HoistTerminator: // Okay, it is safe to hoist the terminator. Instruction *NT = I1->clone(BB1->getContext()); BIParent->getInstList().insert(BI, NT); - if (NT->getType() != Type::VoidTy) { + if (NT->getType() != Type::getVoidTy(BB1->getContext())) { I1->replaceAllUsesWith(NT); I2->replaceAllUsesWith(NT); NT->takeName(I1); @@ -1189,7 +1190,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) { for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { ConstantInt *CB; if ((CB = dyn_cast<ConstantInt>(PN->getIncomingValue(i))) && - CB->getType() == Type::Int1Ty) { + CB->getType() == Type::getInt1Ty(BB->getContext())) { // Okay, we now know that all edges from PredBB should be revectored to // branch to RealDest. BasicBlock *PredBB = PN->getIncomingBlock(i); @@ -1201,7 +1202,8 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) { // difficult cases. Instead of being smart about this, just insert a new // block that jumps to the destination block, effectively splitting // the edge we are about to create. - BasicBlock *EdgeBB = BasicBlock::Create(RealDest->getName()+".critedge", + BasicBlock *EdgeBB = BasicBlock::Create(BB->getContext(), + RealDest->getName()+".critedge", RealDest->getParent(), RealDest); BranchInst::Create(RealDest, EdgeBB); PHINode *PN; @@ -1419,7 +1421,7 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI) { if (FalseRet->getNumOperands() == 0) { TrueSucc->removePredecessor(BI->getParent()); FalseSucc->removePredecessor(BI->getParent()); - ReturnInst::Create(0, BI); + ReturnInst::Create(BI->getContext(), 0, BI); EraseTerminatorInstAndDCECond(BI); return true; } @@ -1468,8 +1470,8 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI) { } Value *RI = !TrueValue ? - ReturnInst::Create(BI) : - ReturnInst::Create(TrueValue, BI); + ReturnInst::Create(BI->getContext(), BI) : + ReturnInst::Create(BI->getContext(), TrueValue, BI); DOUT << "\nCHANGING BRANCH TO TWO RETURNS INTO SELECT:" << "\n " << *BI << "NewRet = " << *RI @@ -1608,7 +1610,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { if (BB->getSinglePredecessor()) { // Turn this into a branch on constant. bool CondIsTrue = PBI->getSuccessor(0) == BB; - BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue)); + BI->setCondition(ConstantInt::get(Type::getInt1Ty(BB->getContext()), + CondIsTrue)); return true; // Nuke the branch on constant. } @@ -1616,7 +1619,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { // in the constant and simplify the block result. Subsequent passes of // simplifycfg will thread the block. if (BlockIsSimpleEnoughToThreadThrough(BB)) { - PHINode *NewPN = PHINode::Create(Type::Int1Ty, + PHINode *NewPN = PHINode::Create(Type::getInt1Ty(BB->getContext()), BI->getCondition()->getName() + ".pr", BB->begin()); // Okay, we're going to insert the PHI node. Since PBI is not the only @@ -1628,7 +1631,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { PBI->getCondition() == BI->getCondition() && PBI->getSuccessor(0) != PBI->getSuccessor(1)) { bool CondIsTrue = PBI->getSuccessor(0) == BB; - NewPN->addIncoming(ConstantInt::get(Type::Int1Ty, + NewPN->addIncoming(ConstantInt::get(Type::getInt1Ty(BB->getContext()), CondIsTrue), *PI); } else { NewPN->addIncoming(BI->getCondition(), *PI); @@ -1700,7 +1703,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { if (OtherDest == BB) { // Insert it at the end of the function, because it's either code, // or it won't matter if it's hot. :) - BasicBlock *InfLoopBlock = BasicBlock::Create("infloop", BB->getParent()); + BasicBlock *InfLoopBlock = BasicBlock::Create(BB->getContext(), + "infloop", BB->getParent()); BranchInst::Create(InfLoopBlock, InfLoopBlock); OtherDest = InfLoopBlock; } @@ -1885,7 +1889,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) { if (BI->isUnconditional()) { Pred->getInstList().pop_back(); // nuke uncond branch - new UnwindInst(Pred); // Use unwind. + new UnwindInst(Pred->getContext(), Pred); // Use unwind. Changed = true; } } else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator())) @@ -2034,7 +2038,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { if (BI->isUnconditional()) { if (BI->getSuccessor(0) == BB) { - new UnreachableInst(TI); + new UnreachableInst(TI->getContext(), TI); TI->eraseFromParent(); Changed = true; } diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp index 848f2b87c4..30cb94d903 100644 --- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -66,8 +66,8 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { } else if (UnwindingBlocks.size() == 1) { UnwindBlock = UnwindingBlocks.front(); } else { - UnwindBlock = BasicBlock::Create("UnifiedUnwindBlock", &F); - new UnwindInst(UnwindBlock); + UnwindBlock = BasicBlock::Create(F.getContext(), "UnifiedUnwindBlock", &F); + new UnwindInst(F.getContext(), UnwindBlock); for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(), E = UnwindingBlocks.end(); I != E; ++I) { @@ -83,8 +83,9 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { } else if (UnreachableBlocks.size() == 1) { UnreachableBlock = UnreachableBlocks.front(); } else { - UnreachableBlock = BasicBlock::Create("UnifiedUnreachableBlock", &F); - new UnreachableInst(UnreachableBlock); + UnreachableBlock = BasicBlock::Create(F.getContext(), + "UnifiedUnreachableBlock", &F); + new UnreachableInst(F.getContext(), UnreachableBlock); for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(), E = UnreachableBlocks.end(); I != E; ++I) { @@ -107,16 +108,17 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { // nodes (if the function returns values), and convert all of the return // instructions into unconditional branches. // - BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F); + BasicBlock *NewRetBlock = BasicBlock::Create(F.getContext(), + "UnifiedReturnBlock", &F); PHINode *PN = 0; - if (F.getReturnType() == Type::VoidTy) { - ReturnInst::Create(NULL, NewRetBlock); + if (F.getReturnType() == Type::getVoidTy(F.getContext())) { + ReturnInst::Create(F.getContext(), NULL, NewRetBlock); } else { // If the function doesn't return void... add a PHI node to the block... PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal"); NewRetBlock->getInstList().push_back(PN); - ReturnInst::Create(PN, NewRetBlock); + ReturnInst::Create(F.getContext(), PN, NewRetBlock); } // Loop over all of the blocks, replacing the return instruction with an diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index b6d98b8573..8270f1723f 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -685,7 +685,8 @@ void SlotTracker::processFunction() { CreateFunctionSlot(BB); for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) { - if (I->getType() != Type::VoidTy && !I->hasName()) + if (I->getType() != Type::getVoidTy(TheFunction->getContext()) && + !I->hasName()) CreateFunctionSlot(I); for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) if (MDNode *N = dyn_cast<MDNode>(I->getOperand(i))) @@ -767,7 +768,8 @@ int SlotTracker::getLocalSlot(const Value *V) { /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. void SlotTracker::CreateModuleSlot(const GlobalValue *V) { assert(V && "Can't insert a null Value into SlotTracker!"); - assert(V->getType() != Type::VoidTy && "Doesn't need a slot!"); + assert(V->getType() != Type::getVoidTy(V->getContext()) && + "Doesn't need a slot!"); assert(!V->hasName() && "Doesn't need a slot!"); unsigned DestSlot = mNext++; @@ -783,8 +785,8 @@ void SlotTracker::CreateModuleSlot(const GlobalValue *V) { /// CreateSlot - Create a new slot for the specified value if it has no name. void SlotTracker::CreateFunctionSlot(const Value *V) { - assert(V->getType() != Type::VoidTy && !V->hasName() && - "Doesn't need a slot!"); + assert(V->getType() != Type::getVoidTy(TheFunction->getContext()) && + !V->hasName() && "Doesn't need a slot!"); unsigned DestSlot = fNext++; fMap[V] = DestSlot; @@ -909,7 +911,7 @@ static void WriteOptimizationInfo(raw_ostream &Out, const User *U) { static void WriteConstantInt(raw_ostream &Out, const Constant *CV, TypePrinting &TypePrinter, SlotTracker *Machine) { if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { - if (CI->getType() == Type::Int1Ty) { + if (CI->getType() == Type::getInt1Ty(CV->getContext())) { Out << (CI->getZExtValue() ? "true" : "false"); return; } @@ -1725,7 +1727,7 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { /// which slot it occupies. /// void AssemblyWriter::printInfoComment(const Value &V) { - if (V.getType() != Type::VoidTy) { + if (V.getType() != Type::getVoidTy(V.getContext())) { Out.PadToColumn(50); Out << "; <"; TypePrinter.print(V.getType(), Out); @@ -1744,7 +1746,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { if (I.hasName()) { PrintLLVMName(Out, &I); Out << " = "; - } else if (I.getType() != Type::VoidTy) { + } else if (I.getType() != Type::getVoidTy(I.getContext())) { // Print out the def slot taken. int SlotNum = Machine.getLocalSlot(&I); if (SlotNum == -1) diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp index 7f6c7e167e..e4c0d1afc4 100644 --- a/lib/VMCore/AutoUpgrade.cpp +++ b/lib/VMCore/AutoUpgrade.cpp @@ -165,7 +165,7 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) { Name.compare(13,4,"psrl", 4) == 0) && Name[17] != 'i') { const llvm::Type *VT = - VectorType::get(IntegerType::get(64), 1); + VectorType::get(IntegerType::get(FTy->getContext(), 64), 1); // We don't have to do anything if the parameter already has // the correct type. @@ -230,6 +230,7 @@ bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) { // order to seamlessly integrate with existing context. void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { Function *F = CI->getCalledFunction(); + LLVMContext &C = CI->getContext(); assert(F && "CallInst has no function associated with it."); @@ -265,23 +266,23 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { if (isLoadH || isLoadL) { Value *Op1 = UndefValue::get(Op0->getType()); Value *Addr = new BitCastInst(CI->getOperand(2), - PointerType::getUnqual(Type::DoubleTy), + PointerType::getUnqual(Type::getDoubleTy(C)), "upgraded.", CI); Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI); - Value *Idx = ConstantInt::get(Type::Int32Ty, 0); + Value *Idx = ConstantInt::get(Type::getInt32Ty(C), 0); Op1 = InsertElementInst::Create(Op1, Load, Idx, "upgraded.", CI); if (isLoadH) { - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 0)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); } else { - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); } Value *Mask = ConstantVector::get(Idxs); SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); } else if (isMovL) { - Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); + Constant *Zero = ConstantInt::get(Type::getInt32Ty(C), 0); Idxs.push_back(Zero); Idxs.push_back(Zero); Idxs.push_back(Zero); @@ -289,32 +290,32 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { Value *ZeroV = ConstantVector::get(Idxs); Idxs.clear(); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 4)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 5)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 4)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 5)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 3)); Value *Mask = ConstantVector::get(Idxs); SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI); } else if (isMovSD || isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) { Value *Op1 = CI->getOperand(2); if (isMovSD) { - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); } else if (isUnpckhPD || isPunpckhQPD) { - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 1)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 3)); } else { - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 0)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), 2)); } Value *Mask = ConstantVector::get(Idxs); SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); } else if (isShufPD) { Value *Op1 = CI->getOperand(2); unsigned MaskVal = cast<ConstantInt>(CI->getOperand(3))->getZExtValue(); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, MaskVal & 1)); - Idxs.push_back(ConstantInt::get(Type::Int32Ty, + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), MaskVal & 1)); + Idxs.push_back(ConstantInt::get(Type::getInt32Ty(C), ((MaskVal >> 1) & 1)+2)); Value *Mask = ConstantVector::get(Idxs); SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 5741cbc3db..50cf84c3fe 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -38,9 +38,9 @@ LLVMContext &BasicBlock::getContext() const { template class SymbolTableListTraits<Instruction, BasicBlock>; -BasicBlock::BasicBlock(const Twine &Name, Function *NewParent, +BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent, BasicBlock *InsertBefore) - : Value(Type::LabelTy, Value::BasicBlockVal), Parent(0) { + : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(0) { // Make sure that we get added to a function LeakDetector::addGarbageObject(this); @@ -246,7 +246,8 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) { BasicBlock *InsertBefore = next(Function::iterator(this)) .getNodePtrUnchecked(); - BasicBlock *New = BasicBlock::Create(BBName, getParent(), InsertBefore); + BasicBlock *New = BasicBlock::Create(getContext(), BBName, + getParent(), InsertBefore); // Move all of the specified instructions from the original basic block into // the new basic block. diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index e30f144658..eda336a580 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -88,7 +88,7 @@ foldConstantCastPair( // Let CastInst::isEliminableCastPair do the heavy lifting. return CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy, DstTy, - Type::Int64Ty); + Type::getInt64Ty(DstTy->getContext())); } static Constant *FoldBitCast(LLVMContext &Context, @@ -103,7 +103,7 @@ static Constant *FoldBitCast(LLVMContext &Context, if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy)) if (PTy->getAddressSpace() == DPTy->getAddressSpace()) { SmallVector<Value*, 8> IdxList; - Value *Zero = Constant::getNullValue(Type::Int32Ty); + Value *Zero = Constant::getNullValue(Type::getInt32Ty(Context)); IdxList.push_back(Zero); const Type *ElTy = PTy->getElementType(); while (ElTy != DPTy->getElementType()) { @@ -164,7 +164,7 @@ static Constant *FoldBitCast(LLVMContext &Context, if (DestTy->isFloatingPoint()) return ConstantFP::get(Context, APFloat(CI->getValue(), - DestTy != Type::PPC_FP128Ty)); + DestTy != Type::getPPC_FP128Ty(Context))); // Otherwise, can't fold this (vector?) return 0; @@ -192,7 +192,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, return UndefValue::get(DestTy); } // No compile-time operations on this type yet. - if (V->getType() == Type::PPC_FP128Ty || DestTy == Type::PPC_FP128Ty) + if (V->getType() == Type::getPPC_FP128Ty(Context) || DestTy == Type::getPPC_FP128Ty(Context)) return 0; // If the cast operand is a constant expression, there's a few things we can @@ -241,10 +241,10 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V)) { bool ignored; APFloat Val = FPC->getValueAPF(); - Val.convert(DestTy == Type::FloatTy ? APFloat::IEEEsingle : - DestTy == Type::DoubleTy ? APFloat::IEEEdouble : - DestTy == Type::X86_FP80Ty ? APFloat::x87DoubleExtended : - DestTy == Type::FP128Ty ? APFloat::IEEEquad : + Val.convert(DestTy == Type::getFloatTy(Context) ? APFloat::IEEEsingle : + DestTy == Type::getDoubleTy(Context) ? APFloat::IEEEdouble : + DestTy == Type::getX86_FP80Ty(Context) ? APFloat::x87DoubleExtended : + DestTy == Type::getFP128Ty(Context) ? APFloat::IEEEquad : APFloat::Bogus, APFloat::rmNearestTiesToEven, &ignored); return ConstantFP::get(Context, Val); @@ -582,7 +582,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, const Constant *C1, const Constant *C2) { // No compile-time operations on this type yet. - if (C1->getType() == Type::PPC_FP128Ty) + if (C1->getType() == Type::getPPC_FP128Ty(Context)) return 0; // Handle UndefValue up front @@ -1045,11 +1045,11 @@ static int IdxCompare(LLVMContext &Context, Constant *C1, Constant *C2, // Ok, we have two differing integer indices. Sign extend them to be the same // type. Long is always big enough, so we use it. - if (C1->getType() != Type::Int64Ty) - C1 = ConstantExpr::getSExt(C1, Type::Int64Ty); + if (C1->getType() != Type::getInt64Ty(Context)) + C1 = ConstantExpr::getSExt(C1, Type::getInt64Ty(Context)); - if (C2->getType() != Type::Int64Ty) - C2 = ConstantExpr::getSExt(C2, Type::Int64Ty); + if (C2->getType() != Type::getInt64Ty(Context)) + C2 = ConstantExpr::getSExt(C2, Type::getInt64Ty(Context)); if (C1 == C2) return 0; // They are equal @@ -1085,7 +1085,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context, "Cannot compare values of different types!"); // No compile-time operations on this type yet. - if (V1->getType() == Type::PPC_FP128Ty) + if (V1->getType() == Type::getPPC_FP128Ty(Context)) return FCmpInst::BAD_FCMP_PREDICATE; // Handle degenerate case quickly @@ -1375,9 +1375,9 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, const Constant *C2) { const Type *ResultTy; if (const VectorType *VT = dyn_cast<VectorType>(C1->getType())) - ResultTy = VectorType::get(Type::Int1Ty, VT->getNumElements()); + ResultTy = VectorType::get(Type::getInt1Ty(Context), VT->getNumElements()); else - ResultTy = Type::Int1Ty; + ResultTy = Type::getInt1Ty(Context); // Fold FCMP_FALSE/FCMP_TRUE unconditionally. if (pred == FCmpInst::FCMP_FALSE) @@ -1391,7 +1391,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, return UndefValue::get(ResultTy); // No compile-time operations on this type yet. - if (C1->getType() == Type::PPC_FP128Ty) + if (C1->getType() == Type::getPPC_FP128Ty(Context)) return 0; // icmp eq/ne(null,GV) -> false/true @@ -1422,25 +1422,25 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, switch (pred) { default: llvm_unreachable("Invalid ICmp Predicate"); return 0; case ICmpInst::ICMP_EQ: - return ConstantInt::get(Type::Int1Ty, V1 == V2); + return ConstantInt::get(Type::getInt1Ty(Context), V1 == V2); case ICmpInst::ICMP_NE: - return ConstantInt::get(Type::Int1Ty, V1 != V2); + return ConstantInt::get(Type::getInt1Ty(Context), V1 != V2); case ICmpInst::ICMP_SLT: - return ConstantInt::get(Type::Int1Ty, V1.slt(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.slt(V2)); case ICmpInst::ICMP_SGT: - return ConstantInt::get(Type::Int1Ty, V1.sgt(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.sgt(V2)); case ICmpInst::ICMP_SLE: - return ConstantInt::get(Type::Int1Ty, V1.sle(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.sle(V2)); case ICmpInst::ICMP_SGE: - return ConstantInt::get(Type::Int1Ty, V1.sge(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.sge(V2)); case ICmpInst::ICMP_ULT: - return ConstantInt::get(Type::Int1Ty, V1.ult(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.ult(V2)); case ICmpInst::ICMP_UGT: - return ConstantInt::get(Type::Int1Ty, V1.ugt(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.ugt(V2)); case ICmpInst::ICMP_ULE: - return ConstantInt::get(Type::Int1Ty, V1.ule(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.ule(V2)); case ICmpInst::ICMP_UGE: - return ConstantInt::get(Type::Int1Ty, V1.uge(V2)); + return ConstantInt::get(Type::getInt1Ty(Context), V1.uge(V2)); } } else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) { APFloat C1V = cast<ConstantFP>(C1)->getValueAPF(); @@ -1451,38 +1451,38 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, case FCmpInst::FCMP_FALSE: return ConstantInt::getFalse(Context); case FCmpInst::FCMP_TRUE: return ConstantInt::getTrue(Context); case FCmpInst::FCMP_UNO: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered); + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered); case FCmpInst::FCMP_ORD: - return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpUnordered); + return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpUnordered); case FCmpInst::FCMP_UEQ: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered || + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered || R==APFloat::cmpEqual); case FCmpInst::FCMP_OEQ: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpEqual); + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpEqual); case FCmpInst::FCMP_UNE: - return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpEqual); + return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpEqual); case FCmpInst::FCMP_ONE: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan || + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan || R==APFloat::cmpGreaterThan); case FCmpInst::FCMP_ULT: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered || + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered || R==APFloat::cmpLessThan); case FCmpInst::FCMP_OLT: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan); + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan); case FCmpInst::FCMP_UGT: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered || + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpUnordered || R==APFloat::cmpGreaterThan); case FCmpInst::FCMP_OGT: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan); + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpGreaterThan); case FCmpInst::FCMP_ULE: - return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpGreaterThan); + return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpGreaterThan); case FCmpInst::FCMP_OLE: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan || + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpLessThan || R==APFloat::cmpEqual); case FCmpInst::FCMP_UGE: - return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpLessThan); + return ConstantInt::get(Type::getInt1Ty(Context), R!=APFloat::cmpLessThan); case FCmpInst::FCMP_OGE: - return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan || + return ConstantInt::get(Type::getInt1Ty(Context), R==APFloat::cmpGreaterThan || R==APFloat::cmpEqual); } } else if (isa<VectorType>(C1->getType())) { @@ -1557,7 +1557,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, // If we evaluated the result, return it now. if (Result != -1) - return ConstantInt::get(Type::Int1Ty, Result); + return ConstantInt::get(Type::getInt1Ty(Context), Result); } else { // Evaluate the relation between the two constants, per the predicate. @@ -1634,7 +1634,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, // If we evaluated the result, return it now. if (Result != -1) - return ConstantInt::get(Type::Int1Ty, Result); + return ConstantInt::get(Type::getInt1Ty(Context), Result); if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) { // If C2 is a constant expr and C1 isn't, flip them around and fold the @@ -1726,9 +1726,9 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, const Type *IdxTy = Combined->getType(); if (IdxTy != Idx0->getType()) { Constant *C1 = - ConstantExpr::getSExtOrBitCast(Idx0, Type::Int64Ty); + ConstantExpr::getSExtOrBitCast(Idx0, Type::getInt64Ty(Context)); Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined, - Type::Int64Ty); + Type::getInt64Ty(Context)); Combined = ConstantExpr::get(Instruction::Add, C1, C2); } else { Combined = @@ -1765,7 +1765,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, // This happens with pointers to member functions in C++. if (CE->getOpcode() == Instruction::IntToPtr && NumIdx == 1 && isa<ConstantInt>(CE->getOperand(0)) && isa<ConstantInt>(Idxs[0]) && - cast<PointerType>(CE->getType())->getElementType() == Type::Int8Ty) { + cast<PointerType>(CE->getType())->getElementType() == Type::getInt8Ty(Context)) { Constant *Base = CE->getOperand(0); Constant *Offset = Idxs[0]; diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 0bff5786b8..647bc1225a 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -233,7 +233,8 @@ ConstantInt* ConstantInt::getTrue(LLVMContext &Context) { if (pImpl->TheTrueVal) return pImpl->TheTrueVal; else - return (pImpl->TheTrueVal = ConstantInt::get(IntegerType::get(1), 1)); + return (pImpl->TheTrueVal = + ConstantInt::get(IntegerType::get(Context, 1), 1)); } ConstantInt* ConstantInt::getFalse(LLVMContext &Context) { @@ -242,7 +243,8 @@ ConstantInt* ConstantInt::getFalse(LLVMContext &Context) { if (pImpl->TheFalseVal) return pImpl->TheFalseVal; else - return (pImpl->TheFalseVal = ConstantInt::get(IntegerType::get(1), 0)); + return (pImpl->TheFalseVal = + ConstantInt::get(IntegerType::get(Context, 1), 0)); } @@ -253,7 +255,7 @@ ConstantInt* ConstantInt::getFalse(LLVMContext &Context) { // invariant which generates an assertion. ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) { // Get the corresponding integer type for the bit width of the value. - const IntegerType *ITy = IntegerType::get(V.getBitWidth()); + const IntegerType *ITy = IntegerType::get(Context, V.getBitWidth()); // get an existing value or the insertion position DenseMapAPIntKeyInfo::KeyTy Key(V, ITy); @@ -317,16 +319,16 @@ Constant* ConstantInt::get(const Type* Ty, const APInt& V) { //===----------------------------------------------------------------------===// static const fltSemantics *TypeToFloatSemantics(const Type *Ty) { - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Ty->getContext())) return &APFloat::IEEEsingle; - if (Ty == Type::DoubleTy) + if (Ty == Type::getDoubleTy(Ty->getContext())) return &APFloat::IEEEdouble; - if (Ty == Type::X86_FP80Ty) + if (Ty == Type::getX86_FP80Ty(Ty->getContext())) return &APFloat::x87DoubleExtended; - else if (Ty == Type::FP128Ty) + else if (Ty == Type::getFP128Ty(Ty->getContext())) return &APFloat::IEEEquad; - assert(Ty == Type::PPC_FP128Ty && "Unknown FP format"); + assert(Ty == Type::getPPC_FP128Ty(Ty->getContext()) && "Unknown FP format"); return &APFloat::PPCDoubleDouble; } @@ -389,17 +391,17 @@ ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) { if (!NewSlot) { const Type *Ty; if (&V.getSemantics() == &APFloat::IEEEsingle) - Ty = Type::FloatTy; + Ty = Type::getFloatTy(Context); else if (&V.getSemantics() == &APFloat::IEEEdouble) - Ty = Type::DoubleTy; + Ty = Type::getDoubleTy(Context); else if (&V.getSemantics() == &APFloat::x87DoubleExtended) - Ty = Type::X86_FP80Ty; + Ty = Type::getX86_FP80Ty(Context); else if (&V.getSemantics() == &APFloat::IEEEquad) - Ty = Type::FP128Ty; + Ty = Type::getFP128Ty(Context); else { assert(&V.getSemantics() == &APFloat::PPCDoubleDouble && "Unknown FP format"); - Ty = Type::PPC_FP128Ty; + Ty = Type::getPPC_FP128Ty(Context); } NewSlot = new ConstantFP(Ty, V); } @@ -481,17 +483,18 @@ Constant* ConstantArray::get(const ArrayType* T, Constant* const* Vals, /// Otherwise, the length parameter specifies how much of the string to use /// and it won't be null terminated. /// -Constant* ConstantArray::get(const StringRef &Str, bool AddNull) { +Constant* ConstantArray::get(LLVMContext &Context, const StringRef &Str, + bool AddNull) { std::vector<Constant*> ElementVals; for (unsigned i = 0; i < Str.size(); ++i) - ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i])); + ElementVals.push_back(ConstantInt::get(Type::getInt8Ty(Context), Str[i])); // Add a null terminator to the string... if (AddNull) { - ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0)); + ElementVals.push_back(ConstantInt::get(Type::getInt8Ty(Context), 0)); } - ArrayType *ATy = ArrayType::get(Type::Int8Ty, ElementVals.size()); + ArrayType *ATy = ArrayType::get(Type::getInt8Ty(Context), ElementVals.size()); return get(ATy, ElementVals); } @@ -769,7 +772,7 @@ getWithOperands(Constant* const *Ops, unsigned NumOps) const { bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) { unsigned NumBits = cast<IntegerType>(Ty)->getBitWidth(); // assert okay - if (Ty == Type::Int1Ty) + if (Ty == Type::getInt1Ty(Ty->getContext())) return Val == 0 || Val == 1; if (NumBits >= 64) return true; // always true, has to fit in largest type @@ -779,7 +782,7 @@ bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) { bool ConstantInt::isValueValidForType(const Type *Ty, int64_t Val) { unsigned NumBits = cast<IntegerType>(Ty)->getBitWidth(); // assert okay - if (Ty == Type::Int1Ty) + if (Ty == Type::getInt1Ty(Ty->getContext())) return Val == 0 || Val == 1 || Val == -1; if (NumBits >= 64) return true; // always true, has to fit in largest type @@ -859,7 +862,7 @@ void ConstantArray::destroyConstant() { /// if the elements of the array are all ConstantInt's. bool ConstantArray::isString() const { // Check the element type for i8... - if (getType()->getElementType() != Type::Int8Ty) + if (getType()->getElementType() != Type::getInt8Ty(getContext())) return false; // Check the elements to make sure they are all integers, not constant // expressions. @@ -874,7 +877,7 @@ bool ConstantArray::isString() const { /// null bytes except its terminator. bool ConstantArray::isCString() const { // Check the element type for i8... - if (getType()->getElementType() != Type::Int8Ty) + if (getType()->getElementType() != Type::getInt8Ty(getContext())) return false; // Last element must be a null. @@ -1262,7 +1265,7 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode, assert(C1->getType() == C2->getType() && "Operand types in binary constant expression should match"); - if (ReqTy == C1->getType() || ReqTy == Type::Int1Ty) + if (ReqTy == C1->getType() || ReqTy == Type::getInt1Ty(ReqTy->getContext())) if (Constant *FC = ConstantFoldBinaryInstruction(ReqTy->getContext(), Opcode, C1, C2)) return FC; // Fold a few common cases... @@ -1367,23 +1370,25 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { Constant* ConstantExpr::getSizeOf(const Type* Ty) { // sizeof is implemented as: (i64) gep (Ty*)null, 1 // Note that a non-inbounds gep is used, as null isn't within any object. - Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1); + Constant *GEPIdx = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1); Constant *GEP = getGetElementPtr( Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1); - return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty); + return getCast(Instruction::PtrToInt, GEP, + Type::getInt64Ty(Ty->getContext())); } Constant* ConstantExpr::getAlignOf(const Type* Ty) { // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1 // Note that a non-inbounds gep is used, as null isn't within any object. const Type *AligningTy = StructType::get(Ty->getContext(), - Type::Int8Ty, Ty, NULL); + Type::getInt8Ty(Ty->getContext()), Ty, NULL); Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo()); - Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); - Constant *One = ConstantInt::get(Type::Int32Ty, 1); + Constant *Zero = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 0); + Constant *One = ConstantInt::get(Type::getInt32Ty(Ty->getContext()), 1); Constant *Indices[2] = { Zero, One }; Constant *GEP = getGetElementPtr(NullPtr, Indices, 2); - return getCast(Instruction::PtrToInt, GEP, Type::Int32Ty); + return getCast(Instruction::PtrToInt, GEP, + Type::getInt32Ty(Ty->getContext())); } @@ -1493,7 +1498,8 @@ ConstantExpr::getICmp(unsigned short pred, Constant* LHS, Constant* RHS) { LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl; // Implicitly locked. - return pImpl->ExprConstants.getOrCreate(Type::Int1Ty, Key); + return + pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key); } Constant * @@ -1515,7 +1521,8 @@ ConstantExpr::getFCmp(unsigned short pred, Constant* LHS, Constant* RHS) { LLVMContextImpl *pImpl = LHS->getType()->getContext().pImpl; // Implicitly locked. - return pImpl->ExprConstants.getOrCreate(Type::Int1Ty, Key); + return + pImpl->ExprConstants.getOrCreate(Type::getInt1Ty(LHS->getContext()), Key); } Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val, @@ -1537,7 +1544,7 @@ Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val, Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) { assert(isa<VectorType>(Val->getType()) && "Tried to create extractelement operation on non-vector type!"); - assert(Idx->getType() == Type::Int32Ty && + assert(Idx->getType() == Type::getInt32Ty(Val->getContext()) && "Extractelement index must be i32 type!"); return getExtractElementTy(cast<VectorType>(Val->getType())->getElementType(), Val, Idx); @@ -1566,7 +1573,7 @@ Constant *ConstantExpr::getInsertElement(Constant *Val, Constant *Elt, "Tried to create insertelement operation on non-vector type!"); assert(Elt->getType() == cast<VectorType>(Val->getType())->getElementType() && "Insertelement types must match!"); - assert(Idx->getType() == Type::Int32Ty && + assert(Idx->getType() == Type::getInt32Ty(Val->getContext()) && "Insertelement index must be i32 type!"); return getInsertElementTy(Val->getType(), Val, Elt, Idx); } diff --git a/lib/VMCore/ConstantsContext.h b/lib/VMCore/ConstantsContext.h index f1d4b25e1b..be75f11e19 100644 --- a/lib/VMCore/ConstantsContext.h +++ b/lib/VMCore/ConstantsContext.h @@ -446,7 +446,7 @@ struct ConstantCreator<ConstantAggregateZero, Type, ValType> { template<> struct ConstantCreator<MDNode, Type, std::vector<Value*> > { static MDNode *create(const Type* Ty, const std::vector<Value*> &V) { - return new MDNode(&V[0], V.size()); + return new MDNode(Ty->getContext(), &V[0], V.size()); } }; diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 88160e1629..b2715d9d21 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -153,14 +153,24 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { /*--.. Operations on integer types .........................................--*/ -LLVMTypeRef LLVMInt1Type(void) { return (LLVMTypeRef) Type::Int1Ty; } -LLVMTypeRef LLVMInt8Type(void) { return (LLVMTypeRef) Type::Int8Ty; } -LLVMTypeRef LLVMInt16Type(void) { return (LLVMTypeRef) Type::Int16Ty; } -LLVMTypeRef LLVMInt32Type(void) { return (LLVMTypeRef) Type::Int32Ty; } -LLVMTypeRef LLVMInt64Type(void) { return (LLVMTypeRef) Type::Int64Ty; } +LLVMTypeRef LLVMInt1Type(void) { + return (LLVMTypeRef) Type::getInt1Ty(getGlobalContext()); +} +LLVMTypeRef LLVMInt8Type(void) { + return (LLVMTypeRef) Type::getInt8Ty(getGlobalContext()); +} +LLVMTypeRef LLVMInt16Type(void) { + return (LLVMTypeRef) Type::getInt16Ty(getGlobalContext()); +} +LLVMTypeRef LLVMInt32Type(void) { + return (LLVMTypeRef) Type::getInt32Ty(getGlobalContext()); +} +LLVMTypeRef LLVMInt64Type(void) { + return (LLVMTypeRef) Type::getInt64Ty(getGlobalContext()); +} LLVMTypeRef LLVMIntType(unsigned NumBits) { - return wrap(IntegerType::get(NumBits)); + return wrap(IntegerType::get(getGlobalContext(), NumBits)); } unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) { @@ -169,11 +179,21 @@ unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) { /*--.. Operations on real types ............................................--*/ -LLVMTypeRef LLVMFloatType(void) { return (LLVMTypeRef) Type::FloatTy; } -LLVMTypeRef LLVMDoubleType(void) { return (LLVMTypeRef) Type::DoubleTy; } -LLVMTypeRef LLVMX86FP80Type(void) { return (LLVMTypeRef) Type::X86_FP80Ty; } -LLVMTypeRef LLVMFP128Type(void) { return (LLVMTypeRef) Type::FP128Ty; } -LLVMTypeRef LLVMPPCFP128Type(void) { return (LLVMTypeRef) Type::PPC_FP128Ty; } +LLVMTypeRef LLVMFloatType(void) { + return (LLVMTypeRef) Type::getFloatTy(getGlobalContext()); +} +LLVMTypeRef LLVMDoubleType(void) { + return (LLVMTypeRef) Type::getDoubleTy(getGlobalContext()); +} +LLVMTypeRef LLVMX86FP80Type(void) { + return (LLVMTypeRef) Type::getX86_FP80Ty(getGlobalContext()); +} +LLVMTypeRef LLVMFP128Type(void) { + return (LLVMTypeRef) Type::getFP128Ty(getGlobalContext()); +} +LLVMTypeRef LLVMPPCFP128Type(void) { + return (LLVMTypeRef) Type::getPPC_FP128Ty(getGlobalContext()); +} /*--.. Operations on function types ........................................--*/ @@ -265,8 +285,12 @@ unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) { /*--.. Operations on other types ...........................................--*/ -LLVMTypeRef LLVMVoidType(void) { return (LLVMTypeRef) Type::VoidTy; } -LLVMTypeRef LLVMLabelType(void) { return (LLVMTypeRef) Type::LabelTy; } +LLVMTypeRef LLVMVoidType(void) { + return (LLVMTypeRef) Type::getVoidTy(getGlobalContext()); +} +LLVMTypeRef LLVMLabelType(void) { + return (LLVMTypeRef) Type::getLabelTy(getGlobalContext()); +} LLVMTypeRef LLVMOpaqueType(void) { return wrap(OpaqueType::get()); @@ -364,15 +388,15 @@ LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, static const fltSemantics &SemanticsForType(Type *Ty) { assert(Ty->isFloatingPoint() && "Type is not floating point!"); - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(getGlobalContext())) return APFloat::IEEEsingle; - if (Ty == Type::DoubleTy) + if (Ty == Type::getDoubleTy(getGlobalContext())) return APFloat::IEEEdouble; - if (Ty == Type::X86_FP80Ty) + if (Ty == Type::getX86_FP80Ty(getGlobalContext())) return APFloat::x87DoubleExtended; - if (Ty == Type::FP128Ty) + if (Ty == Type::getFP128Ty(getGlobalContext())) return APFloat::IEEEquad; - if (Ty == Type::PPC_FP128Ty) + if (Ty == Type::getPPC_FP128Ty(getGlobalContext())) return APFloat::PPCDoubleDouble; return APFloat::Bogus; } @@ -396,7 +420,7 @@ LLVMValueRef LLVMConstString(const char *Str, unsigned Length, int DontNullTerminate) { /* Inverted the sense of AddNull because ', 0)' is a better mnemonic for null termination than ', 1)'. */ - return wrap(ConstantArray::get(std::string(Str, Length), + return wrap(ConstantArray::get(getGlobalContext(), std::string(Str, Length), DontNullTerminate == 0)); } @@ -1113,13 +1137,15 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) { } LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) { - return wrap(BasicBlock::Create(Name, unwrap<Function>(FnRef))); + return wrap(BasicBlock::Create(getGlobalContext(), Name, + unwrap<Function>(FnRef))); } LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBBRef, const char *Name) { BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef); - return wrap(BasicBlock::Create(Name, InsertBeforeBB->getParent(), + return wrap(BasicBlock::Create(getGlobalContext(), Name, + InsertBeforeBB->getParent(), InsertBeforeBB)); } diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 481300500c..8ad885c4c2 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -182,7 +182,7 @@ void Function::BuildLazyArguments() const { // Create the arguments vector, all arguments start out unnamed. const FunctionType *FT = getFunctionType(); for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { - assert(FT->getParamType(i) != Type::VoidTy && + assert(FT->getParamType(i) != Type::getVoidTy(FT->getContext()) && "Cannot have void typed arguments!"); ArgumentList.push_back(new Argument(FT->getParamType(i))); } diff --git a/lib/VMCore/InlineAsm.cpp b/lib/VMCore/InlineAsm.cpp index 485092e6ff..fbd6b90f93 100644 --- a/lib/VMCore/InlineAsm.cpp +++ b/lib/VMCore/InlineAsm.cpp @@ -213,7 +213,7 @@ bool InlineAsm::Verify(const FunctionType *Ty, const StringRef &ConstStr) { switch (NumOutputs) { case 0: - if (Ty->getReturnType() != Type::VoidTy) return false; + if (Ty->getReturnType() != Type::getVoidTy(Ty->getContext())) return false; break; case 1: if (isa<StructType>(Ty->getReturnType())) return false; diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 902d806f23..bbea62bded 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -126,7 +126,7 @@ const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) { if (const VectorType *VT = dyn_cast<VectorType>(Op0->getType())) { // Vector select. - if (VT->getElementType() != Type::Int1Ty) + if (VT->getElementType() != Type::getInt1Ty(Op0->getContext())) return "vector select condition element type must be i1"; const VectorType *ET = dyn_cast<VectorType>(Op1->getType()); if (ET == 0) @@ -134,7 +134,7 @@ const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) { if (ET->getNumElements() != VT->getNumElements()) return "vector select requires selected vectors to have " "the same vector length as select condition"; - } else if (Op0->getType() != Type::Int1Ty) { + } else if (Op0->getType() != Type::getInt1Ty(Op0->getContext())) { return "select condition must be i1 or <n x i1>"; } return 0; @@ -502,7 +502,7 @@ void InvokeInst::removeAttribute(unsigned i, Attributes attr) { //===----------------------------------------------------------------------===// ReturnInst::ReturnInst(const ReturnInst &RI) - : TerminatorInst(Type::VoidTy, Instruction::Ret, + : TerminatorInst(Type::getVoidTy(RI.getContext()), Instruction::Ret, OperandTraits<ReturnInst>::op_end(this) - RI.getNumOperands(), RI.getNumOperands()) { @@ -510,22 +510,22 @@ ReturnInst::ReturnInst(const ReturnInst &RI) Op<0>() = RI.Op<0>(); } -ReturnInst::ReturnInst(Value *retVal, Instruction *InsertBefore) - : TerminatorInst(Type::VoidTy, Instruction::Ret, +ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, Instruction *InsertBefore) + : TerminatorInst(Type::getVoidTy(C), Instruction::Ret, OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal, InsertBefore) { if (retVal) Op<0>() = retVal; } -ReturnInst::ReturnInst(Value *retVal, BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Ret, +ReturnInst::ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd) + : TerminatorInst(Type::getVoidTy(C), Instruction::Ret, OperandTraits<ReturnInst>::op_end(this) - !!retVal, !!retVal, InsertAtEnd) { if (retVal) Op<0>() = retVal; } -ReturnInst::ReturnInst(BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Ret, +ReturnInst::ReturnInst(LLVMContext &Context, BasicBlock *InsertAtEnd) + : TerminatorInst(Type::getVoidTy(Context), Instruction::Ret, OperandTraits<ReturnInst>::op_end(this), 0, InsertAtEnd) { } @@ -551,11 +551,13 @@ ReturnInst::~ReturnInst() { // UnwindInst Implementation //===----------------------------------------------------------------------===// -UnwindInst::UnwindInst(Instruction *InsertBefore) - : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertBefore) { +UnwindInst::UnwindInst(LLVMContext &Context, Instruction *InsertBefore) + : TerminatorInst(Type::getVoidTy(Context), Instruction::Unwind, + 0, 0, InsertBefore) { } -UnwindInst::UnwindInst(BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Unwind, 0, 0, InsertAtEnd) { +UnwindInst::UnwindInst(LLVMContext &Context, BasicBlock *InsertAtEnd) + : TerminatorInst(Type::getVoidTy(Context), Instruction::Unwind, + 0, 0, InsertAtEnd) { } @@ -576,11 +578,14 @@ BasicBlock *UnwindInst::getSuccessorV(unsigned idx) const { // UnreachableInst Implementation //===----------------------------------------------------------------------===// -UnreachableInst::UnreachableInst(Instruction *InsertBefore) - : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertBefore) { +UnreachableInst::UnreachableInst(LLVMContext &Context, + Instruction *InsertBefore) + : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable, + 0, 0, InsertBefore) { } -UnreachableInst::UnreachableInst(BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Unreachable, 0, 0, InsertAtEnd) { +UnreachableInst::UnreachableInst(LLVMContext &Context, BasicBlock *InsertAtEnd) + : TerminatorInst(Type::getVoidTy(Context), Instruction::Unreachable, + 0, 0, InsertAtEnd) { } unsigned UnreachableInst::getNumSuccessorsV() const { @@ -602,12 +607,12 @@ BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const { void BranchInst::AssertOK() { if (isConditional()) - assert(getCondition()->getType() == Type::Int1Ty && + assert(getCondition()->getType() == Type::getInt1Ty(getContext()) && "May only branch on boolean predicates!"); } BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore) - : TerminatorInst(Type::VoidTy, Instruction::Br, + : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br, OperandTraits<BranchInst>::op_end(this) - 1, 1, InsertBefore) { assert(IfTrue != 0 && "Branch destination may not be null!"); @@ -615,7 +620,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore) } BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, Instruction *InsertBefore) - : TerminatorInst(Type::VoidTy, Instruction::Br, + : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br, OperandTraits<BranchInst>::op_end(this) - 3, 3, InsertBefore) { Op<-1>() = IfTrue; @@ -627,7 +632,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, } BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Br, + : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br, OperandTraits<BranchInst>::op_end(this) - 1, 1, InsertAtEnd) { assert(IfTrue != 0 && "Branch destination may not be null!"); @@ -636,7 +641,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Br, + : TerminatorInst(Type::getVoidTy(IfTrue->getContext()), Instruction::Br, OperandTraits<BranchInst>::op_end(this) - 3, 3, InsertAtEnd) { Op<-1>() = IfTrue; @@ -649,7 +654,7 @@ BranchInst::BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BranchInst::BranchInst(const BranchInst &BI) : - TerminatorInst(Type::VoidTy, Instruction::Br, + TerminatorInst(Type::getVoidTy(BI.getContext()), Instruction::Br, OperandTraits<BranchInst>::op_end(this) - BI.getNumOperands(), BI.getNumOperands()) { Op<-1>() = BI.Op<-1>(); @@ -702,11 +707,11 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) { static Value *getAISize(LLVMContext &Context, Value *Amt) { if (!Amt) - Amt = ConstantInt::get(Type::Int32Ty, 1); + Amt = ConstantInt::get(Type::getInt32Ty(Context), 1); else { assert(!isa<BasicBlock>(Amt) && "Passed basic block into allocation size parameter! Use other ctor"); - assert(Amt->getType() == Type::Int32Ty && + assert(Amt->getType() == Type::getInt32Ty(Context) && "Malloc/Allocation array size is not a 32-bit integer!"); } return Amt; @@ -718,7 +723,7 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(Ty->getContext(), ArraySize), InsertBefore) { setAlignment(Align); - assert(Ty != Type::VoidTy && "Cannot allocate void!"); + assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); setName(Name); } @@ -728,7 +733,7 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(Ty->getContext(), ArraySize), InsertAtEnd) { setAlignment(Align); - assert(Ty != Type::VoidTy && "Cannot allocate void!"); + assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!"); setName(Name); } @@ -786,12 +791,14 @@ void FreeInst::AssertOK() { } FreeInst::FreeInst(Value *Ptr, Instruction *InsertBefore) - : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertBefore) { + : UnaryInstruction(Type::getVoidTy(Ptr->getContext()), + Free, Ptr, InsertBefore) { AssertOK(); } FreeInst::FreeInst(Value *Ptr, BasicBlock *InsertAtEnd) - : UnaryInstruction(Type::VoidTy, Free, Ptr, InsertAtEnd) { + : UnaryInstruction(Type::getVoidTy(Ptr->getContext()), + Free, Ptr, InsertAtEnd) { AssertOK(); } @@ -923,7 +930,7 @@ void StoreInst::AssertOK() { StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore) - : Instruction(Type::VoidTy, Store, + : Instruction(Type::getVoidTy(val->getContext()), Store, OperandTraits<StoreInst>::op_begin(this), OperandTraits<StoreInst>::operands(this), InsertBefore) { @@ -935,7 +942,7 @@ StoreInst::StoreInst(Value *val, Value *addr, Instruction *InsertBefore) } StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd) - : Instruction(Type::VoidTy, Store, + : Instruction(Type::getVoidTy(val->getContext()), Store, OperandTraits<StoreInst>::op_begin(this), OperandTraits<StoreInst>::operands(this), InsertAtEnd) { @@ -948,7 +955,7 @@ StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd) StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, Instruction *InsertBefore) - : Instruction(Type::VoidTy, Store, + : Instruction(Type::getVoidTy(val->getContext()), Store, OperandTraits<StoreInst>::op_begin(this), OperandTraits<StoreInst>::operands(this), InsertBefore) { @@ -961,7 +968,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align, Instruction *InsertBefore) - : Instruction(Type::VoidTy, Store, + : Instruction(Type::getVoidTy(val->getContext()), Store, OperandTraits<StoreInst>::op_begin(this), OperandTraits<StoreInst>::operands(this), InsertBefore) { @@ -974,7 +981,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align, BasicBlock *InsertAtEnd) - : Instruction(Type::VoidTy, Store, + : Instruction(Type::getVoidTy(val->getContext()), Store, OperandTraits<StoreInst>::op_begin(this), OperandTraits<StoreInst>::operands(this), InsertAtEnd) { @@ -987,7 +994,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, BasicBlock *InsertAtEnd) - : Instruction(Type::VoidTy, Store, + : Instruction(Type::getVoidTy(val->getContext()), Store, OperandTraits<StoreInst>::op_begin(this), OperandTraits<StoreInst>::operands(this), InsertAtEnd) { @@ -1193,7 +1200,8 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index, bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) { - if (!isa<VectorType>(Val->getType()) || Index->getType() != Type::Int32Ty) + if (!isa<VectorType>(Val->getType()) || + Index->getType() != Type::getInt32Ty(Val->getContext())) return false; return true; } @@ -1247,7 +1255,7 @@ bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType()) return false;// Second operand of insertelement must be vector element type. - if (Index->getType() != Type::Int32Ty) + if (Index->getType() != Type::getInt32Ty(Vec->getContext())) return false; // Third operand of insertelement must be i32. return true; } @@ -1306,7 +1314,7 @@ bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2, const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType()); if (!isa<Constant>(Mask) || MaskTy == 0 || - MaskTy->getElementType() != Type::Int32Ty) + MaskTy->getElementType() != Type::getInt32Ty(V1->getContext())) return false; return true; } @@ -2758,7 +2766,8 @@ void SwitchInst::init(Value *Value, BasicBlock *Default, unsigned NumCases) { /// constructor can also autoinsert before another instruction. SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore) - : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertBefore) { + : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch, + 0, 0, InsertBefore) { init(Value, Default, NumCases); } @@ -2768,12 +2777,13 @@ SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, /// constructor also autoinserts at the end of the specified BasicBlock. SwitchInst::SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, BasicBlock *InsertAtEnd) - : TerminatorInst(Type::VoidTy, Instruction::Switch, 0, 0, InsertAtEnd) { + : TerminatorInst(Type::getVoidTy(Value->getContext()), Instruction::Switch, + 0, 0, InsertAtEnd) { init(Value, Default, NumCases); } SwitchInst::SwitchInst(const SwitchInst &SI) - : TerminatorInst(Type::VoidTy, Instruction::Switch, + : TerminatorInst(Type::getVoidTy(SI.getContext()), Instruction::Switch, allocHungoffUses(SI.getNumOperands()), SI.getNumOperands()) { Use *OL = OperandList, *InOL = SI.OperandList; for (unsigned i = 0, E = SI.getNumOperands(); i != E; i+=2) { @@ -3006,10 +3016,10 @@ InvokeInst *InvokeInst::clone(LLVMContext&) const { return new(getNumOperands()) InvokeInst(*this); } -UnwindInst *UnwindInst::clone(LLVMContext&) const { - return new UnwindInst(); +UnwindInst *UnwindInst::clone(LLVMContext &C) const { + return new UnwindInst(C); } -UnreachableInst *UnreachableInst::clone(LLVMContext&) const { - return new UnreachableInst(); +UnreachableInst *UnreachableInst::clone(LLVMContext &C) const { + return new UnreachableInst(C); } diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 4762a10555..208e1bcedc 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -55,7 +55,7 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) { StringMapEntry<MDString *> &Entry = pImpl->MDStringCache.GetOrCreateValue(Str); MDString *&S = Entry.getValue(); - if (!S) S = new MDString(Entry.getKeyData(), + if (!S) S = new MDString(Context, Entry.getKeyData(), Entry.getKeyLength()); return S; @@ -64,8 +64,8 @@ MDString *MDString::get(LLVMContext &Context, const StringRef &Str) { //===----------------------------------------------------------------------===// //MDNode implementation // -MDNode::MDNode(Value*const* Vals, unsigned NumVals) - : MetadataBase(Type::MetadataTy, Value::MDNodeVal) { +MDNode::MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals) + : MetadataBase(Type::getMetadataTy(C), Value::MDNodeVal) { NumOperands = 0; resizeOperands(NumVals); for (unsigned i = 0; i != NumVals; ++i) { @@ -83,7 +83,7 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) { for (unsigned i = 0; i < NumVals; ++i) V.push_back(Vals[i]); - return pImpl->MDNodes.getOrCreate(Type::MetadataTy, V); + return pImpl->MDNodes.getOrCreate(Type::getMetadataTy(Context), V); } /// dropAllReferences - Remove all uses and clear node vector. @@ -108,9 +108,10 @@ MDNode::~MDNode() { //===----------------------------------------------------------------------===// //NamedMDNode implementation // -NamedMDNode::NamedMDNode(const Twine &N, MetadataBase*const* MDs, +NamedMDNode::NamedMDNode(LLVMContext &C, const Twine &N, + MetadataBase*const* MDs, unsigned NumMDs, Module *ParentModule) - : MetadataBase(Type::MetadataTy, Value::NamedMDNodeVal), Parent(0) { + : MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) { setName(N); NumOperands = 0; resizeOperands(NumMDs); @@ -129,7 +130,8 @@ NamedMDNode *NamedMDNode::Create(const NamedMDNode *NMD, Module *M) { SmallVector<MetadataBase *, 4> Elems; for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) Elems.push_back(NMD->getElement(i)); - return new NamedMDNode(NMD->getName().data(), Elems.data(), Elems.size(), M); + return new NamedMDNode(NMD->getContext(), NMD->getName().data(), + Elems.data(), Elems.size(), M); } /// eraseFromParent - Drop all references and remove the node from parent diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index e06e79a026..add2449107 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -31,14 +31,15 @@ using namespace llvm; // GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() { - GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), Type::Int32Ty, + GlobalVariable *Ret = new GlobalVariable(getGlobalContext(), + Type::getInt32Ty(getGlobalContext()), false, GlobalValue::ExternalLinkage); // This should not be garbage monitored. LeakDetector::removeGarbageObject(Ret); return Ret; } GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() { - GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty, + GlobalAlias *Ret = new GlobalAlias(Type::getInt32Ty(getGlobalContext()), GlobalValue::ExternalLinkage); // This should not be garbage monitored. LeakDetector::removeGarbageObject(Ret); @@ -303,7 +304,7 @@ NamedMDNode *Module::getOrInsertNamedMetadata(const StringRef &Name) { NamedMDNode *NMD = dyn_cast_or_null<NamedMDNode>(getValueSymbolTable().lookup(Name)); if (!NMD) - NMD = NamedMDNode::Create(Name, NULL, 0, this); + NMD = NamedMDNode::Create(getContext(), Name, NULL, 0, this); return NMD; } diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index ac55096ac8..3072e838b5 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -103,26 +103,26 @@ void Type::destroy() const { delete this; } -const Type *Type::getPrimitiveType(TypeID IDNumber) { +const Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) { switch (IDNumber) { - case VoidTyID : return VoidTy; - case FloatTyID : return FloatTy; - case DoubleTyID : return DoubleTy; - case X86_FP80TyID : return X86_FP80Ty; - case FP128TyID : return FP128Ty; - case PPC_FP128TyID : return PPC_FP128Ty; - case LabelTyID : return LabelTy; - case MetadataTyID : return MetadataTy; + case VoidTyID : return getVoidTy(C); + case FloatTyID : return getFloatTy(C); + case DoubleTyID : return getDoubleTy(C); + case X86_FP80TyID : return getX86_FP80Ty(C); + case FP128TyID : return getFP128Ty(C); + case PPC_FP128TyID : return getPPC_FP128Ty(C); + case LabelTyID : return getLabelTy(C); + case MetadataTyID : return getMetadataTy(C); default: return 0; } } -const Type *Type::getVAArgsPromotedType() const { +const Type *Type::getVAArgsPromotedType(LLVMContext &C) const { if (ID == IntegerTyID && getSubclassData() < 32) - return Type::Int32Ty; + return Type::getInt32Ty(C); else if (ID == FloatTyID) - return Type::DoubleTy; + return Type::getDoubleTy(C); else return this; } @@ -288,7 +288,7 @@ std::string Type::getDescription() const { bool StructType::indexValid(const Value *V) const { // Structure indexes require 32-bit integer constants. - if (V->getType() == Type::Int32Ty) + if (V->getType() == Type::getInt32Ty(V->getContext())) if (const ConstantInt *CU = dyn_cast<ConstantInt>(V)) return indexValid(CU->getZExtValue()); return false; @@ -315,25 +315,76 @@ const Type *StructType::getTypeAtIndex(unsigned Idx) const { // Primitive 'Type' data //===----------------------------------------------------------------------===// -const Type *Type::VoidTy = new Type(Type::VoidTyID); -const Type *Type::FloatTy = new Type(Type::FloatTyID); -const Type *Type::DoubleTy = new Type(Type::DoubleTyID); -const Type *Type::X86_FP80Ty = new Type(Type::X86_FP80TyID); -const Type *Type::FP128Ty = new Type(Type::FP128TyID); -const Type *Type::PPC_FP128Ty = new Type(Type::PPC_FP128TyID); -const Type *Type::LabelTy = new Type(Type::LabelTyID); -const Type *Type::MetadataTy = new Type(Type::MetadataTyID); - namespace { struct BuiltinIntegerType : public IntegerType { explicit BuiltinIntegerType(unsigned W) : IntegerType(W) {} }; } -const IntegerType *Type::Int1Ty = new BuiltinIntegerType(1); -const IntegerType *Type::Int8Ty = new BuiltinIntegerType(8); -const IntegerType *Type::Int16Ty = new BuiltinIntegerType(16); -const IntegerType *Type::Int32Ty = new BuiltinIntegerType(32); -const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64); + +const Type *Type::getVoidTy(LLVMContext &C) { + static const Type *VoidTy = new Type(Type::VoidTyID); + return VoidTy; +} + +const Type *Type::getLabelTy(LLVMContext &C) { + static const Type *LabelTy = new Type(Type::LabelTyID); + return LabelTy; +} + +const Type *Type::getFloatTy(LLVMContext &C) { + static const Type *FloatTy = new Type(Type::FloatTyID); + return FloatTy; +} + +const Type *Type::getDoubleTy(LLVMContext &C) { + static const Type *DoubleTy = new Type(Type::DoubleTyID); + return DoubleTy; +} + +const Type *Type::getMetadataTy(LLVMContext &C) { + static const Type *MetadataTy = new Type(Type::MetadataTyID); + return MetadataTy; +} + +const Type *Type::getX86_FP80Ty(LLVMContext &C) { + static const Type *X86_FP80Ty = new Type(Type::X86_FP80TyID); + return X86_FP80Ty; +} + +const Type *Type::getFP128Ty(LLVMContext &C) { + static const Type *FP128Ty = new Type(Type::FP128TyID); + return FP128Ty; +} + +const Type *Type::getPPC_FP128Ty(LLVMContext &C) { + static const Type *PPC_FP128Ty = new Type(Type::PPC_FP128TyID); + return PPC_FP128Ty; +} + +const IntegerType *Type::getInt1Ty(LLVMContext &C) { + static const IntegerType *Int1Ty = new BuiltinIntegerType(1); + return Int1Ty; +} + +const IntegerType *Type::getInt8Ty(LLVMContext &C) { + static const IntegerType *Int8Ty = new BuiltinIntegerType(8); + return Int8Ty; +} + +const IntegerType *Type::getInt16Ty(LLVMContext &C) { + static const IntegerType *Int16Ty = new BuiltinIntegerType(16); + return Int16Ty; +} + +const IntegerType *Type::getInt32Ty(LLVMContext &C) { + static const IntegerType *Int32Ty = new BuiltinIntegerType(32); + return Int32Ty; +} + +const IntegerType *Type::getInt64Ty(LLVMContext &C) { + static const IntegerType *Int64Ty = new BuiltinIntegerType(64); + return Int64Ty; +} //===----------------------------------------------------------------------===// // Derived Type Constructors @@ -344,10 +395,11 @@ const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64); bool FunctionType::isValidReturnType(const Type *RetTy) { if (RetTy->isFirstClassType()) { if (const PointerType *PTy = dyn_cast<PointerType>(RetTy)) - return PTy->getElementType() != Type::MetadataTy; + return PTy->getElementType() != Type::getMetadataTy(RetTy->getContext()); return true; } - if (RetTy == Type::VoidTy || RetTy == Type::MetadataTy || + if (RetTy == Type::getVoidTy(RetTy->getContext()) || + RetTy == Type::getMetadataTy(RetTy->getContext()) || isa<OpaqueType>(RetTy)) return true; @@ -368,7 +420,8 @@ bool FunctionType::isValidReturnType(const Type *RetTy) { bool FunctionType::isValidArgumentType(const Type *ArgTy) { if ((!ArgTy->isFirstClassType() && !isa<OpaqueType>(ArgTy)) || (isa<PointerType>(ArgTy) && - cast<PointerType>(ArgTy)->getElementType() == Type::MetadataTy)) + cast<PointerType>(ArgTy)->getElementType() == + Type::getMetadataTy(ArgTy->getContext()))) return false; return true; @@ -488,7 +541,7 @@ void DerivedType::dropAllTypeUses() { // pick so long as it doesn't point back to this type. We choose something // concrete to avoid overhead for adding to AbstracTypeUser lists and stuff. for (unsigned i = 1, e = NumContainedTys; i != e; ++i) - ContainedTys[i] = Type::Int32Ty; + ContainedTys[i] = Type::getInt32Ty(getContext()); } } @@ -705,17 +758,17 @@ static bool TypeHasCycleThroughItself(const Type *Ty) { static ManagedStatic<TypeMap<IntegerValType, IntegerType> > IntegerTypes; -const IntegerType *IntegerType::get(unsigned NumBits) { +const IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) { assert(NumBits >= MIN_INT_BITS && "bitwidth too small"); assert(NumBits <= MAX_INT_BITS && "bitwidth too large"); // Check for the built-in integer types switch (NumBits) { - case 1: return cast<IntegerType>(Type::Int1Ty); - case 8: return cast<IntegerType>(Type::Int8Ty); - case 16: return cast<IntegerType>(Type::Int16Ty); - case 32: return cast<IntegerType>(Type::Int32Ty); - case 64: return cast<IntegerType>(Type::Int64Ty); + case 1: return cast<IntegerType>(Type::getInt1Ty(C)); + case 8: return cast<IntegerType>(Type::getInt8Ty(C)); + case 16: return cast<IntegerType>(Type::getInt16Ty(C)); + case 32: return cast<IntegerType>(Type::getInt32Ty(C)); + case 64: return cast<IntegerType>(Type::getInt64Ty(C)); default: break; } @@ -806,12 +859,13 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) { } bool ArrayType::isValidElementType(const Type *ElemTy) { - if (ElemTy == Type::VoidTy || ElemTy == Type::LabelTy || - ElemTy == Type::MetadataTy) + if (ElemTy == Type::getVoidTy(ElemTy->getContext()) || + ElemTy == Type::getLabelTy(ElemTy->getContext()) || + ElemTy == Type::getMetadataTy(ElemTy->getContext())) return false; if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy)) - if (PTy->getElementType() == Type::MetadataTy) + if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext())) return false; return true; @@ -885,12 +939,13 @@ StructType *StructType::get(LLVMContext &Context, const Type *type, ...) { } bool StructType::isValidElementType(const Type *ElemTy) { - if (ElemTy == Type::VoidTy || ElemTy == Type::LabelTy || - ElemTy == Type::MetadataTy) + if (ElemTy == Type::getVoidTy(ElemTy->getContext()) || + ElemTy == Type::getLabelTy(ElemTy->getContext()) || + ElemTy == Type::getMetadataTy(ElemTy->getContext())) return false; if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy)) - if (PTy->getElementType() == Type::MetadataTy) + if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext())) return false; return true; @@ -903,7 +958,7 @@ bool StructType::isValidElementType(const Type *ElemTy) { PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) { assert(ValueType && "Can't get a pointer to <null> type!"); - assert(ValueType != Type::VoidTy && + assert(ValueType != Type::getVoidTy(ValueType->getContext()) && "Pointer to void is not valid, use i8* instead!"); assert(isValidElementType(ValueType) && "Invalid type for pointer element!"); PointerValType PVT(ValueType, AddressSpace); @@ -930,11 +985,12 @@ PointerType *Type::getPointerTo(unsigned addrs) const { } bool PointerType::isValidElementType(const Type *ElemTy) { - if (ElemTy == Type::VoidTy || ElemTy == Type::LabelTy) + if (ElemTy == Type::getVoidTy(ElemTy->getContext()) || + ElemTy == Type::getLabelTy(ElemTy->getContext())) return false; if (const PointerType *PTy = dyn_cast<PointerType>(ElemTy)) - if (PTy->getElementType() == Type::MetadataTy) + if (PTy->getElementType() == Type::getMetadataTy(ElemTy->getContext())) return false; return true; diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 104f0377e8..2bdb5b8a79 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -47,11 +47,13 @@ Value::Value(const Type *ty, unsigned scid) SubclassData(0), VTy(checkType(ty)), UseList(0), Name(0) { if (isa<CallInst>(this) || isa<InvokeInst>(this)) - assert((VTy->isFirstClassType() || VTy == Type::VoidTy || + assert((VTy->isFirstClassType() || + VTy == Type::getVoidTy(ty->getContext()) || isa<OpaqueType>(ty) || VTy->getTypeID() == Type::StructTyID) && "invalid CallInst type!"); else if (!isa<Constant>(this) && !isa<BasicBlock>(this)) - assert((VTy->isFirstClassType() || VTy == Type::VoidTy || + assert((VTy->isFirstClassType() || + VTy == Type::getVoidTy(ty->getContext()) || isa<OpaqueType>(ty)) && "Cannot create non-first-class values except for constants!"); } @@ -178,7 +180,8 @@ void Value::setName(const Twine &NewName) { if (getName() == StringRef(NameStr, NameLen)) return; - assert(getType() != Type::VoidTy && "Cannot assign a name to void values!"); + assert(getType() != Type::getVoidTy(getContext()) && + "Cannot assign a name to void values!"); // Get the symbol table to update for this object. ValueSymbolTable *ST; diff --git a/lib/VMCore/ValueTypes.cpp b/lib/VMCore/ValueTypes.cpp index 8a046fd682..b10b3c1200 100644 --- a/lib/VMCore/ValueTypes.cpp +++ b/lib/VMCore/ValueTypes.cpp @@ -21,7 +21,7 @@ using namespace llvm; EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) { EVT VT; - VT.LLVMTy = IntegerType::get(BitWidth); + VT.LLVMTy = IntegerType::get(Context, BitWidth); assert(VT.isExtended() && "Type is not extended!"); return VT; } @@ -137,38 +137,38 @@ const Type *EVT::getTypeForEVT(LLVMContext &Context) const { default: assert(isExtended() && "Type is not extended!"); return LLVMTy; - case MVT::isVoid: return Type::VoidTy; - case MVT::i1: return Type::Int1Ty; - case MVT::i8: return Type::Int8Ty; - case MVT::i16: return Type::Int16Ty; - case MVT::i32: return Type::Int32Ty; - case MVT::i64: return Type::Int64Ty; - case MVT::i128: return IntegerType::get(128); - case MVT::f32: return Type::FloatTy; - case MVT::f64: return Type::DoubleTy; - case MVT::f80: return Type::X86_FP80Ty; - case MVT::f128: return Type::FP128Ty; - case MVT::ppcf128: return Type::PPC_FP128Ty; - case MVT::v2i8: return VectorType::get(Type::Int8Ty, 2); - case MVT::v4i8: return VectorType::get(Type::Int8Ty, 4); - case MVT::v8i8: return VectorType::get(Type::Int8Ty, 8); - case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16); - case MVT::v32i8: return VectorType::get(Type::Int8Ty, 32); - case MVT::v2i16: return VectorType::get(Type::Int16Ty, 2); - case MVT::v4i16: return VectorType::get(Type::Int16Ty, 4); - case MVT::v8i16: return VectorType::get(Type::Int16Ty, 8); - case MVT::v16i16: return VectorType::get(Type::Int16Ty, 16); - case MVT::v2i32: return VectorType::get(Type::Int32Ty, 2); - case MVT::v4i32: return VectorType::get(Type::Int32Ty, 4); - case MVT::v8i32: return VectorType::get(Type::Int32Ty, 8); - case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1); - case MVT::v2i64: return VectorType::get(Type::Int64Ty, 2); - case MVT::v4i64: return VectorType::get(Type::Int64Ty, 4); - case MVT::v2f32: return VectorType::get(Type::FloatTy, 2); - case MVT::v4f32: return VectorType::get(Type::FloatTy, 4); - case MVT::v8f32: return VectorType::get(Type::FloatTy, 8); - case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2); - case MVT::v4f64: return VectorType::get(Type::DoubleTy, 4); + case MVT::isVoid: return Type::getVoidTy(Context); + case MVT::i1: return Type::getInt1Ty(Context); + case MVT::i8: return Type::getInt8Ty(Context); + case MVT::i16: return Type::getInt16Ty(Context); + case MVT::i32: return Type::getInt32Ty(Context); + case MVT::i64: return Type::getInt64Ty(Context); + case MVT::i128: return IntegerType::get(Context, 128); + case MVT::f32: return Type::getFloatTy(Context); + case MVT::f64: return Type::getDoubleTy(Context); + case MVT::f80: return Type::getX86_FP80Ty(Context); + case MVT::f128: return Type::getFP128Ty(Context); + case MVT::ppcf128: return Type::getPPC_FP128Ty(Context); + case MVT::v2i8: return VectorType::get(Type::getInt8Ty(Context), 2); + case MVT::v4i8: return VectorType::get(Type::getInt8Ty(Context), 4); + case MVT::v8i8: return VectorType::get(Type::getInt8Ty(Context), 8); + case MVT::v16i8: return VectorType::get(Type::getInt8Ty(Context), 16); + case MVT::v32i8: return VectorType::get(Type::getInt8Ty(Context), 32); + case MVT::v2i16: return VectorType::get(Type::getInt16Ty(Context), 2); + case MVT::v4i16: return VectorType::get(Type::getInt16Ty(Context), 4); + case MVT::v8i16: return VectorType::get(Type::getInt16Ty(Context), 8); + case MVT::v16i16: return VectorType::get(Type::getInt16Ty(Context), 16); + case MVT::v2i32: return VectorType::get(Type::getInt32Ty(Context), 2); + case MVT::v4i32: return VectorType::get(Type::getInt32Ty(Context), 4); + case MVT::v8i32: return VectorType::get(Type::getInt32Ty(Context), 8); + case MVT::v1i64: return VectorType::get(Type::getInt64Ty(Context), 1); + case MVT::v2i64: return VectorType::get(Type::getInt64Ty(Context), 2); + case MVT::v4i64: return VectorType::get(Type::getInt64Ty(Context), 4); + case MVT::v2f32: return VectorType::get(Type::getFloatTy(Context), 2); + case MVT::v4f32: return VectorType::get(Type::getFloatTy(Context), 4); + case MVT::v8f32: return VectorType::get(Type::getFloatTy(Context), 8); + case MVT::v2f64: return VectorType::get(Type::getDoubleTy(Context), 2); + case MVT::v4f64: return VectorType::get(Type::getDoubleTy(Context), 4); } } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 70370b8c0f..d53cf0eb04 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -558,11 +558,12 @@ void Verifier::visitFunction(Function &F) { "# formal arguments must match # of arguments for function type!", &F, FT); Assert1(F.getReturnType()->isFirstClassType() || - F.getReturnType() == Type::VoidTy || + F.getReturnType() == Type::getVoidTy(F.getContext()) || isa<StructType>(F.getReturnType()), "Functions cannot return aggregate values!", &F); - Assert1(!F.hasStructRetAttr() || F.getReturnType() == Type::VoidTy, + Assert1(!F.hasStructRetAttr() || + F.getReturnType() == Type::getVoidTy(F.getContext()), "Invalid struct return type!", &F); const AttrListPtr &Attrs = F.getAttributes(); @@ -590,7 +591,7 @@ void Verifier::visitFunction(Function &F) { bool isLLVMdotName = F.getName().size() >= 5 && F.getName().substr(0, 5) == "llvm."; if (!isLLVMdotName) - Assert1(F.getReturnType() != Type::MetadataTy, + Assert1(F.getReturnType() != Type::getMetadataTy(F.getContext()), "Function may not return metadata unless it's an intrinsic", &F); // Check that the argument values match the function type for this function... @@ -603,7 +604,7 @@ void Verifier::visitFunction(Function &F) { Assert1(I->getType()->isFirstClassType(), "Function arguments must have first-class types!", I); if (!isLLVMdotName) - Assert2(I->getType() != Type::MetadataTy, + Assert2(I->getType() != Type::getMetadataTy(F.getContext()), "Function takes metadata but isn't an intrinsic", I, &F); } @@ -688,7 +689,7 @@ void Verifier::visitTerminatorInst(TerminatorInst &I) { void Verifier::visitReturnInst(ReturnInst &RI) { Function *F = RI.getParent()->getParent(); unsigned N = RI.getNumOperands(); - if (F->getReturnType() == Type::VoidTy) + if (F->getReturnType() == Type::getVoidTy(RI.getContext())) Assert2(N == 0, "Found return instr that returns non-void in Function of void " "return type!", &RI, F->getReturnType()); @@ -1048,12 +1049,12 @@ void Verifier::VerifyCallSite(CallSite CS) { // Verify that there's no metadata unless it's a direct call to an intrinsic. if (!CS.getCalledFunction() || CS.getCalledFunction()->getName().size() < 5 || CS.getCalledFunction()->getName().substr(0, 5) != "llvm.") { - Assert1(FTy->getReturnType() != Type::MetadataTy, + Assert1(FTy->getReturnType() != Type::getMetadataTy(I->getContext()), "Only intrinsics may return metadata", I); for (FunctionType::param_iterator PI = FTy->param_begin(), PE = FTy->param_end(); PI != PE; ++PI) - Assert1(PI->get() != Type::MetadataTy, "Function has metadata parameter " - "but isn't an intrinsic", I); + Assert1(PI->get() != Type::getMetadataTy(I->getContext()), + "Function has metadata parameter but isn't an intrinsic", I); } visitInstruction(*I); @@ -1218,7 +1219,8 @@ void Verifier::visitLoadInst(LoadInst &LI) { cast<PointerType>(LI.getOperand(0)->getType())->getElementType(); Assert2(ElTy == LI.getType(), "Load result type does not match pointer operand type!", &LI, ElTy); - Assert1(ElTy != Type::MetadataTy, "Can't load metadata!", &LI); + Assert1(ElTy != Type::getMetadataTy(LI.getContext()), + "Can't load metadata!", &LI); visitInstruction(LI); } @@ -1227,7 +1229,8 @@ void Verifier::visitStoreInst(StoreInst &SI) { cast<PointerType>(SI.getOperand(1)->getType())->getElementType(); Assert2(ElTy == SI.getOperand(0)->getType(), "Stored value type does not match pointer operand type!", &SI, ElTy); - Assert1(ElTy != Type::MetadataTy, "Can't store metadata!", &SI); + Assert1(ElTy != Type::getMetadataTy(SI.getContext()), + "Can't store metadata!", &SI); visitInstruction(SI); } @@ -1278,24 +1281,25 @@ void Verifier::visitInstruction(Instruction &I) { // Check that void typed values don't have names - Assert1(I.getType() != Type::VoidTy || !I.hasName(), + Assert1(I.getType() != Type::getVoidTy(I.getContext()) || !I.hasName(), "Instruction has a name, but provides a void value!", &I); // Check that the return value of the instruction is either void or a legal // value type. - Assert1(I.getType() == Type::VoidTy || I.getType()->isFirstClassType() + Assert1(I.getType() == Type::getVoidTy(I.getContext()) || + I.getType()->isFirstClassType() || ((isa<CallInst>(I) || isa<InvokeInst>(I)) && isa<StructType>(I.getType())), "Instruction returns a non-scalar type!", &I); // Check that the instruction doesn't produce metadata or metadata*. Calls // all already checked against the callee type. - Assert1(I.getType() != Type::MetadataTy || + Assert1(I.getType() != Type::getMetadataTy(I.getContext()) || isa<CallInst>(I) || isa<InvokeInst>(I), "Invalid use of metadata!", &I); if (const PointerType *PTy = dyn_cast<PointerType>(I.getType())) - Assert1(PTy->getElementType() != Type::MetadataTy, + Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()), "Instructions may not produce pointer to metadata.", &I); @@ -1322,7 +1326,7 @@ void Verifier::visitInstruction(Instruction &I) { if (const PointerType *PTy = dyn_cast<PointerType>(I.getOperand(i)->getType())) - Assert1(PTy->getElementType() != Type::MetadataTy, + Assert1(PTy->getElementType() != Type::getMetadataTy(I.getContext()), "Invalid use of metadata pointer.", &I); if (Function *F = dyn_cast<Function>(I.getOperand(i))) { diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 9d4e98ca50..4e15732b6e 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -297,12 +297,13 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) { if (isa<StructType>(BBTerm->getType())) BBTerm->replaceAllUsesWith(UndefValue::get(BBTerm->getType())); - else if (BB->getTerminator()->getType() != Type::VoidTy) + else if (BB->getTerminator()->getType() != + Type::getVoidTy(BB->getContext())) BBTerm->replaceAllUsesWith(Constant::getNullValue(BBTerm->getType())); // Replace the old terminator instruction. BB->getInstList().pop_back(); - new UnreachableInst(BB); + new UnreachableInst(BB->getContext(), BB); } // The CFG Simplifier pass may delete one of the basic blocks we are @@ -332,7 +333,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) { for (unsigned i = 0, e = BlockInfo.size(); i != e; ++i) { ValueSymbolTable &ST = BlockInfo[i].first->getValueSymbolTable(); Value* V = ST.lookup(BlockInfo[i].second); - if (V && V->getType() == Type::LabelTy) + if (V && V->getType() == Type::getLabelTy(V->getContext())) BBs.push_back(cast<BasicBlock>(V)); } return true; @@ -390,7 +391,7 @@ bool ReduceCrashingInstructions::TestInsts(std::vector<const Instruction*> for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { Instruction *Inst = I++; if (!Instructions.count(Inst) && !isa<TerminatorInst>(Inst)) { - if (Inst->getType() != Type::VoidTy) + if (Inst->getType() != Type::getVoidTy(Inst->getContext())) Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); Inst->eraseFromParent(); } diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 684dde3538..9fdcc1bdea 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -73,7 +73,7 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I, // If this instruction produces a value, replace any users with null values if (isa<StructType>(TheInst->getType())) TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType())); - else if (TheInst->getType() != Type::VoidTy) + else if (TheInst->getType() != Type::getVoidTy(I->getContext())) TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType())); // Remove the instruction from the program. @@ -184,7 +184,8 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) { std::vector<Constant*> ArrayElts; for (unsigned i = 0, e = TorList.size(); i != e; ++i) { std::vector<Constant*> Elts; - Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second)); + Elts.push_back(ConstantInt::get( + Type::getInt32Ty(TorList[i].first->getContext()), TorList[i].second)); Elts.push_back(TorList[i].first); ArrayElts.push_back(ConstantStruct::get( TorList[i].first->getContext(), Elts)); diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 00f26fe823..64dfe8853e 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -682,12 +682,12 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, } // Call the old main function and return its result - BasicBlock *BB = BasicBlock::Create("entry", newMain); + BasicBlock *BB = BasicBlock::Create(Safe->getContext(), "entry", newMain); CallInst *call = CallInst::Create(oldMainProto, args.begin(), args.end(), "", BB); // If the type of old function wasn't void, return value of call - ReturnInst::Create(call, BB); + ReturnInst::Create(Safe->getContext(), call, BB); } // The second nasty issue we must deal with in the JIT is that the Safe @@ -699,8 +699,9 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // Prototype: void *getPointerToNamedFunction(const char* Name) Constant *resolverFunc = Safe->getOrInsertFunction("getPointerToNamedFunction", - PointerType::getUnqual(Type::Int8Ty), - PointerType::getUnqual(Type::Int8Ty), (Type *)0); + PointerType::getUnqual(Type::getInt8Ty(Safe->getContext())), + PointerType::getUnqual(Type::getInt8Ty(Safe->getContext())), + (Type *)0); // Use the function we just added to get addresses of functions we need. for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) { @@ -711,7 +712,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // Don't forward functions which are external in the test module too. if (TestFn && !TestFn->isDeclaration()) { // 1. Add a string constant with its name to the global file - Constant *InitArray = ConstantArray::get(F->getName()); + Constant *InitArray = ConstantArray::get(F->getContext(), F->getName()); GlobalVariable *funcName = new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/, GlobalValue::InternalLinkage, InitArray, @@ -721,7 +722,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // sbyte* so it matches the signature of the resolver function. // GetElementPtr *funcName, ulong 0, ulong 0 - std::vector<Constant*> GEPargs(2, Constant::getNullValue(Type::Int32Ty)); + std::vector<Constant*> GEPargs(2, + Constant::getNullValue(Type::getInt32Ty(F->getContext()))); Value *GEP = ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2); std::vector<Value*> ResolverArgs; @@ -743,9 +745,12 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, GlobalValue::InternalLinkage, F->getName() + "_wrapper", F->getParent()); - BasicBlock *EntryBB = BasicBlock::Create("entry", FuncWrapper); - BasicBlock *DoCallBB = BasicBlock::Create("usecache", FuncWrapper); - BasicBlock *LookupBB = BasicBlock::Create("lookupfp", FuncWrapper); + BasicBlock *EntryBB = BasicBlock::Create(F->getContext(), + "entry", FuncWrapper); + BasicBlock *DoCallBB = BasicBlock::Create(F->getContext(), + "usecache", FuncWrapper); + BasicBlock *LookupBB = BasicBlock::Create(F->getContext(), + "lookupfp", FuncWrapper); // Check to see if we already looked up the value. Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB); @@ -782,13 +787,13 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, Args.push_back(i); // Pass on the arguments to the real function, return its result - if (F->getReturnType() == Type::VoidTy) { + if (F->getReturnType() == Type::getVoidTy(F->getContext())) { CallInst::Create(FuncPtr, Args.begin(), Args.end(), "", DoCallBB); - ReturnInst::Create(DoCallBB); + ReturnInst::Create(F->getContext(), DoCallBB); } else { CallInst *Call = CallInst::Create(FuncPtr, Args.begin(), Args.end(), "retval", DoCallBB); - ReturnInst::Create(Call, DoCallBB); + ReturnInst::Create(F->getContext(),Call, DoCallBB); } // Use the wrapper function instead of the old function diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 36054fd093..9c8cc6c08f 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -195,8 +195,9 @@ int main(int argc, char **argv, char * const *envp) { // If the program doesn't explicitly call exit, we will need the Exit // function later on to make an explicit call, so get the function now. - Constant *Exit = Mod->getOrInsertFunction("exit", Type::VoidTy, - Type::Int32Ty, NULL); + Constant *Exit = Mod->getOrInsertFunction("exit", Type::getVoidTy(Context), + Type::getInt32Ty(Context), + NULL); // Reset errno to zero on entry to main. errno = 0; diff --git a/unittests/ExecutionEngine/ExecutionEngineTest.cpp b/unittests/ExecutionEngine/ExecutionEngineTest.cpp index 8478ebd230..2106e86b59 100644 --- a/unittests/ExecutionEngine/ExecutionEngineTest.cpp +++ b/unittests/ExecutionEngine/ExecutionEngineTest.cpp @@ -40,7 +40,8 @@ protected: }; TEST_F(ExecutionEngineTest, ForwardGlobalMapping) { - GlobalVariable *G1 = NewExtGlobal(Type::Int32Ty, "Global1"); + GlobalVariable *G1 = + NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1"); int32_t Mem1 = 3; Engine->addGlobalMapping(G1, &Mem1); EXPECT_EQ(&Mem1, Engine->getPointerToGlobalIfAvailable(G1)); @@ -52,7 +53,8 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) { Engine->updateGlobalMapping(G1, &Mem2); EXPECT_EQ(&Mem2, Engine->getPointerToGlobalIfAvailable(G1)); - GlobalVariable *G2 = NewExtGlobal(Type::Int32Ty, "Global1"); + GlobalVariable *G2 = + NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1"); EXPECT_EQ(NULL, Engine->getPointerToGlobalIfAvailable(G2)) << "The NULL return shouldn't depend on having called" << " updateGlobalMapping(..., NULL)"; @@ -64,7 +66,8 @@ TEST_F(ExecutionEngineTest, ForwardGlobalMapping) { } TEST_F(ExecutionEngineTest, ReverseGlobalMapping) { - GlobalVariable *G1 = NewExtGlobal(Type::Int32Ty, "Global1"); + GlobalVariable *G1 = + NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global1"); int32_t Mem1 = 3; Engine->addGlobalMapping(G1, &Mem1); @@ -74,7 +77,8 @@ TEST_F(ExecutionEngineTest, ReverseGlobalMapping) { EXPECT_EQ(NULL, Engine->getGlobalValueAtAddress(&Mem1)); EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2)); - GlobalVariable *G2 = NewExtGlobal(Type::Int32Ty, "Global2"); + GlobalVariable *G2 = + NewExtGlobal(Type::getInt32Ty(getGlobalContext()), "Global2"); Engine->updateGlobalMapping(G2, &Mem1); EXPECT_EQ(G2, Engine->getGlobalValueAtAddress(&Mem1)); EXPECT_EQ(G1, Engine->getGlobalValueAtAddress(&Mem2)); diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp index e8907391af..87e3280cf9 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp @@ -80,8 +80,8 @@ Function *buildFunction(Module *M) { TypeBuilder<int32_t(int32_t), false>::get(getGlobalContext()), GlobalValue::ExternalLinkage, "id", M); Value *Arg = Result->arg_begin(); - BasicBlock *BB = BasicBlock::Create("entry", Result); - ReturnInst::Create(Arg, BB); + BasicBlock *BB = BasicBlock::Create(M->getContext(), "entry", Result); + ReturnInst::Create(M->getContext(), Arg, BB); return Result; } diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index d56a52a430..89a4be70be 100644 --- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -20,7 +20,8 @@ namespace { Function *makeFakeFunction() { std::vector<const Type*> params; - const FunctionType *FTy = FunctionType::get(Type::VoidTy, params, false); + const FunctionType *FTy = + FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false); return Function::Create(FTy, GlobalValue::ExternalLinkage); } diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index d5aa0914fb..9e70a548ef 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -34,7 +34,7 @@ Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) { const FunctionType *FTy = FunctionType::get(G->getType()->getElementType(), params, false); Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M); - BasicBlock *Entry = BasicBlock::Create("entry", F); + BasicBlock *Entry = BasicBlock::Create(M->getContext(), "entry", F); IRBuilder<> builder(Entry); Value *Load = builder.CreateLoad(G); const Type *GTy = G->getType()->getElementType(); @@ -69,7 +69,7 @@ TEST(JIT, GlobalInFunction) { ASSERT_EQ(Error, ""); // Create a global variable. - const Type *GTy = Type::Int32Ty; + const Type *GTy = Type::getInt32Ty(context); GlobalVariable *G = new GlobalVariable( *M, GTy, diff --git a/unittests/Support/TypeBuilderTest.cpp b/unittests/Support/TypeBuilderTest.cpp index 2057093353..bd9f5d64a2 100644 --- a/unittests/Support/TypeBuilderTest.cpp +++ b/unittests/Support/TypeBuilderTest.cpp @@ -17,132 +17,132 @@ using namespace llvm; namespace { TEST(TypeBuilderTest, Void) { - EXPECT_EQ(Type::VoidTy, (TypeBuilder<void, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::VoidTy, (TypeBuilder<void, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder<void, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getVoidTy(getGlobalContext()), (TypeBuilder<void, false>::get(getGlobalContext()))); // Special case for C compatibility: - EXPECT_EQ(PointerType::getUnqual(Type::Int8Ty), + EXPECT_EQ(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())), (TypeBuilder<void*, false>::get(getGlobalContext()))); } TEST(TypeBuilderTest, HostIntegers) { - EXPECT_EQ(Type::Int8Ty, (TypeBuilder<int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, (TypeBuilder<uint8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int16Ty, (TypeBuilder<int16_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int16Ty, (TypeBuilder<uint16_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int32Ty, (TypeBuilder<int32_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int32Ty, (TypeBuilder<uint32_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int64Ty, (TypeBuilder<int64_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int64Ty, (TypeBuilder<uint64_t, false>::get(getGlobalContext()))); - - EXPECT_EQ(IntegerType::get(sizeof(size_t) * CHAR_BIT), + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<int8_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<uint8_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder<int16_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt16Ty(getGlobalContext()), (TypeBuilder<uint16_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder<int32_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (TypeBuilder<uint32_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder<int64_t, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getInt64Ty(getGlobalContext()), (TypeBuilder<uint64_t, false>::get(getGlobalContext()))); + + EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(size_t) * CHAR_BIT), (TypeBuilder<size_t, false>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(sizeof(ptrdiff_t) * CHAR_BIT), + EXPECT_EQ(IntegerType::get(getGlobalContext(), sizeof(ptrdiff_t) * CHAR_BIT), (TypeBuilder<ptrdiff_t, false>::get(getGlobalContext()))); } TEST(TypeBuilderTest, CrossCompilableIntegers) { - EXPECT_EQ(IntegerType::get(1), (TypeBuilder<types::i<1>, true>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(1), (TypeBuilder<types::i<1>, false>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(72), (TypeBuilder<types::i<72>, true>::get(getGlobalContext()))); - EXPECT_EQ(IntegerType::get(72), (TypeBuilder<types::i<72>, false>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder<types::i<1>, true>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 1), (TypeBuilder<types::i<1>, false>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder<types::i<72>, true>::get(getGlobalContext()))); + EXPECT_EQ(IntegerType::get(getGlobalContext(), 72), (TypeBuilder<types::i<72>, false>::get(getGlobalContext()))); } TEST(TypeBuilderTest, Float) { - EXPECT_EQ(Type::FloatTy, (TypeBuilder<float, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::DoubleTy, (TypeBuilder<double, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<float, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<double, false>::get(getGlobalContext()))); // long double isn't supported yet. - EXPECT_EQ(Type::FloatTy, (TypeBuilder<types::ieee_float, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::FloatTy, (TypeBuilder<types::ieee_float, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::DoubleTy, (TypeBuilder<types::ieee_double, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::DoubleTy, (TypeBuilder<types::ieee_double, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::X86_FP80Ty, (TypeBuilder<types::x86_fp80, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::X86_FP80Ty, (TypeBuilder<types::x86_fp80, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::FP128Ty, (TypeBuilder<types::fp128, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::FP128Ty, (TypeBuilder<types::fp128, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::PPC_FP128Ty, (TypeBuilder<types::ppc_fp128, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::PPC_FP128Ty, (TypeBuilder<types::ppc_fp128, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<types::ieee_float, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getFloatTy(getGlobalContext()), (TypeBuilder<types::ieee_float, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<types::ieee_double, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getDoubleTy(getGlobalContext()), (TypeBuilder<types::ieee_double, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder<types::x86_fp80, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getX86_FP80Ty(getGlobalContext()), (TypeBuilder<types::x86_fp80, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder<types::fp128, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getFP128Ty(getGlobalContext()), (TypeBuilder<types::fp128, false>::get(getGlobalContext()))); + EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder<types::ppc_fp128, true>::get(getGlobalContext()))); + EXPECT_EQ(Type::getPPC_FP128Ty(getGlobalContext()), (TypeBuilder<types::ppc_fp128, false>::get(getGlobalContext()))); } TEST(TypeBuilderTest, Derived) { - EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)), + EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext()))), (TypeBuilder<int8_t**, false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::Int8Ty, 7), + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), (TypeBuilder<int8_t[7], false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::Int8Ty, 0), + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), (TypeBuilder<int8_t[], false>::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)), + EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext()))), (TypeBuilder<types::i<8>**, false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::Int8Ty, 7), + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), (TypeBuilder<types::i<8>[7], false>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::Int8Ty, 0), + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), (TypeBuilder<types::i<8>[], false>::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)), + EXPECT_EQ(PointerType::getUnqual(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext()))), (TypeBuilder<types::i<8>**, true>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::Int8Ty, 7), + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 7), (TypeBuilder<types::i<8>[7], true>::get(getGlobalContext()))); - EXPECT_EQ(ArrayType::get(Type::Int8Ty, 0), + EXPECT_EQ(ArrayType::get(Type::getInt8Ty(getGlobalContext()), 0), (TypeBuilder<types::i<8>[], true>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<const int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<volatile int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<const volatile int8_t, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<const types::i<8>, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<volatile types::i<8>, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<const volatile types::i<8>, false>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<const types::i<8>, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<volatile types::i<8>, true>::get(getGlobalContext()))); - EXPECT_EQ(Type::Int8Ty, + EXPECT_EQ(Type::getInt8Ty(getGlobalContext()), (TypeBuilder<const volatile types::i<8>, true>::get(getGlobalContext()))); - EXPECT_EQ(PointerType::getUnqual(Type::Int8Ty), + EXPECT_EQ(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())), (TypeBuilder<const volatile int8_t*const volatile, false>::get(getGlobalContext()))); } TEST(TypeBuilderTest, Functions) { std::vector<const Type*> params; - EXPECT_EQ(FunctionType::get(Type::VoidTy, params, false), + EXPECT_EQ(FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false), (TypeBuilder<void(), true>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder<int8_t(...), false>::get(getGlobalContext()))); params.push_back(TypeBuilder<int32_t*, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), (TypeBuilder<int8_t(const int32_t*), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder<int8_t(const int32_t*, ...), false>::get(getGlobalContext()))); params.push_back(TypeBuilder<char*, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), (TypeBuilder<int8_t(int32_t*, void*), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder<int8_t(int32_t*, char*, ...), false>::get(getGlobalContext()))); params.push_back(TypeBuilder<char, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), (TypeBuilder<int8_t(int32_t*, void*, char), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder<int8_t(int32_t*, char*, char, ...), false>::get(getGlobalContext()))); params.push_back(TypeBuilder<char, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), (TypeBuilder<int8_t(int32_t*, void*, char, char), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder<int8_t(int32_t*, char*, char, char, ...), false>::get(getGlobalContext()))); params.push_back(TypeBuilder<char, false>::get(getGlobalContext())); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, false), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), (TypeBuilder<int8_t(int32_t*, void*, char, char, char), false>::get(getGlobalContext()))); - EXPECT_EQ(FunctionType::get(Type::Int8Ty, params, true), + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder<int8_t(int32_t*, char*, char, char, char, ...), false>::get(getGlobalContext()))); } diff --git a/unittests/Support/ValueHandleTest.cpp b/unittests/Support/ValueHandleTest.cpp index 5e6cd61035..c6b53561d9 100644 --- a/unittests/Support/ValueHandleTest.cpp +++ b/unittests/Support/ValueHandleTest.cpp @@ -26,8 +26,8 @@ protected: std::auto_ptr<BitCastInst> BitcastV; ValueHandle() : - ConstantV(ConstantInt::get(Type::Int32Ty, 0)), - BitcastV(new BitCastInst(ConstantV, Type::Int32Ty)) { + ConstantV(ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 0)), + BitcastV(new BitCastInst(ConstantV, Type::getInt32Ty(getGlobalContext()))) { } }; @@ -45,8 +45,8 @@ TEST_F(ValueHandle, WeakVH_BasicOperation) { // Make sure I can call a method on the underlying Value. It // doesn't matter which method. - EXPECT_EQ(Type::Int32Ty, WVH->getType()); - EXPECT_EQ(Type::Int32Ty, (*WVH).getType()); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), WVH->getType()); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*WVH).getType()); } TEST_F(ValueHandle, WeakVH_Comparisons) { @@ -200,8 +200,8 @@ TEST_F(ValueHandle, CallbackVH_BasicOperation) { // Make sure I can call a method on the underlying Value. It // doesn't matter which method. - EXPECT_EQ(Type::Int32Ty, CVH->getType()); - EXPECT_EQ(Type::Int32Ty, (*CVH).getType()); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), CVH->getType()); + EXPECT_EQ(Type::getInt32Ty(getGlobalContext()), (*CVH).getType()); } TEST_F(ValueHandle, CallbackVH_Comparisons) { @@ -302,7 +302,7 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) { private: virtual void deleted() { - getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::Int32Ty)); + getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::getInt32Ty(getGlobalContext()))); setValPtr(NULL); } virtual void allUsesReplacedWith(Value *new_value) { @@ -319,11 +319,11 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) { RVH = BitcastV.get(); std::auto_ptr<BinaryOperator> BitcastUser( BinaryOperator::CreateAdd(RVH, - Constant::getNullValue(Type::Int32Ty))); + Constant::getNullValue(Type::getInt32Ty(getGlobalContext())))); EXPECT_EQ(BitcastV.get(), BitcastUser->getOperand(0)); BitcastV.reset(); // Would crash without the ValueHandler. - EXPECT_EQ(Constant::getNullValue(Type::Int32Ty), RVH.AURWArgument); - EXPECT_EQ(Constant::getNullValue(Type::Int32Ty), + EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), RVH.AURWArgument); + EXPECT_EQ(Constant::getNullValue(Type::getInt32Ty(getGlobalContext())), BitcastUser->getOperand(0)); } diff --git a/unittests/VMCore/ConstantsTest.cpp b/unittests/VMCore/ConstantsTest.cpp index 42bb6cc2ec..8f28407b8d 100644 --- a/unittests/VMCore/ConstantsTest.cpp +++ b/unittests/VMCore/ConstantsTest.cpp @@ -16,7 +16,7 @@ namespace llvm { namespace { TEST(ConstantsTest, Integer_i1) { - const IntegerType* Int1 = IntegerType::get(1); + const IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1); Constant* One = ConstantInt::get(Int1, 1, true); Constant* Zero = ConstantInt::get(Int1, 0); Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true); @@ -97,7 +97,7 @@ TEST(ConstantsTest, Integer_i1) { } TEST(ConstantsTest, IntSigns) { - const IntegerType* Int8Ty = Type::Int8Ty; + const IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext()); EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue()); EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue()); EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue()); diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp index 22519f9f30..15a128bc44 100644 --- a/unittests/VMCore/MetadataTest.cpp +++ b/unittests/VMCore/MetadataTest.cpp @@ -105,8 +105,8 @@ TEST(MDNodeTest, Simple) { } TEST(MDNodeTest, Delete) { - Constant *C = ConstantInt::get(Type::Int32Ty, 1); - Instruction *I = new BitCastInst(C, Type::Int32Ty); + Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1); + Instruction *I = new BitCastInst(C, Type::getInt32Ty(getGlobalContext())); Value *const V = I; MDNode *n = MDNode::get(Context, &V, 1); @@ -122,8 +122,8 @@ TEST(MDNodeTest, Delete) { } TEST(NamedMDNodeTest, Search) { - Constant *C = ConstantInt::get(Type::Int32Ty, 1); - Constant *C2 = ConstantInt::get(Type::Int32Ty, 2); + Constant *C = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 1); + Constant *C2 = ConstantInt::get(Type::getInt32Ty(getGlobalContext()), 2); Value *const V = C; Value *const V2 = C2; @@ -134,7 +134,7 @@ TEST(NamedMDNodeTest, Search) { Module *M = new Module("MyModule", getGlobalContext()); const char *Name = "llvm.NMD1"; - NamedMDNode *NMD = NamedMDNode::Create(Name, &Nodes[0], 2, M); + NamedMDNode *NMD = NamedMDNode::Create(getGlobalContext(), Name, &Nodes[0], 2, M); std::ostringstream oss; NMD->print(oss); EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n!0 = metadata !{i32 1}\n" diff --git a/unittests/VMCore/PassManagerTest.cpp b/unittests/VMCore/PassManagerTest.cpp index 8122e2cad9..5c3f04ef82 100644 --- a/unittests/VMCore/PassManagerTest.cpp +++ b/unittests/VMCore/PassManagerTest.cpp @@ -272,7 +272,7 @@ namespace llvm { char OnTheFlyTest::ID=0; TEST(PassManager, RunOnce) { - Module M("test-once", *new LLVMContext()); + Module M("test-once", getGlobalContext()); struct ModuleNDNM *mNDNM = new ModuleNDNM(); struct ModuleDNM *mDNM = new ModuleDNM(); struct ModuleNDM *mNDM = new ModuleNDM(); @@ -296,7 +296,7 @@ namespace llvm { } TEST(PassManager, ReRun) { - Module M("test-rerun", *new LLVMContext()); + Module M("test-rerun", getGlobalContext()); struct ModuleNDNM *mNDNM = new ModuleNDNM(); struct ModuleDNM *mDNM = new ModuleDNM(); struct ModuleNDM *mNDM = new ModuleNDM(); @@ -387,7 +387,7 @@ namespace llvm { Module* makeLLVMModule() { // Module Construction - Module* mod = new Module("test-mem", *new LLVMContext()); + Module* mod = new Module("test-mem", getGlobalContext()); mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" "a0:0:64-s0:64:64-f80:128:128"); @@ -396,14 +396,14 @@ namespace llvm { // Type Definitions std::vector<const Type*>FuncTy_0_args; FunctionType* FuncTy_0 = FunctionType::get( - /*Result=*/IntegerType::get(32), + /*Result=*/IntegerType::get(getGlobalContext(), 32), /*Params=*/FuncTy_0_args, /*isVarArg=*/false); std::vector<const Type*>FuncTy_2_args; - FuncTy_2_args.push_back(IntegerType::get(1)); + FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1)); FunctionType* FuncTy_2 = FunctionType::get( - /*Result=*/Type::VoidTy, + /*Result=*/Type::getVoidTy(getGlobalContext()), /*Params=*/FuncTy_2_args, /*isVarArg=*/false); @@ -454,7 +454,7 @@ namespace llvm { // Function: test1 (func_test1) { - BasicBlock* label_entry = BasicBlock::Create("entry",func_test1,0); + BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0); // Block entry (label_entry) CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry); @@ -462,14 +462,14 @@ namespace llvm { int32_3->setTailCall(false);AttrListPtr int32_3_PAL; int32_3->setAttributes(int32_3_PAL); - ReturnInst::Create(int32_3, label_entry); + ReturnInst::Create(getGlobalContext(), int32_3, label_entry); } // Function: test2 (func_test2) { - BasicBlock* label_entry_5 = BasicBlock::Create("entry",func_test2,0); + BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0); // Block entry (label_entry_5) CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5); @@ -477,14 +477,14 @@ namespace llvm { int32_6->setTailCall(false);AttrListPtr int32_6_PAL; int32_6->setAttributes(int32_6_PAL); - ReturnInst::Create(int32_6, label_entry_5); + ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5); } // Function: test3 (func_test3) { - BasicBlock* label_entry_8 = BasicBlock::Create("entry",func_test3,0); + BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0); // Block entry (label_entry_8) CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8); @@ -492,7 +492,7 @@ namespace llvm { int32_9->setTailCall(false);AttrListPtr int32_9_PAL; int32_9->setAttributes(int32_9_PAL); - ReturnInst::Create(int32_9, label_entry_8); + ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8); } @@ -502,10 +502,10 @@ namespace llvm { Value* int1_f = args++; int1_f->setName("f"); - BasicBlock* label_entry_11 = BasicBlock::Create("entry",func_test4,0); - BasicBlock* label_bb = BasicBlock::Create("bb",func_test4,0); - BasicBlock* label_bb1 = BasicBlock::Create("bb1",func_test4,0); - BasicBlock* label_return = BasicBlock::Create("return",func_test4,0); + BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0); + BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0); + BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0); + BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0); // Block entry (label_entry_11) BranchInst::Create(label_bb, label_entry_11); @@ -517,7 +517,7 @@ namespace llvm { BranchInst::Create(label_bb1, label_return, int1_f, label_bb1); // Block return (label_return) - ReturnInst::Create(label_return); + ReturnInst::Create(getGlobalContext(), label_return); } return mod; diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp index 1497e9029d..23919d97f2 100644 --- a/utils/TableGen/IntrinsicEmitter.cpp +++ b/utils/TableGen/IntrinsicEmitter.cpp @@ -143,24 +143,24 @@ EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints, static void EmitTypeForValueType(raw_ostream &OS, MVT::SimpleValueType VT) { if (EVT(VT).isInteger()) { unsigned BitWidth = EVT(VT).getSizeInBits(); - OS << "IntegerType::get(" << BitWidth << ")"; + OS << "IntegerType::get(Context, " << BitWidth << ")"; } else if (VT == MVT::Other) { // MVT::OtherVT is used to mean the empty struct type here. OS << "StructType::get(Context)"; } else if (VT == MVT::f32) { - OS << "Type::FloatTy"; + OS << "Type::getFloatTy(Context)"; } else if (VT == MVT::f64) { - OS << "Type::DoubleTy"; + OS << "Type::getDoubleTy(Context)"; } else if (VT == MVT::f80) { - OS << "Type::X86_FP80Ty"; + OS << "Type::getX86_FP80Ty(Context)"; } else if (VT == MVT::f128) { - OS << "Type::FP128Ty"; + OS << "Type::getFP128Ty(Context)"; } else if (VT == MVT::ppcf128) { - OS << "Type::PPC_FP128Ty"; + OS << "Type::getPPC_FP128Ty(Context)"; } else if (VT == MVT::isVoid) { - OS << "Type::VoidTy"; + OS << "Type::getVoidTy(Context)"; } else if (VT == MVT::Metadata) { - OS << "Type::MetadataTy"; + OS << "Type::getMetadataTy(Context)"; } else { assert(false && "Unsupported ValueType!"); } @@ -229,7 +229,7 @@ static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType, ++ArgNo; } else if (VT == MVT::isVoid) { if (ArgNo == 0) - OS << "Type::VoidTy"; + OS << "Type::getVoidTy(Context)"; else // MVT::isVoid is used to mean varargs here. OS << "..."; |