Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -2002,16 +2002,6 @@ return llvm::makeArrayRef(GCCRegNames); } -static const unsigned AMDGPUAddrSpaceMap[] = { - 1, // opencl_global - 3, // opencl_local - 2, // opencl_constant - 4, // opencl_generic - 1, // cuda_device - 2, // cuda_constant - 3 // cuda_shared -}; - // If you edit the description strings, make sure you update // getPointerWidthV(). @@ -2019,15 +2009,65 @@ "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"; -static const char *const DataLayoutStringSI = +static const char *const DataLayoutStringSIOld = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5: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"; +static const char *const DataLayoutStringSINew = + "e-p:64:64-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5: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"; + class AMDGPUTargetInfo final : public TargetInfo { static const Builtin::Info BuiltinInfo[]; static const char * const GCCRegNames[]; + struct AddrSpace { + unsigned Generic, Global, Local, Constant, Private; + bool UseNew; + AddrSpace(bool UseNew_ = false){ + reset(UseNew_); + } + void reset(bool UseNew_) { + UseNew = UseNew_; + if (UseNew) { + Generic = 0; + Global = 1; + Local = 3; + Constant = 4; + Private = 5; + } else { + Generic = 4; + Global = 1; + Local = 3; + Constant = 2; + Private = 0; + } + } + const LangAS::Map *getMap() { + static LangAS::Map OldMap = { + 1, // opencl_global + 3, // opencl_local + 2, // opencl_constant + 4, // opencl_generic + 1, // cuda_device + 2, // cuda_constant + 3 // cuda_shared + }; + static LangAS::Map NewMap = { + 1, // opencl_global + 3, // opencl_local + 4, // opencl_constant + 0, // opencl_generic + 1, // cuda_device + 4, // cuda_constant + 3 // cuda_shared + }; + return UseNew ? &NewMap : &OldMap; + } + }; + /// \brief The GPU profiles supported by the AMDGPU target. enum GPUKind { GK_NONE, @@ -2061,17 +2101,22 @@ hasFP64(false), hasFMAF(false), hasLDEXPF(false), - hasFullSpeedFP32Denorms(false){ + hasFullSpeedFP32Denorms(false) { if (getTriple().getArch() == llvm::Triple::amdgcn) { hasFP64 = true; hasFMAF = true; hasLDEXPF = true; } + auto UseNewAddrMap = Triple.getEnvironment() == llvm::Triple::AMDNAS || + Triple.getEnvironment() == llvm::Triple::AMDNASCL; + AS.reset(UseNewAddrMap); resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ? - DataLayoutStringSI : DataLayoutStringR600); + (UseNewAddrMap ? DataLayoutStringSINew : + DataLayoutStringSIOld) + : DataLayoutStringR600); - AddrSpaceMap = &AMDGPUAddrSpaceMap; + AddrSpaceMap = AS.getMap(); UseAddrSpaceMapMangling = true; } @@ -2079,14 +2124,10 @@ if (GPU <= GK_CAYMAN) return 32; - switch(AddrSpace) { - default: - return 64; - case 0: - case 3: - case 5: - return 32; + if (AddrSpace == AS.Private || AddrSpace == AS.Local) { + return 32; } + return 64; } uint64_t getPreferredPointerWidth(unsigned AddrSpace) const override { @@ -2283,12 +2324,13 @@ /// DWARF. Optional getDWARFAddressSpace( unsigned AddressSpace) const override { - switch (AddressSpace) { - case 0: // LLVM Private. - return 1; // DWARF Private. - case 3: // LLVM Local. - return 2; // DWARF Local. - default: + const unsigned DWARF_Private = 1; + const unsigned DWARF_Local = 2; + if (AddressSpace == AS.Private) { + return DWARF_Private; + } else if (AddressSpace == AS.Local) { + return DWARF_Local; + } else { return None; } } @@ -2309,6 +2351,8 @@ uint64_t getNullPointerValue(unsigned AS) const override { return AS == LangAS::opencl_local ? ~0 : 0; } + + AddrSpace AS; }; const Builtin::Info AMDGPUTargetInfo::BuiltinInfo[] = { Index: test/CodeGenOpenCL/amdgpu-env-amdnas.cl =================================================================== --- /dev/null +++ test/CodeGenOpenCL/amdgpu-env-amdnas.cl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -O0 -triple amdgcn -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -O0 -triple amdgcn---opencl -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -O0 -triple amdgcn---amdnas -emit-llvm -o - | FileCheck -check-prefix=NEW %s +// RUN: %clang_cc1 %s -O0 -triple amdgcn---amdnascl -emit-llvm -o - | FileCheck -check-prefix=NEW %s + +// CHECK: target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5: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" +// NEW: target datalayout = "e-p:64:64-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5: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" +void foo(void) {} +