[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used … (PR #74128)

2023-12-01 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee created 
https://github.com/llvm/llvm-project/pull/74128

…together by decoupling the handling of the two features.

Today `-split-machine-functions` (MFS) and `-fbasic-block-sections={all,list}` 
cannot be combined with `-basic-block-sections=labels` (the labels option will 
be ignored). The inconsistency comes from the way basic block address map -- 
the underlying mechanism for basic block labels -- encodes basic block 
addresses (https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html).  
Specifically, basic block offsets are computed relative to the function begin 
symbol. This relies on functions being contiguous which is not the case for MFS 
and basic block section binaries. This means Propeller cannot use binary 
profiles collected from these binaries, which limits the applicability of 
Propeller for iterative optimization.

To make the BB address map feature work with BB section binaries, we propose 
modifying the encoding of the BB address map as follows.

The current encoding emits the address of each function and its number of basic 
blocks, followed by basic block entries for each basic block.

|  Address of the function   | //Address//  |   -> 
8 bytes (pointer size)
|  Number of basic blocks in this function |//NumBlocks// |   -> ULEB128
|  BB entry #1
|  BB entry #2
|   ...
|  BB entry #//NumBlocks//

To make this work for basic block sections, we treat each basic block section 
similar to a function, except that basic block sections of the same function 
must be encapsulated in the same structure so we can map all of them to their 
single function.

We modify the encoding to first emit the number of basic block sections (BB 
ranges) in the function. Then we emit the address map of each basic block 
section section as before: the base address of the section, its number of 
blocks, and BB entries for its basic block. The first section in the BB address 
map is always the function entry section.

|  Number of sections for this function   | //NumBBRanges//) | -> ULEB128

| Section //0// begin address |//BaseAddress[0]//  |   -> 8 
bytes (pointer size)
| Number of basic blocks in section //0// |//NumBlocks[0]//|   -> ULEB128
| BB entries for Section //0//
.
.
.
| Section //K// begin address  |//BaseAddress[K]// |   -> 8 
bytes (pointer size)
| Number of basic blocks in section //K//  |//NumBlocks[K]//   |   -> ULEB128
| BB entries for Section //K//

The encoding of basic block entries remains as before with the minor change 
that each basic block offset is now computed relative to the begin symbol of 
its containing BB section.

This patch adds a new boolean codegen option `-basic-block-address-map`. 
Correspondingly, the front-end flag `-fbasic-block-address-map` and LLD flag 
`--lto-basic-block-address-map` are introduced. Analogously, we add a new 
TargetOption field `BBAddrMap`. This means BB address maps are either generated 
for all functions in the compiling unit, or for none (depending on 
`TargetOptions::BBAddrMap`).

This patch disables the old `-fbasic-block-sections=labels` value option but 
does not remove it. A subsequent patch will remove the obsolete option.

We refactor the `BasicBlockSections` pass by separating the BB address map and 
BB sections handing to their own functions (named `handleBBAddrMap` and 
`handleBBSections`).  `handleBBSections` renumbers basic blocks and places them 
in their assigned sections. `handleBBAddrMap` is invoked after 
`handleBBSections` (if requested) and only renumbers the blocks.

- New tests added: # A codgen test `basic-block-labels-with-sections.ll` to 
exercise the combination of `-basic-block-address-map` with 
`-basic-block-sections=list`. # A driver sanity test for the 
`-fbasic-block-address-map` option. # An LLD test for testing the 
`--lto-basic-block-address-map` option. This reuses the LLVM IR from 
`lld/test/ELF/lto/basic-block-sections.ll`.
- Renamed and modified the two existing codegen tests for basic block address 
map (`basic-block-sections-labels-functions-sections.ll` and 
`basic-block-sections-labels.ll`)

Differential Revision: https://reviews.llvm.org/D97526

>From 3f82059172f7e9020ff14e41063208c6d67b7cce Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Fri, 10 Nov 2023 20:16:31 +
Subject: [PATCH] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels
 be used together by decoupling the handling of the two features.

Today `-split-machine-functions` (MFS) and `-fbasic-block-sections={all,list}` 
cannot be combined with `-basic-block-sections=labels` (the labels option will 
be ignored).
The inconsistency comes from the way basic block address map -- the underlying 
mechanism for basic block labels -- encodes basic block addresses 
(https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html).  
Specifically, basic block offsets are computed relative to the function begin 
symbol. This relies o

[llvm] [clang] [lld] [Propeller] Add new flag option '-basic-block-sections=listwithlabels=' to support to use Propeller iteratively. (PR #76497)

2024-01-02 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

Thanks for looking into this. I didn't know you're still looking into this. I 
have a complete PR (including changes to llvm-objdump, llvm-readobj, etc.) 
ready here : https://github.com/rlavaee/llvm-project/tree/bb-addr-map


https://github.com/llvm/llvm-project/pull/76497
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee ready_for_review 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [lld] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-04 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [lld] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits


@@ -858,62 +899,64 @@ struct BBAddrMap {
 bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
   };
 
-  BBAddrMap(uint64_t Addr, std::vector BBEntries)
-  : Addr(Addr), BBEntries(std::move(BBEntries)) {}
+  // Struct representing the BBAddrMap information for a contiguous range of
+  // basic blocks (a function or a basic block section).
+  struct BBRangeEntry {
+uint64_t BaseAddress;   // Base address of the range.
+std::vector BBEntries; // Basic block entries for this range.
+
+// Equality operator for unit testing.
+bool operator==(const BBRangeEntry &Other) const {
+  return BaseAddress == Other.BaseAddress &&
+ std::equal(BBEntries.begin(), BBEntries.end(),
+Other.BBEntries.begin());
+}
+  };
 
-  // Returns the address of the corresponding function.
-  uint64_t getFunctionAddress() const { return Addr; }
+  // All ranges for this function. The first range always corresponds to the
+  // function entry.
+  std::vector BBRanges;
 
-  // Returns the basic block entries for this function.
-  const std::vector &getBBEntries() const { return BBEntries; }
+  // Returns the function address associated with this BBAddrMap, which is
+  // stored as the `BaseAddress` of its first BBRangeEntry. Returns 0 if
+  // BBRanges is empty.
+  uint64_t getFunctionAddress() const {

rlavaee wrote:

I now enforce (when decoding) that BB ranges must be non-empty. Thanks for the 
suggestion.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [lld] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits


@@ -858,62 +899,64 @@ struct BBAddrMap {
 bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
   };
 
-  BBAddrMap(uint64_t Addr, std::vector BBEntries)
-  : Addr(Addr), BBEntries(std::move(BBEntries)) {}
+  // Struct representing the BBAddrMap information for a contiguous range of
+  // basic blocks (a function or a basic block section).
+  struct BBRangeEntry {
+uint64_t BaseAddress;   // Base address of the range.

rlavaee wrote:

Done.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits


@@ -172,6 +172,105 @@ class OtoolOptTable : public CommonOptTable {
"Mach-O object file displaying tool") {}
 };
 
+struct BBAddrMapLabel {
+  std::string BlockLabel;
+  std::string PGOAnalysis;
+};
+
+// This class represents the BBAddrMap and PGOMap associated with a single
+// function.
+class BBAddrMapFunctionEntry {
+public:
+  BBAddrMapFunctionEntry(BBAddrMap AddrMap, PGOAnalysisMap PGOMap)
+  : AddrMap(std::move(AddrMap)), PGOMap(std::move(PGOMap)) {}
+
+  const BBAddrMap &getAddrMap() const { return AddrMap; }
+
+  // Returns the PGO string associated with the entry of index 
`PGOBBEntryIndex`
+  // in `PGOMap`.
+  std::string constructPGOLabelString(size_t PGOBBEntryIndex) const {
+if (!PGOMap.FeatEnable.hasPGOAnalysis())
+  return "";
+std::string PGOString;
+raw_string_ostream PGOSS(PGOString);
+
+PGOSS << " (";
+if (PGOMap.FeatEnable.FuncEntryCount && PGOBBEntryIndex == 0) {
+  PGOSS << "Entry count: " << Twine(PGOMap.FuncEntryCount);
+  if (PGOMap.FeatEnable.hasPGOAnalysisBBData()) {
+PGOSS << ", ";
+  }
+}
+
+if (PGOMap.FeatEnable.hasPGOAnalysisBBData()) {
+
+  assert(PGOBBEntryIndex < PGOMap.BBEntries.size() &&
+ "Expected PGOAnalysisMap and BBAddrMap to have the same entires");
+  const PGOAnalysisMap::PGOBBEntry &PGOBBEntry =
+  PGOMap.BBEntries[PGOBBEntryIndex];
+
+  if (PGOMap.FeatEnable.BBFreq) {
+PGOSS << "Frequency: " << Twine(PGOBBEntry.BlockFreq.getFrequency());
+if (PGOMap.FeatEnable.BrProb && PGOBBEntry.Successors.size() > 0) {
+  PGOSS << ", ";
+}
+  }
+  if (PGOMap.FeatEnable.BrProb && PGOBBEntry.Successors.size() > 0) {
+PGOSS << "Successors: ";
+interleaveComma(
+PGOBBEntry.Successors, PGOSS,
+[&PGOSS](const PGOAnalysisMap::PGOBBEntry::SuccessorEntry &SE) {
+  PGOSS << "BB" << SE.ID << ":";
+  PGOSS.write_hex(SE.Prob.getNumerator());
+});
+  }
+}
+PGOSS << ")";
+
+return PGOString;
+  }
+
+private:
+  const BBAddrMap AddrMap;
+  const PGOAnalysisMap PGOMap;
+};
+
+// This class represents the BBAddrMap and PGOMap of potentially multiple
+// functions in a section.
+class BBAddrMapInfo {
+public:
+  void clear() {
+FunctionAddrToMap.clear();
+RangeBaseAddrToFunctionAddr.clear();
+  }
+  bool empty() const { return FunctionAddrToMap.empty(); }
+
+  void AddFunctionEntry(BBAddrMap AddrMap, PGOAnalysisMap PGOMap) {
+uint64_t FunctionAddr = AddrMap.getFunctionAddress();
+for (size_t I = 1; I < AddrMap.BBRanges.size(); ++I)
+  RangeBaseAddrToFunctionAddr.emplace(AddrMap.BBRanges[I].BaseAddress,
+  FunctionAddr);
+[[maybe_unused]] auto R = FunctionAddrToMap.try_emplace(
+FunctionAddr, std::move(AddrMap), std::move(PGOMap));
+assert(R.second && "duplicate function address");
+  }
+
+  const BBAddrMapFunctionEntry *getEntryForAddress(uint64_t BaseAddress) const 
{

rlavaee wrote:

More about simplicity. Added function comment on when it will return null.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits


@@ -73,68 +83,89 @@ FileHeader:
 Sections:
   - Name:.text.foo
 Type:SHT_PROGBITS
-Address: [[FOO_ADDR]]
+Address: 0x4000
 Flags:   [SHF_ALLOC, SHF_EXECINSTR]
-Content: '503b050520907d02ebf5c3'
+Content: '503b050530907d08ebf50f8dee1fc3'
   - Name:.text.bar
 Type:SHT_PROGBITS
-Address: [[BAR_ADDR]]
+Address: 0x5000
 Flags:   [SHF_ALLOC, SHF_EXECINSTR]
 Content: '5089d0740231f6e8f4ffc3'
+  - Name:.text.split
+Type:SHT_PROGBITS
+Address: 0x6000
+Flags:   [SHF_ALLOC, SHF_EXECINSTR]
+Content: 'c3'
   - Name:.data
 Type:SHT_PROGBITS
 Flags:   [SHF_ALLOC, SHF_WRITE]
-Address: 0x6000
+Address: 0x7000
   - Name:   .llvm_bb_addr_map.foo
 Type:   SHT_LLVM_BB_ADDR_MAP
 Link:   .text.foo
 Entries:
   - Version: 2
-Address: [[FOO_ADDR]]
-BBEntries:
-  - ID:3
-AddressOffset: 0x0
-Size:  0x1
-Metadata:  0x1
-  - ID:1
-AddressOffset: 0x0
-Size:  0x6
-Metadata:  0x0
-  - ID:2
-AddressOffset: 0x1
-Size:  0x4
-Metadata:  0x0
-  - ID:5
-AddressOffset: 0x0
-Size:  0x1
-Metadata:  0x2
+Feature: 0x8
+BBRanges:
+  - BaseAddress: 0x4000
+BBEntries:
+ - ID:3
+   AddressOffset: 0x0

rlavaee wrote:

Starting from version 2, `AddressOffset` in yaml is relative to the end of the 
previous block. This reduces the size of the section since we are using ULEB128 
to encode them. When decoded Address is properly computed.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

> Just nits/minor questions from me, code otherwise LGTM.
> 
> Sorry for the delay in review. I didn't realize you explicitly wanted me to 
> review portions of the code.

Thank you for reviewing. The change in llvm-objdump happened after your PR 
handling PGOAnalysis. So I wanted to make sure it gets on your radar.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [lld] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

Thank everyone for reviewing. I will probably merge this today. I want to save 
myself and others the trouble of merge conflicts over 38 files.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-02-01 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee closed 
https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-25 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

@boomanaiden154 I appreciate if you could PTAL at llvm-objdump changes.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [clang] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-25 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

@tmsri I appreciate if you could please review the codegen and options part.

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [lld] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-25 Thread Rahman Lavaee via cfe-commits


@@ -858,62 +899,64 @@ struct BBAddrMap {
 bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
   };
 
-  BBAddrMap(uint64_t Addr, std::vector BBEntries)
-  : Addr(Addr), BBEntries(std::move(BBEntries)) {}
+  // Struct representing the BBAddrMap information for a contiguous range of
+  // basic blocks (a function or a basic block section).
+  struct BBRangeEntry {
+uint64_t BaseAddress;   // Base address of the range.
+std::vector BBEntries; // Basic block entries for this range.
+
+// Equality operator for unit testing.
+bool operator==(const BBRangeEntry &Other) const {
+  return BaseAddress == Other.BaseAddress &&
+ std::equal(BBEntries.begin(), BBEntries.end(),
+Other.BBEntries.begin());
+}
+  };
 
-  // Returns the address of the corresponding function.
-  uint64_t getFunctionAddress() const { return Addr; }
+  // All ranges for this function. The first range always corresponds to the
+  // function entry.
+  std::vector BBRanges;
 
-  // Returns the basic block entries for this function.
-  const std::vector &getBBEntries() const { return BBEntries; }
+  // Returns the function address associated with this BBAddrMap, which is
+  // stored as the `BaseAddress` of its first BBRangeEntry. Returns 0 if
+  // BBRanges is empty.
+  uint64_t getFunctionAddress() const {

rlavaee wrote:

Changing the return type would change the API. So we would need to sequence 
this. How about an assertion? BBRanges should not be empty (except for tests).

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [SHT_LLVM_BB_ADDR_MAP] Allow basic-block-sections and labels be used together by decoupling the handling of the two features. (PR #74128)

2024-01-19 Thread Rahman Lavaee via cfe-commits


@@ -1401,17 +1406,48 @@ void AsmPrinter::emitBBAddrMapSection(const 
MachineFunction &MF) {
   uint8_t BBAddrMapVersion = OutStreamer->getContext().getBBAddrMapVersion();
   OutStreamer->emitInt8(BBAddrMapVersion);
   OutStreamer->AddComment("feature");
-  auto FeaturesBits = static_cast(PgoAnalysisMapFeatures.getBits());
-  OutStreamer->emitInt8(FeaturesBits);
-  OutStreamer->AddComment("function address");
-  OutStreamer->emitSymbolValue(FunctionSymbol, getPointerSize());
-  OutStreamer->AddComment("number of basic blocks");
-  OutStreamer->emitULEB128IntValue(MF.size());
-  const MCSymbol *PrevMBBEndSymbol = FunctionSymbol;
+  auto Features = getBBAddrMapFeature(MF, MBBSectionRanges.size());
+  OutStreamer->emitInt8(Features.encode());
   // Emit BB Information for each basic block in the function.
+  if (Features.MultiBBRange) {
+OutStreamer->AddComment("number of basic block ranges");
+OutStreamer->emitULEB128IntValue(MBBSectionRanges.size());
+  }
+  // Number of blocks in each MBB section.
+  MapVector MBBSectionNumBlocks;
+  const MCSymbol *PrevMBBEndSymbol = nullptr;
+  if (!Features.MultiBBRange) {
+OutStreamer->AddComment("function address");

rlavaee wrote:

A second reason is backward and forward compatibility. As written, this PR does 
not change the encoding for the normal case. So we don't need to add a new 
version (which leads to even more technical debt).

https://github.com/llvm/llvm-project/pull/74128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7841e21 - Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-14 Thread Rahman Lavaee via cfe-commits

Author: Rahman Lavaee
Date: 2020-09-14T10:16:44-07:00
New Revision: 7841e21c98495ba5e33e0d2507d985bd5b938445

URL: 
https://github.com/llvm/llvm-project/commit/7841e21c98495ba5e33e0d2507d985bd5b938445
DIFF: 
https://github.com/llvm/llvm-project/commit/7841e21c98495ba5e33e0d2507d985bd5b938445.diff

LOG: Let -basic-block-sections=labels emit basicblock metadata in a new 
.bb_addr_map section, instead of emitting special unary-encoded symbols.

This patch introduces the new .bb_addr_map section feature which allows us to 
emit the bits needed for mapping binary profiles to basic blocks into a 
separate section.
The format of the emitted data is represented as follows. It includes a header 
for every function:

|  Address of the function  |  -> 8 bytes (pointer size)
|  Number of basic blocks in this function (>0) |  -> ULEB128

The header is followed by a BB record for every basic block. These records are 
ordered in the same order as MachineBasicBlocks are placed in the function. 
Each BB Info is structured as follows:

|  Offset of the basic block relative to function begin |  -> ULEB128
|  Binary size of the basic block   |  -> ULEB128
|  BB metadata  |  -> ULEB128  [ 
MBB.isReturn() OR MBB.hasTailCall() << 1  OR  MBB.isEHPad() << 2 ]

The new feature will replace the existing "BB labels" functionality with 
-basic-block-sections=labels.
The .bb_addr_map section scrubs the specially-encoded BB symbols from the 
binary and makes it friendly to profilers and debuggers.
Furthermore, the new feature reduces the binary size overhead from 70% bloat to 
only 12%.

For more information and results please refer to the RFC: 
https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html

Reviewed By: MaskRay, snehasish

Differential Revision: https://reviews.llvm.org/D85408

Added: 
llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll

Modified: 
clang/docs/UsersManual.rst
clang/test/CodeGen/basic-block-sections.c
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/include/llvm/CodeGen/MachineFunction.h
llvm/include/llvm/MC/MCObjectFileInfo.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/BasicBlockSections.cpp
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 1a1aea2ae538..2d0d71443dfd 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1700,9 +1700,12 @@ are listed below.
 
 **-fbasic-block-sections=[labels, all, list=, none]**
 
-  Controls whether Clang emits a label for each basic block.  Further, with
-  values "all" and "list=arg", each basic block or a subset of basic blocks
-  can be placed in its own unique section.
+  Controls how Clang emits text sections for basic blocks. With values ``all``
+  and ``list=``, each basic block or a subset of basic blocks can be 
placed
+  in its own unique section. With the "labels" value, normal text sections are
+  emitted, but a ``.bb_addr_map`` section is emitted which includes address
+  offsets for each basic block in the program, relative to the parent function
+  address.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the

diff  --git a/clang/test/CodeGen/basic-block-sections.c 
b/clang/test/CodeGen/basic-block-sections.c
index 6cdea79f0fa7..dc414d70ba5f 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -1,12 +1,11 @@
 // REQUIRES: x86-registered-target
 
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -o - < %s | FileCheck %s 
--check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all 
-fbasic-block-sections=none -o - < %s | FileCheck %s --check-prefix=PLAIN
+// RUN: %clang_cc1 -triple x86_64 -S -o - < %s | FileCheck %s 
--check-prefix=PLAIN
+// RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all 
-fbasic-block-sections=none -o - < %s | FileCheck %s --check-prefix=PLAIN
 
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S 
-fbasic-block-sections=labels -o - < %s | FileCheck %s --check-prefix=BB_LABELS
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all 
-o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S 
-fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames -o - < %s 
| FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all 
-funique-basic-block-section-names -

[clang] [lld] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-05 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee created 
https://github.com/llvm/llvm-project/pull/107494

This feature is supported via the newer option `-fbasic-block-address-map`. 
Using the old option still works by delegating to the newer option, while a 
warning is printed to show deprecation.

>From 716f5da93a2f3763afe152d56aa6f600efe0d0ca Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Thu, 5 Sep 2024 19:14:11 +
Subject: [PATCH] Deprecate the `-fbasic-block-sections=labels` option.

This feature is supported via the newer option `-fbasic-block-address-map`.
Using the old option still works by delegating to the newer option, while a 
warning is generated to show deprecation.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 lld/ELF/LTO.cpp  |  6 --
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   |  9 -
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  4 
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../X86/basic-block-sections-labels-pgo-features.ll  | 10 +-
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 22 files changed, 48 insertions(+), 74 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index f27fa4ace917ea..30a7abeea0fb58 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` which includes address offsets for each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are specified
   //in the file.
-  // "none":Disable sectio

[clang] [lld] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-06 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee updated 
https://github.com/llvm/llvm-project/pull/107494

>From dd73efa8e99982c1ab015156c32bdc71f679361c Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Thu, 5 Sep 2024 19:14:11 +
Subject: [PATCH] Deprecate the `-fbasic-block-sections=labels` option.

This feature is supported via the newer option `-fbasic-block-address-map`.
Using the old option still works by delegating to the newer option, while a 
warning is generated to show deprecation.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 lld/ELF/LTO.cpp  |  6 --
 llvm/docs/CommandGuide/llvm-objdump.rst  |  2 +-
 llvm/docs/Extensions.rst |  2 +-
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 11 +--
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  4 
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../X86/basic-block-sections-labels-pgo-features.ll  | 10 +-
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 24 files changed, 51 insertions(+), 77 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index f27fa4ace917ea..30a7abeea0fb58 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` which includes address offsets for each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are specified
   //in the file.
-  // "none":Disable sections/labels for basic blocks.
+  // "none":Disable sections for

[clang] [lld] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-06 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee updated 
https://github.com/llvm/llvm-project/pull/107494

>From 1e4f893052f763908897aa9236bc0400bb03823b Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Thu, 5 Sep 2024 19:14:11 +
Subject: [PATCH] Deprecate the `-fbasic-block-sections=labels` option.

This feature is supported via the newer option `-fbasic-block-address-map`.
Using the old option still works by delegating to the newer option, while a 
warning is generated to show deprecation.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 lld/ELF/LTO.cpp  |  6 --
 llvm/docs/CommandGuide/llvm-objdump.rst  |  2 +-
 llvm/docs/Extensions.rst |  2 +-
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 11 +--
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  4 
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 ...es.ll => basic-block-address-map-pgo-features.ll} | 10 +-
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 24 files changed, 51 insertions(+), 77 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-pgo-features.ll => 
basic-block-address-map-pgo-features.ll} (88%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index f27fa4ace917ea..30a7abeea0fb58 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` which includes address offsets for each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are specified
   //   

[clang] Propeller config for clang (PR #91002)

2024-05-03 Thread Rahman Lavaee via cfe-commits


@@ -928,6 +928,186 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   )
 endif()
 
+if (CLANG_PROPELLER_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
+  set(CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang)
+  set(CLANGXX_PATH ${CLANG_PATH}++)
+  set(PROPELLER_ARTIFACTS_DIR ${CMAKE_CURRENT_BINARY_DIR}/propeller-artifacts)
+  set(PROPELLER_INSTRUMENTED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-instrumented-clang/)
+  set(PROPELLER_PROFILING_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-profile-collection-run/)
+  set(PROPELLER_OPTIMIZED_BINARY_DIR 
${PROPELLER_ARTIFACTS_DIR}/propeller-optimized-clang/)
+  set(CLANG_PROPELLER_LABELS ${PROPELLER_INSTRUMENTED_BINARY_DIR}/bin/clang)
+  set(CLANG_PROPELLER_LABELS_BINARY 
${CLANG_PROPELLER_LABELS}-${CLANG_VERSION_MAJOR})
+  set(CLANGXX_PROPELLER_LABELS ${CLANG_PROPELLER_LABELS}++)
+  set(PROPELLER_PERF_DATA 
${PROPELLER_ARTIFACTS_DIR}/profiles/propeller_perf.data)
+  set(PROPELLER_CLUSTER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/cluster.txt)
+  set(PROPELLER_SYMORDER_FILE ${PROPELLER_ARTIFACTS_DIR}/profiles/symorder.txt)
+
+  #  Check if perf is available on the system and supports LBR, otherwise
+  #  abort as Propeller cannot be applied here.
+  set(perf_args "${PROPELLER_PERF_PROFILE_COLLECTION_PREFIX}")
+  separate_arguments(perf_args UNIX_COMMAND "${perf_args}")
+  execute_process(
+ COMMAND perf ${perf_args} -- ls
+ RESULT_VARIABLE perf_status
+ OUTPUT_VARIABLE perf_stats
+ ERROR_QUIET
+  )
+  if (perf_status)
+ message(FATAL_ERROR "perf with LBR is not available on this system")
+  else()
+ message(STATUS "perf is available and supports LBR")
+  endif()
+
+  #  Check if create_llvm_prof is available, otherwise abort as Propeller
+  #  cannot be applied here.
+  execute_process(
+ COMMAND sh -c "${PATH_TO_CREATE_LLVM_PROF} --version"
+ RESULT_VARIABLE create_llvm_prof_status
+ OUTPUT_VARIABLE create_llvm_prof_out
+ ERROR_QUIET
+  )
+  if (create_llvm_prof_status)
+ message(FATAL_ERROR "create_llvm_prof is not installed/available at: 
${PATH_TO_CREATE_LLVM_PROF}. "
+ "Use -DPATH_TO_CREATE_LLVM_PROF= during cmake to 
specify its location.")
+  else()
+ message(STATUS "create_llvm_prof is available")
+  endif()
+
+  #  Build an "instrumented" Propeller binary with Propeller labels.  This adds
+  #  a metadata section to the clang binary.
+  add_custom_target(propeller-labels
+ COMMENT "Creating Propeller Labels Binary"
+ DEPENDS clang clang-propeller-labels-build
+  )
+
+  # This command converts hardware profiles to the propeller format.
+  add_custom_command(OUTPUT ${PROPELLER_CLUSTER_FILE}
+ DEPENDS ${PROPELLER_PERF_DATA}
+ COMMAND ${PATH_TO_CREATE_LLVM_PROF} --format=propeller
+ --binary=${CLANG_PROPELLER_LABELS_BINARY}
+--profile=${PROPELLER_PERF_DATA}
+ --out=${PROPELLER_CLUSTER_FILE}
+--propeller_symorder=${PROPELLER_SYMORDER_FILE}
+--propeller_call_chain_clustering
+--propeller_chain_split
+ VERBATIM
+  )
+
+  # Generate Propeller profiles by first hardware sampling a build of clang and
+  # then converting it using create_llvm_prof.
+  add_custom_target(propeller-gen-profiles
+ COMMENT "Generating Propeller Profiles"
+ DEPENDS ${PROPELLER_CLUSTER_FILE}
+  )
+
+  #  This uses the generated Propeller layout files to build the final 
optimized
+  #  clang binary.
+  add_custom_target(propeller-opt-binary
+ COMMENT "Generating Propeller Optimized Clang"
+ DEPENDS clang-propeller-optimized-build
+  )
+
+  # This project is setup to build a propeller "instrumented" labels binary.
+  set(STAMP_DIR 
${PROPELLER_ARTIFACTS_DIR}/stamps/propeller-instrumented-clang-stamps/)
+  set(build_configuration "$")
+  include(ExternalProject)
+  set(CLANG_PROPELLER_INSTRUMENT_CMAKE_CC_FLAGS "-fbasic-block-sections=labels 
${CLANG_PROPELLER_EXTRA_CMAKE_CC_FLAGS}")

rlavaee wrote:

Please replace this with `-fbasic-block-address-map`. Same for the LTO option. 
The old option is going to be deprecated soon.

https://github.com/llvm/llvm-project/pull/91002
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)

2024-09-25 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee closed 
https://github.com/llvm/llvm-project/pull/110039
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)

2024-09-25 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee updated 
https://github.com/llvm/llvm-project/pull/110039

>From 52f633c5d3597c2ece53f821ee775aebce758efb Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Wed, 25 Sep 2024 20:12:07 +
Subject: [PATCH 1/2] Reapply "Deprecate the `-fbasic-block-sections=labels`
 option. (#107494)"

This reverts commit 639a0afa9955a8613902e46e168767bc05c46cdd.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 llvm/docs/CommandGuide/llvm-objdump.rst  |  2 +-
 llvm/docs/Extensions.rst |  2 +-
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 11 +--
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  9 +
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 ...es.ll => basic-block-address-map-pgo-features.ll} | 10 +-
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 23 files changed, 48 insertions(+), 79 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-pgo-features.ll => 
basic-block-address-map-pgo-features.ll} (88%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 57d78f867bab6e..4f03388bc87bd0 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for 
each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are specified
   //in the file.
-  // "none":Disable sections/labels for basic blocks.
+  // "none":Disable sections for basic blocks.
   std::string BBS

[clang] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)

2024-09-25 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee created 
https://github.com/llvm/llvm-project/pull/110039

This reverts commit 639a0afa9955a8613902e46e168767bc05c46cdd with a minor fix 
in lld/ELF/LTO.cpp which sets Options.BBAddrMap when 
`--lto-basic-block-sections=labels` is passed.

>From 52f633c5d3597c2ece53f821ee775aebce758efb Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Wed, 25 Sep 2024 20:12:07 +
Subject: [PATCH] Reapply "Deprecate the `-fbasic-block-sections=labels`
 option. (#107494)"

This reverts commit 639a0afa9955a8613902e46e168767bc05c46cdd.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 llvm/docs/CommandGuide/llvm-objdump.rst  |  2 +-
 llvm/docs/Extensions.rst |  2 +-
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 11 +--
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  9 +
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 ...es.ll => basic-block-address-map-pgo-features.ll} | 10 +-
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 23 files changed, 48 insertions(+), 79 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-pgo-features.ll => 
basic-block-address-map-pgo-features.ll} (88%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 57d78f867bab6e..4f03388bc87bd0 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for 
each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are spec

[clang] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)

2024-09-25 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee edited 
https://github.com/llvm/llvm-project/pull/110039
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Reapply "Deprecate the `-fbasic-block-sections=labels` option." (PR #110039)

2024-09-27 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

Hi. This is expected. Please change your test to use
--basic-block-address-map instead.

On Fri, Sep 27, 2024 at 5:08 AM steelannelida ***@***.***>
wrote:

> This broke on of our tests. Here's a repro:
> https://godbolt.org/z/5xc7GfxcY
>
> I'm not sure if that's intentional or a bug.
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you modified the open/close state.Message
> ID: ***@***.***>
>


https://github.com/llvm/llvm-project/pull/110039
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-20 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee updated 
https://github.com/llvm/llvm-project/pull/107494

>From 57989794675a67b955aaf0e06fb4dbdc3ad48c9b Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Thu, 5 Sep 2024 19:14:11 +
Subject: [PATCH] Deprecate the `-fbasic-block-sections=labels` option.

This feature is supported via the newer option `-fbasic-block-address-map`.
Using the old option still works by delegating to the newer option, while a 
warning is generated to show deprecation.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 llvm/docs/CommandGuide/llvm-objdump.rst  |  2 +-
 llvm/docs/Extensions.rst |  2 +-
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 11 +--
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  4 
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 ...es.ll => basic-block-address-map-pgo-features.ll} | 10 +-
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 23 files changed, 47 insertions(+), 75 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-pgo-features.ll => 
basic-block-address-map-pgo-features.ll} (88%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 57d78f867bab6e..4f03388bc87bd0 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for 
each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are specified
   //in the file.
-  // "none":Disable sectio

[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-20 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

> Just chiming in that I happened to spot the pre-merge check failure looks 
> possibly related.

@jh7370 It's weird I can't reproduce this on my machine.

https://github.com/llvm/llvm-project/pull/107494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [CGData][ThinLTO] Global Outlining with Two-CodeGen Rounds (PR #90933)

2024-09-30 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

> > * Looking at the NFC, this seems like it has very similar issues to 
> > Propeller, which wants to redo just the codegen with a new injected profile 
> > and BB ordering. It would be good to see if we can converge to similar 
> > approaches. I asked @rlavaee to take a look and he is reading through the 
> > background on this work. @rlavaee do you think Propeller could use a 
> > similar approach to this where it saves the pre-codegen bitcode and 
> > re-loads it instead of redoing opt? This isn't necessarily an action item 
> > for this PR, but I wanted Rahman to take a look since he is more familiar 
> > with codegen.
> 
> It's interesting to know that Propeller wants to redo the codegen. I'm happy 
> to align with this work. We've already started discussing this and have 
> shared some details from our side. Here's the link for more info: 
> https://discourse.llvm.org/t/rfc-enhanced-machine-outliner-part-2-thinlto-nolto/78753/11?u=kyulee-com.

Yes. Propeller's final post-link optimization can use the optimized cached 
bitcode from the profiled binary build. This can be an improvement for 
Propeller. @amharc did some experiments to measure the gain from such 
improvements. IIUC, we must use `-codegen-data-generate` and 
`-codegen-data-use` in the profiled and post-link build, respectively, whereas 
they are done in the same build here.

https://github.com/llvm/llvm-project/pull/90933
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-25 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee updated 
https://github.com/llvm/llvm-project/pull/107494

>From 5cc499a7abfeb464ebffba6a04017ec1e5304839 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee 
Date: Thu, 5 Sep 2024 19:14:11 +
Subject: [PATCH 1/2] Deprecate the `-fbasic-block-sections=labels` option.

This feature is supported via the newer option `-fbasic-block-address-map`.
Using the old option still works by delegating to the newer option, while a 
warning is generated to show deprecation.
---
 clang/docs/UsersManual.rst   | 12 +++-
 clang/include/clang/Basic/CodeGenOptions.h   |  9 ++---
 clang/include/clang/Driver/Options.td|  4 ++--
 clang/lib/CodeGen/BackendUtil.cpp|  1 -
 clang/lib/Driver/ToolChains/Clang.cpp| 10 +++---
 clang/test/Driver/fbasic-block-sections.c|  3 ++-
 llvm/docs/CommandGuide/llvm-objdump.rst  |  2 +-
 llvm/docs/Extensions.rst |  2 +-
 llvm/include/llvm/CodeGen/MachineFunction.h  |  5 -
 llvm/include/llvm/Target/TargetOptions.h |  3 ---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp   | 11 +--
 llvm/lib/CodeGen/BasicBlockSections.cpp  |  7 ---
 llvm/lib/CodeGen/CommandFlags.cpp|  2 --
 llvm/lib/CodeGen/MIRParser/MIParser.cpp  |  4 
 llvm/lib/CodeGen/MIRParser/MIRParser.cpp |  4 +---
 llvm/lib/CodeGen/MachineFunction.cpp |  8 +++-
 ...ock.ll => basic-block-address-map-empty-block.ll} |  2 +-
 ll => basic-block-address-map-empty-function.ll} |  4 ++--
 .../X86/basic-block-address-map-function-sections.ll |  1 -
 ...rse.mir => basic-block-address-map-mir-parse.mir} |  4 ++--
 ...es.ll => basic-block-address-map-pgo-features.ll} | 10 +-
 llvm/test/CodeGen/X86/basic-block-address-map.ll |  4 +---
 .../CodeGen/X86/basic-block-sections-mir-print.ll| 10 +-
 23 files changed, 47 insertions(+), 75 deletions(-)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-block.ll => 
basic-block-address-map-empty-block.ll} (83%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-empty-function.ll => 
basic-block-address-map-empty-function.ll} (68%)
 rename llvm/test/CodeGen/X86/{basic-block-labels-mir-parse.mir => 
basic-block-address-map-mir-parse.mir} (97%)
 rename llvm/test/CodeGen/X86/{basic-block-sections-labels-pgo-features.ll => 
basic-block-address-map-pgo-features.ll} (88%)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 57d78f867bab6e..4f03388bc87bd0 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2369,14 +2369,16 @@ are listed below.
  $ cd $P/bar && clang -c -funique-internal-linkage-names name_conflict.c
  $ cd $P && clang foo/name_conflict.o && bar/name_conflict.o
 
-.. option:: -fbasic-block-sections=[labels, all, list=, none]
+.. option:: -f[no]-basic-block-address-map:
+  Emits a ``SHT_LLVM_BB_ADDR_MAP`` section which includes address offsets for 
each
+  basic block in the program, relative to the parent function address.
+
+
+.. option:: -fbasic-block-sections=[all, list=, none]
 
   Controls how Clang emits text sections for basic blocks. With values ``all``
   and ``list=``, each basic block or a subset of basic blocks can be 
placed
-  in its own unique section. With the "labels" value, normal text sections are
-  emitted, but a ``.bb_addr_map`` section is emitted which includes address
-  offsets for each basic block in the program, relative to the parent function
-  address.
+  in its own unique section.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index f2a707a8ba8d76..814d4d4c99e575 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -107,18 +107,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   // This field stores one of the allowed values for the option
   // -fbasic-block-sections=.  The allowed values with this option are:
-  // {"labels", "all", "list=", "none"}.
+  // {"all", "list=", "none"}.
   //
-  // "labels":  Only generate basic block symbols (labels) for all basic
-  //blocks, do not generate unique sections for basic blocks.
-  //Use the machine basic block id in the symbol name to
-  //associate profile info from virtual address to machine
-  //basic block.
   // "all" :Generate basic block sections for all basic blocks.
   // "list=": Generate basic block sections for a subset of basic blocks.
   //The functions and the machine basic block ids are specified
   //in the file.
-  // "none":Disable se

[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-25 Thread Rahman Lavaee via cfe-commits

rlavaee wrote:

> > Just chiming in that I happened to spot the pre-merge check failure looks 
> > possibly related.
> 
> @jh7370 It's weird I can't reproduce this on my machine.

Fixed. It was an assertion failure.

https://github.com/llvm/llvm-project/pull/107494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Deprecate the `-fbasic-block-sections=labels` option. (PR #107494)

2024-09-25 Thread Rahman Lavaee via cfe-commits

https://github.com/rlavaee closed 
https://github.com/llvm/llvm-project/pull/107494
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] Adding Matching and Inference Functionality to Propeller (PR #139008)

2025-05-23 Thread Rahman Lavaee via cfe-commits


@@ -1688,6 +1688,11 @@ def fprofile_sample_accurate : Flag<["-"], 
"fprofile-sample-accurate">,
as cold. Otherwise, treat callsites without profile samples as 
if
we have no profile}]>,
MarshallingInfoFlag>;
+def fpropeller_profile_use_EQ : Joined<["-"], "fpropeller-profile-use=">,
+Group, Visibility<[ClangOption, CC1Option, CLOption]>, 
+MetaVarName<"">,

rlavaee wrote:

We don't need the new flag. The CFG edge profile is already being written to 
the basic-block-sections profile 
(https://github.com/google/llvm-propeller/blob/main/propeller/testdata/sample_verbose_cc_directives.golden.txt),
 as a comment which is [currently 
ignored](https://llvm.org/doxygen/BasicBlockSectionsProfileReader_8h_source.html#l00079)
 by the compiler. We can introduce the CFG profile under a [new 
specifier](https://llvm.org/doxygen/BasicBlockSectionsProfileReader_8cpp_source.html#l00155)

https://github.com/llvm/llvm-project/pull/139008
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits