LLVM 18.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 raw_ostream;
13} // namespace llvm
15
16namespace llvm {
17/// Type wrapper for integer ID for Variables. 0 is reserved.
18enum class VariableID : unsigned { Reserved = 0 };
19/// Variable location definition used by FunctionVarLocs.
20struct VarLocInfo {
22 DIExpression *Expr = nullptr;
25};
26
27/// Data structure describing the variable locations in a function. Used as the
28/// result of the AssignmentTrackingAnalysis pass. Essentially read-only
29/// outside of AssignmentTrackingAnalysis where it is built.
31 /// Maps VarLocInfo.VariableID to a DebugVariable for VarLocRecords.
33 /// List of variable location changes grouped by the instruction the
34 /// change occurs before (see VarLocsBeforeInst). The elements from
35 /// zero to SingleVarLocEnd represent variables with a single location.
36 SmallVector<VarLocInfo> VarLocRecords;
37 /// End of range of VarLocRecords that represent variables with a single
38 /// location that is valid for the entire scope. Range starts at 0.
39 unsigned SingleVarLocEnd = 0;
40 /// Maps an instruction to a range of VarLocs that start just before it.
42 VarLocsBeforeInst;
43
44public:
45 /// Return the DILocalVariable for the location definition represented by \p
46 /// ID.
48 VariableID VarID = Loc->VariableID;
49 return getDILocalVariable(VarID);
50 }
51 /// Return the DILocalVariable of the variable represented by \p ID.
53 return const_cast<DILocalVariable *>(getVariable(ID).getVariable());
54 }
55 /// Return the DebugVariable represented by \p ID.
57 return Variables[static_cast<unsigned>(ID)];
58 }
59
60 ///@name iterators
61 ///@{
62 /// First single-location variable location definition.
63 const VarLocInfo *single_locs_begin() const { return VarLocRecords.begin(); }
64 /// One past the last single-location variable location definition.
65 const VarLocInfo *single_locs_end() const {
66 const auto *It = VarLocRecords.begin();
67 std::advance(It, SingleVarLocEnd);
68 return It;
69 }
70 /// First variable location definition that comes before \p Before.
71 const VarLocInfo *locs_begin(const Instruction *Before) const {
72 auto Span = VarLocsBeforeInst.lookup(Before);
73 const auto *It = VarLocRecords.begin();
74 std::advance(It, Span.first);
75 return It;
76 }
77 /// One past the last variable location definition that comes before \p
78 /// Before.
79 const VarLocInfo *locs_end(const Instruction *Before) const {
80 auto Span = VarLocsBeforeInst.lookup(Before);
81 const auto *It = VarLocRecords.begin();
82 std::advance(It, Span.second);
83 return It;
84 }
85 ///@}
86
87 void print(raw_ostream &OS, const Function &Fn) const;
88
89 ///@{
90 /// Non-const methods used by AssignmentTrackingAnalysis (which invalidate
91 /// analysis results if called incorrectly).
92 void init(FunctionVarLocsBuilder &Builder);
93 void clear();
94 ///@}
95};
96
98 std::unique_ptr<FunctionVarLocs> Results;
99
100public:
101 static char ID;
102
104
105 bool runOnFunction(Function &F) override;
106
107 static bool isRequired() { return true; }
108
109 void getAnalysisUsage(AnalysisUsage &AU) const override {
110 AU.setPreservesAll();
111 }
112
113 const FunctionVarLocs *getResults() { return Results.get(); }
114};
115
116} // end namespace llvm
117#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