diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1616,7 +1616,7 @@ virtual bool validateOpenCLTarget(const LangOptions &Opts, DiagnosticsEngine &Diags) const; - virtual void setAuxTarget(const TargetInfo *Aux) {} + virtual void setAuxTarget(IntrusiveRefCntPtr Aux) {} /// Whether target allows debuginfo types for decl only variables/functions. virtual bool allowDebugInfoForExternalRef() const { return false; } diff --git a/clang/include/clang/Basic/TargetOptions.h b/clang/include/clang/Basic/TargetOptions.h --- a/clang/include/clang/Basic/TargetOptions.h +++ b/clang/include/clang/Basic/TargetOptions.h @@ -28,10 +28,6 @@ /// The name of the target triple to compile for. std::string Triple; - /// When compiling for the device side, contains the triple used to compile - /// for the host. - std::string HostTriple; - /// If given, the name of the target CPU to generate code for. std::string CPU; diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h --- a/clang/lib/Basic/Targets/AMDGPU.h +++ b/clang/lib/Basic/Targets/AMDGPU.h @@ -425,7 +425,7 @@ ? ~0 : 0; } - void setAuxTarget(const TargetInfo *Aux) override; + void setAuxTarget(IntrusiveRefCntPtr Aux) override; bool hasBitIntType() const override { return true; } diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -452,7 +452,7 @@ Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize)); } -void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) { +void AMDGPUTargetInfo::setAuxTarget(IntrusiveRefCntPtr Aux) { assert(HalfFormat == Aux->HalfFormat); assert(FloatFormat == Aux->FloatFormat); assert(DoubleFormat == Aux->DoubleFormat); @@ -462,7 +462,7 @@ // supported by AMDGPU. Therefore keep its own format for these two types. auto SaveLongDoubleFormat = LongDoubleFormat; auto SaveFloat128Format = Float128Format; - copyAuxTarget(Aux); + copyAuxTarget(Aux.get()); LongDoubleFormat = SaveLongDoubleFormat; Float128Format = SaveFloat128Format; // For certain builtin types support on the host target, claim they are diff --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h --- a/clang/lib/Basic/Targets/NVPTX.h +++ b/clang/lib/Basic/Targets/NVPTX.h @@ -60,12 +60,14 @@ static const Builtin::Info BuiltinInfo[]; CudaArch GPU; uint32_t PTXVersion; - std::unique_ptr HostTarget; + IntrusiveRefCntPtr HostTarget; public: NVPTXTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts, unsigned TargetPointerWidth); + void setAuxTarget(IntrusiveRefCntPtr Aux) override; + void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override; diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp --- a/clang/lib/Basic/Targets/NVPTX.cpp +++ b/clang/lib/Basic/Targets/NVPTX.cpp @@ -82,32 +82,28 @@ else resetDataLayout("e-i64:64-i128:128-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()) - 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; + // Set defaults, which will be overridden if there is a host/aux target. + 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"); } +} + +void NVPTXTargetInfo::setAuxTarget(IntrusiveRefCntPtr Aux) { + // Retain the host TargetInfo to use later for checking calling conventions. + HostTarget = Aux; // Copy properties from host target. PointerWidth = HostTarget->getPointerWidth(/* AddrSpace = */ 0); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -118,7 +118,6 @@ TO->CPU = getFrontendOpts().AuxTargetCPU.getValue(); if (getFrontendOpts().AuxTargetFeatures) TO->FeaturesAsWritten = getFrontendOpts().AuxTargetFeatures.getValue(); - TO->HostTriple = getTarget().getTriple().str(); setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), TO)); } @@ -149,8 +148,8 @@ // Adjust target options based on codegen options. getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts()); - if (auto *Aux = getAuxTarget()) - getTarget().setAuxTarget(Aux); + if (AuxTarget) + getTarget().setAuxTarget(AuxTarget); return true; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4472,17 +4472,6 @@ } } - if (LangOpts.CUDA) { - // During CUDA device-side compilation, the aux triple is the - // triple used for host compilation. - if (LangOpts.CUDAIsDevice) - Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple; - } - - // Set the triple of the host for OpenMP device compile. - if (LangOpts.OpenMPIsDevice) - Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple; - ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags, T, Res.getFrontendOpts().OutputFile, LangOpts);