Skip to content

Commit 0fecc48

Browse files
woshiyifeiAlexeySotkin
authored andcommitted
Enable mem2reg if -cl-opt-disable was not specified
1 parent d94ff34 commit 0fecc48

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

common_clang.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,14 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
325325
SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
326326
std::ostream OS(&StreamBuf);
327327
std::string Err;
328-
success = llvm::writeSpirv(M.get(), OS, Err);
328+
if (!(optionsParser.hasOptDisable())){
329+
SPIRV::TranslatorOpts OCLOpts;
330+
OCLOpts.enableAllExtensions();
331+
OCLOpts.setMemToRegEnabled(true);
332+
success = llvm::writeSpirv(M.get(), OCLOpts, OS, Err);
333+
}
334+
else
335+
success = llvm::writeSpirv(M.get(), OS, Err);
329336
err_ostream << Err.c_str();
330337
err_ostream.flush();
331338
}

options.h

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

148148
//
149149
// Validates and prepares the effective options to pass to clang upon
@@ -175,6 +175,7 @@ class CompileOptionsParser {
175175
std::string getEffectiveOptionsAsString() const;
176176

177177
bool hasEmitSPIRV() const { return m_emitSPIRV; }
178+
bool hasOptDisable() const { return m_optDisable; }
178179

179180
private:
180181
OpenCLCompileOptTable m_optTbl;
@@ -183,6 +184,7 @@ class CompileOptionsParser {
183184
llvm::SmallVector<const char *, 16> m_effectiveArgsRaw;
184185
std::string m_sourceName;
185186
bool m_emitSPIRV;
187+
bool m_optDisable;
186188
};
187189

188190
// Tokenize a string into tokens separated by any char in 'delims'.

options_compile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ void CompileOptionsParser::processOptions(const char *pszOptions,
244244
for (ArgsVector::iterator it = m_effectiveArgs.begin(),
245245
end = m_effectiveArgs.end();
246246
it != end; ++it) {
247-
if (it->compare("-emit-spirv") == 0) {
247+
if (it->compare("-cl-opt-disable") == 0) {
248+
m_optDisable = true;
249+
}
250+
else if (it->compare("-emit-spirv") == 0) {
248251
m_effectiveArgsRaw.push_back("-emit-llvm-bc");
249252
m_emitSPIRV = true;
250253
continue;

0 commit comments

Comments
 (0)