Skip to content

Commit 8ca9461

Browse files
committed
merge main into amd-staging
2 parents b937a71 + 315c904 commit 8ca9461

File tree

16 files changed

+143
-185
lines changed

16 files changed

+143
-185
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,10 +2356,9 @@ class BinaryFunction {
23562356
bool postProcessIndirectBranches(MCPlusBuilder::AllocatorIdTy AllocId);
23572357

23582358
/// Validate that all data references to function offsets are claimed by
2359-
/// recognized jump tables. Register externally referenced blocks as entry
2360-
/// points. Returns true if there are no unclaimed externally referenced
2361-
/// offsets.
2362-
bool validateExternallyReferencedOffsets();
2359+
/// recognized jump tables. Returns true if there are no unclaimed externally
2360+
/// referenced offsets.
2361+
bool validateInternalRefDataRelocations();
23632362

23642363
/// Return all call site profile info for this function.
23652364
IndirectCallSiteProfile &getAllCallSites() { return AllCallSites; }

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,41 +2041,47 @@ void BinaryFunction::postProcessJumpTables() {
20412041
}
20422042
}
20432043

2044-
bool BinaryFunction::validateExternallyReferencedOffsets() {
2045-
SmallPtrSet<MCSymbol *, 4> JTTargets;
2046-
for (const JumpTable *JT : llvm::make_second_range(JumpTables))
2047-
JTTargets.insert_range(JT->Entries);
2048-
2049-
bool HasUnclaimedReference = false;
2050-
for (uint64_t Destination : ExternallyReferencedOffsets) {
2051-
// Ignore __builtin_unreachable().
2052-
if (Destination == getSize())
2053-
continue;
2054-
// Ignore constant islands
2055-
if (isInConstantIsland(Destination + getAddress()))
2056-
continue;
2044+
bool BinaryFunction::validateInternalRefDataRelocations() {
2045+
if (InternalRefDataRelocations.empty())
2046+
return true;
20572047

2058-
if (BinaryBasicBlock *BB = getBasicBlockAtOffset(Destination)) {
2059-
// Check if the externally referenced offset is a recognized jump table
2060-
// target.
2061-
if (JTTargets.contains(BB->getLabel()))
2062-
continue;
2048+
// Rely on the user hint that all data refs are valid and only used as
2049+
// destinations by indirect branch in the same function.
2050+
if (opts::StrictMode)
2051+
return true;
20632052

2064-
if (opts::Verbosity >= 1) {
2065-
BC.errs() << "BOLT-WARNING: unclaimed data to code reference (possibly "
2066-
<< "an unrecognized jump table entry) to " << BB->getName()
2067-
<< " in " << *this << "\n";
2068-
}
2069-
auto L = BC.scopeLock();
2070-
addEntryPoint(*BB);
2071-
} else {
2072-
BC.errs() << "BOLT-WARNING: unknown data to code reference to offset "
2073-
<< Twine::utohexstr(Destination) << " in " << *this << "\n";
2074-
setIgnored();
2053+
DenseSet<uint64_t> UnclaimedRelocations(InternalRefDataRelocations);
2054+
for (const JumpTable *JT : llvm::make_second_range(JumpTables)) {
2055+
uint64_t EntryAddress = JT->getAddress();
2056+
while (EntryAddress < JT->getAddress() + JT->getSize()) {
2057+
UnclaimedRelocations.erase(EntryAddress);
2058+
EntryAddress += JT->EntrySize;
20752059
}
2076-
HasUnclaimedReference = true;
20772060
}
2078-
return !HasUnclaimedReference;
2061+
2062+
if (UnclaimedRelocations.empty())
2063+
return true;
2064+
2065+
BC.errs() << "BOLT-WARNING: " << UnclaimedRelocations.size()
2066+
<< " unclaimed data relocation"
2067+
<< (UnclaimedRelocations.size() > 1 ? "s" : "")
2068+
<< " remain against function " << *this;
2069+
if (opts::Verbosity) {
2070+
BC.errs() << ":\n";
2071+
for (uint64_t RelocationAddress : UnclaimedRelocations) {
2072+
const Relocation *Relocation = BC.getRelocationAt(RelocationAddress);
2073+
BC.errs() << " ";
2074+
if (Relocation)
2075+
BC.errs() << *Relocation;
2076+
else
2077+
BC.errs() << "<missing relocation>";
2078+
BC.errs() << '\n';
2079+
}
2080+
} else {
2081+
BC.errs() << ". Re-run with -v=1 to see the list\n";
2082+
}
2083+
2084+
return false;
20792085
}
20802086

20812087
bool BinaryFunction::postProcessIndirectBranches(
@@ -2200,14 +2206,6 @@ bool BinaryFunction::postProcessIndirectBranches(
22002206
LastIndirectJumpBB->updateJumpTableSuccessors();
22012207
}
22022208

2203-
// Validate that all data references to function offsets are claimed by
2204-
// recognized jump tables. Register externally referenced blocks as entry
2205-
// points.
2206-
if (!opts::StrictMode && hasInternalReference()) {
2207-
if (!validateExternallyReferencedOffsets())
2208-
return false;
2209-
}
2210-
22112209
if (HasUnknownControlFlow && !BC.HasRelocations)
22122210
return false;
22132211

@@ -2496,12 +2494,18 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
24962494
CurrentState = State::CFG;
24972495

24982496
// Make any necessary adjustments for indirect branches.
2499-
if (!postProcessIndirectBranches(AllocatorId)) {
2500-
if (opts::Verbosity) {
2501-
BC.errs() << "BOLT-WARNING: failed to post-process indirect branches for "
2502-
<< *this << '\n';
2503-
}
2497+
bool ValidCFG = postProcessIndirectBranches(AllocatorId);
2498+
if (!ValidCFG && opts::Verbosity) {
2499+
BC.errs() << "BOLT-WARNING: failed to post-process indirect branches for "
2500+
<< *this << '\n';
2501+
}
2502+
2503+
// Validate that all data references to function offsets are claimed by
2504+
// recognized jump tables.
2505+
if (ValidCFG)
2506+
ValidCFG = validateInternalRefDataRelocations();
25042507

2508+
if (!ValidCFG) {
25052509
if (BC.isAArch64())
25062510
PreserveNops = BC.HasRelocations;
25072511

bolt/test/X86/unclaimed-jt-entries.s

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232

3333
# RUN: llvm-bolt %t.exe -v=1 -o %t.out 2>&1 | FileCheck %s
3434

35-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
36-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
37-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
38-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
39-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in main
40-
# CHECK: BOLT-WARNING: failed to post-process indirect branches for main
35+
# CHECK: BOLT-WARNING: 11 unclaimed data relocations remain against function main
4136

4237
.text
4338
.globl main

bolt/test/runtime/X86/unclaimed-jt-entries.s

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@
1818

1919
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
2020
# RUN: %clang %cflags %S/Inputs/unclaimed-jt-entries.c -no-pie %t.o -o %t.exe -Wl,-q
21-
# RUN: llvm-bolt %t.exe -v=1 -o %t.out --sequential-disassembly 2>&1 | FileCheck %s
21+
# RUN: llvm-bolt %t.exe -o %t.out 2>&1 | FileCheck %s
2222

23-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
24-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
25-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
26-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
27-
# CHECK: BOLT-WARNING: unclaimed data to code reference (possibly an unrecognized jump table entry) to .Ltmp[[#]] in func
28-
# CHECK: BOLT-WARNING: failed to post-process indirect branches for func
23+
# CHECK: BOLT-WARNING: 11 unclaimed data relocations remain against function func
2924

3025
# Run the optimized binary
3126
# RUN: %t.out 3 | FileCheck %s --check-prefix=CHECK3

clang/include/clang/AST/IgnoreExpr.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717
#include "clang/AST/ExprCXX.h"
1818

1919
namespace clang {
20-
namespace detail {
21-
/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
22-
/// Return Fn_n(...(Fn_1(E)))
23-
inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
24-
template <typename FnTy, typename... FnTys>
25-
Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
26-
return IgnoreExprNodesImpl(std::forward<FnTy>(Fn)(E),
27-
std::forward<FnTys>(Fns)...);
28-
}
29-
} // namespace detail
3020

3121
/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
3222
/// Recursively apply each of the functions to E until reaching a fixed point.
@@ -35,7 +25,7 @@ template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
3525
Expr *LastE = nullptr;
3626
while (E != LastE) {
3727
LastE = E;
38-
E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
28+
((E = std::forward<FnTys>(Fns)(E)), ...);
3929
}
4030
return E;
4131
}

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,17 +2395,17 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
23952395
const FormatToken *LeftSquare = FormatTok;
23962396
nextToken();
23972397
if (Previous) {
2398+
const auto *PrevPrev = Previous->getPreviousNonComment();
2399+
if (Previous->is(tok::star) && PrevPrev && PrevPrev->isTypeName(LangOpts))
2400+
return false;
23982401
if (Previous->closesScope()) {
23992402
// Not a potential C-style cast.
24002403
if (Previous->isNot(tok::r_paren))
24012404
return false;
2402-
const auto *BeforeRParen = Previous->getPreviousNonComment();
24032405
// Lambdas can be cast to function types only, e.g. `std::function<int()>`
24042406
// and `int (*)()`.
2405-
if (!BeforeRParen || BeforeRParen->isNoneOf(tok::greater, tok::r_paren))
2407+
if (!PrevPrev || PrevPrev->isNoneOf(tok::greater, tok::r_paren))
24062408
return false;
2407-
} else if (Previous->is(tok::star)) {
2408-
Previous = Previous->getPreviousNonComment();
24092409
}
24102410
if (Previous && Previous->Tok.getIdentifierInfo() &&
24112411
Previous->isNoneOf(tok::kw_return, tok::kw_co_await, tok::kw_co_yield,

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
23222322
EXPECT_TOKEN(Tokens[3], tok::l_square, TT_LambdaLSquare);
23232323
EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_LambdaDefinitionLParen);
23242324
EXPECT_TOKEN(Tokens[10], tok::l_square, TT_ArraySubscriptLSquare);
2325+
2326+
Tokens = annotate("foo = bar * [] { return 2; }();");
2327+
ASSERT_EQ(Tokens.size(), 15u) << Tokens;
2328+
EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
2329+
EXPECT_TOKEN(Tokens[4], tok::l_square, TT_LambdaLSquare);
2330+
EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_LambdaLBrace);
23252331
}
23262332

23272333
TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {

llvm/include/llvm/CodeGen/MachineFrameInfo.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class MachineFrameInfo {
153153
/// register allocator.
154154
bool isStatepointSpillSlot = false;
155155

156+
/// If true, this stack slot is used for spilling a callee saved register
157+
/// in the calling convention of the containing function.
158+
bool isCalleeSaved = false;
159+
156160
/// Identifier for stack memory type analagous to address space. If this is
157161
/// non-0, the meaning is target defined. Offsets cannot be directly
158162
/// compared between objects with different stack IDs. The object may not
@@ -762,6 +766,18 @@ class MachineFrameInfo {
762766
return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
763767
}
764768

769+
bool isCalleeSavedObjectIndex(int ObjectIdx) const {
770+
assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
771+
"Invalid Object Idx!");
772+
return Objects[ObjectIdx + NumFixedObjects].isCalleeSaved;
773+
}
774+
775+
void setIsCalleeSavedObjectIndex(int ObjectIdx, bool IsCalleeSaved) {
776+
assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
777+
"Invalid Object Idx!");
778+
Objects[ObjectIdx + NumFixedObjects].isCalleeSaved = IsCalleeSaved;
779+
}
780+
765781
/// \see StackID
766782
uint8_t getStackID(int ObjectIdx) const {
767783
return Objects[ObjectIdx+NumFixedObjects].StackID;

llvm/include/llvm/CodeGen/TargetFrameLowering.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,6 @@ class LLVM_ABI TargetFrameLowering {
160160
/// returns false, spill slots will be assigned using generic implementation.
161161
/// assignCalleeSavedSpillSlots() may add, delete or rearrange elements of
162162
/// CSI.
163-
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF,
164-
const TargetRegisterInfo *TRI,
165-
std::vector<CalleeSavedInfo> &CSI,
166-
unsigned &MinCSFrameIndex,
167-
unsigned &MaxCSFrameIndex) const {
168-
return assignCalleeSavedSpillSlots(MF, TRI, CSI);
169-
}
170-
171163
virtual bool
172164
assignCalleeSavedSpillSlots(MachineFunction &MF,
173165
const TargetRegisterInfo *TRI,

0 commit comments

Comments
 (0)