mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
Refactoring. Mainly NFC.
Summary: Eliminated BinaryFunction::getName(). The function was confusing since the name is ambigous. Instead we have BinaryFunction::getPrintName() used for printing and whenever unique string identifier is needed one can use getSymbol()->getName(). In the next diff I'll have a map from MCSymbol to BinaryFunction in BinaryContext to facilitate function lookup from instruction operand expressions. There's one bug fixed where the function was called only under assert() in ICF::foldFunction(). For output we update all symbols associated with the function. At the moment it has no effect on the generated binary but in the future we would like to have all symbols in the symbol table updated. (cherry picked from FBD3704790)
This commit is contained in:
@@ -48,7 +48,7 @@ class BinaryBasicBlock {
|
||||
BinaryFunction *Function;
|
||||
|
||||
/// Label associated with the end of the block in the output binary.
|
||||
MCSymbol *EndLabel{nullptr};
|
||||
const MCSymbol *EndLabel{nullptr};
|
||||
|
||||
/// [Begin, End) address range for this block in the output binary.
|
||||
std::pair<uint64_t, uint64_t> OutputAddressRange{0, 0};
|
||||
@@ -279,7 +279,12 @@ public:
|
||||
}
|
||||
|
||||
/// Return symbol marking the start of this basic block.
|
||||
MCSymbol *getLabel() const {
|
||||
MCSymbol *getLabel() {
|
||||
return Label;
|
||||
}
|
||||
|
||||
/// Return symbol marking the start of this basic block (const version).
|
||||
const MCSymbol *getLabel() const {
|
||||
return Label;
|
||||
}
|
||||
|
||||
@@ -447,12 +452,12 @@ public:
|
||||
}
|
||||
|
||||
/// Sets the symbol pointing to the end of the BB in the output binary.
|
||||
void setEndLabel(MCSymbol *Symbol) {
|
||||
void setEndLabel(const MCSymbol *Symbol) {
|
||||
EndLabel = Symbol;
|
||||
}
|
||||
|
||||
/// Gets the symbol pointing to the end of the BB in the output binary.
|
||||
MCSymbol *getEndLabel() const {
|
||||
const MCSymbol *getEndLabel() const {
|
||||
return EndLabel;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation,
|
||||
bool PrintInstructions) const {
|
||||
StringRef SectionName;
|
||||
Section.getName(SectionName);
|
||||
OS << "Binary Function \"" << getName() << "\" " << Annotation << " {";
|
||||
OS << "Binary Function \"" << *this << "\" " << Annotation << " {";
|
||||
if (Names.size() > 1) {
|
||||
OS << "\n Other names : ";
|
||||
auto Sep = "";
|
||||
@@ -323,7 +323,7 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation,
|
||||
if (FrameInstructions.empty())
|
||||
OS << " <empty>\n";
|
||||
|
||||
OS << "End of Function \"" << getName() << "\"\n\n";
|
||||
OS << "End of Function \"" << *this << "\"\n\n";
|
||||
}
|
||||
|
||||
bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
@@ -340,30 +340,30 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
Labels[0] = Ctx->createTempSymbol("BB0", false);
|
||||
|
||||
auto handleRIPOperand =
|
||||
[&](MCInst &Instruction, uint64_t Address, uint64_t Size) -> bool {
|
||||
uint64_t TargetAddress{0};
|
||||
MCSymbol *TargetSymbol{nullptr};
|
||||
if (!BC.MIA->evaluateRIPOperand(Instruction, Address, Size,
|
||||
TargetAddress)) {
|
||||
DEBUG(dbgs() << "BOLT: rip-relative operand can't be evaluated:\n";
|
||||
BC.InstPrinter->printInst(&Instruction, dbgs(), "", *BC.STI);
|
||||
dbgs() << '\n';
|
||||
Instruction.dump_pretty(dbgs(), BC.InstPrinter.get());
|
||||
dbgs() << '\n';);
|
||||
return false;
|
||||
}
|
||||
// FIXME: check that the address is in data, not in code.
|
||||
if (TargetAddress == 0) {
|
||||
errs() << "BOLT-WARNING: rip-relative operand is zero in function "
|
||||
<< getName() << ". Ignoring function.\n";
|
||||
return false;
|
||||
}
|
||||
TargetSymbol = BC.getOrCreateGlobalSymbol(TargetAddress, "DATAat");
|
||||
BC.MIA->replaceRIPOperandDisp(
|
||||
Instruction, MCOperand::createExpr(MCSymbolRefExpr::create(
|
||||
TargetSymbol, MCSymbolRefExpr::VK_None, *BC.Ctx)));
|
||||
return true;
|
||||
};
|
||||
[&](MCInst &Instruction, uint64_t Address, uint64_t Size) {
|
||||
uint64_t TargetAddress{0};
|
||||
MCSymbol *TargetSymbol{nullptr};
|
||||
if (!BC.MIA->evaluateRIPOperand(Instruction, Address, Size,
|
||||
TargetAddress)) {
|
||||
DEBUG(dbgs() << "BOLT: rip-relative operand can't be evaluated:\n";
|
||||
BC.InstPrinter->printInst(&Instruction, dbgs(), "", *BC.STI);
|
||||
dbgs() << '\n';
|
||||
Instruction.dump_pretty(dbgs(), BC.InstPrinter.get());
|
||||
dbgs() << '\n';);
|
||||
return false;
|
||||
}
|
||||
// FIXME: check that the address is in data, not in code.
|
||||
if (TargetAddress == 0) {
|
||||
errs() << "BOLT-WARNING: rip-relative operand is zero in function "
|
||||
<< *this << ". Ignoring function.\n";
|
||||
return false;
|
||||
}
|
||||
TargetSymbol = BC.getOrCreateGlobalSymbol(TargetAddress, "DATAat");
|
||||
BC.MIA->replaceRIPOperandDisp(
|
||||
Instruction, MCOperand::createExpr(MCSymbolRefExpr::create(
|
||||
TargetSymbol, MCSymbolRefExpr::VK_None, *BC.Ctx)));
|
||||
return true;
|
||||
};
|
||||
|
||||
bool IsSimple = true;
|
||||
for (uint64_t Offset = 0; IsSimple && (Offset < getSize()); ) {
|
||||
@@ -381,7 +381,7 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
errs() << "BOLT-WARNING: unable to disassemble instruction at offset 0x"
|
||||
<< Twine::utohexstr(Offset) << " (address 0x"
|
||||
<< Twine::utohexstr(AbsoluteInstrAddr) << ") in function "
|
||||
<< getName() << '\n';
|
||||
<< *this << '\n';
|
||||
IsSimple = false;
|
||||
break;
|
||||
}
|
||||
@@ -408,12 +408,12 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
if (IsCall && containsAddress(InstructionTarget)) {
|
||||
if (InstructionTarget == getAddress()) {
|
||||
// Recursive call.
|
||||
TargetSymbol = Ctx->getOrCreateSymbol(getName());
|
||||
TargetSymbol = getSymbol();
|
||||
} else {
|
||||
// Possibly an old-style PIC code
|
||||
errs() << "BOLT: internal call detected at 0x"
|
||||
<< Twine::utohexstr(AbsoluteInstrAddr)
|
||||
<< " in function " << getName() << ". Skipping.\n";
|
||||
<< " in function " << *this << ". Skipping.\n";
|
||||
IsSimple = false;
|
||||
}
|
||||
}
|
||||
@@ -448,12 +448,13 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
if (!MIA->convertJmpToTailCall(Instruction)) {
|
||||
assert(IsCondBranch && "unknown tail call instruction");
|
||||
errs() << "BOLT-WARNING: conditional tail call detected in "
|
||||
<< "function " << getName() << " at 0x"
|
||||
<< "function " << *this << " at 0x"
|
||||
<< Twine::utohexstr(AbsoluteInstrAddr) << ".\n";
|
||||
}
|
||||
// TODO: A better way to do this would be using annotations for
|
||||
// MCInst objects.
|
||||
TailCallOffsets.emplace(std::make_pair(Offset, InstructionTarget));
|
||||
TailCallOffsets.emplace(std::make_pair(Offset,
|
||||
InstructionTarget));
|
||||
IsCall = true;
|
||||
}
|
||||
|
||||
@@ -464,7 +465,7 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
// from the libraries. In reality more often than not it is
|
||||
// unreachable code, but we don't know it and have to emit calls
|
||||
// to 0 which make LLVM JIT unhappy.
|
||||
errs() << "BOLT-WARNING: Function " << getName()
|
||||
errs() << "BOLT-WARNING: Function " << *this
|
||||
<< " has a call to address zero. Ignoring function.\n";
|
||||
IsSimple = false;
|
||||
}
|
||||
@@ -491,7 +492,7 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
if (MIA->isIndirectBranch(Instruction)) {
|
||||
DEBUG(dbgs() << "BOLT-WARNING: indirect branch detected at 0x"
|
||||
<< Twine::utohexstr(AbsoluteInstrAddr)
|
||||
<< ". Skipping function " << getName() << ".\n");
|
||||
<< ". Skipping function " << *this << ".\n");
|
||||
IsSimple = false;
|
||||
}
|
||||
// Indirect call. We only need to fix it if the operand is RIP-relative
|
||||
@@ -499,7 +500,7 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
if (!handleRIPOperand(Instruction, AbsoluteInstrAddr, Size)) {
|
||||
errs() << "BOLT-WARNING: cannot handle RIP operand at 0x"
|
||||
<< Twine::utohexstr(AbsoluteInstrAddr)
|
||||
<< ". Skipping function " << getName() << ".\n";
|
||||
<< ". Skipping function " << *this << ".\n";
|
||||
IsSimple = false;
|
||||
}
|
||||
}
|
||||
@@ -509,7 +510,7 @@ bool BinaryFunction::disassemble(ArrayRef<uint8_t> FunctionData) {
|
||||
if (!handleRIPOperand(Instruction, AbsoluteInstrAddr, Size)) {
|
||||
errs() << "BOLT-WARNING: cannot handle RIP operand at 0x"
|
||||
<< Twine::utohexstr(AbsoluteInstrAddr)
|
||||
<< ". Skipping function " << getName() << ".\n";
|
||||
<< ". Skipping function " << *this << ".\n";
|
||||
IsSimple = false;
|
||||
}
|
||||
}
|
||||
@@ -552,7 +553,7 @@ void BinaryFunction::addLandingPads(const unsigned StartIndex,
|
||||
const unsigned NumBlocks) {
|
||||
for (auto *BB : BasicBlocks) {
|
||||
if (LandingPads.find(BB->getLabel()) != LandingPads.end()) {
|
||||
MCSymbol *LP = BB->getLabel();
|
||||
const MCSymbol *LP = BB->getLabel();
|
||||
for (unsigned I : LPToBBIndex[LP]) {
|
||||
assert(I < BasicBlocks.size());
|
||||
BinaryBasicBlock *ThrowBB = BasicBlocks[I];
|
||||
@@ -595,7 +596,7 @@ bool BinaryFunction::buildCFG() {
|
||||
|
||||
auto BranchDataOrErr = BC.DR.getFuncBranchData(getNames());
|
||||
if (!BranchDataOrErr) {
|
||||
DEBUG(dbgs() << "no branch data found for \"" << getName() << "\"\n");
|
||||
DEBUG(dbgs() << "no branch data found for \"" << *this << "\"\n");
|
||||
} else {
|
||||
ExecutionCount = BranchDataOrErr->ExecutionCount;
|
||||
}
|
||||
@@ -1000,7 +1001,7 @@ void BinaryFunction::evaluateProfileData(const FuncBranchData &BranchData) {
|
||||
<< format("%.1f%%", ProfileMatchRatio * 100.0f) << " ("
|
||||
<< (LocalProfileBranches.size() - OrphanBranches.size()) << '/'
|
||||
<< LocalProfileBranches.size() << ") for function "
|
||||
<< getName() << '\n';
|
||||
<< *this << '\n';
|
||||
DEBUG(
|
||||
for (auto &OBranch : OrphanBranches)
|
||||
errs() << "\t0x" << Twine::utohexstr(OBranch.first) << " -> 0x"
|
||||
@@ -1270,7 +1271,7 @@ void BinaryFunction::annotateCFIState() {
|
||||
bool BinaryFunction::fixCFIState() {
|
||||
auto Sep = "";
|
||||
DEBUG(dbgs() << "Trying to fix CFI states for each BB after reordering.\n");
|
||||
DEBUG(dbgs() << "This is the list of CFI states for each BB of " << getName()
|
||||
DEBUG(dbgs() << "This is the list of CFI states for each BB of " << *this
|
||||
<< ": ");
|
||||
|
||||
auto replayCFIInstrs =
|
||||
@@ -1301,7 +1302,7 @@ bool BinaryFunction::fixCFIState() {
|
||||
if (NestedLevel != 0) {
|
||||
errs() << "BOLT-WARNING: CFI rewriter detected nested CFI state while"
|
||||
<< " replaying CFI instructions for BB " << InBB->getName()
|
||||
<< " in function " << getName() << '\n';
|
||||
<< " in function " << *this << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1379,7 +1380,7 @@ bool BinaryFunction::fixCFIState() {
|
||||
if (StackOffset != 0) {
|
||||
errs() << " BOLT-WARNING: not possible to remember/recover state"
|
||||
<< " without corrupting CFI state stack in function "
|
||||
<< getName() << "\n";
|
||||
<< *this << "\n";
|
||||
return false;
|
||||
}
|
||||
} else if (BBCFIState[BBIndex] > State) {
|
||||
@@ -1416,11 +1417,11 @@ void BinaryFunction::modifyLayout(LayoutType Type, bool MinBranchClusters,
|
||||
}
|
||||
else if (BasicBlocksLayout.size() <= FUNC_SIZE_THRESHOLD) {
|
||||
// Work on optimal solution if problem is small enough
|
||||
DEBUG(dbgs() << "finding optimal block layout for " << getName() << "\n");
|
||||
DEBUG(dbgs() << "finding optimal block layout for " << *this << "\n");
|
||||
Algo.reset(new OptimalReorderAlgorithm());
|
||||
}
|
||||
else {
|
||||
DEBUG(dbgs() << "running block layout heuristics on " << getName() << "\n");
|
||||
DEBUG(dbgs() << "running block layout heuristics on " << *this << "\n");
|
||||
|
||||
std::unique_ptr<ClusterAlgorithm> CAlgo;
|
||||
if (MinBranchClusters)
|
||||
@@ -1482,7 +1483,7 @@ std::string constructFilename(std::string Filename,
|
||||
}
|
||||
|
||||
void BinaryFunction::dumpGraph(raw_ostream& OS) const {
|
||||
OS << "strict digraph \"" << getName() << "\" {\n";
|
||||
OS << "strict digraph \"" << *this << "\" {\n";
|
||||
for (auto *BB : BasicBlocks) {
|
||||
for (auto *Succ : BB->successors()) {
|
||||
OS << "\"" << BB->getName() << "\" -> "
|
||||
@@ -1511,7 +1512,7 @@ void BinaryFunction::viewGraph() const {
|
||||
}
|
||||
|
||||
void BinaryFunction::dumpGraphForPass(std::string Annotation) const {
|
||||
auto Filename = constructFilename(getName(), Annotation, ".dot");
|
||||
auto Filename = constructFilename(getPrintName(), Annotation, ".dot");
|
||||
dbgs() << "BOLT-DEBUG: Dumping CFG to " << Filename << "\n";
|
||||
dumpGraphToFile(Filename);
|
||||
}
|
||||
@@ -1607,7 +1608,7 @@ void BinaryFunction::fixBranches() {
|
||||
// invert this conditional branch logic so we can make this a fallthrough.
|
||||
if (TBB == FT && !HotColdBorder) {
|
||||
if (OldFT == nullptr) {
|
||||
errs() << "BOLT-ERROR: malformed CFG for function " << getName()
|
||||
errs() << "BOLT-ERROR: malformed CFG for function " << *this
|
||||
<< " in basic block " << BB->getName() << '\n';
|
||||
}
|
||||
assert(OldFT != nullptr && "malformed CFG");
|
||||
@@ -2136,8 +2137,8 @@ bool BinaryFunction::isIdenticalWith(const BinaryFunction &BF) const {
|
||||
}
|
||||
|
||||
if (PseudosDiffer) {
|
||||
errs() << "BOLT-WARNING: functions " << getName() << " and ";
|
||||
errs() << BF.getName() << " are identical, but have different";
|
||||
errs() << "BOLT-WARNING: functions " << *this << " and ";
|
||||
errs() << BF << " are identical, but have different";
|
||||
errs() << " pseudo instruction sequences.\n";
|
||||
}
|
||||
|
||||
@@ -2308,7 +2309,7 @@ void BinaryFunction::calculateLoopInfo() {
|
||||
}
|
||||
|
||||
void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
|
||||
OS << "Loop Info for Function \"" << getName() << "\"";
|
||||
OS << "Loop Info for Function \"" << *this << "\"";
|
||||
if (hasValidProfile()) {
|
||||
OS << " (count: " << getExecutionCount() << ")";
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
/// Alignment requirements for the function.
|
||||
uint64_t Alignment{1};
|
||||
|
||||
MCSymbol *PersonalityFunction{nullptr};
|
||||
const MCSymbol *PersonalityFunction{nullptr};
|
||||
uint8_t PersonalityEncoding{dwarf::DW_EH_PE_sdata4 | dwarf::DW_EH_PE_pcrel};
|
||||
|
||||
BinaryContext &BC;
|
||||
@@ -183,7 +183,7 @@ private:
|
||||
uint64_t LSDAAddress{0};
|
||||
|
||||
/// Landing pads for the function.
|
||||
std::set<MCSymbol *> LandingPads;
|
||||
std::set<const MCSymbol *> LandingPads;
|
||||
|
||||
/// Associated DIEs in the .debug_info section with their respective CUs.
|
||||
/// There can be multiple because of identical code folding.
|
||||
@@ -340,7 +340,7 @@ private:
|
||||
std::vector<uint32_t> BBCFIState;
|
||||
|
||||
/// Symbol in the output.
|
||||
const MCSymbol *OutputSymbol;
|
||||
MCSymbol *OutputSymbol;
|
||||
|
||||
/// Symbol at the end of the function.
|
||||
MCSymbol *FunctionEndLabel{nullptr};
|
||||
@@ -457,7 +457,9 @@ public:
|
||||
Names({Name}), Symbol(Symbol), Section(Section), Address(Address),
|
||||
IdenticalFunctionAddress(Address), Size(Size), BC(BC), IsSimple(IsSimple),
|
||||
CodeSectionName(".text." + Name), FunctionNumber(++Count)
|
||||
{}
|
||||
{
|
||||
OutputSymbol = BC.Ctx->getOrCreateSymbol(Name);
|
||||
}
|
||||
|
||||
/// Modify code layout making necessary adjustments to instructions at the
|
||||
/// end of basic blocks.
|
||||
@@ -531,7 +533,7 @@ public:
|
||||
///
|
||||
/// We pick the last name from the list to match the name of the function
|
||||
/// in profile data for easier manual analysis.
|
||||
std::string getName() const {
|
||||
std::string getPrintName() const {
|
||||
return Names.size() == 1 ?
|
||||
Names.back() :
|
||||
(Names.back() + "(*" + std::to_string(Names.size()) + ")");
|
||||
@@ -580,8 +582,15 @@ public:
|
||||
return MaxSize;
|
||||
}
|
||||
|
||||
/// Return MC symbol associtated with the function in the output object.
|
||||
const MCSymbol *getOutputSymbol() const {
|
||||
/// Return MC symbol associtated with the function.
|
||||
/// All references to the function should use this symbol.
|
||||
MCSymbol *getSymbol() {
|
||||
return OutputSymbol;
|
||||
}
|
||||
|
||||
/// Return MC symbol associtated with the function (const version).
|
||||
/// All references to the function should use this symbol.
|
||||
const MCSymbol *getSymbol() const {
|
||||
return OutputSymbol;
|
||||
}
|
||||
|
||||
@@ -620,7 +629,7 @@ public:
|
||||
return UsesGnuArgsSize;
|
||||
}
|
||||
|
||||
MCSymbol *getPersonalityFunction() const {
|
||||
const MCSymbol *getPersonalityFunction() const {
|
||||
return PersonalityFunction;
|
||||
}
|
||||
|
||||
@@ -821,11 +830,6 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
BinaryFunction &setOutputSymbol(const MCSymbol *Symbol) {
|
||||
OutputSymbol = Symbol;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BinaryFunction &setSimple(bool Simple) {
|
||||
IsSimple = Simple;
|
||||
return *this;
|
||||
@@ -1080,19 +1084,16 @@ public:
|
||||
uint64_t ImageAddress{0};
|
||||
uint64_t ImageSize{0};
|
||||
uint64_t FileOffset{0};
|
||||
const MCSymbol *OutputSymbol{nullptr};
|
||||
public:
|
||||
uint64_t getAddress() const { return Address; }
|
||||
uint64_t getImageAddress() const { return ImageAddress; }
|
||||
uint64_t getImageSize() const { return ImageSize; }
|
||||
uint64_t getFileOffset() const { return FileOffset; }
|
||||
const MCSymbol *getOutputSymbol() const { return OutputSymbol; }
|
||||
|
||||
void setAddress(uint64_t VAddress) { Address = VAddress; }
|
||||
void setImageAddress(uint64_t Address) { ImageAddress = Address; }
|
||||
void setImageSize(uint64_t Size) { ImageSize = Size; }
|
||||
void setFileOffset(uint64_t Offset) { FileOffset = Offset; }
|
||||
void setOutputSymbol(const MCSymbol *Symbol) { OutputSymbol = Symbol; }
|
||||
};
|
||||
|
||||
/// Cold fragment of the function.
|
||||
@@ -1103,6 +1104,12 @@ public:
|
||||
const FragmentInfo &cold() const { return ColdFragment; }
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS,
|
||||
const BinaryFunction &Function) {
|
||||
OS << Function.getPrintName();
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS,
|
||||
const BinaryFunction::State State) {
|
||||
switch (State) {
|
||||
|
||||
@@ -73,24 +73,24 @@ void OptimizeBodylessFunctions::analyze(
|
||||
|
||||
auto &BB = *BF.begin();
|
||||
const auto &FirstInst = *BB.begin();
|
||||
|
||||
if (!BC.MIA->isTailCall(FirstInst))
|
||||
return;
|
||||
|
||||
auto &Op1 = FirstInst.getOperand(0);
|
||||
if (!Op1.isExpr())
|
||||
return;
|
||||
auto Expr = dyn_cast<MCSymbolRefExpr>(Op1.getExpr());
|
||||
if (!Expr)
|
||||
return;
|
||||
auto AddressIt = BC.GlobalSymbols.find(Expr->getSymbol().getName());
|
||||
if (AddressIt == BC.GlobalSymbols.end())
|
||||
return;
|
||||
auto CalleeIt = BFs.find(AddressIt->second);
|
||||
if (CalleeIt == BFs.end())
|
||||
return;
|
||||
|
||||
if (auto Expr = dyn_cast<MCSymbolRefExpr>(Op1.getExpr())) {
|
||||
auto AddressIt = BC.GlobalSymbols.find(Expr->getSymbol().getName());
|
||||
if (AddressIt != BC.GlobalSymbols.end()) {
|
||||
auto CalleeIt = BFs.find(AddressIt->second);
|
||||
if (CalleeIt != BFs.end()) {
|
||||
assert(Expr->getSymbol().getName() == CalleeIt->second.getName());
|
||||
EquivalentCallTarget[BF.getName()] = &CalleeIt->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(&Expr->getSymbol() == CalleeIt->second.getSymbol());
|
||||
|
||||
EquivalentCallTarget[BF.getSymbol()->getName()] = &CalleeIt->second;
|
||||
}
|
||||
|
||||
void OptimizeBodylessFunctions::optimizeCalls(BinaryFunction &BF,
|
||||
@@ -99,31 +99,30 @@ void OptimizeBodylessFunctions::optimizeCalls(BinaryFunction &BF,
|
||||
for (auto InstIt = (*BBIt).begin(), InstEnd = (*BBIt).end();
|
||||
InstIt != InstEnd; ++InstIt) {
|
||||
auto &Inst = *InstIt;
|
||||
if (BC.MIA->isCall(Inst)) {
|
||||
auto &Op1 = Inst.getOperand(0);
|
||||
if (Op1.isExpr()) {
|
||||
if (auto Expr = dyn_cast<MCSymbolRefExpr>(Op1.getExpr())) {
|
||||
auto OriginalTarget = Expr->getSymbol().getName();
|
||||
auto Target = OriginalTarget;
|
||||
// Iteratively update target since we could have f1() calling f2()
|
||||
// calling f3() calling f4() and we want to output f1() directly
|
||||
// calling f4().
|
||||
while (EquivalentCallTarget.count(Target)) {
|
||||
Target = EquivalentCallTarget.find(Target)->second->getName();
|
||||
}
|
||||
if (Target != OriginalTarget) {
|
||||
DEBUG(errs() << "BOLT-DEBUG: Optimizing " << BF.getName()
|
||||
<< ": replacing call to "
|
||||
<< OriginalTarget
|
||||
<< " by call to " << Target << "\n");
|
||||
Inst.clear();
|
||||
Inst.addOperand(MCOperand::createExpr(
|
||||
MCSymbolRefExpr::create(
|
||||
BC.Ctx->getOrCreateSymbol(Target), *BC.Ctx)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!BC.MIA->isCall(Inst))
|
||||
continue;
|
||||
auto &Op1 = Inst.getOperand(0);
|
||||
if (!Op1.isExpr())
|
||||
continue;
|
||||
auto Expr = dyn_cast<MCSymbolRefExpr>(Op1.getExpr());
|
||||
if (!Expr)
|
||||
continue;
|
||||
auto *OriginalTarget = &Expr->getSymbol();
|
||||
auto *Target = OriginalTarget;
|
||||
// Iteratively update target since we could have f1() calling f2()
|
||||
// calling f3() calling f4() and we want to output f1() directly
|
||||
// calling f4().
|
||||
while (EquivalentCallTarget.count(Target->getName())) {
|
||||
Target =
|
||||
EquivalentCallTarget.find(Target->getName())->second->getSymbol();
|
||||
}
|
||||
if (Target == OriginalTarget)
|
||||
continue;
|
||||
DEBUG(errs() << "BOLT-DEBUG: Optimizing " << (*BBIt).getName()
|
||||
<< " in " << BF
|
||||
<< ": replacing call to " << OriginalTarget->getName()
|
||||
<< " by call to " << Target->getName() << "\n");
|
||||
BC.MIA->replaceCallTargetOperand(Inst, Target, BC.Ctx.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +163,7 @@ void InlineSmallFunctions::findInliningCandidates(
|
||||
BB.size() <= kMaxInstructions &&
|
||||
BC.MIA->isReturn(LastInstruction) &&
|
||||
!BC.MIA->isTailCall(LastInstruction)) {
|
||||
InliningCandidates.insert(Function.getName());
|
||||
InliningCandidates.insert(Function.getSymbol()->getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +185,7 @@ void InlineSmallFunctions::findInliningCandidatesAggressive(
|
||||
const auto &Function = BFIt.second;
|
||||
if (!Function.isSimple() ||
|
||||
!opts::shouldProcess(Function) ||
|
||||
OverwrittenFunctions.count(Function.getName()) ||
|
||||
OverwrittenFunctions.count(Function.getSymbol()->getName()) ||
|
||||
Function.hasEHRanges())
|
||||
continue;
|
||||
uint64_t FunctionSize = 0;
|
||||
@@ -206,7 +205,7 @@ void InlineSmallFunctions::findInliningCandidatesAggressive(
|
||||
}
|
||||
}
|
||||
if (!FoundCFI)
|
||||
InliningCandidates.insert(Function.getName());
|
||||
InliningCandidates.insert(Function.getSymbol()->getName());
|
||||
}
|
||||
|
||||
DEBUG(errs() << "BOLT-DEBUG: " << InliningCandidates.size()
|
||||
@@ -573,7 +572,7 @@ bool InlineSmallFunctions::inlineCallsInFunction(
|
||||
if (FunctionIt != FunctionByName.end()) {
|
||||
auto &TargetFunction = *FunctionIt->second;
|
||||
bool CallToInlineableFunction =
|
||||
InliningCandidates.count(TargetFunction.getName());
|
||||
InliningCandidates.count(TargetFunction.getSymbol()->getName());
|
||||
|
||||
totalInlineableCalls +=
|
||||
CallToInlineableFunction * BB->getExecutionCount();
|
||||
@@ -585,8 +584,8 @@ bool InlineSmallFunctions::inlineCallsInFunction(
|
||||
inlineCall(BC, *BB, &Inst, *TargetFunction.begin());
|
||||
DidInlining = true;
|
||||
DEBUG(errs() << "BOLT-DEBUG: Inlining call to "
|
||||
<< TargetFunction.getName() << " in "
|
||||
<< Function.getName() << "\n");
|
||||
<< TargetFunction << " in "
|
||||
<< Function << "\n");
|
||||
InstIt = NextInstIt;
|
||||
ExtraSize += TargetFunction.getSize();
|
||||
inlinedDynamicCalls += BB->getExecutionCount();
|
||||
@@ -642,7 +641,7 @@ bool InlineSmallFunctions::inlineCallsInFunctionAggressive(
|
||||
if (FunctionIt != FunctionByName.end()) {
|
||||
auto &TargetFunction = *FunctionIt->second;
|
||||
bool CallToInlineableFunction =
|
||||
InliningCandidates.count(TargetFunction.getName());
|
||||
InliningCandidates.count(TargetFunction.getSymbol()->getName());
|
||||
|
||||
totalInlineableCalls +=
|
||||
CallToInlineableFunction * BB->getExecutionCount();
|
||||
@@ -656,8 +655,8 @@ bool InlineSmallFunctions::inlineCallsInFunctionAggressive(
|
||||
inlineCall(BC, Function, BB, InstIndex, TargetFunction);
|
||||
DidInlining = true;
|
||||
DEBUG(errs() << "BOLT-DEBUG: Inlining call to "
|
||||
<< TargetFunction.getName() << " in "
|
||||
<< Function.getName() << "\n");
|
||||
<< TargetFunction << " in "
|
||||
<< Function << "\n");
|
||||
InstIndex = NextBB == BB ? NextInstIndex : BB->size();
|
||||
InstIt = NextBB == BB ? BB->begin() + NextInstIndex : BB->end();
|
||||
ExtraSize += TargetFunction.getSize();
|
||||
@@ -680,7 +679,7 @@ void InlineSmallFunctions::runOnFunctions(
|
||||
std::map<uint64_t, BinaryFunction> &BFs,
|
||||
std::set<uint64_t> &) {
|
||||
for (auto &It : BFs) {
|
||||
FunctionByName[It.second.getName()] = &It.second;
|
||||
FunctionByName[It.second.getSymbol()->getName()] = &It.second;
|
||||
}
|
||||
|
||||
findInliningCandidates(BC, BFs);
|
||||
@@ -749,8 +748,7 @@ void EliminateUnreachableBlocks::runOnFunction(BinaryFunction& Function) {
|
||||
auto Count = Function.eraseDeadBBs(Reachable);
|
||||
if (Count) {
|
||||
DEBUG(dbgs() << "BOLT: Removed " << Count
|
||||
<< " dead basic block(s) in function "
|
||||
<< Function.getName() << '\n');
|
||||
<< " dead basic block(s) in function " << Function << '\n');
|
||||
}
|
||||
|
||||
if (opts::PrintAll || opts::PrintUCE)
|
||||
@@ -818,7 +816,7 @@ void FixupFunctions::runOnFunctions(
|
||||
// Fix the CFI state.
|
||||
if (!Function.fixCFIState()) {
|
||||
errs() << "BOLT-WARNING: unable to fix CFI state for function "
|
||||
<< Function.getName() << ". Skipping.\n";
|
||||
<< Function << ". Skipping.\n";
|
||||
Function.setSimple(false);
|
||||
continue;
|
||||
}
|
||||
@@ -882,7 +880,8 @@ bool SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
|
||||
|
||||
// Lookup the address for the current function and
|
||||
// the tail call target.
|
||||
auto const FnAddress = BC.GlobalSymbols.find(BF.getName());
|
||||
auto const FnAddress =
|
||||
BC.GlobalSymbols.find(BF.getSymbol()->getName());
|
||||
auto const TailAddress = BC.GlobalSymbols.find(TailTarget.getName());
|
||||
if (FnAddress == BC.GlobalSymbols.end() ||
|
||||
TailAddress == BC.GlobalSymbols.end()) {
|
||||
@@ -908,7 +907,7 @@ bool SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
|
||||
// if there are no other users.
|
||||
BB->removeSuccessor(CondTargetBB);
|
||||
DEBUG(dbgs() << "patched " << (isForward ? "(fwd)" : "(back)")
|
||||
<< " tail call in " << BF.getName() << ".\n";);
|
||||
<< " tail call in " << BF << ".\n";);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -918,7 +917,7 @@ bool SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
|
||||
DEBUG(dbgs() << "BOLT: patched " << NumLocalPatchedTailCalls
|
||||
<< " tail calls (" << NumOrigForwardBranches << " forward)"
|
||||
<< " from a total of " << NumLocalTailCalls
|
||||
<< " in function " << BF.getName() << "\n";);
|
||||
<< " in function " << BF << "\n";);
|
||||
|
||||
return NumLocalPatchedTailCalls > 0;
|
||||
}
|
||||
@@ -1016,7 +1015,7 @@ bool SimplifyRODataLoads::simplifyRODataLoads(
|
||||
|
||||
// Look up the symbol address in the global symbols map of the binary
|
||||
// context object.
|
||||
auto GI = BC.GlobalSymbols.find(DisplSymbol.getName().str());
|
||||
auto GI = BC.GlobalSymbols.find(DisplSymbol.getName());
|
||||
if (GI == BC.GlobalSymbols.end())
|
||||
continue;
|
||||
TargetAddress = GI->second;
|
||||
@@ -1179,12 +1178,10 @@ void IdenticalCodeFolding::foldFunction(
|
||||
MCInst &CallInst = CallBB->getInstructionAtIndex(CS.InstrIndex);
|
||||
|
||||
// Replace call target with BFToReplaceWith.
|
||||
MCOperand CallTargetOp =
|
||||
MCOperand::createExpr(
|
||||
MCSymbolRefExpr::create(
|
||||
SymbolToReplaceWith, MCSymbolRefExpr::VK_None, *BC.Ctx));
|
||||
assert(BC.MIA->replaceCallTargetOperand(CallInst, CallTargetOp) &&
|
||||
"unexpected call target prevented the replacement");
|
||||
auto Success = BC.MIA->replaceCallTargetOperand(CallInst,
|
||||
SymbolToReplaceWith,
|
||||
BC.Ctx.get());
|
||||
assert(Success && "unexpected call target prevented the replacement");
|
||||
|
||||
// Add this call site to the callers of BFToReplaceWith.
|
||||
BFToReplaceWithCallers.emplace_back(CS);
|
||||
|
||||
@@ -271,7 +271,7 @@ void RewriteInstance::updateDebugLineInfoForNonSimpleFunctions() {
|
||||
OutputLineTable.addLineEntry(MCLineEntry{nullptr, Loc},
|
||||
FunctionSection);
|
||||
} else {
|
||||
DEBUG(errs() << "BOLT-DEBUG: Function " << Function.getName()
|
||||
DEBUG(errs() << "BOLT-DEBUG: Function " << Function
|
||||
<< " has no associated line number information.\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ void BasicBlockOffsetRanges::addAddressRange(BinaryFunction &Function,
|
||||
BeginAddress - Function.getAddress());
|
||||
if (!FirstBB) {
|
||||
errs() << "BOLT-WARNING: no basic blocks in function "
|
||||
<< Function.getName() << " intersect with debug range [0x"
|
||||
<< Function << " intersect with debug range [0x"
|
||||
<< Twine::utohexstr(BeginAddress) << ", 0x"
|
||||
<< Twine::utohexstr(EndAddress) << ")\n";
|
||||
return;
|
||||
|
||||
@@ -122,7 +122,7 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
|
||||
|
||||
if (opts::PrintExceptions) {
|
||||
errs() << "[LSDA at 0x" << Twine::utohexstr(getLSDAAddress())
|
||||
<< " for function " << getName() << "]:\n";
|
||||
<< " for function " << *this << "]:\n";
|
||||
errs() << "LPStart Encoding = " << (unsigned)LPStartEncoding << '\n';
|
||||
errs() << "LPStart = 0x" << Twine::utohexstr(LPStart) << '\n';
|
||||
errs() << "TType Encoding = " << (unsigned)TTypeEncoding << '\n';
|
||||
@@ -173,7 +173,7 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
|
||||
if (Instructions.find(LandingPad) == Instructions.end()) {
|
||||
errs() << "BOLT-WARNING: landing pad " << Twine::utohexstr(LandingPad)
|
||||
<< " not pointing to an instruction in function "
|
||||
<< getName() << " - ignoring.\n";
|
||||
<< *this << " - ignoring.\n";
|
||||
} else {
|
||||
auto Label = Labels.find(LandingPad);
|
||||
if (Label != Labels.end()) {
|
||||
@@ -331,7 +331,7 @@ void BinaryFunction::updateEHRanges() {
|
||||
continue;
|
||||
|
||||
// Same symbol is used for the beginning and the end of the range.
|
||||
MCSymbol *EHSymbol{nullptr};
|
||||
const MCSymbol *EHSymbol{nullptr};
|
||||
if (BB->isCold()) {
|
||||
// If we see a label in the cold block, it means we have to close
|
||||
// the range using function end symbol.
|
||||
@@ -458,13 +458,13 @@ void BinaryFunction::emitLSDA(MCStreamer *Streamer) {
|
||||
assert(BeginLabel && "start EH label expected");
|
||||
assert(EndLabel && "end EH label expected");
|
||||
|
||||
Streamer->emitAbsoluteSymbolDiff(BeginLabel, getOutputSymbol(), 4);
|
||||
Streamer->emitAbsoluteSymbolDiff(BeginLabel, getSymbol(), 4);
|
||||
Streamer->emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
|
||||
|
||||
if (!CallSite.LP) {
|
||||
Streamer->EmitIntValue(0, 4);
|
||||
} else {
|
||||
Streamer->emitAbsoluteSymbolDiff(CallSite.LP, getOutputSymbol(), 4);
|
||||
Streamer->emitAbsoluteSymbolDiff(CallSite.LP, getSymbol(), 4);
|
||||
}
|
||||
|
||||
Streamer->EmitULEB128IntValue(CallSite.Action);
|
||||
@@ -495,7 +495,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
|
||||
const FDE &CurFDE = *I->second;
|
||||
if (Function.getSize() != CurFDE.getAddressRange()) {
|
||||
errs() << "BOLT-WARNING: CFI information size mismatch for function \""
|
||||
<< Function.getName() << "\""
|
||||
<< Function << "\""
|
||||
<< format(": Function size is %dB, CFI covers "
|
||||
"%dB\n",
|
||||
Function.getSize(), CurFDE.getAddressRange());
|
||||
|
||||
@@ -605,7 +605,7 @@ void RewriteInstance::run() {
|
||||
auto FunctionIt = BinaryFunctions.find(Address);
|
||||
assert(FunctionIt != BinaryFunctions.end() &&
|
||||
"Invalid large function address.");
|
||||
errs() << "BOLT-WARNING: Function " << FunctionIt->second.getName()
|
||||
errs() << "BOLT-WARNING: Function " << FunctionIt->second
|
||||
<< " is larger than its orginal size: emitting again marking it "
|
||||
<< "as not simple.\n";
|
||||
FunctionIt->second.setSimple(false);
|
||||
@@ -787,7 +787,7 @@ void RewriteInstance::discoverFileObjects() {
|
||||
if (SymbolSize != BFI->second.getSize()) {
|
||||
errs() << "BOLT-WARNING: size mismatch for duplicate entries "
|
||||
<< UniqueName << ':' << SymbolSize << " and "
|
||||
<< BFI->second.getName() << ':' << BFI->second.getSize() << '\n';
|
||||
<< BFI->second << ':' << BFI->second.getSize() << '\n';
|
||||
}
|
||||
BFI->second.addAlternativeName(UniqueName);
|
||||
} else {
|
||||
@@ -810,16 +810,6 @@ void RewriteInstance::discoverFileObjects() {
|
||||
"wish to proceed, use -allow-stripped option.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Register the final names of functions with multiple names with BinaryContext
|
||||
// data structures.
|
||||
for (auto &BFI : BinaryFunctions) {
|
||||
uint64_t Address = BFI.first;
|
||||
const BinaryFunction &BF = BFI.second;
|
||||
auto AI = BC->GlobalSymbols.find(BF.getName());
|
||||
if (AI == BC->GlobalSymbols.end())
|
||||
BC->registerNameAtAddress(BF.getName(), Address);
|
||||
}
|
||||
}
|
||||
|
||||
void RewriteInstance::readSpecialSections() {
|
||||
@@ -889,7 +879,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
|
||||
if (!opts::shouldProcess(Function)) {
|
||||
DEBUG(dbgs() << "BOLT: skipping processing function "
|
||||
<< Function.getName() << " per user request.\n");
|
||||
<< Function << " per user request.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -901,7 +891,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
if (!Section.isText() || Section.isVirtual() || !Section.getSize()) {
|
||||
// When could it happen?
|
||||
errs() << "BOLT: corresponding section is non-executable or empty "
|
||||
<< "for function " << Function.getName();
|
||||
<< "for function " << Function;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -920,7 +910,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
uint64_t SectionEnd = Function.getSection().getAddress() +
|
||||
Function.getSection().getSize();
|
||||
if (SectionEnd > SymRefI->first) {
|
||||
errs() << "BOLT-WARNING: symbol after " << Function.getName()
|
||||
errs() << "BOLT-WARNING: symbol after " << Function
|
||||
<< " should not be in the same section.\n";
|
||||
MaxSize = 0;
|
||||
} else {
|
||||
@@ -930,7 +920,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
|
||||
if (MaxSize < Function.getSize()) {
|
||||
errs() << "BOLT-WARNING: symbol seen in the middle of the function "
|
||||
<< Function.getName() << ". Skipping.\n";
|
||||
<< Function << ". Skipping.\n";
|
||||
Function.setSimple(false);
|
||||
continue;
|
||||
}
|
||||
@@ -969,7 +959,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
if (EHFrame->ParseError.empty()) {
|
||||
if (!CFIRdWrt->fillCFIInfoFor(Function)) {
|
||||
errs() << "BOLT-WARNING: unable to fill CFI for function "
|
||||
<< Function.getName() << '\n';
|
||||
<< Function << '\n';
|
||||
Function.setSimple(false);
|
||||
continue;
|
||||
}
|
||||
@@ -1010,7 +1000,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
uint64_t Offset = Addr - I->first;
|
||||
if (Offset == 0 || Offset >= Func.getSize())
|
||||
continue;
|
||||
errs() << "BOLT-WARNING: Function " << Func.getName()
|
||||
errs() << "BOLT-WARNING: Function " << Func
|
||||
<< " has internal BBs that are target of a branch located in "
|
||||
"another function. We will not process this function.\n";
|
||||
Func.setSimple(false);
|
||||
@@ -1056,7 +1046,7 @@ void RewriteInstance::disassembleFunctions() {
|
||||
);
|
||||
auto SFI = ProfiledFunctions.begin();
|
||||
for (int i = 0; i < 100 && SFI != ProfiledFunctions.end(); ++SFI, ++i) {
|
||||
errs() << " " << (*SFI)->getName() << " : "
|
||||
errs() << " " << *SFI << " : "
|
||||
<< (*SFI)->getExecutionCount() << '\n';
|
||||
}
|
||||
}
|
||||
@@ -1147,17 +1137,12 @@ void emitFunction(MCStreamer &Streamer, BinaryFunction &Function,
|
||||
|
||||
Streamer.EmitCodeAlignment(Function.getAlignment());
|
||||
|
||||
if (!EmitColdPart) {
|
||||
MCSymbol *FunctionSymbol = BC.Ctx->getOrCreateSymbol(Function.getName());
|
||||
Streamer.EmitSymbolAttribute(FunctionSymbol, MCSA_ELF_TypeFunction);
|
||||
Streamer.EmitLabel(FunctionSymbol);
|
||||
Function.setOutputSymbol(FunctionSymbol);
|
||||
} else {
|
||||
MCSymbol *FunctionSymbol =
|
||||
BC.Ctx->getOrCreateSymbol(Twine(Function.getName()).concat(".cold"));
|
||||
Streamer.EmitSymbolAttribute(FunctionSymbol, MCSA_ELF_TypeFunction);
|
||||
Streamer.EmitLabel(FunctionSymbol);
|
||||
Function.cold().setOutputSymbol(FunctionSymbol);
|
||||
// Emit all names the function is known under.
|
||||
for (const auto &Name : Function.getNames()) {
|
||||
Twine EmitName = EmitColdPart ? Twine(Name).concat(".cold") : Name;
|
||||
auto *EmitSymbol = BC.Ctx->getOrCreateSymbol(EmitName);
|
||||
Streamer.EmitSymbolAttribute(EmitSymbol, MCSA_ELF_TypeFunction);
|
||||
Streamer.EmitLabel(EmitSymbol);
|
||||
}
|
||||
|
||||
// Emit CFI start
|
||||
@@ -1348,7 +1333,7 @@ void RewriteInstance::emitFunctions() {
|
||||
continue;
|
||||
|
||||
DEBUG(dbgs() << "BOLT: generating code for function \""
|
||||
<< Function.getName() << "\" : "
|
||||
<< Function << "\" : "
|
||||
<< Function.getFunctionNumber() << '\n');
|
||||
|
||||
emitFunction(*Streamer, Function, *BC.get(), /*EmitColdPart=*/false);
|
||||
@@ -1431,7 +1416,7 @@ void RewriteInstance::emitFunctions() {
|
||||
FailedAddresses.emplace_back(Function.getAddress());
|
||||
}
|
||||
} else {
|
||||
errs() << "BOLT: cannot remap function " << Function.getName() << "\n";
|
||||
errs() << "BOLT: cannot remap function " << Function << "\n";
|
||||
FailedAddresses.emplace_back(Function.getAddress());
|
||||
}
|
||||
|
||||
@@ -1458,7 +1443,7 @@ void RewriteInstance::emitFunctions() {
|
||||
|
||||
NextAvailableAddress += Function.cold().getImageSize();
|
||||
} else {
|
||||
errs() << "BOLT: cannot remap function " << Function.getName() << "\n";
|
||||
errs() << "BOLT: cannot remap function " << Function << "\n";
|
||||
FailedAddresses.emplace_back(Function.getAddress());
|
||||
}
|
||||
}
|
||||
@@ -1914,14 +1899,14 @@ void RewriteInstance::rewriteFile() {
|
||||
<< Twine::utohexstr(Function.getImageSize())
|
||||
<< ") is larger than maximum allowed size (0x"
|
||||
<< Twine::utohexstr(Function.getMaxSize())
|
||||
<< ") for function " << Function.getName() << '\n';
|
||||
<< ") for function " << Function << '\n';
|
||||
FailedAddresses.emplace_back(Function.getAddress());
|
||||
continue;
|
||||
}
|
||||
|
||||
OverwrittenScore += Function.getFunctionScore();
|
||||
// Overwrite function in the output file.
|
||||
outs() << "BOLT: rewriting function \"" << Function.getName() << "\"\n";
|
||||
outs() << "BOLT: rewriting function \"" << Function << "\"\n";
|
||||
Out->os().pwrite(reinterpret_cast<char *>(Function.getImageAddress()),
|
||||
Function.getImageSize(), Function.getFileOffset());
|
||||
|
||||
@@ -1943,8 +1928,7 @@ void RewriteInstance::rewriteFile() {
|
||||
}
|
||||
|
||||
// Write cold part
|
||||
outs() << "BOLT: rewriting function \"" << Function.getName()
|
||||
<< "\" (cold part)\n";
|
||||
outs() << "BOLT: rewriting function \"" << Function << "\" (cold part)\n";
|
||||
Out->os().pwrite(reinterpret_cast<char*>(Function.cold().getImageAddress()),
|
||||
Function.cold().getImageSize(),
|
||||
Function.cold().getFileOffset());
|
||||
|
||||
Reference in New Issue
Block a user