Skip to content

Commit 2db67a2

Browse files
committed
[Xtensa] Add '+forced-atomics' target feature support
1 parent 39ebe16 commit 2db67a2

File tree

9 files changed

+5845
-181
lines changed

9 files changed

+5845
-181
lines changed

llvm/lib/Target/Xtensa/Xtensa.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ def FeatureHIFI3 : SubtargetFeature<"hifi3", "HasHIFI3", "true",
183183
def HasHIFI3 : Predicate<"Subtarget->hasHIFI3()">,
184184
AssemblerPredicate<(all_of FeatureHIFI3)>;
185185

186+
// Assume that lock-free native-width atomics are available, even if the target
187+
// and operating system combination would not usually provide them. The user
188+
// is responsible for providing any necessary __sync implementations. Code
189+
// built with this feature is not ABI-compatible with code built without this
190+
// feature, if atomic variables are exposed across the ABI boundary.
191+
def FeatureForcedAtomics : SubtargetFeature<"forced-atomics", "HasForcedAtomics", "true",
192+
"Assume that lock-free native-width atomics are available">;
193+
def HasForcedAtomics : Predicate<"Subtarget->hasForcedAtomics()">,
194+
AssemblerPredicate<(all_of FeatureForcedAtomics)>;
195+
def HasAtomicLdSt : Predicate<"Subtarget->hasS32C1I() || Subtarget->hasForcedAtomics()">;
196+
186197
//===----------------------------------------------------------------------===//
187198
// Xtensa supported processors.
188199
//===----------------------------------------------------------------------===//

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &tm,
440440
if (Subtarget.hasS32C1I()) {
441441
setMaxAtomicSizeInBitsSupported(32);
442442
setMinCmpXchgSizeInBits(32);
443+
} else if (Subtarget.hasForcedAtomics()) {
444+
setMaxAtomicSizeInBitsSupported(32);
443445
} else {
444446
setMaxAtomicSizeInBitsSupported(0);
445447
}

llvm/lib/Target/Xtensa/XtensaInstrInfo.td

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,13 +1841,18 @@ def SIMCALL : RRR_Inst<0x00, 0x00, 0x00, (outs), (ins),
18411841
// Atomic patterns
18421842
//===----------------------------------------------------------------------===//
18431843

1844-
def : Pat<(i32 (atomic_load_8 addr_ish1:$addr)), (L8UI addr_ish1:$addr)>;
1845-
def : Pat<(i32 (atomic_load_16 addr_ish2:$addr)), (L16UI addr_ish2:$addr)>;
1846-
def : Pat<(i32 (atomic_load_32 addr_ish4:$addr)), (L32I addr_ish4:$addr)>;
1847-
1848-
def : Pat<(atomic_store_8 AR:$t, addr_ish1:$addr), (S8I AR:$t, addr_ish1:$addr)>;
1849-
def : Pat<(atomic_store_16 AR:$t, addr_ish2:$addr), (S16I AR:$t, addr_ish2:$addr)>;
1850-
def : Pat<(atomic_store_32 AR:$t, addr_ish4:$addr), (S32I AR:$t, addr_ish4:$addr)>;
1844+
// Atomic load/store are available under both +s32c1i and +force-atomics.
1845+
// Fences will be inserted for atomic load/stores according to the logic in
1846+
// XtensaTargetLowering.
1847+
let Predicates = [HasAtomicLdSt] in {
1848+
def : Pat<(i32 (atomic_load_8 addr_ish1:$addr)), (L8UI addr_ish1:$addr)>;
1849+
def : Pat<(i32 (atomic_load_16 addr_ish2:$addr)), (L16UI addr_ish2:$addr)>;
1850+
def : Pat<(i32 (atomic_load_32 addr_ish4:$addr)), (L32I addr_ish4:$addr)>;
1851+
1852+
def : Pat<(atomic_store_8 AR:$t, addr_ish1:$addr), (S8I AR:$t, addr_ish1:$addr)>;
1853+
def : Pat<(atomic_store_16 AR:$t, addr_ish2:$addr), (S16I AR:$t, addr_ish2:$addr)>;
1854+
def : Pat<(atomic_store_32 AR:$t, addr_ish4:$addr), (S32I AR:$t, addr_ish4:$addr)>;
1855+
}
18511856

18521857
let usesCustomInserter = 1, Predicates = [HasS32C1I] in {
18531858
def ATOMIC_CMP_SWAP_8_P : Pseudo<(outs AR:$dst), (ins AR:$ptr, AR:$cmp, AR:$swap),

llvm/lib/Target/Xtensa/XtensaSubtarget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ XtensaSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) {
7878
HasESP32S2Ops = false;
7979
HasESP32S3Ops = false;
8080
HasHIFI3 = false;
81+
HasForcedAtomics = false;
82+
HasAtomicLdSt = false;
8183

8284
// Parse features string.
8385
ParseSubtargetFeatures(CPUName, CPUName, FS);

llvm/lib/Target/Xtensa/XtensaSubtarget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
137137
// Enable Xtensa HIFI3 Extension
138138
bool HasHIFI3;
139139

140+
// Enable 'forced-atomics' feature
141+
bool HasForcedAtomics;
142+
143+
// Enable atomic load and stores ops
144+
bool HasAtomicLdSt;
145+
146+
140147
XtensaSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
141148

142149
public:
@@ -222,6 +229,10 @@ class XtensaSubtarget : public XtensaGenSubtargetInfo {
222229

223230
bool hasHIFI3() const { return HasHIFI3; }
224231

232+
bool hasForcedAtomics() const { return HasForcedAtomics; }
233+
234+
bool hasAtomicLdSt() const { return HasAtomicLdSt; }
235+
225236
// Automatically generated by tblgen.
226237
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
227238
};

0 commit comments

Comments
 (0)