Skip to content

Add back LCOMPILERS_FAST_ALLOC #ifdef #1682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ set(WITH_WHEREAMI yes
set(WITH_ZLIB yes
CACHE BOOL "Compile with ZLIB Library")

set(WITH_LCOMPILERS_FAST_ALLOC yes
CACHE BOOL "Compile with fast allocator")

# Build to wasm
set(LPYTHON_BUILD_TO_WASM no
CACHE BOOL "Compile LPython To WASM")
Expand All @@ -97,6 +100,7 @@ if (LPYTHON_BUILD_TO_WASM)
set(HAVE_BUILD_TO_WASM yes)
SET(WITH_WHEREAMI no)
SET(WITH_ZLIB no)
SET(WITH_LCOMPILERS_FAST_ALLOC no)
add_definitions("-DHAVE_BUILD_TO_WASM=1")
endif()

Expand All @@ -112,6 +116,10 @@ if (WITH_ZLIB)
find_package(StaticZLIB REQUIRED)
endif()

if (WITH_LCOMPILERS_FAST_ALLOC)
add_definitions("-DLCOMPILERS_FAST_ALLOC=1")
endif()

# LLVM
set(WITH_LLVM no CACHE BOOL "Build with LLVM support")
set(WITH_TARGET_AARCH64 no CACHE BOOL "Enable target AARCH64")
Expand Down
12 changes: 11 additions & 1 deletion src/libasr/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,25 @@ class Allocator
// force new_chunk() not to get inlined, but there is no standard way of
// doing it. This try/catch approach effectively achieves the same using
// standard C++.
#ifdef LCOMPILERS_FAST_ALLOC
try {
#endif
LCOMPILERS_ASSERT(start != nullptr);
size_t addr = current_pos;
current_pos += align(s);
if (size_current() > size_total()) throw std::bad_alloc();
if (size_current() > size_total()) {
#ifdef LCOMPILERS_FAST_ALLOC
throw std::bad_alloc();
#else
return new_chunk(s);
#endif
}
return (void*)addr;
#ifdef LCOMPILERS_FAST_ALLOC
} catch (const std::bad_alloc &e) {
return new_chunk(s);
}
#endif
}

void *new_chunk(size_t s) {
Expand Down