diff options
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 545b85f1c21..fb348e9a6c7 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -203,6 +203,30 @@ bool IRTranslator::translateExtractValue(const User &U) { return true; } +bool IRTranslator::translateInsertValue(const User &U) { + const InsertValueInst &IVI = cast<InsertValueInst>(U); + const Value *Src = IVI.getAggregateOperand(); + Type *Int32Ty = Type::getInt32Ty(IVI.getContext()); + SmallVector<Value *, 1> Indices; + + // getIndexedOffsetInType is designed for GEPs, so the first index is the + // usual array element rather than looking into the actual aggregate. + Indices.push_back(ConstantInt::get(Int32Ty, 0)); + for (auto Idx : IVI.indices()) + Indices.push_back(ConstantInt::get(Int32Ty, Idx)); + + uint64_t Offset = 8 * DL->getIndexedOffsetInType(Src->getType(), Indices); + + unsigned Res = getOrCreateVReg(IVI); + const Value &Inserted = *IVI.getInsertedValueOperand(); + MIRBuilder.buildInsert( + LLT{*IVI.getType(), DL}, Res, getOrCreateVReg(*IVI.getAggregateOperand()), + LLT{*Inserted.getType(), DL}, getOrCreateVReg(Inserted), Offset); + + return true; +} + + bool IRTranslator::translateBitCast(const User &U) { if (LLT{*U.getOperand(0)->getType()} == LLT{*U.getType()}) { unsigned &Reg = ValToVReg[&U]; |