LLVM 17.0.0git
AssignmentTrackingAnalysis.h
Go to the documentation of this file.
1#ifndef LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
2#define LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
3
5#include "llvm/IR/DebugLoc.h"
7#include "llvm/Pass.h"
8
9namespace llvm {
10class Function;
11class Instruction;
12class Value;
13class raw_ostream;
14} // namespace llvm
16
17namespace llvm {
18/// Type wrapper for integer ID for Variables. 0 is reserved.
19enum class VariableID : unsigned { Reserved = 0 };
20/// Variable location definition used by FunctionVarLocs.
21struct VarLocInfo {
23 DIExpression *Expr = nullptr;
26};
27
28/// Data structure describing the variable locations in a function. Used as the
29/// result of the AssignmentTrackingAnalysis pass. Essentially read-only
30/// outside of AssignmentTrackingAnalysis where it is built.
32 /// Maps VarLocInfo.VariableID to a DebugVariable for VarLocRecords.
34 /// List of variable location changes grouped by the instruction the
35 /// change occurs before (see VarLocsBeforeInst). The elements from
36 /// zero to SingleVarLocEnd represent variables with a single location.
37 SmallVector<VarLocInfo> VarLocRecords;
38 /// End of range of VarLocRecords that represent variables with a single
39 /// location that is valid for the entire scope. Range starts at 0.
40 unsigned SingleVarLocEnd = 0;
41 /// Maps an instruction to a range of VarLocs that start just before it.
43 VarLocsBeforeInst;
44
45public:
46 /// Return the DILocalVariable for the location definition represented by \p
47 /// ID.
49 VariableID VarID = Loc->VariableID;
50 return getDILocalVariable(VarID);
51 }
52 /// Return the DILocalVariable of the variable represented by \p ID.
54 return const_cast<DILocalVariable *>(getVariable(ID).getVariable());
55 }
56 /// Return the DebugVariable represented by \p ID.
58 return Variables[static_cast<unsigned>(ID)];
59 }
60
61 ///@name iterators
62 ///@{
63 /// First single-location variable location definition.
64 const VarLocInfo *single_locs_begin() const { return VarLocRecords.begin(); }
65 /// One past the last single-location variable location definition.
66 const VarLocInfo *single_locs_end() const {
67 const auto *It = VarLocRecords.begin();
68 std::advance(It, SingleVarLocEnd);
69 return It;
70 }
71 /// First variable location definition that comes before \p Before.
72 const VarLocInfo *locs_begin(const Instruction *Before) const {
73 auto Span = VarLocsBeforeInst.lookup(Before);
74 const auto *It = VarLocRecords.begin();
75 std::advance(It, Span.first);
76 return It;
77 }
78 /// One past the last variable location definition that comes before \p
79 /// Before.
80 const VarLocInfo *locs_end(const Instruction *Before) const {
81 auto Span = VarLocsBeforeInst.lookup(Before);
82 const auto *It = VarLocRecords.begin();
83 std::advance(It, Span.second);
84 return It;
85 }
86 ///@}
87
88 void print(raw_ostream &OS, const Function &Fn) const;
89
90 ///@{
91 /// Non-const methods used by AssignmentTrackingAnalysis (which invalidate
92 /// analysis results if called incorrectly).
93 void init(FunctionVarLocsBuilder &Builder);
94 void clear();
95 ///@}
96};
97
99 std::unique_ptr<FunctionVarLocs> Results;
100
101public:
102 static char ID;
103
105
106 bool runOnFunction(Function &F) override;
107
108 static bool isRequired() { return true; }
109
110 void getAnalysisUsage(AnalysisUsage &AU) const override {
111 AU.setPreservesAll();
112 }
113
114 const FunctionVarLocs *getResults() { return Results.get(); }
115};
116
117} // end namespace llvm
118#endif // LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
Function Alias Analysis Results
#define F(x, y, z)
Definition: MD5.cpp:55
raw_pwrite_stream & OS
Helper class to build FunctionVarLocs, since that class isn't easy to modify.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
DWARF expression.
A debug info location.
Definition: DebugLoc.h:33
Identifies a unique instance of a variable.
const DILocalVariable * getVariable() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
Data structure describing the variable locations in a function.
void print(raw_ostream &OS, const Function &Fn) const
const VarLocInfo * locs_begin(const Instruction *Before) const
First variable location definition that comes before Before.
const VarLocInfo * single_locs_begin() const
DILocalVariable * getDILocalVariable(const VarLocInfo *Loc) const
Return the DILocalVariable for the location definition represented by ID.
DILocalVariable * getDILocalVariable(VariableID ID) const
Return the DILocalVariable of the variable represented by ID.
const DebugVariable & getVariable(VariableID ID) const
Return the DebugVariable represented by ID.
const VarLocInfo * locs_end(const Instruction *Before) const
One past the last variable location definition that comes before Before.
const VarLocInfo * single_locs_end() const
One past the last single-location variable location definition.
void init(FunctionVarLocsBuilder &Builder)
Lightweight class that wraps the location operand metadata of a debug intrinsic.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
VariableID
Type wrapper for integer ID for Variables. 0 is reserved.
Variable location definition used by FunctionVarLocs.
RawLocationWrapper Values