From e6e1933f31f5e75989e5f4871f7292e2bd1a007f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 14 Jul 2011 17:45:39 +0000 Subject: [PATCH] Change Intrinsic::getDeclaration and friends to take an ArrayRef. llvm-svn: 135154 --- llvm/examples/BrainF/BrainF.cpp | 2 +- llvm/include/llvm/Intrinsics.h | 9 +++++---- llvm/lib/CodeGen/IntrinsicLowering.cpp | 3 +-- .../InstCombine/InstCombineAndOrXor.cpp | 3 +-- .../Transforms/InstCombine/InstCombineCalls.cpp | 2 +- .../InstCombine/InstCombineCompares.cpp | 4 ++-- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp | 2 +- llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | 2 +- llvm/lib/Transforms/Utils/InlineFunction.cpp | 2 +- llvm/lib/VMCore/Function.cpp | 17 +++++++---------- llvm/lib/VMCore/IRBuilder.cpp | 6 +++--- llvm/utils/TableGen/IntrinsicEmitter.cpp | 2 +- 12 files changed, 25 insertions(+), 29 deletions(-) diff --git a/llvm/examples/BrainF/BrainF.cpp b/llvm/examples/BrainF/BrainF.cpp index 264afa281315..e8d87ebfe0df 100644 --- a/llvm/examples/BrainF/BrainF.cpp +++ b/llvm/examples/BrainF/BrainF.cpp @@ -57,7 +57,7 @@ void BrainF::header(LLVMContext& C) { //declare void @llvm.memset.p0i8.i32(i8 *, i8, i32, i32, i1) Type *Tys[] = { Type::getInt8PtrTy(C), Type::getInt32Ty(C) }; Function *memset_func = Intrinsic::getDeclaration(module, Intrinsic::memset, - Tys, 2); + Tys); //declare i32 @getchar() getchar_func = cast(module-> diff --git a/llvm/include/llvm/Intrinsics.h b/llvm/include/llvm/Intrinsics.h index 4885e28611f6..46361ca0c2f8 100644 --- a/llvm/include/llvm/Intrinsics.h +++ b/llvm/include/llvm/Intrinsics.h @@ -16,6 +16,7 @@ #ifndef LLVM_INTRINSICS_H #define LLVM_INTRINSICS_H +#include "llvm/ADT/ArrayRef.h" #include namespace llvm { @@ -44,12 +45,12 @@ namespace Intrinsic { /// Intrinsic::getName(ID) - Return the LLVM name for an intrinsic, such as /// "llvm.ppc.altivec.lvx". - std::string getName(ID id, Type **Tys = 0, unsigned numTys = 0); + std::string getName(ID id, ArrayRef Tys = ArrayRef()); /// Intrinsic::getType(ID) - Return the function type for an intrinsic. /// const FunctionType *getType(LLVMContext &Context, ID id, - Type **Tys = 0, unsigned numTys = 0); + ArrayRef Tys = ArrayRef()); /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be /// overloaded. @@ -67,8 +68,8 @@ namespace Intrinsic { /// overloaded intrinsic, Tys should point to an array of numTys pointers to /// Type, and must provide exactly one type for each overloaded type in the /// intrinsic. - Function *getDeclaration(Module *M, ID id, Type **Tys = 0, - unsigned numTys = 0); + Function *getDeclaration(Module *M, ID id, + ArrayRef Tys = ArrayRef()); /// Map a GCC builtin name to an intrinsic ID. ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName); diff --git a/llvm/lib/CodeGen/IntrinsicLowering.cpp b/llvm/lib/CodeGen/IntrinsicLowering.cpp index a1166d026a58..3313181a6192 100644 --- a/llvm/lib/CodeGen/IntrinsicLowering.cpp +++ b/llvm/lib/CodeGen/IntrinsicLowering.cpp @@ -558,9 +558,8 @@ bool IntrinsicLowering::LowerToByteSwap(CallInst *CI) { return false; // Okay, we can do this xform, do so now. - Type *Tys[] = { Ty }; Module *M = CI->getParent()->getParent()->getParent(); - Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); + Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Ty); Value *Op = CI->getArgOperand(0); Op = CallInst::Create(Int, Op, CI->getName(), CI); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 1dfbd3e548cf..64ea36fb1e9d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1424,9 +1424,8 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) { for (unsigned i = 1, e = ByteValues.size(); i != e; ++i) if (ByteValues[i] != V) return 0; - Type *Tys[] = { ITy }; Module *M = I.getParent()->getParent()->getParent(); - Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); + Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, ITy); return CallInst::Create(F, V); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index b4843658f56b..233a54c93204 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -220,7 +220,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { Type *Tys[3] = { CI.getArgOperand(0)->getType(), CI.getArgOperand(1)->getType(), CI.getArgOperand(2)->getType() }; - CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys, 3)); + CI.setCalledFunction(Intrinsic::getDeclaration(M, MemCpyID, Tys)); Changed = true; } } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 5eb12610b25b..56e69f91d56e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1684,7 +1684,7 @@ static Instruction *ProcessUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B, Type *NewType = IntegerType::get(OrigAdd->getContext(), NewWidth); Value *F = Intrinsic::getDeclaration(M, Intrinsic::sadd_with_overflow, - &NewType, 1); + NewType); InstCombiner::BuilderTy *Builder = IC.Builder; @@ -1725,7 +1725,7 @@ static Instruction *ProcessUAddIdiom(Instruction &I, Value *OrigAddV, Module *M = I.getParent()->getParent()->getParent(); Type *Ty = LHS->getType(); - Value *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, &Ty,1); + Value *F = Intrinsic::getDeclaration(M, Intrinsic::uadd_with_overflow, Ty); CallInst *Call = Builder->CreateCall2(F, LHS, RHS, "uadd"); Value *Add = Builder->CreateExtractValue(Call, 0); diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index a3a3063cdebf..7ed3db6cc1db 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -844,7 +844,7 @@ bool MemCpyOpt::processMemMove(MemMoveInst *M) { M->getRawSource()->getType(), M->getLength()->getType() }; M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, - ArgTys, 3)); + ArgTys)); // MemDep may have over conservative information about this instruction, just // conservatively flush it from the cache. diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 66c302844144..7c415e5150dc 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -994,7 +994,7 @@ struct FFSOpt : public LibCallOptimization { // ffs(x) -> x != 0 ? (i32)llvm.cttz(x)+1 : 0 Type *ArgType = Op->getType(); Value *F = Intrinsic::getDeclaration(Callee->getParent(), - Intrinsic::cttz, &ArgType, 1); + Intrinsic::cttz, ArgType); Value *V = B.CreateCall(F, Op, "cttz"); V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp"); V = B.CreateIntCast(V, B.getInt32Ty(), false, "tmp"); diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 791d30cb1792..d39ea8418730 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -683,7 +683,7 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall, Type *Tys[3] = {VoidPtrTy, VoidPtrTy, Type::getInt64Ty(Context)}; Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(), Intrinsic::memcpy, - Tys, 3); + Tys); Value *DestCast = new BitCastInst(NewAlloca, VoidPtrTy, "tmp", TheCall); Value *SrcCast = new BitCastInst(Arg, VoidPtrTy, "tmp", TheCall); diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp index bde6a6d6918a..6536bcd0e2ed 100644 --- a/llvm/lib/VMCore/Function.cpp +++ b/llvm/lib/VMCore/Function.cpp @@ -333,7 +333,7 @@ unsigned Function::getIntrinsicID() const { return 0; } -std::string Intrinsic::getName(ID id, Type **Tys, unsigned numTys) { +std::string Intrinsic::getName(ID id, ArrayRef Tys) { assert(id < num_intrinsics && "Invalid intrinsic ID!"); static const char * const Table[] = { "not_intrinsic", @@ -341,10 +341,10 @@ std::string Intrinsic::getName(ID id, Type **Tys, unsigned numTys) { #include "llvm/Intrinsics.gen" #undef GET_INTRINSIC_NAME_TABLE }; - if (numTys == 0) + if (Tys.empty()) return Table[id]; std::string Result(Table[id]); - for (unsigned i = 0; i < numTys; ++i) { + for (unsigned i = 0; i < Tys.size(); ++i) { if (const PointerType* PTyp = dyn_cast(Tys[i])) { Result += ".p" + llvm::utostr(PTyp->getAddressSpace()) + EVT::getEVT(PTyp->getElementType()).getEVTString(); @@ -356,8 +356,7 @@ std::string Intrinsic::getName(ID id, Type **Tys, unsigned numTys) { } const FunctionType *Intrinsic::getType(LLVMContext &Context, - ID id, Type **Tys, - unsigned numTys) { + ID id, ArrayRef Tys) { const Type *ResultTy = NULL; std::vector ArgTys; bool IsVarArg = false; @@ -384,14 +383,12 @@ bool Intrinsic::isOverloaded(ID id) { #include "llvm/Intrinsics.gen" #undef GET_INTRINSIC_ATTRIBUTES -Function *Intrinsic::getDeclaration(Module *M, ID id, Type **Tys, - unsigned numTys) { +Function *Intrinsic::getDeclaration(Module *M, ID id, ArrayRef Tys) { // There can never be multiple globals with the same name of different types, // because intrinsics must be a specific type. return - cast(M->getOrInsertFunction(getName(id, Tys, numTys), - getType(M->getContext(), - id, Tys, numTys))); + cast(M->getOrInsertFunction(getName(id, Tys), + getType(M->getContext(), id, Tys))); } // This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method. diff --git a/llvm/lib/VMCore/IRBuilder.cpp b/llvm/lib/VMCore/IRBuilder.cpp index 647c0b7760af..135201876742 100644 --- a/llvm/lib/VMCore/IRBuilder.cpp +++ b/llvm/lib/VMCore/IRBuilder.cpp @@ -67,7 +67,7 @@ CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align, Value *Ops[] = { Ptr, Val, Size, getInt32(Align), getInt1(isVolatile) }; Type *Tys[] = { Ptr->getType(), Size->getType() }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 2); + Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys); CallInst *CI = createCallHelper(TheFn, Ops, 5, this); @@ -87,7 +87,7 @@ CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align, Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys, 3); + Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys); CallInst *CI = createCallHelper(TheFn, Ops, 5, this); @@ -107,7 +107,7 @@ CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align, Value *Ops[] = { Dst, Src, Size, getInt32(Align), getInt1(isVolatile) }; Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() }; Module *M = BB->getParent()->getParent(); - Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys, 3); + Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memmove, Tys); CallInst *CI = createCallHelper(TheFn, Ops, 5, this); diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp index 7a53138c7014..e5e7cea1200f 100644 --- a/llvm/utils/TableGen/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp @@ -259,7 +259,7 @@ static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType, } else if (VT == MVT::iPTRAny) { // Make sure the user has passed us an argument type to overload. If not, // treat it as an ordinary (not overloaded) intrinsic. - OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo + OS << "(" << ArgNo << " < Tys.size()) ? Tys[" << ArgNo << "] : PointerType::getUnqual("; EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo); OS << ")";