diff options
Diffstat (limited to 'lib/CodeGen/LexicalScopes.cpp')
| -rw-r--r-- | lib/CodeGen/LexicalScopes.cpp | 127 | 
1 files changed, 52 insertions, 75 deletions
diff --git a/lib/CodeGen/LexicalScopes.cpp b/lib/CodeGen/LexicalScopes.cpp index b621e3baee513..be61a20424b45 100644 --- a/lib/CodeGen/LexicalScopes.cpp +++ b/lib/CodeGen/LexicalScopes.cpp @@ -59,11 +59,11 @@ void LexicalScopes::extractLexicalScopes(    for (const auto &MBB : *MF) {      const MachineInstr *RangeBeginMI = nullptr;      const MachineInstr *PrevMI = nullptr; -    DebugLoc PrevDL; +    const DILocation *PrevDL = nullptr;      for (const auto &MInsn : MBB) {        // Check if instruction has valid location information. -      const DebugLoc MIDL = MInsn.getDebugLoc(); -      if (MIDL.isUnknown()) { +      const DILocation *MIDL = MInsn.getDebugLoc(); +      if (!MIDL) {          PrevMI = &MInsn;          continue;        } @@ -96,7 +96,7 @@ void LexicalScopes::extractLexicalScopes(      }      // Create last instruction range. -    if (RangeBeginMI && PrevMI && !PrevDL.isUnknown()) { +    if (RangeBeginMI && PrevMI && PrevDL) {        InsnRange R(RangeBeginMI, PrevMI);        MIRanges.push_back(R);        MI2ScopeMap[RangeBeginMI] = getOrCreateLexicalScope(PrevDL); @@ -104,30 +104,19 @@ void LexicalScopes::extractLexicalScopes(    }  } -LexicalScope *LexicalScopes::findInlinedScope(DebugLoc DL) { -  MDNode *Scope = nullptr; -  MDNode *IA = nullptr; -  DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext()); -  auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA)); -  return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr; -} -  /// findLexicalScope - Find lexical scope, either regular or inlined, for the  /// given DebugLoc. Return NULL if not found. -LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) { -  MDNode *Scope = nullptr; -  MDNode *IA = nullptr; -  DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext()); +LexicalScope *LexicalScopes::findLexicalScope(const DILocation *DL) { +  DILocalScope *Scope = DL->getScope();    if (!Scope)      return nullptr;    // The scope that we were created with could have an extra file - which    // isn't what we care about in this case. -  DIDescriptor D = DIDescriptor(Scope); -  if (D.isLexicalBlockFile()) -    Scope = DILexicalBlockFile(Scope).getScope(); +  if (auto *File = dyn_cast<DILexicalBlockFile>(Scope)) +    Scope = File->getScope(); -  if (IA) { +  if (auto *IA = DL->getInlinedAt()) {      auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));      return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;    } @@ -136,47 +125,39 @@ LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) {  /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If  /// not available then create new lexical scope. -LexicalScope *LexicalScopes::getOrCreateLexicalScope(DebugLoc DL) { -  if (DL.isUnknown()) -    return nullptr; -  MDNode *Scope = nullptr; -  MDNode *InlinedAt = nullptr; -  DL.getScopeAndInlinedAt(Scope, InlinedAt, MF->getFunction()->getContext()); - -  if (InlinedAt) { +LexicalScope *LexicalScopes::getOrCreateLexicalScope(const DILocalScope *Scope, +                                                     const DILocation *IA) { +  if (IA) {      // Create an abstract scope for inlined function.      getOrCreateAbstractScope(Scope);      // Create an inlined scope for inlined function. -    return getOrCreateInlinedScope(Scope, InlinedAt); +    return getOrCreateInlinedScope(Scope, IA);    }    return getOrCreateRegularScope(Scope);  }  /// getOrCreateRegularScope - Find or create a regular lexical scope. -LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) { -  DIDescriptor D = DIDescriptor(Scope); -  if (D.isLexicalBlockFile()) { -    Scope = DILexicalBlockFile(Scope).getScope(); -    D = DIDescriptor(Scope); -  } +LexicalScope * +LexicalScopes::getOrCreateRegularScope(const DILocalScope *Scope) { +  if (auto *File = dyn_cast<DILexicalBlockFile>(Scope)) +    Scope = File->getScope();    auto I = LexicalScopeMap.find(Scope);    if (I != LexicalScopeMap.end())      return &I->second; +  // FIXME: Should the following dyn_cast be DILexicalBlock?    LexicalScope *Parent = nullptr; -  if (D.isLexicalBlock()) -    Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope)); -  // FIXME: Use forward_as_tuple instead of make_tuple, once MSVC2012 -  // compatibility is no longer required. -  I = LexicalScopeMap.emplace(std::piecewise_construct, std::make_tuple(Scope), -                              std::make_tuple(Parent, DIDescriptor(Scope), -                                              nullptr, false)).first; +  if (auto *Block = dyn_cast<DILexicalBlockBase>(Scope)) +    Parent = getOrCreateLexicalScope(Block->getScope()); +  I = LexicalScopeMap.emplace(std::piecewise_construct, +                              std::forward_as_tuple(Scope), +                              std::forward_as_tuple(Parent, Scope, nullptr, +                                                    false)).first;    if (!Parent) { -    assert(DIDescriptor(Scope).isSubprogram()); -    assert(DISubprogram(Scope).describes(MF->getFunction())); +    assert(cast<DISubprogram>(Scope)->describes(MF->getFunction()));      assert(!CurrentFnLexicalScope);      CurrentFnLexicalScope = &I->second;    } @@ -185,51 +166,49 @@ LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) {  }  /// getOrCreateInlinedScope - Find or create an inlined lexical scope. -LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *ScopeNode, -                                                     MDNode *InlinedAt) { -  std::pair<const MDNode*, const MDNode*> P(ScopeNode, InlinedAt); +LexicalScope * +LexicalScopes::getOrCreateInlinedScope(const DILocalScope *Scope, +                                       const DILocation *InlinedAt) { +  std::pair<const DILocalScope *, const DILocation *> P(Scope, InlinedAt);    auto I = InlinedLexicalScopeMap.find(P);    if (I != InlinedLexicalScopeMap.end())      return &I->second;    LexicalScope *Parent; -  DILexicalBlock Scope(ScopeNode); -  if (Scope.isSubprogram()) -    Parent = getOrCreateLexicalScope(DebugLoc::getFromDILocation(InlinedAt)); +  if (auto *Block = dyn_cast<DILexicalBlockBase>(Scope)) +    Parent = getOrCreateInlinedScope(Block->getScope(), InlinedAt);    else -    Parent = getOrCreateInlinedScope(Scope.getContext(), InlinedAt); +    Parent = getOrCreateLexicalScope(InlinedAt); -  // FIXME: Use forward_as_tuple instead of make_tuple, once MSVC2012 -  // compatibility is no longer required.    I = InlinedLexicalScopeMap.emplace(std::piecewise_construct, -                                     std::make_tuple(P), -                                     std::make_tuple(Parent, Scope, InlinedAt, -                                                     false)).first; +                                     std::forward_as_tuple(P), +                                     std::forward_as_tuple(Parent, Scope, +                                                           InlinedAt, false)) +          .first;    return &I->second;  }  /// getOrCreateAbstractScope - Find or create an abstract lexical scope. -LexicalScope *LexicalScopes::getOrCreateAbstractScope(const MDNode *N) { -  assert(N && "Invalid Scope encoding!"); +LexicalScope * +LexicalScopes::getOrCreateAbstractScope(const DILocalScope *Scope) { +  assert(Scope && "Invalid Scope encoding!"); -  DIDescriptor Scope(N); -  if (Scope.isLexicalBlockFile()) -    Scope = DILexicalBlockFile(Scope).getScope(); +  if (auto *File = dyn_cast<DILexicalBlockFile>(Scope)) +    Scope = File->getScope();    auto I = AbstractScopeMap.find(Scope);    if (I != AbstractScopeMap.end())      return &I->second; +  // FIXME: Should the following isa be DILexicalBlock?    LexicalScope *Parent = nullptr; -  if (Scope.isLexicalBlock()) { -    DILexicalBlock DB(Scope); -    DIDescriptor ParentDesc = DB.getContext(); -    Parent = getOrCreateAbstractScope(ParentDesc); -  } +  if (auto *Block = dyn_cast<DILexicalBlockBase>(Scope)) +    Parent = getOrCreateAbstractScope(Block->getScope()); +    I = AbstractScopeMap.emplace(std::piecewise_construct,                                 std::forward_as_tuple(Scope),                                 std::forward_as_tuple(Parent, Scope,                                                       nullptr, true)).first; -  if (Scope.isSubprogram()) +  if (isa<DISubprogram>(Scope))      AbstractScopesList.push_back(&I->second);    return &I->second;  } @@ -290,7 +269,7 @@ void LexicalScopes::assignInstructionRanges(  /// have machine instructions that belong to lexical scope identified by  /// DebugLoc.  void LexicalScopes::getMachineBasicBlocks( -    DebugLoc DL, SmallPtrSetImpl<const MachineBasicBlock *> &MBBs) { +    const DILocation *DL, SmallPtrSetImpl<const MachineBasicBlock *> &MBBs) {    MBBs.clear();    LexicalScope *Scope = getOrCreateLexicalScope(DL);    if (!Scope) @@ -313,7 +292,7 @@ void LexicalScopes::getMachineBasicBlocks(  /// dominates - Return true if DebugLoc's lexical scope dominates at least one  /// machine instruction's lexical scope in a given machine basic block. -bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) { +bool LexicalScopes::dominates(const DILocation *DL, MachineBasicBlock *MBB) {    LexicalScope *Scope = getOrCreateLexicalScope(DL);    if (!Scope)      return false; @@ -325,12 +304,10 @@ bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) {    bool Result = false;    for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); I != E;         ++I) { -    DebugLoc IDL = I->getDebugLoc(); -    if (IDL.isUnknown()) -      continue; -    if (LexicalScope *IScope = getOrCreateLexicalScope(IDL)) -      if (Scope->dominates(IScope)) -        return true; +    if (const DILocation *IDL = I->getDebugLoc()) +      if (LexicalScope *IScope = getOrCreateLexicalScope(IDL)) +        if (Scope->dominates(IScope)) +          return true;    }    return Result;  }  | 
