Skip to content

Commit 03fd1f6

Browse files
author
iclsrc
committed
Merge from 'main' to 'sycl-web' (59 commits)
CONFLICT (content): Merge conflict in llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
2 parents 4ee7897 + 586ecdf commit 03fd1f6

File tree

334 files changed

+5755
-2533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

334 files changed

+5755
-2533
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ enum IndirectCallPromotionType : char {
7575
ICP_ALL /// Perform ICP on calls and jump tables.
7676
};
7777

78+
/// Hash functions supported for BF/BB hashing.
79+
enum class HashFunction : char {
80+
StdHash, /// std::hash, implementation is platform-dependent. Provided for
81+
/// backwards compatibility.
82+
XXH3, /// llvm::xxh3_64bits, the default.
83+
Default = XXH3,
84+
};
85+
7886
/// Information on a single indirect call to a particular callee.
7987
struct IndirectCallProfile {
8088
MCSymbol *Symbol;
@@ -2234,18 +2242,21 @@ class BinaryFunction {
22342242
///
22352243
/// If \p UseDFS is set, process basic blocks in DFS order. Otherwise, use
22362244
/// the existing layout order.
2245+
/// \p HashFunction specifies which function is used for BF hashing.
22372246
///
22382247
/// By default, instruction operands are ignored while calculating the hash.
22392248
/// The caller can change this via passing \p OperandHashFunc function.
22402249
/// The return result of this function will be mixed with internal hash.
22412250
size_t computeHash(
2242-
bool UseDFS = false,
2251+
bool UseDFS = false, HashFunction HashFunction = HashFunction::Default,
22432252
OperandHashFuncTy OperandHashFunc = [](const MCOperand &) {
22442253
return std::string();
22452254
}) const;
22462255

22472256
/// Compute hash values for each block of the function.
2248-
void computeBlockHashes() const;
2257+
/// \p HashFunction specifies which function is used for BB hashing.
2258+
void
2259+
computeBlockHashes(HashFunction HashFunction = HashFunction::Default) const;
22492260

22502261
void setDWARFUnit(DWARFUnit *Unit) { DwarfUnit = Unit; }
22512262

bolt/include/bolt/Core/DebugData.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,6 @@ class DebugStrOffsetsWriter {
459459
std::unique_ptr<raw_svector_ostream> StrOffsetsStream;
460460
std::map<uint32_t, uint32_t> IndexToAddressMap;
461461
std::unordered_map<uint64_t, uint64_t> ProcessedBaseOffsets;
462-
// Section size not including header.
463-
uint32_t CurrentSectionSize{0};
464462
bool StrOffsetSectionWasModified = false;
465463
};
466464

bolt/include/bolt/Profile/ProfileYAMLMapping.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ template <> struct ScalarBitSetTraits<PROFILE_PF> {
178178
}
179179
};
180180

181+
template <> struct ScalarEnumerationTraits<llvm::bolt::HashFunction> {
182+
using HashFunction = llvm::bolt::HashFunction;
183+
static void enumeration(IO &io, HashFunction &value) {
184+
io.enumCase(value, "std-hash", HashFunction::StdHash);
185+
io.enumCase(value, "xxh3", HashFunction::XXH3);
186+
}
187+
};
188+
181189
namespace bolt {
182190
struct BinaryProfileHeader {
183191
uint32_t Version{1};
@@ -188,6 +196,7 @@ struct BinaryProfileHeader {
188196
std::string Origin; // How the profile was obtained.
189197
std::string EventNames; // Events used for sample profile.
190198
bool IsDFSOrder{true}; // Whether using DFS block order in function profile
199+
llvm::bolt::HashFunction HashFunction; // Hash used for BB/BF hashing
191200
};
192201
} // end namespace bolt
193202

@@ -200,6 +209,8 @@ template <> struct MappingTraits<bolt::BinaryProfileHeader> {
200209
YamlIO.mapOptional("profile-origin", Header.Origin);
201210
YamlIO.mapOptional("profile-events", Header.EventNames);
202211
YamlIO.mapOptional("dfs-order", Header.IsDFSOrder);
212+
YamlIO.mapOptional("hash-func", Header.HashFunction,
213+
llvm::bolt::HashFunction::StdHash);
203214
}
204215
};
205216

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,7 +3633,7 @@ BinaryFunction::BasicBlockListType BinaryFunction::dfs() const {
36333633
return DFS;
36343634
}
36353635

3636-
size_t BinaryFunction::computeHash(bool UseDFS,
3636+
size_t BinaryFunction::computeHash(bool UseDFS, HashFunction HashFunction,
36373637
OperandHashFuncTy OperandHashFunc) const {
36383638
if (size() == 0)
36393639
return 0;
@@ -3652,7 +3652,13 @@ size_t BinaryFunction::computeHash(bool UseDFS,
36523652
for (const BinaryBasicBlock *BB : Order)
36533653
HashString.append(hashBlock(BC, *BB, OperandHashFunc));
36543654

3655-
return Hash = llvm::xxh3_64bits(HashString);
3655+
switch (HashFunction) {
3656+
case HashFunction::StdHash:
3657+
return Hash = std::hash<std::string>{}(HashString);
3658+
case HashFunction::XXH3:
3659+
return Hash = llvm::xxh3_64bits(HashString);
3660+
}
3661+
llvm_unreachable("Unhandled HashFunction");
36563662
}
36573663

36583664
void BinaryFunction::insertBasicBlocks(

bolt/lib/Core/BinaryFunctionProfile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ void BinaryFunction::mergeProfileDataInto(BinaryFunction &BF) const {
225225
for (const BinaryBasicBlock *BBSucc : BB->successors()) {
226226
(void)BBSucc;
227227
assert(getIndex(BBSucc) == BF.getIndex(*BBMergeSI));
228+
(void)BBMergeSI;
228229

229230
// At this point no branch count should be set to COUNT_NO_PROFILE.
230231
assert(BII->Count != BinaryBasicBlock::COUNT_NO_PROFILE &&

bolt/lib/Core/DebugData.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,10 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
889889
// Handling re-use of str-offsets section.
890890
if (RetVal == ProcessedBaseOffsets.end() || StrOffsetSectionWasModified) {
891891
// Writing out the header for each section.
892-
support::endian::write(*StrOffsetsStream, CurrentSectionSize + 4,
893-
llvm::endianness::little);
892+
support::endian::write(
893+
*StrOffsetsStream,
894+
static_cast<uint32_t>(IndexToAddressMap.size() * 4 + 4),
895+
llvm::endianness::little);
894896
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(5),
895897
llvm::endianness::little);
896898
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(0),

bolt/lib/Passes/IdenticalCodeFolding.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ void IdenticalCodeFolding::runOnFunctions(BinaryContext &BC) {
360360

361361
// Pre-compute hash before pushing into hashtable.
362362
// Hash instruction operands to minimize hash collisions.
363-
BF.computeHash(opts::ICFUseDFS, [&BC](const MCOperand &Op) {
364-
return hashInstOperand(BC, Op);
365-
});
363+
BF.computeHash(
364+
opts::ICFUseDFS, HashFunction::Default,
365+
[&BC](const MCOperand &Op) { return hashInstOperand(BC, Op); });
366366
};
367367

368368
ParallelUtilities::PredicateTy SkipFunc = [&](const BinaryFunction &BF) {

bolt/lib/Passes/VeneerElimination.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void VeneerElimination::runOnFunctions(BinaryContext &BC) {
8989
LLVM_DEBUG(
9090
dbgs() << "BOLT-INFO: number of linker-inserted veneers call sites: "
9191
<< VeneerCallers << "\n");
92+
(void)VeneerCallers;
9293
}
9394

9495
} // namespace bolt

bolt/lib/Profile/StaleProfileMatching.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class StaleMatcher {
225225
std::unordered_map<uint16_t, std::vector<HashBlockPairType>> OpHashToBlocks;
226226
};
227227

228-
void BinaryFunction::computeBlockHashes() const {
228+
void BinaryFunction::computeBlockHashes(HashFunction HashFunction) const {
229229
if (size() == 0)
230230
return;
231231

@@ -241,12 +241,26 @@ void BinaryFunction::computeBlockHashes() const {
241241
// Hashing complete instructions.
242242
std::string InstrHashStr = hashBlock(
243243
BC, *BB, [&](const MCOperand &Op) { return hashInstOperand(BC, Op); });
244-
uint64_t InstrHash = llvm::xxh3_64bits(InstrHashStr);
245-
BlendedHashes[I].InstrHash = (uint16_t)InstrHash;
244+
if (HashFunction == HashFunction::StdHash) {
245+
uint64_t InstrHash = std::hash<std::string>{}(InstrHashStr);
246+
BlendedHashes[I].InstrHash = (uint16_t)hash_value(InstrHash);
247+
} else if (HashFunction == HashFunction::XXH3) {
248+
uint64_t InstrHash = llvm::xxh3_64bits(InstrHashStr);
249+
BlendedHashes[I].InstrHash = (uint16_t)InstrHash;
250+
} else {
251+
llvm_unreachable("Unhandled HashFunction");
252+
}
246253
// Hashing opcodes.
247254
std::string OpcodeHashStr = hashBlockLoose(BC, *BB);
248-
OpcodeHashes[I] = llvm::xxh3_64bits(OpcodeHashStr);
249-
BlendedHashes[I].OpcodeHash = (uint16_t)OpcodeHashes[I];
255+
if (HashFunction == HashFunction::StdHash) {
256+
OpcodeHashes[I] = std::hash<std::string>{}(OpcodeHashStr);
257+
BlendedHashes[I].OpcodeHash = (uint16_t)hash_value(OpcodeHashes[I]);
258+
} else if (HashFunction == HashFunction::XXH3) {
259+
OpcodeHashes[I] = llvm::xxh3_64bits(OpcodeHashStr);
260+
BlendedHashes[I].OpcodeHash = (uint16_t)OpcodeHashes[I];
261+
} else {
262+
llvm_unreachable("Unhandled HashFunction");
263+
}
250264
}
251265

252266
// Initialize neighbor hash.
@@ -258,15 +272,25 @@ void BinaryFunction::computeBlockHashes() const {
258272
uint64_t SuccHash = OpcodeHashes[SuccBB->getIndex()];
259273
Hash = hashing::detail::hash_16_bytes(Hash, SuccHash);
260274
}
261-
BlendedHashes[I].SuccHash = (uint8_t)Hash;
275+
if (HashFunction == HashFunction::StdHash) {
276+
// Compatibility with old behavior.
277+
BlendedHashes[I].SuccHash = (uint8_t)hash_value(Hash);
278+
} else {
279+
BlendedHashes[I].SuccHash = (uint8_t)Hash;
280+
}
262281

263282
// Append hashes of predecessors.
264283
Hash = 0;
265284
for (BinaryBasicBlock *PredBB : BB->predecessors()) {
266285
uint64_t PredHash = OpcodeHashes[PredBB->getIndex()];
267286
Hash = hashing::detail::hash_16_bytes(Hash, PredHash);
268287
}
269-
BlendedHashes[I].PredHash = (uint8_t)Hash;
288+
if (HashFunction == HashFunction::StdHash) {
289+
// Compatibility with old behavior.
290+
BlendedHashes[I].PredHash = (uint8_t)hash_value(Hash);
291+
} else {
292+
BlendedHashes[I].PredHash = (uint8_t)Hash;
293+
}
270294
}
271295

272296
// Assign hashes.
@@ -682,7 +706,7 @@ bool YAMLProfileReader::inferStaleProfile(
682706
<< "\"" << BF.getPrintName() << "\"\n");
683707

684708
// Make sure that block hashes are up to date.
685-
BF.computeBlockHashes();
709+
BF.computeBlockHashes(YamlBP.Header.HashFunction);
686710

687711
const BinaryFunction::BasicBlockOrderType BlockOrder(
688712
BF.getLayout().block_begin(), BF.getLayout().block_end());

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ bool YAMLProfileReader::parseFunctionProfile(
8383
BinaryContext &BC = BF.getBinaryContext();
8484

8585
const bool IsDFSOrder = YamlBP.Header.IsDFSOrder;
86+
const HashFunction HashFunction = YamlBP.Header.HashFunction;
8687
bool ProfileMatched = true;
8788
uint64_t MismatchedBlocks = 0;
8889
uint64_t MismatchedCalls = 0;
@@ -98,7 +99,8 @@ bool YAMLProfileReader::parseFunctionProfile(
9899
FuncRawBranchCount += YamlSI.Count;
99100
BF.setRawBranchCount(FuncRawBranchCount);
100101

101-
if (!opts::IgnoreHash && YamlBF.Hash != BF.computeHash(IsDFSOrder)) {
102+
if (!opts::IgnoreHash &&
103+
YamlBF.Hash != BF.computeHash(IsDFSOrder, HashFunction)) {
102104
if (opts::Verbosity >= 1)
103105
errs() << "BOLT-WARNING: function hash mismatch\n";
104106
ProfileMatched = false;
@@ -326,6 +328,17 @@ bool YAMLProfileReader::mayHaveProfileData(const BinaryFunction &BF) {
326328
}
327329

328330
Error YAMLProfileReader::readProfile(BinaryContext &BC) {
331+
if (opts::Verbosity >= 1) {
332+
outs() << "BOLT-INFO: YAML profile with hash: ";
333+
switch (YamlBP.Header.HashFunction) {
334+
case HashFunction::StdHash:
335+
outs() << "std::hash\n";
336+
break;
337+
case HashFunction::XXH3:
338+
outs() << "xxh3\n";
339+
break;
340+
}
341+
}
329342
YamlProfileToFunction.resize(YamlBP.Functions.size() + 1);
330343

331344
auto profileMatches = [](const yaml::bolt::BinaryFunctionProfile &Profile,
@@ -348,7 +361,8 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
348361

349362
// Recompute hash once per function.
350363
if (!opts::IgnoreHash)
351-
Function.computeHash(YamlBP.Header.IsDFSOrder);
364+
Function.computeHash(YamlBP.Header.IsDFSOrder,
365+
YamlBP.Header.HashFunction);
352366

353367
if (profileMatches(YamlBF, Function))
354368
matchProfileToFunction(YamlBF, Function);

0 commit comments

Comments
 (0)