2017-04-04 18:42:20 +02:00
|
|
|
//===-- IndirectCallPromotion.cpp - Optimizations based on value profiling ===//
|
2016-04-28 01:20:27 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the transformation that promotes indirect calls to
|
|
|
|
// conditional direct calls when the indirect-call value profile metadata is
|
|
|
|
// available.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-04-04 18:42:20 +02:00
|
|
|
#include "llvm/Analysis/BlockFrequencyInfo.h"
|
2017-04-06 22:56:00 +02:00
|
|
|
#include "llvm/Analysis/GlobalsModRef.h"
|
2016-07-12 23:13:44 +02:00
|
|
|
#include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
|
|
|
|
#include "llvm/Analysis/IndirectCallSiteVisitor.h"
|
2017-10-10 01:19:02 +02:00
|
|
|
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
|
2017-08-08 22:57:33 +02:00
|
|
|
#include "llvm/Analysis/ProfileSummaryInfo.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/IR/Function.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/IR/InstrTypes.h"
|
|
|
|
#include "llvm/IR/Instruction.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/IR/MDBuilder.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/IR/PassManager.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/Pass.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/PassRegistry.h"
|
|
|
|
#include "llvm/PassSupport.h"
|
|
|
|
#include "llvm/ProfileData/InstrProf.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2017-04-04 18:42:20 +02:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/Transforms/Instrumentation.h"
|
2016-05-16 18:31:07 +02:00
|
|
|
#include "llvm/Transforms/PGOInstrumentation.h"
|
2016-04-28 01:20:27 +02:00
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2016-08-11 19:20:18 +02:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
2016-04-28 01:20:27 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2016-06-02 03:52:05 +02:00
|
|
|
#define DEBUG_TYPE "pgo-icall-prom"
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
STATISTIC(NumOfPGOICallPromotion, "Number of indirect call promotions.");
|
|
|
|
STATISTIC(NumOfPGOICallsites, "Number of indirect call candidate sites.");
|
|
|
|
|
|
|
|
// Command line option to disable indirect-call promotion with the default as
|
|
|
|
// false. This is for debug purpose.
|
|
|
|
static cl::opt<bool> DisableICP("disable-icp", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Disable indirect call promotion"));
|
|
|
|
|
|
|
|
// Set the cutoff value for the promotion. If the value is other than 0, we
|
|
|
|
// stop the transformation once the total number of promotions equals the cutoff
|
|
|
|
// value.
|
|
|
|
// For debug use only.
|
|
|
|
static cl::opt<unsigned>
|
|
|
|
ICPCutOff("icp-cutoff", cl::init(0), cl::Hidden, cl::ZeroOrMore,
|
2017-05-06 00:31:11 +02:00
|
|
|
cl::desc("Max number of promotions for this compilation"));
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
// If ICPCSSkip is non zero, the first ICPCSSkip callsites will be skipped.
|
|
|
|
// For debug use only.
|
|
|
|
static cl::opt<unsigned>
|
|
|
|
ICPCSSkip("icp-csskip", cl::init(0), cl::Hidden, cl::ZeroOrMore,
|
2017-05-06 00:31:11 +02:00
|
|
|
cl::desc("Skip Callsite up to this number for this compilation"));
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
// Set if the pass is called in LTO optimization. The difference for LTO mode
|
|
|
|
// is the pass won't prefix the source module name to the internal linkage
|
|
|
|
// symbols.
|
|
|
|
static cl::opt<bool> ICPLTOMode("icp-lto", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Run indirect-call promotion in LTO "
|
|
|
|
"mode"));
|
2016-07-12 23:13:44 +02:00
|
|
|
|
2017-02-23 23:15:18 +01:00
|
|
|
// Set if the pass is called in SamplePGO mode. The difference for SamplePGO
|
|
|
|
// mode is it will add prof metadatato the created direct call.
|
|
|
|
static cl::opt<bool>
|
|
|
|
ICPSamplePGOMode("icp-samplepgo", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Run indirect-call promotion in SamplePGO mode"));
|
|
|
|
|
2016-04-28 01:20:27 +02:00
|
|
|
// If the option is set to true, only call instructions will be considered for
|
|
|
|
// transformation -- invoke instructions will be ignored.
|
|
|
|
static cl::opt<bool>
|
|
|
|
ICPCallOnly("icp-call-only", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Run indirect-call promotion for call instructions "
|
|
|
|
"only"));
|
|
|
|
|
|
|
|
// If the option is set to true, only invoke instructions will be considered for
|
|
|
|
// transformation -- call instructions will be ignored.
|
|
|
|
static cl::opt<bool> ICPInvokeOnly("icp-invoke-only", cl::init(false),
|
|
|
|
cl::Hidden,
|
|
|
|
cl::desc("Run indirect-call promotion for "
|
|
|
|
"invoke instruction only"));
|
|
|
|
|
|
|
|
// Dump the function level IR if the transformation happened in this
|
|
|
|
// function. For debug use only.
|
|
|
|
static cl::opt<bool>
|
|
|
|
ICPDUMPAFTER("icp-dumpafter", cl::init(false), cl::Hidden,
|
|
|
|
cl::desc("Dump IR after transformation happens"));
|
|
|
|
|
|
|
|
namespace {
|
2016-05-15 03:04:24 +02:00
|
|
|
class PGOIndirectCallPromotionLegacyPass : public ModulePass {
|
2016-04-28 01:20:27 +02:00
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
2017-02-23 23:15:18 +01:00
|
|
|
PGOIndirectCallPromotionLegacyPass(bool InLTO = false, bool SamplePGO = false)
|
|
|
|
: ModulePass(ID), InLTO(InLTO), SamplePGO(SamplePGO) {
|
2016-05-15 03:04:24 +02:00
|
|
|
initializePGOIndirectCallPromotionLegacyPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
2017-08-08 22:57:33 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<ProfileSummaryInfoWrapperPass>();
|
|
|
|
}
|
|
|
|
|
2016-10-01 04:56:57 +02:00
|
|
|
StringRef getPassName() const override { return "PGOIndirectCallPromotion"; }
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool runOnModule(Module &M) override;
|
|
|
|
|
|
|
|
// If this pass is called in LTO. We need to special handling the PGOFuncName
|
|
|
|
// for the static variables due to LTO's internalization.
|
|
|
|
bool InLTO;
|
2017-02-23 23:15:18 +01:00
|
|
|
|
|
|
|
// If this pass is called in SamplePGO. We need to add the prof metadata to
|
|
|
|
// the promoted direct call.
|
|
|
|
bool SamplePGO;
|
2016-04-28 01:20:27 +02:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2016-05-15 03:04:24 +02:00
|
|
|
char PGOIndirectCallPromotionLegacyPass::ID = 0;
|
2017-08-15 01:25:21 +02:00
|
|
|
INITIALIZE_PASS_BEGIN(PGOIndirectCallPromotionLegacyPass, "pgo-icall-prom",
|
|
|
|
"Use PGO instrumentation profile to promote indirect "
|
|
|
|
"calls to direct calls.",
|
|
|
|
false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass)
|
|
|
|
INITIALIZE_PASS_END(PGOIndirectCallPromotionLegacyPass, "pgo-icall-prom",
|
|
|
|
"Use PGO instrumentation profile to promote indirect "
|
|
|
|
"calls to direct calls.",
|
|
|
|
false, false)
|
2016-04-28 01:20:27 +02:00
|
|
|
|
2017-02-23 23:15:18 +01:00
|
|
|
ModulePass *llvm::createPGOIndirectCallPromotionLegacyPass(bool InLTO,
|
|
|
|
bool SamplePGO) {
|
|
|
|
return new PGOIndirectCallPromotionLegacyPass(InLTO, SamplePGO);
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
2016-05-15 17:18:11 +02:00
|
|
|
namespace {
|
2016-04-28 01:20:27 +02:00
|
|
|
// The class for main data structure to promote indirect calls to conditional
|
|
|
|
// direct calls.
|
|
|
|
class ICallPromotionFunc {
|
|
|
|
private:
|
|
|
|
Function &F;
|
|
|
|
Module *M;
|
|
|
|
|
|
|
|
// Symtab that maps indirect call profile values to function names and
|
|
|
|
// defines.
|
|
|
|
InstrProfSymtab *Symtab;
|
|
|
|
|
2017-02-23 23:15:18 +01:00
|
|
|
bool SamplePGO;
|
|
|
|
|
2017-07-27 18:54:15 +02:00
|
|
|
OptimizationRemarkEmitter &ORE;
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
// A struct that records the direct target and it's call count.
|
|
|
|
struct PromotionCandidate {
|
|
|
|
Function *TargetFunction;
|
|
|
|
uint64_t Count;
|
|
|
|
PromotionCandidate(Function *F, uint64_t C) : TargetFunction(F), Count(C) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check if the indirect-call call site should be promoted. Return the number
|
2016-07-12 23:13:44 +02:00
|
|
|
// of promotions. Inst is the candidate indirect call, ValueDataRef
|
|
|
|
// contains the array of value profile data for profiled targets,
|
|
|
|
// TotalCount is the total profiled count of call executions, and
|
|
|
|
// NumCandidates is the number of candidate entries in ValueDataRef.
|
2016-04-28 01:20:27 +02:00
|
|
|
std::vector<PromotionCandidate> getPromotionCandidatesForCallSite(
|
|
|
|
Instruction *Inst, const ArrayRef<InstrProfValueData> &ValueDataRef,
|
2016-07-12 23:13:44 +02:00
|
|
|
uint64_t TotalCount, uint32_t NumCandidates);
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
// Promote a list of targets for one indirect-call callsite. Return
|
|
|
|
// the number of promotions.
|
|
|
|
uint32_t tryToPromote(Instruction *Inst,
|
|
|
|
const std::vector<PromotionCandidate> &Candidates,
|
|
|
|
uint64_t &TotalCount);
|
|
|
|
|
|
|
|
// Noncopyable
|
|
|
|
ICallPromotionFunc(const ICallPromotionFunc &other) = delete;
|
|
|
|
ICallPromotionFunc &operator=(const ICallPromotionFunc &other) = delete;
|
|
|
|
|
|
|
|
public:
|
2017-02-23 23:15:18 +01:00
|
|
|
ICallPromotionFunc(Function &Func, Module *Modu, InstrProfSymtab *Symtab,
|
2017-07-27 18:54:15 +02:00
|
|
|
bool SamplePGO, OptimizationRemarkEmitter &ORE)
|
|
|
|
: F(Func), M(Modu), Symtab(Symtab), SamplePGO(SamplePGO), ORE(ORE) {}
|
2016-08-11 19:20:18 +02:00
|
|
|
|
2017-08-08 22:57:33 +02:00
|
|
|
bool processFunction(ProfileSummaryInfo *PSI);
|
2016-04-28 01:20:27 +02:00
|
|
|
};
|
2016-05-15 17:18:11 +02:00
|
|
|
} // end anonymous namespace
|
2016-04-28 01:20:27 +02:00
|
|
|
|
2017-01-30 23:46:37 +01:00
|
|
|
bool llvm::isLegalToPromote(Instruction *Inst, Function *F,
|
|
|
|
const char **Reason) {
|
2016-04-28 01:20:27 +02:00
|
|
|
// Check the return type.
|
|
|
|
Type *CallRetType = Inst->getType();
|
|
|
|
if (!CallRetType->isVoidTy()) {
|
2017-01-30 23:46:37 +01:00
|
|
|
Type *FuncRetType = F->getReturnType();
|
2016-04-28 01:20:27 +02:00
|
|
|
if (FuncRetType != CallRetType &&
|
2017-01-30 23:46:37 +01:00
|
|
|
!CastInst::isBitCastable(FuncRetType, CallRetType)) {
|
|
|
|
if (Reason)
|
|
|
|
*Reason = "Return type mismatch";
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the arguments are compatible with the parameters
|
2017-01-30 23:46:37 +01:00
|
|
|
FunctionType *DirectCalleeType = F->getFunctionType();
|
2016-04-28 01:20:27 +02:00
|
|
|
unsigned ParamNum = DirectCalleeType->getFunctionNumParams();
|
|
|
|
CallSite CS(Inst);
|
|
|
|
unsigned ArgNum = CS.arg_size();
|
|
|
|
|
2017-01-30 23:46:37 +01:00
|
|
|
if (ParamNum != ArgNum && !DirectCalleeType->isVarArg()) {
|
|
|
|
if (Reason)
|
|
|
|
*Reason = "The number of arguments mismatch";
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
for (unsigned I = 0; I < ParamNum; ++I) {
|
|
|
|
Type *PTy = DirectCalleeType->getFunctionParamType(I);
|
|
|
|
Type *ATy = CS.getArgument(I)->getType();
|
|
|
|
if (PTy == ATy)
|
|
|
|
continue;
|
2017-01-30 23:46:37 +01:00
|
|
|
if (!CastInst::castIsValid(Instruction::BitCast, CS.getArgument(I), PTy)) {
|
|
|
|
if (Reason)
|
2017-01-31 00:11:29 +01:00
|
|
|
*Reason = "Argument type mismatch";
|
2017-01-30 23:46:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(dbgs() << " #" << NumOfPGOICallPromotion << " Promote the icall to "
|
2017-01-30 23:46:37 +01:00
|
|
|
<< F->getName() << "\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-28 01:20:27 +02:00
|
|
|
// Indirect-call promotion heuristic. The direct targets are sorted based on
|
|
|
|
// the count. Stop at the first target that is not promoted.
|
|
|
|
std::vector<ICallPromotionFunc::PromotionCandidate>
|
|
|
|
ICallPromotionFunc::getPromotionCandidatesForCallSite(
|
|
|
|
Instruction *Inst, const ArrayRef<InstrProfValueData> &ValueDataRef,
|
2016-07-12 23:13:44 +02:00
|
|
|
uint64_t TotalCount, uint32_t NumCandidates) {
|
2016-04-28 01:20:27 +02:00
|
|
|
std::vector<PromotionCandidate> Ret;
|
|
|
|
|
|
|
|
DEBUG(dbgs() << " \nWork on callsite #" << NumOfPGOICallsites << *Inst
|
2016-07-12 23:29:05 +02:00
|
|
|
<< " Num_targets: " << ValueDataRef.size()
|
2016-07-12 23:13:44 +02:00
|
|
|
<< " Num_candidates: " << NumCandidates << "\n");
|
2016-04-28 01:20:27 +02:00
|
|
|
NumOfPGOICallsites++;
|
|
|
|
if (ICPCSSkip != 0 && NumOfPGOICallsites <= ICPCSSkip) {
|
|
|
|
DEBUG(dbgs() << " Skip: User options.\n");
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2016-07-12 23:13:44 +02:00
|
|
|
for (uint32_t I = 0; I < NumCandidates; I++) {
|
2016-04-28 01:20:27 +02:00
|
|
|
uint64_t Count = ValueDataRef[I].Count;
|
|
|
|
assert(Count <= TotalCount);
|
|
|
|
uint64_t Target = ValueDataRef[I].Value;
|
|
|
|
DEBUG(dbgs() << " Candidate " << I << " Count=" << Count
|
|
|
|
<< " Target_func: " << Target << "\n");
|
|
|
|
|
2016-07-17 16:46:58 +02:00
|
|
|
if (ICPInvokeOnly && dyn_cast<CallInst>(Inst)) {
|
|
|
|
DEBUG(dbgs() << " Not promote: User options.\n");
|
2017-07-27 18:54:15 +02:00
|
|
|
ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UserOptions", Inst)
|
|
|
|
<< " Not promote: User options");
|
2016-07-17 16:46:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ICPCallOnly && dyn_cast<InvokeInst>(Inst)) {
|
|
|
|
DEBUG(dbgs() << " Not promote: User option.\n");
|
2017-07-27 18:54:15 +02:00
|
|
|
ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UserOptions", Inst)
|
|
|
|
<< " Not promote: User options");
|
2016-07-17 16:46:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-04-28 01:20:27 +02:00
|
|
|
if (ICPCutOff != 0 && NumOfPGOICallPromotion >= ICPCutOff) {
|
|
|
|
DEBUG(dbgs() << " Not promote: Cutoff reached.\n");
|
2017-07-27 18:54:15 +02:00
|
|
|
ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "CutOffReached", Inst)
|
|
|
|
<< " Not promote: Cutoff reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Function *TargetFunction = Symtab->getFunction(Target);
|
|
|
|
if (TargetFunction == nullptr) {
|
|
|
|
DEBUG(dbgs() << " Not promote: Cannot find the target\n");
|
|
|
|
ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UnableToFindTarget", Inst)
|
|
|
|
<< "Cannot promote indirect call: target not found");
|
2016-04-28 01:20:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-07-27 18:54:15 +02:00
|
|
|
|
2017-01-30 23:46:37 +01:00
|
|
|
const char *Reason = nullptr;
|
2017-07-27 18:54:15 +02:00
|
|
|
if (!isLegalToPromote(Inst, TargetFunction, &Reason)) {
|
|
|
|
using namespace ore;
|
|
|
|
ORE.emit(OptimizationRemarkMissed(DEBUG_TYPE, "UnableToPromote", Inst)
|
|
|
|
<< "Cannot promote indirect call to "
|
|
|
|
<< NV("TargetFunction", TargetFunction) << " with count of "
|
|
|
|
<< NV("Count", Count) << ": " << Reason);
|
2016-04-28 01:20:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-07-27 18:54:15 +02:00
|
|
|
|
2016-04-28 01:20:27 +02:00
|
|
|
Ret.push_back(PromotionCandidate(TargetFunction, Count));
|
|
|
|
TotalCount -= Count;
|
|
|
|
}
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a diamond structure for If_Then_Else. Also update the profile
|
|
|
|
// count. Do the fix-up for the invoke instruction.
|
|
|
|
static void createIfThenElse(Instruction *Inst, Function *DirectCallee,
|
|
|
|
uint64_t Count, uint64_t TotalCount,
|
|
|
|
BasicBlock **DirectCallBB,
|
|
|
|
BasicBlock **IndirectCallBB,
|
|
|
|
BasicBlock **MergeBB) {
|
|
|
|
CallSite CS(Inst);
|
|
|
|
Value *OrigCallee = CS.getCalledValue();
|
|
|
|
|
|
|
|
IRBuilder<> BBBuilder(Inst);
|
|
|
|
LLVMContext &Ctx = Inst->getContext();
|
|
|
|
Value *BCI1 =
|
|
|
|
BBBuilder.CreateBitCast(OrigCallee, Type::getInt8PtrTy(Ctx), "");
|
|
|
|
Value *BCI2 =
|
|
|
|
BBBuilder.CreateBitCast(DirectCallee, Type::getInt8PtrTy(Ctx), "");
|
|
|
|
Value *PtrCmp = BBBuilder.CreateICmpEQ(BCI1, BCI2, "");
|
|
|
|
|
|
|
|
uint64_t ElseCount = TotalCount - Count;
|
|
|
|
uint64_t MaxCount = (Count >= ElseCount ? Count : ElseCount);
|
|
|
|
uint64_t Scale = calculateCountScale(MaxCount);
|
|
|
|
MDBuilder MDB(Inst->getContext());
|
|
|
|
MDNode *BranchWeights = MDB.createBranchWeights(
|
|
|
|
scaleBranchCount(Count, Scale), scaleBranchCount(ElseCount, Scale));
|
|
|
|
TerminatorInst *ThenTerm, *ElseTerm;
|
|
|
|
SplitBlockAndInsertIfThenElse(PtrCmp, Inst, &ThenTerm, &ElseTerm,
|
|
|
|
BranchWeights);
|
|
|
|
*DirectCallBB = ThenTerm->getParent();
|
|
|
|
(*DirectCallBB)->setName("if.true.direct_targ");
|
|
|
|
*IndirectCallBB = ElseTerm->getParent();
|
|
|
|
(*IndirectCallBB)->setName("if.false.orig_indirect");
|
|
|
|
*MergeBB = Inst->getParent();
|
|
|
|
(*MergeBB)->setName("if.end.icp");
|
|
|
|
|
|
|
|
// Special handing of Invoke instructions.
|
|
|
|
InvokeInst *II = dyn_cast<InvokeInst>(Inst);
|
|
|
|
if (!II)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We don't need branch instructions for invoke.
|
|
|
|
ThenTerm->eraseFromParent();
|
|
|
|
ElseTerm->eraseFromParent();
|
|
|
|
|
|
|
|
// Add jump from Merge BB to the NormalDest. This is needed for the newly
|
|
|
|
// created direct invoke stmt -- as its NormalDst will be fixed up to MergeBB.
|
|
|
|
BranchInst::Create(II->getNormalDest(), *MergeBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the PHI in BB that have the CallResult as the operand.
|
|
|
|
static bool getCallRetPHINode(BasicBlock *BB, Instruction *Inst) {
|
|
|
|
BasicBlock *From = Inst->getParent();
|
|
|
|
for (auto &I : *BB) {
|
|
|
|
PHINode *PHI = dyn_cast<PHINode>(&I);
|
|
|
|
if (!PHI)
|
|
|
|
continue;
|
|
|
|
int IX = PHI->getBasicBlockIndex(From);
|
|
|
|
if (IX == -1)
|
|
|
|
continue;
|
|
|
|
Value *V = PHI->getIncomingValue(IX);
|
|
|
|
if (dyn_cast<Instruction>(V) == Inst)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method fixes up PHI nodes in BB where BB is the UnwindDest of an
|
|
|
|
// invoke instruction. In BB, there may be PHIs with incoming block being
|
|
|
|
// OrigBB (the MergeBB after if-then-else splitting). After moving the invoke
|
|
|
|
// instructions to its own BB, OrigBB is no longer the predecessor block of BB.
|
|
|
|
// Instead two new predecessors are added: IndirectCallBB and DirectCallBB,
|
|
|
|
// so the PHI node's incoming BBs need to be fixed up accordingly.
|
|
|
|
static void fixupPHINodeForUnwind(Instruction *Inst, BasicBlock *BB,
|
|
|
|
BasicBlock *OrigBB,
|
|
|
|
BasicBlock *IndirectCallBB,
|
|
|
|
BasicBlock *DirectCallBB) {
|
|
|
|
for (auto &I : *BB) {
|
|
|
|
PHINode *PHI = dyn_cast<PHINode>(&I);
|
|
|
|
if (!PHI)
|
|
|
|
continue;
|
|
|
|
int IX = PHI->getBasicBlockIndex(OrigBB);
|
|
|
|
if (IX == -1)
|
|
|
|
continue;
|
|
|
|
Value *V = PHI->getIncomingValue(IX);
|
|
|
|
PHI->addIncoming(V, IndirectCallBB);
|
|
|
|
PHI->setIncomingBlock(IX, DirectCallBB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method fixes up PHI nodes in BB where BB is the NormalDest of an
|
|
|
|
// invoke instruction. In BB, there may be PHIs with incoming block being
|
|
|
|
// OrigBB (the MergeBB after if-then-else splitting). After moving the invoke
|
|
|
|
// instructions to its own BB, a new incoming edge will be added to the original
|
|
|
|
// NormalDstBB from the IndirectCallBB.
|
|
|
|
static void fixupPHINodeForNormalDest(Instruction *Inst, BasicBlock *BB,
|
|
|
|
BasicBlock *OrigBB,
|
|
|
|
BasicBlock *IndirectCallBB,
|
|
|
|
Instruction *NewInst) {
|
|
|
|
for (auto &I : *BB) {
|
|
|
|
PHINode *PHI = dyn_cast<PHINode>(&I);
|
|
|
|
if (!PHI)
|
|
|
|
continue;
|
|
|
|
int IX = PHI->getBasicBlockIndex(OrigBB);
|
|
|
|
if (IX == -1)
|
|
|
|
continue;
|
|
|
|
Value *V = PHI->getIncomingValue(IX);
|
|
|
|
if (dyn_cast<Instruction>(V) == Inst) {
|
|
|
|
PHI->setIncomingBlock(IX, IndirectCallBB);
|
|
|
|
PHI->addIncoming(NewInst, OrigBB);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PHI->addIncoming(V, IndirectCallBB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a bitcast instruction to the direct-call return value if needed.
|
|
|
|
static Instruction *insertCallRetCast(const Instruction *Inst,
|
|
|
|
Instruction *DirectCallInst,
|
|
|
|
Function *DirectCallee) {
|
|
|
|
if (Inst->getType()->isVoidTy())
|
|
|
|
return DirectCallInst;
|
|
|
|
|
|
|
|
Type *CallRetType = Inst->getType();
|
|
|
|
Type *FuncRetType = DirectCallee->getReturnType();
|
|
|
|
if (FuncRetType == CallRetType)
|
|
|
|
return DirectCallInst;
|
|
|
|
|
|
|
|
BasicBlock *InsertionBB;
|
|
|
|
if (CallInst *CI = dyn_cast<CallInst>(DirectCallInst))
|
|
|
|
InsertionBB = CI->getParent();
|
|
|
|
else
|
|
|
|
InsertionBB = (dyn_cast<InvokeInst>(DirectCallInst))->getNormalDest();
|
|
|
|
|
|
|
|
return (new BitCastInst(DirectCallInst, CallRetType, "",
|
|
|
|
InsertionBB->getTerminator()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a DirectCall instruction in the DirectCallBB.
|
|
|
|
// Parameter Inst is the indirect-call (invoke) instruction.
|
|
|
|
// DirectCallee is the decl of the direct-call (invoke) target.
|
|
|
|
// DirecallBB is the BB that the direct-call (invoke) instruction is inserted.
|
|
|
|
// MergeBB is the bottom BB of the if-then-else-diamond after the
|
|
|
|
// transformation. For invoke instruction, the edges from DirectCallBB and
|
|
|
|
// IndirectCallBB to MergeBB are removed before this call (during
|
2017-10-06 19:04:55 +02:00
|
|
|
// createIfThenElse). Stores the pointer to the Instruction that cast
|
|
|
|
// the direct call in \p CastInst.
|
2016-04-28 01:20:27 +02:00
|
|
|
static Instruction *createDirectCallInst(const Instruction *Inst,
|
|
|
|
Function *DirectCallee,
|
|
|
|
BasicBlock *DirectCallBB,
|
2017-10-06 19:04:55 +02:00
|
|
|
BasicBlock *MergeBB,
|
|
|
|
Instruction *&CastInst) {
|
2016-04-28 01:20:27 +02:00
|
|
|
Instruction *NewInst = Inst->clone();
|
|
|
|
if (CallInst *CI = dyn_cast<CallInst>(NewInst)) {
|
|
|
|
CI->setCalledFunction(DirectCallee);
|
|
|
|
CI->mutateFunctionType(DirectCallee->getFunctionType());
|
|
|
|
} else {
|
|
|
|
// Must be an invoke instruction. Direct invoke's normal destination is
|
|
|
|
// fixed up to MergeBB. MergeBB is the place where return cast is inserted.
|
|
|
|
// Also since IndirectCallBB does not have an edge to MergeBB, there is no
|
|
|
|
// need to insert new PHIs into MergeBB.
|
|
|
|
InvokeInst *II = dyn_cast<InvokeInst>(NewInst);
|
|
|
|
assert(II);
|
|
|
|
II->setCalledFunction(DirectCallee);
|
|
|
|
II->mutateFunctionType(DirectCallee->getFunctionType());
|
|
|
|
II->setNormalDest(MergeBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
DirectCallBB->getInstList().insert(DirectCallBB->getFirstInsertionPt(),
|
|
|
|
NewInst);
|
|
|
|
|
|
|
|
// Clear the value profile data.
|
2016-08-11 19:20:18 +02:00
|
|
|
NewInst->setMetadata(LLVMContext::MD_prof, nullptr);
|
2016-04-28 01:20:27 +02:00
|
|
|
CallSite NewCS(NewInst);
|
|
|
|
FunctionType *DirectCalleeType = DirectCallee->getFunctionType();
|
|
|
|
unsigned ParamNum = DirectCalleeType->getFunctionNumParams();
|
|
|
|
for (unsigned I = 0; I < ParamNum; ++I) {
|
|
|
|
Type *ATy = NewCS.getArgument(I)->getType();
|
|
|
|
Type *PTy = DirectCalleeType->getParamType(I);
|
|
|
|
if (ATy != PTy) {
|
|
|
|
BitCastInst *BI = new BitCastInst(NewCS.getArgument(I), PTy, "", NewInst);
|
|
|
|
NewCS.setArgument(I, BI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 19:04:55 +02:00
|
|
|
CastInst = insertCallRetCast(Inst, NewInst, DirectCallee);
|
|
|
|
return NewInst;
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a PHI to unify the return values of calls.
|
|
|
|
static void insertCallRetPHI(Instruction *Inst, Instruction *CallResult,
|
|
|
|
Function *DirectCallee) {
|
|
|
|
if (Inst->getType()->isVoidTy())
|
|
|
|
return;
|
|
|
|
|
2017-08-28 20:57:00 +02:00
|
|
|
if (Inst->use_empty())
|
|
|
|
return;
|
|
|
|
|
2016-04-28 01:20:27 +02:00
|
|
|
BasicBlock *RetValBB = CallResult->getParent();
|
|
|
|
|
|
|
|
BasicBlock *PHIBB;
|
|
|
|
if (InvokeInst *II = dyn_cast<InvokeInst>(CallResult))
|
|
|
|
RetValBB = II->getNormalDest();
|
|
|
|
|
|
|
|
PHIBB = RetValBB->getSingleSuccessor();
|
|
|
|
if (getCallRetPHINode(PHIBB, Inst))
|
|
|
|
return;
|
|
|
|
|
|
|
|
PHINode *CallRetPHI = PHINode::Create(Inst->getType(), 0);
|
|
|
|
PHIBB->getInstList().push_front(CallRetPHI);
|
|
|
|
Inst->replaceAllUsesWith(CallRetPHI);
|
|
|
|
CallRetPHI->addIncoming(Inst, Inst->getParent());
|
|
|
|
CallRetPHI->addIncoming(CallResult, RetValBB);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function does the actual indirect-call promotion transformation:
|
|
|
|
// For an indirect-call like:
|
|
|
|
// Ret = (*Foo)(Args);
|
|
|
|
// It transforms to:
|
|
|
|
// if (Foo == DirectCallee)
|
|
|
|
// Ret1 = DirectCallee(Args);
|
|
|
|
// else
|
|
|
|
// Ret2 = (*Foo)(Args);
|
|
|
|
// Ret = phi(Ret1, Ret2);
|
|
|
|
// It adds type casts for the args do not match the parameters and the return
|
|
|
|
// value. Branch weights metadata also updated.
|
2017-02-23 23:15:18 +01:00
|
|
|
// If \p AttachProfToDirectCall is true, a prof metadata is attached to the
|
|
|
|
// new direct call to contain \p Count. This is used by SamplePGO inliner to
|
|
|
|
// check callsite hotness.
|
2017-01-24 00:18:24 +01:00
|
|
|
// Returns the promoted direct call instruction.
|
|
|
|
Instruction *llvm::promoteIndirectCall(Instruction *Inst,
|
|
|
|
Function *DirectCallee, uint64_t Count,
|
2017-02-23 23:15:18 +01:00
|
|
|
uint64_t TotalCount,
|
2017-07-27 18:54:15 +02:00
|
|
|
bool AttachProfToDirectCall,
|
|
|
|
OptimizationRemarkEmitter *ORE) {
|
2016-04-28 01:20:27 +02:00
|
|
|
assert(DirectCallee != nullptr);
|
|
|
|
BasicBlock *BB = Inst->getParent();
|
|
|
|
// Just to suppress the non-debug build warning.
|
|
|
|
(void)BB;
|
|
|
|
DEBUG(dbgs() << "\n\n== Basic Block Before ==\n");
|
|
|
|
DEBUG(dbgs() << *BB << "\n");
|
|
|
|
|
|
|
|
BasicBlock *DirectCallBB, *IndirectCallBB, *MergeBB;
|
|
|
|
createIfThenElse(Inst, DirectCallee, Count, TotalCount, &DirectCallBB,
|
|
|
|
&IndirectCallBB, &MergeBB);
|
|
|
|
|
2017-10-06 19:04:55 +02:00
|
|
|
// If the return type of the NewInst is not the same as the Inst, a CastInst
|
|
|
|
// is needed for type casting. Otherwise CastInst is the same as NewInst.
|
|
|
|
Instruction *CastInst = nullptr;
|
2016-04-28 01:20:27 +02:00
|
|
|
Instruction *NewInst =
|
2017-10-06 19:04:55 +02:00
|
|
|
createDirectCallInst(Inst, DirectCallee, DirectCallBB, MergeBB, CastInst);
|
2016-04-28 01:20:27 +02:00
|
|
|
|
2017-02-23 23:15:18 +01:00
|
|
|
if (AttachProfToDirectCall) {
|
|
|
|
SmallVector<uint32_t, 1> Weights;
|
|
|
|
Weights.push_back(Count);
|
|
|
|
MDBuilder MDB(NewInst->getContext());
|
2017-10-06 19:04:55 +02:00
|
|
|
NewInst->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(Weights));
|
2017-02-23 23:15:18 +01:00
|
|
|
}
|
|
|
|
|
2016-04-28 01:20:27 +02:00
|
|
|
// Move Inst from MergeBB to IndirectCallBB.
|
|
|
|
Inst->removeFromParent();
|
|
|
|
IndirectCallBB->getInstList().insert(IndirectCallBB->getFirstInsertionPt(),
|
|
|
|
Inst);
|
|
|
|
|
|
|
|
if (InvokeInst *II = dyn_cast<InvokeInst>(Inst)) {
|
|
|
|
// At this point, the original indirect invoke instruction has the original
|
|
|
|
// UnwindDest and NormalDest. For the direct invoke instruction, the
|
|
|
|
// NormalDest points to MergeBB, and MergeBB jumps to the original
|
|
|
|
// NormalDest. MergeBB might have a new bitcast instruction for the return
|
|
|
|
// value. The PHIs are with the original NormalDest. Since we now have two
|
|
|
|
// incoming edges to NormalDest and UnwindDest, we have to do some fixups.
|
|
|
|
//
|
|
|
|
// UnwindDest will not use the return value. So pass nullptr here.
|
|
|
|
fixupPHINodeForUnwind(Inst, II->getUnwindDest(), MergeBB, IndirectCallBB,
|
|
|
|
DirectCallBB);
|
|
|
|
// We don't need to update the operand from NormalDest for DirectCallBB.
|
|
|
|
// Pass nullptr here.
|
|
|
|
fixupPHINodeForNormalDest(Inst, II->getNormalDest(), MergeBB,
|
2017-10-06 19:04:55 +02:00
|
|
|
IndirectCallBB, CastInst);
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
2017-10-06 19:04:55 +02:00
|
|
|
insertCallRetPHI(Inst, CastInst, DirectCallee);
|
2016-04-28 01:20:27 +02:00
|
|
|
|
|
|
|
DEBUG(dbgs() << "\n== Basic Blocks After ==\n");
|
|
|
|
DEBUG(dbgs() << *BB << *DirectCallBB << *IndirectCallBB << *MergeBB << "\n");
|
|
|
|
|
2017-07-27 18:54:15 +02:00
|
|
|
using namespace ore;
|
|
|
|
if (ORE)
|
|
|
|
ORE->emit(OptimizationRemark(DEBUG_TYPE, "Promoted", Inst)
|
|
|
|
<< "Promote indirect call to " << NV("DirectCallee", DirectCallee)
|
|
|
|
<< " with count " << NV("Count", Count) << " out of "
|
|
|
|
<< NV("TotalCount", TotalCount));
|
2017-01-24 00:18:24 +01:00
|
|
|
return NewInst;
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Promote indirect-call to conditional direct-call for one callsite.
|
|
|
|
uint32_t ICallPromotionFunc::tryToPromote(
|
|
|
|
Instruction *Inst, const std::vector<PromotionCandidate> &Candidates,
|
|
|
|
uint64_t &TotalCount) {
|
|
|
|
uint32_t NumPromoted = 0;
|
|
|
|
|
|
|
|
for (auto &C : Candidates) {
|
|
|
|
uint64_t Count = C.Count;
|
2017-07-27 18:54:15 +02:00
|
|
|
promoteIndirectCall(Inst, C.TargetFunction, Count, TotalCount, SamplePGO,
|
|
|
|
&ORE);
|
2016-04-28 01:20:27 +02:00
|
|
|
assert(TotalCount >= Count);
|
|
|
|
TotalCount -= Count;
|
|
|
|
NumOfPGOICallPromotion++;
|
|
|
|
NumPromoted++;
|
|
|
|
}
|
|
|
|
return NumPromoted;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Traverse all the indirect-call callsite and get the value profile
|
|
|
|
// annotation to perform indirect-call promotion.
|
2017-08-08 22:57:33 +02:00
|
|
|
bool ICallPromotionFunc::processFunction(ProfileSummaryInfo *PSI) {
|
2016-04-28 01:20:27 +02:00
|
|
|
bool Changed = false;
|
2016-07-12 23:13:44 +02:00
|
|
|
ICallPromotionAnalysis ICallAnalysis;
|
2016-04-28 01:20:27 +02:00
|
|
|
for (auto &I : findIndirectCallSites(F)) {
|
2016-07-12 23:13:44 +02:00
|
|
|
uint32_t NumVals, NumCandidates;
|
2016-04-28 01:20:27 +02:00
|
|
|
uint64_t TotalCount;
|
2016-07-12 23:13:44 +02:00
|
|
|
auto ICallProfDataRef = ICallAnalysis.getPromotionCandidatesForInstruction(
|
|
|
|
I, NumVals, TotalCount, NumCandidates);
|
2017-08-08 22:57:33 +02:00
|
|
|
if (!NumCandidates ||
|
|
|
|
(PSI && PSI->hasProfileSummary() && !PSI->isHotCount(TotalCount)))
|
2016-04-28 01:20:27 +02:00
|
|
|
continue;
|
2016-07-12 23:13:44 +02:00
|
|
|
auto PromotionCandidates = getPromotionCandidatesForCallSite(
|
|
|
|
I, ICallProfDataRef, TotalCount, NumCandidates);
|
2016-04-28 01:20:27 +02:00
|
|
|
uint32_t NumPromoted = tryToPromote(I, PromotionCandidates, TotalCount);
|
|
|
|
if (NumPromoted == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Changed = true;
|
|
|
|
// Adjust the MD.prof metadata. First delete the old one.
|
2016-08-11 19:20:18 +02:00
|
|
|
I->setMetadata(LLVMContext::MD_prof, nullptr);
|
2016-04-28 01:20:27 +02:00
|
|
|
// If all promoted, we don't need the MD.prof metadata.
|
|
|
|
if (TotalCount == 0 || NumPromoted == NumVals)
|
|
|
|
continue;
|
|
|
|
// Otherwise we need update with the un-promoted records back.
|
2016-07-12 23:13:44 +02:00
|
|
|
annotateValueSite(*M, *I, ICallProfDataRef.slice(NumPromoted), TotalCount,
|
|
|
|
IPVK_IndirectCallTarget, NumCandidates);
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A wrapper function that does the actual work.
|
2017-08-08 22:57:33 +02:00
|
|
|
static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI,
|
|
|
|
bool InLTO, bool SamplePGO,
|
2017-07-27 18:54:15 +02:00
|
|
|
ModuleAnalysisManager *AM = nullptr) {
|
2016-04-28 01:20:27 +02:00
|
|
|
if (DisableICP)
|
|
|
|
return false;
|
|
|
|
InstrProfSymtab Symtab;
|
2017-06-20 03:38:56 +02:00
|
|
|
if (Error E = Symtab.create(M, InLTO)) {
|
|
|
|
std::string SymtabFailure = toString(std::move(E));
|
|
|
|
DEBUG(dbgs() << "Failed to create symtab: " << SymtabFailure << "\n");
|
|
|
|
(void)SymtabFailure;
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-28 01:20:27 +02:00
|
|
|
bool Changed = false;
|
|
|
|
for (auto &F : M) {
|
|
|
|
if (F.isDeclaration())
|
|
|
|
continue;
|
|
|
|
if (F.hasFnAttribute(Attribute::OptimizeNone))
|
|
|
|
continue;
|
2017-07-27 18:54:15 +02:00
|
|
|
|
|
|
|
std::unique_ptr<OptimizationRemarkEmitter> OwnedORE;
|
|
|
|
OptimizationRemarkEmitter *ORE;
|
|
|
|
if (AM) {
|
|
|
|
auto &FAM =
|
|
|
|
AM->getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
|
|
|
ORE = &FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
|
|
|
|
} else {
|
|
|
|
OwnedORE = make_unique<OptimizationRemarkEmitter>(&F);
|
|
|
|
ORE = OwnedORE.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ICallPromotionFunc ICallPromotion(F, &M, &Symtab, SamplePGO, *ORE);
|
2017-08-08 22:57:33 +02:00
|
|
|
bool FuncChanged = ICallPromotion.processFunction(PSI);
|
2016-04-28 01:20:27 +02:00
|
|
|
if (ICPDUMPAFTER && FuncChanged) {
|
|
|
|
DEBUG(dbgs() << "\n== IR Dump After =="; F.print(dbgs()));
|
|
|
|
DEBUG(dbgs() << "\n");
|
|
|
|
}
|
|
|
|
Changed |= FuncChanged;
|
|
|
|
if (ICPCutOff != 0 && NumOfPGOICallPromotion >= ICPCutOff) {
|
|
|
|
DEBUG(dbgs() << " Stop: Cutoff reached.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2016-05-15 03:04:24 +02:00
|
|
|
bool PGOIndirectCallPromotionLegacyPass::runOnModule(Module &M) {
|
2017-08-08 22:57:33 +02:00
|
|
|
ProfileSummaryInfo *PSI =
|
|
|
|
getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
|
|
|
|
|
2016-04-28 01:20:27 +02:00
|
|
|
// Command-line option has the priority for InLTO.
|
2017-08-08 22:57:33 +02:00
|
|
|
return promoteIndirectCalls(M, PSI, InLTO | ICPLTOMode,
|
2017-02-23 23:15:18 +01:00
|
|
|
SamplePGO | ICPSamplePGOMode);
|
2016-04-28 01:20:27 +02:00
|
|
|
}
|
2016-05-16 18:31:07 +02:00
|
|
|
|
2017-02-23 23:15:18 +01:00
|
|
|
PreservedAnalyses PGOIndirectCallPromotion::run(Module &M,
|
|
|
|
ModuleAnalysisManager &AM) {
|
2017-08-08 22:57:33 +02:00
|
|
|
ProfileSummaryInfo *PSI = &AM.getResult<ProfileSummaryAnalysis>(M);
|
|
|
|
|
|
|
|
if (!promoteIndirectCalls(M, PSI, InLTO | ICPLTOMode,
|
|
|
|
SamplePGO | ICPSamplePGOMode, &AM))
|
2016-05-16 18:31:07 +02:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
|
|
|
|
return PreservedAnalyses::none();
|
|
|
|
}
|