Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 7534620

Browse files
author
Jessica Paquette
committed
[MachineOutliner] Outline both register save calls + no LR save calls together
Instead of treating the outlined functions for these as distinct frames, they should be combined into one case. Neither allows for stack fixups, and both generate the same frame. Thus, they ought to be considered one case. This makes the code far easier to understand, for one thing. It also offers some small code size improvements. It's fairly rare to see a class of outlined functions that doesn't fall entirely into one variant (on CTMark anyway). It does happen from time to time though. This mostly offers some serious simplification. Also update the test to show the added functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348036 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e9322d8 commit 7534620

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
lines changed

lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5165,42 +5165,36 @@ AArch64InstrInfo::getOutliningCandidateInfo(
51655165
SetCandidateCallInfo(MachineOutlinerThunk, 4);
51665166
}
51675167

5168-
// Make sure that LR isn't live on entry to this candidate. The only
5169-
// instructions that use LR that could possibly appear in a repeated sequence
5170-
// are calls. Therefore, we only have to check and see if LR is dead on entry
5171-
// to (or exit from) some candidate.
5172-
else if (std::all_of(RepeatedSequenceLocs.begin(),
5173-
RepeatedSequenceLocs.end(),
5174-
[&TRI](outliner::Candidate &C) {
5175-
C.initLRU(TRI);
5176-
return C.LRU.available(AArch64::LR);
5177-
})) {
5178-
FrameID = MachineOutlinerNoLRSave;
5179-
NumBytesToCreateFrame = 4;
5180-
SetCandidateCallInfo(MachineOutlinerNoLRSave, 4);
5181-
}
5182-
5183-
// LR is live, so we need to save it. Decide whether it should be saved to
5184-
// the stack, or if it can be saved to a register.
51855168
else {
5186-
if (all_of(RepeatedSequenceLocs, [this, &TRI](outliner::Candidate &C) {
5187-
C.initLRU(TRI);
5188-
return findRegisterToSaveLRTo(C);
5189-
})) {
5190-
// Every candidate has an available callee-saved register for the save.
5191-
// We can save LR to a register.
5192-
FrameID = MachineOutlinerRegSave;
5193-
NumBytesToCreateFrame = 4;
5194-
SetCandidateCallInfo(MachineOutlinerRegSave, 12);
5169+
// We need to decide how to emit calls + frames. We can always emit the same
5170+
// frame if we don't need to save to the stack. If we have to save to the
5171+
// stack, then we need a different frame.
5172+
unsigned NumNoStackSave = 0;
5173+
5174+
for (outliner::Candidate &C : RepeatedSequenceLocs) {
5175+
C.initLRU(TRI);
5176+
5177+
// Is LR available? If so, we don't need a save.
5178+
if (C.LRU.available(AArch64::LR)) {
5179+
C.setCallInfo(MachineOutlinerNoLRSave, 4);
5180+
++NumNoStackSave;
5181+
}
5182+
5183+
// Is an unused register available? If so, we won't modify the stack, so
5184+
// we can outline with the same frame type as those that don't save LR.
5185+
else if (findRegisterToSaveLRTo(C)) {
5186+
C.setCallInfo(MachineOutlinerRegSave, 12);
5187+
++NumNoStackSave;
5188+
}
51955189
}
51965190

5197-
else {
5198-
// At least one candidate does not have an available callee-saved
5199-
// register. We must save LR to the stack.
5200-
FrameID = MachineOutlinerDefault;
5201-
NumBytesToCreateFrame = 4;
5191+
// If there are no places where we have to save LR, then note that we don't
5192+
// have to update the stack. Otherwise, give every candidate the default
5193+
// call type.
5194+
if (NumNoStackSave == RepeatedSequenceLocs.size())
5195+
FrameID = MachineOutlinerNoLRSave;
5196+
else
52025197
SetCandidateCallInfo(MachineOutlinerDefault, 12);
5203-
}
52045198
}
52055199

52065200
// Does every candidate's MBB contain a call? If so, then we might have a call

test/CodeGen/AArch64/machine-outliner-regsave.mir

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# RUN: -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
33
# Check that we save LR to a callee-saved register when possible.
44
# foo() should use a callee-saved register. However, bar() should not.
5-
--- |
6-
5+
--- |
6+
77
define void @foo() #0 {
88
ret void
99
}
@@ -17,48 +17,65 @@
1717
---
1818
# Make sure that when we outline and a register is available, we
1919
# use it to save + restore LR instead of SP.
20+
# Also make sure that we can call functions that require no save as the same
21+
# outlined function.
2022
# CHECK: name: foo
21-
# CHECK-DAG: bb.0
23+
# CHECK-DAG: bb.1
2224
# CHECK-DAG: $x[[REG:[0-9]+]] = ORRXrs $xzr, $lr, 0
2325
# CHECK-NEXT: BL
2426
# CHECK-NEXT: $lr = ORRXrs $xzr, $x[[REG]], 0
25-
# CHECK-DAG: bb.1
27+
# CHECK-DAG: bb.2
2628
# CHECK-DAG: $x[[REG]] = ORRXrs $xzr, $lr, 0
2729
# CHECK-NEXT: BL
2830
# CHECK-NEXT: $lr = ORRXrs $xzr, $x[[REG]], 0
29-
# CHECK-DAG: bb.2
31+
# CHECK-DAG: bb.3
3032
# CHECK-DAG: $x[[REG]] = ORRXrs $xzr, $lr, 0
3133
# CHECK-NEXT: BL
3234
# CHECK-NEXT: $lr = ORRXrs $xzr, $x[[REG]], 0
35+
# CHECK-DAG: bb.4
36+
# CHECK-NOT: $x[[REG]] = ORRXrs $xzr, $lr, 0
37+
# CHECK-DAG: BL
3338
name: foo
3439
tracksRegLiveness: true
35-
fixedStack:
40+
fixedStack:
3641
body: |
3742
bb.0:
38-
liveins: $lr, $w9
3943
$x25 = ORRXri $xzr, 1
44+
$lr = ORRXri $xzr, 1
45+
bb.1:
46+
liveins: $lr, $w9
4047
$w9 = ORRWri $wzr, 1
4148
$w9 = ORRWri $wzr, 1
4249
$w9 = ORRWri $wzr, 1
4350
$w9 = ORRWri $wzr, 1
4451
$w9 = ORRWri $wzr, 1
4552
$w9 = ORRWri $wzr, 2
46-
bb.1:
53+
bb.2:
4754
liveins: $lr, $w9
4855
$w9 = ORRWri $wzr, 1
4956
$w9 = ORRWri $wzr, 1
5057
$w9 = ORRWri $wzr, 1
5158
$w9 = ORRWri $wzr, 1
5259
$w9 = ORRWri $wzr, 1
5360
$w9 = ORRWri $wzr, 2
54-
bb.2:
61+
bb.3:
62+
liveins: $lr, $w9
63+
$w9 = ORRWri $wzr, 1
64+
$w9 = ORRWri $wzr, 1
65+
$w9 = ORRWri $wzr, 1
66+
$w9 = ORRWri $wzr, 1
67+
$w9 = ORRWri $wzr, 1
68+
$w9 = ORRWri $wzr, 2
69+
bb.4:
5570
liveins: $lr, $w9
5671
$w9 = ORRWri $wzr, 1
5772
$w9 = ORRWri $wzr, 1
5873
$w9 = ORRWri $wzr, 1
5974
$w9 = ORRWri $wzr, 1
6075
$w9 = ORRWri $wzr, 1
6176
$w9 = ORRWri $wzr, 2
77+
bb.5:
78+
liveins: $w9
6279
RET undef $lr
6380
6481
...
@@ -109,4 +126,3 @@ body: |
109126
bb.3:
110127
liveins: $lr, $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x19, $x20, $x21, $x22, $x23, $x20, $x21, $x22, $x23, $x24, $x25, $x26, $x27, $x28
111128
RET undef $lr
112-

0 commit comments

Comments
 (0)