Skip to content

Commit cc03eca

Browse files
authored
Merge branch 'main' into fix-llt-propagation
2 parents 71509ea + 4cce107 commit cc03eca

File tree

1,099 files changed

+26797
-23591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,099 files changed

+26797
-23591
lines changed

bolt/docs/BinaryAnalysis.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# BOLT-based binary analysis
2+
3+
As part of post-link-time optimizing, BOLT needs to perform a range of analyses
4+
on binaries such as recontructing control flow graphs, and more.
5+
6+
The `llvm-bolt-binary-analysis` tool enables running requested binary analyses
7+
on binaries, and generating reports. It does this by building on top of the
8+
analyses implemented in the BOLT libraries.
9+
10+
## Which binary analyses are implemented?
11+
12+
At the moment, no binary analyses are implemented.
13+
14+
The goal is to make it easy using a plug-in framework to add your own analyses.
15+
16+
## How to add your own binary analysis
17+
18+
_TODO: this section needs to be written. Ideally, we should have a simple
19+
"example" or "template" analysis that can be the starting point for implementing
20+
custom analyses_

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class DIEBuilder {
162162

163163
/// Clone an attribute in reference format.
164164
void cloneDieOffsetReferenceAttribute(
165-
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
165+
DIE &Die, DWARFUnit &U, const DWARFDie &InputDIE,
166166
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref);
167167

168168
/// Clone an attribute in block format.

bolt/include/bolt/Core/DebugNames.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class DWARF5AcceleratorTable {
7272
return std::move(FullTableBuffer);
7373
}
7474
/// Adds a DIE that is referenced across CUs.
75-
void addCrossCUDie(const DIE *Die) {
76-
CrossCUDies.insert({Die->getOffset(), Die});
75+
void addCrossCUDie(DWARFUnit *Unit, const DIE *Die) {
76+
CrossCUDies.insert({Die->getOffset(), {Unit, Die}});
7777
}
7878
/// Returns true if the DIE can generate an entry for a cross cu reference.
7979
/// This only checks TAGs of a DIE because when this is invoked DIE might not
@@ -145,7 +145,7 @@ class DWARF5AcceleratorTable {
145145
llvm::DenseMap<uint64_t, uint32_t> CUOffsetsToPatch;
146146
// Contains a map of Entry ID to Entry relative offset.
147147
llvm::DenseMap<uint64_t, uint32_t> EntryRelativeOffsets;
148-
llvm::DenseMap<uint64_t, const DIE *> CrossCUDies;
148+
llvm::DenseMap<uint64_t, std::pair<DWARFUnit *, const DIE *>> CrossCUDies;
149149
/// Adds Unit to either CUList, LocalTUList or ForeignTUList.
150150
/// Input Unit being processed, and DWO ID if Unit is being processed comes
151151
/// from a DWO section.
@@ -191,6 +191,29 @@ class DWARF5AcceleratorTable {
191191
void emitData();
192192
/// Emit augmentation string.
193193
void emitAugmentationString() const;
194+
/// Creates a new entry for a given DIE.
195+
std::optional<BOLTDWARF5AccelTableData *>
196+
addEntry(DWARFUnit &DU, const DIE &CurrDie,
197+
const std::optional<uint64_t> &DWOID,
198+
const std::optional<BOLTDWARF5AccelTableData *> &Parent,
199+
const std::optional<std::string> &Name,
200+
const uint32_t NumberParentsInChain);
201+
/// Returns UnitID for a given DWARFUnit.
202+
uint32_t getUnitID(const DWARFUnit &Unit,
203+
const std::optional<uint64_t> &DWOID, bool &IsTU);
204+
std::optional<std::string> getName(DWARFUnit &DU,
205+
const std::optional<uint64_t> &DWOID,
206+
const std::string &NameToUse,
207+
DIEValue ValName);
208+
/// Processes a DIE with references to other DIEs for DW_AT_name and
209+
/// DW_AT_linkage_name resolution.
210+
/// If DW_AT_name exists method creates a new entry for this DIE and returns
211+
/// it.
212+
std::optional<BOLTDWARF5AccelTableData *> processReferencedDie(
213+
DWARFUnit &Unit, const DIE &Die, const std::optional<uint64_t> &DWOID,
214+
const std::optional<BOLTDWARF5AccelTableData *> &Parent,
215+
const std::string &NameToUse, const uint32_t NumberParentsInChain,
216+
const dwarf::Attribute &Attr);
194217
};
195218
} // namespace bolt
196219
} // namespace llvm

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ class RewriteInstance {
164164

165165
void preregisterSections();
166166

167+
/// run analyses requested in binary analysis mode.
168+
void runBinaryAnalyses();
169+
167170
/// Run optimizations that operate at the binary, or post-linker, level.
168171
void runOptimizationPasses();
169172

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace opts {
1919

2020
extern bool HeatmapMode;
21+
extern bool BinaryAnalysisMode;
2122

2223
extern llvm::cl::OptionCategory BoltCategory;
2324
extern llvm::cl::OptionCategory BoltDiffCategory;
@@ -27,6 +28,7 @@ extern llvm::cl::OptionCategory BoltOutputCategory;
2728
extern llvm::cl::OptionCategory AggregatorCategory;
2829
extern llvm::cl::OptionCategory BoltInstrCategory;
2930
extern llvm::cl::OptionCategory HeatmapCategory;
31+
extern llvm::cl::OptionCategory BinaryAnalysisCategory;
3032

3133
extern llvm::cl::opt<unsigned> AlignText;
3234
extern llvm::cl::opt<unsigned> AlignFunctions;

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ DWARFDie DIEBuilder::resolveDIEReference(
622622
}
623623

624624
void DIEBuilder::cloneDieOffsetReferenceAttribute(
625-
DIE &Die, const DWARFUnit &U, const DWARFDie &InputDIE,
625+
DIE &Die, DWARFUnit &U, const DWARFDie &InputDIE,
626626
const DWARFAbbreviationDeclaration::AttributeSpec AttrSpec, uint64_t Ref) {
627627
DIE *NewRefDie = nullptr;
628628
DWARFUnit *RefUnit = nullptr;
@@ -654,7 +654,7 @@ void DIEBuilder::cloneDieOffsetReferenceAttribute(
654654
// Adding referenced DIE to DebugNames to be used when entries are created
655655
// that contain cross cu references.
656656
if (DebugNamesTable.canGenerateEntryWithCrossCUReference(U, Die, AttrSpec))
657-
DebugNamesTable.addCrossCUDie(DieInfo.Die);
657+
DebugNamesTable.addCrossCUDie(&U, DieInfo.Die);
658658
// no matter forward reference or backward reference, we are supposed
659659
// to calculate them in `finish` due to the possible modification of
660660
// the DIE.

0 commit comments

Comments
 (0)