Skip to content

Commit 8662845

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:626c7ce33f850831949e4e724016ddbff3a34990 into amd-gfx:1d2f2b3d50fe
Local branch amd-gfx 1d2f2b3 Manual merge remote-tracking branch llvm.org/main into amd-gfx Remote branch main 626c7ce [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (llvm#97984)
2 parents 1d2f2b3 + 626c7ce commit 8662845

File tree

1,194 files changed

+32706
-15855
lines changed

Some content is hidden

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

1,194 files changed

+32706
-15855
lines changed

.github/new-prs-labeler.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,29 @@ backend:AArch64:
775775
- clang/include/clang/Sema/SemaARM.h
776776
- clang/lib/Sema/SemaARM.cpp
777777

778+
backend:Hexagon:
779+
- clang/include/clang/Basic/BuiltinsHexagon*.def
780+
- clang/include/clang/Sema/SemaHexagon.h
781+
- clang/lib/Basic/Targets/Hexagon.*
782+
- clang/lib/CodeGen/Targets/Hexagon.cpp
783+
- clang/lib/Driver/ToolChains/Hexagon.*
784+
- clang/lib/Sema/SemaHexagon.cpp
785+
- lld/ELF/Arch/Hexagon.cpp
786+
- lldb/source/Plugins/ABI/Hexagon/**
787+
- lldb/source/Plugins/DynamicLoader/Hexagon-DYLD/**
788+
- llvm/include/llvm/BinaryFormat/ELFRelocs/Hexagon.def
789+
- llvm/include/llvm/IR/IntrinsicsHexagon*
790+
- llvm/include/llvm/Support/Hexagon*
791+
- llvm/lib/Support/Hexagon*
792+
- llvm/lib/Target/Hexagon/**
793+
- llvm/test/CodeGen/Hexagon/**
794+
- llvm/test/CodeGen/*/Hexagon/**
795+
- llvm/test/DebugInfo/*/Hexagon/**
796+
- llvm/test/Transforms/*/Hexagon
797+
- llvm/test/MC/Disassembler/Hexagon/**
798+
- llvm/test/MC/Hexagon/**
799+
- llvm/test/tools/llvm-objdump/ELF/Hexagon/**
800+
778801
backend:loongarch:
779802
- llvm/include/llvm/IR/IntrinsicsLoongArch.td
780803
- llvm/test/MC/LoongArch/**

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ jobs:
6363
cxx: [ 'clang++-19' ]
6464
include:
6565
- config: 'generic-gcc'
66-
cc: 'gcc-13'
67-
cxx: 'g++-13'
66+
cc: 'gcc-14'
67+
cxx: 'g++-14'
6868
steps:
6969
- uses: actions/checkout@v4
7070
- name: ${{ matrix.config }}.${{ matrix.cxx }}
@@ -101,8 +101,8 @@ jobs:
101101
cxx: [ 'clang++-19' ]
102102
include:
103103
- config: 'generic-gcc-cxx11'
104-
cc: 'gcc-13'
105-
cxx: 'g++-13'
104+
cc: 'gcc-14'
105+
cxx: 'g++-14'
106106
- config: 'generic-cxx23'
107107
cc: 'clang-17'
108108
cxx: 'clang++-17'

bolt/include/bolt/Profile/YAMLProfileReader.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,29 @@ class YAMLProfileReader : public ProfileReaderBase {
7373
bool parseFunctionProfile(BinaryFunction &Function,
7474
const yaml::bolt::BinaryFunctionProfile &YamlBF);
7575

76+
/// Checks if a function profile matches a binary function.
77+
bool profileMatches(const yaml::bolt::BinaryFunctionProfile &Profile,
78+
const BinaryFunction &BF);
79+
7680
/// Infer function profile from stale data (collected on older binaries).
7781
bool inferStaleProfile(BinaryFunction &Function,
7882
const yaml::bolt::BinaryFunctionProfile &YamlBF);
7983

8084
/// Initialize maps for profile matching.
8185
void buildNameMaps(BinaryContext &BC);
8286

87+
/// Matches functions using exact name.
88+
size_t matchWithExactName();
89+
90+
/// Matches function using LTO comomon name.
91+
size_t matchWithLTOCommonName();
92+
93+
/// Matches functions using exact hash.
94+
size_t matchWithHash(BinaryContext &BC);
95+
96+
/// Matches functions with similarly named profiled functions.
97+
size_t matchWithNameSimilarity(BinaryContext &BC);
98+
8399
/// Update matched YAML -> BinaryFunction pair.
84100
void matchProfileToFunction(yaml::bolt::BinaryFunctionProfile &YamlBF,
85101
BinaryFunction &BF) {
@@ -93,9 +109,6 @@ class YAMLProfileReader : public ProfileReaderBase {
93109
ProfiledFunctions.emplace(&BF);
94110
}
95111

96-
/// Matches functions with similarly named profiled functions.
97-
uint64_t matchWithNameSimilarity(BinaryContext &BC);
98-
99112
/// Check if the profile uses an event with a given \p Name.
100113
bool usesEvent(StringRef Name) const;
101114
};

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,7 @@ struct CFISnapshot {
25382538
case MCCFIInstruction::OpWindowSave:
25392539
case MCCFIInstruction::OpNegateRAState:
25402540
case MCCFIInstruction::OpLLVMDefAspaceCfa:
2541+
case MCCFIInstruction::OpLabel:
25412542
llvm_unreachable("unsupported CFI opcode");
25422543
break;
25432544
case MCCFIInstruction::OpRememberState:
@@ -2675,6 +2676,7 @@ struct CFISnapshotDiff : public CFISnapshot {
26752676
case MCCFIInstruction::OpWindowSave:
26762677
case MCCFIInstruction::OpNegateRAState:
26772678
case MCCFIInstruction::OpLLVMDefAspaceCfa:
2679+
case MCCFIInstruction::OpLabel:
26782680
llvm_unreachable("unsupported CFI opcode");
26792681
return false;
26802682
case MCCFIInstruction::OpRememberState:
@@ -2823,6 +2825,7 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
28232825
case MCCFIInstruction::OpWindowSave:
28242826
case MCCFIInstruction::OpNegateRAState:
28252827
case MCCFIInstruction::OpLLVMDefAspaceCfa:
2828+
case MCCFIInstruction::OpLabel:
28262829
llvm_unreachable("unsupported CFI opcode");
28272830
break;
28282831
case MCCFIInstruction::OpGnuArgsSize:

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
129129
LLVM_DEBUG(dbgs() << " Cold part\n");
130130
for (const FunctionFragment &FF :
131131
Function.getLayout().getSplitFragments()) {
132+
// Skip empty fragments to avoid adding zero-address entries to maps.
133+
if (FF.empty())
134+
continue;
132135
ColdPartSource.emplace(FF.getAddress(), Function.getOutputAddress());
133136
Map.clear();
134137
for (const BinaryBasicBlock *const BB : FF)

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 97 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,13 @@ Error YAMLProfileReader::preprocessProfile(BinaryContext &BC) {
342342
return Error::success();
343343
}
344344

345+
bool YAMLProfileReader::profileMatches(
346+
const yaml::bolt::BinaryFunctionProfile &Profile, const BinaryFunction &BF) {
347+
if (opts::IgnoreHash)
348+
return Profile.NumBasicBlocks == BF.size();
349+
return Profile.Hash == static_cast<uint64_t>(BF.getHash());
350+
}
351+
345352
bool YAMLProfileReader::mayHaveProfileData(const BinaryFunction &BF) {
346353
if (opts::MatchProfileWithFunctionHash)
347354
return true;
@@ -358,8 +365,92 @@ bool YAMLProfileReader::mayHaveProfileData(const BinaryFunction &BF) {
358365
return false;
359366
}
360367

361-
uint64_t YAMLProfileReader::matchWithNameSimilarity(BinaryContext &BC) {
362-
uint64_t MatchedWithNameSimilarity = 0;
368+
size_t YAMLProfileReader::matchWithExactName() {
369+
size_t MatchedWithExactName = 0;
370+
// This first pass assigns profiles that match 100% by name and by hash.
371+
for (auto [YamlBF, BF] : llvm::zip_equal(YamlBP.Functions, ProfileBFs)) {
372+
if (!BF)
373+
continue;
374+
BinaryFunction &Function = *BF;
375+
// Clear function call count that may have been set while pre-processing
376+
// the profile.
377+
Function.setExecutionCount(BinaryFunction::COUNT_NO_PROFILE);
378+
379+
if (profileMatches(YamlBF, Function)) {
380+
matchProfileToFunction(YamlBF, Function);
381+
++MatchedWithExactName;
382+
}
383+
}
384+
return MatchedWithExactName;
385+
}
386+
387+
size_t YAMLProfileReader::matchWithHash(BinaryContext &BC) {
388+
// Iterates through profiled functions to match the first binary function with
389+
// the same exact hash. Serves to match identical, renamed functions.
390+
// Collisions are possible where multiple functions share the same exact hash.
391+
size_t MatchedWithHash = 0;
392+
if (opts::MatchProfileWithFunctionHash) {
393+
DenseMap<size_t, BinaryFunction *> StrictHashToBF;
394+
StrictHashToBF.reserve(BC.getBinaryFunctions().size());
395+
396+
for (auto &[_, BF] : BC.getBinaryFunctions())
397+
StrictHashToBF[BF.getHash()] = &BF;
398+
399+
for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
400+
if (YamlBF.Used)
401+
continue;
402+
auto It = StrictHashToBF.find(YamlBF.Hash);
403+
if (It != StrictHashToBF.end() && !ProfiledFunctions.count(It->second)) {
404+
BinaryFunction *BF = It->second;
405+
matchProfileToFunction(YamlBF, *BF);
406+
++MatchedWithHash;
407+
}
408+
}
409+
}
410+
return MatchedWithHash;
411+
}
412+
413+
size_t YAMLProfileReader::matchWithLTOCommonName() {
414+
// This second pass allows name ambiguity for LTO private functions.
415+
size_t MatchedWithLTOCommonName = 0;
416+
for (const auto &[CommonName, LTOProfiles] : LTOCommonNameMap) {
417+
if (!LTOCommonNameFunctionMap.contains(CommonName))
418+
continue;
419+
std::unordered_set<BinaryFunction *> &Functions =
420+
LTOCommonNameFunctionMap[CommonName];
421+
// Return true if a given profile is matched to one of BinaryFunctions with
422+
// matching LTO common name.
423+
auto matchProfile = [&](yaml::bolt::BinaryFunctionProfile *YamlBF) {
424+
if (YamlBF->Used)
425+
return false;
426+
for (BinaryFunction *BF : Functions) {
427+
if (!ProfiledFunctions.count(BF) && profileMatches(*YamlBF, *BF)) {
428+
matchProfileToFunction(*YamlBF, *BF);
429+
++MatchedWithLTOCommonName;
430+
return true;
431+
}
432+
}
433+
return false;
434+
};
435+
bool ProfileMatched = llvm::any_of(LTOProfiles, matchProfile);
436+
437+
// If there's only one function with a given name, try to match it
438+
// partially.
439+
if (!ProfileMatched && LTOProfiles.size() == 1 && Functions.size() == 1 &&
440+
!LTOProfiles.front()->Used &&
441+
!ProfiledFunctions.count(*Functions.begin())) {
442+
matchProfileToFunction(*LTOProfiles.front(), **Functions.begin());
443+
++MatchedWithLTOCommonName;
444+
}
445+
}
446+
return MatchedWithLTOCommonName;
447+
}
448+
449+
size_t YAMLProfileReader::matchWithNameSimilarity(BinaryContext &BC) {
450+
if (opts::NameSimilarityFunctionMatchingThreshold == 0)
451+
return 0;
452+
453+
size_t MatchedWithNameSimilarity = 0;
363454
ItaniumPartialDemangler Demangler;
364455

365456
// Demangle and derive namespace from function name.
@@ -477,17 +568,6 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
477568
}
478569
YamlProfileToFunction.resize(YamlBP.Functions.size() + 1);
479570

480-
auto profileMatches = [](const yaml::bolt::BinaryFunctionProfile &Profile,
481-
BinaryFunction &BF) {
482-
if (opts::IgnoreHash)
483-
return Profile.NumBasicBlocks == BF.size();
484-
return Profile.Hash == static_cast<uint64_t>(BF.getHash());
485-
};
486-
487-
uint64_t MatchedWithExactName = 0;
488-
uint64_t MatchedWithHash = 0;
489-
uint64_t MatchedWithLTOCommonName = 0;
490-
491571
// Computes hash for binary functions.
492572
if (opts::MatchProfileWithFunctionHash) {
493573
for (auto &[_, BF] : BC.getBinaryFunctions()) {
@@ -501,84 +581,15 @@ Error YAMLProfileReader::readProfile(BinaryContext &BC) {
501581
}
502582
}
503583

504-
// This first pass assigns profiles that match 100% by name and by hash.
505-
for (auto [YamlBF, BF] : llvm::zip_equal(YamlBP.Functions, ProfileBFs)) {
506-
if (!BF)
507-
continue;
508-
BinaryFunction &Function = *BF;
509-
// Clear function call count that may have been set while pre-processing
510-
// the profile.
511-
Function.setExecutionCount(BinaryFunction::COUNT_NO_PROFILE);
512-
513-
if (profileMatches(YamlBF, Function)) {
514-
matchProfileToFunction(YamlBF, Function);
515-
++MatchedWithExactName;
516-
}
517-
}
518-
519-
// Iterates through profiled functions to match the first binary function with
520-
// the same exact hash. Serves to match identical, renamed functions.
521-
// Collisions are possible where multiple functions share the same exact hash.
522-
if (opts::MatchProfileWithFunctionHash) {
523-
DenseMap<size_t, BinaryFunction *> StrictHashToBF;
524-
StrictHashToBF.reserve(BC.getBinaryFunctions().size());
525-
526-
for (auto &[_, BF] : BC.getBinaryFunctions())
527-
StrictHashToBF[BF.getHash()] = &BF;
528-
529-
for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
530-
if (YamlBF.Used)
531-
continue;
532-
auto It = StrictHashToBF.find(YamlBF.Hash);
533-
if (It != StrictHashToBF.end() && !ProfiledFunctions.count(It->second)) {
534-
BinaryFunction *BF = It->second;
535-
matchProfileToFunction(YamlBF, *BF);
536-
++MatchedWithHash;
537-
}
538-
}
539-
}
540-
541-
// This second pass allows name ambiguity for LTO private functions.
542-
for (const auto &[CommonName, LTOProfiles] : LTOCommonNameMap) {
543-
if (!LTOCommonNameFunctionMap.contains(CommonName))
544-
continue;
545-
std::unordered_set<BinaryFunction *> &Functions =
546-
LTOCommonNameFunctionMap[CommonName];
547-
// Return true if a given profile is matched to one of BinaryFunctions with
548-
// matching LTO common name.
549-
auto matchProfile = [&](yaml::bolt::BinaryFunctionProfile *YamlBF) {
550-
if (YamlBF->Used)
551-
return false;
552-
for (BinaryFunction *BF : Functions) {
553-
if (!ProfiledFunctions.count(BF) && profileMatches(*YamlBF, *BF)) {
554-
matchProfileToFunction(*YamlBF, *BF);
555-
++MatchedWithLTOCommonName;
556-
return true;
557-
}
558-
}
559-
return false;
560-
};
561-
bool ProfileMatched = llvm::any_of(LTOProfiles, matchProfile);
562-
563-
// If there's only one function with a given name, try to match it
564-
// partially.
565-
if (!ProfileMatched && LTOProfiles.size() == 1 && Functions.size() == 1 &&
566-
!LTOProfiles.front()->Used &&
567-
!ProfiledFunctions.count(*Functions.begin())) {
568-
matchProfileToFunction(*LTOProfiles.front(), **Functions.begin());
569-
++MatchedWithLTOCommonName;
570-
}
571-
}
584+
const size_t MatchedWithExactName = matchWithExactName();
585+
const size_t MatchedWithHash = matchWithHash(BC);
586+
const size_t MatchedWithLTOCommonName = matchWithLTOCommonName();
587+
const size_t MatchedWithNameSimilarity = matchWithNameSimilarity(BC);
572588

573589
for (auto [YamlBF, BF] : llvm::zip_equal(YamlBP.Functions, ProfileBFs))
574590
if (!YamlBF.Used && BF && !ProfiledFunctions.count(BF))
575591
matchProfileToFunction(YamlBF, *BF);
576592

577-
// Uses name similarity to match functions that were not matched by name.
578-
uint64_t MatchedWithNameSimilarity =
579-
opts::NameSimilarityFunctionMatchingThreshold > 0
580-
? matchWithNameSimilarity(BC)
581-
: 0;
582593

583594
for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions)
584595
if (!YamlBF.Used && opts::Verbosity >= 1)

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,20 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
702702
unsigned ShiftVal = AArch64_AM::getArithShiftValue(OperandExtension);
703703
AArch64_AM::ShiftExtendType ExtendType =
704704
AArch64_AM::getArithExtendType(OperandExtension);
705-
if (ShiftVal != 2)
706-
llvm_unreachable("Failed to match indirect branch! (fragment 2)");
705+
if (ShiftVal != 2) {
706+
// TODO: Handle the patten where ShiftVal != 2.
707+
// The following code sequence below has no shift amount,
708+
// the range could be 0 to 4.
709+
// The pattern comes from libc, it occurs when the binary is static.
710+
// adr x6, 0x219fb0 <sigall_set+0x88>
711+
// add x6, x6, x14, lsl #2
712+
// ldr w7, [x6]
713+
// add x6, x6, w7, sxtw => no shift amount
714+
// br x6
715+
errs() << "BOLT-WARNING: "
716+
"Failed to match indirect branch: ShiftVAL != 2 \n";
717+
return false;
718+
}
707719

708720
if (ExtendType == AArch64_AM::SXTB)
709721
ScaleValue = 1LL;
@@ -748,6 +760,19 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
748760
return true;
749761
}
750762

763+
if (DefJTBaseAdd->getOpcode() == AArch64::ADR) {
764+
// TODO: Handle the pattern where there is no adrp/add pair.
765+
// It also occurs when the binary is static.
766+
// adr x13, 0x215a18 <_nl_value_type_LC_COLLATE+0x50>
767+
// ldrh w13, [x13, w12, uxtw #1]
768+
// adr x12, 0x247b30 <__gettextparse+0x5b0>
769+
// add x13, x12, w13, sxth #2
770+
// br x13
771+
errs() << "BOLT-WARNING: Failed to match indirect branch: "
772+
"nop/adr instead of adrp/add \n";
773+
return false;
774+
}
775+
751776
assert(DefJTBaseAdd->getOpcode() == AArch64::ADDXri &&
752777
"Failed to match jump table base address pattern! (1)");
753778

0 commit comments

Comments
 (0)