1 //===- bolt/Passes/DataflowInfoManager.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_DATAFLOWINFOMANAGER_H 10 #define BOLT_PASSES_DATAFLOWINFOMANAGER_H 11 12 #include "bolt/Passes/DominatorAnalysis.h" 13 #include "bolt/Passes/LivenessAnalysis.h" 14 #include "bolt/Passes/ReachingDefOrUse.h" 15 #include "bolt/Passes/ReachingInsns.h" 16 #include "bolt/Passes/StackAllocationAnalysis.h" 17 #include "bolt/Passes/StackPointerTracking.h" 18 #include "bolt/Passes/StackReachingUses.h" 19 20 namespace llvm { 21 namespace bolt { 22 class FrameAnalysis; 23 class RegAnalysis; 24 25 /// Manages instances for dataflow analyses and try to preserve the data 26 /// calculated by each analysis as much as possible, saving the need to 27 /// recompute it. Also provide an interface for data invalidation when the 28 /// analysis is outdated after a transform pass modified the function. 29 class DataflowInfoManager { 30 const RegAnalysis *RA; 31 const FrameAnalysis *FA; 32 const BinaryContext &BC; 33 BinaryFunction &BF; 34 std::unique_ptr<ReachingDefOrUse</*Def=*/true>> RD; 35 std::unique_ptr<ReachingDefOrUse</*Def=*/false>> RU; 36 std::unique_ptr<LivenessAnalysis> LA; 37 std::unique_ptr<StackReachingUses> SRU; 38 std::unique_ptr<DominatorAnalysis</*Bwd=*/false>> DA; 39 std::unique_ptr<DominatorAnalysis</*Bwd=*/true>> PDA; 40 std::unique_ptr<StackPointerTracking> SPT; 41 std::unique_ptr<ReachingInsns<false>> RI; 42 std::unique_ptr<ReachingInsns<true>> RIB; 43 std::unique_ptr<StackAllocationAnalysis> SAA; 44 std::unique_ptr<std::unordered_map<const MCInst *, BinaryBasicBlock *>> 45 InsnToBB; 46 47 // Id of the allocator to be used for annotations added by any of the managed 48 // analysis 49 MCPlusBuilder::AllocatorIdTy AllocatorId; 50 51 public: 52 DataflowInfoManager(BinaryFunction &BF, const RegAnalysis *RA, 53 const FrameAnalysis *FA, 54 MCPlusBuilder::AllocatorIdTy AllocId = 0) RA(RA)55 : RA(RA), FA(FA), BC(BF.getBinaryContext()), BF(BF), 56 AllocatorId(AllocId){}; 57 58 /// Helper function to fetch the parent BB associated with a program point 59 /// If PP is a BB itself, then return itself (cast to a BinaryBasicBlock) getParentBB(ProgramPoint PP)60 BinaryBasicBlock *getParentBB(ProgramPoint PP) { 61 return PP.isBB() ? PP.getBB() : getInsnToBBMap()[PP.getInst()]; 62 } 63 64 ReachingDefOrUse</*Def=*/true> &getReachingDefs(); 65 void invalidateReachingDefs(); 66 ReachingDefOrUse</*Def=*/false> &getReachingUses(); 67 void invalidateReachingUses(); 68 LivenessAnalysis &getLivenessAnalysis(); 69 void invalidateLivenessAnalysis(); 70 StackReachingUses &getStackReachingUses(); 71 void invalidateStackReachingUses(); 72 DominatorAnalysis<false> &getDominatorAnalysis(); 73 void invalidateDominatorAnalysis(); 74 DominatorAnalysis<true> &getPostDominatorAnalysis(); 75 void invalidatePostDominatorAnalysis(); 76 StackPointerTracking &getStackPointerTracking(); 77 void invalidateStackPointerTracking(); 78 ReachingInsns<false> &getReachingInsns(); 79 void invalidateReachingInsns(); 80 ReachingInsns<true> &getReachingInsnsBackwards(); 81 void invalidateReachingInsnsBackwards(); 82 StackAllocationAnalysis &getStackAllocationAnalysis(); 83 void invalidateStackAllocationAnalysis(); 84 std::unordered_map<const MCInst *, BinaryBasicBlock *> &getInsnToBBMap(); 85 void invalidateInsnToBBMap(); 86 void invalidateAll(); 87 }; 88 89 } // end namespace bolt 90 } // end namespace llvm 91 92 #endif 93