+/// simplify_type specializations - Allow casting operators to work directly on
+/// SDOperands as if they were SDNode*'s.
+template<> struct simplify_type<SDOperandImpl> {
+ typedef SDNode* SimpleType;
+ static SimpleType getSimplifiedValue(const SDOperandImpl &Val) {
+ return static_cast<SimpleType>(Val.Val);
+ }
+};
+template<> struct simplify_type<const SDOperandImpl> {
+ typedef SDNode* SimpleType;
+ static SimpleType getSimplifiedValue(const SDOperandImpl &Val) {
+ return static_cast<SimpleType>(Val.Val);
+ }
+};
+
+/// SDOperand - Represents a use of the SDNode referred by
+/// the SDOperandImpl.
+class SDOperand: public SDOperandImpl {
+ /// parent - Parent node of this operand.
+ SDNode *parent;
+ /// Prev, next - Pointers to the uses list of the SDNode referred by
+ /// this operand.
+ SDOperand **Prev, *Next;
+public:
+ friend class SDNode;
+ SDOperand(): SDOperandImpl(), parent(NULL), Prev(NULL), Next(NULL) {}
+
+ SDOperand(SDNode *val, unsigned resno) :
+ SDOperandImpl(val,resno), parent(NULL), Prev(NULL), Next(NULL) {}
+
+ SDOperand(const SDOperandImpl& Op): SDOperandImpl(Op),parent(NULL),
+ Prev(NULL), Next(NULL) {
+ }
+
+ SDOperand& operator= (SDOperandImpl& Op) {
+ *(SDOperandImpl*)this = Op;
+ Next = NULL;
+ Prev = NULL;
+ return *this;
+ }
+
+ SDOperand& operator= (const SDOperandImpl& Op) {
+ *(SDOperandImpl*)this = Op;
+ Next = NULL;
+ Prev = NULL;
+ return *this;
+ }
+
+ SDOperand& operator= (SDOperand& Op) {
+ *(SDOperandImpl*)this = Op;
+ Next = NULL;
+ Prev = NULL;
+ return *this;
+ }
+
+ SDOperand& operator= (const SDOperand& Op) {
+ *(SDOperandImpl*)this = Op;
+ Next = NULL;
+ Prev = NULL;
+ return *this;
+ }
+
+ SDOperand * getNext() { return Next; }
+
+ SDNode *getUser() { return parent; }
+ void setUser(SDNode *p) { parent = p; }
+
+protected:
+ void addToList(SDOperand **List) {
+ Next = *List;
+ if (Next) Next->Prev = &Next;
+ Prev = List;
+ *List = this;
+ }
+
+ void removeFromList() {
+ *Prev = Next;
+ if (Next) Next->Prev = Prev;
+ }
+};
+
+