forked from OSchip/llvm-project
[BOLTCore] [NFC] Fix braces usages according to LLVM
Summary: Fix according to Coding Standards doc, section Don't Use Braces on Simple Single-Statement Bodies of if/else/loop Statements. This set of changes applies to lib Core only. (cherry picked from FBD33240028)
This commit is contained in:
parent
9a689946f2
commit
3652483c8e
|
@ -483,9 +483,8 @@ public:
|
|||
|
||||
/// Add a range of instructions to the end of this basic block.
|
||||
template <typename Itr> void addInstructions(Itr Begin, Itr End) {
|
||||
while (Begin != End) {
|
||||
while (Begin != End)
|
||||
addInstruction(*Begin++);
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a range of instructions to the end of this basic block.
|
||||
|
@ -582,18 +581,16 @@ public:
|
|||
|
||||
/// Add a range of successors.
|
||||
template <typename Itr> void addSuccessors(Itr Begin, Itr End) {
|
||||
while (Begin != End) {
|
||||
while (Begin != End)
|
||||
addSuccessor(*Begin++);
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a range of successors with branch info.
|
||||
template <typename Itr, typename BrItr>
|
||||
void addSuccessors(Itr Begin, Itr End, BrItr BrBegin, BrItr BrEnd) {
|
||||
assert(std::distance(Begin, End) == std::distance(BrBegin, BrEnd));
|
||||
while (Begin != End) {
|
||||
while (Begin != End)
|
||||
addSuccessor(*Begin++, *BrBegin++);
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace Succ with NewSucc. This routine is helpful for preserving
|
||||
|
@ -701,9 +698,8 @@ public:
|
|||
/// Erase instructions in the specified range.
|
||||
template <typename ItrType>
|
||||
void eraseInstructions(ItrType Begin, ItrType End) {
|
||||
while (End > Begin) {
|
||||
while (End > Begin)
|
||||
eraseInstruction(findInstruction(*--End));
|
||||
}
|
||||
}
|
||||
|
||||
/// Erase all instructions.
|
||||
|
@ -855,9 +851,8 @@ public:
|
|||
|
||||
/// Printer required for printing dominator trees.
|
||||
void printAsOperand(raw_ostream &OS, bool PrintType = true) {
|
||||
if (PrintType) {
|
||||
if (PrintType)
|
||||
OS << "basic block ";
|
||||
}
|
||||
OS << getName();
|
||||
}
|
||||
|
||||
|
@ -920,9 +915,8 @@ private:
|
|||
void adjustNumPseudos(const MCInst &Inst, int Sign);
|
||||
|
||||
template <typename Itr> void adjustNumPseudos(Itr Begin, Itr End, int Sign) {
|
||||
while (Begin != End) {
|
||||
while (Begin != End)
|
||||
adjustNumPseudos(*Begin++, Sign);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds predecessor to the BB. Most likely you don't need to call this.
|
||||
|
|
|
@ -281,9 +281,8 @@ public:
|
|||
void setFilename(StringRef Name) { Filename = std::string(Name); }
|
||||
|
||||
Optional<StringRef> getFileBuildID() const {
|
||||
if (FileBuildID) {
|
||||
if (FileBuildID)
|
||||
return StringRef(*FileBuildID);
|
||||
}
|
||||
|
||||
return NoneType();
|
||||
}
|
||||
|
@ -666,9 +665,8 @@ public:
|
|||
iterator_range<FilteredBinaryDataConstIterator>
|
||||
getBinaryDataForSection(const BinarySection &Section) const {
|
||||
auto Begin = BinaryDataMap.lower_bound(Section.getAddress());
|
||||
if (Begin != BinaryDataMap.begin()) {
|
||||
if (Begin != BinaryDataMap.begin())
|
||||
--Begin;
|
||||
}
|
||||
auto End = BinaryDataMap.upper_bound(Section.getEndAddress());
|
||||
auto pred = [&Section](const binary_data_const_iterator &Itr) -> bool {
|
||||
return Itr->second->getSection() == Section;
|
||||
|
@ -681,9 +679,8 @@ public:
|
|||
iterator_range<FilteredBinaryDataIterator>
|
||||
getBinaryDataForSection(BinarySection &Section) {
|
||||
auto Begin = BinaryDataMap.lower_bound(Section.getAddress());
|
||||
if (Begin != BinaryDataMap.begin()) {
|
||||
if (Begin != BinaryDataMap.begin())
|
||||
--Begin;
|
||||
}
|
||||
auto End = BinaryDataMap.upper_bound(Section.getEndAddress());
|
||||
auto pred = [&Section](const binary_data_iterator &Itr) -> bool {
|
||||
return Itr->second->getSection() == Section;
|
||||
|
@ -698,9 +695,8 @@ public:
|
|||
/// Clear the global symbol address -> name(s) map.
|
||||
void clearBinaryData() {
|
||||
GlobalSymbols.clear();
|
||||
for (auto &Entry : BinaryDataMap) {
|
||||
for (auto &Entry : BinaryDataMap)
|
||||
delete Entry.second;
|
||||
}
|
||||
BinaryDataMap.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -708,12 +708,10 @@ private:
|
|||
/// Release memory allocated for CFG and instructions.
|
||||
/// We still keep basic blocks for address translation/mapping purposes.
|
||||
void releaseCFG() {
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : BasicBlocks)
|
||||
BB->releaseCFG();
|
||||
}
|
||||
for (BinaryBasicBlock *BB : DeletedBasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : DeletedBasicBlocks)
|
||||
BB->releaseCFG();
|
||||
}
|
||||
|
||||
clearList(CallSites);
|
||||
clearList(ColdCallSites);
|
||||
|
@ -878,9 +876,8 @@ public:
|
|||
const BinaryLoopInfo &getLoopInfo() { return *BLI.get(); }
|
||||
|
||||
bool isLoopFree() {
|
||||
if (!hasLoopInfo()) {
|
||||
if (!hasLoopInfo())
|
||||
calculateLoopInfo();
|
||||
}
|
||||
return BLI->empty();
|
||||
}
|
||||
|
||||
|
@ -1110,9 +1107,8 @@ public:
|
|||
/// Return the number of emitted instructions for this function.
|
||||
uint32_t getNumNonPseudos() const {
|
||||
uint32_t N = 0;
|
||||
for (BinaryBasicBlock *const &BB : layout()) {
|
||||
for (BinaryBasicBlock *const &BB : layout())
|
||||
N += BB->getNumNonPseudos();
|
||||
}
|
||||
return N;
|
||||
}
|
||||
|
||||
|
@ -1608,9 +1604,8 @@ public:
|
|||
/// Make sure basic blocks' indices match the current layout.
|
||||
void updateLayoutIndices() const {
|
||||
unsigned Index = 0;
|
||||
for (BinaryBasicBlock *BB : layout()) {
|
||||
for (BinaryBasicBlock *BB : layout())
|
||||
BB->setLayoutIndex(Index++);
|
||||
}
|
||||
}
|
||||
|
||||
/// Recompute the CFI state for NumNewBlocks following Start after inserting
|
||||
|
@ -2078,10 +2073,9 @@ public:
|
|||
Size += NextMarker - *DataIter;
|
||||
}
|
||||
|
||||
if (!OnBehalfOf) {
|
||||
if (!OnBehalfOf)
|
||||
for (BinaryFunction *ExternalFunc : Islands->Dependency)
|
||||
Size += ExternalFunc->estimateConstantIslandSize(this);
|
||||
}
|
||||
return Size;
|
||||
}
|
||||
|
||||
|
@ -2311,17 +2305,13 @@ public:
|
|||
size_t estimateHotSize(const bool UseSplitSize = true) const {
|
||||
size_t Estimate = 0;
|
||||
if (UseSplitSize && isSplit()) {
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
|
||||
if (!BB->isCold()) {
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
|
||||
if (!BB->isCold())
|
||||
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
|
||||
if (BB->getKnownExecutionCount() != 0) {
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
|
||||
if (BB->getKnownExecutionCount() != 0)
|
||||
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
|
||||
}
|
||||
}
|
||||
}
|
||||
return Estimate;
|
||||
}
|
||||
|
@ -2330,19 +2320,16 @@ public:
|
|||
if (!isSplit())
|
||||
return estimateSize();
|
||||
size_t Estimate = 0;
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
|
||||
if (BB->isCold()) {
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
|
||||
if (BB->isCold())
|
||||
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
|
||||
}
|
||||
}
|
||||
return Estimate;
|
||||
}
|
||||
|
||||
size_t estimateSize() const {
|
||||
size_t Estimate = 0;
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
|
||||
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
|
||||
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
|
||||
}
|
||||
return Estimate;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,9 +151,8 @@ inline DynoStats getDynoStats(const FuncsType &Funcs) {
|
|||
DynoStats dynoStats(IsAArch64);
|
||||
for (auto &BFI : Funcs) {
|
||||
auto &BF = BFI.second;
|
||||
if (BF.isSimple()) {
|
||||
if (BF.isSimple())
|
||||
dynoStats += getDynoStats(BF);
|
||||
}
|
||||
}
|
||||
return dynoStats;
|
||||
}
|
||||
|
@ -164,9 +163,8 @@ inline void callWithDynoStats(FnType &&Func, const FuncsType &Funcs,
|
|||
StringRef Phase, const bool Flag) {
|
||||
bool IsAArch64 = Funcs.begin()->second.getBinaryContext().isAArch64();
|
||||
DynoStats DynoStatsBefore(IsAArch64);
|
||||
if (Flag) {
|
||||
if (Flag)
|
||||
DynoStatsBefore = getDynoStats(Funcs);
|
||||
}
|
||||
|
||||
Func();
|
||||
|
||||
|
@ -176,9 +174,8 @@ inline void callWithDynoStats(FnType &&Func, const FuncsType &Funcs,
|
|||
outs() << "BOLT-INFO: program-wide dynostats after running " << Phase
|
||||
<< (Changed ? "" : " (no change)") << ":\n\n"
|
||||
<< DynoStatsBefore << '\n';
|
||||
if (Changed) {
|
||||
if (Changed)
|
||||
DynoStatsAfter.print(outs(), &DynoStatsBefore);
|
||||
}
|
||||
outs() << '\n';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1112,9 +1112,8 @@ public:
|
|||
} else if (auto *BinExpr = dyn_cast<MCBinaryExpr>(Expr)) {
|
||||
const auto *SymExpr = dyn_cast<MCSymbolRefExpr>(BinExpr->getLHS());
|
||||
const auto *ConstExpr = dyn_cast<MCConstantExpr>(BinExpr->getRHS());
|
||||
if (BinExpr->getOpcode() == MCBinaryExpr::Add && SymExpr && ConstExpr) {
|
||||
if (BinExpr->getOpcode() == MCBinaryExpr::Add && SymExpr && ConstExpr)
|
||||
return std::make_pair(&SymExpr->getSymbol(), ConstExpr->getValue());
|
||||
}
|
||||
}
|
||||
return std::make_pair(nullptr, 0);
|
||||
}
|
||||
|
@ -1633,9 +1632,8 @@ public:
|
|||
auto *A = new (Allocator.ValueAllocator)
|
||||
MCPlus::MCSimpleAnnotation<ValueType>(Val);
|
||||
|
||||
if (!std::is_trivial<ValueType>::value) {
|
||||
if (!std::is_trivial<ValueType>::value)
|
||||
Allocator.AnnotationPool.insert(A);
|
||||
}
|
||||
setAnnotationOpValue(Inst, Index, reinterpret_cast<int64_t>(A),
|
||||
AllocatorId);
|
||||
return A->getValue();
|
||||
|
|
|
@ -157,10 +157,9 @@ BinaryBasicBlock *BinaryBasicBlock::getSuccessor(const MCSymbol *Label) const {
|
|||
if (!Label && succ_size() == 1)
|
||||
return *succ_begin();
|
||||
|
||||
for (BinaryBasicBlock *BB : successors()) {
|
||||
for (BinaryBasicBlock *BB : successors())
|
||||
if (BB->getLabel() == Label)
|
||||
return BB;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -180,10 +179,9 @@ BinaryBasicBlock *BinaryBasicBlock::getSuccessor(const MCSymbol *Label,
|
|||
}
|
||||
|
||||
BinaryBasicBlock *BinaryBasicBlock::getLandingPad(const MCSymbol *Label) const {
|
||||
for (BinaryBasicBlock *BB : landing_pads()) {
|
||||
for (BinaryBasicBlock *BB : landing_pads())
|
||||
if (BB->getLabel() == Label)
|
||||
return BB;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -240,11 +238,10 @@ int32_t BinaryBasicBlock::getCFIStateAtInstr(const MCInst *Instr) const {
|
|||
assert(State >= 0 && "first CFI cannot be RestoreState");
|
||||
while (Depth && State >= 0) {
|
||||
const MCCFIInstruction &CFIInstr = FDEProgram[State];
|
||||
if (CFIInstr.getOperation() == MCCFIInstruction::OpRestoreState) {
|
||||
if (CFIInstr.getOperation() == MCCFIInstruction::OpRestoreState)
|
||||
++Depth;
|
||||
} else if (CFIInstr.getOperation() == MCCFIInstruction::OpRememberState) {
|
||||
else if (CFIInstr.getOperation() == MCCFIInstruction::OpRememberState)
|
||||
--Depth;
|
||||
}
|
||||
--State;
|
||||
}
|
||||
assert(Depth == 0 && "unbalanced RememberState/RestoreState stack");
|
||||
|
@ -288,9 +285,8 @@ void BinaryBasicBlock::replaceSuccessor(BinaryBasicBlock *Succ,
|
|||
}
|
||||
|
||||
void BinaryBasicBlock::removeAllSuccessors() {
|
||||
for (BinaryBasicBlock *SuccessorBB : successors()) {
|
||||
for (BinaryBasicBlock *SuccessorBB : successors())
|
||||
SuccessorBB->removePredecessor(this);
|
||||
}
|
||||
Successors.clear();
|
||||
BranchInfo.clear();
|
||||
}
|
||||
|
@ -488,10 +484,10 @@ uint32_t BinaryBasicBlock::getNumPseudos() const {
|
|||
#ifndef NDEBUG
|
||||
BinaryContext &BC = Function->getBinaryContext();
|
||||
uint32_t N = 0;
|
||||
for (const MCInst &Instr : Instructions) {
|
||||
for (const MCInst &Instr : Instructions)
|
||||
if (BC.MIB->isPseudo(Instr))
|
||||
++N;
|
||||
}
|
||||
|
||||
if (N != NumPseudos) {
|
||||
errs() << "BOLT-ERROR: instructions for basic block " << getName()
|
||||
<< " in function " << *Function << ": calculated pseudos " << N
|
||||
|
|
|
@ -101,15 +101,12 @@ BinaryContext::BinaryContext(std::unique_ptr<MCContext> Ctx,
|
|||
}
|
||||
|
||||
BinaryContext::~BinaryContext() {
|
||||
for (BinarySection *Section : Sections) {
|
||||
for (BinarySection *Section : Sections)
|
||||
delete Section;
|
||||
}
|
||||
for (BinaryFunction *InjectedFunction : InjectedBinaryFunctions) {
|
||||
for (BinaryFunction *InjectedFunction : InjectedBinaryFunctions)
|
||||
delete InjectedFunction;
|
||||
}
|
||||
for (std::pair<const uint64_t, JumpTable *> JTI : JumpTables) {
|
||||
for (std::pair<const uint64_t, JumpTable *> JTI : JumpTables)
|
||||
delete JTI.second;
|
||||
}
|
||||
clearBinaryData();
|
||||
}
|
||||
|
||||
|
@ -362,9 +359,8 @@ iterator_range<BinaryContext::binary_data_iterator>
|
|||
BinaryContext::getSubBinaryData(BinaryData *BD) {
|
||||
auto Start = std::next(BinaryDataMap.find(BD->getAddress()));
|
||||
auto End = Start;
|
||||
while (End != BinaryDataMap.end() && BD->isAncestorOf(End->second)) {
|
||||
while (End != BinaryDataMap.end() && BD->isAncestorOf(End->second))
|
||||
++End;
|
||||
}
|
||||
return make_range(Start, End);
|
||||
}
|
||||
|
||||
|
@ -426,9 +422,8 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
|
|||
}
|
||||
}
|
||||
|
||||
if (BinaryData *BD = getBinaryDataContainingAddress(Address)) {
|
||||
if (BinaryData *BD = getBinaryDataContainingAddress(Address))
|
||||
return std::make_pair(BD->getSymbol(), Address - BD->getAddress());
|
||||
}
|
||||
|
||||
// TODO: use DWARF info to get size/alignment here?
|
||||
MCSymbol *TargetSymbol = getOrCreateGlobalSymbol(Address, "DATAat");
|
||||
|
@ -533,9 +528,8 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
|
|||
"data object cannot cross a section boundary");
|
||||
UpperBound = JumpTableBD->getEndAddress();
|
||||
}
|
||||
if (NextJTAddress) {
|
||||
if (NextJTAddress)
|
||||
UpperBound = std::min(NextJTAddress, UpperBound);
|
||||
}
|
||||
|
||||
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: analyzeJumpTable in " << BF.getPrintName()
|
||||
<< '\n');
|
||||
|
@ -640,9 +634,8 @@ void BinaryContext::populateJumpTables() {
|
|||
|
||||
uint64_t NextJTAddress = 0;
|
||||
auto NextJTI = std::next(JTI);
|
||||
if (NextJTI != JTE) {
|
||||
if (NextJTI != JTE)
|
||||
NextJTAddress = NextJTI->second->getAddress();
|
||||
}
|
||||
|
||||
const bool Success = analyzeJumpTable(JT->getAddress(), JT->Type, BF,
|
||||
NextJTAddress, &JT->OffsetEntries);
|
||||
|
@ -830,9 +823,8 @@ std::string BinaryContext::generateJumpTableName(const BinaryFunction &BF,
|
|||
if (const JumpTable *JT = BF.getJumpTableContainingAddress(Address)) {
|
||||
Offset = Address - JT->getAddress();
|
||||
auto Itr = JT->Labels.find(Offset);
|
||||
if (Itr != JT->Labels.end()) {
|
||||
if (Itr != JT->Labels.end())
|
||||
return std::string(Itr->second->getName());
|
||||
}
|
||||
Id = JumpTableIds.at(JT->getAddress());
|
||||
} else {
|
||||
Id = JumpTableIds[Address] = BF.JumpTables.size();
|
||||
|
@ -979,9 +971,8 @@ BinaryContext::getBinaryDataContainingAddressImpl(uint64_t Address) const {
|
|||
auto End = BinaryDataMap.end();
|
||||
if ((NI != End && Address == NI->first) ||
|
||||
((NI != BinaryDataMap.begin()) && (NI-- != BinaryDataMap.begin()))) {
|
||||
if (NI->second->containsAddress(Address)) {
|
||||
if (NI->second->containsAddress(Address))
|
||||
return NI->second;
|
||||
}
|
||||
|
||||
// If this is a sub-symbol, see if a parent data contains the address.
|
||||
const BinaryData *BD = NI->second->getParent();
|
||||
|
@ -1268,9 +1259,8 @@ void BinaryContext::fixBinaryDataHoles() {
|
|||
++Itr;
|
||||
}
|
||||
|
||||
if (EndAddress < Section.getEndAddress()) {
|
||||
if (EndAddress < Section.getEndAddress())
|
||||
Holes.emplace_back(EndAddress, Section.getEndAddress() - EndAddress);
|
||||
}
|
||||
|
||||
// If there is already a symbol at the start of the hole, grow that symbol
|
||||
// to cover the rest. Otherwise, create a new symbol to cover the hole.
|
||||
|
@ -1701,9 +1691,8 @@ ErrorOr<BinarySection &> BinaryContext::getSectionForAddress(uint64_t Address) {
|
|||
|
||||
ErrorOr<StringRef>
|
||||
BinaryContext::getSectionNameForAddress(uint64_t Address) const {
|
||||
if (ErrorOr<const BinarySection &> Section = getSectionForAddress(Address)) {
|
||||
if (ErrorOr<const BinarySection &> Section = getSectionForAddress(Address))
|
||||
return Section->getName();
|
||||
}
|
||||
return std::make_error_code(std::errc::bad_address);
|
||||
}
|
||||
|
||||
|
@ -1789,9 +1778,8 @@ bool BinaryContext::deregisterSection(BinarySection &Section) {
|
|||
}
|
||||
|
||||
void BinaryContext::printSections(raw_ostream &OS) const {
|
||||
for (BinarySection *const &Section : Sections) {
|
||||
for (BinarySection *const &Section : Sections)
|
||||
OS << "BOLT-INFO: " << *Section << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
BinarySection &BinaryContext::absoluteSection() {
|
||||
|
@ -2077,9 +2065,8 @@ BinaryFunction *BinaryContext::getBinaryFunctionAtAddress(uint64_t Address) {
|
|||
// function was folded, this will get us the original folded function if it
|
||||
// wasn't removed from the list, e.g. in non-relocation mode.
|
||||
auto BFI = BinaryFunctions.find(Address);
|
||||
if (BFI != BinaryFunctions.end()) {
|
||||
if (BFI != BinaryFunctions.end())
|
||||
return &BFI->second;
|
||||
}
|
||||
|
||||
// We might have folded the function matching the object at the given
|
||||
// address. In such case, we look for a function matching the symbol
|
||||
|
|
|
@ -51,27 +51,24 @@ void BinaryData::merge(const BinaryData *Other) {
|
|||
}
|
||||
|
||||
bool BinaryData::hasName(StringRef Name) const {
|
||||
for (const MCSymbol *Symbol : Symbols) {
|
||||
for (const MCSymbol *Symbol : Symbols)
|
||||
if (Name == Symbol->getName())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BinaryData::hasNameRegex(StringRef NameRegex) const {
|
||||
Regex MatchName(NameRegex);
|
||||
for (const MCSymbol *Symbol : Symbols) {
|
||||
for (const MCSymbol *Symbol : Symbols)
|
||||
if (MatchName.match(Symbol->getName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BinaryData::nameStartsWith(StringRef Prefix) const {
|
||||
for (const MCSymbol *Symbol : Symbols) {
|
||||
for (const MCSymbol *Symbol : Symbols)
|
||||
if (Symbol->getName().startswith(Prefix))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,9 +107,8 @@ size_t padFunction(const BinaryFunction &Function) {
|
|||
for (auto &FPI : FunctionPadding) {
|
||||
std::string Name = FPI.first;
|
||||
size_t Padding = FPI.second;
|
||||
if (Function.hasNameRegex(Name)) {
|
||||
if (Function.hasNameRegex(Name))
|
||||
return Padding;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -206,9 +205,8 @@ void BinaryEmitter::emitAll(StringRef OrgSecPrefix) {
|
|||
ELFDwarfLineSection->setFlags(ELF::SHF_ALLOC);
|
||||
}
|
||||
|
||||
if (RuntimeLibrary *RtLibrary = BC.getRuntimeLibrary()) {
|
||||
if (RuntimeLibrary *RtLibrary = BC.getRuntimeLibrary())
|
||||
RtLibrary->emitBinary(BC, Streamer);
|
||||
}
|
||||
|
||||
BC.getTextSection()->setAlignment(Align(opts::AlignText));
|
||||
|
||||
|
@ -229,9 +227,8 @@ void BinaryEmitter::emitFunctions() {
|
|||
const bool HasProfile = BC.NumProfiledFuncs > 0;
|
||||
const bool OriginalAllowAutoPadding = Streamer.getAllowAutoPadding();
|
||||
for (BinaryFunction *Function : Functions) {
|
||||
if (!BC.shouldEmit(*Function)) {
|
||||
if (!BC.shouldEmit(*Function))
|
||||
continue;
|
||||
}
|
||||
|
||||
LLVM_DEBUG(dbgs() << "BOLT: generating code for function \"" << *Function
|
||||
<< "\" : " << Function->getFunctionNumber() << '\n');
|
||||
|
@ -330,11 +327,10 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
|
|||
}
|
||||
MCSymbol *LSDASymbol =
|
||||
EmitColdPart ? Function.getColdLSDASymbol() : Function.getLSDASymbol();
|
||||
if (LSDASymbol) {
|
||||
if (LSDASymbol)
|
||||
Streamer.emitCFILsda(LSDASymbol, BC.LSDAEncoding);
|
||||
} else {
|
||||
else
|
||||
Streamer.emitCFILsda(0, dwarf::DW_EH_PE_omit);
|
||||
}
|
||||
// Emit CFI instructions relative to the CIE
|
||||
for (const MCCFIInstruction &CFIInstr : Function.cie()) {
|
||||
// Only write CIE CFI insns that LLVM will not already emit
|
||||
|
@ -369,9 +365,8 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
|
|||
Streamer.emitFill(Padding, MAI->getTextAlignFillValue());
|
||||
}
|
||||
|
||||
if (opts::MarkFuncs) {
|
||||
if (opts::MarkFuncs)
|
||||
Streamer.emitIntValue(BC.MIB->getTrapFillValue(), 1);
|
||||
}
|
||||
|
||||
// Emit CFI end
|
||||
if (Function.hasCFI())
|
||||
|
@ -418,9 +413,8 @@ void BinaryEmitter::emitFunctionBody(BinaryFunction &BF, bool EmitColdPart,
|
|||
}
|
||||
Streamer.emitLabel(BB->getLabel());
|
||||
if (!EmitCodeOnly) {
|
||||
if (MCSymbol *EntrySymbol = BF.getSecondaryEntryPointSymbol(*BB)) {
|
||||
if (MCSymbol *EntrySymbol = BF.getSecondaryEntryPointSymbol(*BB))
|
||||
Streamer.emitLabel(EntrySymbol);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if special alignment for macro-fusion is needed.
|
||||
|
@ -630,9 +624,8 @@ void BinaryEmitter::emitConstantIslands(BinaryFunction &BF, bool EmitColdPart,
|
|||
return;
|
||||
// Now emit constant islands from other functions that we may have used in
|
||||
// this function.
|
||||
for (BinaryFunction *ExternalFunc : Islands.Dependency) {
|
||||
for (BinaryFunction *ExternalFunc : Islands.Dependency)
|
||||
emitConstantIslands(*ExternalFunc, EmitColdPart, &BF);
|
||||
}
|
||||
}
|
||||
|
||||
SMLoc BinaryEmitter::emitLineInfo(const BinaryFunction &BF, SMLoc NewLoc,
|
||||
|
@ -718,9 +711,8 @@ void BinaryEmitter::emitJumpTables(const BinaryFunction &BF) {
|
|||
if (!BF.hasJumpTables())
|
||||
return;
|
||||
|
||||
if (opts::PrintJumpTables) {
|
||||
if (opts::PrintJumpTables)
|
||||
outs() << "BOLT-INFO: jump tables for function " << BF << ":\n";
|
||||
}
|
||||
|
||||
for (auto &JTI : BF.jumpTables()) {
|
||||
JumpTable &JT = *JTI.second;
|
||||
|
@ -793,11 +785,10 @@ void BinaryEmitter::emitJumpTable(const JumpTable &JT, MCSection *HotSection,
|
|||
if (!LabelCounts.empty()) {
|
||||
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: jump table count: "
|
||||
<< LabelCounts[LI->second] << '\n');
|
||||
if (LabelCounts[LI->second] > 0) {
|
||||
if (LabelCounts[LI->second] > 0)
|
||||
Streamer.SwitchSection(HotSection);
|
||||
} else {
|
||||
else
|
||||
Streamer.SwitchSection(ColdSection);
|
||||
}
|
||||
Streamer.emitValueToAlignment(JT.EntrySize);
|
||||
}
|
||||
Streamer.emitLabel(LI->second);
|
||||
|
@ -999,9 +990,8 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, bool EmitColdPart) {
|
|||
//
|
||||
// For type table we (re-)encode the table using TTypeEncoding matching
|
||||
// the current assembler mode.
|
||||
for (uint8_t const &Byte : BF.getLSDAActionTable()) {
|
||||
for (uint8_t const &Byte : BF.getLSDAActionTable())
|
||||
Streamer.emitIntValue(Byte, 1);
|
||||
}
|
||||
|
||||
const BinaryFunction::LSDATypeTableTy &TypeTable =
|
||||
(TTypeEncoding & dwarf::DW_EH_PE_indirect) ? BF.getLSDATypeAddressTable()
|
||||
|
@ -1034,9 +1024,8 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, bool EmitColdPart) {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (uint8_t const &Byte : BF.getLSDATypeIndexTable()) {
|
||||
for (uint8_t const &Byte : BF.getLSDATypeIndexTable())
|
||||
Streamer.emitIntValue(Byte, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryEmitter::emitDebugLineInfoForOriginalFunctions() {
|
||||
|
|
|
@ -301,9 +301,8 @@ BinaryFunction::getBasicBlockContainingOffset(uint64_t Offset) {
|
|||
void BinaryFunction::markUnreachableBlocks() {
|
||||
std::stack<BinaryBasicBlock *> Stack;
|
||||
|
||||
for (BinaryBasicBlock *BB : layout()) {
|
||||
for (BinaryBasicBlock *BB : layout())
|
||||
BB->markValid(false);
|
||||
}
|
||||
|
||||
// Add all entries and landing pads as roots.
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
|
@ -544,9 +543,8 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation,
|
|||
else
|
||||
OS << "<unknown>\n";
|
||||
}
|
||||
if (BB->getCFIState() >= 0) {
|
||||
if (BB->getCFIState() >= 0)
|
||||
OS << " CFI State : " << BB->getCFIState() << '\n';
|
||||
}
|
||||
if (opts::EnableBAT) {
|
||||
OS << " Input offset: " << Twine::utohexstr(BB->getInputOffset())
|
||||
<< "\n";
|
||||
|
@ -642,9 +640,8 @@ void BinaryFunction::print(raw_ostream &OS, std::string Annotation,
|
|||
}
|
||||
|
||||
// Print all jump tables.
|
||||
for (const std::pair<const uint64_t, JumpTable *> &JTI : JumpTables) {
|
||||
for (const std::pair<const uint64_t, JumpTable *> &JTI : JumpTables)
|
||||
JTI.second->print(OS);
|
||||
}
|
||||
|
||||
OS << "DWARF CFI Instructions:\n";
|
||||
if (OffsetToCFI.size()) {
|
||||
|
@ -970,9 +967,8 @@ MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
|
|||
|
||||
// For AArch64, check if this address is part of a constant island.
|
||||
if (BC.isAArch64()) {
|
||||
if (MCSymbol *IslandSym = getOrCreateIslandAccess(Address)) {
|
||||
if (MCSymbol *IslandSym = getOrCreateIslandAccess(Address))
|
||||
return IslandSym;
|
||||
}
|
||||
}
|
||||
|
||||
MCSymbol *Label = BC.Ctx->createNamedTempSymbol();
|
||||
|
@ -986,9 +982,8 @@ ErrorOr<ArrayRef<uint8_t>> BinaryFunction::getData() const {
|
|||
assert(Section.containsRange(getAddress(), getMaxSize()) &&
|
||||
"wrong section for function");
|
||||
|
||||
if (!Section.isText() || Section.isVirtual() || !Section.getSize()) {
|
||||
if (!Section.isText() || Section.isVirtual() || !Section.getSize())
|
||||
return std::make_error_code(std::errc::bad_address);
|
||||
}
|
||||
|
||||
StringRef SectionContents = Section.getContents();
|
||||
|
||||
|
@ -1009,9 +1004,8 @@ size_t BinaryFunction::getSizeOfDataInCodeAt(uint64_t Offset) const {
|
|||
return 0;
|
||||
|
||||
auto Iter = Islands->CodeOffsets.upper_bound(Offset);
|
||||
if (Iter != Islands->CodeOffsets.end()) {
|
||||
if (Iter != Islands->CodeOffsets.end())
|
||||
return *Iter - Offset;
|
||||
}
|
||||
return getSize() - Offset;
|
||||
}
|
||||
|
||||
|
@ -1023,11 +1017,9 @@ bool BinaryFunction::isZeroPaddingAt(uint64_t Offset) const {
|
|||
if (Iter != Islands->DataOffsets.end())
|
||||
EndOfCode = *Iter;
|
||||
}
|
||||
for (uint64_t I = Offset; I < EndOfCode; ++I) {
|
||||
if (FunctionData[I] != 0) {
|
||||
for (uint64_t I = Offset; I < EndOfCode; ++I)
|
||||
if (FunctionData[I] != 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1388,9 +1380,8 @@ bool BinaryFunction::disassemble() {
|
|||
BC.MIB->replaceBranchTarget(Instruction, TargetSymbol, &*Ctx);
|
||||
|
||||
// Mark CTC.
|
||||
if (IsCondBranch && IsCall) {
|
||||
if (IsCondBranch && IsCall)
|
||||
MIB->setConditionalTailCall(Instruction, TargetAddress);
|
||||
}
|
||||
} else {
|
||||
// Could not evaluate branch. Should be an indirect call or an
|
||||
// indirect branch. Bail out on the latter case.
|
||||
|
@ -1403,8 +1394,9 @@ bool BinaryFunction::disassemble() {
|
|||
if (BC.isAArch64())
|
||||
handleAArch64IndirectCall(Instruction, Offset);
|
||||
}
|
||||
} else if (MIB->hasPCRelOperand(Instruction) && !UsedReloc)
|
||||
} else if (MIB->hasPCRelOperand(Instruction) && !UsedReloc) {
|
||||
handlePCRelOperand(Instruction, AbsoluteInstrAddr, Size);
|
||||
}
|
||||
|
||||
add_instruction:
|
||||
if (getDWARFLineTable()) {
|
||||
|
@ -1413,9 +1405,8 @@ add_instruction:
|
|||
}
|
||||
|
||||
// Record offset of the instruction for profile matching.
|
||||
if (BC.keepOffsetForInstruction(Instruction)) {
|
||||
if (BC.keepOffsetForInstruction(Instruction))
|
||||
MIB->addAnnotation(Instruction, "Offset", static_cast<uint32_t>(Offset));
|
||||
}
|
||||
|
||||
if (BC.MIB->isNoop(Instruction)) {
|
||||
// NOTE: disassembly loses the correct size information for noops.
|
||||
|
@ -1620,33 +1611,27 @@ bool BinaryFunction::scanExternalRefs() {
|
|||
}
|
||||
|
||||
// Add relocations unless disassembly failed for this function.
|
||||
if (!DisassemblyFailed) {
|
||||
for (Relocation &Rel : FunctionRelocations) {
|
||||
if (!DisassemblyFailed)
|
||||
for (Relocation &Rel : FunctionRelocations)
|
||||
getOriginSection()->addPendingRelocation(Rel);
|
||||
}
|
||||
}
|
||||
|
||||
// Inform BinaryContext that this function symbols will not be defined and
|
||||
// relocations should not be created against them.
|
||||
if (BC.HasRelocations) {
|
||||
for (std::pair<const uint32_t, MCSymbol *> &LI : Labels) {
|
||||
for (std::pair<const uint32_t, MCSymbol *> &LI : Labels)
|
||||
BC.UndefinedSymbols.insert(LI.second);
|
||||
}
|
||||
if (FunctionEndLabel) {
|
||||
if (FunctionEndLabel)
|
||||
BC.UndefinedSymbols.insert(FunctionEndLabel);
|
||||
}
|
||||
}
|
||||
|
||||
clearList(Relocations);
|
||||
clearList(ExternallyReferencedOffsets);
|
||||
|
||||
if (Success && BC.HasRelocations) {
|
||||
if (Success && BC.HasRelocations)
|
||||
HasExternalRefRelocations = true;
|
||||
}
|
||||
|
||||
if (opts::Verbosity >= 1 && !Success) {
|
||||
if (opts::Verbosity >= 1 && !Success)
|
||||
outs() << "BOLT-INFO: failed to scan refs for " << *this << '\n';
|
||||
}
|
||||
|
||||
return Success;
|
||||
}
|
||||
|
@ -1671,22 +1656,19 @@ void BinaryFunction::postProcessEntryPoints() {
|
|||
// If we are at Offset 0 and there is no instruction associated with it,
|
||||
// this means this is an empty function. Just ignore. If we find an
|
||||
// instruction at this offset, this entry point is valid.
|
||||
if (!Offset || getInstructionAtOffset(Offset)) {
|
||||
if (!Offset || getInstructionAtOffset(Offset))
|
||||
continue;
|
||||
}
|
||||
|
||||
// On AArch64 there are legitimate reasons to have references past the
|
||||
// end of the function, e.g. jump tables.
|
||||
if (BC.isAArch64() && Offset == getSize()) {
|
||||
if (BC.isAArch64() && Offset == getSize())
|
||||
continue;
|
||||
}
|
||||
|
||||
errs() << "BOLT-WARNING: reference in the middle of instruction "
|
||||
"detected in function "
|
||||
<< *this << " at offset 0x" << Twine::utohexstr(Offset) << '\n';
|
||||
if (BC.HasRelocations) {
|
||||
if (BC.HasRelocations)
|
||||
setIgnored();
|
||||
}
|
||||
setSimple(false);
|
||||
return;
|
||||
}
|
||||
|
@ -1780,10 +1762,9 @@ bool BinaryFunction::postProcessIndirectBranches(
|
|||
auto addUnknownControlFlow = [&](BinaryBasicBlock &BB) {
|
||||
HasUnknownControlFlow = true;
|
||||
BB.removeAllSuccessors();
|
||||
for (uint64_t PossibleDestination : ExternallyReferencedOffsets) {
|
||||
for (uint64_t PossibleDestination : ExternallyReferencedOffsets)
|
||||
if (BinaryBasicBlock *SuccBB = getBasicBlockAtOffset(PossibleDestination))
|
||||
BB.addSuccessor(SuccBB);
|
||||
}
|
||||
};
|
||||
|
||||
uint64_t NumIndirectJumps = 0;
|
||||
|
@ -1898,9 +1879,8 @@ bool BinaryFunction::postProcessIndirectBranches(
|
|||
std::set<const MCSymbol *> JTLabels;
|
||||
LastIndirectJumpBB->removeAllSuccessors();
|
||||
const JumpTable *JT = getJumpTableContainingAddress(LastJT);
|
||||
for (const MCSymbol *Label : JT->Entries) {
|
||||
for (const MCSymbol *Label : JT->Entries)
|
||||
JTLabels.emplace(Label);
|
||||
}
|
||||
for (const MCSymbol *Label : JTLabels) {
|
||||
BinaryBasicBlock *BB = getBasicBlockForLabel(Label);
|
||||
// Ignore __builtin_unreachable()
|
||||
|
@ -2131,9 +2111,9 @@ bool BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
|
|||
PrevBB = nullptr;
|
||||
bool IsPrevFT = false; // Is previous block a fall-through.
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
if (IsPrevFT) {
|
||||
if (IsPrevFT)
|
||||
PrevBB->addSuccessor(BB);
|
||||
}
|
||||
|
||||
if (BB->empty()) {
|
||||
IsPrevFT = true;
|
||||
PrevBB = BB;
|
||||
|
@ -2233,10 +2213,11 @@ void BinaryFunction::postProcessCFG() {
|
|||
// Remove "Offset" annotations, unless we need an address-translation table
|
||||
// later. This has no cost, since annotations are allocated by a bumpptr
|
||||
// allocator and won't be released anyway until late in the pipeline.
|
||||
if (!requiresAddressTranslation() && !opts::Instrument)
|
||||
if (!requiresAddressTranslation() && !opts::Instrument) {
|
||||
for (BinaryBasicBlock *BB : layout())
|
||||
for (MCInst &Inst : *BB)
|
||||
BC.MIB->removeAnnotation(Inst, "Offset");
|
||||
}
|
||||
|
||||
assert((!isSimple() || validateCFG()) &&
|
||||
"invalid CFG detected after post-processing");
|
||||
|
@ -2518,9 +2499,8 @@ public:
|
|||
auto Iter = FrameRestoreEquivalents.find(I);
|
||||
if (Iter == FrameRestoreEquivalents.end())
|
||||
continue;
|
||||
for (int32_t RuleNumber : Iter->second) {
|
||||
for (int32_t RuleNumber : Iter->second)
|
||||
update(FDE[RuleNumber], RuleNumber);
|
||||
}
|
||||
}
|
||||
|
||||
assert(((CFAReg != (uint32_t)UNKNOWN && CFAOffset != UNKNOWN) ||
|
||||
|
@ -2893,9 +2873,8 @@ bool BinaryFunction::requiresAddressTranslation() const {
|
|||
|
||||
uint64_t BinaryFunction::getInstructionCount() const {
|
||||
uint64_t Count = 0;
|
||||
for (BinaryBasicBlock *const &Block : BasicBlocksLayout) {
|
||||
for (BinaryBasicBlock *const &Block : BasicBlocksLayout)
|
||||
Count += Block->getNumNonPseudos();
|
||||
}
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
@ -2913,12 +2892,10 @@ void BinaryFunction::clearDisasmState() {
|
|||
clearList(InterproceduralReferences);
|
||||
|
||||
if (BC.HasRelocations) {
|
||||
for (std::pair<const uint32_t, MCSymbol *> &LI : Labels) {
|
||||
for (std::pair<const uint32_t, MCSymbol *> &LI : Labels)
|
||||
BC.UndefinedSymbols.insert(LI.second);
|
||||
}
|
||||
if (FunctionEndLabel) {
|
||||
if (FunctionEndLabel)
|
||||
BC.UndefinedSymbols.insert(FunctionEndLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2932,11 +2909,9 @@ void BinaryFunction::setTrapOnEntry() {
|
|||
};
|
||||
|
||||
addTrapAtOffset(0);
|
||||
for (const std::pair<const uint32_t, MCSymbol *> &KV : getLabels()) {
|
||||
if (getSecondaryEntryPointSymbol(KV.second)) {
|
||||
for (const std::pair<const uint32_t, MCSymbol *> &KV : getLabels())
|
||||
if (getSecondaryEntryPointSymbol(KV.second))
|
||||
addTrapAtOffset(KV.first);
|
||||
}
|
||||
}
|
||||
|
||||
TrapsOnEntry = true;
|
||||
}
|
||||
|
@ -2958,14 +2933,12 @@ void BinaryFunction::setIgnored() {
|
|||
if (hasCFG()) {
|
||||
releaseCFG();
|
||||
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : BasicBlocks)
|
||||
delete BB;
|
||||
}
|
||||
clearList(BasicBlocks);
|
||||
|
||||
for (BinaryBasicBlock *BB : DeletedBasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : DeletedBasicBlocks)
|
||||
delete BB;
|
||||
}
|
||||
clearList(DeletedBasicBlocks);
|
||||
|
||||
clearList(BasicBlocksLayout);
|
||||
|
@ -3036,9 +3009,8 @@ namespace {
|
|||
std::string constructFilename(std::string Filename, std::string Annotation,
|
||||
std::string Suffix) {
|
||||
std::replace(Filename.begin(), Filename.end(), '/', '-');
|
||||
if (!Annotation.empty()) {
|
||||
if (!Annotation.empty())
|
||||
Annotation.insert(0, "-");
|
||||
}
|
||||
if (Filename.size() + Annotation.size() + Suffix.size() > MAX_PATH) {
|
||||
assert(Suffix.size() + Annotation.size() <= MAX_PATH);
|
||||
if (opts::Verbosity >= 1) {
|
||||
|
@ -3123,9 +3095,8 @@ void BinaryFunction::dumpGraph(raw_ostream &OS) const {
|
|||
Branch = "FT";
|
||||
}
|
||||
}
|
||||
if (IsJumpTable) {
|
||||
if (IsJumpTable)
|
||||
Branch = "JT";
|
||||
}
|
||||
OS << format("\"%s\" -> \"%s\" [label=\"%s", BB->getName().data(),
|
||||
Succ->getName().data(), Branch.c_str());
|
||||
|
||||
|
@ -3157,9 +3128,8 @@ void BinaryFunction::viewGraph() const {
|
|||
return;
|
||||
}
|
||||
dumpGraphToFile(std::string(Filename));
|
||||
if (DisplayGraph(Filename)) {
|
||||
if (DisplayGraph(Filename))
|
||||
errs() << "BOLT-ERROR: Can't display " << Filename << " with graphviz.\n";
|
||||
}
|
||||
if (std::error_code EC = sys::fs::remove(Filename)) {
|
||||
errs() << "BOLT-WARNING: " << EC.message() << ", failed to remove "
|
||||
<< Filename << "\n";
|
||||
|
@ -3187,9 +3157,8 @@ void BinaryFunction::dumpGraphToFile(std::string Filename) const {
|
|||
|
||||
bool BinaryFunction::validateCFG() const {
|
||||
bool Valid = true;
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : BasicBlocks)
|
||||
Valid &= BB->validateSuccessorInvariants();
|
||||
}
|
||||
|
||||
if (!Valid)
|
||||
return Valid;
|
||||
|
@ -3315,9 +3284,8 @@ void BinaryFunction::fixBranches() {
|
|||
auto L = BC.scopeLock();
|
||||
MIB->replaceBranchTarget(*CondBranch, TSuccessor->getLabel(), Ctx);
|
||||
}
|
||||
if (TSuccessor == FSuccessor) {
|
||||
if (TSuccessor == FSuccessor)
|
||||
BB->removeDuplicateConditionalSuccessor(CondBranch);
|
||||
}
|
||||
if (!NextBB ||
|
||||
((NextBB != TSuccessor || !IsSupported) && NextBB != FSuccessor)) {
|
||||
// If one of the branches is guaranteed to be "long" while the other
|
||||
|
@ -3634,9 +3602,8 @@ size_t BinaryFunction::computeHash(bool UseDFS,
|
|||
Opcode = Opcode >> 8;
|
||||
}
|
||||
|
||||
for (unsigned I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I) {
|
||||
for (unsigned I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I)
|
||||
HashString.append(OperandHashFunc(Inst.getOperand(I)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3660,19 +3627,16 @@ void BinaryFunction::insertBasicBlocks(
|
|||
BasicBlocks[I++] = BB.release();
|
||||
}
|
||||
|
||||
if (RecomputeLandingPads) {
|
||||
if (RecomputeLandingPads)
|
||||
recomputeLandingPads();
|
||||
} else {
|
||||
else
|
||||
updateBBIndices(0);
|
||||
}
|
||||
|
||||
if (UpdateLayout) {
|
||||
if (UpdateLayout)
|
||||
updateLayout(Start, NumNewBlocks);
|
||||
}
|
||||
|
||||
if (UpdateCFIState) {
|
||||
if (UpdateCFIState)
|
||||
updateCFIState(Start, NumNewBlocks);
|
||||
}
|
||||
}
|
||||
|
||||
BinaryFunction::iterator BinaryFunction::insertBasicBlocks(
|
||||
|
@ -3693,36 +3657,31 @@ BinaryFunction::iterator BinaryFunction::insertBasicBlocks(
|
|||
BasicBlocks[I++] = BB.release();
|
||||
}
|
||||
|
||||
if (RecomputeLandingPads) {
|
||||
if (RecomputeLandingPads)
|
||||
recomputeLandingPads();
|
||||
} else {
|
||||
else
|
||||
updateBBIndices(0);
|
||||
}
|
||||
|
||||
if (UpdateLayout) {
|
||||
if (UpdateLayout)
|
||||
updateLayout(*std::prev(RetIter), NumNewBlocks);
|
||||
}
|
||||
|
||||
if (UpdateCFIState) {
|
||||
if (UpdateCFIState)
|
||||
updateCFIState(*std::prev(RetIter), NumNewBlocks);
|
||||
}
|
||||
|
||||
return RetIter;
|
||||
}
|
||||
|
||||
void BinaryFunction::updateBBIndices(const unsigned StartIndex) {
|
||||
for (unsigned I = StartIndex; I < BasicBlocks.size(); ++I) {
|
||||
for (unsigned I = StartIndex; I < BasicBlocks.size(); ++I)
|
||||
BasicBlocks[I]->Index = I;
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryFunction::updateCFIState(BinaryBasicBlock *Start,
|
||||
const unsigned NumNewBlocks) {
|
||||
const int32_t CFIState = Start->getCFIStateAtExit();
|
||||
const unsigned StartIndex = getIndex(Start) + 1;
|
||||
for (unsigned I = 0; I < NumNewBlocks; ++I) {
|
||||
for (unsigned I = 0; I < NumNewBlocks; ++I)
|
||||
BasicBlocks[StartIndex + I]->setCFIState(CFIState);
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryFunction::updateLayout(BinaryBasicBlock *Start,
|
||||
|
@ -4039,12 +3998,10 @@ void BinaryFunction::adjustExecutionCount(uint64_t Count) {
|
|||
}
|
||||
|
||||
BinaryFunction::~BinaryFunction() {
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : BasicBlocks)
|
||||
delete BB;
|
||||
}
|
||||
for (BinaryBasicBlock *BB : DeletedBasicBlocks) {
|
||||
for (BinaryBasicBlock *BB : DeletedBasicBlocks)
|
||||
delete BB;
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryFunction::calculateLoopInfo() {
|
||||
|
@ -4068,9 +4025,8 @@ void BinaryFunction::calculateLoopInfo() {
|
|||
BLI->MaximumDepth = std::max(L->getLoopDepth(), BLI->MaximumDepth);
|
||||
|
||||
// Add nested loops in the stack.
|
||||
for (BinaryLoop::iterator I = L->begin(), E = L->end(); I != E; ++I) {
|
||||
for (BinaryLoop::iterator I = L->begin(), E = L->end(); I != E; ++I)
|
||||
St.push(*I);
|
||||
}
|
||||
|
||||
// Skip if no valid profile is found.
|
||||
if (!hasValidProfile()) {
|
||||
|
@ -4194,9 +4150,8 @@ void BinaryFunction::updateOutputValues(const MCAsmLayout &Layout) {
|
|||
|
||||
if (PrevBB) {
|
||||
uint64_t PrevBBEndAddress = BBAddress;
|
||||
if (BB->isCold() != PrevBB->isCold()) {
|
||||
if (BB->isCold() != PrevBB->isCold())
|
||||
PrevBBEndAddress = getOutputAddress() + getOutputSize();
|
||||
}
|
||||
PrevBB->setOutputEndAddress(PrevBBEndAddress);
|
||||
}
|
||||
PrevBB = BB;
|
||||
|
@ -4252,9 +4207,8 @@ uint64_t BinaryFunction::translateInputToOutputAddress(uint64_t Address) const {
|
|||
// Check if the address is associated with an instruction that is tracked
|
||||
// by address translation.
|
||||
auto KV = InputOffsetToAddressMap.find(Address - getAddress());
|
||||
if (KV != InputOffsetToAddressMap.end()) {
|
||||
if (KV != InputOffsetToAddressMap.end())
|
||||
return KV->second;
|
||||
}
|
||||
|
||||
// FIXME: #18950828 - we rely on relative offsets inside basic blocks to stay
|
||||
// intact. Instead we can use pseudo instructions and/or annotations.
|
||||
|
@ -4393,14 +4347,12 @@ DebugLocationsVector BinaryFunction::translateInputToOutputLocationList(
|
|||
const DebugLocationsVector &InputLL) const {
|
||||
DebugLocationsVector OutputLL;
|
||||
|
||||
if (isFolded()) {
|
||||
if (isFolded())
|
||||
return OutputLL;
|
||||
}
|
||||
|
||||
// If the function hasn't changed - there's nothing to update.
|
||||
if (!isEmitted()) {
|
||||
if (!isEmitted())
|
||||
return InputLL;
|
||||
}
|
||||
|
||||
uint64_t PrevEndAddress = 0;
|
||||
SmallVectorImpl<uint8_t> *PrevExpr = nullptr;
|
||||
|
@ -4480,22 +4432,19 @@ DebugLocationsVector BinaryFunction::translateInputToOutputLocationList(
|
|||
|
||||
void BinaryFunction::printLoopInfo(raw_ostream &OS) const {
|
||||
OS << "Loop Info for Function \"" << *this << "\"";
|
||||
if (hasValidProfile()) {
|
||||
if (hasValidProfile())
|
||||
OS << " (count: " << getExecutionCount() << ")";
|
||||
}
|
||||
OS << "\n";
|
||||
|
||||
std::stack<BinaryLoop *> St;
|
||||
for (auto I = BLI->begin(), E = BLI->end(); I != E; ++I) {
|
||||
for (auto I = BLI->begin(), E = BLI->end(); I != E; ++I)
|
||||
St.push(*I);
|
||||
}
|
||||
while (!St.empty()) {
|
||||
BinaryLoop *L = St.top();
|
||||
St.pop();
|
||||
|
||||
for (BinaryLoop::iterator I = L->begin(), E = L->end(); I != E; ++I) {
|
||||
for (BinaryLoop::iterator I = L->begin(), E = L->end(); I != E; ++I)
|
||||
St.push(*I);
|
||||
}
|
||||
|
||||
if (!hasValidProfile())
|
||||
continue;
|
||||
|
@ -4536,10 +4485,9 @@ bool BinaryFunction::isAArch64Veneer() const {
|
|||
if (BB.size() != 3)
|
||||
return false;
|
||||
|
||||
for (MCInst &Inst : BB) {
|
||||
for (MCInst &Inst : BB)
|
||||
if (!BC.MIB->hasAnnotation(Inst, "AArch64Veneer"))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -81,9 +81,8 @@ void BinaryFunction::postProcessProfile() {
|
|||
|
||||
// If we have at least some branch data for the function indicate that it
|
||||
// was executed.
|
||||
if (opts::FixFuncCounts && ExecutionCount == 0) {
|
||||
if (opts::FixFuncCounts && ExecutionCount == 0)
|
||||
ExecutionCount = 1;
|
||||
}
|
||||
|
||||
// Compute preliminary execution count for each basic block.
|
||||
for (BinaryBasicBlock *BB : BasicBlocks) {
|
||||
|
@ -146,9 +145,8 @@ void BinaryFunction::postProcessProfile() {
|
|||
continue;
|
||||
|
||||
auto CountAnnt = BC.MIB->tryGetAnnotationAs<uint64_t>(Inst, "Count");
|
||||
if (CountAnnt) {
|
||||
if (CountAnnt)
|
||||
BB->setExecutionCount(std::max(BB->getExecutionCount(), *CountAnnt));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -208,9 +206,8 @@ void BinaryFunction::mergeProfileDataInto(BinaryFunction &BF) const {
|
|||
return;
|
||||
|
||||
// Update function execution count.
|
||||
if (getExecutionCount() != BinaryFunction::COUNT_NO_PROFILE) {
|
||||
if (getExecutionCount() != BinaryFunction::COUNT_NO_PROFILE)
|
||||
BF.setExecutionCount(BF.getKnownExecutionCount() + getExecutionCount());
|
||||
}
|
||||
|
||||
// Since we are merging a valid profile, the new profile should be valid too.
|
||||
// It has either already been valid, or it has been cleaned up.
|
||||
|
@ -296,10 +293,9 @@ void BinaryFunction::inferFallThroughCounts() {
|
|||
// Calculate frequency of outgoing branches from this node according to
|
||||
// LBR data.
|
||||
uint64_t ReportedBranches = 0;
|
||||
for (const BinaryBasicBlock::BinaryBranchInfo &SuccBI : BB->branch_info()) {
|
||||
for (const BinaryBasicBlock::BinaryBranchInfo &SuccBI : BB->branch_info())
|
||||
if (SuccBI.Count != BinaryBasicBlock::COUNT_NO_PROFILE)
|
||||
ReportedBranches += SuccBI.Count;
|
||||
}
|
||||
|
||||
// Get taken count of conditional tail call if the block ends with one.
|
||||
uint64_t CTCTakenCount = 0;
|
||||
|
@ -314,9 +310,8 @@ void BinaryFunction::inferFallThroughCounts() {
|
|||
// for a landing pad to be associated with more than one basic blocks,
|
||||
// we may overestimate the frequency of throws for such blocks.
|
||||
uint64_t ReportedThrows = 0;
|
||||
for (const BinaryBasicBlock *LP : BB->landing_pads()) {
|
||||
for (const BinaryBasicBlock *LP : BB->landing_pads())
|
||||
ReportedThrows += LP->getExecutionCount();
|
||||
}
|
||||
|
||||
const uint64_t TotalReportedJumps =
|
||||
ReportedBranches + CTCTakenCount + ReportedThrows;
|
||||
|
|
|
@ -52,9 +52,8 @@ BinarySection::hash(const BinaryData &BD,
|
|||
const Relocation &Rel = *Begin++;
|
||||
Hash = hash_combine(
|
||||
Hash, hash_value(Contents.substr(Offset, Begin->Offset - Offset)));
|
||||
if (BinaryData *RelBD = BC.getBinaryDataByName(Rel.Symbol->getName())) {
|
||||
if (BinaryData *RelBD = BC.getBinaryDataByName(Rel.Symbol->getName()))
|
||||
Hash = hash_combine(Hash, hash(*RelBD, Cache));
|
||||
}
|
||||
Offset = Rel.Offset + Rel.getSize();
|
||||
}
|
||||
|
||||
|
@ -106,9 +105,8 @@ void BinarySection::emitAsData(MCStreamer &Streamer, StringRef NewName) const {
|
|||
SectionOffset += RelocationSize;
|
||||
}
|
||||
assert(SectionOffset <= SectionContents.size() && "overflow error");
|
||||
if (SectionOffset < SectionContents.size()) {
|
||||
if (SectionOffset < SectionContents.size())
|
||||
Streamer.emitBytes(SectionContents.substr(SectionOffset));
|
||||
}
|
||||
}
|
||||
|
||||
if (BC.HasRelocations && opts::HotData && isReordered())
|
||||
|
@ -134,10 +132,9 @@ void BinarySection::flushPendingRelocations(raw_pwrite_stream &OS,
|
|||
<< " address: 0x" << Twine::utohexstr(SectionAddress) << '\n'
|
||||
<< " offset: 0x" << Twine::utohexstr(SectionFileOffset) << '\n');
|
||||
|
||||
for (BinaryPatch &Patch : Patches) {
|
||||
for (BinaryPatch &Patch : Patches)
|
||||
OS.pwrite(Patch.Bytes.data(), Patch.Bytes.size(),
|
||||
SectionFileOffset + Patch.Offset);
|
||||
}
|
||||
|
||||
for (Relocation &Reloc : PendingRelocations) {
|
||||
uint64_t Value = Reloc.Addend;
|
||||
|
@ -194,10 +191,9 @@ void BinarySection::print(raw_ostream &OS) const {
|
|||
if (isTLS())
|
||||
OS << " (tls)";
|
||||
|
||||
if (opts::PrintRelocations) {
|
||||
if (opts::PrintRelocations)
|
||||
for (const Relocation &R : relocations())
|
||||
OS << "\n " << R;
|
||||
}
|
||||
}
|
||||
|
||||
BinarySection::RelocationSetType
|
||||
|
@ -243,9 +239,8 @@ void BinarySection::reorderContents(const std::vector<BinaryData *> &Order,
|
|||
const uint64_t SrcOffset = BD->getAddress() - getAddress();
|
||||
assert(SrcOffset < Contents.size());
|
||||
assert(SrcOffset == BD->getOffset());
|
||||
while (OS.tell() < BD->getOutputOffset()) {
|
||||
while (OS.tell() < BD->getOutputOffset())
|
||||
OS.write((unsigned char)0);
|
||||
}
|
||||
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: " << BD->getName() << " @ " << OS.tell()
|
||||
<< "\n");
|
||||
OS.write(&Src[SrcOffset], BD->getOutputSize());
|
||||
|
@ -275,12 +270,10 @@ std::string BinarySection::encodeELFNote(StringRef NameStr, StringRef DescStr,
|
|||
OS.write(reinterpret_cast<const char *>(&(DescSz)), 4);
|
||||
OS.write(reinterpret_cast<const char *>(&(Type)), 4);
|
||||
OS << NameStr << '\0';
|
||||
for (uint64_t I = NameSz; I < alignTo(NameSz, 4); ++I) {
|
||||
for (uint64_t I = NameSz; I < alignTo(NameSz, 4); ++I)
|
||||
OS << '\0';
|
||||
}
|
||||
OS << DescStr;
|
||||
for (uint64_t I = DescStr.size(); I < alignTo(DescStr.size(), 4); ++I) {
|
||||
for (uint64_t I = DescStr.size(); I < alignTo(DescStr.size(), 4); ++I)
|
||||
OS << '\0';
|
||||
}
|
||||
return OS.str();
|
||||
}
|
||||
|
|
|
@ -192,8 +192,9 @@ void DebugAddrWriter::addIndexAddress(uint64_t Address, uint32_t Index,
|
|||
if (Entry->second > Index)
|
||||
Map.updateAddressToIndex(Address, Index);
|
||||
Map.updateIndexToAddrss(Address, Index);
|
||||
} else
|
||||
} else {
|
||||
Map.insert(Address, Index);
|
||||
}
|
||||
}
|
||||
|
||||
AddressSectionBuffer DebugAddrWriter::finalize() {
|
||||
|
|
|
@ -281,13 +281,11 @@ DynoStats getDynoStats(const BinaryFunction &BF) {
|
|||
const MCSymbol *FBB = nullptr;
|
||||
MCInst *CondBranch = nullptr;
|
||||
MCInst *UncondBranch = nullptr;
|
||||
if (!BB->analyzeBranch(TBB, FBB, CondBranch, UncondBranch)) {
|
||||
if (!BB->analyzeBranch(TBB, FBB, CondBranch, UncondBranch))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!CondBranch && !UncondBranch) {
|
||||
if (!CondBranch && !UncondBranch)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Simple unconditional branch.
|
||||
if (!CondBranch) {
|
||||
|
|
|
@ -229,9 +229,8 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
|
|||
const uint64_t TTEntryAddress = TTEntry + LSDASectionAddress;
|
||||
uint64_t TypeAddress =
|
||||
*Data.getEncodedPointer(&TTEntry, TTypeEncoding, TTEntryAddress);
|
||||
if ((TTypeEncoding & DW_EH_PE_pcrel) && TypeAddress == TTEntryAddress) {
|
||||
if ((TTypeEncoding & DW_EH_PE_pcrel) && TypeAddress == TTEntryAddress)
|
||||
TypeAddress = 0;
|
||||
}
|
||||
if (TypeAddress == 0) {
|
||||
OS << "<all>";
|
||||
return;
|
||||
|
@ -241,11 +240,10 @@ void BinaryFunction::parseLSDA(ArrayRef<uint8_t> LSDASectionData,
|
|||
assert(PointerOrErr && "failed to decode indirect address");
|
||||
TypeAddress = *PointerOrErr;
|
||||
}
|
||||
if (BinaryData *TypeSymBD = BC.getBinaryDataAtAddress(TypeAddress)) {
|
||||
if (BinaryData *TypeSymBD = BC.getBinaryDataAtAddress(TypeAddress))
|
||||
OS << TypeSymBD->getName();
|
||||
} else {
|
||||
else
|
||||
OS << "0x" << Twine::utohexstr(TypeAddress);
|
||||
}
|
||||
};
|
||||
if (opts::PrintExceptions)
|
||||
outs() << " actions: ";
|
||||
|
@ -610,9 +608,8 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
|
|||
raw_string_ostream OS(Str);
|
||||
// Manually encode this instruction using CFI escape
|
||||
OS << Opcode;
|
||||
if (Opcode != DW_CFA_def_cfa_expression) {
|
||||
if (Opcode != DW_CFA_def_cfa_expression)
|
||||
encodeULEB128(Instr.Ops[0], OS);
|
||||
}
|
||||
encodeULEB128(ExprBytes.size(), OS);
|
||||
OS << ExprBytes;
|
||||
Function.addCFIInstruction(
|
||||
|
@ -620,9 +617,8 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
|
|||
break;
|
||||
}
|
||||
case DW_CFA_MIPS_advance_loc8:
|
||||
if (opts::Verbosity >= 1) {
|
||||
if (opts::Verbosity >= 1)
|
||||
errs() << "BOLT-WARNING: DW_CFA_MIPS_advance_loc unimplemented\n";
|
||||
}
|
||||
return false;
|
||||
case DW_CFA_GNU_window_save:
|
||||
case DW_CFA_lo_user:
|
||||
|
@ -643,15 +639,13 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction &Function) const {
|
|||
return true;
|
||||
};
|
||||
|
||||
for (const CFIProgram::Instruction &Instr : CurFDE.getLinkedCIE()->cfis()) {
|
||||
for (const CFIProgram::Instruction &Instr : CurFDE.getLinkedCIE()->cfis())
|
||||
if (!decodeFrameInstruction(Instr))
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const CFIProgram::Instruction &Instr : CurFDE.cfis()) {
|
||||
for (const CFIProgram::Instruction &Instr : CurFDE.cfis())
|
||||
if (!decodeFrameInstruction(Instr))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -771,11 +765,10 @@ Error EHFrameParser::parseCIE(uint64_t StartOffset) {
|
|||
// Skip data alignment
|
||||
Data.getSLEB128(&Offset);
|
||||
// Skip return address register
|
||||
if (Version == 1) {
|
||||
if (Version == 1)
|
||||
Offset += 1;
|
||||
} else {
|
||||
else
|
||||
Data.getULEB128(&Offset);
|
||||
}
|
||||
|
||||
uint32_t FDEPointerEncoding = DW_EH_PE_absptr;
|
||||
uint32_t LSDAPointerEncoding = DW_EH_PE_omit;
|
||||
|
|
|
@ -107,9 +107,8 @@ void bolt::JumpTable::print(raw_ostream &OS) const {
|
|||
OS << "Jump table " << getName() << " for function " << *Parent << " at 0x"
|
||||
<< Twine::utohexstr(getAddress()) << " with a total count of " << Count
|
||||
<< ":\n";
|
||||
for (const uint64_t EntryOffset : OffsetEntries) {
|
||||
for (const uint64_t EntryOffset : OffsetEntries)
|
||||
OS << " 0x" << Twine::utohexstr(EntryOffset) << '\n';
|
||||
}
|
||||
for (const MCSymbol *Entry : Entries) {
|
||||
auto LI = Labels.find(Offset);
|
||||
if (Offset && LI != Labels.end()) {
|
||||
|
|
|
@ -35,10 +35,9 @@ bool MCPlusBuilder::equals(const MCInst &A, const MCInst &B,
|
|||
if (NumOperands != MCPlus::getNumPrimeOperands(B))
|
||||
return false;
|
||||
|
||||
for (unsigned Index = 0; Index < NumOperands; ++Index) {
|
||||
for (unsigned Index = 0; Index < NumOperands; ++Index)
|
||||
if (!equals(A.getOperand(Index), B.getOperand(Index), Comp))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -295,9 +294,8 @@ void MCPlusBuilder::getClobberedRegs(const MCInst &Inst,
|
|||
const MCInstrDesc &InstInfo = Info->get(Inst.getOpcode());
|
||||
|
||||
const MCPhysReg *ImplicitDefs = InstInfo.getImplicitDefs();
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitDefs(); I != E; ++I) {
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitDefs(); I != E; ++I)
|
||||
Regs |= getAliases(ImplicitDefs[I], /*OnlySmaller=*/false);
|
||||
}
|
||||
|
||||
for (unsigned I = 0, E = InstInfo.getNumDefs(); I != E; ++I) {
|
||||
const MCOperand &Operand = Inst.getOperand(I);
|
||||
|
@ -313,13 +311,11 @@ void MCPlusBuilder::getTouchedRegs(const MCInst &Inst, BitVector &Regs) const {
|
|||
const MCInstrDesc &InstInfo = Info->get(Inst.getOpcode());
|
||||
|
||||
const MCPhysReg *ImplicitDefs = InstInfo.getImplicitDefs();
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitDefs(); I != E; ++I) {
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitDefs(); I != E; ++I)
|
||||
Regs |= getAliases(ImplicitDefs[I], /*OnlySmaller=*/false);
|
||||
}
|
||||
const MCPhysReg *ImplicitUses = InstInfo.getImplicitUses();
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitUses(); I != E; ++I) {
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitUses(); I != E; ++I)
|
||||
Regs |= getAliases(ImplicitUses[I], /*OnlySmaller=*/false);
|
||||
}
|
||||
|
||||
for (unsigned I = 0, E = Inst.getNumOperands(); I != E; ++I) {
|
||||
if (!Inst.getOperand(I).isReg())
|
||||
|
@ -335,9 +331,8 @@ void MCPlusBuilder::getWrittenRegs(const MCInst &Inst, BitVector &Regs) const {
|
|||
const MCInstrDesc &InstInfo = Info->get(Inst.getOpcode());
|
||||
|
||||
const MCPhysReg *ImplicitDefs = InstInfo.getImplicitDefs();
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitDefs(); I != E; ++I) {
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitDefs(); I != E; ++I)
|
||||
Regs |= getAliases(ImplicitDefs[I], /*OnlySmaller=*/true);
|
||||
}
|
||||
|
||||
for (unsigned I = 0, E = InstInfo.getNumDefs(); I != E; ++I) {
|
||||
const MCOperand &Operand = Inst.getOperand(I);
|
||||
|
@ -353,9 +348,8 @@ void MCPlusBuilder::getUsedRegs(const MCInst &Inst, BitVector &Regs) const {
|
|||
const MCInstrDesc &InstInfo = Info->get(Inst.getOpcode());
|
||||
|
||||
const MCPhysReg *ImplicitUses = InstInfo.getImplicitUses();
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitUses(); I != E; ++I) {
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitUses(); I != E; ++I)
|
||||
Regs |= getAliases(ImplicitUses[I], /*OnlySmaller=*/true);
|
||||
}
|
||||
|
||||
for (unsigned I = 0, E = Inst.getNumOperands(); I != E; ++I) {
|
||||
if (!Inst.getOperand(I).isReg())
|
||||
|
@ -381,16 +375,14 @@ void MCPlusBuilder::getSrcRegs(const MCInst &Inst, BitVector &Regs) const {
|
|||
return;
|
||||
}
|
||||
|
||||
if (isRep(Inst)) {
|
||||
if (isRep(Inst))
|
||||
getRepRegs(Regs);
|
||||
}
|
||||
|
||||
const MCInstrDesc &InstInfo = Info->get(Inst.getOpcode());
|
||||
|
||||
const MCPhysReg *ImplicitUses = InstInfo.getImplicitUses();
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitUses(); I != E; ++I) {
|
||||
for (unsigned I = 0, E = InstInfo.getNumImplicitUses(); I != E; ++I)
|
||||
Regs |= getAliases(ImplicitUses[I], /*OnlySmaller=*/true);
|
||||
}
|
||||
|
||||
for (unsigned I = InstInfo.getNumDefs(), E = InstInfo.getNumOperands();
|
||||
I != E; ++I) {
|
||||
|
@ -411,10 +403,11 @@ bool MCPlusBuilder::hasUseOfPhysReg(const MCInst &MI, unsigned Reg) const {
|
|||
if (MI.getOperand(I).isReg() &&
|
||||
RegInfo->isSubRegisterEq(Reg, MI.getOperand(I).getReg()))
|
||||
return true;
|
||||
if (const uint16_t *ImpUses = InstInfo.ImplicitUses)
|
||||
if (const uint16_t *ImpUses = InstInfo.ImplicitUses) {
|
||||
for (; *ImpUses; ++ImpUses)
|
||||
if (*ImpUses == Reg || RegInfo->isSubRegister(Reg, *ImpUses))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -439,23 +432,19 @@ const BitVector &MCPlusBuilder::getAliases(MCPhysReg Reg,
|
|||
}
|
||||
std::queue<MCPhysReg> Worklist;
|
||||
// Propagate alias info upwards. Skip reg 0 (mapped to NoRegister)
|
||||
for (MCPhysReg I = 1, E = RegInfo->getNumRegs(); I < E; ++I) {
|
||||
for (MCPhysReg I = 1, E = RegInfo->getNumRegs(); I < E; ++I)
|
||||
Worklist.push(I);
|
||||
}
|
||||
while (!Worklist.empty()) {
|
||||
MCPhysReg I = Worklist.front();
|
||||
Worklist.pop();
|
||||
for (MCSubRegIterator SI(I, RegInfo); SI.isValid(); ++SI) {
|
||||
for (MCSubRegIterator SI(I, RegInfo); SI.isValid(); ++SI)
|
||||
AliasMap[I] |= AliasMap[*SI];
|
||||
}
|
||||
for (MCSuperRegIterator SI(I, RegInfo); SI.isValid(); ++SI) {
|
||||
for (MCSuperRegIterator SI(I, RegInfo); SI.isValid(); ++SI)
|
||||
Worklist.push(*SI);
|
||||
}
|
||||
}
|
||||
// Propagate parent reg downwards
|
||||
for (MCPhysReg I = 1, E = RegInfo->getNumRegs(); I < E; ++I) {
|
||||
for (MCPhysReg I = 1, E = RegInfo->getNumRegs(); I < E; ++I)
|
||||
Worklist.push(I);
|
||||
}
|
||||
while (!Worklist.empty()) {
|
||||
MCPhysReg I = Worklist.front();
|
||||
Worklist.pop();
|
||||
|
@ -495,9 +484,8 @@ uint8_t MCPlusBuilder::getRegSize(MCPhysReg Reg) const {
|
|||
// Build size map
|
||||
for (auto I = RegInfo->regclass_begin(), E = RegInfo->regclass_end(); I != E;
|
||||
++I) {
|
||||
for (MCPhysReg Reg : *I) {
|
||||
for (MCPhysReg Reg : *I)
|
||||
SizeMap[Reg] = I->getSizeInBits() / 8;
|
||||
}
|
||||
}
|
||||
|
||||
return SizeMap[Reg];
|
||||
|
|
Loading…
Reference in New Issue