/// 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];
// 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.
CurDAG->RemoveDeadNode(Node, &ISQU);
UpdateQueue(ISQU);
}
+ //DAG.setSubgraphColor(Node, "black");
}
delete[] ISelQueued;
#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 <algorithm>
#include <deque>
using namespace llvm;
+namespace {
+ cl::opt<bool>
+ GenDebug("gen-debug", cl::desc("Generate debug code"),
+ cl::init(false));
+}
+
//===----------------------------------------------------------------------===//
// DAGISelEmitter Helper methods
//
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
if (II.isSimpleLoad | II.mayLoad | II.mayStore) {
std::vector<std::string>::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<MemSDNode>(" +
*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);
}
}
}
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]);
// 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.