Unconstify Inits

Remove const qualifiers from Init references, per Chris' request.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136531 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp
index a1cf63f..ef6634e 100644
--- a/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -583,7 +583,7 @@
 
 static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) {
   if (N->isLeaf()) {
-    if (dynamic_cast<const DefInit*>(N->getLeafValue()) != NULL)
+    if (dynamic_cast<DefInit*>(N->getLeafValue()) != NULL)
       DepMap[N->getName()]++;
   } else {
     for (size_t i = 0, e = N->getNumChildren(); i != e; ++i)
@@ -692,7 +692,7 @@
   unsigned Size = 3;  // The node itself.
   // If the root node is a ConstantSDNode, increases its size.
   // e.g. (set R32:$dst, 0).
-  if (P->isLeaf() && dynamic_cast<const IntInit*>(P->getLeafValue()))
+  if (P->isLeaf() && dynamic_cast<IntInit*>(P->getLeafValue()))
     Size += 2;
 
   // FIXME: This is a hack to statically increase the priority of patterns
@@ -716,7 +716,7 @@
         Child->getType(0) != MVT::Other)
       Size += getPatternSize(Child, CGP);
     else if (Child->isLeaf()) {
-      if (dynamic_cast<const IntInit*>(Child->getLeafValue()))
+      if (dynamic_cast<IntInit*>(Child->getLeafValue()))
         Size += 5;  // Matches a ConstantSDNode (+3) and a specific value (+2).
       else if (Child->getComplexPatternInfo(CGP))
         Size += getPatternSize(Child, CGP);
@@ -742,7 +742,7 @@
 std::string PatternToMatch::getPredicateCheck() const {
   std::string PredicateCheck;
   for (unsigned i = 0, e = Predicates->getSize(); i != e; ++i) {
-    if (const DefInit *Pred = dynamic_cast<const DefInit*>(Predicates->getElement(i))) {
+    if (DefInit *Pred = dynamic_cast<DefInit*>(Predicates->getElement(i))) {
       Record *Def = Pred->getDef();
       if (!Def->isSubClassOf("Predicate")) {
 #ifndef NDEBUG
@@ -866,12 +866,12 @@
     // The NodeToApply must be a leaf node that is a VT.  OtherOperandNum must
     // have an integer type that is smaller than the VT.
     if (!NodeToApply->isLeaf() ||
-        !dynamic_cast<const DefInit*>(NodeToApply->getLeafValue()) ||
-        !static_cast<const DefInit*>(NodeToApply->getLeafValue())->getDef()
+        !dynamic_cast<DefInit*>(NodeToApply->getLeafValue()) ||
+        !static_cast<DefInit*>(NodeToApply->getLeafValue())->getDef()
                ->isSubClassOf("ValueType"))
       TP.error(N->getOperator()->getName() + " expects a VT operand!");
     MVT::SimpleValueType VT =
-     getValueType(static_cast<const DefInit*>(NodeToApply->getLeafValue())->getDef());
+     getValueType(static_cast<DefInit*>(NodeToApply->getLeafValue())->getDef());
 
     EEVT::TypeSet TypeListTmp(VT, TP);
 
@@ -1021,10 +1021,10 @@
       return PFRec->getOnlyTree()->getNumTypes();
 
     // Get the result tree.
-    const DagInit *Tree = Operator->getValueAsDag("Fragment");
+    DagInit *Tree = Operator->getValueAsDag("Fragment");
     Record *Op = 0;
-    if (Tree && dynamic_cast<const DefInit*>(Tree->getOperator()))
-      Op = dynamic_cast<const DefInit*>(Tree->getOperator())->getDef();
+    if (Tree && dynamic_cast<DefInit*>(Tree->getOperator()))
+      Op = dynamic_cast<DefInit*>(Tree->getOperator())->getDef();
     assert(Op && "Invalid Fragment");
     return GetNumNodeResults(Op, CDP);
   }
@@ -1098,8 +1098,8 @@
     return false;
 
   if (isLeaf()) {
-    if (const DefInit *DI = dynamic_cast<const DefInit*>(getLeafValue())) {
-      if (const DefInit *NDI = dynamic_cast<const DefInit*>(N->getLeafValue())) {
+    if (DefInit *DI = dynamic_cast<DefInit*>(getLeafValue())) {
+      if (DefInit *NDI = dynamic_cast<DefInit*>(N->getLeafValue())) {
         return ((DI->getDef() == NDI->getDef())
                 && (DepVars.find(getName()) == DepVars.end()
                     || getName() == N->getName()));
@@ -1155,9 +1155,9 @@
   for (unsigned i = 0, e = getNumChildren(); i != e; ++i) {
     TreePatternNode *Child = getChild(i);
     if (Child->isLeaf()) {
-      const Init *Val = Child->getLeafValue();
-      if (dynamic_cast<const DefInit*>(Val) &&
-          static_cast<const DefInit*>(Val)->getDef()->getName() == "node") {
+      Init *Val = Child->getLeafValue();
+      if (dynamic_cast<DefInit*>(Val) &&
+          static_cast<DefInit*>(Val)->getDef()->getName() == "node") {
         // We found a use of a formal argument, replace it with its value.
         TreePatternNode *NewChild = ArgMap[Child->getName()];
         assert(NewChild && "Couldn't find formal argument!");
@@ -1319,7 +1319,7 @@
     return 0;
 
   unsigned IID =
-    dynamic_cast<const IntInit*>(getChild(0)->getLeafValue())->getValue();
+    dynamic_cast<IntInit*>(getChild(0)->getLeafValue())->getValue();
   return &CDP.getIntrinsicInfo(IID);
 }
 
@@ -1329,7 +1329,7 @@
 TreePatternNode::getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const {
   if (!isLeaf()) return 0;
 
-  const DefInit *DI = dynamic_cast<const DefInit*>(getLeafValue());
+  DefInit *DI = dynamic_cast<DefInit*>(getLeafValue());
   if (DI && DI->getDef()->isSubClassOf("ComplexPattern"))
     return &CGP.getComplexPattern(DI->getDef());
   return 0;
@@ -1382,7 +1382,7 @@
 bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
   CodeGenDAGPatterns &CDP = TP.getDAGPatterns();
   if (isLeaf()) {
-    if (const DefInit *DI = dynamic_cast<const DefInit*>(getLeafValue())) {
+    if (DefInit *DI = dynamic_cast<DefInit*>(getLeafValue())) {
       // If it's a regclass or something else known, include the type.
       bool MadeChange = false;
       for (unsigned i = 0, e = Types.size(); i != e; ++i)
@@ -1391,7 +1391,7 @@
       return MadeChange;
     }
 
-    if (const IntInit *II = dynamic_cast<const IntInit*>(getLeafValue())) {
+    if (IntInit *II = dynamic_cast<IntInit*>(getLeafValue())) {
       assert(Types.size() == 1 && "Invalid IntInit");
 
       // Int inits are always integers. :)
@@ -1651,7 +1651,7 @@
 static bool OnlyOnRHSOfCommutative(TreePatternNode *N) {
   if (!N->isLeaf() && N->getOperator()->getName() == "imm")
     return true;
-  if (N->isLeaf() && dynamic_cast<const IntInit*>(N->getLeafValue()))
+  if (N->isLeaf() && dynamic_cast<IntInit*>(N->getLeafValue()))
     return true;
   return false;
 }
@@ -1701,14 +1701,14 @@
 // TreePattern implementation
 //
 
-TreePattern::TreePattern(Record *TheRec, const ListInit *RawPat, bool isInput,
+TreePattern::TreePattern(Record *TheRec, ListInit *RawPat, bool isInput,
                          CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp){
   isInputPattern = isInput;
   for (unsigned i = 0, e = RawPat->getSize(); i != e; ++i)
     Trees.push_back(ParseTreePattern(RawPat->getElement(i), ""));
 }
 
-TreePattern::TreePattern(Record *TheRec, const DagInit *Pat, bool isInput,
+TreePattern::TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
                          CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp){
   isInputPattern = isInput;
   Trees.push_back(ParseTreePattern(Pat, ""));
@@ -1739,8 +1739,8 @@
 }
 
 
-TreePatternNode *TreePattern::ParseTreePattern(const Init *TheInit, StringRef OpName){
-  if (const DefInit *DI = dynamic_cast<const DefInit*>(TheInit)) {
+TreePatternNode *TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName){
+  if (DefInit *DI = dynamic_cast<DefInit*>(TheInit)) {
     Record *R = DI->getDef();
 
     // Direct reference to a leaf DagNode or PatFrag?  Turn it into a
@@ -1749,7 +1749,7 @@
     if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag"))
       return ParseTreePattern(
         DagInit::get(DI, "",
-                     std::vector<std::pair<const Init*, std::string> >()),
+                     std::vector<std::pair<Init*, std::string> >()),
         OpName);
 
     // Input argument?
@@ -1764,26 +1764,26 @@
     return Res;
   }
 
-  if (const IntInit *II = dynamic_cast<const IntInit*>(TheInit)) {
+  if (IntInit *II = dynamic_cast<IntInit*>(TheInit)) {
     if (!OpName.empty())
       error("Constant int argument should not have a name!");
     return new TreePatternNode(II, 1);
   }
 
-  if (const BitsInit *BI = dynamic_cast<const BitsInit*>(TheInit)) {
+  if (BitsInit *BI = dynamic_cast<BitsInit*>(TheInit)) {
     // Turn this into an IntInit.
-    const Init *II = BI->convertInitializerTo(IntRecTy::get());
-    if (II == 0 || !dynamic_cast<const IntInit*>(II))
+    Init *II = BI->convertInitializerTo(IntRecTy::get());
+    if (II == 0 || !dynamic_cast<IntInit*>(II))
       error("Bits value must be constants!");
     return ParseTreePattern(II, OpName);
   }
 
-  const DagInit *Dag = dynamic_cast<const DagInit*>(TheInit);
+  DagInit *Dag = dynamic_cast<DagInit*>(TheInit);
   if (!Dag) {
     TheInit->dump();
     error("Pattern has unexpected init kind!");
   }
-  const DefInit *OpDef = dynamic_cast<const DefInit*>(Dag->getOperator());
+  DefInit *OpDef = dynamic_cast<DefInit*>(Dag->getOperator());
   if (!OpDef) error("Pattern has unexpected operator type!");
   Record *Operator = OpDef->getDef();
 
@@ -1948,7 +1948,7 @@
           // us to match things like:
           //  def : Pat<(v1i64 (bitconvert(v2i32 DPR:$src))), (v1i64 DPR:$src)>;
           if (Nodes[i] == Trees[0] && Nodes[i]->isLeaf()) {
-            const DefInit *DI = dynamic_cast<const DefInit*>(Nodes[i]->getLeafValue());
+            DefInit *DI = dynamic_cast<DefInit*>(Nodes[i]->getLeafValue());
             if (DI && (DI->getDef()->isSubClassOf("RegisterClass") ||
                        DI->getDef()->isSubClassOf("RegisterOperand")))
               continue;
@@ -2097,7 +2097,7 @@
 
   // First step, parse all of the fragments.
   for (unsigned i = 0, e = Fragments.size(); i != e; ++i) {
-    const DagInit *Tree = Fragments[i]->getValueAsDag("Fragment");
+    DagInit *Tree = Fragments[i]->getValueAsDag("Fragment");
     TreePattern *P = new TreePattern(Fragments[i], Tree, true, *this);
     PatternFragments[Fragments[i]] = P;
 
@@ -2109,8 +2109,8 @@
       P->error("Cannot have unnamed 'node' values in pattern fragment!");
 
     // Parse the operands list.
-    const DagInit *OpsList = Fragments[i]->getValueAsDag("Operands");
-    const DefInit *OpsOp = dynamic_cast<const DefInit*>(OpsList->getOperator());
+    DagInit *OpsList = Fragments[i]->getValueAsDag("Operands");
+    DefInit *OpsOp = dynamic_cast<DefInit*>(OpsList->getOperator());
     // Special cases: ops == outs == ins. Different names are used to
     // improve readability.
     if (!OpsOp ||
@@ -2122,8 +2122,8 @@
     // Copy over the arguments.
     Args.clear();
     for (unsigned j = 0, e = OpsList->getNumArgs(); j != e; ++j) {
-      if (!dynamic_cast<const DefInit*>(OpsList->getArg(j)) ||
-          static_cast<const DefInit*>(OpsList->getArg(j))->
+      if (!dynamic_cast<DefInit*>(OpsList->getArg(j)) ||
+          static_cast<DefInit*>(OpsList->getArg(j))->
           getDef()->getName() != "node")
         P->error("Operands list should all be 'node' values.");
       if (OpsList->getArgName(j).empty())
@@ -2181,19 +2181,19 @@
 
   // Find some SDNode.
   assert(!SDNodes.empty() && "No SDNodes parsed?");
-  const Init *SomeSDNode = DefInit::get(SDNodes.begin()->first);
+  Init *SomeSDNode = DefInit::get(SDNodes.begin()->first);
 
   for (unsigned iter = 0; iter != 2; ++iter) {
     for (unsigned i = 0, e = DefaultOps[iter].size(); i != e; ++i) {
-      const DagInit *DefaultInfo = DefaultOps[iter][i]->getValueAsDag("DefaultOps");
+      DagInit *DefaultInfo = DefaultOps[iter][i]->getValueAsDag("DefaultOps");
 
       // Clone the DefaultInfo dag node, changing the operator from 'ops' to
       // SomeSDnode so that we can parse this.
-      std::vector<std::pair<const Init*, std::string> > Ops;
+      std::vector<std::pair<Init*, std::string> > Ops;
       for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op)
         Ops.push_back(std::make_pair(DefaultInfo->getArg(op),
                                      DefaultInfo->getArgName(op)));
-      const DagInit *DI = DagInit::get(SomeSDNode, "", Ops);
+      DagInit *DI = DagInit::get(SomeSDNode, "", Ops);
 
       // Create a TreePattern to parse this.
       TreePattern P(DefaultOps[iter][i], DI, false, *this);
@@ -2232,7 +2232,7 @@
   // No name -> not interesting.
   if (Pat->getName().empty()) {
     if (Pat->isLeaf()) {
-      const DefInit *DI = dynamic_cast<const DefInit*>(Pat->getLeafValue());
+      DefInit *DI = dynamic_cast<DefInit*>(Pat->getLeafValue());
       if (DI && (DI->getDef()->isSubClassOf("RegisterClass") ||
                  DI->getDef()->isSubClassOf("RegisterOperand")))
         I->error("Input " + DI->getDef()->getName() + " must be named!");
@@ -2242,7 +2242,7 @@
 
   Record *Rec;
   if (Pat->isLeaf()) {
-    const DefInit *DI = dynamic_cast<const DefInit*>(Pat->getLeafValue());
+    DefInit *DI = dynamic_cast<DefInit*>(Pat->getLeafValue());
     if (!DI) I->error("Input $" + Pat->getName() + " must be an identifier!");
     Rec = DI->getDef();
   } else {
@@ -2260,7 +2260,7 @@
   }
   Record *SlotRec;
   if (Slot->isLeaf()) {
-    SlotRec = dynamic_cast<const DefInit*>(Slot->getLeafValue())->getDef();
+    SlotRec = dynamic_cast<DefInit*>(Slot->getLeafValue())->getDef();
   } else {
     assert(Slot->getNumChildren() == 0 && "can't be a use with children!");
     SlotRec = Slot->getOperator();
@@ -2295,7 +2295,7 @@
       if (!Dest->isLeaf())
         I->error("implicitly defined value should be a register!");
 
-      const DefInit *Val = dynamic_cast<const DefInit*>(Dest->getLeafValue());
+      DefInit *Val = dynamic_cast<DefInit*>(Dest->getLeafValue());
       if (!Val || !Val->getDef()->isSubClassOf("Register"))
         I->error("implicitly defined value should be a register!");
       InstImpResults.push_back(Val->getDef());
@@ -2336,7 +2336,7 @@
     if (!Dest->isLeaf())
       I->error("set destination should be a register!");
 
-    const DefInit *Val = dynamic_cast<const DefInit*>(Dest->getLeafValue());
+    DefInit *Val = dynamic_cast<DefInit*>(Dest->getLeafValue());
     if (!Val)
       I->error("set destination should be a register!");
 
@@ -2402,7 +2402,7 @@
       return false;
 
     const TreePatternNode *N0 = N->getChild(0);
-    if (!N0->isLeaf() || !dynamic_cast<const DefInit*>(N0->getLeafValue()))
+    if (!N0->isLeaf() || !dynamic_cast<DefInit*>(N0->getLeafValue()))
       return false;
 
     const TreePatternNode *N1 = N->getChild(1);
@@ -2419,7 +2419,7 @@
 
   void AnalyzeNode(const TreePatternNode *N) {
     if (N->isLeaf()) {
-      if (const DefInit *DI = dynamic_cast<const DefInit*>(N->getLeafValue())) {
+      if (DefInit *DI = dynamic_cast<DefInit*>(N->getLeafValue())) {
         Record *LeafRec = DI->getDef();
         // Handle ComplexPattern leaves.
         if (LeafRec->isSubClassOf("ComplexPattern")) {
@@ -2526,9 +2526,9 @@
   std::vector<Record*> Instrs = Records.getAllDerivedDefinitions("Instruction");
 
   for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
-    const ListInit *LI = 0;
+    ListInit *LI = 0;
 
-    if (dynamic_cast<const ListInit*>(Instrs[i]->getValueInit("Pattern")))
+    if (dynamic_cast<ListInit*>(Instrs[i]->getValueInit("Pattern")))
       LI = Instrs[i]->getValueAsListInit("Pattern");
 
     // If there is no pattern, only collect minimal information about the
@@ -2620,7 +2620,7 @@
 
       if (i == 0)
         Res0Node = RNode;
-      Record *R = dynamic_cast<const DefInit*>(RNode->getLeafValue())->getDef();
+      Record *R = dynamic_cast<DefInit*>(RNode->getLeafValue())->getDef();
       if (R == 0)
         I->error("Operand $" + OpName + " should be a set destination: all "
                  "outputs must occur before inputs in operand list!");
@@ -2665,8 +2665,8 @@
       InstInputsCheck.erase(OpName);   // It occurred, remove from map.
 
       if (InVal->isLeaf() &&
-          dynamic_cast<const DefInit*>(InVal->getLeafValue())) {
-        Record *InRec = static_cast<const DefInit*>(InVal->getLeafValue())->getDef();
+          dynamic_cast<DefInit*>(InVal->getLeafValue())) {
+        Record *InRec = static_cast<DefInit*>(InVal->getLeafValue())->getDef();
         if (Op.Rec != InRec && !InRec->isSubClassOf("ComplexPattern"))
           I->error("Operand $" + OpName + "'s register class disagrees"
                    " between the operand and pattern");
@@ -2866,13 +2866,13 @@
 
   for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
     Record *CurPattern = Patterns[i];
-    const DagInit *Tree = CurPattern->getValueAsDag("PatternToMatch");
+    DagInit *Tree = CurPattern->getValueAsDag("PatternToMatch");
     TreePattern *Pattern = new TreePattern(CurPattern, Tree, true, *this);
 
     // Inline pattern fragments into it.
     Pattern->InlinePatternFragments();
 
-    const ListInit *LI = CurPattern->getValueAsListInit("ResultInstrs");
+    ListInit *LI = CurPattern->getValueAsListInit("ResultInstrs");
     if (LI->getSize() == 0) continue;  // no pattern.
 
     // Parse the instruction.
@@ -3184,7 +3184,7 @@
     for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
       TreePatternNode *Child = N->getChild(i);
       if (Child->isLeaf())
-        if (const DefInit *DI = dynamic_cast<const DefInit*>(Child->getLeafValue())) {
+        if (DefInit *DI = dynamic_cast<DefInit*>(Child->getLeafValue())) {
           Record *RR = DI->getDef();
           if (RR->isSubClassOf("Register"))
             continue;