1 //===- bolt/Passes/DataflowAnalysis.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 functions and classes used for data-flow analysis.
11 //===----------------------------------------------------------------------===//
13 #include "bolt/Passes/DataflowAnalysis.h"
14 #include "llvm/MC/MCRegisterInfo.h"
16 #define DEBUG_TYPE "dataflow"
20 raw_ostream
&operator<<(raw_ostream
&OS
, const BitVector
&State
) {
24 if (State
.count() > (State
.size() >> 1)) {
25 OS
<< "all, except: ";
28 for (int I
: BV
.set_bits()) {
35 for (int I
: State
.set_bits()) {
48 void doForAllPreds(const BinaryBasicBlock
&BB
,
49 std::function
<void(ProgramPoint
)> Task
) {
50 MCPlusBuilder
*MIB
= BB
.getFunction()->getBinaryContext().MIB
.get();
51 for (BinaryBasicBlock
*Pred
: BB
.predecessors()) {
53 Task(ProgramPoint::getLastPointAt(*Pred
));
55 if (!BB
.isLandingPad())
57 for (BinaryBasicBlock
*Thrower
: BB
.throwers()) {
58 for (MCInst
&Inst
: *Thrower
) {
59 if (!MIB
->isInvoke(Inst
))
61 const std::optional
<MCPlus::MCLandingPad
> EHInfo
= MIB
->getEHInfo(Inst
);
62 if (!EHInfo
|| EHInfo
->first
!= BB
.getLabel())
64 Task(ProgramPoint(&Inst
));
69 /// Operates on all successors of a basic block.
70 void doForAllSuccs(const BinaryBasicBlock
&BB
,
71 std::function
<void(ProgramPoint
)> Task
) {
72 for (BinaryBasicBlock
*Succ
: BB
.successors())
74 Task(ProgramPoint::getFirstPointAt(*Succ
));
77 void RegStatePrinter::print(raw_ostream
&OS
, const BitVector
&State
) const {
82 if (State
.count() > (State
.size() >> 1)) {
83 OS
<< "all, except: ";
86 for (int I
: BV
.set_bits())
87 OS
<< BC
.MRI
->getName(I
) << " ";
90 for (int I
: State
.set_bits())
91 OS
<< BC
.MRI
->getName(I
) << " ";