From: Eric Christopher Date: Mon, 11 Jul 2011 23:06:52 +0000 (+0000) Subject: Revert r134921, 134917, 134908 and 134907. They're causing failures X-Git-Tag: android-x86-6.0-r1~944^2~199 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=d568b3f55294917d1cc701da14a8a7daeb6563e6;p=android-x86%2Fexternal-llvm.git Revert r134921, 134917, 134908 and 134907. They're causing failures in multiple buildbots. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134936 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/utils/TableGen/ARMDecoderEmitter.cpp b/utils/TableGen/ARMDecoderEmitter.cpp index 3721ed41b2a..8a5dc8ba154 100644 --- a/utils/TableGen/ARMDecoderEmitter.cpp +++ b/utils/TableGen/ARMDecoderEmitter.cpp @@ -114,7 +114,7 @@ enum { /// byteFromBitsInit - Return the byte value from a BitsInit. /// Called from getByteField(). -static uint8_t byteFromBitsInit(const BitsInit &init) { +static uint8_t byteFromBitsInit(BitsInit &init) { int width = init.getNumBits(); assert(width <= 8 && "Field is too large for uint8_t!"); @@ -125,7 +125,7 @@ static uint8_t byteFromBitsInit(const BitsInit &init) { uint8_t ret = 0; for (index = 0; index < width; index++) { - if (static_cast(init.getBit(index))->getValue()) + if (static_cast(init.getBit(index))->getValue()) ret |= mask; mask <<= 1; @@ -135,12 +135,12 @@ static uint8_t byteFromBitsInit(const BitsInit &init) { } static uint8_t getByteField(const Record &def, const char *str) { - const BitsInit *bits = def.getValueAsBitsInit(str); + BitsInit *bits = def.getValueAsBitsInit(str); return byteFromBitsInit(*bits); } -static const BitsInit &getBitsField(const Record &def, const char *str) { - const BitsInit *bits = def.getValueAsBitsInit(str); +static BitsInit &getBitsField(const Record &def, const char *str) { + BitsInit *bits = def.getValueAsBitsInit(str); return *bits; } @@ -183,15 +183,15 @@ static bool ValueNotSet(bit_value_t V) { static int Value(bit_value_t V) { return ValueNotSet(V) ? -1 : (V == BIT_FALSE ? 0 : 1); } -static bit_value_t bitFromBits(const BitsInit &bits, unsigned index) { - if (const BitInit *bit = dynamic_cast(bits.getBit(index))) +static bit_value_t bitFromBits(BitsInit &bits, unsigned index) { + if (BitInit *bit = dynamic_cast(bits.getBit(index))) return bit->getValue() ? BIT_TRUE : BIT_FALSE; // The bit is uninitialized. return BIT_UNSET; } // Prints the bit value for each position. -static void dumpBits(raw_ostream &o, const BitsInit &bits) { +static void dumpBits(raw_ostream &o, BitsInit &bits) { unsigned index; for (index = bits.getNumBits(); index > 0; index--) { @@ -424,8 +424,7 @@ protected: if (AllInstructions[Opcode]->isPseudo) return; - const BitsInit &Bits = getBitsField(*AllInstructions[Opcode]->TheDef, - "Inst"); + BitsInit &Bits = getBitsField(*AllInstructions[Opcode]->TheDef, "Inst"); for (unsigned i = 0; i < BIT_WIDTH; ++i) Insn[i] = bitFromBits(Bits, i); @@ -1559,7 +1558,7 @@ ARMDEBackend::populateInstruction(const CodeGenInstruction &CGI, const StringRef Name = Def.getName(); uint8_t Form = getByteField(Def, "Form"); - const BitsInit &Bits = getBitsField(Def, "Inst"); + BitsInit &Bits = getBitsField(Def, "Inst"); // If all the bit positions are not specified; do not decode this instruction. // We are bound to fail! For proper disassembly, the well-known encoding bits diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index 3236a199bbd..d9c3b84d6c2 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -869,7 +869,7 @@ AsmMatcherInfo::getOperandClass(const CGIOperandList::OperandInfo &OI, int SubOpIdx) { Record *Rec = OI.Rec; if (SubOpIdx != -1) - Rec = dynamic_cast(OI.MIOperandInfo->getArg(SubOpIdx))->getDef(); + Rec = dynamic_cast(OI.MIOperandInfo->getArg(SubOpIdx))->getDef(); if (Rec->isSubClassOf("RegisterOperand")) { // RegisterOperand may have an associated ParserMatchClass. If it does, @@ -879,7 +879,7 @@ AsmMatcherInfo::getOperandClass(const CGIOperandList::OperandInfo &OI, throw "Record `" + Rec->getName() + "' does not have a ParserMatchClass!\n"; - if (const DefInit *DI= dynamic_cast(R->getValue())) { + if (DefInit *DI= dynamic_cast(R->getValue())) { Record *MatchClass = DI->getDef(); if (ClassInfo *CI = AsmOperandClasses[MatchClass]) return CI; @@ -1046,9 +1046,9 @@ void AsmMatcherInfo::BuildOperandClasses() { ClassInfo *CI = AsmOperandClasses[*it]; CI->Kind = ClassInfo::UserClass0 + Index; - const ListInit *Supers = (*it)->getValueAsListInit("SuperClasses"); + ListInit *Supers = (*it)->getValueAsListInit("SuperClasses"); for (unsigned i = 0, e = Supers->getSize(); i != e; ++i) { - const DefInit *DI = dynamic_cast(Supers->getElement(i)); + DefInit *DI = dynamic_cast(Supers->getElement(i)); if (!DI) { PrintError((*it)->getLoc(), "Invalid super class reference!"); continue; @@ -1065,28 +1065,28 @@ void AsmMatcherInfo::BuildOperandClasses() { CI->ValueName = (*it)->getName(); // Get or construct the predicate method name. - const Init *PMName = (*it)->getValueInit("PredicateMethod"); - if (const StringInit *SI = dynamic_cast(PMName)) { + Init *PMName = (*it)->getValueInit("PredicateMethod"); + if (StringInit *SI = dynamic_cast(PMName)) { CI->PredicateMethod = SI->getValue(); } else { - assert(dynamic_cast(PMName) && + assert(dynamic_cast(PMName) && "Unexpected PredicateMethod field!"); CI->PredicateMethod = "is" + CI->ClassName; } // Get or construct the render method name. - const Init *RMName = (*it)->getValueInit("RenderMethod"); - if (const StringInit *SI = dynamic_cast(RMName)) { + Init *RMName = (*it)->getValueInit("RenderMethod"); + if (StringInit *SI = dynamic_cast(RMName)) { CI->RenderMethod = SI->getValue(); } else { - assert(dynamic_cast(RMName) && + assert(dynamic_cast(RMName) && "Unexpected RenderMethod field!"); CI->RenderMethod = "add" + CI->ClassName + "Operands"; } // Get the parse method name or leave it as empty. - const Init *PRMName = (*it)->getValueInit("ParserMethod"); - if (const StringInit *SI = dynamic_cast(PRMName)) + Init *PRMName = (*it)->getValueInit("ParserMethod"); + if (StringInit *SI = dynamic_cast(PRMName)) CI->ParserMethod = SI->getValue(); AsmOperandClasses[*it] = CI; diff --git a/utils/TableGen/CallingConvEmitter.cpp b/utils/TableGen/CallingConvEmitter.cpp index 37758bc1cf5..c51afd82a37 100644 --- a/utils/TableGen/CallingConvEmitter.cpp +++ b/utils/TableGen/CallingConvEmitter.cpp @@ -40,7 +40,7 @@ void CallingConvEmitter::run(raw_ostream &O) { void CallingConvEmitter::EmitCallingConv(Record *CC, raw_ostream &O) { - const ListInit *CCActions = CC->getValueAsListInit("Actions"); + ListInit *CCActions = CC->getValueAsListInit("Actions"); Counter = 0; O << "\n\nstatic bool " << CC->getName() @@ -67,7 +67,7 @@ void CallingConvEmitter::EmitAction(Record *Action, O << IndentStr << "if ("; if (Action->isSubClassOf("CCIfType")) { - const ListInit *VTs = Action->getValueAsListInit("VTs"); + ListInit *VTs = Action->getValueAsListInit("VTs"); for (unsigned i = 0, e = VTs->getSize(); i != e; ++i) { Record *VT = VTs->getElementAsRecord(i); if (i != 0) O << " ||\n " << IndentStr; @@ -91,7 +91,7 @@ void CallingConvEmitter::EmitAction(Record *Action, << "(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State))\n" << IndentStr << " return false;\n"; } else if (Action->isSubClassOf("CCAssignToReg")) { - const ListInit *RegList = Action->getValueAsListInit("RegList"); + ListInit *RegList = Action->getValueAsListInit("RegList"); if (RegList->getSize() == 1) { O << IndentStr << "if (unsigned Reg = State.AllocateReg("; O << getQualifiedName(RegList->getElementAsRecord(0)) << ")) {\n"; @@ -112,8 +112,8 @@ void CallingConvEmitter::EmitAction(Record *Action, O << IndentStr << " return false;\n"; O << IndentStr << "}\n"; } else if (Action->isSubClassOf("CCAssignToRegWithShadow")) { - const ListInit *RegList = Action->getValueAsListInit("RegList"); - const ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList"); + ListInit *RegList = Action->getValueAsListInit("RegList"); + ListInit *ShadowRegList = Action->getValueAsListInit("ShadowRegList"); if (ShadowRegList->getSize() >0 && ShadowRegList->getSize() != RegList->getSize()) throw "Invalid length of list of shadowed registers"; diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index bca4bb61c24..26bd8786a49 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -21,19 +21,17 @@ using namespace llvm; static const std::vector getValueAsListOfStrings(Record &R, StringRef FieldName) { - const ListInit *List = R.getValueAsListInit(FieldName); + ListInit *List = R.getValueAsListInit(FieldName); assert (List && "Got a null ListInit"); std::vector Strings; Strings.reserve(List->getSize()); - for (ListInit::const_iterator i = List->begin(), e = List->end(); - i != e; - ++i) { + for (ListInit::iterator i = List->begin(), e = List->end(); i != e; ++i) { assert(*i && "Got a null element in a ListInit"); - if (const StringInit *S = dynamic_cast(*i)) + if (StringInit *S = dynamic_cast(*i)) Strings.push_back(S->getValue()); - else if (const CodeInit *C = dynamic_cast(*i)) + else if (CodeInit *C = dynamic_cast(*i)) Strings.push_back(C->getValue()); else assert(false && "Got a non-string, non-code element in a ListInit"); diff --git a/utils/TableGen/ClangDiagnosticsEmitter.cpp b/utils/TableGen/ClangDiagnosticsEmitter.cpp index debed97d673..0a48e75681f 100644 --- a/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -74,8 +74,7 @@ getCategoryFromDiagGroup(const Record *Group, static std::string getDiagnosticCategory(const Record *R, DiagGroupParentMap &DiagGroupParents) { // If the diagnostic is in a group, and that group has a category, use it. - if (const DefInit *Group = - dynamic_cast(R->getValueInit("Group"))) { + if (DefInit *Group = dynamic_cast(R->getValueInit("Group"))) { // Check the diagnostic's diag group for a category. std::string CatName = getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents); @@ -160,8 +159,7 @@ void ClangDiagsDefsEmitter::run(raw_ostream &OS) { OS.write_escaped(R.getValueAsString("Text")) << '"'; // Warning associated with the diagnostic. - if (const DefInit *DI = - dynamic_cast(R.getValueInit("Group"))) { + if (DefInit *DI = dynamic_cast(R.getValueInit("Group"))) { OS << ", \""; OS.write_escaped(DI->getDef()->getValueAsString("GroupName")) << '"'; } else { @@ -227,7 +225,7 @@ void ClangDiagGroupsEmitter::run(raw_ostream &OS) { Records.getAllDerivedDefinitions("Diagnostic"); for (unsigned i = 0, e = Diags.size(); i != e; ++i) { const Record *R = Diags[i]; - const DefInit *DI = dynamic_cast(R->getValueInit("Group")); + DefInit *DI = dynamic_cast(R->getValueInit("Group")); if (DI == 0) continue; std::string GroupName = DI->getDef()->getValueAsString("GroupName"); DiagsInGroup[GroupName].DiagsInGroup.push_back(R); diff --git a/utils/TableGen/ClangSACheckersEmitter.cpp b/utils/TableGen/ClangSACheckersEmitter.cpp index fe54b3689a4..97739c6b3f4 100644 --- a/utils/TableGen/ClangSACheckersEmitter.cpp +++ b/utils/TableGen/ClangSACheckersEmitter.cpp @@ -28,8 +28,7 @@ static bool isHidden(const Record &R) { if (R.getValueAsBit("Hidden")) return true; // Not declared as hidden, check the parent package if it is hidden. - if (const DefInit *DI = - dynamic_cast(R.getValueInit("ParentPackage"))) + if (DefInit *DI = dynamic_cast(R.getValueInit("ParentPackage"))) return isHidden(*DI->getDef()); return false; @@ -43,8 +42,7 @@ static std::string getPackageFullName(const Record *R); static std::string getParentPackageFullName(const Record *R) { std::string name; - if (const DefInit *DI = - dynamic_cast(R->getValueInit("ParentPackage"))) + if (DefInit *DI = dynamic_cast(R->getValueInit("ParentPackage"))) name = getPackageFullName(DI->getDef()); return name; } @@ -65,8 +63,8 @@ static std::string getCheckerFullName(const Record *R) { } static std::string getStringValue(const Record &R, StringRef field) { - if (const StringInit * - SI = dynamic_cast(R.getValueInit(field))) + if (StringInit * + SI = dynamic_cast(R.getValueInit(field))) return SI->getValue(); return std::string(); } @@ -131,8 +129,8 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) { for (unsigned i = 0, e = checkers.size(); i != e; ++i) { Record *R = checkers[i]; Record *package = 0; - if (const DefInit * - DI = dynamic_cast(R->getValueInit("ParentPackage"))) + if (DefInit * + DI = dynamic_cast(R->getValueInit("ParentPackage"))) package = DI->getDef(); if (!isCheckerNamed(R) && !package) throw "Checker '" + R->getName() + "' is neither named, nor in a package!"; @@ -151,23 +149,21 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) { Record *currR = isCheckerNamed(R) ? R : package; // Insert the checker and its parent packages into the subgroups set of // the corresponding parent package. - while (const DefInit *DI = - dynamic_cast(currR->getValueInit("ParentPackage"))) { + while (DefInit *DI + = dynamic_cast(currR->getValueInit("ParentPackage"))) { Record *parentPackage = DI->getDef(); recordGroupMap[parentPackage]->SubGroups.insert(currR); currR = parentPackage; } // Insert the checker into the set of its group. - if (const DefInit *DI = - dynamic_cast(R->getValueInit("Group"))) + if (DefInit *DI = dynamic_cast(R->getValueInit("Group"))) recordGroupMap[DI->getDef()]->Checkers.insert(R); } // If a package is in group, add all its checkers and its sub-packages // checkers into the group. for (unsigned i = 0, e = packages.size(); i != e; ++i) - if (const DefInit *DI = - dynamic_cast(packages[i]->getValueInit("Group"))) + if (DefInit *DI = dynamic_cast(packages[i]->getValueInit("Group"))) addPackageToCheckerGroup(packages[i], DI->getDef(), recordGroupMap); typedef std::map SortedRecords; @@ -208,8 +204,7 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) { OS << "PACKAGE(" << "\""; OS.write_escaped(getPackageFullName(&R)) << "\", "; // Group index - if (const DefInit *DI = - dynamic_cast(R.getValueInit("Group"))) + if (DefInit *DI = dynamic_cast(R.getValueInit("Group"))) OS << groupToSortIndex[DI->getDef()] << ", "; else OS << "-1, "; @@ -237,8 +232,7 @@ void ClangSACheckersEmitter::run(raw_ostream &OS) { OS << "\""; OS.write_escaped(getStringValue(R, "HelpText")) << "\", "; // Group index - if (const DefInit *DI = - dynamic_cast(R.getValueInit("Group"))) + if (DefInit *DI = dynamic_cast(R.getValueInit("Group"))) OS << groupToSortIndex[DI->getDef()] << ", "; else OS << "-1, "; diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp index 3a846ef366c..d828dfc25db 100644 --- a/utils/TableGen/CodeEmitterGen.cpp +++ b/utils/TableGen/CodeEmitterGen.cpp @@ -38,25 +38,21 @@ void CodeEmitterGen::reverseBits(std::vector &Insts) { R->getValueAsBit("isPseudo")) continue; - const BitsInit *BI = R->getValueAsBitsInit("Inst"); + BitsInit *BI = R->getValueAsBitsInit("Inst"); unsigned numBits = BI->getNumBits(); - - SmallVector NewBits(numBits); - + BitsInit *NewBI = new BitsInit(numBits); for (unsigned bit = 0, end = numBits / 2; bit != end; ++bit) { unsigned bitSwapIdx = numBits - bit - 1; - const Init *OrigBit = BI->getBit(bit); - const Init *BitSwap = BI->getBit(bitSwapIdx); - NewBits[bit] = BitSwap; - NewBits[bitSwapIdx] = OrigBit; + Init *OrigBit = BI->getBit(bit); + Init *BitSwap = BI->getBit(bitSwapIdx); + NewBI->setBit(bit, BitSwap); + NewBI->setBit(bitSwapIdx, OrigBit); } if (numBits % 2) { unsigned middle = (numBits + 1) / 2; - NewBits[middle] = BI->getBit(middle); + NewBI->setBit(middle, BI->getBit(middle)); } - - const BitsInit *NewBI = BitsInit::get(NewBits.begin(), NewBits.end()); // Update the bits in reversed order so that emitInstrOpBits will get the // correct endianness. @@ -67,14 +63,12 @@ void CodeEmitterGen::reverseBits(std::vector &Insts) { // If the VarBitInit at position 'bit' matches the specified variable then // return the variable bit position. Otherwise return -1. int CodeEmitterGen::getVariableBit(const std::string &VarName, - const BitsInit *BI, int bit) { - if (const VarBitInit *VBI = - dynamic_cast(BI->getBit(bit))) { - if (const VarInit *VI = dynamic_cast(VBI->getVariable())) + BitsInit *BI, int bit) { + if (VarBitInit *VBI = dynamic_cast(BI->getBit(bit))) { + if (VarInit *VI = dynamic_cast(VBI->getVariable())) if (VI->getName() == VarName) return VBI->getBitNum(); - } else if (const VarInit *VI = - dynamic_cast(BI->getBit(bit))) { + } else if (VarInit *VI = dynamic_cast(BI->getBit(bit))) { if (VI->getName() == VarName) return 0; } @@ -83,8 +77,8 @@ int CodeEmitterGen::getVariableBit(const std::string &VarName, } void CodeEmitterGen:: -AddCodeToMergeInOperand(Record *R, const BitsInit *BI, - const std::string &VarName, unsigned &NumberedOp, +AddCodeToMergeInOperand(Record *R, BitsInit *BI, const std::string &VarName, + unsigned &NumberedOp, std::string &Case, CodeGenTarget &Target) { CodeGenInstruction &CGI = Target.getInstruction(R); @@ -187,7 +181,7 @@ std::string CodeEmitterGen::getInstructionCase(Record *R, CodeGenTarget &Target) { std::string Case; - const BitsInit *BI = R->getValueAsBitsInit("Inst"); + BitsInit *BI = R->getValueAsBitsInit("Inst"); const std::vector &Vals = R->getValues(); unsigned NumberedOp = 0; @@ -244,12 +238,12 @@ void CodeEmitterGen::run(raw_ostream &o) { continue; } - const BitsInit *BI = R->getValueAsBitsInit("Inst"); + BitsInit *BI = R->getValueAsBitsInit("Inst"); // Start by filling in fixed values. unsigned Value = 0; for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) { - if (const BitInit *B = dynamic_cast(BI->getBit(e-i-1))) + if (BitInit *B = dynamic_cast(BI->getBit(e-i-1))) Value |= B->getValue() << (e-i-1); } o << " " << Value << "U," << '\t' << "// " << R->getName() << "\n"; diff --git a/utils/TableGen/CodeEmitterGen.h b/utils/TableGen/CodeEmitterGen.h index af890bfe247..a874d970fea 100644 --- a/utils/TableGen/CodeEmitterGen.h +++ b/utils/TableGen/CodeEmitterGen.h @@ -35,11 +35,11 @@ private: void emitMachineOpEmitter(raw_ostream &o, const std::string &Namespace); void emitGetValueBit(raw_ostream &o, const std::string &Namespace); void reverseBits(std::vector &Insts); - int getVariableBit(const std::string &VarName, const BitsInit *BI, int bit); + int getVariableBit(const std::string &VarName, BitsInit *BI, int bit); std::string getInstructionCase(Record *R, CodeGenTarget &Target); void - AddCodeToMergeInOperand(Record *R, const BitsInit *BI, - const std::string &VarName, unsigned &NumberedOp, + AddCodeToMergeInOperand(Record *R, BitsInit *BI, const std::string &VarName, + unsigned &NumberedOp, std::string &Case, CodeGenTarget &Target); }; diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp index bb45cb2a296..072893fe5ab 100644 --- a/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/utils/TableGen/CodeGenDAGPatterns.cpp @@ -583,7 +583,7 @@ typedef DepVarMap::const_iterator DepVarMap_citer; static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) { if (N->isLeaf()) { - if (dynamic_cast(N->getLeafValue()) != NULL) + if (dynamic_cast(N->getLeafValue()) != NULL) DepMap[N->getName()]++; } else { for (size_t i = 0, e = N->getNumChildren(); i != e; ++i) @@ -692,7 +692,7 @@ static unsigned getPatternSize(const TreePatternNode *P, 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(P->getLeafValue())) + if (P->isLeaf() && dynamic_cast(P->getLeafValue())) Size += 2; // FIXME: This is a hack to statically increase the priority of patterns @@ -716,7 +716,7 @@ static unsigned getPatternSize(const TreePatternNode *P, Child->getType(0) != MVT::Other) Size += getPatternSize(Child, CGP); else if (Child->isLeaf()) { - if (dynamic_cast(Child->getLeafValue())) + if (dynamic_cast(Child->getLeafValue())) Size += 5; // Matches a ConstantSDNode (+3) and a specific value (+2). else if (Child->getComplexPatternInfo(CGP)) Size += getPatternSize(Child, CGP); @@ -742,8 +742,7 @@ getPatternComplexity(const CodeGenDAGPatterns &CGP) const { std::string PatternToMatch::getPredicateCheck() const { std::string PredicateCheck; for (unsigned i = 0, e = Predicates->getSize(); i != e; ++i) { - if (const DefInit *Pred = - dynamic_cast(Predicates->getElement(i))) { + if (DefInit *Pred = dynamic_cast(Predicates->getElement(i))) { Record *Def = Pred->getDef(); if (!Def->isSubClassOf("Predicate")) { #ifndef NDEBUG @@ -867,13 +866,12 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N, // 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(NodeToApply->getLeafValue()) || - !static_cast(NodeToApply->getLeafValue())->getDef() + !dynamic_cast(NodeToApply->getLeafValue()) || + !static_cast(NodeToApply->getLeafValue())->getDef() ->isSubClassOf("ValueType")) TP.error(N->getOperator()->getName() + " expects a VT operand!"); MVT::SimpleValueType VT = - getValueType(static_cast(NodeToApply->getLeafValue()) - ->getDef()); + getValueType(static_cast(NodeToApply->getLeafValue())->getDef()); EEVT::TypeSet TypeListTmp(VT, TP); @@ -1023,10 +1021,10 @@ static unsigned GetNumNodeResults(Record *Operator, CodeGenDAGPatterns &CDP) { 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(Tree->getOperator())) - Op = dynamic_cast(Tree->getOperator())->getDef(); + if (Tree && dynamic_cast(Tree->getOperator())) + Op = dynamic_cast(Tree->getOperator())->getDef(); assert(Op && "Invalid Fragment"); return GetNumNodeResults(Op, CDP); } @@ -1100,8 +1098,8 @@ bool TreePatternNode::isIsomorphicTo(const TreePatternNode *N, return false; if (isLeaf()) { - if (const DefInit *DI = dynamic_cast(getLeafValue())) { - if (const DefInit *NDI = dynamic_cast(N->getLeafValue())) { + if (DefInit *DI = dynamic_cast(getLeafValue())) { + if (DefInit *NDI = dynamic_cast(N->getLeafValue())) { return ((DI->getDef() == NDI->getDef()) && (DepVars.find(getName()) == DepVars.end() || getName() == N->getName())); @@ -1157,9 +1155,9 @@ SubstituteFormalArguments(std::map &ArgMap) { for (unsigned i = 0, e = getNumChildren(); i != e; ++i) { TreePatternNode *Child = getChild(i); if (Child->isLeaf()) { - const Init *Val = Child->getLeafValue(); - if (dynamic_cast(Val) && - static_cast(Val)->getDef()->getName() == "node") { + Init *Val = Child->getLeafValue(); + if (dynamic_cast(Val) && + static_cast(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!"); @@ -1321,7 +1319,7 @@ getIntrinsicInfo(const CodeGenDAGPatterns &CDP) const { return 0; unsigned IID = - dynamic_cast(getChild(0)->getLeafValue())->getValue(); + dynamic_cast(getChild(0)->getLeafValue())->getValue(); return &CDP.getIntrinsicInfo(IID); } @@ -1331,7 +1329,7 @@ const ComplexPattern * TreePatternNode::getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const { if (!isLeaf()) return 0; - const DefInit *DI = dynamic_cast(getLeafValue()); + DefInit *DI = dynamic_cast(getLeafValue()); if (DI && DI->getDef()->isSubClassOf("ComplexPattern")) return &CGP.getComplexPattern(DI->getDef()); return 0; @@ -1384,7 +1382,7 @@ TreePatternNode::isCommutativeIntrinsic(const CodeGenDAGPatterns &CDP) const { bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) { CodeGenDAGPatterns &CDP = TP.getDAGPatterns(); if (isLeaf()) { - if (const DefInit *DI = dynamic_cast(getLeafValue())) { + if (DefInit *DI = dynamic_cast(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) @@ -1393,7 +1391,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) { return MadeChange; } - if (const IntInit *II = dynamic_cast(getLeafValue())) { + if (IntInit *II = dynamic_cast(getLeafValue())) { assert(Types.size() == 1 && "Invalid IntInit"); // Int inits are always integers. :) @@ -1653,7 +1651,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) { static bool OnlyOnRHSOfCommutative(TreePatternNode *N) { if (!N->isLeaf() && N->getOperator()->getName() == "imm") return true; - if (N->isLeaf() && dynamic_cast(N->getLeafValue())) + if (N->isLeaf() && dynamic_cast(N->getLeafValue())) return true; return false; } @@ -1703,14 +1701,14 @@ bool TreePatternNode::canPatternMatch(std::string &Reason, // 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, "")); @@ -1741,17 +1739,16 @@ void TreePattern::ComputeNamedNodes(TreePatternNode *N) { } -TreePatternNode *TreePattern::ParseTreePattern(const Init *TheInit, - StringRef OpName){ - if (const DefInit *DI = dynamic_cast(TheInit)) { +TreePatternNode *TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName){ + if (DefInit *DI = dynamic_cast(TheInit)) { Record *R = DI->getDef(); // Direct reference to a leaf DagNode or PatFrag? Turn it into a // TreePatternNode of its own. For example: /// (foo GPR, imm) -> (foo GPR, (imm)) if (R->isSubClassOf("SDNode") || R->isSubClassOf("PatFrag")) - return ParseTreePattern(DagInit::get(DI, "", - std::vector >()), + return ParseTreePattern(new DagInit(DI, "", + std::vector >()), OpName); // Input argument? @@ -1766,26 +1763,26 @@ TreePatternNode *TreePattern::ParseTreePattern(const Init *TheInit, return Res; } - if (const IntInit *II = dynamic_cast(TheInit)) { + if (IntInit *II = dynamic_cast(TheInit)) { if (!OpName.empty()) error("Constant int argument should not have a name!"); return new TreePatternNode(II, 1); } - if (const BitsInit *BI = dynamic_cast(TheInit)) { + if (BitsInit *BI = dynamic_cast(TheInit)) { // Turn this into an IntInit. - const Init *II = BI->convertInitializerTo(new IntRecTy()); - if (II == 0 || !dynamic_cast(II)) + Init *II = BI->convertInitializerTo(new IntRecTy()); + if (II == 0 || !dynamic_cast(II)) error("Bits value must be constants!"); return ParseTreePattern(II, OpName); } - const DagInit *Dag = dynamic_cast(TheInit); + DagInit *Dag = dynamic_cast(TheInit); if (!Dag) { TheInit->dump(); error("Pattern has unexpected init kind!"); } - const DefInit *OpDef = dynamic_cast(Dag->getOperator()); + DefInit *OpDef = dynamic_cast(Dag->getOperator()); if (!OpDef) error("Pattern has unexpected operator type!"); Record *Operator = OpDef->getDef(); @@ -1863,7 +1860,7 @@ TreePatternNode *TreePattern::ParseTreePattern(const Init *TheInit, else // Otherwise, no chain. Operator = getDAGPatterns().get_intrinsic_wo_chain_sdnode(); - TreePatternNode *IIDNode = new TreePatternNode(IntInit::get(IID), 1); + TreePatternNode *IIDNode = new TreePatternNode(new IntInit(IID), 1); Children.insert(Children.begin(), IIDNode); } @@ -1950,8 +1947,7 @@ InferAllTypes(const StringMap > *InNamedTypes) { // 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(Nodes[i]->getLeafValue()); + DefInit *DI = dynamic_cast(Nodes[i]->getLeafValue()); if (DI && (DI->getDef()->isSubClassOf("RegisterClass") || DI->getDef()->isSubClassOf("RegisterOperand"))) continue; @@ -2100,7 +2096,7 @@ void CodeGenDAGPatterns::ParsePatternFragments() { // 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; @@ -2112,8 +2108,8 @@ void CodeGenDAGPatterns::ParsePatternFragments() { 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(OpsList->getOperator()); + DagInit *OpsList = Fragments[i]->getValueAsDag("Operands"); + DefInit *OpsOp = dynamic_cast(OpsList->getOperator()); // Special cases: ops == outs == ins. Different names are used to // improve readability. if (!OpsOp || @@ -2125,8 +2121,8 @@ void CodeGenDAGPatterns::ParsePatternFragments() { // Copy over the arguments. Args.clear(); for (unsigned j = 0, e = OpsList->getNumArgs(); j != e; ++j) { - if (!dynamic_cast(OpsList->getArg(j)) || - static_cast(OpsList->getArg(j))-> + if (!dynamic_cast(OpsList->getArg(j)) || + static_cast(OpsList->getArg(j))-> getDef()->getName() != "node") P->error("Operands list should all be 'node' values."); if (OpsList->getArgName(j).empty()) @@ -2184,19 +2180,19 @@ void CodeGenDAGPatterns::ParseDefaultOperands() { // Find some SDNode. assert(!SDNodes.empty() && "No SDNodes parsed?"); - const Init *SomeSDNode = DefInit::get(SDNodes.begin()->first); + Init *SomeSDNode = new DefInit(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 > Ops; + std::vector > 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 = new DagInit(SomeSDNode, "", Ops); // Create a TreePattern to parse this. TreePattern P(DefaultOps[iter][i], DI, false, *this); @@ -2235,7 +2231,7 @@ static bool HandleUse(TreePattern *I, TreePatternNode *Pat, // No name -> not interesting. if (Pat->getName().empty()) { if (Pat->isLeaf()) { - const DefInit *DI = dynamic_cast(Pat->getLeafValue()); + DefInit *DI = dynamic_cast(Pat->getLeafValue()); if (DI && (DI->getDef()->isSubClassOf("RegisterClass") || DI->getDef()->isSubClassOf("RegisterOperand"))) I->error("Input " + DI->getDef()->getName() + " must be named!"); @@ -2245,7 +2241,7 @@ static bool HandleUse(TreePattern *I, TreePatternNode *Pat, Record *Rec; if (Pat->isLeaf()) { - const DefInit *DI = dynamic_cast(Pat->getLeafValue()); + DefInit *DI = dynamic_cast(Pat->getLeafValue()); if (!DI) I->error("Input $" + Pat->getName() + " must be an identifier!"); Rec = DI->getDef(); } else { @@ -2263,7 +2259,7 @@ static bool HandleUse(TreePattern *I, TreePatternNode *Pat, } Record *SlotRec; if (Slot->isLeaf()) { - SlotRec = dynamic_cast(Slot->getLeafValue())->getDef(); + SlotRec = dynamic_cast(Slot->getLeafValue())->getDef(); } else { assert(Slot->getNumChildren() == 0 && "can't be a use with children!"); SlotRec = Slot->getOperator(); @@ -2298,7 +2294,7 @@ FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat, if (!Dest->isLeaf()) I->error("implicitly defined value should be a register!"); - const DefInit *Val = dynamic_cast(Dest->getLeafValue()); + DefInit *Val = dynamic_cast(Dest->getLeafValue()); if (!Val || !Val->getDef()->isSubClassOf("Register")) I->error("implicitly defined value should be a register!"); InstImpResults.push_back(Val->getDef()); @@ -2339,7 +2335,7 @@ FindPatternInputsAndOutputs(TreePattern *I, TreePatternNode *Pat, if (!Dest->isLeaf()) I->error("set destination should be a register!"); - const DefInit *Val = dynamic_cast(Dest->getLeafValue()); + DefInit *Val = dynamic_cast(Dest->getLeafValue()); if (!Val) I->error("set destination should be a register!"); @@ -2405,7 +2401,7 @@ private: return false; const TreePatternNode *N0 = N->getChild(0); - if (!N0->isLeaf() || !dynamic_cast(N0->getLeafValue())) + if (!N0->isLeaf() || !dynamic_cast(N0->getLeafValue())) return false; const TreePatternNode *N1 = N->getChild(1); @@ -2422,7 +2418,7 @@ private: void AnalyzeNode(const TreePatternNode *N) { if (N->isLeaf()) { - if (const DefInit *DI = dynamic_cast(N->getLeafValue())) { + if (DefInit *DI = dynamic_cast(N->getLeafValue())) { Record *LeafRec = DI->getDef(); // Handle ComplexPattern leaves. if (LeafRec->isSubClassOf("ComplexPattern")) { @@ -2529,9 +2525,9 @@ void CodeGenDAGPatterns::ParseInstructions() { std::vector Instrs = Records.getAllDerivedDefinitions("Instruction"); for (unsigned i = 0, e = Instrs.size(); i != e; ++i) { - const ListInit *LI = 0; + ListInit *LI = 0; - if (dynamic_cast(Instrs[i]->getValueInit("Pattern"))) + if (dynamic_cast(Instrs[i]->getValueInit("Pattern"))) LI = Instrs[i]->getValueAsListInit("Pattern"); // If there is no pattern, only collect minimal information about the @@ -2623,7 +2619,7 @@ void CodeGenDAGPatterns::ParseInstructions() { if (i == 0) Res0Node = RNode; - Record *R = dynamic_cast(RNode->getLeafValue())->getDef(); + Record *R = dynamic_cast(RNode->getLeafValue())->getDef(); if (R == 0) I->error("Operand $" + OpName + " should be a set destination: all " "outputs must occur before inputs in operand list!"); @@ -2668,8 +2664,8 @@ void CodeGenDAGPatterns::ParseInstructions() { InstInputsCheck.erase(OpName); // It occurred, remove from map. if (InVal->isLeaf() && - dynamic_cast(InVal->getLeafValue())) { - Record *InRec = static_cast(InVal->getLeafValue())->getDef(); + dynamic_cast(InVal->getLeafValue())) { + Record *InRec = static_cast(InVal->getLeafValue())->getDef(); if (Op.Rec != InRec && !InRec->isSubClassOf("ComplexPattern")) I->error("Operand $" + OpName + "'s register class disagrees" " between the operand and pattern"); @@ -2869,13 +2865,13 @@ void CodeGenDAGPatterns::ParsePatterns() { 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. @@ -3187,8 +3183,7 @@ static void GenerateVariantsOf(TreePatternNode *N, for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) { TreePatternNode *Child = N->getChild(i); if (Child->isLeaf()) - if (const DefInit *DI = - dynamic_cast(Child->getLeafValue())) { + if (DefInit *DI = dynamic_cast(Child->getLeafValue())) { Record *RR = DI->getDef(); if (RR->isSubClassOf("Register")) continue; diff --git a/utils/TableGen/CodeGenDAGPatterns.h b/utils/TableGen/CodeGenDAGPatterns.h index 6e1eb085c0c..e4e8574bbca 100644 --- a/utils/TableGen/CodeGenDAGPatterns.h +++ b/utils/TableGen/CodeGenDAGPatterns.h @@ -26,7 +26,7 @@ namespace llvm { class Record; - class Init; + struct Init; class ListInit; class DagInit; class SDNodeInfo; @@ -306,7 +306,7 @@ class TreePatternNode { /// Val - The init value (e.g. the "GPRC" record, or "7") for a leaf. /// - const Init *Val; + Init *Val; /// Name - The name given to this node with the :$foo notation. /// @@ -327,7 +327,7 @@ public: : Operator(Op), Val(0), TransformFn(0), Children(Ch) { Types.resize(NumResults); } - TreePatternNode(const Init *val, unsigned NumResults) // leaf ctor + TreePatternNode(Init *val, unsigned NumResults) // leaf ctor : Operator(0), Val(val), TransformFn(0) { Types.resize(NumResults); } @@ -358,7 +358,7 @@ public: return Types[ResNo].isDynamicallyResolved(); } - const Init *getLeafValue() const { assert(isLeaf()); return Val; } + Init *getLeafValue() const { assert(isLeaf()); return Val; } Record *getOperator() const { assert(!isLeaf()); return Operator; } unsigned getNumChildren() const { return Children.size(); } @@ -517,9 +517,9 @@ public: /// TreePattern constructor - Parse the specified DagInits into the /// current record. - TreePattern(Record *TheRec, const ListInit *RawPat, bool isInput, + TreePattern(Record *TheRec, ListInit *RawPat, bool isInput, CodeGenDAGPatterns &ise); - TreePattern(Record *TheRec, const DagInit *Pat, bool isInput, + TreePattern(Record *TheRec, DagInit *Pat, bool isInput, CodeGenDAGPatterns &ise); TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput, CodeGenDAGPatterns &ise); @@ -576,7 +576,7 @@ public: void dump() const; private: - TreePatternNode *ParseTreePattern(const Init *DI, StringRef OpName); + TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName); void ComputeNamedNodes(); void ComputeNamedNodes(TreePatternNode *N); }; @@ -631,7 +631,7 @@ public: /// processed to produce isel. class PatternToMatch { public: - PatternToMatch(Record *srcrecord, const ListInit *preds, + PatternToMatch(Record *srcrecord, ListInit *preds, TreePatternNode *src, TreePatternNode *dst, const std::vector &dstregs, unsigned complexity, unsigned uid) @@ -639,7 +639,7 @@ public: Dstregs(dstregs), AddedComplexity(complexity), ID(uid) {} Record *SrcRecord; // Originating Record for the pattern. - const ListInit *Predicates; // Top level predicate conditions to match. + ListInit *Predicates; // Top level predicate conditions to match. TreePatternNode *SrcPattern; // Source pattern to match. TreePatternNode *DstPattern; // Resulting pattern. std::vector Dstregs; // Physical register defs being matched. @@ -647,7 +647,7 @@ public: unsigned ID; // Unique ID for the record. Record *getSrcRecord() const { return SrcRecord; } - const ListInit *getPredicates() const { return Predicates; } + ListInit *getPredicates() const { return Predicates; } TreePatternNode *getSrcPattern() const { return SrcPattern; } TreePatternNode *getDstPattern() const { return DstPattern; } const std::vector &getDstRegs() const { return Dstregs; } diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp index c723c36617e..d1e63a9bd8f 100644 --- a/utils/TableGen/CodeGenInstruction.cpp +++ b/utils/TableGen/CodeGenInstruction.cpp @@ -30,10 +30,9 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { hasOptionalDef = false; isVariadic = false; - const DagInit *OutDI = R->getValueAsDag("OutOperandList"); + DagInit *OutDI = R->getValueAsDag("OutOperandList"); - if (const DefInit *Init = - dynamic_cast(OutDI->getOperator())) { + if (DefInit *Init = dynamic_cast(OutDI->getOperator())) { if (Init->getDef()->getName() != "outs") throw R->getName() + ": invalid def name for output list: use 'outs'"; } else @@ -41,8 +40,8 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { NumDefs = OutDI->getNumArgs(); - const DagInit *InDI = R->getValueAsDag("InOperandList"); - if (const DefInit *Init = dynamic_cast(InDI->getOperator())) { + DagInit *InDI = R->getValueAsDag("InOperandList"); + if (DefInit *Init = dynamic_cast(InDI->getOperator())) { if (Init->getDef()->getName() != "ins") throw R->getName() + ": invalid def name for input list: use 'ins'"; } else @@ -51,7 +50,7 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { unsigned MIOperandNo = 0; std::set OperandNames; for (unsigned i = 0, e = InDI->getNumArgs()+OutDI->getNumArgs(); i != e; ++i){ - const Init *ArgInit; + Init *ArgInit; std::string ArgName; if (i < NumDefs) { ArgInit = OutDI->getArg(i); @@ -61,7 +60,7 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { ArgName = InDI->getArgName(i-NumDefs); } - const DefInit *Arg = dynamic_cast(ArgInit); + DefInit *Arg = dynamic_cast(ArgInit); if (!Arg) throw "Illegal operand for the '" + R->getName() + "' instruction!"; @@ -69,7 +68,7 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { std::string PrintMethod = "printOperand"; std::string EncoderMethod; unsigned NumOps = 1; - const DagInit *MIOpInfo = 0; + DagInit *MIOpInfo = 0; if (Rec->isSubClassOf("RegisterOperand")) { PrintMethod = Rec->getValueAsString("PrintMethod"); } else if (Rec->isSubClassOf("Operand")) { @@ -79,8 +78,8 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { MIOpInfo = Rec->getValueAsDag("MIOperandInfo"); // Verify that MIOpInfo has an 'ops' root value. - if (!dynamic_cast(MIOpInfo->getOperator()) || - dynamic_cast(MIOpInfo->getOperator()) + if (!dynamic_cast(MIOpInfo->getOperator()) || + dynamic_cast(MIOpInfo->getOperator()) ->getDef()->getName() != "ops") throw "Bad value for MIOperandInfo in operand '" + Rec->getName() + "'\n"; @@ -179,7 +178,7 @@ CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) { } // Find the suboperand number involved. - const DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo; + DagInit *MIOpInfo = OperandList[OpIdx].MIOperandInfo; if (MIOpInfo == 0) throw TheDef->getName() + ": unknown suboperand name in '" + Op + "'"; @@ -401,13 +400,12 @@ FlattenAsmStringVariants(StringRef Cur, unsigned Variant) { /// constructor. It checks if an argument in an InstAlias pattern matches /// the corresponding operand of the instruction. It returns true on a /// successful match, with ResOp set to the result operand to be used. -bool CodeGenInstAlias::tryAliasOpMatch(const DagInit *Result, - unsigned AliasOpNo, +bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo, Record *InstOpRec, bool hasSubOps, SMLoc Loc, CodeGenTarget &T, ResultOperand &ResOp) { - const Init *Arg = Result->getArg(AliasOpNo); - const DefInit *ADI = dynamic_cast(Arg); + Init *Arg = Result->getArg(AliasOpNo); + DefInit *ADI = dynamic_cast(Arg); if (ADI && ADI->getDef() == InstOpRec) { // If the operand is a record, it must have a name, and the record type @@ -453,7 +451,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(const DagInit *Result, return true; } - if (const IntInit *II = dynamic_cast(Arg)) { + if (IntInit *II = dynamic_cast(Arg)) { if (hasSubOps || !InstOpRec->isSubClassOf("Operand")) return false; // Integer arguments can't have names. @@ -472,7 +470,7 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T) : TheDef(R) { Result = R->getValueAsDag("ResultInst"); // Verify that the root of the result is an instruction. - const DefInit *DI = dynamic_cast(Result->getOperator()); + DefInit *DI = dynamic_cast(Result->getOperator()); if (DI == 0 || !DI->getDef()->isSubClassOf("Instruction")) throw TGError(R->getLoc(), "result of inst alias should be an instruction"); @@ -482,7 +480,7 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T) : TheDef(R) { // the same class. StringMap NameClass; for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) { - const DefInit *ADI = dynamic_cast(Result->getArg(i)); + DefInit *ADI = dynamic_cast(Result->getArg(i)); if (!ADI || Result->getArgName(i).empty()) continue; // Verify we don't have something like: (someinst GR16:$foo, GR32:$foo) @@ -521,12 +519,11 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T) : TheDef(R) { // If the argument did not match the instruction operand, and the operand // is composed of multiple suboperands, try matching the suboperands. if (NumSubOps > 1) { - const DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo; + DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo; for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) { if (AliasOpNo >= Result->getNumArgs()) throw TGError(R->getLoc(), "not enough arguments for instruction!"); - Record *SubRec = - dynamic_cast(MIOI->getArg(SubOp))->getDef(); + Record *SubRec = dynamic_cast(MIOI->getArg(SubOp))->getDef(); if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false, R->getLoc(), T, ResOp)) { ResultOperands.push_back(ResOp); diff --git a/utils/TableGen/CodeGenInstruction.h b/utils/TableGen/CodeGenInstruction.h index 797be7c612a..e00b631247d 100644 --- a/utils/TableGen/CodeGenInstruction.h +++ b/utils/TableGen/CodeGenInstruction.h @@ -94,7 +94,7 @@ namespace llvm { /// MIOperandInfo - Default MI operand type. Note an operand may be made /// up of multiple MI operands. - const DagInit *MIOperandInfo; + DagInit *MIOperandInfo; /// Constraint info for this operand. This operand can have pieces, so we /// track constraint info for each. @@ -102,7 +102,7 @@ namespace llvm { OperandInfo(Record *R, const std::string &N, const std::string &PMN, const std::string &EMN, unsigned MION, unsigned MINO, - const DagInit *MIOI) + DagInit *MIOI) : Rec(R), Name(N), PrinterMethodName(PMN), EncoderMethodName(EMN), MIOperandNo(MION), MINumOperands(MINO), MIOperandInfo(MIOI) {} @@ -265,7 +265,7 @@ namespace llvm { std::string AsmString; /// Result - The result instruction. - const DagInit *Result; + DagInit *Result; /// ResultInst - The instruction generated by the alias (decoded from /// Result). @@ -311,7 +311,7 @@ namespace llvm { CodeGenInstAlias(Record *R, CodeGenTarget &T); - bool tryAliasOpMatch(const DagInit *Result, unsigned AliasOpNo, + bool tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo, Record *InstOpRec, bool hasSubOps, SMLoc Loc, CodeGenTarget &T, ResultOperand &ResOp); }; diff --git a/utils/TableGen/CodeGenRegisters.cpp b/utils/TableGen/CodeGenRegisters.cpp index b73c2715018..1acf3a85b60 100644 --- a/utils/TableGen/CodeGenRegisters.cpp +++ b/utils/TableGen/CodeGenRegisters.cpp @@ -91,15 +91,14 @@ CodeGenRegister::getSubRegs(CodeGenRegBank &RegBank) { } // Process the composites. - const ListInit *Comps = TheDef->getValueAsListInit("CompositeIndices"); + ListInit *Comps = TheDef->getValueAsListInit("CompositeIndices"); for (unsigned i = 0, e = Comps->size(); i != e; ++i) { - const DagInit *Pat = dynamic_cast(Comps->getElement(i)); + DagInit *Pat = dynamic_cast(Comps->getElement(i)); if (!Pat) throw TGError(TheDef->getLoc(), "Invalid dag '" + Comps->getElement(i)->getAsString() + "' in CompositeIndices"); - const DefInit *BaseIdxInit = - dynamic_cast(Pat->getOperator()); + DefInit *BaseIdxInit = dynamic_cast(Pat->getOperator()); if (!BaseIdxInit || !BaseIdxInit->getDef()->isSubClassOf("SubRegIndex")) throw TGError(TheDef->getLoc(), "Invalid SubClassIndex in " + Pat->getAsString()); @@ -108,7 +107,7 @@ CodeGenRegister::getSubRegs(CodeGenRegBank &RegBank) { CodeGenRegister *R2 = this; for (DagInit::const_arg_iterator di = Pat->arg_begin(), de = Pat->arg_end(); di != de; ++di) { - const DefInit *IdxInit = dynamic_cast(*di); + DefInit *IdxInit = dynamic_cast(*di); if (!IdxInit || !IdxInit->getDef()->isSubClassOf("SubRegIndex")) throw TGError(TheDef->getLoc(), "Invalid SubClassIndex in " + Pat->getAsString()); @@ -164,7 +163,7 @@ struct TupleExpander : SetTheory::Expander { void expand(SetTheory &ST, Record *Def, SetTheory::RecSet &Elts) { std::vector Indices = Def->getValueAsListOfDefs("SubRegIndices"); unsigned Dim = Indices.size(); - const ListInit *SubRegs = Def->getValueAsListInit("SubRegs"); + ListInit *SubRegs = Def->getValueAsListInit("SubRegs"); if (Dim != SubRegs->getSize()) throw TGError(Def->getLoc(), "SubRegIndices and SubRegs size mismatch"); if (Dim < 2) @@ -184,19 +183,19 @@ struct TupleExpander : SetTheory::Expander { // Precompute some types. Record *RegisterCl = Def->getRecords().getClass("Register"); RecTy *RegisterRecTy = new RecordRecTy(RegisterCl); - const StringInit *BlankName = StringInit::get(""); + StringInit *BlankName = new StringInit(""); // Zip them up. for (unsigned n = 0; n != Length; ++n) { std::string Name; Record *Proto = Lists[0][n]; - std::vector Tuple; + std::vector Tuple; unsigned CostPerUse = 0; for (unsigned i = 0; i != Dim; ++i) { Record *Reg = Lists[i][n]; if (i) Name += '_'; Name += Reg->getName(); - Tuple.push_back(DefInit::get(Reg)); + Tuple.push_back(new DefInit(Reg)); CostPerUse = std::max(CostPerUse, unsigned(Reg->getValueAsInt("CostPerUse"))); } @@ -217,7 +216,7 @@ struct TupleExpander : SetTheory::Expander { // Replace the sub-register list with Tuple. if (RV.getName() == "SubRegs") - RV.setValue(ListInit::get(Tuple, RegisterRecTy)); + RV.setValue(new ListInit(Tuple, RegisterRecTy)); // Provide a blank AsmName. MC hacks are required anyway. if (RV.getName() == "AsmName") @@ -225,7 +224,7 @@ struct TupleExpander : SetTheory::Expander { // CostPerUse is aggregated from all Tuple members. if (RV.getName() == "CostPerUse") - RV.setValue(IntInit::get(CostPerUse)); + RV.setValue(new IntInit(CostPerUse)); // Copy fields from the RegisterTuples def. if (RV.getName() == "SubRegIndices" || @@ -279,7 +278,7 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank, Record *R) Members.insert(RegBank.getReg((*Elements)[i])); // Alternative allocation orders may be subsets. - const ListInit *Alts = R->getValueAsListInit("AltOrders"); + ListInit *Alts = R->getValueAsListInit("AltOrders"); AltOrders.resize(Alts->size()); SetTheory::RecSet Order; for (unsigned i = 0, e = Alts->size(); i != e; ++i) { @@ -296,11 +295,11 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank, Record *R) } // SubRegClasses is a list containing (RC, subregindex, ...) dags. - const ListInit *SRC = R->getValueAsListInit("SubRegClasses"); + ListInit *SRC = R->getValueAsListInit("SubRegClasses"); for (ListInit::const_iterator i = SRC->begin(), e = SRC->end(); i != e; ++i) { - const DagInit *DAG = dynamic_cast(*i); + DagInit *DAG = dynamic_cast(*i); if (!DAG) throw "SubRegClasses must contain DAGs"; - const DefInit *DAGOp = dynamic_cast(DAG->getOperator()); + DefInit *DAGOp = dynamic_cast(DAG->getOperator()); Record *RCRec; if (!DAGOp || !(RCRec = DAGOp->getDef())->isSubClassOf("RegisterClass")) throw "Operator '" + DAG->getOperator()->getAsString() + @@ -308,7 +307,7 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank, Record *R) // Iterate over args, all SubRegIndex instances. for (DagInit::const_arg_iterator ai = DAG->arg_begin(), ae = DAG->arg_end(); ai != ae; ++ai) { - const DefInit *Idx = dynamic_cast(*ai); + DefInit *Idx = dynamic_cast(*ai); Record *IdxRec; if (!Idx || !(IdxRec = Idx->getDef())->isSubClassOf("SubRegIndex")) throw "Argument '" + (*ai)->getAsString() + diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp index ceaa82fa05b..929791c3182 100644 --- a/utils/TableGen/CodeGenTarget.cpp +++ b/utils/TableGen/CodeGenTarget.cpp @@ -402,7 +402,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) { // Parse the list of return types. std::vector OverloadedVTs; - const ListInit *TypeList = R->getValueAsListInit("RetTypes"); + ListInit *TypeList = R->getValueAsListInit("RetTypes"); for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { Record *TyEl = TypeList->getElementAsRecord(i); assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); @@ -470,7 +470,7 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R) { } // Parse the intrinsic properties. - const ListInit *PropList = R->getValueAsListInit("Properties"); + ListInit *PropList = R->getValueAsListInit("Properties"); for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) { Record *Property = PropList->getElementAsRecord(i); assert(Property->isSubClassOf("IntrinsicProperty") && diff --git a/utils/TableGen/DAGISelMatcherGen.cpp b/utils/TableGen/DAGISelMatcherGen.cpp index 1c841252e93..c5897c72d36 100644 --- a/utils/TableGen/DAGISelMatcherGen.cpp +++ b/utils/TableGen/DAGISelMatcherGen.cpp @@ -203,7 +203,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) { assert(N->isLeaf() && "Not a leaf?"); // Direct match against an integer constant. - if (const IntInit *II = dynamic_cast(N->getLeafValue())) { + if (IntInit *II = dynamic_cast(N->getLeafValue())) { // If this is the root of the dag we're matching, we emit a redundant opcode // check to ensure that this gets folded into the normal top-level // OpcodeSwitch. @@ -215,7 +215,7 @@ void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) { return AddMatcher(new CheckIntegerMatcher(II->getValue())); } - const DefInit *DI = dynamic_cast(N->getLeafValue()); + DefInit *DI = dynamic_cast(N->getLeafValue()); if (DI == 0) { errs() << "Unknown leaf kind: " << *DI << "\n"; abort(); @@ -283,8 +283,7 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode *N, N->getOperator()->getName() == "or") && N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateFns().empty() && N->getPredicateFns().empty()) { - if (const IntInit *II = - dynamic_cast(N->getChild(1)->getLeafValue())) { + if (IntInit *II = dynamic_cast(N->getChild(1)->getLeafValue())) { if (!isPowerOf2_32(II->getValue())) { // Don't bother with single bits. // If this is at the root of the pattern, we emit a redundant // CheckOpcode so that the following checks get factored properly under @@ -497,7 +496,7 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) { --RecNodeEntry; // Entries in VariableMap are biased. const ComplexPattern &CP = - CGP.getComplexPattern(((const DefInit*)N->getLeafValue())->getDef()); + CGP.getComplexPattern(((DefInit*)N->getLeafValue())->getDef()); // Emit a CheckComplexPat operation, which does the match (aborting if it // fails) and pushes the matched operands onto the recorded nodes list. @@ -573,14 +572,14 @@ void MatcherGen::EmitResultLeafAsOperand(const TreePatternNode *N, SmallVectorImpl &ResultOps) { assert(N->isLeaf() && "Must be a leaf"); - if (const IntInit *II = dynamic_cast(N->getLeafValue())) { + if (IntInit *II = dynamic_cast(N->getLeafValue())) { AddMatcher(new EmitIntegerMatcher(II->getValue(), N->getType(0))); ResultOps.push_back(NextRecordedOperandNo++); return; } // If this is an explicit register reference, handle it. - if (const DefInit *DI = dynamic_cast(N->getLeafValue())) { + if (DefInit *DI = dynamic_cast(N->getLeafValue())) { Record *Def = DI->getDef(); if (Def->isSubClassOf("Register")) { const CodeGenRegister *Reg = diff --git a/utils/TableGen/FastISelEmitter.cpp b/utils/TableGen/FastISelEmitter.cpp index 2a86b896c0c..f54e8df40f2 100644 --- a/utils/TableGen/FastISelEmitter.cpp +++ b/utils/TableGen/FastISelEmitter.cpp @@ -241,7 +241,7 @@ struct OperandsSignature { if (Op->getType(0) != VT) return false; - const DefInit *OpDI = dynamic_cast(Op->getLeafValue()); + DefInit *OpDI = dynamic_cast(Op->getLeafValue()); if (!OpDI) return false; Record *OpLeafRec = OpDI->getDef(); @@ -401,12 +401,12 @@ static std::string PhyRegForNode(TreePatternNode *Op, if (!Op->isLeaf()) return PhysReg; - const DefInit *OpDI = dynamic_cast(Op->getLeafValue()); + DefInit *OpDI = dynamic_cast(Op->getLeafValue()); Record *OpLeafRec = OpDI->getDef(); if (!OpLeafRec->isSubClassOf("Register")) return PhysReg; - PhysReg += static_cast(OpLeafRec->getValue( \ + PhysReg += static_cast(OpLeafRec->getValue( \ "Namespace")->getValue())->getValue(); PhysReg += "::"; PhysReg += Target.getRegBank().getReg(OpLeafRec)->getName(); @@ -468,7 +468,7 @@ void FastISelMap::collectPatterns(CodeGenDAGPatterns &CGP) { // a bit too complicated for now. if (!Dst->getChild(1)->isLeaf()) continue; - const DefInit *SR = dynamic_cast(Dst->getChild(1)->getLeafValue()); + DefInit *SR = dynamic_cast(Dst->getChild(1)->getLeafValue()); if (SR) SubRegNo = getQualifiedName(SR->getDef()); else diff --git a/utils/TableGen/FixedLenDecoderEmitter.cpp b/utils/TableGen/FixedLenDecoderEmitter.cpp index e4b6f128919..c9dcb01de00 100644 --- a/utils/TableGen/FixedLenDecoderEmitter.cpp +++ b/utils/TableGen/FixedLenDecoderEmitter.cpp @@ -48,15 +48,15 @@ static bool ValueNotSet(bit_value_t V) { static int Value(bit_value_t V) { return ValueNotSet(V) ? -1 : (V == BIT_FALSE ? 0 : 1); } -static bit_value_t bitFromBits(const BitsInit &bits, unsigned index) { - if (const BitInit *bit = dynamic_cast(bits.getBit(index))) +static bit_value_t bitFromBits(BitsInit &bits, unsigned index) { + if (BitInit *bit = dynamic_cast(bits.getBit(index))) return bit->getValue() ? BIT_TRUE : BIT_FALSE; // The bit is uninitialized. return BIT_UNSET; } // Prints the bit value for each position. -static void dumpBits(raw_ostream &o, const BitsInit &bits) { +static void dumpBits(raw_ostream &o, BitsInit &bits) { unsigned index; for (index = bits.getNumBits(); index > 0; index--) { @@ -76,8 +76,8 @@ static void dumpBits(raw_ostream &o, const BitsInit &bits) { } } -static const BitsInit &getBitsField(const Record &def, const char *str) { - const BitsInit *bits = def.getValueAsBitsInit(str); +static BitsInit &getBitsField(const Record &def, const char *str) { + BitsInit *bits = def.getValueAsBitsInit(str); return *bits; } @@ -279,8 +279,7 @@ public: protected: // Populates the insn given the uid. void insnWithID(insn_t &Insn, unsigned Opcode) const { - const BitsInit &Bits = - getBitsField(*AllInstructions[Opcode]->TheDef, "Inst"); + BitsInit &Bits = getBitsField(*AllInstructions[Opcode]->TheDef, "Inst"); for (unsigned i = 0; i < BIT_WIDTH; ++i) Insn[i] = bitFromBits(Bits, i); @@ -1231,7 +1230,7 @@ bool FixedLenDecoderEmitter::populateInstruction(const CodeGenInstruction &CGI, Def.getValueAsBit("isCodeGenOnly")) return false; - const BitsInit &Bits = getBitsField(Def, "Inst"); + BitsInit &Bits = getBitsField(Def, "Inst"); if (Bits.allInComplete()) return false; std::vector InsnOperands; @@ -1252,16 +1251,16 @@ bool FixedLenDecoderEmitter::populateInstruction(const CodeGenInstruction &CGI, // Gather the outputs/inputs of the instruction, so we can find their // positions in the encoding. This assumes for now that they appear in the // MCInst in the order that they're listed. - std::vector > InOutOperands; - const DagInit *Out = Def.getValueAsDag("OutOperandList"); - const DagInit *In = Def.getValueAsDag("InOperandList"); + std::vector > InOutOperands; + DagInit *Out = Def.getValueAsDag("OutOperandList"); + DagInit *In = Def.getValueAsDag("InOperandList"); for (unsigned i = 0; i < Out->getNumArgs(); ++i) InOutOperands.push_back(std::make_pair(Out->getArg(i), Out->getArgName(i))); for (unsigned i = 0; i < In->getNumArgs(); ++i) InOutOperands.push_back(std::make_pair(In->getArg(i), In->getArgName(i))); // For each operand, see if we can figure out where it is encoded. - for (std::vector >::iterator + for (std::vector >::iterator NI = InOutOperands.begin(), NE = InOutOperands.end(); NI != NE; ++NI) { unsigned PrevBit = ~0; unsigned Base = ~0; @@ -1269,10 +1268,10 @@ bool FixedLenDecoderEmitter::populateInstruction(const CodeGenInstruction &CGI, std::string Decoder = ""; for (unsigned bi = 0; bi < Bits.getNumBits(); ++bi) { - const VarBitInit *BI = dynamic_cast(Bits.getBit(bi)); + VarBitInit *BI = dynamic_cast(Bits.getBit(bi)); if (!BI) continue; - const VarInit *Var = dynamic_cast(BI->getVariable()); + VarInit *Var = dynamic_cast(BI->getVariable()); assert(Var); unsigned CurrBit = BI->getBitNum(); if (Var->getName() != NI->second) continue; @@ -1302,7 +1301,7 @@ bool FixedLenDecoderEmitter::populateInstruction(const CodeGenInstruction &CGI, // for decoding register classes. // FIXME: This need to be extended to handle instructions with custom // decoder methods, and operands with (simple) MIOperandInfo's. - const TypedInit *TI = dynamic_cast(NI->first); + TypedInit *TI = dynamic_cast(NI->first); RecordRecTy *Type = dynamic_cast(TI->getType()); Record *TypeRecord = Type->getRecord(); bool isReg = false; @@ -1314,8 +1313,8 @@ bool FixedLenDecoderEmitter::populateInstruction(const CodeGenInstruction &CGI, } RecordVal *DecoderString = TypeRecord->getValue("DecoderMethod"); - const StringInit *String = DecoderString ? - dynamic_cast(DecoderString->getValue()) : + StringInit *String = DecoderString ? + dynamic_cast(DecoderString->getValue()) : 0; if (!isReg && String && String->getValue() != "") Decoder = String->getValue(); diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp index 3dcdeaa9115..18d4db080a2 100644 --- a/utils/TableGen/InstrInfoEmitter.cpp +++ b/utils/TableGen/InstrInfoEmitter.cpp @@ -61,7 +61,7 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { // registers in their multi-operand operands. It may also be an anonymous // operand, which has a single operand, but no declared class for the // operand. - const DagInit *MIOI = Inst.Operands[i].MIOperandInfo; + DagInit *MIOI = Inst.Operands[i].MIOperandInfo; if (!MIOI || MIOI->getNumArgs() == 0) { // Single, anonymous, operand. @@ -70,7 +70,7 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) { OperandList.push_back(Inst.Operands[i]); - Record *OpR = dynamic_cast(MIOI->getArg(j))->getDef(); + Record *OpR = dynamic_cast(MIOI->getArg(j))->getDef(); OperandList.back().Rec = OpR; } } @@ -288,11 +288,11 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, if (Inst.hasExtraDefRegAllocReq) OS << "|(1<getValueAsBitsInit("TSFlags"); + BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags"); if (!TSF) throw "no TSFlags?"; uint64_t Value = 0; for (unsigned i = 0, e = TSF->getNumBits(); i != e; ++i) { - if (const BitInit *Bit = dynamic_cast(TSF->getBit(i))) + if (BitInit *Bit = dynamic_cast(TSF->getBit(i))) Value |= uint64_t(Bit->getValue()) << i; else throw "Invalid TSFlags bit in " + Inst.TheDef->getName(); diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 91803309cb0..090faf50855 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -245,7 +245,7 @@ struct OptionDescription { unsigned Flags; std::string Help; unsigned MultiVal; - const Init* InitVal; + Init* InitVal; OptionDescription(OptionType::OptionType t = OptionType::Switch, const std::string& n = "", @@ -589,7 +589,7 @@ Handler GetHandler(FunctionObject* Obj, const DagInit& Dag) { } template -void InvokeDagInitHandler(FunctionObject* Obj, const Init* I) { +void InvokeDagInitHandler(FunctionObject* Obj, Init* I) { typedef void (FunctionObject::*Handler) (const DagInit&); const DagInit& Dag = InitPtrToDag(I); @@ -658,7 +658,7 @@ public: /// operator() - Just forwards to the corresponding property /// handler. - void operator() (const Init* I) { + void operator() (Init* I) { InvokeDagInitHandler(this, I); } @@ -705,10 +705,10 @@ private: void onInit (const DagInit& d) { CheckNumberOfArguments(d, 1); - const Init* i = d.getArg(0); + Init* i = d.getArg(0); const std::string& str = i->getAsString(); - bool correct = optDesc_.isParameter() && dynamic_cast(i); + bool correct = optDesc_.isParameter() && dynamic_cast(i); correct |= (optDesc_.isSwitch() && (str == "true" || str == "false")); if (!correct) @@ -821,7 +821,7 @@ void CollectOptionDescriptions (const RecordVector& V, for (RecordVector::const_iterator B = V.begin(), E = V.end(); B!=E; ++B) { // Throws an exception if the value does not exist. - const ListInit* PropList = (*B)->getValueAsListInit("options"); + ListInit* PropList = (*B)->getValueAsListInit("options"); // For every option description in this list: invoke AddOption. std::for_each(PropList->begin(), PropList->end(), AddOption(OptDescs)); @@ -836,8 +836,8 @@ namespace ToolFlags { struct ToolDescription : public RefCountedBase { std::string Name; - const Init* CmdLine; - const Init* Actions; + Init* CmdLine; + Init* Actions; StrVector InLanguage; std::string InFileOption; std::string OutFileOption; @@ -903,7 +903,7 @@ public: } } - void operator() (const Init* I) { + void operator() (Init* I) { InvokeDagInitHandler(this, I); } @@ -915,9 +915,9 @@ private: void onActions (const DagInit& d) { CheckNumberOfArguments(d, 1); - const Init* Case = d.getArg(0); + Init* Case = d.getArg(0); if (typeid(*Case) != typeid(DagInit) || - GetOperatorName(static_cast(*Case)) != "case") + GetOperatorName(static_cast(*Case)) != "case") throw "The argument to (actions) should be a 'case' construct!"; toolDesc_.Actions = Case; } @@ -954,7 +954,7 @@ private: isReallyJoin = true; } else { - const Init* I = d.getArg(0); + Init* I = d.getArg(0); isReallyJoin = InitPtrToBool(I); } @@ -1007,7 +1007,7 @@ void CollectToolDescriptions (const RecordVector& Tools, E = Tools.end(); B!=E; ++B) { const Record* T = *B; // Throws an exception if the value does not exist. - const ListInit* PropList = T->getValueAsListInit("properties"); + ListInit* PropList = T->getValueAsListInit("properties"); IntrusiveRefCntPtr ToolDesc(new ToolDescription(T->getName())); @@ -1163,7 +1163,7 @@ void WalkCase(const Init* Case, F1 TestCallback, F2 StatementCallback, unsigned i = 1; for (DagInit::const_arg_iterator B = d.arg_begin(), E = d.arg_end(); B != E; ++B) { - const Init* arg = *B; + Init* arg = *B; if (!even) { @@ -1181,8 +1181,8 @@ void WalkCase(const Init* Case, F1 TestCallback, F2 StatementCallback, } else { - if (dynamic_cast(arg) - && GetOperatorName(static_cast(*arg)) == "case") { + if (dynamic_cast(arg) + && GetOperatorName(static_cast(*arg)) == "case") { // Nested 'case'. WalkCase(arg, TestCallback, StatementCallback, IndentLevel + Indent1); } @@ -1210,7 +1210,7 @@ class ExtractOptionNames { ActionName == "parameter_equals" || ActionName == "element_in_list") { CheckNumberOfArguments(Stmt, 1); - const Init* Arg = Stmt.getArg(0); + Init* Arg = Stmt.getArg(0); if (typeid(*Arg) == typeid(StringInit)) OptionNames_.insert(InitPtrToString(Arg)); } @@ -1218,7 +1218,7 @@ class ExtractOptionNames { ActionName == "any_not_empty" || ActionName == "any_empty" || ActionName == "not_empty" || ActionName == "empty") { for (unsigned i = 0, NumArgs = Stmt.getNumArgs(); i < NumArgs; ++i) { - const Init* Arg = Stmt.getArg(i); + Init* Arg = Stmt.getArg(i); if (typeid(*Arg) == typeid(StringInit)) OptionNames_.insert(InitPtrToString(Arg)); } @@ -2613,7 +2613,7 @@ void EmitPreprocessOptions (const RecordKeeper& Records, for (RecordVector::const_iterator B = OptionPreprocessors.begin(), E = OptionPreprocessors.end(); B!=E; ++B) { - const DagInit* Case = (*B)->getValueAsDag("preprocessor"); + DagInit* Case = (*B)->getValueAsDag("preprocessor"); EmitCaseConstructHandler(Case, Indent1, EmitPreprocessOptionsCallback(OptDecs), false, OptDecs, O); @@ -2645,7 +2645,7 @@ public: } } - void operator() (const Init* I) { + void operator() (Init* I) { InvokeDagInitHandler(this, I); } @@ -2655,7 +2655,7 @@ private: CheckNumberOfArguments(d, 2); const std::string& Lang = InitPtrToString(d.getArg(0)); - const Init* Suffixes = d.getArg(1); + Init* Suffixes = d.getArg(1); // Second argument to lang_to_suffixes is either a single string... if (typeid(*Suffixes) == typeid(StringInit)) { @@ -2688,7 +2688,7 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, raw_ostream& O) // Call DoEmitPopulateLanguageMap. for (RecordVector::const_iterator B = LangMaps.begin(), E = LangMaps.end(); B!=E; ++B) { - const ListInit* LangMap = (*B)->getValueAsListInit("map"); + ListInit* LangMap = (*B)->getValueAsListInit("map"); std::for_each(LangMap->begin(), LangMap->end(), DoEmitPopulateLanguageMap(O)); } @@ -2947,7 +2947,7 @@ void FillInHookNames(const ToolDescriptions& ToolDescs, // Look for hook invocations in 'cmd_line'. if (!D.CmdLine) continue; - if (dynamic_cast(D.CmdLine)) + if (dynamic_cast(D.CmdLine)) // This is a string. ExtractHookNames(HookNames, OptDescs).operator()(D.CmdLine); else diff --git a/utils/TableGen/OptParserEmitter.cpp b/utils/TableGen/OptParserEmitter.cpp index f4d7be52db9..431026c669c 100644 --- a/utils/TableGen/OptParserEmitter.cpp +++ b/utils/TableGen/OptParserEmitter.cpp @@ -56,7 +56,7 @@ static int CompareOptionRecords(const void *Av, const void *Bv) { static const std::string getOptionName(const Record &R) { // Use the record name unless EnumName is defined. - if (dynamic_cast(R.getValueInit("EnumName"))) + if (dynamic_cast(R.getValueInit("EnumName"))) return R.getName(); return R.getValueAsString("EnumName"); @@ -105,7 +105,7 @@ void OptParserEmitter::run(raw_ostream &OS) { // The containing option group (if any). OS << ", "; - if (const DefInit *DI = dynamic_cast(R.getValueInit("Group"))) + if (const DefInit *DI = dynamic_cast(R.getValueInit("Group"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; @@ -114,7 +114,7 @@ void OptParserEmitter::run(raw_ostream &OS) { OS << ", INVALID, 0, 0"; // The option help text. - if (!dynamic_cast(R.getValueInit("HelpText"))) { + if (!dynamic_cast(R.getValueInit("HelpText"))) { OS << ",\n"; OS << " "; write_cstring(OS, R.getValueAsString("HelpText")); @@ -145,14 +145,14 @@ void OptParserEmitter::run(raw_ostream &OS) { // The containing option group (if any). OS << ", "; - if (const DefInit *DI = dynamic_cast(R.getValueInit("Group"))) + if (const DefInit *DI = dynamic_cast(R.getValueInit("Group"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; // The option alias (if any). OS << ", "; - if (const DefInit *DI = dynamic_cast(R.getValueInit("Alias"))) + if (const DefInit *DI = dynamic_cast(R.getValueInit("Alias"))) OS << getOptionName(*DI->getDef()); else OS << "INVALID"; @@ -166,7 +166,7 @@ void OptParserEmitter::run(raw_ostream &OS) { for (unsigned i = 0, e = LI->size(); i != e; ++i) { if (i) OS << " | "; - OS << dynamic_cast(LI->getElement(i))->getDef()->getName(); + OS << dynamic_cast(LI->getElement(i))->getDef()->getName(); } } @@ -174,7 +174,7 @@ void OptParserEmitter::run(raw_ostream &OS) { OS << ", " << R.getValueAsInt("NumArgs"); // The option help text. - if (!dynamic_cast(R.getValueInit("HelpText"))) { + if (!dynamic_cast(R.getValueInit("HelpText"))) { OS << ",\n"; OS << " "; write_cstring(OS, R.getValueAsString("HelpText")); @@ -183,7 +183,7 @@ void OptParserEmitter::run(raw_ostream &OS) { // The option meta-variable name. OS << ", "; - if (!dynamic_cast(R.getValueInit("MetaVarName"))) + if (!dynamic_cast(R.getValueInit("MetaVarName"))) write_cstring(OS, R.getValueAsString("MetaVarName")); else OS << "0"; diff --git a/utils/TableGen/PseudoLoweringEmitter.cpp b/utils/TableGen/PseudoLoweringEmitter.cpp index 6f89e01fa2c..db33c1f7f68 100644 --- a/utils/TableGen/PseudoLoweringEmitter.cpp +++ b/utils/TableGen/PseudoLoweringEmitter.cpp @@ -24,11 +24,11 @@ using namespace llvm; // a single dag, so we can do fancier things. unsigned PseudoLoweringEmitter:: -addDagOperandMapping(Record *Rec, const DagInit *Dag, CodeGenInstruction &Insn, +addDagOperandMapping(Record *Rec, DagInit *Dag, CodeGenInstruction &Insn, IndexedMap &OperandMap, unsigned BaseIdx) { unsigned OpsAdded = 0; for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) { - if (const DefInit *DI = dynamic_cast(Dag->getArg(i))) { + if (DefInit *DI = dynamic_cast(Dag->getArg(i))) { // Physical register reference. Explicit check for the special case // "zero_reg" definition. if (DI->getDef()->isSubClassOf("Register") || @@ -54,13 +54,11 @@ addDagOperandMapping(Record *Rec, const DagInit *Dag, CodeGenInstruction &Insn, for (unsigned I = 0, E = Insn.Operands[i].MINumOperands; I != E; ++I) OperandMap[BaseIdx + i + I].Kind = OpData::Operand; OpsAdded += Insn.Operands[i].MINumOperands; - } else if (const IntInit *II = - dynamic_cast(Dag->getArg(i))) { + } else if (IntInit *II = dynamic_cast(Dag->getArg(i))) { OperandMap[BaseIdx + i].Kind = OpData::Imm; OperandMap[BaseIdx + i].Data.Imm = II->getValue(); ++OpsAdded; - } else if (const DagInit *SubDag = - dynamic_cast(Dag->getArg(i))) { + } else if (DagInit *SubDag = dynamic_cast(Dag->getArg(i))) { // Just add the operands recursively. This is almost certainly // a constant value for a complex operand (> 1 MI operand). unsigned NewOps = @@ -79,11 +77,11 @@ void PseudoLoweringEmitter::evaluateExpansion(Record *Rec) { // Validate that the result pattern has the corrent number and types // of arguments for the instruction it references. - const DagInit *Dag = Rec->getValueAsDag("ResultInst"); + DagInit *Dag = Rec->getValueAsDag("ResultInst"); assert(Dag && "Missing result instruction in pseudo expansion!"); DEBUG(dbgs() << " Result: " << *Dag << "\n"); - const DefInit *OpDef = dynamic_cast(Dag->getOperator()); + DefInit *OpDef = dynamic_cast(Dag->getOperator()); if (!OpDef) throw TGError(Rec->getLoc(), Rec->getName() + " has unexpected operator type!"); diff --git a/utils/TableGen/PseudoLoweringEmitter.h b/utils/TableGen/PseudoLoweringEmitter.h index 6e526381874..2749280e6a9 100644 --- a/utils/TableGen/PseudoLoweringEmitter.h +++ b/utils/TableGen/PseudoLoweringEmitter.h @@ -47,7 +47,7 @@ class PseudoLoweringEmitter : public TableGenBackend { SmallVector Expansions; - unsigned addDagOperandMapping(Record *Rec, const DagInit *Dag, + unsigned addDagOperandMapping(Record *Rec, DagInit *Dag, CodeGenInstruction &Insn, IndexedMap &OperandMap, unsigned BaseIdx); diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index a3738065083..730eca1b3ca 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -15,8 +15,6 @@ #include "Error.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Format.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" using namespace llvm; @@ -27,7 +25,7 @@ using namespace llvm; void RecTy::dump() const { print(errs()); } -const Init *BitRecTy::convertValue(const BitsInit *BI) { +Init *BitRecTy::convertValue(BitsInit *BI) { if (BI->getNumBits() != 1) return 0; // Only accept if just one bit! return BI->getBit(0); } @@ -36,14 +34,14 @@ bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const { return RHS->getNumBits() == 1; } -const Init *BitRecTy::convertValue(const IntInit *II) { +Init *BitRecTy::convertValue(IntInit *II) { int64_t Val = II->getValue(); if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit! - return BitInit::get(Val != 0); + return new BitInit(Val != 0); } -const Init *BitRecTy::convertValue(const TypedInit *VI) { +Init *BitRecTy::convertValue(TypedInit *VI) { if (dynamic_cast(VI->getType())) return VI; // Accept variable if it is already of bit type! return 0; @@ -53,21 +51,19 @@ std::string BitsRecTy::getAsString() const { return "bits<" + utostr(Size) + ">"; } -const Init *BitsRecTy::convertValue(const UnsetInit *UI) { - SmallVector Bits(Size); +Init *BitsRecTy::convertValue(UnsetInit *UI) { + BitsInit *Ret = new BitsInit(Size); for (unsigned i = 0; i != Size; ++i) - Bits[i] = UnsetInit::get(); - - return BitsInit::get(Bits.begin(), Bits.end()); + Ret->setBit(i, new UnsetInit()); + return Ret; } -const Init *BitsRecTy::convertValue(const BitInit *UI) { +Init *BitsRecTy::convertValue(BitInit *UI) { if (Size != 1) return 0; // Can only convert single bit. - - const Init *Bits[1] = { UI }; - - return BitsInit::get(Bits, array_endof(Bits)); + BitsInit *Ret = new BitsInit(1); + Ret->setBit(0, UI); + return Ret; } /// canFitInBitfield - Return true if the number of bits is large enough to hold @@ -78,85 +74,82 @@ static bool canFitInBitfield(int64_t Value, unsigned NumBits) { (Value >> NumBits == 0) || (Value >> (NumBits-1) == -1); } -/// convertValue from Int initializer to bits type: Split the integer -/// up into the appropriate bits. +/// convertValue from Int initializer to bits type: Split the integer up into the +/// appropriate bits. /// -const Init *BitsRecTy::convertValue(const IntInit *II) { +Init *BitsRecTy::convertValue(IntInit *II) { int64_t Value = II->getValue(); // Make sure this bitfield is large enough to hold the integer value. if (!canFitInBitfield(Value, Size)) return 0; - SmallVector Bits(Size); - + BitsInit *Ret = new BitsInit(Size); for (unsigned i = 0; i != Size; ++i) - Bits[i] = BitInit::get(Value & (1LL << i)); + Ret->setBit(i, new BitInit(Value & (1LL << i))); - return BitsInit::get(Bits.begin(), Bits.end()); + return Ret; } -const Init *BitsRecTy::convertValue(const BitsInit *BI) { +Init *BitsRecTy::convertValue(BitsInit *BI) { // If the number of bits is right, return it. Otherwise we need to expand or // truncate. if (BI->getNumBits() == Size) return BI; return 0; } -const Init *BitsRecTy::convertValue(const TypedInit *VI) { +Init *BitsRecTy::convertValue(TypedInit *VI) { if (BitsRecTy *BRT = dynamic_cast(VI->getType())) if (BRT->Size == Size) { - SmallVector Bits(Size); - + BitsInit *Ret = new BitsInit(Size); for (unsigned i = 0; i != Size; ++i) - Bits[i] = VarBitInit::get(VI, i); - return BitsInit::get(Bits.begin(), Bits.end()); + Ret->setBit(i, new VarBitInit(VI, i)); + return Ret; } if (Size == 1 && dynamic_cast(VI->getType())) { - const Init *Bits[1] = { VI }; - - return BitsInit::get(Bits, array_endof(Bits)); + BitsInit *Ret = new BitsInit(1); + Ret->setBit(0, VI); + return Ret; } - if (const TernOpInit *Tern = dynamic_cast(VI)) { + if (TernOpInit *Tern = dynamic_cast(VI)) { if (Tern->getOpcode() == TernOpInit::IF) { - const Init *LHS = Tern->getLHS(); - const Init *MHS = Tern->getMHS(); - const Init *RHS = Tern->getRHS(); + Init *LHS = Tern->getLHS(); + Init *MHS = Tern->getMHS(); + Init *RHS = Tern->getRHS(); - const IntInit *MHSi = dynamic_cast(MHS); - const IntInit *RHSi = dynamic_cast(RHS); + IntInit *MHSi = dynamic_cast(MHS); + IntInit *RHSi = dynamic_cast(RHS); if (MHSi && RHSi) { int64_t MHSVal = MHSi->getValue(); int64_t RHSVal = RHSi->getValue(); if (canFitInBitfield(MHSVal, Size) && canFitInBitfield(RHSVal, Size)) { - SmallVector NewBits(Size); + BitsInit *Ret = new BitsInit(Size); for (unsigned i = 0; i != Size; ++i) - NewBits[i] = - TernOpInit::get(TernOpInit::IF, LHS, - IntInit::get((MHSVal & (1LL << i)) ? 1 : 0), - IntInit::get((RHSVal & (1LL << i)) ? 1 : 0), - VI->getType()); - - return BitsInit::get(NewBits.begin(), NewBits.end()); + Ret->setBit(i, new TernOpInit(TernOpInit::IF, LHS, + new IntInit((MHSVal & (1LL << i)) ? 1 : 0), + new IntInit((RHSVal & (1LL << i)) ? 1 : 0), + VI->getType())); + + return Ret; } } else { - const BitsInit *MHSbs = dynamic_cast(MHS); - const BitsInit *RHSbs = dynamic_cast(RHS); + BitsInit *MHSbs = dynamic_cast(MHS); + BitsInit *RHSbs = dynamic_cast(RHS); if (MHSbs && RHSbs) { - SmallVector NewBits(Size); + BitsInit *Ret = new BitsInit(Size); for (unsigned i = 0; i != Size; ++i) - NewBits[i] = TernOpInit::get(TernOpInit::IF, LHS, - MHSbs->getBit(i), - RHSbs->getBit(i), - VI->getType()); + Ret->setBit(i, new TernOpInit(TernOpInit::IF, LHS, + MHSbs->getBit(i), + RHSbs->getBit(i), + VI->getType())); - return BitsInit::get(NewBits.begin(), NewBits.end()); + return Ret; } } } @@ -165,54 +158,54 @@ const Init *BitsRecTy::convertValue(const TypedInit *VI) { return 0; } -const Init *IntRecTy::convertValue(const BitInit *BI) { - return IntInit::get(BI->getValue()); +Init *IntRecTy::convertValue(BitInit *BI) { + return new IntInit(BI->getValue()); } -const Init *IntRecTy::convertValue(const BitsInit *BI) { +Init *IntRecTy::convertValue(BitsInit *BI) { int64_t Result = 0; for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) - if (const BitInit *Bit = dynamic_cast(BI->getBit(i))) { + if (BitInit *Bit = dynamic_cast(BI->getBit(i))) { Result |= Bit->getValue() << i; } else { return 0; } - return IntInit::get(Result); + return new IntInit(Result); } -const Init *IntRecTy::convertValue(const TypedInit *TI) { +Init *IntRecTy::convertValue(TypedInit *TI) { if (TI->getType()->typeIsConvertibleTo(this)) return TI; // Accept variable if already of the right type! return 0; } -const Init *StringRecTy::convertValue(const UnOpInit *BO) { +Init *StringRecTy::convertValue(UnOpInit *BO) { if (BO->getOpcode() == UnOpInit::CAST) { - const Init *L = BO->getOperand()->convertInitializerTo(this); + Init *L = BO->getOperand()->convertInitializerTo(this); if (L == 0) return 0; if (L != BO->getOperand()) - return UnOpInit::get(UnOpInit::CAST, L, new StringRecTy); + return new UnOpInit(UnOpInit::CAST, L, new StringRecTy); return BO; } - return convertValue((const TypedInit*)BO); + return convertValue((TypedInit*)BO); } -const Init *StringRecTy::convertValue(const BinOpInit *BO) { +Init *StringRecTy::convertValue(BinOpInit *BO) { if (BO->getOpcode() == BinOpInit::STRCONCAT) { - const Init *L = BO->getLHS()->convertInitializerTo(this); - const Init *R = BO->getRHS()->convertInitializerTo(this); + Init *L = BO->getLHS()->convertInitializerTo(this); + Init *R = BO->getRHS()->convertInitializerTo(this); if (L == 0 || R == 0) return 0; if (L != BO->getLHS() || R != BO->getRHS()) - return BinOpInit::get(BinOpInit::STRCONCAT, L, R, new StringRecTy); + return new BinOpInit(BinOpInit::STRCONCAT, L, R, new StringRecTy); return BO; } - return convertValue((const TypedInit*)BO); + return convertValue((TypedInit*)BO); } -const Init *StringRecTy::convertValue(const TypedInit *TI) { +Init *StringRecTy::convertValue(TypedInit *TI) { if (dynamic_cast(TI->getType())) return TI; // Accept variable if already of the right type! return 0; @@ -222,13 +215,13 @@ std::string ListRecTy::getAsString() const { return "list<" + Ty->getAsString() + ">"; } -const Init *ListRecTy::convertValue(const ListInit *LI) { - std::vector Elements; +Init *ListRecTy::convertValue(ListInit *LI) { + std::vector Elements; // Verify that all of the elements of the list are subclasses of the // appropriate class! for (unsigned i = 0, e = LI->getSize(); i != e; ++i) - if (const Init *CI = LI->getElement(i)->convertInitializerTo(Ty)) + if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty)) Elements.push_back(CI); else return 0; @@ -238,10 +231,10 @@ const Init *ListRecTy::convertValue(const ListInit *LI) { return 0; } - return ListInit::get(Elements, new ListRecTy(Ty)); + return new ListInit(Elements, new ListRecTy(Ty)); } -const Init *ListRecTy::convertValue(const TypedInit *TI) { +Init *ListRecTy::convertValue(TypedInit *TI) { // Ensure that TI is compatible with our class. if (ListRecTy *LRT = dynamic_cast(TI->getType())) if (LRT->getElementType()->typeIsConvertibleTo(getElementType())) @@ -249,36 +242,36 @@ const Init *ListRecTy::convertValue(const TypedInit *TI) { return 0; } -const Init *CodeRecTy::convertValue(const TypedInit *TI) { +Init *CodeRecTy::convertValue(TypedInit *TI) { if (TI->getType()->typeIsConvertibleTo(this)) return TI; return 0; } -const Init *DagRecTy::convertValue(const TypedInit *TI) { +Init *DagRecTy::convertValue(TypedInit *TI) { if (TI->getType()->typeIsConvertibleTo(this)) return TI; return 0; } -const Init *DagRecTy::convertValue(const UnOpInit *BO) { +Init *DagRecTy::convertValue(UnOpInit *BO) { if (BO->getOpcode() == UnOpInit::CAST) { - const Init *L = BO->getOperand()->convertInitializerTo(this); + Init *L = BO->getOperand()->convertInitializerTo(this); if (L == 0) return 0; if (L != BO->getOperand()) - return UnOpInit::get(UnOpInit::CAST, L, new DagRecTy); + return new UnOpInit(UnOpInit::CAST, L, new DagRecTy); return BO; } return 0; } -const Init *DagRecTy::convertValue(const BinOpInit *BO) { +Init *DagRecTy::convertValue(BinOpInit *BO) { if (BO->getOpcode() == BinOpInit::CONCAT) { - const Init *L = BO->getLHS()->convertInitializerTo(this); - const Init *R = BO->getRHS()->convertInitializerTo(this); + Init *L = BO->getLHS()->convertInitializerTo(this); + Init *R = BO->getRHS()->convertInitializerTo(this); if (L == 0 || R == 0) return 0; if (L != BO->getLHS() || R != BO->getRHS()) - return BinOpInit::get(BinOpInit::CONCAT, L, R, new DagRecTy); + return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy); return BO; } return 0; @@ -288,14 +281,14 @@ std::string RecordRecTy::getAsString() const { return Rec->getName(); } -const Init *RecordRecTy::convertValue(const DefInit *DI) { +Init *RecordRecTy::convertValue(DefInit *DI) { // Ensure that DI is a subclass of Rec. if (!DI->getDef()->isSubClassOf(Rec)) return 0; return DI; } -const Init *RecordRecTy::convertValue(const TypedInit *TI) { +Init *RecordRecTy::convertValue(TypedInit *TI) { // Ensure that TI is compatible with Rec. if (RecordRecTy *RRT = dynamic_cast(TI->getType())) if (RRT->getRecord()->isSubClassOf(getRecord()) || @@ -374,59 +367,25 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) { // Initializer implementations //===----------------------------------------------------------------------===// -FoldingSet Init::UniqueInits; -BumpPtrAllocator Init::InitAllocator; - void Init::dump() const { return print(errs()); } -const UnsetInit *UnsetInit::get() { - FoldingSetNodeID ID; - ID.AddInteger(initUnset); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - UnsetInit *I = InitAllocator.Allocate(); - new (I) UnsetInit(ID); - UniqueInits.InsertNode(I, IP); - return I; -} - -const BitInit *BitInit::get(bool V) { - FoldingSetNodeID ID; - ID.AddInteger(initBit); - ID.AddBoolean(V); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - BitInit *I = InitAllocator.Allocate(); - new (I) BitInit(ID, V); - UniqueInits.InsertNode(I, IP); - return I; -} - -const Init * -BitsInit::convertInitializerBitRange(const std::vector &Bits) const { - SmallVector NewBits(Bits.size()); - +Init *BitsInit::convertInitializerBitRange(const std::vector &Bits) { + BitsInit *BI = new BitsInit(Bits.size()); for (unsigned i = 0, e = Bits.size(); i != e; ++i) { if (Bits[i] >= getNumBits()) { + delete BI; return 0; } - NewBits[i] = getBit(Bits[i]); + BI->setBit(i, getBit(Bits[i])); } - - return BitsInit::get(NewBits.begin(), NewBits.end()); + return BI; } std::string BitsInit::getAsString() const { std::string Result = "{ "; for (unsigned i = 0, e = getNumBits(); i != e; ++i) { if (i) Result += ", "; - if (const Init *Bit = getBit(e-i-1)) + if (Init *Bit = getBit(e-i-1)) Result += Bit->getAsString(); else Result += "*"; @@ -437,141 +396,70 @@ std::string BitsInit::getAsString() const { // resolveReferences - If there are any field references that refer to fields // that have been filled in, we can propagate the values now. // -const Init *BitsInit::resolveReferences(Record &R, - const RecordVal *RV) const { +Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) { bool Changed = false; + BitsInit *New = new BitsInit(getNumBits()); - SmallVector Bits(getNumBits()); - - for (unsigned i = 0, e = getNumBits(); i != e; ++i) { - const Init *B; - const Init *CurBit = getBit(i); + for (unsigned i = 0, e = Bits.size(); i != e; ++i) { + Init *B; + Init *CurBit = getBit(i); do { B = CurBit; CurBit = CurBit->resolveReferences(R, RV); Changed |= B != CurBit; } while (B != CurBit); - Bits[i] = CurBit; + New->setBit(i, CurBit); } if (Changed) - return BitsInit::get(Bits.begin(), Bits.end()); - + return New; + delete New; return this; } -const IntInit *IntInit::get(int64_t V) { - FoldingSetNodeID ID; - ID.AddInteger(initInt); - ID.AddInteger(V); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - IntInit *I = InitAllocator.Allocate(); - new (I) IntInit(ID, V); - UniqueInits.InsertNode(I, IP); - return I; -} - std::string IntInit::getAsString() const { return itostr(Value); } -const Init * -IntInit::convertInitializerBitRange(const std::vector &Bits) const { - SmallVector NewBits(Bits.size()); +Init *IntInit::convertInitializerBitRange(const std::vector &Bits) { + BitsInit *BI = new BitsInit(Bits.size()); for (unsigned i = 0, e = Bits.size(); i != e; ++i) { - if (Bits[i] >= 64) + if (Bits[i] >= 64) { + delete BI; return 0; - - NewBits[i] = BitInit::get(Value & (INT64_C(1) << Bits[i])); - } - - return BitsInit::get(NewBits.begin(), NewBits.end()); -} - -const StringInit *StringInit::get(const std::string &V) { - FoldingSetNodeID ID; - ID.AddInteger(initString); - ID.AddString(V); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - StringInit *I = InitAllocator.Allocate(); - new (I) StringInit(ID, V); - UniqueInits.InsertNode(I, IP); - return I; -} - -const CodeInit *CodeInit::get(const std::string &V) { - FoldingSetNodeID ID; - ID.AddInteger(initCode); - ID.AddString(V); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - CodeInit *I = InitAllocator.Allocate(); - new (I) CodeInit(ID, V); - UniqueInits.InsertNode(I, IP); - return I; -} - -const ListInit *ListInit::get(std::vector &Vs, RecTy *EltTy) { - FoldingSetNodeID ID; - ID.AddInteger(initList); - ID.AddString(EltTy->getAsString()); - - for (std::vector::iterator i = Vs.begin(), iend = Vs.end(); - i != iend; - ++i) { - ID.AddPointer(*i); + } + BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i]))); } - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - ListInit *I = InitAllocator.Allocate(); - new (I) ListInit(ID, Vs, EltTy); - UniqueInits.InsertNode(I, IP); - return I; + return BI; } -const Init * -ListInit::convertInitListSlice(const std::vector &Elements) const { - std::vector Vals; +Init *ListInit::convertInitListSlice(const std::vector &Elements) { + std::vector Vals; for (unsigned i = 0, e = Elements.size(); i != e; ++i) { if (Elements[i] >= getSize()) return 0; Vals.push_back(getElement(Elements[i])); } - return ListInit::get(Vals, getType()); + return new ListInit(Vals, getType()); } Record *ListInit::getElementAsRecord(unsigned i) const { assert(i < Values.size() && "List element index out of range!"); - const DefInit *DI = dynamic_cast(Values[i]); + DefInit *DI = dynamic_cast(Values[i]); if (DI == 0) throw "Expected record in list!"; return DI->getDef(); } -const Init *ListInit::resolveReferences(Record &R, - const RecordVal *RV) const { - std::vector Resolved; +Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) { + std::vector Resolved; Resolved.reserve(getSize()); bool Changed = false; for (unsigned i = 0, e = getSize(); i != e; ++i) { - const Init *E; - const Init *CurElt = getElement(i); + Init *E; + Init *CurElt = getElement(i); do { E = CurElt; @@ -582,25 +470,20 @@ const Init *ListInit::resolveReferences(Record &R, } if (Changed) - return ListInit::get(Resolved, getType()); - + return new ListInit(Resolved, getType()); return this; } -const Init *ListInit::resolveListElementReference(Record &R, - const RecordVal *IRV, - unsigned Elt) const { +Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV, + unsigned Elt) { if (Elt >= getSize()) return 0; // Out of range reference. - - const Init *E = getElement(Elt); - + Init *E = getElement(Elt); // If the element is set to some value, or if we are resolving a reference // to a specific variable and that variable is explicitly unset, then // replace the VarListElementInit with it. - if (IRV || !dynamic_cast(E)) + if (IRV || !dynamic_cast(E)) return E; - return 0; } @@ -613,12 +496,12 @@ std::string ListInit::getAsString() const { return Result + "]"; } -const Init *OpInit::resolveBitReference(Record &R, const RecordVal *IRV, - unsigned Bit) const { - const Init *Folded = Fold(&R, 0); +Init *OpInit::resolveBitReference(Record &R, const RecordVal *IRV, + unsigned Bit) { + Init *Folded = Fold(&R, 0); if (Folded != this) { - const TypedInit *Typed = dynamic_cast(Folded); + TypedInit *Typed = dynamic_cast(Folded); if (Typed) { return Typed->resolveBitReference(R, IRV, Bit); } @@ -627,12 +510,12 @@ const Init *OpInit::resolveBitReference(Record &R, const RecordVal *IRV, return 0; } -const Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV, - unsigned Elt) const { - const Init *Folded = Fold(&R, 0); +Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV, + unsigned Elt) { + Init *Folded = Fold(&R, 0); if (Folded != this) { - const TypedInit *Typed = dynamic_cast(Folded); + TypedInit *Typed = dynamic_cast(Folded); if (Typed) { return Typed->resolveListElementReference(R, IRV, Elt); } @@ -641,39 +524,22 @@ const Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV, return 0; } -const UnOpInit *UnOpInit::get(UnaryOp opc, const Init *lhs, RecTy *Type) { - FoldingSetNodeID ID; - ID.AddInteger(initUnOp); - ID.AddInteger(opc); - ID.AddString(Type->getAsString()); - ID.AddPointer(lhs); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - UnOpInit *I = InitAllocator.Allocate(); - new (I) UnOpInit(ID, opc, lhs, Type); - UniqueInits.InsertNode(I, IP); - return I; -} - -const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { +Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { switch (getOpcode()) { default: assert(0 && "Unknown unop"); case CAST: { if (getType()->getAsString() == "string") { - const StringInit *LHSs = dynamic_cast(LHS); + StringInit *LHSs = dynamic_cast(LHS); if (LHSs) { return LHSs; } - const DefInit *LHSd = dynamic_cast(LHS); + DefInit *LHSd = dynamic_cast(LHS); if (LHSd) { - return StringInit::get(LHSd->getDef()->getName()); + return new StringInit(LHSd->getDef()->getName()); } } else { - const StringInit *LHSs = dynamic_cast(LHS); + StringInit *LHSs = dynamic_cast(LHS); if (LHSs) { std::string Name = LHSs->getValue(); @@ -682,7 +548,7 @@ const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { if (const RecordVal *RV = CurRec->getValue(Name)) { if (RV->getType() != getType()) throw "type mismatch in cast"; - return VarInit::get(Name, RV->getType()); + return new VarInit(Name, RV->getType()); } std::string TemplateArgName = CurRec->getName()+":"+Name; @@ -693,7 +559,7 @@ const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { if (RV->getType() != getType()) throw "type mismatch in cast"; - return VarInit::get(TemplateArgName, RV->getType()); + return new VarInit(TemplateArgName, RV->getType()); } } @@ -706,12 +572,12 @@ const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { if (RV->getType() != getType()) throw "type mismatch in cast"; - return VarInit::get(MCName, RV->getType()); + return new VarInit(MCName, RV->getType()); } } if (Record *D = (CurRec->getRecords()).getDef(Name)) - return DefInit::get(D); + return new DefInit(D); throw TGError(CurRec->getLoc(), "Undefined reference:'" + Name + "'\n"); } @@ -719,7 +585,7 @@ const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { break; } case HEAD: { - const ListInit *LHSl = dynamic_cast(LHS); + ListInit *LHSl = dynamic_cast(LHS); if (LHSl) { if (LHSl->getSize() == 0) { assert(0 && "Empty list in car"); @@ -730,33 +596,33 @@ const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { break; } case TAIL: { - const ListInit *LHSl = dynamic_cast(LHS); + ListInit *LHSl = dynamic_cast(LHS); if (LHSl) { if (LHSl->getSize() == 0) { assert(0 && "Empty list in cdr"); return 0; } - const ListInit *Result = ListInit::get(LHSl->begin()+1, LHSl->end(), - LHSl->getType()); + ListInit *Result = new ListInit(LHSl->begin()+1, LHSl->end(), + LHSl->getType()); return Result; } break; } case EMPTY: { - const ListInit *LHSl = dynamic_cast(LHS); + ListInit *LHSl = dynamic_cast(LHS); if (LHSl) { if (LHSl->getSize() == 0) { - return IntInit::get(1); + return new IntInit(1); } else { - return IntInit::get(0); + return new IntInit(0); } } - const StringInit *LHSs = dynamic_cast(LHS); + StringInit *LHSs = dynamic_cast(LHS); if (LHSs) { if (LHSs->getValue().empty()) { - return IntInit::get(1); + return new IntInit(1); } else { - return IntInit::get(0); + return new IntInit(0); } } @@ -766,12 +632,11 @@ const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { return this; } -const Init *UnOpInit::resolveReferences(Record &R, - const RecordVal *RV) const { - const Init *lhs = LHS->resolveReferences(R, RV); +Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) { + Init *lhs = LHS->resolveReferences(R, RV); if (LHS != lhs) - return (UnOpInit::get(getOpcode(), lhs, getType()))->Fold(&R, 0); + return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0); return Fold(&R, 0); } @@ -786,37 +651,18 @@ std::string UnOpInit::getAsString() const { return Result + "(" + LHS->getAsString() + ")"; } -const BinOpInit *BinOpInit::get(BinaryOp opc, const Init *lhs, - const Init *rhs, RecTy *Type) { - FoldingSetNodeID ID; - ID.AddInteger(initBinOp); - ID.AddInteger(opc); - ID.AddString(Type->getAsString()); - ID.AddPointer(lhs); - ID.AddPointer(rhs); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - BinOpInit *I = InitAllocator.Allocate(); - new (I) BinOpInit(ID, opc, lhs, rhs, Type); - UniqueInits.InsertNode(I, IP); - return I; -} - -const Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { +Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { switch (getOpcode()) { default: assert(0 && "Unknown binop"); case CONCAT: { - const DagInit *LHSs = dynamic_cast(LHS); - const DagInit *RHSs = dynamic_cast(RHS); + DagInit *LHSs = dynamic_cast(LHS); + DagInit *RHSs = dynamic_cast(RHS); if (LHSs && RHSs) { - const DefInit *LOp = dynamic_cast(LHSs->getOperator()); - const DefInit *ROp = dynamic_cast(RHSs->getOperator()); + DefInit *LOp = dynamic_cast(LHSs->getOperator()); + DefInit *ROp = dynamic_cast(RHSs->getOperator()); if (LOp == 0 || ROp == 0 || LOp->getDef() != ROp->getDef()) throw "Concated Dag operators do not match!"; - std::vector Args; + std::vector Args; std::vector ArgNames; for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) { Args.push_back(LHSs->getArg(i)); @@ -826,42 +672,42 @@ const Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { Args.push_back(RHSs->getArg(i)); ArgNames.push_back(RHSs->getArgName(i)); } - return DagInit::get(LHSs->getOperator(), "", Args, ArgNames); + return new DagInit(LHSs->getOperator(), "", Args, ArgNames); } break; } case STRCONCAT: { - const StringInit *LHSs = dynamic_cast(LHS); - const StringInit *RHSs = dynamic_cast(RHS); + StringInit *LHSs = dynamic_cast(LHS); + StringInit *RHSs = dynamic_cast(RHS); if (LHSs && RHSs) - return StringInit::get(LHSs->getValue() + RHSs->getValue()); + return new StringInit(LHSs->getValue() + RHSs->getValue()); break; } case EQ: { // try to fold eq comparison for 'bit' and 'int', otherwise fallback // to string objects. - const IntInit* L = - dynamic_cast(LHS->convertInitializerTo(new IntRecTy())); - const IntInit* R = - dynamic_cast(RHS->convertInitializerTo(new IntRecTy())); + IntInit* L = + dynamic_cast(LHS->convertInitializerTo(new IntRecTy())); + IntInit* R = + dynamic_cast(RHS->convertInitializerTo(new IntRecTy())); if (L && R) - return IntInit::get(L->getValue() == R->getValue()); + return new IntInit(L->getValue() == R->getValue()); - const StringInit *LHSs = dynamic_cast(LHS); - const StringInit *RHSs = dynamic_cast(RHS); + StringInit *LHSs = dynamic_cast(LHS); + StringInit *RHSs = dynamic_cast(RHS); // Make sure we've resolved if (LHSs && RHSs) - return IntInit::get(LHSs->getValue() == RHSs->getValue()); + return new IntInit(LHSs->getValue() == RHSs->getValue()); break; } case SHL: case SRA: case SRL: { - const IntInit *LHSi = dynamic_cast(LHS); - const IntInit *RHSi = dynamic_cast(RHS); + IntInit *LHSi = dynamic_cast(LHS); + IntInit *RHSi = dynamic_cast(RHS); if (LHSi && RHSi) { int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue(); int64_t Result; @@ -871,7 +717,7 @@ const Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { case SRA: Result = LHSv >> RHSv; break; case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break; } - return IntInit::get(Result); + return new IntInit(Result); } break; } @@ -879,13 +725,12 @@ const Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { return this; } -const Init *BinOpInit::resolveReferences(Record &R, - const RecordVal *RV) const { - const Init *lhs = LHS->resolveReferences(R, RV); - const Init *rhs = RHS->resolveReferences(R, RV); +Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) { + Init *lhs = LHS->resolveReferences(R, RV); + Init *rhs = RHS->resolveReferences(R, RV); if (LHS != lhs || RHS != rhs) - return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0); + return (new BinOpInit(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0); return Fold(&R, 0); } @@ -902,43 +747,20 @@ std::string BinOpInit::getAsString() const { return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")"; } -const TernOpInit *TernOpInit::get(TernaryOp opc, const Init *lhs, - const Init *mhs, const Init *rhs, - RecTy *Type) { - FoldingSetNodeID ID; - ID.AddInteger(initTernOp); - ID.AddInteger(opc); - ID.AddString(Type->getAsString()); - ID.AddPointer(lhs); - ID.AddPointer(mhs); - ID.AddPointer(rhs); +static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, + Record *CurRec, MultiClass *CurMultiClass); - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - TernOpInit *I = InitAllocator.Allocate(); - new (I) TernOpInit(ID, opc, lhs, mhs, rhs, Type); - UniqueInits.InsertNode(I, IP); - return I; -} +static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg, + RecTy *Type, Record *CurRec, + MultiClass *CurMultiClass) { + std::vector NewOperands; -static const Init *ForeachHelper(const Init *LHS, const Init *MHS, - const Init *RHS, RecTy *Type, - Record *CurRec, MultiClass *CurMultiClass); - -static const Init *EvaluateOperation(const OpInit *RHSo, const Init *LHS, - const Init *Arg, RecTy *Type, - Record *CurRec, - MultiClass *CurMultiClass) { - std::vector NewOperands; - - const TypedInit *TArg = dynamic_cast(Arg); + TypedInit *TArg = dynamic_cast(Arg); // If this is a dag, recurse if (TArg && TArg->getType()->getAsString() == "dag") { - const Init *Result = ForeachHelper(LHS, Arg, RHSo, Type, - CurRec, CurMultiClass); + Init *Result = ForeachHelper(LHS, Arg, RHSo, Type, + CurRec, CurMultiClass); if (Result != 0) { return Result; } else { @@ -946,21 +768,18 @@ static const Init *EvaluateOperation(const OpInit *RHSo, const Init *LHS, } } - bool change = false; for (int i = 0; i < RHSo->getNumOperands(); ++i) { - const OpInit *RHSoo = dynamic_cast(RHSo->getOperand(i)); + OpInit *RHSoo = dynamic_cast(RHSo->getOperand(i)); if (RHSoo) { - const Init *Result = EvaluateOperation(RHSoo, LHS, Arg, - Type, CurRec, CurMultiClass); + Init *Result = EvaluateOperation(RHSoo, LHS, Arg, + Type, CurRec, CurMultiClass); if (Result != 0) { - change = true; NewOperands.push_back(Result); } else { NewOperands.push_back(Arg); } } else if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) { - change = true; NewOperands.push_back(Arg); } else { NewOperands.push_back(RHSo->getOperand(i)); @@ -968,31 +787,30 @@ static const Init *EvaluateOperation(const OpInit *RHSo, const Init *LHS, } // Now run the operator and use its result as the new leaf - const OpInit *NewOp = RHSo->clone(NewOperands); - const Init *NewVal = NewOp->Fold(CurRec, CurMultiClass); - - if (change) { + OpInit *NewOp = RHSo->clone(NewOperands); + Init *NewVal = NewOp->Fold(CurRec, CurMultiClass); + if (NewVal != NewOp) { + delete NewOp; return NewVal; } return 0; } -static const Init *ForeachHelper(const Init *LHS, const Init *MHS, - const Init *RHS, RecTy *Type, - Record *CurRec, MultiClass *CurMultiClass) { - const DagInit *MHSd = dynamic_cast(MHS); - const ListInit *MHSl = dynamic_cast(MHS); +static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, + Record *CurRec, MultiClass *CurMultiClass) { + DagInit *MHSd = dynamic_cast(MHS); + ListInit *MHSl = dynamic_cast(MHS); DagRecTy *DagType = dynamic_cast(Type); ListRecTy *ListType = dynamic_cast(Type); - const OpInit *RHSo = dynamic_cast(RHS); + OpInit *RHSo = dynamic_cast(RHS); if (!RHSo) { throw TGError(CurRec->getLoc(), "!foreach requires an operator\n"); } - const TypedInit *LHSt = dynamic_cast(LHS); + TypedInit *LHSt = dynamic_cast(LHS); if (!LHSt) { throw TGError(CurRec->getLoc(), "!foreach requires typed variable\n"); @@ -1000,23 +818,23 @@ static const Init *ForeachHelper(const Init *LHS, const Init *MHS, if ((MHSd && DagType) || (MHSl && ListType)) { if (MHSd) { - const Init *Val = MHSd->getOperator(); - const Init *Result = EvaluateOperation(RHSo, LHS, Val, - Type, CurRec, CurMultiClass); + Init *Val = MHSd->getOperator(); + Init *Result = EvaluateOperation(RHSo, LHS, Val, + Type, CurRec, CurMultiClass); if (Result != 0) { Val = Result; } - std::vector > args; + std::vector > args; for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) { - const Init *Arg; + Init *Arg; std::string ArgName; Arg = MHSd->getArg(i); ArgName = MHSd->getArgName(i); // Process args - const Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type, - CurRec, CurMultiClass); + Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type, + CurRec, CurMultiClass); if (Result != 0) { Arg = Result; } @@ -1025,17 +843,17 @@ static const Init *ForeachHelper(const Init *LHS, const Init *MHS, args.push_back(std::make_pair(Arg, ArgName)); } - return DagInit::get(Val, "", args); + return new DagInit(Val, "", args); } if (MHSl) { - std::vector NewOperands; - std::vector NewList(MHSl->begin(), MHSl->end()); + std::vector NewOperands; + std::vector NewList(MHSl->begin(), MHSl->end()); - for (std::vector::iterator li = NewList.begin(), + for (ListInit::iterator li = NewList.begin(), liend = NewList.end(); li != liend; ++li) { - const Init *Item = *li; + Init *Item = *li; NewOperands.clear(); for(int i = 0; i < RHSo->getNumOperands(); ++i) { // First, replace the foreach variable with the list item @@ -1047,33 +865,34 @@ static const Init *ForeachHelper(const Init *LHS, const Init *MHS, } // Now run the operator and use its result as the new list item - const OpInit *NewOp = RHSo->clone(NewOperands); - const Init *NewItem = NewOp->Fold(CurRec, CurMultiClass); + OpInit *NewOp = RHSo->clone(NewOperands); + Init *NewItem = NewOp->Fold(CurRec, CurMultiClass); if (NewItem != NewOp) { *li = NewItem; + delete NewOp; } } - return ListInit::get(NewList, MHSl->getType()); + return new ListInit(NewList, MHSl->getType()); } } return 0; } -const Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { +Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { switch (getOpcode()) { default: assert(0 && "Unknown binop"); case SUBST: { - const DefInit *LHSd = dynamic_cast(LHS); - const VarInit *LHSv = dynamic_cast(LHS); - const StringInit *LHSs = dynamic_cast(LHS); + DefInit *LHSd = dynamic_cast(LHS); + VarInit *LHSv = dynamic_cast(LHS); + StringInit *LHSs = dynamic_cast(LHS); - const DefInit *MHSd = dynamic_cast(MHS); - const VarInit *MHSv = dynamic_cast(MHS); - const StringInit *MHSs = dynamic_cast(MHS); + DefInit *MHSd = dynamic_cast(MHS); + VarInit *MHSv = dynamic_cast(MHS); + StringInit *MHSs = dynamic_cast(MHS); - const DefInit *RHSd = dynamic_cast(RHS); - const VarInit *RHSv = dynamic_cast(RHS); - const StringInit *RHSs = dynamic_cast(RHS); + DefInit *RHSd = dynamic_cast(RHS); + VarInit *RHSv = dynamic_cast(RHS); + StringInit *RHSs = dynamic_cast(RHS); if ((LHSd && MHSd && RHSd) || (LHSv && MHSv && RHSv) @@ -1083,14 +902,14 @@ const Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { if (LHSd->getAsString() == RHSd->getAsString()) { Val = MHSd->getDef(); } - return DefInit::get(Val); + return new DefInit(Val); } if (RHSv) { std::string Val = RHSv->getName(); if (LHSv->getAsString() == RHSv->getAsString()) { Val = MHSv->getName(); } - return VarInit::get(Val, getType()); + return new VarInit(Val, getType()); } if (RHSs) { std::string Val = RHSs->getValue(); @@ -1105,14 +924,14 @@ const Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { idx = found + MHSs->getValue().size(); } while (found != std::string::npos); - return StringInit::get(Val); + return new StringInit(Val); } } break; } case FOREACH: { - const Init *Result = ForeachHelper(LHS, MHS, RHS, getType(), + Init *Result = ForeachHelper(LHS, MHS, RHS, getType(), CurRec, CurMultiClass); if (Result != 0) { return Result; @@ -1121,9 +940,9 @@ const Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { } case IF: { - const IntInit *LHSi = dynamic_cast(LHS); - if (const Init *I = LHS->convertInitializerTo(new IntRecTy())) - LHSi = dynamic_cast(I); + IntInit *LHSi = dynamic_cast(LHS); + if (Init *I = LHS->convertInitializerTo(new IntRecTy())) + LHSi = dynamic_cast(I); if (LHSi) { if (LHSi->getValue()) { return MHS; @@ -1138,35 +957,32 @@ const Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { return this; } -const Init * -TernOpInit::resolveReferences(Record &R, - const RecordVal *RV) const { - const Init *lhs = LHS->resolveReferences(R, RV); +Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) { + Init *lhs = LHS->resolveReferences(R, RV); if (Opc == IF && lhs != LHS) { - const IntInit *Value = dynamic_cast(lhs); - if (const Init *I = lhs->convertInitializerTo(new IntRecTy())) - Value = dynamic_cast(I); + IntInit *Value = dynamic_cast(lhs); + if (Init *I = lhs->convertInitializerTo(new IntRecTy())) + Value = dynamic_cast(I); if (Value != 0) { // Short-circuit if (Value->getValue()) { - const Init *mhs = MHS->resolveReferences(R, RV); - return (TernOpInit::get(getOpcode(), lhs, mhs, - RHS, getType()))->Fold(&R, 0); + Init *mhs = MHS->resolveReferences(R, RV); + return (new TernOpInit(getOpcode(), lhs, mhs, + RHS, getType()))->Fold(&R, 0); } else { - const Init *rhs = RHS->resolveReferences(R, RV); - return (TernOpInit::get(getOpcode(), lhs, MHS, - rhs, getType()))->Fold(&R, 0); + Init *rhs = RHS->resolveReferences(R, RV); + return (new TernOpInit(getOpcode(), lhs, MHS, + rhs, getType()))->Fold(&R, 0); } } } - const Init *mhs = MHS->resolveReferences(R, RV); - const Init *rhs = RHS->resolveReferences(R, RV); + Init *mhs = MHS->resolveReferences(R, RV); + Init *rhs = RHS->resolveReferences(R, RV); if (LHS != lhs || MHS != mhs || RHS != rhs) - return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))-> - Fold(&R, 0); + return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0); return Fold(&R, 0); } @@ -1192,97 +1008,79 @@ RecTy *TypedInit::getFieldType(const std::string &FieldName) const { return 0; } -const Init * -TypedInit::convertInitializerBitRange(const std::vector &Bits) const { +Init *TypedInit::convertInitializerBitRange(const std::vector &Bits) { BitsRecTy *T = dynamic_cast(getType()); if (T == 0) return 0; // Cannot subscript a non-bits variable. unsigned NumBits = T->getNumBits(); - SmallVector NewBits(Bits.size()); + BitsInit *BI = new BitsInit(Bits.size()); for (unsigned i = 0, e = Bits.size(); i != e; ++i) { if (Bits[i] >= NumBits) { + delete BI; return 0; } - NewBits[i] = VarBitInit::get(this, Bits[i]); + BI->setBit(i, new VarBitInit(this, Bits[i])); } - return BitsInit::get(NewBits.begin(), NewBits.end()); + return BI; } -const Init * -TypedInit::convertInitListSlice(const std::vector &Elements) const { +Init *TypedInit::convertInitListSlice(const std::vector &Elements) { ListRecTy *T = dynamic_cast(getType()); if (T == 0) return 0; // Cannot subscript a non-list variable. if (Elements.size() == 1) - return VarListElementInit::get(this, Elements[0]); + return new VarListElementInit(this, Elements[0]); - std::vector ListInits; + std::vector ListInits; ListInits.reserve(Elements.size()); for (unsigned i = 0, e = Elements.size(); i != e; ++i) - ListInits.push_back(VarListElementInit::get(this, Elements[i])); - return ListInit::get(ListInits, T); + ListInits.push_back(new VarListElementInit(this, Elements[i])); + return new ListInit(ListInits, T); } -const VarInit *VarInit::get(const std::string &VN, RecTy *T) { - FoldingSetNodeID ID; - ID.AddInteger(initVar); - ID.AddString(VN); - ID.AddString(T->getAsString()); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - VarInit *I = InitAllocator.Allocate(); - new (I) VarInit(ID, VN, T); - UniqueInits.InsertNode(I, IP); - return I; -} - -const Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV, - unsigned Bit) const { +Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV, + unsigned Bit) { if (R.isTemplateArg(getName())) return 0; if (IRV && IRV->getName() != getName()) return 0; RecordVal *RV = R.getValue(getName()); assert(RV && "Reference to a non-existent variable?"); - assert(dynamic_cast(RV->getValue())); - const BitsInit *BI = (const BitsInit*)RV->getValue(); + assert(dynamic_cast(RV->getValue())); + BitsInit *BI = (BitsInit*)RV->getValue(); assert(Bit < BI->getNumBits() && "Bit reference out of range!"); - const Init *B = BI->getBit(Bit); + Init *B = BI->getBit(Bit); // If the bit is set to some value, or if we are resolving a reference to a // specific variable and that variable is explicitly unset, then replace the // VarBitInit with it. - if (IRV || !dynamic_cast(B)) + if (IRV || !dynamic_cast(B)) return B; return 0; } -const Init *VarInit::resolveListElementReference(Record &R, - const RecordVal *IRV, - unsigned Elt) const { +Init *VarInit::resolveListElementReference(Record &R, const RecordVal *IRV, + unsigned Elt) { if (R.isTemplateArg(getName())) return 0; if (IRV && IRV->getName() != getName()) return 0; RecordVal *RV = R.getValue(getName()); assert(RV && "Reference to a non-existent variable?"); - const ListInit *LI = dynamic_cast(RV->getValue()); + ListInit *LI = dynamic_cast(RV->getValue()); if (!LI) { - const VarInit *VI = dynamic_cast(RV->getValue()); + VarInit *VI = dynamic_cast(RV->getValue()); assert(VI && "Invalid list element!"); - return VarListElementInit::get(VI, Elt); + return new VarListElementInit(VI, Elt); } if (Elt >= LI->getSize()) return 0; // Out of range reference. - const Init *E = LI->getElement(Elt); + Init *E = LI->getElement(Elt); // If the element is set to some value, or if we are resolving a reference // to a specific variable and that variable is explicitly unset, then // replace the VarListElementInit with it. - if (IRV || !dynamic_cast(E)) + if (IRV || !dynamic_cast(E)) return E; return 0; } @@ -1295,15 +1093,15 @@ RecTy *VarInit::getFieldType(const std::string &FieldName) const { return 0; } -const Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, - const std::string &FieldName) const { +Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, + const std::string &FieldName) const { if (dynamic_cast(getType())) if (const RecordVal *Val = R.getValue(VarName)) { - if (RV != Val && (RV || dynamic_cast(Val->getValue()))) + if (RV != Val && (RV || dynamic_cast(Val->getValue()))) return 0; - const Init *TheInit = Val->getValue(); + Init *TheInit = Val->getValue(); assert(TheInit != this && "Infinite loop detected!"); - if (const Init *I = TheInit->getFieldInit(R, RV, FieldName)) + if (Init *I = TheInit->getFieldInit(R, RV, FieldName)) return I; else return 0; @@ -1316,112 +1114,56 @@ const Init *VarInit::getFieldInit(Record &R, const RecordVal *RV, /// If a value is set for the variable later, this method will be called on /// users of the value to allow the value to propagate out. /// -const Init *VarInit::resolveReferences(Record &R, - const RecordVal *RV) const { +Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) { if (RecordVal *Val = R.getValue(VarName)) - if (RV == Val || (RV == 0 - && !dynamic_cast(Val->getValue()))) + if (RV == Val || (RV == 0 && !dynamic_cast(Val->getValue()))) return Val->getValue(); return this; } -const VarBitInit *VarBitInit::get(const TypedInit *T, unsigned B) { - FoldingSetNodeID ID; - ID.AddInteger(initVarBit); - ID.AddPointer(T); - ID.AddInteger(B); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - VarBitInit *I = InitAllocator.Allocate(); - new (I) VarBitInit(ID, T, B); - UniqueInits.InsertNode(I, IP); - return I; -} - std::string VarBitInit::getAsString() const { return TI->getAsString() + "{" + utostr(Bit) + "}"; } -const Init * -VarBitInit::resolveReferences(Record &R, - const RecordVal *RV) const { - if (const Init *I = getVariable()->resolveBitReference(R, RV, getBitNum())) +Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) { + if (Init *I = getVariable()->resolveBitReference(R, RV, getBitNum())) return I; return this; } -const VarListElementInit *VarListElementInit::get(const TypedInit *T, - unsigned E) { - FoldingSetNodeID ID; - ID.AddInteger(initVarListElement); - ID.AddPointer(T); - ID.AddInteger(E); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - VarListElementInit *I = InitAllocator.Allocate(); - new (I) VarListElementInit(ID, T, E); - UniqueInits.InsertNode(I, IP); - return I; -} - std::string VarListElementInit::getAsString() const { return TI->getAsString() + "[" + utostr(Element) + "]"; } -const Init *VarListElementInit::resolveReferences(Record &R, - const RecordVal *RV) const { - if (const Init *I = - getVariable()->resolveListElementReference(R, RV, getElementNum())) +Init *VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) { + if (Init *I = getVariable()->resolveListElementReference(R, RV, + getElementNum())) return I; return this; } -const Init *VarListElementInit::resolveBitReference(Record &R, - const RecordVal *RV, - unsigned Bit) const { +Init *VarListElementInit::resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { // FIXME: This should be implemented, to support references like: // bit B = AA[0]{1}; return 0; } -const Init * -VarListElementInit::resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const { +Init *VarListElementInit:: +resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) { // FIXME: This should be implemented, to support references like: // int B = AA[0][1]; return 0; } -const DefInit *DefInit::get(Record *D) { - FoldingSetNodeID ID; - ID.AddInteger(initDef); - ID.AddString(D->getName()); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - DefInit *I = InitAllocator.Allocate(); - new (I) DefInit(ID, D); - UniqueInits.InsertNode(I, IP); - return I; -} - RecTy *DefInit::getFieldType(const std::string &FieldName) const { if (const RecordVal *RV = Def->getValue(FieldName)) return RV->getType(); return 0; } -const Init *DefInit::getFieldInit(Record &R, const RecordVal *RV, - const std::string &FieldName) const { +Init *DefInit::getFieldInit(Record &R, const RecordVal *RV, + const std::string &FieldName) const { return Def->getValue(FieldName)->getValue(); } @@ -1430,134 +1172,59 @@ std::string DefInit::getAsString() const { return Def->getName(); } -const FieldInit *FieldInit::get(const Init *R, const std::string &FN) { - FoldingSetNodeID ID; - ID.AddInteger(initField); - ID.AddPointer(R); - ID.AddString(FN); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - FieldInit *I = InitAllocator.Allocate(); - new (I) FieldInit(ID, R, FN); - UniqueInits.InsertNode(I, IP); - return I; -} - -const Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const { - if (const Init *BitsVal = Rec->getFieldInit(R, RV, FieldName)) - if (const BitsInit *BI = dynamic_cast(BitsVal)) { +Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { + if (Init *BitsVal = Rec->getFieldInit(R, RV, FieldName)) + if (BitsInit *BI = dynamic_cast(BitsVal)) { assert(Bit < BI->getNumBits() && "Bit reference out of range!"); - const Init *B = BI->getBit(Bit); + Init *B = BI->getBit(Bit); - if (dynamic_cast(B)) // If the bit is set. + if (dynamic_cast(B)) // If the bit is set. return B; // Replace the VarBitInit with it. } return 0; } -const Init *FieldInit::resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const { - if (const Init *ListVal = Rec->getFieldInit(R, RV, FieldName)) - if (const ListInit *LI = dynamic_cast(ListVal)) { +Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt) { + if (Init *ListVal = Rec->getFieldInit(R, RV, FieldName)) + if (ListInit *LI = dynamic_cast(ListVal)) { if (Elt >= LI->getSize()) return 0; - const Init *E = LI->getElement(Elt); + Init *E = LI->getElement(Elt); // If the element is set to some value, or if we are resolving a // reference to a specific variable and that variable is explicitly // unset, then replace the VarListElementInit with it. - if (RV || !dynamic_cast(E)) + if (RV || !dynamic_cast(E)) return E; } return 0; } -const Init *FieldInit::resolveReferences(Record &R, - const RecordVal *RV) const { - const Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec; +Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) { + Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec; - const Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName); + Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName); if (BitsVal) { - const Init *BVR = BitsVal->resolveReferences(R, RV); + Init *BVR = BitsVal->resolveReferences(R, RV); return BVR->isComplete() ? BVR : this; } if (NewRec != Rec) { - return FieldInit::get(NewRec, FieldName); + return new FieldInit(NewRec, FieldName); } return this; } -const DagInit * -DagInit::get(const Init *V, const std::string &VN, - const std::vector > &args) { - FoldingSetNodeID ID; - ID.AddInteger(initDag); - ID.AddPointer(V); - ID.AddString(VN); - - for (std::vector >::const_iterator a - = args.begin(), - aend = args.end(); - a != aend; - ++a) { - ID.AddPointer(a->first); - ID.AddString(a->second); - } - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - DagInit *I = InitAllocator.Allocate(); - new (I) DagInit(ID, V, VN, args); - UniqueInits.InsertNode(I, IP); - return I; -} - -const DagInit * -DagInit::get(const Init *V, const std::string &VN, - const std::vector &args, - const std::vector &argNames) { - FoldingSetNodeID ID; - ID.AddInteger(initDag); - ID.AddPointer(V); - ID.AddString(VN); - - std::vector::const_iterator s = argNames.begin(); - for (std::vector::const_iterator a - = args.begin(), - aend = args.end(); - a != aend; - ++a, ++s) { - ID.AddPointer(*a); - ID.AddString(*s); - } - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - DagInit *I = InitAllocator.Allocate(); - new (I) DagInit(ID, V, VN, args, argNames); - UniqueInits.InsertNode(I, IP); - return I; -} - -const Init *DagInit::resolveReferences(Record &R, - const RecordVal *RV) const { - std::vector NewArgs; +Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) { + std::vector NewArgs; for (unsigned i = 0, e = Args.size(); i != e; ++i) NewArgs.push_back(Args[i]->resolveReferences(R, RV)); - const Init *Op = Val->resolveReferences(R, RV); + Init *Op = Val->resolveReferences(R, RV); if (Args != NewArgs || Op != Val) - return DagInit::get(Op, ValName, NewArgs, ArgNames); + return new DagInit(Op, ValName, NewArgs, ArgNames); return this; } @@ -1585,7 +1252,7 @@ std::string DagInit::getAsString() const { RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P) : Name(N), Ty(T), Prefix(P) { - Value = Ty->convertValue(UnsetInit::get()); + Value = Ty->convertValue(new UnsetInit()); assert(Value && "Cannot create unset value for current type!"); } @@ -1620,7 +1287,7 @@ void Record::setName(const std::string &Name) { /// references. void Record::resolveReferencesTo(const RecordVal *RV) { for (unsigned i = 0, e = Values.size(); i != e; ++i) { - if (const Init *V = Values[i].getValue()) + if (Init *V = Values[i].getValue()) Values[i].setValue(V->resolveReferences(*this, RV)); } } @@ -1665,7 +1332,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) { /// getValueInit - Return the initializer for a value with the specified name, /// or throw an exception if the field does not exist. /// -const Init *Record::getValueInit(StringRef FieldName) const { +Init *Record::getValueInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + @@ -1694,13 +1361,13 @@ std::string Record::getValueAsString(StringRef FieldName) const { /// its value as a BitsInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// -const BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { +BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"; - if (const BitsInit *BI = dynamic_cast(R->getValue())) + if (BitsInit *BI = dynamic_cast(R->getValue())) return BI; throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a BitsInit initializer!"; @@ -1710,13 +1377,13 @@ const BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { /// its value as a ListInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// -const ListInit *Record::getValueAsListInit(StringRef FieldName) const { +ListInit *Record::getValueAsListInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"; - if (const ListInit *LI = dynamic_cast(R->getValue())) + if (ListInit *LI = dynamic_cast(R->getValue())) return LI; throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a list initializer!"; @@ -1728,10 +1395,10 @@ const ListInit *Record::getValueAsListInit(StringRef FieldName) const { /// std::vector Record::getValueAsListOfDefs(StringRef FieldName) const { - const ListInit *List = getValueAsListInit(FieldName); + ListInit *List = getValueAsListInit(FieldName); std::vector Defs; for (unsigned i = 0; i < List->getSize(); i++) { - if (const DefInit *DI = dynamic_cast(List->getElement(i))) { + if (DefInit *DI = dynamic_cast(List->getElement(i))) { Defs.push_back(DI->getDef()); } else { throw "Record `" + getName() + "', field `" + FieldName.str() + @@ -1751,7 +1418,7 @@ int64_t Record::getValueAsInt(StringRef FieldName) const { throw "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"; - if (const IntInit *II = dynamic_cast(R->getValue())) + if (IntInit *II = dynamic_cast(R->getValue())) return II->getValue(); throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have an int initializer!"; @@ -1763,10 +1430,10 @@ int64_t Record::getValueAsInt(StringRef FieldName) const { /// std::vector Record::getValueAsListOfInts(StringRef FieldName) const { - const ListInit *List = getValueAsListInit(FieldName); + ListInit *List = getValueAsListInit(FieldName); std::vector Ints; for (unsigned i = 0; i < List->getSize(); i++) { - if (const IntInit *II = dynamic_cast(List->getElement(i))) { + if (IntInit *II = dynamic_cast(List->getElement(i))) { Ints.push_back(II->getValue()); } else { throw "Record `" + getName() + "', field `" + FieldName.str() + @@ -1782,11 +1449,10 @@ Record::getValueAsListOfInts(StringRef FieldName) const { /// std::vector Record::getValueAsListOfStrings(StringRef FieldName) const { - const ListInit *List = getValueAsListInit(FieldName); + ListInit *List = getValueAsListInit(FieldName); std::vector Strings; for (unsigned i = 0; i < List->getSize(); i++) { - if (const StringInit *II = - dynamic_cast(List->getElement(i))) { + if (StringInit *II = dynamic_cast(List->getElement(i))) { Strings.push_back(II->getValue()); } else { throw "Record `" + getName() + "', field `" + FieldName.str() + @@ -1806,7 +1472,7 @@ Record *Record::getValueAsDef(StringRef FieldName) const { throw "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"; - if (const DefInit *DI = dynamic_cast(R->getValue())) + if (DefInit *DI = dynamic_cast(R->getValue())) return DI->getDef(); throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a def initializer!"; @@ -1822,7 +1488,7 @@ bool Record::getValueAsBit(StringRef FieldName) const { throw "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"; - if (const BitInit *BI = dynamic_cast(R->getValue())) + if (BitInit *BI = dynamic_cast(R->getValue())) return BI->getValue(); throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a bit initializer!"; @@ -1832,13 +1498,13 @@ bool Record::getValueAsBit(StringRef FieldName) const { /// value as an Dag, throwing an exception if the field does not exist or if /// the value is not the right type. /// -const DagInit *Record::getValueAsDag(StringRef FieldName) const { +DagInit *Record::getValueAsDag(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) throw "Record `" + getName() + "' does not have a field named `" + FieldName.str() + "'!\n"; - if (const DagInit *DI = dynamic_cast(R->getValue())) + if (DagInit *DI = dynamic_cast(R->getValue())) return DI; throw "Record `" + getName() + "', field `" + FieldName.str() + "' does not have a dag initializer!"; diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 53e5e1f4f20..f24f5e66fa0 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -15,8 +15,6 @@ #ifndef RECORD_H #define RECORD_H -#include "llvm/ADT/FoldingSet.h" -#include "llvm/Support/Allocator.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/raw_ostream.h" @@ -36,7 +34,7 @@ class DagRecTy; class RecordRecTy; // Init subclasses. -class Init; +struct Init; class UnsetInit; class BitInit; class BitsInit; @@ -77,31 +75,31 @@ struct RecTy { virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0; public: // These methods should only be called from subclasses of Init - virtual const Init *convertValue(const UnsetInit *UI) { return 0; } - virtual const Init *convertValue(const BitInit *BI) { return 0; } - virtual const Init *convertValue(const BitsInit *BI) { return 0; } - virtual const Init *convertValue(const IntInit *II) { return 0; } - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return convertValue((const TypedInit*)UI); + virtual Init *convertValue( UnsetInit *UI) { return 0; } + virtual Init *convertValue( BitInit *BI) { return 0; } + virtual Init *convertValue( BitsInit *BI) { return 0; } + virtual Init *convertValue( IntInit *II) { return 0; } + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { + return convertValue((TypedInit*)UI); } - virtual const Init *convertValue(const BinOpInit *UI) { - return convertValue((const TypedInit*)UI); + virtual Init *convertValue( BinOpInit *UI) { + return convertValue((TypedInit*)UI); } - virtual const Init *convertValue(const TernOpInit *UI) { - return convertValue((const TypedInit*)UI); + virtual Init *convertValue( TernOpInit *UI) { + return convertValue((TypedInit*)UI); } - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const TypedInit *TI) { return 0; } - virtual const Init *convertValue(const VarInit *VI) { - return convertValue((const TypedInit*)VI); + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( TypedInit *TI) { return 0; } + virtual Init *convertValue( VarInit *VI) { + return convertValue((TypedInit*)VI); } - virtual const Init *convertValue(const FieldInit *FI) { - return convertValue((const TypedInit*)FI); + virtual Init *convertValue( FieldInit *FI) { + return convertValue((TypedInit*)FI); } public: // These methods should only be called by subclasses of RecTy. @@ -127,38 +125,22 @@ inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) { /// class BitRecTy : public RecTy { public: - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI) { - return (const Init*)BI; - } - virtual const Init *convertValue(const BitsInit *BI); - virtual const Init *convertValue(const IntInit *II); - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { - return (const Init*)VB; - } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const BinOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TernOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI) { return (Init*)BI; } + virtual Init *convertValue( BitsInit *BI); + virtual Init *convertValue( IntInit *II); + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const { return "bit"; } @@ -187,32 +169,22 @@ public: unsigned getNumBits() const { return Size; } - virtual const Init *convertValue(const UnsetInit *UI); - virtual const Init *convertValue(const BitInit *UI); - virtual const Init *convertValue(const BitsInit *BI); - virtual const Init *convertValue(const IntInit *II); - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const BinOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TernOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI); + virtual Init *convertValue( BitInit *UI); + virtual Init *convertValue( BitsInit *BI); + virtual Init *convertValue( IntInit *II); + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const; @@ -237,36 +209,22 @@ public: /// class IntRecTy : public RecTy { public: - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI); - virtual const Init *convertValue(const BitsInit *BI); - virtual const Init *convertValue(const IntInit *II) { - return (const Init*)II; - } - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const BinOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TernOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI); + virtual Init *convertValue( BitsInit *BI); + virtual Init *convertValue( IntInit *II) { return (Init*)II; } + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const { return "int"; } @@ -289,33 +247,23 @@ public: /// class StringRecTy : public RecTy { public: - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI) { return 0; } - virtual const Init *convertValue(const BitsInit *BI) { return 0; } - virtual const Init *convertValue(const IntInit *II) { return 0; } - virtual const Init *convertValue(const StringInit *SI) { - return (const Init*)SI; - } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const UnOpInit *BO); - virtual const Init *convertValue(const BinOpInit *BO); - virtual const Init *convertValue(const TernOpInit *BO) { - return RecTy::convertValue(BO); - } - - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI) { return 0; } + virtual Init *convertValue( BitsInit *BI) { return 0; } + virtual Init *convertValue( IntInit *II) { return 0; } + virtual Init *convertValue(StringInit *SI) { return (Init*)SI; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( UnOpInit *BO); + virtual Init *convertValue( BinOpInit *BO); + virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} + + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const { return "string"; } @@ -345,34 +293,22 @@ public: RecTy *getElementType() const { return Ty; } - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI) { return 0; } - virtual const Init *convertValue(const BitsInit *BI) { return 0; } - virtual const Init *convertValue(const IntInit *II) { return 0; } - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI); - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const BinOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TernOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI) { return 0; } + virtual Init *convertValue( BitsInit *BI) { return 0; } + virtual Init *convertValue( IntInit *II) { return 0; } + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI); + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const; @@ -396,36 +332,22 @@ public: /// class CodeRecTy : public RecTy { public: - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI) { return 0; } - virtual const Init *convertValue(const BitsInit *BI) { return 0; } - virtual const Init *convertValue(const IntInit *II) { return 0; } - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const CodeInit *CI) { - return (const Init*)CI; - } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const BinOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TernOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI) { return 0; } + virtual Init *convertValue( BitsInit *BI) { return 0; } + virtual Init *convertValue( IntInit *II) { return 0; } + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const { return "code"; } @@ -446,32 +368,22 @@ public: /// class DagRecTy : public RecTy { public: - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI) { return 0; } - virtual const Init *convertValue(const BitsInit *BI) { return 0; } - virtual const Init *convertValue(const IntInit *II) { return 0; } - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const DefInit *DI) { return 0; } - virtual const Init *convertValue(const UnOpInit *BO); - virtual const Init *convertValue(const BinOpInit *BO); - virtual const Init *convertValue(const TernOpInit *BO) { - return RecTy::convertValue(BO); - } - virtual const Init *convertValue(const DagInit *CI) { - return (const Init*)CI; - } - virtual const Init *convertValue(const TypedInit *TI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI) { return 0; } + virtual Init *convertValue( BitsInit *BI) { return 0; } + virtual Init *convertValue( IntInit *II) { return 0; } + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( UnOpInit *BO); + virtual Init *convertValue( BinOpInit *BO); + virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} + virtual Init *convertValue( DagInit *CI) { return (Init*)CI; } + virtual Init *convertValue( TypedInit *TI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const { return "dag"; } @@ -500,34 +412,22 @@ public: Record *getRecord() const { return Rec; } - virtual const Init *convertValue(const UnsetInit *UI) { - return (const Init*)UI; - } - virtual const Init *convertValue(const BitInit *BI) { return 0; } - virtual const Init *convertValue(const BitsInit *BI) { return 0; } - virtual const Init *convertValue(const IntInit *II) { return 0; } - virtual const Init *convertValue(const StringInit *SI) { return 0; } - virtual const Init *convertValue(const ListInit *LI) { return 0; } - virtual const Init *convertValue(const CodeInit *CI) { return 0; } - virtual const Init *convertValue(const VarBitInit *VB) { return 0; } - virtual const Init *convertValue(const UnOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const BinOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const TernOpInit *UI) { - return RecTy::convertValue(UI); - } - virtual const Init *convertValue(const DefInit *DI); - virtual const Init *convertValue(const DagInit *DI) { return 0; } - virtual const Init *convertValue(const TypedInit *VI); - virtual const Init *convertValue(const VarInit *VI) { - return RecTy::convertValue(VI); - } - virtual const Init *convertValue(const FieldInit *FI) { - return RecTy::convertValue(FI); - } + virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } + virtual Init *convertValue( BitInit *BI) { return 0; } + virtual Init *convertValue( BitsInit *BI) { return 0; } + virtual Init *convertValue( IntInit *II) { return 0; } + virtual Init *convertValue(StringInit *SI) { return 0; } + virtual Init *convertValue( ListInit *LI) { return 0; } + virtual Init *convertValue( CodeInit *CI) { return 0; } + virtual Init *convertValue(VarBitInit *VB) { return 0; } + virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} + virtual Init *convertValue( DefInit *DI); + virtual Init *convertValue( DagInit *DI) { return 0; } + virtual Init *convertValue( TypedInit *VI); + virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} + virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} std::string getAsString() const; @@ -553,43 +453,9 @@ RecTy *resolveTypes(RecTy *T1, RecTy *T2); // Initializer Classes //===----------------------------------------------------------------------===// -class Init : public FastFoldingSetNode { - Init(const Init &); // Do not define. - Init &operator=(const Init &); // Do not define. - -protected: - Init(const FoldingSetNodeID &ID) : FastFoldingSetNode(ID) {} - - static FoldingSet UniqueInits; - static BumpPtrAllocator InitAllocator; - - enum Type { - initUnset, - initBit, - initBits, - initInt, - initString, - initCode, - initList, - initUnOp, - initBinOp, - initTernOp, - initQuadOp, - initVar, - initVarBit, - initVarListElement, - initDef, - initField, - initDag - }; - -public: +struct Init { virtual ~Init() {} - static void ReleaseMemory() { - InitAllocator.Reset(); - } - /// isComplete - This virtual method should be overridden by values that may /// not be completely specified yet. virtual bool isComplete() const { return true; } @@ -608,15 +474,14 @@ public: /// function that should be overridden to call the appropriate /// RecTy::convertValue method. /// - virtual const Init *convertInitializerTo(RecTy *Ty) const = 0; + virtual Init *convertInitializerTo(RecTy *Ty) = 0; /// convertInitializerBitRange - This method is used to implement the bitrange /// selection operator. Given an initializer, it selects the specified bits /// out, returning them as a new init of bits type. If it is not legal to use /// the bit subscript operator on this initializer, return null. /// - virtual const Init * - convertInitializerBitRange(const std::vector &Bits) const { + virtual Init *convertInitializerBitRange(const std::vector &Bits) { return 0; } @@ -625,8 +490,7 @@ public: /// elements, returning them as a new init of list type. If it is not legal /// to take a slice of this, return null. /// - virtual const Init * - convertInitListSlice(const std::vector &Elements) const { + virtual Init *convertInitListSlice(const std::vector &Elements) { return 0; } @@ -640,8 +504,8 @@ public: /// initializer for the specified field. If getFieldType returns non-null /// this method should return non-null, otherwise it returns null. /// - virtual const Init *getFieldInit(Record &R, const RecordVal *RV, - const std::string &FieldName) const { + virtual Init *getFieldInit(Record &R, const RecordVal *RV, + const std::string &FieldName) const { return 0; } @@ -650,8 +514,7 @@ public: /// If a value is set for the variable later, this method will be called on /// users of the value to allow the value to propagate out. /// - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const { + virtual Init *resolveReferences(Record &R, const RecordVal *RV) { return this; } }; @@ -665,20 +528,13 @@ inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) { /// class TypedInit : public Init { RecTy *Ty; - - TypedInit(const TypedInit &Other); // Do not define. - TypedInit &operator=(const TypedInit &Other); // Do not define. - -protected: - explicit TypedInit(const FoldingSetNodeID &ID, RecTy *T) : Init(ID), Ty(T) {} - public: + explicit TypedInit(RecTy *T) : Ty(T) {} + RecTy *getType() const { return Ty; } - virtual const Init * - convertInitializerBitRange(const std::vector &Bits) const; - virtual const Init * - convertInitListSlice(const std::vector &Elements) const; + virtual Init *convertInitializerBitRange(const std::vector &Bits); + virtual Init *convertInitListSlice(const std::vector &Elements); /// getFieldType - This method is used to implement the FieldInit class. /// Implementors of this method should return the type of the named field if @@ -690,29 +546,22 @@ public: /// VarBitInit::resolveReferences. If the bit is able to be resolved, we /// simply return the resolved value, otherwise we return null. /// - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const = 0; + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) = 0; /// resolveListElementReference - This method is used to implement /// VarListElementInit::resolveReferences. If the list element is resolvable /// now, we return the resolved value, otherwise we return null. - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const = 0; + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt) = 0; }; /// UnsetInit - ? - Represents an uninitialized value /// class UnsetInit : public Init { - UnsetInit(const FoldingSetNodeID &ID) : Init(ID) {} - UnsetInit(const UnsetInit &); // Do not define. - UnsetInit &operator=(const UnsetInit &Other); // Do not define. - public: - static const UnsetInit *get(); - - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } @@ -725,17 +574,12 @@ public: /// class BitInit : public Init { bool Value; - - explicit BitInit(const FoldingSetNodeID &ID, bool V) : Init(ID), Value(V) {} - BitInit(const BitInit &Other); // Do not define. - BitInit &operator=(BitInit &Other); // Do not define. - public: - static const BitInit *get(bool V); + explicit BitInit(bool V) : Value(V) {} bool getValue() const { return Value; } - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } @@ -746,56 +590,26 @@ public: /// It contains a vector of bits, whose size is determined by the type. /// class BitsInit : public Init { - std::vector Bits; - - BitsInit(const FoldingSetNodeID &ID, unsigned Size) - : Init(ID), Bits(Size) {} - - template - BitsInit(const FoldingSetNodeID &ID, InputIterator start, InputIterator end) - : Init(ID), Bits(start, end) {} - - BitsInit(const BitsInit &Other); // Do not define. - BitsInit &operator=(const BitsInit &Other); // Do not define. - + std::vector Bits; public: - template - static const BitsInit *get(InputIterator Start, InputIterator End) { - FoldingSetNodeID ID; - ID.AddInteger(initBits); - ID.AddInteger(std::distance(Start, End)); - - InputIterator S = Start; - while (S != End) - ID.AddPointer(*S++); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - BitsInit *I = InitAllocator.Allocate(); - new (I) BitsInit(ID, Start, End); - UniqueInits.InsertNode(I, IP); - return I; - } + explicit BitsInit(unsigned Size) : Bits(Size) {} unsigned getNumBits() const { return Bits.size(); } - const Init *getBit(unsigned Bit) const { + Init *getBit(unsigned Bit) const { assert(Bit < Bits.size() && "Bit index out of range!"); return Bits[Bit]; } - void setBit(unsigned Bit, const Init *V) { + void setBit(unsigned Bit, Init *V) { assert(Bit < Bits.size() && "Bit index out of range!"); assert(Bits[Bit] == 0 && "Bit already set!"); Bits[Bit] = V; } - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - virtual const Init * - convertInitializerBitRange(const std::vector &Bits) const; + virtual Init *convertInitializerBitRange(const std::vector &Bits); virtual bool isComplete() const { for (unsigned i = 0; i != getNumBits(); ++i) @@ -809,8 +623,7 @@ public: } virtual std::string getAsString() const; - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); }; @@ -818,23 +631,15 @@ public: /// class IntInit : public TypedInit { int64_t Value; - - explicit IntInit(const FoldingSetNodeID &ID, int64_t V) - : TypedInit(ID, new IntRecTy), Value(V) {} - - IntInit(const IntInit &Other); // Do not define. - IntInit &operator=(const IntInit &Other); // Do note define. - public: - static const IntInit *get(int64_t V); + explicit IntInit(int64_t V) : TypedInit(new IntRecTy), Value(V) {} int64_t getValue() const { return Value; } - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - virtual const Init * - convertInitializerBitRange(const std::vector &Bits) const; + virtual Init *convertInitializerBitRange(const std::vector &Bits); virtual std::string getAsString() const; @@ -842,8 +647,8 @@ public: /// VarBitInit::resolveReferences. If the bit is able to be resolved, we /// simply return the resolved value, otherwise we return null. /// - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const { + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { assert(0 && "Illegal bit reference off int"); return 0; } @@ -851,9 +656,8 @@ public: /// resolveListElementReference - This method is used to implement /// VarListElementInit::resolveReferences. If the list element is resolvable /// now, we return the resolved value, otherwise we return null. - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const { + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt) { assert(0 && "Illegal element reference off int"); return 0; } @@ -864,19 +668,13 @@ public: /// class StringInit : public TypedInit { std::string Value; - - explicit StringInit(const FoldingSetNodeID &ID, const std::string &V) - : TypedInit(ID, new StringRecTy), Value(V) {} - - StringInit(const StringInit &Other); // Do not define. - StringInit &operator=(const StringInit &Other); // Do not define. - public: - static const StringInit *get(const std::string &V); + explicit StringInit(const std::string &V) + : TypedInit(new StringRecTy), Value(V) {} const std::string &getValue() const { return Value; } - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } @@ -886,8 +684,8 @@ public: /// VarBitInit::resolveReferences. If the bit is able to be resolved, we /// simply return the resolved value, otherwise we return null. /// - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const { + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { assert(0 && "Illegal bit reference off string"); return 0; } @@ -895,9 +693,8 @@ public: /// resolveListElementReference - This method is used to implement /// VarListElementInit::resolveReferences. If the list element is resolvable /// now, we return the resolved value, otherwise we return null. - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const { + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt) { assert(0 && "Illegal element reference off string"); return 0; } @@ -907,19 +704,12 @@ public: /// class CodeInit : public Init { std::string Value; - - explicit CodeInit(const FoldingSetNodeID &ID, const std::string &V) - : Init(ID), Value(V) {} - - CodeInit(const CodeInit &Other); // Do not define. - CodeInit &operator=(const CodeInit &Other); // Do not define. - public: - static const CodeInit *get(const std::string &V); + explicit CodeInit(const std::string &V) : Value(V) {} const std::string &getValue() const { return Value; } - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } @@ -929,61 +719,29 @@ public: /// ListInit - [AL, AH, CL] - Represent a list of defs /// class ListInit : public TypedInit { - std::vector Values; - + std::vector Values; public: - typedef std::vector::const_iterator const_iterator; + typedef std::vector::iterator iterator; + typedef std::vector::const_iterator const_iterator; -private: - ListInit(const FoldingSetNodeID &ID, std::vector &Vs, - RecTy *EltTy) - : TypedInit(ID, new ListRecTy(EltTy)) { + explicit ListInit(std::vector &Vs, RecTy *EltTy) + : TypedInit(new ListRecTy(EltTy)) { Values.swap(Vs); } - - template - ListInit(const FoldingSetNodeID &ID, InputIterator Start, InputIterator End, - RecTy *EltTy) - : TypedInit(ID, new ListRecTy(EltTy)), Values(Start, End) {} - - ListInit(const ListInit &Other); // Do not define. - ListInit &operator=(const ListInit &Other); // Do not define. - -public: - static const ListInit *get(std::vector &Vs, RecTy *EltTy); - - template - static const ListInit *get(InputIterator Start, InputIterator End, - RecTy *EltTy) { - FoldingSetNodeID ID; - ID.AddInteger(initList); - ID.AddString(EltTy->getAsString()); - - InputIterator S = Start; - while (S != End) - ID.AddPointer(*S++); - - void *IP = 0; - if (const Init *I = UniqueInits.FindNodeOrInsertPos(ID, IP)) - return static_cast(I); - - ListInit *I = InitAllocator.Allocate(); - new (I) ListInit(ID, Start, End, EltTy); - UniqueInits.InsertNode(I, IP); - return I; - } + explicit ListInit(iterator Start, iterator End, RecTy *EltTy) + : TypedInit(new ListRecTy(EltTy)), Values(Start, End) {} unsigned getSize() const { return Values.size(); } - const Init *getElement(unsigned i) const { + Init *getElement(unsigned i) const { assert(i < Values.size() && "List element index out of range!"); return Values[i]; } Record *getElementAsRecord(unsigned i) const; - const Init *convertInitListSlice(const std::vector &Elements) const; + Init *convertInitListSlice(const std::vector &Elements); - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } @@ -992,12 +750,13 @@ public: /// If a value is set for the variable later, this method will be called on /// users of the value to allow the value to propagate out. /// - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const; + inline iterator begin() { return Values.begin(); } inline const_iterator begin() const { return Values.begin(); } + inline iterator end () { return Values.end(); } inline const_iterator end () const { return Values.end(); } inline size_t size () const { return Values.size(); } @@ -1007,8 +766,8 @@ public: /// VarBitInit::resolveReferences. If the bit is able to be resolved, we /// simply return the resolved value, otherwise we return null. /// - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const { + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { assert(0 && "Illegal bit reference off list"); return 0; } @@ -1016,42 +775,35 @@ public: /// resolveListElementReference - This method is used to implement /// VarListElementInit::resolveReferences. If the list element is resolvable /// now, we return the resolved value, otherwise we return null. - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const; + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt); }; /// OpInit - Base class for operators /// class OpInit : public TypedInit { - OpInit(const OpInit &Other); // Do not define. - OpInit &operator=(OpInit &Other); // Do not define. - -protected: - explicit OpInit(const FoldingSetNodeID &ID, RecTy *Type) - : TypedInit(ID, Type) {} - public: + OpInit(RecTy *Type) : TypedInit(Type) {} + // Clone - Clone this operator, replacing arguments with the new list - virtual const OpInit *clone(std::vector &Operands) const = 0; + virtual OpInit *clone(std::vector &Operands) = 0; virtual int getNumOperands() const = 0; - virtual const Init *getOperand(int i) const = 0; + virtual Init *getOperand(int i) = 0; // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - virtual const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0; + virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0; - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const; - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const; + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit); + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt); }; @@ -1062,40 +814,33 @@ public: enum UnaryOp { CAST, HEAD, TAIL, EMPTY }; private: UnaryOp Opc; - const Init *LHS; - - UnOpInit(const FoldingSetNodeID &ID, UnaryOp opc, const Init *lhs, - RecTy *Type) - : OpInit(ID, Type), Opc(opc), LHS(lhs) {} - - UnOpInit(const UnOpInit &Other); // Do not define. - UnOpInit &operator=(const UnOpInit &Other); // Do not define. - + Init *LHS; public: - static const UnOpInit *get(UnaryOp opc, const Init *lhs, RecTy *Type); + UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) : + OpInit(Type), Opc(opc), LHS(lhs) { + } // Clone - Clone this operator, replacing arguments with the new list - virtual const OpInit *clone(std::vector &Operands) const { + virtual OpInit *clone(std::vector &Operands) { assert(Operands.size() == 1 && "Wrong number of operands for unary operation"); - return UnOpInit::get(getOpcode(), *Operands.begin(), getType()); + return new UnOpInit(getOpcode(), *Operands.begin(), getType()); } int getNumOperands() const { return 1; } - const Init *getOperand(int i) const { + Init *getOperand(int i) { assert(i == 0 && "Invalid operand id for unary operator"); return getOperand(); } UnaryOp getOpcode() const { return Opc; } - const Init *getOperand() const { return LHS; } + Init *getOperand() const { return LHS; } // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - const Init *Fold(Record *CurRec, MultiClass *CurMultiClass)const ; + Init *Fold(Record *CurRec, MultiClass *CurMultiClass); - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const; }; @@ -1107,28 +852,21 @@ public: enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ }; private: BinaryOp Opc; - const Init *LHS, *RHS; - - BinOpInit(const FoldingSetNodeID &ID, BinaryOp opc, const Init *lhs, - const Init *rhs, RecTy *Type) : - OpInit(ID, Type), Opc(opc), LHS(lhs), RHS(rhs) {} - - BinOpInit(const BinOpInit &Other); // Do not define. - BinOpInit &operator=(const BinOpInit &Other); // Do not define. - + Init *LHS, *RHS; public: - static const BinOpInit *get(BinaryOp opc, const Init *lhs, const Init *rhs, - RecTy *Type); + BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) : + OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) { + } // Clone - Clone this operator, replacing arguments with the new list - virtual const OpInit *clone(std::vector &Operands) const { + virtual OpInit *clone(std::vector &Operands) { assert(Operands.size() == 2 && "Wrong number of operands for binary operation"); - return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType()); + return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType()); } int getNumOperands() const { return 2; } - const Init *getOperand(int i) const { + Init *getOperand(int i) { assert((i == 0 || i == 1) && "Invalid operand id for binary operator"); if (i == 0) { return getLHS(); @@ -1138,15 +876,14 @@ public: } BinaryOp getOpcode() const { return Opc; } - const Init *getLHS() const { return LHS; } - const Init *getRHS() const { return RHS; } + Init *getLHS() const { return LHS; } + Init *getRHS() const { return RHS; } // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const; + Init *Fold(Record *CurRec, MultiClass *CurMultiClass); - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const; }; @@ -1158,30 +895,22 @@ public: enum TernaryOp { SUBST, FOREACH, IF }; private: TernaryOp Opc; - const Init *LHS, *MHS, *RHS; - - TernOpInit(const FoldingSetNodeID &ID, TernaryOp opc, const Init *lhs, - const Init *mhs, const Init *rhs, RecTy *Type) : - OpInit(ID, Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {} - - TernOpInit(const TernOpInit &Other); // Do not define. - TernOpInit &operator=(const TernOpInit &Other); // Do not define. - + Init *LHS, *MHS, *RHS; public: - static const TernOpInit *get(TernaryOp opc, const Init *lhs, - const Init *mhs, const Init *rhs, - RecTy *Type); + TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) : + OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) { + } // Clone - Clone this operator, replacing arguments with the new list - virtual const OpInit *clone(std::vector &Operands) const { + virtual OpInit *clone(std::vector &Operands) { assert(Operands.size() == 3 && "Wrong number of operands for ternary operation"); - return TernOpInit::get(getOpcode(), Operands[0], Operands[1], - Operands[2], getType()); + return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2], + getType()); } int getNumOperands() const { return 3; } - const Init *getOperand(int i) const { + Init *getOperand(int i) { assert((i == 0 || i == 1 || i == 2) && "Invalid operand id for ternary operator"); if (i == 0) { @@ -1194,18 +923,17 @@ public: } TernaryOp getOpcode() const { return Opc; } - const Init *getLHS() const { return LHS; } - const Init *getMHS() const { return MHS; } - const Init *getRHS() const { return RHS; } + Init *getLHS() const { return LHS; } + Init *getMHS() const { return MHS; } + Init *getRHS() const { return RHS; } // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const; + Init *Fold(Record *CurRec, MultiClass *CurMultiClass); virtual bool isComplete() const { return false; } - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const; }; @@ -1215,31 +943,23 @@ public: /// class VarInit : public TypedInit { std::string VarName; - - explicit VarInit(const FoldingSetNodeID &ID, const std::string &VN, RecTy *T) - : TypedInit(ID, T), VarName(VN) {} - - VarInit(const VarInit &Other); // Do not define. - VarInit &operator=(const VarInit &Other); // Do not define. - public: - static const VarInit *get(const std::string &VN, RecTy *T); - static const VarInit *get(const Init *VN, RecTy *T); + explicit VarInit(const std::string &VN, RecTy *T) + : TypedInit(T), VarName(VN) {} - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } const std::string &getName() const { return VarName; } - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const; - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const; + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit); + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt); virtual RecTy *getFieldType(const std::string &FieldName) const; - virtual const Init *getFieldInit(Record &R, const RecordVal *RV, + virtual Init *getFieldInit(Record &R, const RecordVal *RV, const std::string &FieldName) const; /// resolveReferences - This method is used by classes that refer to other @@ -1247,8 +967,7 @@ public: /// If a value is set for the variable later, this method will be called on /// users of the value to allow the value to propagate out. /// - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const { return VarName; } }; @@ -1257,101 +976,76 @@ public: /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field. /// class VarBitInit : public Init { - const TypedInit *TI; + TypedInit *TI; unsigned Bit; - - VarBitInit(const FoldingSetNodeID &ID, const TypedInit *T, unsigned B) - : Init(ID), TI(T), Bit(B) { +public: + VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) { assert(T->getType() && dynamic_cast(T->getType()) && ((BitsRecTy*)T->getType())->getNumBits() > B && "Illegal VarBitInit expression!"); } - VarBitInit(const VarBitInit &Other); // Do not define. - VarBitInit &operator=(const VarBitInit &Other); // Do not define. - -public: - static const VarBitInit *get(const TypedInit *T, unsigned B); - - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - const TypedInit *getVariable() const { return TI; } + TypedInit *getVariable() const { return TI; } unsigned getBitNum() const { return Bit; } virtual std::string getAsString() const; - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); }; /// VarListElementInit - List[4] - Represent access to one element of a var or /// field. class VarListElementInit : public TypedInit { - const TypedInit *TI; + TypedInit *TI; unsigned Element; - - VarListElementInit(const FoldingSetNodeID &ID, const TypedInit *T, unsigned E) - : TypedInit(ID, dynamic_cast(T->getType())->getElementType()), +public: + VarListElementInit(TypedInit *T, unsigned E) + : TypedInit(dynamic_cast(T->getType())->getElementType()), TI(T), Element(E) { assert(T->getType() && dynamic_cast(T->getType()) && "Illegal VarBitInit expression!"); } - VarListElementInit(const VarListElementInit &Other); // Do not define. - VarListElementInit &operator=(const VarListElementInit &Other); // Do - // not - // define. - -public: - static const VarListElementInit *get(const TypedInit *T, unsigned E); - - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - const TypedInit *getVariable() const { return TI; } + TypedInit *getVariable() const { return TI; } unsigned getElementNum() const { return Element; } - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const; + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit); /// resolveListElementReference - This method is used to implement /// VarListElementInit::resolveReferences. If the list element is resolvable /// now, we return the resolved value, otherwise we return null. - virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV, - unsigned Elt) const; + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt); virtual std::string getAsString() const; - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); }; /// DefInit - AL - Represent a reference to a 'def' in the description /// class DefInit : public TypedInit { Record *Def; - - explicit DefInit(const FoldingSetNodeID &ID, Record *D) - : TypedInit(ID, new RecordRecTy(D)), Def(D) {} - - DefInit(const DefInit &Other); // Do not define. - DefInit &operator=(const DefInit &Other); // Do not define. - public: - static const DefInit *get(Record *D); + explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {} - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } Record *getDef() const { return Def; } - //virtual const Init * - //convertInitializerBitRange(const std::vector &Bits) const; + //virtual Init *convertInitializerBitRange(const std::vector &Bits); virtual RecTy *getFieldType(const std::string &FieldName) const; - virtual const Init *getFieldInit(Record &R, const RecordVal *RV, + virtual Init *getFieldInit(Record &R, const RecordVal *RV, const std::string &FieldName) const; virtual std::string getAsString() const; @@ -1360,8 +1054,8 @@ public: /// VarBitInit::resolveReferences. If the bit is able to be resolved, we /// simply return the resolved value, otherwise we return null. /// - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const { + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { assert(0 && "Illegal bit reference off def"); return 0; } @@ -1369,9 +1063,8 @@ public: /// resolveListElementReference - This method is used to implement /// VarListElementInit::resolveReferences. If the list element is resolvable /// now, we return the resolved value, otherwise we return null. - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const { + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt) { assert(0 && "Illegal element reference off def"); return 0; } @@ -1381,33 +1074,24 @@ public: /// FieldInit - X.Y - Represent a reference to a subfield of a variable /// class FieldInit : public TypedInit { - const Init *Rec; // Record we are referring to + Init *Rec; // Record we are referring to std::string FieldName; // Field we are accessing - - FieldInit(const FoldingSetNodeID &ID, const Init *R, const std::string &FN) - : TypedInit(ID, R->getFieldType(FN)), Rec(R), FieldName(FN) { +public: + FieldInit(Init *R, const std::string &FN) + : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) { assert(getType() && "FieldInit with non-record type!"); } - FieldInit(const FieldInit &Other); // Do not define. - FieldInit &operator=(const FieldInit &Other); // Do not define. - -public: - static const FieldInit *get(const Init *R, const std::string &FN); - static const FieldInit *get(const Init *R, const Init *FN); - - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const; - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const; + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit); + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt); - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const { return Rec->getAsString() + "." + FieldName; @@ -1419,14 +1103,14 @@ public: /// argument can have a name associated with it. /// class DagInit : public TypedInit { - const Init *Val; + Init *Val; std::string ValName; - std::vector Args; + std::vector Args; std::vector ArgNames; - - DagInit(const FoldingSetNodeID &ID, const Init *V, const std::string &VN, - const std::vector > &args) - : TypedInit(ID, new DagRecTy), Val(V), ValName(VN) { +public: + DagInit(Init *V, std::string VN, + const std::vector > &args) + : TypedInit(new DagRecTy), Val(V), ValName(VN) { Args.reserve(args.size()); ArgNames.reserve(args.size()); for (unsigned i = 0, e = args.size(); i != e; ++i) { @@ -1434,33 +1118,21 @@ class DagInit : public TypedInit { ArgNames.push_back(args[i].second); } } - DagInit(const FoldingSetNodeID &ID, const Init *V, const std::string &VN, - const std::vector &args, + DagInit(Init *V, std::string VN, const std::vector &args, const std::vector &argNames) - : TypedInit(ID, new DagRecTy), Val(V), ValName(VN), Args(args), + : TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args), ArgNames(argNames) { } - DagInit(const DagInit &Other); // Do not define. - DagInit &operator=(const DagInit &Other); // Do not define. - -public: - static const DagInit *get(const Init *V, const std::string &VN, - const std::vector< - std::pair > &args); - static const DagInit *get(const Init *V, const std::string &VN, - const std::vector &args, - const std::vector &argNames); - - virtual const Init *convertInitializerTo(RecTy *Ty) const { + virtual Init *convertInitializerTo(RecTy *Ty) { return Ty->convertValue(this); } - const Init *getOperator() const { return Val; } + Init *getOperator() const { return Val; } const std::string &getName() const { return ValName; } unsigned getNumArgs() const { return Args.size(); } - const Init *getArg(unsigned Num) const { + Init *getArg(unsigned Num) const { assert(Num < Args.size() && "Arg number out of range!"); return Args[Num]; } @@ -1469,18 +1141,17 @@ public: return ArgNames[Num]; } - void setArg(unsigned Num, const Init *I) { + void setArg(unsigned Num, Init *I) { assert(Num < Args.size() && "Arg number out of range!"); Args[Num] = I; } - virtual const Init *resolveReferences(Record &R, - const RecordVal *RV) const; + virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const; - typedef std::vector::iterator arg_iterator; - typedef std::vector::const_iterator const_arg_iterator; + typedef std::vector::iterator arg_iterator; + typedef std::vector::const_iterator const_arg_iterator; typedef std::vector::iterator name_iterator; typedef std::vector::const_iterator const_name_iterator; @@ -1500,15 +1171,14 @@ public: inline size_t name_size () const { return ArgNames.size(); } inline bool name_empty() const { return ArgNames.empty(); } - virtual const Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit) const { + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit) { assert(0 && "Illegal bit reference off dag"); return 0; } - virtual const Init *resolveListElementReference(Record &R, - const RecordVal *RV, - unsigned Elt) const { + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt) { assert(0 && "Illegal element reference off dag"); return 0; } @@ -1522,7 +1192,7 @@ class RecordVal { std::string Name; RecTy *Ty; unsigned Prefix; - const Init *Value; + Init *Value; public: RecordVal(const std::string &N, RecTy *T, unsigned P); @@ -1530,9 +1200,9 @@ public: unsigned getPrefix() const { return Prefix; } RecTy *getType() const { return Ty; } - const Init *getValue() const { return Value; } + Init *getValue() const { return Value; } - bool setValue(const Init *V) { + bool setValue(Init *V) { if (V) { Value = V->convertInitializerTo(Ty); return Value == 0; @@ -1666,7 +1336,7 @@ public: /// getValueInit - Return the initializer for a value with the specified name, /// or throw an exception if the field does not exist. /// - const Init *getValueInit(StringRef FieldName) const; + Init *getValueInit(StringRef FieldName) const; /// getValueAsString - This method looks up the specified field and returns /// its value as a string, throwing an exception if the field does not exist @@ -1678,13 +1348,13 @@ public: /// its value as a BitsInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// - const BitsInit *getValueAsBitsInit(StringRef FieldName) const; + BitsInit *getValueAsBitsInit(StringRef FieldName) const; /// getValueAsListInit - This method looks up the specified field and returns /// its value as a ListInit, throwing an exception if the field does not exist /// or if the value is not the right type. /// - const ListInit *getValueAsListInit(StringRef FieldName) const; + ListInit *getValueAsListInit(StringRef FieldName) const; /// getValueAsListOfDefs - This method looks up the specified field and /// returns its value as a vector of records, throwing an exception if the @@ -1726,7 +1396,7 @@ public: /// value as an Dag, throwing an exception if the field does not exist or if /// the value is not the right type. /// - const DagInit *getValueAsDag(StringRef FieldName) const; + DagInit *getValueAsDag(StringRef FieldName) const; /// getValueAsCode - This method looks up the specified field and returns /// its value as the string data in a CodeInit, throwing an exception if the diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp index 06352a5f69b..abb862445d1 100644 --- a/utils/TableGen/RegisterInfoEmitter.cpp +++ b/utils/TableGen/RegisterInfoEmitter.cpp @@ -722,7 +722,7 @@ RegisterInfoEmitter::runTargetDesc(raw_ostream &OS, CodeGenTarget &Target, if (!V || !V->getValue()) continue; - const DefInit *DI = dynamic_cast(V->getValue()); + DefInit *DI = dynamic_cast(V->getValue()); Record *Alias = DI->getDef(); DwarfRegNums[Reg] = DwarfRegNums[Alias]; } diff --git a/utils/TableGen/SetTheory.cpp b/utils/TableGen/SetTheory.cpp index a888bbc7246..21ac09cb662 100644 --- a/utils/TableGen/SetTheory.cpp +++ b/utils/TableGen/SetTheory.cpp @@ -27,14 +27,14 @@ typedef SetTheory::RecVec RecVec; // (add a, b, ...) Evaluate and union all arguments. struct AddOp : public SetTheory::Operator { - void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) { + void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { ST.evaluate(Expr->arg_begin(), Expr->arg_end(), Elts); } }; // (sub Add, Sub, ...) Set difference. struct SubOp : public SetTheory::Operator { - void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) { + void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { if (Expr->arg_size() < 2) throw "Set difference needs at least two arguments: " + Expr->getAsString(); @@ -49,7 +49,7 @@ struct SubOp : public SetTheory::Operator { // (and S1, S2) Set intersection. struct AndOp : public SetTheory::Operator { - void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) { + void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { if (Expr->arg_size() != 2) throw "Set intersection requires two arguments: " + Expr->getAsString(); RecSet S1, S2; @@ -63,16 +63,16 @@ struct AndOp : public SetTheory::Operator { // SetIntBinOp - Abstract base class for (Op S, N) operators. struct SetIntBinOp : public SetTheory::Operator { - virtual void apply2(SetTheory &ST, const DagInit *Expr, + virtual void apply2(SetTheory &ST, DagInit *Expr, RecSet &Set, int64_t N, RecSet &Elts) =0; - void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) { + void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { if (Expr->arg_size() != 2) throw "Operator requires (Op Set, Int) arguments: " + Expr->getAsString(); RecSet Set; ST.evaluate(Expr->arg_begin()[0], Set); - const IntInit *II = dynamic_cast(Expr->arg_begin()[1]); + IntInit *II = dynamic_cast(Expr->arg_begin()[1]); if (!II) throw "Second argument must be an integer: " + Expr->getAsString(); apply2(ST, Expr, Set, II->getValue(), Elts); @@ -81,7 +81,7 @@ struct SetIntBinOp : public SetTheory::Operator { // (shl S, N) Shift left, remove the first N elements. struct ShlOp : public SetIntBinOp { - void apply2(SetTheory &ST, const DagInit *Expr, + void apply2(SetTheory &ST, DagInit *Expr, RecSet &Set, int64_t N, RecSet &Elts) { if (N < 0) @@ -93,7 +93,7 @@ struct ShlOp : public SetIntBinOp { // (trunc S, N) Truncate after the first N elements. struct TruncOp : public SetIntBinOp { - void apply2(SetTheory &ST, const DagInit *Expr, + void apply2(SetTheory &ST, DagInit *Expr, RecSet &Set, int64_t N, RecSet &Elts) { if (N < 0) @@ -110,7 +110,7 @@ struct RotOp : public SetIntBinOp { RotOp(bool Rev) : Reverse(Rev) {} - void apply2(SetTheory &ST, const DagInit *Expr, + void apply2(SetTheory &ST, DagInit *Expr, RecSet &Set, int64_t N, RecSet &Elts) { if (Reverse) @@ -129,7 +129,7 @@ struct RotOp : public SetIntBinOp { // (decimate S, N) Pick every N'th element of S. struct DecimateOp : public SetIntBinOp { - void apply2(SetTheory &ST, const DagInit *Expr, + void apply2(SetTheory &ST, DagInit *Expr, RecSet &Set, int64_t N, RecSet &Elts) { if (N <= 0) @@ -141,26 +141,25 @@ struct DecimateOp : public SetIntBinOp { // (sequence "Format", From, To) Generate a sequence of records by name. struct SequenceOp : public SetTheory::Operator { - void apply(SetTheory &ST, const DagInit *Expr, RecSet &Elts) { + void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { if (Expr->arg_size() != 3) throw "Bad args to (sequence \"Format\", From, To): " + Expr->getAsString(); std::string Format; - if (const StringInit *SI = - dynamic_cast(Expr->arg_begin()[0])) + if (StringInit *SI = dynamic_cast(Expr->arg_begin()[0])) Format = SI->getValue(); else throw "Format must be a string: " + Expr->getAsString(); int64_t From, To; - if (const IntInit *II = dynamic_cast(Expr->arg_begin()[1])) + if (IntInit *II = dynamic_cast(Expr->arg_begin()[1])) From = II->getValue(); else throw "From must be an integer: " + Expr->getAsString(); if (From < 0 || From >= (1 << 30)) throw "From out of range"; - if (const IntInit *II = dynamic_cast(Expr->arg_begin()[2])) + if (IntInit *II = dynamic_cast(Expr->arg_begin()[2])) To = II->getValue(); else throw "From must be an integer: " + Expr->getAsString(); @@ -168,7 +167,7 @@ struct SequenceOp : public SetTheory::Operator { throw "To out of range"; RecordKeeper &Records = - dynamic_cast(*Expr->getOperator()).getDef()->getRecords(); + dynamic_cast(*Expr->getOperator()).getDef()->getRecords(); int Step = From <= To ? 1 : -1; for (To += Step; From != To; From += Step) { @@ -223,9 +222,9 @@ void SetTheory::addFieldExpander(StringRef ClassName, StringRef FieldName) { addExpander(ClassName, new FieldExpander(FieldName)); } -void SetTheory::evaluate(const Init *Expr, RecSet &Elts) { +void SetTheory::evaluate(Init *Expr, RecSet &Elts) { // A def in a list can be a just an element, or it may expand. - if (const DefInit *Def = dynamic_cast(Expr)) { + if (DefInit *Def = dynamic_cast(Expr)) { if (const RecVec *Result = expand(Def->getDef())) return Elts.insert(Result->begin(), Result->end()); Elts.insert(Def->getDef()); @@ -233,14 +232,14 @@ void SetTheory::evaluate(const Init *Expr, RecSet &Elts) { } // Lists simply expand. - if (const ListInit *LI = dynamic_cast(Expr)) + if (ListInit *LI = dynamic_cast(Expr)) return evaluate(LI->begin(), LI->end(), Elts); // Anything else must be a DAG. - const DagInit *DagExpr = dynamic_cast(Expr); + DagInit *DagExpr = dynamic_cast(Expr); if (!DagExpr) throw "Invalid set element: " + Expr->getAsString(); - const DefInit *OpInit = dynamic_cast(DagExpr->getOperator()); + DefInit *OpInit = dynamic_cast(DagExpr->getOperator()); if (!OpInit) throw "Bad set expression: " + Expr->getAsString(); Operator *Op = Operators.lookup(OpInit->getDef()->getName()); diff --git a/utils/TableGen/SetTheory.h b/utils/TableGen/SetTheory.h index f6123c7d914..e37a76ee68c 100644 --- a/utils/TableGen/SetTheory.h +++ b/utils/TableGen/SetTheory.h @@ -55,7 +55,7 @@ namespace llvm { class DagInit; -class Init; +struct Init; class Record; class RecordKeeper; @@ -70,7 +70,7 @@ public: /// apply - Apply this operator to Expr's arguments and insert the result /// in Elts. - virtual void apply(SetTheory&, const DagInit *Expr, RecSet &Elts) =0; + virtual void apply(SetTheory&, DagInit *Expr, RecSet &Elts) =0; }; /// Expander - A callback function that can transform a Record representing a @@ -115,7 +115,7 @@ public: void addOperator(StringRef Name, Operator*); /// evaluate - Evaluate Expr and append the resulting set to Elts. - void evaluate(const Init *Expr, RecSet &Elts); + void evaluate(Init *Expr, RecSet &Elts); /// evaluate - Evaluate a sequence of Inits and append to Elts. template diff --git a/utils/TableGen/TGParser.cpp b/utils/TableGen/TGParser.cpp index 97cc22e9db4..59097f986f7 100644 --- a/utils/TableGen/TGParser.cpp +++ b/utils/TableGen/TGParser.cpp @@ -28,7 +28,7 @@ namespace llvm { struct SubClassReference { SMLoc RefLoc; Record *Rec; - std::vector TemplateArgs; + std::vector TemplateArgs; SubClassReference() : Rec(0) {} bool isInvalid() const { return Rec == 0; } @@ -37,7 +37,7 @@ struct SubClassReference { struct SubMultiClassReference { SMLoc RefLoc; MultiClass *MC; - std::vector TemplateArgs; + std::vector TemplateArgs; SubMultiClassReference() : MC(0) {} bool isInvalid() const { return MC == 0; } @@ -50,7 +50,7 @@ void SubMultiClassReference::dump() const { MC->dump(); errs() << "Template args:\n"; - for (std::vector::const_iterator i = TemplateArgs.begin(), + for (std::vector::const_iterator i = TemplateArgs.begin(), iend = TemplateArgs.end(); i != iend; ++i) { @@ -80,7 +80,7 @@ bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) { /// SetValue - /// Return true on error, false on success. bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const std::string &ValName, - const std::vector &BitList, const Init *V) { + const std::vector &BitList, Init *V) { if (!V) return false; if (CurRec == 0) CurRec = &CurMultiClass->Rec; @@ -92,7 +92,7 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const std::string &ValName, // Do not allow assignments like 'X = X'. This will just cause infinite loops // in the resolution machinery. if (BitList.empty()) - if (const VarInit *VI = dynamic_cast(V)) + if (VarInit *VI = dynamic_cast(V)) if (VI->getName() == ValName) return false; @@ -101,37 +101,37 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const std::string &ValName, // initializer. // if (!BitList.empty()) { - const BitsInit *CurVal = dynamic_cast(RV->getValue()); + BitsInit *CurVal = dynamic_cast(RV->getValue()); if (CurVal == 0) return Error(Loc, "Value '" + ValName + "' is not a bits type"); // Convert the incoming value to a bits type of the appropriate size... - const Init *BI = V->convertInitializerTo(new BitsRecTy(BitList.size())); + Init *BI = V->convertInitializerTo(new BitsRecTy(BitList.size())); if (BI == 0) { V->convertInitializerTo(new BitsRecTy(BitList.size())); return Error(Loc, "Initializer is not compatible with bit range"); } // We should have a BitsInit type now. - const BitsInit *BInit = dynamic_cast(BI); + BitsInit *BInit = dynamic_cast(BI); assert(BInit != 0); - SmallVector NewBits(CurVal->getNumBits()); + BitsInit *NewVal = new BitsInit(CurVal->getNumBits()); // Loop over bits, assigning values as appropriate. for (unsigned i = 0, e = BitList.size(); i != e; ++i) { unsigned Bit = BitList[i]; - if (NewBits[Bit]) + if (NewVal->getBit(Bit)) return Error(Loc, "Cannot set bit #" + utostr(Bit) + " of value '" + ValName + "' more than once"); - NewBits[Bit] = BInit->getBit(i); + NewVal->setBit(Bit, BInit->getBit(i)); } for (unsigned i = 0, e = CurVal->getNumBits(); i != e; ++i) - if (NewBits[i] == 0) - NewBits[i] = CurVal->getBit(i); + if (NewVal->getBit(i) == 0) + NewVal->setBit(i, CurVal->getBit(i)); - V = BitsInit::get(NewBits.begin(), NewBits.end()); + V = NewVal; } if (RV->setValue(V)) @@ -633,7 +633,7 @@ RecTy *TGParser::ParseType() { /// IDValue ::= ID [multiclass template argument] /// IDValue ::= ID [def name] /// -const Init *TGParser::ParseIDValue(Record *CurRec) { +Init *TGParser::ParseIDValue(Record *CurRec) { assert(Lex.getCode() == tgtok::Id && "Expected ID in ParseIDValue"); std::string Name = Lex.getCurStrVal(); SMLoc Loc = Lex.getLoc(); @@ -643,17 +643,17 @@ const Init *TGParser::ParseIDValue(Record *CurRec) { /// ParseIDValue - This is just like ParseIDValue above, but it assumes the ID /// has already been read. -const Init *TGParser::ParseIDValue(Record *CurRec, +Init *TGParser::ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc) { if (CurRec) { if (const RecordVal *RV = CurRec->getValue(Name)) - return VarInit::get(Name, RV->getType()); + return new VarInit(Name, RV->getType()); std::string TemplateArgName = CurRec->getName()+":"+Name; if (CurRec->isTemplateArg(TemplateArgName)) { const RecordVal *RV = CurRec->getValue(TemplateArgName); assert(RV && "Template arg doesn't exist??"); - return VarInit::get(TemplateArgName, RV->getType()); + return new VarInit(TemplateArgName, RV->getType()); } } @@ -662,12 +662,12 @@ const Init *TGParser::ParseIDValue(Record *CurRec, if (CurMultiClass->Rec.isTemplateArg(MCName)) { const RecordVal *RV = CurMultiClass->Rec.getValue(MCName); assert(RV && "Template arg doesn't exist??"); - return VarInit::get(MCName, RV->getType()); + return new VarInit(MCName, RV->getType()); } } if (Record *D = Records.getDef(Name)) - return DefInit::get(D); + return new DefInit(D); Error(NameLoc, "Variable not defined: '" + Name + "'"); return 0; @@ -677,7 +677,7 @@ const Init *TGParser::ParseIDValue(Record *CurRec, /// /// Operation ::= XOperator ['<' Type '>'] '(' Args ')' /// -const Init *TGParser::ParseOperation(Record *CurRec) { +Init *TGParser::ParseOperation(Record *CurRec) { switch (Lex.getCode()) { default: TokError("unknown operation"); @@ -724,15 +724,15 @@ const Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the '(' - const Init *LHS = ParseValue(CurRec); + Init *LHS = ParseValue(CurRec); if (LHS == 0) return 0; if (Code == UnOpInit::HEAD || Code == UnOpInit::TAIL || Code == UnOpInit::EMPTY) { - const ListInit *LHSl = dynamic_cast(LHS); - const StringInit *LHSs = dynamic_cast(LHS); - const TypedInit *LHSt = dynamic_cast(LHS); + ListInit *LHSl = dynamic_cast(LHS); + StringInit *LHSs = dynamic_cast(LHS); + TypedInit *LHSt = dynamic_cast(LHS); if (LHSl == 0 && LHSs == 0 && LHSt == 0) { TokError("expected list or string type argument in unary operator"); return 0; @@ -758,8 +758,8 @@ const Init *TGParser::ParseOperation(Record *CurRec) { return 0; } if (LHSl) { - const Init *Item = LHSl->getElement(0); - const TypedInit *Itemt = dynamic_cast(Item); + Init *Item = LHSl->getElement(0); + TypedInit *Itemt = dynamic_cast(Item); if (Itemt == 0) { TokError("untyped list element in unary operator"); return 0; @@ -790,7 +790,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { return 0; } Lex.Lex(); // eat the ')' - return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass); + return (new UnOpInit(Code, LHS, Type))->Fold(CurRec, CurMultiClass); } case tgtok::XConcat: @@ -825,7 +825,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the '(' - SmallVector InitList; + SmallVector InitList; InitList.push_back(ParseValue(CurRec)); if (InitList.back() == 0) return 0; @@ -847,15 +847,15 @@ const Init *TGParser::ParseOperation(Record *CurRec) { // shorthand for nesting them. if (Code == BinOpInit::STRCONCAT) { while (InitList.size() > 2) { - const Init *RHS = InitList.pop_back_val(); - RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type)) + Init *RHS = InitList.pop_back_val(); + RHS = (new BinOpInit(Code, InitList.back(), RHS, Type)) ->Fold(CurRec, CurMultiClass); InitList.back() = RHS; } } if (InitList.size() == 2) - return (BinOpInit::get(Code, InitList[0], InitList[1], Type)) + return (new BinOpInit(Code, InitList[0], InitList[1], Type)) ->Fold(CurRec, CurMultiClass); Error(OpLoc, "expected two operands to operator"); @@ -888,7 +888,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the '(' - const Init *LHS = ParseValue(CurRec); + Init *LHS = ParseValue(CurRec); if (LHS == 0) return 0; if (Lex.getCode() != tgtok::comma) { @@ -897,7 +897,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the ',' - const Init *MHS = ParseValue(CurRec); + Init *MHS = ParseValue(CurRec); if (MHS == 0) return 0; if (Lex.getCode() != tgtok::comma) { @@ -906,7 +906,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { } Lex.Lex(); // eat the ',' - const Init *RHS = ParseValue(CurRec); + Init *RHS = ParseValue(CurRec); if (RHS == 0) return 0; if (Lex.getCode() != tgtok::r_paren) { @@ -920,23 +920,23 @@ const Init *TGParser::ParseOperation(Record *CurRec) { case tgtok::XIf: { // FIXME: The `!if' operator doesn't handle non-TypedInit well at // all. This can be made much more robust. - const TypedInit *MHSt = dynamic_cast(MHS); - const TypedInit *RHSt = dynamic_cast(RHS); + TypedInit *MHSt = dynamic_cast(MHS); + TypedInit *RHSt = dynamic_cast(RHS); RecTy *MHSTy = 0; RecTy *RHSTy = 0; if (MHSt == 0 && RHSt == 0) { - const BitsInit *MHSbits = dynamic_cast(MHS); - const BitsInit *RHSbits = dynamic_cast(RHS); + BitsInit *MHSbits = dynamic_cast(MHS); + BitsInit *RHSbits = dynamic_cast(RHS); if (MHSbits && RHSbits && MHSbits->getNumBits() == RHSbits->getNumBits()) { Type = new BitRecTy(); break; } else { - const BitInit *MHSbit = dynamic_cast(MHS); - const BitInit *RHSbit = dynamic_cast(RHS); + BitInit *MHSbit = dynamic_cast(MHS); + BitInit *RHSbit = dynamic_cast(RHS); if (MHSbit && RHSbit) { Type = new BitRecTy(); @@ -964,7 +964,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { break; } case tgtok::XForEach: { - const TypedInit *MHSt = dynamic_cast(MHS); + TypedInit *MHSt = dynamic_cast(MHS); if (MHSt == 0) { TokError("could not get type for !foreach"); return 0; @@ -973,7 +973,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { break; } case tgtok::XSubst: { - const TypedInit *RHSt = dynamic_cast(RHS); + TypedInit *RHSt = dynamic_cast(RHS); if (RHSt == 0) { TokError("could not get type for !subst"); return 0; @@ -982,7 +982,7 @@ const Init *TGParser::ParseOperation(Record *CurRec) { break; } } - return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec, + return (new TernOpInit(Code, LHS, MHS, RHS, Type))->Fold(CurRec, CurMultiClass); } } @@ -1038,11 +1038,11 @@ RecTy *TGParser::ParseOperatorType() { /// SimpleValue ::= SRLTOK '(' Value ',' Value ')' /// SimpleValue ::= STRCONCATTOK '(' Value ',' Value ')' /// -const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { - const Init *R = 0; +Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { + Init *R = 0; switch (Lex.getCode()) { default: TokError("Unknown token when parsing a value"); break; - case tgtok::IntVal: R = IntInit::get(Lex.getCurIntVal()); Lex.Lex(); break; + case tgtok::IntVal: R = new IntInit(Lex.getCurIntVal()); Lex.Lex(); break; case tgtok::StrVal: { std::string Val = Lex.getCurStrVal(); Lex.Lex(); @@ -1053,15 +1053,15 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { Lex.Lex(); } - R = StringInit::get(Val); + R = new StringInit(Val); break; } case tgtok::CodeFragment: - R = CodeInit::get(Lex.getCurStrVal()); + R = new CodeInit(Lex.getCurStrVal()); Lex.Lex(); break; case tgtok::question: - R = UnsetInit::get(); + R = new UnsetInit(); Lex.Lex(); break; case tgtok::Id: { @@ -1085,7 +1085,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { return 0; } - std::vector ValueList = ParseValueList(CurRec, Class); + std::vector ValueList = ParseValueList(CurRec, Class); if (ValueList.empty()) return 0; if (Lex.getCode() != tgtok::greater) { @@ -1110,12 +1110,12 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { Records.addDef(NewRec); // The result of the expression is a reference to the new record. - return DefInit::get(NewRec); + return new DefInit(NewRec); } case tgtok::l_brace: { // Value ::= '{' ValueList '}' SMLoc BraceLoc = Lex.getLoc(); Lex.Lex(); // eat the '{' - std::vector Vals; + std::vector Vals; if (Lex.getCode() != tgtok::r_brace) { Vals = ParseValueList(CurRec); @@ -1127,22 +1127,21 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { } Lex.Lex(); // eat the '}' - SmallVector NewBits(Vals.size()); - + BitsInit *Result = new BitsInit(Vals.size()); for (unsigned i = 0, e = Vals.size(); i != e; ++i) { - const Init *Bit = Vals[i]->convertInitializerTo(new BitRecTy()); + Init *Bit = Vals[i]->convertInitializerTo(new BitRecTy()); if (Bit == 0) { Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+ ") is not convertable to a bit"); return 0; } - NewBits[Vals.size()-i-1] = Bit; + Result->setBit(Vals.size()-i-1, Bit); } - return BitsInit::get(NewBits.begin(), NewBits.end()); + return Result; } case tgtok::l_square: { // Value ::= '[' ValueList ']' Lex.Lex(); // eat the '[' - std::vector Vals; + std::vector Vals; RecTy *DeducedEltTy = 0; ListRecTy *GivenListTy = 0; @@ -1190,10 +1189,10 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { // Check elements RecTy *EltTy = 0; - for (std::vector::iterator i = Vals.begin(), ie = Vals.end(); + for (std::vector::iterator i = Vals.begin(), ie = Vals.end(); i != ie; ++i) { - const TypedInit *TArg = dynamic_cast(*i); + TypedInit *TArg = dynamic_cast(*i); if (TArg == 0) { TokError("Untyped list element"); return 0; @@ -1237,7 +1236,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { DeducedEltTy = EltTy; } - return ListInit::get(Vals, DeducedEltTy); + return new ListInit(Vals, DeducedEltTy); } case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')' Lex.Lex(); // eat the '(' @@ -1246,7 +1245,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { return 0; } - const Init *Operator = ParseValue(CurRec); + Init *Operator = ParseValue(CurRec); if (Operator == 0) return 0; // If the operator name is present, parse it. @@ -1260,7 +1259,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { Lex.Lex(); // eat the VarName. } - std::vector > DagArgs; + std::vector > DagArgs; if (Lex.getCode() != tgtok::r_paren) { DagArgs = ParseDagArgList(CurRec); if (DagArgs.empty()) return 0; @@ -1272,7 +1271,7 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { } Lex.Lex(); // eat the ')' - return DagInit::get(Operator, OperatorName, DagArgs); + return new DagInit(Operator, OperatorName, DagArgs); } case tgtok::XHead: @@ -1302,8 +1301,8 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { /// ValueSuffix ::= '[' BitList ']' /// ValueSuffix ::= '.' ID /// -const Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType) { - const Init *Result = ParseSimpleValue(CurRec, ItemType); +Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType) { + Init *Result = ParseSimpleValue(CurRec, ItemType); if (Result == 0) return 0; // Parse the suffixes now if present. @@ -1362,7 +1361,7 @@ const Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType) { Result->getAsString() + "'"); return 0; } - Result = FieldInit::get(Result, Lex.getCurStrVal()); + Result = new FieldInit(Result, Lex.getCurStrVal()); Lex.Lex(); // eat field name break; } @@ -1373,20 +1372,20 @@ const Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType) { /// /// ParseDagArgList ::= Value (':' VARNAME)? /// ParseDagArgList ::= ParseDagArgList ',' Value (':' VARNAME)? -std::vector > +std::vector > TGParser::ParseDagArgList(Record *CurRec) { - std::vector > Result; + std::vector > Result; while (1) { - const Init *Val = ParseValue(CurRec); - if (Val == 0) return std::vector >(); + Init *Val = ParseValue(CurRec); + if (Val == 0) return std::vector >(); // If the variable name is present, add it. std::string VarName; if (Lex.getCode() == tgtok::colon) { if (Lex.Lex() != tgtok::VarName) { // eat the ':' TokError("expected variable name in dag literal"); - return std::vector >(); + return std::vector >(); } VarName = Lex.getCurStrVal(); Lex.Lex(); // eat the VarName. @@ -1408,10 +1407,9 @@ TGParser::ParseDagArgList(Record *CurRec) { /// /// ValueList ::= Value (',' Value) /// -std::vector TGParser::ParseValueList(Record *CurRec, - Record *ArgsRec, - RecTy *EltTy) { - std::vector Result; +std::vector TGParser::ParseValueList(Record *CurRec, Record *ArgsRec, + RecTy *EltTy) { + std::vector Result; RecTy *ItemType = EltTy; unsigned int ArgN = 0; if (ArgsRec != 0 && EltTy == 0) { @@ -1422,7 +1420,7 @@ std::vector TGParser::ParseValueList(Record *CurRec, ++ArgN; } Result.push_back(ParseValue(CurRec, ItemType)); - if (Result.back() == 0) return std::vector(); + if (Result.back() == 0) return std::vector(); while (Lex.getCode() == tgtok::comma) { Lex.Lex(); // Eat the comma @@ -1431,7 +1429,7 @@ std::vector TGParser::ParseValueList(Record *CurRec, const std::vector &TArgs = ArgsRec->getTemplateArgs(); if (ArgN >= TArgs.size()) { TokError("too many template arguments"); - return std::vector(); + return std::vector(); } const RecordVal *RV = ArgsRec->getValue(TArgs[ArgN]); assert(RV && "Template argument record not found??"); @@ -1439,7 +1437,7 @@ std::vector TGParser::ParseValueList(Record *CurRec, ++ArgN; } Result.push_back(ParseValue(CurRec, ItemType)); - if (Result.back() == 0) return std::vector(); + if (Result.back() == 0) return std::vector(); } return Result; @@ -1492,7 +1490,7 @@ std::string TGParser::ParseDeclaration(Record *CurRec, if (Lex.getCode() == tgtok::equal) { Lex.Lex(); SMLoc ValLoc = Lex.getLoc(); - const Init *Val = ParseValue(CurRec, Type); + Init *Val = ParseValue(CurRec, Type); if (Val == 0 || SetValue(CurRec, ValLoc, DeclName, std::vector(), Val)) return ""; @@ -1576,7 +1574,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) { RecTy *Type = Field->getType(); - const Init *Val = ParseValue(CurRec, Type); + Init *Val = ParseValue(CurRec, Type); if (Val == 0) return true; if (Lex.getCode() != tgtok::semi) @@ -1776,7 +1774,7 @@ std::vector TGParser::ParseLetList() { } Lex.Lex(); // eat the '='. - const Init *Val = ParseValue(0); + Init *Val = ParseValue(0); if (Val == 0) return std::vector(); // Now that we have everything, add the record. @@ -1950,7 +1948,7 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { // template parameters. MultiClass *MC = MultiClasses[Ref.Rec->getName()]; assert(MC && "Didn't lookup multiclass correctly?"); - std::vector &TemplateVals = Ref.TemplateArgs; + std::vector &TemplateVals = Ref.TemplateArgs; // Verify that the correct number of template arguments were specified. const std::vector &TArgs = MC->Rec.getTemplateArgs(); diff --git a/utils/TableGen/TGParser.h b/utils/TableGen/TGParser.h index 82a8a8ceeca..94a1c2b2b25 100644 --- a/utils/TableGen/TGParser.h +++ b/utils/TableGen/TGParser.h @@ -25,7 +25,7 @@ namespace llvm { class RecordVal; class RecordKeeper; struct RecTy; - class Init; + struct Init; struct MultiClass; struct SubClassReference; struct SubMultiClassReference; @@ -33,10 +33,10 @@ namespace llvm { struct LetRecord { std::string Name; std::vector Bits; - const Init *Value; + Init *Value; SMLoc Loc; - LetRecord(const std::string &N, const std::vector &B, - const Init *V, SMLoc L) + LetRecord(const std::string &N, const std::vector &B, Init *V, + SMLoc L) : Name(N), Bits(B), Value(V), Loc(L) { } }; @@ -73,7 +73,7 @@ public: private: // Semantic analysis methods. bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV); bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName, - const std::vector &BitList, const Init *V); + const std::vector &BitList, Init *V); bool AddSubClass(Record *Rec, SubClassReference &SubClass); bool AddSubMultiClass(MultiClass *CurMC, SubMultiClassReference &SubMultiClass); @@ -98,20 +98,18 @@ private: // Parser methods. SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm); SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC); - const Init *ParseIDValue(Record *CurRec); - const Init *ParseIDValue(Record *CurRec, const std::string &Name, - SMLoc NameLoc); - const Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0); - const Init *ParseValue(Record *CurRec, RecTy *ItemType = 0); - std::vector ParseValueList(Record *CurRec, Record *ArgsRec = 0, - RecTy *EltTy = 0); - std::vector > ParseDagArgList(Record *); + Init *ParseIDValue(Record *CurRec); + Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc); + Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0); + Init *ParseValue(Record *CurRec, RecTy *ItemType = 0); + std::vector ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0); + std::vector > ParseDagArgList(Record *); bool ParseOptionalRangeList(std::vector &Ranges); bool ParseOptionalBitList(std::vector &Ranges); std::vector ParseRangeList(); bool ParseRangePiece(std::vector &Ranges); RecTy *ParseType(); - const Init *ParseOperation(Record *CurRec); + Init *ParseOperation(Record *CurRec); RecTy *ParseOperatorType(); std::string ParseObjectName(); Record *ParseClassID(); diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 23a67c0b84b..e8eacb841d0 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -208,7 +208,6 @@ int main(int argc, char **argv) { if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) { errs() << "Could not open input file '" << InputFilename << "': " << ec.message() <<"\n"; - Init::ReleaseMemory(); return 1; } MemoryBuffer *F = File.take(); @@ -222,30 +221,25 @@ int main(int argc, char **argv) { TGParser Parser(SrcMgr, Records); - if (Parser.ParseFile()) { - Init::ReleaseMemory(); + if (Parser.ParseFile()) return 1; - } std::string Error; tool_output_file Out(OutputFilename.c_str(), Error); if (!Error.empty()) { errs() << argv[0] << ": error opening " << OutputFilename << ":" << Error << "\n"; - Init::ReleaseMemory(); return 1; } if (!DependFilename.empty()) { if (OutputFilename == "-") { errs() << argv[0] << ": the option -d must be used together with -o\n"; - Init::ReleaseMemory(); return 1; } tool_output_file DepOut(DependFilename.c_str(), Error); if (!Error.empty()) { errs() << argv[0] << ": error opening " << DependFilename << ":" << Error << "\n"; - Init::ReleaseMemory(); return 1; } DepOut.os() << DependFilename << ":"; @@ -388,14 +382,11 @@ int main(int argc, char **argv) { } default: assert(1 && "Invalid Action"); - Init::ReleaseMemory(); return 1; } // Declare success. Out.keep(); - - Init::ReleaseMemory(); return 0; } catch (const TGError &Error) { @@ -408,7 +399,5 @@ int main(int argc, char **argv) { errs() << argv[0] << ": Unknown unexpected exception occurred.\n"; } - Init::ReleaseMemory(); - return 1; } diff --git a/utils/TableGen/X86RecognizableInstr.cpp b/utils/TableGen/X86RecognizableInstr.cpp index f7170c41e77..f7518a988cc 100644 --- a/utils/TableGen/X86RecognizableInstr.cpp +++ b/utils/TableGen/X86RecognizableInstr.cpp @@ -162,7 +162,7 @@ static bool isRegFormat(uint8_t form) { /// @param init - A reference to the BitsInit to be decoded. /// @return - The field, with the first bit in the BitsInit as the lowest /// order bit. -static uint8_t byteFromBitsInit(const BitsInit &init) { +static uint8_t byteFromBitsInit(BitsInit &init) { int width = init.getNumBits(); assert(width <= 8 && "Field is too large for uint8_t!"); @@ -173,7 +173,7 @@ static uint8_t byteFromBitsInit(const BitsInit &init) { uint8_t ret = 0; for (index = 0; index < width; index++) { - if (static_cast(init.getBit(index))->getValue()) + if (static_cast(init.getBit(index))->getValue()) ret |= mask; mask <<= 1; @@ -189,7 +189,7 @@ static uint8_t byteFromBitsInit(const BitsInit &init) { /// @param name - The name of the field in the record. /// @return - The field, as translated by byteFromBitsInit(). static uint8_t byteFromRec(const Record* rec, const std::string &name) { - const BitsInit* bits = rec->getValueAsBitsInit(name); + BitsInit* bits = rec->getValueAsBitsInit(name); return byteFromBitsInit(*bits); }