Skip to content

Commit

Permalink
[LTO] Remove options to disable inlining, vectorization & GVNLoadPRE.
Browse files Browse the repository at this point in the history
This patch removes some ancient options as a clean-up before moving
code-gen to use LTOBackend in D94487.

I think it would preferable to remove those ancient options, because

  1. There are no corresponding options in LTOBackend based tools,
  2. There are no unit tests for them,
  3. They are not passed through by Clang,
  4. At least for GNVLoadPRE, users could just use GVN's `enable-load-pre`.

Alternatively we could add support for those options to lto::Config &
co, but I think it would be better to remove them, unless they are
actually used in practice.

Reviewed By: steven_wu, tejohnson

Differential Revision: https://reviews.llvm.org/D94783
  • Loading branch information
fhahn committed Jan 16, 2021
1 parent bdd4dda commit bca16e2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 62 deletions.
11 changes: 3 additions & 8 deletions llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,20 @@ struct LTOCodeGenerator {
/// \note It is up to the linker to remove the intermediate output file. Do
/// not try to remove the object file in LTOCodeGenerator's destructor as we
/// don't who (LTOCodeGenerator or the output file) will last longer.
bool compile_to_file(const char **Name, bool DisableVerify,
bool DisableInline, bool DisableGVNLoadPRE,
bool DisableVectorization);
bool compile_to_file(const char **Name, bool DisableVerify);

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

/// Optimizes the merged module. Returns true on success.
///
/// Calls \a verifyMergedModuleOnce().
bool optimize(bool DisableVerify, bool DisableInline, bool DisableGVNLoadPRE,
bool DisableVectorization);
bool optimize(bool DisableVerify);

/// Compiles the merged optimized module into a single output file. It brings
/// the output to a buffer, and returns the buffer to the caller. Return NULL
Expand Down
27 changes: 8 additions & 19 deletions llvm/lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,15 @@ LTOCodeGenerator::compileOptimized() {
return std::move(*BufferOrErr);
}

bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableVerify,
bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization) {
if (!optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableVectorization))
bool LTOCodeGenerator::compile_to_file(const char **Name, bool DisableVerify) {
if (!optimize(DisableVerify))
return false;

return compileOptimizedToFile(Name);
}

std::unique_ptr<MemoryBuffer>
LTOCodeGenerator::compile(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE, bool DisableVectorization) {
if (!optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableVectorization))
std::unique_ptr<MemoryBuffer> LTOCodeGenerator::compile(bool DisableVerify) {
if (!optimize(DisableVerify))
return nullptr;

return compileOptimized();
Expand Down Expand Up @@ -534,9 +527,7 @@ void LTOCodeGenerator::finishOptimizationRemarks() {
}

/// Optimize merged modules using various IPO passes
bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,
bool DisableGVNLoadPRE,
bool DisableVectorization) {
bool LTOCodeGenerator::optimize(bool DisableVerify) {
if (!this->determineTarget())
return false;

Expand Down Expand Up @@ -585,11 +576,9 @@ bool LTOCodeGenerator::optimize(bool DisableVerify, bool DisableInline,

Triple TargetTriple(TargetMach->getTargetTriple());
PassManagerBuilder PMB;
PMB.DisableGVNLoadPRE = DisableGVNLoadPRE;
PMB.LoopVectorize = !DisableVectorization;
PMB.SLPVectorize = !DisableVectorization;
if (!DisableInline)
PMB.Inliner = createFunctionInliningPass();
PMB.LoopVectorize = true;
PMB.SLPVectorize = true;
PMB.Inliner = createFunctionInliningPass();
PMB.LibraryInfo = new TargetLibraryInfoImpl(TargetTriple);
if (Freestanding)
PMB.LibraryInfo->disableAllFunctions();
Expand Down
17 changes: 2 additions & 15 deletions llvm/tools/llvm-lto/llvm-lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ static cl::opt<bool> DisableVerify(
"disable-verify", cl::init(false),
cl::desc("Do not run the verifier during the optimization pipeline"));

static cl::opt<bool> DisableInline("disable-inlining", cl::init(false),
cl::desc("Do not run the inliner pass"));

static cl::opt<bool>
DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
cl::desc("Do not run the GVN load PRE pass"));

static cl::opt<bool> DisableLTOVectorization(
"disable-lto-vectorization", cl::init(false),
cl::desc("Do not run loop or slp vectorization during LTO"));

static cl::opt<bool> EnableFreestanding(
"lto-freestanding", cl::init(false),
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));
Expand Down Expand Up @@ -1042,8 +1031,7 @@ int main(int argc, char **argv) {
error("writing linked module failed.");
}

if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization)) {
if (!CodeGen.optimize(DisableVerify)) {
// Diagnostic messages should have been printed by the handler.
error("error optimizing the code");
}
Expand Down Expand Up @@ -1084,8 +1072,7 @@ int main(int argc, char **argv) {
error(": -save-merged-module must be specified with -o");

const char *OutputName = nullptr;
if (!CodeGen.compile_to_file(&OutputName, DisableVerify, DisableInline,
DisableGVNLoadPRE, DisableLTOVectorization))
if (!CodeGen.compile_to_file(&OutputName, DisableVerify))
error("error compiling the code");
// Diagnostic messages should have been printed by the handler.

Expand Down
23 changes: 3 additions & 20 deletions llvm/tools/lto/lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ OptLevel("O",
cl::ZeroOrMore,
cl::init('2'));

static cl::opt<bool>
DisableInline("disable-inlining", cl::init(false),
cl::desc("Do not run the inliner pass"));

static cl::opt<bool>
DisableGVNLoadPRE("disable-gvn-loadpre", cl::init(false),
cl::desc("Do not run the GVN load PRE pass"));

static cl::opt<bool> DisableLTOVectorization(
"disable-lto-vectorization", cl::init(false),
cl::desc("Do not run loop or slp vectorization during LTO"));

static cl::opt<bool> EnableFreestanding(
"lto-freestanding", cl::init(false),
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));
Expand Down Expand Up @@ -448,9 +436,7 @@ bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) {
const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {
maybeParseOptions(cg);
LibLTOCodeGenerator *CG = unwrap(cg);
CG->NativeObjectFile =
CG->compile(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization);
CG->NativeObjectFile = CG->compile(DisableVerify);
if (!CG->NativeObjectFile)
return nullptr;
*length = CG->NativeObjectFile->getBufferSize();
Expand All @@ -459,8 +445,7 @@ const void *lto_codegen_compile(lto_code_gen_t cg, size_t *length) {

bool lto_codegen_optimize(lto_code_gen_t cg) {
maybeParseOptions(cg);
return !unwrap(cg)->optimize(DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization);
return !unwrap(cg)->optimize(DisableVerify);
}

const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {
Expand All @@ -475,9 +460,7 @@ const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) {

bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) {
maybeParseOptions(cg);
return !unwrap(cg)->compile_to_file(
name, DisableVerify, DisableInline, DisableGVNLoadPRE,
DisableLTOVectorization);
return !unwrap(cg)->compile_to_file(name, DisableVerify);
}

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

0 comments on commit bca16e2

Please sign in to comment.