llvm.org GIT mirror llvm / 5fdd6c8
Second attempt at de-constifying LLVM Types in FunctionType::get(), StructType::get() and TargetData::getIntPtrType(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134982 91177308-0d34-0410-b5e6-96231b3b80d8 Jay Foad 9 years ago
36 changed file(s) with 131 addition(s) and 156 deletion(s). Raw diff Collapse all Expand all
101101 /// FunctionType::get - This static method is the primary way of constructing
102102 /// a FunctionType.
103103 ///
104 static FunctionType *get(const Type *Result,
105 ArrayRef Params, bool isVarArg);
106104 static FunctionType *get(const Type *Result,
107105 ArrayRef Params, bool isVarArg);
108106
205203
206204 /// StructType::get - This static method is the primary way to create a
207205 /// StructType.
208 ///
209 /// FIXME: Remove the 'const Type*' version of this when types are pervasively
210 /// de-constified.
211 static StructType *get(LLVMContext &Context, ArrayRef Elements,
212 bool isPacked = false);
213206 static StructType *get(LLVMContext &Context, ArrayRef Elements,
214207 bool isPacked = false);
215208
221214 /// structure types by specifying the elements as arguments. Note that this
222215 /// method always returns a non-packed struct, and requires at least one
223216 /// element type.
224 static StructType *get(const Type *elt1, ...) END_WITH_NULL;
217 static StructType *get(Type *elt1, ...) END_WITH_NULL;
225218
226219 bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; }
227220
4343
4444 /// Intrinsic::getName(ID) - Return the LLVM name for an intrinsic, such as
4545 /// "llvm.ppc.altivec.lvx".
46 std::string getName(ID id, const Type **Tys = 0, unsigned numTys = 0);
46 std::string getName(ID id, Type **Tys = 0, unsigned numTys = 0);
4747
4848 /// Intrinsic::getType(ID) - Return the function type for an intrinsic.
4949 ///
5050 const FunctionType *getType(LLVMContext &Context, ID id,
51 const Type **Tys = 0, unsigned numTys = 0);
51 Type **Tys = 0, unsigned numTys = 0);
5252
5353 /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be
5454 /// overloaded.
6666 /// overloaded intrinsic, Tys should point to an array of numTys pointers to
6767 /// Type, and must provide exactly one type for each overloaded type in the
6868 /// intrinsic.
69 Function *getDeclaration(Module *M, ID id, const Type **Tys = 0,
69 Function *getDeclaration(Module *M, ID id, Type **Tys = 0,
7070 unsigned numTys = 0);
7171
7272 /// Map a GCC builtin name to an intrinsic ID.
5050 /// namespace llvm {
5151 /// template class TypeBuilder {
5252 /// public:
53 /// static const StructType *get(LLVMContext &Context) {
53 /// static StructType *get(LLVMContext &Context) {
5454 /// // If you cache this result, be sure to cache it separately
5555 /// // for each LLVMContext.
5656 /// return StructType::get(
103103 // Pointers
104104 template class TypeBuilder {
105105 public:
106 static const PointerType *get(LLVMContext &Context) {
106 static PointerType *get(LLVMContext &Context) {
107107 return PointerType::getUnqual(TypeBuilder::get(Context));
108108 }
109109 };
114114 // Arrays
115115 template class TypeBuilder {
116116 public:
117 static const ArrayType *get(LLVMContext &Context) {
117 static ArrayType *get(LLVMContext &Context) {
118118 return ArrayType::get(TypeBuilder::get(Context), N);
119119 }
120120 };
121121 /// LLVM uses an array of length 0 to represent an unknown-length array.
122122 template class TypeBuilder {
123123 public:
124 static const ArrayType *get(LLVMContext &Context) {
124 static ArrayType *get(LLVMContext &Context) {
125125 return ArrayType::get(TypeBuilder::get(Context), 0);
126126 }
127127 };
151151 #define DEFINE_INTEGRAL_TYPEBUILDER(T) \
152152 template<> class TypeBuilder { \
153153 public: \
154 static const IntegerType *get(LLVMContext &Context) { \
154 static IntegerType *get(LLVMContext &Context) { \
155155 return IntegerType::get(Context, sizeof(T) * CHAR_BIT); \
156156 } \
157157 }; \
180180 template
181181 class TypeBuilder, cross> {
182182 public:
183 static const IntegerType *get(LLVMContext &C) {
183 static IntegerType *get(LLVMContext &C) {
184184 return IntegerType::get(C, num_bits);
185185 }
186186 };
187187
188188 template<> class TypeBuilder {
189189 public:
190 static const Type *get(LLVMContext& C) {
190 static Type *get(LLVMContext& C) {
191191 return Type::getFloatTy(C);
192192 }
193193 };
195195
196196 template<> class TypeBuilder {
197197 public:
198 static const Type *get(LLVMContext& C) {
198 static Type *get(LLVMContext& C) {
199199 return Type::getDoubleTy(C);
200200 }
201201 };
203203
204204 template class TypeBuilder {
205205 public:
206 static const Type *get(LLVMContext& C) { return Type::getFloatTy(C); }
206 static Type *get(LLVMContext& C) { return Type::getFloatTy(C); }
207207 };
208208 template class TypeBuilder {
209209 public:
210 static const Type *get(LLVMContext& C) { return Type::getDoubleTy(C); }
210 static Type *get(LLVMContext& C) { return Type::getDoubleTy(C); }
211211 };
212212 template class TypeBuilder {
213213 public:
214 static const Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); }
214 static Type *get(LLVMContext& C) { return Type::getX86_FP80Ty(C); }
215215 };
216216 template class TypeBuilder {
217217 public:
218 static const Type *get(LLVMContext& C) { return Type::getFP128Ty(C); }
218 static Type *get(LLVMContext& C) { return Type::getFP128Ty(C); }
219219 };
220220 template class TypeBuilder {
221221 public:
222 static const Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); }
222 static Type *get(LLVMContext& C) { return Type::getPPC_FP128Ty(C); }
223223 };
224224 template class TypeBuilder {
225225 public:
226 static const Type *get(LLVMContext& C) { return Type::getX86_MMXTy(C); }
226 static Type *get(LLVMContext& C) { return Type::getX86_MMXTy(C); }
227227 };
228228
229229 template class TypeBuilder {
230230 public:
231 static const Type *get(LLVMContext &C) {
231 static Type *get(LLVMContext &C) {
232232 return Type::getVoidTy(C);
233233 }
234234 };
246246
247247 template class TypeBuilder {
248248 public:
249 static const FunctionType *get(LLVMContext &Context) {
249 static FunctionType *get(LLVMContext &Context) {
250250 return FunctionType::get(TypeBuilder::get(Context), false);
251251 }
252252 };
253253 template class TypeBuilder {
254254 public:
255 static const FunctionType *get(LLVMContext &Context) {
256 std::vector params;
255 static FunctionType *get(LLVMContext &Context) {
256 std::vector params;
257257 params.reserve(1);
258258 params.push_back(TypeBuilder::get(Context));
259259 return FunctionType::get(TypeBuilder::get(Context),
263263 template
264264 class TypeBuilder {
265265 public:
266 static const FunctionType *get(LLVMContext &Context) {
267 std::vector params;
266 static FunctionType *get(LLVMContext &Context) {
267 std::vector params;
268268 params.reserve(2);
269269 params.push_back(TypeBuilder::get(Context));
270270 params.push_back(TypeBuilder::get(Context));
275275 template
276276 class TypeBuilder {
277277 public:
278 static const FunctionType *get(LLVMContext &Context) {
279 std::vector params;
278 static FunctionType *get(LLVMContext &Context) {
279 std::vector params;
280280 params.reserve(3);
281281 params.push_back(TypeBuilder::get(Context));
282282 params.push_back(TypeBuilder::get(Context));
290290 bool cross>
291291 class TypeBuilder {
292292 public:
293 static const FunctionType *get(LLVMContext &Context) {
294 std::vector params;
293 static FunctionType *get(LLVMContext &Context) {
294 std::vector params;
295295 params.reserve(4);
296296 params.push_back(TypeBuilder::get(Context));
297297 params.push_back(TypeBuilder::get(Context));
306306 typename A5, bool cross>
307307 class TypeBuilder {
308308 public:
309 static const FunctionType *get(LLVMContext &Context) {
310 std::vector params;
309 static FunctionType *get(LLVMContext &Context) {
310 std::vector params;
311311 params.reserve(5);
312312 params.push_back(TypeBuilder::get(Context));
313313 params.push_back(TypeBuilder::get(Context));
321321
322322 template class TypeBuilder {
323323 public:
324 static const FunctionType *get(LLVMContext &Context) {
324 static FunctionType *get(LLVMContext &Context) {
325325 return FunctionType::get(TypeBuilder::get(Context), true);
326326 }
327327 };
328328 template
329329 class TypeBuilder {
330330 public:
331 static const FunctionType *get(LLVMContext &Context) {
332 std::vector params;
331 static FunctionType *get(LLVMContext &Context) {
332 std::vector params;
333333 params.reserve(1);
334334 params.push_back(TypeBuilder::get(Context));
335335 return FunctionType::get(TypeBuilder::get(Context), params, true);
338338 template
339339 class TypeBuilder {
340340 public:
341 static const FunctionType *get(LLVMContext &Context) {
342 std::vector params;
341 static FunctionType *get(LLVMContext &Context) {
342 std::vector params;
343343 params.reserve(2);
344344 params.push_back(TypeBuilder::get(Context));
345345 params.push_back(TypeBuilder::get(Context));
350350 template
351351 class TypeBuilder {
352352 public:
353 static const FunctionType *get(LLVMContext &Context) {
354 std::vector params;
353 static FunctionType *get(LLVMContext &Context) {
354 std::vector params;
355355 params.reserve(3);
356356 params.push_back(TypeBuilder::get(Context));
357357 params.push_back(TypeBuilder::get(Context));
365365 bool cross>
366366 class TypeBuilder {
367367 public:
368 static const FunctionType *get(LLVMContext &Context) {
369 std::vector params;
368 static FunctionType *get(LLVMContext &Context) {
369 std::vector params;
370370 params.reserve(4);
371371 params.push_back(TypeBuilder::get(Context));
372372 params.push_back(TypeBuilder::get(Context));
381381 typename A5, bool cross>
382382 class TypeBuilder {
383383 public:
384 static const FunctionType *get(LLVMContext &Context) {
385 std::vector params;
384 static FunctionType *get(LLVMContext &Context) {
385 std::vector params;
386386 params.reserve(5);
387387 params.push_back(TypeBuilder::get(Context));
388388 params.push_back(TypeBuilder::get(Context));
14411441 "argument attributes invalid in function type");
14421442 }
14431443
1444 SmallVector<const Type*, 16> ArgListTy;
1444 SmallVector<Type*, 16> ArgListTy;
14451445 for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
14461446 ArgListTy.push_back(ArgList[i].Ty);
14471447
26542654
26552655 // Okay, if we got here, the function is syntactically valid. Convert types
26562656 // and do semantic checks.
2657 std::vector<const Type*> ParamTypeList;
2657 std::vector<Type*> ParamTypeList;
26582658 SmallVector Attrs;
26592659
26602660 if (RetAttrs != Attribute::None)
31703170 if (!(PFTy = dyn_cast(RetType)) ||
31713171 !(Ty = dyn_cast(PFTy->getElementType()))) {
31723172 // Pull out the types of all of the arguments...
3173 std::vector<const Type*> ParamTypes;
3173 std::vector<Type*> ParamTypes;
31743174 for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
31753175 ParamTypes.push_back(ArgList[i].V->getType());
31763176
35073507 if (!(PFTy = dyn_cast(RetType)) ||
35083508 !(Ty = dyn_cast(PFTy->getElementType()))) {
35093509 // Pull out the types of all of the arguments...
3510 std::vector<const Type*> ParamTypes;
3510 std::vector<Type*> ParamTypes;
35113511 for (unsigned i = 0, e = ArgList.size(); i != e; ++i)
35123512 ParamTypes.push_back(ArgList[i].V->getType());
35133513
581581 // FUNCTION: [vararg, attrid, retty, paramty x N]
582582 if (Record.size() < 3)
583583 return Error("Invalid FUNCTION type record");
584 std::vector<const Type*> ArgTys;
584 std::vector<Type*> ArgTys;
585585 for (unsigned i = 3, e = Record.size(); i != e; ++i) {
586586 if (Type *T = getTypeByID(Record[i]))
587587 ArgTys.push_back(T);
837837 // FUNCTION: [vararg, attrid, retty, paramty x N]
838838 if (Record.size() < 3)
839839 return Error("Invalid FUNCTION type record");
840 std::vector<const Type*> ArgTys;
840 std::vector<Type*> ArgTys;
841841 for (unsigned i = 3, e = Record.size(); i != e; ++i) {
842842 if (Type *Elt = getTypeByIDOrNull(Record[i]))
843843 ArgTys.push_back(Elt);
496496 // Find the rewind function if we didn't already.
497497 if (!RewindFunction) {
498498 LLVMContext &Ctx = ResumeInsts[0]->getContext();
499 std::vector
500 Params(1, Type::getInt8PtrTy(Ctx));
501499 FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx),
502 Params, false);
500 Type::getInt8PtrTy(Ctx), false);
503501 const char *RewindName = TLI->getLibcallName(RTLIB::UNWIND_RESUME);
504502 RewindFunction = F->getParent()->getOrInsertFunction(RewindName, FTy);
505503 }
2828 ArgIt ArgBegin, ArgIt ArgEnd,
2929 const Type *RetTy) {
3030 // Insert a correctly-typed definition now.
31 std::vector<const Type *> ParamTys;
31 std::vector<Type *> ParamTys;
3232 for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
3333 ParamTys.push_back(I->getType());
3434 M.getOrInsertFunction(Name, FunctionType::get(RetTy, ParamTys, false));
6868 // program already contains a function with this name.
6969 Module *M = CI->getParent()->getParent()->getParent();
7070 // Get or insert the definition now.
71 std::vector<const Type *> ParamTys;
71 std::vector<Type *> ParamTys;
7272 for (ArgIt I = ArgBegin; I != ArgEnd; ++I)
7373 ParamTys.push_back((*I)->getType());
7474 Constant* FCache = M->getOrInsertFunction(NewFn,
552552 !CI->getType()->isIntegerTy())
553553 return false;
554554
555 const IntegerType *Ty = dyn_cast(CI->getType());
555 IntegerType *Ty = dyn_cast(CI->getType());
556556 if (!Ty)
557557 return false;
558558
559559 // Okay, we can do this xform, do so now.
560 const Type *Tys[] = { Ty };
560 Type *Tys[] = { Ty };
561561 Module *M = CI->getParent()->getParent()->getParent();
562562 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
563563
8686 bool SjLjEHPass::doInitialization(Module &M) {
8787 // Build the function context structure.
8888 // builtin_setjmp uses a five word jbuf
89 const Type *VoidPtrTy =
90 Type::getInt8PtrTy(M.getContext());
91 const Type *Int32Ty = Type::getInt32Ty(M.getContext());
89 Type *VoidPtrTy = Type::getInt8PtrTy(M.getContext());
90 Type *Int32Ty = Type::getInt32Ty(M.getContext());
9291 FunctionContextTy =
9392 StructType::get(VoidPtrTy, // __prev
9493 Int32Ty, // call_site
127127 for (size_t i = 0, e = Globals.size(); i != e; ) {
128128 size_t j = 0;
129129 uint64_t MergedSize = 0;
130 std::vector<const Type*> Tys;
130 std::vector<Type*> Tys;
131131 std::vector Inits;
132132 for (j = i; j != e; ++j) {
133 const Type *Ty = Globals[j]->getType()->getElementType();
133 Type *Ty = Globals[j]->getType()->getElementType();
134134 MergedSize += TD->getTypeAllocSize(Ty);
135135 if (MergedSize > MaxOffset) {
136136 break;
8282
8383 static const FunctionType *getType(LLVMContext &Context, unsigned id) {
8484 const Type *ResultTy = NULL;
85 std::vector<const Type*> ArgTys;
85 std::vector<Type*> ArgTys;
8686 bool IsVarArg = false;
8787
8888 #define GET_INTRINSIC_GENERATOR
9191
9292 static const FunctionType *getType(LLVMContext &Context, unsigned id) {
9393 const Type *ResultTy = NULL;
94 std::vector<const Type*> ArgTys;
94 std::vector<Type*> ArgTys;
9595 bool IsVarArg = false;
9696
9797 #define GET_INTRINSIC_GENERATOR
492492 // Start by computing a new prototype for the function, which is the same as
493493 // the old function, but has modified arguments.
494494 const FunctionType *FTy = F->getFunctionType();
495 std::vector<const Type*> Params;
495 std::vector<Type*> Params;
496496
497497 typedef std::set ScalarizeTable;
498498
207207 // the old function, but doesn't have isVarArg set.
208208 const FunctionType *FTy = Fn.getFunctionType();
209209
210 std::vector<const Type*> Params(FTy->param_begin(), FTy->param_end());
210 std::vector<Type*> Params(FTy->param_begin(), FTy->param_end());
211211 FunctionType *NFTy = FunctionType::get(FTy->getReturnType(),
212212 Params, false);
213213 unsigned NumArgs = Params.size();
646646 // Start by computing a new prototype for the function, which is the same as
647647 // the old function, but has fewer arguments and a different return type.
648648 const FunctionType *FTy = F->getFunctionType();
649 std::vector<const Type*> Params;
649 std::vector<Type*> Params;
650650
651651 // Set up to build a new list of parameter attributes.
652652 SmallVector AttributesVec;
658658
659659 // Find out the new return value.
660660
661 const Type *RetTy = FTy->getReturnType();
661 Type *RetTy = FTy->getReturnType();
662662 const Type *NRetTy = NULL;
663663 unsigned RetCount = NumRetVals(F);
664664
665665 // -1 means unused, other numbers are the new index
666666 SmallVector NewRetIdxs(RetCount, -1);
667 std::vector<const Type*> RetTypes;
667 std::vector<Type*> RetTypes;
668668 if (RetTy->isVoidTy()) {
669669 NRetTy = RetTy;
670670 } else {
13991399 /// MatchBSwap - Given an OR instruction, check to see if this is a bswap idiom.
14001400 /// If so, insert the new bswap intrinsic and return it.
14011401 Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) {
1402 const IntegerType *ITy = dyn_cast(I.getType());
1402 IntegerType *ITy = dyn_cast(I.getType());
14031403 if (!ITy || ITy->getBitWidth() % 16 ||
14041404 // ByteMask only allows up to 32-byte values.
14051405 ITy->getBitWidth() > 32*8)
14231423 for (unsigned i = 1, e = ByteValues.size(); i != e; ++i)
14241424 if (ByteValues[i] != V)
14251425 return 0;
1426 const Type *Tys[] = { ITy };
1426 Type *Tys[] = { ITy };
14271427 Module *M = I.getParent()->getParent()->getParent();
14281428 Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
14291429 return CallInst::Create(F, V);
216216 if (GVSrc->isConstant()) {
217217 Module *M = CI.getParent()->getParent()->getParent();
218218 Intrinsic::ID MemCpyID = Intrinsic::memcpy;
219 const Type *Tys[3] = { CI.getArgOperand(0)->getType(),
220 CI.getArgOperand(1)->getType(),
221 CI.getArgOperand(2)->getType() };
219 Type *Tys[3] = { CI.getArgOperand(0)->getType(),
220 CI.getArgOperand(1)->getType(),
221 CI.getArgOperand(2)->getType() };
222222 CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys, 3));
223223 Changed = true;
224224 }
11861186 const AttrListPtr &NestAttrs = NestF->getAttributes();
11871187 if (!NestAttrs.isEmpty()) {
11881188 unsigned NestIdx = 1;
1189 const Type *NestTy = 0;
1189 Type *NestTy = 0;
11901190 Attributes NestAttr = Attribute::None;
11911191
11921192 // Look for a parameter marked with the 'nest' attribute.
12481248 // Handle this by synthesizing a new function type, equal to FTy
12491249 // with the chain parameter inserted.
12501250
1251 std::vector<const Type*> NewTypes;
1251 std::vector<Type*> NewTypes;
12521252 NewTypes.reserve(FTy->getNumParams()+1);
12531253
12541254 // Insert the chain's type into the list of parameter types, which may
16821682 // result and the overflow bit.
16831683 Module *M = I.getParent()->getParent()->getParent();
16841684
1685 const Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth);
1685 Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth);
16861686 Value *F = Intrinsic::getDeclaration(M, Intrinsic::sadd_with_overflow,
16871687 &NewType, 1);
16881688
17241724 Builder->SetInsertPoint(OrigAdd);
17251725
17261726 Module *M = I.getParent()->getParent()->getParent();
1727 const Type *Ty = LHS->getType();
1727 Type *Ty = LHS->getType();
17281728 Value *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, &Ty,1);
17291729 CallInst *Call = Builder->CreateCall2(F, LHS, RHS, "uadd");
17301730 Value *Add = Builder->CreateExtractValue(Call, 0);
571571 }
572572
573573 Constant *GCOVProfiler::getStartFileFunc() {
574 const Type *Args[] = { Type::getInt8PtrTy(*Ctx) };
575574 const FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx),
576 Args, false);
575 Type::getInt8PtrTy(*Ctx), false);
577576 return M->getOrInsertFunction("llvm_gcda_start_file", FTy);
578577 }
579578
580579 Constant *GCOVProfiler::getIncrementIndirectCounterFunc() {
581 const Type *Args[] = {
580 Type *Args[] = {
582581 Type::getInt32PtrTy(*Ctx), // uint32_t *predecessor
583582 Type::getInt64PtrTy(*Ctx)->getPointerTo(), // uint64_t **state_table_row
584583 };
588587 }
589588
590589 Constant *GCOVProfiler::getEmitFunctionFunc() {
591 const Type *Args[2] = {
590 Type *Args[2] = {
592591 Type::getInt32Ty(*Ctx), // uint32_t ident
593592 Type::getInt8PtrTy(*Ctx), // const char *function_name
594593 };
598597 }
599598
600599 Constant *GCOVProfiler::getEmitArcsFunc() {
601 const Type *Args[] = {
600 Type *Args[] = {
602601 Type::getInt32Ty(*Ctx), // uint32_t num_counters
603602 Type::getInt64PtrTy(*Ctx), // uint64_t *counters
604603 };
133133 void llvm::InsertProfilingShutdownCall(Function *Callee, Module *Mod) {
134134 // llvm.global_dtors is an array of type { i32, void ()* }. Prepare those
135135 // types.
136 const Type *GlobalDtorElems[2] = {
136 Type *GlobalDtorElems[2] = {
137137 Type::getInt32Ty(Mod->getContext()),
138138 FunctionType::get(Type::getVoidTy(Mod->getContext()), false)->getPointerTo()
139139 };
839839
840840 // If not, then we know we can transform this.
841841 Module *Mod = M->getParent()->getParent()->getParent();
842 const Type *ArgTys[3] = { M->getRawDest()->getType(),
843 M->getRawSource()->getType(),
844 M->getLength()->getType() };
842 Type *ArgTys[3] = { M->getRawDest()->getType(),
843 M->getRawSource()->getType(),
844 M->getLength()->getType() };
845845 M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy,
846846 ArgTys, 3));
847847
14971497 Constant *ObjCARCOpt::getRetainRVCallee(Module *M) {
14981498 if (!RetainRVCallee) {
14991499 LLVMContext &C = M->getContext();
1500 const Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
1501 std::vector Params;
1500 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
1501 std::vector Params;
15021502 Params.push_back(I8X);
15031503 const FunctionType *FTy =
15041504 FunctionType::get(I8X, Params, /*isVarArg=*/false);
15141514 Constant *ObjCARCOpt::getAutoreleaseRVCallee(Module *M) {
15151515 if (!AutoreleaseRVCallee) {
15161516 LLVMContext &C = M->getContext();
1517 const Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
1518 std::vector Params;
1517 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
1518 std::vector Params;
15191519 Params.push_back(I8X);
15201520 const FunctionType *FTy =
15211521 FunctionType::get(I8X, Params, /*isVarArg=*/false);
15311531 Constant *ObjCARCOpt::getReleaseCallee(Module *M) {
15321532 if (!ReleaseCallee) {
15331533 LLVMContext &C = M->getContext();
1534 std::vector<const Type *> Params;
1534 std::vector<Type *> Params;
15351535 Params.push_back(PointerType::getUnqual(Type::getInt8Ty(C)));
15361536 AttrListPtr Attributes;
15371537 Attributes.addAttr(~0u, Attribute::NoUnwind);
15471547 Constant *ObjCARCOpt::getRetainCallee(Module *M) {
15481548 if (!RetainCallee) {
15491549 LLVMContext &C = M->getContext();
1550 std::vector<const Type *> Params;
1550 std::vector<Type *> Params;
15511551 Params.push_back(PointerType::getUnqual(Type::getInt8Ty(C)));
15521552 AttrListPtr Attributes;
15531553 Attributes.addAttr(~0u, Attribute::NoUnwind);
15631563 Constant *ObjCARCOpt::getAutoreleaseCallee(Module *M) {
15641564 if (!AutoreleaseCallee) {
15651565 LLVMContext &C = M->getContext();
1566 std::vector<const Type *> Params;
1566 std::vector<Type *> Params;
15671567 Params.push_back(PointerType::getUnqual(Type::getInt8Ty(C)));
15681568 AttrListPtr Attributes;
15691569 Attributes.addAttr(~0u, Attribute::NoUnwind);
32683268 Constant *ObjCARCContract::getStoreStrongCallee(Module *M) {
32693269 if (!StoreStrongCallee) {
32703270 LLVMContext &C = M->getContext();
3271 const Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
3272 const Type *I8XX = PointerType::getUnqual(I8X);
3273 std::vector Params;
3271 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
3272 Type *I8XX = PointerType::getUnqual(I8X);
3273 std::vector Params;
32743274 Params.push_back(I8XX);
32753275 Params.push_back(I8X);
32763276
32903290 Constant *ObjCARCContract::getRetainAutoreleaseCallee(Module *M) {
32913291 if (!RetainAutoreleaseCallee) {
32923292 LLVMContext &C = M->getContext();
3293 const Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
3294 std::vector Params;
3293 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
3294 std::vector Params;
32953295 Params.push_back(I8X);
32963296 const FunctionType *FTy =
32973297 FunctionType::get(I8X, Params, /*isVarArg=*/false);
33063306 Constant *ObjCARCContract::getRetainAutoreleaseRVCallee(Module *M) {
33073307 if (!RetainAutoreleaseRVCallee) {
33083308 LLVMContext &C = M->getContext();
3309 const Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
3310 std::vector Params;
3309 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
3310 std::vector Params;
33113311 Params.push_back(I8X);
33123312 const FunctionType *FTy =
33133313 FunctionType::get(I8X, Params, /*isVarArg=*/false);
991991 }
992992
993993 // ffs(x) -> x != 0 ? (i32)llvm.cttz(x)+1 : 0
994 const Type *ArgType = Op->getType();
994 Type *ArgType = Op->getType();
995995 Value *F = Intrinsic::getDeclaration(Callee->getParent(),
996996 Intrinsic::cttz, &ArgType, 1);
997997 Value *V = B.CreateCall(F, Op, "cttz");
139139 Function *llvm::CloneFunction(const Function *F, ValueToValueMapTy &VMap,
140140 bool ModuleLevelChanges,
141141 ClonedCodeInfo *CodeInfo) {
142 std::vector<const Type*> ArgTypes;
142 std::vector<Type*> ArgTypes;
143143
144144 // The user might be deleting arguments to the function by specifying them in
145145 // the VMap. If so, we need to not add the arguments to the arg ty vector
257257 default: RetTy = Type::getInt16Ty(header->getContext()); break;
258258 }
259259
260 std::vector<const Type*> paramTy;
260 std::vector<Type*> paramTy;
261261
262262 // Add the types of the input values to the function's argument list
263263 for (Values::const_iterator i = inputs.begin(),
278278 }
279279
280280 DEBUG(dbgs() << "Function type: " << *RetTy << " f(");
281 for (std::vector<const Type*>::iterator i = paramTy.begin(),
281 for (std::vector<Type*>::iterator i = paramTy.begin(),
282282 e = paramTy.end(); i != e; ++i)
283283 DEBUG(dbgs() << **i << ", ");
284284 DEBUG(dbgs() << ")\n");
402402
403403 AllocaInst *Struct = 0;
404404 if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
405 std::vector<const Type*> ArgTypes;
405 std::vector<Type*> ArgTypes;
406406 for (Values::iterator v = StructValues.begin(),
407407 ve = StructValues.end(); v != ve; ++v)
408408 ArgTypes.push_back((*v)->getType());
662662
663663 LLVMContext &Context = Arg->getContext();
664664
665 const Type *VoidPtrTy = Type::getInt8PtrTy(Context);
665 Type *VoidPtrTy = Type::getInt8PtrTy(Context);
666666
667667 // Create the alloca. If we have TargetData, use nice alignment.
668668 unsigned Align = 1;
679679 Value *NewAlloca = new AllocaInst(AggTy, 0, Align, Arg->getName(),
680680 &*Caller->begin()->begin());
681681 // Emit a memcpy.
682 const Type *Tys[3] = {VoidPtrTy, VoidPtrTy, Type::getInt64Ty(Context)};
682 Type *Tys[3] = {VoidPtrTy, VoidPtrTy, Type::getInt64Ty(Context)};
683683 Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
684684 Intrinsic::memcpy,
685685 Tys, 3);
618618 StructType *ConstantStruct::getTypeForElements(LLVMContext &Context,
619619 ArrayRef V,
620620 bool Packed) {
621 SmallVector<const Type*, 16> EltTypes;
621 SmallVector<Type*, 16> EltTypes;
622622 for (unsigned i = 0, e = V.size(); i != e; ++i)
623623 EltTypes.push_back(V[i]->getType());
624624
259259 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
260260 LLVMTypeRef *ParamTypes, unsigned ParamCount,
261261 LLVMBool IsVarArg) {
262 std::vector<const Type*> Tys;
262 std::vector<Type*> Tys;
263263 for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I)
264264 Tys.push_back(unwrap(*I));
265265
289289
290290 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
291291 unsigned ElementCount, LLVMBool Packed) {
292 std::vector<const Type*> Tys;
292 std::vector<Type*> Tys;
293293 for (LLVMTypeRef *I = ElementTypes,
294294 *E = ElementTypes + ElementCount; I != E; ++I)
295295 Tys.push_back(unwrap(*I));
332332 return 0;
333333 }
334334
335 std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) {
335 std::string Intrinsic::getName(ID id, Type **Tys, unsigned numTys) {
336336 assert(id < num_intrinsics && "Invalid intrinsic ID!");
337337 static const char * const Table[] = {
338338 "not_intrinsic",
355355 }
356356
357357 const FunctionType *Intrinsic::getType(LLVMContext &Context,
358 ID id, const Type **Tys,
358 ID id, Type **Tys,
359359 unsigned numTys) {
360360 const Type *ResultTy = NULL;
361 std::vector<const Type*> ArgTys;
361 std::vector<Type*> ArgTys;
362362 bool IsVarArg = false;
363363
364364 #define GET_INTRINSIC_GENERATOR
383383 #include "llvm/Intrinsics.gen"
384384 #undef GET_INTRINSIC_ATTRIBUTES
385385
386 Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
386 Function *Intrinsic::getDeclaration(Module *M, ID id, Type **Tys,
387387 unsigned numTys) {
388388 // There can never be multiple globals with the same name of different types,
389389 // because intrinsics must be a specific type.
6464 bool isVolatile, MDNode *TBAATag) {
6565 Ptr = getCastedInt8PtrValue(Ptr);
6666 Value *Ops[] = { Ptr, Val, Size, getInt32(Align), getInt1(isVolatile) };
67 const Type *Tys[] = { Ptr->getType(), Size->getType() };
67 Type *Tys[] = { Ptr->getType(), Size->getType() };
6868 Module *M = BB->getParent()->getParent();
6969 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 2);
7070
8484 Src = getCastedInt8PtrValue(Src);
8585
8686 Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
87 const Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
87 Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
8888 Module *M = BB->getParent()->getParent();
8989 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys, 3);
9090
104104 Src = getCastedInt8PtrValue(Src);
105105
106106 Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
107 const Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
107 Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
108108 Module *M = BB->getParent()->getParent();
109109 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys, 3);
110110
215215 va_start(Args, RetTy);
216216
217217 // Build the list of argument types...
218 std::vector ArgTys;
219 while (const Type *ArgTy = va_arg(Args, const Type*))
218 std::vector ArgTys;
219 while (Type *ArgTy = va_arg(Args, Type*))
220220 ArgTys.push_back(ArgTy);
221221
222222 va_end(Args);
233233 va_start(Args, RetTy);
234234
235235 // Build the list of argument types...
236 std::vector ArgTys;
237 while (const Type *ArgTy = va_arg(Args, const Type*))
236 std::vector ArgTys;
237 while (Type *ArgTy = va_arg(Args, Type*))
238238 ArgTys.push_back(ArgTy);
239239
240240 va_end(Args);
324324 NumContainedTys = Params.size() + 1; // + 1 for result type
325325 }
326326
327 // FIXME: Remove this version.
328 FunctionType *FunctionType::get(const Type *ReturnType,
329 ArrayRef Params, bool isVarArg) {
330 return get(ReturnType, ArrayRef(const_cast(Params.data()),
331 Params.size()), isVarArg);
332 }
333
334327 // FunctionType::get - The factory function for the FunctionType class.
335328 FunctionType *FunctionType::get(const Type *ReturnType,
336329 ArrayRef Params, bool isVarArg) {
356349
357350
358351 FunctionType *FunctionType::get(const Type *Result, bool isVarArg) {
359 return get(Result, ArrayRef<const Type *>(), isVarArg);
352 return get(Result, ArrayRef<Type *>(), isVarArg);
360353 }
361354
362355
464457 //===----------------------------------------------------------------------===//
465458 // StructType Helper functions.
466459
467 // FIXME: Remove this version.
468 StructType *StructType::get(LLVMContext &Context, ArrayRefElements,
469 bool isPacked) {
470 return get(Context, ArrayRef(const_cast(Elements.data()),
471 Elements.size()), isPacked);
472 }
473
474460 StructType *StructType::get(LLVMContext &Context, bool isPacked) {
475 return get(Context, llvm::ArrayRef(), isPacked);
476 }
477
478 StructType *StructType::get(const Type *type, ...) {
461 return get(Context, llvm::ArrayRef(), isPacked);
462 }
463
464 StructType *StructType::get(Type *type, ...) {
479465 assert(type != 0 && "Cannot create a struct type with no elements with this");
480466 LLVMContext &Ctx = type->getContext();
481467 va_list ap;
482 SmallVector<const llvm::Type*, 8> StructFields;
468 SmallVector<llvm::Type*, 8> StructFields;
483469 va_start(ap, type);
484470 while (type) {
485471 StructFields.push_back(type);
172172 static Constant *GetTorInit(std::vector > &TorList) {
173173 assert(!TorList.empty() && "Don't create empty tor list!");
174174 std::vector ArrayElts;
175 const Type *Int32Ty = Type::getInt32Ty(TorList[0].first->getContext());
175 Type *Int32Ty = Type::getInt32Ty(TorList[0].first->getContext());
176176
177177 const StructType *STy =
178178 StructType::get(Int32Ty, TorList[0].first->getType(), NULL);
2222 Module M("world", Context);
2323
2424 const FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context),
25 std::vector<const Type *>(), false);
25 std::vector<Type *>(), false);
2626 Function *F = cast(M.getOrInsertFunction("f", FTy));
2727 BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
2828 ReturnInst::Create(Context, 0, BB);
2020 namespace {
2121
2222 Function *makeFakeFunction() {
23 std::vector<const Type*> params;
23 std::vector<Type*> params;
2424 const FunctionType *FTy =
2525 FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false);
2626 return Function::Create(FTy, GlobalValue::ExternalLinkage);
3636 namespace {
3737
3838 Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) {
39 std::vector<const Type*> params;
39 std::vector<Type*> params;
4040 const FunctionType *FTy = FunctionType::get(G->getType()->getElementType(),
4141 params, false);
4242 Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M);
321321
322322 const FunctionType *Func1Ty =
323323 cast(TypeBuilder::get(Context));
324 std::vector<const Type*> arg_types;
324 std::vector<Type*> arg_types;
325325 arg_types.push_back(Type::getInt1Ty(Context));
326326 const FunctionType *FuncTy = FunctionType::get(
327327 Type::getVoidTy(Context), arg_types, false);
119119 }
120120
121121 TEST(TypeBuilderTest, Functions) {
122 std::vector<const Type*> params;
122 std::vector<Type*> params;
123123 EXPECT_EQ(FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false),
124124 (TypeBuilder::get(getGlobalContext())));
125125 EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true),
186186 static const StructType *get(LLVMContext &Context) {
187187 // Using the static result variable ensures that the type is
188188 // only looked up once.
189 std::vector<const Type*> st;
189 std::vector<Type*> st;
190190 st.push_back(TypeBuilder::get(Context));
191191 st.push_back(TypeBuilder::get(Context));
192192 st.push_back(TypeBuilder::get(Context));
209209 static const StructType *get(LLVMContext &Context) {
210210 // Using the static result variable ensures that the type is
211211 // only looked up once.
212 std::vector<const Type*> st;
212 std::vector<Type*> st;
213213 st.push_back(TypeBuilder, cross>::get(Context));
214214 st.push_back(TypeBuilder*, cross>::get(Context));
215215 st.push_back(TypeBuilder*[], cross>::get(Context));
404404 mod->setTargetTriple("x86_64-unknown-linux-gnu");
405405
406406 // Type Definitions
407 std::vector<const Type*>FuncTy_0_args;
407 std::vector<Type*>FuncTy_0_args;
408408 FunctionType* FuncTy_0 = FunctionType::get(
409409 /*Result=*/IntegerType::get(getGlobalContext(), 32),
410410 /*Params=*/FuncTy_0_args,
411411 /*isVarArg=*/false);
412412
413 std::vector<const Type*>FuncTy_2_args;
413 std::vector<Type*>FuncTy_2_args;
414414 FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
415415 FunctionType* FuncTy_2 = FunctionType::get(
416416 /*Result=*/Type::getVoidTy(getGlobalContext()),