LLVM 21.0.0git
Use.h
Go to the documentation of this file.
1//===- llvm/Use.h - Definition of the Use class -----------------*- 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/// \file
9///
10/// This defines the Use class. The Use class represents the operand of an
11/// instruction or some other User instance which refers to a Value. The Use
12/// class keeps the "use list" of the referenced value up to date.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_IR_USE_H
17#define LLVM_IR_USE_H
18
19#include "llvm-c/Types.h"
22
23namespace llvm {
24
25template <typename> struct simplify_type;
26class User;
27class Value;
28
29/// A Use represents the edge between a Value definition and its users.
30///
31/// This is notionally a two-dimensional linked list. It supports traversing
32/// all of the uses for a particular value definition. It also supports jumping
33/// directly to the used value when we arrive from the User's operands, and
34/// jumping directly to the User when we arrive from the Value's uses.
35class Use {
36public:
37 Use(const Use &U) = delete;
38
39 /// Provide a fast substitute to std::swap<Use>
40 /// that also works with less standard-compliant compilers
41 void swap(Use &RHS);
42
43private:
44 /// Destructor - Only for zap()
45 ~Use() {
46 if (Val)
47 removeFromList();
48 }
49
50 /// Constructor
51 Use(User *Parent) : Parent(Parent) {}
52
53public:
54 friend class Value;
55 friend class User;
56
57 operator Value *() const { return Val; }
58 Value *get() const { return Val; }
59
60 /// Returns the User that contains this Use.
61 ///
62 /// For an instruction operand, for example, this will return the
63 /// instruction.
64 User *getUser() const { return Parent; };
65
66 inline void set(Value *Val);
67
68 inline Value *operator=(Value *RHS);
69 inline const Use &operator=(const Use &RHS);
70
71 Value *operator->() { return Val; }
72 const Value *operator->() const { return Val; }
73
74 Use *getNext() const { return Next; }
75
76 /// Return the operand # of this use in its User.
77 unsigned getOperandNo() const;
78
79 /// Destroys Use operands when the number of operands of
80 /// a User changes.
81 static void zap(Use *Start, const Use *Stop, bool del = false);
82
83private:
84
85 Value *Val = nullptr;
86 Use *Next = nullptr;
87 Use **Prev = nullptr;
88 User *Parent = nullptr;
89
90 void addToList(Use **List) {
91 Next = *List;
92 if (Next)
93 Next->Prev = &Next;
94 Prev = List;
95 *Prev = this;
96 }
97
98 void removeFromList() {
99 *Prev = Next;
100 if (Next)
101 Next->Prev = Prev;
102 }
103};
104
105/// Allow clients to treat uses just like values when using
106/// casting operators.
107template <> struct simplify_type<Use> {
108 using SimpleType = Value *;
109
110 static SimpleType getSimplifiedValue(Use &Val) { return Val.get(); }
111};
112template <> struct simplify_type<const Use> {
113 using SimpleType = /*const*/ Value *;
114
115 static SimpleType getSimplifiedValue(const Use &Val) { return Val.get(); }
116};
117
118// Create wrappers for C Binding types (see CBindingWrapping.h).
120
121} // end namespace llvm
122
123#endif // LLVM_IR_USE_H
aarch64 promote const
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Value * RHS
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
static void zap(Use *Start, const Use *Stop, bool del=false)
Destroys Use operands when the number of operands of a User changes.
Definition: Use.cpp:35
const Value * operator->() const
Definition: Use.h:72
void set(Value *Val)
Definition: Value.h:892
User * getUser() const
Returns the User that contains this Use.
Definition: Use.h:64
unsigned getOperandNo() const
Return the operand # of this use in its User.
Definition: Use.cpp:31
void swap(Use &RHS)
Provide a fast substitute to std::swap<Use> that also works with less standard-compliant compilers.
Definition: Use.cpp:14
Use(const Use &U)=delete
Value * operator->()
Definition: Use.h:71
Use * getNext() const
Definition: Use.h:74
Value * get() const
Definition: Use.h:58
Value * operator=(Value *RHS)
Definition: Value.h:898
LLVM Value Representation.
Definition: Value.h:74
struct LLVMOpaqueUse * LLVMUseRef
Used to get the users and usees of a Value.
Definition: Types.h:133
@ User
could "use" a pointer
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
static SimpleType getSimplifiedValue(Use &Val)
Definition: Use.h:110
static SimpleType getSimplifiedValue(const Use &Val)
Definition: Use.h:115
Define a template that can be specialized by smart pointers to reflect the fact that they are automat...
Definition: Casting.h:34