Skip to content

Commit 7d3e836

Browse files
authored
[SYCL][NVPTX][NFC] Refactor NVPTX target configuration (#3535)
Avoid using `-sycldevice` for configuring NVPTX target.
1 parent 347e41c commit 7d3e836

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

clang/lib/Basic/Targets/NVPTX.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
6262
.Default(32);
6363
}
6464

65-
// FIXME: Needed for compiling SYCL to PTX.
66-
TLSSupported = Triple.getEnvironment() == llvm::Triple::SYCLDevice;
65+
TLSSupported = false;
6766
VLASupported = false;
6867
AddrSpaceMap = &NVPTXAddrSpaceMap;
6968
GridValues = llvm::omp::NVPTXGpuGridValues;

clang/lib/Basic/Targets/NVPTX.h

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public TargetInfo {
171171
return CCCR_Warning;
172172
}
173173

174+
void adjust(LangOptions &Opts) override {
175+
TargetInfo::adjust(Opts);
176+
// FIXME: Needed for compiling SYCL to PTX.
177+
TLSSupported = TLSSupported || Opts.SYCLIsDevice;
178+
}
179+
174180
bool hasExtIntType() const override { return true; }
175181
};
176182
} // namespace targets

llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ void NVPTXPassConfig::addIRPasses() {
304304
const NVPTXSubtarget &ST = *getTM<NVPTXTargetMachine>().getSubtargetImpl();
305305
addPass(createNVVMReflectPass(ST.getSmVersion()));
306306

307-
if (getTM<NVPTXTargetMachine>().getTargetTriple().getOS() == Triple::CUDA &&
308-
getTM<NVPTXTargetMachine>().getTargetTriple().getEnvironment() == Triple::SYCLDevice) {
307+
// FIXME: should the target triple check be done by the pass itself?
308+
// See createNVPTXLowerArgsPass as an example
309+
if (getTM<NVPTXTargetMachine>().getTargetTriple().getOS() == Triple::CUDA) {
309310
addPass(createGlobalOffsetPass());
310311
addPass(createLocalAccessorToSharedMemoryPass());
311312
}

llvm/lib/Target/NVPTX/SYCL/LocalAccessorToSharedMemory.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class LocalAccessorToSharedMemory : public ModulePass {
3838

3939
bool runOnModule(Module &M) override {
4040
// Invariant: This pass is only intended to operate on SYCL kernels being
41-
// compiled to the `nvptx{,64}-nvidia-cuda-sycldevice` triple.
41+
// compiled to the `nvptx{,64}-nvidia-cuda` triple.
42+
// TODO: make sure that non-SYCL kernels are not impacted.
4243
if (skipModule(M))
4344
return false;
4445

@@ -48,7 +49,9 @@ class LocalAccessorToSharedMemory : public ModulePass {
4849
// Access `nvvm.annotations` to determine which functions are kernel entry
4950
// points.
5051
auto NvvmMetadata = M.getNamedMetadata("nvvm.annotations");
51-
assert(NvvmMetadata && "IR compiled to PTX must have nvvm.annotations");
52+
if (!NvvmMetadata)
53+
return false;
54+
5255
for (auto MetadataNode : NvvmMetadata->operands()) {
5356
if (MetadataNode->getNumOperands() != 3)
5457
continue;

0 commit comments

Comments
 (0)