Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[Propeller] Promote functions with propeller profiles to .tex…
…t.hot." This relands commit 4d8d258. The major change here is using 'addUsedIfAvailable<BasicBlockSectionsProfileReader>()` to make sure we don't change the pipeline tests. Differential Revision: https://reviews.llvm.org/D126518
- Loading branch information
Showing
12 changed files
with
318 additions
and
176 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
//===-- BasicBlockSectionsProfileReader.h - BB sections profile reader pass ==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This pass creates the basic block cluster info by reading the basic block | ||
// sections profile. The cluster info will be used by the basic-block-sections | ||
// pass to arrange basic blocks in their sections. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_ANALYSIS_BASICBLOCKSECTIONSINFO_H | ||
#define LLVM_ANALYSIS_BASICBLOCKSECTIONSINFO_H | ||
|
||
#include "llvm/ADT/Optional.h" | ||
#include "llvm/ADT/SmallSet.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringMap.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/InitializePasses.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/LineIterator.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
|
||
using namespace llvm; | ||
|
||
namespace llvm { | ||
|
||
// The cluster information for a machine basic block. | ||
struct BBClusterInfo { | ||
// MachineBasicBlock ID. | ||
unsigned MBBNumber; | ||
// Cluster ID this basic block belongs to. | ||
unsigned ClusterID; | ||
// Position of basic block within the cluster. | ||
unsigned PositionInCluster; | ||
}; | ||
|
||
using ProgramBBClusterInfoMapTy = StringMap<SmallVector<BBClusterInfo>>; | ||
|
||
class BasicBlockSectionsProfileReader : public ImmutablePass { | ||
public: | ||
static char ID; | ||
|
||
BasicBlockSectionsProfileReader(const MemoryBuffer *Buf) | ||
: ImmutablePass(ID), MBuf(Buf) { | ||
initializeBasicBlockSectionsProfileReaderPass( | ||
*PassRegistry::getPassRegistry()); | ||
}; | ||
|
||
BasicBlockSectionsProfileReader() : ImmutablePass(ID) { | ||
initializeBasicBlockSectionsProfileReaderPass( | ||
*PassRegistry::getPassRegistry()); | ||
} | ||
|
||
StringRef getPassName() const override { | ||
return "Basic Block Sections Profile Reader"; | ||
} | ||
|
||
// Returns true if basic block sections profile exist for function \p | ||
// FuncName. | ||
bool isFunctionHot(StringRef FuncName) const; | ||
|
||
// Returns a pair with first element representing whether basic block sections | ||
// profile exist for the function \p FuncName, and the second element | ||
// representing the basic block sections profile (cluster info) for this | ||
// function. If the first element is true and the second element is empty, it | ||
// means unique basic block sections are desired for all basic blocks of the | ||
// function. | ||
std::pair<bool, SmallVector<BBClusterInfo>> | ||
getBBClusterInfoForFunction(StringRef FuncName) const; | ||
|
||
/// Read profiles of basic blocks if available here. | ||
void initializePass() override; | ||
|
||
private: | ||
StringRef getAliasName(StringRef FuncName) const { | ||
auto R = FuncAliasMap.find(FuncName); | ||
return R == FuncAliasMap.end() ? FuncName : R->second; | ||
} | ||
|
||
// This contains the basic-block-sections profile. | ||
const MemoryBuffer *MBuf = nullptr; | ||
|
||
// This encapsulates the BB cluster information for the whole program. | ||
// | ||
// For every function name, it contains the cluster information for (all or | ||
// some of) its basic blocks. The cluster information for every basic block | ||
// includes its cluster ID along with the position of the basic block in that | ||
// cluster. | ||
ProgramBBClusterInfoMapTy ProgramBBClusterInfo; | ||
|
||
// Some functions have alias names. We use this map to find the main alias | ||
// name for which we have mapping in ProgramBBClusterInfo. | ||
StringMap<StringRef> FuncAliasMap; | ||
}; | ||
|
||
// Creates a BasicBlockSectionsProfileReader pass to parse the basic block | ||
// sections profile. \p Buf is a memory buffer that contains the list of | ||
// functions and basic block ids to selectively enable basic block sections. | ||
ImmutablePass * | ||
createBasicBlockSectionsProfileReaderPass(const MemoryBuffer *Buf); | ||
|
||
} // namespace llvm | ||
#endif // LLVM_ANALYSIS_BASICBLOCKSECTIONSINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.