[LLVMdev] Difficulty with reusing DAG nodes.

Richard Pennington rich at pennware.com
Thu Sep 11 18:09:58 PDT 2008


I'm trying to implement *MUL_LOHI for my processor.

My processor has mulxss (e.g.) that gives the 32 high bits of a 64 bit 
multiply.

I tried this in ios2ISelDAGToDAG.cpp:
    /// Mul/Div with two results
     case ISD::SMUL_LOHI:
     case ISD::UMUL_LOHI: {
       SDValue Op1 = Node->getOperand(0);
       SDValue Op2 = Node->getOperand(1);
       AddToISelQueue(Op1);
       AddToISelQueue(Op2);

       unsigned Op;
       Op = (Opcode == ISD::UMUL_LOHI ? Nios2::MULxu : Nios2::MULx);
       SDNode *Hi = CurDAG->getTargetNode(Op, MVT::Flag, Op1, Op2);
       SDNode *Lo = CurDAG->getTargetNode(Nios2::MUL, MVT::Flag, Op1, Op2);
       if (!N.getValue(0).use_empty())
         ReplaceUses(N.getValue(0), SDValue(Lo,0));
       if (!N.getValue(1).use_empty())
         ReplaceUses(N.getValue(1), SDValue(Hi,0));
       return NULL;
     }

The code generator complains:
nios2-elf-ecc: 
/home/rich/llvm-trunk-new/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp:141: 
void llvm::ScheduleDAG::BuildSchedUnits(): Assertion `N->getNodeId() == 
-1 && "Node already inserted!"' failed

I'm guessing that's because I'm reusing Op1 and Op2.
What is the right way to reuse DAG operands?

-Rich



More information about the llvm-dev mailing list