llvm.org GIT mirror llvm / 6cfc806
tblgen: Mechanically move dynamic_cast<> to dyn_cast<>. Some of these dyn_cast<>'s would be better phrased as isa<> or cast<>. That will happen in a future patch. There are also two dyn_cast_or_null<>'s slipped in instead of dyn_cast<>'s, since they were causing crashes with just dyn_cast<>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165646 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Silva 7 years ago
15 changed file(s) with 195 addition(s) and 195 deletion(s). Raw diff Collapse all Expand all
199199 Init *IntRecTy::convertValue(BitsInit *BI) {
200200 int64_t Result = 0;
201201 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
202 if (BitInit *Bit = dynamic_cast>(BI->getBit(i))) {
202 if (BitInit *Bit = dyn_cast>(BI->getBit(i))) {
203203 Result |= Bit->getValue() << i;
204204 } else {
205205 return 0;
614614
615615 Record *ListInit::getElementAsRecord(unsigned i) const {
616616 assert(i < Values.size() && "List element index out of range!");
617 DefInit *DI = dynamic_cast>(Values[i]);
617 DefInit *DI = dyn_cast>(Values[i]);
618618 if (DI == 0) throw "Expected record in list!";
619619 return DI->getDef();
620620 }
649649 // If the element is set to some value, or if we are resolving a reference
650650 // to a specific variable and that variable is explicitly unset, then
651651 // replace the VarListElementInit with it.
652 if (IRV || !dynamic_cast>(E))
652 if (IRV || !dyn_cast>(E))
653653 return E;
654654 return 0;
655655 }
666666 Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
667667 unsigned Elt) const {
668668 Init *Resolved = resolveReferences(R, IRV);
669 OpInit *OResolved = dynamic_cast>(Resolved);
669 OpInit *OResolved = dyn_cast>(Resolved);
670670 if (OResolved) {
671671 Resolved = OResolved->Fold(&R, 0);
672672 }
673673
674674 if (Resolved != this) {
675 TypedInit *Typed = dynamic_cast(Resolved);
675 TypedInit *Typed = dyn_cast(Resolved);
676676 assert(Typed && "Expected typed init for list reference");
677677 if (Typed) {
678678 Init *New = Typed->resolveListElementReference(R, IRV, Elt);
708708 switch (getOpcode()) {
709709 case CAST: {
710710 if (getType()->getAsString() == "string") {
711 StringInit *LHSs = dynamic_cast>(LHS);
711 StringInit *LHSs = dyn_cast>(LHS);
712712 if (LHSs) {
713713 return LHSs;
714714 }
715715
716 DefInit *LHSd = dynamic_cast>(LHS);
716 DefInit *LHSd = dyn_cast>(LHS);
717717 if (LHSd) {
718718 return StringInit::get(LHSd->getDef()->getName());
719719 }
720720
721 IntInit *LHSi = dynamic_cast>(LHS);
721 IntInit *LHSi = dyn_cast>(LHS);
722722 if (LHSi) {
723723 return StringInit::get(LHSi->getAsString());
724724 }
725725 } else {
726 StringInit *LHSs = dynamic_cast>(LHS);
726 StringInit *LHSs = dyn_cast>(LHS);
727727 if (LHSs) {
728728 std::string Name = LHSs->getValue();
729729
772772 break;
773773 }
774774 case HEAD: {
775 ListInit *LHSl = dynamic_cast>(LHS);
775 ListInit *LHSl = dyn_cast>(LHS);
776776 if (LHSl) {
777777 if (LHSl->getSize() == 0) {
778778 assert(0 && "Empty list in car");
783783 break;
784784 }
785785 case TAIL: {
786 ListInit *LHSl = dynamic_cast>(LHS);
786 ListInit *LHSl = dyn_cast>(LHS);
787787 if (LHSl) {
788788 if (LHSl->getSize() == 0) {
789789 assert(0 && "Empty list in cdr");
801801 break;
802802 }
803803 case EMPTY: {
804 ListInit *LHSl = dynamic_cast>(LHS);
804 ListInit *LHSl = dyn_cast>(LHS);
805805 if (LHSl) {
806806 if (LHSl->getSize() == 0) {
807807 return IntInit::get(1);
809809 return IntInit::get(0);
810810 }
811811 }
812 StringInit *LHSs = dynamic_cast>(LHS);
812 StringInit *LHSs = dyn_cast>(LHS);
813813 if (LHSs) {
814814 if (LHSs->getValue().empty()) {
815815 return IntInit::get(1);
864864 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
865865 switch (getOpcode()) {
866866 case CONCAT: {
867 DagInit *LHSs = dynamic_cast(LHS);
868 DagInit *RHSs = dynamic_cast(RHS);
867 DagInit *LHSs = dyn_cast(LHS);
868 DagInit *RHSs = dyn_cast(RHS);
869869 if (LHSs && RHSs) {
870 DefInit *LOp = dynamic_cast(LHSs->getOperator());
871 DefInit *ROp = dynamic_cast(RHSs->getOperator());
870 DefInit *LOp = dyn_cast(LHSs->getOperator());
871 DefInit *ROp = dyn_cast(RHSs->getOperator());
872872 if (LOp == 0 || ROp == 0 || LOp->getDef() != ROp->getDef())
873873 throw "Concated Dag operators do not match!";
874874 std::vector Args;
886886 break;
887887 }
888888 case STRCONCAT: {
889 StringInit *LHSs = dynamic_cast(LHS);
890 StringInit *RHSs = dynamic_cast(RHS);
889 StringInit *LHSs = dyn_cast(LHS);
890 StringInit *RHSs = dyn_cast(RHS);
891891 if (LHSs && RHSs)
892892 return StringInit::get(LHSs->getValue() + RHSs->getValue());
893893 break;
896896 // try to fold eq comparison for 'bit' and 'int', otherwise fallback
897897 // to string objects.
898898 IntInit *L =
899 dynamic_cast>(LHS->convertInitializerTo(IntRecTy::get()));
899 dyn_cast_or_null>(LHS->convertInitializerTo(IntRecTy::get()));
900900 IntInit *R =
901 dynamic_cast>(RHS->convertInitializerTo(IntRecTy::get()));
901 dyn_cast_or_null>(RHS->convertInitializerTo(IntRecTy::get()));
902902
903903 if (L && R)
904904 return IntInit::get(L->getValue() == R->getValue());
905905
906 StringInit *LHSs = dynamic_cast(LHS);
907 StringInit *RHSs = dynamic_cast(RHS);
906 StringInit *LHSs = dyn_cast(LHS);
907 StringInit *RHSs = dyn_cast(RHS);
908908
909909 // Make sure we've resolved
910910 if (LHSs && RHSs)
915915 case SHL:
916916 case SRA:
917917 case SRL: {
918 IntInit *LHSi = dynamic_cast(LHS);
919 IntInit *RHSi = dynamic_cast(RHS);
918 IntInit *LHSi = dyn_cast(LHS);
919 IntInit *RHSi = dyn_cast(RHS);
920920 if (LHSi && RHSi) {
921921 int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
922922 int64_t Result;
989989 MultiClass *CurMultiClass) {
990990 std::vector NewOperands;
991991
992 TypedInit *TArg = dynamic_cast>(Arg);
992 TypedInit *TArg = dyn_cast>(Arg);
993993
994994 // If this is a dag, recurse
995995 if (TArg && TArg->getType()->getAsString() == "dag") {
10031003 }
10041004
10051005 for (int i = 0; i < RHSo->getNumOperands(); ++i) {
1006 OpInit *RHSoo = dynamic_cast>(RHSo->getOperand(i));
1006 OpInit *RHSoo = dyn_cast>(RHSo->getOperand(i));
10071007
10081008 if (RHSoo) {
10091009 Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
10311031
10321032 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
10331033 Record *CurRec, MultiClass *CurMultiClass) {
1034 DagInit *MHSd = dynamic_cast(MHS);
1035 ListInit *MHSl = dynamic_cast(MHS);
1036
1037 OpInit *RHSo = dynamic_cast(RHS);
1034 DagInit *MHSd = dyn_cast(MHS);
1035 ListInit *MHSl = dyn_cast(MHS);
1036
1037 OpInit *RHSo = dyn_cast(RHS);
10381038
10391039 if (!RHSo) {
10401040 throw TGError(CurRec->getLoc(), "!foreach requires an operator\n");
10411041 }
10421042
1043 TypedInit *LHSt = dynamic_cast>(LHS);
1043 TypedInit *LHSt = dyn_cast>(LHS);
10441044
10451045 if (!LHSt) {
10461046 throw TGError(CurRec->getLoc(), "!foreach requires typed variable\n");
11091109 Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
11101110 switch (getOpcode()) {
11111111 case SUBST: {
1112 DefInit *LHSd = dynamic_cast(LHS);
1113 VarInit *LHSv = dynamic_cast(LHS);
1114 StringInit *LHSs = dynamic_cast(LHS);
1115
1116 DefInit *MHSd = dynamic_cast(MHS);
1117 VarInit *MHSv = dynamic_cast(MHS);
1118 StringInit *MHSs = dynamic_cast(MHS);
1119
1120 DefInit *RHSd = dynamic_cast(RHS);
1121 VarInit *RHSv = dynamic_cast(RHS);
1122 StringInit *RHSs = dynamic_cast(RHS);
1112 DefInit *LHSd = dyn_cast(LHS);
1113 VarInit *LHSv = dyn_cast(LHS);
1114 StringInit *LHSs = dyn_cast(LHS);
1115
1116 DefInit *MHSd = dyn_cast(MHS);
1117 VarInit *MHSv = dyn_cast(MHS);
1118 StringInit *MHSs = dyn_cast(MHS);
1119
1120 DefInit *RHSd = dyn_cast(RHS);
1121 VarInit *RHSv = dyn_cast(RHS);
1122 StringInit *RHSs = dyn_cast(RHS);
11231123
11241124 if ((LHSd && MHSd && RHSd)
11251125 || (LHSv && MHSv && RHSv)
11671167 }
11681168
11691169 case IF: {
1170 IntInit *LHSi = dynamic_cast>(LHS);
1170 IntInit *LHSi = dyn_cast>(LHS);
11711171 if (Init *I = LHS->convertInitializerTo(IntRecTy::get()))
1172 LHSi = dynamic_cast>(I);
1172 LHSi = dyn_cast>(I);
11731173 if (LHSi) {
11741174 if (LHSi->getValue()) {
11751175 return MHS;
11891189 Init *lhs = LHS->resolveReferences(R, RV);
11901190
11911191 if (Opc == IF && lhs != LHS) {
1192 IntInit *Value = dynamic_cast>(lhs);
1192 IntInit *Value = dyn_cast>(lhs);
11931193 if (Init *I = lhs->convertInitializerTo(IntRecTy::get()))
1194 Value = dynamic_cast>(I);
1194 Value = dyn_cast>(I);
11951195 if (Value != 0) {
11961196 // Short-circuit
11971197 if (Value->getValue()) {
12851285
12861286 const std::string &VarInit::getName() const {
12871287 StringInit *NameString =
1288 dynamic_cast>(getNameInit());
1288 dyn_cast>(getNameInit());
12891289 assert(NameString && "VarInit name is not a string!");
12901290 return NameString->getValue();
12911291 }
13041304
13051305 RecordVal *RV = R.getValue(getNameInit());
13061306 assert(RV && "Reference to a non-existent variable?");
1307 ListInit *LI = dynamic_cast>(RV->getValue());
1307 ListInit *LI = dyn_cast>(RV->getValue());
13081308 if (!LI) {
1309 TypedInit *VI = dynamic_cast>(RV->getValue());
1309 TypedInit *VI = dyn_cast>(RV->getValue());
13101310 assert(VI && "Invalid list element!");
13111311 return VarListElementInit::get(VI, Elt);
13121312 }
13171317 // If the element is set to some value, or if we are resolving a reference
13181318 // to a specific variable and that variable is explicitly unset, then
13191319 // replace the VarListElementInit with it.
1320 if (IRV || !dynamic_cast>(E))
1320 if (IRV || !dyn_cast>(E))
13211321 return E;
13221322 return 0;
13231323 }
13341334 const std::string &FieldName) const {
13351335 if (isa(getType()))
13361336 if (const RecordVal *Val = R.getValue(VarName)) {
1337 if (RV != Val && (RV || dynamic_cast>(Val->getValue())))
1337 if (RV != Val && (RV || dyn_cast>(Val->getValue())))
13381338 return 0;
13391339 Init *TheInit = Val->getValue();
13401340 assert(TheInit != this && "Infinite loop detected!");
13531353 ///
13541354 Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const {
13551355 if (RecordVal *Val = R.getValue(VarName))
1356 if (RV == Val || (RV == 0 && !dynamic_cast>(Val->getValue())))
1356 if (RV == Val || (RV == 0 && !dyn_cast>(Val->getValue())))
13571357 return Val->getValue();
13581358 return const_cast(this);
13591359 }
14211421 Init *Result = TI->resolveListElementReference(R, RV, Element);
14221422
14231423 if (Result) {
1424 TypedInit *TInit = dynamic_cast>(Result);
1424 TypedInit *TInit = dyn_cast>(Result);
14251425 if (TInit) {
14261426 Init *Result2 = TInit->resolveListElementReference(R, RV, Elt);
14271427 if (Result2) return Result2;
14741474 Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
14751475 unsigned Elt) const {
14761476 if (Init *ListVal = Rec->getFieldInit(R, RV, FieldName))
1477 if (ListInit *LI = dynamic_cast>(ListVal)) {
1477 if (ListInit *LI = dyn_cast>(ListVal)) {
14781478 if (Elt >= LI->getSize()) return 0;
14791479 Init *E = LI->getElement(Elt);
14801480
14811481 // If the element is set to some value, or if we are resolving a
14821482 // reference to a specific variable and that variable is explicitly
14831483 // unset, then replace the VarListElementInit with it.
1484 if (RV || !dynamic_cast>(E))
1484 if (RV || !dyn_cast>(E))
14851485 return E;
14861486 }
14871487 return 0;
16101610 }
16111611
16121612 const std::string &RecordVal::getName() const {
1613 StringInit *NameString = dynamic_cast>(Name);
1613 StringInit *NameString = dyn_cast>(Name);
16141614 assert(NameString && "RecordVal name is not a string!");
16151615 return NameString->getValue();
16161616 }
16401640
16411641 void Record::checkName() {
16421642 // Ensure the record name has string type.
1643 const TypedInit *TypedName = dynamic_cast>(Name);
1643 const TypedInit *TypedName = dyn_cast>(Name);
16441644 assert(TypedName && "Record name is not typed!");
16451645 RecTy *Type = TypedName->getType();
16461646 if (!isa(Type))
16551655
16561656 const std::string &Record::getName() const {
16571657 const StringInit *NameString =
1658 dynamic_cast>(Name);
1658 dyn_cast>(Name);
16591659 assert(NameString && "Record name is not a string!");
16601660 return NameString->getValue();
16611661 }
17721772 throw "Record `" + getName() + "' does not have a field named `" +
17731773 FieldName.str() + "'!\n";
17741774
1775 if (StringInit *SI = dynamic_cast>(R->getValue()))
1775 if (StringInit *SI = dyn_cast>(R->getValue()))
17761776 return SI->getValue();
17771777 throw "Record `" + getName() + "', field `" + FieldName.str() +
17781778 "' does not have a string initializer!";
17881788 throw "Record `" + getName() + "' does not have a field named `" +
17891789 FieldName.str() + "'!\n";
17901790
1791 if (BitsInit *BI = dynamic_cast>(R->getValue()))
1791 if (BitsInit *BI = dyn_cast>(R->getValue()))
17921792 return BI;
17931793 throw "Record `" + getName() + "', field `" + FieldName.str() +
17941794 "' does not have a BitsInit initializer!";
18041804 throw "Record `" + getName() + "' does not have a field named `" +
18051805 FieldName.str() + "'!\n";
18061806
1807 if (ListInit *LI = dynamic_cast>(R->getValue()))
1807 if (ListInit *LI = dyn_cast>(R->getValue()))
18081808 return LI;
18091809 throw "Record `" + getName() + "', field `" + FieldName.str() +
18101810 "' does not have a list initializer!";
18191819 ListInit *List = getValueAsListInit(FieldName);
18201820 std::vector Defs;
18211821 for (unsigned i = 0; i < List->getSize(); i++) {
1822 if (DefInit *DI = dynamic_cast>(List->getElement(i))) {
1822 if (DefInit *DI = dyn_cast>(List->getElement(i))) {
18231823 Defs.push_back(DI->getDef());
18241824 } else {
18251825 throw "Record `" + getName() + "', field `" + FieldName.str() +
18391839 throw "Record `" + getName() + "' does not have a field named `" +
18401840 FieldName.str() + "'!\n";
18411841
1842 if (IntInit *II = dynamic_cast>(R->getValue()))
1842 if (IntInit *II = dyn_cast>(R->getValue()))
18431843 return II->getValue();
18441844 throw "Record `" + getName() + "', field `" + FieldName.str() +
18451845 "' does not have an int initializer!";
18541854 ListInit *List = getValueAsListInit(FieldName);
18551855 std::vector Ints;
18561856 for (unsigned i = 0; i < List->getSize(); i++) {
1857 if (IntInit *II = dynamic_cast>(List->getElement(i))) {
1857 if (IntInit *II = dyn_cast>(List->getElement(i))) {
18581858 Ints.push_back(II->getValue());
18591859 } else {
18601860 throw "Record `" + getName() + "', field `" + FieldName.str() +
18731873 ListInit *List = getValueAsListInit(FieldName);
18741874 std::vector Strings;
18751875 for (unsigned i = 0; i < List->getSize(); i++) {
1876 if (StringInit *II = dynamic_cast>(List->getElement(i))) {
1876 if (StringInit *II = dyn_cast>(List->getElement(i))) {
18771877 Strings.push_back(II->getValue());
18781878 } else {
18791879 throw "Record `" + getName() + "', field `" + FieldName.str() +
18931893 throw "Record `" + getName() + "' does not have a field named `" +
18941894 FieldName.str() + "'!\n";
18951895
1896 if (DefInit *DI = dynamic_cast>(R->getValue()))
1896 if (DefInit *DI = dyn_cast>(R->getValue()))
18971897 return DI->getDef();
18981898 throw "Record `" + getName() + "', field `" + FieldName.str() +
18991899 "' does not have a def initializer!";
19091909 throw "Record `" + getName() + "' does not have a field named `" +
19101910 FieldName.str() + "'!\n";
19111911
1912 if (BitInit *BI = dynamic_cast>(R->getValue()))
1912 if (BitInit *BI = dyn_cast>(R->getValue()))
19131913 return BI->getValue();
19141914 throw "Record `" + getName() + "', field `" + FieldName.str() +
19151915 "' does not have a bit initializer!";
19261926 return false;
19271927 }
19281928 Unset = false;
1929 if (BitInit *BI = dynamic_cast>(R->getValue()))
1929 if (BitInit *BI = dyn_cast>(R->getValue()))
19301930 return BI->getValue();
19311931 throw "Record `" + getName() + "', field `" + FieldName.str() +
19321932 "' does not have a bit initializer!";
19421942 throw "Record `" + getName() + "' does not have a field named `" +
19431943 FieldName.str() + "'!\n";
19441944
1945 if (DagInit *DI = dynamic_cast>(R->getValue()))
1945 if (DagInit *DI = dyn_cast>(R->getValue()))
19461946 return DI;
19471947 throw "Record `" + getName() + "', field `" + FieldName.str() +
19481948 "' does not have a dag initializer!";
20032003 /// to CurRec's name.
20042004 Init *llvm::QualifyName(Record &CurRec, MultiClass *CurMultiClass,
20052005 Init *Name, const std::string &Scoper) {
2006 RecTy *Type = dynamic_cast>(Name)->getType();
2006 RecTy *Type = dyn_cast>(Name)->getType();
20072007
20082008 BinOpInit *NewName =
20092009 BinOpInit::get(BinOpInit::STRCONCAT,
9292 // Do not allow assignments like 'X = X'. This will just cause infinite loops
9393 // in the resolution machinery.
9494 if (BitList.empty())
95 if (VarInit *VI = dynamic_cast>(V))
95 if (VarInit *VI = dyn_cast>(V))
9696 if (VI->getNameInit() == ValName)
9797 return false;
9898
101101 // initializer.
102102 //
103103 if (!BitList.empty()) {
104 BitsInit *CurVal = dynamic_cast>(RV->getValue());
104 BitsInit *CurVal = dyn_cast>(RV->getValue());
105105 if (CurVal == 0)
106106 return Error(Loc, "Value '" + ValName->getAsUnquotedString()
107107 + "' is not a bits type");
113113 }
114114
115115 // We should have a BitsInit type now.
116 BitsInit *BInit = dynamic_cast>(BI);
116 BitsInit *BInit = dyn_cast>(BI);
117117 assert(BInit != 0);
118118
119119 SmallVector NewBits(CurVal->getNumBits());
309309 if (IterVals.size() != Loops.size()) {
310310 assert(IterVals.size() < Loops.size());
311311 ForeachLoop &CurLoop = Loops[IterVals.size()];
312 ListInit *List = dynamic_cast>(CurLoop.ListValue);
312 ListInit *List = dyn_cast>(CurLoop.ListValue);
313313 if (List == 0) {
314314 Error(Loc, "Loop list is not a list");
315315 return true;
334334 // Set the iterator values now.
335335 for (unsigned i = 0, e = IterVals.size(); i != e; ++i) {
336336 VarInit *IterVar = IterVals[i].IterVar;
337 TypedInit *IVal = dynamic_cast>(IterVals[i].IterValue);
337 TypedInit *IVal = dyn_cast>(IterVals[i].IterValue);
338338 if (IVal == 0) {
339339 Error(Loc, "foreach iterator value is untyped");
340340 return true;
406406 RecTy *Type = 0;
407407 if (CurRec) {
408408 const TypedInit *CurRecName =
409 dynamic_cast>(CurRec->getNameInit());
409 dyn_cast>(CurRec->getNameInit());
410410 if (!CurRecName) {
411411 TokError("Record name is not typed!");
412412 return 0;
779779 for (LoopVector::iterator i = Loops.begin(), iend = Loops.end();
780780 i != iend;
781781 ++i) {
782 VarInit *IterVar = dynamic_cast>(i->IterVar);
782 VarInit *IterVar = dyn_cast>(i->IterVar);
783783 if (IterVar && IterVar->getName() == Name)
784784 return IterVar;
785785 }
854854 if (Code == UnOpInit::HEAD
855855 || Code == UnOpInit::TAIL
856856 || Code == UnOpInit::EMPTY) {
857 ListInit *LHSl = dynamic_cast(LHS);
858 StringInit *LHSs = dynamic_cast(LHS);
859 TypedInit *LHSt = dynamic_cast>(LHS);
857 ListInit *LHSl = dyn_cast>(LHS);
858 StringInit *LHSs = dyn_cast(LHS);
859 TypedInit *LHSt = dyn_cast(LHS);
860860 if (LHSl == 0 && LHSs == 0 && LHSt == 0) {
861861 TokError("expected list or string type argument in unary operator");
862862 return 0;
883883 }
884884 if (LHSl) {
885885 Init *Item = LHSl->getElement(0);
886 TypedInit *Itemt = dynamic_cast>(Item);
886 TypedInit *Itemt = dyn_cast>(Item);
887887 if (Itemt == 0) {
888888 TokError("untyped list element in unary operator");
889889 return 0;
10451045 RecTy *MHSTy = 0;
10461046 RecTy *RHSTy = 0;
10471047
1048 if (TypedInit *MHSt = dynamic_cast>(MHS))
1048 if (TypedInit *MHSt = dyn_cast>(MHS))
10491049 MHSTy = MHSt->getType();
1050 if (BitsInit *MHSbits = dynamic_cast>(MHS))
1050 if (BitsInit *MHSbits = dyn_cast>(MHS))
10511051 MHSTy = BitsRecTy::get(MHSbits->getNumBits());
1052 if (dynamic_cast>(MHS))
1052 if (dyn_cast>(MHS))
10531053 MHSTy = BitRecTy::get();
10541054
1055 if (TypedInit *RHSt = dynamic_cast>(RHS))
1055 if (TypedInit *RHSt = dyn_cast>(RHS))
10561056 RHSTy = RHSt->getType();
1057 if (BitsInit *RHSbits = dynamic_cast>(RHS))
1057 if (BitsInit *RHSbits = dyn_cast>(RHS))
10581058 RHSTy = BitsRecTy::get(RHSbits->getNumBits());
1059 if (dynamic_cast>(RHS))
1059 if (dyn_cast>(RHS))
10601060 RHSTy = BitRecTy::get();
10611061
10621062 // For UnsetInit, it's typed from the other hand.
1063 if (dynamic_cast>(MHS))
1063 if (dyn_cast>(MHS))
10641064 MHSTy = RHSTy;
1065 if (dynamic_cast>(RHS))
1065 if (dyn_cast>(RHS))
10661066 RHSTy = MHSTy;
10671067
10681068 if (!MHSTy || !RHSTy) {
10811081 break;
10821082 }
10831083 case tgtok::XForEach: {
1084 TypedInit *MHSt = dynamic_cast>(MHS);
1084 TypedInit *MHSt = dyn_cast>(MHS);
10851085 if (MHSt == 0) {
10861086 TokError("could not get type for !foreach");
10871087 return 0;
10901090 break;
10911091 }
10921092 case tgtok::XSubst: {
1093 TypedInit *RHSt = dynamic_cast>(RHS);
1093 TypedInit *RHSt = dyn_cast>(RHS);
10941094 if (RHSt == 0) {
10951095 TokError("could not get type for !subst");
10961096 return 0;
13141314 for (std::vector::iterator i = Vals.begin(), ie = Vals.end();
13151315 i != ie;
13161316 ++i) {
1317 TypedInit *TArg = dynamic_cast>(*i);
1317 TypedInit *TArg = dyn_cast>(*i);
13181318 if (TArg == 0) {
13191319 TokError("Untyped list element");
13201320 return 0;
14971497 // Create a !strconcat() operation, first casting each operand to
14981498 // a string if necessary.
14991499
1500 TypedInit *LHS = dynamic_cast>(Result);
1500 TypedInit *LHS = dyn_cast>(Result);
15011501 if (!LHS) {
15021502 Error(PasteLoc, "LHS of paste is not typed!");
15031503 return 0;
15241524
15251525 default:
15261526 Init *RHSResult = ParseValue(CurRec, ItemType, ParseNameMode);
1527 RHS = dynamic_cast>(RHSResult);
1527 RHS = dyn_cast>(RHSResult);
15281528 if (!RHS) {
15291529 Error(PasteLoc, "RHS of paste is not typed!");
15301530 return 0;
17151715 default: TokError("Unknown token when expecting a range list"); return 0;
17161716 case tgtok::l_square: { // '[' ValueList ']'
17171717 Init *List = ParseSimpleValue(0, 0, ParseForeachMode);
1718 ForeachListValue = dynamic_cast>(List);
1718 ForeachListValue = dyn_cast>(List);
17191719 if (ForeachListValue == 0) {
17201720 TokError("Expected a Value list");
17211721 return 0;
22562256
22572257 Init *DefName = DefProto->getNameInit();
22582258
2259 StringInit *DefNameString = dynamic_cast>(DefName);
2259 StringInit *DefNameString = dyn_cast>(DefName);
22602260
22612261 if (DefNameString != 0) {
22622262 // We have a fully expanded string so there are no operators to
992992 int SubOpIdx) {
993993 Record *Rec = OI.Rec;
994994 if (SubOpIdx != -1)
995 Rec = dynamic_cast>(OI.MIOperandInfo->getArg(SubOpIdx))->getDef();
995 Rec = dyn_cast>(OI.MIOperandInfo->getArg(SubOpIdx))->getDef();
996996 return getOperandClass(Rec, SubOpIdx);
997997 }
998998
10061006 throw "Record `" + Rec->getName() +
10071007 "' does not have a ParserMatchClass!\n";
10081008
1009 if (DefInit *DI= dynamic_cast>(R->getValue())) {
1009 if (DefInit *DI= dyn_cast>(R->getValue())) {
10101010 Record *MatchClass = DI->getDef();
10111011 if (ClassInfo *CI = AsmOperandClasses[MatchClass])
10121012 return CI;
11841184
11851185 ListInit *Supers = (*it)->getValueAsListInit("SuperClasses");
11861186 for (unsigned i = 0, e = Supers->getSize(); i != e; ++i) {
1187 DefInit *DI = dynamic_cast>(Supers->getElement(i));
1187 DefInit *DI = dyn_cast>(Supers->getElement(i));
11881188 if (!DI) {
11891189 PrintError((*it)->getLoc(), "Invalid super class reference!");
11901190 continue;
12021202
12031203 // Get or construct the predicate method name.
12041204 Init *PMName = (*it)->getValueInit("PredicateMethod");
1205 if (StringInit *SI = dynamic_cast>(PMName)) {
1205 if (StringInit *SI = dyn_cast>(PMName)) {
12061206 CI->PredicateMethod = SI->getValue();
12071207 } else {
1208 assert(dynamic_cast>(PMName) &&
1208 assert(dyn_cast>(PMName) &&
12091209 "Unexpected PredicateMethod field!");
12101210 CI->PredicateMethod = "is" + CI->ClassName;
12111211 }
12121212
12131213 // Get or construct the render method name.
12141214 Init *RMName = (*it)->getValueInit("RenderMethod");
1215 if (StringInit *SI = dynamic_cast>(RMName)) {
1215 if (StringInit *SI = dyn_cast>(RMName)) {
12161216 CI->RenderMethod = SI->getValue();
12171217 } else {
1218 assert(dynamic_cast>(RMName) &&
1218 assert(dyn_cast>(RMName) &&
12191219 "Unexpected RenderMethod field!");
12201220 CI->RenderMethod = "add" + CI->ClassName + "Operands";
12211221 }
12221222
12231223 // Get the parse method name or leave it as empty.
12241224 Init *PRMName = (*it)->getValueInit("ParserMethod");
1225 if (StringInit *SI = dynamic_cast>(PRMName))
1225 if (StringInit *SI = dyn_cast>(PRMName))
12261226 CI->ParserMethod = SI->getValue();
12271227
12281228 // Get the diagnostic type or leave it as empty.
12291229 // Get the parse method name or leave it as empty.
12301230 Init *DiagnosticType = (*it)->getValueInit("DiagnosticType");
1231 if (StringInit *SI = dynamic_cast>(DiagnosticType))
1231 if (StringInit *SI = dyn_cast>(DiagnosticType))
12321232 CI->DiagnosticType = SI->getValue();
12331233
12341234 AsmOperandClasses[*it] = CI;
791791 if (!R->getValueAsBit("EmitAlias"))
792792 continue; // We were told not to emit the alias, but to emit the aliasee.
793793 const DagInit *DI = R->getValueAsDag("ResultInst");
794 const DefInit *Op = dynamic_cast>(DI->getOperator());
794 const DefInit *Op = dyn_cast>(DI->getOperator());
795795 AliasMap[getQualifiedName(Op->getDef())].push_back(Alias);
796796 }
797797
9090 // return the variable bit position. Otherwise return -1.
9191 int CodeEmitterGen::getVariableBit(const std::string &VarName,
9292 BitsInit *BI, int bit) {
93 if (VarBitInit *VBI = dynamic_cast(BI->getBit(bit))) {
94 if (VarInit *VI = dynamic_cast(VBI->getBitVar()))
93 if (VarBitInit *VBI = dyn_cast(BI->getBit(bit))) {
94 if (VarInit *VI = dyn_cast(VBI->getBitVar()))
9595 if (VI->getName() == VarName)
9696 return VBI->getBitNum();
97 } else if (VarInit *VI = dynamic_cast>(BI->getBit(bit))) {
97 } else if (VarInit *VI = dyn_cast>(BI->getBit(bit))) {
9898 if (VI->getName() == VarName)
9999 return 0;
100100 }
268268 // Start by filling in fixed values.
269269 uint64_t Value = 0;
270270 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) {
271 if (BitInit *B = dynamic_cast>(BI->getBit(e-i-1)))
271 if (BitInit *B = dyn_cast>(BI->getBit(e-i-1)))
272272 Value |= (uint64_t)B->getValue() << (e-i-1);
273273 }
274274 o << " UINT64_C(" << Value << ")," << '\t' << "// " << R->getName() << "\n";
581581
582582 static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) {
583583 if (N->isLeaf()) {
584 if (dynamic_cast>(N->getLeafValue()) != NULL)
584 if (dyn_cast>(N->getLeafValue()) != NULL)
585585 DepMap[N->getName()]++;
586586 } else {
587587 for (size_t i = 0, e = N->getNumChildren(); i != e; ++i)
690690 unsigned Size = 3; // The node itself.
691691 // If the root node is a ConstantSDNode, increases its size.
692692 // e.g. (set R32:$dst, 0).
693 if (P->isLeaf() && dynamic_cast>(P->getLeafValue()))
693 if (P->isLeaf() && dyn_cast>(P->getLeafValue()))
694694 Size += 2;
695695
696696 // FIXME: This is a hack to statically increase the priority of patterns
714714 Child->getType(0) != MVT::Other)
715715 Size += getPatternSize(Child, CGP);
716716 else if (Child->isLeaf()) {
717 if (dynamic_cast>(Child->getLeafValue()))
717 if (dyn_cast>(Child->getLeafValue()))
718718 Size += 5; // Matches a ConstantSDNode (+3) and a specific value (+2).
719719 else if (Child->getComplexPatternInfo(CGP))
720720 Size += getPatternSize(Child, CGP);
740740 std::string PatternToMatch::getPredicateCheck() const {
741741 std::string PredicateCheck;
742742 for (unsigned i = 0, e = Predicates->getSize(); i != e; ++i) {
743 if (DefInit *Pred = dynamic_cast>(Predicates->getElement(i))) {
743 if (DefInit *Pred = dyn_cast>(Predicates->getElement(i))) {
744744 Record *Def = Pred->getDef();
745745 if (!Def->isSubClassOf("Predicate")) {
746746 #ifndef NDEBUG
863863 // The NodeToApply must be a leaf node that is a VT. OtherOperandNum must
864864 // have an integer type that is smaller than the VT.
865865 if (!NodeToApply->isLeaf() ||
866 !dynamic_cast>(NodeToApply->getLeafValue()) ||
866 !dyn_cast>(NodeToApply->getLeafValue()) ||
867867 !static_cast(NodeToApply->getLeafValue())->getDef()
868868 ->isSubClassOf("ValueType"))
869869 TP.error(N->getOperator()->getName() + " expects a VT operand!");
10201020 // Get the result tree.
10211021 DagInit *Tree = Operator->getValueAsDag("Fragment");
10221022 Record *Op = 0;
1023 if (Tree && dynamic_cast(Tree->getOperator()))
1024 Op = dynamic_cast(Tree->getOperator())->getDef();
1023 if (Tree && dyn_cast(Tree->getOperator()))
1024 Op = dyn_cast(Tree->getOperator())->getDef();
10251025 assert(Op && "Invalid Fragment");
10261026 return GetNumNodeResults(Op, CDP);
10271027 }
10951095 return false;
10961096
10971097 if (isLeaf()) {
1098 if (DefInit *DI = dynamic_cast(getLeafValue())) {
1099 if (DefInit *NDI = dynamic_cast(N->getLeafValue())) {
1098 if (DefInit *DI = dyn_cast(getLeafValue())) {
1099 if (DefInit *NDI = dyn_cast(N->getLeafValue())) {
11001100 return ((DI->getDef() == NDI->getDef())
11011101 && (DepVars.find(getName()) == DepVars.end()
11021102 || getName() == N->getName()));
11531153 TreePatternNode *Child = getChild(i);
11541154 if (Child->isLeaf()) {
11551155 Init *Val = Child->getLeafValue();
1156 if (dynamic_cast>(Val) &&
1156 if (dyn_cast>(Val) &&
11571157 static_cast(Val)->getDef()->getName() == "node") {
11581158 // We found a use of a formal argument, replace it with its value.
11591159 TreePatternNode *NewChild = ArgMap[Child->getName()];
13161316 return 0;
13171317
13181318 unsigned IID =
1319 dynamic_cast>(getChild(0)->getLeafValue())->getValue();
1319 dyn_cast>(getChild(0)->getLeafValue())->getValue();
13201320 return &CDP.getIntrinsicInfo(IID);
13211321 }
13221322
13261326 TreePatternNode::getComplexPatternInfo(const CodeGenDAGPatterns &CGP) const {
13271327 if (!isLeaf()) return 0;
13281328
1329 DefInit *DI = dynamic_cast>(getLeafValue());
1329 DefInit *DI = dyn_cast>(getLeafValue());
13301330 if (DI && DI->getDef()->isSubClassOf("ComplexPattern"))
13311331 return &CGP.getComplexPattern(DI->getDef());
13321332 return 0;
13791379 bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
13801380 CodeGenDAGPatterns &CDP = TP.getDAGPatterns();
13811381 if (isLeaf()) {
1382 if (DefInit *DI = dynamic_cast>(getLeafValue())) {
1382 if (DefInit *DI = dyn_cast>(getLeafValue())) {
13831383 // If it's a regclass or something else known, include the type.
13841384 bool MadeChange = false;
13851385 for (unsigned i = 0, e = Types.size(); i != e; ++i)
13881388 return MadeChange;
13891389 }
13901390
1391 if (IntInit *II = dynamic_cast>(getLeafValue())) {
1391 if (IntInit *II = dyn_cast>(getLeafValue())) {
13921392 assert(Types.size() == 1 && "Invalid IntInit");
13931393
13941394 // Int inits are always integers. :)
16401640 static bool OnlyOnRHSOfCommutative(TreePatternNode *N) {
16411641 if (!N->isLeaf() && N->getOperator()->getName() == "imm")
16421642 return true;
1643 if (N->isLeaf() && dynamic_cast>(N->getLeafValue()))
1643 if (N->isLeaf() && dyn_cast>(N->getLeafValue()))
16441644 return true;
16451645 return false;
16461646 }
17291729
17301730
17311731 TreePatternNode *TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName){
1732 if (DefInit *DI = dynamic_cast>(TheInit)) {
1732 if (DefInit *DI = dyn_cast>(TheInit)) {
17331733 Record *R = DI->getDef();
17341734
17351735 // Direct reference to a leaf DagNode or PatFrag? Turn it into a
17531753 return Res;
17541754 }
17551755
1756 if (IntInit *II = dynamic_cast>(TheInit)) {
1756 if (IntInit *II = dyn_cast>(TheInit)) {
17571757 if (!OpName.empty())
17581758 error("Constant int argument should not have a name!");
17591759 return new TreePatternNode(II, 1);
17601760 }
17611761
1762 if (BitsInit *BI = dynamic_cast>(TheInit)) {
1762 if (BitsInit *BI = dyn_cast>(TheInit)) {
17631763 // Turn this into an IntInit.
17641764 Init *II = BI->convertInitializerTo(IntRecTy::get());
1765 if (II == 0 || !dynamic_cast>(II))
1765 if (II == 0 || !dyn_cast>(II))
17661766 error("Bits value must be constants!");
17671767 return ParseTreePattern(II, OpName);
17681768 }
17691769
1770 DagInit *Dag = dynamic_cast>(TheInit);
1770 DagInit *Dag = dyn_cast>(TheInit);
17711771 if (!Dag) {
17721772 TheInit->dump();
17731773 error("Pattern has unexpected init kind!");
17741774 }
1775 DefInit *OpDef = dynamic_cast>(Dag->getOperator());
1775 DefInit *OpDef = dyn_cast>(Dag->getOperator());
17761776 if (!OpDef) error("Pattern has unexpected operator type!");
17771777 Record *Operator = OpDef->getDef();
17781778
19371937 // us to match things like:
19381938 // def : Pat<(v1i64 (bitconvert(v2i32 DPR:$src))), (v1i64 DPR:$src)>;
19391939 if (Nodes[i] == Trees[0] && Nodes[i]->isLeaf()) {
1940 DefInit *DI = dynamic_cast>(Nodes[i]->getLeafValue());
1940 DefInit *DI = dyn_cast>(Nodes[i]->getLeafValue());
19411941 if (DI && (DI->getDef()->isSubClassOf("RegisterClass") ||
19421942 DI->getDef()->isSubClassOf("RegisterOperand")))
19431943 continue;
21022102
21032103 // Parse the operands list.
21042104 DagInit *OpsList = Fragments[i]->getValueAsDag("Operands");
2105 DefInit *OpsOp = dynamic_cast>(OpsList->getOperator());
2105 DefInit *OpsOp = dyn_cast>(OpsList->getOperator());
21062106 // Special cases: ops == outs == ins. Different names are used to
21072107 // improve readability.
21082108 if (!OpsOp ||
21142114 // Copy over the arguments.
21152115 Args.clear();
21162116 for (unsigned j = 0, e = OpsList->getNumArgs(); j != e; ++j) {
2117 if (!dynamic_cast>(OpsList->getArg(j)) ||
2117 if (!dyn_cast>(OpsList->getArg(j)) ||
21182118 static_cast(OpsList->getArg(j))->
21192119 getDef()->getName() != "node")
21202120 P->error("Operands list should all be 'node' values.");
22172217 // No name -> not interesting.
22182218 if (Pat->getName().empty()) {
22192219 if (Pat->isLeaf()) {
2220 DefInit *DI = dynamic_cast>(Pat->getLeafValue());
2220 DefInit *DI = dyn_cast>(Pat->getLeafValue());
22212221 if (DI && (DI->getDef()->isSubClassOf("RegisterClass") ||
22222222 DI->getDef()->isSubClassOf("RegisterOperand")))
22232223 I->error("Input " + DI->getDef()->getName() + " must be named!");
22272227
22282228 Record *Rec;
22292229 if (Pat->isLeaf()) {
2230 DefInit *DI = dynamic_cast>(Pat->getLeafValue());
2230 DefInit *DI = dyn_cast>(Pat->getLeafValue());
22312231 if (!DI) I->error("Input $" + Pat->getName() + " must be an identifier!");
22322232 Rec = DI->getDef();
22332233 } else {
22452245 }
22462246 Record *SlotRec;
22472247 if (Slot->isLeaf()) {
2248 SlotRec = dynamic_cast>(Slot->getLeafValue())->getDef();
2248 SlotRec = dyn_cast>(Slot->getLeafValue())->getDef();
22492249 } else {
22502250 assert(Slot->getNumChildren() == 0 && "can't be a use with children!");
22512251 SlotRec = Slot->getOperator();
22802280 if (!Dest->isLeaf())
22812281 I->error("implicitly defined value should be a register!");
22822282
2283 DefInit *Val = dynamic_cast>(Dest->getLeafValue());
2283 DefInit *Val = dyn_cast>(Dest->getLeafValue());
22842284 if (!Val || !Val->getDef()->isSubClassOf("Register"))
22852285 I->error("implicitly defined value should be a register!");
22862286 InstImpResults.push_back(Val->getDef());
23212321 if (!Dest->isLeaf())
23222322 I->error("set destination should be a register!");
23232323
2324 DefInit *Val = dynamic_cast>(Dest->getLeafValue());
2324 DefInit *Val = dyn_cast>(Dest->getLeafValue());
23252325 if (!Val)
23262326 I->error("set destination should be a register!");
23272327
23802380 return false;
23812381
23822382 const TreePatternNode *N0 = N->getChild(0);
2383 if (!N0->isLeaf() || !dynamic_cast>(N0->getLeafValue()))
2383 if (!N0->isLeaf() || !dyn_cast>(N0->getLeafValue()))
23842384 return false;
23852385
23862386 const TreePatternNode *N1 = N->getChild(1);
23982398 public:
23992399 void AnalyzeNode(const TreePatternNode *N) {
24002400 if (N->isLeaf()) {
2401 if (DefInit *DI = dynamic_cast>(N->getLeafValue())) {
2401 if (DefInit *DI = dyn_cast>(N->getLeafValue())) {
24022402 Record *LeafRec = DI->getDef();
24032403 // Handle ComplexPattern leaves.
24042404 if (LeafRec->isSubClassOf("ComplexPattern")) {
25032503 /// hasNullFragReference - Return true if the DAG has any reference to the
25042504 /// null_frag operator.
25052505 static bool hasNullFragReference(DagInit *DI) {
2506 DefInit *OpDef = dynamic_cast>(DI->getOperator());
2506 DefInit *OpDef = dyn_cast>(DI->getOperator());
25072507 if (!OpDef) return false;
25082508 Record *Operator = OpDef->getDef();
25092509
25112511 if (Operator->getName() == "null_frag") return true;
25122512 // If any of the arguments reference the null fragment, return true.
25132513 for (unsigned i = 0, e = DI->getNumArgs(); i != e; ++i) {
2514 DagInit *Arg = dynamic_cast>(DI->getArg(i));
2514 DagInit *Arg = dyn_cast>(DI->getArg(i));
25152515 if (Arg && hasNullFragReference(Arg))
25162516 return true;
25172517 }
25232523 /// the null_frag operator.
25242524 static bool hasNullFragReference(ListInit *LI) {
25252525 for (unsigned i = 0, e = LI->getSize(); i != e; ++i) {
2526 DagInit *DI = dynamic_cast>(LI->getElement(i));
2526 DagInit *DI = dyn_cast>(LI->getElement(i));
25272527 assert(DI && "non-dag in an instruction Pattern list?!");
25282528 if (hasNullFragReference(DI))
25292529 return true;
25512551 for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
25522552 ListInit *LI = 0;
25532553
2554 if (dynamic_cast>(Instrs[i]->getValueInit("Pattern")))
2554 if (dyn_cast>(Instrs[i]->getValueInit("Pattern")))
25552555 LI = Instrs[i]->getValueAsListInit("Pattern");
25562556
25572557 // If there is no pattern, only collect minimal information about the
26462646
26472647 if (i == 0)
26482648 Res0Node = RNode;
2649 Record *R = dynamic_cast>(RNode->getLeafValue())->getDef();
2649 Record *R = dyn_cast>(RNode->getLeafValue())->getDef();
26502650 if (R == 0)
26512651 I->error("Operand $" + OpName + " should be a set destination: all "
26522652 "outputs must occur before inputs in operand list!");
26892689 InstInputsCheck.erase(OpName); // It occurred, remove from map.
26902690
26912691 if (InVal->isLeaf() &&
2692 dynamic_cast>(InVal->getLeafValue())) {
2692 dyn_cast>(InVal->getLeafValue())) {
26932693 Record *InRec = static_cast(InVal->getLeafValue())->getDef();
26942694 if (Op.Rec != InRec && !InRec->isSubClassOf("ComplexPattern"))
26952695 I->error("Operand $" + OpName + "'s register class disagrees"
33533353 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
33543354 TreePatternNode *Child = N->getChild(i);
33553355 if (Child->isLeaf())
3356 if (DefInit *DI = dynamic_cast>(Child->getLeafValue())) {
3356 if (DefInit *DI = dyn_cast>(Child->getLeafValue())) {
33573357 Record *RR = DI->getDef();
33583358 if (RR->isSubClassOf("Register"))
33593359 continue;
3131
3232 DagInit *OutDI = R->getValueAsDag("OutOperandList");
3333
34 if (DefInit *Init = dynamic_cast>(OutDI->getOperator())) {
34 if (DefInit *Init = dyn_cast>(OutDI->getOperator())) {
3535 if (Init->getDef()->getName() != "outs")
3636 throw R->getName() + ": invalid def name for output list: use 'outs'";
3737 } else
4040 NumDefs = OutDI->getNumArgs();
4141
4242 DagInit *InDI = R->getValueAsDag("InOperandList");
43 if (DefInit *Init = dynamic_cast>(InDI->getOperator())) {
43 if (DefInit *Init = dyn_cast>(InDI->getOperator())) {
4444 if (Init->getDef()->getName() != "ins")
4545 throw R->getName() + ": invalid def name for input list: use 'ins'";
4646 } else
5959 ArgName = InDI->getArgName(i-NumDefs);
6060 }
6161
62 DefInit *Arg = dynamic_cast>(ArgInit);
62 DefInit *Arg = dyn_cast>(ArgInit);
6363 if (!Arg)
6464 throw "Illegal operand for the '" + R->getName() + "' instruction!";
6565
7979 MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
8080
8181 // Verify that MIOpInfo has an 'ops' root value.
82 if (!dynamic_cast(MIOpInfo->getOperator()) ||
83 dynamic_cast(MIOpInfo->getOperator())
82 if (!dyn_cast(MIOpInfo->getOperator()) ||
83 dyn_cast(MIOpInfo->getOperator())
8484 ->getDef()->getName() != "ops")
8585 throw "Bad value for MIOperandInfo in operand '" + Rec->getName() +
8686 "'\n";
415415 ArrayRef Loc, CodeGenTarget &T,
416416 ResultOperand &ResOp) {
417417 Init *Arg = Result->getArg(AliasOpNo);
418 DefInit *ADI = dynamic_cast>(Arg);
418 DefInit *ADI = dyn_cast>(Arg);
419419
420420 if (ADI && ADI->getDef() == InstOpRec) {
421421 // If the operand is a record, it must have a name, and the record type
445445 DagInit *DI = InstOpRec->getValueAsDag("MIOperandInfo");
446446 // The operand info should only have a single (register) entry. We
447447 // want the register class of it.
448 InstOpRec = dynamic_cast>(DI->getArg(0))->getDef();
448 InstOpRec = dyn_cast>(DI->getArg(0))->getDef();
449449 }
450450
451451 if (InstOpRec->isSubClassOf("RegisterOperand"))
485485 }
486486
487487 // Literal integers.
488 if (IntInit *II = dynamic_cast>(Arg)) {
488 if (IntInit *II = dyn_cast>(Arg)) {
489489 if (hasSubOps || !InstOpRec->isSubClassOf("Operand"))
490490 return false;
491491 // Integer arguments can't have names.
517517 Result = R->getValueAsDag("ResultInst");
518518
519519 // Verify that the root of the result is an instruction.
520 DefInit *DI = dynamic_cast>(Result->getOperator());
520 DefInit *DI = dyn_cast>(Result->getOperator());
521521 if (DI == 0 || !DI->getDef()->isSubClassOf("Instruction"))
522522 throw TGError(R->getLoc(), "result of inst alias should be an instruction");
523523
527527 // the same class.
528528 StringMap NameClass;
529529 for (unsigned i = 0, e = Result->getNumArgs(); i != e; ++i) {
530 DefInit *ADI = dynamic_cast>(Result->getArg(i));
530 DefInit *ADI = dyn_cast>(Result->getArg(i));
531531 if (!ADI || Result->getArgName(i).empty())
532532 continue;
533533 // Verify we don't have something like: (someinst GR16:$foo, GR32:$foo)
574574 } else {
575575 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
576576 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
577 Record *SubRec = dynamic_cast>(MIOI->getArg(SubOp))->getDef();
577 Record *SubRec = dyn_cast>(MIOI->getArg(SubOp))->getDef();
578578
579579 // Take care to instantiate each of the suboperands with the correct
580580 // nomenclature: $foo.bar
595595 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
596596 if (AliasOpNo >= Result->getNumArgs())
597597 throw TGError(R->getLoc(), "not enough arguments for instruction!");
598 Record *SubRec = dynamic_cast>(MIOI->getArg(SubOp))->getDef();
598 Record *SubRec = dyn_cast>(MIOI->getArg(SubOp))->getDef();
599599 if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false,
600600 R->getLoc(), T, ResOp)) {
601601 ResultOperands.push_back(ResOp);
5858 SmallVector RegexList;
5959 for (DagInit::const_arg_iterator
6060 AI = Expr->arg_begin(), AE = Expr->arg_end(); AI != AE; ++AI) {
61 StringInit *SI = dynamic_cast>(*AI);
61 StringInit *SI = dyn_cast>(*AI);
6262 if (!SI)
6363 throw "instregex requires pattern string: " + Expr->getAsString();
6464 std::string pat = SI->getValue();
202202 assert(N->isLeaf() && "Not a leaf?");
203203
204204 // Direct match against an integer constant.
205 if (IntInit *II = dynamic_cast>(N->getLeafValue())) {
205 if (IntInit *II = dyn_cast>(N->getLeafValue())) {
206206 // If this is the root of the dag we're matching, we emit a redundant opcode
207207 // check to ensure that this gets folded into the normal top-level
208208 // OpcodeSwitch.
214214 return AddMatcher(new CheckIntegerMatcher(II->getValue()));
215215 }
216216
217 DefInit *DI = dynamic_cast>(N->getLeafValue());
217 DefInit *DI = dyn_cast>(N->getLeafValue());
218218 if (DI == 0) {
219219 errs() << "Unknown leaf kind: " << *N << "\n";
220220 abort();
282282 N->getOperator()->getName() == "or") &&
283283 N->getChild(1)->isLeaf() && N->getChild(1)->getPredicateFns().empty() &&
284284 N->getPredicateFns().empty()) {
285 if (IntInit *II = dynamic_cast>(N->getChild(1)->getLeafValue())) {
285 if (IntInit *II = dyn_cast>(N->getChild(1)->getLeafValue())) {
286286 if (!isPowerOf2_32(II->getValue())) { // Don't bother with single bits.
287287 // If this is at the root of the pattern, we emit a redundant
288288 // CheckOpcode so that the following checks get factored properly under
571571 SmallVectorImpl &ResultOps) {
572572 assert(N->isLeaf() && "Must be a leaf");
573573
574 if (IntInit *II = dynamic_cast>(N->getLeafValue())) {
574 if (IntInit *II = dyn_cast>(N->getLeafValue())) {
575575 AddMatcher(new EmitIntegerMatcher(II->getValue(), N->getType(0)));
576576 ResultOps.push_back(NextRecordedOperandNo++);
577577 return;
578578 }
579579
580580 // If this is an explicit register reference, handle it.
581 if (DefInit *DI = dynamic_cast>(N->getLeafValue())) {
581 if (DefInit *DI = dyn_cast>(N->getLeafValue())) {
582582 Record *Def = DI->getDef();
583583 if (Def->isSubClassOf("Register")) {
584584 const CodeGenRegister *Reg =
244244 if (Op->getType(0) != VT)
245245 return false;
246246
247 DefInit *OpDI = dynamic_cast>(Op->getLeafValue());
247 DefInit *OpDI = dyn_cast>(Op->getLeafValue());
248248 if (!OpDI)
249249 return false;
250250 Record *OpLeafRec = OpDI->getDef();
405405 if (!Op->isLeaf())
406406 return PhysReg;
407407
408 DefInit *OpDI = dynamic_cast>(Op->getLeafValue());
408 DefInit *OpDI = dyn_cast>(Op->getLeafValue());
409409 Record *OpLeafRec = OpDI->getDef();
410410 if (!OpLeafRec->isSubClassOf("Register"))
411411 return PhysReg;
472472 // a bit too complicated for now.
473473 if (!Dst->getChild(1)->isLeaf()) continue;
474474
475 DefInit *SR = dynamic_cast>(Dst->getChild(1)->getLeafValue());
475 DefInit *SR = dyn_cast>(Dst->getChild(1)->getLeafValue());
476476 if (SR)
477477 SubRegNo = getQualifiedName(SR->getDef());
478478 else
141141 return ValueNotSet(V) ? -1 : (V == BIT_FALSE ? 0 : 1);
142142 }
143143 static bit_value_t bitFromBits(const BitsInit &bits, unsigned index) {
144 if (BitInit *bit = dynamic_cast>(bits.getBit(index)))
144 if (BitInit *bit = dyn_cast>(bits.getBit(index)))
145145 return bit->getValue() ? BIT_TRUE : BIT_FALSE;
146146
147147 // The bit is uninitialized.
17561756 // for decoding register classes.
17571757 // FIXME: This need to be extended to handle instructions with custom
17581758 // decoder methods, and operands with (simple) MIOperandInfo's.
1759 TypedInit *TI = dynamic_cast>(NI->first);
1759 TypedInit *TI = dyn_cast>(NI->first);
17601760 RecordRecTy *Type = dyn_cast(TI->getType());
17611761 Record *TypeRecord = Type->getRecord();
17621762 bool isReg = false;
17691769
17701770 RecordVal *DecoderString = TypeRecord->getValue("DecoderMethod");
17711771 StringInit *String = DecoderString ?
1772 dynamic_cast>(DecoderString->getValue()) : 0;
1772 dyn_cast>(DecoderString->getValue()) : 0;
17731773 if (!isReg && String && String->getValue() != "")
17741774 Decoder = String->getValue();
17751775
17801780
17811781 for (unsigned bi = 0; bi < Bits.getNumBits(); ++bi) {
17821782 VarInit *Var = 0;
1783 VarBitInit *BI = dynamic_cast>(Bits.getBit(bi));
1783 VarBitInit *BI = dyn_cast>(Bits.getBit(bi));
17841784 if (BI)
1785 Var = dynamic_cast>(BI->getBitVar());
1785 Var = dyn_cast>(BI->getBitVar());
17861786 else
1787 Var = dynamic_cast>(Bits.getBit(bi));
1787 Var = dyn_cast>(Bits.getBit(bi));
17881788
17891789 if (!Var) {
17901790 if (Base != ~0U) {
8888 for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) {
8989 OperandList.push_back(Inst.Operands[i]);
9090
91 Record *OpR = dynamic_cast>(MIOI->getArg(j))->getDef();
91 Record *OpR = dyn_cast>(MIOI->getArg(j))->getDef();
9292 OperandList.back().Rec = OpR;
9393 }
9494 }
344344 if (!TSF) throw "no TSFlags?";
345345 uint64_t Value = 0;
346346 for (unsigned i = 0, e = TSF->getNumBits(); i != e; ++i) {
347 if (BitInit *Bit = dynamic_cast>(TSF->getBit(i)))
347 if (BitInit *Bit = dyn_cast>(TSF->getBit(i)))
348348 Value |= uint64_t(Bit->getValue()) << i;
349349 else
350350 throw "Invalid TSFlags bit in " + Inst.TheDef->getName();
7373 IndexedMap &OperandMap, unsigned BaseIdx) {
7474 unsigned OpsAdded = 0;
7575 for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) {
76 if (DefInit *DI = dynamic_cast>(Dag->getArg(i))) {
76 if (DefInit *DI = dyn_cast>(Dag->getArg(i))) {
7777 // Physical register reference. Explicit check for the special case
7878 // "zero_reg" definition.
7979 if (DI->getDef()->isSubClassOf("Register") ||
9999 for (unsigned I = 0, E = Insn.Operands[i].MINumOperands; I != E; ++I)
100100 OperandMap[BaseIdx + i + I].Kind = OpData::Operand;
101101 OpsAdded += Insn.Operands[i].MINumOperands;
102 } else if (IntInit *II = dynamic_cast>(Dag->getArg(i))) {
102 } else if (IntInit *II = dyn_cast>(Dag->getArg(i))) {
103103 OperandMap[BaseIdx + i].Kind = OpData::Imm;
104104 OperandMap[BaseIdx + i].Data.Imm = II->getValue();
105105 ++OpsAdded;
106 } else if (DagInit *SubDag = dynamic_cast>(Dag->getArg(i))) {
106 } else if (DagInit *SubDag = dyn_cast>(Dag->getArg(i))) {
107107 // Just add the operands recursively. This is almost certainly
108108 // a constant value for a complex operand (> 1 MI operand).
109109 unsigned NewOps =
126126 assert(Dag && "Missing result instruction in pseudo expansion!");
127127 DEBUG(dbgs() << " Result: " << *Dag << "\n");
128128
129 DefInit *OpDef = dynamic_cast>(Dag->getOperator());
129 DefInit *OpDef = dyn_cast>(Dag->getOperator());
130130 if (!OpDef)
131131 throw TGError(Rec->getLoc(), Rec->getName() +
132132 " has unexpected operator type!");
324324 if (!V || !V->getValue())
325325 continue;
326326
327 DefInit *DI = dynamic_cast>(V->getValue());
327 DefInit *DI = dyn_cast>(V->getValue());
328328 Record *Alias = DI->getDef();
329329 DwarfRegNums[Reg] = DwarfRegNums[Alias];
330330 }
750750 BitsInit *BI = Reg->getValueAsBitsInit("HWEncoding");
751751 uint64_t Value = 0;
752752 for (unsigned b = 0, be = BI->getNumBits(); b != be; ++b) {
753 if (BitInit *B = dynamic_cast>(BI->getBit(b)))
753 if (BitInit *B = dyn_cast>(BI->getBit(b)))
754754 Value |= (uint64_t)B->getValue() << b;
755755 }
756756 OS << " " << Value << ",\n";
7171 throw "Operator requires (Op Set, Int) arguments: " + Expr->getAsString();
7272 RecSet Set;
7373 ST.evaluate(Expr->arg_begin()[0], Set);
74 IntInit *II = dynamic_cast>(Expr->arg_begin()[1]);
74 IntInit *II = dyn_cast>(Expr->arg_begin()[1]);
7575 if (!II)
7676 throw "Second argument must be an integer: " + Expr->getAsString();
7777 apply2(ST, Expr, Set, II->getValue(), Elts);
164164 throw "Bad args to (sequence \"Format\", From, To): " +
165165 Expr->getAsString();
166166 else if (Expr->arg_size() == 4) {
167 if (IntInit *II = dynamic_cast>(Expr->arg_begin()[3])) {
167 if (IntInit *II = dyn_cast>(Expr->arg_begin()[3])) {
168168 Step = II->getValue();
169169 } else
170170 throw "Stride must be an integer: " + Expr->getAsString();
171171 }
172172
173173 std::string Format;
174 if (StringInit *SI = dynamic_cast>(Expr->arg_begin()[0]))
174 if (StringInit *SI = dyn_cast>(Expr->arg_begin()[0]))
175175 Format = SI->getValue();
176176 else
177177 throw "Format must be a string: " + Expr->getAsString();
178178
179179 int64_t From, To;
180 if (IntInit *II = dynamic_cast>(Expr->arg_begin()[1]))
180 if (IntInit *II = dyn_cast>(Expr->arg_begin()[1]))
181181 From = II->getValue();
182182 else
183183 throw "From must be an integer: " + Expr->getAsString();
184184 if (From < 0 || From >= (1 << 30))
185185 throw "From out of range";
186186
187 if (IntInit *II = dynamic_cast>(Expr->arg_begin()[2]))
187 if (IntInit *II = dyn_cast>(Expr->arg_begin()[2]))
188188 To = II->getValue();
189189 else
190190 throw "From must be an integer: " + Expr->getAsString();
192192 throw "To out of range";
193193
194194 RecordKeeper &Records =
195 dynamic_cast(*Expr->getOperator()).getDef()->getRecords();
195 dyn_cast(Expr->getOperator())->getDef()->getRecords();
196196
197197 Step *= From <= To ? 1 : -1;
198198 while (true) {
260260
261261 void SetTheory::evaluate(Init *Expr, RecSet &Elts) {
262262 // A def in a list can be a just an element, or it may expand.
263 if (DefInit *Def = dynamic_cast>(Expr)) {
263 if (DefInit *Def = dyn_cast>(Expr)) {
264264 if (const RecVec *Result = expand(Def->getDef()))
265265 return Elts.insert(Result->begin(), Result->end());
266266 Elts.insert(Def->getDef());
268268 }
269269
270270 // Lists simply expand.
271 if (ListInit *LI = dynamic_cast>(Expr))
271 if (ListInit *LI = dyn_cast>(Expr))
272272 return evaluate(LI->begin(), LI->end(), Elts);
273273
274274 // Anything else must be a DAG.
275 DagInit *DagExpr = dynamic_cast>(Expr);
275 DagInit *DagExpr = dyn_cast>(Expr);
276276 if (!DagExpr)
277277 throw "Invalid set element: " + Expr->getAsString();
278 DefInit *OpInit = dynamic_cast>(DagExpr->getOperator());
278 DefInit *OpInit = dyn_cast>(DagExpr->getOperator());
279279 if (!OpInit)
280280 throw "Bad set expression: " + Expr->getAsString();
281281 Operator *Op = Operators.lookup(OpInit->getDef()->getName());
295295 const std::vector &SC = Set->getSuperClasses();
296296 for (unsigned i = 0, e = SC.size(); i != e; ++i) {
297297 // Skip unnamed superclasses.
298 if (!dynamic_cast>(SC[i]->getNameInit()))
298 if (!dyn_cast>(SC[i]->getNameInit()))
299299 continue;
300300 if (Expander *Exp = Expanders.lookup(SC[i]->getName())) {
301301 // This breaks recursive definitions.