summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-basic-block-sections-support.patch
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-basic-block-sections-support.patch')
-rw-r--r--dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-basic-block-sections-support.patch237
1 files changed, 0 insertions, 237 deletions
diff --git a/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-basic-block-sections-support.patch b/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-basic-block-sections-support.patch
deleted file mode 100644
index f90a79ae..00000000
--- a/dynamic-layers/clang-layer/recipes-devtools/clang/files/llvm10-basic-block-sections-support.patch
+++ /dev/null
@@ -1,237 +0,0 @@
1From d51fdb9f2986747a56c593fa057d531720b39deb Mon Sep 17 00:00:00 2001
2From: Sriraman Tallam <tmsriram@google.com>
3Date: Fri, 13 Mar 2020 15:58:57 -0700
4Subject: [PATCH] Basic Block Sections Support.
5
6This is the first in a series of patches to enable Basic Block Sections
7in LLVM.
8
9We introduce a new compiler option, -fbasicblock-sections=, which places every
10basic block in a unique ELF text section in the object file along with a
11symbol labeling the basic block. The linker can then order the basic block
12sections in any arbitrary sequence which when done correctly can encapsulate
13block layout, function layout and function splitting optimizations. However,
14there are a couple of challenges to be addressed for this to be feasible:
15
161) The compiler must not allow any implicit fall-through between any two
17 adjacent basic blocks as they could be reordered at link time to be
18 non-adjacent. In other words, the compiler must make a fall-through
19 between adjacent basic blocks explicit by retaining the direct jump
20 instruction that jumps to the next basic block. These branches can only
21 be removed later by the linker after the blocks have been reordered.
222) All inter-basic block branch targets would now need to be resolved by
23 the linker as they cannot be calculated during compile time. This is
24 done using static relocations which bloats the size of the object files.
25 Further, the compiler tries to use short branch instructions on some ISAs
26 for branch offsets that can be accommodated in one byte. This is not
27 possible with basic block sections as the offset is not determined at
28 compile time, and long branch instructions have to be used everywhere.
293) Each additional section bloats object file sizes by tens of bytes. The
30 number of basic blocks can be potentially very large compared to the
31 size of functions and can bloat object sizes significantly. Option
32 fbasicblock-sections= also takes a file path which can be used to
33 specify a subset of basic blocks that needs unique sections to keep
34 the bloats small.
354) Debug Info and CFI need special handling and will be presented as
36 separate patches.
37
38Basic Block Labels
39
40With -fbasicblock-sections=labels, or when a basic block is placed in a
41unique section, it is labelled with a symbol. This allows easy mapping of
42virtual addresses from PMU profiles back to the corresponding basic blocks.
43Since the number of basic blocks is large, the labeling bloats the symbol
44table sizes and the string table sizes significantly. While the binary size
45does increase, it does not affect performance as the symbol table is not
46loaded in memory during run-time. The string table size bloat is kept very
47minimal using a unary naming scheme that uses string suffix compression.
48The basic blocks for function foo are named "a.BB.foo", "aa.BB.foo", ...
49This turns out to be very good for string table sizes and the bloat in the
50string table size for a very large binary is ~8 %. The naming also allows
51using the --symbol-ordering-file option in LLD to arbitrarily reorder the
52sections.
53
54Differential Revision: https://reviews.llvm.org/D68063
55
56Upstream-Status: Backport [https://github.com/llvm/llvm-project/commit/4dfe92e46542be46d634a7ec24da2f2f889623d0]
57Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
58---
59 llvm/include/llvm/CodeGen/CommandFlags.inc | 34 ++++++++++++++++++++++
60 llvm/include/llvm/Target/TargetMachine.h | 14 +++++++++
61 llvm/include/llvm/Target/TargetOptions.h | 31 ++++++++++++++++++--
62 3 files changed, 76 insertions(+), 3 deletions(-)
63
64diff --git a/llvm/include/llvm/CodeGen/CommandFlags.inc b/llvm/include/llvm/CodeGen/CommandFlags.inc
65index 8739b644873d..6475a5b19edb 100644
66--- a/llvm/include/llvm/CodeGen/CommandFlags.inc
67+++ b/llvm/include/llvm/CodeGen/CommandFlags.inc
68@@ -238,6 +238,12 @@ static cl::opt<bool>
69 cl::desc("Emit functions into separate sections"),
70 cl::init(false));
71
72+static cl::opt<std::string>
73+ BBSections("basicblock-sections",
74+ cl::desc("Emit basic blocks into separate sections"),
75+ cl::value_desc("all | <function list (file)> | labels | none"),
76+ cl::init("none"));
77+
78 static cl::opt<unsigned> TLSSize("tls-size",
79 cl::desc("Bit size of immediate TLS offsets"),
80 cl::init(0));
81@@ -251,6 +257,11 @@ static cl::opt<bool>
82 cl::desc("Give unique names to every section"),
83 cl::init(true));
84
85+static cl::opt<bool> UniqueBBSectionNames(
86+ "unique-bb-section-names",
87+ cl::desc("Give unique names to every basic block section"),
88+ cl::init(false));
89+
90 static cl::opt<llvm::EABI>
91 EABIVersion("meabi", cl::desc("Set EABI type (default depends on triple):"),
92 cl::init(EABI::Default),
93@@ -285,6 +296,27 @@ static cl::opt<bool>
94 cl::desc("Always emit a debug frame section."),
95 cl::init(false));
96
97+static llvm::BasicBlockSection
98+getBBSectionsMode(llvm::TargetOptions &Options) {
99+ if (BBSections == "all")
100+ return BasicBlockSection::All;
101+ else if (BBSections == "labels")
102+ return BasicBlockSection::Labels;
103+ else if (BBSections == "none")
104+ return BasicBlockSection::None;
105+ else {
106+ ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
107+ MemoryBuffer::getFile(BBSections);
108+ if (!MBOrErr) {
109+ errs() << "Error loading basic block sections function list file: "
110+ << MBOrErr.getError().message() << "\n";
111+ } else {
112+ Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
113+ }
114+ return BasicBlockSection::List;
115+ }
116+}
117+
118 // Common utility function tightly tied to the options listed here. Initializes
119 // a TargetOptions object with CodeGen flags and returns it.
120 static TargetOptions InitTargetOptionsFromCodeGenFlags() {
121@@ -308,7 +340,9 @@ static TargetOptions InitTargetOptionsFromCodeGenFlags() {
122 Options.RelaxELFRelocations = RelaxELFRelocations;
123 Options.DataSections = DataSections;
124 Options.FunctionSections = FunctionSections;
125+ Options.BBSections = getBBSectionsMode(Options);
126 Options.UniqueSectionNames = UniqueSectionNames;
127+ Options.UniqueBBSectionNames = UniqueBBSectionNames;
128 Options.TLSSize = TLSSize;
129 Options.EmulatedTLS = EmulatedTLS;
130 Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
131diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
132index 176ae39b17a7..4a1f3377f31d 100644
133--- a/llvm/include/llvm/Target/TargetMachine.h
134+++ b/llvm/include/llvm/Target/TargetMachine.h
135@@ -242,6 +242,9 @@ public:
136
137 bool getUniqueSectionNames() const { return Options.UniqueSectionNames; }
138
139+ /// Return true if unique basic block section names must be generated.
140+ bool getUniqueBBSectionNames() const { return Options.UniqueBBSectionNames; }
141+
142 /// Return true if data objects should be emitted into their own section,
143 /// corresponds to -fdata-sections.
144 bool getDataSections() const {
145@@ -254,6 +257,17 @@ public:
146 return Options.FunctionSections;
147 }
148
149+ /// If basic blocks should be emitted into their own section,
150+ /// corresponding to -fbasicblock-sections.
151+ llvm::BasicBlockSection getBBSectionsType() const {
152+ return Options.BBSections;
153+ }
154+
155+ /// Get the list of functions and basic block ids that need unique sections.
156+ const MemoryBuffer *getBBSectionsFuncListBuf() const {
157+ return Options.BBSectionsFuncListBuf.get();
158+ }
159+
160 /// Get a \c TargetIRAnalysis appropriate for the target.
161 ///
162 /// This is used to construct the new pass manager's target IR analysis pass,
163diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
164index 84c6ee2a6387..d27c7b0178f0 100644
165--- a/llvm/include/llvm/Target/TargetOptions.h
166+++ b/llvm/include/llvm/Target/TargetOptions.h
167@@ -16,8 +16,11 @@
168
169 #include "llvm/MC/MCTargetOptions.h"
170
171+#include <memory>
172+
173 namespace llvm {
174 class MachineFunction;
175+ class MemoryBuffer;
176 class Module;
177
178 namespace FloatABI {
179@@ -63,6 +66,18 @@ namespace llvm {
180 };
181 }
182
183+ enum class BasicBlockSection {
184+ All, // Use Basic Block Sections for all basic blocks. A section
185+ // for every basic block can significantly bloat object file sizes.
186+ List, // Get list of functions & BBs from a file. Selectively enables
187+ // basic block sections for a subset of basic blocks which can be
188+ // used to control object size bloats from creating sections.
189+ Labels, // Do not use Basic Block Sections but label basic blocks. This
190+ // is useful when associating profile counts from virtual addresses
191+ // to basic blocks.
192+ None // Do not use Basic Block Sections.
193+ };
194+
195 enum class EABI {
196 Unknown,
197 Default, // Default means not specified
198@@ -114,9 +129,9 @@ namespace llvm {
199 EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
200 DisableIntegratedAS(false), RelaxELFRelocations(false),
201 FunctionSections(false), DataSections(false),
202- UniqueSectionNames(true), TrapUnreachable(false),
203- NoTrapAfterNoreturn(false), TLSSize(0), EmulatedTLS(false),
204- ExplicitEmulatedTLS(false), EnableIPRA(false),
205+ UniqueSectionNames(true), UniqueBBSectionNames(false),
206+ TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
207+ EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
208 EmitStackSizeSection(false), EnableMachineOutliner(false),
209 SupportsDefaultOutlining(false), EmitAddrsig(false),
210 EnableDebugEntryValues(false), ForceDwarfFrameSection(false) {}
211@@ -224,6 +239,9 @@ namespace llvm {
212
213 unsigned UniqueSectionNames : 1;
214
215+ /// Use unique names for basic block sections.
216+ unsigned UniqueBBSectionNames : 1;
217+
218 /// Emit target-specific trap instruction for 'unreachable' IR instructions.
219 unsigned TrapUnreachable : 1;
220
221@@ -256,6 +274,13 @@ namespace llvm {
222 /// Emit address-significance table.
223 unsigned EmitAddrsig : 1;
224
225+ /// Emit basic blocks into separate sections.
226+ BasicBlockSection BBSections = BasicBlockSection::None;
227+
228+ /// Memory Buffer that contains information on sampled basic blocks and used
229+ /// to selectively generate basic block sections.
230+ std::shared_ptr<MemoryBuffer> BBSectionsFuncListBuf;
231+
232 /// Emit debug info about parameter's entry values.
233 unsigned EnableDebugEntryValues : 1;
234
235--
2362.33.1
237