[llvm-commits] [llvm] r173445 - in /llvm/trunk: docs/TableGen/LangRef.rst include/llvm/TableGen/Record.h lib/TableGen/Record.cpp lib/TableGen/TGLexer.cpp lib/TableGen/TGLexer.h lib/TableGen/TGParser.cpp test/TableGen/math.td
Hal Finkel
hfinkel at anl.gov
Fri Jan 25 06:49:08 PST 2013
Author: hfinkel
Date: Fri Jan 25 08:49:08 2013
New Revision: 173445
URL: http://llvm.org/viewvc/llvm-project?rev=173445&view=rev
Log:
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.
Added:
llvm/trunk/test/TableGen/math.td
Modified:
llvm/trunk/docs/TableGen/LangRef.rst
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
llvm/trunk/lib/TableGen/TGLexer.cpp
llvm/trunk/lib/TableGen/TGLexer.h
llvm/trunk/lib/TableGen/TGParser.cpp
Modified: llvm/trunk/docs/TableGen/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/TableGen/LangRef.rst?rev=173445&r1=173444&r2=173445&view=diff
==============================================================================
--- llvm/trunk/docs/TableGen/LangRef.rst (original)
+++ llvm/trunk/docs/TableGen/LangRef.rst Fri Jan 25 08:49:08 2013
@@ -91,7 +91,7 @@
.. productionlist::
BangOperator: one of
:!eq !if !head !tail !con
- :!shl !sra !srl
+ :!add !shl !sra !srl
:!cast !empty !subst !foreach !strconcat
Syntax
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=173445&r1=173444&r2=173445&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Fri Jan 25 08:49:08 2013
@@ -930,7 +930,7 @@
///
class BinOpInit : public OpInit {
public:
- enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ };
+ enum BinaryOp { ADD, SHL, SRA, SRL, STRCONCAT, CONCAT, EQ };
private:
BinaryOp Opc;
Init *LHS, *RHS;
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=173445&r1=173444&r2=173445&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Fri Jan 25 08:49:08 2013
@@ -935,6 +935,7 @@
break;
}
+ case ADD:
case SHL:
case SRA:
case SRL: {
@@ -945,6 +946,7 @@
int64_t Result;
switch (getOpcode()) {
default: llvm_unreachable("Bad opcode!");
+ case ADD: 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;
@@ -970,6 +972,7 @@
std::string Result;
switch (Opc) {
case CONCAT: Result = "!con"; break;
+ case ADD: Result = "!add"; break;
case SHL: Result = "!shl"; break;
case SRA: Result = "!sra"; break;
case SRL: Result = "!srl"; break;
Modified: llvm/trunk/lib/TableGen/TGLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGLexer.cpp?rev=173445&r1=173444&r2=173445&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGLexer.cpp (original)
+++ llvm/trunk/lib/TableGen/TGLexer.cpp Fri Jan 25 08:49:08 2013
@@ -462,6 +462,7 @@
.Case("head", tgtok::XHead)
.Case("tail", tgtok::XTail)
.Case("con", tgtok::XConcat)
+ .Case("add", tgtok::XADD)
.Case("shl", tgtok::XSHL)
.Case("sra", tgtok::XSRA)
.Case("srl", tgtok::XSRL)
Modified: llvm/trunk/lib/TableGen/TGLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGLexer.h?rev=173445&r1=173444&r2=173445&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGLexer.h (original)
+++ llvm/trunk/lib/TableGen/TGLexer.h Fri Jan 25 08:49:08 2013
@@ -46,7 +46,7 @@
MultiClass, String,
// !keywords.
- XConcat, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
+ XConcat, XADD, XSRA, XSRL, XSHL, XStrConcat, XCast, XSubst,
XForEach, XHead, XTail, XEmpty, XIf, XEq,
// Integer value.
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=173445&r1=173444&r2=173445&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Fri Jan 25 08:49:08 2013
@@ -912,6 +912,7 @@
}
case tgtok::XConcat:
+ case tgtok::XADD:
case tgtok::XSRA:
case tgtok::XSRL:
case tgtok::XSHL:
@@ -927,6 +928,7 @@
switch (OpTok) {
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::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;
@@ -1142,6 +1144,7 @@
/// SimpleValue ::= '[' ValueList ']'
/// SimpleValue ::= '(' IDValue DagArgList ')'
/// SimpleValue ::= CONCATTOK '(' Value ',' Value ')'
+/// SimpleValue ::= ADDTOK '(' Value ',' Value ')'
/// SimpleValue ::= SHLTOK '(' Value ',' Value ')'
/// SimpleValue ::= SRATOK '(' Value ',' Value ')'
/// SimpleValue ::= SRLTOK '(' Value ',' Value ')'
@@ -1397,6 +1400,7 @@
case tgtok::XEmpty:
case tgtok::XCast: // Value ::= !unop '(' Value ')'
case tgtok::XConcat:
+ case tgtok::XADD:
case tgtok::XSRA:
case tgtok::XSRL:
case tgtok::XSHL:
Added: llvm/trunk/test/TableGen/math.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/math.td?rev=173445&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/math.td (added)
+++ llvm/trunk/test/TableGen/math.td Fri Jan 25 08:49:08 2013
@@ -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
+
More information about the llvm-commits
mailing list