Skip to content

[ctx_prof] Make the profile output analyzable by llvm-bcanalyzer #99563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

mtrofin
Copy link
Member

@mtrofin mtrofin commented Jul 18, 2024

This requires output-ing a "Magic" 4-byte header. We also emit a block info block, to describe our blocks and records. The output of llvm-bcanalyzer would look like:

<BLOCKINFO_BLOCK/>
<Metadata NumWords=17 BlockCodeSize=2>
  <Version op0=1/>
  <Context NumWords=13 BlockCodeSize=2>
    <GUID op0=2/>
    <Counters op0=1 op1=2 op2=3/>

Instead of having Unknown for block and record IDs.

Issue #89287

This requires output-ing a "Magic" 4-byte header. We also emit a
block info block, to describe our blocks and records. The output
of `llvm-bcanalyzer` would look like:

```
<BLOCKINFO_BLOCK/>
<Metadata NumWords=17 BlockCodeSize=2>
  <Version op0=1/>
  <Context NumWords=13 BlockCodeSize=2>
    <GUID op0=2/>
    <Counters op0=1 op1=2 op2=3/>
```

Instead of having `Unknown` for block and record IDs.
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Jul 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 18, 2024

@llvm/pr-subscribers-pgo

Author: Mircea Trofin (mtrofin)

Changes

This requires output-ing a "Magic" 4-byte header. We also emit a block info block, to describe our blocks and records. The output of llvm-bcanalyzer would look like:

&lt;BLOCKINFO_BLOCK/&gt;
&lt;Metadata NumWords=17 BlockCodeSize=2&gt;
  &lt;Version op0=1/&gt;
  &lt;Context NumWords=13 BlockCodeSize=2&gt;
    &lt;GUID op0=2/&gt;
    &lt;Counters op0=1 op1=2 op2=3/&gt;

Instead of having Unknown for block and record IDs.


Full diff: https://github.com/llvm/llvm-project/pull/99563.diff

5 Files Affected:

  • (modified) llvm/include/llvm/ProfileData/PGOCtxProfReader.h (+5-2)
  • (modified) llvm/include/llvm/ProfileData/PGOCtxProfWriter.h (+3-9)
  • (modified) llvm/lib/ProfileData/PGOCtxProfReader.cpp (+13)
  • (modified) llvm/lib/ProfileData/PGOCtxProfWriter.cpp (+34)
  • (modified) llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp (+24-17)
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
index a19b3f51d642d..28f05e9073a8a 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
@@ -73,7 +73,8 @@ class PGOContextualProfile final {
 };
 
 class PGOCtxProfileReader final {
-  BitstreamCursor &Cursor;
+  StringRef Magic;
+  BitstreamCursor Cursor;
   Expected<BitstreamEntry> advance();
   Error readMetadata();
   Error wrongValue(const Twine &);
@@ -84,7 +85,9 @@ class PGOCtxProfileReader final {
   bool canReadContext();
 
 public:
-  PGOCtxProfileReader(BitstreamCursor &Cursor) : Cursor(Cursor) {}
+  PGOCtxProfileReader(StringRef Buffer)
+      : Magic(Buffer.substr(0, PGOCtxProfileWriter::ContainerMagic.size())),
+        Cursor(Buffer.substr(PGOCtxProfileWriter::ContainerMagic.size())) {}
 
   Expected<std::map<GlobalValue::GUID, PGOContextualProfile>> loadContexts();
 };
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
index ecee7a2cfb539..db9a0fd77f835 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfWriter.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_PROFILEDATA_PGOCTXPROFWRITER_H_
 #define LLVM_PROFILEDATA_PGOCTXPROFWRITER_H_
 
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Bitstream/BitCodeEnums.h"
 #include "llvm/Bitstream/BitstreamWriter.h"
 #include "llvm/ProfileData/CtxInstrContextNode.h"
@@ -68,15 +69,7 @@ class PGOCtxProfileWriter final {
 
 public:
   PGOCtxProfileWriter(raw_ostream &Out,
-                      std::optional<unsigned> VersionOverride = std::nullopt)
-      : Writer(Out, 0) {
-    Writer.EnterSubblock(PGOCtxProfileBlockIDs::ProfileMetadataBlockID,
-                         CodeLen);
-    const auto Version = VersionOverride ? *VersionOverride : CurrentVersion;
-    Writer.EmitRecord(PGOCtxProfileRecords::Version,
-                      SmallVector<unsigned, 1>({Version}));
-  }
-
+                      std::optional<unsigned> VersionOverride = std::nullopt);
   ~PGOCtxProfileWriter() { Writer.ExitBlock(); }
 
   void write(const ctx_profile::ContextNode &);
@@ -85,6 +78,7 @@ class PGOCtxProfileWriter final {
   static constexpr unsigned CodeLen = 2;
   static constexpr uint32_t CurrentVersion = 1;
   static constexpr unsigned VBREncodingBits = 6;
+  static constexpr StringRef ContainerMagic = "CTXP";
 };
 
 } // namespace llvm
diff --git a/llvm/lib/ProfileData/PGOCtxProfReader.cpp b/llvm/lib/ProfileData/PGOCtxProfReader.cpp
index 1b42d8c765f2d..6b932b3ea02b4 100644
--- a/llvm/lib/ProfileData/PGOCtxProfReader.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfReader.cpp
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ProfileData/PGOCtxProfReader.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Bitstream/BitCodeEnums.h"
 #include "llvm/Bitstream/BitstreamReader.h"
 #include "llvm/ProfileData/InstrProf.h"
@@ -139,6 +140,18 @@ PGOCtxProfileReader::readContext(bool ExpectIndex) {
 }
 
 Error PGOCtxProfileReader::readMetadata() {
+  if (Magic.size() < PGOCtxProfileWriter::ContainerMagic.size() ||
+      Magic != PGOCtxProfileWriter::ContainerMagic)
+    return make_error<InstrProfError>(instrprof_error::invalid_prof,
+                                      "Invalid magic");
+
+  BitstreamEntry Entry;
+  RET_ON_ERR(Cursor.advance().moveInto(Entry));
+  if (Entry.Kind != BitstreamEntry::SubBlock ||
+      Entry.ID != bitc::BLOCKINFO_BLOCK_ID)
+    return unsupported("Expected Block ID");
+  RET_ON_ERR(Cursor.SkipBlock());
+
   EXPECT_OR_RET(Blk, advance());
   if (Blk->Kind != BitstreamEntry::SubBlock)
     return unsupported("Expected Version record");
diff --git a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
index 5081797564469..74cd8763cc769 100644
--- a/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
+++ b/llvm/lib/ProfileData/PGOCtxProfWriter.cpp
@@ -16,6 +16,40 @@
 using namespace llvm;
 using namespace llvm::ctx_profile;
 
+PGOCtxProfileWriter::PGOCtxProfileWriter(
+    raw_ostream &Out, std::optional<unsigned> VersionOverride)
+    : Writer(Out, 0) {
+  static_assert(ContainerMagic.size() == 4);
+  Out.write(ContainerMagic.data(), ContainerMagic.size());
+  Writer.EnterBlockInfoBlock();
+  {
+    auto DescribeBlock = [&](unsigned ID, StringRef Name) {
+      Writer.EmitRecord(bitc::BLOCKINFO_CODE_SETBID,
+                        SmallVector<unsigned, 1>{ID});
+      Writer.EmitRecord(bitc::BLOCKINFO_CODE_BLOCKNAME,
+                        llvm::arrayRefFromStringRef(Name));
+    };
+    SmallVector<uint64_t, 16> Data;
+    auto DescribeRecord = [&](unsigned RecordID, StringRef Name) {
+      Data.clear();
+      Data.push_back(RecordID);
+      llvm::append_range(Data, Name);
+      Writer.EmitRecord(bitc::BLOCKINFO_CODE_SETRECORDNAME, Data);
+    };
+    DescribeBlock(PGOCtxProfileBlockIDs::ProfileMetadataBlockID, "Metadata");
+    DescribeRecord(PGOCtxProfileRecords::Version, "Version");
+    DescribeBlock(PGOCtxProfileBlockIDs::ContextNodeBlockID, "Context");
+    DescribeRecord(PGOCtxProfileRecords::Guid, "GUID");
+    DescribeRecord(PGOCtxProfileRecords::CalleeIndex, "CalleeIndex");
+    DescribeRecord(PGOCtxProfileRecords::Counters, "Counters");
+  }
+  Writer.ExitBlock();
+  Writer.EnterSubblock(PGOCtxProfileBlockIDs::ProfileMetadataBlockID, CodeLen);
+  const auto Version = VersionOverride ? *VersionOverride : CurrentVersion;
+  Writer.EmitRecord(PGOCtxProfileRecords::Version,
+                    SmallVector<unsigned, 1>({Version}));
+}
+
 void PGOCtxProfileWriter::writeCounters(const ContextNode &Node) {
   Writer.EmitCode(bitc::UNABBREV_RECORD);
   Writer.EmitVBR(PGOCtxProfileRecords::Counters, VBREncodingBits);
diff --git a/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp b/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp
index 6c6798ded00b5..476f293780d84 100644
--- a/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp
+++ b/llvm/unittests/ProfileData/PGOCtxProfReaderWriterTest.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Bitstream/BitstreamReader.h"
+#include "llvm/Bitcode/BitcodeAnalyzer.h"
 #include "llvm/ProfileData/CtxInstrContextNode.h"
 #include "llvm/ProfileData/PGOCtxProfReader.h"
 #include "llvm/ProfileData/PGOCtxProfWriter.h"
@@ -106,8 +106,20 @@ TEST_F(PGOCtxProfRWTest, RoundTrip) {
         MemoryBuffer::getFile(ProfileFile.path());
     ASSERT_TRUE(!!MB);
     ASSERT_NE(*MB, nullptr);
-    BitstreamCursor Cursor((*MB)->getBuffer());
-    PGOCtxProfileReader Reader(Cursor);
+
+    // Check it's analyzable by the BCAnalyzer
+    BitcodeAnalyzer BA((*MB)->getBuffer());
+    std::string AnalyzerDump;
+    raw_string_ostream OS(AnalyzerDump);
+    BCDumpOptions Opts(OS);
+
+    // As in, expect no error.
+    EXPECT_FALSE(BA.analyze(Opts));
+    EXPECT_TRUE(AnalyzerDump.find("<Metadata BlockID") != std::string::npos);
+    EXPECT_TRUE(AnalyzerDump.find("<Context BlockID") != std::string::npos);
+    EXPECT_TRUE(AnalyzerDump.find("<CalleeIndex codeid") != std::string::npos);
+
+    PGOCtxProfileReader Reader((*MB)->getBuffer());
     auto Expected = Reader.loadContexts();
     ASSERT_TRUE(!!Expected);
     auto &Ctxes = *Expected;
@@ -143,8 +155,7 @@ TEST_F(PGOCtxProfRWTest, InvalidCounters) {
     auto MB = MemoryBuffer::getFile(ProfileFile.path());
     ASSERT_TRUE(!!MB);
     ASSERT_NE(*MB, nullptr);
-    BitstreamCursor Cursor((*MB)->getBuffer());
-    PGOCtxProfileReader Reader(Cursor);
+    PGOCtxProfileReader Reader((*MB)->getBuffer());
     auto Expected = Reader.loadContexts();
     EXPECT_FALSE(Expected);
     consumeError(Expected.takeError());
@@ -152,16 +163,14 @@ TEST_F(PGOCtxProfRWTest, InvalidCounters) {
 }
 
 TEST_F(PGOCtxProfRWTest, Empty) {
-  BitstreamCursor Cursor("");
-  PGOCtxProfileReader Reader(Cursor);
+  PGOCtxProfileReader Reader("");
   auto Expected = Reader.loadContexts();
   EXPECT_FALSE(Expected);
   consumeError(Expected.takeError());
 }
 
 TEST_F(PGOCtxProfRWTest, Invalid) {
-  BitstreamCursor Cursor("Surely this is not valid");
-  PGOCtxProfileReader Reader(Cursor);
+  PGOCtxProfileReader Reader("Surely this is not valid");
   auto Expected = Reader.loadContexts();
   EXPECT_FALSE(Expected);
   consumeError(Expected.takeError());
@@ -182,8 +191,8 @@ TEST_F(PGOCtxProfRWTest, ValidButEmpty) {
     auto MB = MemoryBuffer::getFile(ProfileFile.path());
     ASSERT_TRUE(!!MB);
     ASSERT_NE(*MB, nullptr);
-    BitstreamCursor Cursor((*MB)->getBuffer());
-    PGOCtxProfileReader Reader(Cursor);
+
+    PGOCtxProfileReader Reader((*MB)->getBuffer());
     auto Expected = Reader.loadContexts();
     EXPECT_TRUE(!!Expected);
     EXPECT_TRUE(Expected->empty());
@@ -204,8 +213,8 @@ TEST_F(PGOCtxProfRWTest, WrongVersion) {
     auto MB = MemoryBuffer::getFile(ProfileFile.path());
     ASSERT_TRUE(!!MB);
     ASSERT_NE(*MB, nullptr);
-    BitstreamCursor Cursor((*MB)->getBuffer());
-    PGOCtxProfileReader Reader(Cursor);
+
+    PGOCtxProfileReader Reader((*MB)->getBuffer());
     auto Expected = Reader.loadContexts();
     EXPECT_FALSE(Expected);
     consumeError(Expected.takeError());
@@ -228,8 +237,7 @@ TEST_F(PGOCtxProfRWTest, DuplicateRoots) {
     auto MB = MemoryBuffer::getFile(ProfileFile.path());
     ASSERT_TRUE(!!MB);
     ASSERT_NE(*MB, nullptr);
-    BitstreamCursor Cursor((*MB)->getBuffer());
-    PGOCtxProfileReader Reader(Cursor);
+    PGOCtxProfileReader Reader((*MB)->getBuffer());
     auto Expected = Reader.loadContexts();
     EXPECT_FALSE(Expected);
     consumeError(Expected.takeError());
@@ -255,8 +263,7 @@ TEST_F(PGOCtxProfRWTest, DuplicateTargets) {
     auto MB = MemoryBuffer::getFile(ProfileFile.path());
     ASSERT_TRUE(!!MB);
     ASSERT_NE(*MB, nullptr);
-    BitstreamCursor Cursor((*MB)->getBuffer());
-    PGOCtxProfileReader Reader(Cursor);
+    PGOCtxProfileReader Reader((*MB)->getBuffer());
     auto Expected = Reader.loadContexts();
     EXPECT_FALSE(Expected);
     consumeError(Expected.takeError());

Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with one suggestion below

if (Entry.Kind != BitstreamEntry::SubBlock ||
Entry.ID != bitc::BLOCKINFO_BLOCK_ID)
return unsupported("Expected Block ID");
RET_ON_ERR(Cursor.SkipBlock());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about why calling SkipBlock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mtrofin mtrofin merged commit cc7308a into llvm:main Jul 23, 2024
3 of 5 checks passed
@mtrofin mtrofin deleted the metadata branch July 23, 2024 12:59
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 23, 2024

LLVM Buildbot has detected a new failure on builder llvm-nvptx-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/2157

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
...
0.874 [2/9/644] Linking CXX executable unittests/ExecutionEngine/Orc/OrcJITTests
0.887 [2/8/645] Linking CXX executable unittests/tools/llvm-exegesis/LLVMExegesisTests
0.945 [2/7/646] Linking CXX executable unittests/CodeGen/CodeGenTests
0.959 [2/6/647] Linking CXX executable unittests/Frontend/LLVMFrontendTests
1.045 [2/5/648] Linking CXX executable unittests/Analysis/AnalysisTests
1.093 [2/4/649] Linking CXX executable unittests/IR/IRTests
1.201 [2/3/650] Linking CXX executable unittests/Support/SupportTests
1.212 [2/2/651] Linking CXX executable unittests/ADT/ADTTests
6.009 [2/1/652] Building CXX object unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o
6.174 [1/1/653] Linking CXX executable unittests/ProfileData/ProfileDataTests
FAILED: unittests/ProfileData/ProfileDataTests 
: && /usr/bin/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -fuse-ld=gold     -Wl,--gc-sections unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/BPFunctionNodeTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/CoverageMappingTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/InstrProfDataTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/InstrProfTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/ItaniumManglingCanonicalizerTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/MemProfTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/SampleProfTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/SymbolRemappingReaderTest.cpp.o -o unittests/ProfileData/ProfileDataTests  -Wl,-rpath,/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/lib  lib/libLLVMCoverage.so.20.0git  lib/libLLVMProfileData.so.20.0git  lib/libllvm_gtest_main.so.20.0git  lib/libLLVMTestingSupport.so.20.0git  lib/libLLVMObject.so.20.0git  lib/libLLVMCore.so.20.0git  lib/libllvm_gtest.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/lib && :
unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o:PGOCtxProfReaderWriterTest.cpp:function PGOCtxProfRWTest_RoundTrip_Test::TestBody() [clone .localalias]: error: undefined reference to 'llvm::BitcodeAnalyzer::BitcodeAnalyzer(llvm::StringRef, std::optional<llvm::StringRef>)'
unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o:PGOCtxProfReaderWriterTest.cpp:function PGOCtxProfRWTest_RoundTrip_Test::TestBody() [clone .localalias]: error: undefined reference to 'llvm::BitcodeAnalyzer::analyze(std::optional<llvm::BCDumpOptions>, std::optional<llvm::StringRef>)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 23, 2024

LLVM Buildbot has detected a new failure on builder llvm-nvptx64-nvidia-ubuntu running on as-builder-7 while building llvm at step 6 "test-build-unified-tree-check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/2158

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-llvm) failure: test (failure)
...
1.040 [3/8/644] Linking CXX executable unittests/tools/llvm-exegesis/LLVMExegesisTests
1.068 [3/7/645] Linking CXX executable unittests/Analysis/AnalysisTests
1.088 [3/6/646] Linking CXX executable unittests/CodeGen/CodeGenTests
1.165 [3/5/647] Linking CXX executable unittests/IR/IRTests
1.270 [3/4/648] Linking CXX executable unittests/Support/SupportTests
1.295 [3/3/649] Linking CXX executable unittests/ADT/ADTTests
1.347 [3/2/650] Building CXX object unittests/TableGen/CMakeFiles/TableGenTests.dir/AutomataTest.cpp.o
1.431 [2/2/651] Linking CXX executable unittests/TableGen/TableGenTests
6.114 [2/1/652] Building CXX object unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o
6.280 [1/1/653] Linking CXX executable unittests/ProfileData/ProfileDataTests
FAILED: unittests/ProfileData/ProfileDataTests 
: && /usr/bin/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -fuse-ld=gold     -Wl,--gc-sections unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/BPFunctionNodeTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/CoverageMappingTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/InstrProfDataTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/InstrProfTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/ItaniumManglingCanonicalizerTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/MemProfTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/SampleProfTest.cpp.o unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/SymbolRemappingReaderTest.cpp.o -o unittests/ProfileData/ProfileDataTests  -Wl,-rpath,/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/lib  lib/libLLVMCoverage.so.20.0git  lib/libLLVMProfileData.so.20.0git  lib/libllvm_gtest_main.so.20.0git  lib/libLLVMTestingSupport.so.20.0git  lib/libLLVMObject.so.20.0git  lib/libLLVMCore.so.20.0git  lib/libllvm_gtest.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx64-nvidia-ubuntu/build/lib && :
unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o:PGOCtxProfReaderWriterTest.cpp:function PGOCtxProfRWTest_RoundTrip_Test::TestBody() [clone .localalias]: error: undefined reference to 'llvm::BitcodeAnalyzer::BitcodeAnalyzer(llvm::StringRef, std::optional<llvm::StringRef>)'
unittests/ProfileData/CMakeFiles/ProfileDataTests.dir/PGOCtxProfReaderWriterTest.cpp.o:PGOCtxProfReaderWriterTest.cpp:function PGOCtxProfRWTest_RoundTrip_Test::TestBody() [clone .localalias]: error: undefined reference to 'llvm::BitcodeAnalyzer::analyze(std::optional<llvm::BCDumpOptions>, std::optional<llvm::StringRef>)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
)

Summary:
This requires output-ing a "Magic" 4-byte header. We also emit a block info block, to describe our blocks and records. The output of `llvm-bcanalyzer` would look like:

```
<BLOCKINFO_BLOCK/>
<Metadata NumWords=17 BlockCodeSize=2>
  <Version op0=1/>
  <Context NumWords=13 BlockCodeSize=2>
    <GUID op0=2/>
    <Counters op0=1 op1=2 op2=3/>
```

Instead of having `Unknown` for block and record IDs.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251052
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Sep 6, 2024
…m#99563)

This requires output-ing a "Magic" 4-byte header. We also emit a block info block, to describe our blocks and records. The output of `llvm-bcanalyzer` would look like:

```
<BLOCKINFO_BLOCK/>
<Metadata NumWords=17 BlockCodeSize=2>
  <Version op0=1/>
  <Context NumWords=13 BlockCodeSize=2>
    <GUID op0=2/>
    <Counters op0=1 op1=2 op2=3/>
```

Instead of having `Unknown` for block and record IDs.

Change-Id: I5e76f07704c1716ae4d992c779a05a286fbe601b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants