mirror of
https://github.com/intel/llvm.git
synced 2026-01-19 09:31:59 +08:00
Summary: Refactor architecture-specific code out of llvm into llvm-bolt. Introduce MCPlusBuilder, a class that is taking over MCInstrAnalysis responsibilities, i.e. creating, analyzing, and modifying instructions. To access the builder use BC->MIB, i.e. substitute MIA with MIB. MIB is an acronym for MCInstBuilder, that's what MCPlusBuilder used to be. The name stuck, and I find it better than MPB. Instructions are still MCInst, and a bunch of BOLT-specific code still lives in LLVM, but the staff under Target/* is significantly reduced. (cherry picked from FBD7300101)
94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
//===--- Passes/PLTCall.h - PLT call optimization -------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Replace calls to PLT entries with indirect calls against GOT.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "PLTCall.h"
|
|
#include "llvm/Support/Options.h"
|
|
|
|
#define DEBUG_TYPE "bolt-plt"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace opts {
|
|
|
|
extern cl::OptionCategory BoltOptCategory;
|
|
|
|
cl::opt<bolt::PLTCall::OptType>
|
|
PLT("plt",
|
|
cl::desc("optimize PLT calls (requires linking with -znow)"),
|
|
cl::init(bolt::PLTCall::OT_NONE),
|
|
cl::values(clEnumValN(bolt::PLTCall::OT_NONE,
|
|
"none",
|
|
"do not optimize PLT calls"),
|
|
clEnumValN(bolt::PLTCall::OT_HOT,
|
|
"hot",
|
|
"optimize executed (hot) PLT calls"),
|
|
clEnumValN(bolt::PLTCall::OT_ALL,
|
|
"all",
|
|
"optimize all PLT calls")),
|
|
cl::ZeroOrMore,
|
|
cl::cat(BoltOptCategory));
|
|
|
|
}
|
|
|
|
namespace llvm {
|
|
namespace bolt {
|
|
|
|
void PLTCall::runOnFunctions(
|
|
BinaryContext &BC,
|
|
std::map<uint64_t, BinaryFunction> &BFs,
|
|
std::set<uint64_t> &) {
|
|
if (opts::PLT == OT_NONE)
|
|
return;
|
|
|
|
uint64_t NumCallsOptimized = 0;
|
|
for (auto &It : BFs) {
|
|
auto &Function = It.second;
|
|
if (!shouldOptimize(Function))
|
|
continue;
|
|
|
|
if (opts::PLT == OT_HOT &&
|
|
Function.getExecutionCount() == BinaryFunction::COUNT_NO_PROFILE)
|
|
continue;
|
|
|
|
for (auto *BB : Function.layout()) {
|
|
if (opts::PLT == OT_HOT && !BB->getKnownExecutionCount())
|
|
continue;
|
|
|
|
for (auto &Instr : *BB) {
|
|
if (!BC.MIB->isCall(Instr))
|
|
continue;
|
|
const auto *CallSymbol = BC.MIB->getTargetSymbol(Instr);
|
|
if (!CallSymbol)
|
|
continue;
|
|
const auto *CalleeBF = BC.getFunctionForSymbol(CallSymbol);
|
|
if (!CalleeBF || !CalleeBF->isPLTFunction())
|
|
continue;
|
|
BC.MIB->convertCallToIndirectCall(Instr,
|
|
CalleeBF->getPLTSymbol(),
|
|
BC.Ctx.get());
|
|
++NumCallsOptimized;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (NumCallsOptimized) {
|
|
BC.RequiresZNow = true;
|
|
outs() << "BOLT-INFO: " << NumCallsOptimized
|
|
<< " PLT calls in the binary were optimized.\n";
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace bolt
|
|
} // namespace llvm
|