[llvm] a93d033 - [TableGen] Change representation of ArgumentAttributes (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 11 06:03:49 PDT 2022
Author: Nikita Popov
Date: 2022-10-11T15:03:38+02:00
New Revision: a93d03310e2c02fa5e24544df4706650f85788f7
URL: https://github.com/llvm/llvm-project/commit/a93d03310e2c02fa5e24544df4706650f85788f7
DIFF: https://github.com/llvm/llvm-project/commit/a93d03310e2c02fa5e24544df4706650f85788f7.diff
LOG: [TableGen] Change representation of ArgumentAttributes (NFC)
Instead of a flat list that includes the argument index, use a
nested vector, where each inner vector is the attribute set for
a single argument. This is more obvious and makes followup changes
simpler.
Added:
Modified:
llvm/utils/TableGen/CodeGenIntrinsics.h
llvm/utils/TableGen/CodeGenTarget.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenIntrinsics.h b/llvm/utils/TableGen/CodeGenIntrinsics.h
index fe595058f6190..41e2365ec1209 100644
--- a/llvm/utils/TableGen/CodeGenIntrinsics.h
+++ b/llvm/utils/TableGen/CodeGenIntrinsics.h
@@ -14,6 +14,7 @@
#define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
#include "SDNodeProperties.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/MachineValueType.h"
#include <string>
#include <vector>
@@ -164,20 +165,20 @@ struct CodeGenIntrinsic {
};
struct ArgAttribute {
- unsigned Index;
ArgAttrKind Kind;
uint64_t Value;
- ArgAttribute(unsigned Idx, ArgAttrKind K, uint64_t V)
- : Index(Idx), Kind(K), Value(V) {}
+ ArgAttribute(ArgAttrKind K, uint64_t V) : Kind(K), Value(V) {}
bool operator<(const ArgAttribute &Other) const {
- return std::tie(Index, Kind, Value) <
- std::tie(Other.Index, Other.Kind, Other.Value);
+ return std::tie(Kind, Value) < std::tie(Other.Kind, Other.Value);
}
};
- std::vector<ArgAttribute> ArgumentAttributes;
+ /// Vector of attributes for each argument.
+ SmallVector<SmallVector<ArgAttribute, 0>> ArgumentAttributes;
+
+ void addArgAttribute(unsigned Idx, ArgAttrKind AK, uint64_t V = 0);
bool hasProperty(enum SDNP Prop) const {
return Properties & (1 << Prop);
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index 6b4667ee8ead6..8384a8ceab625 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -825,7 +825,8 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
Properties = parseSDPatternOperatorProperties(R);
// Sort the argument attributes for later benefit.
- llvm::sort(ArgumentAttributes);
+ for (auto &Attrs : ArgumentAttributes)
+ llvm::sort(Attrs);
}
void CodeGenIntrinsic::setDefaultProperties(
@@ -888,35 +889,35 @@ void CodeGenIntrinsic::setProperty(Record *R) {
hasSideEffects = true;
else if (R->isSubClassOf("NoCapture")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, NoCapture, 0);
+ addArgAttribute(ArgNo, NoCapture);
} else if (R->isSubClassOf("NoAlias")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, NoAlias, 0);
+ addArgAttribute(ArgNo, NoAlias);
} else if (R->isSubClassOf("NoUndef")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, NoUndef, 0);
+ addArgAttribute(ArgNo, NoUndef);
} else if (R->isSubClassOf("NonNull")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, NonNull, 0);
+ addArgAttribute(ArgNo, NonNull);
} else if (R->isSubClassOf("Returned")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
+ addArgAttribute(ArgNo, Returned);
} else if (R->isSubClassOf("ReadOnly")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, ReadOnly, 0);
+ addArgAttribute(ArgNo, ReadOnly);
} else if (R->isSubClassOf("WriteOnly")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, WriteOnly, 0);
+ addArgAttribute(ArgNo, WriteOnly);
} else if (R->isSubClassOf("ReadNone")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, ReadNone, 0);
+ addArgAttribute(ArgNo, ReadNone);
} else if (R->isSubClassOf("ImmArg")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, ImmArg, 0);
+ addArgAttribute(ArgNo, ImmArg);
} else if (R->isSubClassOf("Align")) {
unsigned ArgNo = R->getValueAsInt("ArgNo");
uint64_t Align = R->getValueAsInt("Align");
- ArgumentAttributes.emplace_back(ArgNo, Alignment, Align);
+ addArgAttribute(ArgNo, Alignment, Align);
} else
llvm_unreachable("Unknown property!");
}
@@ -930,7 +931,17 @@ bool CodeGenIntrinsic::isParamAPointer(unsigned ParamIdx) const {
bool CodeGenIntrinsic::isParamImmArg(unsigned ParamIdx) const {
// Convert argument index to attribute index starting from `FirstArgIndex`.
- ArgAttribute Val{ParamIdx + 1, ImmArg, 0};
- return std::binary_search(ArgumentAttributes.begin(),
- ArgumentAttributes.end(), Val);
+ ++ParamIdx;
+ if (ParamIdx >= ArgumentAttributes.size())
+ return false;
+ ArgAttribute Val{ImmArg, 0};
+ return std::binary_search(ArgumentAttributes[ParamIdx].begin(),
+ ArgumentAttributes[ParamIdx].end(), Val);
+}
+
+void CodeGenIntrinsic::addArgAttribute(unsigned Idx, ArgAttrKind AK,
+ uint64_t V) {
+ if (Idx >= ArgumentAttributes.size())
+ ArgumentAttributes.resize(Idx + 1);
+ ArgumentAttributes[Idx].emplace_back(AK, V);
}
diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 4436faea7eb5e..a5685609d6f0a 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -699,76 +699,74 @@ void IntrinsicEmitter::EmitAttributes(const CodeGenIntrinsicTable &Ints,
// Keep track of the number of attributes we're writing out.
unsigned numAttrs = 0;
- // The argument attributes are alreadys sorted by argument index.
- assert(is_sorted(Intrinsic.ArgumentAttributes) &&
- "Argument attributes are not sorted");
-
- unsigned Ai = 0, Ae = Intrinsic.ArgumentAttributes.size();
- if (Ae) {
- while (Ai != Ae) {
- unsigned AttrIdx = Intrinsic.ArgumentAttributes[Ai].Index;
- OS << " const Attribute::AttrKind AttrParam" << AttrIdx << "[]= {";
- ListSeparator LS(",");
-
- bool AllValuesAreZero = true;
- SmallVector<uint64_t, 8> Values;
- do {
- switch (Intrinsic.ArgumentAttributes[Ai].Kind) {
- case CodeGenIntrinsic::NoCapture:
- OS << LS << "Attribute::NoCapture";
- break;
- case CodeGenIntrinsic::NoAlias:
- OS << LS << "Attribute::NoAlias";
- break;
- case CodeGenIntrinsic::NoUndef:
- OS << LS << "Attribute::NoUndef";
- break;
- case CodeGenIntrinsic::NonNull:
- OS << LS << "Attribute::NonNull";
- break;
- case CodeGenIntrinsic::Returned:
- OS << LS << "Attribute::Returned";
- break;
- case CodeGenIntrinsic::ReadOnly:
- OS << LS << "Attribute::ReadOnly";
- break;
- case CodeGenIntrinsic::WriteOnly:
- OS << LS << "Attribute::WriteOnly";
- break;
- case CodeGenIntrinsic::ReadNone:
- OS << LS << "Attribute::ReadNone";
- break;
- case CodeGenIntrinsic::ImmArg:
- OS << LS << "Attribute::ImmArg";
- break;
- case CodeGenIntrinsic::Alignment:
- OS << LS << "Attribute::Alignment";
- break;
- }
- uint64_t V = Intrinsic.ArgumentAttributes[Ai].Value;
- Values.push_back(V);
- AllValuesAreZero &= (V == 0);
-
- ++Ai;
- } while (Ai != Ae && Intrinsic.ArgumentAttributes[Ai].Index == AttrIdx);
- OS << "};\n";
+ for (const auto &[AttrIdx, Attrs] :
+ enumerate(Intrinsic.ArgumentAttributes)) {
+ if (Attrs.empty())
+ continue;
+
+ // The argument attributes are alreadys sorted by argument kind.
+ assert(is_sorted(Attrs) &&
+ "Argument attributes are not sorted");
- // Generate attribute value array if not all attribute values are zero.
- if (!AllValuesAreZero) {
- OS << " const uint64_t AttrValParam" << AttrIdx << "[]= {";
- ListSeparator LSV(",");
- for (const auto V : Values)
- OS << LSV << V;
- OS << "};\n";
+ OS << " const Attribute::AttrKind AttrParam" << AttrIdx << "[] = {";
+ ListSeparator LS(",");
+ bool AllValuesAreZero = true;
+ SmallVector<uint64_t, 8> Values;
+ for (const CodeGenIntrinsic::ArgAttribute &Attr : Attrs) {
+ switch (Attr.Kind) {
+ case CodeGenIntrinsic::NoCapture:
+ OS << LS << "Attribute::NoCapture";
+ break;
+ case CodeGenIntrinsic::NoAlias:
+ OS << LS << "Attribute::NoAlias";
+ break;
+ case CodeGenIntrinsic::NoUndef:
+ OS << LS << "Attribute::NoUndef";
+ break;
+ case CodeGenIntrinsic::NonNull:
+ OS << LS << "Attribute::NonNull";
+ break;
+ case CodeGenIntrinsic::Returned:
+ OS << LS << "Attribute::Returned";
+ break;
+ case CodeGenIntrinsic::ReadOnly:
+ OS << LS << "Attribute::ReadOnly";
+ break;
+ case CodeGenIntrinsic::WriteOnly:
+ OS << LS << "Attribute::WriteOnly";
+ break;
+ case CodeGenIntrinsic::ReadNone:
+ OS << LS << "Attribute::ReadNone";
+ break;
+ case CodeGenIntrinsic::ImmArg:
+ OS << LS << "Attribute::ImmArg";
+ break;
+ case CodeGenIntrinsic::Alignment:
+ OS << LS << "Attribute::Alignment";
+ break;
}
- // AttributeList::ReturnIndex = 0, AttrParam0 corresponds to return
- // value.
- OS << " AS[" << numAttrs++ << "] = AttributeList::get(C, "
- << AttrIdx << ", AttrParam" << AttrIdx;
- if (!AllValuesAreZero)
- OS << ", AttrValParam" << AttrIdx;
- OS << ");\n";
+
+ Values.push_back(Attr.Value);
+ AllValuesAreZero &= (Attr.Value == 0);
+ }
+
+ OS << "};\n";
+
+ // Generate attribute value array if not all attribute values are zero.
+ if (!AllValuesAreZero) {
+ OS << " const uint64_t AttrValParam" << AttrIdx << "[]= {";
+ ListSeparator LSV(",");
+ for (const auto V : Values)
+ OS << LSV << V;
+ OS << "};\n";
}
+ // AttributeList::ReturnIndex = 0, AttrParam0 corresponds to return
+ // value.
+ OS << " AS[" << numAttrs++ << "] = AttributeList::get(C, "
+ << AttrIdx << ", AttrParam" << AttrIdx;
+ if (!AllValuesAreZero)
+ OS << ", AttrValParam" << AttrIdx;
+ OS << ");\n";
}
if (!Intrinsic.canThrow ||
More information about the llvm-commits
mailing list