Skip to content

Commit e32e38e

Browse files
nikicfmayer
authored andcommitted
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.4 [skip ci]
2 parents c69f388 + d484c4d commit e32e38e

File tree

1,661 files changed

+238260
-108312
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,661 files changed

+238260
-108312
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
clang/lib/AST/Interp/ @tbaederr
3636
clang/test/AST/Interp/ @tbaederr
3737

38+
/clang/include/clang/CIR @lanza @bcardosolopes
39+
/clang/lib/CIR @lanza @bcardosolopes
40+
/clang/tools/cir-* @lanza @bcardosolopes
41+
3842
/lldb/ @JDevlieghere
3943

4044
# MLIR Interfaces.

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,8 @@ class DataAggregator : public DataReader {
198198
/// A trace is region of code executed between two LBR entries supplied in
199199
/// execution order.
200200
///
201-
/// Return true if the trace is valid, false otherwise.
202-
bool
203-
recordTrace(BinaryFunction &BF, const LBREntry &First, const LBREntry &Second,
204-
uint64_t Count,
205-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const;
206-
207201
/// Return a vector of offsets corresponding to a trace in a function
208-
/// (see recordTrace() above).
202+
/// if the trace is valid, std::nullopt otherwise.
209203
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
210204
getFallthroughsInTrace(BinaryFunction &BF, const LBREntry &First,
211205
const LBREntry &Second, uint64_t Count = 1) const;

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,13 @@ class RewriteInstance {
422422
/// Section name used for extra BOLT code in addition to .text.
423423
static StringRef getBOLTTextSectionName() { return ".bolt.text"; }
424424

425+
/// Symbol markers for BOLT reserved area.
426+
static StringRef getBOLTReservedStart() { return "__bolt_reserved_start"; }
427+
static StringRef getBOLTReservedEnd() { return "__bolt_reserved_end"; }
428+
425429
/// Common section names.
426430
static StringRef getEHFrameSectionName() { return ".eh_frame"; }
431+
static StringRef getEHFrameHdrSectionName() { return ".eh_frame_hdr"; }
427432
static StringRef getRelaDynSectionName() { return ".rela.dyn"; }
428433

429434
/// FILE symbol name used for local fragments of global functions.
@@ -493,6 +498,9 @@ class RewriteInstance {
493498
/// Store all non-zero symbols in this map for a quick address lookup.
494499
std::map<uint64_t, llvm::object::SymbolRef> FileSymRefs;
495500

501+
/// FILE symbols used for disambiguating split function parents.
502+
std::vector<ELFSymbolRef> FileSymbols;
503+
496504
std::unique_ptr<DWARFRewriter> DebugInfoRewriter;
497505

498506
std::unique_ptr<BoltAddressTranslation> BAT;

bolt/include/bolt/Utils/NameResolver.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ class NameResolver {
2828
static constexpr char Sep = '/';
2929

3030
public:
31-
/// Return unique version of the \p Name in the form "Name<Sep><Number>".
31+
/// Return the number of uniquified versions of a given \p Name.
32+
uint64_t getUniquifiedNameCount(StringRef Name) const {
33+
if (Counters.contains(Name))
34+
return Counters.at(Name);
35+
return 0;
36+
}
37+
38+
/// Return unique version of the \p Name in the form "Name<Sep><ID>".
39+
std::string getUniqueName(StringRef Name, const uint64_t ID) const {
40+
return (Name + Twine(Sep) + Twine(ID)).str();
41+
}
42+
43+
/// Register new version of \p Name and return unique version in the form
44+
/// "Name<Sep><Number>".
3245
std::string uniquify(StringRef Name) {
3346
const uint64_t ID = ++Counters[Name];
34-
return (Name + Twine(Sep) + Twine(ID)).str();
47+
return getUniqueName(Name, ID);
3548
}
3649

3750
/// For uniquified \p Name, return the original form (that may no longer be

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,17 @@ bool DataAggregator::doTrace(const LBREntry &First, const LBREntry &Second,
861861
return true;
862862
}
863863

864-
bool DataAggregator::recordTrace(
865-
BinaryFunction &BF, const LBREntry &FirstLBR, const LBREntry &SecondLBR,
866-
uint64_t Count,
867-
SmallVector<std::pair<uint64_t, uint64_t>, 16> &Branches) const {
864+
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
865+
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
866+
const LBREntry &FirstLBR,
867+
const LBREntry &SecondLBR,
868+
uint64_t Count) const {
869+
SmallVector<std::pair<uint64_t, uint64_t>, 16> Branches;
870+
868871
BinaryContext &BC = BF.getBinaryContext();
869872

870873
if (!BF.isSimple())
871-
return false;
874+
return std::nullopt;
872875

873876
assert(BF.hasCFG() && "can only record traces in CFG state");
874877

@@ -877,13 +880,13 @@ bool DataAggregator::recordTrace(
877880
const uint64_t To = SecondLBR.From - BF.getAddress();
878881

879882
if (From > To)
880-
return false;
883+
return std::nullopt;
881884

882885
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
883886
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
884887

885888
if (!FromBB || !ToBB)
886-
return false;
889+
return std::nullopt;
887890

888891
// Adjust FromBB if the first LBR is a return from the last instruction in
889892
// the previous block (that instruction should be a call).
@@ -907,7 +910,7 @@ bool DataAggregator::recordTrace(
907910
// within the same basic block, e.g. when two call instructions are in the
908911
// same block. In this case we skip the processing.
909912
if (FromBB == ToBB)
910-
return true;
913+
return Branches;
911914

912915
// Process blocks in the original layout order.
913916
BinaryBasicBlock *BB = BF.getLayout().getBlock(FromBB->getIndex());
@@ -921,7 +924,7 @@ bool DataAggregator::recordTrace(
921924
LLVM_DEBUG(dbgs() << "no fall-through for the trace:\n"
922925
<< " " << FirstLBR << '\n'
923926
<< " " << SecondLBR << '\n');
924-
return false;
927+
return std::nullopt;
925928
}
926929

927930
const MCInst *Instr = BB->getLastNonPseudoInstr();
@@ -945,20 +948,7 @@ bool DataAggregator::recordTrace(
945948
BI.Count += Count;
946949
}
947950

948-
return true;
949-
}
950-
951-
std::optional<SmallVector<std::pair<uint64_t, uint64_t>, 16>>
952-
DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
953-
const LBREntry &FirstLBR,
954-
const LBREntry &SecondLBR,
955-
uint64_t Count) const {
956-
SmallVector<std::pair<uint64_t, uint64_t>, 16> Res;
957-
958-
if (!recordTrace(BF, FirstLBR, SecondLBR, Count, Res))
959-
return std::nullopt;
960-
961-
return Res;
951+
return Branches;
962952
}
963953

964954
bool DataAggregator::recordEntry(BinaryFunction &BF, uint64_t To, bool Mispred,

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
248248
/// Update ORC data in the binary.
249249
Error rewriteORCTables();
250250

251+
/// Validate written ORC tables after binary emission.
252+
Error validateORCTables();
253+
251254
/// Static call table handling.
252255
Error readStaticCalls();
253256
Error rewriteStaticCalls();
@@ -358,6 +361,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
358361
if (Error E = updateStaticKeysJumpTablePostEmit())
359362
return E;
360363

364+
if (Error E = validateORCTables())
365+
return E;
366+
361367
return Error::success();
362368
}
363369
};
@@ -837,6 +843,32 @@ Error LinuxKernelRewriter::rewriteORCTables() {
837843
return Error::success();
838844
}
839845

846+
Error LinuxKernelRewriter::validateORCTables() {
847+
if (!ORCUnwindIPSection)
848+
return Error::success();
849+
850+
const uint64_t IPSectionAddress = ORCUnwindIPSection->getAddress();
851+
DataExtractor IPDE = DataExtractor(ORCUnwindIPSection->getOutputContents(),
852+
BC.AsmInfo->isLittleEndian(),
853+
BC.AsmInfo->getCodePointerSize());
854+
DataExtractor::Cursor IPCursor(0);
855+
uint64_t PrevIP = 0;
856+
for (uint32_t Index = 0; Index < NumORCEntries; ++Index) {
857+
const uint64_t IP =
858+
IPSectionAddress + IPCursor.tell() + (int32_t)IPDE.getU32(IPCursor);
859+
if (!IPCursor)
860+
return createStringError(errc::executable_format_error,
861+
"out of bounds while reading ORC IP table: %s",
862+
toString(IPCursor.takeError()).c_str());
863+
864+
assert(IP >= PrevIP && "Unsorted ORC table detected");
865+
(void)PrevIP;
866+
PrevIP = IP;
867+
}
868+
869+
return Error::success();
870+
}
871+
840872
/// The static call site table is created by objtool and contains entries in the
841873
/// following format:
842874
///

0 commit comments

Comments
 (0)