Skip to content

Commit

Permalink
Determine if we are using ACC and apply the corresponding flags
Browse files Browse the repository at this point in the history
This commit should be noop for all non-ACC users.
  • Loading branch information
ChuanqiXu9 committed Sep 18, 2023
1 parent 215ca4e commit 1527007
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ else()
)
endif()

set(IS_ACC OFF CACHE INTERNAL "Whether the current compiler is ACC")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
try_compile(IS_ACC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/cmake/IsACC.cpp)
if (${IS_ACC})
message("-- Using ACC")
# It is super rare that the destructor of an exception can be throwable.
# But such little probability prevents optimizations for coroutines
# significantly.
# Since the the body of coroutines are wrapped into a big try-catch.
# So the coroutines can be marked as noexcept automatically if all its
# promise functions and the allocation functions matches the behavior.
list(APPEND CXX_FLAGS "-fdisable-exception-with-may-throw-dtor")
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND CXX_FLAGS "-fcoroutines")
endif()
Expand Down
3 changes: 3 additions & 0 deletions cmake/IsACC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef __alibaba_clang__
#error "The current compiler is not ACC"
#endif

0 comments on commit 1527007

Please sign in to comment.