Skip to content

Commit 5f41cef

Browse files
[AArch64] NFC: Simplify discombobulating 'requiresSMChange' interface (#78703)
Having it return a `std::optional<bool>` is unnecessarily confusing. This patch changes it to a simple 'bool'. This patch also removes the 'BodyOverridesInterface' operand because there is only a single use for this which is easily rewritten.
1 parent 40a631f commit 5f41cef

File tree

5 files changed

+28
-80
lines changed

5 files changed

+28
-80
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7635,8 +7635,7 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
76357635
}
76367636

76377637
SDValue PStateSM;
7638-
std::optional<bool> RequiresSMChange =
7639-
CallerAttrs.requiresSMChange(CalleeAttrs);
7638+
bool RequiresSMChange = CallerAttrs.requiresSMChange(CalleeAttrs);
76407639
if (RequiresSMChange) {
76417640
if (CallerAttrs.hasStreamingInterfaceOrBody())
76427641
PStateSM = DAG.getConstant(1, DL, MVT::i64);
@@ -7910,8 +7909,9 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
79107909

79117910
SDValue InGlue;
79127911
if (RequiresSMChange) {
7913-
SDValue NewChain = changeStreamingMode(DAG, DL, *RequiresSMChange, Chain,
7914-
InGlue, PStateSM, true);
7912+
SDValue NewChain =
7913+
changeStreamingMode(DAG, DL, CalleeAttrs.hasStreamingInterface(), Chain,
7914+
InGlue, PStateSM, true);
79157915
Chain = NewChain.getValue(0);
79167916
InGlue = NewChain.getValue(1);
79177917
}
@@ -8061,8 +8061,8 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
80618061

80628062
if (RequiresSMChange) {
80638063
assert(PStateSM && "Expected a PStateSM to be set");
8064-
Result = changeStreamingMode(DAG, DL, !*RequiresSMChange, Result, InGlue,
8065-
PStateSM, false);
8064+
Result = changeStreamingMode(DAG, DL, !CalleeAttrs.hasStreamingInterface(),
8065+
Result, InGlue, PStateSM, false);
80668066
}
80678067

80688068
if (RequiresLazySave) {
@@ -25463,8 +25463,7 @@ bool AArch64TargetLowering::fallBackToDAGISel(const Instruction &Inst) const {
2546325463
if (auto *Base = dyn_cast<CallBase>(&Inst)) {
2546425464
auto CallerAttrs = SMEAttrs(*Inst.getFunction());
2546525465
auto CalleeAttrs = SMEAttrs(*Base);
25466-
if (CallerAttrs.requiresSMChange(CalleeAttrs,
25467-
/*BodyOverridesInterface=*/false) ||
25466+
if (CallerAttrs.requiresSMChange(CalleeAttrs) ||
2546825467
CallerAttrs.requiresLazySave(CalleeAttrs))
2546925468
return true;
2547025469
}

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,9 @@ bool AArch64TTIImpl::areInlineCompatible(const Function *Caller,
236236
return false;
237237

238238
if (CallerAttrs.requiresLazySave(CalleeAttrs) ||
239-
CallerAttrs.requiresSMChange(CalleeAttrs,
240-
/*BodyOverridesInterface=*/true)) {
239+
(CallerAttrs.requiresSMChange(CalleeAttrs) &&
240+
(!CallerAttrs.hasStreamingInterfaceOrBody() ||
241+
!CalleeAttrs.hasStreamingBody()))) {
241242
if (hasPossibleIncompatibleOps(Callee))
242243
return false;
243244
}

llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,17 @@ SMEAttrs::SMEAttrs(const AttributeList &Attrs) {
8282
Bitmask |= encodeZT0State(StateValue::New);
8383
}
8484

85-
std::optional<bool>
86-
SMEAttrs::requiresSMChange(const SMEAttrs &Callee,
87-
bool BodyOverridesInterface) const {
88-
// If the transition is not through a call (e.g. when considering inlining)
89-
// and Callee has a streaming body, then we can ignore the interface of
90-
// Callee.
91-
if (BodyOverridesInterface && Callee.hasStreamingBody()) {
92-
return hasStreamingInterfaceOrBody() ? std::nullopt
93-
: std::optional<bool>(true);
94-
}
95-
85+
bool SMEAttrs::requiresSMChange(const SMEAttrs &Callee) const {
9686
if (Callee.hasStreamingCompatibleInterface())
97-
return std::nullopt;
87+
return false;
9888

9989
// Both non-streaming
10090
if (hasNonStreamingInterfaceAndBody() && Callee.hasNonStreamingInterface())
101-
return std::nullopt;
91+
return false;
10292

10393
// Both streaming
10494
if (hasStreamingInterfaceOrBody() && Callee.hasStreamingInterface())
105-
return std::nullopt;
95+
return false;
10696

107-
return Callee.hasStreamingInterface();
97+
return true;
10898
}

llvm/lib/Target/AArch64/Utils/AArch64SMEAttributes.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,7 @@ class SMEAttrs {
7575

7676
/// \return true if a call from Caller -> Callee requires a change in
7777
/// streaming mode.
78-
/// If \p BodyOverridesInterface is true and Callee has a streaming body,
79-
/// then requiresSMChange considers a call to Callee as having a Streaming
80-
/// interface. This can be useful when considering e.g. inlining, where we
81-
/// explicitly want the body to overrule the interface (because after inlining
82-
/// the interface is no longer relevant).
83-
std::optional<bool>
84-
requiresSMChange(const SMEAttrs &Callee,
85-
bool BodyOverridesInterface = false) const;
78+
bool requiresSMChange(const SMEAttrs &Callee) const;
8679

8780
// Interfaces to query PSTATE.ZA
8881
bool hasNewZABody() const { return Bitmask & ZA_New; }

llvm/unittests/Target/AArch64/SMEAttributesTest.cpp

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -193,86 +193,51 @@ TEST(SMEAttributes, Transitions) {
193193
ASSERT_FALSE(SA(SA::Normal).requiresSMChange(SA(SA::Normal)));
194194
// Normal -> Normal + LocallyStreaming
195195
ASSERT_FALSE(SA(SA::Normal).requiresSMChange(SA(SA::Normal | SA::SM_Body)));
196-
ASSERT_EQ(*SA(SA::Normal)
197-
.requiresSMChange(SA(SA::Normal | SA::SM_Body),
198-
/*BodyOverridesInterface=*/true),
199-
true);
200196

201197
// Normal -> Streaming
202-
ASSERT_EQ(*SA(SA::Normal).requiresSMChange(SA(SA::SM_Enabled)), true);
198+
ASSERT_TRUE(SA(SA::Normal).requiresSMChange(SA(SA::SM_Enabled)));
203199
// Normal -> Streaming + LocallyStreaming
204-
ASSERT_EQ(*SA(SA::Normal).requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body)),
205-
true);
206-
ASSERT_EQ(*SA(SA::Normal)
207-
.requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body),
208-
/*BodyOverridesInterface=*/true),
209-
true);
200+
ASSERT_TRUE(
201+
SA(SA::Normal).requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body)));
210202

211203
// Normal -> Streaming-compatible
212204
ASSERT_FALSE(SA(SA::Normal).requiresSMChange(SA(SA::SM_Compatible)));
213205
// Normal -> Streaming-compatible + LocallyStreaming
214206
ASSERT_FALSE(
215207
SA(SA::Normal).requiresSMChange(SA(SA::SM_Compatible | SA::SM_Body)));
216-
ASSERT_EQ(*SA(SA::Normal)
217-
.requiresSMChange(SA(SA::SM_Compatible | SA::SM_Body),
218-
/*BodyOverridesInterface=*/true),
219-
true);
220208

221209
// Streaming -> Normal
222-
ASSERT_EQ(*SA(SA::SM_Enabled).requiresSMChange(SA(SA::Normal)), false);
210+
ASSERT_TRUE(SA(SA::SM_Enabled).requiresSMChange(SA(SA::Normal)));
223211
// Streaming -> Normal + LocallyStreaming
224-
ASSERT_EQ(*SA(SA::SM_Enabled).requiresSMChange(SA(SA::Normal | SA::SM_Body)),
225-
false);
226-
ASSERT_FALSE(SA(SA::SM_Enabled)
227-
.requiresSMChange(SA(SA::Normal | SA::SM_Body),
228-
/*BodyOverridesInterface=*/true));
212+
ASSERT_TRUE(
213+
SA(SA::SM_Enabled).requiresSMChange(SA(SA::Normal | SA::SM_Body)));
229214

230215
// Streaming -> Streaming
231216
ASSERT_FALSE(SA(SA::SM_Enabled).requiresSMChange(SA(SA::SM_Enabled)));
232217
// Streaming -> Streaming + LocallyStreaming
233218
ASSERT_FALSE(
234219
SA(SA::SM_Enabled).requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body)));
235-
ASSERT_FALSE(SA(SA::SM_Enabled)
236-
.requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body),
237-
/*BodyOverridesInterface=*/true));
238220

239221
// Streaming -> Streaming-compatible
240222
ASSERT_FALSE(SA(SA::SM_Enabled).requiresSMChange(SA(SA::SM_Compatible)));
241223
// Streaming -> Streaming-compatible + LocallyStreaming
242224
ASSERT_FALSE(
243225
SA(SA::SM_Enabled).requiresSMChange(SA(SA::SM_Compatible | SA::SM_Body)));
244-
ASSERT_FALSE(SA(SA::SM_Enabled)
245-
.requiresSMChange(SA(SA::SM_Compatible | SA::SM_Body),
246-
/*BodyOverridesInterface=*/true));
247226

248227
// Streaming-compatible -> Normal
249-
ASSERT_EQ(*SA(SA::SM_Compatible).requiresSMChange(SA(SA::Normal)), false);
250-
ASSERT_EQ(
251-
*SA(SA::SM_Compatible).requiresSMChange(SA(SA::Normal | SA::SM_Body)),
252-
false);
253-
ASSERT_EQ(*SA(SA::SM_Compatible)
254-
.requiresSMChange(SA(SA::Normal | SA::SM_Body),
255-
/*BodyOverridesInterface=*/true),
256-
true);
228+
ASSERT_TRUE(SA(SA::SM_Compatible).requiresSMChange(SA(SA::Normal)));
229+
ASSERT_TRUE(
230+
SA(SA::SM_Compatible).requiresSMChange(SA(SA::Normal | SA::SM_Body)));
257231

258232
// Streaming-compatible -> Streaming
259-
ASSERT_EQ(*SA(SA::SM_Compatible).requiresSMChange(SA(SA::SM_Enabled)), true);
233+
ASSERT_TRUE(SA(SA::SM_Compatible).requiresSMChange(SA(SA::SM_Enabled)));
260234
// Streaming-compatible -> Streaming + LocallyStreaming
261-
ASSERT_EQ(
262-
*SA(SA::SM_Compatible).requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body)),
263-
true);
264-
ASSERT_EQ(*SA(SA::SM_Compatible)
265-
.requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body),
266-
/*BodyOverridesInterface=*/true),
267-
true);
235+
ASSERT_TRUE(
236+
SA(SA::SM_Compatible).requiresSMChange(SA(SA::SM_Enabled | SA::SM_Body)));
268237

269238
// Streaming-compatible -> Streaming-compatible
270239
ASSERT_FALSE(SA(SA::SM_Compatible).requiresSMChange(SA(SA::SM_Compatible)));
271240
// Streaming-compatible -> Streaming-compatible + LocallyStreaming
272241
ASSERT_FALSE(SA(SA::SM_Compatible)
273242
.requiresSMChange(SA(SA::SM_Compatible | SA::SM_Body)));
274-
ASSERT_EQ(*SA(SA::SM_Compatible)
275-
.requiresSMChange(SA(SA::SM_Compatible | SA::SM_Body),
276-
/*BodyOverridesInterface=*/true),
277-
true);
278243
}

0 commit comments

Comments
 (0)