summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2016-11-15 06:49:28 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2016-11-15 06:49:28 +0000
commitee23318db7271689541c8057916d93fe4ac68964 (patch)
treecbf7dc6a2c81ae261141440d51152ad90519e936
parent1ccb8e7cd4c7e3a97cb0e2327b9a9d8ccfcc3c39 (diff)
TableGen: Add operator !or
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286936 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/TableGen/LangRef.rst4
-rw-r--r--include/llvm/TableGen/Record.h2
-rw-r--r--lib/TableGen/Record.cpp3
-rw-r--r--lib/TableGen/TGLexer.cpp1
-rw-r--r--lib/TableGen/TGLexer.h4
-rw-r--r--lib/TableGen/TGParser.cpp3
-rw-r--r--test/TableGen/math.td10
7 files changed, 23 insertions, 4 deletions
diff --git a/docs/TableGen/LangRef.rst b/docs/TableGen/LangRef.rst
index 58da6285c07..285572fa481 100644
--- a/docs/TableGen/LangRef.rst
+++ b/docs/TableGen/LangRef.rst
@@ -97,7 +97,9 @@ wide variety of meanings:
BangOperator: one of
:!eq !if !head !tail !con
:!add !shl !sra !srl !and
- :!cast !empty !subst !foreach !listconcat !strconcat
+ :!or !empty !subst !foreach !strconcat
+ :!cast !listconcat
+
Syntax
======
diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h
index 393cafa7924..87ba6fd68ec 100644
--- a/include/llvm/TableGen/Record.h
+++ b/include/llvm/TableGen/Record.h
@@ -798,7 +798,7 @@ public:
///
class BinOpInit : public OpInit, public FoldingSetNode {
public:
- enum BinaryOp : uint8_t { ADD, AND, SHL, SRA, SRL, LISTCONCAT,
+ enum BinaryOp : uint8_t { ADD, AND, OR, SHL, SRA, SRL, LISTCONCAT,
STRCONCAT, CONCAT, EQ };
private:
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index 7f02c3189f3..bffe27144cf 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -865,6 +865,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
}
case ADD:
case AND:
+ case OR:
case SHL:
case SRA:
case SRL: {
@@ -879,6 +880,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
default: llvm_unreachable("Bad opcode!");
case ADD: Result = LHSv + RHSv; break;
case AND: Result = LHSv & RHSv; break;
+ case OR: Result = LHSv | RHSv; break;
case SHL: Result = LHSv << RHSv; break;
case SRA: Result = LHSv >> RHSv; break;
case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
@@ -906,6 +908,7 @@ std::string BinOpInit::getAsString() const {
case CONCAT: Result = "!con"; break;
case ADD: Result = "!add"; break;
case AND: Result = "!and"; break;
+ case OR: Result = "!or"; break;
case SHL: Result = "!shl"; break;
case SRA: Result = "!sra"; break;
case SRL: Result = "!srl"; break;
diff --git a/lib/TableGen/TGLexer.cpp b/lib/TableGen/TGLexer.cpp
index c526fc05d08..5d6f7c23e0b 100644
--- a/lib/TableGen/TGLexer.cpp
+++ b/lib/TableGen/TGLexer.cpp
@@ -472,6 +472,7 @@ tgtok::TokKind TGLexer::LexExclaim() {
.Case("con", tgtok::XConcat)
.Case("add", tgtok::XADD)
.Case("and", tgtok::XAND)
+ .Case("or", tgtok::XOR)
.Case("shl", tgtok::XSHL)
.Case("sra", tgtok::XSRA)
.Case("srl", tgtok::XSRL)
diff --git a/lib/TableGen/TGLexer.h b/lib/TableGen/TGLexer.h
index cbc30be8a57..b5b58161878 100644
--- a/lib/TableGen/TGLexer.h
+++ b/lib/TableGen/TGLexer.h
@@ -45,9 +45,9 @@ namespace tgtok {
// Keywords.
Bit, Bits, Class, Code, Dag, Def, Foreach, Defm, Field, In, Int, Let, List,
MultiClass, String,
-
+
// !keywords.
- XConcat, XADD, XAND, XSRA, XSRL, XSHL, XListConcat, XStrConcat, XCast,
+ XConcat, XADD, XAND, XOR, XSRA, XSRL, XSHL, XListConcat, XStrConcat, XCast,
XSubst, XForEach, XHead, XTail, XEmpty, XIf, XEq,
// Integer value.
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp
index 0a6752bb26d..ff5c96b0cd5 100644
--- a/lib/TableGen/TGParser.cpp
+++ b/lib/TableGen/TGParser.cpp
@@ -881,6 +881,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XConcat:
case tgtok::XADD:
case tgtok::XAND:
+ case tgtok::XOR:
case tgtok::XSRA:
case tgtok::XSRL:
case tgtok::XSHL:
@@ -899,6 +900,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XConcat: Code = BinOpInit::CONCAT;Type = DagRecTy::get(); break;
case tgtok::XADD: Code = BinOpInit::ADD; Type = IntRecTy::get(); break;
case tgtok::XAND: Code = BinOpInit::AND; Type = IntRecTy::get(); break;
+ case tgtok::XOR: Code = BinOpInit::OR; Type = IntRecTy::get(); break;
case tgtok::XSRA: Code = BinOpInit::SRA; Type = IntRecTy::get(); break;
case tgtok::XSRL: Code = BinOpInit::SRL; Type = IntRecTy::get(); break;
case tgtok::XSHL: Code = BinOpInit::SHL; Type = IntRecTy::get(); break;
@@ -1446,6 +1448,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
case tgtok::XConcat:
case tgtok::XADD:
case tgtok::XAND:
+ case tgtok::XOR:
case tgtok::XSRA:
case tgtok::XSRL:
case tgtok::XSHL:
diff --git a/test/TableGen/math.td b/test/TableGen/math.td
index d966346596a..a8b939176e0 100644
--- a/test/TableGen/math.td
+++ b/test/TableGen/math.td
@@ -15,12 +15,18 @@ class Int<int value> {
int Value = value;
}
+def v1022 : Int<1022>;
+
// CHECK: def v0
// CHECK: Value = 0
// CHECK: def v1
// CHECK: Value = 1
+// CHECK: def v1023
+// CHECK: Value = 1023
+def v1023 : Int<!or(v1022.Value, 1)>;
+
def v1024 : Int<1024>;
// CHECK: def v1024
// CHECK: Value = 1024
@@ -35,3 +41,7 @@ def v2048 : Int<!add(v1024.Value, v1024.Value)>;
def v0 : Int<!and(v1024.Value, v2048.Value)>;
def v1 : Int<!and(v1025.Value, 1)>;
+
+// CHECK: def v3072
+// CHECK: Value = 3072
+def v3072 : Int<!or(v1024.Value, v2048.Value)>;