summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/TableGen/LangIntro.rst6
-rw-r--r--lib/TableGen/Record.cpp6
-rw-r--r--test/TableGen/math.td10
3 files changed, 20 insertions, 2 deletions
diff --git a/docs/TableGen/LangIntro.rst b/docs/TableGen/LangIntro.rst
index 3e74dffb00e..0f8b3f62136 100644
--- a/docs/TableGen/LangIntro.rst
+++ b/docs/TableGen/LangIntro.rst
@@ -208,6 +208,12 @@ supported include:
on string, int and bit objects. Use !cast<string> to compare other types of
objects.
+``!shl(a,b)``
+``!srl(a,b)``
+``!sra(a,b)``
+``!add(a,b)``
+ The usual logical and arithmetic operators.
+
Note that all of the values have rules specifying how they convert to values
for different types. These rules allow you to assign a value like "``7``"
to a "``bits<4>``" value, for example.
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index f7843dc8360..0f40904ae91 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -955,8 +955,10 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
case SHL:
case SRA:
case SRL: {
- IntInit *LHSi = dyn_cast<IntInit>(LHS);
- IntInit *RHSi = dyn_cast<IntInit>(RHS);
+ IntInit *LHSi =
+ dyn_cast_or_null<IntInit>(LHS->convertInitializerTo(IntRecTy::get()));
+ IntInit *RHSi =
+ dyn_cast_or_null<IntInit>(RHS->convertInitializerTo(IntRecTy::get()));
if (LHSi && RHSi) {
int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
int64_t Result;
diff --git a/test/TableGen/math.td b/test/TableGen/math.td
index 59d16ae908e..71c60579de2 100644
--- a/test/TableGen/math.td
+++ b/test/TableGen/math.td
@@ -1,6 +1,16 @@
// RUN: llvm-tblgen %s | FileCheck %s
// XFAIL: vg_leak
+def shifts {
+ bits<2> b = 0b10;
+ int i = 2;
+ int shifted_b = !shl(b, 2);
+ int shifted_i = !shl(i, 2);
+}
+// CHECK: def shifts
+// CHECK: shifted_b = 8
+// CHECK: shifted_i = 8
+
class Int<int value> {
int Value = value;
}