c2a7aa0f18f8 — Leonard Ritter 2 months ago
* use a special module flag to select native module compilation presets
* work compiler flags into the cache key
M genie.lua +2 -2
@@ 104,8 104,8 @@ if IS_AARCH64 then
 end
 local LLVM_LIBS = pkg_config(LLVM_CONFIG .. " --link-static --libs orcjit"
     .. " engine passes option objcarcopts coverage support lto coroutines"
-    .. " webassembly frontendopenmp native "
-    .. TARGET_COMPONENTS)
+    .. " webassembly frontendopenmp native orcshared orctargetprocess jitlink"
+    .. " " .. TARGET_COMPONENTS)
 local LLVM_INCLUDEDIR = pkg_config(LLVM_CONFIG .. " --includedir")
 
 local CLANG_DEPS = {

          
M include/scopes/config.h +0 -6
@@ 15,12 15,6 @@ 
 // produces a firehose of information
 #define SCOPES_DEBUG_CODEGEN 0
 
-// run LLVM optimization passes
-// turning this on is detrimental to startup time
-// scopes output is typically clean enough to provide fairly good performance
-// on its own.
-#define SCOPES_OPTIMIZE_ASSEMBLY CF_O0
-
 // any location error aborts immediately and can not be caught
 #define SCOPES_EARLY_ABORT 0
 

          
M lib/scopes/core.sc +2 -5
@@ 178,7 178,7 @@ fn build-typify-function (f)
     let types = (alloca-array type 1:usize)
     store Value (getelementptr types 0)
     let types = (bitcast types TypeArrayPointer)
-    let result = (sc_compile (sc_typify f 1 types) compile-flag-cache)
+    let result = (sc_compile (sc_typify f 1 types) compile-flag-module)
     let result-type = (sc_value_type result)
     if (ptrcmp!= result-type SpiceMacroFunction)
         error

          
@@ 4018,10 4018,7 @@ fn exec-module (expr eval-scope)
         let f =
             do
                 hide-traceback;
-                sc_compile wrapf
-                    | compile-flag-cache
-                        # can't use this flag yet because it breaks code
-                        #compile-flag-O1
+                sc_compile wrapf compile-flag-module
         if (('typeof f) == StageFunctionType)
             let fptr = (f as StageFunctionType)
             let result =

          
M src/boot.cpp +1 -1
@@ 284,7 284,7 @@ skip_regular_load:
     auto stage_func_type = native_opaque_pointer_type(raising_function_type(
         arguments_type({TYPE_CompileStage}), {}));
 
-    const int compile_flags = CF_Cache;
+    const int compile_flags = CF_Module;
 
 compile_stage:
     if (fn->get_type() == stage_func_type) {

          
M src/cache.cpp +3 -3
@@ 179,15 179,15 @@ const char *get_cache_dir() {
     return cache_dir;
 }
 
-const String *get_cache_key(const char *content, size_t size) {
+const String *get_cache_key(uint64_t hash, const char *content, size_t size) {
     // split into four parts, hash each part -> 256 bits
     uint64_t h[4];
     memset(h, 0, sizeof(h));
     if (size < 4) {
-        h[0] = hash_bytes(content, size);
+        h[0] = hash2(hash, hash_bytes(content, size));
     } else {
         size_t part = size / 4;
-        h[0] = hash_bytes(content, part);
+        h[0] = hash2(hash, hash_bytes(content, part));
         h[1] = hash2(h[0], hash_bytes(content + part, part));
         h[2] = hash2(h[1], hash_bytes(content + part * 2, part));
         h[3] = hash2(h[2], hash_bytes(content + part * 3, size - 3 * part));

          
M src/cache.hpp +2 -1
@@ 8,12 8,13 @@ 
 #define SCOPES_CACHE_HPP
 
 #include <stddef.h>
+#include <stdint.h>
 
 namespace scopes {
 
 struct String;
 
-const String *get_cache_key(const char *content, size_t size);
+const String *get_cache_key(uint64_t hash, const char *content, size_t size);
 int get_cache_misses();
 const char *get_cache_dir();
 const char *get_cache_file(const String *key);

          
M src/compiler_flags.hpp +1 -1
@@ 20,7 20,7 @@ namespace scopes {
     T(CF_O2, (CF_O0 | (1 << 6)), "compile-flag-O2") \
     T(CF_O3, (CF_O1 | CF_O2), "compile-flag-O3") \
     T(CF_Cache, (1 << 7), "compile-flag-cache") \
-
+    T(CF_Module, (1 << 8), "compile-flag-module") \
 
 enum {
 #define T(NAME, VALUE, SNAME) \

          
M src/execution.cpp +5 -4
@@ 277,6 277,8 @@ SCOPES_RESULT(void) init_execution() {
     auto ES = LLVMOrcLLJITGetExecutionSession(orc);
     assert(ES);
     object_layer = LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(ES);
+    add_jit_event_listener(LLVMCreateGDBRegistrationListener());
+
     jit_dylib = LLVMOrcLLJITGetMainJITDylib(orc);
 
     LLVMOrcDefinitionGeneratorRef defgen = 0;

          
@@ 291,8 293,6 @@ SCOPES_RESULT(void) init_execution() {
     LLVMOrcJITDylibAddGenerator(jit_dylib,
         LLVMOrcCreateCustomCAPIDefinitionGenerator(&definition_generator, nullptr));
 
-    add_jit_event_listener(LLVMCreateGDBRegistrationListener());
-
 #if 0
     LLVMOrcTargetAddress retaddr = 0;
     LLVMOrcErrorCode err = LLVMOrcCreateLazyCompileCallback(orc, &retaddr, lazy_compile_callback, nullptr);

          
@@ 332,7 332,7 @@ SCOPES_RESULT(void) add_module(LLVMModul
     const char *filepath = nullptr;
     if (cache) {
         assert(irbuf);
-        key = get_cache_key(LLVMGetBufferStart(irbuf), LLVMGetBufferSize(irbuf));
+        key = get_cache_key(compiler_flags, LLVMGetBufferStart(irbuf), LLVMGetBufferSize(irbuf));
         filepath = get_cache_file(key);
 
         const char *keyfilepath = get_cache_key_file(key);

          
@@ 511,7 511,8 @@ SCOPES_RESULT(void) add_object(const cha
 void init_llvm() {
     global_c_namespace = dlopen(NULL, RTLD_LAZY);
 
-    LLVMEnablePrettyStackTrace();
+    // remove crash message
+    //LLVMEnablePrettyStackTrace();
     LLVMInitializeNativeTarget();
     LLVMInitializeNativeAsmPrinter();
     LLVMInitializeNativeAsmParser();

          
M src/gen_llvm.cpp +4 -3
@@ 3407,9 3407,10 @@ SCOPES_RESULT(ConstPointerRef) compile(c
 #else
     flags |= CF_NoDebugInfo;
 #endif
-#ifdef SCOPES_OPTIMIZE_ASSEMBLY
-    flags |= SCOPES_OPTIMIZE_ASSEMBLY;
-#endif
+    if (flags & CF_Module) {
+        flags |= CF_O0;
+        flags |= CF_Cache;
+    }
 
     /*
     const Type *functype = pointer_type(

          
M testing/test_codegen.sc +1 -1
@@ 4,6 4,6 @@ using import testing
 fn elidable (x)
     extractvalue (insertvalue x 1 0) 0
 
-compile (static-typify elidable (tuple i32 i32)) 'dump-function 'O0
+compile (static-typify elidable (tuple i32 i32)) 'dump-function
 
 ;
  No newline at end of file