LLVM 22.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 LLVM_ABI void swap(Use &RHS);
42
43private:
44 /// Destructor - Only for zap()
45 ~Use() { removeFromList(); }
46
47 /// Constructor
48 Use(User *Parent) : Parent(Parent) {}
49
50public:
51 friend class Value;
52 friend class User;
53
54 operator Value *() const { return Val; }
55 Value *get() const { return Val; }
56
57 /// Returns the User that contains this Use.
58 ///
59 /// For an instruction operand, for example, this will return the
60 /// instruction.
61 User *getUser() const { return Parent; };
62
63 LLVM_ABI inline void set(Value *Val);
64
66 LLVM_ABI inline const Use &operator=(const Use &RHS);
67
68 Value *operator->() { return Val; }
69 const Value *operator->() const { return Val; }
70
71 Use *getNext() const { return Next; }
72
73 /// Return the operand # of this use in its User.
74 LLVM_ABI unsigned getOperandNo() const;
75
76 /// Destroys Use operands when the number of operands of
77 /// a User changes.
78 LLVM_ABI static void zap(Use *Start, const Use *Stop, bool del = false);
79
80private:
81
82 Value *Val = nullptr;
83 Use *Next = nullptr;
84 Use **Prev = nullptr;
85 User *Parent = nullptr;
86
87 void addToList(Use **List) {
88 Next = *List;
89 if (Next)
90 Next->Prev = &Next;
91 Prev = List;
92 *Prev = this;
93 }
94
95 void removeFromList() {
96 if (Prev) {
97 *Prev = Next;
98 if (Next) {
99 Next->Prev = Prev;
100 Next = nullptr;
101 }
102
103 Prev = nullptr;
104 }
105 }
106};
107
108/// Allow clients to treat uses just like values when using
109/// casting operators.
110template <> struct simplify_type<Use> {
111 using SimpleType = Value *;
112
113 static SimpleType getSimplifiedValue(Use &Val) { return Val.get(); }
114};
115template <> struct simplify_type<const Use> {
116 using SimpleType = /*const*/ Value *;
117
118 static SimpleType getSimplifiedValue(const Use &Val) { return Val.get(); }
119};
120
121// Create wrappers for C Binding types (see CBindingWrapping.h).
123
124} // end namespace llvm
125
126#endif // LLVM_IR_USE_H
aarch64 promote const
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define LLVM_ABI
Definition: Compiler.h:213
Value * RHS
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
static LLVM_ABI 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:39
const Value * operator->() const
Definition: Use.h:69
LLVM_ABI void set(Value *Val)
Definition: Value.h:905
User * getUser() const
Returns the User that contains this Use.
Definition: Use.h:61
LLVM_ABI unsigned getOperandNo() const
Return the operand # of this use in its User.
Definition: Use.cpp:35
LLVM_ABI 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:68
Use * getNext() const
Definition: Use.h:71
Value * get() const
Definition: Use.h:55
LLVM_ABI Value * operator=(Value *RHS)
Definition: Value.h:912
LLVM Value Representation.
Definition: Value.h:75
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:113
static SimpleType getSimplifiedValue(const Use &Val)
Definition: Use.h:118
Define a template that can be specialized by smart pointers to reflect the fact that they are automat...
Definition: Casting.h:34