Skip to content

Commit 255e3a3

Browse files
committed
[Xtensa] Support for asm underscore prefix
1 parent 74a35b5 commit 255e3a3

File tree

12 files changed

+363
-5
lines changed

12 files changed

+363
-5
lines changed

llvm/lib/Target/Xtensa/AsmParser/XtensaAsmParser.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ struct XtensaOperand : public MCParsedAsmOperand {
309309
bool isImm8n_7() const { return isImm(-8, 7); }
310310

311311
bool isShimm1_31() const { return isImm(1, 31); }
312+
313+
bool isShimm0_31() const { return isImm(0, 31); }
312314

313315
bool isImm16_31() const { return isImm(16, 31); }
314316

@@ -646,6 +648,19 @@ bool XtensaAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
646648
Inst = TmpInst;
647649
}
648650
} break;
651+
case Xtensa::SLLI: {
652+
uint32_t ImmOp32 = static_cast<uint32_t>(Inst.getOperand(2).getImm());
653+
int64_t Imm = ImmOp32;
654+
if (Imm == 0) {
655+
MCInst TmpInst;
656+
TmpInst.setLoc(IDLoc);
657+
TmpInst.setOpcode(Xtensa::OR);
658+
TmpInst.addOperand(Inst.getOperand(0));
659+
TmpInst.addOperand(Inst.getOperand(1));
660+
TmpInst.addOperand(Inst.getOperand(1));
661+
Inst = TmpInst;
662+
}
663+
} break;
649664
default:
650665
break;
651666
}
@@ -720,6 +735,9 @@ bool XtensaAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
720735
case Match_InvalidShimm1_31:
721736
return Error(RefineErrorLoc(IDLoc, Operands, ErrorInfo),
722737
"expected immediate in range [1, 31]");
738+
case Match_InvalidShimm0_31:
739+
return Error(RefineErrorLoc(IDLoc, Operands, ErrorInfo),
740+
"expected immediate in range [0, 31]");
723741
case Match_InvalidUimm4:
724742
return Error(RefineErrorLoc(IDLoc, Operands, ErrorInfo),
725743
"expected immediate in range [0, 15]");

llvm/lib/Target/Xtensa/Disassembler/XtensaDisassembler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,14 @@ static DecodeStatus decodeShimm1_31Operand(MCInst &Inst, uint64_t Imm,
659659
return MCDisassembler::Success;
660660
}
661661

662+
static DecodeStatus decodeShimm0_31Operand(MCInst &Inst, uint64_t Imm,
663+
int64_t Address,
664+
const void *Decoder) {
665+
assert(isUInt<5>(Imm) && "Invalid immediate");
666+
Inst.addOperand(MCOperand::createImm(32 - Imm));
667+
return MCDisassembler::Success;
668+
}
669+
662670
static DecodeStatus decodeImm7_22Operand(MCInst &Inst, uint64_t Imm,
663671
int64_t Address,
664672
const void *Decoder) {

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ void XtensaInstPrinter::printShimm1_31_AsmOperand(const MCInst *MI, int OpNum,
264264
printOperand(MI, OpNum, O);
265265
}
266266

267+
void XtensaInstPrinter::printShimm0_31_AsmOperand(const MCInst *MI, int OpNum,
268+
raw_ostream &O) {
269+
if (MI->getOperand(OpNum).isImm()) {
270+
int64_t Value = MI->getOperand(OpNum).getImm();
271+
assert((Value >= 0 && Value <= 31) &&
272+
"Invalid argument, value must be in range [0,31]");
273+
O << Value;
274+
} else
275+
printOperand(MI, OpNum, O);
276+
}
277+
267278
void XtensaInstPrinter::printImm1_16_AsmOperand(const MCInst *MI, int OpNum,
268279
raw_ostream &O) {
269280
if (MI->getOperand(OpNum).isImm()) {

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaInstPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class XtensaInstPrinter : public MCInstPrinter {
5959
void printUimm4_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
6060
void printUimm5_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
6161
void printShimm1_31_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
62+
void printShimm0_31_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
6263
void printImm1_16_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
6364
void printImm1n_15_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
6465
void printImm32n_95_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);

llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCCodeEmitter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class XtensaMCCodeEmitter : public MCCodeEmitter {
135135
SmallVectorImpl<MCFixup> &Fixups,
136136
const MCSubtargetInfo &STI) const;
137137

138+
uint32_t getShimm0_31OpValue(const MCInst &MI, unsigned OpNo,
139+
SmallVectorImpl<MCFixup> &Fixups,
140+
const MCSubtargetInfo &STI) const;
141+
138142
uint32_t getB4constOpValue(const MCInst &MI, unsigned OpNo,
139143
SmallVectorImpl<MCFixup> &Fixups,
140144
const MCSubtargetInfo &STI) const;
@@ -454,6 +458,18 @@ XtensaMCCodeEmitter::getShimm1_31OpValue(const MCInst &MI, unsigned OpNo,
454458
return ((32 - Res) & 0x1f);
455459
}
456460

461+
uint32_t
462+
XtensaMCCodeEmitter::getShimm0_31OpValue(const MCInst &MI, unsigned OpNo,
463+
SmallVectorImpl<MCFixup> &Fixups,
464+
const MCSubtargetInfo &STI) const {
465+
const MCOperand &MO = MI.getOperand(OpNo);
466+
uint32_t Res = static_cast<uint32_t>(MO.getImm());
467+
468+
assert(((Res >= 0) && (Res <= 31)) && "Unexpected operand value!");
469+
470+
return ((32 - Res) & 0x1f);
471+
}
472+
457473
uint32_t
458474
XtensaMCCodeEmitter::getImm1_16OpValue(const MCInst &MI, unsigned OpNo,
459475
SmallVectorImpl<MCFixup> &Fixups,

0 commit comments

Comments
 (0)