llvm.org GIT mirror llvm / ce04a4a
TableGen: Remove the cast-from-string-to-variable-reference feature Summary: Cast-from-string for records isn't going away, but cast-from-string for variables is a pretty dodgy feature to have, especially when referencing template arguments. It's doubtful that this ever worked in a reliable way, and nobody seems to be using it, so let's get rid of it and get some related cleanups. Change-Id: I395ac8a43fef4cf98e611f2f552300d21e99b66a Reviewers: arsenm, craig.topper, tra, MartinO Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D44195 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327844 91177308-0d34-0410-b5e6-96231b3b80d8 Nicolai Haehnle 1 year, 6 months ago
5 changed file(s) with 32 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
214214 references to template arguments of the outer multiclass).
215215
216216 If the type of 'a' does not match *type*, TableGen aborts with an error.
217
218 For historical reasons, 'a' can also be the name of a variable or a
219 template argument in some cases, but this use is unreliable and is
220 discouraged.
221217
222218 Otherwise, perform a normal type cast e.g. between an int and a bit, or
223219 between record types. This allows casting a record to a subclass, though if
743743
744744 // Fold - If possible, fold this to a simpler init. Return this if not
745745 // possible to fold.
746 virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
746 virtual Init *Fold(Record *CurRec) const = 0;
747747
748748 Init *getBit(unsigned Bit) const override;
749749 };
791791
792792 // Fold - If possible, fold this to a simpler init. Return this if not
793793 // possible to fold.
794 Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
794 Init *Fold(Record *CurRec) const override;
795795
796796 Init *resolveReferences(Resolver &R) const override;
797797
845845
846846 // Fold - If possible, fold this to a simpler init. Return this if not
847847 // possible to fold.
848 Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
848 Init *Fold(Record *CurRec) const override;
849849
850850 Init *resolveReferences(Resolver &R) const override;
851851
903903
904904 // Fold - If possible, fold this to a simpler init. Return this if not
905905 // possible to fold.
906 Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const override;
906 Init *Fold(Record *CurRec) const override;
907907
908908 bool isComplete() const override {
909909 return LHS->isComplete() && MHS->isComplete() && RHS->isComplete();
699699 ProfileUnOpInit(ID, getOpcode(), getOperand(), getType());
700700 }
701701
702 Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
702 Init *UnOpInit::Fold(Record *CurRec) const {
703703 switch (getOpcode()) {
704704 case CAST:
705705 if (isa(getType())) {
713713 return StringInit::get(LHSi->getAsString());
714714 } else if (isa(getType())) {
715715 if (StringInit *Name = dyn_cast(LHS)) {
716 // From TGParser::ParseIDValue
717 if (CurRec) {
718 if (const RecordVal *RV = CurRec->getValue(Name)) {
719 if (RV->getType() != getType())
720 PrintFatalError("type mismatch in cast");
721 return VarInit::get(Name, RV->getType());
722 }
723
724 Init *TemplateArgName = QualifyName(*CurRec, CurMultiClass, Name,
725 ":");
726
727 if (CurRec->isTemplateArg(TemplateArgName)) {
728 const RecordVal *RV = CurRec->getValue(TemplateArgName);
729 assert(RV && "Template arg doesn't exist??");
730
731 if (RV->getType() != getType())
732 PrintFatalError("type mismatch in cast");
733
734 return VarInit::get(TemplateArgName, RV->getType());
735 }
736 }
737
738 if (CurMultiClass) {
739 Init *MCName = QualifyName(CurMultiClass->Rec, CurMultiClass, Name,
740 "::");
741
742 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
743 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
744 assert(RV && "Template arg doesn't exist??");
745
746 if (RV->getType() != getType())
747 PrintFatalError("type mismatch in cast");
748
749 return VarInit::get(MCName, RV->getType());
750 }
751 }
752716 assert(CurRec && "NULL pointer");
753717 if (Record *D = (CurRec->getRecords()).getDef(Name->getValue()))
754718 return DefInit::get(D);
755719
756720 PrintFatalError(CurRec->getLoc(),
757 "Undefined reference:'" + Name->getValue() + "'\n");
721 Twine("Undefined reference to record: '") +
722 Name->getValue() + "'\n");
758723 }
759724 }
760725
798763
799764 if (LHS != lhs)
800765 return (UnOpInit::get(getOpcode(), lhs, getType()))
801 ->Fold(R.getCurrentRecord(), nullptr);
802 return Fold(R.getCurrentRecord(), nullptr);
766 ->Fold(R.getCurrentRecord());
767 return Fold(R.getCurrentRecord());
803768 }
804769
805770 std::string UnOpInit::getAsString() const {
850815 return StringInit::get(Concat);
851816 }
852817
853 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
818 Init *BinOpInit::Fold(Record *CurRec) const {
854819 switch (getOpcode()) {
855820 case CONCAT: {
856821 DagInit *LHSs = dyn_cast(LHS);
973938
974939 if (LHS != lhs || RHS != rhs)
975940 return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))
976 ->Fold(R.getCurrentRecord(), nullptr);
977 return Fold(R.getCurrentRecord(), nullptr);
941 ->Fold(R.getCurrentRecord());
942 return Fold(R.getCurrentRecord());
978943 }
979944
980945 std::string BinOpInit::getAsString() const {
10831048 return nullptr;
10841049 }
10851050
1086 Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
1051 Init *TernOpInit::Fold(Record *CurRec) const {
10871052 switch (getOpcode()) {
10881053 case SUBST: {
10891054 DefInit *LHSd = dyn_cast(LHS);
11981163
11991164 if (LHS != lhs || MHS != mhs || RHS != rhs)
12001165 return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))
1201 ->Fold(R.getCurrentRecord(), nullptr);
1202 return Fold(R.getCurrentRecord(), nullptr);
1166 ->Fold(R.getCurrentRecord());
1167 return Fold(R.getCurrentRecord());
12031168 }
12041169
12051170 std::string TernOpInit::getAsString() const {
14001365 return nullptr;
14011366
14021367 return UnOpInit::get(UnOpInit::CAST, const_cast(this), Ty)
1403 ->Fold(nullptr, nullptr);
1368 ->Fold(nullptr);
14041369 }
14051370
14061371 Init *TypedInit::convertInitListSlice(ArrayRef Elements) const {
22012166 }
22022167
22032168 if (BinOpInit *BinOp = dyn_cast(NewName))
2204 NewName = BinOp->Fold(&CurRec, CurMultiClass);
2169 NewName = BinOp->Fold(&CurRec);
22052170 return NewName;
22062171 }
22072172
935935 return nullptr;
936936 }
937937 Lex.Lex(); // eat the ')'
938 return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
938 return (UnOpInit::get(Code, LHS, Type))->Fold(CurRec);
939939 }
940940
941941 case tgtok::XIsA: {
11231123 Code == BinOpInit::AND || Code == BinOpInit::OR) {
11241124 while (InitList.size() > 2) {
11251125 Init *RHS = InitList.pop_back_val();
1126 RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type))
1127 ->Fold(CurRec, CurMultiClass);
1126 RHS = (BinOpInit::get(Code, InitList.back(), RHS, Type))->Fold(CurRec);
11281127 InitList.back() = RHS;
11291128 }
11301129 }
11311130
11321131 if (InitList.size() == 2)
11331132 return (BinOpInit::get(Code, InitList[0], InitList[1], Type))
1134 ->Fold(CurRec, CurMultiClass);
1133 ->Fold(CurRec);
11351134
11361135 Error(OpLoc, "expected two operands to operator");
11371136 return nullptr;
12361235 }
12371236
12381237 return (TernOpInit::get(TernOpInit::FOREACH, LHS, MHS, RHS, OutType))
1239 ->Fold(CurRec, CurMultiClass);
1238 ->Fold(CurRec);
12401239 }
12411240
12421241 case tgtok::XDag:
13771376 break;
13781377 }
13791378 }
1380 return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec,
1381 CurMultiClass);
1379 return (TernOpInit::get(Code, LHS, MHS, RHS, Type))->Fold(CurRec);
13821380 }
13831381
13841382 case tgtok::XFoldl: {
19951993 break;
19961994 }
19971995
1998 Result = BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS,
1999 StringRecTy::get())->Fold(CurRec, CurMultiClass);
1996 Result =
1997 BinOpInit::get(BinOpInit::STRCONCAT, LHS, RHS, StringRecTy::get())
1998 ->Fold(CurRec);
20001999 break;
20012000 }
20022001 }
28312830 if (DefNameString) {
28322831 // We have a fully expanded string so there are no operators to
28332832 // resolve. We should concatenate the given prefix and name.
2834 DefName =
2835 BinOpInit::get(BinOpInit::STRCONCAT,
2836 UnOpInit::get(UnOpInit::CAST, DefmPrefix,
2837 StringRecTy::get())->Fold(DefProto, &MC),
2838 DefName, StringRecTy::get())->Fold(DefProto, &MC);
2833 DefName = BinOpInit::get(
2834 BinOpInit::STRCONCAT,
2835 UnOpInit::get(UnOpInit::CAST, DefmPrefix, StringRecTy::get())
2836 ->Fold(DefProto),
2837 DefName, StringRecTy::get())
2838 ->Fold(DefProto);
28392839 }
28402840
28412841 // Make a trail of SMLocs from the multiclass instantiations.
1111 multiclass M0 {
1212 // This should work fine.
1313 def _m00 : B(s)>;
14 // CHECK: error: Undefined reference:'d1_r1_no_such_record'
14 // CHECK: error: Undefined reference to record: 'd1_r1_no_such_record'
1515 def _m01: B(s#"_no_such_record")>;
1616 }
1717