[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)
Sander de Smalen via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 25 09:42:25 PST 2024
================
@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const FunctionType *T) {
// FIXME: noreturn
}
+enum SMEState {
+ Normal = 0,
+ SM_Enabled = 1 << 0,
+ SM_Compatible = 1 << 1,
+ ZA_Agnostic = 1 << 2,
+ ZA_Shift = 3,
+ ZT0_Shift = 6,
+ None = 0b000,
+ In = 0b001,
+ Out = 0b010,
+ InOut = 0b011,
+ Preserves = 0b100
+};
+
+unsigned encodeZAState(unsigned SMEAttrs) {
+ switch (SMEAttrs) {
+ case FunctionType::ARM_None:
+ return SMEState::None;
+ case FunctionType::ARM_In:
+ return SMEState::In;
+ case FunctionType::ARM_Out:
+ return SMEState::Out;
+ case FunctionType::ARM_InOut:
+ return SMEState::InOut;
+ case FunctionType::ARM_Preserves:
+ return SMEState::Preserves;
+ }
+ llvm_unreachable("Unrecognised SME attribute");
+}
+
+// As described in the AArch64 ACLE, the mangling scheme for function types
+// which have SME attributes is implemented as a "pseudo" template:
+//
+// '__SME_ATTRS<<normal_function_type>, <sme_state>>'
+//
+// Combining the function type with a bitmask representing the streaming and ZA
+// properties of the function's interface.
+//
+// The mangling scheme is otherwise defined in the appendices to the Procedure
+// Call Standard for the Arm Architecture, see
+// https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#appendix-c-mangling
+//
+void CXXNameMangler::mangleSMEAttrs(unsigned SMEAttrs) {
+ if (!SMEAttrs)
+ return;
+
+ // Streaming Mode
+ unsigned Bitmask = SMEState::Normal;
+ if (SMEAttrs & FunctionType::SME_PStateSMEnabledMask)
+ Bitmask |= SMEState::SM_Enabled;
+ else if (SMEAttrs & FunctionType::SME_PStateSMCompatibleMask)
+ Bitmask |= SMEState::SM_Compatible;
+
+ // TODO: Must represent __arm_agnostic("sme_za_state")
+
+ // ZA-State
+ Bitmask |= encodeZAState(FunctionType::getArmZAState(SMEAttrs))
+ << SMEState::ZA_Shift;
+
+ // ZT0 State
+ Bitmask |= encodeZAState(FunctionType::getArmZT0State(SMEAttrs))
+ << SMEState::ZT0_Shift;
+
+ Out << "Lj" << Bitmask << "EE";
+
+ return;
----------------
sdesmalen-arm wrote:
no need for `return;`
https://github.com/llvm/llvm-project/pull/114209
More information about the cfe-commits
mailing list