[DwarfCompileUnit] getOrCreateCommonBlock(): check for existing entity first. NFCI
authorKristina Bessonova <kbessonova@accesssoftek.com>
Tue, 2 Nov 2021 18:37:48 +0000 (20:37 +0200)
committerKristina Bessonova <kbessonova@accesssoftek.com>
Sun, 14 Nov 2021 08:58:24 +0000 (10:58 +0200)
For global variables and common blocks there is no way to create entities
through getOrCreateContextDIE(), so no need to obtain the context first.

Differential Revision: https://reviews.llvm.org/D113651

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

index b1d9c02..8c0a1f6 100644 (file)
@@ -349,12 +349,10 @@ void DwarfCompileUnit::addLocationAttribute(
 
 DIE *DwarfCompileUnit::getOrCreateCommonBlock(
     const DICommonBlock *CB, ArrayRef<GlobalExpr> GlobalExprs) {
-  // Construct the context before querying for the existence of the DIE in case
-  // such construction creates the DIE.
-  DIE *ContextDIE = getOrCreateContextDIE(CB->getScope());
-
+  // Check for pre-existence.
   if (DIE *NDie = getDIE(CB))
     return NDie;
+  DIE *ContextDIE = getOrCreateContextDIE(CB->getScope());
   DIE &NDie = createAndAddDIE(dwarf::DW_TAG_common_block, *ContextDIE, CB);
   StringRef Name = CB->getName().empty() ? "_BLNK_" : CB->getName();
   addString(NDie, dwarf::DW_AT_name, Name);