aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-04-14 21:41:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-06-22 18:20:56 +0000
commitbdd1243df58e60e85101c09001d9812a789b6bc4 (patch)
treea1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp
parent781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff)
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp94
1 files changed, 87 insertions, 7 deletions
diff --git a/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp b/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp
index 6685145ea6d2..8ee43261fc1d 100644
--- a/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp
+++ b/contrib/llvm-project/clang/lib/Basic/TargetInfo.cpp
@@ -14,6 +14,7 @@
#include "clang/Basic/AddressSpaces.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticFrontend.h"
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
@@ -23,6 +24,30 @@
using namespace clang;
static const LangASMap DefaultAddrSpaceMap = {0};
+// The fake address space map must have a distinct entry for each
+// language-specific address space.
+static const LangASMap FakeAddrSpaceMap = {
+ 0, // Default
+ 1, // opencl_global
+ 3, // opencl_local
+ 2, // opencl_constant
+ 0, // opencl_private
+ 4, // opencl_generic
+ 5, // opencl_global_device
+ 6, // opencl_global_host
+ 7, // cuda_device
+ 8, // cuda_constant
+ 9, // cuda_shared
+ 1, // sycl_global
+ 5, // sycl_global_device
+ 6, // sycl_global_host
+ 3, // sycl_local
+ 0, // sycl_private
+ 10, // ptr32_sptr
+ 11, // ptr32_uptr
+ 12, // ptr64
+ 13, // hlsl_groupshared
+};
// TargetInfo Constructor.
TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
@@ -33,6 +58,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
VLASupported = true;
NoAsmVariants = false;
HasLegalHalfType = false;
+ HalfArgsAndReturns = false;
HasFloat128 = false;
HasIbm128 = false;
HasFloat16 = false;
@@ -45,6 +71,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
IntWidth = IntAlign = 32;
LongWidth = LongAlign = 32;
LongLongWidth = LongLongAlign = 64;
+ Int128Align = 128;
// Fixed point default bit widths
ShortAccumWidth = ShortAccumAlign = 16;
@@ -152,8 +179,6 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
MaxOpenCLWorkGroupSize = 1024;
MaxBitIntWidth.reset();
-
- ProgramAddrSpace = 0;
}
// Out of line virtual dtor for TargetInfo.
@@ -207,11 +232,11 @@ const char *TargetInfo::getTypeConstantSuffix(IntType T) const {
case UnsignedChar:
if (getCharWidth() < getIntWidth())
return "";
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case UnsignedShort:
if (getShortWidth() < getIntWidth())
return "";
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case UnsignedInt: return "U";
case UnsignedLong: return "UL";
case UnsignedLongLong: return "ULL";
@@ -485,7 +510,10 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
}
if (Opts.MaxBitIntWidth)
- MaxBitIntWidth = Opts.MaxBitIntWidth;
+ MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth);
+
+ if (Opts.FakeAddressSpaceMap)
+ AddrSpaceMap = &FakeAddrSpaceMap;
}
bool TargetInfo::initFeatureMap(
@@ -493,13 +521,61 @@ bool TargetInfo::initFeatureMap(
const std::vector<std::string> &FeatureVec) const {
for (const auto &F : FeatureVec) {
StringRef Name = F;
+ if (Name.empty())
+ continue;
// Apply the feature via the target.
- bool Enabled = Name[0] == '+';
- setFeatureEnabled(Features, Name.substr(1), Enabled);
+ if (Name[0] != '+' && Name[0] != '-')
+ Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
+ else
+ setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
}
return true;
}
+ParsedTargetAttr TargetInfo::parseTargetAttr(StringRef Features) const {
+ ParsedTargetAttr Ret;
+ if (Features == "default")
+ return Ret;
+ SmallVector<StringRef, 1> AttrFeatures;
+ Features.split(AttrFeatures, ",");
+
+ // Grab the various features and prepend a "+" to turn on the feature to
+ // the backend and add them to our existing set of features.
+ for (auto &Feature : AttrFeatures) {
+ // Go ahead and trim whitespace rather than either erroring or
+ // accepting it weirdly.
+ Feature = Feature.trim();
+
+ // TODO: Support the fpmath option. It will require checking
+ // overall feature validity for the function with the rest of the
+ // attributes on the function.
+ if (Feature.startswith("fpmath="))
+ continue;
+
+ if (Feature.startswith("branch-protection=")) {
+ Ret.BranchProtection = Feature.split('=').second.trim();
+ continue;
+ }
+
+ // While we're here iterating check for a different target cpu.
+ if (Feature.startswith("arch=")) {
+ if (!Ret.CPU.empty())
+ Ret.Duplicate = "arch=";
+ else
+ Ret.CPU = Feature.split("=").second.trim();
+ } else if (Feature.startswith("tune=")) {
+ if (!Ret.Tune.empty())
+ Ret.Duplicate = "tune=";
+ else
+ Ret.Tune = Feature.split("=").second.trim();
+ } else if (Feature.startswith("no-"))
+ Ret.Features.push_back("-" + Feature.split("-").second.str());
+ else
+ Ret.Features.push_back("+" + Feature.str());
+ }
+ return Ret;
+}
+
TargetInfo::CallingConvKind
TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
if (getCXXABI() != TargetCXXABI::Microsoft &&
@@ -508,6 +584,10 @@ TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
return CCK_Default;
}
+bool TargetInfo::areDefaultedSMFStillPOD(const LangOptions &LangOpts) const {
+ return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15;
+}
+
LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
switch (TK) {
case OCLTK_Image: