LLVM 22.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
17#include "llvm/IR/Instruction.h"
19
20namespace llvm {
21class AssumptionCache;
22class DominatorTree;
23class DataLayout;
24class TargetLibraryInfo;
25
26/// PHITransAddr - An address value which tracks and handles phi translation.
27/// As we walk "up" the CFG through predecessors, we need to ensure that the
28/// address we're tracking is kept up to date. For example, if we're analyzing
29/// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
30/// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
31/// incorrect pointer in the predecessor block.
32///
33/// This is designed to be a relatively small object that lives on the stack and
34/// is copyable.
35///
37 /// Addr - The actual address we're analyzing.
38 Value *Addr;
39
40 /// The DataLayout we are playing with.
41 const DataLayout &DL;
42
43 /// TLI - The target library info if known, otherwise null.
44 const TargetLibraryInfo *TLI = nullptr;
45
46 /// A cache of \@llvm.assume calls used by SimplifyInstruction.
48
49 /// InstInputs - The inputs for our symbolic address.
51
52public:
54 : Addr(Addr), DL(DL), AC(AC) {
55 // If the address is an instruction, the whole thing is considered an input.
56 addAsInput(Addr);
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 return any_of(InstInputs, [BB](const auto &InstInput) {
67 return InstInput->getParent() == BB;
68 });
69 }
70
71 /// isPotentiallyPHITranslatable - If this needs PHI translation, return true
72 /// if we have some hope of doing it. This should be used as a filter to
73 /// avoid calling PHITranslateValue in hopeless situations.
75
76 /// translateValue - PHI translate the current address up the CFG from
77 /// CurBB to Pred, updating our state to reflect any needed changes. If
78 /// 'MustDominate' is true, the translated value must dominate PredBB.
80 const DominatorTree *DT, bool MustDominate);
81
82 /// translateWithInsertion - PHI translate this value into the specified
83 /// predecessor block, inserting a computation of the value if it is
84 /// unavailable.
85 ///
86 /// All newly created instructions are added to the NewInsts list. This
87 /// returns null on failure.
88 ///
91 const DominatorTree &DT,
93
94 LLVM_ABI void dump() const;
95
96 /// verify - Check internal consistency of this data structure. If the
97 /// structure is valid, it returns true. If invalid, it prints errors and
98 /// returns false.
99 LLVM_ABI bool verify() const;
100
101private:
102 Value *translateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB,
103 const DominatorTree *DT);
104
105 /// insertTranslatedSubExpr - Insert a computation of the PHI translated
106 /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
107 /// block. All newly created instructions are added to the NewInsts list.
108 /// This returns null on failure.
109 ///
110 Value *insertTranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
111 BasicBlock *PredBB, const DominatorTree &DT,
113
114 /// addAsInput - If the specified value is an instruction, add it as an input.
115 Value *addAsInput(Value *V) {
116 // If V is an instruction, it is now an input.
117 if (Instruction *VI = dyn_cast<Instruction>(V))
118 InstInputs.push_back(VI);
119 return V;
120 }
121};
122
123} // end namespace llvm
124
125#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition: Compiler.h:213
uint64_t Addr
This file defines the SmallVector class.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:165
PHITransAddr - An address value which tracks and handles phi translation.
Definition: PHITransAddr.h:36
LLVM_ABI Value * translateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
translateValue - PHI translate the current address up the CFG from CurBB to Pred, updating our state ...
LLVM_ABI void dump() const
PHITransAddr(Value *Addr, const DataLayout &DL, AssumptionCache *AC)
Definition: PHITransAddr.h:53
LLVM_ABI bool isPotentiallyPHITranslatable() const
isPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
LLVM_ABI bool verify() const
verify - Check internal consistency of this data structure.
LLVM_ABI Value * translateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl< Instruction * > &NewInsts)
translateWithInsertion - PHI translate this value into the specified predecessor block,...
bool needsPHITranslationFromBlock(BasicBlock *BB) const
needsPHITranslationFromBlock - Return true if moving from the specified BasicBlock to its predecessor...
Definition: PHITransAddr.h:63
Value * getAddr() const
Definition: PHITransAddr.h:59
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
Provides information about what library functions are available for the current target.
LLVM Value Representation.
Definition: Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1751