[llvm] [gSYM] Add support merged functions in gSYM format (PR #101604)

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 3 00:13:24 PDT 2024


================
@@ -189,6 +189,44 @@ llvm::Error GsymCreator::encode(FileWriter &O) const {
   return ErrorSuccess();
 }
 
+void GsymCreator::prepareMergedFunctions(OutputAggregator &Out) {
+  // Nothing to do if we have less than 2 functions.
+  if (Funcs.size() < 2)
+    return;
+
+  // Sort the function infos by address range first
+  llvm::sort(Funcs);
+  std::vector<FunctionInfo> TopLevelFuncs;
+
+  // Add the first function info to the top level functions
+  TopLevelFuncs.emplace_back(std::move(Funcs.front()));
+
+  // Now if the next function info has the same address range as the top level,
+  // then merge it into the top level function, otherwise add it to the top
+  // level.
+  for (size_t Idx = 1; Idx < Funcs.size(); ++Idx) {
+    FunctionInfo &TopFunc = TopLevelFuncs.back();
+    FunctionInfo &MatchFunc = Funcs[Idx];
+    if (TopFunc.Range == MatchFunc.Range) {
+      // Both have the same range - add the 2nd func as a child of the 1st func
+      if (!TopFunc.MergedFunctions)
+        TopFunc.MergedFunctions = MergedFunctionsInfo();
+      TopFunc.MergedFunctions->MergedFunctions.emplace_back(
+          std::move(MatchFunc));
----------------
clayborg wrote:

We need to add code that removes duplicates from the merged function infos. Previously we would only keep one, but now we are keeping them all. There is already an operator== for FunctionInfos:

```
inline bool operator==(const FunctionInfo &LHS, const FunctionInfo &RHS);
```
This should be modified to include comparing the merged function info member. Check all other `FunctionInfo::operator` methods and add support for the MergedFunctionInfos. 

We have these sorted so equal items should be right next to each other. So before inserting, just check if one is equal to the previous merged function info and don't add it if is equal.


https://github.com/llvm/llvm-project/pull/101604


More information about the llvm-commits mailing list