Skip to content

Commit

Permalink
[AArch64] Add Missing Custom Target Operands
Browse files Browse the repository at this point in the history
I noticed, when examining the generated Asm Matcher table, that some of
these custom immediate operands are missing, and so we are not parsing
some hint aliases into the correct MCInst.

Where this becomes apparent is when you parse e.g. `hint rust-lang#7` into an
MCInst - without these cases, it becomes the MCInst `(HINT 17)`, which
will always be printed as `hint rust-lang#17`. With these cases, it becomes the
MCInst `XPACLRI`, which will be printed as `xpaclri` with pauth, or
`hint rust-lang#17` without, matching how `xpaclri` is parsed.

We only handle some specific hint aliases in this manner, usually where
these hints have specific effects that need to be modelled for accurate
code-generation. Otherwise, we just use the normal `InstAlias` system
to have the aliases parsed into a `(HINT N)` MCInst.

Differential Revision: https://reviews.llvm.org/D146630
  • Loading branch information
lenary committed Mar 23, 2023
1 parent 82c83d7 commit 6194446
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
17 changes: 14 additions & 3 deletions llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7642,9 +7642,10 @@ unsigned AArch64AsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
return Match_Success;
return Match_InvalidOperand;

// If the kind is a token for a literal immediate, check if our asm
// operand matches. This is for InstAliases which have a fixed-value
// immediate in the syntax.
// If the kind is a token for a literal immediate, check if our asm operand
// matches. This is for InstAliases which have a fixed-value immediate in
// the asm string, such as hints which are parsed into a specific
// instruction definition.
#define MATCH_HASH(N) \
case MCK__HASH_##N: \
return MatchesOpImmediate(N);
Expand All @@ -7654,10 +7655,20 @@ unsigned AArch64AsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
MATCH_HASH(3)
MATCH_HASH(4)
MATCH_HASH(6)
MATCH_HASH(7)
MATCH_HASH(8)
MATCH_HASH(10)
MATCH_HASH(12)
MATCH_HASH(14)
MATCH_HASH(16)
MATCH_HASH(24)
MATCH_HASH(25)
MATCH_HASH(26)
MATCH_HASH(27)
MATCH_HASH(28)
MATCH_HASH(29)
MATCH_HASH(30)
MATCH_HASH(31)
MATCH_HASH(32)
MATCH_HASH(40)
MATCH_HASH(48)
Expand Down
39 changes: 39 additions & 0 deletions llvm/test/MC/AArch64/armv8.3a-signed-pointer.s
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,83 @@

// ALL-EMPTY:
// ALL-EMPTY:
hint #25
paciasp
// CHECK-NEXT: paciasp // encoding: [0x3f,0x23,0x03,0xd5]
// CHECK-NEXT: paciasp // encoding: [0x3f,0x23,0x03,0xd5]
// NO83-NEXT: hint #25 // encoding: [0x3f,0x23,0x03,0xd5]
// NO83-NEXT: hint #25 // encoding: [0x3f,0x23,0x03,0xd5]
hint #29
autiasp
// CHECK-NEXT: autiasp // encoding: [0xbf,0x23,0x03,0xd5]
// CHECK-NEXT: autiasp // encoding: [0xbf,0x23,0x03,0xd5]
// NO83-NEXT: hint #29 // encoding: [0xbf,0x23,0x03,0xd5]
// NO83-NEXT: hint #29 // encoding: [0xbf,0x23,0x03,0xd5]
hint #24
paciaz
// CHECK-NEXT: paciaz // encoding: [0x1f,0x23,0x03,0xd5]
// CHECK-NEXT: paciaz // encoding: [0x1f,0x23,0x03,0xd5]
// NO83-NEXT: hint #24 // encoding: [0x1f,0x23,0x03,0xd5]
// NO83-NEXT: hint #24 // encoding: [0x1f,0x23,0x03,0xd5]
hint #28
autiaz
// CHECK-NEXT: autiaz // encoding: [0x9f,0x23,0x03,0xd5]
// CHECK-NEXT: autiaz // encoding: [0x9f,0x23,0x03,0xd5]
// NO83-NEXT: hint #28 // encoding: [0x9f,0x23,0x03,0xd5]
// NO83-NEXT: hint #28 // encoding: [0x9f,0x23,0x03,0xd5]
hint #8
pacia1716
// CHECK-NEXT: pacia1716 // encoding: [0x1f,0x21,0x03,0xd5]
// CHECK-NEXT: pacia1716 // encoding: [0x1f,0x21,0x03,0xd5]
// NO83-NEXT: hint #8 // encoding: [0x1f,0x21,0x03,0xd5]
// NO83-NEXT: hint #8 // encoding: [0x1f,0x21,0x03,0xd5]
hint #12
autia1716
// CHECK-NEXT: autia1716 // encoding: [0x9f,0x21,0x03,0xd5]
// CHECK-NEXT: autia1716 // encoding: [0x9f,0x21,0x03,0xd5]
// NO83-NEXT: hint #12 // encoding: [0x9f,0x21,0x03,0xd5]
// NO83-NEXT: hint #12 // encoding: [0x9f,0x21,0x03,0xd5]
hint #27
pacibsp
// CHECK-NEXT: pacibsp // encoding: [0x7f,0x23,0x03,0xd5]
// CHECK-NEXT: pacibsp // encoding: [0x7f,0x23,0x03,0xd5]
// NO83-NEXT: hint #27 // encoding: [0x7f,0x23,0x03,0xd5]
// NO83-NEXT: hint #27 // encoding: [0x7f,0x23,0x03,0xd5]
hint #31
autibsp
// CHECK-NEXT: autibsp // encoding: [0xff,0x23,0x03,0xd5]
// CHECK-NEXT: autibsp // encoding: [0xff,0x23,0x03,0xd5]
// NO83-NEXT: hint #31 // encoding: [0xff,0x23,0x03,0xd5]
// NO83-NEXT: hint #31 // encoding: [0xff,0x23,0x03,0xd5]
hint #26
pacibz
// CHECK-NEXT: pacibz // encoding: [0x5f,0x23,0x03,0xd5]
// CHECK-NEXT: pacibz // encoding: [0x5f,0x23,0x03,0xd5]
// NO83-NEXT: hint #26 // encoding: [0x5f,0x23,0x03,0xd5]
// NO83-NEXT: hint #26 // encoding: [0x5f,0x23,0x03,0xd5]
hint #30
autibz
// CHECK-NEXT: autibz // encoding: [0xdf,0x23,0x03,0xd5]
// CHECK-NEXT: autibz // encoding: [0xdf,0x23,0x03,0xd5]
// NO83-NEXT: hint #30 // encoding: [0xdf,0x23,0x03,0xd5]
// NO83-NEXT: hint #30 // encoding: [0xdf,0x23,0x03,0xd5]
hint #10
pacib1716
// CHECK-NEXT: pacib1716 // encoding: [0x5f,0x21,0x03,0xd5]
// CHECK-NEXT: pacib1716 // encoding: [0x5f,0x21,0x03,0xd5]
// NO83-NEXT: hint #10 // encoding: [0x5f,0x21,0x03,0xd5]
// NO83-NEXT: hint #10 // encoding: [0x5f,0x21,0x03,0xd5]
hint #14
autib1716
// CHECK-NEXT: autib1716 // encoding: [0xdf,0x21,0x03,0xd5]
// CHECK-NEXT: autib1716 // encoding: [0xdf,0x21,0x03,0xd5]
// NO83-NEXT: hint #14 // encoding: [0xdf,0x21,0x03,0xd5]
// NO83-NEXT: hint #14 // encoding: [0xdf,0x21,0x03,0xd5]
hint #7
xpaclri
// CHECK-NEXT: xpaclri // encoding: [0xff,0x20,0x03,0xd5]
// CHECK-NEXT: xpaclri // encoding: [0xff,0x20,0x03,0xd5]
// NO83-NEXT: hint #7 // encoding: [0xff,0x20,0x03,0xd5]
// NO83-NEXT: hint #7 // encoding: [0xff,0x20,0x03,0xd5]

// ALL-EMPTY:
Expand Down

0 comments on commit 6194446

Please sign in to comment.