Skip to content

Commit 2f5e990

Browse files
committed
LLVM and SPIRV-LLVM-Translator pulldown (WW10)
LLVM: llvm/llvm-project@9d899d8f01872 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@e95ae260
2 parents f810047 + 381bb84 commit 2f5e990

File tree

2,920 files changed

+84557
-36844
lines changed

Some content is hidden

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

2,920 files changed

+84557
-36844
lines changed

.github/workflows/issue-release-workflow.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ on:
1919
types:
2020
- created
2121
- edited
22+
issues:
23+
types:
24+
- opened
2225

2326
env:
24-
COMMENT_BODY: ${{ github.event.comment.body }}
27+
COMMENT_BODY: ${{ github.event.action == 'opened' && github.event.issue.body || github.event.comment.body }}
2528

2629
jobs:
2730
backport-commits:
@@ -30,7 +33,7 @@ jobs:
3033
if: >-
3134
(github.repository == 'llvm/llvm-project') &&
3235
!startswith(github.event.comment.body, '<!--IGNORE-->') &&
33-
contains(github.event.comment.body, '/cherry-pick')
36+
contains(github.event.action == 'opened' && github.event.issue.body || github.event.comment.body, '/cherry-pick')
3437
steps:
3538
- name: Fetch LLVM sources
3639
uses: actions/checkout@v2

.github/workflows/issue-subscriber.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ jobs:
1818
pip install -r requirements.txt
1919
2020
- name: Update watchers
21+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
22+
env:
23+
LABEL_NAME: ${{ github.event.label.name }}
2124
run: |
2225
./github-automation.py \
23-
--token ${{ secrets.ISSUE_SUBSCRIBER_TOKEN }} \
26+
--token '${{ secrets.ISSUE_SUBSCRIBER_TOKEN }}' \
2427
issue-subscriber \
25-
--issue-number ${{ github.event.issue.number }} \
26-
--label-name ${{ github.event.label.name }}
28+
--issue-number '${{ github.event.issue.number }}' \
29+
--label-name "$LABEL_NAME"

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class BinaryContext {
211211
std::map<unsigned, DwarfLineTable> DwarfLineTablesCUMap;
212212

213213
public:
214-
static std::unique_ptr<BinaryContext>
214+
static Expected<std::unique_ptr<BinaryContext>>
215215
createBinaryContext(const ObjectFile *File, bool IsPIC,
216216
std::unique_ptr<DWARFContext> DwCtx);
217217

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class MCPlusBuilder {
7474
AllocatorIdTy MaxAllocatorId = 0;
7575

7676
/// We encode Index and Value into a 64-bit immediate operand value.
77-
static int64_t encodeAnnotationImm(unsigned Index, int64_t Value) {
78-
assert(Index < 256 && "annotation index max value exceeded");
79-
assert((Value == (Value << 8) >> 8) && "annotation value out of range");
77+
static int64_t encodeAnnotationImm(uint8_t Index, int64_t Value) {
78+
if (LLVM_UNLIKELY(Value != extractAnnotationValue(Value)))
79+
report_fatal_error("annotation value out of range");
8080

8181
Value &= 0xff'ffff'ffff'ffff;
8282
Value |= (int64_t)Index << 56;
@@ -85,14 +85,13 @@ class MCPlusBuilder {
8585
}
8686

8787
/// Extract annotation index from immediate operand value.
88-
static unsigned extractAnnotationIndex(int64_t ImmValue) {
88+
static uint8_t extractAnnotationIndex(int64_t ImmValue) {
8989
return ImmValue >> 56;
9090
}
9191

9292
/// Extract annotation value from immediate operand value.
9393
static int64_t extractAnnotationValue(int64_t ImmValue) {
94-
ImmValue &= 0xff'ffff'ffff'ffff;
95-
return (ImmValue << 8) >> 8;
94+
return SignExtend64<56>(ImmValue & 0xff'ffff'ffff'ffffULL);
9695
}
9796

9897
MCInst *getAnnotationInst(const MCInst &Inst) const {

bolt/include/bolt/Passes/ShrinkWrapping.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ class ShrinkWrapping {
308308
std::vector<MCInst *> BestSavePos;
309309

310310
/// Pass stats
311-
static uint64_t SpillsMovedRegularMode;
312-
static uint64_t SpillsMovedPushPopMode;
311+
static std::atomic_uint64_t SpillsMovedRegularMode;
312+
static std::atomic_uint64_t SpillsMovedPushPopMode;
313313

314314
Optional<unsigned> AnnotationIndex;
315315

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ class DWARFRewriter {
147147
SimpleBinaryPatcher &DebugInfoPatcher,
148148
Optional<uint64_t> RangesBase = None);
149149

150-
/// Patch DW_AT_(low|high)_pc values for the \p DIE based on \p Range.
151-
void patchLowHigh(DWARFDie DIE, DebugAddressRange Range,
152-
SimpleBinaryPatcher &DebugInfoPatcher,
153-
Optional<uint64_t> DWOId);
154-
155150
/// Helper function for creating and returning per-DWO patchers/writers.
156151
template <class T, class Patcher>
157152
Patcher *getBinaryDWOPatcherHelper(T &BinaryPatchers, uint64_t DwoId) {

bolt/include/bolt/Rewrite/MachORewriteInstance.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ class MachORewriteInstance {
6565
void rewriteFile();
6666

6767
public:
68-
MachORewriteInstance(object::MachOObjectFile *InputFile, StringRef ToolPath);
68+
// This constructor has complex initialization that can fail during
69+
// construction. Constructors can’t return errors, so clients must test \p Err
70+
// after the object is constructed. Use createMachORewriteInstance instead.
71+
MachORewriteInstance(object::MachOObjectFile *InputFile, StringRef ToolPath,
72+
Error &Err);
73+
74+
static Expected<std::unique_ptr<MachORewriteInstance>>
75+
createMachORewriteInstance(object::MachOObjectFile *InputFile,
76+
StringRef ToolPath);
6977
~MachORewriteInstance();
7078

7179
Error setProfile(StringRef FileName);

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ class ProfileReaderBase;
4141
/// events.
4242
class RewriteInstance {
4343
public:
44+
// This constructor has complex initialization that can fail during
45+
// construction. Constructors can’t return errors, so clients must test \p Err
46+
// after the object is constructed. Use createRewriteInstance instead.
4447
RewriteInstance(llvm::object::ELFObjectFileBase *File, const int Argc,
45-
const char *const *Argv, StringRef ToolPath);
48+
const char *const *Argv, StringRef ToolPath, Error &Err);
49+
50+
static Expected<std::unique_ptr<RewriteInstance>>
51+
createRewriteInstance(llvm::object::ELFObjectFileBase *File, const int Argc,
52+
const char *const *Argv, StringRef ToolPath);
4653
~RewriteInstance();
4754

4855
/// Assign profile from \p Filename to this instance.

bolt/lib/Core/BinaryContext.cpp

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/MC/MCSubtargetInfo.h"
3434
#include "llvm/MC/MCSymbol.h"
3535
#include "llvm/Support/CommandLine.h"
36+
#include "llvm/Support/Error.h"
3637
#include "llvm/Support/Regex.h"
3738
#include <algorithm>
3839
#include <functional>
@@ -115,7 +116,7 @@ BinaryContext::~BinaryContext() {
115116

116117
/// Create BinaryContext for a given architecture \p ArchName and
117118
/// triple \p TripleName.
118-
std::unique_ptr<BinaryContext>
119+
Expected<std::unique_ptr<BinaryContext>>
119120
BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
120121
std::unique_ptr<DWARFContext> DwCtx) {
121122
StringRef ArchName = "";
@@ -131,8 +132,8 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
131132
"+fullfp16,+spe,+fuse-aes,+rcpc";
132133
break;
133134
default:
134-
errs() << "BOLT-ERROR: Unrecognized machine in ELF file.\n";
135-
return nullptr;
135+
return createStringError(std::errc::not_supported,
136+
"BOLT-ERROR: Unrecognized machine in ELF file");
136137
}
137138

138139
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
@@ -141,39 +142,37 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
141142
std::string Error;
142143
const Target *TheTarget =
143144
TargetRegistry::lookupTarget(std::string(ArchName), *TheTriple, Error);
144-
if (!TheTarget) {
145-
errs() << "BOLT-ERROR: " << Error;
146-
return nullptr;
147-
}
145+
if (!TheTarget)
146+
return createStringError(make_error_code(std::errc::not_supported),
147+
Twine("BOLT-ERROR: ", Error));
148148

149149
std::unique_ptr<const MCRegisterInfo> MRI(
150150
TheTarget->createMCRegInfo(TripleName));
151-
if (!MRI) {
152-
errs() << "BOLT-ERROR: no register info for target " << TripleName << "\n";
153-
return nullptr;
154-
}
151+
if (!MRI)
152+
return createStringError(
153+
make_error_code(std::errc::not_supported),
154+
Twine("BOLT-ERROR: no register info for target ", TripleName));
155155

156156
// Set up disassembler.
157157
std::unique_ptr<const MCAsmInfo> AsmInfo(
158158
TheTarget->createMCAsmInfo(*MRI, TripleName, MCTargetOptions()));
159-
if (!AsmInfo) {
160-
errs() << "BOLT-ERROR: no assembly info for target " << TripleName << "\n";
161-
return nullptr;
162-
}
159+
if (!AsmInfo)
160+
return createStringError(
161+
make_error_code(std::errc::not_supported),
162+
Twine("BOLT-ERROR: no assembly info for target ", TripleName));
163163

164164
std::unique_ptr<const MCSubtargetInfo> STI(
165165
TheTarget->createMCSubtargetInfo(TripleName, "", FeaturesStr));
166-
if (!STI) {
167-
errs() << "BOLT-ERROR: no subtarget info for target " << TripleName << "\n";
168-
return nullptr;
169-
}
166+
if (!STI)
167+
return createStringError(
168+
make_error_code(std::errc::not_supported),
169+
Twine("BOLT-ERROR: no subtarget info for target ", TripleName));
170170

171171
std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
172-
if (!MII) {
173-
errs() << "BOLT-ERROR: no instruction info for target " << TripleName
174-
<< "\n";
175-
return nullptr;
176-
}
172+
if (!MII)
173+
return createStringError(
174+
make_error_code(std::errc::not_supported),
175+
Twine("BOLT-ERROR: no instruction info for target ", TripleName));
177176

178177
std::unique_ptr<MCContext> Ctx(
179178
new MCContext(*TheTriple, AsmInfo.get(), MRI.get(), STI.get()));
@@ -198,28 +197,27 @@ BinaryContext::createBinaryContext(const ObjectFile *File, bool IsPIC,
198197
std::unique_ptr<MCDisassembler> DisAsm(
199198
TheTarget->createMCDisassembler(*STI, *Ctx));
200199

201-
if (!DisAsm) {
202-
errs() << "BOLT-ERROR: no disassembler for target " << TripleName << "\n";
203-
return nullptr;
204-
}
200+
if (!DisAsm)
201+
return createStringError(
202+
make_error_code(std::errc::not_supported),
203+
Twine("BOLT-ERROR: no disassembler info for target ", TripleName));
205204

206205
std::unique_ptr<const MCInstrAnalysis> MIA(
207206
TheTarget->createMCInstrAnalysis(MII.get()));
208-
if (!MIA) {
209-
errs() << "BOLT-ERROR: failed to create instruction analysis for target"
210-
<< TripleName << "\n";
211-
return nullptr;
212-
}
207+
if (!MIA)
208+
return createStringError(
209+
make_error_code(std::errc::not_supported),
210+
Twine("BOLT-ERROR: failed to create instruction analysis for target ",
211+
TripleName));
213212

214213
int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
215214
std::unique_ptr<MCInstPrinter> InstructionPrinter(
216215
TheTarget->createMCInstPrinter(*TheTriple, AsmPrinterVariant, *AsmInfo,
217216
*MII, *MRI));
218-
if (!InstructionPrinter) {
219-
errs() << "BOLT-ERROR: no instruction printer for target " << TripleName
220-
<< '\n';
221-
return nullptr;
222-
}
217+
if (!InstructionPrinter)
218+
return createStringError(
219+
make_error_code(std::errc::not_supported),
220+
Twine("BOLT-ERROR: no instruction printer for target ", TripleName));
223221
InstructionPrinter->setPrintImmHex(true);
224222

225223
std::unique_ptr<MCCodeEmitter> MCE(

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ void StackLayoutModifier::initialize() {
710710
IsInitialized = true;
711711
}
712712

713-
uint64_t ShrinkWrapping::SpillsMovedRegularMode = 0;
714-
uint64_t ShrinkWrapping::SpillsMovedPushPopMode = 0;
713+
std::atomic_uint64_t ShrinkWrapping::SpillsMovedRegularMode{0};
714+
std::atomic_uint64_t ShrinkWrapping::SpillsMovedPushPopMode{0};
715715

716716
using BBIterTy = BinaryBasicBlock::iterator;
717717

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/Support/CommandLine.h"
3131
#include "llvm/Support/Debug.h"
3232
#include "llvm/Support/Endian.h"
33+
#include "llvm/Support/Error.h"
3334
#include "llvm/Support/FileSystem.h"
3435
#include "llvm/Support/ThreadPool.h"
3536
#include "llvm/Support/ToolOutputFile.h"
@@ -863,11 +864,11 @@ namespace {
863864

864865
std::unique_ptr<BinaryContext>
865866
createDwarfOnlyBC(const object::ObjectFile &File) {
866-
return BinaryContext::createBinaryContext(
867+
return cantFail(BinaryContext::createBinaryContext(
867868
&File, false,
868869
DWARFContext::create(File, DWARFContext::ProcessDebugRelocations::Ignore,
869870
nullptr, "", WithColor::defaultErrorHandler,
870-
WithColor::defaultWarningHandler));
871+
WithColor::defaultWarningHandler)));
871872
}
872873

873874
StringMap<KnownSectionsEntry>
@@ -1363,47 +1364,6 @@ void getRangeAttrData(DWARFDie DIE, Optional<AttrInfo> &LowPCVal,
13631364

13641365
} // namespace
13651366

1366-
void DWARFRewriter::patchLowHigh(DWARFDie DIE, DebugAddressRange Range,
1367-
SimpleBinaryPatcher &DebugInfoPatcher,
1368-
Optional<uint64_t> DWOId) {
1369-
Optional<AttrInfo> LowPCVal = None;
1370-
Optional<AttrInfo> HighPCVal = None;
1371-
getRangeAttrData(DIE, LowPCVal, HighPCVal);
1372-
uint64_t LowPCOffset = LowPCVal->Offset;
1373-
uint64_t HighPCOffset = HighPCVal->Offset;
1374-
auto *TempDebugPatcher = &DebugInfoPatcher;
1375-
if (LowPCVal->V.getForm() == dwarf::DW_FORM_GNU_addr_index) {
1376-
uint32_t AddressIndex =
1377-
AddrWriter->getIndexFromAddress(Range.LowPC, *DWOId);
1378-
TempDebugPatcher = getBinaryDWODebugInfoPatcher(*DWOId);
1379-
TempDebugPatcher->addUDataPatch(LowPCOffset, AddressIndex, LowPCVal->Size);
1380-
// 2.17.2
1381-
// If the value of the DW_AT_high_pc is of class address, it is the
1382-
// relocated address of the first location past the last instruction
1383-
// associated with the entity; if it is of class constant, the value is
1384-
// an unsigned integer offset which when added to the low PC gives the
1385-
// address of the first location past the last instruction associated
1386-
// with the entity.
1387-
if (!HighPCVal->V.isFormClass(DWARFFormValue::FC_Constant)) {
1388-
AddressIndex = AddrWriter->getIndexFromAddress(Range.HighPC, *DWOId);
1389-
TempDebugPatcher->addUDataPatch(HighPCOffset, AddressIndex,
1390-
HighPCVal->Size);
1391-
}
1392-
} else {
1393-
TempDebugPatcher->addLE64Patch(LowPCOffset, Range.LowPC);
1394-
}
1395-
1396-
uint64_t HighPC = Range.HighPC;
1397-
// The DW_FORM_data* is delta between high and low pc
1398-
if (HighPCVal->V.getForm() != dwarf::Form::DW_FORM_addr)
1399-
HighPC -= Range.LowPC;
1400-
1401-
if (isHighPcFormEightBytes(HighPCVal->V.getForm()))
1402-
TempDebugPatcher->addLE64Patch(HighPCOffset, HighPC);
1403-
else
1404-
TempDebugPatcher->addLE32Patch(HighPCOffset, HighPC);
1405-
}
1406-
14071367
void DWARFRewriter::convertToRangesPatchAbbrev(
14081368
const DWARFUnit &Unit, const DWARFAbbreviationDeclaration *Abbrev,
14091369
DebugAbbrevWriter &AbbrevWriter, Optional<uint64_t> RangesBase) {

bolt/lib/Rewrite/MachORewriteInstance.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/Support/Errc.h"
2525
#include "llvm/Support/FileSystem.h"
2626
#include "llvm/Support/ToolOutputFile.h"
27+
#include <memory>
2728

2829
namespace opts {
2930

@@ -82,11 +83,28 @@ MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
8283

8384
#define DEBUG_TYPE "bolt"
8485

86+
Expected<std::unique_ptr<MachORewriteInstance>>
87+
MachORewriteInstance::createMachORewriteInstance(
88+
object::MachOObjectFile *InputFile, StringRef ToolPath) {
89+
Error Err = Error::success();
90+
auto MachORI =
91+
std::make_unique<MachORewriteInstance>(InputFile, ToolPath, Err);
92+
if (Err)
93+
return std::move(Err);
94+
return MachORI;
95+
}
96+
8597
MachORewriteInstance::MachORewriteInstance(object::MachOObjectFile *InputFile,
86-
StringRef ToolPath)
87-
: InputFile(InputFile), ToolPath(ToolPath),
88-
BC(BinaryContext::createBinaryContext(InputFile, /* IsPIC */ true,
89-
DWARFContext::create(*InputFile))) {
98+
StringRef ToolPath, Error &Err)
99+
: InputFile(InputFile), ToolPath(ToolPath) {
100+
ErrorAsOutParameter EAO(&Err);
101+
auto BCOrErr = BinaryContext::createBinaryContext(
102+
InputFile, /* IsPIC */ true, DWARFContext::create(*InputFile));
103+
if (Error E = BCOrErr.takeError()) {
104+
Err = std::move(E);
105+
return;
106+
}
107+
BC = std::move(BCOrErr.get());
90108
BC->initializeTarget(std::unique_ptr<MCPlusBuilder>(createMCPlusBuilder(
91109
BC->TheTriple->getArch(), BC->MIA.get(), BC->MII.get(), BC->MRI.get())));
92110
if (opts::Instrument)

0 commit comments

Comments
 (0)