Skip to content

Commit c2a27ea

Browse files
authored
Merge pull request intel#232 from haonanya/emit-spirv-text
Emit text format of spir-v from opencl-clang
2 parents 76f0b17 + 9089407 commit c2a27ea

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

common_clang.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Copyright (c) Intel Corporation (2009-2017).
7979
#include <thread>
8080
#endif
8181

82+
namespace SPIRV {
83+
// Use textual format for SPIRV.
84+
extern bool SPIRVUseTextFormat;
85+
} // namespace SPIRV
86+
8287
using namespace Intel::OpenCL::ClangFE;
8388

8489
static volatile bool lazyCCInit =
@@ -303,8 +308,10 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
303308
// llvm::remove_fatal_error_handler();
304309
err_ostream.flush();
305310

306-
if (success && optionsParser.hasEmitSPIRV()) {
311+
if (success && (optionsParser.hasEmitSPIRV() || optionsParser.hasEmitSPIRVText())) {
307312
// Translate LLVM IR to SPIR-V.
313+
if (optionsParser.hasEmitSPIRVText())
314+
SPIRV::SPIRVUseTextFormat = true;
308315
llvm::StringRef LLVM_IR(static_cast<const char*>(pResult->GetIR()),
309316
pResult->GetIRSize());
310317
std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer(LLVM_IR, pResult->GetIRName(), false);

opencl_clang_options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ def target_triple : Separate<["-"], "target-triple">, HelpText<"Specify target
4040
def spir_std_1_0: Flag<["-"], "spir-std=1.0">;
4141
def spir_std_1_2: Flag<["-"], "spir-std=1.2">;
4242
def x : Separate<["-"], "x">;
43+
def Xclang : Separate<["-"], "Xclang">, HelpText<"Pass an additional option to clang -cc1 invocation">;

options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class EffectiveOptionsFilter {
142142
class CompileOptionsParser {
143143
public:
144144
CompileOptionsParser(const char *pszOpenCLVersion)
145-
: m_commonFilter(pszOpenCLVersion), m_emitSPIRV(false), m_optDisable(false) {}
145+
: m_commonFilter(pszOpenCLVersion), m_emitSPIRV(false), m_emitSPIRVText(false), m_optDisable(false) {}
146146

147147
//
148148
// Validates and prepares the effective options to pass to clang upon
@@ -171,6 +171,7 @@ class CompileOptionsParser {
171171

172172
bool hasEmitSPIRV() const { return m_emitSPIRV; }
173173
bool hasOptDisable() const { return m_optDisable; }
174+
bool hasEmitSPIRVText() const { return m_emitSPIRVText; }
174175

175176
private:
176177
OpenCLCompileOptTable m_optTbl;
@@ -179,6 +180,7 @@ class CompileOptionsParser {
179180
llvm::SmallVector<const char *, 16> m_effectiveArgsRaw;
180181
std::string m_sourceName;
181182
bool m_emitSPIRV;
183+
bool m_emitSPIRVText;
182184
bool m_optDisable;
183185
};
184186

options_compile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ std::string EffectiveOptionsFilter::processOptions(const OpenCLArgList &args,
160160
effectiveArgs.push_back("-debug-info-kind=line-tables-only");
161161
effectiveArgs.push_back("-dwarf-version=4");
162162
break;
163+
case OPT_COMPILE_Xclang:
164+
effectiveArgs.push_back((*it)->getValue());
165+
break;
163166
}
164167
}
165168

@@ -257,6 +260,10 @@ void CompileOptionsParser::processOptions(const char *pszOptions,
257260
m_effectiveArgsRaw.push_back("-emit-llvm-bc");
258261
m_emitSPIRV = true;
259262
continue;
263+
}else if (it->compare("-emit-spirv-text") == 0) {
264+
m_effectiveArgsRaw.push_back("-emit-llvm-bc");
265+
m_emitSPIRVText = true;
266+
continue;
260267
}
261268
m_effectiveArgsRaw.push_back(it->c_str());
262269
}

0 commit comments

Comments
 (0)