|
|
|||
File indexing completed on 2026-05-10 08:44:10
0001 //===- llvm/Use.h - Definition of the Use class -----------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 /// \file 0009 /// 0010 /// This defines the Use class. The Use class represents the operand of an 0011 /// instruction or some other User instance which refers to a Value. The Use 0012 /// class keeps the "use list" of the referenced value up to date. 0013 /// 0014 /// Pointer tagging is used to efficiently find the User corresponding to a Use 0015 /// without having to store a User pointer in every Use. A User is preceded in 0016 /// memory by all the Uses corresponding to its operands, and the low bits of 0017 /// one of the fields (Prev) of the Use class are used to encode offsets to be 0018 /// able to find that User given a pointer to any Use. For details, see: 0019 /// 0020 /// http://www.llvm.org/docs/ProgrammersManual.html#UserLayout 0021 /// 0022 //===----------------------------------------------------------------------===// 0023 0024 #ifndef LLVM_IR_USE_H 0025 #define LLVM_IR_USE_H 0026 0027 #include "llvm-c/Types.h" 0028 #include "llvm/Support/CBindingWrapping.h" 0029 #include "llvm/Support/Compiler.h" 0030 0031 namespace llvm { 0032 0033 template <typename> struct simplify_type; 0034 class User; 0035 class Value; 0036 0037 /// A Use represents the edge between a Value definition and its users. 0038 /// 0039 /// This is notionally a two-dimensional linked list. It supports traversing 0040 /// all of the uses for a particular value definition. It also supports jumping 0041 /// directly to the used value when we arrive from the User's operands, and 0042 /// jumping directly to the User when we arrive from the Value's uses. 0043 class Use { 0044 public: 0045 Use(const Use &U) = delete; 0046 0047 /// Provide a fast substitute to std::swap<Use> 0048 /// that also works with less standard-compliant compilers 0049 void swap(Use &RHS); 0050 0051 private: 0052 /// Destructor - Only for zap() 0053 ~Use() { 0054 if (Val) 0055 removeFromList(); 0056 } 0057 0058 /// Constructor 0059 Use(User *Parent) : Parent(Parent) {} 0060 0061 public: 0062 friend class Value; 0063 friend class User; 0064 0065 operator Value *() const { return Val; } 0066 Value *get() const { return Val; } 0067 0068 /// Returns the User that contains this Use. 0069 /// 0070 /// For an instruction operand, for example, this will return the 0071 /// instruction. 0072 User *getUser() const { return Parent; }; 0073 0074 inline void set(Value *Val); 0075 0076 inline Value *operator=(Value *RHS); 0077 inline const Use &operator=(const Use &RHS); 0078 0079 Value *operator->() { return Val; } 0080 const Value *operator->() const { return Val; } 0081 0082 Use *getNext() const { return Next; } 0083 0084 /// Return the operand # of this use in its User. 0085 unsigned getOperandNo() const; 0086 0087 /// Destroys Use operands when the number of operands of 0088 /// a User changes. 0089 static void zap(Use *Start, const Use *Stop, bool del = false); 0090 0091 private: 0092 0093 Value *Val = nullptr; 0094 Use *Next = nullptr; 0095 Use **Prev = nullptr; 0096 User *Parent = nullptr; 0097 0098 void addToList(Use **List) { 0099 Next = *List; 0100 if (Next) 0101 Next->Prev = &Next; 0102 Prev = List; 0103 *Prev = this; 0104 } 0105 0106 void removeFromList() { 0107 *Prev = Next; 0108 if (Next) 0109 Next->Prev = Prev; 0110 } 0111 }; 0112 0113 /// Allow clients to treat uses just like values when using 0114 /// casting operators. 0115 template <> struct simplify_type<Use> { 0116 using SimpleType = Value *; 0117 0118 static SimpleType getSimplifiedValue(Use &Val) { return Val.get(); } 0119 }; 0120 template <> struct simplify_type<const Use> { 0121 using SimpleType = /*const*/ Value *; 0122 0123 static SimpleType getSimplifiedValue(const Use &Val) { return Val.get(); } 0124 }; 0125 0126 // Create wrappers for C Binding types (see CBindingWrapping.h). 0127 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef) 0128 0129 } // end namespace llvm 0130 0131 #endif // LLVM_IR_USE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|