Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ class TargetInfo : public TransferrableTargetInfo,
// TargetInfo Constructor. Default initializes all fields.
TargetInfo(const llvm::Triple &T);

// UserLabelPrefix must match DL's getGlobalPrefix() when interpreted
// as a DataLayout object.
void resetDataLayout(StringRef DL, const char *UserLabelPrefix = "");
/// Set the data layout to the given string.
void resetDataLayout(StringRef DL);

/// Set the data layout based on current triple and ABI.
void resetDataLayout();

// Target features that are read-only and should not be disabled/enabled
// by command line options. Such features are for emitting predefined
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
Float128Format = &llvm::APFloat::IEEEquad();
Ibm128Format = &llvm::APFloat::PPCDoubleDouble();
MCountName = "mcount";
UserLabelPrefix = "_";
UserLabelPrefix = Triple.isOSBinFormatMachO() ? "_" : "";
RegParmMax = 0;
SSERegParmMax = 0;
HasAlignMac68kSupport = false;
Expand Down Expand Up @@ -196,9 +196,10 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
// Out of line virtual dtor for TargetInfo.
TargetInfo::~TargetInfo() {}

void TargetInfo::resetDataLayout(StringRef DL, const char *ULP) {
DataLayoutString = DL.str();
UserLabelPrefix = ULP;
void TargetInfo::resetDataLayout(StringRef DL) { DataLayoutString = DL.str(); }

void TargetInfo::resetDataLayout() {
DataLayoutString = Triple.computeDataLayout(getABI());
}

bool
Expand Down
32 changes: 1 addition & 31 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasD128 = false;
}

setDataLayout();
resetDataLayout();

if (HasNoFP) {
FPU &= ~FPUMode;
Expand Down Expand Up @@ -1628,21 +1628,6 @@ AArch64leTargetInfo::AArch64leTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: AArch64TargetInfo(Triple, Opts) {}

void AArch64leTargetInfo::setDataLayout() {
if (getTriple().isOSBinFormatMachO()) {
if(getTriple().isArch32Bit())
resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-"
"i128:128-n32:64-S128-Fn32",
"_");
else
resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-"
"n32:64-S128-Fn32",
"_");
} else
resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
"i64:64-i128:128-n32:64-S128-Fn32");
}

void AArch64leTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
Builder.defineMacro("__AARCH64EL__");
Expand All @@ -1661,12 +1646,6 @@ void AArch64beTargetInfo::getTargetDefines(const LangOptions &Opts,
AArch64TargetInfo::getTargetDefines(Opts, Builder);
}

void AArch64beTargetInfo::setDataLayout() {
assert(!getTriple().isOSBinFormatMachO());
resetDataLayout("E-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
"i64:64-i128:128-n32:64-S128-Fn32");
}

WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsTargetInfo<AArch64leTargetInfo>(Triple, Opts), Triple(Triple) {
Expand All @@ -1685,15 +1664,6 @@ WindowsARM64TargetInfo::WindowsARM64TargetInfo(const llvm::Triple &Triple,
IntPtrType = SignedLongLong;
}

void WindowsARM64TargetInfo::setDataLayout() {
resetDataLayout(Triple.isOSBinFormatMachO()
? "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:"
"128-n32:64-S128-Fn32"
: "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-"
"i64:64-i128:128-n32:64-S128-Fn32",
Triple.isOSBinFormatMachO() ? "_" : "");
}

TargetInfo::BuiltinVaListKind
WindowsARM64TargetInfo::getBuiltinVaListKind() const {
return TargetInfo::CharPtrBuiltinVaList;
Expand Down
10 changes: 1 addition & 9 deletions clang/lib/Basic/Targets/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ static const unsigned ARM64AddrSpaceMap[] = {
};

class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
virtual void setDataLayout() = 0;
static const TargetInfo::GCCRegAlias GCCRegAliases[];
static const char *const GCCRegNames[];

Expand Down Expand Up @@ -274,9 +273,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
private:
void setDataLayout() override;
MacroBuilder &Builder) const override;
};

template <>
Expand All @@ -297,8 +294,6 @@ class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
WindowsARM64TargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts);

void setDataLayout() override;

BuiltinVaListKind getBuiltinVaListKind() const override;

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
Expand Down Expand Up @@ -332,9 +327,6 @@ class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;

private:
void setDataLayout() override;
};

void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts,
Expand Down
13 changes: 1 addition & 12 deletions clang/lib/Basic/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ namespace targets {
// If you edit the description strings, make sure you update
// getPointerWidthV().

static const char *const DataLayoutStringR600 =
"e-m:e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"
"-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1";

static const char *const DataLayoutStringAMDGCN =
"e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32"
"-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-"
"v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-"
"v2048:2048-n32:64-S32-A5-G1-ni:7:8:9";

const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
llvm::AMDGPUAS::FLAT_ADDRESS, // Default
llvm::AMDGPUAS::GLOBAL_ADDRESS, // opencl_global
Expand Down Expand Up @@ -237,8 +227,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
GPUFeatures(isAMDGCN(Triple) ?
llvm::AMDGPU::getArchAttrAMDGCN(GPUKind) :
llvm::AMDGPU::getArchAttrR600(GPUKind)) {
resetDataLayout(isAMDGCN(getTriple()) ? DataLayoutStringAMDGCN
: DataLayoutStringR600);
resetDataLayout();

setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
!isAMDGCN(Triple));
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Basic/Targets/ARC.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class LLVM_LIBRARY_VISIBILITY ARCTargetInfo : public TargetInfo {
PtrDiffType = SignedInt;
IntPtrType = SignedInt;
UseZeroLengthBitfieldAlignment = true;
resetDataLayout("e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-"
"i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32");
resetDataLayout();
}

void getTargetDefines(const LangOptions &Opts,
Expand Down
43 changes: 3 additions & 40 deletions clang/lib/Basic/Targets/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,12 @@ void ARMTargetInfo::setABIAAPCS() {

ZeroLengthBitfieldBoundary = 0;

// Thumb1 add sp, #imm requires the immediate value be multiple of 4,
// so set preferred for small types to 32.
if (T.isOSBinFormatMachO()) {
resetDataLayout(BigEndian
? "E-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
: "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
"_");
} else if (T.isOSWindows()) {
assert(!BigEndian && "Windows on ARM does not support big endian");
resetDataLayout("e"
"-m:w"
"-p:32:32"
"-Fi8"
"-i64:64"
"-v128:64:128"
"-a:0:32"
"-n32"
"-S64");
} else {
resetDataLayout(BigEndian
? "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
}
resetDataLayout();

// FIXME: Enumerated types are variable width in straight AAPCS.
}

void ARMTargetInfo::setABIAPCS(bool IsAAPCS16) {
const llvm::Triple &T = getTriple();

IsAAPCS = false;

if (IsAAPCS16)
Expand All @@ -89,20 +65,7 @@ void ARMTargetInfo::setABIAPCS(bool IsAAPCS16) {
/// gcc.
ZeroLengthBitfieldBoundary = 32;

if (T.isOSBinFormatMachO() && IsAAPCS16) {
assert(!BigEndian && "AAPCS16 does not support big-endian");
resetDataLayout("e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128", "_");
} else if (T.isOSBinFormatMachO())
resetDataLayout(
BigEndian
? "E-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
: "e-m:o-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32",
"_");
else
resetDataLayout(
BigEndian
? "E-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
: "e-m:e-p:32:32-Fi8-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32");
resetDataLayout();

// FIXME: Override "preferred align" for double and long long.
}
Expand Down Expand Up @@ -1545,7 +1508,7 @@ CygwinARMTargetInfo::CygwinARMTargetInfo(const llvm::Triple &Triple,
this->WCharType = TargetInfo::UnsignedShort;
TLSSupported = false;
DoubleAlign = LongLongAlign = 64;
resetDataLayout("e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64");
resetDataLayout();
}

void CygwinARMTargetInfo::getTargetDefines(const LangOptions &Opts,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/AVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
Int16Type = SignedInt;
Char32Type = UnsignedLong;
SigAtomicType = SignedChar;
resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8:16-a:8");
resetDataLayout();
}

void getTargetDefines(const LangOptions &Opts,
Expand Down
6 changes: 1 addition & 5 deletions clang/lib/Basic/Targets/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ class LLVM_LIBRARY_VISIBILITY BPFTargetInfo : public TargetInfo {
IntMaxType = SignedLong;
Int64Type = SignedLong;
RegParmMax = 5;
if (Triple.getArch() == llvm::Triple::bpfeb) {
resetDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
} else {
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
}
resetDataLayout();
MaxAtomicPromoteWidth = 64;
MaxAtomicInlineWidth = 64;
TLSSupported = false;
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Basic/Targets/CSKY.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public TargetInfo {

UseZeroLengthBitfieldAlignment = true;
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
resetDataLayout("e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-"
"v64:32:32-v128:32:32-a:0:32-Fi32-n32");

setABI("abiv2");
resetDataLayout();
}

StringRef getABI() const override { return ABI; }
Expand Down
6 changes: 1 addition & 5 deletions clang/lib/Basic/Targets/DirectX.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
NoAsmVariants = true;
PlatformMinVersion = Triple.getOSVersion();
PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
// TODO: We need to align vectors on the element size generally, but for now
// we hard code this for 3-element 32- and 64-bit vectors as a workaround.
// See https://github.com/llvm/llvm-project/issues/123968
resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
"32-f64:64-n8:16:32:64-v48:16:16-v96:32:32-v192:64:64");
resetDataLayout();
TheCXXABI.set(TargetCXXABI::GenericItanium);
}
bool useFP16ConversionIntrinsics() const override { return false; }
Expand Down
8 changes: 1 addition & 7 deletions clang/lib/Basic/Targets/Hexagon.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ class LLVM_LIBRARY_VISIBILITY HexagonTargetInfo : public TargetInfo {
public:
HexagonTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
// Specify the vector alignment explicitly. For v512x1, the calculated
// alignment would be 512*alignment(i1), which is 512 bytes, instead of
// the required minimum of 64 bytes.
resetDataLayout(
"e-m:e-p:32:32:32-a:0-n16:32-"
"i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"
"v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048");
resetDataLayout();
SizeType = UnsignedInt;
PtrDiffType = SignedInt;
IntPtrType = SignedInt;
Expand Down
10 changes: 1 addition & 9 deletions clang/lib/Basic/Targets/Lanai.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ class LLVM_LIBRARY_VISIBILITY LanaiTargetInfo : public TargetInfo {
public:
LanaiTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
// Description string has to be kept in sync with backend.
resetDataLayout("E" // Big endian
"-m:e" // ELF name manging
"-p:32:32" // 32 bit pointers, 32 bit aligned
"-i64:64" // 64 bit integers, 64 bit aligned
"-a:0:32" // 32 bit alignment of objects of aggregate type
"-n32" // 32 bit native integer width
"-S64" // 64 bit natural stack alignment
);
resetDataLayout();

// Setting RegParmMax equal to what mregparm was set to in the old
// toolchain
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/Targets/LoongArch.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
IntPtrType = SignedInt;
PtrDiffType = SignedInt;
SizeType = UnsignedInt;
resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
// TODO: select appropriate ABI.
setABI("ilp32d");
resetDataLayout();
}

bool setABI(const std::string &Name) override {
Expand All @@ -158,9 +158,9 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
IntMaxType = Int64Type = SignedLong;
HasUnalignedAccess = true;
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
// TODO: select appropriate ABI.
setABI("lp64d");
resetDataLayout();
}

bool setABI(const std::string &Name) override {
Expand Down
26 changes: 1 addition & 25 deletions clang/lib/Basic/Targets/M68k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,7 @@ namespace targets {
M68kTargetInfo::M68kTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: TargetInfo(Triple), TargetOpts(Opts) {

std::string Layout;

// M68k is Big Endian
Layout += "E";

// FIXME how to wire it with the used object format?
Layout += "-m:e";

// M68k pointers are always 32 bit wide even for 16-bit CPUs
Layout += "-p:32:16:32";

// M68k integer data types
Layout += "-i8:8:8-i16:16:16-i32:16:32";

// FIXME no floats at the moment

// The registers can hold 8, 16, 32 bits
Layout += "-n8:16:32";

// 16 bit alignment for both stack and aggregate
// in order to conform to ABI used by GCC
Layout += "-a:0:16-S16";

resetDataLayout(Layout);
resetDataLayout();

SizeType = UnsignedInt;
PtrDiffType = SignedInt;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/MSP430.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LLVM_LIBRARY_VISIBILITY MSP430TargetInfo : public TargetInfo {
IntPtrType = SignedInt;
PtrDiffType = SignedInt;
SigAtomicType = SignedLong;
resetDataLayout("e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16");
resetDataLayout();
}
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
Expand Down
Loading
Loading