Skip to content

Commit 8aa15c1

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW06)
LLVM: llvm/llvm-project@8ce99dadb007 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@fb2dd0e
2 parents 01f3fc7 + dc05829 commit 8aa15c1

File tree

4,234 files changed

+140316
-125453
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,234 files changed

+140316
-125453
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ CheckOptions:
1818
value: 1
1919
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
2020
value: 1
21+
- key: modernize-use-default-member-init.UseAssignment
22+
value: 1

bolt/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ add_subdirectory(lib)
9191
add_subdirectory(tools)
9292

9393
if (BOLT_INCLUDE_TESTS)
94+
if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
95+
add_subdirectory(unittests)
96+
list(APPEND BOLT_TEST_DEPS BoltUnitTests)
97+
endif()
9498
add_subdirectory(test)
9599
endif()
96100

bolt/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ compiler option. Since GCC8 enables this option by default, you have to
3030
explicitly disable it by adding `-fno-reorder-blocks-and-partition` flag if
3131
you are compiling with GCC8 or above.
3232

33+
NOTE2: DWARF v5 is the new debugging format generated by the latest LLVM and GCC
34+
compilers. It offers several benefits over the previous DWARF v4. Currently, the
35+
support for v5 is a work in progress for BOLT. While you will be able to
36+
optimize binaries produced by the latest compilers, until the support is
37+
complete, you will not be able to update the debug info with
38+
`-update-debug-sections`. To temporarily work around the issue, we recommend
39+
compiling binaries with `-gdwarf-4` option that forces DWARF v4 output.
40+
3341
PIE and .so support has been added recently. Please report bugs if you
3442
encounter any issues.
3543

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@
2828
#include "llvm/MC/MCAsmInfo.h"
2929
#include "llvm/MC/MCCodeEmitter.h"
3030
#include "llvm/MC/MCContext.h"
31-
#include "llvm/MC/MCDwarf.h"
32-
#include "llvm/MC/MCInstrInfo.h"
3331
#include "llvm/MC/MCObjectFileInfo.h"
3432
#include "llvm/MC/MCObjectWriter.h"
3533
#include "llvm/MC/MCPseudoProbe.h"
3634
#include "llvm/MC/MCSectionELF.h"
3735
#include "llvm/MC/MCSectionMachO.h"
36+
#include "llvm/MC/MCStreamer.h"
3837
#include "llvm/MC/MCSymbol.h"
3938
#include "llvm/MC/TargetRegistry.h"
4039
#include "llvm/Support/ErrorOr.h"

bolt/include/bolt/Core/BinaryData.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define BOLT_CORE_BINARY_DATA_H
1717

1818
#include "llvm/ADT/Twine.h"
19-
#include "llvm/MC/MCStreamer.h"
2019
#include "llvm/MC/MCSymbol.h"
2120
#include "llvm/Support/raw_ostream.h"
2221
#include <algorithm>

bolt/include/bolt/Core/DebugData.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef BOLT_CORE_DEBUG_DATA_H
1515
#define BOLT_CORE_DEBUG_DATA_H
1616

17-
#include "llvm/ADT/MapVector.h"
1817
#include "llvm/ADT/SmallVector.h"
1918
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
2019
#include "llvm/MC/MCDwarf.h"
@@ -33,8 +32,6 @@
3332

3433
namespace llvm {
3534

36-
class DWARFAbbreviationDeclarationSet;
37-
3835
namespace bolt {
3936

4037
class BinaryContext;

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,14 @@ class MCPlusBuilder {
18981898
}
18991899
};
19001900

1901+
MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,
1902+
const MCInstrInfo *,
1903+
const MCRegisterInfo *);
1904+
1905+
MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
1906+
const MCInstrInfo *,
1907+
const MCRegisterInfo *);
1908+
19011909
} // namespace bolt
19021910
} // namespace llvm
19031911

bolt/include/bolt/Passes/AllocCombiner.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace llvm {
1515
namespace bolt {
16-
class DataflowInfoManager;
17-
class FrameAnalysis;
1816

1917
class AllocCombinerPass : public BinaryFunctionPass {
2018
/// Stats aggregating variables

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
#define BOLT_REWRITE_DWARF_REWRITER_H
1111

1212
#include "bolt/Core/DebugData.h"
13-
#include "bolt/Rewrite/RewriteInstance.h"
1413
#include <cstdint>
15-
#include <map>
1614
#include <memory>
1715
#include <mutex>
16+
#include <set>
1817
#include <unordered_map>
1918
#include <vector>
2019

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ class RewriteInstance {
545545
friend class RewriteInstanceDiff;
546546
};
547547

548+
MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
549+
const MCInstrAnalysis *Analysis,
550+
const MCInstrInfo *Info,
551+
const MCRegisterInfo *RegInfo);
552+
548553
} // namespace bolt
549554
} // namespace llvm
550555

bolt/include/bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h

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

1717
#include "bolt/Passes/InstrumentationSummary.h"
1818
#include "bolt/RuntimeLibs/RuntimeLibrary.h"
19+
#include <memory>
1920

2021
namespace llvm {
2122
namespace bolt {

bolt/include/bolt/Utils/CommandLineOpts.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extern llvm::cl::opt<unsigned long long> HeatmapMinAddress;
4444
extern llvm::cl::opt<bool> HotData;
4545
extern llvm::cl::opt<bool> HotFunctionsAtEnd;
4646
extern llvm::cl::opt<bool> HotText;
47-
extern llvm::cl::opt<std::string> InputFilename;
4847
extern llvm::cl::opt<bool> Instrument;
4948
extern llvm::cl::opt<std::string> OutputFilename;
5049
extern llvm::cl::opt<std::string> PerfData;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "llvm/MC/MCExpr.h"
2929
#include "llvm/MC/MCInst.h"
3030
#include "llvm/MC/MCInstPrinter.h"
31-
#include "llvm/MC/MCStreamer.h"
3231
#include "llvm/Object/ObjectFile.h"
3332
#include "llvm/Support/CommandLine.h"
3433
#include "llvm/Support/Debug.h"
@@ -3613,13 +3612,13 @@ void BinaryFunction::insertBasicBlocks(
36133612
std::vector<std::unique_ptr<BinaryBasicBlock>> &&NewBBs,
36143613
const bool UpdateLayout, const bool UpdateCFIState,
36153614
const bool RecomputeLandingPads) {
3616-
const auto StartIndex = Start ? getIndex(Start) : -1;
3615+
const int64_t StartIndex = Start ? getIndex(Start) : -1LL;
36173616
const size_t NumNewBlocks = NewBBs.size();
36183617

36193618
BasicBlocks.insert(BasicBlocks.begin() + (StartIndex + 1), NumNewBlocks,
36203619
nullptr);
36213620

3622-
auto I = StartIndex + 1;
3621+
int64_t I = StartIndex + 1;
36233622
for (std::unique_ptr<BinaryBasicBlock> &BB : NewBBs) {
36243623
assert(!BasicBlocks[I]);
36253624
BasicBlocks[I++] = BB.release();

bolt/lib/Core/DebugData.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "bolt/Core/DebugData.h"
14-
#include "bolt/Core/BinaryBasicBlock.h"
15-
#include "bolt/Core/BinaryFunction.h"
14+
#include "bolt/Core/BinaryContext.h"
1615
#include "bolt/Utils/Utils.h"
16+
#include "llvm/MC/MCContext.h"
1717
#include "llvm/MC/MCObjectStreamer.h"
18-
#include "llvm/MC/MCSymbol.h"
1918
#include "llvm/Support/CommandLine.h"
2019
#include "llvm/Support/EndianStream.h"
2120
#include "llvm/Support/LEB128.h"
@@ -32,6 +31,8 @@ extern llvm::cl::opt<unsigned> Verbosity;
3231
} // namespace opts
3332

3433
namespace llvm {
34+
class MCSymbol;
35+
3536
namespace bolt {
3637

3738
const DebugLineTableRowRef DebugLineTableRowRef::NULL_ROW{0, 0};

bolt/lib/Core/JumpTable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "bolt/Core/BinaryFunction.h"
1515
#include "bolt/Core/BinarySection.h"
1616
#include "llvm/Support/CommandLine.h"
17-
#include "llvm/Support/Debug.h"
1817

1918
#define DEBUG_TYPE "bolt"
2019

bolt/lib/Passes/IndirectCallPromotion.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "bolt/Passes/IndirectCallPromotion.h"
1414
#include "bolt/Passes/BinaryFunctionCallGraph.h"
1515
#include "bolt/Passes/DataflowInfoManager.h"
16-
#include "bolt/Utils/CommandLineOpts.h"
1716
#include "llvm/Support/CommandLine.h"
1817

1918
#define DEBUG_TYPE "ICP"
@@ -281,7 +280,7 @@ IndirectCallPromotion::getCallTargets(BinaryBasicBlock &BB,
281280
Inst.getOperand(0).getReg() == BC.MRI->getProgramCounter())
282281
return Targets;
283282

284-
auto ICSP = BC.MIB->tryGetAnnotationAs<IndirectCallSiteProfile>(
283+
const auto ICSP = BC.MIB->tryGetAnnotationAs<IndirectCallSiteProfile>(
285284
Inst, "CallProfile");
286285
if (ICSP) {
287286
for (const IndirectCallProfile &CSP : ICSP.get()) {
@@ -292,17 +291,18 @@ IndirectCallPromotion::getCallTargets(BinaryBasicBlock &BB,
292291
}
293292
}
294293

295-
// Sort by target count, number of indices in case of jump table, and
296-
// mispredicts. We prioritize targets with high count, small number of
297-
// indices and high mispredicts
294+
// Sort by target count, number of indices in case of jump table, and
295+
// mispredicts. We prioritize targets with high count, small number of indices
296+
// and high mispredicts. Break ties by selecting targets with lower addresses.
298297
std::stable_sort(Targets.begin(), Targets.end(),
299298
[](const Callsite &A, const Callsite &B) {
300299
if (A.Branches != B.Branches)
301300
return A.Branches > B.Branches;
302-
else if (A.JTIndices.size() != B.JTIndices.size())
301+
if (A.JTIndices.size() != B.JTIndices.size())
303302
return A.JTIndices.size() < B.JTIndices.size();
304-
else
303+
if (A.Mispreds != B.Mispreds)
305304
return A.Mispreds > B.Mispreds;
305+
return A.To.Addr < B.To.Addr;
306306
});
307307

308308
// Remove non-symbol targets
@@ -938,7 +938,7 @@ size_t IndirectCallPromotion::canPromoteCallsite(
938938
// If we have no targets (or no calls), skip this callsite.
939939
if (Targets.empty() || !NumCalls) {
940940
if (opts::Verbosity >= 1) {
941-
const auto InstIdx = &Inst - &(*BB.begin());
941+
const ptrdiff_t InstIdx = &Inst - &(*BB.begin());
942942
outs() << "BOLT-INFO: ICP failed in " << *BB.getFunction() << " @ "
943943
<< InstIdx << " in " << BB.getName() << ", calls = " << NumCalls
944944
<< ", targets empty or NumCalls == 0.\n";
@@ -985,7 +985,7 @@ size_t IndirectCallPromotion::canPromoteCallsite(
985985
if (TopNFrequency == 0 ||
986986
TopNFrequency < opts::IndirectCallPromotionMispredictThreshold) {
987987
if (opts::Verbosity >= 1) {
988-
const auto InstIdx = &Inst - &(*BB.begin());
988+
const ptrdiff_t InstIdx = &Inst - &(*BB.begin());
989989
outs() << "BOLT-INFO: ICP failed in " << *BB.getFunction() << " @ "
990990
<< InstIdx << " in " << BB.getName() << ", calls = " << NumCalls
991991
<< ", top N mis. frequency " << format("%.1f", TopNFrequency)
@@ -1034,7 +1034,7 @@ size_t IndirectCallPromotion::canPromoteCallsite(
10341034
if (TopNMispredictFrequency <
10351035
opts::IndirectCallPromotionMispredictThreshold) {
10361036
if (opts::Verbosity >= 1) {
1037-
const auto InstIdx = &Inst - &(*BB.begin());
1037+
const ptrdiff_t InstIdx = &Inst - &(*BB.begin());
10381038
outs() << "BOLT-INFO: ICP failed in " << *BB.getFunction() << " @ "
10391039
<< InstIdx << " in " << BB.getName()
10401040
<< ", calls = " << NumCalls << ", top N mispredict frequency "
@@ -1064,7 +1064,7 @@ void IndirectCallPromotion::printCallsiteInfo(
10641064
BinaryContext &BC = BB.getFunction()->getBinaryContext();
10651065
const bool IsTailCall = BC.MIB->isTailCall(Inst);
10661066
const bool IsJumpTable = BB.getFunction()->getJumpTable(Inst);
1067-
const auto InstIdx = &Inst - &(*BB.begin());
1067+
const ptrdiff_t InstIdx = &Inst - &(*BB.begin());
10681068

10691069
outs() << "BOLT-INFO: ICP candidate branch info: " << *BB.getFunction()
10701070
<< " @ " << InstIdx << " in " << BB.getName()
@@ -1219,7 +1219,7 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
12191219

12201220
for (unsigned Idx = 0; Idx < BB->size(); ++Idx) {
12211221
MCInst &Inst = BB->getInstructionAtIndex(Idx);
1222-
const auto InstIdx = &Inst - &(*BB->begin());
1222+
const ptrdiff_t InstIdx = &Inst - &(*BB->begin());
12231223
const bool IsTailCall = BC.MIB->isTailCall(Inst);
12241224
const bool HasIndirectCallProfile =
12251225
BC.MIB->hasAnnotation(Inst, "CallProfile");

bolt/lib/Passes/ThreeWayBranch.cpp

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

1313
#include "bolt/Passes/ThreeWayBranch.h"
1414

15-
#include <numeric>
16-
1715
using namespace llvm;
1816

1917
namespace llvm {

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void convert(const BinaryFunction &BF,
5959
CSI.Offset = *Offset - BB->getInputOffset();
6060

6161
if (BC.MIB->isIndirectCall(Instr) || BC.MIB->isIndirectBranch(Instr)) {
62-
auto ICSP = BC.MIB->tryGetAnnotationAs<IndirectCallSiteProfile>(
62+
const auto ICSP = BC.MIB->tryGetAnnotationAs<IndirectCallSiteProfile>(
6363
Instr, "CallProfile");
6464
if (!ICSP)
6565
continue;

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "bolt/Core/BinaryFunction.h"
1212
#include "bolt/Core/DebugData.h"
1313
#include "bolt/Core/ParallelUtilities.h"
14+
#include "bolt/Rewrite/RewriteInstance.h"
1415
#include "bolt/Utils/Utils.h"
1516
#include "llvm/ADT/STLExtras.h"
1617
#include "llvm/BinaryFormat/Dwarf.h"
@@ -20,11 +21,8 @@
2021
#include "llvm/MC/MCAsmBackend.h"
2122
#include "llvm/MC/MCAsmLayout.h"
2223
#include "llvm/MC/MCContext.h"
23-
#include "llvm/MC/MCDwarf.h"
2424
#include "llvm/MC/MCObjectWriter.h"
25-
#include "llvm/MC/MCSection.h"
2625
#include "llvm/MC/MCStreamer.h"
27-
#include "llvm/MC/MCSymbol.h"
2826
#include "llvm/Object/ObjectFile.h"
2927
#include "llvm/Support/Casting.h"
3028
#include "llvm/Support/CommandLine.h"

bolt/lib/Rewrite/MachORewriteInstance.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
#include "bolt/Rewrite/ExecutableFileMemoryManager.h"
2020
#include "bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h"
2121
#include "bolt/Utils/Utils.h"
22-
#include "llvm/MC/MCAsmBackend.h"
2322
#include "llvm/MC/MCAsmLayout.h"
2423
#include "llvm/MC/MCObjectStreamer.h"
25-
#include "llvm/MC/MCObjectWriter.h"
2624
#include "llvm/Support/FileSystem.h"
2725
#include "llvm/Support/ToolOutputFile.h"
2826

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
#include "llvm/MC/MCAsmBackend.h"
3636
#include "llvm/MC/MCAsmInfo.h"
3737
#include "llvm/MC/MCAsmLayout.h"
38-
#include "llvm/MC/MCContext.h"
3938
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
4039
#include "llvm/MC/MCObjectStreamer.h"
41-
#include "llvm/MC/MCObjectWriter.h"
4240
#include "llvm/MC/MCStreamer.h"
4341
#include "llvm/MC/MCSymbol.h"
4442
#include "llvm/MC/TargetRegistry.h"
@@ -321,27 +319,6 @@ namespace bolt {
321319

322320
extern const char *BoltRevision;
323321

324-
extern MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,
325-
const MCInstrInfo *,
326-
const MCRegisterInfo *);
327-
extern MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
328-
const MCInstrInfo *,
329-
const MCRegisterInfo *);
330-
331-
} // namespace bolt
332-
} // namespace llvm
333-
334-
namespace {
335-
336-
bool refersToReorderedSection(ErrorOr<BinarySection &> Section) {
337-
auto Itr =
338-
std::find_if(opts::ReorderData.begin(), opts::ReorderData.end(),
339-
[&](const std::string &SectionName) {
340-
return (Section && Section->getName() == SectionName);
341-
});
342-
return Itr != opts::ReorderData.end();
343-
}
344-
345322
MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
346323
const MCInstrAnalysis *Analysis,
347324
const MCInstrInfo *Info,
@@ -359,6 +336,20 @@ MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
359336
llvm_unreachable("architecture unsupported by MCPlusBuilder");
360337
}
361338

339+
} // namespace bolt
340+
} // namespace llvm
341+
342+
namespace {
343+
344+
bool refersToReorderedSection(ErrorOr<BinarySection &> Section) {
345+
auto Itr =
346+
std::find_if(opts::ReorderData.begin(), opts::ReorderData.end(),
347+
[&](const std::string &SectionName) {
348+
return (Section && Section->getName() == SectionName);
349+
});
350+
return Itr != opts::ReorderData.end();
351+
}
352+
362353
} // anonymous namespace
363354

364355
RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,

0 commit comments

Comments
 (0)