summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2017-01-05 16:53:21 +0000
committerJustin Lebar <jlebar@google.com>2017-01-05 16:53:21 +0000
commitb6626593555ad2542c2d3800befa7c9d193032d1 (patch)
tree5b60ddbf0104e86079c8df37c9fbd65bbfb295bf /clang/lib
parent0203f2c26e49afedcbcf5f6a2c0c0d4a16169364 (diff)
downloadbcm5719-llvm-b6626593555ad2542c2d3800befa7c9d193032d1.tar.gz
bcm5719-llvm-b6626593555ad2542c2d3800befa7c9d193032d1.zip
[CUDA] More correctly inherit primitive types from the host during device compilation.
Summary: CUDA lets users share structs between the host and device, so for that and other reasons, primitive types such as ptrdiff_t should be the same on both sides of the compilation. Our code to do this wasn't entirely successful. In particular, we did a bunch of work during the NVPTXTargetInfo constructor, only to override it in the NVPTX{32,64}TargetInfo constructors. It worked well enough on Linux and Mac, but Windows is LLP64, which is different enough to break it. This patch removes the NVPTX{32,64}TargetInfo classes entirely and fixes the bug described above. Reviewers: tra Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28322 llvm-svn: 291135
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Basic/Targets.cpp68
1 files changed, 35 insertions, 33 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index b77233c2c0a..4716b5e9b1c 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -1751,30 +1751,57 @@ class NVPTXTargetInfo : public TargetInfo {
static const char *const GCCRegNames[];
static const Builtin::Info BuiltinInfo[];
CudaArch GPU;
+ std::unique_ptr<TargetInfo> HostTarget;
public:
- NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+ NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts,
+ unsigned TargetPointerWidth)
: TargetInfo(Triple) {
+ assert((TargetPointerWidth == 32 || TargetPointerWidth == 64) &&
+ "NVPTX only supports 32- and 64-bit modes.");
+
TLSSupported = false;
- LongWidth = LongAlign = 64;
AddrSpaceMap = &NVPTXAddrSpaceMap;
UseAddrSpaceMapMangling = true;
+
// Define available target features
// These must be defined in sorted order!
NoAsmVariants = true;
GPU = CudaArch::SM_20;
+ if (TargetPointerWidth == 32)
+ resetDataLayout("e-p:32:32-i64:64-v16:16-v32:32-n16:32:64");
+ else
+ resetDataLayout("e-i64:64-v16:16-v32:32-n16:32:64");
+
// If possible, get a TargetInfo for our host triple, so we can match its
// types.
llvm::Triple HostTriple(Opts.HostTriple);
- if (HostTriple.isNVPTX())
- return;
- std::unique_ptr<TargetInfo> HostTarget(
- AllocateTarget(llvm::Triple(Opts.HostTriple), Opts));
+ if (!HostTriple.isNVPTX())
+ HostTarget.reset(AllocateTarget(llvm::Triple(Opts.HostTriple), Opts));
+
+ // If no host target, make some guesses about the data layout and return.
if (!HostTarget) {
+ LongWidth = LongAlign = TargetPointerWidth;
+ PointerWidth = PointerAlign = TargetPointerWidth;
+ switch (TargetPointerWidth) {
+ case 32:
+ SizeType = TargetInfo::UnsignedInt;
+ PtrDiffType = TargetInfo::SignedInt;
+ IntPtrType = TargetInfo::SignedInt;
+ break;
+ case 64:
+ SizeType = TargetInfo::UnsignedLong;
+ PtrDiffType = TargetInfo::SignedLong;
+ IntPtrType = TargetInfo::SignedLong;
+ break;
+ default:
+ llvm_unreachable("TargetPointerWidth must be 32 or 64");
+ }
return;
}
+ // Copy properties from host target.
PointerWidth = HostTarget->getPointerWidth(/* AddrSpace = */ 0);
PointerAlign = HostTarget->getPointerAlign(/* AddrSpace = */ 0);
BoolWidth = HostTarget->getBoolWidth();
@@ -1953,31 +1980,6 @@ ArrayRef<const char *> NVPTXTargetInfo::getGCCRegNames() const {
return llvm::makeArrayRef(GCCRegNames);
}
-class NVPTX32TargetInfo : public NVPTXTargetInfo {
-public:
- NVPTX32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
- : NVPTXTargetInfo(Triple, Opts) {
- LongWidth = LongAlign = 32;
- PointerWidth = PointerAlign = 32;
- SizeType = TargetInfo::UnsignedInt;
- PtrDiffType = TargetInfo::SignedInt;
- IntPtrType = TargetInfo::SignedInt;
- resetDataLayout("e-p:32:32-i64:64-v16:16-v32:32-n16:32:64");
- }
-};
-
-class NVPTX64TargetInfo : public NVPTXTargetInfo {
-public:
- NVPTX64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
- : NVPTXTargetInfo(Triple, Opts) {
- PointerWidth = PointerAlign = 64;
- SizeType = TargetInfo::UnsignedLong;
- PtrDiffType = TargetInfo::SignedLong;
- IntPtrType = TargetInfo::SignedLong;
- resetDataLayout("e-i64:64-v16:16-v32:32-n16:32:64");
- }
-};
-
static const unsigned AMDGPUAddrSpaceMap[] = {
1, // opencl_global
3, // opencl_local
@@ -8735,9 +8737,9 @@ static TargetInfo *AllocateTarget(const llvm::Triple &Triple,
}
case llvm::Triple::nvptx:
- return new NVPTX32TargetInfo(Triple, Opts);
+ return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/32);
case llvm::Triple::nvptx64:
- return new NVPTX64TargetInfo(Triple, Opts);
+ return new NVPTXTargetInfo(Triple, Opts, /*TargetPointerWidth=*/64);
case llvm::Triple::amdgcn:
case llvm::Triple::r600:
OpenPOWER on IntegriCloud