LLVM API Documentation
00001 //===-- llvm/Use.h - Definition of the Use class ----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This defines the Use class. The Use class represents the operand of an 00011 // instruction or some other User instance which refers to a Value. The Use 00012 // class keeps the "use list" of the referenced value up to date. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_USE_H 00017 #define LLVM_USE_H 00018 00019 #include "llvm/ADT/ilist" 00020 00021 namespace llvm { 00022 00023 template<typename NodeTy> struct ilist_traits; 00024 class Value; 00025 class User; 00026 00027 00028 //===----------------------------------------------------------------------===// 00029 // Use Class 00030 //===----------------------------------------------------------------------===// 00031 00032 // Use is here to make keeping the "use" list of a Value up-to-date really easy. 00033 // 00034 class Use { 00035 Value *Val; 00036 User *U; 00037 Use *Prev, *Next; 00038 friend struct ilist_traits<Use>; 00039 public: 00040 inline Use(Value *v, User *user); 00041 inline Use(const Use &u); 00042 inline ~Use(); 00043 00044 operator Value*() const { return Val; } 00045 Value *get() const { return Val; } 00046 User *getUser() const { return U; } 00047 00048 inline void set(Value *Val); 00049 00050 Value *operator=(Value *RHS) { 00051 set(RHS); 00052 return RHS; 00053 } 00054 const Use &operator=(const Use &RHS) { 00055 set(RHS.Val); 00056 return *this; 00057 } 00058 00059 Value *operator->() { return Val; } 00060 const Value *operator->() const { return Val; } 00061 }; 00062 00063 template<> 00064 struct ilist_traits<Use> { 00065 static Use *getPrev(Use *N) { return N->Prev; } 00066 static Use *getNext(Use *N) { return N->Next; } 00067 static const Use *getPrev(const Use *N) { return N->Prev; } 00068 static const Use *getNext(const Use *N) { return N->Next; } 00069 static void setPrev(Use *N, Use *Prev) { N->Prev = Prev; } 00070 static void setNext(Use *N, Use *Next) { N->Next = Next; } 00071 00072 // createNode - this is used to create the end marker for the use list 00073 static Use *createNode() { return new Use(0,0); } 00074 00075 void addNodeToList(Use *NTy) {} 00076 void removeNodeFromList(Use *NTy) {} 00077 void transferNodesFromList(iplist<Use, ilist_traits> &L2, 00078 ilist_iterator<Use> first, 00079 ilist_iterator<Use> last) {} 00080 }; 00081 00082 00083 template<> struct simplify_type<Use> { 00084 typedef Value* SimpleType; 00085 static SimpleType getSimplifiedValue(const Use &Val) { 00086 return static_cast<SimpleType>(Val.get()); 00087 } 00088 }; 00089 template<> struct simplify_type<const Use> { 00090 typedef Value* SimpleType; 00091 static SimpleType getSimplifiedValue(const Use &Val) { 00092 return static_cast<SimpleType>(Val.get()); 00093 } 00094 }; 00095 00096 struct UseListIteratorWrapper : public iplist<Use>::iterator { 00097 typedef iplist<Use>::iterator Super; 00098 UseListIteratorWrapper() {} 00099 UseListIteratorWrapper(const Super &RHS) : Super(RHS) {} 00100 00101 UseListIteratorWrapper &operator=(const Super &RHS) { 00102 Super::operator=(RHS); 00103 return *this; 00104 } 00105 00106 inline User *operator*() const; 00107 User *operator->() const { return operator*(); } 00108 00109 UseListIteratorWrapper operator--() { return Super::operator--(); } 00110 UseListIteratorWrapper operator++() { return Super::operator++(); } 00111 00112 UseListIteratorWrapper operator--(int) { // postdecrement operators... 00113 UseListIteratorWrapper tmp = *this; 00114 --*this; 00115 return tmp; 00116 } 00117 UseListIteratorWrapper operator++(int) { // postincrement operators... 00118 UseListIteratorWrapper tmp = *this; 00119 ++*this; 00120 return tmp; 00121 } 00122 }; 00123 00124 struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator { 00125 typedef iplist<Use>::const_iterator Super; 00126 UseListConstIteratorWrapper() {} 00127 UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {} 00128 00129 // Allow conversion from non-const to const iterators 00130 UseListConstIteratorWrapper(const UseListIteratorWrapper &RHS) : Super(RHS) {} 00131 UseListConstIteratorWrapper(const iplist<Use>::iterator &RHS) : Super(RHS) {} 00132 00133 UseListConstIteratorWrapper &operator=(const Super &RHS) { 00134 Super::operator=(RHS); 00135 return *this; 00136 } 00137 00138 inline const User *operator*() const; 00139 const User *operator->() const { return operator*(); } 00140 00141 UseListConstIteratorWrapper operator--() { return Super::operator--(); } 00142 UseListConstIteratorWrapper operator++() { return Super::operator++(); } 00143 00144 UseListConstIteratorWrapper operator--(int) { // postdecrement operators... 00145 UseListConstIteratorWrapper tmp = *this; 00146 --*this; 00147 return tmp; 00148 } 00149 UseListConstIteratorWrapper operator++(int) { // postincrement operators... 00150 UseListConstIteratorWrapper tmp = *this; 00151 ++*this; 00152 return tmp; 00153 } 00154 }; 00155 00156 } // End llvm namespace 00157 00158 #endif