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