[llvm-commits] [llvm] r157416 - in /llvm/trunk: include/llvm/Target/Target.td test/TableGen/SetTheory.td utils/TableGen/SetTheory.cpp
Owen Anderson
resistor at mac.com
Thu May 24 14:37:08 PDT 2012
Author: resistor
Date: Thu May 24 16:37:08 2012
New Revision: 157416
URL: http://llvm.org/viewvc/llvm-project?rev=157416&view=rev
Log:
Teach tblgen's set theory "sequence" operator to support an optional stride operand.
Modified:
llvm/trunk/include/llvm/Target/Target.td
llvm/trunk/test/TableGen/SetTheory.td
llvm/trunk/utils/TableGen/SetTheory.cpp
Modified: llvm/trunk/include/llvm/Target/Target.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/Target.td?rev=157416&r1=157415&r2=157416&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/Target.td (original)
+++ llvm/trunk/include/llvm/Target/Target.td Thu May 24 16:37:08 2012
@@ -191,7 +191,8 @@
// also in the second set.
//
// (sequence "R%u", 0, 15) -> [R0, R1, ..., R15]. Generate a sequence of
-// numbered registers.
+// numbered registers. Takes an optional 4th operand which is a stride to use
+// when generating the sequence.
//
// (shl GPR, 4) - Remove the first N elements.
//
Modified: llvm/trunk/test/TableGen/SetTheory.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/SetTheory.td?rev=157416&r1=157415&r2=157416&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/SetTheory.td (original)
+++ llvm/trunk/test/TableGen/SetTheory.td Thu May 24 16:37:08 2012
@@ -161,10 +161,12 @@
def S9b : Set<(sequence "e%u", 7, 3)>;
def S9c : Set<(sequence "e%u", 0, 0)>;
def S9d : Set<(sequence "S%ua", 7, 9)>;
+def S9e : Set<(sequence "e%u", 3, 6, 2)>;
// CHECK: S9a = [ e3 e4 e5 e6 e7 ]
// CHECK: S9b = [ e7 e6 e5 e4 e3 ]
// CHECK: S9c = [ e0 ]
// CHECK: S9d = [ a b c d e0 e3 e6 e9 e4 e5 e7 ]
+// CHECK: S9e = [ e3 e5 ]
// The 'interleave' operator is almost the inverse of 'decimate'.
def interleave;
Modified: llvm/trunk/utils/TableGen/SetTheory.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/SetTheory.cpp?rev=157416&r1=157415&r2=157416&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/SetTheory.cpp (original)
+++ llvm/trunk/utils/TableGen/SetTheory.cpp Thu May 24 16:37:08 2012
@@ -160,9 +160,17 @@
// (sequence "Format", From, To) Generate a sequence of records by name.
struct SequenceOp : public SetTheory::Operator {
void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
- if (Expr->arg_size() != 3)
+ int Step = 1;
+ if (Expr->arg_size() > 4)
throw "Bad args to (sequence \"Format\", From, To): " +
Expr->getAsString();
+ else if (Expr->arg_size() == 4) {
+ if (IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[3])) {
+ Step = II->getValue();
+ } else
+ throw "Stride must be an integer: " + Expr->getAsString();
+ }
+
std::string Format;
if (StringInit *SI = dynamic_cast<StringInit*>(Expr->arg_begin()[0]))
Format = SI->getValue();
@@ -187,8 +195,12 @@
RecordKeeper &Records =
dynamic_cast<DefInit&>(*Expr->getOperator()).getDef()->getRecords();
- int Step = From <= To ? 1 : -1;
- for (To += Step; From != To; From += Step) {
+ Step *= From <= To ? 1 : -1;
+ while (true) {
+ if (Step > 0 && From > To)
+ break;
+ else if (Step < 0 && From < To)
+ break;
std::string Name;
raw_string_ostream OS(Name);
OS << format(Format.c_str(), unsigned(From));
@@ -200,6 +212,8 @@
Elts.insert(Result->begin(), Result->end());
else
Elts.insert(Rec);
+
+ From += Step;
}
}
};
More information about the llvm-commits
mailing list