Skip to content

Commit ffccfde

Browse files
committed
[hexagon] Add {con,de}structive interference size defn
This support was originally added in 72c373b ([C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (#89446), 2024-04-26). We're overriding the values for Hexagon here. Signed-off-by: Brian Cain <[email protected]>
1 parent f118c88 commit ffccfde

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

clang/lib/Basic/Targets/Hexagon.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ static constexpr CPUSuffix Suffixes[] = {
238238
{{"hexagonv73"}, {"73"}},
239239
};
240240

241+
std::optional<unsigned> HexagonTargetInfo::getHexagonCPURev(StringRef Name) {
242+
StringRef Arch = Name;
243+
Arch.consume_front("hexagonv");
244+
Arch.consume_back("t");
245+
246+
unsigned Val;
247+
if (!Arch.getAsInteger(0, Val))
248+
return Val;
249+
250+
return std::nullopt;
251+
}
252+
241253
const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
242254
const CPUSuffix *Item = llvm::find_if(
243255
Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });

clang/lib/Basic/Targets/Hexagon.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Basic/TargetOptions.h"
1818
#include "llvm/Support/Compiler.h"
1919
#include "llvm/TargetParser/Triple.h"
20+
#include <optional>
2021

2122
namespace clang {
2223
namespace targets {
@@ -115,6 +116,7 @@ class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo {
115116
std::string_view getClobbers() const override { return ""; }
116117

117118
static const char *getHexagonCPUSuffix(StringRef Name);
119+
static std::optional<unsigned> getHexagonCPURev(StringRef Name);
118120

119121
bool isValidCPUName(StringRef Name) const override {
120122
return getHexagonCPUSuffix(Name);
@@ -139,6 +141,14 @@ class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo {
139141
}
140142

141143
bool hasBitIntType() const override { return true; }
144+
145+
std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
146+
std::optional<unsigned> Rev = getHexagonCPURev(CPU);
147+
148+
// V73 and later have 64-byte cache lines.
149+
unsigned CacheLineSizeBytes = Rev >= 73 ? 64 : 32;
150+
return std::make_pair(CacheLineSizeBytes, CacheLineSizeBytes);
151+
}
142152
};
143153
} // namespace targets
144154
} // namespace clang

clang/test/Preprocessor/hexagon-predefines.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,20 @@
169169
// CHECK-ATOMIC: #define __CLANG_ATOMIC_POINTER_LOCK_FREE 2
170170
// CHECK-ATOMIC: #define __CLANG_ATOMIC_SHORT_LOCK_FREE 2
171171
// CHECK-ATOMIC: #define __CLANG_ATOMIC_WCHAR_T_LOCK_FREE 2
172+
173+
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-linux-musl \
174+
// RUN: -target-cpu hexagonv67 | FileCheck \
175+
// RUN: %s -check-prefix CHECK-INTERFERENCE
176+
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-none-elf \
177+
// RUN: -target-cpu hexagonv67 | FileCheck \
178+
// RUN: %s -check-prefix CHECK-INTERFERENCE
179+
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-none-elf \
180+
// RUN: -target-cpu hexagonv71t | FileCheck \
181+
// RUN: %s -check-prefix CHECK-INTERFERENCE
182+
// CHECK-INTERFERENCE: #define __GCC_CONSTRUCTIVE_SIZE 32
183+
// CHECK-INTERFERENCE: #define __GCC_DESTRUCTIVE_SIZE 32
184+
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-none-elf \
185+
// RUN: -target-cpu hexagonv73 | FileCheck \
186+
// RUN: %s -check-prefix CHECK-INTERFERENCE-73
187+
// CHECK-INTERFERENCE-73: #define __GCC_CONSTRUCTIVE_SIZE 64
188+
// CHECK-INTERFERENCE-73: #define __GCC_DESTRUCTIVE_SIZE 64

0 commit comments

Comments
 (0)