Skip to content

Commit 2fbf16e

Browse files
committed
[TableGen] Refactor Intrinsics record
- Eliminate unused `isTarget` field in Intrinsic record. - Eliminate `isOverloaded`, `Types` and `TypeSig` fields from the record, as they are already available through the `TypeInfo` field. Change intrinsic emitter code to look for this info using fields of the `TypeInfo` record attached to the `Intrinsic` record. - Fix several intrinsic related unit tests to source the `Intrinsic` class def from Intrinsics.td as opposed to defining a skeleton in the test. - This eliminate some duplication of information in the Intrinsic class, as well as reduces the memory allocated for record fields, resulting in ~2% reduction (though that's not the main goal).
1 parent c2b92a4 commit 2fbf16e

File tree

7 files changed

+35
-166
lines changed

7 files changed

+35
-166
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,7 @@ class Intrinsic<list<LLVMType> ret_types,
669669
// IntrinsicProperty<1>
670670
bit DisableDefaultAttributes = disable_default_attributes;
671671

672-
bit isTarget = false;
673-
674672
TypeInfoGen TypeInfo = TypeInfoGen<RetTypes, ParamTypes>;
675-
bit isOverloaded = TypeInfo.isOverloaded;
676-
list<LLVMType> Types = TypeInfo.Types;
677-
list<list<int>> TypeSig = TypeInfo.TypeSig;
678673
}
679674

680675
// Intrinsic with default attributes (disable_default_attributes = false).

llvm/test/TableGen/intrinsic-attrs.td

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,6 @@
1-
// RUN: llvm-tblgen -gen-intrinsic-impl -I %p/../../include %s | FileCheck %s
1+
// RUN: llvm-tblgen -gen-intrinsic-impl -I %p/../../include -DTEST_INTRINSICS_SUPPRESS_DEFS %s | FileCheck %s
22

3-
// Get the minimum blurb necessary to process ...
4-
include "llvm/CodeGen/ValueTypes.td"
5-
include "llvm/CodeGen/SDNodeProperties.td"
6-
7-
class LLVMType<ValueType vt> {
8-
ValueType VT = vt;
9-
int isAny = 0;
10-
}
11-
12-
def llvm_i32_ty : LLVMType<i32>;
13-
def llvm_ptr_ty : LLVMType<iPTR>;
14-
15-
class AttrIndex<int idx> {
16-
int Value = idx;
17-
}
18-
19-
def FuncIndex : AttrIndex<-1>;
20-
def RetIndex : AttrIndex<0>;
21-
class ArgIndex<int argNo> : AttrIndex<!add(argNo, 1)>;
22-
23-
class IntrinsicProperty<bit is_default = 0> {
24-
bit IsDefault = is_default;
25-
}
26-
27-
def IntrNoMem : IntrinsicProperty;
28-
def IntrHasSideEffects : IntrinsicProperty;
29-
class Dereferenceable<AttrIndex idx, int bytes> : IntrinsicProperty {
30-
int ArgNo = idx.Value;
31-
int Bytes = bytes;
32-
}
33-
34-
class Intrinsic<list<LLVMType> ret_types,
35-
list<LLVMType> param_types = [],
36-
list<IntrinsicProperty> intr_properties = [],
37-
string name = "",
38-
list<SDNodeProperty> sd_properties = [],
39-
bit disable_default_attributes = 0> : SDPatternOperator {
40-
string LLVMName = name;
41-
string TargetPrefix = "";
42-
list<LLVMType> RetTypes = ret_types;
43-
list<LLVMType> ParamTypes = param_types;
44-
list<IntrinsicProperty> IntrProperties = intr_properties;
45-
let Properties = sd_properties;
46-
bit DisableDefaultAttributes = 1;
47-
48-
49-
bit isTarget = 0;
50-
bit DisableDefaultAttributes = disable_default_attributes;
51-
}
3+
include "llvm/IR/Intrinsics.td"
524

535
// ... this intrinsic.
546
def int_random_gen : Intrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrHasSideEffects]>;
Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
1-
// RUN: llvm-tblgen -gen-intrinsic-enums %s | FileCheck %s
1+
// RUN: llvm-tblgen -gen-intrinsic-enums -I %p/../../include %s -DTEST_INTRINSICS_SUPPRESS_DEFS | FileCheck %s
22
// XFAIL: vg_leak
33

4-
class IntrinsicProperty<bit is_default = 0> {
5-
bit IsDefault = is_default;
6-
}
7-
8-
class SDNodeProperty;
9-
10-
class ValueType<int size, int value> {
11-
string Namespace = "MVT";
12-
int Size = size;
13-
int Value = value;
14-
}
15-
16-
class LLVMType<ValueType vt> {
17-
ValueType VT = vt;
18-
}
19-
20-
class Intrinsic<string name, list<LLVMType> param_types = []> {
21-
string LLVMName = name;
22-
bit isTarget = 0;
23-
string TargetPrefix = "";
24-
list<LLVMType> RetTypes = [];
25-
list<LLVMType> ParamTypes = param_types;
26-
list<IntrinsicProperty> IntrProperties = [];
27-
list<SDNodeProperty> Properties = [];
28-
bit DisableDefaultAttributes = 1;
29-
}
30-
31-
def iAny : ValueType<0, 253>;
32-
def llvm_anyint_ty : LLVMType<iAny>;
4+
include "llvm/IR/Intrinsics.td"
335

346
// Make sure we generate the long name without crashing
357
// CHECK: this_is_a_really_long_intrinsic_name_but_we_should_still_not_crash, // llvm.this.is.a.really.long.intrinsic.name.but.we.should.still.not.crash
36-
def int_foo : Intrinsic<"llvm.foo", [llvm_anyint_ty]>;
37-
def int_this_is_a_really_long_intrinsic_name_but_we_should_still_not_crash : Intrinsic<"llvm.this.is.a.really.long.intrinsic.name.but.we.should.still.not.crash", [llvm_anyint_ty]>;
8+
def int_foo : Intrinsic<[llvm_anyint_ty], [], [], "llvm.foo">;
9+
def int_this_is_a_really_long_intrinsic_name_but_we_should_still_not_crash : Intrinsic<[llvm_anyint_ty], [], [], "llvm.this.is.a.really.long.intrinsic.name.but.we.should.still.not.crash">;
3810

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,11 @@
1-
// RUN: llvm-tblgen -gen-intrinsic-enums %s | FileCheck %s
1+
// RUN: llvm-tblgen -gen-intrinsic-enums -I %p/../../include %s -DTEST_INTRINSICS_SUPPRESS_DEFS | FileCheck %s
22
// XFAIL: vg_leak
33

4-
class IntrinsicProperty<bit is_default = 0> {
5-
bit IsDefault = is_default;
6-
}
7-
8-
class SDNodeProperty;
9-
10-
class ValueType<int size, int value> {
11-
string Namespace = "MVT";
12-
int Size = size;
13-
int Value = value;
14-
}
15-
16-
class LLVMType<ValueType vt> {
17-
ValueType VT = vt;
18-
}
19-
20-
class Intrinsic<string name, list<LLVMType> ret_types = []> {
21-
string LLVMName = name;
22-
bit isTarget = 0;
23-
string TargetPrefix = "";
24-
list<LLVMType> RetTypes = ret_types;
25-
list<LLVMType> ParamTypes = [];
26-
list<IntrinsicProperty> IntrProperties = [];
27-
list<SDNodeProperty> Properties = [];
28-
bit DisableDefaultAttributes = 1;
29-
}
30-
31-
def iAny : ValueType<0, 253>;
32-
def llvm_anyint_ty : LLVMType<iAny>;
4+
include "llvm/IR/Intrinsics.td"
335

346
// Make sure we can return up to 8 values
357
// CHECK: returns_8_results = {{[0-9]+}}, // llvm.returns.8.results
36-
def int_returns_8_results : Intrinsic<"llvm.returns.8.results",
8+
def int_returns_8_results : Intrinsic<
379
[llvm_anyint_ty, llvm_anyint_ty, llvm_anyint_ty, llvm_anyint_ty,
38-
llvm_anyint_ty, llvm_anyint_ty, llvm_anyint_ty, llvm_anyint_ty]>;
10+
llvm_anyint_ty, llvm_anyint_ty, llvm_anyint_ty, llvm_anyint_ty],
11+
[], [], "llvm.returns.8.results">;

llvm/test/TableGen/searchabletables-intrinsic.td

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,19 @@
1-
// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
1+
// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include -DTEST_INTRINSICS_SUPPRESS_DEFS %s | FileCheck %s
22
// XFAIL: vg_leak
33

44
include "llvm/TableGen/SearchableTable.td"
5-
6-
class IntrinsicProperty<bit is_default = 0> {
7-
bit IsDefault = is_default;
8-
}
9-
10-
class SDNodeProperty;
11-
12-
class ValueType<int size, int value> {
13-
string Namespace = "MVT";
14-
int Size = size;
15-
int Value = value;
16-
}
17-
18-
class LLVMType<ValueType vt> {
19-
ValueType VT = vt;
20-
}
21-
22-
class Intrinsic<list<LLVMType> param_types = []> {
23-
string LLVMName = "";
24-
bit isTarget = 0;
25-
string TargetPrefix = "";
26-
list<LLVMType> RetTypes = [];
27-
list<LLVMType> ParamTypes = param_types;
28-
list<IntrinsicProperty> IntrProperties = [];
29-
list<SDNodeProperty> Properties = [];
30-
bit DisableDefaultAttributes = 1;
31-
}
32-
33-
def iAny : ValueType<0, 253>;
34-
def llvm_anyint_ty : LLVMType<iAny>;
5+
include "llvm/IR/Intrinsics.td"
356

367
def int_abc : Intrinsic<[llvm_anyint_ty]>;
378
def int_xyz : Intrinsic<[llvm_anyint_ty]>;
389

39-
let isTarget = 1, TargetPrefix = "gtarget" in {
10+
let TargetPrefix = "gtarget" in {
4011
def int_gtarget_def : Intrinsic<[llvm_anyint_ty]>;
4112
def int_gtarget_defg : Intrinsic<[llvm_anyint_ty]>;
4213
def int_gtarget_uvw : Intrinsic<[llvm_anyint_ty]>;
4314
}
4415

45-
let isTarget = 1, TargetPrefix = "ftarget" in {
16+
let TargetPrefix = "ftarget" in {
4617
def int_ftarget_ghi : Intrinsic<[llvm_anyint_ty]>;
4718
def int_ftarget_ghi_x : Intrinsic<[llvm_anyint_ty]>;
4819
def int_ftarget_rst : Intrinsic<[llvm_anyint_ty]>;

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,22 @@ CodeGenIntrinsic::CodeGenIntrinsic(const Record *R,
9696
TargetPrefix + ".'!");
9797
}
9898

99-
if (auto *Types = R->getValue("Types")) {
100-
auto *TypeList = cast<ListInit>(Types->getValue());
101-
isOverloaded = R->getValueAsBit("isOverloaded");
99+
const Record *TypeInfo = R->getValueAsDef("TypeInfo");
100+
if (!TypeInfo->isSubClassOf("TypeInfoGen"))
101+
PrintFatalError(DefLoc, "TypeInfo field in " + DefName +
102+
" should be of subclass of TypeInfoGen!");
102103

103-
unsigned I = 0;
104-
for (unsigned E = R->getValueAsListInit("RetTypes")->size(); I < E; ++I)
105-
IS.RetTys.push_back(TypeList->getElementAsRecord(I));
104+
isOverloaded = TypeInfo->getValueAsBit("isOverloaded");
105+
const ListInit *TypeList = TypeInfo->getValueAsListInit("Types");
106106

107-
for (unsigned E = TypeList->size(); I < E; ++I)
108-
IS.ParamTys.push_back(TypeList->getElementAsRecord(I));
109-
}
107+
// Types field is a concatenation of Return types followed by Param types.
108+
unsigned Idx = 0;
109+
unsigned NumRet = R->getValueAsListInit("RetTypes")->size();
110+
for (; Idx < NumRet; ++Idx)
111+
IS.RetTys.push_back(TypeList->getElementAsRecord(Idx));
112+
113+
for (unsigned E = TypeList->size(); Idx < E; ++Idx)
114+
IS.ParamTys.push_back(TypeList->getElementAsRecord(Idx));
110115

111116
// Parse the intrinsic properties.
112117
ListInit *PropList = R->getValueAsListInit("IntrProperties");

llvm/utils/TableGen/IntrinsicEmitter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,12 @@ using TypeSigTy = SmallVector<unsigned char>;
273273
/// Computes type signature of the intrinsic \p Int.
274274
static TypeSigTy ComputeTypeSignature(const CodeGenIntrinsic &Int) {
275275
TypeSigTy TypeSig;
276-
if (const auto *R = Int.TheDef->getValue("TypeSig")) {
277-
for (const auto *a : cast<ListInit>(R->getValue())->getValues()) {
278-
for (const auto *b : cast<ListInit>(a)->getValues())
279-
TypeSig.emplace_back(cast<IntInit>(b)->getValue());
280-
}
276+
const Record *TypeInfo = Int.TheDef->getValueAsDef("TypeInfo");
277+
const ListInit *OuterList = TypeInfo->getValueAsListInit("TypeSig");
278+
279+
for (const auto *Outer : OuterList->getValues()) {
280+
for (const auto *Inner : cast<ListInit>(Outer)->getValues())
281+
TypeSig.emplace_back(cast<IntInit>(Inner)->getValue());
281282
}
282283
return TypeSig;
283284
}

0 commit comments

Comments
 (0)