@@ -1618,6 +1618,14 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
1618
1618
ParseStatus parseTH (OperandVector &Operands, int64_t &TH);
1619
1619
ParseStatus parseStringWithPrefix (StringRef Prefix, StringRef &Value,
1620
1620
SMLoc &StringLoc);
1621
+ ParseStatus parseStringOrIntWithPrefix (OperandVector &Operands,
1622
+ StringRef Name,
1623
+ ArrayRef<const char *> Ids,
1624
+ int64_t &IntVal);
1625
+ ParseStatus parseStringOrIntWithPrefix (OperandVector &Operands,
1626
+ StringRef Name,
1627
+ ArrayRef<const char *> Ids,
1628
+ AMDGPUOperand::ImmTy Type);
1621
1629
1622
1630
bool isModifier ();
1623
1631
bool isOperandModifier (const AsmToken &Token, const AsmToken &NextToken) const ;
@@ -6633,27 +6641,17 @@ ParseStatus AMDGPUAsmParser::parseCPol(OperandVector &Operands) {
6633
6641
6634
6642
ParseStatus AMDGPUAsmParser::parseScope (OperandVector &Operands,
6635
6643
int64_t &Scope) {
6636
- Scope = AMDGPU::CPol::SCOPE_CU; // default;
6644
+ static const unsigned Scopes[] = {CPol::SCOPE_CU, CPol::SCOPE_SE,
6645
+ CPol::SCOPE_DEV, CPol::SCOPE_SYS};
6637
6646
6638
- StringRef Value;
6639
- SMLoc StringLoc;
6640
- ParseStatus Res;
6641
-
6642
- Res = parseStringWithPrefix (" scope" , Value, StringLoc);
6643
- if (!Res.isSuccess ())
6644
- return Res;
6645
-
6646
- Scope = StringSwitch<int64_t >(Value)
6647
- .Case (" SCOPE_CU" , AMDGPU::CPol::SCOPE_CU)
6648
- .Case (" SCOPE_SE" , AMDGPU::CPol::SCOPE_SE)
6649
- .Case (" SCOPE_DEV" , AMDGPU::CPol::SCOPE_DEV)
6650
- .Case (" SCOPE_SYS" , AMDGPU::CPol::SCOPE_SYS)
6651
- .Default (0xffffffff );
6647
+ ParseStatus Res = parseStringOrIntWithPrefix (
6648
+ Operands, " scope" , {" SCOPE_CU" , " SCOPE_SE" , " SCOPE_DEV" , " SCOPE_SYS" },
6649
+ Scope);
6652
6650
6653
- if (Scope == 0xffffffff )
6654
- return Error (StringLoc, " invalid scope value " ) ;
6651
+ if (Res. isSuccess () )
6652
+ Scope = Scopes[Scope] ;
6655
6653
6656
- return ParseStatus::Success ;
6654
+ return Res ;
6657
6655
}
6658
6656
6659
6657
ParseStatus AMDGPUAsmParser::parseTH (OperandVector &Operands, int64_t &TH) {
@@ -6742,6 +6740,44 @@ ParseStatus AMDGPUAsmParser::parseStringWithPrefix(StringRef Prefix,
6742
6740
: ParseStatus::Failure;
6743
6741
}
6744
6742
6743
+ ParseStatus AMDGPUAsmParser::parseStringOrIntWithPrefix (
6744
+ OperandVector &Operands, StringRef Name, ArrayRef<const char *> Ids,
6745
+ int64_t &IntVal) {
6746
+ if (!trySkipId (Name, AsmToken::Colon))
6747
+ return ParseStatus::NoMatch;
6748
+
6749
+ SMLoc StringLoc = getLoc ();
6750
+
6751
+ StringRef Value;
6752
+ if (isToken (AsmToken::Identifier)) {
6753
+ Value = getTokenStr ();
6754
+ lex ();
6755
+
6756
+ for (IntVal = 0 ; IntVal < (int64_t )Ids.size (); ++IntVal)
6757
+ if (Value == Ids[IntVal])
6758
+ break ;
6759
+ } else if (!parseExpr (IntVal))
6760
+ return ParseStatus::Failure;
6761
+
6762
+ if (IntVal < 0 || IntVal >= (int64_t )Ids.size ())
6763
+ return Error (StringLoc, " invalid " + Twine (Name) + " value" );
6764
+
6765
+ return ParseStatus::Success;
6766
+ }
6767
+
6768
+ ParseStatus AMDGPUAsmParser::parseStringOrIntWithPrefix (
6769
+ OperandVector &Operands, StringRef Name, ArrayRef<const char *> Ids,
6770
+ AMDGPUOperand::ImmTy Type) {
6771
+ SMLoc S = getLoc ();
6772
+ int64_t IntVal;
6773
+
6774
+ ParseStatus Res = parseStringOrIntWithPrefix (Operands, Name, Ids, IntVal);
6775
+ if (Res.isSuccess ())
6776
+ Operands.push_back (AMDGPUOperand::CreateImm (this , IntVal, S, Type));
6777
+
6778
+ return Res;
6779
+ }
6780
+
6745
6781
// ===----------------------------------------------------------------------===//
6746
6782
// MTBUF format
6747
6783
// ===----------------------------------------------------------------------===//
@@ -9396,57 +9432,16 @@ void AMDGPUAsmParser::cvtDPP(MCInst &Inst, const OperandVector &Operands, bool I
9396
9432
ParseStatus AMDGPUAsmParser::parseSDWASel (OperandVector &Operands,
9397
9433
StringRef Prefix,
9398
9434
AMDGPUOperand::ImmTy Type) {
9399
- using namespace llvm ::AMDGPU::SDWA;
9400
-
9401
- SMLoc S = getLoc ();
9402
- StringRef Value;
9403
-
9404
- SMLoc StringLoc;
9405
- ParseStatus Res = parseStringWithPrefix (Prefix, Value, StringLoc);
9406
- if (!Res.isSuccess ())
9407
- return Res;
9408
-
9409
- int64_t Int;
9410
- Int = StringSwitch<int64_t >(Value)
9411
- .Case (" BYTE_0" , SdwaSel::BYTE_0)
9412
- .Case (" BYTE_1" , SdwaSel::BYTE_1)
9413
- .Case (" BYTE_2" , SdwaSel::BYTE_2)
9414
- .Case (" BYTE_3" , SdwaSel::BYTE_3)
9415
- .Case (" WORD_0" , SdwaSel::WORD_0)
9416
- .Case (" WORD_1" , SdwaSel::WORD_1)
9417
- .Case (" DWORD" , SdwaSel::DWORD)
9418
- .Default (0xffffffff );
9419
-
9420
- if (Int == 0xffffffff )
9421
- return Error (StringLoc, " invalid " + Twine (Prefix) + " value" );
9422
-
9423
- Operands.push_back (AMDGPUOperand::CreateImm (this , Int, S, Type));
9424
- return ParseStatus::Success;
9435
+ return parseStringOrIntWithPrefix (
9436
+ Operands, Prefix,
9437
+ {" BYTE_0" , " BYTE_1" , " BYTE_2" , " BYTE_3" , " WORD_0" , " WORD_1" , " DWORD" },
9438
+ Type);
9425
9439
}
9426
9440
9427
9441
ParseStatus AMDGPUAsmParser::parseSDWADstUnused (OperandVector &Operands) {
9428
- using namespace llvm ::AMDGPU::SDWA;
9429
-
9430
- SMLoc S = getLoc ();
9431
- StringRef Value;
9432
-
9433
- SMLoc StringLoc;
9434
- ParseStatus Res = parseStringWithPrefix (" dst_unused" , Value, StringLoc);
9435
- if (!Res.isSuccess ())
9436
- return Res;
9437
-
9438
- int64_t Int;
9439
- Int = StringSwitch<int64_t >(Value)
9440
- .Case (" UNUSED_PAD" , DstUnused::UNUSED_PAD)
9441
- .Case (" UNUSED_SEXT" , DstUnused::UNUSED_SEXT)
9442
- .Case (" UNUSED_PRESERVE" , DstUnused::UNUSED_PRESERVE)
9443
- .Default (0xffffffff );
9444
-
9445
- if (Int == 0xffffffff )
9446
- return Error (StringLoc, " invalid dst_unused value" );
9447
-
9448
- Operands.push_back (AMDGPUOperand::CreateImm (this , Int, S, AMDGPUOperand::ImmTySDWADstUnused));
9449
- return ParseStatus::Success;
9442
+ return parseStringOrIntWithPrefix (
9443
+ Operands, " dst_unused" , {" UNUSED_PAD" , " UNUSED_SEXT" , " UNUSED_PRESERVE" },
9444
+ AMDGPUOperand::ImmTySDWADstUnused);
9450
9445
}
9451
9446
9452
9447
void AMDGPUAsmParser::cvtSdwaVOP1 (MCInst &Inst, const OperandVector &Operands) {
0 commit comments