Index: docs/TableGen/LangIntro.rst =================================================================== --- docs/TableGen/LangIntro.rst +++ docs/TableGen/LangIntro.rst @@ -211,10 +211,6 @@ If the type of 'a' does not match *type*, TableGen aborts with an error. - For historical reasons, 'a' can also be the name of a variable or a - template argument in some cases, but this use is unreliable and is - discouraged. - Otherwise, perform a normal type cast e.g. between an int and a bit, or between record types. This allows casting a record to a subclass, though if the types do not match, constant folding will be inhibited. !cast Index: include/llvm/TableGen/Record.h =================================================================== --- include/llvm/TableGen/Record.h +++ include/llvm/TableGen/Record.h @@ -744,7 +744,7 @@ // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0; + virtual Init *Fold(Record *CurRec) const = 0; Init *getBit(unsigned Bit) const override; }; @@ -792,7 +792,7 @@ // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override; + Init *Fold(Record *CurRec) const override; Init *resolveReferences(Resolver &R) const override; @@ -846,7 +846,7 @@ // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override; + Init *Fold(Record *CurRec) const override; Init *resolveReferences(Resolver &R) const override; @@ -904,7 +904,7 @@ // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override; + Init *Fold(Record *CurRec) const override; bool isComplete() const override { return LHS->isComplete() && MHS->isComplete() && RHS->isComplete(); Index: lib/TableGen/Record.cpp =================================================================== --- lib/TableGen/Record.cpp +++ lib/TableGen/Record.cpp @@ -700,7 +700,7 @@ ProfileUnOpInit(ID, getOpcode(), getOperand(), getType()); } -Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { +Init *UnOpInit::Fold(Record *CurRec) const { switch (getOpcode()) { case CAST: if (isa(getType())) { @@ -714,42 +714,6 @@ return StringInit::get(LHSi->getAsString()); } else if (isa(getType())) { if (StringInit *Name = dyn_cast(LHS)) { - // From TGParser::ParseIDValue - if (CurRec) { - if (const RecordVal *RV = CurRec->getValue(Name)) { - if (RV->getType() != getType()) - PrintFatalError("type mismatch in cast"); - return VarInit::get(Name, RV->getType()); - } - - Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name, - ":"); - - if (CurRec->isTemplateArg(TemplateArgName)) { - const RecordVal *RV = CurRec->getValue(TemplateArgName); - assert(RV && "Template arg doesn't exist??"); - - if (RV->getType() != getType()) - PrintFatalError("type mismatch in cast"); - - return VarInit::get(TemplateArgName, RV->getType()); - } - } - - if (CurMultiClass) { - Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name, - "::"); - - if (CurMultiClass->Rec.isTemplateArg(MCName)) { - const RecordVal *RV = CurMultiClass->Rec.getValue(MCName); - assert(RV && "Template arg doesn't exist??"); - - if (RV->getType() != getType()) - PrintFatalError("type mismatch in cast"); - - return VarInit::get(MCName, RV->getType()); - } - } assert(CurRec && "NULL pointer"); if (Record *D = (CurRec->getRecords()).getDef(Name->getValue())) return DefInit::get(D); @@ -799,8 +763,8 @@ if (LHS != lhs) return (UnOpInit::get(getOpcode(), lhs, getType())) - ->Fold(R.getCurrentRecord(), nullptr); - return Fold(R.getCurrentRecord(), nullptr); + ->Fold(R.getCurrentRecord()); + return Fold(R.getCurrentRecord()); } std::string UnOpInit::getAsString() const { @@ -851,7 +815,7 @@ return StringInit::get(Concat); } -Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { +Init *BinOpInit::Fold(Record *CurRec) const { switch (getOpcode()) { case CONCAT: { DagInit *LHSs = dyn_cast(LHS); @@ -974,8 +938,8 @@ if (LHS != lhs || RHS != rhs) return (BinOpInit::get(getOpcode(), lhs, rhs, getType())) - ->Fold(R.getCurrentRecord(), nullptr); - return Fold(R.getCurrentRecord(), nullptr); + ->Fold(R.getCurrentRecord()); + return Fold(R.getCurrentRecord()); } std::string BinOpInit::getAsString() const { @@ -1084,7 +1048,7 @@ return nullptr; } -Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { +Init *TernOpInit::Fold(Record *CurRec) const { switch (getOpcode()) { case SUBST: { DefInit *LHSd = dyn_cast(LHS); @@ -1199,8 +1163,8 @@ if (LHS != lhs || MHS != mhs || RHS != rhs) return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType())) - ->Fold(R.getCurrentRecord(), nullptr); - return Fold(R.getCurrentRecord(), nullptr); + ->Fold(R.getCurrentRecord()); + return Fold(R.getCurrentRecord()); } std::string TernOpInit::getAsString() const { @@ -1401,7 +1365,7 @@ return nullptr; return UnOpInit::get(UnOpInit::CAST, const_cast(this), Ty) - ->Fold(nullptr, nullptr); + ->Fold(nullptr); } Init *TypedInit::convertInitListSlice(ArrayRef Elements) const { @@ -2202,7 +2166,7 @@ } if (BinOpInit *BinOp = dyn_cast(NewName)) - NewName = BinOp->Fold(&CurRec, CurMultiClass); + NewName = BinOp->Fold(&CurRec); return NewName; } Index: lib/TableGen/TGParser.cpp =================================================================== --- lib/TableGen/TGParser.cpp +++ lib/TableGen/TGParser.cpp @@ -936,7 +936,7 @@ return nullptr; } Lex.Lex(); // eat the ')' - return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass); + return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec); } case tgtok::XIsA: { @@ -1123,15 +1123,14 @@ Code == BinOpInit::AND || Code == BinOpInit::OR) { while (InitList.size() > 2) { Init *RHS = InitList.pop_back_val(); - RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type)) - ->Fold(CurRec, CurMultiClass); + RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type))->Fold(CurRec); InitList.back() = RHS; } } if (InitList.size() == 2) return (BinOpInit::get(Code, InitList[0], InitList[1], Type)) - ->Fold(CurRec, CurMultiClass); + ->Fold(CurRec); Error(OpLoc, "expected two operands to operator"); return nullptr; @@ -1236,7 +1235,7 @@ } return (TernOpInit::get(TernOpInit::FOREACH, LHS, MHS, RHS, OutType)) - ->Fold(CurRec, CurMultiClass); + ->Fold(CurRec); } case tgtok::XDag: @@ -1377,8 +1376,7 @@ break; } } - return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec, - CurMultiClass); + return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec); } case tgtok::XFoldl: { @@ -1995,8 +1993,9 @@ break; } - Result = BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS, - StringRecTy::get())->Fold(CurRec, CurMultiClass); + Result = + BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS, StringRecTy::get()) + ->Fold(CurRec); break; } } @@ -2831,11 +2830,12 @@ if (DefNameString) { // We have a fully expanded string so there are no operators to // resolve. We should concatenate the given prefix and name. - DefName = - BinOpInit::get(BinOpInit::STRCONCAT, - UnOpInit::get(UnOpInit::CAST, DefmPrefix, - StringRecTy::get())->Fold(DefProto, &MC), - DefName, StringRecTy::get())->Fold(DefProto, &MC); + DefName = BinOpInit::get( + BinOpInit::STRCONCAT, + UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get()) + ->Fold(DefProto), + DefName, StringRecTy::get()) + ->Fold(DefProto); } // Make a trail of SMLocs from the multiclass instantiations.