Skip to content

Commit eedf18f

Browse files
author
sstefan1
committed
[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
1 parent 545de56 commit eedf18f

File tree

9 files changed

+128
-70
lines changed

9 files changed

+128
-70
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ include "llvm/CodeGen/SDNodeProperties.td"
1717
// Properties we keep track of for intrinsics.
1818
//===----------------------------------------------------------------------===//
1919

20-
class IntrinsicProperty;
20+
class IntrinsicProperty<bit is_default = 0> {
21+
bit IsDefault = is_default;
22+
}
2123

2224
// Intr*Mem - Memory properties. If no property is set, the worst case
2325
// is assumed (it may read and write any memory it can get access to and it may
@@ -331,14 +333,19 @@ class Intrinsic<list<LLVMType> ret_types,
331333
list<LLVMType> param_types = [],
332334
list<IntrinsicProperty> intr_properties = [],
333335
string name = "",
334-
list<SDNodeProperty> sd_properties = []> : SDPatternOperator {
336+
list<SDNodeProperty> sd_properties = [],
337+
bit disable_default_attributes = 0> : SDPatternOperator {
335338
string LLVMName = name;
336339
string TargetPrefix = ""; // Set to a prefix for target-specific intrinsics.
337340
list<LLVMType> RetTypes = ret_types;
338341
list<LLVMType> ParamTypes = param_types;
339342
list<IntrinsicProperty> IntrProperties = intr_properties;
340343
let Properties = sd_properties;
341344

345+
// Disable applying IntrinsicProperties that are marked default with
346+
// IntrinsicProperty<1>
347+
bit DisableDefaultAttributes = disable_default_attributes;
348+
342349
bit isTarget = 0;
343350
}
344351

llvm/test/TableGen/intrin-side-effects.td

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class LLVMType<ValueType vt> {
1111

1212
def llvm_i32_ty : LLVMType<i32>;
1313

14-
class IntrinsicProperty;
14+
class IntrinsicProperty<bit is_default = 0> {
15+
bit IsDefault = is_default;
16+
}
17+
1518
def IntrNoMem : IntrinsicProperty;
1619
def IntrHasSideEffects : IntrinsicProperty;
1720

@@ -27,6 +30,8 @@ class Intrinsic<list<LLVMType> ret_types,
2730
list<LLVMType> ParamTypes = param_types;
2831
list<IntrinsicProperty> IntrProperties = intr_properties;
2932
let Properties = sd_properties;
33+
bit DisableDefaultAttributes = 1;
34+
3035

3136
bit isTarget = 0;
3237
}

llvm/test/TableGen/intrinsic-long-name.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// RUN: llvm-tblgen -gen-intrinsic-enums %s | FileCheck %s
22
// XFAIL: vg_leak
33

4-
class IntrinsicProperty;
4+
class IntrinsicProperty<bit is_default = 0> {
5+
bit IsDefault = is_default;
6+
}
7+
58
class SDNodeProperty;
69

710
class ValueType<int size, int value> {
@@ -22,6 +25,7 @@ class Intrinsic<string name, list<LLVMType> param_types = []> {
2225
list<LLVMType> ParamTypes = param_types;
2326
list<IntrinsicProperty> IntrProperties = [];
2427
list<SDNodeProperty> Properties = [];
28+
bit DisableDefaultAttributes = 1;
2529
}
2630

2731
def iAny : ValueType<0, 253>;

llvm/test/TableGen/intrinsic-pointer-to-any.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
// case, so TableGen would hit an assertion in EncodeFixedType that was checking
77
// to ensure that the substitution being processed was correctly replaced.
88

9-
class IntrinsicProperty;
9+
class IntrinsicProperty<bit is_default = 0> {
10+
bit IsDefault = is_default;
11+
}
12+
1013
class SDNodeProperty;
1114

1215
class ValueType<int size, int value> {
@@ -32,6 +35,7 @@ class Intrinsic<list<LLVMType> ret_types> {
3235
list<IntrinsicProperty> IntrProperties = [];
3336
list<SDNodeProperty> Properties = [];
3437
bit isTarget = 0;
38+
bit DisableDefaultAttributes = 1;
3539
}
3640

3741
class LLVMQualPointerType<LLVMType elty>

llvm/test/TableGen/intrinsic-struct.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// RUN: llvm-tblgen -gen-intrinsic-enums %s | FileCheck %s
22
// XFAIL: vg_leak
33

4-
class IntrinsicProperty;
4+
class IntrinsicProperty<bit is_default = 0> {
5+
bit IsDefault = is_default;
6+
}
7+
58
class SDNodeProperty;
69

710
class ValueType<int size, int value> {
@@ -22,6 +25,7 @@ class Intrinsic<string name, list<LLVMType> ret_types = []> {
2225
list<LLVMType> ParamTypes = [];
2326
list<IntrinsicProperty> IntrProperties = [];
2427
list<SDNodeProperty> Properties = [];
28+
bit DisableDefaultAttributes = 1;
2529
}
2630

2731
def iAny : ValueType<0, 253>;

llvm/test/TableGen/intrinsic-varargs.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
include "llvm/CodeGen/ValueTypes.td"
55

6-
class IntrinsicProperty;
6+
class IntrinsicProperty<bit is_default = 0> {
7+
bit IsDefault = is_default;
8+
}
79
class SDNodeProperty;
810

911
class LLVMType<ValueType vt> {
@@ -18,6 +20,7 @@ class Intrinsic<string name, list<LLVMType> param_types = []> {
1820
list<LLVMType> ParamTypes = param_types;
1921
list<IntrinsicProperty> IntrProperties = [];
2022
list<SDNodeProperty> Properties = [];
23+
bit DisableDefaultAttributes = 1;
2124
}
2225

2326
def llvm_vararg_ty : LLVMType<isVoid>; // this means vararg here

llvm/test/TableGen/searchabletables-intrinsic.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
include "llvm/TableGen/SearchableTable.td"
55

6-
class IntrinsicProperty;
6+
class IntrinsicProperty<bit is_default = 0> {
7+
bit IsDefault = is_default;
8+
}
9+
710
class SDNodeProperty;
811

912
class ValueType<int size, int value> {
@@ -24,6 +27,7 @@ class Intrinsic<list<LLVMType> param_types = []> {
2427
list<LLVMType> ParamTypes = param_types;
2528
list<IntrinsicProperty> IntrProperties = [];
2629
list<SDNodeProperty> Properties = [];
30+
bit DisableDefaultAttributes = 1;
2731
}
2832

2933
def iAny : ValueType<0, 253>;

llvm/utils/TableGen/CodeGenIntrinsics.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ struct CodeGenIntrinsic {
176176
return Properties & (1 << Prop);
177177
}
178178

179+
/// Goes through all IntrProperties and sets to true ones that have IsDefault
180+
/// value set to true.
181+
void setDefaultProperties(Record *R);
182+
183+
/// Helper function to set property \p Name to true;
184+
void setProperty(Record *R);
185+
179186
/// Returns true if the parameter at \p ParamIdx is a pointer type. Returns
180187
/// false if the parameter is not a pointer, or \p ParamIdx is greater than
181188
/// the size of \p IS.ParamVTs.

llvm/utils/TableGen/CodeGenTarget.cpp

Lines changed: 82 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -766,75 +766,17 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
766766
IS.ParamTypeDefs.push_back(TyEl);
767767
}
768768

769+
// Set default properties to true.
770+
setDefaultProperties(R);
771+
769772
// Parse the intrinsic properties.
770773
ListInit *PropList = R->getValueAsListInit("IntrProperties");
771774
for (unsigned i = 0, e = PropList->size(); i != e; ++i) {
772775
Record *Property = PropList->getElementAsRecord(i);
773776
assert(Property->isSubClassOf("IntrinsicProperty") &&
774777
"Expected a property!");
775778

776-
if (Property->getName() == "IntrNoMem")
777-
ModRef = NoMem;
778-
else if (Property->getName() == "IntrReadMem")
779-
ModRef = ModRefBehavior(ModRef & ~MR_Mod);
780-
else if (Property->getName() == "IntrWriteMem")
781-
ModRef = ModRefBehavior(ModRef & ~MR_Ref);
782-
else if (Property->getName() == "IntrArgMemOnly")
783-
ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem);
784-
else if (Property->getName() == "IntrInaccessibleMemOnly")
785-
ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_InaccessibleMem);
786-
else if (Property->getName() == "IntrInaccessibleMemOrArgMemOnly")
787-
ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem |
788-
MR_InaccessibleMem);
789-
else if (Property->getName() == "Commutative")
790-
isCommutative = true;
791-
else if (Property->getName() == "Throws")
792-
canThrow = true;
793-
else if (Property->getName() == "IntrNoDuplicate")
794-
isNoDuplicate = true;
795-
else if (Property->getName() == "IntrConvergent")
796-
isConvergent = true;
797-
else if (Property->getName() == "IntrNoReturn")
798-
isNoReturn = true;
799-
else if (Property->getName() == "IntrNoSync")
800-
isNoSync = true;
801-
else if (Property->getName() == "IntrNoFree")
802-
isNoFree = true;
803-
else if (Property->getName() == "IntrWillReturn")
804-
isWillReturn = true;
805-
else if (Property->getName() == "IntrCold")
806-
isCold = true;
807-
else if (Property->getName() == "IntrSpeculatable")
808-
isSpeculatable = true;
809-
else if (Property->getName() == "IntrHasSideEffects")
810-
hasSideEffects = true;
811-
else if (Property->isSubClassOf("NoCapture")) {
812-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
813-
ArgumentAttributes.emplace_back(ArgNo, NoCapture, 0);
814-
} else if (Property->isSubClassOf("NoAlias")) {
815-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
816-
ArgumentAttributes.emplace_back(ArgNo, NoAlias, 0);
817-
} else if (Property->isSubClassOf("Returned")) {
818-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
819-
ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
820-
} else if (Property->isSubClassOf("ReadOnly")) {
821-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
822-
ArgumentAttributes.emplace_back(ArgNo, ReadOnly, 0);
823-
} else if (Property->isSubClassOf("WriteOnly")) {
824-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
825-
ArgumentAttributes.emplace_back(ArgNo, WriteOnly, 0);
826-
} else if (Property->isSubClassOf("ReadNone")) {
827-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
828-
ArgumentAttributes.emplace_back(ArgNo, ReadNone, 0);
829-
} else if (Property->isSubClassOf("ImmArg")) {
830-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
831-
ArgumentAttributes.emplace_back(ArgNo, ImmArg, 0);
832-
} else if (Property->isSubClassOf("Align")) {
833-
unsigned ArgNo = Property->getValueAsInt("ArgNo");
834-
uint64_t Align = Property->getValueAsInt("Align");
835-
ArgumentAttributes.emplace_back(ArgNo, Alignment, Align);
836-
} else
837-
llvm_unreachable("Unknown property!");
779+
setProperty(Property);
838780
}
839781

840782
// Also record the SDPatternOperator Properties.
@@ -844,6 +786,84 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
844786
llvm::sort(ArgumentAttributes);
845787
}
846788

789+
void CodeGenIntrinsic::setDefaultProperties(Record *R) {
790+
// opt-out of using default attributes.
791+
if (R->getValueAsBit("DisableDefaultAttributes"))
792+
return;
793+
794+
std::vector<Record *> Defs =
795+
R->getRecords().getAllDerivedDefinitions("IntrinsicProperty");
796+
797+
for (Record *Rec : Defs)
798+
if (Rec->getValueAsBit("IsDefault"))
799+
setProperty(Rec);
800+
}
801+
802+
void CodeGenIntrinsic::setProperty(Record *R) {
803+
if (R->getName() == "IntrNoMem")
804+
ModRef = NoMem;
805+
else if (R->getName() == "IntrReadMem")
806+
ModRef = ModRefBehavior(ModRef & ~MR_Mod);
807+
else if (R->getName() == "IntrWriteMem")
808+
ModRef = ModRefBehavior(ModRef & ~MR_Ref);
809+
else if (R->getName() == "IntrArgMemOnly")
810+
ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem);
811+
else if (R->getName() == "IntrInaccessibleMemOnly")
812+
ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_InaccessibleMem);
813+
else if (R->getName() == "IntrInaccessibleMemOrArgMemOnly")
814+
ModRef = ModRefBehavior((ModRef & ~MR_Anywhere) | MR_ArgMem |
815+
MR_InaccessibleMem);
816+
else if (R->getName() == "Commutative")
817+
isCommutative = true;
818+
else if (R->getName() == "Throws")
819+
canThrow = true;
820+
else if (R->getName() == "IntrNoDuplicate")
821+
isNoDuplicate = true;
822+
else if (R->getName() == "IntrConvergent")
823+
isConvergent = true;
824+
else if (R->getName() == "IntrNoReturn")
825+
isNoReturn = true;
826+
else if (R->getName() == "IntrNoSync")
827+
isNoSync = true;
828+
else if (R->getName() == "IntrNoFree")
829+
isNoFree = true;
830+
else if (R->getName() == "IntrWillReturn")
831+
isWillReturn = true;
832+
else if (R->getName() == "IntrCold")
833+
isCold = true;
834+
else if (R->getName() == "IntrSpeculatable")
835+
isSpeculatable = true;
836+
else if (R->getName() == "IntrHasSideEffects")
837+
hasSideEffects = true;
838+
else if (R->isSubClassOf("NoCapture")) {
839+
unsigned ArgNo = R->getValueAsInt("ArgNo");
840+
ArgumentAttributes.emplace_back(ArgNo, NoCapture, 0);
841+
} else if (R->isSubClassOf("NoAlias")) {
842+
unsigned ArgNo = R->getValueAsInt("ArgNo");
843+
ArgumentAttributes.emplace_back(ArgNo, NoAlias, 0);
844+
} else if (R->isSubClassOf("Returned")) {
845+
unsigned ArgNo = R->getValueAsInt("ArgNo");
846+
ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
847+
} else if (R->isSubClassOf("ReadOnly")) {
848+
unsigned ArgNo = R->getValueAsInt("ArgNo");
849+
ArgumentAttributes.emplace_back(ArgNo, ReadOnly, 0);
850+
} else if (R->isSubClassOf("WriteOnly")) {
851+
unsigned ArgNo = R->getValueAsInt("ArgNo");
852+
ArgumentAttributes.emplace_back(ArgNo, WriteOnly, 0);
853+
} else if (R->isSubClassOf("ReadNone")) {
854+
unsigned ArgNo = R->getValueAsInt("ArgNo");
855+
ArgumentAttributes.emplace_back(ArgNo, ReadNone, 0);
856+
} else if (R->isSubClassOf("ImmArg")) {
857+
unsigned ArgNo = R->getValueAsInt("ArgNo");
858+
ArgumentAttributes.emplace_back(ArgNo, ImmArg, 0);
859+
} else if (R->isSubClassOf("Align")) {
860+
unsigned ArgNo = R->getValueAsInt("ArgNo");
861+
uint64_t Align = R->getValueAsInt("Align");
862+
ArgumentAttributes.emplace_back(ArgNo, Alignment, Align);
863+
} else
864+
llvm_unreachable("Unknown property!");
865+
}
866+
847867
bool CodeGenIntrinsic::isParamAPointer(unsigned ParamIdx) const {
848868
if (ParamIdx >= IS.ParamVTs.size())
849869
return false;

0 commit comments

Comments
 (0)