diff --git a/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp b/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp --- a/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp +++ b/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp @@ -67,6 +67,7 @@ RecordKeeper &Records; class VarLenInst { + RecordVal *TheDef; size_t NumBits; // Set if any of the segment is not fixed value. @@ -80,7 +81,7 @@ public: VarLenInst() : NumBits(0U), HasDynamicSegment(false) {} - explicit VarLenInst(const DagInit *DI); + explicit VarLenInst(const DagInit *DI, RecordVal *TheDef); /// Number of bits size_t size() const { return NumBits; } @@ -114,7 +115,9 @@ } // end anonymous namespace -VarLenCodeEmitterGen::VarLenInst::VarLenInst(const DagInit *DI) : NumBits(0U) { +VarLenCodeEmitterGen::VarLenInst::VarLenInst(const DagInit *DI, + RecordVal *TheDef) + : TheDef(TheDef), NumBits(0U) { buildRec(DI); for (const auto &S : Segments) NumBits += S.first; @@ -132,48 +135,50 @@ const Init *Arg = DI->getArg(i); if (const auto *BI = dyn_cast(Arg)) { if (!BI->isComplete()) - PrintFatalError("Expecting complete bits init in `" + Op + "`"); + PrintFatalError(TheDef->getLoc(), + "Expecting complete bits init in `" + Op + "`"); Segments.push_back({BI->getNumBits(), BI}); } else if (const auto *BI = dyn_cast(Arg)) { if (!BI->isConcrete()) - PrintFatalError("Expecting concrete bit init in `" + Op + "`"); + PrintFatalError(TheDef->getLoc(), + "Expecting concrete bit init in `" + Op + "`"); Segments.push_back({1, BI}); } else if (const auto *SubDI = dyn_cast(Arg)) { buildRec(SubDI); } else { - PrintFatalError("Unrecognized type of argument in `" + Op + - "`: " + Arg->getAsString()); + PrintFatalError(TheDef->getLoc(), "Unrecognized type of argument in `" + + Op + "`: " + Arg->getAsString()); } } } else if (Op == "operand") { // (operand , <# of bits>) if (DI->getNumArgs() != 2) - PrintFatalError("Expecting 2 arguments for `operand`"); + PrintFatalError(TheDef->getLoc(), "Expecting 2 arguments for `operand`"); HasDynamicSegment = true; const Init *OperandName = DI->getArg(0), *NumBits = DI->getArg(1); if (!isa(OperandName) || !isa(NumBits)) - PrintFatalError("Invalid argument types for `operand`"); + PrintFatalError(TheDef->getLoc(), "Invalid argument types for `operand`"); auto NumBitsVal = cast(NumBits)->getValue(); if (NumBitsVal <= 0) - PrintFatalError("Invalid number of bits for `operand`"); + PrintFatalError(TheDef->getLoc(), "Invalid number of bits for `operand`"); Segments.push_back({NumBitsVal, OperandName}); } else if (Op == "slice") { // (slice , , ) if (DI->getNumArgs() != 3) - PrintFatalError("Expecting 3 arguments for `slice`"); + PrintFatalError(TheDef->getLoc(), "Expecting 3 arguments for `slice`"); HasDynamicSegment = true; Init *OperandName = DI->getArg(0), *HiBit = DI->getArg(1), *LoBit = DI->getArg(2); if (!isa(OperandName) || !isa(HiBit) || !isa(LoBit)) - PrintFatalError("Invalid argument types for `slice`"); + PrintFatalError(TheDef->getLoc(), "Invalid argument types for `slice`"); auto HiBitVal = cast(HiBit)->getValue(), LoBitVal = cast(LoBit)->getValue(); if (HiBitVal < 0 || LoBitVal < 0) - PrintFatalError("Invalid bit range for `slice`"); + PrintFatalError(TheDef->getLoc(), "Invalid bit range for `slice`"); bool NeedSwap = false; unsigned NumBits = 0U; if (HiBitVal < LoBitVal) { @@ -217,14 +222,16 @@ for (auto &KV : EBM) { HwModes.insert(KV.first); Record *EncodingDef = KV.second; - auto *DI = EncodingDef->getValueAsDag("Inst"); - VarLenInsts.insert({EncodingDef, VarLenInst(DI)}); + RecordVal *RV = EncodingDef->getValue("Inst"); + DagInit *DI = cast(RV->getValue()); + VarLenInsts.insert({EncodingDef, VarLenInst(DI, RV)}); } continue; } } - auto *DI = R->getValueAsDag("Inst"); - VarLenInsts.insert({R, VarLenInst(DI)}); + RecordVal *RV = R->getValue("Inst"); + DagInit *DI = cast(RV->getValue()); + VarLenInsts.insert({R, VarLenInst(DI, RV)}); } // Emit function declaration