//===- bolt/Passes/BinaryPasses.h - Binary-level passes ---------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // The set of optimization/analysis passes that run on BinaryFunctions. // //===----------------------------------------------------------------------===// #ifndef BOLT_PASSES_BINARY_PASSES_H #define BOLT_PASSES_BINARY_PASSES_H #include "bolt/Core/BinaryContext.h" #include "bolt/Core/BinaryFunction.h" #include "bolt/Core/DynoStats.h" #include "bolt/Profile/BoltAddressTranslation.h" #include "llvm/Support/CommandLine.h" #include <atomic> #include <set> #include <string> #include <unordered_set> namespace llvm { namespace bolt { /// An optimization/analysis pass that runs on functions. class BinaryFunctionPass { … }; /// A pass to set initial program-wide dynostats. class DynoStatsSetPass : public BinaryFunctionPass { … }; /// A pass to print program-wide dynostats. class DynoStatsPrintPass : public BinaryFunctionPass { … }; /// The pass normalizes CFG by performing the following transformations: /// * removes empty basic blocks /// * merges duplicate edges and updates jump instructions class NormalizeCFG : public BinaryFunctionPass { … }; /// Detect and eliminate unreachable basic blocks. We could have those /// filled with nops and they are used for alignment. class EliminateUnreachableBlocks : public BinaryFunctionPass { … }; // Reorder the basic blocks for each function based on hotness. class ReorderBasicBlocks : public BinaryFunctionPass { … }; /// Sync local branches with CFG. class FixupBranches : public BinaryFunctionPass { … }; /// Fix the CFI state and exception handling information after all other /// passes have completed. class FinalizeFunctions : public BinaryFunctionPass { … }; /// Perform any necessary adjustments for functions that do not fit into their /// original space in non-relocation mode. class CheckLargeFunctions : public BinaryFunctionPass { … }; /// Convert and remove all BOLT-related annotations before LLVM code emission. class LowerAnnotations : public BinaryFunctionPass { … }; /// Clean the state of the MC representation before sending it to emission class CleanMCState : public BinaryFunctionPass { … }; /// An optimization to simplify conditional tail calls by removing /// unnecessary branches. /// /// This optimization considers both of the following cases: /// /// foo: ... /// jcc L1 original /// ... /// L1: jmp bar # TAILJMP /// /// -> /// /// foo: ... /// jcc bar iff jcc L1 is expected /// ... /// /// L1 is unreachable /// /// OR /// /// foo: ... /// jcc L2 /// L1: jmp dest # TAILJMP /// L2: ... /// /// -> /// /// foo: jncc dest # TAILJMP /// L2: ... /// /// L1 is unreachable /// /// For this particular case, the first basic block ends with /// a conditional branch and has two successors, one fall-through /// and one for when the condition is true. /// The target of the conditional is a basic block with a single /// unconditional branch (i.e. tail call) to another function. /// We don't care about the contents of the fall-through block. /// We assume that the target of the conditional branch is the /// first successor. class SimplifyConditionalTailCalls : public BinaryFunctionPass { … }; /// Convert instructions to the form with the minimum operand width. class ShortenInstructions : public BinaryFunctionPass { … }; /// Perform simple peephole optimizations. class Peepholes : public BinaryFunctionPass { … }; /// An optimization to simplify loads from read-only sections.The pass converts /// load instructions with statically computed target address such as: /// /// mov 0x12f(%rip), %eax /// /// to their counterparts that use immediate operands instead of memory loads: /// /// mov $0x4007dc, %eax /// /// when the target address points somewhere inside a read-only section. /// class SimplifyRODataLoads : public BinaryFunctionPass { … }; /// Assign output sections to all functions. class AssignSections : public BinaryFunctionPass { … }; /// Compute and report to the user the imbalance in flow equations for all /// CFGs, so we can detect bad quality profile. Prints average and standard /// deviation of the absolute differences of outgoing flow minus incoming flow /// for blocks of interest (excluding prologues, epilogues, and BB frequency /// lower than 100). class PrintProfileStats : public BinaryFunctionPass { … }; /// Prints a list of the top 100 functions sorted by a set of /// dyno stats categories. class PrintProgramStats : public BinaryFunctionPass { … }; /// Pass for lowering any instructions that we have raised and that have /// to be lowered. class InstructionLowering : public BinaryFunctionPass { … }; /// Pass for stripping 'repz' from 'repz retq' sequence of instructions. class StripRepRet : public BinaryFunctionPass { … }; /// Pass for inlining calls to memcpy using 'rep movsb' on X86. class InlineMemcpy : public BinaryFunctionPass { … }; /// Pass for specializing memcpy for a size of 1 byte. class SpecializeMemcpy1 : public BinaryFunctionPass { … }; /// Pass to remove nops in code class RemoveNops : public BinaryFunctionPass { … }; enum FrameOptimizationType : char { … }; } // namespace bolt } // namespace llvm #endif