Skip to content

Commit a9052b4

Browse files
committed
[AArch64] Add isAuthenticated predicate to MCInstDesc
Add a predicate to MCInstDesc that allows tools to determine whether an instruction authenticates a pointer. This can be used by diagnostic tools to hint at pointer authentication failures. Differential Revision: https://reviews.llvm.org/D70329 rdar://55089604
1 parent 7c47a37 commit a9052b4

File tree

9 files changed

+61
-6
lines changed

9 files changed

+61
-6
lines changed

llvm/include/llvm/MC/MCInstrDesc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ enum Flag {
176176
Add,
177177
Trap,
178178
VariadicOpsAreDefs,
179+
Authenticated,
179180
};
180181
}
181182

@@ -416,6 +417,15 @@ class MCInstrDesc {
416417
return Flags & (1ULL << MCID::VariadicOpsAreDefs);
417418
}
418419

420+
/// Return true if this instruction authenticates a pointer (e.g. LDRAx/BRAx
421+
/// from ARMv8.3, which perform loads/branches with authentication).
422+
///
423+
/// An authenticated instruction may fail in an ABI-defined manner when
424+
/// operating on an invalid signed pointer.
425+
bool isAuthenticated() const {
426+
return Flags & (1ULL << MCID::Authenticated);
427+
}
428+
419429
//===--------------------------------------------------------------------===//
420430
// Side Effect Analysis
421431
//===--------------------------------------------------------------------===//

llvm/include/llvm/Target/Target.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ class Instruction : InstructionEncoding {
530530
bit hasCtrlDep = 0; // Does this instruction r/w ctrl-flow chains?
531531
bit isNotDuplicable = 0; // Is it unsafe to duplicate this instruction?
532532
bit isConvergent = 0; // Is this instruction convergent?
533+
bit isAuthenticated = 0; // Does this instruction authenticate a pointer?
533534
bit isAsCheapAsAMove = 0; // As cheap (or cheaper) than a move instruction.
534535
bit hasExtraSrcRegAllocReq = 0; // Sources have special regalloc requirement?
535536
bit hasExtraDefRegAllocReq = 0; // Defs have special regalloc requirement?

llvm/lib/Target/AArch64/AArch64InstrFormats.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,7 @@ class RCPCLoad<bits<2> sz, string asm, RegisterClass RC>
14831483
class AuthBase<bits<1> M, dag oops, dag iops, string asm, string operands,
14841484
list<dag> pattern>
14851485
: I<oops, iops, asm, operands, "", pattern>, Sched<[]> {
1486+
let isAuthenticated = 1;
14861487
let Inst{31-25} = 0b1101011;
14871488
let Inst{20-11} = 0b1111100001;
14881489
let Inst{10} = M;
@@ -1522,6 +1523,7 @@ class BaseAuthLoad<bit M, bit W, dag oops, dag iops, string asm,
15221523
bits<10> offset;
15231524
bits<5> Rn;
15241525
bits<5> Rt;
1526+
let isAuthenticated = 1;
15251527
let Inst{31-24} = 0b11111000;
15261528
let Inst{23} = M;
15271529
let Inst{22} = offset{9};

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,20 +819,26 @@ let Predicates = [HasComplxNum, HasNEON] in {
819819
let Uses = [LR], Defs = [LR] in {
820820
def PACIAZ : SystemNoOperands<0b000, "paciaz">;
821821
def PACIBZ : SystemNoOperands<0b010, "pacibz">;
822-
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
823-
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
822+
let isAuthenticated = 1 in {
823+
def AUTIAZ : SystemNoOperands<0b100, "autiaz">;
824+
def AUTIBZ : SystemNoOperands<0b110, "autibz">;
825+
}
824826
}
825827
let Uses = [LR, SP], Defs = [LR] in {
826828
def PACIASP : SystemNoOperands<0b001, "paciasp">;
827829
def PACIBSP : SystemNoOperands<0b011, "pacibsp">;
828-
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
829-
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
830+
let isAuthenticated = 1 in {
831+
def AUTIASP : SystemNoOperands<0b101, "autiasp">;
832+
def AUTIBSP : SystemNoOperands<0b111, "autibsp">;
833+
}
830834
}
831835
let Uses = [X16, X17], Defs = [X17], CRm = 0b0001 in {
832836
def PACIA1716 : SystemNoOperands<0b000, "pacia1716">;
833837
def PACIB1716 : SystemNoOperands<0b010, "pacib1716">;
834-
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
835-
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
838+
let isAuthenticated = 1 in {
839+
def AUTIA1716 : SystemNoOperands<0b100, "autia1716">;
840+
def AUTIB1716 : SystemNoOperands<0b110, "autib1716">;
841+
}
836842
}
837843

838844
let Uses = [LR], Defs = [LR], CRm = 0b0000 in {

llvm/unittests/Target/AArch64/InstSizes.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ void runChecks(
7878

7979
} // anonymous namespace
8080

81+
TEST(InstSizes, Authenticated) {
82+
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
83+
ASSERT_TRUE(TM);
84+
std::unique_ptr<AArch64InstrInfo> II = createInstrInfo(TM.get());
85+
86+
auto isAuthInst = [](AArch64InstrInfo &II, MachineFunction &MF) {
87+
auto I = MF.begin()->begin();
88+
EXPECT_EQ(4u, II.getInstSizeInBytes(*I));
89+
EXPECT_TRUE(I->getDesc().isAuthenticated());
90+
};
91+
92+
runChecks(TM.get(), II.get(), "",
93+
" \n"
94+
" BLRAA $x10, $x9\n",
95+
isAuthInst);
96+
97+
runChecks(TM.get(), II.get(), "",
98+
" \n"
99+
" RETAB implicit $lr, implicit $sp, implicit killed $x0\n",
100+
isAuthInst);
101+
102+
runChecks(TM.get(), II.get(), "",
103+
" \n"
104+
" frame-destroy AUTIASP implicit-def $lr, implicit killed $lr, implicit $sp\n",
105+
isAuthInst);
106+
107+
runChecks(TM.get(), II.get(), "",
108+
" \n"
109+
" frame-destroy AUTIBSP implicit-def $lr, implicit killed $lr, implicit $sp\n",
110+
isAuthInst);
111+
}
112+
81113
TEST(InstSizes, STACKMAP) {
82114
std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
83115
ASSERT_TRUE(TM);

llvm/utils/TableGen/CodeGenInstruction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ CodeGenInstruction::CodeGenInstruction(Record *R)
396396
hasNoSchedulingInfo = R->getValueAsBit("hasNoSchedulingInfo");
397397
FastISelShouldIgnore = R->getValueAsBit("FastISelShouldIgnore");
398398
variadicOpsAreDefs = R->getValueAsBit("variadicOpsAreDefs");
399+
isAuthenticated = R->getValueAsBit("isAuthenticated");
399400

400401
bool Unset;
401402
mayLoad = R->getValueAsBitOrUnset("mayLoad", Unset);

llvm/utils/TableGen/CodeGenInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ template <typename T> class ArrayRef;
278278
bool hasChain : 1;
279279
bool hasChain_Inferred : 1;
280280
bool variadicOpsAreDefs : 1;
281+
bool isAuthenticated : 1;
281282

282283
std::string DeprecatedReason;
283284
bool HasComplexDeprecationPredicate;

llvm/utils/TableGen/InstrDocsEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
138138
FLAG(isConvergent)
139139
FLAG(hasNoSchedulingInfo)
140140
FLAG(variadicOpsAreDefs)
141+
FLAG(isAuthenticated)
141142
if (!FlagStrings.empty()) {
142143
OS << "Flags: ";
143144
bool IsFirst = true;

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
708708
if (Inst.isInsertSubreg) OS << "|(1ULL<<MCID::InsertSubreg)";
709709
if (Inst.isConvergent) OS << "|(1ULL<<MCID::Convergent)";
710710
if (Inst.variadicOpsAreDefs) OS << "|(1ULL<<MCID::VariadicOpsAreDefs)";
711+
if (Inst.isAuthenticated) OS << "|(1ULL<<MCID::Authenticated)";
711712

712713
// Emit all of the target-specific flags...
713714
BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags");

0 commit comments

Comments
 (0)