llvm.org GIT mirror llvm / debcb01
Move types back to the 2.5 API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77516 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 10 years ago
71 changed file(s) with 287 addition(s) and 439 deletion(s). Raw diff Collapse all Expand all
307307 Function *PrototypeAST::Codegen() {
308308 // Make the function type: double(double,double) etc.
309309 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
310 FunctionType *FT = getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
310 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
311311
312312 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
313313
10811081 Function *PrototypeAST::Codegen() {
10821082 // Make the function type: double(double,double) etc.
10831083 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1084 FunctionType *FT = getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
1084 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
10851085
10861086 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
10871087
916916 Function *PrototypeAST::Codegen() {
917917 // Make the function type: double(double,double) etc.
918918 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
919 FunctionType *FT = getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
919 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
920920
921921 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
922922
15501550 Function *PrototypeAST::Codegen() {
15511551 // Make the function type: double(double,double) etc.
15521552 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1553 FunctionType *FT = getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
1553 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
15541554
15551555 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
15561556
15751575 Function *PrototypeAST::Codegen() {
15761576 // Make the function type: double(double,double) etc.
15771577 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1578 FunctionType *FT = getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
1578 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
15791579
15801580 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
15811581
19101910 Function *PrototypeAST::Codegen() {
19111911 // Make the function type: double(double,double) etc.
19121912 std::vector<const Type*> Doubles(Args.size(), Type::DoubleTy);
1913 FunctionType *FT = getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
1913 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
19141914
19151915 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
19161916
137137 //declare i32 @puts(i8 *)
138138 Function *puts_func = cast(module->
139139 getOrInsertFunction("puts", IntegerType::Int32Ty,
140 C.getPointerTypeUnqual(IntegerType::Int8Ty), NULL));
140 PointerType::getUnqual(IntegerType::Int8Ty), NULL));
141141
142142 //brainf.aberror:
143143 aberrorbb = BasicBlock::Create(label, brainf_func);
283283
284284 // Make part of PHI instruction now, wait until end of loop to finish
285285 PHINode *phi_0 =
286 PHINode::Create(C.getPointerTypeUnqual(IntegerType::Int8Ty),
286 PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty),
287287 headreg, testbb);
288288 phi_0->reserveOperandSpace(2);
289289 phi_0->addIncoming(curhead, bb_0);
439439
440440 //%head.%d = phi i8 *[%head.%d, %main.%d]
441441 PHINode *phi_1 = builder->
442 CreatePHI(C.getPointerTypeUnqual(IntegerType::Int8Ty), headreg);
442 CreatePHI(PointerType::getUnqual(IntegerType::Int8Ty), headreg);
443443 phi_1->reserveOperandSpace(1);
444444 phi_1->addIncoming(head_0, testbb);
445445 curhead = phi_1;
908908 Function *PrototypeAST::Codegen() {
909909 // Make the function type: double(double,double) etc.
910910 std::vector Doubles(Args.size(), Type::DoubleTy);
911 FunctionType *FT =
912 getGlobalContext().getFunctionType(Type::DoubleTy, Doubles, false);
911 FunctionType *FT = FunctionType::get(Type::DoubleTy, Doubles, false);
913912
914913 Function *F = Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
915914
3030
3131 // Create the main function: first create the type 'int ()'
3232 FunctionType *FT =
33 Context.getFunctionType(Type::Int32Ty, /*not vararg*/false);
33 FunctionType::get(Type::Int32Ty, /*not vararg*/false);
3434
3535 // By passing a module as the last parameter to the Function constructor,
3636 // it automatically gets appended to the Module.
476476 /// getTypeForMVT - This method returns an LLVM type corresponding to the
477477 /// specified MVT. For integer types, this returns an unsigned type. Note
478478 /// that this will abort for types that cannot be represented.
479 const Type *getTypeForMVT(LLVMContext &Context) const;
479 const Type *getTypeForMVT() const;
480480
481481 /// getMVT - Return the value type corresponding to the specified type.
482482 /// This returns all pointers as iPTR. If HandleUnknown is true, unknown
666666 static inline bool classof(const Value *V) {
667667 return isa(V) && classof(cast(V));
668668 }
669
670 /// @brief Create a result type for fcmp/icmp
671 static const Type* makeCmpResultType(const Type* opnd_type) {
672 if (const VectorType* vt = dyn_cast(opnd_type)) {
673 return VectorType::get(Type::Int1Ty, vt->getNumElements());
674 }
675 return Type::Int1Ty;
676 }
669677 };
670678
671679
644644 Value *LHS, ///< The left-hand-side of the expression
645645 Value *RHS, ///< The right-hand-side of the expression
646646 const Twine &NameStr = "" ///< Name of the instruction
647 ) : CmpInst(InsertBefore->getContext().makeCmpResultType(LHS->getType()),
647 ) : CmpInst(makeCmpResultType(LHS->getType()),
648648 Instruction::ICmp, pred, LHS, RHS, NameStr,
649649 InsertBefore) {
650650 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
665665 Value *LHS, ///< The left-hand-side of the expression
666666 Value *RHS, ///< The right-hand-side of the expression
667667 const Twine &NameStr = "" ///< Name of the instruction
668 ) : CmpInst(InsertAtEnd.getContext().makeCmpResultType(LHS->getType()),
668 ) : CmpInst(makeCmpResultType(LHS->getType()),
669669 Instruction::ICmp, pred, LHS, RHS, NameStr,
670670 &InsertAtEnd) {
671671 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
686686 Value *LHS, ///< The left-hand-side of the expression
687687 Value *RHS, ///< The right-hand-side of the expression
688688 const Twine &NameStr = "" ///< Name of the instruction
689 ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
689 ) : CmpInst(makeCmpResultType(LHS->getType()),
690690 Instruction::ICmp, pred, LHS, RHS, NameStr) {
691691 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
692692 pred <= CmpInst::LAST_ICMP_PREDICATE &&
819819 Value *LHS, ///< The left-hand-side of the expression
820820 Value *RHS, ///< The right-hand-side of the expression
821821 const Twine &NameStr = "" ///< Name of the instruction
822 ) : CmpInst(InsertBefore->getContext().makeCmpResultType(LHS->getType()),
822 ) : CmpInst(makeCmpResultType(LHS->getType()),
823823 Instruction::FCmp, pred, LHS, RHS, NameStr,
824824 InsertBefore) {
825825 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
838838 Value *LHS, ///< The left-hand-side of the expression
839839 Value *RHS, ///< The right-hand-side of the expression
840840 const Twine &NameStr = "" ///< Name of the instruction
841 ) : CmpInst(InsertAtEnd.getContext().makeCmpResultType(LHS->getType()),
841 ) : CmpInst(makeCmpResultType(LHS->getType()),
842842 Instruction::FCmp, pred, LHS, RHS, NameStr,
843843 &InsertAtEnd) {
844844 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
857857 Value *LHS, ///< The left-hand-side of the expression
858858 Value *RHS, ///< The right-hand-side of the expression
859859 const Twine &NameStr = "" ///< Name of the instruction
860 ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
860 ) : CmpInst(makeCmpResultType(LHS->getType()),
861861 Instruction::FCmp, pred, LHS, RHS, NameStr) {
862862 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
863863 "Invalid FCmp predicate value");
909909 static inline bool classof(const Value *V) {
910910 return isa(V) && classof(cast(V));
911911 }
912
913912 };
914913
915914 //===----------------------------------------------------------------------===//
9090 // MDString accessors
9191 MDString* getMDString(const StringRef &Str);
9292
93 // FunctionType accessors
94 FunctionType* getFunctionType(const Type* Result, bool isVarArg);
95 FunctionType* getFunctionType(const Type* Result,
96 const std::vector& Params,
97 bool isVarArg);
98
99 // IntegerType accessors
100 const IntegerType* getIntegerType(unsigned NumBits);
101
102 // OpaqueType accessors
103 OpaqueType* getOpaqueType();
104
105 // StructType accessors
106 StructType* getStructType(bool isPacked=false);
107 StructType* getStructType(const std::vector& Params,
108 bool isPacked = false);
109 StructType* getStructType(const Type* type, ...);
110
111 // ArrayType accessors
112 ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
113
114 // PointerType accessors
115 PointerType* getPointerType(const Type* ElementType, unsigned AddressSpace);
116 PointerType* getPointerTypeUnqual(const Type* ElementType);
117
118 // VectorType accessors
119 VectorType* getVectorType(const Type* ElementType, unsigned NumElements);
120 VectorType* getVectorTypeInteger(const VectorType* VTy);
121 VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
122 VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
123
124 // Other helpers
125 /// @brief Create a result type for fcmp/icmp
126 const Type* makeCmpResultType(const Type* opnd_type);
12793
12894 // Methods for erasing constants
12995 void erase(MDString *M);
106106 public:
107107 static const PointerType *get(LLVMContext &Context) {
108108 static const PointerType *const result =
109 Context.getPointerTypeUnqual(TypeBuilder::get(Context));
109 PointerType::getUnqual(TypeBuilder::get(Context));
110110 return result;
111111 }
112112 };
119119 public:
120120 static const ArrayType *get(LLVMContext &Context) {
121121 static const ArrayType *const result =
122 Context.getArrayType(TypeBuilder::get(Context), N);
122 ArrayType::get(TypeBuilder::get(Context), N);
123123 return result;
124124 }
125125 };
128128 public:
129129 static const ArrayType *get(LLVMContext &Context) {
130130 static const ArrayType *const result =
131 Context.getArrayType(TypeBuilder::get(Context), 0);
131 ArrayType::get(TypeBuilder::get(Context), 0);
132132 return result;
133133 }
134134 };
160160 public: \
161161 static const IntegerType *get(LLVMContext &Context) { \
162162 static const IntegerType *const result = \
163 Context.getIntegerType(sizeof(T) * CHAR_BIT); \
163 IntegerType::get(sizeof(T) * CHAR_BIT); \
164164 return result; \
165165 } \
166166 }; \
190190 class TypeBuilder, cross> {
191191 public:
192192 static const IntegerType *get(LLVMContext &Context) {
193 static const IntegerType *const result = Context.getIntegerType(num_bits);
193 static const IntegerType *const result = IntegerType::get(num_bits);
194194 return result;
195195 }
196196 };
253253
254254 private:
255255 static const FunctionType *create(LLVMContext &Context) {
256 return Context.getFunctionType(TypeBuilder::get(Context), false);
256 return FunctionType::get(TypeBuilder::get(Context), false);
257257 }
258258 };
259259 template class TypeBuilder {
268268 std::vector params;
269269 params.reserve(1);
270270 params.push_back(TypeBuilder::get(Context));
271 return Context.getFunctionType(TypeBuilder::get(Context),
271 return FunctionType::get(TypeBuilder::get(Context),
272272 params, false);
273273 }
274274 };
286286 params.reserve(2);
287287 params.push_back(TypeBuilder::get(Context));
288288 params.push_back(TypeBuilder::get(Context));
289 return Context.getFunctionType(TypeBuilder::get(Context),
289 return FunctionType::get(TypeBuilder::get(Context),
290290 params, false);
291291 }
292292 };
305305 params.push_back(TypeBuilder::get(Context));
306306 params.push_back(TypeBuilder::get(Context));
307307 params.push_back(TypeBuilder::get(Context));
308 return Context.getFunctionType(TypeBuilder::get(Context),
308 return FunctionType::get(TypeBuilder::get(Context),
309309 params, false);
310310 }
311311 };
327327 params.push_back(TypeBuilder::get(Context));
328328 params.push_back(TypeBuilder::get(Context));
329329 params.push_back(TypeBuilder::get(Context));
330 return Context.getFunctionType(TypeBuilder::get(Context),
330 return FunctionType::get(TypeBuilder::get(Context),
331331 params, false);
332332 }
333333 };
350350 params.push_back(TypeBuilder::get(Context));
351351 params.push_back(TypeBuilder::get(Context));
352352 params.push_back(TypeBuilder::get(Context));
353 return Context.getFunctionType(TypeBuilder::get(Context),
353 return FunctionType::get(TypeBuilder::get(Context),
354354 params, false);
355355 }
356356 };
364364
365365 private:
366366 static const FunctionType *create(LLVMContext &Context) {
367 return Context.getFunctionType(TypeBuilder::get(Context), true);
367 return FunctionType::get(TypeBuilder::get(Context), true);
368368 }
369369 };
370370 template
380380 std::vector params;
381381 params.reserve(1);
382382 params.push_back(TypeBuilder::get(Context));
383 return Context.getFunctionType(TypeBuilder::get(Context),
384 params, true);
383 return FunctionType::get(TypeBuilder::get(Context), params, true);
385384 }
386385 };
387386 template
398397 params.reserve(2);
399398 params.push_back(TypeBuilder::get(Context));
400399 params.push_back(TypeBuilder::get(Context));
401 return Context.getFunctionType(TypeBuilder::get(Context),
400 return FunctionType::get(TypeBuilder::get(Context),
402401 params, true);
403402 }
404403 };
417416 params.push_back(TypeBuilder::get(Context));
418417 params.push_back(TypeBuilder::get(Context));
419418 params.push_back(TypeBuilder::get(Context));
420 return Context.getFunctionType(TypeBuilder::get(Context),
419 return FunctionType::get(TypeBuilder::get(Context),
421420 params, true);
422421 }
423422 };
439438 params.push_back(TypeBuilder::get(Context));
440439 params.push_back(TypeBuilder::get(Context));
441440 params.push_back(TypeBuilder::get(Context));
442 return Context.getFunctionType(TypeBuilder::get(Context),
441 return FunctionType::get(TypeBuilder::get(Context),
443442 params, true);
444443 }
445444 };
462461 params.push_back(TypeBuilder::get(Context));
463462 params.push_back(TypeBuilder::get(Context));
464463 params.push_back(TypeBuilder::get(Context));
465 return Context.getFunctionType(TypeBuilder::get(Context),
464 return FunctionType::get(TypeBuilder::get(Context),
466465 params, true);
467466 }
468467 };
183183 if (DstEltTy->isFloatingPoint()) {
184184 // Fold to an vector of integers with same size as our FP type.
185185 unsigned FPWidth = DstEltTy->getPrimitiveSizeInBits();
186 const Type *DestIVTy = Context.getVectorType(
187 Context.getIntegerType(FPWidth), NumDstElt);
186 const Type *DestIVTy = VectorType::get(
187 IntegerType::get(FPWidth), NumDstElt);
188188 // Recursively handle this integer conversion, if possible.
189189 C = FoldBitCast(C, DestIVTy, TD, Context);
190190 if (!C) return 0;
197197 // it to integer first.
198198 if (SrcEltTy->isFloatingPoint()) {
199199 unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits();
200 const Type *SrcIVTy = Context.getVectorType(
201 Context.getIntegerType(FPWidth), NumSrcElt);
200 const Type *SrcIVTy = VectorType::get(
201 IntegerType::get(FPWidth), NumSrcElt);
202202 // Ask VMCore to do the conversion now that #elts line up.
203203 C = ConstantExpr::getBitCast(C, SrcIVTy);
204204 CV = dyn_cast(C);
469469 : M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0),
470470 RegionStartFn(0), RegionEndFn(0),
471471 DeclareFn(0) {
472 EmptyStructPtr = VMContext.getPointerTypeUnqual(VMContext.getStructType());
472 EmptyStructPtr = PointerType::getUnqual(StructType::get());
473473 }
474474
475475 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
492492 // Return Constant if previously defined.
493493 if (Slot) return Slot;
494494
495 const PointerType *DestTy = VMContext.getPointerTypeUnqual(Type::Int8Ty);
495 const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty);
496496
497497 // If empty string then use a i8* null instead.
498498 if (String.empty())
521521 for (unsigned i = 0; i != NumTys; ++i)
522522 Elts.push_back(getCastToEmpty(Tys[i]));
523523
524 Constant *Init = ConstantArray::get(VMContext.getArrayType(EmptyStructPtr,
524 Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
525525 Elts.size()),
526526 Elts.data(), Elts.size());
527527 // If we already have this array, just return the uniqued version.
10741074 const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type");
10751075 if (!Ty) return 0;
10761076
1077 Ty = Context.getPointerType(Ty, 0);
1077 Ty = PointerType::get(Ty, 0);
10781078
10791079 Value *Val = V->stripPointerCasts();
10801080 for (Value::use_iterator I = Val->use_begin(), E = Val->use_end();
7474 ConstantRange X = getRange(Mul->getOperand(0), T, SE);
7575 if (X.isFullSet()) return FullSet;
7676
77 const IntegerType *Ty = Context.getIntegerType(X.getBitWidth());
78 const IntegerType *ExTy = Context.getIntegerType(X.getBitWidth() *
77 const IntegerType *Ty = IntegerType::get(X.getBitWidth());
78 const IntegerType *ExTy = IntegerType::get(X.getBitWidth() *
7979 Mul->getNumOperands());
8080 ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth());
8181
46694669
46704670 // Check Add for unsigned overflow.
46714671 // TODO: More sophisticated things could be done here.
4672 const Type *WideTy = getContext().getIntegerType(getTypeSizeInBits(Ty) + 1);
4672 const Type *WideTy = IntegerType::get(getTypeSizeInBits(Ty) + 1);
46734673 const SCEV *EDiff = getZeroExtendExpr(Diff, WideTy);
46744674 const SCEV *ERoundUp = getZeroExtendExpr(RoundUp, WideTy);
46754675 const SCEV *OperandExtendedAdd = getAddExpr(EDiff, ERoundUp);
470470 Error("bitwidth for integer type out of range!");
471471 return lltok::Error;
472472 }
473 TyVal = Context.getIntegerType(NumBits);
473 TyVal = IntegerType::get(NumBits);
474474 return lltok::Type;
475475 }
476476
11031103 break;
11041104 case lltok::kw_opaque:
11051105 // TypeRec ::= 'opaque'
1106 Result = Context.getOpaqueType();
1106 Result = OpaqueType::get();
11071107 Lex.Lex();
11081108 break;
11091109 case lltok::lbrace:
11331133 if (const Type *T = M->getTypeByName(Lex.getStrVal())) {
11341134 Result = T;
11351135 } else {
1136 Result = Context.getOpaqueType();
1136 Result = OpaqueType::get();
11371137 ForwardRefTypes.insert(std::make_pair(Lex.getStrVal(),
11381138 std::make_pair(Result,
11391139 Lex.getLoc())));
11521152 if (I != ForwardRefTypeIDs.end())
11531153 Result = I->second.first;
11541154 else {
1155 Result = Context.getOpaqueType();
1155 Result = OpaqueType::get();
11561156 ForwardRefTypeIDs.insert(std::make_pair(Lex.getUIntVal(),
11571157 std::make_pair(Result,
11581158 Lex.getLoc())));
11651165 Lex.Lex();
11661166 unsigned Val;
11671167 if (ParseUInt32(Val)) return true;
1168 OpaqueType *OT = Context.getOpaqueType(); //Use temporary placeholder.
1168 OpaqueType *OT = OpaqueType::get(); //Use temporary placeholder.
11691169 UpRefs.push_back(UpRefRecord(Lex.getLoc(), Val, OT));
11701170 Result = OT;
11711171 break;
11861186 return TokError("pointers to void are invalid; use i8* instead");
11871187 if (!PointerType::isValidElementType(Result.get()))
11881188 return TokError("pointer to this type is invalid");
1189 Result = HandleUpRefs(Context.getPointerTypeUnqual(Result.get()));
1189 Result = HandleUpRefs(PointerType::getUnqual(Result.get()));
11901190 Lex.Lex();
11911191 break;
11921192
12031203 ParseToken(lltok::star, "expected '*' in address space"))
12041204 return true;
12051205
1206 Result = HandleUpRefs(Context.getPointerType(Result.get(), AddrSpace));
1206 Result = HandleUpRefs(PointerType::get(Result.get(), AddrSpace));
12071207 break;
12081208 }
12091209
13641364 for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
13651365 ArgListTy.push_back(ArgList[i].Type);
13661366
1367 Result = HandleUpRefs(Context.getFunctionType(Result.get(),
1367 Result = HandleUpRefs(FunctionType::get(Result.get(),
13681368 ArgListTy, isVarArg));
13691369 return false;
13701370 }
13801380 Lex.Lex(); // Consume the '{'
13811381
13821382 if (EatIfPresent(lltok::rbrace)) {
1383 Result = Context.getStructType(Packed);
1383 Result = StructType::get(Packed);
13841384 return false;
13851385 }
13861386
14121412 std::vector ParamsListTy;
14131413 for (unsigned i = 0, e = ParamsList.size(); i != e; ++i)
14141414 ParamsListTy.push_back(ParamsList[i].get());
1415 Result = HandleUpRefs(Context.getStructType(ParamsListTy, Packed));
1415 Result = HandleUpRefs(StructType::get(ParamsListTy, Packed));
14161416 return false;
14171417 }
14181418
14511451 return Error(SizeLoc, "size too large for vector");
14521452 if (!VectorType::isValidElementType(EltTy))
14531453 return Error(TypeLoc, "vector element type must be fp or integer");
1454 Result = Context.getVectorType(EltTy, unsigned(Size));
1454 Result = VectorType::get(EltTy, unsigned(Size));
14551455 } else {
14561456 if (!ArrayType::isValidElementType(EltTy))
14571457 return Error(TypeLoc, "invalid array element type");
1458 Result = HandleUpRefs(Context.getArrayType(EltTy, Size));
1458 Result = HandleUpRefs(ArrayType::get(EltTy, Size));
14591459 }
14601460 return false;
14611461 }
18351835 return Error(FirstEltLoc, "invalid array element type: " +
18361836 Elts[0]->getType()->getDescription());
18371837
1838 ArrayType *ATy = Context.getArrayType(Elts[0]->getType(), Elts.size());
1838 ArrayType *ATy = ArrayType::get(Elts[0]->getType(), Elts.size());
18391839
18401840 // Verify all elements are correct type!
18411841 for (unsigned i = 0, e = Elts.size(); i != e; ++i) {
24162416 return Error(RetTypeLoc, "functions with 'sret' argument must return void");
24172417
24182418 const FunctionType *FT =
2419 Context.getFunctionType(RetType, ParamTypeList, isVarArg);
2420 const PointerType *PFT = Context.getPointerTypeUnqual(FT);
2419 FunctionType::get(RetType, ParamTypeList, isVarArg);
2420 const PointerType *PFT = PointerType::getUnqual(FT);
24212421
24222422 Fn = 0;
24232423 if (!FunctionName.empty()) {
29012901 if (!FunctionType::isValidReturnType(RetType))
29022902 return Error(RetTypeLoc, "Invalid result type for LLVM function");
29032903
2904 Ty = Context.getFunctionType(RetType, ParamTypes, false);
2905 PFTy = Context.getPointerTypeUnqual(Ty);
2904 Ty = FunctionType::get(RetType, ParamTypes, false);
2905 PFTy = PointerType::getUnqual(Ty);
29062906 }
29072907
29082908 // Look up the callee.
32413241 if (!FunctionType::isValidReturnType(RetType))
32423242 return Error(RetTypeLoc, "Invalid result type for LLVM function");
32433243
3244 Ty = Context.getFunctionType(RetType, ParamTypes, false);
3245 PFTy = Context.getPointerTypeUnqual(Ty);
3244 Ty = FunctionType::get(RetType, ParamTypes, false);
3245 PFTy = PointerType::getUnqual(Ty);
32463246 }
32473247
32483248 // Look up the callee.
321321 // The type table allows forward references. Push as many Opaque types as
322322 // needed to get up to ID.
323323 while (TypeList.size() <= ID)
324 TypeList.push_back(Context.getOpaqueType());
324 TypeList.push_back(OpaqueType::get());
325325 return TypeList.back().get();
326326 }
327327
511511 if (Record.size() < 1)
512512 return Error("Invalid Integer type record");
513513
514 ResultTy = Context.getIntegerType(Record[0]);
514 ResultTy = IntegerType::get(Record[0]);
515515 break;
516516 case bitc::TYPE_CODE_POINTER: { // POINTER: [pointee type] or
517517 // [pointee type, address space]
520520 unsigned AddressSpace = 0;
521521 if (Record.size() == 2)
522522 AddressSpace = Record[1];
523 ResultTy = Context.getPointerType(getTypeByID(Record[0], true),
523 ResultTy = PointerType::get(getTypeByID(Record[0], true),
524524 AddressSpace);
525525 break;
526526 }
533533 for (unsigned i = 3, e = Record.size(); i != e; ++i)
534534 ArgTys.push_back(getTypeByID(Record[i], true));
535535
536 ResultTy = Context.getFunctionType(getTypeByID(Record[2], true), ArgTys,
536 ResultTy = FunctionType::get(getTypeByID(Record[2], true), ArgTys,
537537 Record[0]);
538538 break;
539539 }
543543 std::vector EltTys;
544544 for (unsigned i = 1, e = Record.size(); i != e; ++i)
545545 EltTys.push_back(getTypeByID(Record[i], true));
546 ResultTy = Context.getStructType(EltTys, Record[0]);
546 ResultTy = StructType::get(EltTys, Record[0]);
547547 break;
548548 }
549549 case bitc::TYPE_CODE_ARRAY: // ARRAY: [numelts, eltty]
550550 if (Record.size() < 2)
551551 return Error("Invalid ARRAY type record");
552 ResultTy = Context.getArrayType(getTypeByID(Record[1], true), Record[0]);
552 ResultTy = ArrayType::get(getTypeByID(Record[1], true), Record[0]);
553553 break;
554554 case bitc::TYPE_CODE_VECTOR: // VECTOR: [numelts, eltty]
555555 if (Record.size() < 2)
556556 return Error("Invalid VECTOR type record");
557 ResultTy = Context.getVectorType(getTypeByID(Record[1], true), Record[0]);
557 ResultTy = VectorType::get(getTypeByID(Record[1], true), Record[0]);
558558 break;
559559 }
560560
561561 if (NumRecords == TypeList.size()) {
562562 // If this is a new type slot, just append it.
563 TypeList.push_back(ResultTy ? ResultTy : Context.getOpaqueType());
563 TypeList.push_back(ResultTy ? ResultTy : OpaqueType::get());
564564 ++NumRecords;
565565 } else if (ResultTy == 0) {
566566 // Otherwise, this was forward referenced, so an opaque type was created,
10451045 return Error("Invalid CE_SHUFFLEVEC record");
10461046 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
10471047 Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
1048 const Type *ShufTy = Context.getVectorType(Type::Int32Ty,
1048 const Type *ShufTy = VectorType::get(Type::Int32Ty,
10491049 OpTy->getNumElements());
10501050 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
10511051 V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
10581058 return Error("Invalid CE_SHUFVEC_EX record");
10591059 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
10601060 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
1061 const Type *ShufTy = Context.getVectorType(Type::Int32Ty,
1061 const Type *ShufTy = VectorType::get(Type::Int32Ty,
10621062 RTy->getNumElements());
10631063 Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
10641064 V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
19391939 Value *Val, *Ptr;
19401940 if (getValueTypePair(Record, OpNum, NextValueNo, Val) ||
19411941 getValue(Record, OpNum,
1942 Context.getPointerTypeUnqual(Val->getType()), Ptr)||
1942 PointerType::getUnqual(Val->getType()), Ptr)||
19431943 OpNum+2 != Record.size())
19441944 return Error("Invalid STORE record");
19451945
353353
354354 // Create the temporary if we didn't already.
355355 if (!ExceptionValueVar) {
356 ExceptionValueVar = new AllocaInst(
357 BB->getContext().getPointerTypeUnqual(Type::Int8Ty),
356 ExceptionValueVar = new AllocaInst(PointerType::getUnqual(Type::Int8Ty),
358357 "eh.value", F->begin()->begin());
359358 ++NumStackTempsIntroduced;
360359 }
36633663 TLI.isConsecutiveLoad(LD2, LD1, LD1VT.getSizeInBits()/8, 1, MFI)) {
36643664 unsigned Align = LD1->getAlignment();
36653665 unsigned NewAlign = TLI.getTargetData()->
3666 getABITypeAlignment(VT.getTypeForMVT(*DAG.getContext()));
3666 getABITypeAlignment(VT.getTypeForMVT());
36673667
36683668 if (NewAlign <= Align &&
36693669 (!LegalOperations || TLI.isOperationLegal(ISD::LOAD, VT)))
37213721 (!LegalOperations || TLI.isOperationLegal(ISD::LOAD, VT))) {
37223722 LoadSDNode *LN0 = cast(N0);
37233723 unsigned Align = TLI.getTargetData()->
3724 getABITypeAlignment(VT.getTypeForMVT(*DAG.getContext()));
3724 getABITypeAlignment(VT.getTypeForMVT());
37253725 unsigned OrigAlign = LN0->getAlignment();
37263726
37273727 if (Align <= OrigAlign) {
49924992
49934993 unsigned NewAlign = MinAlign(LD->getAlignment(), PtrOff);
49944994 if (NewAlign <
4995 TLI.getTargetData()->getABITypeAlignment(NewVT.getTypeForMVT(
4996 *DAG.getContext())))
4995 TLI.getTargetData()->getABITypeAlignment(NewVT.getTypeForMVT()))
49974996 return SDValue();
49984997
49994998 SDValue NewPtr = DAG.getNode(ISD::ADD, LD->getDebugLoc(),
50485047 unsigned OrigAlign = ST->getAlignment();
50495048 MVT SVT = Value.getOperand(0).getValueType();
50505049 unsigned Align = TLI.getTargetData()->
5051 getABITypeAlignment(SVT.getTypeForMVT(*DAG.getContext()));
5050 getABITypeAlignment(SVT.getTypeForMVT());
50525051 if (Align <= OrigAlign &&
50535052 ((!LegalOperations && !ST->isVolatile()) ||
50545053 TLI.isOperationLegalOrCustom(ISD::STORE, SVT)))
53285327 // Check the resultant load doesn't need a higher alignment than the
53295328 // original load.
53305329 unsigned NewAlign =
5331 TLI.getTargetData()->getABITypeAlignment(LVT.getTypeForMVT(
5332 *DAG.getContext()));
5330 TLI.getTargetData()->getABITypeAlignment(LVT.getTypeForMVT());
53335331
53345332 if (NewAlign > Align || !TLI.isOperationLegalOrCustom(ISD::LOAD, LVT))
53355333 return SDValue();
58115809 const TargetData &TD = *TLI.getTargetData();
58125810
58135811 // Create a ConstantArray of the two constants.
5814 Constant *CA = ConstantArray::get(
5815 DAG.getContext()->getArrayType(FPTy, 2), Elts, 2);
5812 Constant *CA = ConstantArray::get(ArrayType::get(FPTy, 2), Elts, 2);
58165813 SDValue CPIdx = DAG.getConstantPool(CA, TLI.getPointerTy(),
58175814 TD.getPrefTypeAlignment(FPTy));
58185815 unsigned Alignment = cast(CPIdx)->getAlignment();
360360 // smaller type.
361361 TLI.isLoadExtLegal(ISD::EXTLOAD, SVT) &&
362362 TLI.ShouldShrinkFPConstant(OrigVT)) {
363 const Type *SType = SVT.getTypeForMVT(*DAG.getContext());
363 const Type *SType = SVT.getTypeForMVT();
364364 LLVMC = cast(ConstantExpr::getFPTrunc(LLVMC, SType));
365365 VT = SVT;
366366 Extend = true;
11061106 // expand it.
11071107 if (!TLI.allowsUnalignedMemoryAccesses()) {
11081108 unsigned ABIAlignment = TLI.getTargetData()->
1109 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT(
1110 *DAG.getContext()));
1109 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
11111110 if (LD->getAlignment() < ABIAlignment){
1112 Result = ExpandUnalignedLoad(cast(Result.getNode()), DAG,
1113 TLI);
1111 Result = ExpandUnalignedLoad(cast(Result.getNode()),
1112 DAG, TLI);
11141113 Tmp3 = Result.getOperand(0);
11151114 Tmp4 = Result.getOperand(1);
11161115 Tmp3 = LegalizeOp(Tmp3);
12901289 // expand it.
12911290 if (!TLI.allowsUnalignedMemoryAccesses()) {
12921291 unsigned ABIAlignment = TLI.getTargetData()->
1293 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT(
1294 *DAG.getContext()));
1292 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
12951293 if (LD->getAlignment() < ABIAlignment){
1296 Result = ExpandUnalignedLoad(cast(Result.getNode()), DAG,
1297 TLI);
1294 Result = ExpandUnalignedLoad(cast(Result.getNode()),
1295 DAG, TLI);
12981296 Tmp1 = Result.getOperand(0);
12991297 Tmp2 = Result.getOperand(1);
13001298 Tmp1 = LegalizeOp(Tmp1);
13691367 // expand it.
13701368 if (!TLI.allowsUnalignedMemoryAccesses()) {
13711369 unsigned ABIAlignment = TLI.getTargetData()->
1372 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT(
1373 *DAG.getContext()));
1370 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
13741371 if (ST->getAlignment() < ABIAlignment)
13751372 Result = ExpandUnalignedStore(cast(Result.getNode()), DAG,
13761373 TLI);
14691466 // expand it.
14701467 if (!TLI.allowsUnalignedMemoryAccesses()) {
14711468 unsigned ABIAlignment = TLI.getTargetData()->
1472 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT(
1473 *DAG.getContext()));
1469 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
14741470 if (ST->getAlignment() < ABIAlignment)
14751471 Result = ExpandUnalignedStore(cast(Result.getNode()), DAG,
14761472 TLI);
17361732 // Create the stack frame object.
17371733 unsigned SrcAlign =
17381734 TLI.getTargetData()->getPrefTypeAlignment(SrcOp.getValueType().
1739 getTypeForMVT(*DAG.getContext()));
1735 getTypeForMVT());
17401736 SDValue FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
17411737
17421738 FrameIndexSDNode *StackPtrFI = cast(FIPtr);
17471743 unsigned SlotSize = SlotVT.getSizeInBits();
17481744 unsigned DestSize = DestVT.getSizeInBits();
17491745 unsigned DestAlign =
1750 TLI.getTargetData()->getPrefTypeAlignment(DestVT.getTypeForMVT(
1751 *DAG.getContext()));
1746 TLI.getTargetData()->getPrefTypeAlignment(DestVT.getTypeForMVT());
17521747
17531748 // Emit a store to the stack slot. Use a truncstore if the input value is
17541749 // later than DestVT.
18431838 CV.push_back(const_cast(V->getConstantIntValue()));
18441839 } else {
18451840 assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
1846 const Type *OpNTy = OpVT.getTypeForMVT(*DAG.getContext());
1841 const Type *OpNTy = OpVT.getTypeForMVT();
18471842 CV.push_back(Context->getUndef(OpNTy));
18481843 }
18491844 }
18971892 TargetLowering::ArgListEntry Entry;
18981893 for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i) {
18991894 MVT ArgVT = Node->getOperand(i).getValueType();
1900 const Type *ArgTy = ArgVT.getTypeForMVT(*DAG.getContext());
1895 const Type *ArgTy = ArgVT.getTypeForMVT();
19011896 Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
19021897 Entry.isSExt = isSigned;
19031898 Entry.isZExt = !isSigned;
19071902 TLI.getPointerTy());
19081903
19091904 // Splice the libcall in wherever FindInputOutputChains tells us to.
1910 const Type *RetTy = Node->getValueType(0).getTypeForMVT(*DAG.getContext());
1905 const Type *RetTy = Node->getValueType(0).getTypeForMVT();
19111906 std::pair CallInfo =
19121907 TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false,
19131908 0, CallingConv::C, false, Callee, Args, DAG,
23962391 // Increment the pointer, VAList, to the next vaarg
23972392 Tmp3 = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), VAList,
23982393 DAG.getConstant(TLI.getTargetData()->
2399 getTypeAllocSize(VT.getTypeForMVT(
2400 *DAG.getContext())),
2394 getTypeAllocSize(VT.getTypeForMVT()),
24012395 TLI.getPointerTy()));
24022396 // Store the incremented VAList to the legalized pointer
24032397 Tmp3 = DAG.getStore(VAList.getValue(1), dl, Tmp3, Tmp2, V, 0);
10081008 TargetLowering::ArgListEntry Entry;
10091009 for (unsigned i = 0; i != NumOps; ++i) {
10101010 Entry.Node = Ops[i];
1011 Entry.Ty = Entry.Node.getValueType().getTypeForMVT(*DAG.getContext());
1011 Entry.Ty = Entry.Node.getValueType().getTypeForMVT();
10121012 Entry.isSExt = isSigned;
10131013 Entry.isZExt = !isSigned;
10141014 Args.push_back(Entry);
10161016 SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
10171017 TLI.getPointerTy());
10181018
1019 const Type *RetTy = RetVT.getTypeForMVT(*DAG.getContext());
1019 const Type *RetTy = RetVT.getTypeForMVT();
10201020 std::pair CallInfo =
10211021 TLI.LowerCallTo(DAG.getEntryNode(), RetTy, isSigned, !isSigned, false,
10221022 false, 0, CallingConv::C, false, Callee, Args, DAG, dl);
114114 // Create the stack frame object. Make sure it is aligned for both
115115 // the source and expanded destination types.
116116 unsigned Alignment =
117 TLI.getTargetData()->getPrefTypeAlignment(NOutVT.getTypeForMVT(
118 *DAG.getContext()));
117 TLI.getTargetData()->getPrefTypeAlignment(NOutVT.getTypeForMVT());
119118 SDValue StackPtr = DAG.CreateStackTemporary(InVT, Alignment);
120119 int SPFI = cast(StackPtr.getNode())->getIndex();
121120 const Value *SV = PseudoSourceValue::getFixedStack(SPFI);
666666 // so use a truncating store.
667667 SDValue EltPtr = GetVectorElementPointer(StackPtr, EltVT, Idx);
668668 unsigned Alignment =
669 TLI.getTargetData()->getPrefTypeAlignment(VecVT.getTypeForMVT(
670 *DAG.getContext()));
669 TLI.getTargetData()->getPrefTypeAlignment(VecVT.getTypeForMVT());
671670 Store = DAG.getTruncStore(Store, dl, Elt, EltPtr, NULL, 0, EltVT);
672671
673672 // Load the Lo part from the stack slot.
797797 unsigned SelectionDAG::getMVTAlignment(MVT VT) const {
798798 const Type *Ty = VT == MVT::iPTR ?
799799 PointerType::get(Type::Int8Ty, 0) :
800 VT.getTypeForMVT(*Context);
800 VT.getTypeForMVT();
801801
802802 return TLI.getTargetData()->getABITypeAlignment(Ty);
803803 }
13881388 SDValue SelectionDAG::CreateStackTemporary(MVT VT, unsigned minAlign) {
13891389 MachineFrameInfo *FrameInfo = getMachineFunction().getFrameInfo();
13901390 unsigned ByteSize = VT.getStoreSizeInBits()/8;
1391 const Type *Ty = VT.getTypeForMVT(*Context);
1391 const Type *Ty = VT.getTypeForMVT();
13921392 unsigned StackAlign =
13931393 std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty), minAlign);
13941394
14011401 SDValue SelectionDAG::CreateStackTemporary(MVT VT1, MVT VT2) {
14021402 unsigned Bytes = std::max(VT1.getStoreSizeInBits(),
14031403 VT2.getStoreSizeInBits())/8;
1404 const Type *Ty1 = VT1.getTypeForMVT(*Context);
1405 const Type *Ty2 = VT2.getTypeForMVT(*Context);
1404 const Type *Ty1 = VT1.getTypeForMVT();
1405 const Type *Ty2 = VT2.getTypeForMVT();
14061406 const TargetData *TD = TLI.getTargetData();
14071407 unsigned Align = std::max(TD->getPrefTypeAlignment(Ty1),
14081408 TD->getPrefTypeAlignment(Ty2));
31033103 MVT VT = TLI.getOptimalMemOpType(Size, Align, isSrcConst, isSrcStr, DAG);
31043104 if (VT != MVT::iAny) {
31053105 unsigned NewAlign = (unsigned)
3106 TLI.getTargetData()->getABITypeAlignment(VT.getTypeForMVT(
3107 *DAG.getContext()));
3106 TLI.getTargetData()->getABITypeAlignment(VT.getTypeForMVT());
31083107 // If source is a string constant, this will require an unaligned load.
31093108 if (NewAlign > Align && (isSrcConst || AllowUnalign)) {
31103109 if (Dst.getOpcode() != ISD::FrameIndex) {
55155515 for (unsigned Value = 0, NumValues = ValueVTs.size();
55165516 Value != NumValues; ++Value) {
55175517 MVT VT = ValueVTs[Value];
5518 const Type *ArgTy = VT.getTypeForMVT(*DAG.getContext());
5518 const Type *ArgTy = VT.getTypeForMVT();
55195519 ISD::ArgFlagsTy Flags;
55205520 unsigned OriginalAlignment =
55215521 getTargetData()->getABITypeAlignment(ArgTy);
56465646 for (unsigned Value = 0, NumValues = ValueVTs.size();
56475647 Value != NumValues; ++Value) {
56485648 MVT VT = ValueVTs[Value];
5649 const Type *ArgTy = VT.getTypeForMVT(*DAG.getContext());
5649 const Type *ArgTy = VT.getTypeForMVT();
56505650 SDValue Op = SDValue(Args[i].Node.getNode(),
56515651 Args[i].Node.getResNo() + Value);
56525652 ISD::ArgFlagsTy Flags;
187187
188188 Constant *ShadowStackGC::GetFrameMap(Function &F) {
189189 // doInitialization creates the abstract type of this value.
190 LLVMContext &Context = F.getContext();
191
192190 Type *VoidPtr = PointerType::getUnqual(Type::Int8Ty);
193191
194192 // Truncate the ShadowStackDescriptor if some metadata is null.
208206
209207 Constant *DescriptorElts[] = {
210208 ConstantStruct::get(BaseElts, 2),
211 ConstantArray::get(Context.getArrayType(VoidPtr, NumMeta),
209 ConstantArray::get(ArrayType::get(VoidPtr, NumMeta),
212210 Metadata.begin(), NumMeta)
213211 };
214212
367367 GenericValue JIT::runFunction(Function *F,
368368 const std::vector &ArgValues) {
369369 assert(F && "Function *F was null at entry to run()");
370 LLVMContext &Context = F->getContext();
371370
372371 void *FPtr = getPointerToFunction(F);
373372 assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
469468 // arguments. Make this function and return.
470469
471470 // First, create the function.
472 FunctionType *STy=Context.getFunctionType(RetTy, false);
471 FunctionType *STy=FunctionType::get(RetTy, false);
473472 Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
474473 F->getParent());
475474
11471147 "Appending variables with different section name need to be linked!");
11481148
11491149 unsigned NewSize = T1->getNumElements() + T2->getNumElements();
1150 ArrayType *NewType = Context.getArrayType(T1->getElementType(),
1150 ArrayType *NewType = ArrayType::get(T1->getElementType(),
11511151 NewSize);
11521152
11531153 G1->setName(""); // Clear G1's name in case of a conflict!
100100 TargetLowering::ArgListEntry Entry;
101101 for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) {
102102 MVT ArgVT = Op.getOperand(i).getValueType();
103 const Type *ArgTy = ArgVT.getTypeForMVT(*DAG.getContext());
103 const Type *ArgTy = ArgVT.getTypeForMVT();
104104 Entry.Node = Op.getOperand(i);
105105 Entry.Ty = ArgTy;
106106 Entry.isSExt = isSigned;
111111 TLI.getPointerTy());
112112
113113 // Splice the libcall in wherever FindInputOutputChains tells us to.
114 const Type *RetTy =
115 Op.getNode()->getValueType(0).getTypeForMVT(*DAG.getContext());
114 const Type *RetTy = Op.getNode()->getValueType(0).getTypeForMVT();
116115 std::pair CallInfo =
117116 TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false,
118117 0, CallingConv::C, false, Callee, Args, DAG,
371371 TargetLowering::ArgListEntry Entry;
372372 for (unsigned i = 0; i != NumOps; ++i) {
373373 Entry.Node = Ops[i];
374 Entry.Ty = Entry.Node.getValueType().getTypeForMVT(*DAG.getContext());
374 Entry.Ty = Entry.Node.getValueType().getTypeForMVT();
375375 Entry.isSExt = isSigned;
376376 Entry.isZExt = !isSigned;
377377 Args.push_back(Entry);
378378 }
379379 SDValue Callee = DAG.getExternalSymbol(getPIC16LibcallName(Call), MVT::i8);
380380
381 const Type *RetTy = RetVT.getTypeForMVT(*DAG.getContext());
381 const Type *RetTy = RetVT.getTypeForMVT();
382382 std::pair CallInfo =
383383 LowerCallTo(DAG.getEntryNode(), RetTy, isSigned, !isSigned, false,
384384 false, 0, CallingConv::C, false, Callee, Args, DAG, dl);
12901290
12911291 // Lower to a call to __trampoline_setup(Trmp, TrampSize, FPtr, ctx_reg)
12921292 std::pair CallResult =
1293 LowerCallTo(Chain, Op.getValueType().getTypeForMVT(*DAG.getContext()),
1293 LowerCallTo(Chain, Op.getValueType().getTypeForMVT(),
12941294 false, false, false, false, 0, CallingConv::C, false,
12951295 DAG.getExternalSymbol("__trampoline_setup", PtrVT),
12961296 Args, DAG, dl);
379379 return SDValue();
380380 }
381381 unsigned ABIAlignment = getTargetData()->
382 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT(*DAG.getContext()));
382 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
383383 // Leave aligned load alone.
384384 if (LD->getAlignment() >= ABIAlignment) {
385385 return SDValue();
474474 return SDValue();
475475 }
476476 unsigned ABIAlignment = getTargetData()->
477 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT(*DAG.getContext()));
477 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
478478 // Leave aligned store alone.
479479 if (ST->getAlignment() >= ABIAlignment) {
480480 return SDValue();
10761076 break;
10771077 }
10781078 unsigned ABIAlignment = getTargetData()->
1079 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT(*DAG.getContext()));
1079 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
10801080 unsigned Alignment = ST->getAlignment();
10811081 if (Alignment >= ABIAlignment) {
10821082 break;
587587 }
588588
589589 // Construct the new function type using the new arguments.
590 FunctionType *NFTy = Context.getFunctionType(RetTy, Params, FTy->isVarArg());
590 FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
591591
592592 // Create the new function body and insert it into the module...
593593 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
196196 // Start by computing a new prototype for the function, which is the same as
197197 // the old function, but doesn't have isVarArg set.
198198 const FunctionType *FTy = Fn.getFunctionType();
199 LLVMContext &Context = FTy->getContext();
200199
201200 std::vector Params(FTy->param_begin(), FTy->param_end());
202 FunctionType *NFTy = Context.getFunctionType(FTy->getReturnType(),
201 FunctionType *NFTy = FunctionType::get(FTy->getReturnType(),
203202 Params, false);
204203 unsigned NumArgs = Params.size();
205204
640639 // something and {} into void.
641640 // Make the new struct packed if we used to return a packed struct
642641 // already.
643 NRetTy = Context.getStructType(RetTypes, STy->isPacked());
642 NRetTy = StructType::get(RetTypes, STy->isPacked());
644643 else if (RetTypes.size() == 1)
645644 // One return type? Just a simple value then, but only if we didn't use to
646645 // return a struct with that simple value before.
708707 }
709708
710709 // Create the new function type based on the recomputed parameters.
711 FunctionType *NFTy = Context.getFunctionType(NRetTy, Params,
710 FunctionType *NFTy = FunctionType::get(NRetTy, Params,
712711 FTy->isVarArg());
713712
714713 // No change?
102102 // by putting them in the used array
103103 {
104104 std::vector AUGs;
105 const Type *SBP= Context.getPointerTypeUnqual(Type::Int8Ty);
105 const Type *SBP= PointerType::getUnqual(Type::Int8Ty);
106106 for (std::vector::iterator GI = Named.begin(),
107107 GE = Named.end(); GI != GE; ++GI) {
108108 (*GI)->setLinkage(GlobalValue::ExternalLinkage);
109109 AUGs.push_back(ConstantExpr::getBitCast(*GI, SBP));
110110 }
111 ArrayType *AT = Context.getArrayType(SBP, AUGs.size());
111 ArrayType *AT = ArrayType::get(SBP, AUGs.size());
112112 Constant *Init = ConstantArray::get(AT, AUGs);
113113 GlobalValue *gv = new GlobalVariable(M, AT, false,
114114 GlobalValue::AppendingLinkage,
825825 if (NElements->getZExtValue() != 1) {
826826 // If we have an array allocation, transform it to a single element
827827 // allocation to make the code below simpler.
828 Type *NewTy = Context.getArrayType(MI->getAllocatedType(),
828 Type *NewTy = ArrayType::get(MI->getAllocatedType(),
829829 NElements->getZExtValue());
830830 MallocInst *NewMI =
831831 new MallocInst(NewTy, Context.getNullValue(Type::Int32Ty),
11601160 cast(cast(PN->getType())->getElementType());
11611161
11621162 Result =
1163 PHINode::Create(Context.getPointerTypeUnqual(ST->getElementType(FieldNo)),
1163 PHINode::Create(PointerType::getUnqual(ST->getElementType(FieldNo)),
11641164 PN->getName()+".f"+utostr(FieldNo), PN);
11651165 PHIsToRewrite.push_back(std::make_pair(PN, FieldNo));
11661166 } else {
12811281
12821282 for (unsigned FieldNo = 0, e = STy->getNumElements(); FieldNo != e;++FieldNo){
12831283 const Type *FieldTy = STy->getElementType(FieldNo);
1284 const Type *PFieldTy = Context.getPointerTypeUnqual(FieldTy);
1284 const Type *PFieldTy = PointerType::getUnqual(FieldTy);
12851285
12861286 GlobalVariable *NGV =
12871287 new GlobalVariable(*GV->getParent(),
19561956 if (Ctors[i]) {
19571957 CSVals[1] = Ctors[i];
19581958 } else {
1959 const Type *FTy = Context.getFunctionType(Type::VoidTy, false);
1960 const PointerType *PFTy = Context.getPointerTypeUnqual(FTy);
1959 const Type *FTy = FunctionType::get(Type::VoidTy, false);
1960 const PointerType *PFTy = PointerType::getUnqual(FTy);
19611961 CSVals[1] = Context.getNullValue(PFTy);
19621962 CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
19631963 }
200200 // This function is always successful, unless it isn't.
201201 bool LowerSetJmp::doInitialization(Module& M)
202202 {
203 LLVMContext &Context = M.getContext();
204 const Type *SBPTy = Context.getPointerTypeUnqual(Type::Int8Ty);
205 const Type *SBPPTy = Context.getPointerTypeUnqual(SBPTy);
203 const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty);
204 const Type *SBPPTy = PointerType::getUnqual(SBPTy);
206205
207206 // N.B. See llvm/runtime/GCCLibraries/libexception/SJLJ-Exception.h for
208207 // a description of the following library functions.
258257 // throwing the exception for us.
259258 void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
260259 {
261 const Type* SBPTy = Inst->getContext().getPointerTypeUnqual(Type::Int8Ty);
260 const Type* SBPTy = PointerType::getUnqual(Type::Int8Ty);
262261
263262 // Create the call to "__llvm_sjljeh_throw_longjmp". This takes the
264263 // same parameters as "longjmp", except that the buffer is cast to a
311310 assert(Inst && "Couldn't find even ONE instruction in entry block!");
312311
313312 // Fill in the alloca and call to initialize the SJ map.
314 const Type *SBPTy = Func->getContext().getPointerTypeUnqual(Type::Int8Ty);
313 const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty);
315314 AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
316315 CallInst::Create(InitSJMap, Map, "", Inst);
317316 return SJMap[Func] = Map;
377376 Function* Func = ABlock->getParent();
378377
379378 // Add this setjmp to the setjmp map.
380 const Type* SBPTy = Inst->getContext().getPointerTypeUnqual(Type::Int8Ty);
379 const Type* SBPTy = PointerType::getUnqual(Type::Int8Ty);
381380 CastInst* BufPtr =
382381 new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
383382 std::vector Args =
6969 // function into the appropriate instruction.
7070 //
7171 void RaiseAllocations::doInitialization(Module &M) {
72 LLVMContext &Context = M.getContext();
73
7472 // Get Malloc and free prototypes if they exist!
7573 MallocFunc = M.getFunction("malloc");
7674 if (MallocFunc) {
7876
7977 // Get the expected prototype for malloc
8078 const FunctionType *Malloc1Type =
81 Context.getFunctionType(Context.getPointerTypeUnqual(Type::Int8Ty),
79 FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
8280 std::vector(1, Type::Int64Ty), false);
8381
8482 // Chck to see if we got the expected malloc
8684 // Check to see if the prototype is wrong, giving us i8*(i32) * malloc
8785 // This handles the common declaration of: 'void *malloc(unsigned);'
8886 const FunctionType *Malloc2Type =
89 Context.getFunctionType(Context.getPointerTypeUnqual(Type::Int8Ty),
87 FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
9088 std::vector(1, Type::Int32Ty), false);
9189 if (TyWeHave != Malloc2Type) {
9290 // Check to see if the prototype is missing, giving us
9391 // i8*(...) * malloc
9492 // This handles the common declaration of: 'void *malloc();'
9593 const FunctionType *Malloc3Type =
96 Context.getFunctionType(Context.getPointerTypeUnqual(Type::Int8Ty),
94 FunctionType::get(PointerType::getUnqual(Type::Int8Ty),
9795 true);
9896 if (TyWeHave != Malloc3Type)
9997 // Give up
107105 const FunctionType* TyWeHave = FreeFunc->getFunctionType();
108106
109107 // Get the expected prototype for void free(i8*)
110 const FunctionType *Free1Type = Context.getFunctionType(Type::VoidTy,
111 std::vector(1, Context.getPointerTypeUnqual(Type::Int8Ty)),
108 const FunctionType *Free1Type = FunctionType::get(Type::VoidTy,
109 std::vector(1, PointerType::getUnqual(Type::Int8Ty)),
112110 false);
113111
114112 if (TyWeHave != Free1Type) {
115113 // Check to see if the prototype was forgotten, giving us
116114 // void (...) * free
117115 // This handles the common forward declaration of: 'void free();'
118 const FunctionType* Free2Type = Context.getFunctionType(Type::VoidTy,
116 const FunctionType* Free2Type = FunctionType::get(Type::VoidTy,
119117 true);
120118
121119 if (TyWeHave != Free2Type) {
122120 // One last try, check to see if we can find free as
123121 // int (...)* free. This handles the case where NOTHING was declared.
124 const FunctionType* Free3Type = Context.getFunctionType(Type::Int32Ty,
122 const FunctionType* Free3Type = FunctionType::get(Type::Int32Ty,
125123 true);
126124
127125 if (TyWeHave != Free3Type) {
223221 Value *Source = *CS.arg_begin();
224222 if (!isa(Source->getType()))
225223 Source = new IntToPtrInst(Source,
226 Context.getPointerTypeUnqual(Type::Int8Ty),
224 PointerType::getUnqual(Type::Int8Ty),
227225 "FreePtrCast", I);
228226 new FreeInst(Source, I);
229227
231231 AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
232232
233233
234 FunctionType *NFTy =
235 F->getContext().getFunctionType(STy, Params, FTy->isVarArg());
234 FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
236235 Function *NF = Function::Create(NFTy, F->getLinkage());
237236 NF->takeName(F);
238237 NF->copyAttributesFrom(F);
6262 if (!I->isDeclaration())
6363 ++NumFunctions;
6464
65 const Type *ATy = M.getContext().getArrayType(Type::Int32Ty, NumFunctions);
65 const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions);
6666 GlobalVariable *Counters =
6767 new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
6868 M.getContext().getNullValue(ATy), "FuncProfCounters");
107107 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
108108 NumBlocks += I->size();
109109
110 const Type *ATy = M.getContext().getArrayType(Type::Int32Ty, NumBlocks);
110 const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks);
111111 GlobalVariable *Counters =
112112 new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
113113 M.getContext().getNullValue(ATy), "BlockProfCounters");
6363 NumEdges += BB->getTerminator()->getNumSuccessors();
6464 }
6565
66 const Type *ATy = M.getContext().getArrayType(Type::Int32Ty, NumEdges);
66 const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges);
6767 GlobalVariable *Counters =
6868 new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage,
6969 M.getContext().getNullValue(ATy), "EdgeProfCounters");
2424 GlobalValue *Array) {
2525 LLVMContext &Context = MainFn->getContext();
2626 const Type *ArgVTy =
27 Context.getPointerTypeUnqual(Context.getPointerTypeUnqual(Type::Int8Ty));
28 const PointerType *UIntPtr = Context.getPointerTypeUnqual(Type::Int32Ty);
27 PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));
28 const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty);
2929 Module &M = *MainFn->getParent();
3030 Constant *InitFn = M.getOrInsertFunction(FnName, Type::Int32Ty, Type::Int32Ty,
3131 ArgVTy, UIntPtr, Type::Int32Ty,
76807680 case 32 :
76817681 case 64 :
76827682 case 128:
7683 SExtType = Context->getIntegerType(Ty->getBitWidth() - ShiftAmt1);
7683 SExtType = IntegerType::get(Ty->getBitWidth() - ShiftAmt1);
76847684 break;
76857685 default: break;
76867686 }
96969696
96979697 // Use an integer load+store unless we can find something better.
96989698 Type *NewPtrTy =
9699 Context->getPointerTypeUnqual(Context->getIntegerType(Size<<3));
9699 PointerType::getUnqual(IntegerType::get(Size<<3));
97009700
97019701 // Memcpy forces the use of i8* for the source and destination. That means
97029702 // that if you're using memcpy to move one double around, you'll get a cast
97259725 }
97269726
97279727 if (SrcETy->isSingleValueType())
9728 NewPtrTy = Context->getPointerTypeUnqual(SrcETy);
9728 NewPtrTy = PointerType::getUnqual(SrcETy);
97299729 }
97309730 }
97319731
97679767
97689768 // memset(s,c,n) -> store s, c (for n=1,2,4,8)
97699769 if (Len <= 8 && isPowerOf2_32((uint32_t)Len)) {
9770 const Type *ITy = Context->getIntegerType(Len*8); // n=1 -> i8.
9770 const Type *ITy = IntegerType::get(Len*8); // n=1 -> i8.
97719771
97729772 Value *Dest = MI->getDest();
9773 Dest = InsertBitCastBefore(Dest, Context->getPointerTypeUnqual(ITy), *MI);
9773 Dest = InsertBitCastBefore(Dest, PointerType::getUnqual(ITy), *MI);
97749774
97759775 // Alignment 0 is identity for alignment 1 for memset, but not store.
97769776 if (Alignment == 0) Alignment = 1;
98749874 // Turn X86 loadups -> load if the pointer is known aligned.
98759875 if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
98769876 Value *Ptr = InsertBitCastBefore(II->getOperand(1),
9877 Context->getPointerTypeUnqual(II->getType()),
9877 PointerType::getUnqual(II->getType()),
98789878 CI);
98799879 return new LoadInst(Ptr);
98809880 }
98849884 // Turn stvx -> store if the pointer is known aligned.
98859885 if (GetOrEnforceKnownAlignment(II->getOperand(2), 16) >= 16) {
98869886 const Type *OpPtrTy =
9887 Context->getPointerTypeUnqual(II->getOperand(1)->getType());
9887 PointerType::getUnqual(II->getOperand(1)->getType());
98889888 Value *Ptr = InsertBitCastBefore(II->getOperand(2), OpPtrTy, CI);
98899889 return new StoreInst(II->getOperand(1), Ptr);
98909890 }
98959895 // Turn X86 storeu -> store if the pointer is known aligned.
98969896 if (GetOrEnforceKnownAlignment(II->getOperand(1), 16) >= 16) {
98979897 const Type *OpPtrTy =
9898 Context->getPointerTypeUnqual(II->getOperand(2)->getType());
9898 PointerType::getUnqual(II->getOperand(2)->getType());
98999899 Value *Ptr = InsertBitCastBefore(II->getOperand(1), OpPtrTy, CI);
99009900 return new StoreInst(II->getOperand(2), Ptr);
99019901 }
1006110061 // If the call and callee calling conventions don't match, this call must
1006210062 // be unreachable, as the call is undefined.
1006310063 new StoreInst(Context->getTrue(),
10064 Context->getUndef(Context->getPointerTypeUnqual(Type::Int1Ty)),
10064 Context->getUndef(PointerType::getUnqual(Type::Int1Ty)),
1006510065 OldCall);
1006610066 if (!OldCall->use_empty())
1006710067 OldCall->replaceAllUsesWith(Context->getUndef(OldCall->getType()));
1007510075 // undef so that we know that this code is not reachable, despite the fact
1007610076 // that we can't modify the CFG here.
1007710077 new StoreInst(Context->getTrue(),
10078 Context->getUndef(Context->getPointerTypeUnqual(Type::Int1Ty)),
10078 Context->getUndef(PointerType::getUnqual(Type::Int1Ty)),
1007910079 CS.getInstruction());
1008010080
1008110081 if (!CS.getInstruction()->use_empty())
1045610456
1045710457 // Replace the trampoline call with a direct call. Let the generic
1045810458 // code sort out any function type mismatches.
10459 FunctionType *NewFTy =
10460 Context->getFunctionType(FTy->getReturnType(), NewTypes,
10459 FunctionType *NewFTy = FunctionType::get(FTy->getReturnType(), NewTypes,
1046110460 FTy->isVarArg());
1046210461 Constant *NewCallee =
10463 NestF->getType() == Context->getPointerTypeUnqual(NewFTy) ?
10462 NestF->getType() == PointerType::getUnqual(NewFTy) ?
1046410463 NestF : ConstantExpr::getBitCast(NestF,
10465 Context->getPointerTypeUnqual(NewFTy));
10464 PointerType::getUnqual(NewFTy));
1046610465 const AttrListPtr &NewPAL = AttrListPtr::get(NewAttrs.begin(),
1046710466 NewAttrs.end());
1046810467
1136611365 if (AI.isArrayAllocation()) { // Check C != 1
1136711366 if (const ConstantInt *C = dyn_cast(AI.getArraySize())) {
1136811367 const Type *NewTy =
11369 Context->getArrayType(AI.getAllocatedType(), C->getZExtValue());
11368 ArrayType::get(AI.getAllocatedType(), C->getZExtValue());
1137011369 AllocationInst *New = 0;
1137111370
1137211371 // Create and insert the replacement instruction...
1142611425 if (isa(Op)) {
1142711426 // Insert a new store to null because we cannot modify the CFG here.
1142811427 new StoreInst(Context->getTrue(),
11429 Context->getUndef(Context->getPointerTypeUnqual(Type::Int1Ty)), &FI);
11428 Context->getUndef(PointerType::getUnqual(Type::Int1Ty)), &FI);
1143011429 return EraseInstFromFunction(FI);
1143111430 }
1143211431
1173311732 }
1173411733 }
1173511734
11736 SrcTy = Context->getPointerType(SrcPTy, SrcTy->getAddressSpace());
11735 SrcTy = PointerType::get(SrcPTy, SrcTy->getAddressSpace());
1173711736 }
1173811737
1173911738 if (!SrcPTy->isInteger() && !isa(SrcPTy))
1245512454 unsigned AS =
1245612455 cast(I->getOperand(0)->getType())->getAddressSpace();
1245712456 Value *Ptr = InsertBitCastBefore(I->getOperand(0),
12458 Context->getPointerType(EI.getType(), AS),EI);
12457 PointerType::get(EI.getType(), AS),EI);
1245912458 GetElementPtrInst *GEP =
1246012459 GetElementPtrInst::Create(Ptr, EI.getOperand(1), I->getName()+".gep");
1246112460 cast(GEP)->setIsInBounds(true);
19461946
19471947 NewCmpTy = NewCmpLHS->getType();
19481948 NewTyBits = SE->getTypeSizeInBits(NewCmpTy);
1949 const Type *NewCmpIntTy = Context.getIntegerType(NewTyBits);
1949 const Type *NewCmpIntTy = IntegerType::get(NewTyBits);
19501950 if (RequiresTypeConversion(NewCmpTy, CmpTy)) {
19511951 // Check if it is possible to rewrite it using
19521952 // an iv / stride of a smaller integer type.
351351
352352 TargetData &TD = getAnalysis();
353353 AliasAnalysis &AA = getAnalysis();
354 LLVMContext &Context = SI->getContext();
355354 Module *M = SI->getParent()->getParent()->getParent();
356355
357356 // Okay, so we now have a single store that can be splatable. Scan to find
440439 StartPtr = Range.StartPtr;
441440
442441 // Cast the start ptr to be i8* as memset requires.
443 const Type *i8Ptr = Context.getPointerTypeUnqual(Type::Int8Ty);
442 const Type *i8Ptr = PointerType::getUnqual(Type::Int8Ty);
444443 if (StartPtr->getType() != i8Ptr)
445444 StartPtr = new BitCastInst(StartPtr, i8Ptr, StartPtr->getName(),
446445 InsertPt);
306306 DOUT << "CONVERT TO SCALAR INTEGER: " << *AI << "\n";
307307
308308 // Create and insert the integer alloca.
309 const Type *NewTy = F.getContext().getIntegerType(AllocaSize*8);
309 const Type *NewTy = IntegerType::get(AllocaSize*8);
310310 NewAI = new AllocaInst(NewTy, 0, "", AI->getParent()->begin());
311311 ConvertUsesToScalar(AI, NewAI, 0);
312312 }
899899 SmallVector &NewElts){
900900 // Extract each element out of the integer according to its structure offset
901901 // and store the element value to the individual alloca.
902 LLVMContext &Context = SI->getContext();
903902 Value *SrcVal = SI->getOperand(0);
904903 const Type *AllocaEltTy = AI->getType()->getElementType();
905904 uint64_t AllocaSizeBits = TD->getTypeAllocSizeInBits(AllocaEltTy);
913912 // Handle tail padding by extending the operand
914913 if (TD->getTypeSizeInBits(SrcVal->getType()) != AllocaSizeBits)
915914 SrcVal = new ZExtInst(SrcVal,
916 Context.getIntegerType(AllocaSizeBits), "", SI);
915 IntegerType::get(AllocaSizeBits), "", SI);
917916
918917 DOUT << "PROMOTING STORE TO WHOLE ALLOCA: " << *AI << *SI;
919918
945944
946945 if (FieldSizeBits != AllocaSizeBits)
947946 EltVal = new TruncInst(EltVal,
948 Context.getIntegerType(FieldSizeBits), "", SI);
947 IntegerType::get(FieldSizeBits), "", SI);
949948 Value *DestField = NewElts[i];
950949 if (EltVal->getType() == FieldTy) {
951950 // Storing to an integer field of this size, just do it.
955954 } else {
956955 // Otherwise, bitcast the dest pointer (for aggregates).
957956 DestField = new BitCastInst(DestField,
958 Context.getPointerTypeUnqual(EltVal->getType()),
957 PointerType::getUnqual(EltVal->getType()),
959958 "", SI);
960959 }
961960 new StoreInst(EltVal, DestField, SI);
988987 // Truncate down to an integer of the right size.
989988 if (ElementSizeBits != AllocaSizeBits)
990989 EltVal = new TruncInst(EltVal,
991 Context.getIntegerType(ElementSizeBits),"",SI);
990 IntegerType::get(ElementSizeBits),"",SI);
992991 Value *DestField = NewElts[i];
993992 if (EltVal->getType() == ArrayEltTy) {
994993 // Storing to an integer field of this size, just do it.
998997 } else {
999998 // Otherwise, bitcast the dest pointer (for aggregates).
1000999 DestField = new BitCastInst(DestField,
1001 Context.getPointerTypeUnqual(EltVal->getType()),
1000 PointerType::getUnqual(EltVal->getType()),
10021001 "", SI);
10031002 }
10041003 new StoreInst(EltVal, DestField, SI);
10451044 LLVMContext &Context = LI->getContext();
10461045
10471046 Value *ResultVal =
1048 Context.getNullValue(Context.getIntegerType(AllocaSizeBits));
1047 Context.getNullValue(IntegerType::get(AllocaSizeBits));
10491048
10501049 for (unsigned i = 0, e = NewElts.size(); i != e; ++i) {
10511050 // Load the value from the alloca. If the NewElt is an aggregate, cast
10581057 // Ignore zero sized fields like {}, they obviously contain no data.
10591058 if (FieldSizeBits == 0) continue;
10601059
1061 const IntegerType *FieldIntTy = Context.getIntegerType(FieldSizeBits);
1060 const IntegerType *FieldIntTy = IntegerType::get(FieldSizeBits);
10621061 if (!isa(FieldTy) && !FieldTy->isFloatingPoint() &&
10631062 !isa(FieldTy))
10641063 SrcField = new BitCastInst(SrcField,
1065 Context.getPointerTypeUnqual(FieldIntTy),
1064 PointerType::getUnqual(FieldIntTy),
10661065 "", LI);
10671066 SrcField = new LoadInst(SrcField, "sroa.load.elt", LI);
10681067
12961295 cast(VecTy)->getElementType()
12971296 ->getPrimitiveSizeInBits()/8 == EltSize)) {
12981297 if (VecTy == 0)
1299 VecTy = In->getContext().getVectorType(In, AllocaSize/EltSize);
1298 VecTy = VectorType::get(In, AllocaSize/EltSize);
13001299 return;
13011300 }
13021301 }
16221621 unsigned LIBitWidth = TD->getTypeSizeInBits(ToType);
16231622 if (LIBitWidth < NTy->getBitWidth())
16241623 FromVal =
1625 Builder.CreateTrunc(FromVal, Context.getIntegerType(LIBitWidth), "tmp");
1624 Builder.CreateTrunc(FromVal, IntegerType::get(LIBitWidth), "tmp");
16261625 else if (LIBitWidth > NTy->getBitWidth())
16271626 FromVal =
1628 Builder.CreateZExt(FromVal, Context.getIntegerType(LIBitWidth), "tmp");
1627 Builder.CreateZExt(FromVal, IntegerType::get(LIBitWidth), "tmp");
16291628
16301629 // If the result is an integer, this is a trunc or bitcast.
16311630 if (isa(ToType)) {
17101709 unsigned SrcStoreWidth = TD->getTypeStoreSizeInBits(SV->getType());
17111710 unsigned DestStoreWidth = TD->getTypeStoreSizeInBits(AllocaType);
17121711 if (SV->getType()->isFloatingPoint() || isa(SV->getType()))
1713 SV = Builder.CreateBitCast(SV, Context.getIntegerType(SrcWidth), "tmp");
1712 SV = Builder.CreateBitCast(SV, IntegerType::get(SrcWidth), "tmp");
17141713 else if (isa(SV->getType()))
17151714 SV = Builder.CreatePtrToInt(SV, TD->getIntPtrType(), "tmp");
17161715
125125 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
126126 Value *LibCallOptimization::CastToCStr(Value *V, IRBuilder<> &B) {
127127 return
128 B.CreateBitCast(V, Context->getPointerTypeUnqual(Type::Int8Ty), "cstr");
128 B.CreateBitCast(V, PointerType::getUnqual(Type::Int8Ty), "cstr");
129129 }
130130
131131 /// EmitStrLen - Emit a call to the strlen function to the builder, for the
139139
140140 Constant *StrLen =M->getOrInsertFunction("strlen", AttrListPtr::get(AWI, 2),
141141 TD->getIntPtrType(),
142 Context->getPointerTypeUnqual(Type::Int8Ty),
142 PointerType::getUnqual(Type::Int8Ty),
143143 NULL);
144144 CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen");
145145 if (const Function *F = dyn_cast(StrLen->stripPointerCasts()))
170170 AWI = AttributeWithIndex::get(~0u, Attribute::ReadOnly | Attribute::NoUnwind);
171171
172172 Value *MemChr = M->getOrInsertFunction("memchr", AttrListPtr::get(&AWI, 1),
173 Context->getPointerTypeUnqual(Type::Int8Ty),
174 Context->getPointerTypeUnqual(Type::Int8Ty),
173 PointerType::getUnqual(Type::Int8Ty),
174 PointerType::getUnqual(Type::Int8Ty),
175175 Type::Int32Ty, TD->getIntPtrType(),
176176 NULL);
177177 CallInst *CI = B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr");
194194
195195 Value *MemCmp = M->getOrInsertFunction("memcmp", AttrListPtr::get(AWI, 3),
196196 Type::Int32Ty,
197 Context->getPointerTypeUnqual(Type::Int8Ty),
198 Context->getPointerTypeUnqual(Type::Int8Ty),
197 PointerType::getUnqual(Type::Int8Ty),
198 PointerType::getUnqual(Type::Int8Ty),
199199 TD->getIntPtrType(), NULL);
200200 CallInst *CI = B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B),
201201 Len, "memcmp");
273273
274274 Value *PutS = M->getOrInsertFunction("puts", AttrListPtr::get(AWI, 2),
275275 Type::Int32Ty,
276 Context->getPointerTypeUnqual(Type::Int8Ty),
276 PointerType::getUnqual(Type::Int8Ty),
277277 NULL);
278278 CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts");
279279 if (const Function *F = dyn_cast(PutS->stripPointerCasts()))
313313 Constant *F;
314314 if (isa(File->getType()))
315315 F = M->getOrInsertFunction("fputs", AttrListPtr::get(AWI, 3), Type::Int32Ty,
316 Context->getPointerTypeUnqual(Type::Int8Ty),
316 PointerType::getUnqual(Type::Int8Ty),
317317 File->getType(), NULL);
318318 else
319319 F = M->getOrInsertFunction("fputs", Type::Int32Ty,
320 Context->getPointerTypeUnqual(Type::Int8Ty),
320 PointerType::getUnqual(Type::Int8Ty),
321321 File->getType(), NULL);
322322 CallInst *CI = B.CreateCall2(F, CastToCStr(Str, B), File, "fputs");
323323
338338 if (isa(File->getType()))
339339 F = M->getOrInsertFunction("fwrite", AttrListPtr::get(AWI, 3),
340340 TD->getIntPtrType(),
341 Context->getPointerTypeUnqual(Type::Int8Ty),
341 PointerType::getUnqual(Type::Int8Ty),
342342 TD->getIntPtrType(), TD->getIntPtrType(),
343343 File->getType(), NULL);
344344 else
345345 F = M->getOrInsertFunction("fwrite", TD->getIntPtrType(),
346 Context->getPointerTypeUnqual(Type::Int8Ty),
346 PointerType::getUnqual(Type::Int8Ty),
347347 TD->getIntPtrType(), TD->getIntPtrType(),
348348 File->getType(), NULL);
349349 CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
554554 // Verify the "strcat" function prototype.
555555 const FunctionType *FT = Callee->getFunctionType();
556556 if (FT->getNumParams() != 2 ||
557 FT->getReturnType() != Context->getPointerTypeUnqual(Type::Int8Ty) ||
557 FT->getReturnType() != PointerType::getUnqual(Type::Int8Ty) ||
558558 FT->getParamType(0) != FT->getReturnType() ||
559559 FT->getParamType(1) != FT->getReturnType())
560560 return 0;
601601 // Verify the "strncat" function prototype.
602602 const FunctionType *FT = Callee->getFunctionType();
603603 if (FT->getNumParams() != 3 ||
604 FT->getReturnType() != Context->getPointerTypeUnqual(Type::Int8Ty) ||
604 FT->getReturnType() != PointerType::getUnqual(Type::Int8Ty) ||
605605 FT->getParamType(0) != FT->getReturnType() ||
606606 FT->getParamType(1) != FT->getReturnType() ||
607607 !isa(FT->getParamType(2)))
646646 // Verify the "strchr" function prototype.
647647 const FunctionType *FT = Callee->getFunctionType();
648648 if (FT->getNumParams() != 2 ||
649 FT->getReturnType() != Context->getPointerTypeUnqual(Type::Int8Ty) ||
649 FT->getReturnType() != PointerType::getUnqual(Type::Int8Ty) ||
650650 FT->getParamType(0) != FT->getReturnType())
651651 return 0;
652652
700700 const FunctionType *FT = Callee->getFunctionType();
701701 if (FT->getNumParams() != 2 || FT->getReturnType() != Type::Int32Ty ||
702702 FT->getParamType(0) != FT->getParamType(1) ||
703 FT->getParamType(0) != Context->getPointerTypeUnqual(Type::Int8Ty))
703 FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty))
704704 return 0;
705705
706706 Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2);
744744 const FunctionType *FT = Callee->getFunctionType();
745745 if (FT->getNumParams() != 3 || FT->getReturnType() != Type::Int32Ty ||
746746 FT->getParamType(0) != FT->getParamType(1) ||
747 FT->getParamType(0) != Context->getPointerTypeUnqual(Type::Int8Ty) ||
747 FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty) ||
748748 !isa(FT->getParamType(2)))
749749 return 0;
750750
790790 const FunctionType *FT = Callee->getFunctionType();
791791 if (FT->getNumParams() != 2 || FT->getReturnType() != FT->getParamType(0) ||
792792 FT->getParamType(0) != FT->getParamType(1) ||
793 FT->getParamType(0) != Context->getPointerTypeUnqual(Type::Int8Ty))
793 FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty))
794794 return 0;
795795
796796 Value *Dst = CI->getOperand(1), *Src = CI->getOperand(2);
817817 const FunctionType *FT = Callee->getFunctionType();
818818 if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) ||
819819 FT->getParamType(0) != FT->getParamType(1) ||
820 FT->getParamType(0) != Context->getPointerTypeUnqual(Type::Int8Ty) ||
820 FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty) ||
821821 !isa(FT->getParamType(2)))
822822 return 0;
823823
862862 virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
863863 const FunctionType *FT = Callee->getFunctionType();
864864 if (FT->getNumParams() != 1 ||
865 FT->getParamType(0) != Context->getPointerTypeUnqual(Type::Int8Ty) ||
865 FT->getParamType(0) != PointerType::getUnqual(Type::Int8Ty) ||
866866 !isa(FT->getReturnType()))
867867 return 0;
868868
936936 // memcmp(S1,S2,2) != 0 -> (*(short*)LHS ^ *(short*)RHS) != 0
937937 // memcmp(S1,S2,4) != 0 -> (*(int*)LHS ^ *(int*)RHS) != 0
938938 if ((Len == 2 || Len == 4) && IsOnlyUsedInZeroEqualityComparison(CI)) {
939 const Type *PTy = Context->getPointerTypeUnqual(Len == 2 ?
939 const Type *PTy = PointerType::getUnqual(Len == 2 ?
940940 Type::Int16Ty : Type::Int32Ty);
941941 LHS = B.CreateBitCast(LHS, PTy, "tmp");
942942 RHS = B.CreateBitCast(RHS, PTy, "tmp");
150150 ArgTypes.push_back(I->getType());
151151
152152 // Create a new function type...
153 FunctionType *FTy =
154 F->getContext().getFunctionType(F->getFunctionType()->getReturnType(),
153 FunctionType *FTy = FunctionType::get(F->getFunctionType()->getReturnType(),
155154 ArgTypes, F->getFunctionType()->isVarArg());
156155
157156 // Create the new function...
265265 if (AggregateArgs)
266266 paramTy.push_back((*I)->getType());
267267 else
268 paramTy.push_back(
269 header->getContext().getPointerTypeUnqual((*I)->getType()));
268 paramTy.push_back(PointerType::getUnqual((*I)->getType()));
270269 }
271270
272271 DOUT << "Function type: " << *RetTy << " f(";
277276
278277 if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
279278 PointerType *StructPtr =
280 Context.getPointerTypeUnqual(Context.getStructType(paramTy));
279 PointerType::getUnqual(StructType::get(paramTy));
281280 paramTy.clear();
282281 paramTy.push_back(StructPtr);
283282 }
284283 const FunctionType *funcType =
285 Context.getFunctionType(RetTy, paramTy, false);
284 FunctionType::get(RetTy, paramTy, false);
286285
287286 // Create the new function
288287 Function *newFunction = Function::Create(funcType,
386385 ArgTypes.push_back((*v)->getType());
387386
388387 // Allocate a struct at the beginning of this function
389 Type *StructArgTy = Context.getStructType(ArgTypes);
388 Type *StructArgTy = StructType::get(ArgTypes);
390389 Struct =
391390 new AllocaInst(StructArgTy, 0, "structArg",
392391 codeReplacer->getParent()->begin()->begin());
303303 if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) &&
304304 !CalledFunc->onlyReadsMemory()) {
305305 const Type *AggTy = cast(I->getType())->getElementType();
306 const Type *VoidPtrTy = Context.getPointerTypeUnqual(Type::Int8Ty);
306 const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
307307
308308 // Create the alloca. If we have TargetData, use nice alignment.
309309 unsigned Align = 1;
8686 // This function is always successful.
8787 //
8888 bool LowerAllocations::doInitialization(Module &M) {
89 const Type *BPTy = M.getContext().getPointerTypeUnqual(Type::Int8Ty);
89 const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
9090 // Prototype malloc as "char* malloc(...)", because we don't know in
9191 // doInitialization whether size_t is int or long.
92 FunctionType *FT = M.getContext().getFunctionType(BPTy, true);
92 FunctionType *FT = FunctionType::get(BPTy, true);
9393 MallocFunc = M.getOrInsertFunction("malloc", FT);
9494 FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
9595 return true;
165165 } else if (FreeInst *FI = dyn_cast(I)) {
166166 Value *PtrCast =
167167 new BitCastInst(FI->getOperand(0),
168 Context.getPointerTypeUnqual(Type::Int8Ty), "", I);
168 PointerType::getUnqual(Type::Int8Ty), "", I);
169169
170170 // Insert a call to the free function...
171171 CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
116116 bool LowerInvoke::doInitialization(Module &M) {
117117 LLVMContext &Context = M.getContext();
118118
119 const Type *VoidPtrTy = Context.getPointerTypeUnqual(Type::Int8Ty);
119 const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
120120 AbortMessage = 0;
121121 if (ExpensiveEHSupport) {
122122 // Insert a type for the linked list of jump buffers.
123123 unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
124124 JBSize = JBSize ? JBSize : 200;
125 const Type *JmpBufTy = Context.getArrayType(VoidPtrTy, JBSize);
125 const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JBSize);
126126
127127 { // The type is recursive, so use a type holder.
128128 std::vector Elements;
129129 Elements.push_back(JmpBufTy);
130 OpaqueType *OT = Context.getOpaqueType();
131 Elements.push_back(Context.getPointerTypeUnqual(OT));
132 PATypeHolder JBLType(Context.getStructType(Elements));
130 OpaqueType *OT = OpaqueType::get();
131 Elements.push_back(PointerType::getUnqual(OT));
132 PATypeHolder JBLType(StructType::get(Elements));
133133 OT->refineAbstractTypeTo(JBLType.get()); // Complete the cycle.
134134 JBLinkTy = JBLType.get();
135135 M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy);
136136 }
137137
138 const Type *PtrJBList = Context.getPointerTypeUnqual(JBLinkTy);
138 const Type *PtrJBList = PointerType::getUnqual(JBLinkTy);
139139
140140 // Now that we've done that, insert the jmpbuf list head global, unless it
141141 // already exists.
2525
2626 static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
2727 assert(F && "Illegal to upgrade a non-existent Function.");
28
29 LLVMContext &Context = F->getContext();
3028
3129 // Get the Function's name.
3230 const std::string& Name = F->getName();
166164 Name.compare(13,4,"psrl", 4) == 0) && Name[17] != 'i') {
167165
168166 const llvm::Type *VT =
169 Context.getVectorType(Context.getIntegerType(64), 1);
167 VectorType::get(IntegerType::get(64), 1);
170168
171169 // We don't have to do anything if the parameter already has
172170 // the correct type.
267265 if (isLoadH || isLoadL) {
268266 Value *Op1 = Context.getUndef(Op0->getType());
269267 Value *Addr = new BitCastInst(CI->getOperand(2),
270 Context.getPointerTypeUnqual(Type::DoubleTy),
268 PointerType::getUnqual(Type::DoubleTy),
271269 "upgraded.", CI);
272270 Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI);
273271 Value *Idx = ConstantInt::get(Type::Int32Ty, 0);
13721372 const Constant *C2) {
13731373 const Type *ResultTy;
13741374 if (const VectorType *VT = dyn_cast(C1->getType()))
1375 ResultTy = Context.getVectorType(Type::Int1Ty, VT->getNumElements());
1375 ResultTy = VectorType::get(Type::Int1Ty, VT->getNumElements());
13761376 else
13771377 ResultTy = Type::Int1Ty;
13781378
16761676 (Value **)Idxs,
16771677 (Value **)Idxs+NumIdx);
16781678 assert(Ty != 0 && "Invalid indices for GEP!");
1679 return Context.getUndef(Context.getPointerType(Ty, Ptr->getAddressSpace()));
1679 return Context.getUndef(PointerType::get(Ty, Ptr->getAddressSpace()));
16801680 }
16811681
16821682 Constant *Idx0 = Idxs[0];
16941694 (Value**)Idxs+NumIdx);
16951695 assert(Ty != 0 && "Invalid indices for GEP!");
16961696 return Context.getConstantPointerNull(
1697 Context.getPointerType(Ty,Ptr->getAddressSpace()));
1697 PointerType::get(Ty,Ptr->getAddressSpace()));
16981698 }
16991699 }
17001700
177177 // invariant which generates an assertion.
178178 ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) {
179179 // Get the corresponding integer type for the bit width of the value.
180 const IntegerType *ITy = Context.getIntegerType(V.getBitWidth());
180 const IntegerType *ITy = IntegerType::get(V.getBitWidth());
181181 // get an existing value or the insertion position
182182 DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
183183
161161 LLVMTypeRef LLVMInt64Type(void) { return (LLVMTypeRef) Type::Int64Ty; }
162162
163163 LLVMTypeRef LLVMIntType(unsigned NumBits) {
164 return wrap(getGlobalContext().getIntegerType(NumBits));
164 return wrap(IntegerType::get(NumBits));
165165 }
166166
167167 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
185185 for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I)
186186 Tys.push_back(unwrap(*I));
187187
188 return wrap(getGlobalContext().getFunctionType(unwrap(ReturnType), Tys,
189 IsVarArg != 0));
188 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
190189 }
191190
192191 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
217216 *E = ElementTypes + ElementCount; I != E; ++I)
218217 Tys.push_back(unwrap(*I));
219218
220 return wrap(getGlobalContext().getStructType(Tys, Packed != 0));
219 return wrap(StructType::get(Tys, Packed != 0));
221220 }
222221
223222 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
238237 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
239238
240239 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
241 return wrap(getGlobalContext().getArrayType(unwrap(ElementType),
242 ElementCount));
240 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
243241 }
244242
245243 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
246 return wrap(getGlobalContext().getPointerType(unwrap(ElementType),
247 AddressSpace));
244 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
248245 }
249246
250247 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
251 return wrap(getGlobalContext().getVectorType(unwrap(ElementType),
252 ElementCount));
248 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
253249 }
254250
255251 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
274270 LLVMTypeRef LLVMLabelType(void) { return (LLVMTypeRef) Type::LabelTy; }
275271
276272 LLVMTypeRef LLVMOpaqueType(void) {
277 return wrap(getGlobalContext().getOpaqueType());
273 return wrap(OpaqueType::get());
278274 }
279275
280276 /*--.. Operations on type handles ..........................................--*/
407403
408404 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
409405 LLVMValueRef *ConstantVals, unsigned Length) {
410 return wrap(ConstantArray::get(
411 getGlobalContext().getArrayType(unwrap(ElementTy), Length),
406 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length),
412407 unwrap(ConstantVals, Length),
413408 Length));
414409 }
345345 #include "llvm/Intrinsics.gen"
346346 #undef GET_INTRINSIC_GENERATOR
347347
348 return Context.getFunctionType(ResultTy, ArgTys, IsVarArg);
348 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
349349 }
350350
351351 bool Intrinsic::isOverloaded(ID id) {
9797 bool constant, LinkageTypes Link,
9898 Constant *InitVal, const Twine &Name,
9999 bool ThreadLocal, unsigned AddressSpace)
100 : GlobalValue(Context.getPointerType(Ty, AddressSpace),
100 : GlobalValue(PointerType::get(Ty, AddressSpace),
101101 Value::GlobalVariableVal,
102102 OperandTraits::op_begin(this),
103103 InitVal != 0, Link, Name),
116116 const Twine &Name,
117117 GlobalVariable *Before, bool ThreadLocal,
118118 unsigned AddressSpace)
119 : GlobalValue(M.getContext().getPointerType(Ty, AddressSpace),
119 : GlobalValue(PointerType::get(Ty, AddressSpace),
120120 Value::GlobalVariableVal,
121121 OperandTraits::op_begin(this),
122122 InitVal != 0, Link, Name),
715715 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
716716 unsigned Align, const Twine &Name,
717717 Instruction *InsertBefore)
718 : UnaryInstruction(Ty->getContext().getPointerTypeUnqual(Ty), iTy,
718 : UnaryInstruction(PointerType::getUnqual(Ty), iTy,
719719 getAISize(Ty->getContext(), ArraySize), InsertBefore) {
720720 setAlignment(Align);
721721 assert(Ty != Type::VoidTy && "Cannot allocate void!");
725725 AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
726726 unsigned Align, const Twine &Name,
727727 BasicBlock *InsertAtEnd)
728 : UnaryInstruction(Ty->getContext().getPointerTypeUnqual(Ty), iTy,
728 : UnaryInstruction(PointerType::getUnqual(Ty), iTy,
729729 getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
730730 setAlignment(Align);
731731 assert(Ty != Type::VoidTy && "Cannot allocate void!");
10451045
10461046 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
10471047 const Twine &Name, Instruction *InBe)
1048 : Instruction(Ptr->getType()->getContext().getPointerType(
1048 : Instruction(PointerType::get(
10491049 checkType(getIndexedType(Ptr->getType(),Idx)), retrieveAddrSpace(Ptr)),
10501050 GetElementPtr,
10511051 OperandTraits::op_end(this) - 2,
10551055
10561056 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
10571057 const Twine &Name, BasicBlock *IAE)
1058 : Instruction(Ptr->getType()->getContext().getPointerType(
1058 : Instruction(PointerType::get(
10591059 checkType(getIndexedType(Ptr->getType(),Idx)),
10601060 retrieveAddrSpace(Ptr)),
10611061 GetElementPtr,
12691269 ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
12701270 const Twine &Name,
12711271 Instruction *InsertBefore)
1272 : Instruction(V1->getType()->getContext().getVectorType(
1273 cast(V1->getType())->getElementType(),
1272 : Instruction(VectorType::get(cast(V1->getType())->getElementType(),
12741273 cast(Mask->getType())->getNumElements()),
12751274 ShuffleVector,
12761275 OperandTraits::op_begin(this),
112112 return pImpl->getMDString(Str.data(), Str.size());
113113 }
114114
115 // FunctionType accessors
116 FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
117 return FunctionType::get(Result, isVarArg);
118 }
119
120 FunctionType* LLVMContext::getFunctionType(const Type* Result,
121 const std::vector& Params,
122 bool isVarArg) {
123 return FunctionType::get(Result, Params, isVarArg);
124 }
125
126 // IntegerType accessors
127 const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
128 return IntegerType::get(NumBits);
129 }
130
131 // OpaqueType accessors
132 OpaqueType* LLVMContext::getOpaqueType() {
133 return OpaqueType::get();
134 }
135
136 // StructType accessors
137 StructType* LLVMContext::getStructType(bool isPacked) {
138 return StructType::get(isPacked);
139 }
140
141 StructType* LLVMContext::getStructType(const std::vector& Params,
142 bool isPacked) {
143 return StructType::get(Params, isPacked);
144 }
145
146 StructType *LLVMContext::getStructType(const Type *type, ...) {
147 va_list ap;
148 std::vector StructFields;
149 va_start(ap, type);
150 while (type) {
151 StructFields.push_back(type);
152 type = va_arg(ap, llvm::Type*);
153 }
154 return StructType::get(StructFields);
155 }
156
157 // ArrayType accessors
158 ArrayType* LLVMContext::getArrayType(const Type* ElementType,
159 uint64_t NumElements) {
160 return ArrayType::get(ElementType, NumElements);
161 }
162
163 // PointerType accessors
164 PointerType* LLVMContext::getPointerType(const Type* ElementType,
165 unsigned AddressSpace) {
166 return PointerType::get(ElementType, AddressSpace);
167 }
168
169 PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
170 return PointerType::getUnqual(ElementType);
171 }
172
173 // VectorType accessors
174 VectorType* LLVMContext::getVectorType(const Type* ElementType,
175 unsigned NumElements) {
176 return VectorType::get(ElementType, NumElements);
177 }
178
179 VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
180 return VectorType::getInteger(VTy);
181 }
182
183 VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
184 return VectorType::getExtendedElementVectorType(VTy);
185 }
186
187 VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
188 return VectorType::getTruncatedElementVectorType(VTy);
189 }
190
191 const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
192 if (const VectorType* vt = dyn_cast(opnd_type)) {
193 return getVectorType(Type::Int1Ty, vt->getNumElements());
194 }
195 return Type::Int1Ty;
196 }
197
198115 void LLVMContext::erase(MDString *M) {
199116 pImpl->erase(M);
200117 }
152152
153153 // If the function exists but has the wrong type, return a bitcast to the
154154 // right type.
155 if (F->getType() != Context.getPointerTypeUnqual(Ty))
156 return ConstantExpr::getBitCast(F, Context.getPointerTypeUnqual(Ty));
155 if (F->getType() != PointerType::getUnqual(Ty))
156 return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
157157
158158 // Otherwise, we just found the existing function or a prototype.
159159 return F;
202202
203203 // Build the function type and chain to the other getOrInsertFunction...
204204 return getOrInsertFunction(Name,
205 Context.getFunctionType(RetTy, ArgTys, false),
205 FunctionType::get(RetTy, ArgTys, false),
206206 AttributeList);
207207 }
208208
220220
221221 // Build the function type and chain to the other getOrInsertFunction...
222222 return getOrInsertFunction(Name,
223 Context.getFunctionType(RetTy, ArgTys, false),
223 FunctionType::get(RetTy, ArgTys, false),
224224 AttrListPtr::get((AttributeWithIndex *)0, 0));
225225 }
226226
270270
271271 // If the variable exists but has the wrong type, return a bitcast to the
272272 // right type.
273 if (GV->getType() != Context.getPointerTypeUnqual(Ty))
274 return ConstantExpr::getBitCast(GV, Context.getPointerTypeUnqual(Ty));
273 if (GV->getType() != PointerType::getUnqual(Ty))
274 return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
275275
276276 // Otherwise, we just found the existing function or a prototype.
277277 return GV;
2020
2121 MVT MVT::getExtendedIntegerVT(unsigned BitWidth) {
2222 MVT VT;
23 VT.LLVMTy = getGlobalContext().getIntegerType(BitWidth);
23 VT.LLVMTy = IntegerType::get(BitWidth);
2424 assert(VT.isExtended() && "Type is not extended!");
2525 return VT;
2626 }
2727
2828 MVT MVT::getExtendedVectorVT(MVT VT, unsigned NumElements) {
2929 MVT ResultVT;
30 ResultVT.LLVMTy = getGlobalContext().getVectorType(
31 VT.getTypeForMVT(getGlobalContext()),
32 NumElements);
30 ResultVT.LLVMTy = VectorType::get(VT.getTypeForMVT(), NumElements);
3331 assert(ResultVT.isExtended() && "Type is not extended!");
3432 return ResultVT;
3533 }
132130 /// getTypeForMVT - This method returns an LLVM type corresponding to the
133131 /// specified MVT. For integer types, this returns an unsigned type. Note
134132 /// that this will abort for types that cannot be represented.
135 const Type *MVT::getTypeForMVT(LLVMContext &Context) const {
133 const Type *MVT::getTypeForMVT() const {
136134 switch (V) {
137135 default:
138136 assert(isExtended() && "Type is not extended!");
143141 case MVT::i16: return Type::Int16Ty;
144142 case MVT::i32: return Type::Int32Ty;
145143 case MVT::i64: return Type::Int64Ty;
146 case MVT::i128: return Context.getIntegerType(128);
144 case MVT::i128: return IntegerType::get(128);
147145 case MVT::f32: return Type::FloatTy;
148146 case MVT::f64: return Type::DoubleTy;
149147 case MVT::f80: return Type::X86_FP80Ty;
150148 case MVT::f128: return Type::FP128Ty;
151149 case MVT::ppcf128: return Type::PPC_FP128Ty;
152 case MVT::v2i8: return Context.getVectorType(Type::Int8Ty, 2);
153 case MVT::v4i8: return Context.getVectorType(Type::Int8Ty, 4);
154 case MVT::v8i8: return Context.getVectorType(Type::Int8Ty, 8);
155 case MVT::v16i8: return Context.getVectorType(Type::Int8Ty, 16);
156 case MVT::v32i8: return Context.getVectorType(Type::Int8Ty, 32);
157 case MVT::v2i16: return Context.getVectorType(Type::Int16Ty, 2);
158 case MVT::v4i16: return Context.getVectorType(Type::Int16Ty, 4);
159 case MVT::v8i16: return Context.getVectorType(Type::Int16Ty, 8);
160 case MVT::v16i16: return Context.getVectorType(Type::Int16Ty, 16);
161 case MVT::v2i32: return Context.getVectorType(Type::Int32Ty, 2);
162 case MVT::v4i32: return Context.getVectorType(Type::Int32Ty, 4);
163 case MVT::v8i32: return Context.getVectorType(Type::Int32Ty, 8);
164 case MVT::v1i64: return Context.getVectorType(Type::Int64Ty, 1);
165 case MVT::v2i64: return Context.getVectorType(Type::Int64Ty, 2);
166 case MVT::v4i64: return Context.getVectorType(Type::Int64Ty, 4);
167 case MVT::v2f32: return Context.getVectorType(Type::FloatTy, 2);
168 case MVT::v4f32: return Context.getVectorType(Type::FloatTy, 4);
169 case MVT::v8f32: return Context.getVectorType(Type::FloatTy, 8);
170 case MVT::v2f64: return Context.getVectorType(Type::DoubleTy, 2);
171 case MVT::v4f64: return Context.getVectorType(Type::DoubleTy, 4);
150 case MVT::v2i8: return VectorType::get(Type::Int8Ty, 2);
151 case MVT::v4i8: return VectorType::get(Type::Int8Ty, 4);
152 case MVT::v8i8: return VectorType::get(Type::Int8Ty, 8);
153 case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16);
154 case MVT::v32i8: return VectorType::get(Type::Int8Ty, 32);
155 case MVT::v2i16: return VectorType::get(Type::Int16Ty, 2);
156 case MVT::v4i16: return VectorType::get(Type::Int16Ty, 4);
157 case MVT::v8i16: return VectorType::get(Type::Int16Ty, 8);
158 case MVT::v16i16: return VectorType::get(Type::Int16Ty, 16);
159 case MVT::v2i32: return VectorType::get(Type::Int32Ty, 2);
160 case MVT::v4i32: return VectorType::get(Type::Int32Ty, 4);
161 case MVT::v8i32: return VectorType::get(Type::Int32Ty, 8);
162 case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1);
163 case MVT::v2i64: return VectorType::get(Type::Int64Ty, 2);
164 case MVT::v4i64: return VectorType::get(Type::Int64Ty, 4);
165 case MVT::v2f32: return VectorType::get(Type::FloatTy, 2);
166 case MVT::v4f32: return VectorType::get(Type::FloatTy, 4);
167 case MVT::v8f32: return VectorType::get(Type::FloatTy, 8);
168 case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2);
169 case MVT::v4f64: return VectorType::get(Type::DoubleTy, 4);
172170 }
173171 }
174172
14891489 bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
14901490 int VT, unsigned ArgNo, std::string &Suffix) {
14911491 const FunctionType *FTy = F->getFunctionType();
1492 LLVMContext &Context = FTy->getContext();
14931492
14941493 unsigned NumElts = 0;
14951494 const Type *EltTy = Ty;
16191618 "vector elements!", F);
16201619 return false;
16211620 }
1622 } else if (MVT((MVT::SimpleValueType)VT).getTypeForMVT(Context) != EltTy) {
1621 } else if (MVT((MVT::SimpleValueType)VT).getTypeForMVT() != EltTy) {
16231622 CheckFailed(IntrinsicParam(ArgNo, NumRets) + " is wrong!", F);
16241623 return false;
16251624 } else if (EltTy != Ty) {
180180 /// as a constant array.
181181 static Constant *GetTorInit(std::vector > &TorList) {
182182 assert(!TorList.empty() && "Don't create empty tor list!");
183 LLVMContext &Context = TorList[0].first->getContext();
184183 std::vector ArrayElts;
185184 for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
186185 std::vector Elts;
188187 Elts.push_back(TorList[i].first);
189188 ArrayElts.push_back(ConstantStruct::get(Elts));
190189 }
191 return ConstantArray::get(Context.getArrayType(ArrayElts[0]->getType(),
190 return ConstantArray::get(ArrayType::get(ArrayElts[0]->getType(),
192191 ArrayElts.size()),
193192 ArrayElts);
194193 }
700700 // Prototype: void *getPointerToNamedFunction(const char* Name)
701701 Constant *resolverFunc =
702702 Safe->getOrInsertFunction("getPointerToNamedFunction",
703 Context.getPointerTypeUnqual(Type::Int8Ty),
704 Context.getPointerTypeUnqual(Type::Int8Ty), (Type *)0);
703 PointerType::getUnqual(Type::Int8Ty),
704 PointerType::getUnqual(Type::Int8Ty), (Type *)0);
705705
706706 // Use the function we just added to get addresses of functions we need.
707707 for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) {
764764 // Cast the result from the resolver to correctly-typed function.
765765 CastInst *CastedResolver =
766766 new BitCastInst(Resolver,
767 Context.getPointerTypeUnqual(F->getFunctionType()),
767 PointerType::getUnqual(F->getFunctionType()),
768768 "resolverCast", LookupBB);
769769
770770 // Save the value in our cache.
3030
3131 Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) {
3232 std::vector params;
33 const FunctionType *FTy =
34 getGlobalContext().getFunctionType(G->getType()->getElementType(),
33 const FunctionType *FTy = FunctionType::get(G->getType()->getElementType(),
3534 params, false);
3635 Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M);
3736 BasicBlock *Entry = BasicBlock::Create("entry", F);
170170 st.push_back(TypeBuilder::get(Context));
171171 st.push_back(TypeBuilder::get(Context));
172172 st.push_back(TypeBuilder::get(Context));
173 static const StructType *const result = Context.getStructType(st);
173 static const StructType *const result = StructType::get(st);
174174 return result;
175175 }
176176
193193 st.push_back(TypeBuilder, cross>::get(Context));
194194 st.push_back(TypeBuilder*, cross>::get(Context));
195195 st.push_back(TypeBuilder*[], cross>::get(Context));
196 static const StructType *const result = Context.getStructType(st);
196 static const StructType *const result = StructType::get(st);
197197 return result;
198198 }
199199
162162 O << Size << ", ";
163163 else
164164 O << "\n" << IndentStr << " State.getTarget().getTargetData()"
165 "->getTypeAllocSize(LocVT.getTypeForMVT(State.getContext())), ";
165 "->getTypeAllocSize(LocVT.getTypeForMVT()), ";
166166 if (Align)
167167 O << Align;
168168 else
169169 O << "\n" << IndentStr << " State.getTarget().getTargetData()"
170 "->getABITypeAlignment(LocVT.getTypeForMVT(State.getContext()))";
170 "->getABITypeAlignment(LocVT.getTypeForMVT())";
171171 O << ");\n" << IndentStr
172172 << "State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset"
173173 << Counter << ", LocVT, LocInfo));\n";