diff options
Diffstat (limited to 'lib/CodeGen')
| -rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 | ||||
| -rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 137 | ||||
| -rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.h | 9 | ||||
| -rw-r--r-- | lib/CodeGen/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lib/CodeGen/DwarfEHPrepare.cpp | 4 | ||||
| -rw-r--r-- | lib/CodeGen/MachineFunction.cpp | 43 | ||||
| -rw-r--r-- | lib/CodeGen/MachineFunctionPass.cpp | 6 | ||||
| -rw-r--r-- | lib/CodeGen/MachineFunctionPrinterPass.cpp | 60 | ||||
| -rw-r--r-- | lib/CodeGen/MachineInstr.cpp | 17 | ||||
| -rw-r--r-- | lib/CodeGen/MachineSSAUpdater.cpp | 2 | ||||
| -rw-r--r-- | lib/CodeGen/SelectionDAG/FastISel.cpp | 4 | ||||
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SDNodeDbgValue.h | 1 | ||||
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 46 | ||||
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 11 | ||||
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h | 6 | ||||
| -rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 17 | 
16 files changed, 204 insertions, 174 deletions
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 3e71d18b5261..625a2b95f205 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -340,19 +340,17 @@ static void EmitComments(const MachineInstr &MI, raw_ostream &CommentOS) {    const MachineFunction *MF = MI.getParent()->getParent();    const TargetMachine &TM = MF->getTarget(); -  if (!MI.getDebugLoc().isUnknown()) { -    DILocation DLT = MF->getDILocation(MI.getDebugLoc()); -     -    // Print source line info. -    DIScope Scope = DLT.getScope(); +  DebugLoc DL = MI.getDebugLoc(); +  if (!DL.isUnknown()) {          // Print source line info. +    DIScope Scope(DL.getScope(MF->getFunction()->getContext()));      // Omit the directory, because it's likely to be long and uninteresting.      if (Scope.Verify())        CommentOS << Scope.getFilename();      else        CommentOS << "<unknown>"; -    CommentOS << ':' << DLT.getLineNumber(); -    if (DLT.getColumnNumber() != 0) -      CommentOS << ':' << DLT.getColumnNumber(); +    CommentOS << ':' << DL.getLine(); +    if (DL.getCol() != 0) +      CommentOS << ':' << DL.getCol();      CommentOS << '\n';    } diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index fb91d4f9849f..9084456c8f4d 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -302,7 +302,7 @@ DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T)    : DwarfPrinter(OS, A, T), ModuleCU(0),      AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),      DIEBlocks(), SectionSourceLines(), didInitial(false), shouldEmit(false), -    CurrentFnDbgScope(0), PrevDILoc(0), DebugTimer(0) { +    CurrentFnDbgScope(0), DebugTimer(0) {    NextStringPoolNumber = 0;    if (TimePassesIsEnabled)      DebugTimer = new Timer("Dwarf Debug Writer"); @@ -1932,13 +1932,14 @@ void DwarfDebug::endModule() {  /// findAbstractVariable - Find abstract variable, if any, associated with Var.  DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,                                                unsigned FrameIdx, -                                              DILocation &ScopeLoc) { +                                              DebugLoc ScopeLoc) {    DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var.getNode());    if (AbsDbgVariable)      return AbsDbgVariable; -  DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope().getNode()); +  LLVMContext &Ctx = Var.getNode()->getContext(); +  DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx));    if (!Scope)      return NULL; @@ -1953,13 +1954,14 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,  /// FIXME : Refactor findAbstractVariable.  DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,                                                const MachineInstr *MI, -                                              DILocation &ScopeLoc) { +                                              DebugLoc ScopeLoc) {    DbgVariable *AbsDbgVariable = AbstractVariables.lookup(Var.getNode());    if (AbsDbgVariable)      return AbsDbgVariable; -  DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope().getNode()); +  LLVMContext &Ctx = Var.getNode()->getContext(); +  DbgScope *Scope = AbstractScopes.lookup(ScopeLoc.getScope(Ctx));    if (!Scope)      return NULL; @@ -1975,24 +1977,27 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &Var,  void DwarfDebug::collectVariableInfo() {    if (!MMI) return; +  const LLVMContext &Ctx = MF->getFunction()->getContext(); +    MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();    for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),           VE = VMap.end(); VI != VE; ++VI) {      MDNode *Var = VI->first;      if (!Var) continue; -    DIVariable DV (Var); -    std::pair< unsigned, MDNode *> VP = VI->second; -    DILocation ScopeLoc(VP.second); - -    DbgScope *Scope = -      ConcreteScopes.lookup(ScopeLoc.getOrigLocation().getNode()); -    if (!Scope) -      Scope = DbgScopeMap.lookup(ScopeLoc.getScope().getNode()); +    DIVariable DV(Var); +    const std::pair<unsigned, DebugLoc> &VP = VI->second; + +    DbgScope *Scope = 0; +    if (MDNode *IA = VP.second.getInlinedAt(Ctx)) +      Scope = ConcreteScopes.lookup(IA); +    if (Scope == 0) +      Scope = DbgScopeMap.lookup(VP.second.getScope(Ctx)); +          // If variable scope is not found then skip this variable. -    if (!Scope) +    if (Scope == 0)        continue; -    DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first, ScopeLoc); +    DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.first, VP.second);      DbgVariable *RegVar = new DbgVariable(DV, VP.first, AbsDbgVariable);      Scope->addVariable(RegVar);    } @@ -2021,16 +2026,17 @@ void DwarfDebug::collectVariableInfo() {        DebugLoc DL = MInsn->getDebugLoc();        if (DL.isUnknown()) continue; -      DILocation ScopeLoc = MF->getDILocation(DL); -      DbgScope *Scope = -        ConcreteScopes.lookup(ScopeLoc.getOrigLocation().getNode()); -      if (!Scope) -        Scope = DbgScopeMap.lookup(ScopeLoc.getScope().getNode()); +      DbgScope *Scope = 0; +      if (MDNode *IA = DL.getInlinedAt(Ctx)) +        Scope = ConcreteScopes.lookup(IA); +      if (Scope == 0) +        Scope = DbgScopeMap.lookup(DL.getScope(Ctx)); +              // If variable scope is not found then skip this variable. -      if (!Scope) +      if (Scope == 0)          continue; -      DbgVariable *AbsDbgVariable = findAbstractVariable(DV, MInsn, ScopeLoc); +      DbgVariable *AbsDbgVariable = findAbstractVariable(DV, MInsn, DL);        DbgVariable *RegVar = new DbgVariable(DV, MInsn, AbsDbgVariable);        DbgValueStartMap[MInsn] = RegVar;        Scope->addVariable(RegVar); @@ -2044,12 +2050,15 @@ void DwarfDebug::beginScope(const MachineInstr *MI) {    DebugLoc DL = MI->getDebugLoc();    if (DL.isUnknown())      return; -  DILocation DILoc = MF->getDILocation(DL); -  if (!DILoc.getScope().Verify()) -    return;    // Check and update last known location info. -  if(DILoc.getNode() == PrevDILoc) +  if (DL == PrevInstLoc) +    return; +   +  MDNode *Scope = DL.getScope(MF->getFunction()->getContext()); +   +  // FIXME: Should only verify each scope once! +  if (!DIScope(Scope).Verify())      return;    // DBG_VALUE instruction establishes new value. @@ -2057,10 +2066,8 @@ void DwarfDebug::beginScope(const MachineInstr *MI) {      DenseMap<const MachineInstr *, DbgVariable *>::iterator DI        = DbgValueStartMap.find(MI);      if (DI != DbgValueStartMap.end()) { -      MCSymbol *Label = recordSourceLine(DILoc.getLineNumber(), -                                         DILoc.getColumnNumber(), -                                         DILoc.getScope().getNode()); -      PrevDILoc = DILoc.getNode(); +      MCSymbol *Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope); +      PrevInstLoc = DL;        DI->second->setDbgValueLabel(Label);      }      return; @@ -2068,10 +2075,8 @@ void DwarfDebug::beginScope(const MachineInstr *MI) {    // Emit a label to indicate location change. This is used for line     // table even if this instruction does start a new scope. -  MCSymbol *Label = recordSourceLine(DILoc.getLineNumber(), -                                     DILoc.getColumnNumber(), -                                     DILoc.getScope().getNode()); -  PrevDILoc = DILoc.getNode(); +  MCSymbol *Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope); +  PrevInstLoc = DL;    // update DbgScope if this instruction starts a new scope.    InsnToDbgScopeMapTy::iterator I = DbgScopeBeginMap.find(MI); @@ -2094,15 +2099,12 @@ void DwarfDebug::endScope(const MachineInstr *MI) {    DebugLoc DL = MI->getDebugLoc();    if (DL.isUnknown())      return; -  DILocation DILoc = MF->getDILocation(DL); -  if (!DILoc.getScope().Verify()) -    return; -   +    // Emit a label and update DbgScope if this instruction ends a scope.    InsnToDbgScopeMapTy::iterator I = DbgScopeEndMap.find(MI);    if (I == DbgScopeEndMap.end())      return; - +      MCSymbol *Label = MMI->getContext().CreateTempSymbol();    Asm->OutStreamer.EmitLabel(Label); @@ -2115,7 +2117,6 @@ void DwarfDebug::endScope(const MachineInstr *MI) {  /// createDbgScope - Create DbgScope for the scope.  void DwarfDebug::createDbgScope(MDNode *Scope, MDNode *InlinedAt) { -    if (!InlinedAt) {      DbgScope *WScope = DbgScopeMap.lookup(Scope);      if (WScope) @@ -2147,6 +2148,8 @@ bool DwarfDebug::extractScopeInformation() {    DenseMap<const MachineInstr *, unsigned> MIIndexMap;    unsigned MIIndex = 0; +  LLVMContext &Ctx = MF->getFunction()->getContext(); +      // Scan each instruction and create scopes. First build working set of scopes.    for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();         I != E; ++I) { @@ -2156,16 +2159,17 @@ bool DwarfDebug::extractScopeInformation() {        // FIXME : Remove DBG_VALUE check.        if (MInsn->isDebugValue()) continue;        MIIndexMap[MInsn] = MIIndex++; +              DebugLoc DL = MInsn->getDebugLoc();        if (DL.isUnknown()) continue; -      DILocation DLT = MF->getDILocation(DL); -      DIScope DLTScope = DLT.getScope(); -      if (!DLTScope.getNode()) continue; +       +      MDNode *Scope = DL.getScope(Ctx); +              // There is no need to create another DIE for compile unit. For all        // other scopes, create one DbgScope now. This will be translated        // into a scope DIE at the end. -      if (DLTScope.isCompileUnit()) continue; -      createDbgScope(DLTScope.getNode(), DLT.getOrigLocation().getNode()); +      if (DIScope(Scope).isCompileUnit()) continue; +      createDbgScope(Scope, DL.getInlinedAt(Ctx));      }    } @@ -2179,17 +2183,17 @@ bool DwarfDebug::extractScopeInformation() {        // FIXME : Remove DBG_VALUE check.        if (MInsn->isDebugValue()) continue;        DebugLoc DL = MInsn->getDebugLoc(); -      if (DL.isUnknown())  continue; -      DILocation DLT = MF->getDILocation(DL); -      DIScope DLTScope = DLT.getScope(); -      if (!DLTScope.getNode()) continue; +      if (DL.isUnknown()) continue; + +      MDNode *Scope = DL.getScope(Ctx); +      if (Scope == 0) continue; +              // There is no need to create another DIE for compile unit. For all        // other scopes, create one DbgScope now. This will be translated        // into a scope DIE at the end. -      if (DLTScope.isCompileUnit()) continue; -      DbgScope *Scope = getUpdatedDbgScope(DLTScope.getNode(), MInsn,  -                                           DLT.getOrigLocation().getNode()); -      Scope->setLastInsn(MInsn); +      if (DIScope(Scope).isCompileUnit()) continue; +      DbgScope *DScope = getUpdatedDbgScope(Scope, MInsn, DL.getInlinedAt(Ctx)); +      DScope->setLastInsn(MInsn);      }    } @@ -2255,20 +2259,21 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {    // Emit label for the implicitly defined dbg.stoppoint at the start of the    // function.    DebugLoc FDL = MF->getDefaultDebugLoc(); -  if (!FDL.isUnknown()) { -    DILocation DLT = MF->getDILocation(FDL); -    DISubprogram SP = getDISubprogram(DLT.getScope().getNode()); -    unsigned Line, Col; -    if (SP.Verify()) { -      Line = SP.getLineNumber(); -      Col = 0; -    } else { -      Line = DLT.getLineNumber(); -      Col = DLT.getColumnNumber(); -    } -     -    recordSourceLine(Line, Col, DLT.getScope().getNode()); +  if (FDL.isUnknown()) return; +   +  MDNode *Scope = FDL.getScope(MF->getFunction()->getContext()); +   +  DISubprogram SP = getDISubprogram(Scope); +  unsigned Line, Col; +  if (SP.Verify()) { +    Line = SP.getLineNumber(); +    Col = 0; +  } else { +    Line = FDL.getLine(); +    Col = FDL.getCol();    } +   +  recordSourceLine(Line, Col, Scope);  }  /// endFunction - Gather and emit post-function debug information. diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index ad6b0c2cb7cd..03d9d9935f2f 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -195,7 +195,7 @@ class DwarfDebug : public DwarfPrinter {    /// Previous instruction's location information. This is used to determine    /// label location to indicate scope boundries in dwarf debug info. -  mutable const MDNode *PrevDILoc; +  DebugLoc PrevInstLoc;    /// DebugTimer - Timer for the Dwarf debug writer.    Timer *DebugTimer; @@ -361,7 +361,8 @@ class DwarfDebug : public DwarfPrinter {    /// getUpdatedDbgScope - Find or create DbgScope assicated with     /// the instruction. Initialize scope and update scope hierarchy. -  DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt); +  DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, +                               MDNode *InlinedAt);    /// createDbgScope - Create DbgScope for the scope.    void createDbgScope(MDNode *Scope, MDNode *InlinedAt); @@ -370,9 +371,9 @@ class DwarfDebug : public DwarfPrinter {    /// findAbstractVariable - Find abstract variable associated with Var.    DbgVariable *findAbstractVariable(DIVariable &Var, unsigned FrameIdx,  -                                    DILocation &Loc); +                                    DebugLoc Loc);    DbgVariable *findAbstractVariable(DIVariable &Var, const MachineInstr *MI, -                                    DILocation &Loc); +                                    DebugLoc Loc);    /// updateSubprogramScopeDIE - Find DIE for the given subprogram and     /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes. diff --git a/lib/CodeGen/CMakeLists.txt b/lib/CodeGen/CMakeLists.txt index d385b860d86e..62d18836c93e 100644 --- a/lib/CodeGen/CMakeLists.txt +++ b/lib/CodeGen/CMakeLists.txt @@ -27,6 +27,7 @@ add_llvm_library(LLVMCodeGen    MachineFunction.cpp    MachineFunctionAnalysis.cpp    MachineFunctionPass.cpp +  MachineFunctionPrinterPass.cpp    MachineInstr.cpp    MachineLICM.cpp    MachineLoopInfo.cpp diff --git a/lib/CodeGen/DwarfEHPrepare.cpp b/lib/CodeGen/DwarfEHPrepare.cpp index 8bae9edde721..7dbfd7d168bd 100644 --- a/lib/CodeGen/DwarfEHPrepare.cpp +++ b/lib/CodeGen/DwarfEHPrepare.cpp @@ -661,7 +661,7 @@ bool DwarfEHPrepare::PromoteStackTemporaries() {  /// the start of the basic block (unless there already is one, in which case  /// the existing call is returned).  Instruction *DwarfEHPrepare::CreateExceptionValueCall(BasicBlock *BB) { -  Instruction *Start = BB->getFirstNonPHI(); +  Instruction *Start = BB->getFirstNonPHIOrDbg();    // Is this a call to eh.exception?    if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(Start))      if (CI->getIntrinsicID() == Intrinsic::eh_exception) @@ -681,7 +681,7 @@ Instruction *DwarfEHPrepare::CreateExceptionValueCall(BasicBlock *BB) {  /// (creating it if necessary) at the start of the basic block (unless  /// there already is a load, in which case the existing load is returned).  Instruction *DwarfEHPrepare::CreateValueLoad(BasicBlock *BB) { -  Instruction *Start = BB->getFirstNonPHI(); +  Instruction *Start = BB->getFirstNonPHIOrDbg();    // Is this a load of the exception temporary?    if (ExceptionValueVar)      if (LoadInst* LI = dyn_cast<LoadInst>(Start)) diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index f6cc71f3a437..beac0c630bb5 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -39,40 +39,6 @@  #include "llvm/Support/raw_ostream.h"  using namespace llvm; -namespace { -  struct Printer : public MachineFunctionPass { -    static char ID; - -    raw_ostream &OS; -    const std::string Banner; - -    Printer(raw_ostream &os, const std::string &banner)  -      : MachineFunctionPass(&ID), OS(os), Banner(banner) {} - -    const char *getPassName() const { return "MachineFunction Printer"; } - -    virtual void getAnalysisUsage(AnalysisUsage &AU) const { -      AU.setPreservesAll(); -      MachineFunctionPass::getAnalysisUsage(AU); -    } - -    bool runOnMachineFunction(MachineFunction &MF) { -      OS << "# " << Banner << ":\n"; -      MF.print(OS); -      return false; -    } -  }; -  char Printer::ID = 0; -} - -/// Returns a newly-created MachineFunction Printer pass. The default banner is -/// empty. -/// -FunctionPass *llvm::createMachineFunctionPrinterPass(raw_ostream &OS, -                                                     const std::string &Banner){ -  return new Printer(OS, Banner); -} -  //===----------------------------------------------------------------------===//  // MachineFunction implementation  //===----------------------------------------------------------------------===// @@ -436,15 +402,6 @@ unsigned MachineFunction::addLiveIn(unsigned PReg,    return VReg;  } -/// getDILocation - Get the DILocation for a given DebugLoc object. -DILocation MachineFunction::getDILocation(DebugLoc DL) const { -  unsigned Idx = DL.getIndex(); -  assert(Idx < DebugLocInfo.DebugLocations.size() && -         "Invalid index into debug locations!"); -  return DILocation(DebugLocInfo.DebugLocations[Idx]); -} - -  /// getJTISymbol - Return the MCSymbol for the specified non-empty jump table.  /// If isLinkerPrivate is specified, an 'l' label is returned, otherwise a  /// normal 'L' label is returned. diff --git a/lib/CodeGen/MachineFunctionPass.cpp b/lib/CodeGen/MachineFunctionPass.cpp index 2f8d4c9e7aa4..e5a491270a8c 100644 --- a/lib/CodeGen/MachineFunctionPass.cpp +++ b/lib/CodeGen/MachineFunctionPass.cpp @@ -15,8 +15,14 @@  #include "llvm/Analysis/AliasAnalysis.h"  #include "llvm/CodeGen/MachineFunctionAnalysis.h"  #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/Passes.h"  using namespace llvm; +Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O, +                                             const std::string &Banner) const { +  return createMachineFunctionPrinterPass(O, Banner); +} +  bool MachineFunctionPass::runOnFunction(Function &F) {    // Do not codegen any 'available_externally' functions at all, they have    // definitions outside the translation unit. diff --git a/lib/CodeGen/MachineFunctionPrinterPass.cpp b/lib/CodeGen/MachineFunctionPrinterPass.cpp new file mode 100644 index 000000000000..547c4febc8da --- /dev/null +++ b/lib/CodeGen/MachineFunctionPrinterPass.cpp @@ -0,0 +1,60 @@ +//===-- MachineFunctionPrinterPass.cpp ------------------------------------===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// MachineFunctionPrinterPass implementation. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/Passes.h" +#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +namespace { +/// MachineFunctionPrinterPass - This is a pass to dump the IR of a +/// MachineFunction. +/// +struct MachineFunctionPrinterPass : public MachineFunctionPass { +  static char ID; + +  raw_ostream &OS; +  const std::string Banner; + +  MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner)  +      : MachineFunctionPass(&ID), OS(os), Banner(banner) {} + +  const char *getPassName() const { return "MachineFunction Printer"; } + +  virtual void getAnalysisUsage(AnalysisUsage &AU) const { +    AU.setPreservesAll(); +    MachineFunctionPass::getAnalysisUsage(AU); +  } + +  bool runOnMachineFunction(MachineFunction &MF) { +    OS << "# " << Banner << ":\n"; +    MF.print(OS); +    return false; +  } +}; + +char MachineFunctionPrinterPass::ID = 0; +} + +namespace llvm { +/// Returns a newly-created MachineFunction Printer pass. The +/// default banner is empty. +/// +MachineFunctionPass *createMachineFunctionPrinterPass(raw_ostream &OS, +                                                      const std::string &Banner){ +  return new MachineFunctionPrinterPass(OS, Banner); +} + +} diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 40d6b2093be7..39b7fb507f8b 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -395,7 +395,7 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineMemOperand &MMO) {  /// TID NULL and no operands.  MachineInstr::MachineInstr()    : TID(0), NumImplicitOps(0), AsmPrinterFlags(0), MemRefs(0), MemRefsEnd(0), -    Parent(0), debugLoc(DebugLoc::getUnknownLoc()) { +    Parent(0) {    // Make sure that we get added to a machine basicblock    LeakDetector::addGarbageObject(this);  } @@ -415,8 +415,7 @@ void MachineInstr::addImplicitDefUseOperands() {  /// instructions with variable number of operands).  MachineInstr::MachineInstr(const TargetInstrDesc &tid, bool NoImp)    : TID(&tid), NumImplicitOps(0), AsmPrinterFlags(0), -    MemRefs(0), MemRefsEnd(0), Parent(0), -    debugLoc(DebugLoc::getUnknownLoc()) { +    MemRefs(0), MemRefsEnd(0), Parent(0) {    if (!NoImp && TID->getImplicitDefs())      for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs)        NumImplicitOps++; @@ -454,8 +453,7 @@ MachineInstr::MachineInstr(const TargetInstrDesc &tid, const DebugLoc dl,  ///  MachineInstr::MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &tid)    : TID(&tid), NumImplicitOps(0), AsmPrinterFlags(0), -    MemRefs(0), MemRefsEnd(0), Parent(0),  -    debugLoc(DebugLoc::getUnknownLoc()) { +    MemRefs(0), MemRefsEnd(0), Parent(0) {    assert(MBB && "Cannot use inserting ctor with null basic block!");    if (TID->ImplicitDefs)      for (const unsigned *ImpDefs = TID->getImplicitDefs(); *ImpDefs; ++ImpDefs) @@ -1221,17 +1219,16 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const {      // TODO: print InlinedAtLoc information -    DILocation DLT = MF->getDILocation(debugLoc); -    DIScope Scope = DLT.getScope(); +    DIScope Scope(debugLoc.getScope(MF->getFunction()->getContext()));      OS << " dbg:";      // Omit the directory, since it's usually long and uninteresting.      if (Scope.Verify())        OS << Scope.getFilename();      else        OS << "<unknown>"; -    OS << ':' << DLT.getLineNumber(); -    if (DLT.getColumnNumber() != 0) -      OS << ':' << DLT.getColumnNumber(); +    OS << ':' << debugLoc.getLine(); +    if (debugLoc.getCol() != 0) +      OS << ':' << debugLoc.getCol();    }    OS << "\n"; diff --git a/lib/CodeGen/MachineSSAUpdater.cpp b/lib/CodeGen/MachineSSAUpdater.cpp index 2255dc339657..b79cdbb660de 100644 --- a/lib/CodeGen/MachineSSAUpdater.cpp +++ b/lib/CodeGen/MachineSSAUpdater.cpp @@ -125,7 +125,7 @@ MachineInstr *InsertNewDef(unsigned Opcode,                             const TargetRegisterClass *RC,                             MachineRegisterInfo *MRI, const TargetInstrInfo *TII) {    unsigned NewVR = MRI->createVirtualRegister(RC); -  return BuildMI(*BB, I, DebugLoc::getUnknownLoc(), TII->get(Opcode), NewVR); +  return BuildMI(*BB, I, DebugLoc(), TII->get(Opcode), NewVR);  }  /// GetValueInMiddleOfBlock - Construct SSA form, materializing a value that diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index e4e9ef405f63..d6f8a205c1f6 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -340,8 +340,8 @@ bool FastISel::SelectCall(User *I) {        StaticAllocaMap.find(AI);      if (SI == StaticAllocaMap.end()) break; // VLAs.      int FI = SI->second; -    if (MDNode *Dbg = DI->getDbgMetadata()) -      MMI->setVariableDbgInfo(DI->getVariable(), FI, Dbg); +    if (!DI->getDebugLoc().isUnknown()) +      MMI->setVariableDbgInfo(DI->getVariable(), FI, DI->getDebugLoc());      // Building the map above is target independent.  Generating DBG_VALUE      // inline is target dependent; do this now. diff --git a/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h b/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h index 7638ea2ae162..9d1568f01f40 100644 --- a/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h +++ b/lib/CodeGen/SelectionDAG/SDNodeDbgValue.h @@ -16,6 +16,7 @@  #include "llvm/ADT/SmallVector.h"  #include "llvm/Support/DebugLoc.h" +#include "llvm/System/DataTypes.h"  namespace llvm { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 0ba65ab7f96d..3643ea7c5315 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -794,8 +794,7 @@ unsigned SelectionDAG::getEVTAlignment(EVT VT) const {  // EntryNode could meaningfully have debug info if we can find it...  SelectionDAG::SelectionDAG(TargetLowering &tli, FunctionLoweringInfo &fli)    : TLI(tli), FLI(fli), DW(0), -    EntryNode(ISD::EntryToken, DebugLoc::getUnknownLoc(), -              getVTList(MVT::Other)), +    EntryNode(ISD::EntryToken, DebugLoc(), getVTList(MVT::Other)),      Root(getEntryNode()), Ordering(0) {    AllNodes.push_back(&EntryNode);    Ordering = new SDNodeOrdering(); @@ -919,8 +918,7 @@ SDValue SelectionDAG::getConstant(const ConstantInt &Val, EVT VT, bool isT) {    if (VT.isVector()) {      SmallVector<SDValue, 8> Ops;      Ops.assign(VT.getVectorNumElements(), Result); -    Result = getNode(ISD::BUILD_VECTOR, DebugLoc::getUnknownLoc(), -                     VT, &Ops[0], Ops.size()); +    Result = getNode(ISD::BUILD_VECTOR, DebugLoc(), VT, &Ops[0], Ops.size());    }    return Result;  } @@ -963,8 +961,7 @@ SDValue SelectionDAG::getConstantFP(const ConstantFP& V, EVT VT, bool isTarget){      SmallVector<SDValue, 8> Ops;      Ops.assign(VT.getVectorNumElements(), Result);      // FIXME DebugLoc info might be appropriate here -    Result = getNode(ISD::BUILD_VECTOR, DebugLoc::getUnknownLoc(), -                     VT, &Ops[0], Ops.size()); +    Result = getNode(ISD::BUILD_VECTOR, DebugLoc(), VT, &Ops[0], Ops.size());    }    return Result;  } @@ -3094,6 +3091,8 @@ SDValue SelectionDAG::getStackArgumentTokenFactor(SDValue Chain) {  /// operand.  static SDValue getMemsetValue(SDValue Value, EVT VT, SelectionDAG &DAG,                                DebugLoc dl) { +  assert(Value.getOpcode() != ISD::UNDEF); +    unsigned NumBits = VT.getScalarType().getSizeInBits();    if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Value)) {      APInt Val = APInt(NumBits, C->getZExtValue() & 255); @@ -3197,7 +3196,7 @@ static bool isMemSrcFromString(SDValue Src, std::string &Str) {  static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps,                                       unsigned Limit, uint64_t Size,                                       unsigned DstAlign, unsigned SrcAlign, -                                     bool SafeToUseFP, +                                     bool NonScalarIntSafe,                                       SelectionDAG &DAG,                                       const TargetLowering &TLI) {    assert((SrcAlign == 0 || SrcAlign >= DstAlign) && @@ -3207,7 +3206,8 @@ static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps,    // the inferred alignment of the source. 'DstAlign', on the other hand, is the    // specified alignment of the memory operation. If it is zero, that means    // it's possible to change the alignment of the destination. -  EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign, SafeToUseFP, DAG); +  EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign, +                                   NonScalarIntSafe, DAG);    if (VT == MVT::Other) {      VT = TLI.getPointerTy(); @@ -3266,10 +3266,13 @@ static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, DebugLoc dl,                                         unsigned Align, bool AlwaysInline,                                         const Value *DstSV, uint64_t DstSVOff,                                         const Value *SrcSV, uint64_t SrcSVOff) { -  const TargetLowering &TLI = DAG.getTargetLoweringInfo(); +  // Turn a memcpy of undef to nop. +  if (Src.getOpcode() == ISD::UNDEF) +    return Chain;    // Expand memcpy to a series of load and store ops if the size operand falls    // below a certain threshold. +  const TargetLowering &TLI = DAG.getTargetLoweringInfo();    std::vector<EVT> MemOps;    uint64_t Limit = -1ULL;    if (!AlwaysInline) @@ -3352,10 +3355,13 @@ static SDValue getMemmoveLoadsAndStores(SelectionDAG &DAG, DebugLoc dl,                                          unsigned Align,bool AlwaysInline,                                          const Value *DstSV, uint64_t DstSVOff,                                          const Value *SrcSV, uint64_t SrcSVOff) { -  const TargetLowering &TLI = DAG.getTargetLoweringInfo(); +  // Turn a memmove of undef to nop. +  if (Src.getOpcode() == ISD::UNDEF) +    return Chain;    // Expand memmove to a series of load and store ops if the size operand falls    // below a certain threshold. +  const TargetLowering &TLI = DAG.getTargetLoweringInfo();    std::vector<EVT> MemOps;    uint64_t Limit = -1ULL;    if (!AlwaysInline) @@ -3426,21 +3432,24 @@ static SDValue getMemsetStores(SelectionDAG &DAG, DebugLoc dl,                                 SDValue Src, uint64_t Size,                                 unsigned Align,                                 const Value *DstSV, uint64_t DstSVOff) { -  const TargetLowering &TLI = DAG.getTargetLoweringInfo(); +  // Turn a memset of undef to nop. +  if (Src.getOpcode() == ISD::UNDEF) +    return Chain;    // Expand memset to a series of load/store ops if the size operand    // falls below a certain threshold. +  const TargetLowering &TLI = DAG.getTargetLoweringInfo();    std::vector<EVT> MemOps;    bool DstAlignCanChange = false;    MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();    FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Dst);    if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))      DstAlignCanChange = true; -  bool IsZero = isa<ConstantSDNode>(Src) && -    cast<ConstantSDNode>(Src)->isNullValue(); +  bool NonScalarIntSafe = +    isa<ConstantSDNode>(Src) && cast<ConstantSDNode>(Src)->isNullValue();    if (!FindOptimalMemOpLowering(MemOps, TLI.getMaxStoresPerMemset(),                                  Size, (DstAlignCanChange ? 0 : Align), 0, -                                IsZero, DAG, TLI)) +                                NonScalarIntSafe, DAG, TLI))      return SDValue();    if (DstAlignCanChange) { @@ -3592,9 +3601,9 @@ SDValue SelectionDAG::getMemset(SDValue Chain, DebugLoc dl, SDValue Dst,      if (ConstantSize->isNullValue())        return Chain; -    SDValue Result = -      getMemsetStores(*this, dl, Chain, Dst, Src, ConstantSize->getZExtValue(), -                      Align, DstSV, DstSVOff); +    SDValue Result = getMemsetStores(*this, dl, Chain, Dst, Src, +                                     ConstantSize->getZExtValue(), +                                     Align, DstSV, DstSVOff);      if (Result.getNode())        return Result;    } @@ -5323,8 +5332,7 @@ HandleSDNode::~HandleSDNode() {  GlobalAddressSDNode::GlobalAddressSDNode(unsigned Opc, const GlobalValue *GA,                                           EVT VT, int64_t o, unsigned char TF) -  : SDNode(Opc, DebugLoc::getUnknownLoc(), getSDVTList(VT)), -    Offset(o), TargetFlags(TF) { +  : SDNode(Opc, DebugLoc(), getSDVTList(VT)), Offset(o), TargetFlags(TF) {    TheGlobal = const_cast<GlobalValue*>(GA);  } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 922c6e8b02a9..879bdb2cbbb7 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -546,7 +546,7 @@ void SelectionDAGBuilder::clear() {    PendingExports.clear();    EdgeMapping.clear();    DAG.clear(); -  CurDebugLoc = DebugLoc::getUnknownLoc(); +  CurDebugLoc = DebugLoc();    HasTailCall = false;  } @@ -3800,8 +3800,8 @@ SelectionDAGBuilder::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {      int FI = SI->second;      if (MachineModuleInfo *MMI = DAG.getMachineModuleInfo()) -      if (MDNode *Dbg = DI.getDbgMetadata()) -        MMI->setVariableDbgInfo(Variable, FI, Dbg); +      if (!DI.getDebugLoc().isUnknown()) +        MMI->setVariableDbgInfo(Variable, FI, DI.getDebugLoc());      return 0;    }    case Intrinsic::dbg_value: { @@ -3851,9 +3851,10 @@ SelectionDAGBuilder::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {      if (SI == FuncInfo.StaticAllocaMap.end())        return 0; // VLAs.      int FI = SI->second; +          if (MachineModuleInfo *MMI = DAG.getMachineModuleInfo()) -      if (MDNode *Dbg = DI.getDbgMetadata()) -        MMI->setVariableDbgInfo(Variable, FI, Dbg); +      if (!DI.getDebugLoc().isUnknown()) +        MMI->setVariableDbgInfo(Variable, FI, DI.getDebugLoc());      return 0;    }    case Intrinsic::eh_exception: { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h index bc4b33dff12f..9f027729b75e 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -306,10 +306,8 @@ public:    SelectionDAGBuilder(SelectionDAG &dag, TargetLowering &tli,                        FunctionLoweringInfo &funcinfo,                        CodeGenOpt::Level ol) -    : CurDebugLoc(DebugLoc::getUnknownLoc()), SDNodeOrder(0), -      TLI(tli), DAG(dag), FuncInfo(funcinfo), OptLevel(ol), -      HasTailCall(false), -      Context(dag.getContext()) { +    : SDNodeOrder(0), TLI(tli), DAG(dag), FuncInfo(funcinfo), OptLevel(ol), +      HasTailCall(false), Context(dag.getContext()) {    }    void init(GCFunctionInfo *gfi, AliasAnalysis &aa); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index ea96b2179999..d54566b8cd3a 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -368,28 +368,25 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {  /// attached with this instruction.  static void SetDebugLoc(Instruction *I, SelectionDAGBuilder *SDB,                          FastISel *FastIS, MachineFunction *MF) { -  MDNode *Dbg = I->getDbgMetadata(); -  if (Dbg == 0) return; +  DebugLoc DL = I->getDebugLoc(); +  if (DL.isUnknown()) return; -  DILocation DILoc(Dbg); -  DebugLoc Loc = ExtractDebugLocation(DILoc, MF->getDebugLocInfo()); - -  SDB->setCurDebugLoc(Loc); +  SDB->setCurDebugLoc(DL);    if (FastIS) -    FastIS->setCurDebugLoc(Loc); +    FastIS->setCurDebugLoc(DL);    // If the function doesn't have a default debug location yet, set    // it. This is kind of a hack.    if (MF->getDefaultDebugLoc().isUnknown()) -    MF->setDefaultDebugLoc(Loc); +    MF->setDefaultDebugLoc(DL);  }  /// ResetDebugLoc - Set MF's and SDB's DebugLocs to Unknown.  static void ResetDebugLoc(SelectionDAGBuilder *SDB, FastISel *FastIS) { -  SDB->setCurDebugLoc(DebugLoc::getUnknownLoc()); +  SDB->setCurDebugLoc(DebugLoc());    if (FastIS) -    FastIS->setCurDebugLoc(DebugLoc::getUnknownLoc()); +    FastIS->setCurDebugLoc(DebugLoc());  }  void SelectionDAGISel::SelectBasicBlock(BasicBlock *LLVMBB,  | 
