llvm.org GIT mirror llvm / 3f7b7f8
tblgen: Use semantically correct RTTI functions. Also, some minor cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165647 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Silva 7 years ago
11 changed file(s) with 59 addition(s) and 80 deletion(s). Raw diff Collapse all Expand all
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 || !dyn_cast(E))
652 if (IRV || !isa(E))
653653 return E;
654654 return 0;
655655 }
708708 switch (getOpcode()) {
709709 case CAST: {
710710 if (getType()->getAsString() == "string") {
711 StringInit *LHSs = dyn_cast(LHS);
712 if (LHSs) {
711 if (StringInit *LHSs = dyn_cast(LHS))
713712 return LHSs;
714 }
715
716 DefInit *LHSd = dyn_cast(LHS);
717 if (LHSd) {
713
714 if (DefInit *LHSd = dyn_cast(LHS))
718715 return StringInit::get(LHSd->getDef()->getName());
719 }
720
721 IntInit *LHSi = dyn_cast(LHS);
722 if (LHSi) {
716
717 if (IntInit *LHSi = dyn_cast(LHS))
723718 return StringInit::get(LHSi->getAsString());
724 }
725719 } else {
726 StringInit *LHSs = dyn_cast(LHS);
727 if (LHSs) {
720 if (StringInit *LHSs = dyn_cast(LHS)) {
728721 std::string Name = LHSs->getValue();
729722
730723 // From TGParser::ParseIDValue
772765 break;
773766 }
774767 case HEAD: {
775 ListInit *LHSl = dyn_cast(LHS);
776 if (LHSl) {
768 if (ListInit *LHSl = dyn_cast(LHS)) {
777769 if (LHSl->getSize() == 0) {
778770 assert(0 && "Empty list in car");
779771 return 0;
783775 break;
784776 }
785777 case TAIL: {
786 ListInit *LHSl = dyn_cast(LHS);
787 if (LHSl) {
778 if (ListInit *LHSl = dyn_cast(LHS)) {
788779 if (LHSl->getSize() == 0) {
789780 assert(0 && "Empty list in cdr");
790781 return 0;
801792 break;
802793 }
803794 case EMPTY: {
804 ListInit *LHSl = dyn_cast(LHS);
805 if (LHSl) {
795 if (ListInit *LHSl = dyn_cast(LHS)) {
806796 if (LHSl->getSize() == 0) {
807797 return IntInit::get(1);
808798 } else {
809799 return IntInit::get(0);
810800 }
811801 }
812 StringInit *LHSs = dyn_cast(LHS);
813 if (LHSs) {
802 if (StringInit *LHSs = dyn_cast(LHS)) {
814803 if (LHSs->getValue().empty()) {
815804 return IntInit::get(1);
816805 } else {
12841273 }
12851274
12861275 const std::string &VarInit::getName() const {
1287 StringInit *NameString =
1288 dyn_cast(getNameInit());
1276 StringInit *NameString = dyn_cast(getNameInit());
12891277 assert(NameString && "VarInit name is not a string!");
12901278 return NameString->getValue();
12911279 }
13171305 // If the element is set to some value, or if we are resolving a reference
13181306 // to a specific variable and that variable is explicitly unset, then
13191307 // replace the VarListElementInit with it.
1320 if (IRV || !dyn_cast(E))
1308 if (IRV || !isa(E))
13211309 return E;
13221310 return 0;
13231311 }
13341322 const std::string &FieldName) const {
13351323 if (isa(getType()))
13361324 if (const RecordVal *Val = R.getValue(VarName)) {
1337 if (RV != Val && (RV || dyn_cast(Val->getValue())))
1325 if (RV != Val && (RV || isa(Val->getValue())))
13381326 return 0;
13391327 Init *TheInit = Val->getValue();
13401328 assert(TheInit != this && "Infinite loop detected!");
13531341 ///
13541342 Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const {
13551343 if (RecordVal *Val = R.getValue(VarName))
1356 if (RV == Val || (RV == 0 && !dyn_cast(Val->getValue())))
1344 if (RV == Val || (RV == 0 && !isa(Val->getValue())))
13571345 return Val->getValue();
13581346 return const_cast(this);
13591347 }
14211409 Init *Result = TI->resolveListElementReference(R, RV, Element);
14221410
14231411 if (Result) {
1424 TypedInit *TInit = dyn_cast(Result);
1425 if (TInit) {
1412 if (TypedInit *TInit = dyn_cast(Result)) {
14261413 Init *Result2 = TInit->resolveListElementReference(R, RV, Elt);
14271414 if (Result2) return Result2;
14281415 return new VarListElementInit(TInit, Elt);
14811468 // If the element is set to some value, or if we are resolving a
14821469 // reference to a specific variable and that variable is explicitly
14831470 // unset, then replace the VarListElementInit with it.
1484 if (RV || !dyn_cast(E))
1471 if (RV || !isa(E))
14851472 return E;
14861473 }
14871474 return 0;
16541641 }
16551642
16561643 const std::string &Record::getName() const {
1657 const StringInit *NameString =
1658 dyn_castStringInit>(Name);
1644 const StringInit *NameString = dyn_cast<StringInit>(Name);
16591645 assert(NameString && "Record name is not a string!");
16601646 return NameString->getValue();
16611647 }
405405
406406 RecTy *Type = 0;
407407 if (CurRec) {
408 const TypedInit *CurRecName =
409 dyn_cast(CurRec->getNameInit());
408 const TypedInit *CurRecName = dyn_cast(CurRec->getNameInit());
410409 if (!CurRecName) {
411410 TokError("Record name is not typed!");
412411 return 0;
10491048 MHSTy = MHSt->getType();
10501049 if (BitsInit *MHSbits = dyn_cast(MHS))
10511050 MHSTy = BitsRecTy::get(MHSbits->getNumBits());
1052 if (dyn_cast(MHS))
1051 if (isa(MHS))
10531052 MHSTy = BitRecTy::get();
10541053
10551054 if (TypedInit *RHSt = dyn_cast(RHS))
10561055 RHSTy = RHSt->getType();
10571056 if (BitsInit *RHSbits = dyn_cast(RHS))
10581057 RHSTy = BitsRecTy::get(RHSbits->getNumBits());
1059 if (dyn_cast(RHS))
1058 if (isa(RHS))
10601059 RHSTy = BitRecTy::get();
10611060
10621061 // For UnsetInit, it's typed from the other hand.
1063 if (dyn_cast(MHS))
1062 if (isa(MHS))
10641063 MHSTy = RHSTy;
1065 if (dyn_cast(RHS))
1064 if (isa(RHS))
10661065 RHSTy = MHSTy;
10671066
10681067 if (!MHSTy || !RHSTy) {
992992 int SubOpIdx) {
993993 Record *Rec = OI.Rec;
994994 if (SubOpIdx != -1)
995 Rec = dyn_cast(OI.MIOperandInfo->getArg(SubOpIdx))->getDef();
995 Rec = cast(OI.MIOperandInfo->getArg(SubOpIdx))->getDef();
996996 return getOperandClass(Rec, SubOpIdx);
997997 }
998998
12051205 if (StringInit *SI = dyn_cast(PMName)) {
12061206 CI->PredicateMethod = SI->getValue();
12071207 } else {
1208 assert(dyn_cast(PMName) &&
1209 "Unexpected PredicateMethod field!");
1208 assert(isa(PMName) && "Unexpected PredicateMethod field!");
12101209 CI->PredicateMethod = "is" + CI->ClassName;
12111210 }
12121211
12151214 if (StringInit *SI = dyn_cast(RMName)) {
12161215 CI->RenderMethod = SI->getValue();
12171216 } else {
1218 assert(dyn_cast(RMName) &&
1219 "Unexpected RenderMethod field!");
1217 assert(isa(RMName) && "Unexpected RenderMethod field!");
12201218 CI->RenderMethod = "add" + CI->ClassName + "Operands";
12211219 }
12221220
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 = dyn_cast(DI->getOperator());
794 const DefInit *Op = cast(DI->getOperator());
795795 AliasMap[getQualifiedName(Op->getDef())].push_back(Alias);
796796 }
797797
581581
582582 static void FindDepVarsOf(TreePatternNode *N, DepVarMap &DepMap) {
583583 if (N->isLeaf()) {
584 if (dyn_cast(N->getLeafValue()) != NULL)
584 if (isa(N->getLeafValue()))
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() && dyn_cast(P->getLeafValue()))
693 if (P->isLeaf() && isa(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 (dyn_cast(Child->getLeafValue()))
717 if (isa(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);
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 !dyn_cast(NodeToApply->getLeafValue()) ||
866 !isa(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 && dyn_cast(Tree->getOperator()))
1024 Op = dyn_cast(Tree->getOperator())->getDef();
1023 if (Tree)
1024 if (DefInit *DI = dyn_cast(Tree->getOperator()))
1025 Op = DI->getDef();
10251026 assert(Op && "Invalid Fragment");
10261027 return GetNumNodeResults(Op, CDP);
10271028 }
11531154 TreePatternNode *Child = getChild(i);
11541155 if (Child->isLeaf()) {
11551156 Init *Val = Child->getLeafValue();
1156 if (dyn_cast(Val) &&
1157 static_cast(Val)->getDef()->getName() == "node") {
1157 if (isa(Val) &&
1158 cast(Val)->getDef()->getName() == "node") {
11581159 // We found a use of a formal argument, replace it with its value.
11591160 TreePatternNode *NewChild = ArgMap[Child->getName()];
11601161 assert(NewChild && "Couldn't find formal argument!");
13151316 getOperator() != CDP.get_intrinsic_wo_chain_sdnode())
13161317 return 0;
13171318
1318 unsigned IID =
1319 dyn_cast(getChild(0)->getLeafValue())->getValue();
1319 unsigned IID = cast(getChild(0)->getLeafValue())->getValue();
13201320 return &CDP.getIntrinsicInfo(IID);
13211321 }
13221322
16401640 static bool OnlyOnRHSOfCommutative(TreePatternNode *N) {
16411641 if (!N->isLeaf() && N->getOperator()->getName() == "imm")
16421642 return true;
1643 if (N->isLeaf() && dyn_cast(N->getLeafValue()))
1643 if (N->isLeaf() && isa(N->getLeafValue()))
16441644 return true;
16451645 return false;
16461646 }
17621762 if (BitsInit *BI = dyn_cast(TheInit)) {
17631763 // Turn this into an IntInit.
17641764 Init *II = BI->convertInitializerTo(IntRecTy::get());
1765 if (II == 0 || !dyn_cast(II))
1765 if (II == 0 || !isa(II))
17661766 error("Bits value must be constants!");
17671767 return ParseTreePattern(II, OpName);
17681768 }
21142114 // Copy over the arguments.
21152115 Args.clear();
21162116 for (unsigned j = 0, e = OpsList->getNumArgs(); j != e; ++j) {
2117 if (!dyn_cast(OpsList->getArg(j)) ||
2118 static_cast(OpsList->getArg(j))->
2119 getDef()->getName() != "node")
2117 if (!isa(OpsList->getArg(j)) ||
2118 cast(OpsList->getArg(j))->getDef()->getName() != "node")
21202119 P->error("Operands list should all be 'node' values.");
21212120 if (OpsList->getArgName(j).empty())
21222121 P->error("Operands list should have names for each operand!");
22452244 }
22462245 Record *SlotRec;
22472246 if (Slot->isLeaf()) {
2248 SlotRec = dyn_cast(Slot->getLeafValue())->getDef();
2247 SlotRec = cast(Slot->getLeafValue())->getDef();
22492248 } else {
22502249 assert(Slot->getNumChildren() == 0 && "can't be a use with children!");
22512250 SlotRec = Slot->getOperator();
23802379 return false;
23812380
23822381 const TreePatternNode *N0 = N->getChild(0);
2383 if (!N0->isLeaf() || !dyn_cast(N0->getLeafValue()))
2382 if (!N0->isLeaf() || !isa(N0->getLeafValue()))
23842383 return false;
23852384
23862385 const TreePatternNode *N1 = N->getChild(1);
25512550 for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
25522551 ListInit *LI = 0;
25532552
2554 if (dyn_cast(Instrs[i]->getValueInit("Pattern")))
2553 if (isa(Instrs[i]->getValueInit("Pattern")))
25552554 LI = Instrs[i]->getValueAsListInit("Pattern");
25562555
25572556 // If there is no pattern, only collect minimal information about the
26462645
26472646 if (i == 0)
26482647 Res0Node = RNode;
2649 Record *R = dyn_cast(RNode->getLeafValue())->getDef();
2648 Record *R = cast(RNode->getLeafValue())->getDef();
26502649 if (R == 0)
26512650 I->error("Operand $" + OpName + " should be a set destination: all "
26522651 "outputs must occur before inputs in operand list!");
26882687 TreePatternNode *InVal = InstInputsCheck[OpName];
26892688 InstInputsCheck.erase(OpName); // It occurred, remove from map.
26902689
2691 if (InVal->isLeaf() &&
2692 dyn_cast(InVal->getLeafValue())) {
2690 if (InVal->isLeaf() && isa(InVal->getLeafValue())) {
26932691 Record *InRec = static_cast(InVal->getLeafValue())->getDef();
26942692 if (Op.Rec != InRec && !InRec->isSubClassOf("ComplexPattern"))
26952693 I->error("Operand $" + OpName + "'s register class disagrees"
7979 MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
8080
8181 // Verify that MIOpInfo has an 'ops' root value.
82 if (!dyn_cast(MIOpInfo->getOperator()) ||
83 dyn_cast(MIOpInfo->getOperator())
84 ->getDef()->getName() != "ops")
82 if (!isa(MIOpInfo->getOperator()) ||
83 cast(MIOpInfo->getOperator())->getDef()->getName() != "ops")
8584 throw "Bad value for MIOperandInfo in operand '" + Rec->getName() +
8685 "'\n";
8786
445444 DagInit *DI = InstOpRec->getValueAsDag("MIOperandInfo");
446445 // The operand info should only have a single (register) entry. We
447446 // want the register class of it.
448 InstOpRec = dyn_cast(DI->getArg(0))->getDef();
447 InstOpRec = cast(DI->getArg(0))->getDef();
449448 }
450449
451450 if (InstOpRec->isSubClassOf("RegisterOperand"))
574573 } else {
575574 DagInit *MIOI = ResultInst->Operands[i].MIOperandInfo;
576575 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
577 Record *SubRec = dyn_cast(MIOI->getArg(SubOp))->getDef();
576 Record *SubRec = cast(MIOI->getArg(SubOp))->getDef();
578577
579578 // Take care to instantiate each of the suboperands with the correct
580579 // nomenclature: $foo.bar
595594 for (unsigned SubOp = 0; SubOp != NumSubOps; ++SubOp) {
596595 if (AliasOpNo >= Result->getNumArgs())
597596 throw TGError(R->getLoc(), "not enough arguments for instruction!");
598 Record *SubRec = dyn_cast(MIOI->getArg(SubOp))->getDef();
597 Record *SubRec = cast(MIOI->getArg(SubOp))->getDef();
599598 if (tryAliasOpMatch(Result, AliasOpNo, SubRec, false,
600599 R->getLoc(), T, ResOp)) {
601600 ResultOperands.push_back(ResOp);
405405 if (!Op->isLeaf())
406406 return PhysReg;
407407
408 DefInit *OpDI = dyn_cast(Op->getLeafValue());
409 Record *OpLeafRec = OpDI->getDef();
408 Record *OpLeafRec = cast(Op->getLeafValue())->getDef();
410409 if (!OpLeafRec->isSubClassOf("Register"))
411410 return PhysReg;
412411
413 PhysReg += static_cast(OpLeafRec->getValue( \
414 "Namespace")->getValue())->getValue();
412 PhysReg += cast(OpLeafRec->getValue("Namespace")->getValue())
413 ->getValue();
415414 PhysReg += "::";
416415 PhysReg += Target.getRegBank().getReg(OpLeafRec)->getName();
417416 return PhysReg;
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 = dyn_cast(NI->first);
1760 RecordRecTy *Type = dyn_cast(TI->getType());
1759 TypedInit *TI = cast(NI->first);
1760 RecordRecTy *Type = cast(TI->getType());
17611761 Record *TypeRecord = Type->getRecord();
17621762 bool isReg = false;
17631763 if (TypeRecord->isSubClassOf("RegisterOperand"))
8888 for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) {
8989 OperandList.push_back(Inst.Operands[i]);
9090
91 Record *OpR = dyn_cast(MIOI->getArg(j))->getDef();
91 Record *OpR = cast(MIOI->getArg(j))->getDef();
9292 OperandList.back().Rec = OpR;
9393 }
9494 }
324324 if (!V || !V->getValue())
325325 continue;
326326
327 DefInit *DI = dyn_cast(V->getValue());
327 DefInit *DI = cast(V->getValue());
328328 Record *Alias = DI->getDef();
329329 DwarfRegNums[Reg] = DwarfRegNums[Alias];
330330 }
192192 throw "To out of range";
193193
194194 RecordKeeper &Records =
195 dyn_cast(Expr->getOperator())->getDef()->getRecords();
195 cast(Expr->getOperator())->getDef()->getRecords();
196196
197197 Step *= From <= To ? 1 : -1;
198198 while (true) {