@@ -1894,8 +1894,8 @@ static void allocateAndSetAll(StructLoweringState &pass,
1894
1894
}
1895
1895
}
1896
1896
1897
- static void castTupleInstr (SingleValueInstruction *instr, IRGenModule &Mod,
1898
- LargeSILTypeMapper &Mapper) {
1897
+ static void retypeTupleInstr (SingleValueInstruction *instr, IRGenModule &Mod,
1898
+ LargeSILTypeMapper &Mapper) {
1899
1899
SILType currSILType = instr->getType ();
1900
1900
auto funcType = getInnerFunctionType (currSILType);
1901
1901
assert (funcType && " Expected a function Type" );
@@ -1910,25 +1910,31 @@ static void castTupleInstr(SingleValueInstruction *instr, IRGenModule &Mod,
1910
1910
1911
1911
auto II = instr->getIterator ();
1912
1912
++II;
1913
- SILBuilderWithScope castBuilder (II);
1914
- SingleValueInstruction *castInstr = nullptr ;
1913
+ SILBuilderWithScope Builder (II);
1914
+ SingleValueInstruction *newInstr = nullptr ;
1915
1915
switch (instr->getKind ()) {
1916
1916
// Add cast to the new sil function type:
1917
1917
case SILInstructionKind::TupleExtractInst: {
1918
- castInstr = castBuilder.createUncheckedReinterpretCast (
1919
- instr->getLoc (), instr, newSILType.getObjectType ());
1918
+ auto extractInst = cast<TupleExtractInst>(instr);
1919
+ newInstr = Builder.createTupleExtract (
1920
+ extractInst->getLoc (), extractInst->getOperand (),
1921
+ extractInst->getFieldIndex (),
1922
+ newSILType.getObjectType ());
1920
1923
break ;
1921
1924
}
1922
1925
case SILInstructionKind::TupleElementAddrInst: {
1923
- castInstr = castBuilder.createUncheckedAddrCast (
1924
- instr->getLoc (), instr, newSILType.getAddressType ());
1926
+ auto elementAddrInst = cast<TupleElementAddrInst>(instr);
1927
+ newInstr = Builder.createTupleElementAddr (
1928
+ elementAddrInst->getLoc (), elementAddrInst->getOperand (),
1929
+ elementAddrInst->getFieldIndex (),
1930
+ newSILType.getAddressType ());
1925
1931
break ;
1926
1932
}
1927
1933
default :
1928
1934
llvm_unreachable (" Unexpected instruction inside tupleInstsToMod" );
1929
1935
}
1930
- instr->replaceAllUsesWith (castInstr );
1931
- castInstr-> setOperand ( 0 , instr );
1936
+ instr->replaceAllUsesWith (newInstr );
1937
+ instr-> eraseFromParent ( );
1932
1938
}
1933
1939
1934
1940
static SILValue createCopyOfEnum (StructLoweringState &pass,
@@ -2090,7 +2096,7 @@ static void rewriteFunction(StructLoweringState &pass,
2090
2096
}
2091
2097
2092
2098
for (SingleValueInstruction *instr : pass.tupleInstsToMod ) {
2093
- castTupleInstr (instr, pass.Mod , pass.Mapper );
2099
+ retypeTupleInstr (instr, pass.Mod , pass.Mapper );
2094
2100
}
2095
2101
2096
2102
while (!pass.allocStackInstsToMod .empty ()) {
0 commit comments