Skip to content

Commit

Permalink
Merged main:9c5003cc0c70 into amd-gfx:606d2d42f73e
Browse files Browse the repository at this point in the history
Local branch amd-gfx 606d2d4 Merged main:81e3e7e5d455 into amd-gfx:207601c46e4e
Remote branch main 9c5003c [RISCV] Implement RISCVInstrInfo::getMemOperandsWithOffsetWidth (llvm#73681)
  • Loading branch information
SC llvm team authored and SC llvm team committed Nov 29, 2023
2 parents 606d2d4 + 9c5003c commit 4938c62
Show file tree
Hide file tree
Showing 39 changed files with 1,496 additions and 1,093 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/AttrDocs.td
Original file line number Diff line number Diff line change
Expand Up @@ -7073,7 +7073,7 @@ Parameters annotated with `in` or with no annotation are passed by value from
the caller to the callee.

Parameters annotated with `out` are written to the argument after the callee
returns (Note: arguments values passed into `out` parameters _are not_ copied
returns (Note: arguments values passed into `out` parameters *are not* copied
into the callee).

Parameters annotated with `inout` are copied into the callee via a temporary,
Expand Down
52 changes: 43 additions & 9 deletions clang/lib/CodeGen/CGCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,48 @@ static SmallString<32> buildSuspendPrefixStr(CGCoroData &Coro, AwaitKind Kind) {
return Prefix;
}

static bool memberCallExpressionCanThrow(const Expr *E) {
if (const auto *CE = dyn_cast<CXXMemberCallExpr>(E))
if (const auto *Proto =
CE->getMethodDecl()->getType()->getAs<FunctionProtoType>())
if (isNoexceptExceptionSpec(Proto->getExceptionSpecType()) &&
Proto->canThrow() == CT_Cannot)
return false;
return true;
// Check if function can throw based on prototype noexcept, also works for
// destructors which are implicitly noexcept but can be marked noexcept(false).
static bool FunctionCanThrow(const FunctionDecl *D) {
const auto *Proto = D->getType()->getAs<FunctionProtoType>();
if (!Proto) {
// Function proto is not found, we conservatively assume throwing.
return true;
}
return !isNoexceptExceptionSpec(Proto->getExceptionSpecType()) ||
Proto->canThrow() != CT_Cannot;
}

static bool ResumeStmtCanThrow(const Stmt *S) {
if (const auto *CE = dyn_cast<CallExpr>(S)) {
const auto *Callee = CE->getDirectCallee();
if (!Callee)
// We don't have direct callee. Conservatively assume throwing.
return true;

if (FunctionCanThrow(Callee))
return true;

// Fall through to visit the children.
}

if (const auto *TE = dyn_cast<CXXBindTemporaryExpr>(S)) {
// Special handling of CXXBindTemporaryExpr here as calling of Dtor of the
// temporary is not part of `children()` as covered in the fall through.
// We need to mark entire statement as throwing if the destructor of the
// temporary throws.
const auto *Dtor = TE->getTemporary()->getDestructor();
if (FunctionCanThrow(Dtor))
return true;

// Fall through to visit the children.
}

for (const auto *child : S->children())
if (ResumeStmtCanThrow(child))
return true;

return false;
}

// Emit suspend expression which roughly looks like:
Expand Down Expand Up @@ -233,7 +267,7 @@ static LValueOrRValue emitSuspendExpression(CodeGenFunction &CGF, CGCoroData &Co
// is marked as 'noexcept', we avoid generating this additional IR.
CXXTryStmt *TryStmt = nullptr;
if (Coro.ExceptionHandler && Kind == AwaitKind::Init &&
memberCallExpressionCanThrow(S.getResumeExpr())) {
ResumeStmtCanThrow(S.getResumeExpr())) {
Coro.ResumeEHVar =
CGF.CreateTempAlloca(Builder.getInt1Ty(), Prefix + Twine("resume.eh"));
Builder.CreateFlagStore(true, Coro.ResumeEHVar);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTReaderDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ void ASTDeclReader::ReadCXXDefinitionData(
break;
case LCK_ByCopy:
case LCK_ByRef:
auto *Var = readDeclAs<VarDecl>();
auto *Var = readDeclAs<ValueDecl>();
SourceLocation EllipsisLoc = readSourceLocation();
new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
ToCapture++;
Expand Down
66 changes: 64 additions & 2 deletions clang/test/CodeGenCoroutines/coro-init-await-nontrivial-return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ struct NontrivialType {
~NontrivialType() {}
};

struct NontrivialTypeWithThrowingDtor {
~NontrivialTypeWithThrowingDtor() noexcept(false) {}
};

namespace can_throw {
struct Task {
struct promise_type;
using handle_type = std::coroutine_handle<promise_type>;
Expand Down Expand Up @@ -38,9 +43,66 @@ Task coro_create() {
co_return;
}

// CHECK-LABEL: define{{.*}} ptr @_Z11coro_createv(
// CHECK-LABEL: define{{.*}} ptr @_ZN9can_throw11coro_createEv(
// CHECK: init.ready:
// CHECK-NEXT: store i1 true, ptr {{.*}}
// CHECK-NEXT: call void @_ZN4Task23initial_suspend_awaiter12await_resumeEv(
// CHECK-NEXT: call void @_ZN9can_throw4Task23initial_suspend_awaiter12await_resumeEv(
// CHECK-NEXT: call void @_ZN14NontrivialTypeD1Ev(
// CHECK-NEXT: store i1 false, ptr {{.*}}
}

template <typename R>
struct NoexceptResumeTask {
struct promise_type;
using handle_type = std::coroutine_handle<promise_type>;

struct initial_suspend_awaiter {
bool await_ready() {
return false;
}

void await_suspend(handle_type h) {}

R await_resume() noexcept { return {}; }
};

struct promise_type {
void return_void() {}
void unhandled_exception() {}
initial_suspend_awaiter initial_suspend() { return {}; }
std::suspend_never final_suspend() noexcept { return {}; }
NoexceptResumeTask get_return_object() {
return NoexceptResumeTask{handle_type::from_promise(*this)};
}
};

handle_type handler;
};

namespace no_throw {
using InitNoThrowTask = NoexceptResumeTask<NontrivialType>;

InitNoThrowTask coro_create() {
co_return;
}

// CHECK-LABEL: define{{.*}} ptr @_ZN8no_throw11coro_createEv(
// CHECK: init.ready:
// CHECK-NEXT: call void @_ZN18NoexceptResumeTaskI14NontrivialTypeE23initial_suspend_awaiter12await_resumeEv(
// CHECK-NEXT: call void @_ZN14NontrivialTypeD1Ev(
}

namespace throwing_dtor {
using InitTaskWithThrowingDtor = NoexceptResumeTask<NontrivialTypeWithThrowingDtor>;

InitTaskWithThrowingDtor coro_create() {
co_return;
}

// CHECK-LABEL: define{{.*}} ptr @_ZN13throwing_dtor11coro_createEv(
// CHECK: init.ready:
// CHECK-NEXT: store i1 true, ptr {{.*}}
// CHECK-NEXT: call void @_ZN18NoexceptResumeTaskI30NontrivialTypeWithThrowingDtorE23initial_suspend_awaiter12await_resumeEv(
// CHECK-NEXT: call void @_ZN30NontrivialTypeWithThrowingDtorD1Ev(
// CHECK-NEXT: store i1 false, ptr {{.*}}
}
24 changes: 24 additions & 0 deletions clang/test/Modules/pr72828.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Test that we can handle capturing structured bindings.
//
// RUN: rm -fr %t
// RUN: mkdir %t
//
// RUN: %clang_cc1 -std=c++23 -triple %itanium_abi_triple \
// RUN: %s -emit-module-interface -o %t/m.pcm
// RUN: %clang_cc1 -std=c++23 -triple %itanium_abi_triple \
// RUN: -S -emit-llvm -disable-llvm-passes %t/m.pcm \
// RUN: -o - | FileCheck %s

export module m;

struct s {
int m;
};

void f() {
auto [x] = s();
[x] {};
}

// Check that we can generate the LLVM IR expectedly.
// CHECK: define{{.*}}@_ZGIW1m
6 changes: 6 additions & 0 deletions compiler-rt/include/sanitizer/memprof_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const char *SANITIZER_CDECL __memprof_default_options(void);
/// \returns 0 on success.
int SANITIZER_CDECL __memprof_profile_dump(void);

/// Closes the existing file descriptor, if it is valid and not stdout or
/// stderr, and resets the internal state such that the profile filename is
/// reopened on the next profile dump attempt. This can be used to enable
/// multiple rounds of profiling on the same binary.
void SANITIZER_CDECL __memprof_profile_reset(void);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/lib/memprof/memprof_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,13 @@ int __memprof_profile_dump() {
// detected during the dumping process.
return 0;
}

void __memprof_profile_reset() {
if (report_file.fd != kInvalidFd && report_file.fd != kStdoutFd &&
report_file.fd != kStderrFd) {
CloseFile(report_file.fd);
// Setting the file descriptor to kInvalidFd ensures that we will reopen the
// file when invoking Write again.
report_file.fd = kInvalidFd;
}
}
1 change: 1 addition & 0 deletions compiler-rt/lib/memprof/memprof_interface_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern uptr __memprof_shadow_memory_dynamic_address;
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE extern char
__memprof_profile_filename[1];
SANITIZER_INTERFACE_ATTRIBUTE int __memprof_profile_dump();
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_profile_reset();

SANITIZER_INTERFACE_ATTRIBUTE void __memprof_load(uptr p);
SANITIZER_INTERFACE_ATTRIBUTE void __memprof_store(uptr p);
Expand Down
39 changes: 39 additions & 0 deletions compiler-rt/test/memprof/TestCases/profile_reset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Test to ensure that multiple rounds of dumping, using the
// __memprof_profile_reset interface to close the initial file
// and cause the profile to be reopened, works as expected.

// RUN: %clangxx_memprof %s -o %t

// RUN: rm -f %t.log.*
// RUN: %env_memprof_opts=print_text=true:log_path=%t.log %run %t

// Check both outputs, starting with the renamed initial dump, then remove it so
// that the second glob matches a single file.
// RUN: FileCheck %s < %t.log.*.sv
// RUN: rm -f %t.log.*.sv
// RUN: FileCheck %s < %t.log.*
// CHECK: Memory allocation stack id

#include <sanitizer/memprof_interface.h>
#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <string>
int main(int argc, char **argv) {
char *x = (char *)malloc(10);
memset(x, 0, 10);
free(x);
__memprof_profile_dump();
// Save the initial dump in a different file.
std::string origname = __sanitizer_get_report_path();
std::string svname = origname + ".sv";
rename(origname.c_str(), svname.c_str());
// This should cause the current file descriptor to be closed and the
// the internal state reset so that the profile filename is reopened
// on the next write.
__memprof_profile_reset();
// This will dump to origname again.
__memprof_profile_dump();
return 0;
}
10 changes: 3 additions & 7 deletions libc/cmake/modules/LLVMLibCFlagRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ endfunction(get_fq_dep_list_without_flag)
# Special flags
set(FMA_OPT_FLAG "FMA_OPT")
set(ROUND_OPT_FLAG "ROUND_OPT")
# SSE2 is the baseline for x86_64, so we add a negative flag to disable it if needed.
set(DISABLE_SSE2_OPT_FLAG "DISABLE_SSE2_OPT")
# This flag will define macros that gated away vectorization code such that
# one can always test the fallback generic code path.
set(PREFER_GENERIC_FLAG "PREFER_GENERIC")

# Skip FMA_OPT flag for targets that don't support fma.
if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
Expand All @@ -145,8 +146,3 @@ endif()
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")))
set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)
endif()

# Skip DISABLE_SSE2_OPT flag for targets that don't support SSE2.
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
set(SKIP_FLAG_EXPANSION_DISABLE_SSE2_OPT TRUE)
endif()
18 changes: 9 additions & 9 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function(_get_common_compile_options output_var flags)
set(ADD_SSE4_2_FLAG TRUE)
endif()

list(FIND flags ${DISABLE_SSE2_OPT_FLAG} no_sse2)
if(${no_sse2} LESS 0)
list(FIND flags "${DISABLE_SSE2_OPT_FLAG}__ONLY" no_sse2)
list(FIND flags ${PREFER_GENERIC_FLAG} prefer_generic)
if(${prefer_generic} LESS 0)
list(FIND flags "${PREFER_GENERIC_FLAG}__ONLY" prefer_generic)
endif()
if((${no_sse2} GREATER -1) AND (LIBC_CPU_FEATURES MATCHES "SSE2"))
set(DISABLE_SSE2_FLAG TRUE)
if(${prefer_generic} GREATER -1)
set(ADD_PREFER_GENERIC_FLAG TRUE)
endif()

set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN})
Expand Down Expand Up @@ -66,17 +66,17 @@ function(_get_common_compile_options output_var flags)
if(ADD_SSE4_2_FLAG)
list(APPEND compile_options "-msse4.2")
endif()
if(DISABLE_SSE2_FLAG)
list(APPEND compile_options "-mno-sse2")
if(ADD_PREFER_GENERIC_FLAG)
list(APPEND compile_options "-D__LIBC_PREFER_GENERIC")
endif()
elseif(MSVC)
list(APPEND compile_options "/EHs-c-")
list(APPEND compile_options "/GR-")
if(ADD_FMA_FLAG)
list(APPEND compile_options "/arch:AVX2")
endif()
if(DISABLE_SSE2_FLAG)
list(APPEND compile_options "/arch:SSE")
if(ADD_PREFER_GENERIC_FLAG)
list(APPEND compile_options "/D__LIBC_PREFER_GENERIC")
endif()
endif()
if (LIBC_TARGET_ARCHITECTURE_IS_GPU)
Expand Down
16 changes: 8 additions & 8 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ set(TARGET_LIBC_ENTRYPOINTS
#libc.src.stdio.scanf
#libc.src.stdio.fscanf

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r

# sys/mman.h entrypoints
libc.src.sys.mman.madvise
libc.src.sys.mman.mmap
Expand Down Expand Up @@ -459,6 +451,14 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.signal.sigfillset
libc.src.signal.signal

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r

# threads.h entrypoints
libc.src.threads.call_once
libc.src.threads.cnd_broadcast
Expand Down
10 changes: 1 addition & 9 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.strtoll
libc.src.stdlib.strtoul
libc.src.stdlib.strtoull

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r


# sys/mman.h entrypoints
libc.src.sys.mman.mmap
libc.src.sys.mman.munmap
Expand Down
Loading

0 comments on commit 4938c62

Please sign in to comment.