Add memory-env option.

This commit is contained in:
Christoffer Lerno
2023-01-26 20:33:37 +01:00
committed by Christoffer Lerno
parent 6a73c8e90e
commit 6eb65d5b37
10 changed files with 72 additions and 13 deletions

View File

@@ -11,6 +11,14 @@ enum CompilerOptLevel
O3
}
enum MemoryEnvironment
{
NORMAL,
SMALL,
TINY,
NONE
}
enum OsType
{
UNKNOWN,
@@ -51,9 +59,9 @@ enum OsType
EMSCRIPTEN,
}
const OsType OS_TYPE = (OsType)($$OS_TYPE);
const OsType OS_TYPE = (OsType)$$OS_TYPE;
const bool COMPILER_LIBC_AVAILABLE = $$COMPILER_LIBC_AVAILABLE;
const CompilerOptLevel COMPILER_OPT_LEVEL = (CompilerOptLevel)($$COMPILER_OPT_LEVEL);
const CompilerOptLevel COMPILER_OPT_LEVEL = (CompilerOptLevel)$$COMPILER_OPT_LEVEL;
const bool BIG_ENDIAN = $$PLATFORM_BIG_ENDIAN;
const bool I128_NATIVE_SUPPORT = $$PLATFORM_I128_SUPPORTED;
const bool F16_SUPPORT = $$PLATFORM_F16_SUPPORTED;
@@ -62,7 +70,7 @@ const bool COMPILER_SAFE_MODE = $$COMPILER_SAFE_MODE;
const usz LLVM_VERSION = $$LLVM_VERSION;
const bool BENCHMARKING = $$BENCHMARKING;
const bool TESTING = $$TESTING;
const usz TEMP_ALLOCATOR_SIZE = 128 * 1024;
const MemoryEnvironment MEMORY_ENV = (MemoryEnvironment)$$MEMORY_ENVIRONMENT;
macro bool os_is_posix()
{
@@ -86,4 +94,5 @@ macro bool os_is_posix()
$echo("Assuming non-Posix environment");
return false;
$endswitch;
}
}

View File

@@ -275,7 +275,16 @@ macro TempAllocator* temp_allocator()
{
if (!thread_temp_allocator)
{
thread_temp_allocator = allocator::new_temp(env::TEMP_ALLOCATOR_SIZE, allocator::LIBC_ALLOCATOR)!!;
$switch (env::MEMORY_ENV):
$case NORMAL:
thread_temp_allocator = allocator::new_temp(1024 * 256, allocator::LIBC_ALLOCATOR)!!;
$case SMALL:
thread_temp_allocator = allocator::new_temp(1024 * 16, allocator::LIBC_ALLOCATOR)!!;
$case TINY:
thread_temp_allocator = allocator::new_temp(1024 * 4, allocator::LIBC_ALLOCATOR)!!;
$case NONE:
unreachable("Temp allocator must explicitly created when memory-env is set to 'none'.");
$endswitch;
}
return thread_temp_allocator;
}

View File

@@ -131,6 +131,7 @@ static void usage(void)
OUTPUT("");
OUTPUT(" --reloc=<option> - Relocation model: none, pic, PIC, pie, PIE.");
OUTPUT(" --x86vec=<option> - Set max level of vector instructions: none, native, mmx, sse, avx, avx512.");
OUTPUT(" --memory-env=<option> - Set the memory environment: normal, small, tiny, none.");
OUTPUT("");
OUTPUT(" --debug-stats - Print debug statistics.");
#ifndef NDEBUG
@@ -546,6 +547,11 @@ static void parse_option(BuildOptions *options)
options->x86_vector_capability = (X86VectorCapability)parse_multi_option(argopt, 6, vector_capability);
return;
}
if ((argopt = match_argopt("memory-env")))
{
options->memory_environment = (MemoryEnvironment )parse_multi_option(argopt, 4, memory_environment);
return;
}
if ((argopt = match_argopt("reloc")))
{
options->reloc_model = (RelocModel)parse_multi_option(argopt, 5, reloc_models);
@@ -839,6 +845,7 @@ BuildOptions parse_arguments(int argc, const char *argv[])
.reloc_model = RELOC_DEFAULT,
.backend = BACKEND_LLVM,
.x86_vector_capability = X86VECTOR_DEFAULT,
.memory_environment = MEMORY_ENV_NOT_SET,
.win.crt_linking = WIN_CRT_DEFAULT,
.files = NULL,
.build_dir = NULL,

View File

@@ -147,6 +147,7 @@ typedef enum
X86VECTOR_NATIVE = 5,
} X86VectorCapability;
static const char *vector_capability[6] = {
[X86VECTOR_NONE] = "none",
[X86VECTOR_MMX] = "mmx",
@@ -156,6 +157,22 @@ static const char *vector_capability[6] = {
[X86VECTOR_NATIVE] = "native"
};
typedef enum
{
MEMORY_ENV_NOT_SET = -1,
MEMORY_ENV_NORMAL = 0,
MEMORY_ENV_SMALL = 1,
MEMORY_ENV_TINY = 2,
MEMORY_ENV_NONE = 3,
} MemoryEnvironment;
static const char *memory_environment[6] = {
[MEMORY_ENV_NORMAL] = "normal",
[MEMORY_ENV_SMALL] = "small",
[MEMORY_ENV_TINY] = "tiny",
[MEMORY_ENV_NONE] = "none",
};
typedef enum
{
WIN_CRT_DEFAULT = -1,
@@ -284,6 +301,7 @@ typedef struct BuildOptions_
const char *obj_out;
RelocModel reloc_model;
X86VectorCapability x86_vector_capability;
MemoryEnvironment memory_environment;
bool print_keywords;
bool print_attributes;
bool print_builtins;
@@ -365,6 +383,7 @@ typedef struct
bool no_entry;
int build_threads;
OptimizationLevel optimization_level;
MemoryEnvironment memory_environment;
SizeOptimizationLevel size_optimization_level;
bool single_module;
DebugInfo debug_info;

View File

@@ -196,6 +196,10 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
{
target->feature.safe_mode = options->safe_mode == 1;
}
if (options->memory_environment != MEMORY_ENV_NOT_SET)
{
target->memory_environment = options->memory_environment;
}
if (options->debug_info_override != DEBUG_INFO_NOT_SET)
{
target->debug_info = options->debug_info_override;
@@ -301,6 +305,7 @@ void init_default_build_target(BuildTarget *target, BuildOptions *options)
.source_dirs = options->files,
.name = options->output_name,
.optimization_level = OPTIMIZATION_DEFAULT,
.memory_environment = MEMORY_ENV_NORMAL,
.size_optimization_level = SIZE_OPTIMIZATION_NONE,
.symtab_size = options->symtab_size ? options->symtab_size : DEFAULT_SYMTAB_SIZE,
.switchrange_max_size = DEFAULT_SWITCHRANGE_MAX_SIZE,

View File

@@ -20,6 +20,7 @@ const char *project_default_keys[] = {
"link-args",
"linked-libraries",
"macossdk",
"memory-env",
"no-entry",
"nolibc",
"nostdlib",
@@ -62,6 +63,7 @@ const char* project_target_keys[] = {
"link-args-override",
"link-args-add",
"macossdk",
"memory-env",
"nolibc",
"nostdlib",
"panicfn",
@@ -289,6 +291,9 @@ static void load_into_build_target(JSONObject *json, const char *type, BuildTarg
DebugInfo info = get_valid_string_setting(json, "debug-info", type, debug_infos, 0, 3, "one of 'full' 'line-table' or 'none'.");
if (info > -1) target->debug_info = info;
MemoryEnvironment env = get_valid_string_setting(json, "memory-env", type, memory_environment, 0, 4, "one of 'normal', 'small', 'tiny' or 'none'.");
if (env > -1) target->memory_environment = env;
// Symtab
long symtab_size = get_valid_integer(json, "symtab", type, false);
if (symtab_size > 0)
@@ -409,6 +414,7 @@ static void project_add_targets(Project *project, JSONObject *project_data)
BuildTarget default_target = {
.optimization_level = OPTIMIZATION_DEFAULT,
.memory_environment = MEMORY_ENV_NORMAL,
.size_optimization_level = SIZE_OPTIMIZATION_NONE,
.arch_os_target = ARCH_OS_TARGET_DEFAULT,
.debug_info = DEBUG_INFO_NONE,

View File

@@ -551,9 +551,11 @@ static void setup_int_define(const char *id, uint64_t i, Type *type)
{
TokenType token_type = TOKEN_CONST_IDENT;
id = symtab_add(id, (uint32_t) strlen(id), fnv1a(id, (uint32_t) strlen(id)), &token_type);
assert(type_is_integer(type));
Expr *expr = expr_new_const_int(INVALID_SPAN, type, i, true);
if (expr_const_will_overflow(&expr->const_expr, type->type_kind))
Type *flat = type_flatten(type);
assert(type_is_integer(flat));
Expr *expr = expr_new_const_int(INVALID_SPAN, flat, i, true);
expr->type = type;
if (expr_const_will_overflow(&expr->const_expr, flat->type_kind))
{
error_exit("Integer define %s overflow.", id);
}
@@ -745,6 +747,7 @@ static int jump_buffer_size()
}
UNREACHABLE
}
void compile()
{
symtab_init(active_target.symtab_size);
@@ -770,6 +773,7 @@ void compile()
setup_bool_define("PLATFORM_I128_SUPPORTED", platform_target.int128);
setup_bool_define("PLATFORM_F128_SUPPORTED", platform_target.float128);
setup_bool_define("PLATFORM_F16_SUPPORTED", platform_target.float16);
setup_int_define("MEMORY_ENVIRONMENT", (uint64_t)active_target.memory_environment, type_int);
setup_bool_define("COMPILER_LIBC_AVAILABLE", !active_target.no_libc);
setup_int_define("COMPILER_OPT_LEVEL", (uint64_t)active_target.optimization_level, type_int);
setup_int_define("OS_TYPE", (uint64_t)platform_target.os, type_int);

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.24"
#define COMPILER_VERSION "0.4.25"

View File

@@ -350,7 +350,7 @@ voiderr64: ; preds = %after_check63, %voi
br i1 %not, label %if.then, label %if.exit
if.then: ; preds = %voiderr64
%79 = call i64 @std_core_mem_allocator_new_temp(ptr %retparam65, i64 131072, ptr @std_core_mem_allocator__SYSTEM_ALLOCATOR)
%79 = call i64 @std_core_mem_allocator_new_temp(ptr %retparam65, i64 262144, ptr @std_core_mem_allocator__SYSTEM_ALLOCATOR)
%not_err66 = icmp eq i64 %79, 0
br i1 %not_err66, label %after_check67, label %assign_optional
@@ -364,7 +364,7 @@ after_check67: ; preds = %if.then
panic_block: ; preds = %assign_optional
%81 = load ptr, ptr @std_core_builtin_panic, align 8
call void %81(ptr @.panic_msg, i64 27, ptr @.file, i64 6, ptr @.func, i64 4,
call void %81(ptr @.panic_msg,
unreachable
noerr_block: ; preds = %after_check67

View File

@@ -494,7 +494,7 @@ voiderr97: ; preds = %after_check96, %voi
br i1 %not, label %if.then, label %if.exit
if.then: ; preds = %voiderr97
%158 = call i64 @std_core_mem_allocator_new_temp(%TempAllocator** %retparam98, i64 131072, %Allocator* @std_core_mem_allocator__SYSTEM_ALLOCATOR)
%158 = call i64 @std_core_mem_allocator_new_temp(%TempAllocator** %retparam98, i64 262144, %Allocator* @std_core_mem_allocator__SYSTEM_ALLOCATOR)
%not_err99 = icmp eq i64 %158, 0
br i1 %not_err99, label %after_check100, label %assign_optional
@@ -508,7 +508,7 @@ after_check100: ; preds = %if.then
panic_block: ; preds = %assign_optional
%160 = load void (i8*, i64, i8*, i64, i8*, i64, i32)*, void (i8*, i64, i8*, i64, i8*, i64, i32)** @std_core_builtin_panic, align 8
call void %160(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.panic_msg, i64 0, i64 0), i64 27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.file, i64 0, i64 0), i64 6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.func, i64 0, i64 0), i64 4,
call void %160(i8* getelementptr inbounds
unreachable
noerr_block: ; preds = %after_check100