Skip to content

Commit

Permalink
Enable mem2reg if -cl-opt-disable was not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
woshiyifei committed May 21, 2020
1 parent 9f0c2c0 commit d4ce529
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion common_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
std::ostream OS(&StreamBuf);
std::string Err;
success = llvm::writeSpirv(M.get(), OS, Err);
SPIRV::TranslatorOpts SPIRVOpts;
SPIRVOpts.enableAllExtensions();
if (!optionsParser.hasOptDisable()) {
SPIRVOpts.setMemToRegEnabled(true);
}
success = llvm::writeSpirv(M.get(), SPIRVOpts, OS, Err);
err_ostream << Err.c_str();
err_ostream.flush();
}
Expand Down
4 changes: 3 additions & 1 deletion options.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class EffectiveOptionsFilter {
class CompileOptionsParser {
public:
CompileOptionsParser(const char *pszOpenCLVersion)
: m_commonFilter(pszOpenCLVersion), m_emitSPIRV(false) {}
: m_commonFilter(pszOpenCLVersion), m_emitSPIRV(false), m_optDisable(false) {}

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

bool hasEmitSPIRV() const { return m_emitSPIRV; }
bool hasOptDisable() const { return m_optDisable; }

private:
OpenCLCompileOptTable m_optTbl;
Expand All @@ -183,6 +184,7 @@ class CompileOptionsParser {
llvm::SmallVector<const char *, 16> m_effectiveArgsRaw;
std::string m_sourceName;
bool m_emitSPIRV;
bool m_optDisable;
};

// Tokenize a string into tokens separated by any char in 'delims'.
Expand Down
5 changes: 4 additions & 1 deletion options_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ void CompileOptionsParser::processOptions(const char *pszOptions,
for (ArgsVector::iterator it = m_effectiveArgs.begin(),
end = m_effectiveArgs.end();
it != end; ++it) {
if (it->compare("-emit-spirv") == 0) {
if (it->compare("-cl-opt-disable") == 0) {
m_optDisable = true;
}
else if (it->compare("-emit-spirv") == 0) {
m_effectiveArgsRaw.push_back("-emit-llvm-bc");
m_emitSPIRV = true;
continue;
Expand Down

0 comments on commit d4ce529

Please sign in to comment.