76
76
#include " llvm/Transforms/Instrumentation/MemProfiler.h"
77
77
#include " llvm/Transforms/Instrumentation/MemorySanitizer.h"
78
78
#include " llvm/Transforms/Instrumentation/PGOInstrumentation.h"
79
+ #include " llvm/Transforms/Instrumentation/RemoveTrapsPass.h"
79
80
#include " llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
80
81
#include " llvm/Transforms/Instrumentation/SanitizerCoverage.h"
81
82
#include " llvm/Transforms/Instrumentation/ThreadSanitizer.h"
82
83
#include " llvm/Transforms/ObjCARC.h"
83
84
#include " llvm/Transforms/Scalar/EarlyCSE.h"
84
85
#include " llvm/Transforms/Scalar/GVN.h"
85
86
#include " llvm/Transforms/Scalar/JumpThreading.h"
87
+ #include " llvm/Transforms/Scalar/SimplifyCFG.h"
86
88
#include " llvm/Transforms/Utils/Debugify.h"
87
89
#include " llvm/Transforms/Utils/EntryExitInstrumenter.h"
88
90
#include " llvm/Transforms/Utils/ModuleUtils.h"
@@ -98,6 +100,10 @@ using namespace llvm;
98
100
namespace llvm {
99
101
extern cl::opt<bool > PrintPipelinePasses;
100
102
103
+ cl::opt<bool > ClRemoveTraps (" clang-remove-traps" , cl::Optional,
104
+ cl::desc (" Insert remove-traps pass." ),
105
+ cl::init(false ));
106
+
101
107
// Experiment to move sanitizers earlier.
102
108
static cl::opt<bool > ClSanitizeOnOptimizerEarlyEP (
103
109
" sanitizer-early-opt-ep" , cl::Optional,
@@ -744,6 +750,17 @@ static void addSanitizers(const Triple &TargetTriple,
744
750
// LastEP does not need GlobalsAA.
745
751
PB.registerOptimizerLastEPCallback (SanitizersCallback);
746
752
}
753
+
754
+ if (ClRemoveTraps) {
755
+ PB.registerOptimizerEarlyEPCallback ([&](ModulePassManager &MPM,
756
+ OptimizationLevel Level) {
757
+ FunctionPassManager FPM;
758
+ FPM.addPass (RemoveTrapsPass ());
759
+ FPM.addPass (
760
+ SimplifyCFGPass (SimplifyCFGOptions ().convertSwitchRangeToICmp (true )));
761
+ MPM.addPass (createModuleToFunctionPassAdaptor (std::move (FPM)));
762
+ });
763
+ }
747
764
}
748
765
749
766
void EmitAssemblyHelper::RunOptimizationPipeline (
0 commit comments