Skip to content

Commit f3cc5b1

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW39)
LLVM: llvm/llvm-project@6b0b306 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@3938c74
2 parents 70c2dc6 + 71d1538 commit f3cc5b1

File tree

5,859 files changed

+381704
-226760
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,859 files changed

+381704
-226760
lines changed

.github/workflows/version-check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_version_from_tag(tag):
1212
# We have an rc tag.
1313
return m.group(1,2,3)
1414
# We have a final release tag.
15-
return (m.group(1), m.group(2), int(m.group(3)) + 1)
15+
return (m.group(1), m.group(2), str(int(m.group(3)) + 1))
1616

1717
m = re.match('llvmorg-([0-9]+)-init', tag)
1818
if m:

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,9 @@ inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
104104
/// Filter iterator.
105105
template <typename ItrType,
106106
typename PredType = std::function<bool(const ItrType &)>>
107-
class FilterIterator
108-
: public std::iterator<std::bidirectional_iterator_tag,
109-
typename std::iterator_traits<ItrType>::value_type> {
107+
class FilterIterator {
108+
using inner_traits = std::iterator_traits<ItrType>;
110109
using Iterator = FilterIterator;
111-
using T = typename std::iterator_traits<ItrType>::reference;
112-
using PointerT = typename std::iterator_traits<ItrType>::pointer;
113110

114111
PredType Pred;
115112
ItrType Itr, End;
@@ -128,14 +125,20 @@ class FilterIterator
128125
}
129126

130127
public:
128+
using iterator_category = std::bidirectional_iterator_tag;
129+
using value_type = typename inner_traits::value_type;
130+
using difference_type = typename inner_traits::difference_type;
131+
using pointer = typename inner_traits::pointer;
132+
using reference = typename inner_traits::reference;
133+
131134
Iterator &operator++() { next(); return *this; }
132135
Iterator &operator--() { prev(); return *this; }
133136
Iterator operator++(int) { auto Tmp(Itr); next(); return Tmp; }
134137
Iterator operator--(int) { auto Tmp(Itr); prev(); return Tmp; }
135138
bool operator==(const Iterator &Other) const { return Itr == Other.Itr; }
136139
bool operator!=(const Iterator &Other) const { return !operator==(Other); }
137-
T operator*() { return *Itr; }
138-
PointerT operator->() { return &operator*(); }
140+
reference operator*() { return *Itr; }
141+
pointer operator->() { return &operator*(); }
139142
FilterIterator(PredType Pred, ItrType Itr, ItrType End)
140143
: Pred(Pred), Itr(Itr), End(End) {
141144
nextMatching();
@@ -383,6 +386,8 @@ class BinaryContext {
383386
}
384387

385388
unsigned getDWARFEncodingSize(unsigned Encoding) {
389+
if (Encoding == dwarf::DW_EH_PE_omit)
390+
return 0;
386391
switch (Encoding & 0x0f) {
387392
default:
388393
llvm_unreachable("unknown encoding");
@@ -666,7 +671,6 @@ class BinaryContext {
666671

667672
/// DWARF encoding. Available encoding types defined in BinaryFormat/Dwarf.h
668673
/// enum Constants, e.g. DW_EH_PE_omit.
669-
unsigned TTypeEncoding = dwarf::DW_EH_PE_omit;
670674
unsigned LSDAEncoding = dwarf::DW_EH_PE_omit;
671675

672676
BinaryContext(std::unique_ptr<MCContext> Ctx,

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
#include "bolt/Core/JumpTable.h"
3535
#include "bolt/Core/MCPlus.h"
3636
#include "bolt/Utils/NameResolver.h"
37+
#include "llvm/ADT/STLExtras.h"
38+
#include "llvm/ADT/SmallString.h"
3739
#include "llvm/ADT/StringRef.h"
3840
#include "llvm/ADT/iterator.h"
41+
#include "llvm/ADT/iterator_range.h"
3942
#include "llvm/BinaryFormat/Dwarf.h"
4043
#include "llvm/MC/MCContext.h"
4144
#include "llvm/MC/MCDwarf.h"
@@ -44,9 +47,11 @@
4447
#include "llvm/Object/ObjectFile.h"
4548
#include "llvm/Support/raw_ostream.h"
4649
#include <algorithm>
50+
#include <iterator>
4751
#include <limits>
4852
#include <unordered_map>
4953
#include <unordered_set>
54+
#include <utility>
5055
#include <vector>
5156

5257
using namespace llvm::object;
@@ -142,7 +147,8 @@ class BinaryFunction {
142147
uint64_t Action;
143148
};
144149

145-
using CallSitesType = SmallVector<CallSite, 0>;
150+
using CallSitesList = SmallVector<std::pair<FragmentNum, CallSite>, 0>;
151+
using CallSitesRange = iterator_range<CallSitesList::const_iterator>;
146152

147153
using IslandProxiesType =
148154
std::map<BinaryFunction *, std::map<const MCSymbol *, MCSymbol *>>;
@@ -382,6 +388,9 @@ class BinaryFunction {
382388
/// Original LSDA address for the function.
383389
uint64_t LSDAAddress{0};
384390

391+
/// Original LSDA type encoding
392+
unsigned LSDATypeEncoding{dwarf::DW_EH_PE_omit};
393+
385394
/// Containing compilation unit for the function.
386395
DWARFUnit *DwarfUnit{nullptr};
387396

@@ -492,8 +501,7 @@ class BinaryFunction {
492501
DenseMap<int32_t, SmallVector<int32_t, 4>> FrameRestoreEquivalents;
493502

494503
// For tracking exception handling ranges.
495-
CallSitesType CallSites;
496-
CallSitesType ColdCallSites;
504+
CallSitesList CallSites;
497505

498506
/// Binary blobs representing action, type, and type index tables for this
499507
/// function' LSDA (exception handling).
@@ -507,9 +515,9 @@ class BinaryFunction {
507515
/// addressing.
508516
LSDATypeTableTy LSDATypeAddressTable;
509517

510-
/// Marking for the beginning of language-specific data area for the function.
511-
MCSymbol *LSDASymbol{nullptr};
512-
MCSymbol *ColdLSDASymbol{nullptr};
518+
/// Marking for the beginnings of language-specific data areas for each
519+
/// fragment of the function.
520+
SmallVector<MCSymbol *, 0> LSDASymbols;
513521

514522
/// Map to discover which CFIs are attached to a given instruction offset.
515523
/// Maps an instruction offset into a FrameInstructions offset.
@@ -716,7 +724,6 @@ class BinaryFunction {
716724
BB->releaseCFG();
717725

718726
clearList(CallSites);
719-
clearList(ColdCallSites);
720727
clearList(LSDATypeTable);
721728
clearList(LSDATypeAddressTable);
722729

@@ -1067,6 +1074,14 @@ class BinaryFunction {
10671074
return N;
10681075
}
10691076

1077+
/// Return true if function has instructions to emit.
1078+
bool hasNonPseudoInstructions() const {
1079+
for (const BinaryBasicBlock &BB : blocks())
1080+
if (BB.getNumNonPseudos() > 0)
1081+
return true;
1082+
return false;
1083+
}
1084+
10701085
/// Return MC symbol associated with the function.
10711086
/// All references to the function should use this symbol.
10721087
MCSymbol *getSymbol(const FragmentNum Fragment = FragmentNum::main()) {
@@ -1418,14 +1433,24 @@ class BinaryFunction {
14181433

14191434
uint8_t getPersonalityEncoding() const { return PersonalityEncoding; }
14201435

1421-
const CallSitesType &getCallSites() const { return CallSites; }
1436+
CallSitesRange getCallSites(const FragmentNum F) const {
1437+
return make_range(std::equal_range(CallSites.begin(), CallSites.end(),
1438+
std::make_pair(F, CallSite()),
1439+
llvm::less_first()));
1440+
}
14221441

1423-
const CallSitesType &getColdCallSites() const { return ColdCallSites; }
1442+
void
1443+
addCallSites(const ArrayRef<std::pair<FragmentNum, CallSite>> NewCallSites) {
1444+
llvm::copy(NewCallSites, std::back_inserter(CallSites));
1445+
llvm::stable_sort(CallSites, llvm::less_first());
1446+
}
14241447

14251448
ArrayRef<uint8_t> getLSDAActionTable() const { return LSDAActionTable; }
14261449

14271450
const LSDATypeTableTy &getLSDATypeTable() const { return LSDATypeTable; }
14281451

1452+
unsigned getLSDATypeEncoding() const { return LSDATypeEncoding; }
1453+
14291454
const LSDATypeTableTy &getLSDATypeAddressTable() const {
14301455
return LSDATypeAddressTable;
14311456
}
@@ -1822,9 +1847,11 @@ class BinaryFunction {
18221847
return *this;
18231848
}
18241849

1825-
/// Set LSDA symbol for the function.
1850+
/// Set main LSDA symbol for the function.
18261851
BinaryFunction &setLSDASymbol(MCSymbol *Symbol) {
1827-
LSDASymbol = Symbol;
1852+
if (LSDASymbols.empty())
1853+
LSDASymbols.resize(1);
1854+
LSDASymbols.front() = Symbol;
18281855
return *this;
18291856
}
18301857

@@ -1848,30 +1875,25 @@ class BinaryFunction {
18481875
uint64_t getLSDAAddress() const { return LSDAAddress; }
18491876

18501877
/// Return symbol pointing to function's LSDA.
1851-
MCSymbol *getLSDASymbol() {
1852-
if (LSDASymbol)
1853-
return LSDASymbol;
1854-
if (CallSites.empty())
1878+
MCSymbol *getLSDASymbol(const FragmentNum F) {
1879+
if (F.get() < LSDASymbols.size() && LSDASymbols[F.get()] != nullptr)
1880+
return LSDASymbols[F.get()];
1881+
if (getCallSites(F).empty())
18551882
return nullptr;
18561883

1857-
LSDASymbol = BC.Ctx->getOrCreateSymbol(
1858-
Twine("GCC_except_table") + Twine::utohexstr(getFunctionNumber()));
1859-
1860-
return LSDASymbol;
1861-
}
1884+
if (F.get() >= LSDASymbols.size())
1885+
LSDASymbols.resize(F.get() + 1);
18621886

1863-
/// Return symbol pointing to function's LSDA for the cold part.
1864-
MCSymbol *getColdLSDASymbol(const FragmentNum Fragment) {
1865-
if (ColdLSDASymbol)
1866-
return ColdLSDASymbol;
1867-
if (ColdCallSites.empty())
1868-
return nullptr;
1887+
SmallString<256> SymbolName;
1888+
if (F == FragmentNum::main())
1889+
SymbolName = formatv("GCC_except_table{0:x-}", getFunctionNumber());
1890+
else
1891+
SymbolName = formatv("GCC_cold_except_table{0:x-}.{1}",
1892+
getFunctionNumber(), F.get());
18691893

1870-
ColdLSDASymbol =
1871-
BC.Ctx->getOrCreateSymbol(formatv("GCC_cold_except_table{0:x-}.{1}",
1872-
getFunctionNumber(), Fragment.get()));
1894+
LSDASymbols[F.get()] = BC.Ctx->getOrCreateSymbol(SymbolName);
18731895

1874-
return ColdLSDASymbol;
1896+
return LSDASymbols[F.get()];
18751897
}
18761898

18771899
void setOutputDataAddress(uint64_t Address) { OutputDataOffset = Address; }
@@ -2101,6 +2123,12 @@ class BinaryFunction {
21012123
/// cannot be statically evaluated for any given indirect branch.
21022124
bool postProcessIndirectBranches(MCPlusBuilder::AllocatorIdTy AllocId);
21032125

2126+
/// Validate that all data references to function offsets are claimed by
2127+
/// recognized jump tables. Register externally referenced blocks as entry
2128+
/// points. Returns true if there are no unclaimed externally referenced
2129+
/// offsets.
2130+
bool validateExternallyReferencedOffsets();
2131+
21042132
/// Return all call site profile info for this function.
21052133
IndirectCallSiteProfile &getAllCallSites() { return AllCallSites; }
21062134

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,14 @@ class MCPlusBuilder {
164164
void setTailCall(MCInst &Inst);
165165

166166
public:
167-
class InstructionIterator
168-
: public std::iterator<std::bidirectional_iterator_tag, MCInst> {
167+
class InstructionIterator {
169168
public:
169+
using iterator_category = std::bidirectional_iterator_tag;
170+
using value_type = MCInst;
171+
using difference_type = std::ptrdiff_t;
172+
using pointer = value_type *;
173+
using reference = value_type &;
174+
170175
class Impl {
171176
public:
172177
virtual Impl *Copy() const = 0;

bolt/include/bolt/Passes/CacheMetrics.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,9 @@ namespace bolt {
2121
class BinaryFunction;
2222
namespace CacheMetrics {
2323

24-
/// Calculate various metrics related to instruction cache performance.
24+
/// Calculate and print various metrics related to instruction cache performance
2525
void printAll(const std::vector<BinaryFunction *> &BinaryFunctions);
2626

27-
/// Calculate Extended-TSP metric, which quantifies the expected number of
28-
/// i-cache misses for a given pair of basic blocks. The parameters are:
29-
/// - SrcAddr is the address of the source block;
30-
/// - SrcSize is the size of the source block;
31-
/// - DstAddr is the address of the destination block;
32-
/// - Count is the number of jumps between the pair of blocks.
33-
double extTSPScore(uint64_t SrcAddr, uint64_t SrcSize, uint64_t DstAddr,
34-
uint64_t Count);
35-
3627
} // namespace CacheMetrics
3728
} // namespace bolt
3829
} // namespace llvm

bolt/include/bolt/Passes/DataflowAnalysis.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,18 @@ class DataflowAnalysis {
439439
/// Define an iterator for navigating the expressions calculated by a
440440
/// dataflow analysis at each program point, when they are backed by a
441441
/// BitVector.
442-
class ExprIterator
443-
: public std::iterator<std::forward_iterator_tag, const MCInst *> {
442+
class ExprIterator {
444443
const BitVector *BV;
445444
const std::vector<MCInst *> &Expressions;
446445
int Idx;
447446

448447
public:
448+
using iterator_category = std::forward_iterator_tag;
449+
using value_type = const MCInst *;
450+
using difference_type = std::ptrdiff_t;
451+
using pointer = value_type *;
452+
using reference = value_type &;
453+
449454
ExprIterator &operator++() {
450455
assert(Idx != -1 && "Iterator already at the end");
451456
Idx = BV->find_next(Idx);

bolt/include/bolt/Passes/IndirectCallPromotion.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ class IndirectCallPromotion : public BinaryFunctionPass {
217217
bool shouldPrint(const BinaryFunction &BF) const override {
218218
return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
219219
}
220+
bool shouldOptimize(const BinaryFunction &BF) const override {
221+
return BF.isSimple() && !BF.isIgnored() && BF.hasProfile() &&
222+
!BF.hasUnknownControlFlow();
223+
}
220224
void runOnFunctions(BinaryContext &BC) override;
221225
};
222226

bolt/include/bolt/Passes/SplitFunctions.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ enum SplitFunctionsStrategy : char {
3434
All
3535
};
3636

37+
class SplitStrategy {
38+
public:
39+
using BlockIt = BinaryFunction::BasicBlockOrderType::iterator;
40+
41+
virtual ~SplitStrategy() = default;
42+
virtual bool canSplit(const BinaryFunction &BF) = 0;
43+
virtual bool keepEmpty() = 0;
44+
virtual void fragment(const BlockIt Start, const BlockIt End) = 0;
45+
};
46+
3747
/// Split function code in multiple parts.
3848
class SplitFunctions : public BinaryFunctionPass {
3949
private:
4050
/// Split function body into fragments.
41-
template <typename Strategy>
42-
void splitFunction(BinaryFunction &Function, Strategy S = {});
51+
void splitFunction(BinaryFunction &Function, SplitStrategy &Strategy);
4352

4453
struct TrampolineKey {
4554
FragmentNum SourceFN = FragmentNum::main();

bolt/include/bolt/Rewrite/ExecutableFileMemoryManager.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define BOLT_REWRITE_EXECUTABLE_FILE_MEMORY_MANAGER_H
1111

1212
#include "llvm/ADT/StringRef.h"
13-
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
13+
#include "llvm/ExecutionEngine/RuntimeDyld.h"
1414
#include <cstdint>
1515
#include <string>
1616

@@ -20,14 +20,21 @@ namespace bolt {
2020
class BinaryContext;
2121

2222
/// Class responsible for allocating and managing code and data sections.
23-
class ExecutableFileMemoryManager : public SectionMemoryManager {
23+
class ExecutableFileMemoryManager : public RuntimeDyld::MemoryManager {
2424
private:
25-
uint8_t *allocateSection(intptr_t Size, unsigned Alignment,
25+
uint8_t *allocateSection(uintptr_t Size, unsigned Alignment,
2626
unsigned SectionID, StringRef SectionName,
2727
bool IsCode, bool IsReadOnly);
2828
BinaryContext &BC;
2929
bool AllowStubs;
3030

31+
struct AllocInfo {
32+
uint8_t *Address;
33+
size_t Size;
34+
size_t Alignment;
35+
};
36+
SmallVector<AllocInfo, 8> AllocatedSections;
37+
3138
public:
3239
// Our linker's main purpose is to handle a single object file, created
3340
// by RewriteInstance after reading the input binary and reordering it.
@@ -69,7 +76,16 @@ class ExecutableFileMemoryManager : public SectionMemoryManager {
6976

7077
bool allowStubAllocation() const override { return AllowStubs; }
7178

72-
bool finalizeMemory(std::string *ErrMsg = nullptr) override;
79+
/// Count processed objects and skip memory finalization.
80+
bool finalizeMemory(std::string *ErrMsg) override {
81+
++ObjectsLoaded;
82+
return false;
83+
}
84+
85+
/// Ignore EH frames.
86+
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
87+
size_t Size) override {}
88+
void deregisterEHFrames() override {}
7389
};
7490

7591
} // namespace bolt

0 commit comments

Comments
 (0)