1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Add an addition operator to TableGen

This adds an !add(a, b) operator to tablegen; this will be used
to cleanup the PPC register definitions.

llvm-svn: 173445
This commit is contained in:
Hal Finkel 2013-01-25 14:49:08 +00:00
parent e74bc9b8dc
commit 4279c8573b
7 changed files with 26 additions and 3 deletions

View File

@ -91,7 +91,7 @@ wide variety of meanings:
.. productionlist:: .. productionlist::
BangOperator: one of BangOperator: one of
:!eq !if !head !tail !con :!eq !if !head !tail !con
:!shl !sra !srl :!add !shl !sra !srl
:!cast !empty !subst !foreach !strconcat :!cast !empty !subst !foreach !strconcat
Syntax Syntax

View File

@ -930,7 +930,7 @@ public:
/// ///
class BinOpInit : public OpInit { class BinOpInit : public OpInit {
public: public:
enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ }; enum BinaryOp { ADD, SHL, SRA, SRL, STRCONCAT, CONCAT, EQ };
private: private:
BinaryOp Opc; BinaryOp Opc;
Init *LHS, *RHS; Init *LHS, *RHS;

View File

@ -935,6 +935,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
break; break;
} }
case ADD:
case SHL: case SHL:
case SRA: case SRA:
case SRL: { case SRL: {
@ -945,6 +946,7 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
int64_t Result; int64_t Result;
switch (getOpcode()) { switch (getOpcode()) {
default: llvm_unreachable("Bad opcode!"); default: llvm_unreachable("Bad opcode!");
case ADD: 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;
@ -970,6 +972,7 @@ std::string BinOpInit::getAsString() const {
std::string Result; std::string Result;
switch (Opc) { switch (Opc) {
case CONCAT: Result = "!con"; break; case CONCAT: Result = "!con"; break;
case ADD: Result = "!add"; 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

@ -462,6 +462,7 @@ tgtok::TokKind TGLexer::LexExclaim() {
.Case("head", tgtok::XHead) .Case("head", tgtok::XHead)
.Case("tail", tgtok::XTail) .Case("tail", tgtok::XTail)
.Case("con", tgtok::XConcat) .Case("con", tgtok::XConcat)
.Case("add", tgtok::XADD)
.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

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

View File

@ -912,6 +912,7 @@ Init *TGParser::ParseOperation(Record *CurRec) {
} }
case tgtok::XConcat: case tgtok::XConcat:
case tgtok::XADD:
case tgtok::XSRA: case tgtok::XSRA:
case tgtok::XSRL: case tgtok::XSRL:
case tgtok::XSHL: case tgtok::XSHL:
@ -927,6 +928,7 @@ Init *TGParser::ParseOperation(Record *CurRec) {
switch (OpTok) { switch (OpTok) {
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::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;
@ -1142,6 +1144,7 @@ RecTy *TGParser::ParseOperatorType() {
/// SimpleValue ::= '[' ValueList ']' /// SimpleValue ::= '[' ValueList ']'
/// SimpleValue ::= '(' IDValue DagArgList ')' /// SimpleValue ::= '(' IDValue DagArgList ')'
/// SimpleValue ::= CONCATTOK '(' Value ',' Value ')' /// SimpleValue ::= CONCATTOK '(' Value ',' Value ')'
/// SimpleValue ::= ADDTOK '(' Value ',' Value ')'
/// SimpleValue ::= SHLTOK '(' Value ',' Value ')' /// SimpleValue ::= SHLTOK '(' Value ',' Value ')'
/// SimpleValue ::= SRATOK '(' Value ',' Value ')' /// SimpleValue ::= SRATOK '(' Value ',' Value ')'
/// SimpleValue ::= SRLTOK '(' Value ',' Value ')' /// SimpleValue ::= SRLTOK '(' Value ',' Value ')'
@ -1397,6 +1400,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
case tgtok::XEmpty: case tgtok::XEmpty:
case tgtok::XCast: // Value ::= !unop '(' Value ')' case tgtok::XCast: // Value ::= !unop '(' Value ')'
case tgtok::XConcat: case tgtok::XConcat:
case tgtok::XADD:
case tgtok::XSRA: case tgtok::XSRA:
case tgtok::XSRL: case tgtok::XSRL:
case tgtok::XSHL: case tgtok::XSHL:

15
test/TableGen/math.td Normal file
View File

@ -0,0 +1,15 @@
// RUN: llvm-tblgen %s | FileCheck %s
class Int<int value> {
int Value = value;
}
def v1024 : Int<1024>;
// CHECK: Value = 1024
def v1025 : Int<!add(v1024.Value, 1)>;
// CHECK: Value = 1025
def v2048 : Int<!add(v1024.Value, v1024.Value)>;
// CHECK: Value = 2048