Skip to content

Commit ff0f21d

Browse files
mdtoguchivladimirlaz
authored andcommitted
[SYCL] remove usage of SPIRV library and generate SPIRV binary via llvm-spirv
Signed-off-by: Vladimir Lazarev <[email protected]> Signed-off-by: Michael D Toguchi <[email protected]>
1 parent fbffaab commit ff0f21d

File tree

22 files changed

+102
-73
lines changed

22 files changed

+102
-73
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate transcendental
218218
LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
219219

220220
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
221-
LANGOPT(SYCLUseBitcode , 1, 0, "Generate bitcode for SYCL")
222221
LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
223222

224223
LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")

clang/include/clang/CodeGen/BackendUtil.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace clang {
3030
enum BackendAction {
3131
Backend_EmitAssembly, ///< Emit native assembly files
3232
Backend_EmitBC, ///< Emit LLVM bitcode files
33-
Backend_EmitSPIRV, ///< Emit SPIR-V bitcode files
3433
Backend_EmitLL, ///< Emit human-readable LLVM assembly
3534
Backend_EmitNothing, ///< Don't emit anything (benchmarking mode)
3635
Backend_EmitMCNull, ///< Run CodeGen, but don't emit anything

clang/include/clang/CodeGen/CodeGenAction.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@ class EmitBCAction : public CodeGenAction {
9292
EmitBCAction(llvm::LLVMContext *_VMContext = nullptr);
9393
};
9494

95-
class EmitSPIRVAction : public CodeGenAction {
96-
virtual void anchor();
97-
public:
98-
EmitSPIRVAction(llvm::LLVMContext *_VMContext = nullptr);
99-
};
100-
10195
class EmitLLVMAction : public CodeGenAction {
10296
virtual void anchor();
10397
public:

clang/include/clang/Driver/Action.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ class Action {
7272
OffloadBundlingJobClass,
7373
OffloadUnbundlingJobClass,
7474
OffloadWrappingJobClass,
75+
SPIRVTranslatorJobClass,
7576

7677
JobClassFirst = PreprocessJobClass,
77-
JobClassLast = OffloadWrappingJobClass
78+
JobClassLast = SPIRVTranslatorJobClass
7879
};
7980

8081
// The offloading kind determines if this action is binded to a particular
@@ -626,6 +627,17 @@ class OffloadWrappingJobAction : public JobAction {
626627
}
627628
};
628629

630+
class SPIRVTranslatorJobAction : public JobAction {
631+
void anchor() override;
632+
633+
public:
634+
SPIRVTranslatorJobAction(Action *Input, types::ID OutputType);
635+
636+
static bool classof(const Action *A) {
637+
return A->getKind() == SPIRVTranslatorJobClass;
638+
}
639+
};
640+
629641
} // namespace driver
630642
} // namespace clang
631643

clang/include/clang/Driver/ToolChain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,15 @@ class ToolChain {
130130
mutable std::unique_ptr<Tool> Link;
131131
mutable std::unique_ptr<Tool> OffloadBundler;
132132
mutable std::unique_ptr<Tool> OffloadWrapper;
133+
mutable std::unique_ptr<Tool> SPIRVTranslator;
133134

134135
Tool *getClang() const;
135136
Tool *getAssemble() const;
136137
Tool *getLink() const;
137138
Tool *getClangAs() const;
138139
Tool *getOffloadBundler() const;
139140
Tool *getOffloadWrapper() const;
141+
Tool *getSPIRVTranslator() const;
140142

141143
mutable std::unique_ptr<SanitizerArgs> SanitizerArguments;
142144
mutable std::unique_ptr<XRayArgs> XRayArguments;

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ enum ActionKind {
5757
/// Emit a .bc file.
5858
EmitBC,
5959

60-
/// Emit a .spv file.
61-
EmitSPIRV,
62-
6360
/// Translate input source into HTML.
6461
EmitHTML,
6562

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
#include "llvm/SYCL/ASFixer.h"
7171
#include <memory>
7272

73-
#include "LLVMSPIRVLib.h"
7473
namespace SPIRV {
7574
extern llvm::cl::opt<bool> SPIRVNoDerefAttr;
7675
}
@@ -807,7 +806,6 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
807806

808807
bool UsesCodeGen = (Action != Backend_EmitNothing &&
809808
Action != Backend_EmitBC &&
810-
Action != Backend_EmitSPIRV &&
811809
Action != Backend_EmitLL);
812810
CreateTargetMachine(UsesCodeGen);
813811

@@ -841,6 +839,10 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
841839
break;
842840

843841
case Backend_EmitBC:
842+
if (LangOpts.SYCLIsDevice) {
843+
PerModulePasses.add(createASFixerPass());
844+
PerModulePasses.add(createDeadCodeEliminationPass());
845+
}
844846
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
845847
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
846848
ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
@@ -871,24 +873,6 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
871873
}
872874
break;
873875

874-
case Backend_EmitSPIRV:
875-
if (LangOpts.SYCLIsDevice) {
876-
// TODO: SPIRVNoDerefAttr is not modeled when using the bitcode pass
877-
SPIRV::SPIRVNoDerefAttr = true;
878-
// TODO: this pass added to work around missing linkonce_odr in SPIR-V
879-
PerModulePasses.add(
880-
createAlwaysInlinerLegacyPass(true /*InsertLifetimeIntrinsics*/));
881-
PerModulePasses.add(createASFixerPass());
882-
PerModulePasses.add(createDeadCodeEliminationPass());
883-
}
884-
if (LangOpts.SYCLUseBitcode)
885-
PerModulePasses.add(
886-
createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, false));
887-
else
888-
PerModulePasses.add(createSPIRVWriterPass(*OS));
889-
890-
break;
891-
892876
case Backend_EmitLL:
893877
PerModulePasses.add(
894878
createPrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists));
@@ -1203,6 +1187,10 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12031187
break;
12041188

12051189
case Backend_EmitBC:
1190+
if (LangOpts.SYCLIsDevice) {
1191+
CodeGenPasses.add(createASFixerPass());
1192+
CodeGenPasses.add(createDeadCodeEliminationPass());
1193+
}
12061194
if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
12071195
if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
12081196
ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
@@ -1232,18 +1220,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12321220
}
12331221
break;
12341222

1235-
case Backend_EmitSPIRV:
1236-
if (LangOpts.SYCLIsDevice) {
1237-
SPIRV::SPIRVNoDerefAttr = true;
1238-
// TODO: this pass added to work around missing linkonce_odr in SPIR-V
1239-
CodeGenPasses.add(
1240-
createAlwaysInlinerLegacyPass(true /*InsertLifetimeIntrinsics*/));
1241-
CodeGenPasses.add(createASFixerPass());
1242-
CodeGenPasses.add(createDeadCodeEliminationPass());
1243-
}
1244-
CodeGenPasses.add(createSPIRVWriterPass(*OS));
1245-
break;
1246-
12471223
case Backend_EmitLL:
12481224
MPM.addPass(PrintModulePass(*OS, "", CodeGenOpts.EmitLLVMUseLists));
12491225
break;

clang/lib/CodeGen/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ set(LLVM_LINK_COMPONENTS
2424
Target
2525
TransformUtils
2626
ASFixer
27-
SPIRVLib
2827
)
2928

3029
# In a standard Clang+LLVM build, we need to generate intrinsics before

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,6 @@ GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) {
836836
return CI.createDefaultOutputFile(false, InFile, "ll");
837837
case Backend_EmitBC:
838838
return CI.createDefaultOutputFile(true, InFile, "bc");
839-
case Backend_EmitSPIRV:
840-
return CI.createDefaultOutputFile(true, InFile, "spv");
841839
case Backend_EmitNothing:
842840
return nullptr;
843841
case Backend_EmitMCNull:
@@ -1059,10 +1057,6 @@ void EmitBCAction::anchor() { }
10591057
EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext)
10601058
: CodeGenAction(Backend_EmitBC, _VMContext) {}
10611059

1062-
void EmitSPIRVAction::anchor() { }
1063-
EmitSPIRVAction::EmitSPIRVAction(llvm::LLVMContext *_VMContext)
1064-
: CodeGenAction(Backend_EmitSPIRV, _VMContext) {}
1065-
10661060
void EmitLLVMAction::anchor() { }
10671061
EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext)
10681062
: CodeGenAction(Backend_EmitLL, _VMContext) {}

clang/lib/Driver/Action.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,9 @@ void OffloadWrappingJobAction::anchor() {}
415415
OffloadWrappingJobAction::OffloadWrappingJobAction(Action *Input,
416416
types::ID Type)
417417
: JobAction(OffloadWrappingJobClass, Input, Type) {}
418+
419+
void SPIRVTranslatorJobAction::anchor() {}
420+
421+
SPIRVTranslatorJobAction::SPIRVTranslatorJobAction(Action *Input,
422+
types::ID Type)
423+
: JobAction(SPIRVTranslatorJobClass, Input, Type) {}

0 commit comments

Comments
 (0)