Skip to content

Commit 182209f

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:d9111f19d2ea into amd-gfx:00799b092b24
Local branch amd-gfx 00799b0 Merged main:c7d237085bf9 into amd-gfx:4b28d14fac77 Remote branch main d9111f1 [mlir][bufferization]-Refactor findValueInReverseUseDefChain to accept opOperand (llvm#121304)
2 parents 00799b0 + d9111f1 commit 182209f

File tree

24 files changed

+1005
-554
lines changed

24 files changed

+1005
-554
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,14 @@ INTERCEPTOR(int, strncmp, const char *s1, const char *s2, usize size) {
520520
void *ctx;
521521
COMMON_INTERCEPTOR_ENTER(ctx, strncmp, s1, s2, size);
522522
unsigned char c1 = 0, c2 = 0;
523-
uptr i;
523+
usize i;
524524
for (i = 0; i < size; i++) {
525525
c1 = (unsigned char)s1[i];
526526
c2 = (unsigned char)s2[i];
527527
if (c1 != c2 || c1 == '\0') break;
528528
}
529-
uptr i1 = i;
530-
uptr i2 = i;
529+
usize i1 = i;
530+
usize i2 = i;
531531
if (common_flags()->strict_string_checks) {
532532
for (; i1 < size && s1[i1]; i1++) {}
533533
for (; i2 < size && s2[i2]; i2++) {}
@@ -583,14 +583,14 @@ INTERCEPTOR(int, strncasecmp, const char *s1, const char *s2, SIZE_T size) {
583583
void *ctx;
584584
COMMON_INTERCEPTOR_ENTER(ctx, strncasecmp, s1, s2, size);
585585
unsigned char c1 = 0, c2 = 0;
586-
uptr i;
586+
usize i;
587587
for (i = 0; i < size; i++) {
588588
c1 = (unsigned char)s1[i];
589589
c2 = (unsigned char)s2[i];
590590
if (CharCaseCmp(c1, c2) != 0 || c1 == '\0') break;
591591
}
592-
uptr i1 = i;
593-
uptr i2 = i;
592+
usize i1 = i;
593+
usize i2 = i;
594594
if (common_flags()->strict_string_checks) {
595595
for (; i1 < size && s1[i1]; i1++) {}
596596
for (; i2 < size && s2[i2]; i2++) {}
@@ -851,7 +851,7 @@ int MemcmpInterceptorCommon(void *ctx,
851851
unsigned char c1 = 0, c2 = 0;
852852
const unsigned char *s1 = (const unsigned char*)a1;
853853
const unsigned char *s2 = (const unsigned char*)a2;
854-
uptr i;
854+
usize i;
855855
for (i = 0; i < size; i++) {
856856
c1 = s1[i];
857857
c2 = s2[i];

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
5858
// First set the offset on the file, and on the bytes saved
5959
m_saved_data_size = HEADER_SIZE;
6060
// We know we will have at least Misc, SystemInfo, Modules, and ThreadList
61-
// (corresponding memory list for stacks) And an additional memory list for
62-
// non-stacks.
61+
// (corresponding memory list for stacks), an additional memory list for
62+
// non-stacks, and a stream to mark this minidump was generated by LLDB.
6363
lldb_private::Target &target = m_process_sp->GetTarget();
6464
m_expected_directories = 6;
6565
// Check if OS is linux and reserve directory space for all linux specific
@@ -90,7 +90,10 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
9090
"sections. Written / Expected (%" PRIx64 " / %" PRIx64 ")",
9191
new_offset, m_saved_data_size);
9292

93-
return error;
93+
if (error.Fail())
94+
return error;
95+
96+
return AddLLDBGeneratedStream();
9497
}
9598

9699
Status MinidumpFileBuilder::AddDirectory(StreamType type,
@@ -126,6 +129,12 @@ Status MinidumpFileBuilder::AddDirectory(StreamType type,
126129
return error;
127130
}
128131

132+
Status MinidumpFileBuilder::AddLLDBGeneratedStream() {
133+
Status error;
134+
StreamType type = StreamType::LLDBGenerated;
135+
return AddDirectory(type, 0);
136+
}
137+
129138
Status MinidumpFileBuilder::AddSystemInfo() {
130139
Status error;
131140
const llvm::Triple &target_triple =

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class MinidumpFileBuilder {
120120
void DeleteFile() noexcept;
121121

122122
private:
123+
lldb_private::Status AddLLDBGeneratedStream();
123124
// Add data to the end of the buffer, if the buffer exceeds the flush level,
124125
// trigger a flush.
125126
lldb_private::Status AddData(const void *data, uint64_t size);

lldb/source/Plugins/Process/minidump/MinidumpParser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ llvm::ArrayRef<uint8_t> MinidumpParser::GetStream(StreamType stream_type) {
4949
return m_file->getRawStream(stream_type).value_or(llvm::ArrayRef<uint8_t>());
5050
}
5151

52+
std::optional<llvm::ArrayRef<uint8_t>>
53+
MinidumpParser::GetRawStream(StreamType stream_type) {
54+
return m_file->getRawStream(stream_type);
55+
}
56+
5257
UUID MinidumpParser::GetModuleUUID(const minidump::Module *module) {
5358
auto cv_record =
5459
GetData().slice(module->CvRecord.RVA, module->CvRecord.DataSize);
@@ -651,6 +656,7 @@ MinidumpParser::GetStreamTypeAsString(StreamType stream_type) {
651656
ENUM_TO_CSTR(FacebookAbortReason);
652657
ENUM_TO_CSTR(FacebookThreadName);
653658
ENUM_TO_CSTR(FacebookLogcat);
659+
ENUM_TO_CSTR(LLDBGenerated);
654660
}
655661
return "unknown stream type";
656662
}

lldb/source/Plugins/Process/minidump/MinidumpParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class MinidumpParser {
5959
llvm::ArrayRef<uint8_t> GetData();
6060

6161
llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
62+
std::optional<llvm::ArrayRef<uint8_t>> GetRawStream(StreamType stream_type);
6263

6364
UUID GetModuleUUID(const minidump::Module *module);
6465

lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,22 @@ DataExtractor ProcessMinidump::GetAuxvData() {
354354
GetAddressByteSize(), GetAddressByteSize());
355355
}
356356

357+
bool ProcessMinidump::IsLLDBMinidump() {
358+
std::optional<llvm::ArrayRef<uint8_t>> lldb_generated_section =
359+
m_minidump_parser->GetRawStream(StreamType::LLDBGenerated);
360+
return lldb_generated_section.has_value();
361+
}
362+
363+
DynamicLoader *ProcessMinidump::GetDynamicLoader() {
364+
// This is a workaround for the dynamic loader not playing nice in issue
365+
// #119598. The specific reason we use the dynamic loader is to get the TLS
366+
// info sections, which we can assume are not being written to the minidump
367+
// unless it's an LLDB generate minidump.
368+
if (IsLLDBMinidump())
369+
return PostMortemProcess::GetDynamicLoader();
370+
return nullptr;
371+
}
372+
357373
void ProcessMinidump::BuildMemoryRegions() {
358374
if (m_memory_regions)
359375
return;

lldb/source/Plugins/Process/minidump/ProcessMinidump.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class ProcessMinidump : public PostMortemProcess {
5353

5454
Status DoLoadCore() override;
5555

56+
DynamicLoader *GetDynamicLoader() override;
57+
5658
// Returns AUXV structure found in the core file
5759
lldb_private::DataExtractor GetAuxvData() override;
5860

@@ -74,8 +76,8 @@ class ProcessMinidump : public PostMortemProcess {
7476

7577
ArchSpec GetArchitecture();
7678

77-
Status GetMemoryRegions(
78-
lldb_private::MemoryRegionInfos &region_list) override;
79+
Status
80+
GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override;
7981

8082
bool GetProcessInfo(ProcessInstanceInfo &info) override;
8183

@@ -113,6 +115,7 @@ class ProcessMinidump : public PostMortemProcess {
113115
std::optional<MemoryRegionInfos> m_memory_regions;
114116

115117
void BuildMemoryRegions();
118+
bool IsLLDBMinidump();
116119
};
117120

118121
} // namespace minidump

llvm/include/llvm/BinaryFormat/MinidumpConstants.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ HANDLE_MDMP_STREAM_TYPE(0xFACECCCC, FacebookAppStateLog)
8585
HANDLE_MDMP_STREAM_TYPE(0xFACEDEAD, FacebookAbortReason)
8686
HANDLE_MDMP_STREAM_TYPE(0xFACEE000, FacebookThreadName)
8787

88+
// LLDB specific stream types
89+
// Ascii for 'LLDB'
90+
HANDLE_MDMP_STREAM_TYPE(0x4C4C4442, LLDBGenerated)
91+
8892
HANDLE_MDMP_ARCH(0x0000, X86) // PROCESSOR_ARCHITECTURE_INTEL
8993
HANDLE_MDMP_ARCH(0x0001, MIPS) // PROCESSOR_ARCHITECTURE_MIPS
9094
HANDLE_MDMP_ARCH(0x0002, Alpha) // PROCESSOR_ARCHITECTURE_ALPHA

llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,36 @@ inline bind_ty<LLT> m_Type(LLT &Ty) { return Ty; }
372372
inline bind_ty<CmpInst::Predicate> m_Pred(CmpInst::Predicate &P) { return P; }
373373
inline operand_type_match m_Pred() { return operand_type_match(); }
374374

375+
template <typename BindTy> struct deferred_helper {
376+
static bool match(const MachineRegisterInfo &MRI, BindTy &VR, BindTy &V) {
377+
return VR == V;
378+
}
379+
};
380+
381+
template <> struct deferred_helper<LLT> {
382+
static bool match(const MachineRegisterInfo &MRI, LLT VT, Register R) {
383+
return VT == MRI.getType(R);
384+
}
385+
};
386+
387+
template <typename Class> struct deferred_ty {
388+
Class &VR;
389+
390+
deferred_ty(Class &V) : VR(V) {}
391+
392+
template <typename ITy> bool match(const MachineRegisterInfo &MRI, ITy &&V) {
393+
return deferred_helper<Class>::match(MRI, VR, V);
394+
}
395+
};
396+
397+
/// Similar to m_SpecificReg/Type, but the specific value to match originated
398+
/// from an earlier sub-pattern in the same mi_match expression. For example,
399+
/// we cannot match `(add X, X)` with `m_GAdd(m_Reg(X), m_SpecificReg(X))`
400+
/// because `X` is not initialized at the time it's passed to `m_SpecificReg`.
401+
/// Instead, we can use `m_GAdd(m_Reg(x), m_DeferredReg(X))`.
402+
inline deferred_ty<Register> m_DeferredReg(Register &R) { return R; }
403+
inline deferred_ty<LLT> m_DeferredType(LLT &Ty) { return Ty; }
404+
375405
struct ImplicitDefMatch {
376406
bool match(const MachineRegisterInfo &MRI, Register Reg) {
377407
MachineInstr *TmpMI;
@@ -401,8 +431,13 @@ struct BinaryOp_match {
401431
if (TmpMI->getOpcode() == Opcode && TmpMI->getNumOperands() == 3) {
402432
return (L.match(MRI, TmpMI->getOperand(1).getReg()) &&
403433
R.match(MRI, TmpMI->getOperand(2).getReg())) ||
404-
(Commutable && (R.match(MRI, TmpMI->getOperand(1).getReg()) &&
405-
L.match(MRI, TmpMI->getOperand(2).getReg())));
434+
// NOTE: When trying the alternative operand ordering
435+
// with a commutative operation, it is imperative to always run
436+
// the LHS sub-pattern (i.e. `L`) before the RHS sub-pattern
437+
// (i.e. `R`). Otherwsie, m_DeferredReg/Type will not work as
438+
// expected.
439+
(Commutable && (L.match(MRI, TmpMI->getOperand(2).getReg()) &&
440+
R.match(MRI, TmpMI->getOperand(1).getReg())));
406441
}
407442
}
408443
return false;
@@ -426,8 +461,13 @@ struct BinaryOpc_match {
426461
TmpMI->getNumOperands() == 3) {
427462
return (L.match(MRI, TmpMI->getOperand(1).getReg()) &&
428463
R.match(MRI, TmpMI->getOperand(2).getReg())) ||
429-
(Commutable && (R.match(MRI, TmpMI->getOperand(1).getReg()) &&
430-
L.match(MRI, TmpMI->getOperand(2).getReg())));
464+
// NOTE: When trying the alternative operand ordering
465+
// with a commutative operation, it is imperative to always run
466+
// the LHS sub-pattern (i.e. `L`) before the RHS sub-pattern
467+
// (i.e. `R`). Otherwsie, m_DeferredReg/Type will not work as
468+
// expected.
469+
(Commutable && (L.match(MRI, TmpMI->getOperand(2).getReg()) &&
470+
R.match(MRI, TmpMI->getOperand(1).getReg())));
431471
}
432472
}
433473
return false;
@@ -674,6 +714,10 @@ struct CompareOp_match {
674714
Register RHS = TmpMI->getOperand(3).getReg();
675715
if (L.match(MRI, LHS) && R.match(MRI, RHS))
676716
return true;
717+
// NOTE: When trying the alternative operand ordering
718+
// with a commutative operation, it is imperative to always run
719+
// the LHS sub-pattern (i.e. `L`) before the RHS sub-pattern
720+
// (i.e. `R`). Otherwsie, m_DeferredReg/Type will not work as expected.
677721
if (Commutable && L.match(MRI, RHS) && R.match(MRI, LHS) &&
678722
P.match(MRI, CmpInst::getSwappedPredicate(TmpPred)))
679723
return true;

llvm/include/llvm/Config/llvm-config.h.cmake

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

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 522511
19+
#define LLVM_MAIN_REVISION 522518
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

0 commit comments

Comments
 (0)