Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bbdac9

Browse files
authored
[MIParser] - Add support for MMRAs (llvm#180320)
Probably just forgotten in llvm#78569
1 parent d62bc3a commit 8bbdac9

5 files changed

Lines changed: 97 additions & 2 deletions

File tree

llvm/lib/CodeGen/MIRParser/MILexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) {
294294
MIToken::kw_machine_block_address_taken)
295295
.Case("call-frame-size", MIToken::kw_call_frame_size)
296296
.Case("noconvergent", MIToken::kw_noconvergent)
297+
.Case("mmra", MIToken::kw_mmra)
297298
.Default(MIToken::Identifier);
298299
}
299300

llvm/lib/CodeGen/MIRParser/MILexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ struct MIToken {
147147
kw_machine_block_address_taken,
148148
kw_call_frame_size,
149149
kw_noconvergent,
150+
kw_mmra,
150151

151152
// Metadata types.
152153
kw_distinct,

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ class MIParser {
523523
bool parsePreOrPostInstrSymbol(MCSymbol *&Symbol);
524524
bool parseHeapAllocMarker(MDNode *&Node);
525525
bool parsePCSections(MDNode *&Node);
526+
bool parseMMRA(MDNode *&Node);
526527

527528
bool parseTargetImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
528529
MachineOperand &Dest, const MIRFormatter &MF);
@@ -1077,7 +1078,7 @@ bool MIParser::parse(MachineInstr *&MI) {
10771078
while (!Token.isNewlineOrEOF() && Token.isNot(MIToken::kw_pre_instr_symbol) &&
10781079
Token.isNot(MIToken::kw_post_instr_symbol) &&
10791080
Token.isNot(MIToken::kw_heap_alloc_marker) &&
1080-
Token.isNot(MIToken::kw_pcsections) &&
1081+
Token.isNot(MIToken::kw_pcsections) && Token.isNot(MIToken::kw_mmra) &&
10811082
Token.isNot(MIToken::kw_cfi_type) &&
10821083
Token.isNot(MIToken::kw_deactivation_symbol) &&
10831084
Token.isNot(MIToken::kw_debug_location) &&
@@ -1113,7 +1114,9 @@ bool MIParser::parse(MachineInstr *&MI) {
11131114
if (Token.is(MIToken::kw_pcsections))
11141115
if (parsePCSections(PCSections))
11151116
return true;
1116-
1117+
MDNode *MMRA = nullptr;
1118+
if (Token.is(MIToken::kw_mmra) && parseMMRA(MMRA))
1119+
return true;
11171120
unsigned CFIType = 0;
11181121
if (Token.is(MIToken::kw_cfi_type)) {
11191122
lex();
@@ -1210,6 +1213,8 @@ bool MIParser::parse(MachineInstr *&MI) {
12101213
MI->setHeapAllocMarker(MF, HeapAllocMarker);
12111214
if (PCSections)
12121215
MI->setPCSections(MF, PCSections);
1216+
if (MMRA)
1217+
MI->setMMRAMetadata(MF, MMRA);
12131218
if (CFIType)
12141219
MI->setCFIType(MF, CFIType);
12151220
if (DS)
@@ -3614,6 +3619,20 @@ bool MIParser::parsePCSections(MDNode *&Node) {
36143619
return false;
36153620
}
36163621

3622+
bool MIParser::parseMMRA(MDNode *&Node) {
3623+
assert(Token.is(MIToken::kw_mmra) && "Invalid token for MMRA!");
3624+
lex();
3625+
if (parseMDNode(Node))
3626+
return true;
3627+
if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3628+
Token.is(MIToken::lbrace))
3629+
return false;
3630+
if (Token.isNot(MIToken::comma))
3631+
return error("expected ',' before the next machine operand");
3632+
lex();
3633+
return false;
3634+
}
3635+
36173636
static void initSlots2BasicBlocks(
36183637
const Function &F,
36193638
DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# RUN: split-file %s %t
2+
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -run-pass=none -filetype=null %t/expected-id.mir 2>&1 | FileCheck -check-prefix=ERR0 %s
3+
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -run-pass=none -filetype=null %t/undefined-id.mir 2>&1 | FileCheck -check-prefix=ERR1 %s
4+
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -run-pass=none -filetype=null %t/missing-comma.mir 2>&1 | FileCheck -check-prefix=ERR2 %s
5+
6+
;--- expected-id.mir
7+
# ERR0: expected metadata id after '!'
8+
--- |
9+
define void @test_expected_id() { unreachable }
10+
!0 = !{!"amdgpu-synchronize-as", !"local"}
11+
...
12+
---
13+
name: test_expected_id
14+
body: |
15+
bb.0:
16+
liveins: $vgpr0, $vgpr1
17+
ATOMIC_FENCE 5, 2, mmra ! _
18+
S_ENDPGM 0
19+
...
20+
21+
;--- undefined-id.mir
22+
# ERR1: use of undefined metadata '!1'
23+
--- |
24+
define void @test_undefined_id() { unreachable }
25+
!0 = !{!"amdgpu-synchronize-as", !"local"}
26+
...
27+
---
28+
name: test_undefined_id
29+
body: |
30+
bb.0:
31+
liveins: $vgpr0, $vgpr1
32+
ATOMIC_FENCE 5, 2, mmra !1
33+
S_ENDPGM 0
34+
...
35+
36+
;--- missing-comma.mir
37+
# ERR2: expected ',' before the next machine operand
38+
--- |
39+
define void @test_missing_comma() { unreachable }
40+
!0 = !{!"amdgpu-synchronize-as", !"local"}
41+
...
42+
---
43+
name: test_missing_comma
44+
body: |
45+
bb.0:
46+
liveins: $vgpr0, $vgpr1
47+
ATOMIC_FENCE 5, 2, mmra !0 implicit $exec
48+
S_ENDPGM 0
49+
...
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -run-pass=none -o - %s | FileCheck %s
2+
# This test ensures that the MIR parser parses mmra metadata correctly.
3+
4+
--- |
5+
6+
define void @test_mmra(ptr addrspace(1) %ptr) {
7+
entry:
8+
fence syncscope("workgroup") release, !mmra !0
9+
ret void
10+
}
11+
12+
!0 = !{!"amdgpu-synchronize-as", !"local"}
13+
14+
...
15+
---
16+
name: test_mmra
17+
body: |
18+
bb.0.entry:
19+
liveins: $vgpr0, $vgpr1
20+
21+
; CHECK-LABEL: name: test_mmra
22+
; CHECK: ATOMIC_FENCE 5, 2, mmra !0
23+
ATOMIC_FENCE 5, 2, mmra !0
24+
S_ENDPGM 0
25+
...

0 commit comments

Comments
 (0)