[llvm] [SHT_LLVM_FUNC_MAP][ObjectYaml]Introduce function address map section and emit dynamic instruction count(ObjectYaml part) (PR #124332)

Lei Wang via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 22:07:08 PST 2025


================
@@ -535,6 +535,27 @@ Example of BBAddrMap with PGO data:
    .uleb128  1000                         # BB_3 basic block frequency (only when enabled)
    .uleb128  0                            # BB_3 successors count (only enabled with branch probabilities)
 
+``SHT_LLVM_FUNC_MAP`` Section (function address map)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+This section stores the mapping from the binary address of function to its
+related metadata features. It is used to emit function-level analysis data and
+can be enabled through ``--func-map`` option. The fields are encoded in the
+following format:
+
+#. A version number byte used for backward compatibility.
----------------
wlei-llvm wrote:

I also have questions about the "merging"(would appreciate any guidance!). Right now, the `AsmPrinter` works like this https://github.com/llvm/llvm-project/pull/124334/files#diff-17b326b45ef392288420bed274616afa7df81b27576c96723b3c25f5198dc398R1567-R1589  (mostly learned from `BB_ADDR_MAP`)
IIUC, It's nested into the .text section.

```
# FOREACH function in Module do:
   ...
   OutStreamer->pushSection();
   OutStreamer->switchSection(FuncMapSection);
   # emit version number
   # emit entries..
   OutStreamer->popSection();
   ...
# FOREACH end
...
```
Now to do the merging, I assume we have to hoist the `version` emission and compute the entries size on Module level, like:
```
# emit version number.    (how to do this?)
# compute and emit entries size

# FOREACH function in Module do:
  ...
  OutStreamer->pushSection();
  OutStreamer->switchSection(FuncMapSection);
  # emit entries..
  OutStreamer->popSection();
  ...
# FOREACH end
...
```
Then here, how to emit the version number into the "Header" section, any code pointer for reference? Also how does the COMDAT deduplication work here, say if a function is eliminated, then do we need to adjust the entry size accordingly?



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


More information about the llvm-commits mailing list