[flang-commits] [lldb] [mlir] [llvm] [clang] [compiler-rt] [flang] [clang-tools-extra] [Profile] Add binary profile correlation to offload profile metadata at runtime. (PR #69493)
Zequan Wu via flang-commits
flang-commits at lists.llvm.org
Wed Nov 15 14:38:51 PST 2023
================
@@ -46,14 +73,38 @@ const char *InstrProfCorrelator::NumCountersAttributeName = "Num Counters";
llvm::Expected<std::unique_ptr<InstrProfCorrelator::Context>>
InstrProfCorrelator::Context::get(std::unique_ptr<MemoryBuffer> Buffer,
- const object::ObjectFile &Obj) {
+ const object::ObjectFile &Obj,
+ ProfCorrelatorKind FileKind) {
+ auto C = std::make_unique<Context>();
auto CountersSection = getInstrProfSection(Obj, IPSK_cnts);
if (auto Err = CountersSection.takeError())
return std::move(Err);
- auto C = std::make_unique<Context>();
+ if (FileKind == InstrProfCorrelator::BINARY) {
+ auto DataSection = getInstrProfSection(Obj, IPSK_data);
+ if (auto Err = DataSection.takeError())
+ return std::move(Err);
+ auto DataOrErr = DataSection->getContents();
+ if (!DataOrErr)
+ return DataOrErr.takeError();
+ auto NameSection = getInstrProfSection(Obj, IPSK_name);
+ if (auto Err = NameSection.takeError())
+ return std::move(Err);
+ auto NameOrErr = NameSection->getContents();
+ if (!NameOrErr)
+ return NameOrErr.takeError();
+ C->DataStart = DataOrErr->data();
+ C->DataEnd = DataOrErr->data() + DataOrErr->size();
+ C->NameStart = NameOrErr->data();
+ C->NameSize = NameOrErr->size();
+ }
C->Buffer = std::move(Buffer);
C->CountersSectionStart = CountersSection->getAddress();
C->CountersSectionEnd = C->CountersSectionStart + CountersSection->getSize();
+ // In COFF object file, there's a null byte at the beginning of the counter
+ // section which doesn't exist in raw profile.
+ if (Obj.getTripleObjectFormat() == Triple::COFF)
+ C->CountersSectionStart++;
----------------
ZequanWu wrote:
Done.
https://github.com/llvm/llvm-project/pull/69493
More information about the flang-commits
mailing list