LLVM 19.0.0git
AssignmentTrackingAnalysis.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/AssignmentTrackingAnalysis.h --------------*- 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#ifndef LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
10#define LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
11
13#include "llvm/IR/DebugLoc.h"
15#include "llvm/IR/PassManager.h"
16#include "llvm/Pass.h"
17
18namespace llvm {
19class Instruction;
20class raw_ostream;
21} // namespace llvm
23
24namespace llvm {
25/// Type wrapper for integer ID for Variables. 0 is reserved.
26enum class VariableID : unsigned { Reserved = 0 };
27/// Variable location definition used by FunctionVarLocs.
28struct VarLocInfo {
30 DIExpression *Expr = nullptr;
33};
34
35/// Data structure describing the variable locations in a function. Used as the
36/// result of the AssignmentTrackingAnalysis pass. Essentially read-only
37/// outside of AssignmentTrackingAnalysis where it is built.
39 /// Maps VarLocInfo.VariableID to a DebugVariable for VarLocRecords.
41 /// List of variable location changes grouped by the instruction the
42 /// change occurs before (see VarLocsBeforeInst). The elements from
43 /// zero to SingleVarLocEnd represent variables with a single location.
44 SmallVector<VarLocInfo> VarLocRecords;
45 /// End of range of VarLocRecords that represent variables with a single
46 /// location that is valid for the entire scope. Range starts at 0.
47 unsigned SingleVarLocEnd = 0;
48 /// Maps an instruction to a range of VarLocs that start just before it.
50 VarLocsBeforeInst;
51
52public:
53 /// Return the DILocalVariable for the location definition represented by \p
54 /// ID.
56 VariableID VarID = Loc->VariableID;
57 return getDILocalVariable(VarID);
58 }
59 /// Return the DILocalVariable of the variable represented by \p ID.
61 return const_cast<DILocalVariable *>(getVariable(ID).getVariable());
62 }
63 /// Return the DebugVariable represented by \p ID.
65 return Variables[static_cast<unsigned>(ID)];
66 }
67
68 ///@name iterators
69 ///@{
70 /// First single-location variable location definition.
71 const VarLocInfo *single_locs_begin() const { return VarLocRecords.begin(); }
72 /// One past the last single-location variable location definition.
73 const VarLocInfo *single_locs_end() const {
74 const auto *It = VarLocRecords.begin();
75 std::advance(It, SingleVarLocEnd);
76 return It;
77 }
78 /// First variable location definition that comes before \p Before.
79 const VarLocInfo *locs_begin(const Instruction *Before) const {
80 auto Span = VarLocsBeforeInst.lookup(Before);
81 const auto *It = VarLocRecords.begin();
82 std::advance(It, Span.first);
83 return It;
84 }
85 /// One past the last variable location definition that comes before \p
86 /// Before.
87 const VarLocInfo *locs_end(const Instruction *Before) const {
88 auto Span = VarLocsBeforeInst.lookup(Before);
89 const auto *It = VarLocRecords.begin();
90 std::advance(It, Span.second);
91 return It;
92 }
93 ///@}
94
95 void print(raw_ostream &OS, const Function &Fn) const;
96
97 ///@{
98 /// Non-const methods used by AssignmentTrackingAnalysis (which invalidate
99 /// analysis results if called incorrectly).
100 void init(FunctionVarLocsBuilder &Builder);
101 void clear();
102 ///@}
103};
104
106 : public AnalysisInfoMixin<DebugAssignmentTrackingAnalysis> {
108 static AnalysisKey Key;
109
110public:
113};
114
116 : public PassInfoMixin<DebugAssignmentTrackingPrinterPass> {
117 raw_ostream &OS;
118
119public:
122};
123
125 std::unique_ptr<FunctionVarLocs> Results;
126
127public:
128 static char ID;
129
131
132 bool runOnFunction(Function &F) override;
133
134 static bool isRequired() { return true; }
135
136 void getAnalysisUsage(AnalysisUsage &AU) const override {
137 AU.setPreservesAll();
138 }
139
140 const FunctionVarLocs *getResults() { return Results.get(); }
141};
142
143} // end namespace llvm
144#endif // LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
Function Alias Analysis Results
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionAnalysisManager FAM
This header defines various interfaces for pass management in LLVM.
raw_pwrite_stream & OS
Helper class to build FunctionVarLocs, since that class isn't easy to modify.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:239
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.
Result run(Function &F, FunctionAnalysisManager &FAM)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
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)
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
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:1209
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.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:91
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:68
Variable location definition used by FunctionVarLocs.
RawLocationWrapper Values