Index: llvm/trunk/include/llvm/TableGen/Record.h =================================================================== --- llvm/trunk/include/llvm/TableGen/Record.h +++ llvm/trunk/include/llvm/TableGen/Record.h @@ -679,6 +679,9 @@ assert(i < NumValues && "List element index out of range!"); return getTrailingObjects()[i]; } + RecTy *getElementType() const { + return cast(getType())->getElementType(); + } Record *getElementAsRecord(unsigned i) const; Index: llvm/trunk/lib/TableGen/Record.cpp =================================================================== --- llvm/trunk/lib/TableGen/Record.cpp +++ llvm/trunk/lib/TableGen/Record.cpp @@ -501,7 +501,7 @@ if (!Changed) return const_cast(this); - return ListInit::get(Elements, Ty); + return ListInit::get(Elements, ElementType); } return nullptr; @@ -515,7 +515,7 @@ return nullptr; Vals.push_back(getElement(Element)); } - return ListInit::get(Vals, getType()); + return ListInit::get(Vals, getElementType()); } Record *ListInit::getElementAsRecord(unsigned i) const { @@ -543,7 +543,7 @@ } if (Changed) - return ListInit::get(Resolved, getType()); + return ListInit::get(Resolved, getElementType()); return const_cast(this); } @@ -701,7 +701,7 @@ assert(!LHSl->empty() && "Empty list in tail"); // Note the +1. We can't just pass the result of getValues() // directly. - return ListInit::get(LHSl->getValues().slice(1), LHSl->getType()); + return ListInit::get(LHSl->getValues().slice(1), LHSl->getElementType()); } break; @@ -801,8 +801,7 @@ SmallVector Args; Args.insert(Args.end(), LHSs->begin(), LHSs->end()); Args.insert(Args.end(), RHSs->begin(), RHSs->end()); - return ListInit::get( - Args, cast(LHSs->getType())->getElementType()); + return ListInit::get(Args, LHSs->getElementType()); } break; } @@ -919,9 +918,6 @@ ProfileTernOpInit(ID, getOpcode(), getLHS(), getMHS(), getRHS(), getType()); } -static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, Record *CurRec, - MultiClass *CurMultiClass); - // Evaluates operation RHSo after replacing all operands matching LHS with Arg. static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg, Record *CurRec, MultiClass *CurMultiClass) { @@ -949,8 +945,8 @@ } // Applies RHS to all elements of MHS, using LHS as a temp variable. -static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, Record *CurRec, - MultiClass *CurMultiClass) { +static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type, + Record *CurRec, MultiClass *CurMultiClass) { OpInit *RHSo = dyn_cast(RHS); if (!RHSo) @@ -973,7 +969,8 @@ StringInit *ArgName = MHSd->getArgName(i); // If this is a dag, recurse if (isa(Arg)) { - if (Init *Result = ForeachHelper(LHS, Arg, RHSo, CurRec, CurMultiClass)) + if (Init *Result = + ForeachHelper(LHS, Arg, RHSo, Type, CurRec, CurMultiClass)) Arg = Result; } else if (Init *Result = EvaluateOperation(RHSo, LHS, Arg, CurRec, CurMultiClass)) { @@ -988,14 +985,15 @@ } ListInit *MHSl = dyn_cast(MHS); - if (MHSl) { + ListRecTy *ListType = dyn_cast(Type); + if (MHSl && ListType) { SmallVector NewList(MHSl->begin(), MHSl->end()); for (Init *&Arg : NewList) { if (Init *Result = EvaluateOperation(RHSo, LHS, Arg, CurRec, CurMultiClass)) Arg = Result; } - return ListInit::get(NewList, MHSl->getType()); + return ListInit::get(NewList, ListType->getElementType()); } return nullptr; } @@ -1046,7 +1044,8 @@ } case FOREACH: { - if (Init *Result = ForeachHelper(LHS, MHS, RHS, CurRec, CurMultiClass)) + if (Init *Result = + ForeachHelper(LHS, MHS, RHS, getType(), CurRec, CurMultiClass)) return Result; break; } @@ -1225,7 +1224,7 @@ for (unsigned Element : Elements) ListInits.push_back(VarListElementInit::get(const_cast(this), Element)); - return ListInit::get(ListInits, T); + return ListInit::get(ListInits, T->getElementType()); }