[llvm] r228967 - IR: Stop abusing DW_TAG_base_type for compile unit arrays

Duncan P. N. Exon Smith dexonsmith at apple.com
Thu Feb 12 13:52:11 PST 2015


Author: dexonsmith
Date: Thu Feb 12 15:52:11 2015
New Revision: 228967

URL: http://llvm.org/viewvc/llvm-project?rev=228967&view=rev
Log:
IR: Stop abusing DW_TAG_base_type for compile unit arrays

The sub-arrays for compile units have for a long time been initialized
to distinct temporary nodes with the `DW_TAG_base_type` tag, with no
other operands.  These invalid `DIBasicType`s are later replaced with
appropriate arrays.

This seems like a poor man's assertion that the arrays do eventually get
replaced.  These days, temporaries in the graph will cause assertions
when writing bitcode or assembly, so this isn't necessary.  Use
temporary empty tuples instead.

Note that the whole idea of using temporaries and then replacing them
later is wasteful here.  We never actually want to merge compile units
by uniquing based on content.  Compile units should use `getDistinct()`
instead of `get()`, and then their operands can be freely replaced later
on.

Modified:
    llvm/trunk/lib/IR/DIBuilder.cpp

Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=228967&r1=228966&r2=228967&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Thu Feb 12 15:52:11 2015
@@ -150,16 +150,14 @@ DICompileUnit DIBuilder::createCompileUn
          "Invalid Language tag");
   assert(!Filename.empty() &&
          "Unable to create compile unit without filename");
-  Metadata *TElts[] = {HeaderBuilder::get(DW_TAG_base_type).get(VMContext)};
-  TempEnumTypes = MDNode::getTemporary(VMContext, TElts).release();
 
-  TempRetainTypes = MDNode::getTemporary(VMContext, TElts).release();
-
-  TempSubprograms = MDNode::getTemporary(VMContext, TElts).release();
-
-  TempGVs = MDNode::getTemporary(VMContext, TElts).release();
-
-  TempImportedModules = MDNode::getTemporary(VMContext, TElts).release();
+  // TODO: Once we make MDCompileUnit distinct, stop using temporaries here
+  // (just start with operands assigned to nullptr).
+  TempEnumTypes = MDTuple::getTemporary(VMContext, None).release();
+  TempRetainTypes = MDTuple::getTemporary(VMContext, None).release();
+  TempSubprograms = MDTuple::getTemporary(VMContext, None).release();
+  TempGVs = MDTuple::getTemporary(VMContext, None).release();
+  TempImportedModules = MDTuple::getTemporary(VMContext, None).release();
 
   Metadata *Elts[] = {HeaderBuilder::get(dwarf::DW_TAG_compile_unit)
                           .concat(Lang)
@@ -174,6 +172,8 @@ DICompileUnit DIBuilder::createCompileUn
                       TempEnumTypes, TempRetainTypes, TempSubprograms, TempGVs,
                       TempImportedModules};
 
+  // TODO: Switch to getDistinct().  We never want to merge compile units based
+  // on contents.
   MDNode *CUNode = MDNode::get(VMContext, Elts);
 
   // Create a named metadata so that it is easier to find cu in a module.





More information about the llvm-commits mailing list