Skip to content

Commit

Permalink
Merged main:8474bfdd149b into amd-gfx:24c3950d1abc
Browse files Browse the repository at this point in the history
Local branch amd-gfx 24c3950 Manually merged main:6a91b7051df7 into amd-gfx:cbe644758d17
Remote branch main 8474bfd [NFC] [docs] Clarify we are talking about a function
  • Loading branch information
SC llvm team authored and dstutt committed Nov 10, 2023
2 parents 24c3950 + 8474bfd commit f34f6bd
Show file tree
Hide file tree
Showing 450 changed files with 22,218 additions and 2,633 deletions.
2 changes: 1 addition & 1 deletion bolt/docs/doxygen.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ PREDEFINED =
EXPAND_AS_DEFINED =

# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
# remove all refrences to function-like macros that are alone on a line, have an
# remove all references to function-like macros that are alone on a line, have an
# all uppercase name, and do not end with a semicolon. Such function macros are
# typically used for boiler-plate code, and will confuse the parser if not
# removed.
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ class BinaryContext {
bool registerFragment(BinaryFunction &TargetFunction,
BinaryFunction &Function) const;

/// Add unterprocedural reference for \p Function to \p Address
/// Add interprocedural reference for \p Function to \p Address
void addInterproceduralReference(BinaryFunction *Function, uint64_t Address) {
InterproceduralReferences.push_back({Function, Address});
}
Expand Down
5 changes: 3 additions & 2 deletions bolt/include/bolt/Core/BinaryFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,8 @@ class BinaryFunction {

/// Rebuilds BBs layout, ignoring dead BBs. Returns the number of removed
/// BBs and the removed number of bytes of code.
std::pair<unsigned, uint64_t> eraseInvalidBBs();
std::pair<unsigned, uint64_t>
eraseInvalidBBs(const MCCodeEmitter *Emitter = nullptr);

/// Get the relative order between two basic blocks in the original
/// layout. The result is > 0 if B occurs before A and < 0 if B
Expand Down Expand Up @@ -2172,7 +2173,7 @@ class BinaryFunction {
/// is corrupted. If it is unable to fix it, it returns false.
bool finalizeCFIState();

/// Return true if this function needs an address-transaltion table after
/// Return true if this function needs an address-translation table after
/// its code emission.
bool requiresAddressTranslation() const;

Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/BinarySection.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BinarySection {
return *ContentsOrErr;
}

/// Get the set of relocations refering to data in this section that
/// Get the set of relocations referring to data in this section that
/// has been reordered. The relocation offsets will be modified to
/// reflect the new data locations.
RelocationSetType reorderRelocations(bool Inplace) const;
Expand Down
12 changes: 6 additions & 6 deletions bolt/include/bolt/Core/DebugData.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::optional<AttrInfo> findAttributeInfo(const DWARFDie DIE,
dwarf::Attribute Attr);

// DWARF5 Header in order of encoding.
// Types represent encodnig sizes.
// Types represent encoding sizes.
using UnitLengthType = uint32_t;
using VersionType = uint16_t;
using AddressSizeType = uint8_t;
Expand Down Expand Up @@ -372,13 +372,13 @@ class DebugAddrWriter {
}

/// Updates AddressToIndex Map.
/// Follows the same symantics as unordered map [].
/// Follows the same semantics as unordered map [].
void updateAddressToIndex(uint64_t Address, uint32_t Index) {
AddressToIndex[Address] = Index;
}

/// Updates IndexToAddress Map.
/// Follows the same symantics as unordered map [].
/// Follows the same semantics as unordered map [].
void updateIndexToAddrss(uint64_t Address, uint32_t Index) {
IndexToAddress[Index] = Address;
}
Expand Down Expand Up @@ -474,7 +474,7 @@ class DebugStrWriter {
}

/// Adds string to .debug_str.
/// On first invokation it initializes internal data stractures.
/// On first invocation it initializes internal data structures.
uint32_t addString(StringRef Str);

/// Returns False if no strings were added to .debug_str.
Expand All @@ -485,7 +485,7 @@ class DebugStrWriter {
std::mutex WriterMutex;
/// Initializes Buffer and Stream.
void initialize();
/// Creats internal data stractures.
/// Creates internal data structures.
void create();
std::unique_ptr<DebugStrBufferVector> StrBuffer;
std::unique_ptr<raw_svector_ostream> StrStream;
Expand Down Expand Up @@ -585,7 +585,7 @@ class DebugLoclistWriter : public DebugLocWriter {
void finalize(DIEBuilder &DIEBldr, DIE &Die) override;

/// Returns CU ID.
/// For Skelton CU it is a CU Offset.
/// For Skeleton CU it is a CU Offset.
/// For DWO CU it is a DWO ID.
uint64_t getCUID() const {
return CU.isDWOUnit() ? *CU.getDWOId() : CU.getOffset();
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/DynoStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DynoStats {
/// Maps instruction opcodes to:
/// 1. Accumulated executed instruction counts.
/// 2. a multimap that records highest execution counts, function names,
/// and BB offsets where intructions of these opcodes occur.
/// and BB offsets where instructions of these opcodes occur.
using MaxOpcodeHistogramTy =
std::multimap<uint64_t, std::pair<StringRef, uint32_t>>;
using OpcodeHistogramTy =
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class EHFrameParser {
/// void PatcherCallback(uint64_t Value, uint64_t Offset, uint64_t Type);
///
/// where Value is a value of the reference, Offset - is an offset into the
/// frame data at which the reference occured, and Type is a DWARF encoding
/// frame data at which the reference occurred, and Type is a DWARF encoding
/// type of the reference.
static Error parse(DWARFDataExtractor Data, uint64_t EHFrameAddress,
PatcherCallbackTy PatcherCallback);
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ class MCPlusBuilder {

/// Replace the compound memory operand of Inst with an immediate operand.
/// The value of the immediate operand is computed by reading the \p
/// ConstantData array starting from \p offset and assuming little-endianess.
/// ConstantData array starting from \p offset and assuming little-endianness.
/// Return true on success. The given instruction is modified in place.
virtual bool replaceMemOperandWithImm(MCInst &Inst, StringRef ConstantData,
uint64_t Offset) const {
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Core/Relocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct Relocation {

/// Handle special cases when relocation should not be processed by BOLT or
/// change relocation \p Type to proper one before continuing if \p Contents
/// and \P Type mismatch occured.
/// and \P Type mismatch occurred.
static bool skipRelocationProcess(uint64_t &Type, uint64_t Contents);

// Adjust value depending on relocation type (make it PC relative or not)
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Passes/FixRelaxationPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
//
// This file declares the FixRelaxations class, which locates instructions with
// wrong targets and fixes them. Such problems usually occures when linker
// wrong targets and fixes them. Such problems usually occurs when linker
// relaxes (changes) instructions, but doesn't fix relocations types properly
// for them.
//
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Passes/InstrumentationSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BinaryFunction;
// counters. It also provides function names and offsets used when writing the
// fdata file.

// Location information -- analoguous to the concept of the same name in fdata
// Location information -- analogous to the concept of the same name in fdata
// writing/reading. The difference is that the name is stored as an index to a
// string table written separately.
struct LocDescription {
Expand Down
8 changes: 4 additions & 4 deletions bolt/include/bolt/Passes/ReorderAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ClusterAlgorithm {
virtual void clusterBasicBlocks(BinaryFunction &BF,
bool ComputeEdges = false) = 0;

/// Compute for each cluster its averagae execution frequency, that is
/// Compute for each cluster its average execution frequency, that is
/// the sum of average frequencies of its blocks (execution count / # instrs).
/// The average frequencies are stored in the AvgFreq vector, index by the
/// cluster indices in the Clusters vector.
Expand Down Expand Up @@ -128,7 +128,7 @@ class MinBranchGreedyClusterAlgorithm : public GreedyClusterAlgorithm {
// A -> B with execution count 500,
// A -> C with execution count 100, and
// D -> B with execution count 150
// wher B, C are the only successors of A and A, D are thr only predessecors
// where B, C are the only successors of A and A, D are the only predecessors
// of B. Then if we choose to layout edge A -> B as a fallthrough, the win in
// branches would be 500 - 100 - 150 = 250. That is the weight of edge A->B.
int64_t calculateWeight(const EdgeTy &E, const BinaryFunction &BF) const;
Expand All @@ -144,8 +144,8 @@ class MinBranchGreedyClusterAlgorithm : public GreedyClusterAlgorithm {
void reset() override;
};

/// Objects of this class implement various basic block reordering alogrithms.
/// Most of these algorithms depend on a clustering alogrithm.
/// Objects of this class implement various basic block reordering algorithms.
/// Most of these algorithms depend on a clustering algorithm.
/// Here we have 3 conflicting goals as to how to layout clusters. If we want
/// to minimize jump offsets, we should put clusters with heavy inter-cluster
/// dependence as close as possible. If we want to maximize the probability
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Passes/StackReachingUses.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StackReachingUses
/// Answer whether the stack position written by the store represented in
/// \p StoreFIE is loaded from or consumed in any way. The set of all
/// relevant expressions reaching this store should be in \p Candidates.
/// If \p IncludelocalAccesses is false, we only consider wheter there is
/// If \p IncludelocalAccesses is false, we only consider whether there is
/// a callee that consumes this stack position.
bool isStoreUsed(const FrameIndexEntry &StoreFIE, ExprIterator Candidates,
bool IncludeLocalAccesses = true) const;
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Passes/StokeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Pass to get information for functions for the Stoke Optimization
// To use the Stoke optimization technique to optimize the HHVM.
// This Pass solves the two major problems to use the Stoke program without
// proting its code:
// probing its code:
//
// 1. Stoke works on function level, but it is only limited to relative
// small functions which are loop-free, call-free, exception-free, etc.
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Passes/TailDuplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class TailDuplication : public BinaryFunctionPass {
/// Returns true if Reg is used by Inst
bool regIsUsed(const MCInst &Inst, unsigned Reg, BinaryContext &BC) const;

/// Returns true if Reg is overwritten before its used by StartBB's sucessors
/// Returns true if Reg is overwritten before its used by StartBB's successors
bool isOverwrittenBeforeUsed(BinaryBasicBlock &StartBB, unsigned Reg) const;

/// Constant and Copy Propagate for the block formed by OriginalBB and
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Profile/DataAggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class DataAggregator : public DataReader {
ErrorOr<AggregatedLBREntry> parseAggregatedLBREntry();

/// Parse either buildid:offset or just offset, representing a location in the
/// binary. Used exclusevely for pre-aggregated LBR samples.
/// binary. Used exclusively for pre-aggregated LBR samples.
ErrorOr<Location> parseLocationOrOffset();

/// Check if a field separator is the next char to parse and, if yes, consume
Expand Down
4 changes: 2 additions & 2 deletions bolt/include/bolt/Profile/DataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ class DataReader : public ProfileReaderBase {
///
/// The examples records branches from local symbol func (from t2.c), offset
/// 11, to global symbol globalfunc, offset 1d, with 1775 branches, no
/// mispreds. Of these branches, 1002 were preceeded by a sequence of
/// mispreds. Of these branches, 1002 were preceded by a sequence of
/// branches from func, offset 18 to offset 20 and then from offset 31 to
/// offset d. The rest 773 branches were preceeded by a different sequence
/// offset d. The rest 773 branches were preceded by a different sequence
/// of branches, from func, offset 18 to offset 60 and then from offset 71 to
/// offset d.
std::error_code parse();
Expand Down
1 change: 1 addition & 0 deletions bolt/include/bolt/Rewrite/RewriteInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ class RewriteInstance {

/// Common section names.
static StringRef getEHFrameSectionName() { return ".eh_frame"; }
static StringRef getRelaDynSectionName() { return ".rela.dyn"; }

/// An instance of the input binary we are processing, externally owned.
llvm::object::ELFObjectFileBase *InputFile;
Expand Down
6 changes: 3 additions & 3 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ void BinaryContext::foldFunction(BinaryFunction &ChildBF,
}

void BinaryContext::fixBinaryDataHoles() {
assert(validateObjectNesting() && "object nesting inconsitency detected");
assert(validateObjectNesting() && "object nesting inconsistency detected");

for (BinarySection &Section : allocatableSections()) {
std::vector<std::pair<uint64_t, uint64_t>> Holes;
Expand Down Expand Up @@ -1451,7 +1451,7 @@ void BinaryContext::fixBinaryDataHoles() {
}
}

assert(validateObjectNesting() && "object nesting inconsitency detected");
assert(validateObjectNesting() && "object nesting inconsistency detected");
assert(validateHoles() && "top level hole detected in object map");
}

Expand Down Expand Up @@ -1796,7 +1796,7 @@ void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
MarkerSymType BinaryContext::getMarkerType(const SymbolRef &Symbol) const {
// For aarch64 and riscv, the ABI defines mapping symbols so we identify data
// in the code section (see IHI0056B). $x identifies a symbol starting code or
// the end of a data chunk inside code, $d indentifies start of data.
// the end of a data chunk inside code, $d identifies start of data.
if ((!isAArch64() && !isRISCV()) || ELFSymbolRef(Symbol).getSize())
return MarkerSymType::NONE;

Expand Down
7 changes: 4 additions & 3 deletions bolt/lib/Core/BinaryFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ void BinaryFunction::markUnreachableBlocks() {

// Any unnecessary fallthrough jumps revealed after calling eraseInvalidBBs
// will be cleaned up by fixBranches().
std::pair<unsigned, uint64_t> BinaryFunction::eraseInvalidBBs() {
std::pair<unsigned, uint64_t>
BinaryFunction::eraseInvalidBBs(const MCCodeEmitter *Emitter) {
DenseSet<const BinaryBasicBlock *> InvalidBBs;
unsigned Count = 0;
uint64_t Bytes = 0;
Expand All @@ -331,7 +332,7 @@ std::pair<unsigned, uint64_t> BinaryFunction::eraseInvalidBBs() {
assert(!isEntryPoint(*BB) && "all entry blocks must be valid");
InvalidBBs.insert(BB);
++Count;
Bytes += BC.computeCodeSize(BB->begin(), BB->end());
Bytes += BC.computeCodeSize(BB->begin(), BB->end(), Emitter);
}
}

Expand Down Expand Up @@ -4306,7 +4307,7 @@ BinaryFunction::translateInputToOutputRange(DebugAddressRange InRange) const {
// block boundaries.
auto translateBlockOffset = [&](const uint64_t Offset) {
const uint64_t OutAddress = BB.getOutputAddressRange().first + Offset;
return OutAddress;
return std::min(OutAddress, BB.getOutputAddressRange().second);
};

uint64_t OutLowPC = BB.getOutputAddressRange().first;
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Core/BinarySection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void BinarySection::print(raw_ostream &OS) const {
BinarySection::RelocationSetType
BinarySection::reorderRelocations(bool Inplace) const {
assert(PendingRelocations.empty() &&
"reodering pending relocations not supported");
"reordering pending relocations not supported");
RelocationSetType NewRelocations;
for (const Relocation &Rel : relocations()) {
uint64_t RelAddr = Rel.Offset + getAddress();
Expand Down
6 changes: 3 additions & 3 deletions bolt/lib/Core/DebugData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ uint64_t DebugRangeListsSectionWriter::addRanges(
}

struct LocListsRangelistsHeader {
UnitLengthType UnitLength; // Size of loclist entris section, not including
UnitLengthType UnitLength; // Size of loclist entries section, not including
// size of header.
VersionType Version;
AddressSizeType AddressSize;
Expand Down Expand Up @@ -449,8 +449,8 @@ static void updateAddressBase(DIEBuilder &DIEBlder, DebugAddrWriter &AddrWriter,
}

void DebugAddrWriter::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
// Handling the case wehre debug information is a mix of Debug fission and
// monolitic.
// Handling the case where debug information is a mix of Debug fission and
// monolithic.
if (!CU.getDWOId())
return;
const uint64_t CUID = getCUID(CU);
Expand Down
2 changes: 1 addition & 1 deletion bolt/lib/Core/DynoStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void DynoStats::operator+=(const DynoStats &Other) {
if (I == OpcodeHistogram.end()) {
OpcodeHistogram.emplace(Stat);
} else {
// Merge Other Historgrams, log only the opts::PrintDynoOpcodeStat'th
// Merge other histograms, log only the opts::PrintDynoOpcodeStat'th
// maximum counts.
I->second.first += Stat.second.first;
auto &MMap = I->second.second;
Expand Down
4 changes: 2 additions & 2 deletions bolt/lib/Core/Relocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static bool skipRelocationProcessAArch64(uint64_t &Type, uint64_t Contents) {
// changed TLS access model (e.g. changed global dynamic model
// to initial exec), thus changing the instructions. The static
// relocations might be invalid at this point and we might no
// need to proccess these relocations anymore.
// need to process these relocations anymore.
// More information could be found by searching
// elfNN_aarch64_tls_relax in bfd
switch (Type) {
Expand Down Expand Up @@ -503,7 +503,7 @@ static uint64_t extractValueAArch64(uint64_t Type, uint64_t Contents,
case ELF::R_AARCH64_MOVW_UABS_G1:
case ELF::R_AARCH64_MOVW_UABS_G0_NC:
case ELF::R_AARCH64_MOVW_UABS_G0:
// The shift goest in bits 22:21 of MOV* instructions
// The shift goes in bits 22:21 of MOV* instructions
uint8_t Shift = (Contents >> 21) & 0x3;
// Immediate goes in bits 20:5
Contents = (Contents >> 5) & 0xffff;
Expand Down
18 changes: 13 additions & 5 deletions bolt/lib/Passes/ADRRelaxationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
continue;
}

BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
if (TargetBF && TargetBF == &BF)
continue;
// Don't relax adr if it points to the same function and it is not split
// and BF initial size is < 1MB.
const unsigned OneMB = 0x100000;
if (!BF.isSplit() && BF.getSize() < OneMB) {
BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
if (TargetBF && TargetBF == &BF)
continue;
}

MCPhysReg Reg;
BC.MIB->getADRReg(Inst, Reg);
Expand All @@ -72,14 +77,17 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {

if (It != BB.begin() && BC.MIB->isNoop(*std::prev(It))) {
It = BB.eraseInstruction(std::prev(It));
} else if (opts::StrictMode && !BF.isSimple()) {
} else if (std::next(It) != BB.end() && BC.MIB->isNoop(*std::next(It))) {
BB.eraseInstruction(std::next(It));
} else if (!opts::StrictMode && !BF.isSimple()) {
// If the function is not simple, it may contain a jump table undetected
// by us. This jump table may use an offset from the branch instruction
// to land in the desired place. If we add new instructions, we
// invalidate this offset, so we have to rely on linker-inserted NOP to
// replace it with ADRP, and abort if it is not present.
auto L = BC.scopeLock();
errs() << formatv("BOLT-ERROR: Cannot relax adr in non-simple function "
"{0}. Can't proceed in current mode.\n",
"{0}. Use --strict option to override\n",
BF.getOneName());
PassFailed = true;
return;
Expand Down
Loading

0 comments on commit f34f6bd

Please sign in to comment.