1 //===- bolt/Passes/RegReAssign.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_REGREASSIGN_H 10 #define BOLT_PASSES_REGREASSIGN_H 11 12 #include "bolt/Core/BinaryFunctionCallGraph.h" 13 #include "bolt/Passes/BinaryPasses.h" 14 #include "bolt/Passes/RegAnalysis.h" 15 16 namespace llvm { 17 namespace bolt { 18 19 class RegReAssign : public BinaryFunctionPass { 20 std::vector<int64_t> RegScore; 21 std::vector<size_t> RankedRegs; 22 BitVector ClassicRegs; 23 BitVector CalleeSaved; 24 BitVector ClassicCSR; 25 BitVector ExtendedCSR; 26 BitVector GPRegs; 27 28 /// Hooks to other passes 29 std::unique_ptr<RegAnalysis> RA; 30 std::unique_ptr<BinaryFunctionCallGraph> CG; 31 32 /// Stats 33 DenseSet<const BinaryFunction *> FuncsChanged; 34 int64_t StaticBytesSaved{0}; 35 int64_t DynBytesSaved{0}; 36 37 void swap(BinaryFunction &Function, MCPhysReg A, MCPhysReg B); 38 void rankRegisters(BinaryFunction &Function); 39 void aggressivePassOverFunction(BinaryFunction &Function); 40 bool conservativePassOverFunction(BinaryFunction &Function); 41 void setupAggressivePass(BinaryContext &BC, 42 std::map<uint64_t, BinaryFunction> &BFs); 43 void setupConservativePass(BinaryContext &BC, 44 std::map<uint64_t, BinaryFunction> &BFs); 45 46 public: 47 /// BinaryPass public interface 48 RegReAssign(const cl::opt<bool> & PrintPass)49 explicit RegReAssign(const cl::opt<bool> &PrintPass) 50 : BinaryFunctionPass(PrintPass) {} 51 getName()52 const char *getName() const override { return "regreassign"; } 53 shouldPrint(const BinaryFunction & BF)54 bool shouldPrint(const BinaryFunction &BF) const override { 55 return BinaryFunctionPass::shouldPrint(BF) && FuncsChanged.count(&BF) > 0; 56 } 57 58 Error runOnFunctions(BinaryContext &BC) override; 59 }; 60 } // namespace bolt 61 } // namespace llvm 62 63 #endif 64