Allow binary and for tblgen math.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214851 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Joerg Sonnenberger 2014-08-05 09:43:25 +00:00
parent e6329cf303
commit c754b579ae
6 changed files with 18 additions and 3 deletions

View File

@ -928,7 +928,7 @@ public:
/// ///
class BinOpInit : public OpInit { class BinOpInit : public OpInit {
public: public:
enum BinaryOp { ADD, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ }; enum BinaryOp { ADD, AND, SHL, SRA, SRL, LISTCONCAT, STRCONCAT, CONCAT, EQ };
private: private:
BinaryOp Opc; BinaryOp Opc;

View File

@ -952,6 +952,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
break; break;
} }
case ADD: case ADD:
case AND:
case SHL: case SHL:
case SRA: case SRA:
case SRL: { case SRL: {
@ -965,6 +966,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
switch (getOpcode()) { switch (getOpcode()) {
default: llvm_unreachable("Bad opcode!"); default: llvm_unreachable("Bad opcode!");
case ADD: Result = LHSv + RHSv; break; case ADD: Result = LHSv + RHSv; break;
case AND: Result = LHSv & RHSv; break;
case SHL: Result = LHSv << RHSv; break; case SHL: Result = LHSv << RHSv; break;
case SRA: Result = LHSv >> RHSv; break; case SRA: Result = LHSv >> RHSv; break;
case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break; case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
@ -991,6 +993,7 @@ std::string BinOpInit::getAsString() const {
switch (Opc) { switch (Opc) {
case CONCAT: Result = "!con"; break; case CONCAT: Result = "!con"; break;
case ADD: Result = "!add"; break; case ADD: Result = "!add"; break;
case AND: Result = "!and"; break;
case SHL: Result = "!shl"; break; case SHL: Result = "!shl"; break;
case SRA: Result = "!sra"; break; case SRA: Result = "!sra"; break;
case SRL: Result = "!srl"; break; case SRL: Result = "!srl"; break;

View File

@ -471,6 +471,7 @@ tgtok::TokKind TGLexer::LexExclaim() {
.Case("tail", tgtok::XTail) .Case("tail", tgtok::XTail)
.Case("con", tgtok::XConcat) .Case("con", tgtok::XConcat)
.Case("add", tgtok::XADD) .Case("add", tgtok::XADD)
.Case("and", tgtok::XAND)
.Case("shl", tgtok::XSHL) .Case("shl", tgtok::XSHL)
.Case("sra", tgtok::XSRA) .Case("sra", tgtok::XSRA)
.Case("srl", tgtok::XSRL) .Case("srl", tgtok::XSRL)

View File

@ -47,8 +47,8 @@ namespace tgtok {
MultiClass, String, MultiClass, String,
// !keywords. // !keywords.
XConcat, XADD, XSRA, XSRL, XSHL, XListConcat, XStrConcat, XCast, XSubst, XConcat, XADD, XAND, XSRA, XSRL, XSHL, XListConcat, XStrConcat, XCast,
XForEach, XHead, XTail, XEmpty, XIf, XEq, XSubst, XForEach, XHead, XTail, XEmpty, XIf, XEq,
// Integer value. // Integer value.
IntVal, IntVal,

View File

@ -911,6 +911,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XConcat: case tgtok::XConcat:
case tgtok::XADD: case tgtok::XADD:
case tgtok::XAND:
case tgtok::XSRA: case tgtok::XSRA:
case tgtok::XSRL: case tgtok::XSRL:
case tgtok::XSHL: case tgtok::XSHL:
@ -928,6 +929,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
default: llvm_unreachable("Unhandled code!"); default: llvm_unreachable("Unhandled code!");
case tgtok::XConcat: Code = BinOpInit::CONCAT;Type = DagRecTy::get(); break; case tgtok::XConcat: Code = BinOpInit::CONCAT;Type = DagRecTy::get(); break;
case tgtok::XADD: Code = BinOpInit::ADD; Type = IntRecTy::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::XSRA: Code = BinOpInit::SRA; Type = IntRecTy::get(); break;
case tgtok::XSRL: Code = BinOpInit::SRL; Type = IntRecTy::get(); break; case tgtok::XSRL: Code = BinOpInit::SRL; Type = IntRecTy::get(); break;
case tgtok::XSHL: Code = BinOpInit::SHL; 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::XCast: // Value ::= !unop '(' Value ')'
case tgtok::XConcat: case tgtok::XConcat:
case tgtok::XADD: case tgtok::XADD:
case tgtok::XAND:
case tgtok::XSRA: case tgtok::XSRA:
case tgtok::XSRL: case tgtok::XSRL:
case tgtok::XSHL: case tgtok::XSHL:

View File

@ -15,6 +15,12 @@ class Int<int value> {
int Value = value; int Value = value;
} }
// CHECK: def v0
// CHECK: Value = 0
// CHECK: def v1
// CHECK: Value = 1
def v1024 : Int<1024>; def v1024 : Int<1024>;
// CHECK: def v1024 // CHECK: def v1024
// CHECK: Value = 1024 // CHECK: Value = 1024
@ -27,3 +33,5 @@ def v2048 : Int<!add(v1024.Value, v1024.Value)>;
// CHECK: def v2048 // CHECK: def v2048
// CHECK: Value = 2048 // CHECK: Value = 2048
def v0 : Int<!and(v1024.Value, v2048.Value)>;
def v1 : Int<!and(v1025.Value, 1)>;