Skip to content

Commit 191a62a

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW12)
LLVM: llvm/llvm-project@86a0b39aa5721 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@950ce8f
2 parents e3a1541 + f3fca92 commit 191a62a

File tree

5,741 files changed

+283699
-156893
lines changed

Some content is hidden

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

5,741 files changed

+283699
-156893
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ class BinaryContext {
489489
void adjustCodePadding();
490490

491491
/// Regular page size.
492-
static constexpr unsigned RegularPageSize = 0x1000;
492+
unsigned RegularPageSize{0x1000};
493+
static constexpr unsigned RegularPageSizeX86 = 0x1000;
494+
static constexpr unsigned RegularPageSizeAArch64 = 0x10000;
493495

494496
/// Huge page size to use.
495497
static constexpr unsigned HugePageSize = 0x200000;

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,6 @@ class MCPlusBuilder {
526526
return false;
527527
}
528528

529-
virtual bool isMOVSX64rm32(const MCInst &Inst) const {
530-
llvm_unreachable("not implemented");
531-
return false;
532-
}
533-
534529
virtual bool isLeave(const MCInst &Inst) const {
535530
llvm_unreachable("not implemented");
536531
return false;
@@ -1292,6 +1287,16 @@ class MCPlusBuilder {
12921287
return false;
12931288
}
12941289

1290+
/// Convert a move instruction into a conditional move instruction, given a
1291+
/// condition code.
1292+
virtual bool
1293+
convertMoveToConditionalMove(MCInst &Inst, unsigned CC,
1294+
bool AllowStackMemOp = false,
1295+
bool AllowBasePtrStackMemOp = false) const {
1296+
llvm_unreachable("not implemented");
1297+
return false;
1298+
}
1299+
12951300
/// Lower a tail call instruction \p Inst if required by target.
12961301
virtual bool lowerTailCall(MCInst &Inst) {
12971302
llvm_unreachable("not implemented");
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===- bolt/Passes/CMOVConversion.h ----------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This pass finds the following patterns:
10+
// jcc
11+
// / \
12+
// (empty) mov src, dst
13+
// \ /
14+
//
15+
// and replaces them with:
16+
//
17+
// cmovcc src, dst
18+
//
19+
// The advantage of performing this conversion in BOLT (compared to compiler
20+
// heuristic driven instruction selection) is that BOLT can use LBR
21+
// misprediction information and only convert poorly predictable branches.
22+
// Note that branch misprediction rate is different from branch bias.
23+
// For well-predictable branches, it might be beneficial to leave jcc+mov as is
24+
// from microarchitectural perspective to avoid unneeded dependencies (CMOV
25+
// instruction has a dataflow dependence on flags and both operands).
26+
//
27+
//===----------------------------------------------------------------------===//
28+
29+
#ifndef BOLT_PASSES_CMOVCONVERSION_H
30+
#define BOLT_PASSES_CMOVCONVERSION_H
31+
32+
#include "bolt/Passes/BinaryPasses.h"
33+
34+
namespace llvm {
35+
namespace bolt {
36+
37+
/// Pass for folding eligible hammocks into CMOV's if profitable.
38+
class CMOVConversion : public BinaryFunctionPass {
39+
struct Stats {
40+
/// Record how many possible cases there are.
41+
uint64_t StaticPossible = 0;
42+
uint64_t DynamicPossible = 0;
43+
44+
/// Record how many cases were converted.
45+
uint64_t StaticPerformed = 0;
46+
uint64_t DynamicPerformed = 0;
47+
48+
/// Record how many mispredictions were eliminated.
49+
uint64_t PossibleMP = 0;
50+
uint64_t RemovedMP = 0;
51+
52+
Stats operator+(const Stats &O) {
53+
StaticPossible += O.StaticPossible;
54+
DynamicPossible += O.DynamicPossible;
55+
StaticPerformed += O.StaticPerformed;
56+
DynamicPerformed += O.DynamicPerformed;
57+
PossibleMP += O.PossibleMP;
58+
RemovedMP += O.RemovedMP;
59+
return *this;
60+
}
61+
double getStaticRatio() { return (double)StaticPerformed / StaticPossible; }
62+
double getDynamicRatio() {
63+
return (double)DynamicPerformed / DynamicPossible;
64+
}
65+
double getMPRatio() { return (double)RemovedMP / PossibleMP; }
66+
67+
void dump();
68+
};
69+
// BinaryContext-wide stats
70+
Stats Global;
71+
72+
void runOnFunction(BinaryFunction &Function);
73+
74+
public:
75+
explicit CMOVConversion() : BinaryFunctionPass(false) {}
76+
77+
const char *getName() const override { return "CMOV conversion"; }
78+
79+
void runOnFunctions(BinaryContext &BC) override;
80+
};
81+
82+
} // namespace bolt
83+
} // namespace llvm
84+
85+
#endif

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class RewriteInstance {
9696

9797
/// Read info from special sections. E.g. eh_frame and .gcc_except_table
9898
/// for exception and stack unwinding information.
99-
void readSpecialSections();
99+
Error readSpecialSections();
100100

101101
/// Adjust supplied command-line options based on input data.
102102
void adjustCommandLineOptions();
@@ -260,9 +260,9 @@ class RewriteInstance {
260260
void disassemblePLTSectionX86(BinarySection &Section, uint64_t EntrySize);
261261

262262
/// ELF-specific part. TODO: refactor into new class.
263-
#define ELF_FUNCTION(FUNC) \
264-
template <typename ELFT> void FUNC(object::ELFObjectFile<ELFT> *Obj); \
265-
void FUNC() { \
263+
#define ELF_FUNCTION(TYPE, FUNC) \
264+
template <typename ELFT> TYPE FUNC(object::ELFObjectFile<ELFT> *Obj); \
265+
TYPE FUNC() { \
266266
if (auto *ELF32LE = dyn_cast<object::ELF32LEObjectFile>(InputFile)) \
267267
return FUNC(ELF32LE); \
268268
if (auto *ELF64LE = dyn_cast<object::ELF64LEObjectFile>(InputFile)) \
@@ -277,25 +277,25 @@ class RewriteInstance {
277277
void patchELFPHDRTable();
278278

279279
/// Create section header table.
280-
ELF_FUNCTION(patchELFSectionHeaderTable);
280+
ELF_FUNCTION(void, patchELFSectionHeaderTable);
281281

282282
/// Create the regular symbol table and patch dyn symbol tables.
283-
ELF_FUNCTION(patchELFSymTabs);
283+
ELF_FUNCTION(void, patchELFSymTabs);
284284

285285
/// Read dynamic section/segment of ELF.
286-
ELF_FUNCTION(readELFDynamic);
286+
ELF_FUNCTION(Error, readELFDynamic);
287287

288288
/// Patch dynamic section/segment of ELF.
289-
ELF_FUNCTION(patchELFDynamic);
289+
ELF_FUNCTION(void, patchELFDynamic);
290290

291291
/// Patch .got
292-
ELF_FUNCTION(patchELFGOT);
292+
ELF_FUNCTION(void, patchELFGOT);
293293

294294
/// Patch allocatable relocation sections.
295-
ELF_FUNCTION(patchELFAllocatableRelaSections);
295+
ELF_FUNCTION(void, patchELFAllocatableRelaSections);
296296

297297
/// Finalize memory image of section header string table.
298-
ELF_FUNCTION(finalizeSectionStringTable);
298+
ELF_FUNCTION(void, finalizeSectionStringTable);
299299

300300
/// Return a name of the input file section in the output file.
301301
template <typename ELFObjType, typename ELFShdrTy>
@@ -498,7 +498,8 @@ class RewriteInstance {
498498
};
499499

500500
/// AArch64 PLT sections.
501-
const PLTSectionInfo AArch64_PLTSections[2] = {{".plt"}, {nullptr}};
501+
const PLTSectionInfo AArch64_PLTSections[3] = {
502+
{".plt"}, {".iplt"}, {nullptr}};
502503

503504
/// Return PLT information for a section with \p SectionName or nullptr
504505
/// if the section is not PLT.

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern llvm::cl::OptionCategory BoltInstrCategory;
3030
extern llvm::cl::OptionCategory HeatmapCategory;
3131

3232
extern llvm::cl::opt<unsigned> AlignText;
33+
extern llvm::cl::opt<unsigned> AlignFunctions;
3334
extern llvm::cl::opt<bool> AggregateOnly;
3435
extern llvm::cl::opt<unsigned> BucketsPerLine;
3536
extern llvm::cl::opt<bool> DiffOnly;

bolt/lib/Core/BinaryContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ BinaryContext::BinaryContext(std::unique_ptr<MCContext> Ctx,
101101
InstPrinter(std::move(InstPrinter)), MIA(std::move(MIA)),
102102
MIB(std::move(MIB)), MRI(std::move(MRI)), DisAsm(std::move(DisAsm)) {
103103
Relocation::Arch = this->TheTriple->getArch();
104+
RegularPageSize = isAArch64() ? RegularPageSizeAArch64 : RegularPageSizeX86;
104105
PageAlign = opts::NoHugePages ? RegularPageSize : HugePageSize;
105106
}
106107

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
291291
BC.Ctx->addGenDwarfSection(Section);
292292

293293
if (BC.HasRelocations) {
294+
// Set section alignment to at least maximum possible object alignment.
295+
// We need this to support LongJmp and other passes that calculates
296+
// tentative layout.
297+
if (Section->getAlignment() < opts::AlignFunctions)
298+
Section->setAlignment(Align(opts::AlignFunctions));
299+
294300
Streamer.emitCodeAlignment(BinaryFunction::MinAlign, &*BC.STI);
295301
uint16_t MaxAlignBytes = EmitColdPart ? Function.getMaxColdAlignmentBytes()
296302
: Function.getMaxAlignmentBytes();

bolt/lib/Passes/Aligner.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern cl::OptionCategory BoltOptCategory;
2323

2424
extern cl::opt<bool> AlignBlocks;
2525
extern cl::opt<bool> PreserveBlocksAlignment;
26+
extern cl::opt<unsigned> AlignFunctions;
2627

2728
cl::opt<unsigned>
2829
AlignBlocksMinSize("align-blocks-min-size",
@@ -43,13 +44,6 @@ AlignBlocksThreshold("align-blocks-threshold",
4344
cl::Hidden,
4445
cl::cat(BoltOptCategory));
4546

46-
cl::opt<unsigned>
47-
AlignFunctions("align-functions",
48-
cl::desc("align functions at a given value (relocation mode)"),
49-
cl::init(64),
50-
cl::ZeroOrMore,
51-
cl::cat(BoltOptCategory));
52-
5347
cl::opt<unsigned>
5448
AlignFunctionsMaxBytes("align-functions-max-bytes",
5549
cl::desc("maximum number of bytes to use to align functions"),

0 commit comments

Comments
 (0)