Skip to content

Commit e11d34a

Browse files
committed
[Xtensa] Correction of the ESP32-S2 target.
The ESP32-S2 chip includes Xtensa ISA extension which helps to work with GPIO, so we add instructions description and test. Add MEMCTL feature to ESP32-S@ target. Implement Xtensa illegal instructions with tests.
1 parent 928fd25 commit e11d34a

File tree

13 files changed

+151
-2
lines changed

13 files changed

+151
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ struct XtensaOperand : public MCParsedAsmOperand {
350350

351351
bool isseimm7_22() const { return isImm(7, 22); }
352352

353+
bool isSelect_256() const { return isImm(0, 255); }
354+
353355
/// getStartLoc - Gets location of the first token of this operand
354356
SMLoc getStartLoc() const override { return StartLoc; }
355357
/// getEndLoc - Gets location of the last token of this operand
@@ -621,6 +623,9 @@ bool XtensaAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
621623
case Match_Invalidseimm7_22:
622624
return Error(RefineErrorLoc(IDLoc, Operands, ErrorInfo),
623625
"expected immediate in range [7, 22]");
626+
case Match_InvalidSelect_256:
627+
return Error(RefineErrorLoc(IDLoc, Operands, ErrorInfo),
628+
"expected immediate in range [0, 255]");
624629
}
625630

626631
report_fatal_error("Unknown match type detected!");

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,14 @@ static DecodeStatus decodeSeimm7_22Operand(MCInst &Inst, uint64_t Imm,
568568
return MCDisassembler::Success;
569569
}
570570

571+
static DecodeStatus decodeSelect_256Operand(MCInst &Inst, uint64_t Imm,
572+
int64_t Address,
573+
const void *Decoder) {
574+
assert(isUInt<8>(Imm) && "Invalid immediate");
575+
Inst.addOperand(MCOperand::createImm(Imm));
576+
return MCDisassembler::Success;
577+
}
578+
571579
static int64_t TableB4const[16] = {-1, 1, 2, 3, 4, 5, 6, 7,
572580
8, 10, 12, 16, 32, 64, 128, 256};
573581
static DecodeStatus decodeB4constOperand(MCInst &Inst, uint64_t Imm,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,14 @@ void XtensaInstPrinter::printSeimm7_22_AsmOperand(const MCInst *MI, int OpNum,
436436
} else
437437
printOperand(MI, OpNum, O);
438438
}
439+
440+
void XtensaInstPrinter::printSelect_256_AsmOperand(const MCInst *MI, int OpNum,
441+
raw_ostream &O) {
442+
if (MI->getOperand(OpNum).isImm()) {
443+
int64_t Value = MI->getOperand(OpNum).getImm();
444+
assert((Value >= 0 && Value <= 255) &&
445+
"Invalid argument, value must be in range [0,255]");
446+
O << Value;
447+
} else
448+
printOperand(MI, OpNum, O);
449+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class XtensaInstPrinter : public MCInstPrinter {
7373
void printB4const_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
7474
void printB4constu_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
7575
void printSeimm7_22_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
76+
void printSelect_256_AsmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
7677
};
7778
} // end namespace llvm
7879

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class XtensaMCCodeEmitter : public MCCodeEmitter {
142142
uint32_t getSeimm7_22OpValue(const MCInst &MI, unsigned OpNo,
143143
SmallVectorImpl<MCFixup> &Fixups,
144144
const MCSubtargetInfo &STI) const;
145+
146+
uint32_t getSelect_256OpValue(const MCInst &MI, unsigned OpNo,
147+
SmallVectorImpl<MCFixup> &Fixups,
148+
const MCSubtargetInfo &STI) const;
149+
145150
};
146151
} // namespace
147152

@@ -593,4 +598,16 @@ XtensaMCCodeEmitter::getSeimm7_22OpValue(const MCInst &MI, unsigned OpNo,
593598
return res;
594599
}
595600

601+
uint32_t
602+
XtensaMCCodeEmitter::getSelect_256OpValue(const MCInst &MI, unsigned OpNo,
603+
SmallVectorImpl<MCFixup> &Fixups,
604+
const MCSubtargetInfo &STI) const {
605+
const MCOperand &MO = MI.getOperand(OpNo);
606+
uint32_t Res = static_cast<uint32_t>(MO.getImm());
607+
608+
assert(((Res >= 0) && (Res <= 255)) && "Unexpected operand value!");
609+
610+
return Res;
611+
}
612+
596613
#include "XtensaGenMCCodeEmitter.inc"

llvm/lib/Target/Xtensa/Xtensa.td

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def FeatureMiscSR : SubtargetFeature<"miscsr", "HasMiscSR", "true",
153153
def HasMiscSR : Predicate<"Subtarget->hasMiscSR()">,
154154
AssemblerPredicate<(all_of FeatureMiscSR)>;
155155

156+
def FeatureESP32S2Ops : SubtargetFeature<"esp32s2", "HasESP32S2Ops", "true",
157+
"Support Xtensa esp32-s2 ISA extension">;
158+
def HasESP32S2Ops : Predicate<"Subtarget->hasESP32S2Ops()">,
159+
AssemblerPredicate<(all_of FeatureESP32S2Ops)>;
160+
156161
//===----------------------------------------------------------------------===//
157162
// Xtensa supported processors.
158163
//===----------------------------------------------------------------------===//
@@ -170,8 +175,8 @@ def : Proc<"esp8266", [FeatureDensity, FeatureNSA, FeatureMul32, FeatureExtended
170175
FeatureInterrupt, FeatureRelocatableVector, FeatureTimerInt, FeatureRegionProtection, FeaturePRID]>;
171176

172177
def : Proc<"esp32-s2", [FeatureDensity, FeatureWindowed, FeatureSEXT, FeatureNSA, FeatureMul32, FeatureMul32High, FeatureTHREADPTR, FeatureDiv32,
173-
FeatureDebug, FeatureException, FeatureHighPriInterrupts, FeatureCoprocessor, FeatureInterrupt, FeatureRelocatableVector,
174-
FeatureTimerInt, FeaturePRID, FeatureRegionProtection, FeatureMiscSR]>;
178+
FeatureMEMCTL, FeatureDebug, FeatureException, FeatureHighPriInterrupts, FeatureCoprocessor, FeatureInterrupt,
179+
FeatureRelocatableVector, FeatureTimerInt, FeaturePRID, FeatureRegionProtection, FeatureMiscSR, FeatureESP32S2Ops]>;
175180

176181
//===----------------------------------------------------------------------===//
177182
// Register File Description

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,27 @@ def WITLB : RRR_Inst<0x00, 0x00, 0x05, (outs AR:$t), (ins AR:$s),
14501450
let r = 0x6;
14511451
}
14521452

1453+
//===----------------------------------------------------------------------===//
1454+
// Illegal instructions
1455+
//===----------------------------------------------------------------------===//
1456+
1457+
let isBarrier = 1, isTerminator = 1 in {
1458+
def ILL : CALLX_Inst<0x00, 0x00, 0x00, (outs), (ins),
1459+
"ill", []> {
1460+
let m = 0x0;
1461+
let n = 0x0;
1462+
let r = 0;
1463+
let s = 0;
1464+
}
1465+
1466+
def ILL_N : RRRN_Inst<0x0C, (outs), (ins),
1467+
"ill.n", []>, Requires<[HasDensity]> {
1468+
let r = 0xf;
1469+
let s = 0x0;
1470+
let t = 0x6;
1471+
}
1472+
}
1473+
14531474
//===----------------------------------------------------------------------===//
14541475
// Atomic patterns
14551476
//===----------------------------------------------------------------------===//
@@ -1584,6 +1605,40 @@ let usesCustomInserter = 1, Predicates = [HasS32C1I] in {
15841605
[(set AR:$dst, (atomic_load_umax_32 AR:$ptr, AR:$arg))]>;
15851606
}
15861607

1608+
//===----------------------------------------------------------------------===//
1609+
// Xtensa ESP32S2 Instructions
1610+
//===----------------------------------------------------------------------===//
1611+
let Predicates = [HasESP32S2Ops] in {
1612+
def WR_MASK_GPIO_OUT : RRR_Inst<0x0, 0x06, 0x0, (outs), (ins AR:$s, AR:$t),
1613+
"wr_mask_gpio_out\t$s, $t", []> {
1614+
let r = 0x2;
1615+
}
1616+
1617+
def SET_BIT_GPIO_OUT : RRR_Inst<0x0, 0x06, 0x0, (outs), (ins select_256:$imm),
1618+
"set_bit_gpio_out\t$imm", []> {
1619+
bits<8> imm;
1620+
1621+
let r = 0x1;
1622+
let s = imm{7-4};
1623+
let t = imm{3-0};
1624+
}
1625+
1626+
def CLR_BIT_GPIO_OUT : RRR_Inst<0x0, 0x06, 0x0, (outs), (ins select_256:$imm),
1627+
"clr_bit_gpio_out\t$imm", []> {
1628+
bits<8> imm;
1629+
1630+
let r = 0x0;
1631+
let s = imm{7-4};
1632+
let t = imm{3-0};
1633+
}
1634+
1635+
def GET_GPIO_IN : RRR_Inst<0x0, 0x06, 0x0, (outs AR:$t), (ins),
1636+
"get_gpio_in\t$t", []> {
1637+
let r = 0x3;
1638+
let s = 0x0;
1639+
}
1640+
}
1641+
15871642
//===----------------------------------------------------------------------===//
15881643
// DSP Instructions
15891644
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaOperands.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ def seimm7_22: Immediate<i32, [{ return Imm >= 7 && Imm <= 22; }], "Seimm7_22_As
175175
let DecoderMethod = "decodeSeimm7_22Operand";
176176
}
177177

178+
// select_256 predicate - Immediate in the range [0,255]
179+
def Select_256_AsmOperand: ImmAsmOperand<"Select_256">;
180+
def select_256: Immediate<i32, [{ return Imm >= 0 && Imm <= 255; }], "Select_256_AsmOperand"> {
181+
let EncoderMethod = "getSelect_256OpValue";
182+
let DecoderMethod = "decodeSelect_256Operand";
183+
}
184+
178185
//===----------------------------------------------------------------------===//
179186
// Memory address operands
180187
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaSubtarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ XtensaSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
5959
HasPRID = false;
6060
HasRegionProtection = false;
6161
HasMiscSR = false;
62+
HasESP32S2Ops = false;
6263

6364
// Parse features string.
6465
ParseSubtargetFeatures(CPUName, CPUName, FS);

llvm/lib/Target/Xtensa/XtensaSubtarget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
119119
// Enable Xtensa Miscellaneous Special Reigsiters option
120120
bool HasMiscSR;
121121

122+
// Enable Xtensa esp32-s2 ISA extension
123+
bool HasESP32S2Ops;
124+
122125
XtensaSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
123126

124127
public:
@@ -190,6 +193,8 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
190193

191194
bool hasMiscSR() const { return HasMiscSR; }
192195

196+
bool hasESP32S2Ops() const { return HasESP32S2Ops; }
197+
193198
// Automatically generated by tblgen.
194199
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
195200
};

0 commit comments

Comments
 (0)