Commit 259ce709 by Nicolas Capens Committed by Nicolas Capens

Only lower MSan codegen optimization for LLVM JIT

The large slowdown in codegen for MemorySanitizer instrumented Reactor code only affects the LLVM backend, and the workaround of not performing codegen optimizations is also LLVM specific. So only override the optimization level for LLVM for MSan builds. Previously it was done in Nucleus, but this abstract API affects other backends too, and this depended on rr::Optimization::Level::None to correspond with llvm::CodeGenOpt::None which might not always remain the case. Bug: b/155148722 Change-Id: I2499935b1ddbd3cefd4b4497094c70ce284b170c Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/50488 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 43fcd32b
...@@ -198,6 +198,14 @@ JITGlobals::JITGlobals(llvm::orc::JITTargetMachineBuilder &&jitTargetMachineBuil ...@@ -198,6 +198,14 @@ JITGlobals::JITGlobals(llvm::orc::JITTargetMachineBuilder &&jitTargetMachineBuil
llvm::CodeGenOpt::Level JITGlobals::toLLVM(rr::Optimization::Level level) llvm::CodeGenOpt::Level JITGlobals::toLLVM(rr::Optimization::Level level)
{ {
// TODO(b/173257647): MemorySanitizer instrumentation produces IR which takes
// a lot longer to process by the machine code optimization passes. Disabling
// them has a negligible effect on code quality but compiles much faster.
if(__has_feature(memory_sanitizer))
{
return llvm::CodeGenOpt::None;
}
switch(level) switch(level)
{ {
case rr::Optimization::Level::None: return llvm::CodeGenOpt::None; case rr::Optimization::Level::None: return llvm::CodeGenOpt::None;
...@@ -206,6 +214,7 @@ llvm::CodeGenOpt::Level JITGlobals::toLLVM(rr::Optimization::Level level) ...@@ -206,6 +214,7 @@ llvm::CodeGenOpt::Level JITGlobals::toLLVM(rr::Optimization::Level level)
case rr::Optimization::Level::Aggressive: return llvm::CodeGenOpt::Aggressive; case rr::Optimization::Level::Aggressive: return llvm::CodeGenOpt::Aggressive;
default: UNREACHABLE("Unknown Optimization Level %d", int(level)); default: UNREACHABLE("Unknown Optimization Level %d", int(level));
} }
return llvm::CodeGenOpt::Default; return llvm::CodeGenOpt::Default;
} }
......
...@@ -28,12 +28,6 @@ ...@@ -28,12 +28,6 @@
# undef None // TODO(b/127920555) # undef None // TODO(b/127920555)
#endif #endif
// A Clang extension to determine compiler features.
// We use it to detect Sanitizer builds (e.g. -fsanitize=memory).
#ifndef __has_feature
# define __has_feature(x) 0
#endif
static_assert(sizeof(short) == 2, "Reactor's 'Short' type is 16-bit, and requires the C++ 'short' to match that."); static_assert(sizeof(short) == 2, "Reactor's 'Short' type is 16-bit, and requires the C++ 'short' to match that.");
static_assert(sizeof(int) == 4, "Reactor's 'Int' type is 32-bit, and requires the C++ 'int' to match that."); static_assert(sizeof(int) == 4, "Reactor's 'Int' type is 32-bit, and requires the C++ 'int' to match that.");
...@@ -85,14 +79,6 @@ public: ...@@ -85,14 +79,6 @@ public:
this->level = Level::REACTOR_DEFAULT_OPT_LEVEL; this->level = Level::REACTOR_DEFAULT_OPT_LEVEL;
} }
#endif #endif
// TODO(b/173257647): MemorySanitizer instrumentation produces IR which takes
// a lot longer to process by the machine code optimization passes. Disabling
// them has a negligible effect on code quality but compiles much faster.
if(__has_feature(memory_sanitizer))
{
this->level = Level::None;
}
} }
Level getLevel() const { return level; } Level getLevel() const { return level; }
......
...@@ -52,6 +52,12 @@ int DebugPrintf(const char *format, ...); ...@@ -52,6 +52,12 @@ int DebugPrintf(const char *format, ...);
} }
#endif #endif
// A Clang extension to determine compiler features.
// We use it to detect Sanitizer builds (e.g. -fsanitize=memory).
#ifndef __has_feature
# define __has_feature(x) 0
#endif
// Whether Reactor routine instrumentation is enabled for MSan builds. // Whether Reactor routine instrumentation is enabled for MSan builds.
// TODO(b/155148722): Remove when unconditionally instrumenting for all build systems. // TODO(b/155148722): Remove when unconditionally instrumenting for all build systems.
#if !defined REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION #if !defined REACTOR_ENABLE_MEMORY_SANITIZER_INSTRUMENTATION
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment