mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-05 09:24:28 +00:00
[IPO/MergeFunctions] changes so it doesn't try to bitcast a struct return type but instead recreates it with insert/extract value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207679 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -784,8 +784,23 @@ void MergeFunctions::writeThunkOrAlias(Function *F, Function *G) {
|
||||
// Helper for writeThunk,
|
||||
// Selects proper bitcast operation,
|
||||
// but a bit simpler then CastInst::getCastOpcode.
|
||||
static Value* createCast(IRBuilder<false> &Builder, Value *V, Type *DestTy) {
|
||||
static Value *createCast(IRBuilder<false> &Builder, Value *V, Type *DestTy) {
|
||||
Type *SrcTy = V->getType();
|
||||
if (SrcTy->isStructTy()) {
|
||||
assert(DestTy->isStructTy());
|
||||
assert(SrcTy->getStructNumElements() == DestTy->getStructNumElements());
|
||||
Value *Result = UndefValue::get(DestTy);
|
||||
for (unsigned int I = 0, E = SrcTy->getStructNumElements(); I < E; ++I) {
|
||||
Value *Element = createCast(
|
||||
Builder, Builder.CreateExtractValue(V, ArrayRef<unsigned int>(I)),
|
||||
DestTy->getStructElementType(I));
|
||||
|
||||
Result =
|
||||
Builder.CreateInsertValue(Result, Element, ArrayRef<unsigned int>(I));
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
assert(!DestTy->isStructTy());
|
||||
if (SrcTy->isIntegerTy() && DestTy->isPointerTy())
|
||||
return Builder.CreateIntToPtr(V, DestTy);
|
||||
else if (SrcTy->isPointerTy() && DestTy->isIntegerTy())
|
||||
|
Reference in New Issue
Block a user