Skip to content

Commit 13f4177

Browse files
committed
[RISCV] Add load/store clustering in post machine schedule
If post machine schedule is used, previous cluster of load/store which formed in machine schedule may break. In order to solve this, add load/sotre clustering to post machine schedule.
1 parent cbc7812 commit 13f4177

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ static cl::opt<bool> EnableMISchedLoadStoreClustering(
9999
cl::desc("Enable load and store clustering in the machine scheduler"),
100100
cl::init(true));
101101

102+
static cl::opt<bool> EnablePostMISchedLoadStoreClustering(
103+
"riscv-postmisched-load-store-clustering", cl::Hidden,
104+
cl::desc("Enable PostRA load and store clustering in the machine scheduler"),
105+
cl::init(true));
106+
102107
static cl::opt<bool>
103108
EnableVLOptimizer("riscv-enable-vl-optimizer",
104109
cl::desc("Enable the RISC-V VL Optimizer pass"),
@@ -360,6 +365,19 @@ class RISCVPassConfig : public TargetPassConfig {
360365
return DAG;
361366
}
362367

368+
ScheduleDAGInstrs *
369+
createPostMachineScheduler(MachineSchedContext *C) const override {
370+
ScheduleDAGMI *DAG = nullptr;
371+
if (EnablePostMISchedLoadStoreClustering) {
372+
DAG = createGenericSchedPostRA(C);
373+
DAG->addMutation(createLoadClusterDAGMutation(
374+
DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
375+
DAG->addMutation(createStoreClusterDAGMutation(
376+
DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
377+
}
378+
return DAG;
379+
}
380+
363381
void addIRPasses() override;
364382
bool addPreISel() override;
365383
void addCodeGenPrepare() override;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -verify-misched -enable-post-misched=false \
3+
# RUN: -riscv-postmisched-load-store-clustering=false -debug-only=machine-scheduler \
4+
# RUN: -start-before=machine-scheduler -stop-after=postmisched -o - 2>&1 < %s \
5+
# RUN: | FileCheck -check-prefix=NOPOSTMISCHED %s
6+
# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -mattr=+use-postra-scheduler -verify-misched -enable-post-misched=true \
7+
# RUN: -riscv-postmisched-load-store-clustering=false -debug-only=machine-scheduler \
8+
# RUN: -start-before=machine-scheduler -stop-after=postmisched -o - 2>&1 < %s \
9+
# RUN: | FileCheck -check-prefix=NOCLUSTER %s
10+
# RUN: llc -mtriple=riscv64 -x mir -mcpu=sifive-p470 -mattr=+use-postra-scheduler -verify-misched -enable-post-misched=true \
11+
# RUN: -debug-only=machine-scheduler \
12+
# RUN: -start-before=machine-scheduler -stop-after=postmisched -o - 2>&1 < %s \
13+
# RUN: | FileCheck -check-prefix=MEMCLUSTER %s
14+
15+
...
16+
---
17+
name: mem_clustering_1
18+
tracksRegLiveness: true
19+
body: |
20+
bb.0:
21+
liveins: $x6, $x10, $x14, $x15, $x16, $x17
22+
; NOPOSTMISCHED-LABEL: name: mem_clustering_1
23+
; NOPOSTMISCHED: liveins: $x6, $x10, $x14, $x15, $x16, $x17
24+
; NOPOSTMISCHED-NEXT: {{ $}}
25+
; NOPOSTMISCHED-NEXT: renamable $x5 = LW renamable $x15, 0 :: (load (s32))
26+
; NOPOSTMISCHED-NEXT: renamable $x7 = LW renamable $x15, 8 :: (load (s32))
27+
; NOPOSTMISCHED-NEXT: renamable $x28 = LW renamable $x15, 16 :: (load (s32))
28+
; NOPOSTMISCHED-NEXT: renamable $x29 = LW renamable $x15, 24 :: (load (s32))
29+
; NOPOSTMISCHED-NEXT: renamable $x11 = ADDW renamable $x6, killed renamable $x5
30+
; NOPOSTMISCHED-NEXT: renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
31+
; NOPOSTMISCHED-NEXT: renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
32+
; NOPOSTMISCHED-NEXT: renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
33+
; NOPOSTMISCHED-NEXT: SW renamable $x14, renamable $x15, 0 :: (store (s32))
34+
; NOPOSTMISCHED-NEXT: SW renamable $x14, renamable $x15, 8 :: (store (s32))
35+
; NOPOSTMISCHED-NEXT: SW renamable $x14, renamable $x15, 16 :: (store (s32))
36+
; NOPOSTMISCHED-NEXT: SW renamable $x14, renamable $x15, 24 :: (store (s32))
37+
; NOPOSTMISCHED-NEXT: PseudoRET
38+
;
39+
; NOCLUSTER-LABEL: name: mem_clustering_1
40+
; NOCLUSTER: liveins: $x6, $x10, $x14, $x15, $x16, $x17
41+
; NOCLUSTER-NEXT: {{ $}}
42+
; NOCLUSTER-NEXT: renamable $x5 = LW renamable $x15, 0 :: (load (s32))
43+
; NOCLUSTER-NEXT: SW renamable $x14, renamable $x15, 0 :: (store (s32))
44+
; NOCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x6, killed renamable $x5
45+
; NOCLUSTER-NEXT: renamable $x7 = LW renamable $x15, 8 :: (load (s32))
46+
; NOCLUSTER-NEXT: renamable $x28 = LW renamable $x15, 16 :: (load (s32))
47+
; NOCLUSTER-NEXT: renamable $x29 = LW renamable $x15, 24 :: (load (s32))
48+
; NOCLUSTER-NEXT: renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
49+
; NOCLUSTER-NEXT: SW renamable $x14, renamable $x15, 8 :: (store (s32))
50+
; NOCLUSTER-NEXT: SW renamable $x14, renamable $x15, 16 :: (store (s32))
51+
; NOCLUSTER-NEXT: SW killed renamable $x14, killed renamable $x15, 24 :: (store (s32))
52+
; NOCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
53+
; NOCLUSTER-NEXT: renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
54+
; NOCLUSTER-NEXT: PseudoRET
55+
;
56+
; MEMCLUSTER-LABEL: name: mem_clustering_1
57+
; MEMCLUSTER: liveins: $x6, $x10, $x14, $x15, $x16, $x17
58+
; MEMCLUSTER-NEXT: {{ $}}
59+
; MEMCLUSTER-NEXT: renamable $x5 = LW renamable $x15, 0 :: (load (s32))
60+
; MEMCLUSTER-NEXT: renamable $x7 = LW renamable $x15, 8 :: (load (s32))
61+
; MEMCLUSTER-NEXT: renamable $x28 = LW renamable $x15, 16 :: (load (s32))
62+
; MEMCLUSTER-NEXT: renamable $x29 = LW renamable $x15, 24 :: (load (s32))
63+
; MEMCLUSTER-NEXT: SW renamable $x14, renamable $x15, 0 :: (store (s32))
64+
; MEMCLUSTER-NEXT: SW renamable $x14, renamable $x15, 8 :: (store (s32))
65+
; MEMCLUSTER-NEXT: SW renamable $x14, renamable $x15, 16 :: (store (s32))
66+
; MEMCLUSTER-NEXT: SW killed renamable $x14, killed renamable $x15, 24 :: (store (s32))
67+
; MEMCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x6, killed renamable $x5
68+
; MEMCLUSTER-NEXT: renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
69+
; MEMCLUSTER-NEXT: renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
70+
; MEMCLUSTER-NEXT: renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
71+
; MEMCLUSTER-NEXT: PseudoRET
72+
renamable $x5 = LW renamable $x15, 0 :: (load (s32))
73+
renamable $x7 = LW renamable $x15, 8 :: (load (s32))
74+
renamable $x28 = LW renamable $x15, 16 :: (load (s32))
75+
renamable $x29 = LW renamable $x15, 24 :: (load (s32))
76+
renamable $x11 = ADDW killed renamable $x6, killed renamable $x5
77+
renamable $x13 = ADDW killed renamable $x7, killed renamable $x28
78+
renamable $x11 = ADDW killed renamable $x11, killed renamable $x13
79+
renamable $x6 = ADDW killed renamable $x11, killed renamable $x29
80+
SW renamable $x14, renamable $x15, 0 :: (store (s32))
81+
SW renamable $x14, renamable $x15, 8 :: (store (s32))
82+
SW renamable $x14, renamable $x15, 16 :: (store (s32))
83+
SW renamable $x14, renamable $x15, 24 :: (store (s32))
84+
PseudoRET
85+
...

0 commit comments

Comments
 (0)