[llvm] 5b70001 - [AArch64][PAC] Add helper enum/functions to handle PAC keys/ops.

Ahmed Bougacha via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 24 08:16:09 PDT 2022


Author: Ahmed Bougacha
Date: 2022-10-24T08:15:17-07:00
New Revision: 5b70001974680da136b4707ba133d7b392ef6616

URL: https://github.com/llvm/llvm-project/commit/5b70001974680da136b4707ba133d7b392ef6616
DIFF: https://github.com/llvm/llvm-project/commit/5b70001974680da136b4707ba133d7b392ef6616.diff

LOG: [AArch64][PAC] Add helper enum/functions to handle PAC keys/ops.

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64InstrInfo.h
    llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
    llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.h b/llvm/lib/Target/AArch64/AArch64InstrInfo.h
index a1c6f1957664f..c24322295043c 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.h
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.h
@@ -501,6 +501,39 @@ static inline bool isPTrueOpcode(unsigned Opc) {
 /// Return opcode to be used for indirect calls.
 unsigned getBLRCallOpcode(const MachineFunction &MF);
 
+/// Return XPAC opcode to be used for a ptrauth strip using the given key.
+static inline unsigned getXPACOpcodeForKey(AArch64PACKey::ID K) {
+  using namespace AArch64PACKey;
+  switch (K) {
+  case IA: case IB: return AArch64::XPACI;
+  case DA: case DB: return AArch64::XPACD;
+  }
+}
+
+/// Return AUT opcode to be used for a ptrauth auth using the given key, or its
+/// AUT*Z variant that doesn't take a discriminator operand, using zero instead.
+static inline unsigned getAUTOpcodeForKey(AArch64PACKey::ID K, bool Zero) {
+  using namespace AArch64PACKey;
+  switch (K) {
+  case IA: return Zero ? AArch64::AUTIZA : AArch64::AUTIA;
+  case IB: return Zero ? AArch64::AUTIZB : AArch64::AUTIB;
+  case DA: return Zero ? AArch64::AUTDZA : AArch64::AUTDA;
+  case DB: return Zero ? AArch64::AUTDZB : AArch64::AUTDB;
+  }
+}
+
+/// Return PAC opcode to be used for a ptrauth sign using the given key, or its
+/// PAC*Z variant that doesn't take a discriminator operand, using zero instead.
+static inline unsigned getPACOpcodeForKey(AArch64PACKey::ID K, bool Zero) {
+  using namespace AArch64PACKey;
+  switch (K) {
+  case IA: return Zero ? AArch64::PACIZA : AArch64::PACIA;
+  case IB: return Zero ? AArch64::PACIZB : AArch64::PACIB;
+  case DA: return Zero ? AArch64::PACDZA : AArch64::PACDA;
+  case DB: return Zero ? AArch64::PACDZB : AArch64::PACDB;
+  }
+}
+
 // struct TSFlags {
 #define TSFLAG_ELEMENT_SIZE_TYPE(X)      (X)       // 3-bits
 #define TSFLAG_DESTRUCTIVE_INST_TYPE(X) ((X) << 3) // 4-bits

diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
index 7afeaa0af2f9a..88c560cafffbc 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -5845,7 +5845,7 @@ bool AArch64InstructionSelector::selectIntrinsic(MachineInstr &I,
     auto DiscVal = getIConstantVRegVal(DiscReg, MRI);
     bool IsDiscZero = DiscVal && DiscVal->isNullValue();
 
-    if (Key > 3)
+    if (Key > AArch64PACKey::LAST)
       return false;
 
     unsigned Opcodes[][4] = {

diff  --git a/llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h b/llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
index 94bf55e2d4d2b..e893337f2a12d 100644
--- a/llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
+++ b/llvm/lib/Target/AArch64/Utils/AArch64BaseInfo.h
@@ -793,6 +793,48 @@ namespace AArch64II {
   };
 } // end namespace AArch64II
 
+//===----------------------------------------------------------------------===//
+// v8.3a Pointer Authentication
+//
+
+namespace AArch64PACKey {
+enum ID : uint8_t {
+  IA = 0,
+  IB = 1,
+  DA = 2,
+  DB = 3,
+  LAST = DB
+};
+} // namespace AArch64PACKey
+
+/// Return 2-letter identifier string for numeric key ID.
+inline static StringRef AArch64PACKeyIDToString(AArch64PACKey::ID KeyID) {
+  switch (KeyID) {
+  case AArch64PACKey::IA:
+    return StringRef("ia");
+  case AArch64PACKey::IB:
+    return StringRef("ib");
+  case AArch64PACKey::DA:
+    return StringRef("da");
+  case AArch64PACKey::DB:
+    return StringRef("db");
+  }
+}
+
+/// Return numeric key ID for 2-letter identifier string.
+inline static Optional<AArch64PACKey::ID>
+AArch64StringToPACKeyID(StringRef Name) {
+  if (Name == "ia")
+    return AArch64PACKey::IA;
+  if (Name == "ib")
+    return AArch64PACKey::IB;
+  if (Name == "da")
+    return AArch64PACKey::DA;
+  if (Name == "db")
+    return AArch64PACKey::DB;
+  return None;
+}
+
 namespace AArch64 {
 // The number of bits in a SVE register is architecturally defined
 // to be a multiple of this value.  If <M x t> has this number of bits,


        


More information about the llvm-commits mailing list