LLVM API Documentation

SelectionDAGDumper.cpp
Go to the documentation of this file.
00001 //===-- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() -----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This implements the SelectionDAG::dump method and friends.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/CodeGen/SelectionDAG.h"
00015 #include "ScheduleDAGSDNodes.h"
00016 #include "llvm/ADT/StringExtras.h"
00017 #include "llvm/CodeGen/MachineConstantPool.h"
00018 #include "llvm/CodeGen/MachineFunction.h"
00019 #include "llvm/CodeGen/MachineModuleInfo.h"
00020 #include "llvm/IR/DebugInfo.h"
00021 #include "llvm/IR/Function.h"
00022 #include "llvm/IR/Intrinsics.h"
00023 #include "llvm/Support/Debug.h"
00024 #include "llvm/Support/GraphWriter.h"
00025 #include "llvm/Support/raw_ostream.h"
00026 #include "llvm/Target/TargetInstrInfo.h"
00027 #include "llvm/Target/TargetIntrinsicInfo.h"
00028 #include "llvm/Target/TargetMachine.h"
00029 #include "llvm/Target/TargetRegisterInfo.h"
00030 #include "llvm/Target/TargetSubtargetInfo.h"
00031 using namespace llvm;
00032 
00033 std::string SDNode::getOperationName(const SelectionDAG *G) const {
00034   switch (getOpcode()) {
00035   default:
00036     if (getOpcode() < ISD::BUILTIN_OP_END)
00037       return "<<Unknown DAG Node>>";
00038     if (isMachineOpcode()) {
00039       if (G)
00040         if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
00041           if (getMachineOpcode() < TII->getNumOpcodes())
00042             return TII->getName(getMachineOpcode());
00043       return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
00044     }
00045     if (G) {
00046       const TargetLowering &TLI = G->getTargetLoweringInfo();
00047       const char *Name = TLI.getTargetNodeName(getOpcode());
00048       if (Name) return Name;
00049       return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
00050     }
00051     return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
00052 
00053 #ifndef NDEBUG
00054   case ISD::DELETED_NODE:               return "<<Deleted Node!>>";
00055 #endif
00056   case ISD::PREFETCH:                   return "Prefetch";
00057   case ISD::ATOMIC_FENCE:               return "AtomicFence";
00058   case ISD::ATOMIC_CMP_SWAP:            return "AtomicCmpSwap";
00059   case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
00060   case ISD::ATOMIC_SWAP:                return "AtomicSwap";
00061   case ISD::ATOMIC_LOAD_ADD:            return "AtomicLoadAdd";
00062   case ISD::ATOMIC_LOAD_SUB:            return "AtomicLoadSub";
00063   case ISD::ATOMIC_LOAD_AND:            return "AtomicLoadAnd";
00064   case ISD::ATOMIC_LOAD_OR:             return "AtomicLoadOr";
00065   case ISD::ATOMIC_LOAD_XOR:            return "AtomicLoadXor";
00066   case ISD::ATOMIC_LOAD_NAND:           return "AtomicLoadNand";
00067   case ISD::ATOMIC_LOAD_MIN:            return "AtomicLoadMin";
00068   case ISD::ATOMIC_LOAD_MAX:            return "AtomicLoadMax";
00069   case ISD::ATOMIC_LOAD_UMIN:           return "AtomicLoadUMin";
00070   case ISD::ATOMIC_LOAD_UMAX:           return "AtomicLoadUMax";
00071   case ISD::ATOMIC_LOAD:                return "AtomicLoad";
00072   case ISD::ATOMIC_STORE:               return "AtomicStore";
00073   case ISD::PCMARKER:                   return "PCMarker";
00074   case ISD::READCYCLECOUNTER:           return "ReadCycleCounter";
00075   case ISD::SRCVALUE:                   return "SrcValue";
00076   case ISD::MDNODE_SDNODE:              return "MDNode";
00077   case ISD::EntryToken:                 return "EntryToken";
00078   case ISD::TokenFactor:                return "TokenFactor";
00079   case ISD::AssertSext:                 return "AssertSext";
00080   case ISD::AssertZext:                 return "AssertZext";
00081 
00082   case ISD::BasicBlock:                 return "BasicBlock";
00083   case ISD::VALUETYPE:                  return "ValueType";
00084   case ISD::Register:                   return "Register";
00085   case ISD::RegisterMask:               return "RegisterMask";
00086   case ISD::Constant:
00087     if (cast<ConstantSDNode>(this)->isOpaque())
00088       return "OpaqueConstant";
00089     return "Constant";
00090   case ISD::ConstantFP:                 return "ConstantFP";
00091   case ISD::GlobalAddress:              return "GlobalAddress";
00092   case ISD::GlobalTLSAddress:           return "GlobalTLSAddress";
00093   case ISD::FrameIndex:                 return "FrameIndex";
00094   case ISD::JumpTable:                  return "JumpTable";
00095   case ISD::GLOBAL_OFFSET_TABLE:        return "GLOBAL_OFFSET_TABLE";
00096   case ISD::RETURNADDR:                 return "RETURNADDR";
00097   case ISD::FRAMEADDR:                  return "FRAMEADDR";
00098   case ISD::READ_REGISTER:              return "READ_REGISTER";
00099   case ISD::WRITE_REGISTER:             return "WRITE_REGISTER";
00100   case ISD::FRAME_TO_ARGS_OFFSET:       return "FRAME_TO_ARGS_OFFSET";
00101   case ISD::EH_RETURN:                  return "EH_RETURN";
00102   case ISD::EH_SJLJ_SETJMP:             return "EH_SJLJ_SETJMP";
00103   case ISD::EH_SJLJ_LONGJMP:            return "EH_SJLJ_LONGJMP";
00104   case ISD::ConstantPool:               return "ConstantPool";
00105   case ISD::TargetIndex:                return "TargetIndex";
00106   case ISD::ExternalSymbol:             return "ExternalSymbol";
00107   case ISD::BlockAddress:               return "BlockAddress";
00108   case ISD::INTRINSIC_WO_CHAIN:
00109   case ISD::INTRINSIC_VOID:
00110   case ISD::INTRINSIC_W_CHAIN: {
00111     unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
00112     unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
00113     if (IID < Intrinsic::num_intrinsics)
00114       return Intrinsic::getName((Intrinsic::ID)IID);
00115     else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
00116       return TII->getName(IID);
00117     llvm_unreachable("Invalid intrinsic ID");
00118   }
00119 
00120   case ISD::BUILD_VECTOR:               return "BUILD_VECTOR";
00121   case ISD::TargetConstant:
00122     if (cast<ConstantSDNode>(this)->isOpaque())
00123       return "OpaqueTargetConstant";
00124     return "TargetConstant";
00125   case ISD::TargetConstantFP:           return "TargetConstantFP";
00126   case ISD::TargetGlobalAddress:        return "TargetGlobalAddress";
00127   case ISD::TargetGlobalTLSAddress:     return "TargetGlobalTLSAddress";
00128   case ISD::TargetFrameIndex:           return "TargetFrameIndex";
00129   case ISD::TargetJumpTable:            return "TargetJumpTable";
00130   case ISD::TargetConstantPool:         return "TargetConstantPool";
00131   case ISD::TargetExternalSymbol:       return "TargetExternalSymbol";
00132   case ISD::TargetBlockAddress:         return "TargetBlockAddress";
00133 
00134   case ISD::CopyToReg:                  return "CopyToReg";
00135   case ISD::CopyFromReg:                return "CopyFromReg";
00136   case ISD::UNDEF:                      return "undef";
00137   case ISD::MERGE_VALUES:               return "merge_values";
00138   case ISD::INLINEASM:                  return "inlineasm";
00139   case ISD::EH_LABEL:                   return "eh_label";
00140   case ISD::HANDLENODE:                 return "handlenode";
00141 
00142   // Unary operators
00143   case ISD::FABS:                       return "fabs";
00144   case ISD::FNEG:                       return "fneg";
00145   case ISD::FSQRT:                      return "fsqrt";
00146   case ISD::FSIN:                       return "fsin";
00147   case ISD::FCOS:                       return "fcos";
00148   case ISD::FSINCOS:                    return "fsincos";
00149   case ISD::FTRUNC:                     return "ftrunc";
00150   case ISD::FFLOOR:                     return "ffloor";
00151   case ISD::FCEIL:                      return "fceil";
00152   case ISD::FRINT:                      return "frint";
00153   case ISD::FNEARBYINT:                 return "fnearbyint";
00154   case ISD::FROUND:                     return "fround";
00155   case ISD::FEXP:                       return "fexp";
00156   case ISD::FEXP2:                      return "fexp2";
00157   case ISD::FLOG:                       return "flog";
00158   case ISD::FLOG2:                      return "flog2";
00159   case ISD::FLOG10:                     return "flog10";
00160 
00161   // Binary operators
00162   case ISD::ADD:                        return "add";
00163   case ISD::SUB:                        return "sub";
00164   case ISD::MUL:                        return "mul";
00165   case ISD::MULHU:                      return "mulhu";
00166   case ISD::MULHS:                      return "mulhs";
00167   case ISD::SDIV:                       return "sdiv";
00168   case ISD::UDIV:                       return "udiv";
00169   case ISD::SREM:                       return "srem";
00170   case ISD::UREM:                       return "urem";
00171   case ISD::SMUL_LOHI:                  return "smul_lohi";
00172   case ISD::UMUL_LOHI:                  return "umul_lohi";
00173   case ISD::SDIVREM:                    return "sdivrem";
00174   case ISD::UDIVREM:                    return "udivrem";
00175   case ISD::AND:                        return "and";
00176   case ISD::OR:                         return "or";
00177   case ISD::XOR:                        return "xor";
00178   case ISD::SHL:                        return "shl";
00179   case ISD::SRA:                        return "sra";
00180   case ISD::SRL:                        return "srl";
00181   case ISD::ROTL:                       return "rotl";
00182   case ISD::ROTR:                       return "rotr";
00183   case ISD::FADD:                       return "fadd";
00184   case ISD::FSUB:                       return "fsub";
00185   case ISD::FMUL:                       return "fmul";
00186   case ISD::FDIV:                       return "fdiv";
00187   case ISD::FMA:                        return "fma";
00188   case ISD::FREM:                       return "frem";
00189   case ISD::FCOPYSIGN:                  return "fcopysign";
00190   case ISD::FGETSIGN:                   return "fgetsign";
00191   case ISD::FPOW:                       return "fpow";
00192 
00193   case ISD::FPOWI:                      return "fpowi";
00194   case ISD::SETCC:                      return "setcc";
00195   case ISD::SELECT:                     return "select";
00196   case ISD::VSELECT:                    return "vselect";
00197   case ISD::SELECT_CC:                  return "select_cc";
00198   case ISD::INSERT_VECTOR_ELT:          return "insert_vector_elt";
00199   case ISD::EXTRACT_VECTOR_ELT:         return "extract_vector_elt";
00200   case ISD::CONCAT_VECTORS:             return "concat_vectors";
00201   case ISD::INSERT_SUBVECTOR:           return "insert_subvector";
00202   case ISD::EXTRACT_SUBVECTOR:          return "extract_subvector";
00203   case ISD::SCALAR_TO_VECTOR:           return "scalar_to_vector";
00204   case ISD::VECTOR_SHUFFLE:             return "vector_shuffle";
00205   case ISD::CARRY_FALSE:                return "carry_false";
00206   case ISD::ADDC:                       return "addc";
00207   case ISD::ADDE:                       return "adde";
00208   case ISD::SADDO:                      return "saddo";
00209   case ISD::UADDO:                      return "uaddo";
00210   case ISD::SSUBO:                      return "ssubo";
00211   case ISD::USUBO:                      return "usubo";
00212   case ISD::SMULO:                      return "smulo";
00213   case ISD::UMULO:                      return "umulo";
00214   case ISD::SUBC:                       return "subc";
00215   case ISD::SUBE:                       return "sube";
00216   case ISD::SHL_PARTS:                  return "shl_parts";
00217   case ISD::SRA_PARTS:                  return "sra_parts";
00218   case ISD::SRL_PARTS:                  return "srl_parts";
00219 
00220   // Conversion operators.
00221   case ISD::SIGN_EXTEND:                return "sign_extend";
00222   case ISD::ZERO_EXTEND:                return "zero_extend";
00223   case ISD::ANY_EXTEND:                 return "any_extend";
00224   case ISD::SIGN_EXTEND_INREG:          return "sign_extend_inreg";
00225   case ISD::ANY_EXTEND_VECTOR_INREG:    return "any_extend_vector_inreg";
00226   case ISD::SIGN_EXTEND_VECTOR_INREG:   return "sign_extend_vector_inreg";
00227   case ISD::ZERO_EXTEND_VECTOR_INREG:   return "zero_extend_vector_inreg";
00228   case ISD::TRUNCATE:                   return "truncate";
00229   case ISD::FP_ROUND:                   return "fp_round";
00230   case ISD::FLT_ROUNDS_:                return "flt_rounds";
00231   case ISD::FP_ROUND_INREG:             return "fp_round_inreg";
00232   case ISD::FP_EXTEND:                  return "fp_extend";
00233 
00234   case ISD::SINT_TO_FP:                 return "sint_to_fp";
00235   case ISD::UINT_TO_FP:                 return "uint_to_fp";
00236   case ISD::FP_TO_SINT:                 return "fp_to_sint";
00237   case ISD::FP_TO_UINT:                 return "fp_to_uint";
00238   case ISD::BITCAST:                    return "bitcast";
00239   case ISD::ADDRSPACECAST:              return "addrspacecast";
00240   case ISD::FP16_TO_FP:                 return "fp16_to_fp";
00241   case ISD::FP_TO_FP16:                 return "fp_to_fp16";
00242 
00243   case ISD::CONVERT_RNDSAT: {
00244     switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
00245     default: llvm_unreachable("Unknown cvt code!");
00246     case ISD::CVT_FF:                   return "cvt_ff";
00247     case ISD::CVT_FS:                   return "cvt_fs";
00248     case ISD::CVT_FU:                   return "cvt_fu";
00249     case ISD::CVT_SF:                   return "cvt_sf";
00250     case ISD::CVT_UF:                   return "cvt_uf";
00251     case ISD::CVT_SS:                   return "cvt_ss";
00252     case ISD::CVT_SU:                   return "cvt_su";
00253     case ISD::CVT_US:                   return "cvt_us";
00254     case ISD::CVT_UU:                   return "cvt_uu";
00255     }
00256   }
00257 
00258     // Control flow instructions
00259   case ISD::BR:                         return "br";
00260   case ISD::BRIND:                      return "brind";
00261   case ISD::BR_JT:                      return "br_jt";
00262   case ISD::BRCOND:                     return "brcond";
00263   case ISD::BR_CC:                      return "br_cc";
00264   case ISD::CALLSEQ_START:              return "callseq_start";
00265   case ISD::CALLSEQ_END:                return "callseq_end";
00266 
00267     // Other operators
00268   case ISD::LOAD:                       return "load";
00269   case ISD::STORE:                      return "store";
00270   case ISD::VAARG:                      return "vaarg";
00271   case ISD::VACOPY:                     return "vacopy";
00272   case ISD::VAEND:                      return "vaend";
00273   case ISD::VASTART:                    return "vastart";
00274   case ISD::DYNAMIC_STACKALLOC:         return "dynamic_stackalloc";
00275   case ISD::EXTRACT_ELEMENT:            return "extract_element";
00276   case ISD::BUILD_PAIR:                 return "build_pair";
00277   case ISD::STACKSAVE:                  return "stacksave";
00278   case ISD::STACKRESTORE:               return "stackrestore";
00279   case ISD::TRAP:                       return "trap";
00280   case ISD::DEBUGTRAP:                  return "debugtrap";
00281   case ISD::LIFETIME_START:             return "lifetime.start";
00282   case ISD::LIFETIME_END:               return "lifetime.end";
00283 
00284   // Bit manipulation
00285   case ISD::BSWAP:                      return "bswap";
00286   case ISD::CTPOP:                      return "ctpop";
00287   case ISD::CTTZ:                       return "cttz";
00288   case ISD::CTTZ_ZERO_UNDEF:            return "cttz_zero_undef";
00289   case ISD::CTLZ:                       return "ctlz";
00290   case ISD::CTLZ_ZERO_UNDEF:            return "ctlz_zero_undef";
00291 
00292   // Trampolines
00293   case ISD::INIT_TRAMPOLINE:            return "init_trampoline";
00294   case ISD::ADJUST_TRAMPOLINE:          return "adjust_trampoline";
00295 
00296   case ISD::CONDCODE:
00297     switch (cast<CondCodeSDNode>(this)->get()) {
00298     default: llvm_unreachable("Unknown setcc condition!");
00299     case ISD::SETOEQ:                   return "setoeq";
00300     case ISD::SETOGT:                   return "setogt";
00301     case ISD::SETOGE:                   return "setoge";
00302     case ISD::SETOLT:                   return "setolt";
00303     case ISD::SETOLE:                   return "setole";
00304     case ISD::SETONE:                   return "setone";
00305 
00306     case ISD::SETO:                     return "seto";
00307     case ISD::SETUO:                    return "setuo";
00308     case ISD::SETUEQ:                   return "setue";
00309     case ISD::SETUGT:                   return "setugt";
00310     case ISD::SETUGE:                   return "setuge";
00311     case ISD::SETULT:                   return "setult";
00312     case ISD::SETULE:                   return "setule";
00313     case ISD::SETUNE:                   return "setune";
00314 
00315     case ISD::SETEQ:                    return "seteq";
00316     case ISD::SETGT:                    return "setgt";
00317     case ISD::SETGE:                    return "setge";
00318     case ISD::SETLT:                    return "setlt";
00319     case ISD::SETLE:                    return "setle";
00320     case ISD::SETNE:                    return "setne";
00321 
00322     case ISD::SETTRUE:                  return "settrue";
00323     case ISD::SETTRUE2:                 return "settrue2";
00324     case ISD::SETFALSE:                 return "setfalse";
00325     case ISD::SETFALSE2:                return "setfalse2";
00326     }
00327   }
00328 }
00329 
00330 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
00331   switch (AM) {
00332   default:              return "";
00333   case ISD::PRE_INC:    return "<pre-inc>";
00334   case ISD::PRE_DEC:    return "<pre-dec>";
00335   case ISD::POST_INC:   return "<post-inc>";
00336   case ISD::POST_DEC:   return "<post-dec>";
00337   }
00338 }
00339 
00340 void SDNode::dump() const { dump(nullptr); }
00341 void SDNode::dump(const SelectionDAG *G) const {
00342   print(dbgs(), G);
00343   dbgs() << '\n';
00344 }
00345 
00346 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
00347   OS << (const void*)this << ": ";
00348 
00349   for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
00350     if (i) OS << ",";
00351     if (getValueType(i) == MVT::Other)
00352       OS << "ch";
00353     else
00354       OS << getValueType(i).getEVTString();
00355   }
00356   OS << " = " << getOperationName(G);
00357 }
00358 
00359 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
00360   if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
00361     if (!MN->memoperands_empty()) {
00362       OS << "<";
00363       OS << "Mem:";
00364       for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
00365            e = MN->memoperands_end(); i != e; ++i) {
00366         OS << **i;
00367         if (std::next(i) != e)
00368           OS << " ";
00369       }
00370       OS << ">";
00371     }
00372   } else if (const ShuffleVectorSDNode *SVN =
00373                dyn_cast<ShuffleVectorSDNode>(this)) {
00374     OS << "<";
00375     for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
00376       int Idx = SVN->getMaskElt(i);
00377       if (i) OS << ",";
00378       if (Idx < 0)
00379         OS << "u";
00380       else
00381         OS << Idx;
00382     }
00383     OS << ">";
00384   } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
00385     OS << '<' << CSDN->getAPIntValue() << '>';
00386   } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
00387     if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
00388       OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
00389     else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
00390       OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
00391     else {
00392       OS << "<APFloat(";
00393       CSDN->getValueAPF().bitcastToAPInt().dump();
00394       OS << ")>";
00395     }
00396   } else if (const GlobalAddressSDNode *GADN =
00397              dyn_cast<GlobalAddressSDNode>(this)) {
00398     int64_t offset = GADN->getOffset();
00399     OS << '<';
00400     GADN->getGlobal()->printAsOperand(OS);
00401     OS << '>';
00402     if (offset > 0)
00403       OS << " + " << offset;
00404     else
00405       OS << " " << offset;
00406     if (unsigned int TF = GADN->getTargetFlags())
00407       OS << " [TF=" << TF << ']';
00408   } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
00409     OS << "<" << FIDN->getIndex() << ">";
00410   } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
00411     OS << "<" << JTDN->getIndex() << ">";
00412     if (unsigned int TF = JTDN->getTargetFlags())
00413       OS << " [TF=" << TF << ']';
00414   } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
00415     int offset = CP->getOffset();
00416     if (CP->isMachineConstantPoolEntry())
00417       OS << "<" << *CP->getMachineCPVal() << ">";
00418     else
00419       OS << "<" << *CP->getConstVal() << ">";
00420     if (offset > 0)
00421       OS << " + " << offset;
00422     else
00423       OS << " " << offset;
00424     if (unsigned int TF = CP->getTargetFlags())
00425       OS << " [TF=" << TF << ']';
00426   } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
00427     OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
00428     if (unsigned TF = TI->getTargetFlags())
00429       OS << " [TF=" << TF << ']';
00430   } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
00431     OS << "<";
00432     const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
00433     if (LBB)
00434       OS << LBB->getName() << " ";
00435     OS << (const void*)BBDN->getBasicBlock() << ">";
00436   } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
00437     OS << ' ' << PrintReg(R->getReg(),
00438                           G ? G->getSubtarget().getRegisterInfo() : nullptr);
00439   } else if (const ExternalSymbolSDNode *ES =
00440              dyn_cast<ExternalSymbolSDNode>(this)) {
00441     OS << "'" << ES->getSymbol() << "'";
00442     if (unsigned int TF = ES->getTargetFlags())
00443       OS << " [TF=" << TF << ']';
00444   } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
00445     if (M->getValue())
00446       OS << "<" << M->getValue() << ">";
00447     else
00448       OS << "<null>";
00449   } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
00450     if (MD->getMD())
00451       OS << "<" << MD->getMD() << ">";
00452     else
00453       OS << "<null>";
00454   } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
00455     OS << ":" << N->getVT().getEVTString();
00456   }
00457   else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
00458     OS << "<" << *LD->getMemOperand();
00459 
00460     bool doExt = true;
00461     switch (LD->getExtensionType()) {
00462     default: doExt = false; break;
00463     case ISD::EXTLOAD:  OS << ", anyext"; break;
00464     case ISD::SEXTLOAD: OS << ", sext"; break;
00465     case ISD::ZEXTLOAD: OS << ", zext"; break;
00466     }
00467     if (doExt)
00468       OS << " from " << LD->getMemoryVT().getEVTString();
00469 
00470     const char *AM = getIndexedModeName(LD->getAddressingMode());
00471     if (*AM)
00472       OS << ", " << AM;
00473 
00474     OS << ">";
00475   } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
00476     OS << "<" << *ST->getMemOperand();
00477 
00478     if (ST->isTruncatingStore())
00479       OS << ", trunc to " << ST->getMemoryVT().getEVTString();
00480 
00481     const char *AM = getIndexedModeName(ST->getAddressingMode());
00482     if (*AM)
00483       OS << ", " << AM;
00484 
00485     OS << ">";
00486   } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
00487     OS << "<" << *M->getMemOperand() << ">";
00488   } else if (const BlockAddressSDNode *BA =
00489                dyn_cast<BlockAddressSDNode>(this)) {
00490     int64_t offset = BA->getOffset();
00491     OS << "<";
00492     BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
00493     OS << ", ";
00494     BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
00495     OS << ">";
00496     if (offset > 0)
00497       OS << " + " << offset;
00498     else
00499       OS << " " << offset;
00500     if (unsigned int TF = BA->getTargetFlags())
00501       OS << " [TF=" << TF << ']';
00502   } else if (const AddrSpaceCastSDNode *ASC =
00503                dyn_cast<AddrSpaceCastSDNode>(this)) {
00504     OS << '['
00505        << ASC->getSrcAddressSpace()
00506        << " -> "
00507        << ASC->getDestAddressSpace()
00508        << ']';
00509   }
00510 
00511   if (unsigned Order = getIROrder())
00512       OS << " [ORD=" << Order << ']';
00513 
00514   if (getNodeId() != -1)
00515     OS << " [ID=" << getNodeId() << ']';
00516 
00517   DebugLoc dl = getDebugLoc();
00518   if (G && !dl.isUnknown()) {
00519     DIScope
00520       Scope(dl.getScope(G->getMachineFunction().getFunction()->getContext()));
00521     OS << " dbg:";
00522     assert((!Scope || Scope.isScope()) &&
00523       "Scope of a DebugLoc should be null or a DIScope.");
00524     // Omit the directory, since it's usually long and uninteresting.
00525     if (Scope)
00526       OS << Scope.getFilename();
00527     else
00528       OS << "<unknown>";
00529     OS << ':' << dl.getLine();
00530     if (dl.getCol() != 0)
00531       OS << ':' << dl.getCol();
00532   }
00533 }
00534 
00535 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
00536   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
00537     if (N->getOperand(i).getNode()->hasOneUse())
00538       DumpNodes(N->getOperand(i).getNode(), indent+2, G);
00539     else
00540       dbgs() << "\n" << std::string(indent+2, ' ')
00541              << (void*)N->getOperand(i).getNode() << ": <multiple use>";
00542 
00543   dbgs() << '\n';
00544   dbgs().indent(indent);
00545   N->dump(G);
00546 }
00547 
00548 void SelectionDAG::dump() const {
00549   dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:";
00550 
00551   for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
00552        I != E; ++I) {
00553     const SDNode *N = I;
00554     if (!N->hasOneUse() && N != getRoot().getNode())
00555       DumpNodes(N, 2, this);
00556   }
00557 
00558   if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
00559   dbgs() << "\n\n";
00560 }
00561 
00562 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
00563   print_types(OS, G);
00564   print_details(OS, G);
00565 }
00566 
00567 typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
00568 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
00569                        const SelectionDAG *G, VisitedSDNodeSet &once) {
00570   if (!once.insert(N))          // If we've been here before, return now.
00571     return;
00572 
00573   // Dump the current SDNode, but don't end the line yet.
00574   OS.indent(indent);
00575   N->printr(OS, G);
00576 
00577   // Having printed this SDNode, walk the children:
00578   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
00579     const SDNode *child = N->getOperand(i).getNode();
00580 
00581     if (i) OS << ",";
00582     OS << " ";
00583 
00584     if (child->getNumOperands() == 0) {
00585       // This child has no grandchildren; print it inline right here.
00586       child->printr(OS, G);
00587       once.insert(child);
00588     } else {         // Just the address. FIXME: also print the child's opcode.
00589       OS << (const void*)child;
00590       if (unsigned RN = N->getOperand(i).getResNo())
00591         OS << ":" << RN;
00592     }
00593   }
00594 
00595   OS << "\n";
00596 
00597   // Dump children that have grandchildren on their own line(s).
00598   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
00599     const SDNode *child = N->getOperand(i).getNode();
00600     DumpNodesr(OS, child, indent+2, G, once);
00601   }
00602 }
00603 
00604 void SDNode::dumpr() const {
00605   VisitedSDNodeSet once;
00606   DumpNodesr(dbgs(), this, 0, nullptr, once);
00607 }
00608 
00609 void SDNode::dumpr(const SelectionDAG *G) const {
00610   VisitedSDNodeSet once;
00611   DumpNodesr(dbgs(), this, 0, G, once);
00612 }
00613 
00614 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
00615                                   const SelectionDAG *G, unsigned depth,
00616                                   unsigned indent) {
00617   if (depth == 0)
00618     return;
00619 
00620   OS.indent(indent);
00621 
00622   N->print(OS, G);
00623 
00624   if (depth < 1)
00625     return;
00626 
00627   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
00628     // Don't follow chain operands.
00629     if (N->getOperand(i).getValueType() == MVT::Other)
00630       continue;
00631     OS << '\n';
00632     printrWithDepthHelper(OS, N->getOperand(i).getNode(), G, depth-1, indent+2);
00633   }
00634 }
00635 
00636 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
00637                             unsigned depth) const {
00638   printrWithDepthHelper(OS, this, G, depth, 0);
00639 }
00640 
00641 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
00642   // Don't print impossibly deep things.
00643   printrWithDepth(OS, G, 10);
00644 }
00645 
00646 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
00647   printrWithDepth(dbgs(), G, depth);
00648 }
00649 
00650 void SDNode::dumprFull(const SelectionDAG *G) const {
00651   // Don't print impossibly deep things.
00652   dumprWithDepth(G, 10);
00653 }
00654 
00655 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
00656   print_types(OS, G);
00657   for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
00658     if (i) OS << ", "; else OS << " ";
00659     OS << (void*)getOperand(i).getNode();
00660     if (unsigned RN = getOperand(i).getResNo())
00661       OS << ":" << RN;
00662   }
00663   print_details(OS, G);
00664 }