From 626b108619ec72267ff7b89d325ccf808fee88b6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 17 May 2012 05:13:57 +0000 Subject: [PATCH] Genericize the intrinsics descriptor decoding a bit to make room for future expansion, no functionality change yet though. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156979 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Function.cpp | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index ce653ce1b66..abe7f9455f6 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -361,14 +361,12 @@ std::string Intrinsic::getName(ID id, ArrayRef Tys) { #include "llvm/Intrinsics.gen" #undef GET_INTRINSTIC_GENERATOR_GLOBAL -static Type *DecodeFixedType(unsigned &TableVal, ArrayRef Tys, - LLVMContext &Context) { - unsigned Nibble = TableVal & 0xF; - TableVal >>= 4; - +static Type *DecodeFixedType(unsigned &NextElt, ArrayRef Infos, + ArrayRef Tys, LLVMContext &Context) { + IIT_Info Info = IIT_Info(Infos[NextElt++]); unsigned StructElts = 2; - switch ((IIT_Info)Nibble) { + switch (Info) { case IIT_Done: return Type::getVoidTy(Context); case IIT_I1: return Type::getInt1Ty(Context); case IIT_I8: return Type::getInt8Ty(Context); @@ -381,28 +379,27 @@ static Type *DecodeFixedType(unsigned &TableVal, ArrayRef Tys, case IIT_METADATA: return Type::Type::getMetadataTy(Context); case IIT_EMPTYSTRUCT: return StructType::get(Context); case IIT_V2: - return VectorType::get(DecodeFixedType(TableVal, Tys, Context), 2); + return VectorType::get(DecodeFixedType(NextElt, Infos, Tys, Context), 2); case IIT_V4: - return VectorType::get(DecodeFixedType(TableVal, Tys, Context), 4); + return VectorType::get(DecodeFixedType(NextElt, Infos, Tys, Context), 4); case IIT_V8: - return VectorType::get(DecodeFixedType(TableVal, Tys, Context), 8); + return VectorType::get(DecodeFixedType(NextElt, Infos, Tys, Context), 8); case IIT_V16: - return VectorType::get(DecodeFixedType(TableVal, Tys, Context), 16); + return VectorType::get(DecodeFixedType(NextElt, Infos, Tys, Context), 16); case IIT_V32: - return VectorType::get(DecodeFixedType(TableVal, Tys, Context), 32); + return VectorType::get(DecodeFixedType(NextElt, Infos, Tys, Context), 32); case IIT_PTR: - return PointerType::getUnqual(DecodeFixedType(TableVal, Tys, Context)); + return PointerType::getUnqual(DecodeFixedType(NextElt, Infos, Tys,Context)); case IIT_ARG: case IIT_EXTEND_VEC_ARG: case IIT_TRUNC_VEC_ARG: { - unsigned ArgNo = TableVal & 0xF; - TableVal >>= 4; + unsigned ArgNo = NextElt == Infos.size() ? 0 : Infos[NextElt++]; assert(ArgNo < Tys.size() && "Not enough types specified!"); Type *T = Tys[ArgNo]; - if (Nibble == IIT_EXTEND_VEC_ARG) + if (Info == IIT_EXTEND_VEC_ARG) T = VectorType::getExtendedElementVectorType(cast(T)); - if (Nibble == IIT_TRUNC_VEC_ARG) + if (Info == IIT_TRUNC_VEC_ARG) T = VectorType::getTruncatedElementVectorType(cast(T)); return T; } @@ -412,7 +409,7 @@ static Type *DecodeFixedType(unsigned &TableVal, ArrayRef Tys, case IIT_STRUCT2: { Type *Elts[5]; for (unsigned i = 0; i != StructElts; ++i) - Elts[i] = DecodeFixedType(TableVal, Tys, Context); + Elts[i] = DecodeFixedType(NextElt, Infos, Tys, Context); return StructType::get(Context, ArrayRef(Elts, StructElts)); } } @@ -428,10 +425,18 @@ FunctionType *Intrinsic::getType(LLVMContext &Context, // Check to see if the intrinsic's type was expressible by the table. unsigned TableVal = IIT_Table[id-1]; if (TableVal != ~0U) { - ResultTy = DecodeFixedType(TableVal, Tys, Context); + // Decode the TableVal into an array of IITValues. + SmallVector IITValues; + do { + IITValues.push_back(TableVal & 0xF); + TableVal >>= 4; + } while (TableVal); - while (TableVal) - ArgTys.push_back(DecodeFixedType(TableVal, Tys, Context)); + unsigned NextElt = 0; + ResultTy = DecodeFixedType(NextElt, IITValues, Tys, Context); + + while (NextElt != IITValues.size()) + ArgTys.push_back(DecodeFixedType(NextElt, IITValues, Tys, Context)); return FunctionType::get(ResultTy, ArgTys, false); }