Skip to content

Commit 3ef9706

Browse files
committed
[MIR] Allow overriding isSSA, noPhis, noVRegs in MIR input
Allow setting the computed properties IsSSA, NoPHIs, NoVRegs for MIR functions in MIR input. The default value is still the computed value. If the property is set to false, the computed result is ignored. This allows for tests where a pass is for example inserting PHI nodes into a function that didn't have any previously. Closes #37787
1 parent c30fa3c commit 3ef9706

File tree

11 files changed

+88
-14
lines changed

11 files changed

+88
-14
lines changed

llvm/include/llvm/CodeGen/MIRYamlMapping.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,11 @@ struct MachineFunction {
730730
bool TracksRegLiveness = false;
731731
bool HasWinCFI = false;
732732

733+
// Computed properties that should be overridable
734+
bool NoPHIs = false;
735+
bool IsSSA = false;
736+
bool NoVRegs = false;
737+
733738
bool CallsEHReturn = false;
734739
bool CallsUnwindInit = false;
735740
bool HasEHCatchret = false;
@@ -770,6 +775,12 @@ template <> struct MappingTraits<MachineFunction> {
770775
YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness, false);
771776
YamlIO.mapOptional("hasWinCFI", MF.HasWinCFI, false);
772777

778+
// PHIs must be not be capitalized, since it will clash with the MIR opcode
779+
// leading to false-positive FileCheck hits with CHECK-NOT
780+
YamlIO.mapOptional("noPhis", MF.NoPHIs, true);
781+
YamlIO.mapOptional("isSSA", MF.IsSSA, true);
782+
YamlIO.mapOptional("noVRegs", MF.NoVRegs, true);
783+
773784
YamlIO.mapOptional("callsEHReturn", MF.CallsEHReturn, false);
774785
YamlIO.mapOptional("callsUnwindInit", MF.CallsUnwindInit, false);
775786
YamlIO.mapOptional("hasEHCatchret", MF.HasEHCatchret, false);

llvm/lib/CodeGen/MIRParser/MIRParser.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ class MIRParserImpl {
178178
SMDiagnostic diagFromBlockStringDiag(const SMDiagnostic &Error,
179179
SMRange SourceRange);
180180

181-
void computeFunctionProperties(MachineFunction &MF);
181+
void computeFunctionProperties(MachineFunction &MF,
182+
const yaml::MachineFunction &YamlMF);
182183

183184
void setupDebugValueTracking(MachineFunction &MF,
184185
PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF);
@@ -373,7 +374,8 @@ static bool isSSA(const MachineFunction &MF) {
373374
return true;
374375
}
375376

376-
void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
377+
void MIRParserImpl::computeFunctionProperties(
378+
MachineFunction &MF, const yaml::MachineFunction &YamlMF) {
377379
MachineFunctionProperties &Properties = MF.getProperties();
378380

379381
bool HasPHI = false;
@@ -398,20 +400,25 @@ void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
398400
}
399401
}
400402
}
401-
if (!HasPHI)
403+
404+
// Don't overwrite NoPHIs if the input MIR explicitly set it to false
405+
if (YamlMF.NoPHIs && !HasPHI)
402406
Properties.set(MachineFunctionProperties::Property::NoPHIs);
407+
403408
MF.setHasInlineAsm(HasInlineAsm);
404409

405410
if (HasTiedOps && AllTiedOpsRewritten)
406411
Properties.set(MachineFunctionProperties::Property::TiedOpsRewritten);
407412

408-
if (isSSA(MF))
413+
// Don't overwrite IsSSA if the input MIR explicitly set it to false
414+
if (YamlMF.IsSSA && isSSA(MF))
409415
Properties.set(MachineFunctionProperties::Property::IsSSA);
410416
else
411417
Properties.reset(MachineFunctionProperties::Property::IsSSA);
412418

419+
// Don't overwrite NoVRegs if the input MIR explicitly set it to false
413420
const MachineRegisterInfo &MRI = MF.getRegInfo();
414-
if (MRI.getNumVirtRegs() == 0)
421+
if (YamlMF.NoVRegs && MRI.getNumVirtRegs() == 0)
415422
Properties.set(MachineFunctionProperties::Property::NoVRegs);
416423
}
417424

@@ -595,7 +602,7 @@ MIRParserImpl::initializeMachineFunction(const yaml::MachineFunction &YamlMF,
595602
MachineRegisterInfo &MRI = MF.getRegInfo();
596603
MRI.freezeReservedRegs();
597604

598-
computeFunctionProperties(MF);
605+
computeFunctionProperties(MF, YamlMF);
599606

600607
if (initializeCallSiteInfo(PFS, YamlMF))
601608
return false;

llvm/lib/CodeGen/MIRPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ void MIRPrinter::print(const MachineFunction &MF) {
223223
YamlMF.TracksDebugUserValues = MF.getProperties().hasProperty(
224224
MachineFunctionProperties::Property::TracksDebugUserValues);
225225

226+
YamlMF.NoPHIs = MF.getProperties().hasProperty(
227+
MachineFunctionProperties::Property::NoPHIs);
228+
YamlMF.IsSSA = MF.getProperties().hasProperty(
229+
MachineFunctionProperties::Property::IsSSA);
230+
YamlMF.NoVRegs = MF.getProperties().hasProperty(
231+
MachineFunctionProperties::Property::NoVRegs);
232+
226233
convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
227234
MachineModuleSlotTracker MST(MMI, &MF);
228235
MST.incorporateFunction(MF.getFunction());

llvm/test/CodeGen/AArch64/mlicm-stack-write-check.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
---
44
name: test
55
tracksRegLiveness: true
6+
isSSA: false
67
registers:
78
- { id: 0, class: gpr64 }
89
stack:
@@ -30,11 +31,11 @@ body: |
3031
bb.2:
3132
liveins: $x0
3233
%0 = COPY $x0
33-
%0 = COPY $x0 ; Force isSSA = false.
3434
...
3535
---
3636
name: test2
3737
tracksRegLiveness: true
38+
isSSA: false
3839
registers:
3940
- { id: 0, class: gpr64 }
4041
stack:
@@ -62,5 +63,4 @@ body: |
6263
bb.2:
6364
liveins: $x0
6465
%0 = COPY $x0
65-
%0 = COPY $x0 ; Force isSSA = false.
6666
...

llvm/test/CodeGen/AMDGPU/early-tailduplicator-nophis.mir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -run-pass=early-tailduplication -verify-machineinstrs -o - %s | FileCheck %s
33

44
# There are no phis in this testcase. Early tail duplication introduces them,
5-
# so the NoPHIs property needs to be cleared to avoid verifier errors
5+
# so the NoPHIs property needs to be set explicitly to false to avoid verifier
6+
# errors
67

78
---
89
name: tail_duplicate_nophis
910
tracksRegLiveness: true
11+
noPhis: false
1012
body: |
1113
; CHECK-LABEL: name: tail_duplicate_nophis
1214
; CHECK: bb.0:

llvm/test/CodeGen/Hexagon/expand-condsets-impuse2.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
name: f0
88
tracksRegLiveness: true
9+
isSSA: false
910
body: |
1011
bb.0:
1112
successors: %bb.1
1213
liveins: $r0, $r1
1314
%0:intregs = COPY $r0
14-
%0:intregs = COPY $r0 ; defeat IsSSA detection
1515
%1:intregs = COPY $r1
1616
%2:intregs = COPY $r0
1717
%3:intregs = M2_mpyi %2, %1

llvm/test/CodeGen/Hexagon/expand-condsets-phys-reg.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
name: fred
1111
tracksRegLiveness: true
12+
isSSA: false
1213
body: |
1314
bb.0:
1415
successors: %bb.1, %bb.2
1516
liveins: $r0
1617
17-
%0:intregs = A2_tfrsi 0 ;; Multiple defs to ensure IsSSA = false
1818
%0:intregs = L2_loadri_io $r0, 0
1919
%1:predregs = C2_cmpgti %0, 10
2020
%2:intregs = C2_mux %1, $r31, %0

llvm/test/CodeGen/Hexagon/expand-condsets-rm-reg.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
name: fred
2222
tracksRegLiveness: true
23+
isSSA: false
2324
registers:
2425
- { id: 0, class: intregs }
2526
- { id: 1, class: intregs }
@@ -35,7 +36,6 @@ body: |
3536
bb.0:
3637
liveins: $r0, $r1, $p0
3738
%0 = COPY $r0
38-
%0 = COPY $r0 ; Force isSSA = false.
3939
%1 = COPY $r1
4040
%2 = COPY $p0
4141
; Check that %3 was coalesced into %4.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# RUN: llc -run-pass none -o - %s | FileCheck %s
2+
# Test that we can disable certain properties that are normally computed
3+
4+
---
5+
# CHECK-LABEL: name: TestNoPhis
6+
# CHECK: noPhis: true
7+
# CHECK: ...
8+
name: TestNoPhis
9+
...
10+
---
11+
# CHECK-LABEL: name: TestNoPhisOverride
12+
# CHECK: noPhis: false
13+
# CHECK: ...
14+
name: TestNoPhisOverride
15+
noPhis: false
16+
...
17+
---
18+
# CHECK-LABEL: name: TestIsSSA
19+
# CHECK: isSSA: true
20+
# CHECK: ...
21+
name: TestIsSSA
22+
...
23+
---
24+
# CHECK-LABEL: name: TestIsSSAOverride
25+
# CHECK: isSSA: false
26+
# CHECK: ...
27+
name: TestIsSSAOverride
28+
isSSA: false
29+
...
30+
---
31+
# CHECK-LABEL: name: TestNoVRegs
32+
# CHECK: noVRegs: true
33+
# CHECK: ...
34+
name: TestNoVRegs
35+
...
36+
---
37+
# CHECK-LABEL: name: TestNoVRegsOverride
38+
# CHECK: noVRegs: false
39+
# CHECK: ...
40+
name: TestNoVRegsOverride
41+
noVRegs: false
42+
...

llvm/test/CodeGen/X86/sjlj-shadow-stack-liveness.mir

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ name: bar
1414
# CHECK-LABEL: name: bar
1515
alignment: 16
1616
tracksRegLiveness: true
17+
noPhis: false
1718
body: |
1819
bb.0:
1920
%0:gr64 = IMPLICIT_DEF
@@ -29,8 +30,6 @@ body: |
2930
; CHECK-NOT: MOV64rm killed %0
3031
; CHECK-NEXT: MOV64rm killed %0
3132
32-
; FIXME: Dummy PHI to set the property NoPHIs to false. PR38439.
3333
bb.2:
34-
%1:gr64 = PHI undef %1, %bb.2, undef %1, %bb.2
3534
JMP_1 %bb.2
3635
...

llvm/test/tools/llvm-reduce/mir/preserve-func-info.mir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# RESULT-NEXT: failedISel: true
1515
# RESULT-NEXT: tracksRegLiveness: true
1616
# RESULT-NEXT: hasWinCFI: true
17+
# RESULT-NEXT: noPhis: false
18+
# RESULT-NEXT: isSSA: false
19+
# RESULT-NEXT: noVRegs: false
1720
# RESULT-NEXT: callsEHReturn: true
1821
# RESULT-NEXT: callsUnwindInit: true
1922
# RESULT-NEXT: hasEHCatchret: true
@@ -41,6 +44,9 @@ selected: true
4144
failedISel: true
4245
tracksRegLiveness: true
4346
hasWinCFI: true
47+
noPhis: false
48+
isSSA: false
49+
noVRegs: false
4450
failsVerification: true
4551
tracksDebugUserValues: true
4652
callsEHReturn: true

0 commit comments

Comments
 (0)