Skip to content

Commit 43dce27

Browse files
committed
[BOLT][NFCI] Migrate pseudo probes to MetadataRewriter interface
Use new MetdataRewriter interface to update pseudo probes and move ProbeDecoder out of BinaryContext into new PseudoProbeRewriter class. Depends on D154021 Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D154022 Differential Revision: https://reviews.llvm.org/D154023
1 parent 98e2d63 commit 43dce27

File tree

7 files changed

+424
-380
lines changed

7 files changed

+424
-380
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "llvm/MC/MCContext.h"
3030
#include "llvm/MC/MCObjectFileInfo.h"
3131
#include "llvm/MC/MCObjectWriter.h"
32-
#include "llvm/MC/MCPseudoProbe.h"
3332
#include "llvm/MC/MCSectionELF.h"
3433
#include "llvm/MC/MCSectionMachO.h"
3534
#include "llvm/MC/MCStreamer.h"
@@ -681,9 +680,6 @@ class BinaryContext {
681680
/// and are referenced from BinaryFunction.
682681
std::list<std::pair<BinaryFunction *, uint64_t>> InterproceduralReferences;
683682

684-
/// PseudoProbe decoder
685-
MCPseudoProbeDecoder ProbeDecoder;
686-
687683
/// DWARF encoding. Available encoding types defined in BinaryFormat/Dwarf.h
688684
/// enum Constants, e.g. DW_EH_PE_omit.
689685
unsigned LSDAEncoding = dwarf::DW_EH_PE_omit;

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -423,21 +423,6 @@ class BinaryFunction {
423423
return BB->getIndex();
424424
}
425425

426-
/// Return basic block that originally contained offset \p Offset
427-
/// from the function start.
428-
BinaryBasicBlock *getBasicBlockContainingOffset(uint64_t Offset);
429-
430-
const BinaryBasicBlock *getBasicBlockContainingOffset(uint64_t Offset) const {
431-
return const_cast<BinaryFunction *>(this)->getBasicBlockContainingOffset(
432-
Offset);
433-
}
434-
435-
/// Return basic block that started at offset \p Offset.
436-
BinaryBasicBlock *getBasicBlockAtOffset(uint64_t Offset) {
437-
BinaryBasicBlock *BB = getBasicBlockContainingOffset(Offset);
438-
return BB && BB->getOffset() == Offset ? BB : nullptr;
439-
}
440-
441426
/// Release memory taken by the list.
442427
template <typename T> BinaryFunction &clearList(T &List) {
443428
T TempList;
@@ -900,6 +885,21 @@ class BinaryFunction {
900885
return LabelToBB.lookup(Label);
901886
}
902887

888+
/// Return basic block that originally contained offset \p Offset
889+
/// from the function start.
890+
BinaryBasicBlock *getBasicBlockContainingOffset(uint64_t Offset);
891+
892+
const BinaryBasicBlock *getBasicBlockContainingOffset(uint64_t Offset) const {
893+
return const_cast<BinaryFunction *>(this)->getBasicBlockContainingOffset(
894+
Offset);
895+
}
896+
897+
/// Return basic block that started at offset \p Offset.
898+
BinaryBasicBlock *getBasicBlockAtOffset(uint64_t Offset) {
899+
BinaryBasicBlock *BB = getBasicBlockContainingOffset(Offset);
900+
return BB && BB->getOffset() == Offset ? BB : nullptr;
901+
}
902+
903903
/// Retrieve the landing pad BB associated with invoke instruction \p Invoke
904904
/// that is in \p BB. Return nullptr if none exists
905905
BinaryBasicBlock *getLandingPadBBFor(const BinaryBasicBlock &BB,

bolt/include/bolt/Rewrite/MetadataRewriters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class BinaryContext;
1919

2020
// The list of rewriter build functions.
2121

22+
std::unique_ptr<MetadataRewriter> createPseudoProbeRewriter(BinaryContext &);
23+
2224
std::unique_ptr<MetadataRewriter> createSDTRewriter(BinaryContext &);
2325

2426
} // namespace bolt

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,6 @@ class RewriteInstance {
201201
/// Update LKMarkers' locations for the output binary.
202202
void updateLKMarkers();
203203

204-
/// Update address of MCDecodedPseudoProbe.
205-
void updatePseudoProbes();
206-
207-
/// Encode MCDecodedPseudoProbe.
208-
void encodePseudoProbes();
209-
210204
/// Return the list of code sections in the output order.
211205
std::vector<BinarySection *> getCodeSections();
212206

@@ -395,10 +389,6 @@ class RewriteInstance {
395389
/// of appending contents to it.
396390
bool willOverwriteSection(StringRef SectionName);
397391

398-
/// Parse .pseudo_probe_desc section and .pseudo_probe section
399-
/// Setup Pseudo probe decoder
400-
void parsePseudoProbe();
401-
402392
public:
403393
/// Standard ELF sections we overwrite.
404394
static constexpr const char *SectionsToOverwrite[] = {
@@ -580,15 +570,6 @@ class RewriteInstance {
580570
/// .note.gnu.build-id section.
581571
ErrorOr<BinarySection &> BuildIDSection{std::errc::bad_address};
582572

583-
/// .pseudo_probe_desc section.
584-
/// Contains information about pseudo probe description, like its related
585-
/// function
586-
ErrorOr<BinarySection &> PseudoProbeDescSection{std::errc::bad_address};
587-
588-
/// .pseudo_probe section.
589-
/// Contains information about pseudo probe details, like its address
590-
ErrorOr<BinarySection &> PseudoProbeSection{std::errc::bad_address};
591-
592573
/// Helper for accessing sections by name.
593574
BinarySection *getSection(const Twine &Name) {
594575
ErrorOr<BinarySection &> ErrOrSection = BC->getUniqueSectionByName(Name);

bolt/lib/Rewrite/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_llvm_library(LLVMBOLTRewrite
1616
JITLinkLinker.cpp
1717
MachORewriteInstance.cpp
1818
MetadataManager.cpp
19+
PseudoProbeRewriter.cpp
1920
RewriteInstance.cpp
2021
SDTRewriter.cpp
2122

0 commit comments

Comments
 (0)