LLVM  14.0.0git
PHITransAddr.h
Go to the documentation of this file.
1 //===- PHITransAddr.h - PHI Translation for Addresses -----------*- 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 // This file declares the PHITransAddr class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_ANALYSIS_PHITRANSADDR_H
14 #define LLVM_ANALYSIS_PHITRANSADDR_H
15 
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/IR/Instruction.h"
18 
19 namespace llvm {
20  class AssumptionCache;
21  class DominatorTree;
22  class DataLayout;
23  class TargetLibraryInfo;
24 
25 /// PHITransAddr - An address value which tracks and handles phi translation.
26 /// As we walk "up" the CFG through predecessors, we need to ensure that the
27 /// address we're tracking is kept up to date. For example, if we're analyzing
28 /// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
29 /// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
30 /// incorrect pointer in the predecessor block.
31 ///
32 /// This is designed to be a relatively small object that lives on the stack and
33 /// is copyable.
34 ///
35 class PHITransAddr {
36  /// Addr - The actual address we're analyzing.
37  Value *Addr;
38 
39  /// The DataLayout we are playing with.
40  const DataLayout &DL;
41 
42  /// TLI - The target library info if known, otherwise null.
43  const TargetLibraryInfo *TLI;
44 
45  /// A cache of \@llvm.assume calls used by SimplifyInstruction.
46  AssumptionCache *AC;
47 
48  /// InstInputs - The inputs for our symbolic address.
50 
51 public:
53  : Addr(addr), DL(DL), TLI(nullptr), AC(AC) {
54  // If the address is an instruction, the whole thing is considered an input.
55  if (Instruction *I = dyn_cast<Instruction>(Addr))
56  InstInputs.push_back(I);
57  }
58 
59  Value *getAddr() const { return Addr; }
60 
61  /// NeedsPHITranslationFromBlock - Return true if moving from the specified
62  /// BasicBlock to its predecessors requires PHI translation.
64  // We do need translation if one of our input instructions is defined in
65  // this block.
66  for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
67  if (InstInputs[i]->getParent() == BB)
68  return true;
69  return false;
70  }
71 
72  /// IsPotentiallyPHITranslatable - If this needs PHI translation, return true
73  /// if we have some hope of doing it. This should be used as a filter to
74  /// avoid calling PHITranslateValue in hopeless situations.
75  bool IsPotentiallyPHITranslatable() const;
76 
77  /// PHITranslateValue - PHI translate the current address up the CFG from
78  /// CurBB to Pred, updating our state to reflect any needed changes. If
79  /// 'MustDominate' is true, the translated value must dominate
80  /// PredBB. This returns true on failure and sets Addr to null.
81  bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
82  const DominatorTree *DT, bool MustDominate);
83 
84  /// PHITranslateWithInsertion - PHI translate this value into the specified
85  /// predecessor block, inserting a computation of the value if it is
86  /// unavailable.
87  ///
88  /// All newly created instructions are added to the NewInsts list. This
89  /// returns null on failure.
90  ///
92  const DominatorTree &DT,
94 
95  void dump() const;
96 
97  /// Verify - Check internal consistency of this data structure. If the
98  /// structure is valid, it returns true. If invalid, it prints errors and
99  /// returns false.
100  bool Verify() const;
101 
102 private:
103  Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB,
104  const DominatorTree *DT);
105 
106  /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
107  /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
108  /// block. All newly created instructions are added to the NewInsts list.
109  /// This returns null on failure.
110  ///
111  Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
112  BasicBlock *PredBB, const DominatorTree &DT,
114 
115  /// AddAsInput - If the specified value is an instruction, add it as an input.
116  Value *AddAsInput(Value *V) {
117  // If V is an instruction, it is now an input.
118  if (Instruction *VI = dyn_cast<Instruction>(V))
119  InstInputs.push_back(VI);
120  return V;
121  }
122 };
123 
124 } // end namespace llvm
125 
126 #endif
i
i
Definition: README.txt:29
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:112
llvm::PHITransAddr
PHITransAddr - An address value which tracks and handles phi translation.
Definition: PHITransAddr.h:35
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
llvm::PHITransAddr::PHITranslateWithInsertion
Value * PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl< Instruction * > &NewInsts)
PHITranslateWithInsertion - PHI translate this value into the specified predecessor block,...
Definition: PHITransAddr.cpp:341
llvm::PHITransAddr::IsPotentiallyPHITranslatable
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
Definition: PHITransAddr.cpp:114
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
Instruction.h
llvm::Instruction
Definition: Instruction.h:45
VI
@ VI
Definition: SIInstrInfo.cpp:7679
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:80
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::PHITransAddr::PHITransAddr
PHITransAddr(Value *addr, const DataLayout &DL, AssumptionCache *AC)
Definition: PHITransAddr.h:52
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::PHITransAddr::PHITranslateValue
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
PHITranslateValue - PHI translate the current address up the CFG from CurBB to Pred,...
Definition: PHITransAddr.cpp:312
llvm::PHITransAddr::dump
void dump() const
Definition: PHITransAddr.cpp:45
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
getParent
static const Function * getParent(const Value *V)
Definition: BasicAliasAnalysis.cpp:776
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::PHITransAddr::Verify
bool Verify() const
Verify - Check internal consistency of this data structure.
Definition: PHITransAddr.cpp:91
llvm::PHITransAddr::getAddr
Value * getAddr() const
Definition: PHITransAddr.h:59
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:219
SmallVector.h
llvm::SmallVectorImpl< Instruction * >
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::PHITransAddr::NeedsPHITranslationFromBlock
bool NeedsPHITranslationFromBlock(BasicBlock *BB) const
NeedsPHITranslationFromBlock - Return true if moving from the specified BasicBlock to its predecessor...
Definition: PHITransAddr.h:63
llvm::Value
LLVM Value Representation.
Definition: Value.h:75