@@ -1354,6 +1354,11 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
13541354 SMLoc getFlatOffsetLoc (const OperandVector &Operands) const ;
13551355 SMLoc getSMEMOffsetLoc (const OperandVector &Operands) const ;
13561356
1357+ SMLoc getOperandLoc (std::function<bool (const AMDGPUOperand&)> Test,
1358+ const OperandVector &Operands) const ;
1359+ SMLoc getImmLoc (AMDGPUOperand::ImmTy Type, const OperandVector &Operands) const ;
1360+ SMLoc getRegLoc (unsigned Reg, const OperandVector &Operands) const ;
1361+
13571362 bool validateInstruction (const MCInst &Inst, const SMLoc &IDLoc, const OperandVector &Operands);
13581363 bool validateFlatOffset (const MCInst &Inst, const OperandVector &Operands);
13591364 bool validateSMEMOffset (const MCInst &Inst, const OperandVector &Operands);
@@ -3339,7 +3344,6 @@ bool AMDGPUAsmParser::validateDivScale(const MCInst &Inst) {
33393344 if (Inst.getOperand (AMDGPU::getNamedOperandIdx (Inst.getOpcode (), Name))
33403345 .getImm () &
33413346 SISrcMods::ABS ) {
3342- Error (getLoc (), " ABS not allowed in VOP3B instructions" );
33433347 return false ;
33443348 }
33453349 }
@@ -3598,7 +3602,8 @@ bool AMDGPUAsmParser::validateFlatOffset(const MCInst &Inst,
35983602}
35993603
36003604SMLoc AMDGPUAsmParser::getSMEMOffsetLoc (const OperandVector &Operands) const {
3601- for (unsigned i = 1 , e = Operands.size (); i != e; ++i) {
3605+ // Start with second operand because SMEM Offset cannot be dst or src0.
3606+ for (unsigned i = 2 , e = Operands.size (); i != e; ++i) {
36023607 AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
36033608 if (Op.isSMEMOffset ())
36043609 return Op.getStartLoc ();
@@ -3760,7 +3765,7 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
37603765 const SMLoc &IDLoc,
37613766 const OperandVector &Operands) {
37623767 if (!validateLdsDirect (Inst)) {
3763- Error (IDLoc ,
3768+ Error (getRegLoc ( AMDGPU :: LDS_DIRECT , Operands) ,
37643769 " invalid use of lds_direct" );
37653770 return false ;
37663771 }
@@ -3785,18 +3790,18 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
37853790 return false ;
37863791 }
37873792 if (!validateIntClampSupported (Inst)) {
3788- Error (IDLoc ,
3793+ Error (getImmLoc (AMDGPUOperand::ImmTyClampSI, Operands) ,
37893794 " integer clamping is not supported on this GPU" );
37903795 return false ;
37913796 }
37923797 if (!validateOpSel (Inst)) {
3793- Error (IDLoc ,
3798+ Error (getImmLoc (AMDGPUOperand::ImmTyOpSel, Operands) ,
37943799 " invalid op_sel operand" );
37953800 return false ;
37963801 }
37973802 // For MUBUF/MTBUF d16 is a part of opcode, so there is nothing to validate.
37983803 if (!validateMIMGD16 (Inst)) {
3799- Error (IDLoc ,
3804+ Error (getImmLoc (AMDGPUOperand::ImmTyD16, Operands) ,
38003805 " d16 modifier is not supported on this GPU" );
38013806 return false ;
38023807 }
@@ -3815,12 +3820,12 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
38153820 return false ;
38163821 }
38173822 if (!validateMIMGAtomicDMask (Inst)) {
3818- Error (IDLoc ,
3823+ Error (getImmLoc (AMDGPUOperand::ImmTyDMask, Operands) ,
38193824 " invalid atomic image dmask" );
38203825 return false ;
38213826 }
38223827 if (!validateMIMGGatherDMask (Inst)) {
3823- Error (IDLoc ,
3828+ Error (getImmLoc (AMDGPUOperand::ImmTyDMask, Operands) ,
38243829 " invalid image_gather dmask: only one bit must be set" );
38253830 return false ;
38263831 }
@@ -3838,6 +3843,7 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
38383843 return false ;
38393844 }
38403845 if (!validateDivScale (Inst)) {
3846+ Error (IDLoc, " ABS not allowed in VOP3B instructions" );
38413847 return false ;
38423848 }
38433849 if (!validateCoherencyBits (Inst, Operands, IDLoc)) {
@@ -6079,6 +6085,33 @@ AMDGPUAsmParser::lex() {
60796085 Parser.Lex ();
60806086}
60816087
6088+ SMLoc
6089+ AMDGPUAsmParser::getOperandLoc (std::function<bool (const AMDGPUOperand&)> Test,
6090+ const OperandVector &Operands) const {
6091+ for (unsigned i = Operands.size () - 1 ; i > 0 ; --i) {
6092+ AMDGPUOperand &Op = ((AMDGPUOperand &)*Operands[i]);
6093+ if (Test (Op))
6094+ return Op.getStartLoc ();
6095+ }
6096+ return ((AMDGPUOperand &)*Operands[0 ]).getStartLoc ();
6097+ }
6098+
6099+ SMLoc
6100+ AMDGPUAsmParser::getImmLoc (AMDGPUOperand::ImmTy Type,
6101+ const OperandVector &Operands) const {
6102+ auto Test = [=](const AMDGPUOperand& Op) { return Op.isImmTy (Type); };
6103+ return getOperandLoc (Test, Operands);
6104+ }
6105+
6106+ SMLoc
6107+ AMDGPUAsmParser::getRegLoc (unsigned Reg,
6108+ const OperandVector &Operands) const {
6109+ auto Test = [=](const AMDGPUOperand& Op) {
6110+ return Op.isRegKind () && Op.getReg () == Reg;
6111+ };
6112+ return getOperandLoc (Test, Operands);
6113+ }
6114+
60826115// ===----------------------------------------------------------------------===//
60836116// swizzle
60846117// ===----------------------------------------------------------------------===//
0 commit comments