[clang] [compiler-rt] [llvm] [InstrFDO][TypeProf] Implement binary instrumentation and profile read/write (PR #66825)

Mingming Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 26 10:39:02 PDT 2024


================
@@ -560,6 +602,28 @@ Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
   return Error::success();
 }
 
+uint64_t InstrProfSymtab::getVTableHashFromAddress(uint64_t Address) {
+  finalizeSymtab();
----------------
minglotus-6 wrote:

Added a comment.

Thinking about it, there might be a way to call 'finalize' once to make the code simpler (illustrated below). If the overall idea looks good, I could work on a separate change to refactor existing code.

'Symtab' implementation is something like this

```
Status Symtab::addElement() {
   if (finalized)
     return error("symtab cannot have new element after being finalized");
  // add element implementation
}

void Symtab::finalize() {
  llvm::sort(vectors);
  finalized=true;
}
```

And user code is like

```
auto symtab = createSymtab();

for (auto element : elements) {
  symtab.addElement(element);
}

symtab.finalize();

auto result = symtab.getFuncHashFromAddress(addr);
...
```




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


More information about the cfe-commits mailing list