[llvm] 52086f8 - [llvm][TableGen] Define FieldInit::isConcrete overload
River Riddle via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 18:05:06 PST 2020
Author: River Riddle
Date: 2020-02-10T18:04:58-08:00
New Revision: 52086f802e37fbb2acc61c49120990b0b3fd10cd
URL: https://github.com/llvm/llvm-project/commit/52086f802e37fbb2acc61c49120990b0b3fd10cd
DIFF: https://github.com/llvm/llvm-project/commit/52086f802e37fbb2acc61c49120990b0b3fd10cd.diff
LOG: [llvm][TableGen] Define FieldInit::isConcrete overload
Summary:
There are a few field init values that are concrete but not complete/foldable (e.g. `?`). This allows for using those values as initializers without erroring out.
Example:
```
class A {
string value = ?;
}
class B<A impl> : A {
let value = impl.value; // This currently emits an error.
let value = ?; // This doesn't emit an error.
}
```
Differential Revision: https://reviews.llvm.org/D74360
Added:
llvm/test/TableGen/field-access-initializers.td
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 6667afe445bf..48aeaa14ca48 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -1295,6 +1295,7 @@ class FieldInit : public TypedInit {
Init *resolveReferences(Resolver &R) const override;
Init *Fold(Record *CurRec) const;
+ bool isConcrete() const override;
std::string getAsString() const override {
return Rec->getAsString() + "." + FieldName->getValue().str();
}
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 54ff9ae30679..ca8cd15294d2 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -1778,6 +1778,14 @@ Init *FieldInit::Fold(Record *CurRec) const {
return const_cast<FieldInit *>(this);
}
+bool FieldInit::isConcrete() const {
+ if (DefInit *DI = dyn_cast<DefInit>(Rec)) {
+ Init *FieldVal = DI->getDef()->getValue(FieldName)->getValue();
+ return FieldVal->isConcrete();
+ }
+ return false;
+}
+
static void ProfileCondOpInit(FoldingSetNodeID &ID,
ArrayRef<Init *> CondRange,
ArrayRef<Init *> ValRange,
diff --git a/llvm/test/TableGen/field-access-initializers.td b/llvm/test/TableGen/field-access-initializers.td
new file mode 100644
index 000000000000..5a25e2901aee
--- /dev/null
+++ b/llvm/test/TableGen/field-access-initializers.td
@@ -0,0 +1,23 @@
+// RUN: llvm-tblgen %s | FileCheck %s
+// XFAIL: vg_leak
+
+// CHECK: --- Defs ---
+
+// CHECK: def A1 {
+// CHECK: string value = ?;
+// CHECK: }
+
+// CHECK: def B1 {
+// CHECK: string value = A1.value;
+// CHECK: }
+
+class A {
+ string value = ?;
+}
+
+class B<A impl> : A {
+ let value = impl.value;
+}
+
+def A1 : A;
+def B1 : B<A1>;
More information about the llvm-commits
mailing list