2003-10-16 16:53:04 +00:00
|
|
|
//===-- llvm/Use.h - Definition of the Use class ----------------*- C++ -*-===//
|
2003-10-20 20:19:47 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-16 16:53:04 +00:00
|
|
|
//
|
|
|
|
// This defines the Use class. The Use class represents the operand of an
|
|
|
|
// instruction or some other User instance which refers to a Value. The Use
|
|
|
|
// class keeps the "use list" of the referenced value up to date.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_USE_H
|
|
|
|
#define LLVM_USE_H
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/ilist"
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2003-10-16 16:53:04 +00:00
|
|
|
template<typename NodeTy> struct ilist_traits;
|
|
|
|
class Value;
|
|
|
|
class User;
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Use Class
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Use is here to make keeping the "use" list of a Value up-to-date really easy.
|
|
|
|
//
|
|
|
|
class Use {
|
|
|
|
Value *Val;
|
|
|
|
User *U;
|
|
|
|
Use *Prev, *Next;
|
|
|
|
friend class ilist_traits<Use>;
|
|
|
|
public:
|
|
|
|
inline Use(Value *v, User *user);
|
|
|
|
inline Use(const Use &u);
|
|
|
|
inline ~Use();
|
|
|
|
|
|
|
|
operator Value*() const { return Val; }
|
|
|
|
Value *get() const { return Val; }
|
|
|
|
User *getUser() const { return U; }
|
|
|
|
|
|
|
|
inline void set(Value *Val);
|
|
|
|
|
|
|
|
Value *operator=(Value *RHS) {
|
|
|
|
set(RHS);
|
|
|
|
return RHS;
|
|
|
|
}
|
|
|
|
const Use &operator=(const Use &RHS) {
|
|
|
|
set(RHS.Val);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value *operator->() { return Val; }
|
|
|
|
const Value *operator->() const { return Val; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ilist_traits<Use> {
|
|
|
|
static Use *getPrev(Use *N) { return N->Prev; }
|
|
|
|
static Use *getNext(Use *N) { return N->Next; }
|
|
|
|
static const Use *getPrev(const Use *N) { return N->Prev; }
|
|
|
|
static const Use *getNext(const Use *N) { return N->Next; }
|
|
|
|
static void setPrev(Use *N, Use *Prev) { N->Prev = Prev; }
|
|
|
|
static void setNext(Use *N, Use *Next) { N->Next = Next; }
|
|
|
|
|
|
|
|
// createNode - this is used to create the end marker for the use list
|
|
|
|
static Use *createNode() { return new Use(0,0); }
|
|
|
|
|
|
|
|
void addNodeToList(Use *NTy) {}
|
|
|
|
void removeNodeFromList(Use *NTy) {}
|
|
|
|
void transferNodesFromList(iplist<Use, ilist_traits> &L2,
|
|
|
|
ilist_iterator<Use> first,
|
|
|
|
ilist_iterator<Use> last) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-11-14 06:03:05 +00:00
|
|
|
template<> struct simplify_type<Use> {
|
2003-10-16 16:53:04 +00:00
|
|
|
typedef Value* SimpleType;
|
|
|
|
static SimpleType getSimplifiedValue(const Use &Val) {
|
2003-11-16 20:21:15 +00:00
|
|
|
return static_cast<SimpleType>(Val.get());
|
2003-10-16 16:53:04 +00:00
|
|
|
}
|
|
|
|
};
|
2003-11-14 06:03:05 +00:00
|
|
|
template<> struct simplify_type<const Use> {
|
2003-10-16 16:53:04 +00:00
|
|
|
typedef Value* SimpleType;
|
|
|
|
static SimpleType getSimplifiedValue(const Use &Val) {
|
2003-11-16 20:21:15 +00:00
|
|
|
return static_cast<SimpleType>(Val.get());
|
2003-10-16 16:53:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UseListIteratorWrapper : public iplist<Use>::iterator {
|
|
|
|
typedef iplist<Use>::iterator Super;
|
|
|
|
UseListIteratorWrapper() {}
|
|
|
|
UseListIteratorWrapper(const Super &RHS) : Super(RHS) {}
|
|
|
|
|
|
|
|
UseListIteratorWrapper &operator=(const Super &RHS) {
|
|
|
|
Super::operator=(RHS);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline User *operator*() const;
|
|
|
|
User *operator->() const { return operator*(); }
|
|
|
|
|
|
|
|
UseListIteratorWrapper operator--() { return Super::operator--(); }
|
|
|
|
UseListIteratorWrapper operator++() { return Super::operator++(); }
|
|
|
|
|
|
|
|
UseListIteratorWrapper operator--(int) { // postdecrement operators...
|
|
|
|
UseListIteratorWrapper tmp = *this;
|
|
|
|
--*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
UseListIteratorWrapper operator++(int) { // postincrement operators...
|
|
|
|
UseListIteratorWrapper tmp = *this;
|
|
|
|
++*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UseListConstIteratorWrapper : public iplist<Use>::const_iterator {
|
|
|
|
typedef iplist<Use>::const_iterator Super;
|
|
|
|
UseListConstIteratorWrapper() {}
|
|
|
|
UseListConstIteratorWrapper(const Super &RHS) : Super(RHS) {}
|
|
|
|
|
|
|
|
// Allow conversion from non-const to const iterators
|
|
|
|
UseListConstIteratorWrapper(const UseListIteratorWrapper &RHS) : Super(RHS) {}
|
|
|
|
UseListConstIteratorWrapper(const iplist<Use>::iterator &RHS) : Super(RHS) {}
|
|
|
|
|
|
|
|
UseListConstIteratorWrapper &operator=(const Super &RHS) {
|
|
|
|
Super::operator=(RHS);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const User *operator*() const;
|
|
|
|
const User *operator->() const { return operator*(); }
|
|
|
|
|
|
|
|
UseListConstIteratorWrapper operator--() { return Super::operator--(); }
|
|
|
|
UseListConstIteratorWrapper operator++() { return Super::operator++(); }
|
|
|
|
|
|
|
|
UseListConstIteratorWrapper operator--(int) { // postdecrement operators...
|
|
|
|
UseListConstIteratorWrapper tmp = *this;
|
|
|
|
--*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
UseListConstIteratorWrapper operator++(int) { // postincrement operators...
|
|
|
|
UseListConstIteratorWrapper tmp = *this;
|
|
|
|
++*this;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2003-10-16 16:53:04 +00:00
|
|
|
#endif
|