LLVM  13.0.0git
Public Types | Public Member Functions | List of all members
llvm::DeclContext Class Reference

A DeclContext is a named program scope that is used for ODR uniquing of types. More...

#include "llvm/DWARFLinker/DWARFLinkerDeclContext.h"

Public Types

using Map = DenseSet< DeclContext *, DeclMapInfo >

Public Member Functions

 DeclContext ()
 DeclContext (unsigned Hash, uint32_t Line, uint32_t ByteSize, uint16_t Tag, StringRef Name, StringRef File, const DeclContext &Parent, DWARFDie LastSeenDIE=DWARFDie(), unsigned CUId=0)
uint32_t getQualifiedNameHash () const
bool setLastSeenDIE (CompileUnit &U, const DWARFDie &Die)
 Set the last DIE/CU a context was seen in and, possibly invalidate the context if it is ambiguous. More...
uint32_t getCanonicalDIEOffset () const
void setCanonicalDIEOffset (uint32_t Offset)
bool isDefinedInClangModule () const
void setDefinedInClangModule (bool Val)
uint16_t getTag () const

Detailed Description

A DeclContext is a named program scope that is used for ODR uniquing of types.

The set of DeclContext for the ODR-subject parts of a Dwarf link is expanded (and uniqued) with each new object file processed. We need to determine the context of each DIE in an linked object file to see if the corresponding type has already been emitted.

The contexts are conceptually organized as a tree (eg. a function scope is contained in a namespace scope that contains other scopes), but storing/accessing them in an actual tree is too inefficient: we need to be able to very quickly query a context for a given child context by name. Storing a StringMap in each DeclContext would be too space inefficient.

The solution here is to give each DeclContext a link to its parent (this allows to walk up the tree), but to query the existence of a specific DeclContext using a separate DenseMap keyed on the hash of the fully qualified name of the context.

Definition at line 77 of file DWARFLinkerDeclContext.h.

Member Typedef Documentation

◆ Map

Definition at line 79 of file DWARFLinkerDeclContext.h.

Constructor & Destructor Documentation

◆ DeclContext() [1/2]

llvm::DeclContext::DeclContext ( )

Definition at line 81 of file DWARFLinkerDeclContext.h.

◆ DeclContext() [2/2]

llvm::DeclContext::DeclContext ( unsigned  Hash,
uint32_t  Line,
uint32_t  ByteSize,
uint16_t  Tag,
StringRef  Name,
StringRef  File,
const DeclContext Parent,
DWARFDie  LastSeenDIE = DWARFDie(),
unsigned  CUId = 0 

Definition at line 83 of file DWARFLinkerDeclContext.h.

Member Function Documentation

◆ getCanonicalDIEOffset()

uint32_t llvm::DeclContext::getCanonicalDIEOffset ( ) const

Definition at line 94 of file DWARFLinkerDeclContext.h.

Referenced by llvm::CompileUnit::fixupForwardReferences().

◆ getQualifiedNameHash()

uint32_t llvm::DeclContext::getQualifiedNameHash ( ) const

Definition at line 90 of file DWARFLinkerDeclContext.h.

◆ getTag()

uint16_t llvm::DeclContext::getTag ( ) const

Definition at line 100 of file DWARFLinkerDeclContext.h.

◆ isDefinedInClangModule()

bool llvm::DeclContext::isDefinedInClangModule ( ) const

Definition at line 97 of file DWARFLinkerDeclContext.h.

◆ setCanonicalDIEOffset()

void llvm::DeclContext::setCanonicalDIEOffset ( uint32_t  Offset)

Definition at line 95 of file DWARFLinkerDeclContext.h.

References Offset.

◆ setDefinedInClangModule()

void llvm::DeclContext::setDefinedInClangModule ( bool  Val)

Definition at line 98 of file DWARFLinkerDeclContext.h.

◆ setLastSeenDIE()

bool llvm::DeclContext::setLastSeenDIE ( CompileUnit U,
const DWARFDie Die 

Set the last DIE/CU a context was seen in and, possibly invalidate the context if it is ambiguous.

In the current implementation, we don't handle overloaded functions well, because the argument types are not taken into account when computing the DeclContext tree.

Some of this is mitigated byt using mangled names that do contain the arguments types, but sometimes (e.g. with function templates) we don't have that. In that case, just do not unique anything that refers to the contexts we are not able to distinguish.

If a context that is not a namespace appears twice in the same CU, we know it is ambiguous. Make it invalid.

Definition at line 30 of file DWARFLinkerDeclContext.cpp.

References llvm::CompileUnit::DIEInfo::Ctxt, llvm::CompileUnit::getInfo(), llvm::CompileUnit::getOrigUnit(), and llvm::CompileUnit::getUniqueID().

The documentation for this class was generated from the following files: