1 //===- bolt/Passes/IdenticalCodeFolding.h -----------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef BOLT_PASSES_IDENTICAL_CODE_FOLDING_H 10 #define BOLT_PASSES_IDENTICAL_CODE_FOLDING_H 11 12 #include "bolt/Core/BinaryFunction.h" 13 #include "bolt/Passes/BinaryPasses.h" 14 15 namespace llvm { 16 namespace bolt { 17 18 /// An optimization that replaces references to identical functions with 19 /// references to a single one of them. 20 /// 21 class IdenticalCodeFolding : public BinaryFunctionPass { 22 protected: shouldOptimize(const BinaryFunction & BF)23 bool shouldOptimize(const BinaryFunction &BF) const override { 24 if (BF.hasUnknownControlFlow()) 25 return false; 26 if (BF.isFolded()) 27 return false; 28 if (BF.hasSDTMarker()) 29 return false; 30 return BinaryFunctionPass::shouldOptimize(BF); 31 } 32 33 public: IdenticalCodeFolding(const cl::opt<bool> & PrintPass)34 explicit IdenticalCodeFolding(const cl::opt<bool> &PrintPass) 35 : BinaryFunctionPass(PrintPass) {} 36 getName()37 const char *getName() const override { return "identical-code-folding"; } 38 void runOnFunctions(BinaryContext &BC) override; 39 }; 40 41 } // namespace bolt 42 } // namespace llvm 43 44 #endif 45