1 //===- bolt/Passes/DataflowInfoManager.cpp --------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the DataflowInfoManager class.
11 //===----------------------------------------------------------------------===//
13 #include "bolt/Passes/DataflowInfoManager.h"
18 ReachingDefOrUse
</*Def=*/true> &DataflowInfoManager::getReachingDefs() {
21 assert(RA
&& "RegAnalysis required");
22 RD
.reset(new ReachingDefOrUse
<true>(*RA
, BF
, std::nullopt
, AllocatorId
));
27 void DataflowInfoManager::invalidateReachingDefs() { RD
.reset(nullptr); }
29 ReachingDefOrUse
</*Def=*/false> &DataflowInfoManager::getReachingUses() {
32 assert(RA
&& "RegAnalysis required");
33 RU
.reset(new ReachingDefOrUse
<false>(*RA
, BF
, std::nullopt
, AllocatorId
));
38 void DataflowInfoManager::invalidateReachingUses() { RU
.reset(nullptr); }
40 LivenessAnalysis
&DataflowInfoManager::getLivenessAnalysis() {
43 assert(RA
&& "RegAnalysis required");
44 LA
.reset(new LivenessAnalysis(*RA
, BF
, AllocatorId
));
49 void DataflowInfoManager::invalidateLivenessAnalysis() { LA
.reset(nullptr); }
51 StackReachingUses
&DataflowInfoManager::getStackReachingUses() {
54 assert(FA
&& "FrameAnalysis required");
55 SRU
.reset(new StackReachingUses(*FA
, BF
, AllocatorId
));
60 void DataflowInfoManager::invalidateStackReachingUses() { SRU
.reset(nullptr); }
62 DominatorAnalysis
<false> &DataflowInfoManager::getDominatorAnalysis() {
65 DA
.reset(new DominatorAnalysis
<false>(BF
, AllocatorId
));
70 void DataflowInfoManager::invalidateDominatorAnalysis() { DA
.reset(nullptr); }
72 DominatorAnalysis
<true> &DataflowInfoManager::getPostDominatorAnalysis() {
75 PDA
.reset(new DominatorAnalysis
<true>(BF
, AllocatorId
));
80 void DataflowInfoManager::invalidatePostDominatorAnalysis() {
84 StackPointerTracking
&DataflowInfoManager::getStackPointerTracking() {
87 SPT
.reset(new StackPointerTracking(BF
, AllocatorId
));
92 void DataflowInfoManager::invalidateStackPointerTracking() {
93 invalidateStackAllocationAnalysis();
97 ReachingInsns
<false> &DataflowInfoManager::getReachingInsns() {
100 RI
.reset(new ReachingInsns
<false>(BF
, AllocatorId
));
105 void DataflowInfoManager::invalidateReachingInsns() { RI
.reset(nullptr); }
107 ReachingInsns
<true> &DataflowInfoManager::getReachingInsnsBackwards() {
110 RIB
.reset(new ReachingInsns
<true>(BF
, AllocatorId
));
115 void DataflowInfoManager::invalidateReachingInsnsBackwards() {
119 StackAllocationAnalysis
&DataflowInfoManager::getStackAllocationAnalysis() {
123 new StackAllocationAnalysis(BF
, getStackPointerTracking(), AllocatorId
));
128 void DataflowInfoManager::invalidateStackAllocationAnalysis() {
132 std::unordered_map
<const MCInst
*, BinaryBasicBlock
*> &
133 DataflowInfoManager::getInsnToBBMap() {
136 InsnToBB
.reset(new std::unordered_map
<const MCInst
*, BinaryBasicBlock
*>());
137 for (BinaryBasicBlock
&BB
: BF
) {
138 for (MCInst
&Inst
: BB
)
139 (*InsnToBB
)[&Inst
] = &BB
;
144 void DataflowInfoManager::invalidateInsnToBBMap() { InsnToBB
.reset(nullptr); }
146 void DataflowInfoManager::invalidateAll() {
147 invalidateReachingDefs();
148 invalidateReachingUses();
149 invalidateLivenessAnalysis();
150 invalidateStackReachingUses();
151 invalidateDominatorAnalysis();
152 invalidatePostDominatorAnalysis();
153 invalidateStackPointerTracking();
154 invalidateReachingInsns();
155 invalidateReachingInsnsBackwards();
156 invalidateStackAllocationAnalysis();
157 invalidateInsnToBBMap();
160 } // end namespace bolt
161 } // end namespace llvm