diff options
Diffstat (limited to 'utils/TableGen/IntrinsicEmitter.cpp')
-rw-r--r-- | utils/TableGen/IntrinsicEmitter.cpp | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp index 155d1ab..fe55242 100644 --- a/utils/TableGen/IntrinsicEmitter.cpp +++ b/utils/TableGen/IntrinsicEmitter.cpp @@ -15,6 +15,7 @@ #include "CodeGenTarget.h" #include "SequenceToOffsetTable.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/TableGen/Error.h" #include "llvm/TableGen/Record.h" #include "llvm/TableGen/StringMatcher.h" #include "llvm/TableGen/TableGenBackend.h" @@ -249,7 +250,7 @@ static void EncodeFixedValueType(MVT::SimpleValueType VT, if (EVT(VT).isInteger()) { unsigned BitWidth = EVT(VT).getSizeInBits(); switch (BitWidth) { - default: throw "unhandled integer type width in intrinsic!"; + default: PrintFatalError("unhandled integer type width in intrinsic!"); case 1: return Sig.push_back(IIT_I1); case 8: return Sig.push_back(IIT_I8); case 16: return Sig.push_back(IIT_I16); @@ -259,7 +260,7 @@ static void EncodeFixedValueType(MVT::SimpleValueType VT, } switch (VT) { - default: throw "unhandled MVT in intrinsic!"; + default: PrintFatalError("unhandled MVT in intrinsic!"); case MVT::f32: return Sig.push_back(IIT_F32); case MVT::f64: return Sig.push_back(IIT_F64); case MVT::Metadata: return Sig.push_back(IIT_METADATA); @@ -328,7 +329,7 @@ static void EncodeFixedType(Record *R, std::vector<unsigned char> &ArgCodes, if (EVT(VT).isVector()) { EVT VVT = VT; switch (VVT.getVectorNumElements()) { - default: throw "unhandled vector type width in intrinsic!"; + default: PrintFatalError("unhandled vector type width in intrinsic!"); case 2: Sig.push_back(IIT_V2); break; case 4: Sig.push_back(IIT_V4); break; case 8: Sig.push_back(IIT_V8); break; @@ -510,10 +511,10 @@ EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) { OS << "// Add parameter attributes that are not common to all intrinsics.\n"; OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n"; if (TargetOnly) - OS << "static AttrListPtr getAttributes(" << TargetPrefix + OS << "static AttrListPtr getAttributes(LLVMContext &C, " << TargetPrefix << "Intrinsic::ID id) {\n"; else - OS << "AttrListPtr Intrinsic::getAttributes(ID id) {\n"; + OS << "AttrListPtr Intrinsic::getAttributes(LLVMContext &C, ID id) {\n"; // Compute the maximum number of attribute arguments and the map typedef std::map<const CodeGenIntrinsic*, unsigned, @@ -547,6 +548,7 @@ EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) { OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n"; OS << " unsigned NumAttrs = 0;\n"; OS << " if (id != 0) {\n"; + OS << " SmallVector<Attributes::AttrVal, 8> AttrVec;\n"; OS << " switch(IntrinsicsToAttributesMap[id - "; if (TargetOnly) OS << "Intrinsic::num_intrinsics"; @@ -564,58 +566,49 @@ EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) { unsigned numAttrs = 0; // The argument attributes are alreadys sorted by argument index. - for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) { - unsigned argNo = intrinsic.ArgumentAttributes[ai].first; + unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); + if (ae) { + while (ai != ae) { + unsigned argNo = intrinsic.ArgumentAttributes[ai].first; - OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(" - << argNo+1 << ", "; + OS << " AttrVec.clear();\n"; - bool moreThanOne = false; + do { + switch (intrinsic.ArgumentAttributes[ai].second) { + case CodeGenIntrinsic::NoCapture: + OS << " AttrVec.push_back(Attributes::NoCapture);\n"; + break; + } - do { - if (moreThanOne) OS << '|'; + ++ai; + } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo); - switch (intrinsic.ArgumentAttributes[ai].second) { - case CodeGenIntrinsic::NoCapture: - OS << "Attribute::NoCapture"; - break; - } - - ++ai; - moreThanOne = true; - } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo); - - OS << ");\n"; + OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(C, " + << argNo+1 << ", AttrVec);\n"; + } } ModRefKind modRef = getModRefKind(intrinsic); if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) { - OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, "; - bool Emitted = false; - if (!intrinsic.canThrow) { - OS << "Attribute::NoUnwind"; - Emitted = true; - } - - if (intrinsic.isNoReturn) { - if (Emitted) OS << '|'; - OS << "Attribute::NoReturn"; - Emitted = true; - } + OS << " AttrVec.clear();\n"; + + if (!intrinsic.canThrow) + OS << " AttrVec.push_back(Attributes::NoUnwind);\n"; + if (intrinsic.isNoReturn) + OS << " AttrVec.push_back(Attributes::NoReturn);\n"; switch (modRef) { case MRK_none: break; case MRK_readonly: - if (Emitted) OS << '|'; - OS << "Attribute::ReadOnly"; + OS << " AttrVec.push_back(Attributes::ReadOnly);\n"; break; case MRK_readnone: - if (Emitted) OS << '|'; - OS << "Attribute::ReadNone"; + OS << " AttrVec.push_back(Attributes::ReadNone);\n"; break; } - OS << ");\n"; + OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(C, " + << "AttrListPtr::FunctionIndex, AttrVec);\n"; } if (numAttrs) { @@ -628,7 +621,7 @@ EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) { OS << " }\n"; OS << " }\n"; - OS << " return AttrListPtr::get(ArrayRef<AttributeWithIndex>(AWI, " + OS << " return AttrListPtr::get(C, ArrayRef<AttributeWithIndex>(AWI, " "NumAttrs));\n"; OS << "}\n"; OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n"; @@ -700,8 +693,8 @@ EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints, if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName, Ints[i].EnumName)).second) - throw "Intrinsic '" + Ints[i].TheDef->getName() + - "': duplicate GCC builtin name!"; + PrintFatalError("Intrinsic '" + Ints[i].TheDef->getName() + + "': duplicate GCC builtin name!"); } } |