Skip to content

Commit 0c96571

Browse files
MDevereauwwwatermiao
authored andcommitted
[AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276)
This enables specifing "za" or "zt0" to the clobber list for inline asm. This complies with the acle SME addition to the asm extension here: ARM-software/acle#276 Signed-off-by: chenmiao <[email protected]> Signed-off-by: chenmiao <[email protected]>
1 parent 8664637 commit 0c96571

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,8 @@ TargetInfo::BuiltinVaListKind AArch64TargetInfo::getBuiltinVaListKind() const {
11461146
}
11471147

11481148
const char *const AArch64TargetInfo::GCCRegNames[] = {
1149+
// clang-format off
1150+
11491151
// 32-bit Integer registers
11501152
"w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
11511153
"w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", "w22",
@@ -1182,7 +1184,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
11821184

11831185
// SVE predicate-as-counter registers
11841186
"pn0", "pn1", "pn2", "pn3", "pn4", "pn5", "pn6", "pn7", "pn8",
1185-
"pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
1187+
"pn9", "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
1188+
1189+
// SME registers
1190+
"za", "zt0",
1191+
1192+
// clang-format on
11861193
};
11871194

11881195
ArrayRef<const char *> AArch64TargetInfo::getGCCRegNames() const {

clang/test/CodeGen/aarch64-inline-asm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
9595
// CHECK: [[ARG2:%.+]] = load i64, ptr
9696
// CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 [[ARG2]])
9797
}
98+
99+
void test_sme_constraints(){
100+
asm("movt zt0[3, mul vl], z0" : : : "za");
101+
// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
102+
103+
asm("movt zt0[3, mul vl], z0" : : : "zt0");
104+
// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
105+
}

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10364,6 +10364,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
1036410364
parseConstraintCode(Constraint) != AArch64CC::Invalid)
1036510365
return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
1036610366

10367+
if (Constraint == "{za}") {
10368+
return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
10369+
}
10370+
10371+
if (Constraint == "{zt0}") {
10372+
return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
10373+
}
10374+
1036710375
// Use the default implementation in TargetLowering to convert the register
1036810376
// constraint into a member of a register class.
1036910377
std::pair<unsigned, const TargetRegisterClass *> Res;

llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const MachineFunction &MF,
491491
MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
492492
return true;
493493

494+
// ZA/ZT0 registers are reserved but may be permitted in the clobber list.
495+
if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
496+
return true;
497+
494498
return !isReservedReg(MF, PhysReg);
495499
}
496500

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - | FileCheck %s
3+
4+
define void @alpha(<vscale x 4 x i32> %x) local_unnamed_addr {
5+
entry:
6+
; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $za
7+
tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
8+
ret void
9+
}
10+
11+
define void @beta(<vscale x 4 x i32> %x) local_unnamed_addr {
12+
entry:
13+
; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def early-clobber $zt0
14+
tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
15+
ret void
16+
}

0 commit comments

Comments
 (0)