Index: include/llvm/CodeGen/SelectionDAGNodes.h =================================================================== --- include/llvm/CodeGen/SelectionDAGNodes.h +++ include/llvm/CodeGen/SelectionDAGNodes.h @@ -667,7 +667,7 @@ /// Return the opcode of this operation for printing. std::string getOperationName(const SelectionDAG *G = nullptr) const; static const char* getIndexedModeName(ISD::MemIndexedMode AM); - void print_types(raw_ostream &OS, const SelectionDAG *G) const; + void print_operation(raw_ostream &OS, const SelectionDAG *G) const; void print_details(raw_ostream &OS, const SelectionDAG *G) const; void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const; void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const; Index: lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -393,9 +393,7 @@ dbgs() << '\n'; } -void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const { - OS << PrintNodeId(*this) << " = "; - +void SDNode::print_operation(raw_ostream &OS, const SelectionDAG *G) const { OS << getOperationName(G) << ':'; for (unsigned i = 0, e = getNumValues(); i != e; ++i) { if (i) OS << ","; @@ -409,7 +407,7 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { if (const MachineSDNode *MN = dyn_cast(this)) { if (!MN->memoperands_empty()) { - OS << "<"; + OS << " <"; OS << "Mem:"; for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(), e = MN->memoperands_end(); i != e; ++i) { @@ -421,7 +419,7 @@ } } else if (const ShuffleVectorSDNode *SVN = dyn_cast(this)) { - OS << "<"; + OS << " <"; for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) { int Idx = SVN->getMaskElt(i); if (i) OS << ","; @@ -432,21 +430,21 @@ } OS << ">"; } else if (const ConstantSDNode *CSDN = dyn_cast(this)) { - OS << '<' << CSDN->getAPIntValue() << '>'; + OS << " <" << CSDN->getAPIntValue() << '>'; } else if (const ConstantFPSDNode *CSDN = dyn_cast(this)) { if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle) - OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; + OS << " <" << CSDN->getValueAPF().convertToFloat() << '>'; else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble) - OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; + OS << " <" << CSDN->getValueAPF().convertToDouble() << '>'; else { - OS << "getValueAPF().bitcastToAPInt().dump(); OS << ")>"; } } else if (const GlobalAddressSDNode *GADN = dyn_cast(this)) { int64_t offset = GADN->getOffset(); - OS << '<'; + OS << " <"; GADN->getGlobal()->printAsOperand(OS); OS << '>'; if (offset > 0) @@ -456,17 +454,17 @@ if (unsigned int TF = GADN->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const FrameIndexSDNode *FIDN = dyn_cast(this)) { - OS << "<" << FIDN->getIndex() << ">"; + OS << " <" << FIDN->getIndex() << ">"; } else if (const JumpTableSDNode *JTDN = dyn_cast(this)) { - OS << "<" << JTDN->getIndex() << ">"; + OS << " <" << JTDN->getIndex() << ">"; if (unsigned int TF = JTDN->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const ConstantPoolSDNode *CP = dyn_cast(this)){ int offset = CP->getOffset(); if (CP->isMachineConstantPoolEntry()) - OS << "<" << *CP->getMachineCPVal() << ">"; + OS << " <" << *CP->getMachineCPVal() << ">"; else - OS << "<" << *CP->getConstVal() << ">"; + OS << " <" << *CP->getConstVal() << ">"; if (offset > 0) OS << " + " << offset; else @@ -474,11 +472,11 @@ if (unsigned int TF = CP->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const TargetIndexSDNode *TI = dyn_cast(this)) { - OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">"; + OS << " <" << TI->getIndex() << '+' << TI->getOffset() << ">"; if (unsigned TF = TI->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const BasicBlockSDNode *BBDN = dyn_cast(this)) { - OS << "<"; + OS << " <"; const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); if (LBB) OS << LBB->getName() << " "; @@ -488,24 +486,24 @@ G ? G->getSubtarget().getRegisterInfo() : nullptr); } else if (const ExternalSymbolSDNode *ES = dyn_cast(this)) { - OS << "'" << ES->getSymbol() << "'"; + OS << " '" << ES->getSymbol() << "'"; if (unsigned int TF = ES->getTargetFlags()) OS << " [TF=" << TF << ']'; } else if (const SrcValueSDNode *M = dyn_cast(this)) { if (M->getValue()) - OS << "<" << M->getValue() << ">"; + OS << " <" << M->getValue() << ">"; else - OS << ""; + OS << " "; } else if (const MDNodeSDNode *MD = dyn_cast(this)) { if (MD->getMD()) - OS << "<" << MD->getMD() << ">"; + OS << " <" << MD->getMD() << ">"; else - OS << ""; + OS << " "; } else if (const VTSDNode *N = dyn_cast(this)) { OS << ":" << N->getVT().getEVTString(); } else if (const LoadSDNode *LD = dyn_cast(this)) { - OS << "<" << *LD->getMemOperand(); + OS << " <" << *LD->getMemOperand(); bool doExt = true; switch (LD->getExtensionType()) { @@ -523,7 +521,7 @@ OS << ">"; } else if (const StoreSDNode *ST = dyn_cast(this)) { - OS << "<" << *ST->getMemOperand(); + OS << " <" << *ST->getMemOperand(); if (ST->isTruncatingStore()) OS << ", trunc to " << ST->getMemoryVT().getEVTString(); @@ -534,11 +532,11 @@ OS << ">"; } else if (const MemSDNode* M = dyn_cast(this)) { - OS << "<" << *M->getMemOperand() << ">"; + OS << " <" << *M->getMemOperand() << ">"; } else if (const BlockAddressSDNode *BA = dyn_cast(this)) { int64_t offset = BA->getOffset(); - OS << "<"; + OS << " <"; BA->getBlockAddress()->getFunction()->printAsOperand(OS, false); OS << ", "; BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false); @@ -551,7 +549,7 @@ OS << " [TF=" << TF << ']'; } else if (const AddrSpaceCastSDNode *ASC = dyn_cast(this)) { - OS << '[' + OS << " [" << ASC->getSrcAddressSpace() << " -> " << ASC->getDestAddressSpace() @@ -582,13 +580,35 @@ } } +/// Return true if this node is so simple that we should just print it inline +/// if it appears as an operand. +static bool shouldPrintInline(const SDNode &Node) { + switch (Node.getOpcode()) { + case ISD::CONDCODE: + case ISD::Constant: + case ISD::ConstantFP: + case ISD::MDNODE_SDNODE: + case ISD::Register: + case ISD::RegisterMask: + case ISD::TargetConstant: + case ISD::TargetConstantFP: + case ISD::UNDEF: + case ISD::VALUETYPE: + return true; + } + return false; +} + static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) { - for (const SDValue &Op : N->op_values()) + for (const SDValue &Op : N->op_values()) { + if (shouldPrintInline(*Op.getNode())) + continue; if (Op.getNode()->hasOneUse()) DumpNodes(Op.getNode(), indent+2, G); else dbgs() << "\n" << std::string(indent+2, ' ') << PrintNodeId(*Op.getNode()) << ": "; + } dbgs() << '\n'; dbgs().indent(indent); @@ -601,7 +621,8 @@ for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); I != E; ++I) { const SDNode *N = I; - if (!N->hasOneUse() && N != getRoot().getNode()) + if (!N->hasOneUse() && N != getRoot().getNode() && + (!shouldPrintInline(*N) || N->use_empty())) DumpNodes(N, 2, this); } @@ -610,8 +631,8 @@ } void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const { - print_types(OS, G); - OS << ' '; + OS << PrintNodeId(*this) << " = "; + print_operation(OS, G); print_details(OS, G); } @@ -701,14 +722,24 @@ dumprWithDepth(G, 10); } +static void printOperand(raw_ostream &OS, const SelectionDAG *G, + const SDValue Value) { + if (shouldPrintInline(*Value.getNode())) { + Value->print_operation(OS, G); + Value->print_details(OS, G); + } else { + OS << PrintNodeId(*Value.getNode()); + if (unsigned RN = Value.getResNo()) + OS << ':' << RN; + } +} + void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const { - print_types(OS, G); + OS << PrintNodeId(*this) << " = "; + print_operation(OS, G); for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { if (i) OS << ", "; else OS << " "; - const SDValue Operand = getOperand(i); - OS << PrintNodeId(*Operand.getNode()); - if (unsigned RN = Operand.getResNo()) - OS << ":" << RN; + printOperand(OS, G, getOperand(i)); } print_details(OS, G); }