aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenTarget.cpp
diff options
context:
space:
mode:
authorsstefan1 <sstipanovic@s-energize.com>2020-08-26 10:37:48 +0200
committersstefan1 <sstipanovic@s-energize.com>2020-08-26 11:37:59 +0200
commit99d18f79646cf154fed1ffdb473afa8ebd943b07 (patch)
tree509b60ebc30b4049d2ca9fbef8667bdc11224bb9 /llvm/utils/TableGen/CodeGenTarget.cpp
parent1f44dfb640cbf04fd348c726950e556883cf7944 (diff)
downloadllvm-99d18f79646cf154fed1ffdb473afa8ebd943b07.zip
llvm-99d18f79646cf154fed1ffdb473afa8ebd943b07.tar.gz
llvm-99d18f79646cf154fed1ffdb473afa8ebd943b07.tar.bz2
Reland [IR] Intrinsics default attributes and opt-out flag
Intrinsic properties can now be set to default and applied to all intrinsics. If the attributes are not needed, the user can opt-out by setting the DisableDefaultAttributes flag to true. Differential Revision: https://reviews.llvm.org/D70365
Diffstat (limited to 'llvm/utils/TableGen/CodeGenTarget.cpp')
-rw-r--r--llvm/utils/TableGen/CodeGenTarget.cpp155
1 files changed, 90 insertions, 65 deletions
diff --git a/llvm/utils/TableGen/CodeGenTarget.cpp b/llvm/utils/TableGen/CodeGenTarget.cpp
index 891a08e..7824d8d 100644
--- a/llvm/utils/TableGen/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/CodeGenTarget.cpp
@@ -599,12 +599,19 @@ ComplexPattern::ComplexPattern(Record *R) {
//===----------------------------------------------------------------------===//
CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
- std::vector<Record*> Defs = RC.getAllDerivedDefinitions("Intrinsic");
+ std::vector<Record *> IntrProperties =
+ RC.getAllDerivedDefinitions("IntrinsicProperty");
+ std::vector<Record *> DefaultProperties;
+ for (Record *Rec : IntrProperties)
+ if (Rec->getValueAsBit("IsDefault"))
+ DefaultProperties.push_back(Rec);
+
+ std::vector<Record *> Defs = RC.getAllDerivedDefinitions("Intrinsic");
Intrinsics.reserve(Defs.size());
for (unsigned I = 0, e = Defs.size(); I != e; ++I)
- Intrinsics.push_back(CodeGenIntrinsic(Defs[I]));
+ Intrinsics.push_back(CodeGenIntrinsic(Defs[I], DefaultProperties));
llvm::sort(Intrinsics,
[](const CodeGenIntrinsic &LHS, const CodeGenIntrinsic &RHS) {
@@ -620,7 +627,8 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
Targets.back().Count = Intrinsics.size() - Targets.back().Offset;
}
-CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
+CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
+ std::vector<Record *> DefaultProperties) {
TheDef = R;
std::string DefName = std::string(R->getName());
ArrayRef<SMLoc> DefLoc = R->getLoc();
@@ -766,6 +774,9 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
IS.ParamTypeDefs.push_back(TyEl);
}
+ // Set default properties to true.
+ setDefaultProperties(R, DefaultProperties);
+
// Parse the intrinsic properties.
ListInit *PropList = R->getValueAsListInit("IntrProperties");
for (unsigned i = 0, e = PropList->size(); i != e; ++i) {
@@ -773,68 +784,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
assert(Property->isSubClassOf("IntrinsicProperty") &&
"Expected a property!");
- if (Property->getName() == "IntrNoMem")
- ModRef = NoMem;
- else if (Property->getName() == "IntrReadMem")
- ModRef = ModRefBehavior(ModRef & ~MR_Mod);
- else if (Property->getName() == "IntrWriteMem")
- ModRef = ModRefBehavior(ModRef & ~MR_Ref);
- else if (Property->getName() == "IntrArgMemOnly")
- ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem);
- else if (Property->getName() == "IntrInaccessibleMemOnly")
- ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_InaccessibleMem);
- else if (Property->getName() == "IntrInaccessibleMemOrArgMemOnly")
- ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem |
- MR_InaccessibleMem);
- else if (Property->getName() == "Commutative")
- isCommutative = true;
- else if (Property->getName() == "Throws")
- canThrow = true;
- else if (Property->getName() == "IntrNoDuplicate")
- isNoDuplicate = true;
- else if (Property->getName() == "IntrConvergent")
- isConvergent = true;
- else if (Property->getName() == "IntrNoReturn")
- isNoReturn = true;
- else if (Property->getName() == "IntrNoSync")
- isNoSync = true;
- else if (Property->getName() == "IntrNoFree")
- isNoFree = true;
- else if (Property->getName() == "IntrWillReturn")
- isWillReturn = true;
- else if (Property->getName() == "IntrCold")
- isCold = true;
- else if (Property->getName() == "IntrSpeculatable")
- isSpeculatable = true;
- else if (Property->getName() == "IntrHasSideEffects")
- hasSideEffects = true;
- else if (Property->isSubClassOf("NoCapture")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, NoCapture, 0);
- } else if (Property->isSubClassOf("NoAlias")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, NoAlias, 0);
- } else if (Property->isSubClassOf("Returned")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
- } else if (Property->isSubClassOf("ReadOnly")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, ReadOnly, 0);
- } else if (Property->isSubClassOf("WriteOnly")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, WriteOnly, 0);
- } else if (Property->isSubClassOf("ReadNone")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, ReadNone, 0);
- } else if (Property->isSubClassOf("ImmArg")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- ArgumentAttributes.emplace_back(ArgNo, ImmArg, 0);
- } else if (Property->isSubClassOf("Align")) {
- unsigned ArgNo = Property->getValueAsInt("ArgNo");
- uint64_t Align = Property->getValueAsInt("Align");
- ArgumentAttributes.emplace_back(ArgNo, Alignment, Align);
- } else
- llvm_unreachable("Unknown property!");
+ setProperty(Property);
}
// Also record the SDPatternOperator Properties.
@@ -844,6 +794,81 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
llvm::sort(ArgumentAttributes);
}
+void CodeGenIntrinsic::setDefaultProperties(
+ Record *R, std::vector<Record *> DefaultProperties) {
+ // opt-out of using default attributes.
+ if (R->getValueAsBit("DisableDefaultAttributes"))
+ return;
+
+ for (Record *Rec : DefaultProperties)
+ setProperty(Rec);
+}
+
+void CodeGenIntrinsic::setProperty(Record *R) {
+ if (R->getName() == "IntrNoMem")
+ ModRef = NoMem;
+ else if (R->getName() == "IntrReadMem")
+ ModRef = ModRefBehavior(ModRef & ~MR_Mod);
+ else if (R->getName() == "IntrWriteMem")
+ ModRef = ModRefBehavior(ModRef & ~MR_Ref);
+ else if (R->getName() == "IntrArgMemOnly")
+ ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem);
+ else if (R->getName() == "IntrInaccessibleMemOnly")
+ ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_InaccessibleMem);
+ else if (R->getName() == "IntrInaccessibleMemOrArgMemOnly")
+ ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem |
+ MR_InaccessibleMem);
+ else if (R->getName() == "Commutative")
+ isCommutative = true;
+ else if (R->getName() == "Throws")
+ canThrow = true;
+ else if (R->getName() == "IntrNoDuplicate")
+ isNoDuplicate = true;
+ else if (R->getName() == "IntrConvergent")
+ isConvergent = true;
+ else if (R->getName() == "IntrNoReturn")
+ isNoReturn = true;
+ else if (R->getName() == "IntrNoSync")
+ isNoSync = true;
+ else if (R->getName() == "IntrNoFree")
+ isNoFree = true;
+ else if (R->getName() == "IntrWillReturn")
+ isWillReturn = true;
+ else if (R->getName() == "IntrCold")
+ isCold = true;
+ else if (R->getName() == "IntrSpeculatable")
+ isSpeculatable = true;
+ else if (R->getName() == "IntrHasSideEffects")
+ hasSideEffects = true;
+ else if (R->isSubClassOf("NoCapture")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, NoCapture, 0);
+ } else if (R->isSubClassOf("NoAlias")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, NoAlias, 0);
+ } else if (R->isSubClassOf("Returned")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
+ } else if (R->isSubClassOf("ReadOnly")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, ReadOnly, 0);
+ } else if (R->isSubClassOf("WriteOnly")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, WriteOnly, 0);
+ } else if (R->isSubClassOf("ReadNone")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, ReadNone, 0);
+ } else if (R->isSubClassOf("ImmArg")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ ArgumentAttributes.emplace_back(ArgNo, ImmArg, 0);
+ } else if (R->isSubClassOf("Align")) {
+ unsigned ArgNo = R->getValueAsInt("ArgNo");
+ uint64_t Align = R->getValueAsInt("Align");
+ ArgumentAttributes.emplace_back(ArgNo, Alignment, Align);
+ } else
+ llvm_unreachable("Unknown property!");
+}
+
bool CodeGenIntrinsic::isParamAPointer(unsigned ParamIdx) const {
if (ParamIdx >= IS.ParamVTs.size())
return false;