[llvm-commits] [llvm] r49795 - in /llvm/trunk: include/llvm/CodeGen/ScheduleDAG.h include/llvm/CodeGen/SelectionDAG.h include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/LegalizeDAG.cpp lib/C

Bill Wendling isanbard at gmail.com
Wed Apr 16 13:16:36 PDT 2008


Hi Roman,

>  +/// SDOperandPtr - A helper SDOperand poiner class, that can handle

poiner -> pointer

>  +/// arrays of SDUse and arrays of SDOperand objects. This is required
>  +/// in many places inside the SelectionDAG.
>  +///
>  +class SDOperandPtr {
>  +  const SDOperand *ptr; // The pointer to the SDOperand object
>  +  int object_size;      // The size of the object containg the SDOperand
>  +public:
>  +  SDOperandPtr(SDUse * use_ptr) {
>  +    ptr = &use_ptr->getSDOperand();
>  +    object_size = sizeof(SDUse);
>  +  }
>  +
>  +  SDOperandPtr(const SDOperand * op_ptr) {
>  +    ptr = op_ptr;
>  +    object_size = sizeof(SDOperand);
>  +  }
>  +
>  +  operator const SDOperand *() const {
>  +    assert(object_size == sizeof(SDOperand) &&
>  +           "Only SDOperand can be converted");
>  +    return ptr;
>  +  }
>  +
>  +  const SDOperand operator *() { return *ptr; }
>  +  const SDOperand *operator ->() { return ptr; }
>  +  SDOperandPtr operator ++ () {
>  +    ptr = (SDOperand*)((char *)ptr + object_size);
>  +    return *this;
>  +  }
>  +
>  +  SDOperandPtr operator ++ (int) {
>  +    SDOperandPtr tmp = *this;
>  +    ptr = (SDOperand*)((char *)ptr + object_size);
>  +    return tmp;
>  +  }
>  +
>  +  SDOperand operator[] (int idx) const {
>  +    return *(SDOperand*)((char*) ptr + object_size * idx);
>  +  }
>  +};
>  +

I must say that I'm not a fan of this class. I don't like the fact
that you're doing pointer arithmetic. Is there another way to
implement this? Perhaps with some template magic?

-bw



More information about the llvm-commits mailing list