From: Vikram S. Adve Date: Thu, 11 Oct 2001 04:22:45 +0000 (+0000) Subject: Add graph edges due to implicit refs in each machine instruction. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8d0ffa553fda8d3fe8bfbeb7a10f98c46f8afb4c;p=oota-llvm.git Add graph edges due to implicit refs in each machine instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@724 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp index 97a3b7ab4cc..c9d01934b04 100644 --- a/lib/CodeGen/InstrSched/SchedGraph.cpp +++ b/lib/CodeGen/InstrSched/SchedGraph.cpp @@ -528,6 +528,20 @@ SchedGraph::addMachineRegEdges(RegToRefVecMap& regToRefVecMap, } +inline void +CreateSSAEdge(SchedGraph* graph, + MachineInstr* defInstr, + SchedGraphNode* node, + const Value* val) +{ + // this instruction does define value `val'. + // if there is a node for it in the same graph, add an edge. + SchedGraphNode* defNode = graph->getGraphNodeForInstr(defInstr); + if (defNode != NULL && defNode != node) + (void) new SchedGraphEdge(defNode, node, val); +} + + void SchedGraph::addSSAEdge(SchedGraphNode* node, const Value* val, @@ -552,22 +566,37 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, const MachineInstrInfo& mii = target.getInstrInfo(); for (unsigned i=0, N=defMvec.size(); i < N; i++) - for (int o=0, N = mii.getNumOperands(defMvec[i]->getOpCode()); o < N; o++) - { - const MachineOperand& defOp = defMvec[i]->getOperand(o); - - if (defOp.opIsDef() - && (defOp.getOperandType() == MachineOperand::MO_VirtualRegister - || defOp.getOperandType() == MachineOperand::MO_CCRegister) - && (defOp.getVRegValue() == val)) - { - // this instruction does define value `val'. - // if there is a node for it in the same graph, add an edge. - SchedGraphNode* defNode = this->getGraphNodeForInstr(defMvec[i]); - if (defNode != NULL && defNode != node) - (void) new SchedGraphEdge(defNode, node, val); - } - } + { + bool edgeAddedForInstr = false; + + // First check the explicit operands + for (int o=0, N=mii.getNumOperands(defMvec[i]->getOpCode()); o < N; o++) + { + const MachineOperand& defOp = defMvec[i]->getOperand(o); + + if (defOp.opIsDef() + && (defOp.getOperandType() == MachineOperand::MO_VirtualRegister + || defOp.getOperandType() == MachineOperand::MO_CCRegister) + && (defOp.getVRegValue() == val)) + { + CreateSSAEdge(this, defMvec[i], node, val); + edgeAddedForInstr = true; + break; + } + } + + // Then check the implicit operands + if (! edgeAddedForInstr) + { + for (unsigned o=0, N=defMvec[i]->getNumImplicitRefs(); o < N; ++o) + if (defMvec[i]->implicitRefIsDefined(o)) + { + CreateSSAEdge(this, defMvec[i], node, val); + edgeAddedForInstr = true; + break; + } + } + } } @@ -624,18 +653,14 @@ SchedGraph::addEdgesForInstruction(const MachineInstr& minstr, break; } } - - // Add edges for values implicitly used by the machine instruction sequence - // for the VM instruction but not made explicit operands. Examples include - // function arguments to a Call instructions or the return value of a Ret - // instruction. We'll conservatively add the dependences to every machine - // machine instruction in the instruction sequence for this VM instr - // (at least for now, there is never more than one machine instr). + + // Add edges for values implicitly used by the machine instruction. + // Examples include function arguments to a Call instructions or the return + // value of a Ret instruction. // - const vector& implicitUses = - instr.getMachineInstrVec().getImplicitUses(); - for (unsigned i=0; i < implicitUses.size(); ++i) - addSSAEdge(node, implicitUses[i], target); + for (unsigned i=0, N=minstr.getNumImplicitRefs(); i < N; ++i) + if (! minstr.implicitRefIsDefined(i)) + addSSAEdge(node, minstr.getImplicitRef(i), target); } diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp index 97a3b7ab4cc..c9d01934b04 100644 --- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp @@ -528,6 +528,20 @@ SchedGraph::addMachineRegEdges(RegToRefVecMap& regToRefVecMap, } +inline void +CreateSSAEdge(SchedGraph* graph, + MachineInstr* defInstr, + SchedGraphNode* node, + const Value* val) +{ + // this instruction does define value `val'. + // if there is a node for it in the same graph, add an edge. + SchedGraphNode* defNode = graph->getGraphNodeForInstr(defInstr); + if (defNode != NULL && defNode != node) + (void) new SchedGraphEdge(defNode, node, val); +} + + void SchedGraph::addSSAEdge(SchedGraphNode* node, const Value* val, @@ -552,22 +566,37 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, const MachineInstrInfo& mii = target.getInstrInfo(); for (unsigned i=0, N=defMvec.size(); i < N; i++) - for (int o=0, N = mii.getNumOperands(defMvec[i]->getOpCode()); o < N; o++) - { - const MachineOperand& defOp = defMvec[i]->getOperand(o); - - if (defOp.opIsDef() - && (defOp.getOperandType() == MachineOperand::MO_VirtualRegister - || defOp.getOperandType() == MachineOperand::MO_CCRegister) - && (defOp.getVRegValue() == val)) - { - // this instruction does define value `val'. - // if there is a node for it in the same graph, add an edge. - SchedGraphNode* defNode = this->getGraphNodeForInstr(defMvec[i]); - if (defNode != NULL && defNode != node) - (void) new SchedGraphEdge(defNode, node, val); - } - } + { + bool edgeAddedForInstr = false; + + // First check the explicit operands + for (int o=0, N=mii.getNumOperands(defMvec[i]->getOpCode()); o < N; o++) + { + const MachineOperand& defOp = defMvec[i]->getOperand(o); + + if (defOp.opIsDef() + && (defOp.getOperandType() == MachineOperand::MO_VirtualRegister + || defOp.getOperandType() == MachineOperand::MO_CCRegister) + && (defOp.getVRegValue() == val)) + { + CreateSSAEdge(this, defMvec[i], node, val); + edgeAddedForInstr = true; + break; + } + } + + // Then check the implicit operands + if (! edgeAddedForInstr) + { + for (unsigned o=0, N=defMvec[i]->getNumImplicitRefs(); o < N; ++o) + if (defMvec[i]->implicitRefIsDefined(o)) + { + CreateSSAEdge(this, defMvec[i], node, val); + edgeAddedForInstr = true; + break; + } + } + } } @@ -624,18 +653,14 @@ SchedGraph::addEdgesForInstruction(const MachineInstr& minstr, break; } } - - // Add edges for values implicitly used by the machine instruction sequence - // for the VM instruction but not made explicit operands. Examples include - // function arguments to a Call instructions or the return value of a Ret - // instruction. We'll conservatively add the dependences to every machine - // machine instruction in the instruction sequence for this VM instr - // (at least for now, there is never more than one machine instr). + + // Add edges for values implicitly used by the machine instruction. + // Examples include function arguments to a Call instructions or the return + // value of a Ret instruction. // - const vector& implicitUses = - instr.getMachineInstrVec().getImplicitUses(); - for (unsigned i=0; i < implicitUses.size(); ++i) - addSSAEdge(node, implicitUses[i], target); + for (unsigned i=0, N=minstr.getNumImplicitRefs(); i < N; ++i) + if (! minstr.implicitRefIsDefined(i)) + addSSAEdge(node, minstr.getImplicitRef(i), target); }