@@ -66,16 +66,14 @@ struct ParserOptionsSet {
66
66
};
67
67
68
68
class RISCVAsmParser : public MCTargetAsmParser {
69
- // This tracks the parsing of the 4 operands that make up the vtype portion
70
- // of vset(i)vli instructions which are separated by commas. The state names
71
- // represent the next expected operand with Done meaning no other operands are
72
- // expected.
73
- enum VTypeState {
74
- VTypeState_SEW,
75
- VTypeState_LMUL,
76
- VTypeState_TailPolicy,
77
- VTypeState_MaskPolicy,
78
- VTypeState_Done,
69
+ // This tracks the parsing of the 4 optional operands that make up the vtype
70
+ // portion of vset(i)vli instructions which are separated by commas.
71
+ enum class VTypeState {
72
+ SeenNothingYet,
73
+ SeenSew,
74
+ SeenLmul,
75
+ SeenTailPolicy,
76
+ SeenMaskPolicy,
79
77
};
80
78
81
79
SmallVector<FeatureBitset, 4 > FeatureBitStack;
@@ -2229,25 +2227,30 @@ bool RISCVAsmParser::parseVTypeToken(const AsmToken &Tok, VTypeState &State,
2229
2227
return true ;
2230
2228
2231
2229
StringRef Identifier = Tok.getIdentifier ();
2232
-
2233
- switch (State) {
2234
- case VTypeState_SEW:
2235
- if (!Identifier.consume_front (" e" ))
2236
- break ;
2230
+ if (State < VTypeState::SeenSew && Identifier.consume_front (" e" )) {
2237
2231
if (Identifier.getAsInteger (10 , Sew))
2238
- break ;
2232
+ return true ;
2239
2233
if (!RISCVVType::isValidSEW (Sew))
2240
- break ;
2241
- State = VTypeState_LMUL;
2234
+ return true ;
2235
+
2236
+ State = VTypeState::SeenSew;
2242
2237
return false ;
2243
- case VTypeState_LMUL: {
2244
- if (!Identifier.consume_front (" m" ))
2245
- break ;
2238
+ }
2239
+
2240
+ if (State < VTypeState::SeenLmul && Identifier.consume_front (" m" )) {
2241
+ // Might arrive here if lmul and tail policy unspecified, if so we're
2242
+ // parsing a MaskPolicy not an LMUL.
2243
+ if (Identifier == " a" || Identifier == " u" ) {
2244
+ MaskAgnostic = (Identifier == " a" );
2245
+ State = VTypeState::SeenMaskPolicy;
2246
+ return false ;
2247
+ }
2248
+
2246
2249
Fractional = Identifier.consume_front (" f" );
2247
2250
if (Identifier.getAsInteger (10 , Lmul))
2248
- break ;
2251
+ return true ;
2249
2252
if (!RISCVVType::isValidLMUL (Lmul, Fractional))
2250
- break ;
2253
+ return true ;
2251
2254
2252
2255
if (Fractional) {
2253
2256
unsigned ELEN = STI->hasFeature (RISCV::FeatureStdExtZve64x) ? 64 : 32 ;
@@ -2258,30 +2261,32 @@ bool RISCVAsmParser::parseVTypeToken(const AsmToken &Tok, VTypeState &State,
2258
2261
Twine (MinLMUL) + " is reserved" );
2259
2262
}
2260
2263
2261
- State = VTypeState_TailPolicy ;
2264
+ State = VTypeState::SeenLmul ;
2262
2265
return false ;
2263
2266
}
2264
- case VTypeState_TailPolicy:
2267
+
2268
+ if (State < VTypeState::SeenTailPolicy && Identifier.starts_with (" t" )) {
2265
2269
if (Identifier == " ta" )
2266
2270
TailAgnostic = true ;
2267
2271
else if (Identifier == " tu" )
2268
2272
TailAgnostic = false ;
2269
2273
else
2270
- break ;
2271
- State = VTypeState_MaskPolicy;
2274
+ return true ;
2275
+
2276
+ State = VTypeState::SeenTailPolicy;
2272
2277
return false ;
2273
- case VTypeState_MaskPolicy:
2278
+ }
2279
+
2280
+ if (State < VTypeState::SeenMaskPolicy && Identifier.starts_with (" m" )) {
2274
2281
if (Identifier == " ma" )
2275
2282
MaskAgnostic = true ;
2276
2283
else if (Identifier == " mu" )
2277
2284
MaskAgnostic = false ;
2278
2285
else
2279
- break ;
2280
- State = VTypeState_Done;
2286
+ return true ;
2287
+
2288
+ State = VTypeState::SeenMaskPolicy;
2281
2289
return false ;
2282
- case VTypeState_Done:
2283
- // Extra token?
2284
- break ;
2285
2290
}
2286
2291
2287
2292
return true ;
@@ -2290,49 +2295,45 @@ bool RISCVAsmParser::parseVTypeToken(const AsmToken &Tok, VTypeState &State,
2290
2295
ParseStatus RISCVAsmParser::parseVTypeI (OperandVector &Operands) {
2291
2296
SMLoc S = getLoc ();
2292
2297
2293
- unsigned Sew = 0 ;
2294
- unsigned Lmul = 0 ;
2298
+ // Default values
2299
+ unsigned Sew = 8 ;
2300
+ unsigned Lmul = 1 ;
2295
2301
bool Fractional = false ;
2296
2302
bool TailAgnostic = false ;
2297
2303
bool MaskAgnostic = false ;
2298
2304
2299
- VTypeState State = VTypeState_SEW;
2300
- SMLoc SEWLoc = S;
2301
-
2302
- if (parseVTypeToken (getTok (), State, Sew, Lmul, Fractional, TailAgnostic,
2303
- MaskAgnostic))
2304
- return ParseStatus::NoMatch;
2305
-
2306
- getLexer ().Lex ();
2307
-
2308
- while (parseOptionalToken (AsmToken::Comma)) {
2305
+ VTypeState State = VTypeState::SeenNothingYet;
2306
+ do {
2309
2307
if (parseVTypeToken (getTok (), State, Sew, Lmul, Fractional, TailAgnostic,
2310
- MaskAgnostic))
2308
+ MaskAgnostic)) {
2309
+ // The first time, errors return NoMatch rather than Failure
2310
+ if (State == VTypeState::SeenNothingYet)
2311
+ return ParseStatus::NoMatch;
2311
2312
break ;
2313
+ }
2312
2314
2313
2315
getLexer ().Lex ();
2314
- }
2316
+ } while ( parseOptionalToken (AsmToken::Comma));
2315
2317
2316
- if (getLexer ().is (AsmToken::EndOfStatement) && State == VTypeState_Done) {
2317
- RISCVVType::VLMUL VLMUL = RISCVVType::encodeLMUL (Lmul, Fractional);
2318
- if (Fractional) {
2319
- unsigned ELEN = STI->hasFeature (RISCV::FeatureStdExtZve64x) ? 64 : 32 ;
2320
- unsigned MaxSEW = ELEN / Lmul;
2321
- // If MaxSEW < 8, we should have printed warning about reserved LMUL.
2322
- if (MaxSEW >= 8 && Sew > MaxSEW)
2323
- Warning (SEWLoc,
2324
- " use of vtype encodings with SEW > " + Twine (MaxSEW) +
2325
- " and LMUL == mf" + Twine (Lmul) +
2326
- " may not be compatible with all RVV implementations" );
2327
- }
2318
+ if (!getLexer ().is (AsmToken::EndOfStatement) ||
2319
+ State == VTypeState::SeenNothingYet)
2320
+ return generateVTypeError (S);
2328
2321
2329
- unsigned VTypeI =
2330
- RISCVVType::encodeVTYPE (VLMUL, Sew, TailAgnostic, MaskAgnostic);
2331
- Operands.push_back (RISCVOperand::createVType (VTypeI, S));
2332
- return ParseStatus::Success;
2322
+ RISCVVType::VLMUL VLMUL = RISCVVType::encodeLMUL (Lmul, Fractional);
2323
+ if (Fractional) {
2324
+ unsigned ELEN = STI->hasFeature (RISCV::FeatureStdExtZve64x) ? 64 : 32 ;
2325
+ unsigned MaxSEW = ELEN / Lmul;
2326
+ // If MaxSEW < 8, we should have printed warning about reserved LMUL.
2327
+ if (MaxSEW >= 8 && Sew > MaxSEW)
2328
+ Warning (S, " use of vtype encodings with SEW > " + Twine (MaxSEW) +
2329
+ " and LMUL == mf" + Twine (Lmul) +
2330
+ " may not be compatible with all RVV implementations" );
2333
2331
}
2334
2332
2335
- return generateVTypeError (S);
2333
+ unsigned VTypeI =
2334
+ RISCVVType::encodeVTYPE (VLMUL, Sew, TailAgnostic, MaskAgnostic);
2335
+ Operands.push_back (RISCVOperand::createVType (VTypeI, S));
2336
+ return ParseStatus::Success;
2336
2337
}
2337
2338
2338
2339
bool RISCVAsmParser::generateVTypeError (SMLoc ErrorLoc) {
0 commit comments