Skip to content

Commit d4ce529

Browse files
committed
Enable mem2reg if -cl-opt-disable was not specified
1 parent 9f0c2c0 commit d4ce529

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

common_clang.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ 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+
SPIRV::TranslatorOpts SPIRVOpts;
329+
SPIRVOpts.enableAllExtensions();
330+
if (!optionsParser.hasOptDisable()) {
331+
SPIRVOpts.setMemToRegEnabled(true);
332+
}
333+
success = llvm::writeSpirv(M.get(), SPIRVOpts, OS, Err);
329334
err_ostream << Err.c_str();
330335
err_ostream.flush();
331336
}

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
@@ -242,7 +242,10 @@ void CompileOptionsParser::processOptions(const char *pszOptions,
242242
for (ArgsVector::iterator it = m_effectiveArgs.begin(),
243243
end = m_effectiveArgs.end();
244244
it != end; ++it) {
245-
if (it->compare("-emit-spirv") == 0) {
245+
if (it->compare("-cl-opt-disable") == 0) {
246+
m_optDisable = true;
247+
}
248+
else if (it->compare("-emit-spirv") == 0) {
246249
m_effectiveArgsRaw.push_back("-emit-llvm-bc");
247250
m_emitSPIRV = true;
248251
continue;

0 commit comments

Comments
 (0)