[llvm] r269236 - SDAG: Add a helper to replace and remove a node during ISel
H.J. Lu via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 15:47:18 PDT 2016
On Wed, May 11, 2016 at 2:13 PM, Justin Bogner via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: bogner
> Date: Wed May 11 16:13:17 2016
> New Revision: 269236
>
> URL: http://llvm.org/viewvc/llvm-project?rev=269236&view=rev
> Log:
> SDAG: Add a helper to replace and remove a node during ISel
>
> It's very common to want to replace a node and then remove it since
> it's dead, especially as we port backends from the SDNode *Select API
> to the void Select one. This helper makes this sequence a bit less
> verbose.
>
> Modified:
> llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h
> llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h?rev=269236&r1=269235&r2=269236&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/SelectionDAGISel.h Wed May 11 16:13:17 2016
> @@ -234,6 +234,11 @@ protected:
> CurDAG->ReplaceAllUsesWith(F, T);
> }
>
> + /// Replace all uses of \c F with \c T, then remove \c F from the DAG.
> + void ReplaceNode(SDNode *F, SDNode *T) {
> + CurDAG->ReplaceAllUsesWith(F, T);
> + CurDAG->RemoveDeadNode(F);
> + }
>
> /// SelectInlineAsmMemoryOperands - Calls to this are automatically generated
> /// by tblgen. Others should not call it.
>
Did you miss
case ISD::BRIND: {
if (Subtarget->isTargetNaCl())
// NaCl has its own pass where jmp %r32 are converted to jmp %r64. We
// leave the instruction alone.
break;
if (Subtarget->isTarget64BitILP32()) {
// Converts a 32-bit register to a 64-bit, zero-extended version of
// it. This is needed because x86-64 can do many things, but jmp %r32
// ain't one of them.
const SDValue &Target = Node->getOperand(1);
assert(Target.getSimpleValueType() == llvm::MVT::i32);
SDValue ZextTarget = CurDAG->getZExtOrTrunc(Target, dl, EVT(MVT::i64));
SDValue Brind = CurDAG->getNode(ISD::BRIND, dl, MVT::Other,
Node->getOperand(0), ZextTarget);
ReplaceUses(SDValue(Node, 0), Brind);
SelectCode(ZextTarget.getNode());
SelectCode(Brind.getNode());
return nullptr;
}
break;
}
It leaves dead and invalid nodes behind.
H.J.
More information about the llvm-commits
mailing list