Coverage Report

Created: 2019-02-15 18:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/clang-build/lib/Target/BPF/BPFGenAsmMatcher.inc
Line
Count
Source (jump to first uncovered line)
1
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2
|*                                                                            *|
3
|* Assembly Matcher Source Fragment                                           *|
4
|*                                                                            *|
5
|* Automatically generated file, do not edit!                                 *|
6
|*                                                                            *|
7
\*===----------------------------------------------------------------------===*/
8
9
10
#ifdef GET_ASSEMBLER_HEADER
11
#undef GET_ASSEMBLER_HEADER
12
  // This should be included into the middle of the declaration of
13
  // your subclasses implementation of MCTargetAsmParser.
14
  uint64_t ComputeAvailableFeatures(const FeatureBitset& FB) const;
15
  void convertToMCInst(unsigned Kind, MCInst &Inst, unsigned Opcode,
16
                       const OperandVector &Operands);
17
  void convertToMapAndConstraints(unsigned Kind,
18
                           const OperandVector &Operands) override;
19
  unsigned MatchInstructionImpl(const OperandVector &Operands,
20
                                MCInst &Inst,
21
                                uint64_t &ErrorInfo,
22
                                bool matchingInlineAsm,
23
                                unsigned VariantID = 0);
24
#endif // GET_ASSEMBLER_HEADER_INFO
25
26
27
#ifdef GET_OPERAND_DIAGNOSTIC_TYPES
28
#undef GET_OPERAND_DIAGNOSTIC_TYPES
29
30
#endif // GET_OPERAND_DIAGNOSTIC_TYPES
31
32
33
#ifdef GET_REGISTER_MATCHER
34
#undef GET_REGISTER_MATCHER
35
36
// Flags for subtarget features that participate in instruction matching.
37
enum SubtargetFeatureFlag : uint8_t {
38
  Feature_None = 0
39
};
40
41
277
static unsigned MatchRegisterName(StringRef Name) {
42
277
  switch (Name.size()) {
43
277
  
default: break54
;
44
277
  case 2:  // 20 strings to match.
45
213
    switch (Name[0]) {
46
213
    
default: break40
;
47
213
    case 'r':  // 10 strings to match.
48
105
      switch (Name[1]) {
49
105
      
default: break0
;
50
105
      case '0':  // 1 string to match.
51
16
        return 1;  // "r0"
52
105
      case '1':  // 1 string to match.
53
13
        return 2;  // "r1"
54
105
      case '2':  // 1 string to match.
55
16
        return 3;  // "r2"
56
105
      case '3':  // 1 string to match.
57
11
        return 4;  // "r3"
58
105
      case '4':  // 1 string to match.
59
6
        return 5;  // "r4"
60
105
      case '5':  // 1 string to match.
61
7
        return 6;  // "r5"
62
105
      case '6':  // 1 string to match.
63
7
        return 7;  // "r6"
64
105
      case '7':  // 1 string to match.
65
8
        return 8;  // "r7"
66
105
      case '8':  // 1 string to match.
67
8
        return 9;  // "r8"
68
105
      case '9':  // 1 string to match.
69
13
        return 10;  // "r9"
70
0
      }
71
0
      break;
72
68
    case 'w':  // 10 strings to match.
73
68
      switch (Name[1]) {
74
68
      
default: break0
;
75
68
      case '0':  // 1 string to match.
76
5
        return 13;  // "w0"
77
68
      case '1':  // 1 string to match.
78
8
        return 14;  // "w1"
79
68
      case '2':  // 1 string to match.
80
6
        return 15;  // "w2"
81
68
      case '3':  // 1 string to match.
82
6
        return 16;  // "w3"
83
68
      case '4':  // 1 string to match.
84
6
        return 17;  // "w4"
85
68
      case '5':  // 1 string to match.
86
7
        return 18;  // "w5"
87
68
      case '6':  // 1 string to match.
88
7
        return 19;  // "w6"
89
68
      case '7':  // 1 string to match.
90
8
        return 20;  // "w7"
91
68
      case '8':  // 1 string to match.
92
7
        return 21;  // "w8"
93
68
      case '9':  // 1 string to match.
94
8
        return 22;  // "w9"
95
0
      }
96
0
      break;
97
40
    }
98
40
    break;
99
40
  case 3:  // 4 strings to match.
100
10
    switch (Name[0]) {
101
10
    
default: break0
;
102
10
    case 'r':  // 2 strings to match.
103
6
      if (Name[1] != '1')
104
0
        break;
105
6
      switch (Name[2]) {
106
6
      
default: break0
;
107
6
      case '0':  // 1 string to match.
108
6
        return 11;  // "r10"
109
6
      case '1':  // 1 string to match.
110
0
        return 12;  // "r11"
111
0
      }
112
0
      break;
113
4
    case 'w':  // 2 strings to match.
114
4
      if (Name[1] != '1')
115
0
        break;
116
4
      switch (Name[2]) {
117
4
      
default: break0
;
118
4
      case '0':  // 1 string to match.
119
4
        return 23;  // "w10"
120
4
      case '1':  // 1 string to match.
121
0
        return 24;  // "w11"
122
0
      }
123
0
      break;
124
0
    }
125
0
    break;
126
94
  }
127
94
  return 0;
128
94
}
129
130
#endif // GET_REGISTER_MATCHER
131
132
133
#ifdef GET_SUBTARGET_FEATURE_NAME
134
#undef GET_SUBTARGET_FEATURE_NAME
135
136
// User-level names for subtarget features that participate in
137
// instruction matching.
138
static const char *getSubtargetFeatureName(uint64_t Val) {
139
  return "(unknown)";
140
}
141
142
#endif // GET_SUBTARGET_FEATURE_NAME
143
144
145
#ifdef GET_MATCHER_IMPLEMENTATION
146
#undef GET_MATCHER_IMPLEMENTATION
147
148
enum {
149
  Tie0_0_0,
150
  Tie0_0_3,
151
  Tie0_12_12,
152
};
153
154
static const uint8_t TiedAsmOperandTable[][3] = {
155
  /* Tie0_0_0 */ { 0, 0, 0 },
156
  /* Tie0_0_3 */ { 0, 0, 3 },
157
  /* Tie0_12_12 */ { 0, 12, 12 },
158
};
159
160
namespace {
161
enum OperatorConversionKind {
162
  CVT_Done,
163
  CVT_Reg,
164
  CVT_Tied,
165
  CVT_95_Reg,
166
  CVT_95_addImmOperands,
167
  CVT_imm_95_0,
168
  CVT_NUM_CONVERTERS
169
};
170
171
enum InstructionConversionKind {
172
  Convert__Reg1_0__Reg1_2,
173
  Convert__Reg1_0__Imm1_2,
174
  Convert__Reg1_0__Tie0_0_0__Reg1_3,
175
  Convert__Reg1_0__Tie0_0_0__Imm1_3,
176
  Convert__Reg1_0__Tie0_0_3,
177
  Convert__Reg1_0__Tie0_0_0__Reg1_4,
178
  Convert__Reg1_0__Tie0_0_0__Imm1_4,
179
  Convert__Reg1_0__Tie0_0_0__Reg1_5,
180
  Convert__Reg1_0__Tie0_0_0__Imm1_5,
181
  Convert__Reg1_0__Reg1_8__Imm1_9,
182
  Convert__Reg1_10__Reg1_6__Imm1_7,
183
  Convert__Imm1_1,
184
  Convert_NoOperands,
185
  Convert__Reg1_1__Reg1_3__Imm1_5,
186
  Convert__Reg1_1__Imm1_3__Imm1_5,
187
  Convert__Reg1_1__Reg1_4__Imm1_6,
188
  Convert__Reg1_1__Imm1_4__Imm1_6,
189
  Convert__Reg1_1__Reg1_5__Imm1_7,
190
  Convert__Reg1_1__Imm1_5__Imm1_7,
191
  Convert__Reg1_1__Imm1_2__Imm1_3,
192
  Convert__Reg1_1__Reg1_2__Imm1_3,
193
  Convert__Reg1_12__Reg1_7__Imm1_8__Tie0_12_12,
194
  Convert__imm_95_0__Reg1_9,
195
  Convert__imm_95_0__Imm1_9,
196
  CVT_NUM_SIGNATURES
197
};
198
199
} // end anonymous namespace
200
201
static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][9] = {
202
  // Convert__Reg1_0__Reg1_2
203
  { CVT_95_Reg, 0, CVT_95_Reg, 2, CVT_Done },
204
  // Convert__Reg1_0__Imm1_2
205
  { CVT_95_Reg, 0, CVT_95_addImmOperands, 2, CVT_Done },
206
  // Convert__Reg1_0__Tie0_0_0__Reg1_3
207
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_0, CVT_95_Reg, 3, CVT_Done },
208
  // Convert__Reg1_0__Tie0_0_0__Imm1_3
209
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_0, CVT_95_addImmOperands, 3, CVT_Done },
210
  // Convert__Reg1_0__Tie0_0_3
211
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_3, CVT_Done },
212
  // Convert__Reg1_0__Tie0_0_0__Reg1_4
213
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_0, CVT_95_Reg, 4, CVT_Done },
214
  // Convert__Reg1_0__Tie0_0_0__Imm1_4
215
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_0, CVT_95_addImmOperands, 4, CVT_Done },
216
  // Convert__Reg1_0__Tie0_0_0__Reg1_5
217
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_0, CVT_95_Reg, 5, CVT_Done },
218
  // Convert__Reg1_0__Tie0_0_0__Imm1_5
219
  { CVT_95_Reg, 0, CVT_Tied, Tie0_0_0, CVT_95_addImmOperands, 5, CVT_Done },
220
  // Convert__Reg1_0__Reg1_8__Imm1_9
221
  { CVT_95_Reg, 0, CVT_95_Reg, 8, CVT_95_addImmOperands, 9, CVT_Done },
222
  // Convert__Reg1_10__Reg1_6__Imm1_7
223
  { CVT_95_Reg, 10, CVT_95_Reg, 6, CVT_95_addImmOperands, 7, CVT_Done },
224
  // Convert__Imm1_1
225
  { CVT_95_addImmOperands, 1, CVT_Done },
226
  // Convert_NoOperands
227
  { CVT_Done },
228
  // Convert__Reg1_1__Reg1_3__Imm1_5
229
  { CVT_95_Reg, 1, CVT_95_Reg, 3, CVT_95_addImmOperands, 5, CVT_Done },
230
  // Convert__Reg1_1__Imm1_3__Imm1_5
231
  { CVT_95_Reg, 1, CVT_95_addImmOperands, 3, CVT_95_addImmOperands, 5, CVT_Done },
232
  // Convert__Reg1_1__Reg1_4__Imm1_6
233
  { CVT_95_Reg, 1, CVT_95_Reg, 4, CVT_95_addImmOperands, 6, CVT_Done },
234
  // Convert__Reg1_1__Imm1_4__Imm1_6
235
  { CVT_95_Reg, 1, CVT_95_addImmOperands, 4, CVT_95_addImmOperands, 6, CVT_Done },
236
  // Convert__Reg1_1__Reg1_5__Imm1_7
237
  { CVT_95_Reg, 1, CVT_95_Reg, 5, CVT_95_addImmOperands, 7, CVT_Done },
238
  // Convert__Reg1_1__Imm1_5__Imm1_7
239
  { CVT_95_Reg, 1, CVT_95_addImmOperands, 5, CVT_95_addImmOperands, 7, CVT_Done },
240
  // Convert__Reg1_1__Imm1_2__Imm1_3
241
  { CVT_95_Reg, 1, CVT_95_addImmOperands, 2, CVT_95_addImmOperands, 3, CVT_Done },
242
  // Convert__Reg1_1__Reg1_2__Imm1_3
243
  { CVT_95_Reg, 1, CVT_95_Reg, 2, CVT_95_addImmOperands, 3, CVT_Done },
244
  // Convert__Reg1_12__Reg1_7__Imm1_8__Tie0_12_12
245
  { CVT_95_Reg, 12, CVT_95_Reg, 7, CVT_95_addImmOperands, 8, CVT_Tied, Tie0_12_12, CVT_Done },
246
  // Convert__imm_95_0__Reg1_9
247
  { CVT_imm_95_0, 0, CVT_95_Reg, 9, CVT_Done },
248
  // Convert__imm_95_0__Imm1_9
249
  { CVT_imm_95_0, 0, CVT_95_addImmOperands, 9, CVT_Done },
250
};
251
252
void BPFAsmParser::
253
convertToMCInst(unsigned Kind, MCInst &Inst, unsigned Opcode,
254
120
                const OperandVector &Operands) {
255
120
  assert(Kind < CVT_NUM_SIGNATURES && "Invalid signature!");
256
120
  const uint8_t *Converter = ConversionTable[Kind];
257
120
  unsigned OpIdx;
258
120
  Inst.setOpcode(Opcode);
259
454
  for (const uint8_t *p = Converter; *p; 
p+= 2334
) {
260
334
    OpIdx = *(p + 1);
261
334
    switch (*p) {
262
334
    
default: 0
llvm_unreachable0
("invalid conversion entry!");
263
334
    case CVT_Reg:
264
0
      static_cast<BPFOperand&>(*Operands[OpIdx]).addRegOperands(Inst, 1);
265
0
      break;
266
334
    case CVT_Tied: {
267
47
      assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -
268
47
                          std::begin(TiedAsmOperandTable)) &&
269
47
             "Tied operand not found");
270
47
      unsigned TiedResOpnd = TiedAsmOperandTable[OpIdx][0];
271
47
      if (TiedResOpnd != (uint8_t) -1)
272
47
        Inst.addOperand(Inst.getOperand(TiedResOpnd));
273
47
      break;
274
334
    }
275
334
    case CVT_95_Reg:
276
172
      static_cast<BPFOperand&>(*Operands[OpIdx]).addRegOperands(Inst, 1);
277
172
      break;
278
334
    case CVT_95_addImmOperands:
279
109
      static_cast<BPFOperand&>(*Operands[OpIdx]).addImmOperands(Inst, 1);
280
109
      break;
281
334
    case CVT_imm_95_0:
282
6
      Inst.addOperand(MCOperand::createImm(0));
283
6
      break;
284
334
    }
285
334
  }
286
120
}
287
288
void BPFAsmParser::
289
convertToMapAndConstraints(unsigned Kind,
290
0
                           const OperandVector &Operands) {
291
0
  assert(Kind < CVT_NUM_SIGNATURES && "Invalid signature!");
292
0
  unsigned NumMCOperands = 0;
293
0
  const uint8_t *Converter = ConversionTable[Kind];
294
0
  for (const uint8_t *p = Converter; *p; p+= 2) {
295
0
    switch (*p) {
296
0
    default: llvm_unreachable("invalid conversion entry!");
297
0
    case CVT_Reg:
298
0
      Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);
299
0
      Operands[*(p + 1)]->setConstraint("r");
300
0
      ++NumMCOperands;
301
0
      break;
302
0
    case CVT_Tied:
303
0
      ++NumMCOperands;
304
0
      break;
305
0
    case CVT_95_Reg:
306
0
      Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);
307
0
      Operands[*(p + 1)]->setConstraint("r");
308
0
      NumMCOperands += 1;
309
0
      break;
310
0
    case CVT_95_addImmOperands:
311
0
      Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);
312
0
      Operands[*(p + 1)]->setConstraint("m");
313
0
      NumMCOperands += 1;
314
0
      break;
315
0
    case CVT_imm_95_0:
316
0
      Operands[*(p + 1)]->setMCOperandNum(NumMCOperands);
317
0
      Operands[*(p + 1)]->setConstraint("");
318
0
      ++NumMCOperands;
319
0
      break;
320
0
    }
321
0
  }
322
0
}
323
324
namespace {
325
326
/// MatchClassKind - The kinds of classes which participate in
327
/// instruction matching.
328
enum MatchClassKind {
329
  InvalidMatchClass = 0,
330
  OptionalMatchClass = 1,
331
  MCK__EXCLAIM_, // '!'
332
  MCK__38_, // '&'
333
  MCK__40_, // '('
334
  MCK__41_, // ')'
335
  MCK__STAR_, // '*'
336
  MCK__43_, // '+'
337
  MCK__MINUS_, // '-'
338
  MCK__47_, // '/'
339
  MCK__LT_, // '<'
340
  MCK__61_, // '='
341
  MCK__GT_, // '>'
342
  MCK__91_, // '['
343
  MCK__93_, // ']'
344
  MCK__94_, // '^'
345
  MCK_be16, // 'be16'
346
  MCK_be32, // 'be32'
347
  MCK_be64, // 'be64'
348
  MCK_call, // 'call'
349
  MCK_callx, // 'callx'
350
  MCK_exit, // 'exit'
351
  MCK_goto, // 'goto'
352
  MCK_if, // 'if'
353
  MCK_ld_95_pseudo, // 'ld_pseudo'
354
  MCK_le16, // 'le16'
355
  MCK_le32, // 'le32'
356
  MCK_le64, // 'le64'
357
  MCK_lea, // 'lea'
358
  MCK_ll, // 'll'
359
  MCK_lock, // 'lock'
360
  MCK_nop, // 'nop'
361
  MCK_s, // 's'
362
  MCK_skb, // 'skb'
363
  MCK_u16, // 'u16'
364
  MCK_u32, // 'u32'
365
  MCK_u64, // 'u64'
366
  MCK_u8, // 'u8'
367
  MCK__124_, // '|'
368
  MCK_LAST_TOKEN = MCK__124_,
369
  MCK_R0, // register class 'R0'
370
  MCK_GPR, // register class 'GPR'
371
  MCK_GPR32, // register class 'GPR32'
372
  MCK_LAST_REGISTER = MCK_GPR32,
373
  MCK_Imm, // user defined class 'ImmAsmOperand'
374
  NumMatchClassKinds
375
};
376
377
}
378
379
1.86k
static unsigned getDiagKindFromRegisterClass(MatchClassKind RegisterClass) {
380
1.86k
  return MCTargetAsmParser::Match_InvalidOperand;
381
1.86k
}
382
383
2.31k
static MatchClassKind matchTokenString(StringRef Name) {
384
2.31k
  switch (Name.size()) {
385
2.31k
  
default: break0
;
386
2.31k
  case 1:  // 16 strings to match.
387
2.15k
    switch (Name[0]) {
388
2.15k
    
default: break0
;
389
2.15k
    case '!':  // 1 string to match.
390
22
      return MCK__EXCLAIM_;  // "!"
391
2.15k
    case '&':  // 1 string to match.
392
14
      return MCK__38_;  // "&"
393
2.15k
    case '(':  // 1 string to match.
394
111
      return MCK__40_;  // "("
395
2.15k
    case ')':  // 1 string to match.
396
53
      return MCK__41_;  // ")"
397
2.15k
    case '*':  // 1 string to match.
398
193
      return MCK__STAR_;  // "*"
399
2.15k
    case '+':  // 1 string to match.
400
32
      return MCK__43_;  // "+"
401
2.15k
    case '-':  // 1 string to match.
402
40
      return MCK__MINUS_;  // "-"
403
2.15k
    case '/':  // 1 string to match.
404
46
      return MCK__47_;  // "/"
405
2.15k
    case '<':  // 1 string to match.
406
158
      return MCK__LT_;  // "<"
407
2.15k
    case '=':  // 1 string to match.
408
737
      return MCK__61_;  // "="
409
2.15k
    case '>':  // 1 string to match.
410
218
      return MCK__GT_;  // ">"
411
2.15k
    case '[':  // 1 string to match.
412
9
      return MCK__91_;  // "["
413
2.15k
    case ']':  // 1 string to match.
414
6
      return MCK__93_;  // "]"
415
2.15k
    case '^':  // 1 string to match.
416
72
      return MCK__94_;  // "^"
417
2.15k
    case 's':  // 1 string to match.
418
368
      return MCK_s;  // "s"
419
2.15k
    case '|':  // 1 string to match.
420
80
      return MCK__124_;  // "|"
421
0
    }
422
0
    break;
423
43
  case 2:  // 3 strings to match.
424
43
    switch (Name[0]) {
425
43
    
default: break0
;
426
43
    case 'i':  // 1 string to match.
427
0
      if (Name[1] != 'f')
428
0
        break;
429
0
      return MCK_if;   // "if"
430
4
    case 'l':  // 1 string to match.
431
4
      if (Name[1] != 'l')
432
0
        break;
433
4
      return MCK_ll;   // "ll"
434
39
    case 'u':  // 1 string to match.
435
39
      if (Name[1] != '8')
436
0
        break;
437
39
      return MCK_u8;  // "u8"
438
0
    }
439
0
    break;
440
68
  case 3:  // 6 strings to match.
441
68
    switch (Name[0]) {
442
68
    
default: break0
;
443
68
    case 'l':  // 1 string to match.
444
0
      if (memcmp(Name.data()+1, "ea", 2) != 0)
445
0
        break;
446
0
      return MCK_lea;  // "lea"
447
0
    case 'n':  // 1 string to match.
448
0
      if (memcmp(Name.data()+1, "op", 2) != 0)
449
0
        break;
450
0
      return MCK_nop;  // "nop"
451
15
    case 's':  // 1 string to match.
452
15
      if (memcmp(Name.data()+1, "kb", 2) != 0)
453
0
        break;
454
15
      return MCK_skb;  // "skb"
455
53
    case 'u':  // 3 strings to match.
456
53
      switch (Name[1]) {
457
53
      
default: break0
;
458
53
      case '1':  // 1 string to match.
459
16
        if (Name[2] != '6')
460
0
          break;
461
16
        return MCK_u16;  // "u16"
462
27
      case '3':  // 1 string to match.
463
27
        if (Name[2] != '2')
464
0
          break;
465
27
        return MCK_u32;  // "u32"
466
27
      case '6':  // 1 string to match.
467
10
        if (Name[2] != '4')
468
0
          break;
469
10
        return MCK_u64;  // "u64"
470
0
      }
471
0
      break;
472
0
    }
473
0
    break;
474
49
  case 4:  // 10 strings to match.
475
49
    switch (Name[0]) {
476
49
    
default: break0
;
477
49
    case 'b':  // 3 strings to match.
478
9
      if (Name[1] != 'e')
479
0
        break;
480
9
      switch (Name[2]) {
481
9
      
default: break0
;
482
9
      case '1':  // 1 string to match.
483
2
        if (Name[3] != '6')
484
0
          break;
485
2
        return MCK_be16;   // "be16"
486
3
      case '3':  // 1 string to match.
487
3
        if (Name[3] != '2')
488
0
          break;
489
3
        return MCK_be32;   // "be32"
490
4
      case '6':  // 1 string to match.
491
4
        if (Name[3] != '4')
492
0
          break;
493
4
        return MCK_be64;  // "be64"
494
0
      }
495
0
      break;
496
0
    case 'c':  // 1 string to match.
497
0
      if (memcmp(Name.data()+1, "all", 3) != 0)
498
0
        break;
499
0
      return MCK_call;   // "call"
500
0
    case 'e':  // 1 string to match.
501
0
      if (memcmp(Name.data()+1, "xit", 3) != 0)
502
0
        break;
503
0
      return MCK_exit;   // "exit"
504
40
    case 'g':  // 1 string to match.
505
40
      if (memcmp(Name.data()+1, "oto", 3) != 0)
506
0
        break;
507
40
      return MCK_goto;   // "goto"
508
40
    case 'l':  // 4 strings to match.
509
0
      switch (Name[1]) {
510
0
      default: break;
511
0
      case 'e':  // 3 strings to match.
512
0
        switch (Name[2]) {
513
0
        default: break;
514
0
        case '1':  // 1 string to match.
515
0
          if (Name[3] != '6')
516
0
            break;
517
0
          return MCK_le16;   // "le16"
518
0
        case '3':  // 1 string to match.
519
0
          if (Name[3] != '2')
520
0
            break;
521
0
          return MCK_le32;   // "le32"
522
0
        case '6':  // 1 string to match.
523
0
          if (Name[3] != '4')
524
0
            break;
525
0
          return MCK_le64;  // "le64"
526
0
        }
527
0
        break;
528
0
      case 'o':  // 1 string to match.
529
0
        if (memcmp(Name.data()+2, "ck", 2) != 0)
530
0
          break;
531
0
        return MCK_lock;  // "lock"
532
0
      }
533
0
      break;
534
0
    }
535
0
    break;
536
0
  case 5:  // 1 string to match.
537
0
    if (memcmp(Name.data()+0, "callx", 5) != 0)
538
0
      break;
539
0
    return MCK_callx;  // "callx"
540
0
  case 9:  // 1 string to match.
541
0
    if (memcmp(Name.data()+0, "ld_pseudo", 9) != 0)
542
0
      break;
543
0
    return MCK_ld_95_pseudo;  // "ld_pseudo"
544
0
  }
545
0
  return InvalidMatchClass;
546
0
}
547
548
/// isSubclass - Compute whether \p A is a subclass of \p B.
549
9.07k
static bool isSubclass(MatchClassKind A, MatchClassKind B) {
550
9.07k
  if (A == B)
551
2.40k
    return true;
552
6.67k
553
6.67k
  switch (A) {
554
6.67k
  default:
555
5.92k
    return false;
556
6.67k
557
6.67k
  case MCK_R0:
558
749
    return B == MCK_GPR;
559
6.67k
  }
560
6.67k
}
561
562
6.05k
static unsigned validateOperandClass(MCParsedAsmOperand &GOp, MatchClassKind Kind) {
563
6.05k
  BPFOperand &Operand = (BPFOperand&)GOp;
564
6.05k
  if (Kind == InvalidMatchClass)
565
4
    return MCTargetAsmParser::Match_InvalidOperand;
566
6.05k
567
6.05k
  if (Operand.isToken() && 
Kind <= MCK_LAST_TOKEN2.39k
)
568
2.31k
    return isSubclass(matchTokenString(Operand.getToken()), Kind) ?
569
968
             MCTargetAsmParser::Match_Success :
570
2.31k
             
MCTargetAsmParser::Match_InvalidOperand1.35k
;
571
3.73k
572
3.73k
  switch (Kind) {
573
3.73k
  
default: break3.57k
;
574
3.73k
  // 'Imm' class
575
3.73k
  case MCK_Imm: {
576
160
    DiagnosticPredicate DP(Operand.isImm());
577
160
    if (DP.isMatch())
578
116
      return MCTargetAsmParser::Match_Success;
579
44
    break;
580
44
    }
581
3.61k
  } // end switch (Kind)
582
3.61k
583
3.61k
  if (Operand.isReg()) {
584
3.46k
    MatchClassKind OpKind;
585
3.46k
    switch (Operand.getReg()) {
586
3.46k
    
default: OpKind = InvalidMatchClass; break0
;
587
3.46k
    
case BPF::W0: OpKind = MCK_GPR32; break115
;
588
3.46k
    
case BPF::R0: OpKind = MCK_R0; break770
;
589
3.46k
    
case BPF::W1: OpKind = MCK_GPR32; break122
;
590
3.46k
    
case BPF::R1: OpKind = MCK_GPR; break55
;
591
3.46k
    
case BPF::W2: OpKind = MCK_GPR32; break116
;
592
3.46k
    
case BPF::R2: OpKind = MCK_GPR; break89
;
593
3.46k
    
case BPF::W3: OpKind = MCK_GPR32; break116
;
594
3.46k
    
case BPF::R3: OpKind = MCK_GPR; break70
;
595
3.46k
    
case BPF::W4: OpKind = MCK_GPR32; break146
;
596
3.46k
    
case BPF::R4: OpKind = MCK_GPR; break92
;
597
3.46k
    
case BPF::W5: OpKind = MCK_GPR32; break196
;
598
3.46k
    
case BPF::R5: OpKind = MCK_GPR; break141
;
599
3.46k
    
case BPF::W6: OpKind = MCK_GPR32; break164
;
600
3.46k
    
case BPF::R6: OpKind = MCK_GPR; break144
;
601
3.46k
    
case BPF::W7: OpKind = MCK_GPR32; break207
;
602
3.46k
    
case BPF::R7: OpKind = MCK_GPR; break170
;
603
3.46k
    
case BPF::W8: OpKind = MCK_GPR32; break140
;
604
3.46k
    
case BPF::R8: OpKind = MCK_GPR; break141
;
605
3.46k
    
case BPF::W9: OpKind = MCK_GPR32; break90
;
606
3.46k
    
case BPF::R9: OpKind = MCK_GPR; break164
;
607
3.46k
    
case BPF::W10: OpKind = MCK_GPR32; break107
;
608
3.46k
    
case BPF::R10: OpKind = MCK_GPR; break105
;
609
3.46k
    
case BPF::W11: OpKind = MCK_GPR32; break0
;
610
3.46k
    
case BPF::R11: OpKind = MCK_GPR; break0
;
611
3.46k
    }
612
3.46k
    return isSubclass(OpKind, Kind) ? 
(unsigned)MCTargetAsmParser::Match_Success1.67k
:
613
3.46k
                                      
getDiagKindFromRegisterClass(Kind)1.78k
;
614
3.46k
  }
615
157
616
157
  if (Kind > MCK_LAST_TOKEN && 
Kind <= MCK_LAST_REGISTER129
)
617
85
    return getDiagKindFromRegisterClass(Kind);
618
72
619
72
  return MCTargetAsmParser::Match_InvalidOperand;
620
72
}
621
622
#ifndef NDEBUG
623
const char *getMatchClassName(MatchClassKind Kind) {
624
  switch (Kind) {
625
  case InvalidMatchClass: return "InvalidMatchClass";
626
  case OptionalMatchClass: return "OptionalMatchClass";
627
  case MCK__EXCLAIM_: return "MCK__EXCLAIM_";
628
  case MCK__38_: return "MCK__38_";
629
  case MCK__40_: return "MCK__40_";
630
  case MCK__41_: return "MCK__41_";
631
  case MCK__STAR_: return "MCK__STAR_";
632
  case MCK__43_: return "MCK__43_";
633
  case MCK__MINUS_: return "MCK__MINUS_";
634
  case MCK__47_: return "MCK__47_";
635
  case MCK__LT_: return "MCK__LT_";
636
  case MCK__61_: return "MCK__61_";
637
  case MCK__GT_: return "MCK__GT_";
638
  case MCK__91_: return "MCK__91_";
639
  case MCK__93_: return "MCK__93_";
640
  case MCK__94_: return "MCK__94_";
641
  case MCK_be16: return "MCK_be16";
642
  case MCK_be32: return "MCK_be32";
643
  case MCK_be64: return "MCK_be64";
644
  case MCK_call: return "MCK_call";
645
  case MCK_callx: return "MCK_callx";
646
  case MCK_exit: return "MCK_exit";
647
  case MCK_goto: return "MCK_goto";
648
  case MCK_if: return "MCK_if";
649
  case MCK_ld_95_pseudo: return "MCK_ld_95_pseudo";
650
  case MCK_le16: return "MCK_le16";
651
  case MCK_le32: return "MCK_le32";
652
  case MCK_le64: return "MCK_le64";
653
  case MCK_lea: return "MCK_lea";
654
  case MCK_ll: return "MCK_ll";
655
  case MCK_lock: return "MCK_lock";
656
  case MCK_nop: return "MCK_nop";
657
  case MCK_s: return "MCK_s";
658
  case MCK_skb: return "MCK_skb";
659
  case MCK_u16: return "MCK_u16";
660
  case MCK_u32: return "MCK_u32";
661
  case MCK_u64: return "MCK_u64";
662
  case MCK_u8: return "MCK_u8";
663
  case MCK__124_: return "MCK__124_";
664
  case MCK_R0: return "MCK_R0";
665
  case MCK_GPR: return "MCK_GPR";
666
  case MCK_GPR32: return "MCK_GPR32";
667
  case MCK_Imm: return "MCK_Imm";
668
  case NumMatchClassKinds: return "NumMatchClassKinds";
669
  }
670
  llvm_unreachable("unhandled MatchClassKind!");
671
}
672
673
#endif // NDEBUG
674
uint64_t BPFAsmParser::
675
3
ComputeAvailableFeatures(const FeatureBitset& FB) const {
676
3
  uint64_t Features = 0;
677
3
  return Features;
678
3
}
679
680
static bool checkAsmTiedOperandConstraints(const BPFAsmParser&AsmParser,
681
                               unsigned Kind,
682
                               const OperandVector &Operands,
683
120
                               uint64_t &ErrorInfo) {
684
120
  assert(Kind < CVT_NUM_SIGNATURES && "Invalid signature!");
685
120
  const uint8_t *Converter = ConversionTable[Kind];
686
454
  for (const uint8_t *p = Converter; *p; 
p+= 2334
) {
687
334
    switch (*p) {
688
334
    case CVT_Tied: {
689
47
      unsigned OpIdx = *(p+1);
690
47
      assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -
691
47
                              std::begin(TiedAsmOperandTable)) &&
692
47
             "Tied operand not found");
693
47
      unsigned OpndNum1 = TiedAsmOperandTable[OpIdx][1];
694
47
      unsigned OpndNum2 = TiedAsmOperandTable[OpIdx][2];
695
47
      if (OpndNum1 != OpndNum2) {
696
5
        auto &SrcOp1 = Operands[OpndNum1];
697
5
        auto &SrcOp2 = Operands[OpndNum2];
698
5
        if (SrcOp1->isReg() && SrcOp2->isReg()) {
699
5
          if (!AsmParser.regsEqual(*SrcOp1, *SrcOp2)) {
700
0
            ErrorInfo = OpndNum2;
701
0
            return false;
702
0
          }
703
47
        }
704
5
      }
705
47
      break;
706
47
    }
707
287
    default:
708
287
      break;
709
334
    }
710
334
  }
711
120
  return true;
712
120
}
713
714
static const char *const MnemonicTable =
715
    "\000\001*\004call\005callx\004exit\004goto\002if\tld_pseudo\003lea\004l"
716
    "ock\003nop\002r0";
717
718
namespace {
719
  struct MatchEntry {
720
    uint8_t Mnemonic;
721
    uint16_t Opcode;
722
    uint8_t ConvertFn;
723
    uint8_t RequiredFeatures;
724
    uint8_t Classes[13];
725
675
    StringRef getMnemonic() const {
726
675
      return StringRef(MnemonicTable + Mnemonic + 1,
727
675
                       MnemonicTable[Mnemonic]);
728
675
    }
729
  };
730
731
  // Predicate for searching for an opcode.
732
  struct LessOpcode {
733
364
    bool operator()(const MatchEntry &LHS, StringRef RHS) {
734
364
      return LHS.getMnemonic() < RHS;
735
364
    }
736
311
    bool operator()(StringRef LHS, const MatchEntry &RHS) {
737
311
      return LHS < RHS.getMnemonic();
738
311
    }
739
0
    bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {
740
0
      return LHS.getMnemonic() < RHS.getMnemonic();
741
0
    }
742
  };
743
} // end anonymous namespace.
744
745
static const MatchEntry MatchTable0[] = {
746
  { 0 /*  */, BPF::MOV_rr, Convert__Reg1_0__Reg1_2, 0, { MCK_GPR, MCK__61_, MCK_GPR }, },
747
  { 0 /*  */, BPF::MOV_ri, Convert__Reg1_0__Imm1_2, 0, { MCK_GPR, MCK__61_, MCK_Imm }, },
748
  { 0 /*  */, BPF::MOV_rr_32, Convert__Reg1_0__Reg1_2, 0, { MCK_GPR32, MCK__61_, MCK_GPR32 }, },
749
  { 0 /*  */, BPF::MOV_ri_32, Convert__Reg1_0__Imm1_2, 0, { MCK_GPR32, MCK__61_, MCK_Imm }, },
750
  { 0 /*  */, BPF::AND_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__38_, MCK__61_, MCK_GPR }, },
751
  { 0 /*  */, BPF::AND_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__38_, MCK__61_, MCK_Imm }, },
752
  { 0 /*  */, BPF::MUL_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__STAR_, MCK__61_, MCK_GPR }, },
753
  { 0 /*  */, BPF::MUL_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__STAR_, MCK__61_, MCK_Imm }, },
754
  { 0 /*  */, BPF::ADD_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__43_, MCK__61_, MCK_GPR }, },
755
  { 0 /*  */, BPF::ADD_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__43_, MCK__61_, MCK_Imm }, },
756
  { 0 /*  */, BPF::SUB_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__MINUS_, MCK__61_, MCK_GPR }, },
757
  { 0 /*  */, BPF::SUB_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__MINUS_, MCK__61_, MCK_Imm }, },
758
  { 0 /*  */, BPF::DIV_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__47_, MCK__61_, MCK_GPR }, },
759
  { 0 /*  */, BPF::DIV_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__47_, MCK__61_, MCK_Imm }, },
760
  { 0 /*  */, BPF::NEG_64, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK__MINUS_, MCK_GPR }, },
761
  { 0 /*  */, BPF::BE16, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK_be16, MCK_GPR }, },
762
  { 0 /*  */, BPF::BE32, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK_be32, MCK_GPR }, },
763
  { 0 /*  */, BPF::BE64, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK_be64, MCK_GPR }, },
764
  { 0 /*  */, BPF::LE16, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK_le16, MCK_GPR }, },
765
  { 0 /*  */, BPF::LE32, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK_le32, MCK_GPR }, },
766
  { 0 /*  */, BPF::LE64, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR, MCK__61_, MCK_le64, MCK_GPR }, },
767
  { 0 /*  */, BPF::LD_imm64, Convert__Reg1_0__Imm1_2, 0, { MCK_GPR, MCK__61_, MCK_Imm, MCK_ll }, },
768
  { 0 /*  */, BPF::XOR_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__94_, MCK__61_, MCK_GPR }, },
769
  { 0 /*  */, BPF::XOR_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__94_, MCK__61_, MCK_Imm }, },
770
  { 0 /*  */, BPF::OR_rr, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR, MCK__124_, MCK__61_, MCK_GPR }, },
771
  { 0 /*  */, BPF::OR_ri, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR, MCK__124_, MCK__61_, MCK_Imm }, },
772
  { 0 /*  */, BPF::AND_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__38_, MCK__61_, MCK_GPR32 }, },
773
  { 0 /*  */, BPF::AND_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__38_, MCK__61_, MCK_Imm }, },
774
  { 0 /*  */, BPF::MUL_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__STAR_, MCK__61_, MCK_GPR32 }, },
775
  { 0 /*  */, BPF::MUL_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__STAR_, MCK__61_, MCK_Imm }, },
776
  { 0 /*  */, BPF::ADD_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__43_, MCK__61_, MCK_GPR32 }, },
777
  { 0 /*  */, BPF::ADD_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__43_, MCK__61_, MCK_Imm }, },
778
  { 0 /*  */, BPF::SUB_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__MINUS_, MCK__61_, MCK_GPR32 }, },
779
  { 0 /*  */, BPF::SUB_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__MINUS_, MCK__61_, MCK_Imm }, },
780
  { 0 /*  */, BPF::DIV_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__47_, MCK__61_, MCK_GPR32 }, },
781
  { 0 /*  */, BPF::DIV_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__47_, MCK__61_, MCK_Imm }, },
782
  { 0 /*  */, BPF::NEG_32, Convert__Reg1_0__Tie0_0_3, 0, { MCK_GPR32, MCK__61_, MCK__MINUS_, MCK_GPR32 }, },
783
  { 0 /*  */, BPF::XOR_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__94_, MCK__61_, MCK_GPR32 }, },
784
  { 0 /*  */, BPF::XOR_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__94_, MCK__61_, MCK_Imm }, },
785
  { 0 /*  */, BPF::OR_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_3, 0, { MCK_GPR32, MCK__124_, MCK__61_, MCK_GPR32 }, },
786
  { 0 /*  */, BPF::OR_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_3, 0, { MCK_GPR32, MCK__124_, MCK__61_, MCK_Imm }, },
787
  { 0 /*  */, BPF::SLL_rr, Convert__Reg1_0__Tie0_0_0__Reg1_4, 0, { MCK_GPR, MCK__LT_, MCK__LT_, MCK__61_, MCK_GPR }, },
788
  { 0 /*  */, BPF::SLL_ri, Convert__Reg1_0__Tie0_0_0__Imm1_4, 0, { MCK_GPR, MCK__LT_, MCK__LT_, MCK__61_, MCK_Imm }, },
789
  { 0 /*  */, BPF::SRL_rr, Convert__Reg1_0__Tie0_0_0__Reg1_4, 0, { MCK_GPR, MCK__GT_, MCK__GT_, MCK__61_, MCK_GPR }, },
790
  { 0 /*  */, BPF::SRL_ri, Convert__Reg1_0__Tie0_0_0__Imm1_4, 0, { MCK_GPR, MCK__GT_, MCK__GT_, MCK__61_, MCK_Imm }, },
791
  { 0 /*  */, BPF::SLL_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_4, 0, { MCK_GPR32, MCK__LT_, MCK__LT_, MCK__61_, MCK_GPR32 }, },
792
  { 0 /*  */, BPF::SLL_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_4, 0, { MCK_GPR32, MCK__LT_, MCK__LT_, MCK__61_, MCK_Imm }, },
793
  { 0 /*  */, BPF::SRL_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_4, 0, { MCK_GPR32, MCK__GT_, MCK__GT_, MCK__61_, MCK_GPR32 }, },
794
  { 0 /*  */, BPF::SRL_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_4, 0, { MCK_GPR32, MCK__GT_, MCK__GT_, MCK__61_, MCK_Imm }, },
795
  { 0 /*  */, BPF::SRA_rr, Convert__Reg1_0__Tie0_0_0__Reg1_5, 0, { MCK_GPR, MCK_s, MCK__GT_, MCK__GT_, MCK__61_, MCK_GPR }, },
796
  { 0 /*  */, BPF::SRA_ri, Convert__Reg1_0__Tie0_0_0__Imm1_5, 0, { MCK_GPR, MCK_s, MCK__GT_, MCK__GT_, MCK__61_, MCK_Imm }, },
797
  { 0 /*  */, BPF::SRA_rr_32, Convert__Reg1_0__Tie0_0_0__Reg1_5, 0, { MCK_GPR32, MCK_s, MCK__GT_, MCK__GT_, MCK__61_, MCK_GPR32 }, },
798
  { 0 /*  */, BPF::SRA_ri_32, Convert__Reg1_0__Tie0_0_0__Imm1_5, 0, { MCK_GPR32, MCK_s, MCK__GT_, MCK__GT_, MCK__61_, MCK_Imm }, },
799
  { 0 /*  */, BPF::LDH, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR, MCK__61_, MCK__STAR_, MCK__40_, MCK_u16, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
800
  { 0 /*  */, BPF::LDW, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR, MCK__61_, MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
801
  { 0 /*  */, BPF::LDD, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR, MCK__61_, MCK__STAR_, MCK__40_, MCK_u64, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
802
  { 0 /*  */, BPF::LDB, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR, MCK__61_, MCK__STAR_, MCK__40_, MCK_u8, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
803
  { 0 /*  */, BPF::LDH32, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR32, MCK__61_, MCK__STAR_, MCK__40_, MCK_u16, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
804
  { 0 /*  */, BPF::LDW32, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR32, MCK__61_, MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
805
  { 0 /*  */, BPF::LDB32, Convert__Reg1_0__Reg1_8__Imm1_9, 0, { MCK_GPR32, MCK__61_, MCK__STAR_, MCK__40_, MCK_u8, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_ }, },
806
  { 1 /* * */, BPF::STH, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u16, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR }, },
807
  { 1 /* * */, BPF::STH32, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u16, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR32 }, },
808
  { 1 /* * */, BPF::STW, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR }, },
809
  { 1 /* * */, BPF::STW32, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR32 }, },
810
  { 1 /* * */, BPF::STD, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u64, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR }, },
811
  { 1 /* * */, BPF::STB, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u8, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR }, },
812
  { 1 /* * */, BPF::STB32, Convert__Reg1_10__Reg1_6__Imm1_7, 0, { MCK__STAR_, MCK__40_, MCK_u8, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__61_, MCK_GPR32 }, },
813
  { 3 /* call */, BPF::JAL, Convert__Imm1_1, 0, { MCK_call, MCK_Imm }, },
814
  { 8 /* callx */, BPF::JALX, Convert__Imm1_1, 0, { MCK_callx, MCK_Imm }, },
815
  { 14 /* exit */, BPF::RET, Convert_NoOperands, 0, { MCK_exit }, },
816
  { 19 /* goto */, BPF::JMP, Convert__Imm1_1, 0, { MCK_goto, MCK_Imm }, },
817
  { 24 /* if */, BPF::JULT_rr, Convert__Reg1_1__Reg1_3__Imm1_5, 0, { MCK_if, MCK_GPR, MCK__LT_, MCK_GPR, MCK_goto, MCK_Imm }, },
818
  { 24 /* if */, BPF::JULT_ri, Convert__Reg1_1__Imm1_3__Imm1_5, 0, { MCK_if, MCK_GPR, MCK__LT_, MCK_Imm, MCK_goto, MCK_Imm }, },
819
  { 24 /* if */, BPF::JUGT_rr, Convert__Reg1_1__Reg1_3__Imm1_5, 0, { MCK_if, MCK_GPR, MCK__GT_, MCK_GPR, MCK_goto, MCK_Imm }, },
820
  { 24 /* if */, BPF::JUGT_ri, Convert__Reg1_1__Imm1_3__Imm1_5, 0, { MCK_if, MCK_GPR, MCK__GT_, MCK_Imm, MCK_goto, MCK_Imm }, },
821
  { 24 /* if */, BPF::JULT_rr_32, Convert__Reg1_1__Reg1_3__Imm1_5, 0, { MCK_if, MCK_GPR32, MCK__LT_, MCK_GPR32, MCK_goto, MCK_Imm }, },
822
  { 24 /* if */, BPF::JULT_ri_32, Convert__Reg1_1__Imm1_3__Imm1_5, 0, { MCK_if, MCK_GPR32, MCK__LT_, MCK_Imm, MCK_goto, MCK_Imm }, },
823
  { 24 /* if */, BPF::JUGT_rr_32, Convert__Reg1_1__Reg1_3__Imm1_5, 0, { MCK_if, MCK_GPR32, MCK__GT_, MCK_GPR32, MCK_goto, MCK_Imm }, },
824
  { 24 /* if */, BPF::JUGT_ri_32, Convert__Reg1_1__Imm1_3__Imm1_5, 0, { MCK_if, MCK_GPR32, MCK__GT_, MCK_Imm, MCK_goto, MCK_Imm }, },
825
  { 24 /* if */, BPF::JNE_rr, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__EXCLAIM_, MCK__61_, MCK_GPR, MCK_goto, MCK_Imm }, },
826
  { 24 /* if */, BPF::JNE_ri, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__EXCLAIM_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
827
  { 24 /* if */, BPF::JULE_rr, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__LT_, MCK__61_, MCK_GPR, MCK_goto, MCK_Imm }, },
828
  { 24 /* if */, BPF::JULE_ri, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__LT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
829
  { 24 /* if */, BPF::JEQ_rr, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__61_, MCK__61_, MCK_GPR, MCK_goto, MCK_Imm }, },
830
  { 24 /* if */, BPF::JEQ_ri, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__61_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
831
  { 24 /* if */, BPF::JUGE_rr, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__GT_, MCK__61_, MCK_GPR, MCK_goto, MCK_Imm }, },
832
  { 24 /* if */, BPF::JUGE_ri, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK__GT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
833
  { 24 /* if */, BPF::JSLT_rr, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK_s, MCK__LT_, MCK_GPR, MCK_goto, MCK_Imm }, },
834
  { 24 /* if */, BPF::JSLT_ri, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK_s, MCK__LT_, MCK_Imm, MCK_goto, MCK_Imm }, },
835
  { 24 /* if */, BPF::JSGT_rr, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK_s, MCK__GT_, MCK_GPR, MCK_goto, MCK_Imm }, },
836
  { 24 /* if */, BPF::JSGT_ri, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR, MCK_s, MCK__GT_, MCK_Imm, MCK_goto, MCK_Imm }, },
837
  { 24 /* if */, BPF::JNE_rr_32, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__EXCLAIM_, MCK__61_, MCK_GPR32, MCK_goto, MCK_Imm }, },
838
  { 24 /* if */, BPF::JNE_ri_32, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__EXCLAIM_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
839
  { 24 /* if */, BPF::JULE_rr_32, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__LT_, MCK__61_, MCK_GPR32, MCK_goto, MCK_Imm }, },
840
  { 24 /* if */, BPF::JULE_ri_32, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__LT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
841
  { 24 /* if */, BPF::JEQ_rr_32, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__61_, MCK__61_, MCK_GPR32, MCK_goto, MCK_Imm }, },
842
  { 24 /* if */, BPF::JEQ_ri_32, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__61_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
843
  { 24 /* if */, BPF::JUGE_rr_32, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__GT_, MCK__61_, MCK_GPR32, MCK_goto, MCK_Imm }, },
844
  { 24 /* if */, BPF::JUGE_ri_32, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK__GT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
845
  { 24 /* if */, BPF::JSLT_rr_32, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__LT_, MCK_GPR32, MCK_goto, MCK_Imm }, },
846
  { 24 /* if */, BPF::JSLT_ri_32, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__LT_, MCK_Imm, MCK_goto, MCK_Imm }, },
847
  { 24 /* if */, BPF::JSGT_rr_32, Convert__Reg1_1__Reg1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__GT_, MCK_GPR32, MCK_goto, MCK_Imm }, },
848
  { 24 /* if */, BPF::JSGT_ri_32, Convert__Reg1_1__Imm1_4__Imm1_6, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__GT_, MCK_Imm, MCK_goto, MCK_Imm }, },
849
  { 24 /* if */, BPF::JSLE_rr, Convert__Reg1_1__Reg1_5__Imm1_7, 0, { MCK_if, MCK_GPR, MCK_s, MCK__LT_, MCK__61_, MCK_GPR, MCK_goto, MCK_Imm }, },
850
  { 24 /* if */, BPF::JSLE_ri, Convert__Reg1_1__Imm1_5__Imm1_7, 0, { MCK_if, MCK_GPR, MCK_s, MCK__LT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
851
  { 24 /* if */, BPF::JSGE_rr, Convert__Reg1_1__Reg1_5__Imm1_7, 0, { MCK_if, MCK_GPR, MCK_s, MCK__GT_, MCK__61_, MCK_GPR, MCK_goto, MCK_Imm }, },
852
  { 24 /* if */, BPF::JSGE_ri, Convert__Reg1_1__Imm1_5__Imm1_7, 0, { MCK_if, MCK_GPR, MCK_s, MCK__GT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
853
  { 24 /* if */, BPF::JSLE_rr_32, Convert__Reg1_1__Reg1_5__Imm1_7, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__LT_, MCK__61_, MCK_GPR32, MCK_goto, MCK_Imm }, },
854
  { 24 /* if */, BPF::JSLE_ri_32, Convert__Reg1_1__Imm1_5__Imm1_7, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__LT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
855
  { 24 /* if */, BPF::JSGE_rr_32, Convert__Reg1_1__Reg1_5__Imm1_7, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__GT_, MCK__61_, MCK_GPR32, MCK_goto, MCK_Imm }, },
856
  { 24 /* if */, BPF::JSGE_ri_32, Convert__Reg1_1__Imm1_5__Imm1_7, 0, { MCK_if, MCK_GPR32, MCK_s, MCK__GT_, MCK__61_, MCK_Imm, MCK_goto, MCK_Imm }, },
857
  { 27 /* ld_pseudo */, BPF::LD_pseudo, Convert__Reg1_1__Imm1_2__Imm1_3, 0, { MCK_ld_95_pseudo, MCK_GPR, MCK_Imm, MCK_Imm }, },
858
  { 37 /* lea */, BPF::FI_ri, Convert__Reg1_1__Reg1_2__Imm1_3, 0, { MCK_lea, MCK_GPR, MCK_GPR, MCK_Imm }, },
859
  { 41 /* lock */, BPF::XADD32, Convert__Reg1_12__Reg1_7__Imm1_8__Tie0_12_12, 0, { MCK_lock, MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__43_, MCK__61_, MCK_GPR }, },
860
  { 41 /* lock */, BPF::XADD64, Convert__Reg1_12__Reg1_7__Imm1_8__Tie0_12_12, 0, { MCK_lock, MCK__STAR_, MCK__40_, MCK_u64, MCK__STAR_, MCK__41_, MCK__40_, MCK_GPR, MCK_Imm, MCK__41_, MCK__43_, MCK__61_, MCK_GPR }, },
861
  { 46 /* nop */, BPF::NOP, Convert__Imm1_1, 0, { MCK_nop, MCK_Imm }, },
862
  { 50 /* r0 */, BPF::LD_IND_H, Convert__imm_95_0__Reg1_9, 0, { MCK_R0, MCK__61_, MCK__STAR_, MCK__40_, MCK_u16, MCK__STAR_, MCK__41_, MCK_skb, MCK__91_, MCK_GPR, MCK__93_ }, },
863
  { 50 /* r0 */, BPF::LD_ABS_H, Convert__imm_95_0__Imm1_9, 0, { MCK_R0, MCK__61_, MCK__STAR_, MCK__40_, MCK_u16, MCK__STAR_, MCK__41_, MCK_skb, MCK__91_, MCK_Imm, MCK__93_ }, },
864
  { 50 /* r0 */, BPF::LD_IND_W, Convert__imm_95_0__Reg1_9, 0, { MCK_R0, MCK__61_, MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK_skb, MCK__91_, MCK_GPR, MCK__93_ }, },
865
  { 50 /* r0 */, BPF::LD_ABS_W, Convert__imm_95_0__Imm1_9, 0, { MCK_R0, MCK__61_, MCK__STAR_, MCK__40_, MCK_u32, MCK__STAR_, MCK__41_, MCK_skb, MCK__91_, MCK_Imm, MCK__93_ }, },
866
  { 50 /* r0 */, BPF::LD_IND_B, Convert__imm_95_0__Reg1_9, 0, { MCK_R0, MCK__61_, MCK__STAR_, MCK__40_, MCK_u8, MCK__STAR_, MCK__41_, MCK_skb, MCK__91_, MCK_GPR, MCK__93_ }, },
867
  { 50 /* r0 */, BPF::LD_ABS_B, Convert__imm_95_0__Imm1_9, 0, { MCK_R0, MCK__61_, MCK__STAR_, MCK__40_, MCK_u8, MCK__STAR_, MCK__41_, MCK_skb, MCK__91_, MCK_Imm, MCK__93_ }, },
868
};
869
870
#include "llvm/Support/Debug.h"
871
#include "llvm/Support/Format.h"
872
873
unsigned BPFAsmParser::
874
MatchInstructionImpl(const OperandVector &Operands,
875
                     MCInst &Inst,
876
                     uint64_t &ErrorInfo,
877
120
                     bool matchingInlineAsm, unsigned VariantID) {
878
120
  // Eliminate obvious mismatches.
879
120
  if (Operands.size() > 13) {
880
0
    ErrorInfo = 13;
881
0
    return Match_InvalidOperand;
882
0
  }
883
120
884
120
  // Get the current feature set.
885
120
  uint64_t AvailableFeatures = getAvailableFeatures();
886
120
887
120
  // Get the instruction mnemonic, which is the first token.
888
120
  StringRef Mnemonic;
889
120
  if (Operands[0]->isToken())
890
52
    Mnemonic = ((BPFOperand&)*Operands[0]).getToken();
891
120
892
120
  // Some state to try to produce better error messages.
893
120
  bool HadMatchOtherThanFeatures = false;
894
120
  bool HadMatchOtherThanPredicate = false;
895
120
  unsigned RetCode = Match_InvalidOperand;
896
120
  uint64_t MissingFeatures = ~0ULL;
897
120
  // Set ErrorInfo to the operand that mismatches if it is
898
120
  // wrong for all instances of the instruction.
899
120
  ErrorInfo = ~0ULL;
900
120
  // Find the appropriate table for this asm variant.
901
120
  const MatchEntry *Start, *End;
902
120
  switch (VariantID) {
903
120
  
default: 0
llvm_unreachable0
("invalid variant!");
904
120
  case 0: Start = std::begin(MatchTable0); End = std::end(MatchTable0); break;
905
120
  }
906
120
  // Search the table.
907
120
  auto MnemonicRange = std::make_pair(Start, End);
908
120
  unsigned SIndex = Mnemonic.empty() ? 
068
:
152
;
909
120
  if (!Mnemonic.empty())
910
52
    MnemonicRange = std::equal_range(Start, End, Mnemonic.lower(), LessOpcode());
911
120
912
120
  DEBUG_WITH_TYPE("asm-matcher", dbgs() << "AsmMatcher: found " <<
913
120
  std::distance(MnemonicRange.first, MnemonicRange.second) << 
914
120
  " encodings with mnemonic '" << Mnemonic << "'\n");
915
120
916
120
  // Return a more specific error code if no mnemonics match.
917
120
  if (MnemonicRange.first == MnemonicRange.second)
918
0
    return Match_MnemonicFail;
919
120
920
120
  for (const MatchEntry *it = MnemonicRange.first, *ie = MnemonicRange.second;
921
3.41k
       it != ie; 
++it3.29k
) {
922
3.41k
    bool HasRequiredFeatures =
923
3.41k
      (AvailableFeatures & it->RequiredFeatures) == it->RequiredFeatures;
924
3.41k
    DEBUG_WITH_TYPE("asm-matcher", dbgs() << "Trying to match opcode "
925
3.41k
                                          << MII.getName(it->Opcode) << "\n");
926
3.41k
    bool OperandsValid = true;
927
6.17k
    for (unsigned FormalIdx = SIndex, ActualIdx = SIndex; FormalIdx != 13; 
++FormalIdx2.76k
) {
928
6.17k
      auto Formal = static_cast<MatchClassKind>(it->Classes[FormalIdx]);
929
6.17k
      DEBUG_WITH_TYPE("asm-matcher",
930
6.17k
                      dbgs() << "  Matching formal operand class " << getMatchClassName(Formal)
931
6.17k
                             << " against actual operand at index " << ActualIdx);
932
6.17k
      if (ActualIdx < Operands.size())
933
6.17k
        
DEBUG_WITH_TYPE6.05k
("asm-matcher", dbgs() << " (";
934
6.17k
                        Operands[ActualIdx]->print(dbgs()); dbgs() << "): ");
935
6.17k
      else
936
6.17k
        
DEBUG_WITH_TYPE118
("asm-matcher", dbgs() << ": ");
937
6.17k
      if (ActualIdx >= Operands.size()) {
938
118
        DEBUG_WITH_TYPE("asm-matcher", dbgs() << "actual operand index out of range ");
939
118
        OperandsValid = (Formal == InvalidMatchClass) || 
isSubclass(Formal, OptionalMatchClass)0
;
940
118
        if (!OperandsValid) 
ErrorInfo = ActualIdx0
;
941
118
        break;
942
118
      }
943
6.05k
      MCParsedAsmOperand &Actual = *Operands[ActualIdx];
944
6.05k
      unsigned Diag = validateOperandClass(Actual, Formal);
945
6.05k
      if (Diag == Match_Success) {
946
2.76k
        DEBUG_WITH_TYPE("asm-matcher",
947
2.76k
                        dbgs() << "match success using generic matcher\n");
948
2.76k
        ++ActualIdx;
949
2.76k
        continue;
950
2.76k
      }
951
3.29k
      // If the generic handler indicates an invalid operand
952
3.29k
      // failure, check for a special case.
953
3.29k
      if (Diag != Match_Success) {
954
3.29k
        unsigned TargetDiag = validateTargetOperandClass(Actual, Formal);
955
3.29k
        if (TargetDiag == Match_Success) {
956
0
          DEBUG_WITH_TYPE("asm-matcher",
957
0
                          dbgs() << "match success using target matcher\n");
958
0
          ++ActualIdx;
959
0
          continue;
960
0
        }
961
3.29k
        // If the target matcher returned a specific error code use
962
3.29k
        // that, else use the one from the generic matcher.
963
3.29k
        if (TargetDiag != Match_InvalidOperand && 
HasRequiredFeatures0
)
964
0
          Diag = TargetDiag;
965
3.29k
      }
966
3.29k
      // If current formal operand wasn't matched and it is optional
967
3.29k
      // then try to match next formal operand
968
3.29k
      if (Diag == Match_InvalidOperand && isSubclass(Formal, OptionalMatchClass)) {
969
0
        DEBUG_WITH_TYPE("asm-matcher", dbgs() << "ignoring optional operand\n");
970
0
        continue;
971
0
      }
972
3.29k
      // If this operand is broken for all of the instances of this
973
3.29k
      // mnemonic, keep track of it so we can report loc info.
974
3.29k
      // If we already had a match that only failed due to a
975
3.29k
      // target predicate, that diagnostic is preferred.
976
3.29k
      if (!HadMatchOtherThanPredicate &&
977
3.29k
          (it == MnemonicRange.first || 
ErrorInfo <= ActualIdx3.18k
)) {
978
1.19k
        if (HasRequiredFeatures && (ErrorInfo != ActualIdx || 
Diag != Match_InvalidOperand953
))
979
240
          RetCode = Diag;
980
1.19k
        ErrorInfo = ActualIdx;
981
1.19k
      }
982
3.29k
      // Otherwise, just reject this instance of the mnemonic.
983
3.29k
      OperandsValid = false;
984
3.29k
      break;
985
3.29k
    }
986
3.41k
987
3.41k
    if (!OperandsValid) {
988
3.29k
      DEBUG_WITH_TYPE("asm-matcher", dbgs() << "Opcode result: multiple "
989
3.29k
                                               "operand mismatches, ignoring "
990
3.29k
                                               "this opcode\n");
991
3.29k
      continue;
992
3.29k
    }
993
120
    if (!HasRequiredFeatures) {
994
0
      HadMatchOtherThanFeatures = true;
995
0
      uint64_t NewMissingFeatures = it->RequiredFeatures & ~AvailableFeatures;
996
0
      DEBUG_WITH_TYPE("asm-matcher", dbgs() << "Missing target features: "
997
0
                                            << format_hex(NewMissingFeatures, 18)
998
0
                                            << "\n");
999
0
      if (countPopulation(NewMissingFeatures) <=
1000
0
          countPopulation(MissingFeatures))
1001
0
        MissingFeatures = NewMissingFeatures;
1002
0
      continue;
1003
0
    }
1004
120
1005
120
    Inst.clear();
1006
120
1007
120
    Inst.setOpcode(it->Opcode);
1008
120
    // We have a potential match but have not rendered the operands.
1009
120
    // Check the target predicate to handle any context sensitive
1010
120
    // constraints.
1011
120
    // For example, Ties that are referenced multiple times must be
1012
120
    // checked here to ensure the input is the same for each match
1013
120
    // constraints. If we leave it any later the ties will have been
1014
120
    // canonicalized
1015
120
    unsigned MatchResult;
1016
120
    if ((MatchResult = checkEarlyTargetMatchPredicate(Inst, Operands)) != Match_Success) {
1017
0
      Inst.clear();
1018
0
      DEBUG_WITH_TYPE(
1019
0
          "asm-matcher",
1020
0
          dbgs() << "Early target match predicate failed with diag code "
1021
0
                 << MatchResult << "\n");
1022
0
      RetCode = MatchResult;
1023
0
      HadMatchOtherThanPredicate = true;
1024
0
      continue;
1025
0
    }
1026
120
1027
120
    if (matchingInlineAsm) {
1028
0
      convertToMapAndConstraints(it->ConvertFn, Operands);
1029
0
      if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, Operands, ErrorInfo))
1030
0
        return Match_InvalidTiedOperand;
1031
0
1032
0
      return Match_Success;
1033
0
    }
1034
120
1035
120
    // We have selected a definite instruction, convert the parsed
1036
120
    // operands into the appropriate MCInst.
1037
120
    convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);
1038
120
1039
120
    // We have a potential match. Check the target predicate to
1040
120
    // handle any context sensitive constraints.
1041
120
    if ((MatchResult = checkTargetMatchPredicate(Inst)) != Match_Success) {
1042
0
      DEBUG_WITH_TYPE("asm-matcher",
1043
0
                      dbgs() << "Target match predicate failed with diag code "
1044
0
                             << MatchResult << "\n");
1045
0
      Inst.clear();
1046
0
      RetCode = MatchResult;
1047
0
      HadMatchOtherThanPredicate = true;
1048
0
      continue;
1049
0
    }
1050
120
1051
120
    if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, Operands, ErrorInfo))
1052
0
      return Match_InvalidTiedOperand;
1053
120
1054
120
    DEBUG_WITH_TYPE(
1055
120
        "asm-matcher",
1056
120
        dbgs() << "Opcode result: complete match, selecting this opcode\n");
1057
120
    return Match_Success;
1058
120
  }
1059
120
1060
120
  // Okay, we had no match.  Try to return a useful error code.
1061
120
  
if (0
HadMatchOtherThanPredicate0
||
!HadMatchOtherThanFeatures0
)
1062
0
    return RetCode;
1063
0
1064
0
  // Missing feature matches return which features were missing
1065
0
  ErrorInfo = MissingFeatures;
1066
0
  return Match_MissingFeature;
1067
0
}
1068
1069
#endif // GET_MATCHER_IMPLEMENTATION
1070
1071
1072
#ifdef GET_MNEMONIC_SPELL_CHECKER
1073
#undef GET_MNEMONIC_SPELL_CHECKER
1074
1075
static std::string BPFMnemonicSpellCheck(StringRef S, uint64_t FBS, unsigned VariantID) {
1076
  const unsigned MaxEditDist = 2;
1077
  std::vector<StringRef> Candidates;
1078
  StringRef Prev = "";
1079
1080
  // Find the appropriate table for this asm variant.
1081
  const MatchEntry *Start, *End;
1082
  switch (VariantID) {
1083
  default: llvm_unreachable("invalid variant!");
1084
  case 0: Start = std::begin(MatchTable0); End = std::end(MatchTable0); break;
1085
  }
1086
1087
  for (auto I = Start; I < End; I++) {
1088
    // Ignore unsupported instructions.
1089
    if ((FBS & I->RequiredFeatures) != I->RequiredFeatures)
1090
      continue;
1091
1092
    StringRef T = I->getMnemonic();
1093
    // Avoid recomputing the edit distance for the same string.
1094
    if (T.equals(Prev))
1095
      continue;
1096
1097
    Prev = T;
1098
    unsigned Dist = S.edit_distance(T, false, MaxEditDist);
1099
    if (Dist <= MaxEditDist)
1100
      Candidates.push_back(T);
1101
  }
1102
1103
  if (Candidates.empty())
1104
    return "";
1105
1106
  std::string Res = ", did you mean: ";
1107
  unsigned i = 0;
1108
  for( ; i < Candidates.size() - 1; i++)
1109
    Res += Candidates[i].str() + ", ";
1110
  return Res + Candidates[i].str() + "?";
1111
}
1112
1113
#endif // GET_MNEMONIC_SPELL_CHECKER
1114