Skip to content

Commit 2f4bf48

Browse files
committed
[Xtensa] Implement ESP32-S3 target.
Implement support of the ESP32-S3 chip in clang and llvm. The ESP32-S3 chip includes Xtensa ISA extension which helps to work with GPIO, so we add instructions description and test.
1 parent e11d34a commit 2f4bf48

File tree

8 files changed

+82
-1
lines changed

8 files changed

+82
-1
lines changed

clang/lib/Basic/Targets/Xtensa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class LLVM_LIBRARY_VISIBILITY XtensaTargetInfo : public TargetInfo {
9898
.Case("esp32", true)
9999
.Case("esp8266", true)
100100
.Case("esp32-s2", true)
101+
.Case("esp32-s3", true)
101102
.Case("generic", true)
102103
.Default(false);
103104
}

clang/lib/Driver/ToolChains/Xtensa.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ XtensaGCCToolchainDetector::XtensaGCCToolchainDetector(
4545
ToolchainName = "xtensa-esp32-elf";
4646
else if (CPUName.equals("esp32-s2"))
4747
ToolchainName = "xtensa-esp32s2-elf";
48+
else if (CPUName.equals("esp32-s3"))
49+
ToolchainName = "xtensa-esp32s3-elf";
4850
else if (CPUName.equals("esp8266"))
4951
ToolchainName = "xtensa-lx106-elf";
5052

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ bool XtensaAsmParser::checkRegister(unsigned RegNo) {
947947
unsigned NumMiscSR = 0;
948948
bool IsESP32 = false;
949949
bool IsESP32_S2 = false;
950+
bool IsESP32_S3 = false;
950951
bool Res = true;
951952

952953
// Assume that CPU is esp32 by default
@@ -960,6 +961,11 @@ bool XtensaAsmParser::checkRegister(unsigned RegNo) {
960961
NumTimers = 3;
961962
NumMiscSR = 4;
962963
IsESP32_S2 = true;
964+
} else if (CPU == "esp32-s3") {
965+
NumIntLevels = 6;
966+
NumTimers = 3;
967+
NumMiscSR = 4;
968+
IsESP32_S3 = true;
963969
} else if (CPU == "esp8266") {
964970
NumIntLevels = 2;
965971
NumTimers = 1;
@@ -1083,7 +1089,7 @@ bool XtensaAsmParser::checkRegister(unsigned RegNo) {
10831089
Res = hasTHREADPTR();
10841090
break;
10851091
case Xtensa::GPIO_OUT:
1086-
Res = IsESP32_S2;
1092+
Res = IsESP32_S2 || IsESP32_S3;
10871093
break;
10881094
case Xtensa::EXPSTATE:
10891095
Res = IsESP32;

llvm/lib/Target/Xtensa/Xtensa.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def FeatureESP32S2Ops : SubtargetFeature<"esp32s2", "HasESP32S2Ops", "tru
158158
def HasESP32S2Ops : Predicate<"Subtarget->hasESP32S2Ops()">,
159159
AssemblerPredicate<(all_of FeatureESP32S2Ops)>;
160160

161+
def FeatureESP32S3Ops : SubtargetFeature<"esp32s3", "HasESP32S3Ops", "true",
162+
"Support Xtensa esp32-s3 ISA extension">;
163+
def HasESP32S3Ops : Predicate<"Subtarget->hasESP32S3Ops()">,
164+
AssemblerPredicate<(all_of FeatureESP32S3Ops)>;
165+
161166
//===----------------------------------------------------------------------===//
162167
// Xtensa supported processors.
163168
//===----------------------------------------------------------------------===//
@@ -178,6 +183,12 @@ def : Proc<"esp32-s2", [FeatureDensity, FeatureWindowed, FeatureSEXT, FeatureNSA
178183
FeatureMEMCTL, FeatureDebug, FeatureException, FeatureHighPriInterrupts, FeatureCoprocessor, FeatureInterrupt,
179184
FeatureRelocatableVector, FeatureTimerInt, FeaturePRID, FeatureRegionProtection, FeatureMiscSR, FeatureESP32S2Ops]>;
180185

186+
def : Proc<"esp32-s3", [FeatureDensity, FeatureSingleFloat, FeatureLoop, FeatureMAC16, FeatureWindowed, FeatureBoolean,
187+
FeatureSEXT, FeatureNSA, FeatureMul32, FeatureMul32High, FeatureDFPAccel, FeatureS32C1I, FeatureTHREADPTR, FeatureDiv32,
188+
FeatureATOMCTL, FeatureMEMCTL, FeatureDebug, FeatureException, FeatureHighPriInterrupts, FeatureCoprocessor,
189+
FeatureInterrupt, FeatureRelocatableVector, FeatureTimerInt, FeaturePRID, FeatureRegionProtection, FeatureMiscSR,
190+
FeatureESP32S3Ops]>;
191+
181192
//===----------------------------------------------------------------------===//
182193
// Register File Description
183194
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,40 @@ let Predicates = [HasESP32S2Ops] in {
16391639
}
16401640
}
16411641

1642+
//===----------------------------------------------------------------------===//
1643+
// Xtensa ESP32S3 Instructions
1644+
//===----------------------------------------------------------------------===//
1645+
let Predicates = [HasESP32S3Ops] in {
1646+
def EE_WR_MASK_GPIO_OUT : RRR_Inst<0x04, 0x02, 0x07, (outs), (ins AR:$t, AR:$s),
1647+
"ee.wr_mask_gpio_out\t$t, $s", []> {
1648+
let r = 0x4;
1649+
}
1650+
1651+
def EE_SET_BIT_GPIO_OUT : RRR_Inst<0x04, 0x05, 0x07, (outs), (ins select_256:$imm),
1652+
"ee.set_bit_gpio_out\t$imm", []> {
1653+
bits<8> imm;
1654+
1655+
let r = 0x4;
1656+
let s = imm{7-4};
1657+
let t = imm{3-0};
1658+
}
1659+
1660+
def EE_CLR_BIT_GPIO_OUT : RRR_Inst<0x04, 0x06, 0x07, (outs), (ins select_256:$imm),
1661+
"ee.clr_bit_gpio_out\t$imm", []> {
1662+
bits<8> imm;
1663+
1664+
let r = 0x4;
1665+
let s = imm{7-4};
1666+
let t = imm{3-0};
1667+
}
1668+
1669+
def EE_GET_GPIO_IN : RRR_Inst<0x04, 0x05, 0x06, (outs AR:$t), (ins),
1670+
"ee.get_gpio_in\t$t", []> {
1671+
let r = 0x0;
1672+
let s = 0x8;
1673+
}
1674+
}
1675+
16421676
//===----------------------------------------------------------------------===//
16431677
// DSP Instructions
16441678
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaSubtarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ XtensaSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
6060
HasRegionProtection = false;
6161
HasMiscSR = false;
6262
HasESP32S2Ops = false;
63+
HasESP32S3Ops = false;
6364

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

llvm/lib/Target/Xtensa/XtensaSubtarget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
122122
// Enable Xtensa esp32-s2 ISA extension
123123
bool HasESP32S2Ops;
124124

125+
// Enable Xtensa esp32-s3 ISA extension
126+
bool HasESP32S3Ops;
127+
125128
XtensaSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
126129

127130
public:
@@ -195,6 +198,8 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
195198

196199
bool hasESP32S2Ops() const { return HasESP32S2Ops; }
197200

201+
bool hasESP32S3Ops() const { return HasESP32S3Ops; }
202+
198203
// Automatically generated by tblgen.
199204
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
200205
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# RUN: llvm-mc %s -triple=xtensa -mattr=+esp32s3 -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
3+
4+
.align 4
5+
LBL0:
6+
7+
# CHECK-INST: ee.clr_bit_gpio_out 52
8+
# CHECK: encoding: [0x44,0x43,0x76]
9+
ee.clr_bit_gpio_out 52
10+
11+
# CHECK-INST: ee.get_gpio_in a2
12+
# CHECK: encoding: [0x24,0x08,0x65]
13+
ee.get_gpio_in a2
14+
15+
# CHECK-INST: ee.set_bit_gpio_out 18
16+
# CHECK: encoding: [0x24,0x41,0x75]
17+
ee.set_bit_gpio_out 18
18+
19+
# CHECK-INST: ee.wr_mask_gpio_out a3, a2
20+
# CHECK: encoding: [0x34,0x42,0x72]
21+
ee.wr_mask_gpio_out a3, a2

0 commit comments

Comments
 (0)