Skip to content

Commit a3dff30

Browse files
committed
Merge branch 'main' into branch-protection-pauthabi
2 parents 501a43b + afb584a commit a3dff30

File tree

4,883 files changed

+85235
-31492
lines changed

Some content is hidden

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

4,883 files changed

+85235
-31492
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/**

bolt/include/bolt/Core/DebugData.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,16 @@ class DebugRangesSectionWriter {
226226
/// Needs to be invoked before each \p CU is processed.
227227
void virtual initSection(DWARFUnit &CU){};
228228

229+
/// Initializes Ranges section with empty list.
230+
void initSection();
231+
229232
protected:
230233
std::unique_ptr<DebugBufferVector> RangesBuffer;
231234

232235
std::unique_ptr<raw_svector_ostream> RangesStream;
233236

234237
std::mutex WriterMutex;
235238

236-
/// Current offset in the section (updated as new entries are written).
237-
/// Starts with 16 since the first 16 bytes are reserved for an empty range.
238-
uint32_t SectionOffset{0};
239-
240239
/// Offset of an empty address ranges list.
241240
static constexpr uint64_t EmptyRangesOffset{0};
242241

bolt/include/bolt/Core/HashUtilities.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "bolt/Core/BinaryBasicBlock.h"
1818
#include "bolt/Core/BinaryContext.h"
19+
#include "bolt/Profile/ProfileYAMLMapping.h"
1920

2021
namespace llvm {
2122
namespace bolt {
@@ -35,6 +36,13 @@ std::string hashBlock(BinaryContext &BC, const BinaryBasicBlock &BB,
3536

3637
std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB);
3738

39+
std::string hashBlockCalls(BinaryContext &BC, const BinaryBasicBlock &BB);
40+
41+
std::string
42+
hashBlockCalls(const DenseMap<uint32_t, yaml::bolt::BinaryFunctionProfile *>
43+
&IdToYamlFunction,
44+
const yaml::bolt::BinaryBasicBlockProfile &YamlBB);
45+
3846
} // namespace bolt
3947
} // namespace llvm
4048

bolt/include/bolt/Profile/YAMLProfileReader.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class YAMLProfileReader : public ProfileReaderBase {
4040
/// Check if the file contains YAML.
4141
static bool isYAML(StringRef Filename);
4242

43+
using ProfileLookupMap =
44+
DenseMap<uint32_t, yaml::bolt::BinaryFunctionProfile *>;
45+
4346
private:
4447
/// Adjustments for basic samples profiles (without LBR).
4548
bool NormalizeByInsnCount{false};
@@ -56,6 +59,10 @@ class YAMLProfileReader : public ProfileReaderBase {
5659
/// is attributed.
5760
FunctionSet ProfiledFunctions;
5861

62+
/// Maps profiled function id to function, for function matching with calls as
63+
/// anchors.
64+
ProfileLookupMap IdToYamLBF;
65+
5966
/// For LTO symbol resolution.
6067
/// Map a common LTO prefix to a list of YAML profiles matching the prefix.
6168
StringMap<std::vector<yaml::bolt::BinaryFunctionProfile *>> LTOCommonNameMap;
@@ -73,13 +80,29 @@ class YAMLProfileReader : public ProfileReaderBase {
7380
bool parseFunctionProfile(BinaryFunction &Function,
7481
const yaml::bolt::BinaryFunctionProfile &YamlBF);
7582

83+
/// Checks if a function profile matches a binary function.
84+
bool profileMatches(const yaml::bolt::BinaryFunctionProfile &Profile,
85+
const BinaryFunction &BF);
86+
7687
/// Infer function profile from stale data (collected on older binaries).
7788
bool inferStaleProfile(BinaryFunction &Function,
7889
const yaml::bolt::BinaryFunctionProfile &YamlBF);
7990

8091
/// Initialize maps for profile matching.
8192
void buildNameMaps(BinaryContext &BC);
8293

94+
/// Matches functions using exact name.
95+
size_t matchWithExactName();
96+
97+
/// Matches function using LTO comomon name.
98+
size_t matchWithLTOCommonName();
99+
100+
/// Matches functions using exact hash.
101+
size_t matchWithHash(BinaryContext &BC);
102+
103+
/// Matches functions with similarly named profiled functions.
104+
size_t matchWithNameSimilarity(BinaryContext &BC);
105+
83106
/// Update matched YAML -> BinaryFunction pair.
84107
void matchProfileToFunction(yaml::bolt::BinaryFunctionProfile &YamlBF,
85108
BinaryFunction &BF) {
@@ -93,9 +116,6 @@ class YAMLProfileReader : public ProfileReaderBase {
93116
ProfiledFunctions.emplace(&BF);
94117
}
95118

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

bolt/include/bolt/Utils/NameResolver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class NameResolver {
6161
std::tie(LHS, RHS) = UniqueName.split(Sep);
6262
return (LHS + Suffix + Twine(Sep) + RHS).str();
6363
}
64+
65+
// Drops the suffix that describes the function's number of names.
66+
static StringRef dropNumNames(StringRef Name) {
67+
const size_t Pos = Name.find("(*");
68+
return Pos != StringRef::npos ? Name.substr(0, Pos) : Name;
69+
}
6470
};
6571

6672
} // namespace bolt

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/Core/DebugData.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,14 @@ DebugRangesSectionWriter::DebugRangesSectionWriter() {
137137
RangesBuffer = std::make_unique<DebugBufferVector>();
138138
RangesStream = std::make_unique<raw_svector_ostream>(*RangesBuffer);
139139

140-
// Add an empty range as the first entry;
141-
SectionOffset +=
142-
writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
143140
Kind = RangesWriterKind::DebugRangesWriter;
144141
}
145142

143+
void DebugRangesSectionWriter::initSection() {
144+
// Adds an empty range to the buffer.
145+
writeAddressRanges(*RangesStream.get(), DebugAddressRangesVector{});
146+
}
147+
146148
uint64_t DebugRangesSectionWriter::addRanges(
147149
DebugAddressRangesVector &&Ranges,
148150
std::map<DebugAddressRangesVector, uint64_t> &CachedRanges) {
@@ -166,21 +168,20 @@ uint64_t DebugRangesSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
166168
// Reading the SectionOffset and updating it should be atomic to guarantee
167169
// unique and correct offsets in patches.
168170
std::lock_guard<std::mutex> Lock(WriterMutex);
169-
const uint32_t EntryOffset = SectionOffset;
170-
SectionOffset += writeAddressRanges(*RangesStream.get(), Ranges);
171+
const uint32_t EntryOffset = RangesBuffer->size();
172+
writeAddressRanges(*RangesStream.get(), Ranges);
171173

172174
return EntryOffset;
173175
}
174176

175177
uint64_t DebugRangesSectionWriter::getSectionOffset() {
176178
std::lock_guard<std::mutex> Lock(WriterMutex);
177-
return SectionOffset;
179+
return RangesBuffer->size();
178180
}
179181

180182
void DebugRangesSectionWriter::appendToRangeBuffer(
181183
const DebugBufferVector &CUBuffer) {
182184
*RangesStream << CUBuffer;
183-
SectionOffset = RangesBuffer->size();
184185
}
185186

186187
DebugAddrWriter *DebugRangeListsSectionWriter::AddrWriter = nullptr;
@@ -327,7 +328,6 @@ void DebugRangeListsSectionWriter::finalizeSection() {
327328
*RangesStream << *Header;
328329
*RangesStream << *CUArrayBuffer;
329330
*RangesStream << *CUBodyBuffer;
330-
SectionOffset = RangesBuffer->size();
331331
}
332332

333333
void DebugRangeListsSectionWriter::initSection(DWARFUnit &Unit) {

bolt/lib/Core/HashUtilities.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "bolt/Core/HashUtilities.h"
1414
#include "bolt/Core/BinaryContext.h"
15+
#include "bolt/Utils/NameResolver.h"
1516
#include "llvm/MC/MCInstPrinter.h"
1617

1718
namespace llvm {
@@ -155,5 +156,50 @@ std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB) {
155156
return HashString;
156157
}
157158

159+
/// An even looser hash level relative to $ hashBlockLoose to use with stale
160+
/// profile matching, composed of the names of a block's called functions in
161+
/// lexicographic order.
162+
std::string hashBlockCalls(BinaryContext &BC, const BinaryBasicBlock &BB) {
163+
// The hash is computed by creating a string of all lexicographically ordered
164+
// called function names.
165+
std::vector<std::string> FunctionNames;
166+
for (const MCInst &Instr : BB) {
167+
// Skip non-call instructions.
168+
if (!BC.MIB->isCall(Instr))
169+
continue;
170+
const MCSymbol *CallSymbol = BC.MIB->getTargetSymbol(Instr);
171+
if (!CallSymbol)
172+
continue;
173+
FunctionNames.push_back(std::string(CallSymbol->getName()));
174+
}
175+
std::sort(FunctionNames.begin(), FunctionNames.end());
176+
std::string HashString;
177+
for (const std::string &FunctionName : FunctionNames)
178+
HashString.append(FunctionName);
179+
180+
return HashString;
181+
}
182+
183+
/// The same as the $hashBlockCalls function, but for profiled functions.
184+
std::string
185+
hashBlockCalls(const DenseMap<uint32_t, yaml::bolt::BinaryFunctionProfile *>
186+
&IdToYamlFunction,
187+
const yaml::bolt::BinaryBasicBlockProfile &YamlBB) {
188+
std::vector<std::string> FunctionNames;
189+
for (const yaml::bolt::CallSiteInfo &CallSiteInfo : YamlBB.CallSites) {
190+
auto It = IdToYamlFunction.find(CallSiteInfo.DestId);
191+
if (It == IdToYamlFunction.end())
192+
continue;
193+
StringRef Name = NameResolver::dropNumNames(It->second->Name);
194+
FunctionNames.push_back(std::string(Name));
195+
}
196+
std::sort(FunctionNames.begin(), FunctionNames.end());
197+
std::string HashString;
198+
for (const std::string &FunctionName : FunctionNames)
199+
HashString.append(FunctionName);
200+
201+
return HashString;
202+
}
203+
158204
} // namespace bolt
159205
} // namespace llvm

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)

0 commit comments

Comments
 (0)