Skip to content

Commit

Permalink
[hexagon] Add {con,de}structive interference size defn (#94877)
Browse files Browse the repository at this point in the history
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 <bcain@quicinc.com>
  • Loading branch information
androm3da committed Jul 9, 2024
1 parent cc945e4 commit c91b50e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/lib/Basic/Targets/Hexagon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ static constexpr CPUSuffix Suffixes[] = {
{{"hexagonv73"}, {"73"}},
};

std::optional<unsigned> HexagonTargetInfo::getHexagonCPURev(StringRef Name) {
StringRef Arch = Name;
Arch.consume_front("hexagonv");
Arch.consume_back("t");

unsigned Val;
if (!Arch.getAsInteger(0, Val))
return Val;

return std::nullopt;
}

const char *HexagonTargetInfo::getHexagonCPUSuffix(StringRef Name) {
const CPUSuffix *Item = llvm::find_if(
Suffixes, [Name](const CPUSuffix &S) { return S.Name == Name; });
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Basic/Targets/Hexagon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/Basic/TargetOptions.h"
#include "llvm/Support/Compiler.h"
#include "llvm/TargetParser/Triple.h"
#include <optional>

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

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

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

bool hasBitIntType() const override { return true; }

std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
std::optional<unsigned> Rev = getHexagonCPURev(CPU);

// V73 and later have 64-byte cache lines.
unsigned CacheLineSizeBytes = Rev >= 73 ? 64 : 32;
return std::make_pair(CacheLineSizeBytes, CacheLineSizeBytes);
}
};
} // namespace targets
} // namespace clang
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Preprocessor/hexagon-predefines.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,20 @@
// CHECK-ATOMIC: #define __CLANG_ATOMIC_POINTER_LOCK_FREE 2
// CHECK-ATOMIC: #define __CLANG_ATOMIC_SHORT_LOCK_FREE 2
// CHECK-ATOMIC: #define __CLANG_ATOMIC_WCHAR_T_LOCK_FREE 2

// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-linux-musl \
// RUN: -target-cpu hexagonv67 | FileCheck \
// RUN: %s -check-prefix CHECK-INTERFERENCE
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-none-elf \
// RUN: -target-cpu hexagonv67 | FileCheck \
// RUN: %s -check-prefix CHECK-INTERFERENCE
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-none-elf \
// RUN: -target-cpu hexagonv71t | FileCheck \
// RUN: %s -check-prefix CHECK-INTERFERENCE
// CHECK-INTERFERENCE: #define __GCC_CONSTRUCTIVE_SIZE 32
// CHECK-INTERFERENCE: #define __GCC_DESTRUCTIVE_SIZE 32
// RUN: %clang_cc1 -E -dM -triple hexagon-unknown-none-elf \
// RUN: -target-cpu hexagonv73 | FileCheck \
// RUN: %s -check-prefix CHECK-INTERFERENCE-73
// CHECK-INTERFERENCE-73: #define __GCC_CONSTRUCTIVE_SIZE 64
// CHECK-INTERFERENCE-73: #define __GCC_DESTRUCTIVE_SIZE 64

0 comments on commit c91b50e

Please sign in to comment.