Skip to content

Commit

Permalink
Merge branch 'llvm:main' into check-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ZijunZhaoCCK authored Jan 26, 2024
2 parents 2ab3f7b + e0ade45 commit 30be503
Show file tree
Hide file tree
Showing 879 changed files with 19,746 additions and 9,044 deletions.
13 changes: 7 additions & 6 deletions .ci/generate-buildkite-pipeline-premerge
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ set -o pipefail

# Environment variables script works with:

# Fetch origin/main to have an up to date merge base for main...HEAD diff.
git fetch origin main:main
# Set by buildkite
: ${BUILDKITE_PULL_REQUEST_BASE_BRANCH:=}
: ${BUILDKITE_COMMIT:=}
: ${BUILDKITE_BRANCH:=}
# Fetch origin to have an up to date merge base for the diff.
git fetch origin
# List of files affected by this commit
: ${MODIFIED_FILES:=$(git diff --name-only main...HEAD)}
: ${MODIFIED_FILES:=$(git diff --name-only origin/${BUILDKITE_PULL_REQUEST_BASE_BRANCH}...HEAD)}
# Filter rules for generic windows tests
: ${WINDOWS_AGENTS:='{"queue": "windows"}'}
# Filter rules for generic linux tests
: ${LINUX_AGENTS:='{"queue": "linux"}'}
# Set by buildkite
: ${BUILDKITE_COMMIT:=}
: ${BUILDKITE_BRANCH:=}

reviewID="$(git log --format=%B -n 1 | sed -nE 's/^Review-ID:[[:space:]]*(.+)$/\1/p')"
if [[ "${reviewID}" != "" ]]; then
Expand Down
33 changes: 1 addition & 32 deletions .github/workflows/issue-release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
if: >-
(github.repository == 'llvm/llvm-project') &&
!startswith(github.event.comment.body, '<!--IGNORE-->') &&
Expand Down Expand Up @@ -65,35 +66,3 @@ jobs:
--branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
--issue-number ${{ github.event.issue.number }} \
auto
create-pull-request:
name: Create Pull Request
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
if: >-
(github.repository == 'llvm/llvm-project') &&
!startswith(github.event.comment.body, '<!--IGNORE-->') &&
contains(github.event.comment.body, '/branch ')
steps:
- name: Fetch LLVM sources
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Environment
run: |
pip install -r ./llvm/utils/git/requirements.txt
- name: Create Pull Request
run: |
printf "%s" "$COMMENT_BODY" |
./llvm/utils/git/github-automation.py \
--repo "$GITHUB_REPOSITORY" \
--token ${{ github.token }} \
release-workflow \
--branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
--issue-number ${{ github.event.issue.number }} \
auto
2 changes: 1 addition & 1 deletion .github/workflows/version-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_version_from_tag(tag):

m = re.match("llvmorg-([0-9]+)-init", tag)
if m:
return (m.group(1), "0", "0")
return (m.group(1), "1", "0")

raise Exception(f"error: Tag is not valid: {tag}")

Expand Down
13 changes: 9 additions & 4 deletions bolt/docs/BAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Cold functions table header
```

### Functions table
Hot and cold functions tables share the encoding except difference marked below.
Hot and cold functions tables share the encoding except differences marked below.
Header:
| Entry | Encoding | Description |
| ------ | ----- | ----------- |
Expand All @@ -80,18 +80,23 @@ Hot indices are delta encoded, implicitly starting at zero.
| `Address` | Continuous, Delta, ULEB128 | Function address in the output binary |
| `HotIndex` | Delta, ULEB128 | Cold functions only: index of corresponding hot function in hot functions table |
| `NumEntries` | ULEB128 | Number of address translation entries for a function |
| `EqualElems` | ULEB128 | Hot functions only: number of equal offsets in the beginning of a function |
| `BranchEntries` | Bitmask, `alignTo(EqualElems, 8)` bits | Hot functions only: if `EqualElems` is non-zero, bitmask denoting entries with `BRANCHENTRY` bit |

Function header is followed by `NumEntries` pairs of offsets for current
function.
Function header is followed by `EqualElems` offsets (hot functions only) and
`NumEntries-EqualElems` (`NumEntries` for cold functions) pairs of offsets for
current function.

### Address translation table
Delta encoding means that only the difference with the previous corresponding
entry is encoded. Input offsets implicitly start at zero.
| Entry | Encoding | Description |
| ------ | ------| ----------- |
| `OutputOffset` | Continuous, Delta, ULEB128 | Function offset in output binary |
| `InputOffset` | Delta, SLEB128 | Function offset in input binary with `BRANCHENTRY` LSB bit |
| `InputOffset` | Optional, Delta, SLEB128 | Function offset in input binary with `BRANCHENTRY` LSB bit |

`BRANCHENTRY` bit denotes whether a given offset pair is a control flow source
(branch or call instruction). If not set, it signifies a control flow target
(basic block offset).
`InputAddr` is omitted for equal offsets in input and output function. In this
case, `BRANCHENTRY` bits are encoded separately in a `BranchEntries` bitvector.
8 changes: 8 additions & 0 deletions bolt/include/bolt/Profile/BoltAddressTranslation.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ class BoltAddressTranslation {
void parseMaps(std::vector<uint64_t> &HotFuncs, uint64_t &PrevAddress,
DataExtractor &DE, uint64_t &Offset, Error &Err);

/// Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
/// entries in function address translation map.
APInt calculateBranchEntriesBitMask(MapTy &Map, size_t EqualElems);

/// Calculate the number of equal offsets (output = input) in the beginning
/// of the function.
size_t getNumEqualOffsets(const MapTy &Map) const;

std::map<uint64_t, MapTy> Maps;

/// Links outlined cold bocks to their original function
Expand Down
2 changes: 1 addition & 1 deletion bolt/include/bolt/Rewrite/DWARFRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DWARFRewriter {
std::unordered_map<uint64_t, uint64_t> DwoRangesBase;

std::unordered_map<DWARFUnit *, uint64_t> LineTablePatchMap;
std::unordered_map<DWARFUnit *, uint64_t> TypeUnitRelocMap;
std::unordered_map<const DWARFUnit *, uint64_t> TypeUnitRelocMap;

/// Entries for GDB Index Types CU List
using GDBIndexTUEntryType = std::vector<GDBIndexTUEntry>;
Expand Down
22 changes: 17 additions & 5 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ PrintMemData("print-mem-data",
cl::ZeroOrMore,
cl::cat(BoltCategory));

cl::opt<std::string> CompDirOverride(
"comp-dir-override",
cl::desc("overrides DW_AT_comp_dir, and provides an alterantive base "
"location, which is used with DW_AT_dwo_name to construct a path "
"to *.dwo files."),
cl::Hidden, cl::init(""), cl::cat(BoltCategory));
} // namespace opts

namespace llvm {
Expand Down Expand Up @@ -1574,12 +1580,18 @@ void BinaryContext::preprocessDWODebugInfo() {
for (const std::unique_ptr<DWARFUnit> &CU : DwCtx->compile_units()) {
DWARFUnit *const DwarfUnit = CU.get();
if (std::optional<uint64_t> DWOId = DwarfUnit->getDWOId()) {
DWARFUnit *DWOCU = DwarfUnit->getNonSkeletonUnitDIE(false).getDwarfUnit();
std::string DWOName = dwarf::toString(
DwarfUnit->getUnitDIE().find(
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
"");
SmallString<16> AbsolutePath;
if (!opts::CompDirOverride.empty()) {
sys::path::append(AbsolutePath, opts::CompDirOverride);
sys::path::append(AbsolutePath, DWOName);
}
DWARFUnit *DWOCU =
DwarfUnit->getNonSkeletonUnitDIE(false, AbsolutePath).getDwarfUnit();
if (!DWOCU->isDWOUnit()) {
std::string DWOName = dwarf::toString(
DwarfUnit->getUnitDIE().find(
{dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
"");
outs() << "BOLT-WARNING: Debug Fission: DWO debug information for "
<< DWOName
<< " was not retrieved and won't be updated. Please check "
Expand Down
16 changes: 9 additions & 7 deletions bolt/lib/Passes/BinaryPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,26 +1417,28 @@ void PrintProgramStats::runOnFunctions(BinaryContext &BC) {
<< (NumNonSimpleProfiledFunctions == 1 ? "" : "s")
<< " with profile could not be optimized\n";
}
if (NumStaleProfileFunctions) {
if (NumAllStaleFunctions) {
const float PctStale =
NumStaleProfileFunctions / (float)NumAllProfiledFunctions * 100.0f;
NumAllStaleFunctions / (float)NumAllProfiledFunctions * 100.0f;
auto printErrorOrWarning = [&]() {
if (PctStale > opts::StaleThreshold)
errs() << "BOLT-ERROR: ";
else
errs() << "BOLT-WARNING: ";
};
printErrorOrWarning();
errs() << NumStaleProfileFunctions
errs() << NumAllStaleFunctions
<< format(" (%.1f%% of all profiled)", PctStale) << " function"
<< (NumStaleProfileFunctions == 1 ? "" : "s")
<< (NumAllStaleFunctions == 1 ? "" : "s")
<< " have invalid (possibly stale) profile."
" Use -report-stale to see the list.\n";
if (TotalSampleCount > 0) {
printErrorOrWarning();
errs() << StaleSampleCount << " out of " << TotalSampleCount
<< " samples in the binary ("
<< format("%.1f", ((100.0f * StaleSampleCount) / TotalSampleCount))
errs() << (StaleSampleCount + InferredSampleCount) << " out of "
<< TotalSampleCount << " samples in the binary ("
<< format("%.1f",
((100.0f * (StaleSampleCount + InferredSampleCount)) /
TotalSampleCount))
<< "%) belong to functions with invalid"
" (possibly stale) profile.\n";
}
Expand Down
91 changes: 85 additions & 6 deletions bolt/lib/Profile/BoltAddressTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "bolt/Profile/BoltAddressTranslation.h"
#include "bolt/Core/BinaryFunction.h"
#include "llvm/ADT/APInt.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/LEB128.h"
Expand Down Expand Up @@ -110,6 +111,34 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
outs() << "BOLT-INFO: Wrote " << Maps.size() << " BAT maps\n";
}

APInt BoltAddressTranslation::calculateBranchEntriesBitMask(MapTy &Map,
size_t EqualElems) {
APInt BitMask(alignTo(EqualElems, 8), 0);
size_t Index = 0;
for (std::pair<const uint32_t, uint32_t> &KeyVal : Map) {
if (Index == EqualElems)
break;
const uint32_t OutputOffset = KeyVal.second;
if (OutputOffset & BRANCHENTRY)
BitMask.setBit(Index);
++Index;
}
return BitMask;
}

size_t BoltAddressTranslation::getNumEqualOffsets(const MapTy &Map) const {
size_t EqualOffsets = 0;
for (const std::pair<const uint32_t, uint32_t> &KeyVal : Map) {
const uint32_t OutputOffset = KeyVal.first;
const uint32_t InputOffset = KeyVal.second >> 1;
if (OutputOffset == InputOffset)
++EqualOffsets;
else
break;
}
return EqualOffsets;
}

template <bool Cold>
void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
uint64_t &PrevAddress, raw_ostream &OS) {
Expand Down Expand Up @@ -139,14 +168,35 @@ void BoltAddressTranslation::writeMaps(std::map<uint64_t, MapTy> &Maps,
PrevIndex = HotIndex;
}
encodeULEB128(NumEntries, OS);
// For hot fragments only: encode the number of equal offsets
// (output = input) in the beginning of the function. Only encode one offset
// in these cases.
const size_t EqualElems = Cold ? 0 : getNumEqualOffsets(Map);
if (!Cold) {
encodeULEB128(EqualElems, OS);
if (EqualElems) {
const size_t BranchEntriesBytes = alignTo(EqualElems, 8) / 8;
APInt BranchEntries = calculateBranchEntriesBitMask(Map, EqualElems);
OS.write(reinterpret_cast<const char *>(BranchEntries.getRawData()),
BranchEntriesBytes);
LLVM_DEBUG({
dbgs() << "BranchEntries: ";
SmallString<8> BitMaskStr;
BranchEntries.toString(BitMaskStr, 2, false);
dbgs() << BitMaskStr << '\n';
});
}
}
size_t Index = 0;
uint64_t InOffset = 0;
// Output and Input addresses and delta-encoded
for (std::pair<const uint32_t, uint32_t> &KeyVal : Map) {
const uint64_t OutputAddress = KeyVal.first + Address;
encodeULEB128(OutputAddress - PrevAddress, OS);
PrevAddress = OutputAddress;
encodeSLEB128(KeyVal.second - InOffset, OS);
InOffset = KeyVal.second;
if (Index++ >= EqualElems)
encodeSLEB128(KeyVal.second - InOffset, OS);
InOffset = KeyVal.second; // Keeping InOffset as if BRANCHENTRY is encoded
}
}
}
Expand Down Expand Up @@ -197,6 +247,29 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
HotFuncs.push_back(Address);
}
const uint32_t NumEntries = DE.getULEB128(&Offset, &Err);
// Equal offsets, hot fragments only.
size_t EqualElems = 0;
APInt BEBitMask;
if (!Cold) {
EqualElems = DE.getULEB128(&Offset, &Err);
LLVM_DEBUG(dbgs() << formatv("Equal offsets: {0}, {1} bytes\n",
EqualElems, getULEB128Size(EqualElems)));
if (EqualElems) {
const size_t BranchEntriesBytes = alignTo(EqualElems, 8) / 8;
BEBitMask = APInt(alignTo(EqualElems, 8), 0);
LoadIntFromMemory(
BEBitMask,
reinterpret_cast<const uint8_t *>(
DE.getBytes(&Offset, BranchEntriesBytes, &Err).data()),
BranchEntriesBytes);
LLVM_DEBUG({
dbgs() << "BEBitMask: ";
SmallString<8> BitMaskStr;
BEBitMask.toString(BitMaskStr, 2, false);
dbgs() << BitMaskStr << ", " << BranchEntriesBytes << " bytes\n";
});
}
}
MapTy Map;

LLVM_DEBUG(dbgs() << "Parsing " << NumEntries << " entries for 0x"
Expand All @@ -207,14 +280,20 @@ void BoltAddressTranslation::parseMaps(std::vector<uint64_t> &HotFuncs,
const uint64_t OutputAddress = PrevAddress + OutputDelta;
const uint64_t OutputOffset = OutputAddress - Address;
PrevAddress = OutputAddress;
const int64_t InputDelta = DE.getSLEB128(&Offset, &Err);
InputOffset += InputDelta;
int64_t InputDelta = 0;
if (J < EqualElems) {
InputOffset = (OutputOffset << 1) | BEBitMask[J];
} else {
InputDelta = DE.getSLEB128(&Offset, &Err);
InputOffset += InputDelta;
}
Map.insert(std::pair<uint32_t, uint32_t>(OutputOffset, InputOffset));
LLVM_DEBUG(
dbgs() << formatv("{0:x} -> {1:x} ({2}/{3}b -> {4}/{5}b), {6:x}\n",
OutputOffset, InputOffset, OutputDelta,
encodeULEB128(OutputDelta, nulls()), InputDelta,
encodeSLEB128(InputDelta, nulls()), OutputAddress));
getULEB128Size(OutputDelta), InputDelta,
(J < EqualElems) ? 0 : getSLEB128Size(InputDelta),
OutputAddress));
}
Maps.insert(std::pair<uint64_t, MapTy>(Address, Map));
}
Expand Down
Loading

0 comments on commit 30be503

Please sign in to comment.