llvm.org GIT mirror llvm / eb9a85f
Change Intrinsic::getDeclaration and friends to take an ArrayRef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135154 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
12 changed file(s) with 25 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
5656 //declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i32, i1)
5757 Type *Tys[] = { Type::getInt8PtrTy(C), Type::getInt32Ty(C) };
5858 Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset,
59 Tys, 2);
59 Tys);
6060
6161 //declare i32 @getchar()
6262 getchar_func = cast(module->
1515 #ifndef LLVM_INTRINSICS_H
1616 #define LLVM_INTRINSICS_H
1717
18 #include "llvm/ADT/ArrayRef.h"
1819 #include
1920
2021 namespace llvm {
4344
4445 /// Intrinsic::getName(ID) - Return the LLVM name for an intrinsic, such as
4546 /// "llvm.ppc.altivec.lvx".
46 std::string getName(ID id, Type **Tys = 0, unsigned numTys = 0);
47 std::string getName(ID id, ArrayRef Tys = ArrayRef());
4748
4849 /// Intrinsic::getType(ID) - Return the function type for an intrinsic.
4950 ///
5051 const FunctionType *getType(LLVMContext &Context, ID id,
51 Type **Tys = 0, unsigned numTys = 0);
52 ArrayRef Tys = ArrayRef());
5253
5354 /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be
5455 /// overloaded.
6667 /// overloaded intrinsic, Tys should point to an array of numTys pointers to
6768 /// Type, and must provide exactly one type for each overloaded type in the
6869 /// intrinsic.
69 Function *getDeclaration(Module *M, ID id, Type **Tys = 0,
70 unsigned numTys = 0);
70 Function *getDeclaration(Module *M, ID id,
71 ArrayRef Tys = ArrayRef());
7172
7273 /// Map a GCC builtin name to an intrinsic ID.
7374 ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName);
557557 return false;
558558
559559 // Okay, we can do this xform, do so now.
560 Type *Tys[] = { Ty };
561560 Module *M = CI->getParent()->getParent()->getParent();
562 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
561 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty);
563562
564563 Value *Op = CI->getArgOperand(0);
565564 Op = CallInst::Create(Int, Op, CI->getName(), CI);
14231423 for (unsigned i = 1, e = ByteValues.size(); i != e; ++i)
14241424 if (ByteValues[i] != V)
14251425 return 0;
1426 Type *Tys[] = { ITy };
14271426 Module *M = I.getParent()->getParent()->getParent();
1428 Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
1427 Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, ITy);
14291428 return CallInst::Create(F, V);
14301429 }
14311430
219219 Type *Tys[3] = { CI.getArgOperand(0)->getType(),
220220 CI.getArgOperand(1)->getType(),
221221 CI.getArgOperand(2)->getType() };
222 CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys, 3));
222 CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys));
223223 Changed = true;
224224 }
225225 }
16831683
16841684 Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth);
16851685 Value *F = Intrinsic::getDeclaration(M, Intrinsic::sadd_with_overflow,
1686 &NewType, 1);
1686 NewType);
16871687
16881688 InstCombiner::BuilderTy *Builder = IC.Builder;
16891689
17241724
17251725 Module *M = I.getParent()->getParent()->getParent();
17261726 Type *Ty = LHS->getType();
1727 Value *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, &Ty,1);
1727 Value *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, Ty);
17281728 CallInst *Call = Builder->CreateCall2(F, LHS, RHS, "uadd");
17291729 Value *Add = Builder->CreateExtractValue(Call, 0);
17301730
843843 M->getRawSource()->getType(),
844844 M->getLength()->getType() };
845845 M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy,
846 ArgTys, 3));
846 ArgTys));
847847
848848 // MemDep may have over conservative information about this instruction, just
849849 // conservatively flush it from the cache.
993993 // ffs(x) -> x != 0 ? (i32)llvm.cttz(x)+1 : 0
994994 Type *ArgType = Op->getType();
995995 Value *F = Intrinsic::getDeclaration(Callee->getParent(),
996 Intrinsic::cttz, &ArgType, 1);
996 Intrinsic::cttz, ArgType);
997997 Value *V = B.CreateCall(F, Op, "cttz");
998998 V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp");
999999 V = B.CreateIntCast(V, B.getInt32Ty(), false, "tmp");
682682 Type *Tys[3] = {VoidPtrTy, VoidPtrTy, Type::getInt64Ty(Context)};
683683 Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
684684 Intrinsic::memcpy,
685 Tys, 3);
685 Tys);
686686 Value *DestCast = new BitCastInst(NewAlloca, VoidPtrTy, "tmp", TheCall);
687687 Value *SrcCast = new BitCastInst(Arg, VoidPtrTy, "tmp", TheCall);
688688
332332 return 0;
333333 }
334334
335 std::string Intrinsic::getName(ID id, Type **Tys, unsigned numTys) {
335 std::string Intrinsic::getName(ID id, ArrayRef Tys) {
336336 assert(id < num_intrinsics && "Invalid intrinsic ID!");
337337 static const char * const Table[] = {
338338 "not_intrinsic",
340340 #include "llvm/Intrinsics.gen"
341341 #undef GET_INTRINSIC_NAME_TABLE
342342 };
343 if (numTys == 0)
343 if (Tys.empty())
344344 return Table[id];
345345 std::string Result(Table[id]);
346 for (unsigned i = 0; i < numTys; ++i) {
346 for (unsigned i = 0; i < Tys.size(); ++i) {
347347 if (const PointerType* PTyp = dyn_cast(Tys[i])) {
348348 Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) +
349349 EVT::getEVT(PTyp->getElementType()).getEVTString();
355355 }
356356
357357 const FunctionType *Intrinsic::getType(LLVMContext &Context,
358 ID id, Type **Tys,
359 unsigned numTys) {
358 ID id, ArrayRef Tys) {
360359 const Type *ResultTy = NULL;
361360 std::vector ArgTys;
362361 bool IsVarArg = false;
383382 #include "llvm/Intrinsics.gen"
384383 #undef GET_INTRINSIC_ATTRIBUTES
385384
386 Function *Intrinsic::getDeclaration(Module *M, ID id, Type **Tys,
387 unsigned numTys) {
385 Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef Tys) {
388386 // There can never be multiple globals with the same name of different types,
389387 // because intrinsics must be a specific type.
390388 return
391 cast(M->getOrInsertFunction(getName(id, Tys, numTys),
392 getType(M->getContext(),
393 id, Tys, numTys)));
389 cast(M->getOrInsertFunction(getName(id, Tys),
390 getType(M->getContext(), id, Tys)));
394391 }
395392
396393 // This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method.
6666 Value *Ops[] = { Ptr, Val, Size, getInt32(Align), getInt1(isVolatile) };
6767 Type *Tys[] = { Ptr->getType(), Size->getType() };
6868 Module *M = BB->getParent()->getParent();
69 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 2);
69 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys);
7070
7171 CallInst *CI = createCallHelper(TheFn, Ops, 5, this);
7272
8686 Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
8787 Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
8888 Module *M = BB->getParent()->getParent();
89 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys, 3);
89 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys);
9090
9191 CallInst *CI = createCallHelper(TheFn, Ops, 5, this);
9292
106106 Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) };
107107 Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
108108 Module *M = BB->getParent()->getParent();
109 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys, 3);
109 Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys);
110110
111111 CallInst *CI = createCallHelper(TheFn, Ops, 5, this);
112112
258258 } else if (VT == MVT::iPTRAny) {
259259 // Make sure the user has passed us an argument type to overload. If not,
260260 // treat it as an ordinary (not overloaded) intrinsic.
261 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
261 OS << "(" << ArgNo << " < Tys.size()) ? Tys[" << ArgNo
262262 << "] : PointerType::getUnqual(";
263263 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
264264 OS << ")";