forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[llvm][TableGen] Add a !initialized predicate to allow testing for ? (l…
…lvm#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 <[email protected]>
- Loading branch information
Showing
7 changed files
with
99 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,7 @@ enum TokKind { | |
XTail, | ||
XSize, | ||
XEmpty, | ||
XInitialized, | ||
XIf, | ||
XCond, | ||
XEq, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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>; |