From 25a022c7801b047b31d7610386e8a9ddca878cb1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 11 Jul 2006 01:40:09 +0000 Subject: [PATCH] Fix CodeGen/Alpha/2006-07-03-ASMFormalLowering.ll and PR818. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29099 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 43 +++++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index aeaba539b13..a798f554fcc 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -1163,25 +1163,42 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { AddLegalizedOperand(SDOperand(Node, 1), Tmp2); return Op.ResNo ? Tmp2 : Tmp1; } - case ISD::INLINEASM: - Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize Chain. - Tmp2 = Node->getOperand(Node->getNumOperands()-1); - if (Tmp2.getValueType() == MVT::Flag) // Legalize Flag if it exists. - Tmp2 = Tmp3 = SDOperand(0, 0); - else - Tmp3 = LegalizeOp(Tmp2); - - if (Tmp1 != Node->getOperand(0) || Tmp2 != Tmp3) { - std::vector Ops(Node->op_begin(), Node->op_end()); - Ops[0] = Tmp1; - if (Tmp3.Val) Ops.back() = Tmp3; - Result = DAG.UpdateNodeOperands(Result, Ops); + case ISD::INLINEASM: { + std::vector Ops(Node->op_begin(), Node->op_end()); + bool Changed = false; + // Legalize all of the operands of the inline asm, in case they are nodes + // that need to be expanded or something. Note we skip the asm string and + // all of the TargetConstant flags. + SDOperand Op = LegalizeOp(Ops[0]); + Changed = Op != Ops[0]; + Ops[0] = Op; + + bool HasInFlag = Ops.back().getValueType() == MVT::Flag; + for (unsigned i = 2, e = Ops.size()-HasInFlag; i < e; ) { + unsigned NumVals = cast(Ops[i])->getValue() >> 3; + for (++i; NumVals; ++i, --NumVals) { + SDOperand Op = LegalizeOp(Ops[i]); + if (Op != Ops[i]) { + Changed = true; + Ops[i] = Op; + } + } } + + if (HasInFlag) { + Op = LegalizeOp(Ops.back()); + Changed |= Op != Ops.back(); + Ops.back() = Op; + } + + if (Changed) + Result = DAG.UpdateNodeOperands(Result, Ops); // INLINE asm returns a chain and flag, make sure to add both to the map. AddLegalizedOperand(SDOperand(Node, 0), Result.getValue(0)); AddLegalizedOperand(SDOperand(Node, 1), Result.getValue(1)); return Result.getValue(Op.ResNo); + } case ISD::BR: Tmp1 = LegalizeOp(Node->getOperand(0)); // Legalize the chain. // Ensure that libcalls are emitted before a branch.