Skip to content

Commit 97b1548

Browse files
Merge pull request #78321 from aschwaighofer/propagate_large
LargeLoadable types: propagate large type property along projections
2 parents 52a2638 + e242d78 commit 97b1548

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

lib/IRGen/LoadableByAddress.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,8 @@ class LargeLoadableHeuristic {
35043504
bool isLargeLoadableType(SILType ty);
35053505
bool isPotentiallyCArray(SILType ty);
35063506

3507+
void propagate(PostOrderFunctionInfo &po);
3508+
35073509
private:
35083510
bool isLargeLoadableTypeOld(SILType ty);
35093511

@@ -3545,6 +3547,32 @@ class LargeLoadableHeuristic {
35453547
};
35463548
}
35473549

3550+
void LargeLoadableHeuristic::propagate(PostOrderFunctionInfo &po) {
3551+
if (!UseAggressiveHeuristic)
3552+
return;
3553+
3554+
for (auto *BB : po.getPostOrder()) {
3555+
for (auto &I : llvm::reverse(*BB)) {
3556+
switch (I.getKind()) {
3557+
case SILInstructionKind::TupleExtractInst:
3558+
case SILInstructionKind::StructExtractInst: {
3559+
auto &proj = cast<SingleValueInstruction>(I);
3560+
if (isLargeLoadableType(proj.getType())) {
3561+
auto opdTy = proj.getOperand(0)->getType();
3562+
auto entry = largeTypeProperties[opdTy];
3563+
entry.setNumRegisters(65535);
3564+
largeTypeProperties[opdTy] = entry;
3565+
}
3566+
}
3567+
break;
3568+
3569+
default:
3570+
continue;
3571+
}
3572+
}
3573+
}
3574+
}
3575+
35483576
void LargeLoadableHeuristic::visit(SILArgument *arg) {
35493577
auto objType = arg->getType().getObjectType();
35503578
if (numRegisters(objType) < NumRegistersLargeType)
@@ -4659,6 +4687,9 @@ static void runPeepholesAndReg2Mem(SILPassManager *pm, SILModule *silMod,
46594687
// Delete replaced instructions.
46604688
opts.deleteInstructions();
46614689

4690+
PostOrderFunctionInfo postorderInfo(&currF);
4691+
heuristic.propagate(postorderInfo);
4692+
46624693
AddressAssignment assignment(heuristic, irgenModule, currF);
46634694

46644695
// Assign addresses to basic block arguments.
@@ -4729,7 +4760,6 @@ static void runPeepholesAndReg2Mem(SILPassManager *pm, SILModule *silMod,
47294760
}
47304761

47314762
// Asign addresses to non-address SSA values.
4732-
PostOrderFunctionInfo postorderInfo(&currF);
47334763
for (auto *BB : postorderInfo.getReversePostOrder()) {
47344764
SmallVector<SILInstruction *, 32> origInsts;
47354765
for (SILInstruction &i : *BB) {

test/IRGen/Inputs/large_c.h

+16
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,19 @@ typedef union {
7878
unsigned char cnt;
7979
} out;
8080
} union_t;
81+
82+
83+
typedef enum {
84+
TYPE1,
85+
TYPE2,
86+
TYPE3
87+
} member_type_t;
88+
89+
typedef unsigned char uuid_t[16];
90+
typedef struct {
91+
member_type_t member_type;
92+
union {
93+
uuid_t uuid;
94+
unsigned x;
95+
} member_value;
96+
} member_id_t;

test/IRGen/loadable_by_address_reg2mem.sil

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %target-swift-frontend %s -Xllvm -sil-print-types -Xllvm -sil-print-after=loadable-address -import-objc-header %S/Inputs/large_c.h -c -o %t/t.o 2>&1 | %FileCheck %s
22

3+
// wasm currently disables aggressive reg2mem
4+
// UNSUPPORTED: wasm
5+
// UNSUPPORTED: OS=wasi
6+
// UNSUPPORTED: CPU=wasm32
7+
38
sil_stage canonical
49

510
import Builtin
@@ -397,3 +402,25 @@ bb3(%4 : $X):
397402
%t = tuple ()
398403
return %t : $()
399404
}
405+
406+
sil @usei8 : $@convention(thin) (UInt8) -> ()
407+
408+
// CHECK: sil @test16
409+
// CHECK: bb0(%0 : $member_id_t):
410+
// CHECK: [[T0:%.*]] = alloc_stack $member_id_t
411+
// CHECK: store %0 to [[T0]] : $*member_id_t
412+
// CHECK: struct_element_addr [[T0]]
413+
// CHECK:} // end sil function 'test16'
414+
415+
sil @test16 : $@convention(thin) (member_id_t) -> () {
416+
bb0(%0 : $member_id_t):
417+
%2 = alloc_stack $X
418+
%44 = struct_extract %0 : $member_id_t, #member_id_t.member_value // user: %45
419+
%45 = unchecked_trivial_bit_cast %44 : $member_id_t.__Unnamed_union_member_value to $(UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
420+
%46 = tuple_extract %45 : $(UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8), 0
421+
%11 = function_ref @usei8 : $@convention(thin) (UInt8) -> ()
422+
%12 = apply %11(%46) : $@convention(thin) (UInt8) -> ()
423+
dealloc_stack %2 : $*X
424+
%13 = tuple ()
425+
return %13 : $()
426+
}

0 commit comments

Comments
 (0)