mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 04:02:41 +01:00
[SampleFDO] Place the discriminator flag variable into the used list.
We create flag variable "__llvm_fs_discriminator__" in the binary to indicate that FSAFDO hierarchical discriminators are used. This variable might be GC'ed by the linker since it is not explicitly reference. I initially added the var to the use list in pass MIRFSDiscriminator but it did not work. It turned out the used global list is collected in lowering (before MIR pass) and then emitted in the end of pass pipeline. Here I add the variable to the use list in IR level's AddDiscriminators pass. The machine level code is still keep in the case IR's AddDiscriminators is not invoked. If this is the case, this just use -Wl,--export-dynamic-symbol=__llvm_fs_discriminator__ to force the emit. Differential Revision: https://reviews.llvm.org/D103988
This commit is contained in:
parent
17842d79ed
commit
022ca8be28
@ -19,10 +19,12 @@
|
||||
#include "llvm/Analysis/ProfileSummaryInfo.h"
|
||||
#include "llvm/IR/BasicBlock.h"
|
||||
#include "llvm/IR/CFG.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DebugLoc.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/ProfileData/SampleProf.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
||||
|
||||
namespace llvm {
|
||||
using namespace sampleprof;
|
||||
@ -92,6 +94,10 @@ private:
|
||||
/// Return true if the given callsite is hot wrt to hot cutoff threshold.
|
||||
bool callsiteIsHot(const FunctionSamples *CallsiteFS, ProfileSummaryInfo *PSI,
|
||||
bool ProfAccForSymsInList);
|
||||
|
||||
/// Create a global variable to flag FSDiscriminators are used.
|
||||
void createFSDiscriminatorVariable(Module *M);
|
||||
|
||||
} // end of namespace sampleprofutil
|
||||
} // end of namespace llvm
|
||||
|
||||
|
@ -19,10 +19,12 @@
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h"
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace sampleprof;
|
||||
using namespace sampleprofutil;
|
||||
|
||||
#define DEBUG_TYPE "mirfs-discriminators"
|
||||
|
||||
@ -127,16 +129,7 @@ bool MIRAddFSDiscriminators::runOnMachineFunction(MachineFunction &MF) {
|
||||
}
|
||||
|
||||
if (Changed) {
|
||||
Module *M = MF.getFunction().getParent();
|
||||
const char *FSDiscriminatorVar = "__llvm_fs_discriminator__";
|
||||
if (!M->getGlobalVariable(FSDiscriminatorVar)) {
|
||||
auto &Context = M->getContext();
|
||||
// Create a global variable to flag that FSDiscriminators are used.
|
||||
new GlobalVariable(*M, Type::getInt1Ty(Context), true,
|
||||
GlobalValue::WeakAnyLinkage,
|
||||
ConstantInt::getTrue(Context), FSDiscriminatorVar);
|
||||
}
|
||||
|
||||
createFSDiscriminatorVariable(MF.getFunction().getParent());
|
||||
LLVM_DEBUG(dbgs() << "Num of FS Discriminators: " << NumNewD << "\n");
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,11 @@
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Utils.h"
|
||||
#include "llvm/Transforms/Utils/SampleProfileLoaderBaseUtil.h"
|
||||
#include <utility>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace sampleprofutil;
|
||||
|
||||
#define DEBUG_TYPE "add-discriminators"
|
||||
|
||||
@ -172,6 +174,10 @@ static bool addDiscriminators(Function &F) {
|
||||
if (NoDiscriminators || !F.getSubprogram())
|
||||
return false;
|
||||
|
||||
// Create FSDiscriminatorVariable if flow sensitive discriminators are used.
|
||||
if (EnableFSDiscriminator)
|
||||
createFSDiscriminatorVariable(F.getParent());
|
||||
|
||||
bool Changed = false;
|
||||
|
||||
using Location = std::pair<StringRef, unsigned>;
|
||||
|
@ -159,5 +159,19 @@ unsigned SampleCoverageTracker::computeCoverage(unsigned Used,
|
||||
return Total > 0 ? Used * 100 / Total : 100;
|
||||
}
|
||||
|
||||
/// Create a global variable to flag FSDiscriminators are used.
|
||||
void createFSDiscriminatorVariable(Module *M) {
|
||||
const char *FSDiscriminatorVar = "__llvm_fs_discriminator__";
|
||||
if (M->getGlobalVariable(FSDiscriminatorVar))
|
||||
return;
|
||||
|
||||
auto &Context = M->getContext();
|
||||
// Place this variable to llvm.used so it won't be GC'ed.
|
||||
appendToUsed(*M, {new GlobalVariable(*M, Type::getInt1Ty(Context), true,
|
||||
GlobalValue::WeakODRLinkage,
|
||||
ConstantInt::getTrue(Context),
|
||||
FSDiscriminatorVar)});
|
||||
}
|
||||
|
||||
} // end of namespace sampleprofutil
|
||||
} // end of namespace llvm
|
||||
|
Loading…
Reference in New Issue
Block a user