Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Add a CC1 option to enable the Swift function-merging pass
Browse files Browse the repository at this point in the history
Patch by Linus Nilsson.
  • Loading branch information
vedantk committed Nov 9, 2018
1 parent 0789816 commit ac8be9e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/clang/Driver/CC1Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">,
HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">;
def fmerge_functions : Flag<["-"], "fmerge-functions">,
HelpText<"Permit merging of identical functions when optimizing.">;
def fmerge_similar_functions : Flag<["-"], "fmerge-similar-functions">,
HelpText<"Permit merging of similar functions when optimizing.">;
def femit_coverage_notes : Flag<["-"], "femit-coverage-notes">,
HelpText<"Emit a gcov coverage notes file when compiling.">;
def femit_coverage_data: Flag<["-"], "femit-coverage-data">,
Expand Down
1 change: 1 addition & 0 deletions include/clang/Frontend/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ CODEGENOPT(IncrementalLinkerCompatible, 1, 0) ///< Emit an object file which can
///< linker.
CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
CODEGENOPT(MergeFunctions , 1, 0) ///< Set when -fmerge-functions is enabled.
CODEGENOPT(MergeSimilarFunctions , 1, 0) ///< Set when -fmerge-similar-functions is enabled.
CODEGENOPT(MSVolatile , 1, 0) ///< Set when /volatile:ms is enabled.
CODEGENOPT(NoCommon , 1, 0) ///< Set when -fno-common or C++ is enabled.
CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm is
Expand Down
1 change: 1 addition & 0 deletions lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,

PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
PMBuilder.MergeSimilarFunctions = CodeGenOpts.MergeSimilarFunctions;
PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
Expand Down
8 changes: 8 additions & 0 deletions lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


//===--- LLVM.cpp - Clang+LLVM ToolChain Implementations --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
Expand Down Expand Up @@ -3407,6 +3409,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fdelete_null_pointer_checks, false))
CmdArgs.push_back("-fno-delete-null-pointer-checks");

if (Args.hasArg(options::OPT_fmerge_similar_functions))
CmdArgs.push_back("-fmerge-similar-functions");

if (Args.hasArg(options::OPT_fmerge_functions))
CmdArgs.push_back("-fmerge-functions");

// LLVM Code Generator Options.

if (Args.hasArg(options::OPT_frewrite_map_file) ||
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
OPT_fno_unique_section_names, true);

Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
Opts.MergeSimilarFunctions = Args.hasArg(OPT_fmerge_similar_functions);

Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);

Expand Down
2 changes: 1 addition & 1 deletion test/CodeGenCXX/merge-functions.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: x86-registered-target
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O1 -fmerge-functions -emit-llvm -o - -x c++ < %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -O1 -fmerge-functions -fmerge-similar-functions -emit-llvm -o - -x c++ < %s | FileCheck %s

// Basic functionality test. Function merging doesn't kick in on functions that
// are too simple.
Expand Down

0 comments on commit ac8be9e

Please sign in to comment.