aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/IntrinsicEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/utils/TableGen/IntrinsicEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/IntrinsicEmitter.cpp242
1 files changed, 85 insertions, 157 deletions
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 4be0d90a45d2..3d1d258e342e 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -378,7 +378,7 @@ static void EncodeFixedType(Record *R, std::vector<unsigned char> &ArgCodes,
MVT VVT = VT;
if (VVT.isScalableVector())
Sig.push_back(IIT_SCALABLE_VEC);
- switch (VVT.getVectorNumElements()) {
+ switch (VVT.getVectorMinNumElements()) {
default: PrintFatalError("unhandled vector type width in intrinsic!");
case 1: Sig.push_back(IIT_V1); break;
case 2: Sig.push_back(IIT_V2); break;
@@ -584,6 +584,9 @@ struct AttributeComparator {
if (L->isNoDuplicate != R->isNoDuplicate)
return R->isNoDuplicate;
+ if (L->isNoMerge != R->isNoMerge)
+ return R->isNoMerge;
+
if (L->isNoReturn != R->isNoReturn)
return R->isNoReturn;
@@ -638,13 +641,13 @@ void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size()));
unsigned &N = UniqAttributes[&intrinsic];
if (N) continue;
- assert(AttrNum < 256 && "Too many unique attributes for table!");
N = ++AttrNum;
+ assert(N < 65536 && "Too many unique attributes for table!");
}
// Emit an array of AttributeList. Most intrinsics will have at least one
// entry, for the function itself (index ~1), which is usually nounwind.
- OS << " static const uint8_t IntrinsicsToAttributesMap[] = {\n";
+ OS << " static const uint16_t IntrinsicsToAttributesMap[] = {\n";
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
const CodeGenIntrinsic &intrinsic = Ints[i];
@@ -659,240 +662,165 @@ void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
OS << " if (id != 0) {\n";
OS << " switch(IntrinsicsToAttributesMap[id - 1]) {\n";
OS << " default: llvm_unreachable(\"Invalid attribute number\");\n";
- for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(),
- E = UniqAttributes.end(); I != E; ++I) {
- OS << " case " << I->second << ": {\n";
+ for (auto UniqAttribute : UniqAttributes) {
+ OS << " case " << UniqAttribute.second << ": {\n";
- const CodeGenIntrinsic &intrinsic = *(I->first);
+ const CodeGenIntrinsic &Intrinsic = *(UniqAttribute.first);
// Keep track of the number of attributes we're writing out.
unsigned numAttrs = 0;
// The argument attributes are alreadys sorted by argument index.
- unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size();
- if (ae) {
- while (ai != ae) {
- unsigned attrIdx = intrinsic.ArgumentAttributes[ai].Index;
+ unsigned Ai = 0, Ae = Intrinsic.ArgumentAttributes.size();
+ if (Ae) {
+ while (Ai != Ae) {
+ unsigned AttrIdx = Intrinsic.ArgumentAttributes[Ai].Index;
- OS << " const Attribute::AttrKind AttrParam" << attrIdx << "[]= {";
- bool addComma = false;
+ OS << " const Attribute::AttrKind AttrParam" << AttrIdx << "[]= {";
+ ListSeparator LS(",");
bool AllValuesAreZero = true;
SmallVector<uint64_t, 8> Values;
do {
- switch (intrinsic.ArgumentAttributes[ai].Kind) {
+ switch (Intrinsic.ArgumentAttributes[Ai].Kind) {
case CodeGenIntrinsic::NoCapture:
- if (addComma)
- OS << ",";
- OS << "Attribute::NoCapture";
- addComma = true;
+ OS << LS << "Attribute::NoCapture";
break;
case CodeGenIntrinsic::NoAlias:
- if (addComma)
- OS << ",";
- OS << "Attribute::NoAlias";
- addComma = true;
+ OS << LS << "Attribute::NoAlias";
break;
case CodeGenIntrinsic::NoUndef:
- if (addComma)
- OS << ",";
- OS << "Attribute::NoUndef";
- addComma = true;
+ OS << LS << "Attribute::NoUndef";
break;
case CodeGenIntrinsic::Returned:
- if (addComma)
- OS << ",";
- OS << "Attribute::Returned";
- addComma = true;
+ OS << LS << "Attribute::Returned";
break;
case CodeGenIntrinsic::ReadOnly:
- if (addComma)
- OS << ",";
- OS << "Attribute::ReadOnly";
- addComma = true;
+ OS << LS << "Attribute::ReadOnly";
break;
case CodeGenIntrinsic::WriteOnly:
- if (addComma)
- OS << ",";
- OS << "Attribute::WriteOnly";
- addComma = true;
+ OS << LS << "Attribute::WriteOnly";
break;
case CodeGenIntrinsic::ReadNone:
- if (addComma)
- OS << ",";
- OS << "Attribute::ReadNone";
- addComma = true;
+ OS << LS << "Attribute::ReadNone";
break;
case CodeGenIntrinsic::ImmArg:
- if (addComma)
- OS << ',';
- OS << "Attribute::ImmArg";
- addComma = true;
+ OS << LS << "Attribute::ImmArg";
break;
case CodeGenIntrinsic::Alignment:
- if (addComma)
- OS << ',';
- OS << "Attribute::Alignment";
- addComma = true;
+ OS << LS << "Attribute::Alignment";
break;
}
- uint64_t V = intrinsic.ArgumentAttributes[ai].Value;
+ uint64_t V = Intrinsic.ArgumentAttributes[Ai].Value;
Values.push_back(V);
AllValuesAreZero &= (V == 0);
- ++ai;
- } while (ai != ae && intrinsic.ArgumentAttributes[ai].Index == attrIdx);
+ ++Ai;
+ } while (Ai != Ae && Intrinsic.ArgumentAttributes[Ai].Index == AttrIdx);
OS << "};\n";
// Generate attribute value array if not all attribute values are zero.
if (!AllValuesAreZero) {
- OS << " const uint64_t AttrValParam" << attrIdx << "[]= {";
- addComma = false;
- for (const auto V : Values) {
- if (addComma)
- OS << ',';
- OS << V;
- addComma = true;
- }
+ OS << " const uint64_t AttrValParam" << AttrIdx << "[]= {";
+ ListSeparator LSV(",");
+ for (const auto V : Values)
+ OS << LSV << V;
OS << "};\n";
}
OS << " AS[" << numAttrs++ << "] = AttributeList::get(C, "
- << attrIdx << ", AttrParam" << attrIdx;
+ << AttrIdx << ", AttrParam" << AttrIdx;
if (!AllValuesAreZero)
- OS << ", AttrValParam" << attrIdx;
+ OS << ", AttrValParam" << AttrIdx;
OS << ");\n";
}
}
- if (!intrinsic.canThrow ||
- (intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem &&
- !intrinsic.hasSideEffects) ||
- intrinsic.isNoReturn || intrinsic.isNoSync || intrinsic.isNoFree ||
- intrinsic.isWillReturn || intrinsic.isCold || intrinsic.isNoDuplicate ||
- intrinsic.isConvergent || intrinsic.isSpeculatable) {
+ if (!Intrinsic.canThrow ||
+ (Intrinsic.ModRef != CodeGenIntrinsic::ReadWriteMem &&
+ !Intrinsic.hasSideEffects) ||
+ Intrinsic.isNoReturn || Intrinsic.isNoSync || Intrinsic.isNoFree ||
+ Intrinsic.isWillReturn || Intrinsic.isCold || Intrinsic.isNoDuplicate ||
+ Intrinsic.isNoMerge || Intrinsic.isConvergent ||
+ Intrinsic.isSpeculatable) {
OS << " const Attribute::AttrKind Atts[] = {";
- bool addComma = false;
- if (!intrinsic.canThrow) {
- OS << "Attribute::NoUnwind";
- addComma = true;
- }
- if (intrinsic.isNoReturn) {
- if (addComma)
- OS << ",";
- OS << "Attribute::NoReturn";
- addComma = true;
- }
- if (intrinsic.isNoSync) {
- if (addComma)
- OS << ",";
- OS << "Attribute::NoSync";
- addComma = true;
- }
- if (intrinsic.isNoFree) {
- if (addComma)
- OS << ",";
- OS << "Attribute::NoFree";
- addComma = true;
- }
- if (intrinsic.isWillReturn) {
- if (addComma)
- OS << ",";
- OS << "Attribute::WillReturn";
- addComma = true;
- }
- if (intrinsic.isCold) {
- if (addComma)
- OS << ",";
- OS << "Attribute::Cold";
- addComma = true;
- }
- if (intrinsic.isNoDuplicate) {
- if (addComma)
- OS << ",";
- OS << "Attribute::NoDuplicate";
- addComma = true;
- }
- if (intrinsic.isConvergent) {
- if (addComma)
- OS << ",";
- OS << "Attribute::Convergent";
- addComma = true;
- }
- if (intrinsic.isSpeculatable) {
- if (addComma)
- OS << ",";
- OS << "Attribute::Speculatable";
- addComma = true;
- }
-
- switch (intrinsic.ModRef) {
+ ListSeparator LS(",");
+ if (!Intrinsic.canThrow)
+ OS << LS << "Attribute::NoUnwind";
+ if (Intrinsic.isNoReturn)
+ OS << LS << "Attribute::NoReturn";
+ if (Intrinsic.isNoSync)
+ OS << LS << "Attribute::NoSync";
+ if (Intrinsic.isNoFree)
+ OS << LS << "Attribute::NoFree";
+ if (Intrinsic.isWillReturn)
+ OS << LS << "Attribute::WillReturn";
+ if (Intrinsic.isCold)
+ OS << LS << "Attribute::Cold";
+ if (Intrinsic.isNoDuplicate)
+ OS << LS << "Attribute::NoDuplicate";
+ if (Intrinsic.isNoMerge)
+ OS << LS << "Attribute::NoMerge";
+ if (Intrinsic.isConvergent)
+ OS << LS << "Attribute::Convergent";
+ if (Intrinsic.isSpeculatable)
+ OS << LS << "Attribute::Speculatable";
+
+ switch (Intrinsic.ModRef) {
case CodeGenIntrinsic::NoMem:
- if (intrinsic.hasSideEffects)
+ if (Intrinsic.hasSideEffects)
break;
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::ReadNone";
break;
case CodeGenIntrinsic::ReadArgMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::ReadOnly,";
OS << "Attribute::ArgMemOnly";
break;
case CodeGenIntrinsic::ReadMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::ReadOnly";
break;
case CodeGenIntrinsic::ReadInaccessibleMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::ReadOnly,";
OS << "Attribute::InaccessibleMemOnly";
break;
case CodeGenIntrinsic::ReadInaccessibleMemOrArgMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::ReadOnly,";
OS << "Attribute::InaccessibleMemOrArgMemOnly";
break;
case CodeGenIntrinsic::WriteArgMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::WriteOnly,";
OS << "Attribute::ArgMemOnly";
break;
case CodeGenIntrinsic::WriteMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::WriteOnly";
break;
case CodeGenIntrinsic::WriteInaccessibleMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::WriteOnly,";
OS << "Attribute::InaccessibleMemOnly";
break;
case CodeGenIntrinsic::WriteInaccessibleMemOrArgMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::WriteOnly,";
OS << "Attribute::InaccessibleMemOrArgMemOnly";
break;
case CodeGenIntrinsic::ReadWriteArgMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::ArgMemOnly";
break;
case CodeGenIntrinsic::ReadWriteInaccessibleMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::InaccessibleMemOnly";
break;
case CodeGenIntrinsic::ReadWriteInaccessibleMemOrArgMem:
- if (addComma)
- OS << ",";
+ OS << LS;
OS << "Attribute::InaccessibleMemOrArgMemOnly";
break;
case CodeGenIntrinsic::ReadWriteMem:
@@ -977,25 +905,25 @@ void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
// Note: this could emit significantly better code if we cared.
- for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
+ for (auto &I : BuiltinMap) {
OS << " ";
- if (!I->first.empty())
- OS << "if (TargetPrefix == \"" << I->first << "\") ";
+ if (!I.first.empty())
+ OS << "if (TargetPrefix == \"" << I.first << "\") ";
else
OS << "/* Target Independent Builtins */ ";
OS << "{\n";
// Emit the comparisons for this target prefix.
- OS << " static const BuiltinEntry " << I->first << "Names[] = {\n";
- for (const auto &P : I->second) {
+ OS << " static const BuiltinEntry " << I.first << "Names[] = {\n";
+ for (const auto &P : I.second) {
OS << " {Intrinsic::" << P.second << ", "
<< Table.GetOrAddStringOffset(P.first) << "}, // " << P.first << "\n";
}
OS << " };\n";
- OS << " auto I = std::lower_bound(std::begin(" << I->first << "Names),\n";
- OS << " std::end(" << I->first << "Names),\n";
+ OS << " auto I = std::lower_bound(std::begin(" << I.first << "Names),\n";
+ OS << " std::end(" << I.first << "Names),\n";
OS << " BuiltinNameStr);\n";
- OS << " if (I != std::end(" << I->first << "Names) &&\n";
+ OS << " if (I != std::end(" << I.first << "Names) &&\n";
OS << " I->getName() == BuiltinNameStr)\n";
OS << " return I->IntrinID;\n";
OS << " }\n";