Skip to content

Commit

Permalink
Store index inside BinaryBasicBlock instead of in map on BinaryFunction.
Browse files Browse the repository at this point in the history
Summary:
Store the basic block index inside the BinaryBasicBlock instead of a map in BinaryFunction.
This cut another 15-20 sec. from the processing time for hhvm.

(cherry picked from FBD3533606)
  • Loading branch information
Bill Nell authored and maksfb committed Jul 8, 2016
1 parent 90c9323 commit bdd4af2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 3 additions & 0 deletions bolt/BinaryBasicBlock.h
Expand Up @@ -56,6 +56,9 @@ class BinaryBasicBlock {
/// Alignment requirements for the block.
uint64_t Alignment{1};

/// Index to BasicBlocks vector in BinaryFunction.
unsigned Index{~0u};

/// Number of pseudo instructions in this block.
uint32_t NumPseudos{0};

Expand Down
12 changes: 4 additions & 8 deletions bolt/BinaryFunction.h
Expand Up @@ -257,10 +257,6 @@ class BinaryFunction : public AddressRangesOwner {
BasicBlockListType BasicBlocks;
BasicBlockOrderType BasicBlocksLayout;

// Map that keeps track of the index of each basic block in the BasicBlocks
// vector. Used to make getIndex fast.
std::unordered_map<const BinaryBasicBlock*, unsigned> BasicBlockIndices;

// At each basic block entry we attach a CFI state to detect if reordering
// corrupts the CFI state for a block. The CFI state is simply the index in
// FrameInstructions for the CFI responsible for creating this state.
Expand Down Expand Up @@ -405,10 +401,10 @@ class BinaryFunction : public AddressRangesOwner {
/// CFG after an optimization pass.
void dumpGraphForPass(std::string Annotation = "") const;

/// Get basic block index assuming it belongs to this function.
/// Get basic block index assuming it belongs to this function.
unsigned getIndex(const BinaryBasicBlock *BB) const {
assert(BasicBlockIndices.find(BB) != BasicBlockIndices.end());
return BasicBlockIndices.find(BB)->second;
assert(BB->Index < BasicBlocks.size());
return BB->Index;
}

/// Returns the n-th basic block in this function in its original layout, or
Expand Down Expand Up @@ -563,7 +559,7 @@ class BinaryFunction : public AddressRangesOwner {
BB->setAlignment(std::min(DerivedAlignment, uint64_t(32)));
}

BasicBlockIndices[BB] = BasicBlocks.size() - 1;
BB->Index = BasicBlocks.size() - 1;

return BB;
}
Expand Down

0 comments on commit bdd4af2

Please sign in to comment.