diff options
author | Tim Northover <tnorthover@apple.com> | 2016-08-19 20:08:55 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2016-08-19 20:08:55 +0000 |
commit | bbbfb1cfb85f5cd3166b6536eeb88f1cbe4f29ad (patch) | |
tree | 0c22edf783120262f91cdc7e54e2f152e387ef68 /llvm/lib/CodeGen | |
parent | 68726a5359270d877a8cddc61e38d179f79dc070 (diff) | |
download | bcm5719-llvm-bbbfb1cfb85f5cd3166b6536eeb88f1cbe4f29ad.tar.gz bcm5719-llvm-bbbfb1cfb85f5cd3166b6536eeb88f1cbe4f29ad.zip |
GlobalISel: translate insertvalue instructions.
This adds a G_INSERT instruction, which technically makes G_SEQUENCE redundant
(it's equivalent to a G_INSERT into an IMPLICIT_DEF). We'll leave G_SEQUENCE
for now though: it's likely to be far more common as it's a fundamental part of
legalization, so avoiding the mess and bloat of the extra IMPLICIT_DEFs is
probably worthwhile.
llvm-svn: 279306
Diffstat (limited to 'llvm/lib/CodeGen')
-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]; |