Krzysztof Drewniak b24caf3d2b
[llvm][TableGen] Add a !initialized predicate to allow testing for ? (#117964)
There are cases (like in an upcoming patch to MLIR's `Property` class)
where the ? value is a useful null value. However, existing predicates
make ti difficult to test if the value in a record one is operating is ?
or not.

This commit adds the !initialized predicate, which is 1 on concrete,
non-? values and 0 on ?.

---------

Co-authored-by: Akshat Oke <Akshat.Oke@amd.com>
2024-12-17 20:34:35 -06:00

60 lines
1.1 KiB
TableGen

// RUN: llvm-tblgen %s | FileCheck %s
// CHECK: class F<Y [[ARG:.+]] = ?> {
// CHECK: string ret = !if(!initialized([[ARG]].str), [[ARG]].str, "N/A");
// CHECK: }
// CHECK-LABEL: def C
// CHECK: bit c0 = 0
// CHECK: bit c1 = 1
// CHECK: bit c2 = 1
def C {
bit c0 = !initialized(?);
bit c1 = !initialized(0);
bit c2 = !initialized(1);
}
class Y {
string str = ?;
}
class F<Y y> {
string ret = !if(!initialized(y.str), y.str, "N/A");
}
def Y0 : Y;
def Y1 : Y {
let str = "foo";
}
// CHECK-LABEL: def FY0
// CHECK: string ret = "N/A";
// CHECK-LABEL: def FY1
// CHECK: string ret = "foo";
def FY0 : F<Y0>;
def FY1 : F<Y1>;
class G<Y y> {
list<string> v = [y.str];
bit isInit = !initialized(v);
}
// CHECK-LABEL: def GY0
// CHECK: isInit = 1
// CHECK-LABEL: def GY1
// CHECK: isInit = 1
def GY0 : G<Y0>;
def GY1 : G<Y1>;
class Thing;
def aThing : Thing;
class Propagate<Thing t> {
Thing ret = !if(!initialized(t), t, ?);
}
// CHECK-LABEL: def PropagateNothing
// CHECK: Thing ret = ?
// CHECK-LABEL: def PropagateThing
// CHECK: Thing ret = aThing
def PropagateNothing : Propagate<?>;
def PropagateThing : Propagate<aThing>;