llvm.org GIT mirror llvm / b26fb77
Add an option to the LTO code generator to disable vectorization during LTO We used to always vectorize (slp and loop vectorize) in the LTO pass pipeline. r220345 changed it so that we used the PassManager's fields 'LoopVectorize' and 'SLPVectorize' out of the desire to be able to disable vectorization using the cl::opt flags 'vectorize-loops'/'slp-vectorize' which the before mentioned fields default to. Unfortunately, this turns off vectorization because those fields default to false. This commit adds flags to the LTO library to disable lto vectorization which reconciles the desire to optionally disable vectorization during LTO and the desired behavior of defaulting to enabled vectorization. We really want tools to set PassManager flags directly to enable/disable vectorization and not go the route via cl::opt flags *in* PassManagerBuilder.cpp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220652 91177308-0d34-0410-b5e6-96231b3b80d8 Arnold Schwaighofer 4 years ago
5 changed file(s) with 32 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
100100 bool disableOpt,
101101 bool disableInline,
102102 bool disableGVNLoadPRE,
103 bool disableVectorization,
103104 std::string &errMsg);
104105
105106 // As with compile_to_file(), this function compiles the merged module into
111112 bool disableOpt,
112113 bool disableInline,
113114 bool disableGVNLoadPRE,
115 bool disableVectorization,
114116 std::string &errMsg);
115117
116118 void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
119121 void initializeLTOPasses();
120122
121123 bool generateObjectFile(raw_ostream &out, bool disableOpt, bool disableInline,
122 bool disableGVNLoadPRE, std::string &errMsg);
124 bool disableGVNLoadPRE, bool disableVectorization,
125 std::string &errMsg);
123126 void applyScopeRestrictions();
124127 void applyRestriction(GlobalValue &GV, ArrayRef Libcalls,
125128 std::vector &MustPreserveList,
187187 bool disableOpt,
188188 bool disableInline,
189189 bool disableGVNLoadPRE,
190 bool disableVectorization,
190191 std::string& errMsg) {
191192 // make unique temp .o file to put generated object file
192193 SmallString<128> Filename;
201202 // generate object file
202203 tool_output_file objFile(Filename.c_str(), FD);
203204
204 bool genResult = generateObjectFile(objFile.os(), disableOpt, disableInline,
205 disableGVNLoadPRE, errMsg);
205 bool genResult =
206 generateObjectFile(objFile.os(), disableOpt, disableInline,
207 disableGVNLoadPRE, disableVectorization, errMsg);
206208 objFile.os().close();
207209 if (objFile.os().has_error()) {
208210 objFile.os().clear_error();
225227 bool disableOpt,
226228 bool disableInline,
227229 bool disableGVNLoadPRE,
230 bool disableVectorization,
228231 std::string& errMsg) {
229232 const char *name;
230233 if (!compile_to_file(&name, disableOpt, disableInline, disableGVNLoadPRE,
231 errMsg))
234 disableVectorization, errMsg))
232235 return nullptr;
233236
234237 // read .o file into memory buffer
440443 bool DisableOpt,
441444 bool DisableInline,
442445 bool DisableGVNLoadPRE,
446 bool DisableVectorization,
443447 std::string &errMsg) {
444448 if (!this->determineTarget(errMsg))
445449 return false;
458462 Triple TargetTriple(TargetMach->getTargetTriple());
459463 PassManagerBuilder PMB;
460464 PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
465 PMB.LoopVectorize = !DisableVectorization;
466 PMB.SLPVectorize = !DisableVectorization;
461467 if (!DisableInline)
462468 PMB.Inliner = createFunctionInliningPass();
463469 PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple);
443443 // More loops are countable; try to optimize them.
444444 PM.add(createIndVarSimplifyPass());
445445 PM.add(createLoopDeletionPass());
446 PM.add(createLoopVectorizePass(DisableUnrollLoops, LoopVectorize));
446 PM.add(createLoopVectorizePass(true, LoopVectorize));
447447
448448 // More scalar chains could be vectorized due to more alias information
449449 if (RunSLPAfterLoopVectorization)
3838 cl::desc("Do not run the GVN load PRE pass"));
3939
4040 static cl::opt
41 DisableLTOVectorization("disable-lto-vectorization", cl::init(false),
42 cl::desc("Do not run loop or slp vectorization during LTO"));
43
44 static cl::opt
4145 UseDiagnosticHandler("use-diagnostic-handler", cl::init(false),
4246 cl::desc("Use a diagnostic handler to test the handler interface"));
4347
178182 if (!OutputFilename.empty()) {
179183 size_t len = 0;
180184 std::string ErrorInfo;
181 const void *Code = CodeGen.compile(&len, DisableOpt, DisableInline,
182 DisableGVNLoadPRE, ErrorInfo);
185 const void *Code =
186 CodeGen.compile(&len, DisableOpt, DisableInline, DisableGVNLoadPRE,
187 DisableLTOVectorization, ErrorInfo);
183188 if (!Code) {
184189 errs() << argv[0]
185190 << ": error compiling the code: " << ErrorInfo << "\n";
199204 std::string ErrorInfo;
200205 const char *OutputName = nullptr;
201206 if (!CodeGen.compile_to_file(&OutputName, DisableOpt, DisableInline,
202 DisableGVNLoadPRE, ErrorInfo)) {
207 DisableGVNLoadPRE, DisableLTOVectorization,
208 ErrorInfo)) {
203209 errs() << argv[0]
204210 << ": error compiling the code: " << ErrorInfo
205211 << "\n";
3030 static cl::opt
3131 DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
3232 cl::desc("Do not run the GVN load PRE pass"));
33
34 static cl::opt
35 DisableLTOVectorization("disable-lto-vectorization", cl::init(false),
36 cl::desc("Do not run loop or slp vectorization during LTO"));
3337
3438 // Holds most recent error string.
3539 // *** Not thread safe ***
251255 parsedOptions = true;
252256 }
253257 return unwrap(cg)->compile(length, DisableOpt, DisableInline,
254 DisableGVNLoadPRE, sLastErrorString);
258 DisableGVNLoadPRE, DisableLTOVectorization,
259 sLastErrorString);
255260 }
256261
257262 bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
260265 lto_add_attrs(cg);
261266 parsedOptions = true;
262267 }
263 return !unwrap(cg)->compile_to_file(name, DisableOpt, DisableInline,
264 DisableGVNLoadPRE, sLastErrorString);
268 return !unwrap(cg)->compile_to_file(
269 name, DisableOpt, DisableInline, DisableGVNLoadPRE,
270 DisableLTOVectorization, sLastErrorString);
265271 }
266272
267273 void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {