llvm.org GIT mirror llvm / 365773b
[AMDGPU, AsmParser] Enable the mnemonic spell corrector. Patch by Dmitry Venikov git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321202 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 2 years ago
3 changed file(s) with 70 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
535535 return EndLoc;
536536 }
537537
538 SMRange getLocRange() const {
539 return SMRange(StartLoc, EndLoc);
540 }
541
538542 Modifiers getModifiers() const {
539543 assert(isRegKind() || isImmTy(ImmTyNone));
540544 return isRegKind() ? Reg.Mods : Imm.Mods;
22432247 return true;
22442248 }
22452249
2250 static std::string AMDGPUMnemonicSpellCheck(StringRef S, uint64_t FBS,
2251 unsigned VariantID = 0);
2252
22462253 bool AMDGPUAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
22472254 OperandVector &Operands,
22482255 MCStreamer &Out,
22852292 case Match_MissingFeature:
22862293 return Error(IDLoc, "instruction not supported on this GPU");
22872294
2288 case Match_MnemonicFail:
2289 return Error(IDLoc, "unrecognized instruction mnemonic");
2295 case Match_MnemonicFail: {
2296 uint64_t FBS = ComputeAvailableFeatures(getSTI().getFeatureBits());
2297 std::string Suggestion = AMDGPUMnemonicSpellCheck(
2298 ((AMDGPUOperand &)*Operands[0]).getToken(), FBS);
2299 return Error(IDLoc, "invalid instruction" + Suggestion,
2300 ((AMDGPUOperand &)*Operands[0]).getLocRange());
2301 }
22902302
22912303 case Match_InvalidOperand: {
22922304 SMLoc ErrorLoc = IDLoc;
47854797
47864798 #define GET_REGISTER_MATCHER
47874799 #define GET_MATCHER_IMPLEMENTATION
4800 #define GET_MNEMONIC_SPELL_CHECKER
47884801 #include "AMDGPUGenAsmMatcher.inc"
47894802
47904803 // This fuction should be defined after auto-generated include so that we have
0 # RUN: not llvm-mc -triple amdgcn < %s 2>&1 | FileCheck %s
1
2 # This tests the mnemonic spell checker.
3
4 # First check what happens when an instruction is omitted:
5
6 v2, v4, v6
7
8 # CHECK: unknown token in expression
9 # CHECK-NEXT: v2, v4, v6
10 # CHECK-NEXT: ^
11
12 # CHECK: error: not a valid operand.
13 # CHECK-NEXT: v2, v4, v6
14 # CHECK-NEXT: ^
15
16 # We don't want to see a suggestion here; the edit distance is too large to
17 # give sensible suggestions:
18
19 aaaaaaaaaaaaaaa v1, v2, v3
20
21 # CHECK: error: invalid instruction
22 # CHECK-NEXT: aaaaaaaaaaaaaaa v1, v2, v3
23 # CHECK-NEXT: ^
24
25 # Check that we get one suggestion: 'dsc_write_src2_b64' is 1 edit away, i.e. an deletion.
26
27 dsc_write_src2_b64 v1, v2, v3
28
29 # CHECK: error: invalid instruction, did you mean: ds_write_src2_b64?
30 # CHECK-NEXT: dsc_write_src2_b64 v1, v2, v3
31 # CHECK-NEXT: ^
32
33 # Check edit distance 1 and 2, just insertions:
34
35 s_mov_b v1, v2
36
37 # CHECK: error: invalid instruction, did you mean: s_mov_b32, s_mov_b64?
38 # CHECK-NEXT: s_mov_b v1, v2
39 # CHECK-NEXT: ^
40
41 # Check an instruction that is 2 edits away, and also has a lot of candidates:
42
43 s_load_dwordx v1, v2, v3
44
45 # CHECK: error: invalid instruction, did you mean: s_load_dword, s_load_dwordx16, s_load_dwordx2, s_load_dwordx4, s_load_dwordx8?
46 # CHECK-NEXT: s_load_dwordx v1, v2, v3
47 # CHECK-NEXT: ^
None // RUN: not llvm-mc -arch=amdgcn -mcpu=gfx900 -show-encoding %s 2>&1 | FileCheck -check-prefix=GCN %s
1 // RUN: not llvm-mc -arch=amdgcn -mcpu=tonga -show-encoding %s 2>&1 | FileCheck -check-prefix=GCN %s
2 // RUN: not llvm-mc -arch=amdgcn -mcpu=hawaii -show-encoding %s 2>&1 | FileCheck -check-prefix=GCN %s
0 // RUN: not llvm-mc -arch=amdgcn -mcpu=gfx900 -show-encoding %s 2>&1 | FileCheck -check-prefixes=GCN,GFX9 %s
1 // RUN: not llvm-mc -arch=amdgcn -mcpu=tonga -show-encoding %s 2>&1 | FileCheck -check-prefixes=GCN,VI %s
2 // RUN: not llvm-mc -arch=amdgcn -mcpu=hawaii -show-encoding %s 2>&1 | FileCheck -check-prefixes=GCN,CI %s
33
44 v_swap_b32 v1, 1
55 // GCN: :16: error: invalid operand for instruction
99
1010 // FIXME: Better error for it requiring VOP1 encoding
1111 v_swap_b32_e64 v1, v2
12 // GCN: :1: error: unrecognized instruction mnemonic
12 // GFX9: :1: error: invalid instruction, did you mean: v_swap_b32?
13 // CI: :1: error: invalid instruction
14 // VI: :1: error: invalid instruction
1315
1416 v_swap_b32 v1, v2, v1
1517 // GCN: :20: error: invalid operand for instruction
2123 // GCN: :20: error: invalid operand for instruction
2224
2325 v_swap_codegen_pseudo_b32 v1, v2
24 // GCN: :1: error: unrecognized instruction mnemonic
26 // GCN: :1: error: invalid instruction