forked from OSchip/llvm-project
TableGen: Fix type of resolved and converted lists
Summary: There are no new test cases, but a subsequent patch will introduce assertions that would be triggered by existing test cases without this fix. Change-Id: I6a82d4b311b012aff3932978ae86f6a2dcfbf725 Reviewers: arsenm, craig.topper, tra, MartinO Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D43556 llvm-svn: 325798
This commit is contained in:
parent
6d64915c87
commit
81097ba6b5
|
@ -679,6 +679,9 @@ public:
|
|||
assert(i < NumValues && "List element index out of range!");
|
||||
return getTrailingObjects<Init *>()[i];
|
||||
}
|
||||
RecTy *getElementType() const {
|
||||
return cast<ListRecTy>(getType())->getElementType();
|
||||
}
|
||||
|
||||
Record *getElementAsRecord(unsigned i) const;
|
||||
|
||||
|
|
|
@ -501,7 +501,7 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const {
|
|||
|
||||
if (!Changed)
|
||||
return const_cast<ListInit*>(this);
|
||||
return ListInit::get(Elements, Ty);
|
||||
return ListInit::get(Elements, ElementType);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
@ -515,7 +515,7 @@ Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
|
|||
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 @@ Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) const {
|
|||
}
|
||||
|
||||
if (Changed)
|
||||
return ListInit::get(Resolved, getType());
|
||||
return ListInit::get(Resolved, getElementType());
|
||||
return const_cast<ListInit *>(this);
|
||||
}
|
||||
|
||||
|
@ -701,7 +701,7 @@ Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
|
|||
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 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
|
|||
SmallVector<Init *, 8> Args;
|
||||
Args.insert(Args.end(), LHSs->begin(), LHSs->end());
|
||||
Args.insert(Args.end(), RHSs->begin(), RHSs->end());
|
||||
return ListInit::get(
|
||||
Args, cast<ListRecTy>(LHSs->getType())->getElementType());
|
||||
return ListInit::get(Args, LHSs->getElementType());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -919,9 +918,6 @@ void TernOpInit::Profile(FoldingSetNodeID &ID) const {
|
|||
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 @@ static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
|
|||
}
|
||||
|
||||
// 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<OpInit>(RHS);
|
||||
|
||||
if (!RHSo)
|
||||
|
@ -973,7 +969,8 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, Record *CurRec,
|
|||
StringInit *ArgName = MHSd->getArgName(i);
|
||||
// If this is a dag, recurse
|
||||
if (isa<DagInit>(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 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, Record *CurRec,
|
|||
}
|
||||
|
||||
ListInit *MHSl = dyn_cast<ListInit>(MHS);
|
||||
if (MHSl) {
|
||||
ListRecTy *ListType = dyn_cast<ListRecTy>(Type);
|
||||
if (MHSl && ListType) {
|
||||
SmallVector<Init *, 8> 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 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
|
|||
}
|
||||
|
||||
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 @@ Init *TypedInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
|
|||
for (unsigned Element : Elements)
|
||||
ListInits.push_back(VarListElementInit::get(const_cast<TypedInit *>(this),
|
||||
Element));
|
||||
return ListInit::get(ListInits, T);
|
||||
return ListInit::get(ListInits, T->getElementType());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue