Skip to content

Commit 34d51b7

Browse files
committed
check op_sel and .l/.h syntax
1 parent 5e26ff3 commit 34d51b7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/MC/MCParser/MCAsmParser.h"
3434
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
3535
#include "llvm/MC/MCParser/MCTargetAsmParser.h"
36+
#include "llvm/MC/MCRegisterInfo.h"
3637
#include "llvm/MC/MCSymbol.h"
3738
#include "llvm/MC/TargetRegistry.h"
3839
#include "llvm/Support/AMDGPUMetadata.h"
@@ -1536,6 +1537,10 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
15361537
return getFeatureBits()[AMDGPU::FeatureFlatInstOffsets];
15371538
}
15381539

1540+
bool hasTrue16Insts() const {
1541+
return getFeatureBits()[AMDGPU::FeatureTrue16BitInsts];
1542+
}
1543+
15391544
bool hasArchitectedFlatScratch() const {
15401545
return getFeatureBits()[AMDGPU::FeatureArchitectedFlatScratch];
15411546
}
@@ -1777,6 +1782,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
17771782
bool validateMIMGDim(const MCInst &Inst, const OperandVector &Operands);
17781783
bool validateMIMGMSAA(const MCInst &Inst);
17791784
bool validateOpSel(const MCInst &Inst);
1785+
bool validateTrue16OpSel(const MCInst &Inst);
17801786
bool validateNeg(const MCInst &Inst, int OpName);
17811787
bool validateDPP(const MCInst &Inst, const OperandVector &Operands);
17821788
bool validateVccOperand(MCRegister Reg) const;
@@ -4651,6 +4657,39 @@ bool AMDGPUAsmParser::validateOpSel(const MCInst &Inst) {
46514657
return true;
46524658
}
46534659

4660+
bool AMDGPUAsmParser::validateTrue16OpSel(const MCInst &Inst) {
4661+
if (!hasTrue16Insts())
4662+
return true;
4663+
const MCRegisterInfo *MRI = getMRI();
4664+
const unsigned Opc = Inst.getOpcode();
4665+
int OpSelIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::op_sel);
4666+
if (OpSelIdx == -1)
4667+
return true;
4668+
unsigned OpSelOpValue = Inst.getOperand(OpSelIdx).getImm();
4669+
// If the value is 0 we could have a default OpSel Operand, so conservatively
4670+
// allow it.
4671+
if (OpSelOpValue == 0)
4672+
return true;
4673+
unsigned OpCount = 0;
4674+
for (int OpName : {AMDGPU::OpName::src0, AMDGPU::OpName::src1,
4675+
AMDGPU::OpName::src2, AMDGPU::OpName::vdst}) {
4676+
int OpIdx = AMDGPU::getNamedOperandIdx(Inst.getOpcode(), OpName);
4677+
if (OpIdx == -1)
4678+
continue;
4679+
const MCOperand &Op = Inst.getOperand(OpIdx);
4680+
if (Op.isReg() &&
4681+
MRI->getRegClass(AMDGPU::VGPR_16RegClassID).contains(Op.getReg())) {
4682+
bool VGPRSuffixIsHi = AMDGPU::isHi16Reg(Op.getReg(), *MRI);
4683+
bool OpSelOpIsHi = ((OpSelOpValue & (1 << OpCount)) != 0);
4684+
if (OpSelOpIsHi != VGPRSuffixIsHi)
4685+
return false;
4686+
}
4687+
++OpCount;
4688+
}
4689+
4690+
return true;
4691+
}
4692+
46544693
bool AMDGPUAsmParser::validateNeg(const MCInst &Inst, int OpName) {
46554694
assert(OpName == AMDGPU::OpName::neg_lo || OpName == AMDGPU::OpName::neg_hi);
46564695

@@ -5132,6 +5171,11 @@ bool AMDGPUAsmParser::validateInstruction(const MCInst &Inst,
51325171
Error(getRegLoc(LDS_DIRECT, Operands), *ErrMsg);
51335172
return false;
51345173
}
5174+
if (!validateTrue16OpSel(Inst)) {
5175+
Error(getImmLoc(AMDGPUOperand::ImmTyOpSel, Operands),
5176+
"op_sel operand conflicts with 16-bit operand suffix");
5177+
return false;
5178+
}
51355179
if (!validateSOPLiteral(Inst)) {
51365180
Error(getLitLoc(Operands),
51375181
"only one unique literal operand is allowed");

0 commit comments

Comments
 (0)