summaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
diff options
context:
space:
mode:
authorvvvv <[email protected]>2024-02-06 20:01:22 +0300
committervvvv <[email protected]>2024-02-06 20:22:16 +0300
commit0203b7a9a40828bb2bd4c32029b79ff0ea3d1f8f (patch)
treee630d0d5bd0bd29fc8c2d2842ed2cfde781b993a /contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
parentba27db76d99d12a4f1c06960b5449423218614c4 (diff)
llvm16 targets
Diffstat (limited to 'contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h')
-rw-r--r--contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h128
1 files changed, 128 insertions, 0 deletions
diff --git a/contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h b/contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
new file mode 100644
index 00000000000..d7f15023d30
--- /dev/null
+++ b/contrib/libs/llvm16/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
@@ -0,0 +1,128 @@
+#pragma once
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#endif
+
+#ifndef LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
+#define LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
+
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/DebugLoc.h"
+#include "llvm/Pass.h"
+
+namespace llvm {
+class Function;
+class Instruction;
+class Value;
+class raw_ostream;
+} // namespace llvm
+class FunctionVarLocsBuilder;
+
+namespace llvm {
+/// Type wrapper for integer ID for Variables. 0 is reserved.
+enum class VariableID : unsigned { Reserved = 0 };
+/// Variable location definition used by FunctionVarLocs.
+struct VarLocInfo {
+ llvm::VariableID VariableID;
+ DIExpression *Expr = nullptr;
+ DebugLoc DL;
+ Value *V = nullptr; // TODO: Needs to be value_s_ for variadic expressions.
+};
+
+/// Data structure describing the variable locations in a function. Used as the
+/// result of the AssignmentTrackingAnalysis pass. Essentially read-only
+/// outside of AssignmentTrackingAnalysis where it is built.
+class FunctionVarLocs {
+ /// Maps VarLocInfo.VariableID to a DebugVariable for VarLocRecords.
+ SmallVector<DebugVariable> Variables;
+ /// List of variable location changes grouped by the instruction the
+ /// change occurs before (see VarLocsBeforeInst). The elements from
+ /// zero to SingleVarLocEnd represent variables with a single location.
+ SmallVector<VarLocInfo> VarLocRecords;
+ /// End of range of VarLocRecords that represent variables with a single
+ /// location that is valid for the entire scope. Range starts at 0.
+ unsigned SingleVarLocEnd = 0;
+ /// Maps an instruction to a range of VarLocs that start just before it.
+ DenseMap<const Instruction *, std::pair<unsigned, unsigned>>
+ VarLocsBeforeInst;
+
+public:
+ /// Return the DILocalVariable for the location definition represented by \p
+ /// ID.
+ DILocalVariable *getDILocalVariable(const VarLocInfo *Loc) const {
+ VariableID VarID = Loc->VariableID;
+ return getDILocalVariable(VarID);
+ }
+ /// Return the DILocalVariable of the variable represented by \p ID.
+ DILocalVariable *getDILocalVariable(VariableID ID) const {
+ return const_cast<DILocalVariable *>(getVariable(ID).getVariable());
+ }
+ /// Return the DebugVariable represented by \p ID.
+ const DebugVariable &getVariable(VariableID ID) const {
+ return Variables[static_cast<unsigned>(ID)];
+ }
+
+ ///@name iterators
+ ///@{
+ /// First single-location variable location definition.
+ const VarLocInfo *single_locs_begin() const { return VarLocRecords.begin(); }
+ /// One past the last single-location variable location definition.
+ const VarLocInfo *single_locs_end() const {
+ const auto *It = VarLocRecords.begin();
+ std::advance(It, SingleVarLocEnd);
+ return It;
+ }
+ /// First variable location definition that comes before \p Before.
+ const VarLocInfo *locs_begin(const Instruction *Before) const {
+ auto Span = VarLocsBeforeInst.lookup(Before);
+ const auto *It = VarLocRecords.begin();
+ std::advance(It, Span.first);
+ return It;
+ }
+ /// One past the last variable location definition that comes before \p
+ /// Before.
+ const VarLocInfo *locs_end(const Instruction *Before) const {
+ auto Span = VarLocsBeforeInst.lookup(Before);
+ const auto *It = VarLocRecords.begin();
+ std::advance(It, Span.second);
+ return It;
+ }
+ ///@}
+
+ void print(raw_ostream &OS, const Function &Fn) const;
+
+ ///@{
+ /// Non-const methods used by AssignmentTrackingAnalysis (which invalidate
+ /// analysis results if called incorrectly).
+ void init(FunctionVarLocsBuilder &Builder);
+ void clear();
+ ///@}
+};
+
+class AssignmentTrackingAnalysis : public FunctionPass {
+ std::unique_ptr<FunctionVarLocs> Results;
+
+public:
+ static char ID;
+
+ AssignmentTrackingAnalysis();
+
+ bool runOnFunction(Function &F) override;
+
+ static bool isRequired() { return true; }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+
+ const FunctionVarLocs *getResults() { return Results.get(); }
+};
+
+} // end namespace llvm
+#endif // LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif