Skip to content

Commit f959d81

Browse files
committed
[LTO] Move DisableVerify setting to LTOCodeGenerator class (NFC).
To simplify the transition to using LTOBackend, move DisableVerify to the LTOCodeGenerator class, like most/all other options. Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D95223
1 parent 77adbe6 commit f959d81

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,20 @@ struct LTOCodeGenerator {
145145
/// \note It is up to the linker to remove the intermediate output file. Do
146146
/// not try to remove the object file in LTOCodeGenerator's destructor as we
147147
/// don't who (LTOCodeGenerator or the output file) will last longer.
148-
bool compile_to_file(const char **Name, bool DisableVerify);
148+
bool compile_to_file(const char **Name);
149149

150150
/// As with compile_to_file(), this function compiles the merged module into
151151
/// single output file. Instead of returning the output file path to the
152152
/// caller (linker), it brings the output to a buffer, and returns the buffer
153153
/// to the caller. This function should delete the intermediate file once
154154
/// its content is brought to memory. Return NULL if the compilation was not
155155
/// successful.
156-
std::unique_ptr<MemoryBuffer> compile(bool DisableVerify);
156+
std::unique_ptr<MemoryBuffer> compile();
157157

158158
/// Optimizes the merged module. Returns true on success.
159159
///
160160
/// Calls \a verifyMergedModuleOnce().
161-
bool optimize(bool DisableVerify);
161+
bool optimize();
162162

163163
/// Compiles the merged optimized module into a single output file. It brings
164164
/// the output to a buffer, and returns the buffer to the caller. Return NULL
@@ -178,6 +178,8 @@ struct LTOCodeGenerator {
178178
/// assume builtins are present on the target.
179179
void setFreestanding(bool Enabled) { Freestanding = Enabled; }
180180

181+
void setDisableVerify(bool Value) { DisableVerify = Value; }
182+
181183
void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
182184

183185
LLVMContext &getContext() { return Context; }
@@ -239,6 +241,7 @@ struct LTOCodeGenerator {
239241
std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
240242
bool Freestanding = false;
241243
std::unique_ptr<ToolOutputFile> StatsFile = nullptr;
244+
bool DisableVerify = false;
242245
};
243246
}
244247
#endif

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ LTOCodeGenerator::compileOptimized() {
326326
return std::move(*BufferOrErr);
327327
}
328328

329-
bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableVerify) {
330-
if (!optimize(DisableVerify))
329+
bool LTOCodeGenerator::compile_to_file(const char **Name) {
330+
if (!optimize())
331331
return false;
332332

333333
return compileOptimizedToFile(Name);
334334
}
335335

336-
std::unique_ptr<MemoryBuffer> LTOCodeGenerator::compile(bool DisableVerify) {
337-
if (!optimize(DisableVerify))
336+
std::unique_ptr<MemoryBuffer> LTOCodeGenerator::compile() {
337+
if (!optimize())
338338
return nullptr;
339339

340340
return compileOptimized();
@@ -527,7 +527,7 @@ void LTOCodeGenerator::finishOptimizationRemarks() {
527527
}
528528

529529
/// Optimize merged modules using various IPO passes
530-
bool LTOCodeGenerator::optimize(bool DisableVerify) {
530+
bool LTOCodeGenerator::optimize() {
531531
if (!this->determineTarget())
532532
return false;
533533

llvm/tools/llvm-lto/llvm-lto.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ int main(int argc, char **argv) {
953953
true);
954954

955955
LTOCodeGenerator CodeGen(Context);
956+
CodeGen.setDisableVerify(DisableVerify);
956957

957958
if (UseDiagnosticHandler)
958959
CodeGen.setDiagnosticHandler(handleDiagnostics, nullptr);
@@ -1026,7 +1027,7 @@ int main(int argc, char **argv) {
10261027
error("writing linked module failed.");
10271028
}
10281029

1029-
if (!CodeGen.optimize(DisableVerify)) {
1030+
if (!CodeGen.optimize()) {
10301031
// Diagnostic messages should have been printed by the handler.
10311032
error("error optimizing the code");
10321033
}
@@ -1067,7 +1068,7 @@ int main(int argc, char **argv) {
10671068
error(": -save-merged-module must be specified with -o");
10681069

10691070
const char *OutputName = nullptr;
1070-
if (!CodeGen.compile_to_file(&OutputName, DisableVerify))
1071+
if (!CodeGen.compile_to_file(&OutputName))
10711072
error("error compiling the code");
10721073
// Diagnostic messages should have been printed by the handler.
10731074

llvm/tools/lto/lto.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static void lto_add_attrs(lto_code_gen_t cg) {
152152
report_fatal_error("Optimization level must be between 0 and 3");
153153
CG->setOptLevel(OptLevel - '0');
154154
CG->setFreestanding(EnableFreestanding);
155+
CG->setDisableVerify(DisableVerify);
155156
}
156157

157158
extern const char* lto_get_version() {
@@ -432,7 +433,7 @@ bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
432433
const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
433434
maybeParseOptions(cg);
434435
LibLTOCodeGenerator *CG = unwrap(cg);
435-
CG->NativeObjectFile = CG->compile(DisableVerify);
436+
CG->NativeObjectFile = CG->compile();
436437
if (!CG->NativeObjectFile)
437438
return nullptr;
438439
*length = CG->NativeObjectFile->getBufferSize();
@@ -441,7 +442,7 @@ const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
441442

442443
bool lto_codegen_optimize(lto_code_gen_t cg) {
443444
maybeParseOptions(cg);
444-
return !unwrap(cg)->optimize(DisableVerify);
445+
return !unwrap(cg)->optimize();
445446
}
446447

447448
const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {
@@ -456,7 +457,7 @@ const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {
456457

457458
bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
458459
maybeParseOptions(cg);
459-
return !unwrap(cg)->compile_to_file(name, DisableVerify);
460+
return !unwrap(cg)->compile_to_file(name);
460461
}
461462

462463
void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) {

0 commit comments

Comments
 (0)