Skip to content

Commit 112f651

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:2e26d091060e into amd-gfx:22f2ec2d35d2
Local branch amd-gfx 22f2ec2 Merged main:8f397e04e5ce into amd-gfx:61f415de20dd Remote branch main 2e26d09 BlockFrequencyInfo: Add PrintBlockFreq helper (llvm#67512)
2 parents 22f2ec2 + 2e26d09 commit 112f651

20 files changed

+151
-174
lines changed

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ if(APPLE AND CMAKE_GENERATOR STREQUAL Xcode)
123123
endif()
124124

125125
set(LLDB_EXPORT_ALL_SYMBOLS 0 CACHE BOOL
126-
"Causes lldb to export all symbols when building liblldb.")
126+
"Causes lldb to export some private symbols when building liblldb. See lldb/source/API/liblldb-private.exports for the full list of symbols that get exported.")
127+
128+
set(LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE "" CACHE PATH
129+
"When `LLDB_EXPORT_ALL_SYMBOLS` is enabled, this specifies the exports file to use when building liblldb.")
127130

128131
if ((NOT MSVC) OR MSVC12)
129132
add_definitions( -DHAVE_ROUND )

lldb/source/API/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,18 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
177177
# from working on some systems but limits the liblldb size.
178178
MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb namespace")
179179
add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports)
180-
else()
181-
# Don't use an explicit export. Instead, tell the linker to
182-
# export all symbols.
180+
elseif (NOT LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE)
181+
# Don't use an explicit export. Instead, tell the linker to export all symbols.
183182
MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces")
183+
MESSAGE(WARNING "Private LLDB symbols frequently change and no API stability is guaranteed. "
184+
"Only the SB API is guaranteed to be stable.")
184185
add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports)
186+
else ()
187+
MESSAGE("-- Symbols (liblldb): exporting all symbols specified in the exports "
188+
" file '${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}'")
189+
MESSAGE(WARNING "Private LLDB symbols frequently change and no API stability is guaranteed. "
190+
"Only the SB API is guaranteed to be stable.")
191+
add_llvm_symbol_exports(liblldb "${LLDB_EXPORT_ALL_SYMBOLS_EXPORTS_FILE}")
185192
endif()
186193
set_target_properties(liblldb_exports PROPERTIES FOLDER "lldb misc")
187194
elseif (LLDB_EXPORT_ALL_SYMBOLS)

llvm/include/llvm/ADT/bit.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@
2727
#include <cstdlib> // for _byteswap_{ushort,ulong,uint64}
2828
#endif
2929

30+
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
31+
defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
32+
#include <endian.h>
33+
#elif defined(_AIX)
34+
#include <sys/machine.h>
35+
#elif defined(__sun)
36+
/* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */
37+
#include <sys/types.h>
38+
#define BIG_ENDIAN 4321
39+
#define LITTLE_ENDIAN 1234
40+
#if defined(_BIG_ENDIAN)
41+
#define BYTE_ORDER BIG_ENDIAN
42+
#else
43+
#define BYTE_ORDER LITTLE_ENDIAN
44+
#endif
45+
#elif defined(__MVS__)
46+
#define BIG_ENDIAN 4321
47+
#define LITTLE_ENDIAN 1234
48+
#define BYTE_ORDER BIG_ENDIAN
49+
#else
50+
#if !defined(BYTE_ORDER) && !defined(_WIN32)
51+
#include <machine/endian.h>
52+
#endif
53+
#endif
54+
3055
#ifdef _MSC_VER
3156
// Declare these intrinsics manually rather including intrin.h. It's very
3257
// expensive, and bit.h is popular via MathExtras.h.
@@ -41,6 +66,16 @@ unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
4166

4267
namespace llvm {
4368

69+
enum class endianness {
70+
big,
71+
little,
72+
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
73+
native = big
74+
#else
75+
native = little
76+
#endif
77+
};
78+
4479
// This implementation of bit_cast is different from the C++20 one in two ways:
4580
// - It isn't constexpr because that requires compiler support.
4681
// - It requires trivially-constructible To, to avoid UB in the implementation.

llvm/include/llvm/Analysis/BlockFrequencyInfo.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/IR/PassManager.h"
1717
#include "llvm/Pass.h"
1818
#include "llvm/Support/BlockFrequency.h"
19+
#include "llvm/Support/Printable.h"
1920
#include <cstdint>
2021
#include <memory>
2122
#include <optional>
@@ -92,14 +93,6 @@ class BlockFrequencyInfo {
9293
void calculate(const Function &F, const BranchProbabilityInfo &BPI,
9394
const LoopInfo &LI);
9495

95-
// Print the block frequency Freq to OS using the current functions entry
96-
// frequency to convert freq into a relative decimal form.
97-
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
98-
99-
// Convenience method that attempts to look up the frequency associated with
100-
// BB and print it to OS.
101-
raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
102-
10396
BlockFrequency getEntryFreq() const;
10497
void releaseMemory();
10598
void print(raw_ostream &OS) const;
@@ -108,6 +101,15 @@ class BlockFrequencyInfo {
108101
void verifyMatch(BlockFrequencyInfo &Other) const;
109102
};
110103

104+
/// Print the block frequency @p Freq relative to the current functions entry
105+
/// frequency. Returns a Printable object that can be piped via `<<` to a
106+
/// `raw_ostream`.
107+
Printable printBlockFreq(const BlockFrequencyInfo &BFI, BlockFrequency Freq);
108+
109+
/// Convenience function equivalent to calling
110+
/// `printBlockFreq(BFI, BFI.getBlocakFreq(&BB))`.
111+
Printable printBlockFreq(const BlockFrequencyInfo &BFI, const BasicBlock &BB);
112+
111113
/// Analysis pass which computes \c BlockFrequencyInfo.
112114
class BlockFrequencyAnalysis
113115
: public AnalysisInfoMixin<BlockFrequencyAnalysis> {

llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,15 @@ class BlockFrequencyInfoImplBase {
533533

534534
void setBlockFreq(const BlockNode &Node, BlockFrequency Freq);
535535

536-
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockNode &Node) const;
537-
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
538-
539536
BlockFrequency getEntryFreq() const {
540537
assert(!Freqs.empty());
541538
return BlockFrequency(Freqs[0].Integer);
542539
}
543540
};
544541

542+
void printBlockFreqImpl(raw_ostream &OS, BlockFrequency EntryFreq,
543+
BlockFrequency Freq);
544+
545545
namespace bfi_detail {
546546

547547
template <class BlockT> struct TypeMap {};
@@ -1067,11 +1067,6 @@ template <class BT> class BlockFrequencyInfoImpl : BlockFrequencyInfoImplBase {
10671067
raw_ostream &print(raw_ostream &OS) const override;
10681068

10691069
using BlockFrequencyInfoImplBase::dump;
1070-
using BlockFrequencyInfoImplBase::printBlockFreq;
1071-
1072-
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockT *BB) const {
1073-
return BlockFrequencyInfoImplBase::printBlockFreq(OS, getNode(BB));
1074-
}
10751070

10761071
void verifyMatch(BlockFrequencyInfoImpl<BT> &Other) const;
10771072
};
@@ -1862,7 +1857,7 @@ struct BFIDOTGraphTraitsBase : public DefaultDOTGraphTraits {
18621857
OS << Node->getName() << " : ";
18631858
switch (GType) {
18641859
case GVDT_Fraction:
1865-
Graph->printBlockFreq(OS, Node);
1860+
OS << printBlockFreq(*Graph, *Node);
18661861
break;
18671862
case GVDT_Integer:
18681863
OS << Graph->getBlockFreq(Node).getFrequency();

llvm/include/llvm/CodeGen/MBFIWrapper.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "llvm/ADT/DenseMap.h"
1818
#include "llvm/Support/BlockFrequency.h"
19-
#include "llvm/Support/raw_ostream.h"
2019
#include <optional>
2120

2221
namespace llvm {
@@ -33,14 +32,11 @@ class MBFIWrapper {
3332
std::optional<uint64_t>
3433
getBlockProfileCount(const MachineBasicBlock *MBB) const;
3534

36-
raw_ostream &printBlockFreq(raw_ostream &OS,
37-
const MachineBasicBlock *MBB) const;
38-
raw_ostream &printBlockFreq(raw_ostream &OS, BlockFrequency Freq) const;
3935
void view(const Twine &Name, bool isSimple = true);
4036
BlockFrequency getEntryFreq() const;
41-
const MachineBlockFrequencyInfo &getMBFI() { return MBFI; }
37+
const MachineBlockFrequencyInfo &getMBFI() const { return MBFI; }
4238

43-
private:
39+
private:
4440
const MachineBlockFrequencyInfo &MBFI;
4541
DenseMap<const MachineBasicBlock *, BlockFrequency> MergedBBFreq;
4642
};

llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,22 @@ class MachineBlockFrequencyInfo : public MachineFunctionPass {
9191
/// rendered using dot.
9292
void view(const Twine &Name, bool isSimple = true) const;
9393

94-
// Print the block frequency Freq to OS using the current functions entry
95-
// frequency to convert freq into a relative decimal form.
96-
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
97-
98-
// Convenience method that attempts to look up the frequency associated with
99-
// BB and print it to OS.
100-
raw_ostream &printBlockFreq(raw_ostream &OS,
101-
const MachineBasicBlock *MBB) const;
102-
10394
/// Divide a block's BlockFrequency::getFrequency() value by this value to
10495
/// obtain the entry block - relative frequency of said block.
10596
BlockFrequency getEntryFreq() const;
10697
};
10798

99+
/// Print the block frequency @p Freq relative to the current functions entry
100+
/// frequency. Returns a Printable object that can be piped via `<<` to a
101+
/// `raw_ostream`.
102+
Printable printBlockFreq(const MachineBlockFrequencyInfo &MBFI,
103+
BlockFrequency Freq);
104+
105+
/// Convenience function equivalent to calling
106+
/// `printBlockFreq(MBFI, MBFI.getBlockFreq(&MBB))`.
107+
Printable printBlockFreq(const MachineBlockFrequencyInfo &MBFI,
108+
const MachineBasicBlock &MBB);
109+
108110
} // end namespace llvm
109111

110112
#endif // LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 476933
19+
#define LLVM_MAIN_REVISION 476937
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/Support/Endian.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_SUPPORT_ENDIAN_H
1414
#define LLVM_SUPPORT_ENDIAN_H
1515

16+
#include "llvm/ADT/bit.h"
1617
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/SwapByteOrder.h"
1819
#include <cassert>
@@ -22,13 +23,6 @@
2223
#include <type_traits>
2324

2425
namespace llvm {
25-
26-
enum class endianness {
27-
big,
28-
little,
29-
native = llvm::sys::IsBigEndianHost ? big : little
30-
};
31-
3226
namespace support {
3327

3428
// TODO: Remove the following once we are done migrating to llvm::endianness,

llvm/include/llvm/Support/SwapByteOrder.h

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,12 @@
1919
#include <cstdint>
2020
#include <type_traits>
2121

22-
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
23-
defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
24-
#include <endian.h>
25-
#elif defined(_AIX)
26-
#include <sys/machine.h>
27-
#elif defined(__sun)
28-
/* Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h */
29-
#include <sys/types.h>
30-
#define BIG_ENDIAN 4321
31-
#define LITTLE_ENDIAN 1234
32-
#if defined(_BIG_ENDIAN)
33-
#define BYTE_ORDER BIG_ENDIAN
34-
#else
35-
#define BYTE_ORDER LITTLE_ENDIAN
36-
#endif
37-
#elif defined(__MVS__)
38-
#define BIG_ENDIAN 4321
39-
#define LITTLE_ENDIAN 1234
40-
#define BYTE_ORDER BIG_ENDIAN
41-
#else
42-
#if !defined(BYTE_ORDER) && !defined(_WIN32)
43-
#include <machine/endian.h>
44-
#endif
45-
#endif
46-
4722
namespace llvm {
4823

4924
namespace sys {
5025

51-
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
52-
constexpr bool IsBigEndianHost = true;
53-
#else
54-
constexpr bool IsBigEndianHost = false;
55-
#endif
26+
constexpr bool IsBigEndianHost =
27+
llvm::endianness::native == llvm::endianness::big;
5628

5729
static const bool IsLittleEndianHost = !IsBigEndianHost;
5830

llvm/lib/Analysis/BlockFrequencyInfo.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,13 @@ cl::opt<PGOViewCountsType> PGOViewCounts(
7878
clEnumValN(PGOVCT_Graph, "graph", "show a graph."),
7979
clEnumValN(PGOVCT_Text, "text", "show in text.")));
8080

81-
static cl::opt<bool> PrintBlockFreq(
82-
"print-bfi", cl::init(false), cl::Hidden,
83-
cl::desc("Print the block frequency info."));
84-
85-
cl::opt<std::string> PrintBlockFreqFuncName(
86-
"print-bfi-func-name", cl::Hidden,
87-
cl::desc("The option to specify the name of the function "
88-
"whose block frequency info is printed."));
81+
static cl::opt<bool> PrintBFI("print-bfi", cl::init(false), cl::Hidden,
82+
cl::desc("Print the block frequency info."));
83+
84+
cl::opt<std::string>
85+
PrintBFIFuncName("print-bfi-func-name", cl::Hidden,
86+
cl::desc("The option to specify the name of the function "
87+
"whose block frequency info is printed."));
8988
} // namespace llvm
9089

9190
namespace llvm {
@@ -193,9 +192,8 @@ void BlockFrequencyInfo::calculate(const Function &F,
193192
F.getName().equals(ViewBlockFreqFuncName))) {
194193
view();
195194
}
196-
if (PrintBlockFreq &&
197-
(PrintBlockFreqFuncName.empty() ||
198-
F.getName().equals(PrintBlockFreqFuncName))) {
195+
if (PrintBFI &&
196+
(PrintBFIFuncName.empty() || F.getName().equals(PrintBFIFuncName))) {
199197
print(dbgs());
200198
}
201199
}
@@ -267,17 +265,6 @@ const BranchProbabilityInfo *BlockFrequencyInfo::getBPI() const {
267265
return BFI ? &BFI->getBPI() : nullptr;
268266
}
269267

270-
raw_ostream &BlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
271-
BlockFrequency Freq) const {
272-
return BFI ? BFI->printBlockFreq(OS, Freq) : OS;
273-
}
274-
275-
raw_ostream &
276-
BlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
277-
const BasicBlock *BB) const {
278-
return BFI ? BFI->printBlockFreq(OS, BB) : OS;
279-
}
280-
281268
BlockFrequency BlockFrequencyInfo::getEntryFreq() const {
282269
return BFI ? BFI->getEntryFreq() : BlockFrequency(0);
283270
}
@@ -294,6 +281,18 @@ void BlockFrequencyInfo::verifyMatch(BlockFrequencyInfo &Other) const {
294281
BFI->verifyMatch(*Other.BFI);
295282
}
296283

284+
Printable llvm::printBlockFreq(const BlockFrequencyInfo &BFI,
285+
BlockFrequency Freq) {
286+
return Printable([&BFI, Freq](raw_ostream &OS) {
287+
printBlockFreqImpl(OS, BFI.getEntryFreq(), Freq);
288+
});
289+
}
290+
291+
Printable llvm::printBlockFreq(const BlockFrequencyInfo &BFI,
292+
const BasicBlock &BB) {
293+
return printBlockFreq(BFI, BFI.getBlockFreq(&BB));
294+
}
295+
297296
INITIALIZE_PASS_BEGIN(BlockFrequencyInfoWrapperPass, "block-freq",
298297
"Block Frequency Analysis", true, true)
299298
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)

llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -640,19 +640,19 @@ BlockFrequencyInfoImplBase::getLoopName(const LoopData &Loop) const {
640640
return getBlockName(Loop.getHeader()) + (Loop.isIrreducible() ? "**" : "*");
641641
}
642642

643-
raw_ostream &
644-
BlockFrequencyInfoImplBase::printBlockFreq(raw_ostream &OS,
645-
const BlockNode &Node) const {
646-
return OS << getFloatingBlockFreq(Node);
647-
}
648-
649-
raw_ostream &
650-
BlockFrequencyInfoImplBase::printBlockFreq(raw_ostream &OS,
651-
BlockFrequency Freq) const {
643+
void llvm::printBlockFreqImpl(raw_ostream &OS, BlockFrequency EntryFreq,
644+
BlockFrequency Freq) {
645+
if (Freq == BlockFrequency(0)) {
646+
OS << "0";
647+
return;
648+
}
649+
if (EntryFreq == BlockFrequency(0)) {
650+
OS << "<invalid BFI>";
651+
return;
652+
}
652653
Scaled64 Block(Freq.getFrequency(), 0);
653-
Scaled64 Entry(getEntryFreq().getFrequency(), 0);
654-
655-
return OS << Block / Entry;
654+
Scaled64 Entry(EntryFreq.getFrequency(), 0);
655+
OS << Block / Entry;
656656
}
657657

658658
void IrreducibleGraph::addNodesInLoop(const BFIBase::LoopData &OuterLoop) {

0 commit comments

Comments
 (0)