Ban rematerializable instructions with side effects.
[oota-llvm.git] / utils / TableGen / SetTheory.cpp
index e168b549bc3ea3bc5eeb9e0ae445da38e0e7c82e..bef73f33effe089fed35cc689635cdc223bf0322 100644 (file)
@@ -13,7 +13,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "SetTheory.h"
-#include "Record.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
 #include "llvm/Support/Format.h"
 
 using namespace llvm;
@@ -140,10 +141,6 @@ struct DecimateOp : public SetIntBinOp {
 
 // (sequence "Format", From, To) Generate a sequence of records by name.
 struct SequenceOp : public SetTheory::Operator {
-  RecordKeeper &Records;
-
-  SequenceOp(RecordKeeper&R) : Records(R) {}
-
   void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) {
     if (Expr->arg_size() != 3)
       throw "Bad args to (sequence \"Format\", From, To): " +
@@ -159,16 +156,24 @@ struct SequenceOp : public SetTheory::Operator {
       From = II->getValue();
     else
       throw "From must be an integer: " + Expr->getAsString();
+    if (From < 0 || From >= (1 << 30))
+      throw "From out of range";
+
     if (IntInit *II = dynamic_cast<IntInit*>(Expr->arg_begin()[2]))
       To = II->getValue();
     else
       throw "From must be an integer: " + Expr->getAsString();
+    if (To < 0 || To >= (1 << 30))
+      throw "To out of range";
+
+    RecordKeeper &Records =
+      dynamic_cast<DefInit&>(*Expr->getOperator()).getDef()->getRecords();
 
     int Step = From <= To ? 1 : -1;
     for (To += Step; From != To; From += Step) {
       std::string Name;
       raw_string_ostream OS(Name);
-      OS << format(Format.c_str(), From);
+      OS << format(Format.c_str(), unsigned(From));
       Record *Rec = Records.getDef(OS.str());
       if (!Rec)
         throw "No def named '" + Name + "': " + Expr->getAsString();
@@ -193,7 +198,7 @@ struct FieldExpander : public SetTheory::Expander {
 };
 } // end anonymous namespace
 
-SetTheory::SetTheory(RecordKeeper *Records) {
+SetTheory::SetTheory() {
   addOperator("add", new AddOp);
   addOperator("sub", new SubOp);
   addOperator("and", new AndOp);
@@ -202,8 +207,7 @@ SetTheory::SetTheory(RecordKeeper *Records) {
   addOperator("rotl", new RotOp(false));
   addOperator("rotr", new RotOp(true));
   addOperator("decimate", new DecimateOp);
-  if (Records)
-    addOperator("sequence", new SequenceOp(*Records));
+  addOperator("sequence", new SequenceOp);
 }
 
 void SetTheory::addOperator(StringRef Name, Operator *Op) {