diff options
author | guopeilin <guopeilin1@huawei.com> | 2021-09-11 18:50:30 +0800 |
---|---|---|
committer | guopeilin <guopeilin1@huawei.com> | 2021-09-11 18:51:35 +0800 |
commit | 749ddd25e901c5214222be0e8e7be47424e5fdfe (patch) | |
tree | c05fdfcffe69df6aa79e86059dcd19abb9b3e564 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | df975e459008504db1248414718c1b936685d16f (diff) | |
download | llvm-749ddd25e901c5214222be0e8e7be47424e5fdfe.zip llvm-749ddd25e901c5214222be0e8e7be47424e5fdfe.tar.gz llvm-749ddd25e901c5214222be0e8e7be47424e5fdfe.tar.bz2 |
[BitcodeReader] Delay select until all constants resolved
Like the shuffle, we should treat the select delayed so that
all constants can be resolved.
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D109053
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 6aad83e..c339418 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2355,6 +2355,15 @@ Error BitcodeReader::parseConstants() { unsigned CstNo; }; std::vector<DelayedShufTy> DelayedShuffles; + struct DelayedSelTy { + Type *OpTy; + uint64_t Op0Idx; + uint64_t Op1Idx; + uint64_t Op2Idx; + unsigned CstNo; + }; + std::vector<DelayedSelTy> DelayedSelectors; + while (true) { Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks(); if (!MaybeEntry) @@ -2391,6 +2400,27 @@ Error BitcodeReader::parseConstants() { Value *V = ConstantExpr::getShuffleVector(Op0, Op1, Mask); ValueList.assignValue(V, CstNo); } + for (auto &DelayedSelector : DelayedSelectors) { + Type *OpTy = DelayedSelector.OpTy; + Type *SelectorTy = Type::getInt1Ty(Context); + uint64_t Op0Idx = DelayedSelector.Op0Idx; + uint64_t Op1Idx = DelayedSelector.Op1Idx; + uint64_t Op2Idx = DelayedSelector.Op2Idx; + uint64_t CstNo = DelayedSelector.CstNo; + Constant *Op1 = ValueList.getConstantFwdRef(Op1Idx, OpTy); + Constant *Op2 = ValueList.getConstantFwdRef(Op2Idx, OpTy); + // The selector might be an i1 or an <n x i1> + // Get the type from the ValueList before getting a forward ref. + if (VectorType *VTy = dyn_cast<VectorType>(OpTy)) { + Value *V = ValueList[Op0Idx]; + assert(V); + if (SelectorTy != V->getType()) + SelectorTy = VectorType::get(SelectorTy, VTy->getElementCount()); + } + Constant *Op0 = ValueList.getConstantFwdRef(Op0Idx, SelectorTy); + Value *V = ConstantExpr::getSelect(Op0, Op1, Op2); + ValueList.assignValue(V, CstNo); + } if (NextCstNo != ValueList.size()) return error("Invalid constant reference"); @@ -2687,21 +2717,11 @@ Error BitcodeReader::parseConstants() { if (Record.size() < 3) return error("Invalid record"); - Type *SelectorTy = Type::getInt1Ty(Context); - - // The selector might be an i1, an <n x i1>, or a <vscale x n x i1> - // Get the type from the ValueList before getting a forward ref. - if (VectorType *VTy = dyn_cast<VectorType>(CurTy)) - if (Value *V = ValueList[Record[0]]) - if (SelectorTy != V->getType()) - SelectorTy = VectorType::get(SelectorTy, - VTy->getElementCount()); - - V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0], - SelectorTy), - ValueList.getConstantFwdRef(Record[1],CurTy), - ValueList.getConstantFwdRef(Record[2],CurTy)); - break; + DelayedSelectors.push_back( + {CurTy, Record[0], Record[1], Record[2], NextCstNo}); + (void)ValueList.getConstantFwdRef(NextCstNo, CurTy); + ++NextCstNo; + continue; } case bitc::CST_CODE_CE_EXTRACTELT : { // CE_EXTRACTELT: [opty, opval, opty, opval] |