Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: I253d0ab91c9bc14c39fb246487b508feff28bc14
  • Loading branch information
Jenkins authored and ronlieb committed Oct 5, 2024
2 parents eb1a4a6 + 91fdfec commit f102fb0
Show file tree
Hide file tree
Showing 22 changed files with 305 additions and 38 deletions.
21 changes: 18 additions & 3 deletions compiler-rt/lib/lsan/lsan_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ static void ReportUnsuspendedThreads(const SuspendedThreadsList &) {}

# else // !SANITIZER_FUCHSIA

static void ReportUnsuspendedThreads(
static bool ReportUnsuspendedThreads(
const SuspendedThreadsList &suspended_threads) {
InternalMmapVector<tid_t> threads(suspended_threads.ThreadCount());
for (uptr i = 0; i < suspended_threads.ThreadCount(); ++i)
Expand All @@ -713,13 +713,17 @@ static void ReportUnsuspendedThreads(
InternalMmapVector<tid_t> unsuspended;
GetRunningThreadsLocked(&unsuspended);

bool succeded = true;
for (auto os_id : unsuspended) {
uptr i = InternalLowerBound(threads, os_id);
if (i >= threads.size() || threads[i] != os_id)
if (i >= threads.size() || threads[i] != os_id) {
succeded = false;
Report(
"Running thread %zu was not suspended. False leaks are possible.\n",
os_id);
}
}
return succeded;
}

# endif // !SANITIZER_FUCHSIA
Expand All @@ -729,7 +733,18 @@ static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads,
CheckForLeaksParam *param = reinterpret_cast<CheckForLeaksParam *>(arg);
CHECK(param);
CHECK(!param->success);
ReportUnsuspendedThreads(suspended_threads);
if (!ReportUnsuspendedThreads(suspended_threads)) {
switch (flags()->thread_suspend_fail) {
case 0:
param->success = true;
return;
case 1:
break;
case 2:
// Will crash on return.
return;
}
}
ClassifyAllChunks(suspended_threads, &param->frontier, param->caller_tid,
param->caller_sp);
ForEachChunk(CollectLeaksCb, &param->leaks);
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/lsan/lsan_flags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ LSAN_FLAG(bool, use_poisoned, false,
LSAN_FLAG(bool, log_pointers, false, "Debug logging")
LSAN_FLAG(bool, log_threads, false, "Debug logging")
LSAN_FLAG(const char *, suppressions, "", "Suppressions file name.")
LSAN_FLAG(int, thread_suspend_fail, 1,
"Behaviour if thread suspendion all thread (0 - "
"abandon leak checking, 1 - continue with leak checking (reported "
"leaks can be false), 2 - crash (for debugging LSAN)).")
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ bool ThreadSuspender::SuspendAllThreads() {
switch (thread_lister.ListThreads(&threads)) {
case ThreadLister::Error:
ResumeAllThreads();
Report("Failed to list threads\n");
return false;
case ThreadLister::Incomplete:
retry = true;
Expand All @@ -228,6 +229,8 @@ bool ThreadSuspender::SuspendAllThreads() {
if (SuspendThread(tid))
retry = true;
}
if (retry)
VReport(1, "SuspendAllThreads retry: %d\n", i);
}
return suspended_threads_list_.ThreadCount();
}
Expand Down
10 changes: 10 additions & 0 deletions lld/MachO/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,16 @@ void SymtabSection::emitStabs() {
if (defined->isAbsolute())
continue;

// Never generate a STABS entry for a symbol that has been ICF'ed using a
// thunk, just as we do for fully ICF'ed functions. Otherwise, we end up
// generating invalid DWARF as dsymutil will assume the entire function
// body is at that location, when, in reality, only the thunk is
// present. This will end up causing overlapping DWARF entries.
// TODO: Find an implementation that works in combination with
// `--keep-icf-stabs`.
if (defined->identicalCodeFoldingKind == Symbol::ICFFoldKind::Thunk)
continue;

// Constant-folded symbols go in the executable's symbol table, but don't
// get a stabs entry unless --keep-icf-stabs flag is specified
if (!config->keepICFStabs &&
Expand Down
115 changes: 115 additions & 0 deletions lld/test/MachO/icf-safe-thunks-dwarf.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
; REQUIRES: aarch64

;;; Build the
; RUN: rm -rf %t; mkdir %t
; RUN: llc -filetype=obj %s -O3 -o %t/icf-obj-safe-thunks-dwarf.o -enable-machine-outliner=never -mtriple arm64-apple-macos -addrsig
; RUN: %lld -arch arm64 -lSystem --icf=safe_thunks -dylib -o %t/icf-safe-dwarf.dylib %t/icf-obj-safe-thunks-dwarf.o

;;; Check that we generate valid dSYM
; RUN: dsymutil %t/icf-safe-dwarf.dylib -o %t/icf-safe.dSYM
; RUN: llvm-dwarfdump --verify %t/icf-safe.dSYM | FileCheck %s --check-prefix=VERIFY-DSYM
; VERIFY-DSYM: No errors.

;;; Check that we don't generate STABS entries (N_FUN) for ICF'ed function thunks
; RUN: dsymutil -s %t/icf-safe-dwarf.dylib | FileCheck %s --check-prefix=VERIFY-STABS
; VERIFY-STABS-NOT: N_FUN{{.*}}_func_B
; VERIFY-STABS-NOT: N_FUN{{.*}}_func_C

;;; Check that we do generate STABS entries (N_FUN) for non-ICF'ed functions
; VERIFY-STABS: N_FUN{{.*}}_func_A
; VERIFY-STABS: N_FUN{{.*}}_take_func_addr


; ModuleID = 'icf-safe-thunks-dwarf.cpp'
source_filename = "icf-safe-thunks-dwarf.cpp"
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "arm64-apple-macosx11.0.0"

; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
define i32 @func_A() #0 !dbg !13 {
entry:
ret i32 1
}

; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
define i32 @func_B() #0 !dbg !18 {
entry:
ret i32 1
}

; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
define i32 @func_C() #0 !dbg !20 {
entry:
ret i32 1
}

; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
define i64 @take_func_addr() #0 !dbg !22 {
entry:
%val = alloca i64, align 8
store i64 0, ptr %val, align 8
%0 = load i64, ptr %val, align 8
%add = add i64 %0, ptrtoint (ptr @func_A to i64)
store i64 %add, ptr %val, align 8
%1 = load i64, ptr %val, align 8
%add1 = add i64 %1, ptrtoint (ptr @func_B to i64)
store i64 %add1, ptr %val, align 8
%2 = load i64, ptr %val, align 8
%add2 = add i64 %2, ptrtoint (ptr @func_C to i64)
store i64 %add2, ptr %val, align 8
%3 = load i64, ptr %val, align 8
ret i64 %3
}

attributes #0 = { noinline nounwind }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!6, !7, !8, !9, !10, !11}
!llvm.ident = !{!12}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
!1 = !DIFile(filename: "icf-safe-thunks-dwarf.cpp", directory: "/tmp/test")
!6 = !{i32 7, !"Dwarf Version", i32 4}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{i32 1, !"wchar_size", i32 4}
!9 = !{i32 8, !"PIC Level", i32 2}
!10 = !{i32 7, !"uwtable", i32 1}
!11 = !{i32 7, !"frame-pointer", i32 1}
!12 = !{!"clang version 20.0.0"}
!13 = distinct !DISubprogram(name: "func_A", scope: !1, file: !1, line: 4, type: !14, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!14 = !DISubroutineType(types: !15)
!15 = !{}
!18 = distinct !DISubprogram(name: "func_B", scope: !1, file: !1, line: 5, type: !14, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!20 = distinct !DISubprogram(name: "func_C", scope: !1, file: !1, line: 6, type: !14, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
!22 = distinct !DISubprogram(name: "take_func_addr", scope: !1, file: !1, line: 8, type: !14, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;; Generate the above LLVM IR with the below script ;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; #!/bin/bash
; set -ex
; TOOLCHAIN_BIN="llvm-project/build/Debug/bin"
;
; # Create icf-safe-thunks-dwarf.cpp file
; cat > icf-safe-thunks-dwarf.cpp <<EOF
; #define ATTR __attribute__((noinline)) extern "C"
; typedef unsigned long long ULL;
;
; ATTR int func_A() { return 1; }
; ATTR int func_B() { return 1; }
; ATTR int func_C() { return 1; }
;
; ATTR ULL take_func_addr() {
; ULL val = 0;
; val += (ULL)(void*)func_A;
; val += (ULL)(void*)func_B;
; val += (ULL)(void*)func_C;
; return val;
; }
; EOF
;
; $TOOLCHAIN_BIN/clang -target arm64-apple-macos11.0 -S -emit-llvm -g \
; icf-safe-thunks-dwarf.cpp
4 changes: 3 additions & 1 deletion lldb/source/Commands/CommandObjectSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class CommandObjectSessionSave : public CommandObjectParsed {
: CommandObjectParsed(interpreter, "session save",
"Save the current session transcripts to a file.\n"
"If no file if specified, transcripts will be "
"saved to a temporary file.",
"saved to a temporary file.\n"
"Note: transcripts will only be saved if "
"interpreter.save-transcript is true.\n",
"session save [file]") {
AddSimpleArgumentList(eArgTypePath, eArgRepeatOptional);
}
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3308,6 +3308,10 @@ bool CommandInterpreter::SaveTranscript(
result.SetStatus(eReturnStatusSuccessFinishNoResult);
result.AppendMessageWithFormat("Session's transcripts saved to %s\n",
output_file->c_str());
if (!GetSaveTranscript())
result.AppendError(
"Note: the setting interpreter.save-transcript is set to false, so the "
"transcript might not have been recorded.");

if (GetOpenTranscriptInEditor() && Host::IsInteractiveGraphicSession()) {
const FileSpec file_spec;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Interpreter/InterpreterProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let Definition = "interpreter" in {
def SaveSessionOnQuit: Property<"save-session-on-quit", "Boolean">,
Global,
DefaultFalse,
Desc<"If true, LLDB will save the session's transcripts before quitting.">;
Desc<"If true, LLDB will save the session's transcripts before quitting. Note: transcripts will only be saved if interpreter.save-transcript is true.">;
def OpenTranscriptInEditor: Property<"open-transcript-in-editor", "Boolean">,
Global,
DefaultTrue,
Expand Down
32 changes: 32 additions & 0 deletions lldb/test/API/commands/session/save/TestSessionSave.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def test_session_save(self):
interpreter.HandleCommand("session save", res)
self.assertTrue(res.Succeeded())
raw += self.raw_transcript_builder(cmd, res)
# Also check that we don't print an error message about an empty transcript.
self.assertNotIn("interpreter.save-transcript is set to false", res.GetError())

with open(os.path.join(td.name, os.listdir(td.name)[0]), "r") as file:
content = file.read()
Expand All @@ -93,6 +95,36 @@ def test_session_save(self):
for line in lines:
self.assertIn(line, content)

@no_debug_info_test
def test_session_save_no_transcript_warning(self):
interpreter = self.dbg.GetCommandInterpreter()

self.runCmd("settings set interpreter.save-transcript false")

# These commands won't be saved, so are arbitrary.
commands = [
"p 1",
"settings set interpreter.save-session-on-quit true",
"fr v",
"settings set interpreter.echo-comment-commands true",
]

for command in commands:
res = lldb.SBCommandReturnObject()
interpreter.HandleCommand(command, res)

output_file = self.getBuildArtifact("my-session")

res = lldb.SBCommandReturnObject()
interpreter.HandleCommand("session save " + output_file, res)
self.assertTrue(res.Succeeded())
# We should warn about the setting being false.
self.assertIn("interpreter.save-transcript is set to false", res.GetError())
self.assertTrue(
os.path.getsize(output_file) == 0,
"Output file should be empty since we didn't save the transcript.",
)

@no_debug_info_test
def test_session_save_on_quit(self):
raw = ""
Expand Down
47 changes: 47 additions & 0 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,49 @@ RISCVTTIImpl::getConstantPoolLoadCost(Type *Ty, TTI::TargetCostKind CostKind) {
/*AddressSpace=*/0, CostKind);
}

InstructionCost
RISCVTTIImpl::isMultipleInsertSubvector(VectorType *Tp, ArrayRef<int> Mask,
TTI::TargetCostKind CostKind) {
if (!isa<FixedVectorType>(Tp))
return InstructionCost::getInvalid();
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Tp);
if (LT.second.getScalarSizeInBits() == 1)
return InstructionCost::getInvalid();
// Try to guess SubTp.
for (unsigned SubVecSize = 1, E = Mask.size(); SubVecSize < E;
SubVecSize <<= 1) {
if (E % SubVecSize != 0)
continue;
SmallVector<int> RepeatedPattern(createSequentialMask(0, SubVecSize, 0));
bool Skip = false;
for (unsigned I = 0; I != E; I += SubVecSize)
if (!Mask.slice(I, SubVecSize).equals(RepeatedPattern)) {
Skip = true;
break;
}
if (Skip)
continue;
InstructionCost Cost = 0;
unsigned NumSlides = Log2_32(E / SubVecSize);
// The cost of extraction from a subvector is 0 if the index is 0.
for (unsigned I = 0; I != NumSlides; ++I) {
unsigned InsertIndex = SubVecSize * (1 << I);
FixedVectorType *SubTp = FixedVectorType::get(
cast<FixedVectorType>(Tp)->getElementType(), InsertIndex);
FixedVectorType *DesTp =
FixedVectorType::getDoubleElementsVectorType(SubTp);
std::pair<InstructionCost, MVT> DesLT = getTypeLegalizationCost(DesTp);
// Add the cost of whole vector register move because the destination
// vector register group for vslideup cannot overlap the source.
Cost += DesLT.first * TLI->getLMULCost(DesLT.second);
Cost += getShuffleCost(TTI::SK_InsertSubvector, DesTp, {}, CostKind,
InsertIndex, SubTp);
}
return Cost;
}
return InstructionCost::getInvalid();
}

static VectorType *getVRGatherIndexType(MVT DataVT, const RISCVSubtarget &ST,
LLVMContext &C) {
assert((DataVT.getScalarSizeInBits() != 8 ||
Expand Down Expand Up @@ -394,6 +437,10 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
LT.second, CostKind);
}
}
if (InstructionCost Cost =
isMultipleInsertSubvector(Tp, Mask, CostKind);
Cost.isValid())
return Cost;
}
// vrgather + cost of generating the mask constant.
// We model this for an unknown mask with a single vrgather.
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
/// type.
InstructionCost getConstantPoolLoadCost(Type *Ty,
TTI::TargetCostKind CostKind);

/// Return the cost if a shufflevector can be consist of multiple vslideup.
/// Otherwise, return InstructionCost::getInvalid().
InstructionCost isMultipleInsertSubvector(VectorType *Tp, ArrayRef<int> Mask,
TTI::TargetCostKind CostKind);

public:
explicit RISCVTTIImpl(const RISCVTargetMachine *TM, const Function &F)
: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
Expand Down
26 changes: 22 additions & 4 deletions llvm/lib/TargetParser/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,8 @@ struct RISCVHwProbe {
};
const StringMap<bool> sys::getHostCPUFeatures() {
RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_BASE_BEHAVIOR=*/3, 0},
{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0},
{/*RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF=*/9, 0}};
int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/Query,
/*pair_count=*/std::size(Query), /*cpu_count=*/0,
/*cpus=*/0, /*flags=*/0);
Expand Down Expand Up @@ -2047,9 +2048,26 @@ const StringMap<bool> sys::getHostCPUFeatures() {
Features["zicond"] = ExtMask & (1ULL << 35); // RISCV_HWPROBE_EXT_ZICOND
Features["zihintpause"] =
ExtMask & (1ULL << 36); // RISCV_HWPROBE_EXT_ZIHINTPAUSE

// TODO: set unaligned-scalar-mem if RISCV_HWPROBE_KEY_MISALIGNED_PERF returns
// RISCV_HWPROBE_MISALIGNED_FAST.
Features["zve32x"] = ExtMask & (1ULL << 37); // RISCV_HWPROBE_EXT_ZVE32X
Features["zve32f"] = ExtMask & (1ULL << 38); // RISCV_HWPROBE_EXT_ZVE32F
Features["zve64x"] = ExtMask & (1ULL << 39); // RISCV_HWPROBE_EXT_ZVE64X
Features["zve64f"] = ExtMask & (1ULL << 40); // RISCV_HWPROBE_EXT_ZVE64F
Features["zve64d"] = ExtMask & (1ULL << 41); // RISCV_HWPROBE_EXT_ZVE64D
Features["zimop"] = ExtMask & (1ULL << 42); // RISCV_HWPROBE_EXT_ZIMOP
Features["zca"] = ExtMask & (1ULL << 43); // RISCV_HWPROBE_EXT_ZCA
Features["zcb"] = ExtMask & (1ULL << 44); // RISCV_HWPROBE_EXT_ZCB
Features["zcd"] = ExtMask & (1ULL << 45); // RISCV_HWPROBE_EXT_ZCD
Features["zcf"] = ExtMask & (1ULL << 46); // RISCV_HWPROBE_EXT_ZCF
Features["zcmop"] = ExtMask & (1ULL << 47); // RISCV_HWPROBE_EXT_ZCMOP
Features["zawrs"] = ExtMask & (1ULL << 48); // RISCV_HWPROBE_EXT_ZAWRS

// Check whether the processor supports fast misaligned scalar memory access.
// NOTE: RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF is only available on
// Linux 6.11 or later. If it is not recognized, the key field will be cleared
// to -1.
if (Query[2].Key != -1 &&
Query[2].Value == /*RISCV_HWPROBE_MISALIGNED_SCALAR_FAST=*/3)
Features["unaligned-scalar-mem"] = true;

return Features;
}
Expand Down
Loading

0 comments on commit f102fb0

Please sign in to comment.