VLAs may refer to a previous DIE to express the DW_AT_count of their type. Clang generates an artificial "vla_expr" variable for this. If this DIE hasn't been created yet LLVM asserts. This patch fixes this by sorting the local variables so that dependencies come before they are needed. It also replaces the linear scan in DWARFFile with a std::map, which can be faster.
Details
Diff Detail
Event Timeline
lib/CodeGen/AsmPrinter/DwarfFile.h | ||
---|---|---|
52 | Do you really need std::map<> here? Can't you use an LLVM container? |
lib/CodeGen/AsmPrinter/DwarfFile.h | ||
---|---|---|
52 | Is there a better container for this? I need something that allows me to
DenseMap doesn't support (2), so the only other alternative I could come up with was a SmallVector or a std::list that is kept sorted after each insert by using std::lower_bound to look up the insertion point. Using a std::list instead the SmallVector would be more memory efficient than the std::map. Using a SmallVector would use least memory, but has quadratic worst-case behavior. Any preferences/suggestions? |
Some comments inline, but this is almost good to go IMHO.
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | ||
---|---|---|
573–583 | I think the logic here is correct, but I don't necessarily like all this level of nesting. DICompositeType *Array = dyn_cast<>(); if (!Array) return false [...] | |
586 | that variables that variables :) | |
lib/CodeGen/AsmPrinter/DwarfFile.h | ||
52 | I think a map is fine, but I'd add a comment here explaining the rationale, if you don't mind. |
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | ||
---|---|---|
590 ↗ | (On Diff #133082) | std::stable_sort requires comparison function object to satisfy Compare concept. It is mentioned that comp(a, b) establishes strict weak ordering relation. One of the requirements of this ordering is transitivity of incomparability, i.e. if x <> y and y <> z then it should be x <> z. But with dependency relation it is possible that x and y are independent, y and z are independent, but x depends on z. During my testing I had DbgVariable in the following order array count vla_expr and the sorting proceeded as is [1] < [0] => false, no swapping is [2] < [1] => false, no swapping finish sort We didn't even check that array depends on vla_expr. Looks like for dependency relation something like stable topological sorting is more appropriate. |
Terrific, looks much better now :)