From: David Greene Date: Mon, 27 Oct 2008 21:56:29 +0000 (+0000) Subject: Have TableGen emit setSubgraphColor calls under control of a -gen-debug X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8ad4c00c00233acb8a3395098e2b575cc34de46b;p=oota-llvm.git Have TableGen emit setSubgraphColor calls under control of a -gen-debug flag. Then in a debugger developers can set breakpoints at these calls to see waht is about to be selected and what the resulting subgraph looks like. This really helps when debugging instruction selection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58278 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/DAGISelHeader.h b/include/llvm/CodeGen/DAGISelHeader.h index 3542ebcbd02..e50ee7c00ad 100644 --- a/include/llvm/CodeGen/DAGISelHeader.h +++ b/include/llvm/CodeGen/DAGISelHeader.h @@ -153,7 +153,7 @@ void ReplaceUses(SDNode *F, SDNode *T) DISABLE_INLINE { /// SelectRoot - Top level entry to DAG instruction selector. /// Selects instructions starting at the root of the current DAG. -void SelectRoot() { +void SelectRoot(SelectionDAG &DAG) { SelectRootInit(); unsigned NumBytes = (DAGSize + 7) / 8; ISelQueued = new unsigned char[NumBytes]; @@ -176,14 +176,18 @@ void SelectRoot() { // Skip already selected nodes. if (isSelected(Node->getNodeId())) continue; + DAG.setSubgraphColor(Node, "red"); SDNode *ResNode = Select(SDValue(Node, 0)); // If node should not be replaced, // continue with the next one. if (ResNode == Node) continue; // Replace node. - if (ResNode) + if (ResNode) { + DAG.setSubgraphColor(ResNode, "yellow"); + DAG.setSubgraphColor(ResNode, "black"); ReplaceUses(Node, ResNode); + } // If after the replacement this node is not used any more, // remove this dead node. if (Node->use_empty()) { // Don't delete EntryToken, etc. @@ -191,6 +195,7 @@ void SelectRoot() { CurDAG->RemoveDeadNode(Node, &ISQU); UpdateQueue(ISQU); } + //DAG.setSubgraphColor(Node, "black"); } delete[] ISelQueued; diff --git a/lib/Target/ARM/ARMISelDAGToDAG.cpp b/lib/Target/ARM/ARMISelDAGToDAG.cpp index 560be0ad96e..060f61ca70c 100644 --- a/lib/Target/ARM/ARMISelDAGToDAG.cpp +++ b/lib/Target/ARM/ARMISelDAGToDAG.cpp @@ -94,7 +94,7 @@ public: void ARMDAGToDAGISel::InstructionSelect() { DEBUG(BB->dump()); - SelectRoot(); + SelectRoot(*CurDAG); CurDAG->RemoveDeadNodes(); } diff --git a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp index e4bd152885b..e0ae5564ed8 100644 --- a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp +++ b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp @@ -230,7 +230,7 @@ void AlphaDAGToDAGISel::InstructionSelect() { DEBUG(BB->dump()); // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); CurDAG->RemoveDeadNodes(); } diff --git a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp index 92c76af1d06..d6a492b575c 100644 --- a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp +++ b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp @@ -344,7 +344,7 @@ SPUDAGToDAGISel::InstructionSelect() DEBUG(BB->dump()); // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); CurDAG->RemoveDeadNodes(); } diff --git a/lib/Target/IA64/IA64ISelDAGToDAG.cpp b/lib/Target/IA64/IA64ISelDAGToDAG.cpp index 6d3199307e5..ae59ea2489d 100644 --- a/lib/Target/IA64/IA64ISelDAGToDAG.cpp +++ b/lib/Target/IA64/IA64ISelDAGToDAG.cpp @@ -97,7 +97,7 @@ void IA64DAGToDAGISel::InstructionSelect() { DEBUG(BB->dump()); // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); CurDAG->RemoveDeadNodes(); } diff --git a/lib/Target/Mips/MipsISelDAGToDAG.cpp b/lib/Target/Mips/MipsISelDAGToDAG.cpp index 2e3756a8715..b31bcbdc0b3 100644 --- a/lib/Target/Mips/MipsISelDAGToDAG.cpp +++ b/lib/Target/Mips/MipsISelDAGToDAG.cpp @@ -105,7 +105,7 @@ InstructionSelect() #endif // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); #ifndef NDEBUG DOUT << "===== Instruction selection ends:\n"; diff --git a/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp b/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp index 4d06089e9c1..d98be99f86c 100644 --- a/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp +++ b/lib/Target/PIC16/PIC16ISelDAGToDAG.cpp @@ -102,7 +102,7 @@ void PIC16DAGToDAGISel::InstructionSelect() #endif // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); DOUT << "===== Instruction selection ends:\n"; diff --git a/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/lib/Target/PowerPC/PPCISelDAGToDAG.cpp index e2ffb31fcc9..37ca2be85d6 100644 --- a/lib/Target/PowerPC/PPCISelDAGToDAG.cpp +++ b/lib/Target/PowerPC/PPCISelDAGToDAG.cpp @@ -204,7 +204,7 @@ void PPCDAGToDAGISel::InstructionSelect() { DEBUG(BB->dump()); // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); CurDAG->RemoveDeadNodes(); } diff --git a/lib/Target/Sparc/SparcISelDAGToDAG.cpp b/lib/Target/Sparc/SparcISelDAGToDAG.cpp index 66e143de3fe..ceba75d7889 100644 --- a/lib/Target/Sparc/SparcISelDAGToDAG.cpp +++ b/lib/Target/Sparc/SparcISelDAGToDAG.cpp @@ -70,7 +70,7 @@ void SparcDAGToDAGISel::InstructionSelect() { DEBUG(BB->dump()); // Select target instructions for the DAG. - SelectRoot(); + SelectRoot(*CurDAG); CurDAG->RemoveDeadNodes(); } diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 6735f1d80b7..c3419809786 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -655,7 +655,7 @@ void X86DAGToDAGISel::InstructionSelect() { DOUT << "===== Instruction selection begins:\n"; Indent = 0; #endif - SelectRoot(); + SelectRoot(*CurDAG); #ifndef NDEBUG DOUT << "===== Instruction selection ends:\n"; #endif diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 299612977a1..82d414884b5 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -14,13 +14,21 @@ #include "DAGISelEmitter.h" #include "Record.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/Streams.h" #include #include using namespace llvm; +namespace { + cl::opt + GenDebug("gen-debug", cl::desc("Generate debug code"), + cl::init(false)); +} + //===----------------------------------------------------------------------===// // DAGISelEmitter Helper methods // @@ -969,6 +977,10 @@ public: emitCode("InChains.push_back(" + ChainName + ");"); emitCode(ChainName + " = CurDAG->getNode(ISD::TokenFactor, MVT::Other, " "&InChains[0], InChains.size());"); + if (GenDebug) { + emitCode("CurDAG->setSubgraphColor(" + ChainName +".getNode(), \"yellow\");"); + emitCode("CurDAG->setSubgraphColor(" + ChainName +".getNode(), \"black\");"); + } } // Loop over all of the operands of the instruction pattern, emitting code @@ -1096,13 +1108,18 @@ public: if (II.isSimpleLoad | II.mayLoad | II.mayStore) { std::vector::const_iterator mi, mie; for (mi = LSI.begin(), mie = LSI.end(); mi != mie; ++mi) { - emitCode("SDValue LSI_" + *mi + " = " + std::string LSIName = "LSI_" + *mi; + emitCode("SDValue " + LSIName + " = " "CurDAG->getMemOperand(cast(" + *mi + ")->getMemOperand());"); + if (GenDebug) { + emitCode("CurDAG->setSubgraphColor(" + LSIName +".getNode(), \"yellow\");"); + emitCode("CurDAG->setSubgraphColor(" + LSIName +".getNode(), \"black\");"); + } if (IsVariadic) - emitCode("Ops" + utostr(OpsNo) + ".push_back(LSI_" + *mi + ");"); + emitCode("Ops" + utostr(OpsNo) + ".push_back(" + LSIName + ");"); else - AllOps.push_back("LSI_" + *mi); + AllOps.push_back(LSIName); } } @@ -1269,6 +1286,18 @@ public: } emitCode(CodePrefix + Code + ");"); + + if (GenDebug) { + if (!isRoot) { + emitCode("CurDAG->setSubgraphColor(" + NodeName +".getNode(), \"yellow\");"); + emitCode("CurDAG->setSubgraphColor(" + NodeName +".getNode(), \"black\");"); + } + else { + emitCode("CurDAG->setSubgraphColor(" + NodeName +", \"yellow\");"); + emitCode("CurDAG->setSubgraphColor(" + NodeName +", \"black\");"); + } + } + for (unsigned i = 0, e = After.size(); i != e; ++i) emitCode(After[i]); @@ -1766,8 +1795,19 @@ void DAGISelEmitter::EmitInstructionSelector(std::ostream &OS) { // Replace the emission code within selection routines with calls to the // emission functions. - CallerCode = "return Emit_" + utostr(EmitFuncNum) + CallerCode; - GeneratedCode.push_back(std::make_pair(false, CallerCode)); + if (GenDebug) { + GeneratedCode.push_back(std::make_pair(0, "CurDAG->setSubgraphColor(N.getNode(), \"red\");")); + } + CallerCode = "SDNode *Result = Emit_" + utostr(EmitFuncNum) + CallerCode; + GeneratedCode.push_back(std::make_pair(3, CallerCode)); + if (GenDebug) { + GeneratedCode.push_back(std::make_pair(0, "if(Result) {")); + GeneratedCode.push_back(std::make_pair(0, " CurDAG->setSubgraphColor(Result, \"yellow\");")); + GeneratedCode.push_back(std::make_pair(0, " CurDAG->setSubgraphColor(Result, \"black\");")); + GeneratedCode.push_back(std::make_pair(0, "}")); + //GeneratedCode.push_back(std::make_pair(0, "CurDAG->setSubgraphColor(N.getNode(), \"black\");")); + } + GeneratedCode.push_back(std::make_pair(0, "return Result;")); } // Print function.