Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace bolt {

class BinaryFunction;

using BinaryFunctionListType = std::vector<BinaryFunction *>;
using ConstBinaryFunctionListType = std::vector<const BinaryFunction *>;

/// Information on loadable part of the file.
struct SegmentInfo {
uint64_t Address; /// Address of the segment in memory.
Expand Down Expand Up @@ -228,11 +231,11 @@ class BinaryContext {
/// Store all functions in the binary, sorted by original address.
std::map<uint64_t, BinaryFunction> BinaryFunctions;

/// A mutex that is used to control parallel accesses to BinaryFunctions
/// A mutex that is used to control parallel accesses to BinaryFunctions.
mutable llvm::sys::RWMutex BinaryFunctionsMutex;

/// Functions injected by BOLT
std::vector<BinaryFunction *> InjectedBinaryFunctions;
/// Functions injected by BOLT.
BinaryFunctionListType InjectedBinaryFunctions;

/// Jump tables for all functions mapped by address.
std::map<uint64_t, JumpTable *> JumpTables;
Expand Down Expand Up @@ -567,13 +570,13 @@ class BinaryContext {
const InstructionListType &Instructions,
const Twine &Name = "");

std::vector<BinaryFunction *> &getInjectedBinaryFunctions() {
BinaryFunctionListType &getInjectedBinaryFunctions() {
return InjectedBinaryFunctions;
}

/// Return vector with all functions, i.e. include functions from the input
/// binary and functions created by BOLT.
std::vector<BinaryFunction *> getAllBinaryFunctions();
BinaryFunctionListType getAllBinaryFunctions();

/// Construct a jump table for \p Function at \p Address or return an existing
/// one at that location.
Expand Down Expand Up @@ -1385,7 +1388,7 @@ class BinaryContext {
const uint32_t SrcCUID, unsigned FileIndex);

/// Return functions in output layout order
std::vector<BinaryFunction *> getSortedFunctions();
BinaryFunctionListType getSortedFunctions();

/// Do the best effort to calculate the size of the function by emitting
/// its code, and relaxing branch instructions. By default, branch
Expand Down
4 changes: 2 additions & 2 deletions bolt/include/bolt/Core/BinaryFunctionCallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef BOLT_PASSES_BINARY_FUNCTION_CALLGRAPH_H
#define BOLT_PASSES_BINARY_FUNCTION_CALLGRAPH_H

#include "bolt/Core/BinaryContext.h"
#include "bolt/Core/CallGraph.h"
#include <deque>
#include <functional>
Expand All @@ -18,7 +19,6 @@ namespace llvm {
namespace bolt {

class BinaryFunction;
class BinaryContext;

class BinaryFunctionCallGraph : public CallGraph {
public:
Expand Down Expand Up @@ -46,7 +46,7 @@ class BinaryFunctionCallGraph : public CallGraph {

private:
std::unordered_map<const BinaryFunction *, NodeId> FuncToNodeId;
std::vector<BinaryFunction *> Funcs;
BinaryFunctionListType Funcs;
};

using CgFilterFunction = std::function<bool(const BinaryFunction &BF)>;
Expand Down
5 changes: 2 additions & 3 deletions bolt/include/bolt/Passes/CacheMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
#ifndef BOLT_PASSES_CACHEMETRICS_H
#define BOLT_PASSES_CACHEMETRICS_H

#include "bolt/Core/BinaryContext.h"
#include <vector>

namespace llvm {

class raw_ostream;

namespace bolt {
class BinaryFunction;
namespace CacheMetrics {

/// Calculate and print various metrics related to instruction cache performance
void printAll(raw_ostream &OS,
const std::vector<BinaryFunction *> &BinaryFunctions);
void printAll(raw_ostream &OS, const BinaryFunctionListType &BinaryFunctions);

} // namespace CacheMetrics
} // namespace bolt
Expand Down
16 changes: 7 additions & 9 deletions bolt/include/bolt/Passes/LongJmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ class LongJmpPass : public BinaryFunctionPass {
/// purposes, we need to do a size worst-case estimation. Real layout is done
/// by RewriteInstance::mapFileSections()
void tentativeLayout(const BinaryContext &BC,
std::vector<BinaryFunction *> &SortedFunctions);
uint64_t
tentativeLayoutRelocMode(const BinaryContext &BC,
std::vector<BinaryFunction *> &SortedFunctions,
uint64_t DotAddress);
uint64_t
tentativeLayoutRelocColdPart(const BinaryContext &BC,
std::vector<BinaryFunction *> &SortedFunctions,
uint64_t DotAddress);
BinaryFunctionListType &SortedFunctions);
uint64_t tentativeLayoutRelocMode(const BinaryContext &BC,
BinaryFunctionListType &SortedFunctions,
uint64_t DotAddress);
uint64_t tentativeLayoutRelocColdPart(const BinaryContext &BC,
BinaryFunctionListType &SortedFunctions,
uint64_t DotAddress);
void tentativeBBLayout(const BinaryFunction &Func);

/// Update stubs addresses with their exact address after a round of stub
Expand Down
6 changes: 3 additions & 3 deletions bolt/include/bolt/Profile/YAMLProfileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class YAMLProfileReader : public ProfileReaderBase {
}

/// Returns the binary functions with the parameter neighbor hash.
std::optional<std::vector<BinaryFunction *>>
std::optional<BinaryFunctionListType>
getBFsWithNeighborHash(uint64_t NeighborHash) {
auto It = NeighborHashToBFs.find(NeighborHash);
return It == NeighborHashToBFs.end() ? std::nullopt
Expand All @@ -93,7 +93,7 @@ class YAMLProfileReader : public ProfileReaderBase {
DenseMap<BinaryFunction *, std::set<BinaryFunction *>> BFAdjacencyMap;

/// Maps neighbor hashes to binary functions.
DenseMap<uint64_t, std::vector<BinaryFunction *>> NeighborHashToBFs;
DenseMap<uint64_t, BinaryFunctionListType> NeighborHashToBFs;

/// Adjacency map for profile functions in the call graph.
DenseMap<yaml::bolt::BinaryFunctionProfile *,
Expand Down Expand Up @@ -187,7 +187,7 @@ class YAMLProfileReader : public ProfileReaderBase {
StringSet<> ProfileFunctionNames;

/// BinaryFunction pointers indexed by YamlBP functions.
std::vector<BinaryFunction *> ProfileBFs;
BinaryFunctionListType ProfileBFs;

// Pseudo probe function GUID to inline tree node
GUIDInlineTreeMap TopLevelGUIDToInlineTree;
Expand Down
10 changes: 5 additions & 5 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ void BinaryContext::populateJumpTables() {
}

void BinaryContext::skipMarkedFragments() {
std::vector<BinaryFunction *> FragmentQueue;
BinaryFunctionListType FragmentQueue;
// Copy the functions to FragmentQueue.
FragmentQueue.assign(FragmentsToSkip.begin(), FragmentsToSkip.end());
auto addToWorklist = [&](BinaryFunction *Function) -> void {
Expand Down Expand Up @@ -1715,8 +1715,8 @@ unsigned BinaryContext::addDebugFilenameToUnit(const uint32_t DestCUID,
DestCUID, DstUnit->getVersion()));
}

std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
std::vector<BinaryFunction *> SortedFunctions(BinaryFunctions.size());
BinaryFunctionListType BinaryContext::getSortedFunctions() {
BinaryFunctionListType SortedFunctions(BinaryFunctions.size());
llvm::transform(llvm::make_second_range(BinaryFunctions),
SortedFunctions.begin(),
[](BinaryFunction &BF) { return &BF; });
Expand All @@ -1725,8 +1725,8 @@ std::vector<BinaryFunction *> BinaryContext::getSortedFunctions() {
return SortedFunctions;
}

std::vector<BinaryFunction *> BinaryContext::getAllBinaryFunctions() {
std::vector<BinaryFunction *> AllFunctions;
BinaryFunctionListType BinaryContext::getAllBinaryFunctions() {
BinaryFunctionListType AllFunctions;
AllFunctions.reserve(BinaryFunctions.size() + InjectedBinaryFunctions.size());
llvm::transform(llvm::make_second_range(BinaryFunctions),
std::back_inserter(AllFunctions),
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Core/BinaryEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void BinaryEmitter::emitAll(StringRef OrgSecPrefix) {
}

void BinaryEmitter::emitFunctions() {
auto emit = [&](const std::vector<BinaryFunction *> &Functions) {
auto emit = [&](const BinaryFunctionListType &Functions) {
const bool HasProfile = BC.NumProfiledFuncs > 0;
const bool OriginalAllowAutoPadding = Streamer.getAllowAutoPadding();
for (BinaryFunction *Function : Functions) {
Expand Down Expand Up @@ -282,7 +282,7 @@ void BinaryEmitter::emitFunctions() {
}

// Emit functions in sorted order.
std::vector<BinaryFunction *> SortedFunctions = BC.getSortedFunctions();
BinaryFunctionListType SortedFunctions = BC.getSortedFunctions();
emit(SortedFunctions);

// Emit functions added by BOLT.
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Passes/BinaryPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {
}

if (!opts::PrintSortedBy.empty()) {
std::vector<BinaryFunction *> Functions;
BinaryFunctionListType Functions;
std::map<const BinaryFunction *, DynoStats> Stats;

for (auto &BFI : BC.getBinaryFunctions()) {
Expand Down Expand Up @@ -1700,7 +1700,7 @@ Error PrintProgramStats::runOnFunctions(BinaryContext &BC) {

// Collect and print information about suboptimal code layout on input.
if (opts::ReportBadLayout) {
std::vector<BinaryFunction *> SuboptimalFuncs;
BinaryFunctionListType SuboptimalFuncs;
for (auto &BFI : BC.getBinaryFunctions()) {
BinaryFunction &BF = BFI.second;
if (!BF.hasValidProfile())
Expand Down
10 changes: 5 additions & 5 deletions bolt/lib/Passes/CacheMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constexpr unsigned ITLBEntries = 16;

/// Initialize and return a position map for binary basic blocks
void extractBasicBlockInfo(
const std::vector<BinaryFunction *> &BinaryFunctions,
const BinaryFunctionListType &BinaryFunctions,
std::unordered_map<BinaryBasicBlock *, uint64_t> &BBAddr,
std::unordered_map<BinaryBasicBlock *, uint64_t> &BBSize) {

Expand All @@ -54,7 +54,7 @@ void extractBasicBlockInfo(
/// the ordering of basic blocks. The method returns a pair
/// (the number of fallthrough branches, the total number of branches)
std::pair<uint64_t, uint64_t>
calcTSPScore(const std::vector<BinaryFunction *> &BinaryFunctions,
calcTSPScore(const BinaryFunctionListType &BinaryFunctions,
const std::unordered_map<BinaryBasicBlock *, uint64_t> &BBAddr,
const std::unordered_map<BinaryBasicBlock *, uint64_t> &BBSize) {
uint64_t Score = 0;
Expand Down Expand Up @@ -95,7 +95,7 @@ using Predecessors = std::vector<std::pair<BinaryFunction *, uint64_t>>;
/// Build a simplified version of the call graph: For every function, keep
/// its callers and the frequencies of the calls
std::unordered_map<const BinaryFunction *, Predecessors>
extractFunctionCalls(const std::vector<BinaryFunction *> &BinaryFunctions) {
extractFunctionCalls(const BinaryFunctionListType &BinaryFunctions) {
std::unordered_map<const BinaryFunction *, Predecessors> Calls;

for (BinaryFunction *SrcFunction : BinaryFunctions) {
Expand Down Expand Up @@ -140,7 +140,7 @@ extractFunctionCalls(const std::vector<BinaryFunction *> &BinaryFunctions) {
/// the page. The following procedure detects short and long calls, and
/// estimates the expected number of cache misses for the long ones.
double expectedCacheHitRatio(
const std::vector<BinaryFunction *> &BinaryFunctions,
const BinaryFunctionListType &BinaryFunctions,
const std::unordered_map<BinaryBasicBlock *, uint64_t> &BBAddr,
const std::unordered_map<BinaryBasicBlock *, uint64_t> &BBSize) {
std::unordered_map<const BinaryFunction *, Predecessors> Calls =
Expand Down Expand Up @@ -213,7 +213,7 @@ double expectedCacheHitRatio(
} // namespace

void CacheMetrics::printAll(raw_ostream &OS,
const std::vector<BinaryFunction *> &BFs) {
const BinaryFunctionListType &BFs) {
// Stats related to hot-cold code splitting
size_t NumFunctions = 0;
size_t NumProfiledFunctions = 0;
Expand Down
6 changes: 3 additions & 3 deletions bolt/lib/Passes/IdenticalCodeFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ typedef std::unordered_map<BinaryFunction *, std::set<BinaryFunction *>,
KeyHash, KeyCongruent>
CongruentBucketsMap;

typedef std::unordered_map<BinaryFunction *, std::vector<BinaryFunction *>,
KeyHash, KeyEqual>
typedef std::unordered_map<BinaryFunction *, BinaryFunctionListType, KeyHash,
KeyEqual>
IdenticalBucketsMap;

namespace llvm {
Expand Down Expand Up @@ -522,7 +522,7 @@ Error IdenticalCodeFolding::runOnFunctions(BinaryContext &BC) {

for (auto &IBI : IdenticalBuckets) {
// Functions identified as identical.
std::vector<BinaryFunction *> &Twins = IBI.second;
BinaryFunctionListType &Twins = IBI.second;
if (Twins.size() < 2)
continue;

Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Passes/Inliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ Error Inliner::runOnFunctions(BinaryContext &BC) {
InliningCandidates.clear();
findInliningCandidates(BC);

std::vector<BinaryFunction *> ConsideredFunctions;
BinaryFunctionListType ConsideredFunctions;
for (auto &BFI : BC.getBinaryFunctions()) {
BinaryFunction &Function = BFI.second;
if (!shouldOptimize(Function))
Expand Down
15 changes: 8 additions & 7 deletions bolt/lib/Passes/LongJmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void LongJmpPass::tentativeBBLayout(const BinaryFunction &Func) {
}

uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
const BinaryContext &BC, BinaryFunctionListType &SortedFunctions,
uint64_t DotAddress) {
DotAddress = alignTo(DotAddress, llvm::Align(opts::AlignFunctions));
for (BinaryFunction *Func : SortedFunctions) {
Expand All @@ -325,9 +325,10 @@ uint64_t LongJmpPass::tentativeLayoutRelocColdPart(
return DotAddress;
}

uint64_t LongJmpPass::tentativeLayoutRelocMode(
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions,
uint64_t DotAddress) {
uint64_t
LongJmpPass::tentativeLayoutRelocMode(const BinaryContext &BC,
BinaryFunctionListType &SortedFunctions,
uint64_t DotAddress) {
// Compute hot cold frontier
int64_t LastHotIndex = -1u;
uint32_t CurrentIndex = 0;
Expand Down Expand Up @@ -398,8 +399,8 @@ uint64_t LongJmpPass::tentativeLayoutRelocMode(
return DotAddress;
}

void LongJmpPass::tentativeLayout(
const BinaryContext &BC, std::vector<BinaryFunction *> &SortedFunctions) {
void LongJmpPass::tentativeLayout(const BinaryContext &BC,
BinaryFunctionListType &SortedFunctions) {
uint64_t DotAddress = BC.LayoutStartAddress;

if (!BC.HasRelocations) {
Expand Down Expand Up @@ -920,7 +921,7 @@ Error LongJmpPass::runOnFunctions(BinaryContext &BC) {
}

BC.outs() << "BOLT-INFO: Starting stub-insertion pass\n";
std::vector<BinaryFunction *> Sorted = BC.getSortedFunctions();
BinaryFunctionListType Sorted = BC.getSortedFunctions();
bool Modified;
uint32_t Iterations = 0;
do {
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Passes/ProfileQualityStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static cl::opt<unsigned> PercentileForProfileQualityCheck(
} // namespace opts

namespace {
using FunctionListType = std::vector<const BinaryFunction *>;
using FunctionListType = ConstBinaryFunctionListType;
using function_iterator = FunctionListType::iterator;

// Function number -> vector of flows for BBs in the function
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Passes/ReorderFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
case RT_NONE:
break;
case RT_EXEC_COUNT: {
std::vector<BinaryFunction *> SortedFunctions(BFs.size());
BinaryFunctionListType SortedFunctions(BFs.size());
llvm::transform(llvm::make_second_range(BFs), SortedFunctions.begin(),
[](BinaryFunction &BF) { return &BF; });
llvm::stable_sort(SortedFunctions,
Expand Down Expand Up @@ -471,7 +471,7 @@ Error ReorderFunctions::runOnFunctions(BinaryContext &BC) {
}

if (FuncsFile || LinkSectionsFile) {
std::vector<BinaryFunction *> SortedFunctions(BFs.size());
BinaryFunctionListType SortedFunctions(BFs.size());
llvm::transform(llvm::make_second_range(BFs), SortedFunctions.begin(),
[](BinaryFunction &BF) { return &BF; });

Expand Down
6 changes: 3 additions & 3 deletions bolt/lib/Profile/YAMLProfileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
auto BFsWithSameHashOpt = CGMatcher.getBFsWithNeighborHash(Hash);
if (!BFsWithSameHashOpt)
continue;
std::vector<BinaryFunction *> BFsWithSameHash = BFsWithSameHashOpt.value();
BinaryFunctionListType BFsWithSameHash = BFsWithSameHashOpt.value();
// Finds the binary function with the longest common prefix to the profiled
// function and matches.
BinaryFunction *ClosestBF = nullptr;
Expand Down Expand Up @@ -725,7 +725,7 @@ size_t YAMLProfileReader::matchWithNameSimilarity(BinaryContext &BC) {
NamespaceToProfiledBFSizes[YamlBFNamespace].insert(YamlBF.NumBasicBlocks);
}

StringMap<std::vector<BinaryFunction *>> NamespaceToBFs;
StringMap<BinaryFunctionListType> NamespaceToBFs;

// Maps namespaces to BFs excluding binary functions with no equal sized
// profiled functions belonging to the same namespace.
Expand Down Expand Up @@ -760,7 +760,7 @@ size_t YAMLProfileReader::matchWithNameSimilarity(BinaryContext &BC) {
continue;

std::string &YamlBFDemangledName = ProfileBFDemangledNames[I];
std::vector<BinaryFunction *> BFs = It->second;
BinaryFunctionListType BFs = It->second;
unsigned MinEditDistance = UINT_MAX;
BinaryFunction *ClosestNameBF = nullptr;

Expand Down
Loading