diff options
author | Duncan Sands <baldrick@free.fr> | 2008-06-06 12:08:01 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2008-06-06 12:08:01 +0000 |
commit | 83ec4b6711980242ef3c55a4fa36b2d7a39c1bfb (patch) | |
tree | 318323f012863299f9ae063e79a47985c2e8dc4b /lib/VMCore | |
parent | cc41940dff771c98321d601e04e60dc8c67b6e87 (diff) |
Wrap MVT::ValueType in a struct to get type safety
and better control the abstraction. Rename the type
to MVT. To update out-of-tree patches, the main
thing to do is to rename MVT::ValueType to MVT, and
rewrite expressions like MVT::getSizeInBits(VT) in
the form VT.getSizeInBits(). Use VT.getSimpleVT()
to extract a MVT::SimpleValueType for use in switch
statements (you will get an assert failure if VT is
an extended value type - these shouldn't exist after
type legalization).
This results in a small speedup of codegen and no
new testsuite failures (x86-64 linux).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52044 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Function.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/ValueTypes.cpp | 62 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 17 |
3 files changed, 42 insertions, 39 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 2ab1194949..7533185be1 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -336,7 +336,7 @@ std::string Intrinsic::getName(ID id, const Type **Tys, unsigned numTys) { std::string Result(Table[id]); for (unsigned i = 0; i < numTys; ++i) if (Tys[i]) - Result += "." + MVT::getValueTypeString(MVT::getValueType(Tys[i])); + Result += "." + MVT::getMVT(Tys[i]).getMVTString(); return Result; } diff --git a/lib/VMCore/ValueTypes.cpp b/lib/VMCore/ValueTypes.cpp index 88add7c174..ca23284a17 100644 --- a/lib/VMCore/ValueTypes.cpp +++ b/lib/VMCore/ValueTypes.cpp @@ -1,4 +1,4 @@ -//===-- ValueTypes.cpp - Implementation of MVT::ValueType methods ---------===// +//===----------- ValueTypes.cpp - Implementation of MVT methods -----------===// // // The LLVM Compiler Infrastructure // @@ -17,17 +17,17 @@ #include "llvm/DerivedTypes.h" using namespace llvm; -/// MVT::getValueTypeString - This function returns value type as a string, -/// e.g. "i32". -std::string MVT::getValueTypeString(MVT::ValueType VT) { - switch (VT) { +/// getMVTString - This function returns value type as a string, e.g. "i32". +std::string MVT::getMVTString() const { + switch (V) { default: - if (isVector(VT)) - return "v" + utostr(getVectorNumElements(VT)) + - getValueTypeString(getVectorElementType(VT)); - if (isInteger(VT)) - return "i" + utostr(getSizeInBits(VT)); - assert(0 && "Invalid ValueType!"); + if (isVector()) + return "v" + utostr(getVectorNumElements()) + + getVectorElementType().getMVTString(); + if (isInteger()) + return "i" + utostr(getSizeInBits()); + assert(0 && "Invalid MVT!"); + return "?"; case MVT::i1: return "i1"; case MVT::i8: return "i8"; case MVT::i16: return "i16"; @@ -58,19 +58,20 @@ std::string MVT::getValueTypeString(MVT::ValueType VT) { } } -/// MVT::getTypeForValueType - This method returns an LLVM type corresponding -/// to the specified ValueType. Note that this will abort for types that cannot -/// be represented. -const Type *MVT::getTypeForValueType(MVT::ValueType VT) { - switch (VT) { +/// getTypeForMVT - This method returns an LLVM type corresponding to the +/// specified MVT. For integer types, this returns an unsigned type. Note +/// that this will abort for types that cannot be represented. +const Type *MVT::getTypeForMVT() const { + switch (V) { default: - if (isVector(VT)) - return VectorType::get(getTypeForValueType(getVectorElementType(VT)), - getVectorNumElements(VT)); - if (isInteger(VT)) - return IntegerType::get(getSizeInBits(VT)); - assert(0 && "ValueType does not correspond to LLVM type!"); - case MVT::isVoid:return Type::VoidTy; + if (isVector()) + return VectorType::get(getVectorElementType().getTypeForMVT(), + getVectorNumElements()); + if (isInteger()) + return IntegerType::get(getSizeInBits()); + assert(0 && "MVT does not correspond to LLVM type!"); + return Type::VoidTy; + case MVT::isVoid: return Type::VoidTy; case MVT::i1: return Type::Int1Ty; case MVT::i8: return Type::Int8Ty; case MVT::i16: return Type::Int16Ty; @@ -98,18 +99,19 @@ const Type *MVT::getTypeForValueType(MVT::ValueType VT) { } } -/// MVT::getValueType - Return the value type corresponding to the specified -/// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true, -/// unknown types are returned as Other, otherwise they are invalid. -MVT::ValueType MVT::getValueType(const Type *Ty, bool HandleUnknown) { +/// getMVT - Return the value type corresponding to the specified type. This +/// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types +/// are returned as Other, otherwise they are invalid. +MVT MVT::getMVT(const Type *Ty, bool HandleUnknown){ switch (Ty->getTypeID()) { default: if (HandleUnknown) return MVT::Other; assert(0 && "Unknown type!"); + return MVT::isVoid; case Type::VoidTyID: return MVT::isVoid; case Type::IntegerTyID: - return getIntegerType(cast<IntegerType>(Ty)->getBitWidth()); + return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth()); case Type::FloatTyID: return MVT::f32; case Type::DoubleTyID: return MVT::f64; case Type::X86_FP80TyID: return MVT::f80; @@ -118,8 +120,8 @@ MVT::ValueType MVT::getValueType(const Type *Ty, bool HandleUnknown) { case Type::PointerTyID: return MVT::iPTR; case Type::VectorTyID: { const VectorType *VTy = cast<VectorType>(Ty); - return getVectorType(getValueType(VTy->getElementType(), false), - VTy->getNumElements()); + return getVectorVT(getMVT(VTy->getElementType(), false), + VTy->getNumElements()); } } } diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index bfa2e6573f..ac529e3b7f 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -1331,7 +1331,7 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, // Note that "arg#0" is the return type. for (unsigned ArgNo = 0; ArgNo < Count; ++ArgNo) { - MVT::ValueType VT = va_arg(VA, MVT::ValueType); + int VT = va_arg(VA, int); // An MVT::SimpleValueType when non-negative. if (VT == MVT::isVoid && ArgNo > 0) { if (!FTy->isVarArg()) @@ -1351,8 +1351,8 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, EltTy = VTy->getElementType(); NumElts = VTy->getNumElements(); } - - if ((int)VT < 0) { + + if (VT < 0) { int Match = ~VT; if (Match == 0) { if (Ty != FTy->getReturnType()) { @@ -1403,7 +1403,7 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, Suffix += "."; if (EltTy != Ty) Suffix += "v" + utostr(NumElts); - Suffix += MVT::getValueTypeString(MVT::getValueType(EltTy)); + Suffix += MVT::getMVT(EltTy).getMVTString(); } else if (VT == MVT::iPTR) { if (!isa<PointerType>(Ty)) { if (ArgNo == 0) @@ -1414,19 +1414,20 @@ void Verifier::VerifyIntrinsicPrototype(Intrinsic::ID ID, "pointer and a pointer is required.", F); break; } - } else if (MVT::isVector(VT)) { + } else if (MVT((MVT::SimpleValueType)VT).isVector()) { + MVT VVT = MVT((MVT::SimpleValueType)VT); // If this is a vector argument, verify the number and type of elements. - if (MVT::getVectorElementType(VT) != MVT::getValueType(EltTy)) { + if (VVT.getVectorElementType() != MVT::getMVT(EltTy)) { CheckFailed("Intrinsic prototype has incorrect vector element type!", F); break; } - if (MVT::getVectorNumElements(VT) != NumElts) { + if (VVT.getVectorNumElements() != NumElts) { CheckFailed("Intrinsic prototype has incorrect number of " "vector elements!",F); break; } - } else if (MVT::getTypeForValueType(VT) != EltTy) { + } else if (MVT((MVT::SimpleValueType)VT).getTypeForMVT() != EltTy) { if (ArgNo == 0) CheckFailed("Intrinsic prototype has incorrect result type!", F); else |