From c754b579ae1f3ce76b98dbf14bd88b3d653b34e7 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Tue, 5 Aug 2014 09:43:25 +0000 Subject: [PATCH] Allow binary and for tblgen math. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214851 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/TableGen/Record.h | 2 +- lib/TableGen/Record.cpp | 3 +++ lib/TableGen/TGLexer.cpp | 1 + lib/TableGen/TGLexer.h | 4 ++-- lib/TableGen/TGParser.cpp | 3 +++ test/TableGen/math.td | 8 ++++++++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/llvm/TableGen/Record.h b/include/llvm/TableGen/Record.h index 36464d75d5a..84901e5fcb4 100644 --- a/include/llvm/TableGen/Record.h +++ b/include/llvm/TableGen/Record.h @@ -928,7 +928,7 @@ public: /// class BinOpInit : public OpInit { public: - enum BinaryOp { ADD, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ }; + enum BinaryOp { ADD, AND, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ }; private: BinaryOp Opc; diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 0f40904ae91..cf8ef9bbf27 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -952,6 +952,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { break; } case ADD: + case AND: case SHL: case SRA: case SRL: { @@ -965,6 +966,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { switch (getOpcode()) { default: llvm_unreachable("Bad opcode!"); case ADD: Result = LHSv + RHSv; break; + case AND: 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; @@ -991,6 +993,7 @@ std::string BinOpInit::getAsString() const { switch (Opc) { case CONCAT: Result = "!con"; break; case ADD: Result = "!add"; break; + case AND: Result = "!and"; 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 fc1d3ca3392..cfcc119f82d 100644 --- a/lib/TableGen/TGLexer.cpp +++ b/lib/TableGen/TGLexer.cpp @@ -471,6 +471,7 @@ tgtok::TokKind TGLexer::LexExclaim() { .Case("tail", tgtok::XTail) .Case("con", tgtok::XConcat) .Case("add", tgtok::XADD) + .Case("and", tgtok::XAND) .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 a2c95ca833d..c7f7306a149 100644 --- a/lib/TableGen/TGLexer.h +++ b/lib/TableGen/TGLexer.h @@ -47,8 +47,8 @@ namespace tgtok { MultiClass, String, // !keywords. - XConcat, XADD, XSRA, XSRL, XSHL, XListConcat, XStrConcat, XCast, XSubst, - XForEach, XHead, XTail, XEmpty, XIf, XEq, + XConcat, XADD, XAND, XSRA, XSRL, XSHL, XListConcat, XStrConcat, XCast, + XSubst, XForEach, XHead, XTail, XEmpty, XIf, XEq, // Integer value. IntVal, diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index a9de4eac9d3..d020a8bdc1a 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -911,6 +911,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) { case tgtok::XConcat: case tgtok::XADD: + case tgtok::XAND: case tgtok::XSRA: case tgtok::XSRL: case tgtok::XSHL: @@ -928,6 +929,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) { default: llvm_unreachable("Unhandled code!"); 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::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::XCast: // Value ::= !unop '(' Value ')' case tgtok::XConcat: case tgtok::XADD: + case tgtok::XAND: case tgtok::XSRA: case tgtok::XSRL: case tgtok::XSHL: diff --git a/test/TableGen/math.td b/test/TableGen/math.td index 71c60579de2..d966346596a 100644 --- a/test/TableGen/math.td +++ b/test/TableGen/math.td @@ -15,6 +15,12 @@ class Int { int Value = value; } +// CHECK: def v0 +// CHECK: Value = 0 + +// CHECK: def v1 +// CHECK: Value = 1 + def v1024 : Int<1024>; // CHECK: def v1024 // CHECK: Value = 1024 @@ -27,3 +33,5 @@ def v2048 : Int; // CHECK: def v2048 // CHECK: Value = 2048 +def v0 : Int; +def v1 : Int; -- 2.34.1