Skip to content
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
3 changes: 3 additions & 0 deletions include/daScript/simulate/aot_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,7 @@ namespace das {
void builtin_main_loop ( const TBlock<bool> & block, Context * context, LineInfoArg * at );

vec4f _builtin_hash ( Context & context, SimNode_CallBase * call, vec4f * args );

const char * das_get_platform_name();
const char * das_get_architecture_name();
}
9 changes: 3 additions & 6 deletions modules/dasLLVM/daslib/llvm_boost.das
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,9 @@ def LLVMIsVector3(typ : LLVMOpaqueType?) : bool {
def LLVMBuildLoadVector3(builder : LLVMOpaqueBuilder?; var types : PrimitiveTypes?; var typ : LLVMOpaqueType?; ptr : LLVMOpaqueValue?; name : string) {
verify(LLVMGetVectorSize(typ) == 3u)
let elemT = LLVMGetElementType(typ)
var ld = LLVMBuildLoad2(builder, LLVMVectorType(elemT, 4u), ptr, name)
LLVMSetVolatile(ld, 1)
LLVMSetAlignment(ld, 4u)
var x = LLVMBuildExtractElement(builder, ld, types.ConstI32(0ul), "")
var y = LLVMBuildExtractElement(builder, ld, types.ConstI32(1ul), "")
var z = LLVMBuildExtractElement(builder, ld, types.ConstI32(2ul), "")
var x = LLVMBuildLoad2(builder, elemT, ptr, "")
var y = LLVMBuildLoad2(builder, elemT, LLVMBuildGEP2(builder, elemT, ptr, types.ConstI32(1ul), "", true), "")
var z = LLVMBuildLoad2(builder, elemT, LLVMBuildGEP2(builder, elemT, ptr, types.ConstI32(2ul), "", true), "")
var xyz = LLVMGetUndef(LLVMVectorType(elemT, 3u))
xyz = LLVMBuildInsertElement(builder, xyz, x, types.ConstI32(0ul), "")
xyz = LLVMBuildInsertElement(builder, xyz, y, types.ConstI32(1ul), "")
Expand Down
15 changes: 12 additions & 3 deletions modules/dasLLVM/daslib/llvm_jit.das
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class LlvmJitVisitor : AstVisitor {
option_no_alias : bool = false
option_no_capture : bool = false
own_di : bool = false
ldu_hint : array<bool>
ldu_hint : bool
attributes : Attributes?

def LlvmJitVisitor(ctx : Context?; var types_ : PrimitiveTypes?; uids : UidNodes?; need_di : bool; dib : LLVMOpaqueDIBuilder?; attrs : Attributes?) {
Expand Down Expand Up @@ -698,7 +698,7 @@ class LlvmJitVisitor : AstVisitor {
assert(g_builder != null, "missing builder")
thisFunc = get_ptr(fun)
uid.reset(get_ptr(fun))
ldu_hint |> push(LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS)
ldu_hint = LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS
let fnmna = uid.get_dll_fn_name(fun)
ffunc = LLVMGetNamedFunction(g_mod, fnmna.impl())
wfunc = LLVMGetNamedFunction(g_mod, fnmna.publ())
Expand Down Expand Up @@ -731,7 +731,7 @@ class LlvmJitVisitor : AstVisitor {
LLVMPositionBuilderAtEnd(g_builder, function_entry)
LLVMBuildBr(g_builder, function_body)
debug_after_function()
ldu_hint |> pop()
LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS = ldu_hint
ffunc = null
thisFunc = null
uid.reset(null)
Expand Down Expand Up @@ -6190,6 +6190,9 @@ class JIT_LLVM : AstSimulateMacro {
assume path_to_shared_lib = string(prog.policies.jit_path_to_shared_lib)
assume path_to_linker = string(prog.policies.jit_path_to_linker)

// Set global options
LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS = prog._options |> find_arg("jit_vec3_ldu") ?as tBool ?? LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS_DEFAULT

prog |> for_each_module <| $(mod) {
mod |> for_each_function("") <| $(fun) {
var rqj = fun.moreFlags.requestJit
Expand Down Expand Up @@ -6325,3 +6328,9 @@ class JIT_LLVM : AstSimulateMacro {
}


[_macro, macro_function]
def init_llvm_jit_module_options() {
if (is_compiling_macros_in_module("llvm_jit")) {
this_module() |> add_module_option("jit_vec3_ldu", Type.tBool)
}
}
6 changes: 3 additions & 3 deletions modules/dasLLVM/daslib/llvm_jit_common.das
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ let public LLVM_DEBUG_LINE_TRACES = false

let public LLVM_JIT_LOG = false || LLVM_DEBUG_EVERYTHING

var public LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS = false
let public LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS_DEFAULT = false // NOTE - this should be true, to match interpreter and AOT behavior
var public LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS = LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS_DEFAULT

let public LLVM_ENABLE_OPT_PASS = LLVM_DEBUG_EVERYTHING ? false : true
let public LLVM_LOG_RESULT = LLVM_DEBUG_EVERYTHING || LLVM_DEBUG_RESULT
Expand Down Expand Up @@ -869,9 +870,8 @@ def public build_broadcast_vector(builder : LLVMOpaqueBuilder?; opType : TypeDec
}
}

def public LLVMBuildLoadData2Aligned(builder : LLVMOpaqueBuilder?; var typ : LLVMOpaqueType?; ptr : LLVMOpaqueValue?; alignment : int; name : string) {
def public LLVMBuildLoadData2Aligned(builder : LLVMOpaqueBuilder?; var typ : LLVMOpaqueType?; ptr : LLVMOpaqueValue?; alignment : int; name : string) {
if (!LLVM_JIT_ALLOW_UNALIGNED_VECTOR_READ_OUT_OF_BOUNDS && alignment != 16 && LLVMIsVector3(typ)) {
// slow path
return LLVMBuildLoadVector3(builder, g_prim_t, typ, ptr, name)
} else {
return LLVMBuildLoad2Aligned(builder, typ, ptr, alignment |> uint, name)
Expand Down
6 changes: 1 addition & 5 deletions modules/dasLLVM/profile/nbodies.das
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ let {
nbodies = 5
}

[jit]
def offset_momentum(var bodies : body[5]) {
var px : float3
for (b in bodies) {
Expand All @@ -55,7 +54,7 @@ def offset_momentum(var bodies : body[5]) {
bodies[0].v = px / SOLAR_MASS
}

[jit, hint(alwaysinline, hot, noalias=bodies, unsafe_range_check)]
[hint(vec3_ldu)]
def advance(var bodies : body[5]) {
unroll <| $() {
for (i in range(nbodies)) {
Expand All @@ -74,7 +73,6 @@ def advance(var bodies : body[5]) {
}
}

[jit]
def energy(var bodies : body[5]) {
var e = 0.0
var i = 0
Expand All @@ -89,15 +87,13 @@ def energy(var bodies : body[5]) {
return e
}

[jit]
def scale_bodies(scale; var bodies : body[5]) {
for (b in bodies) {
b.mass *= scale * scale
b.v *= scale
}
}

[jit]
def nbodies(n : int) {
scale_bodies(0.01, g_bodies)
for (i in range(n)) {
Expand Down
37 changes: 37 additions & 0 deletions src/builtin/module_builtin_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,38 @@ namespace das
idpi->noPointerCast = true;
}

// windows, darwin, linux, etc
const char * das_get_platform_name() {
#if defined(_WIN32) || defined(_WIN64)
return "windows";
#elif defined(__APPLE__) || defined(__MACH__)
return "darwin";
#elif defined(__linux__)
return "linux";
#elif defined(__EMSCRIPTEN__)
return "emscripten";
#else
return "unknown";
#endif
}

// x86, arm, etc
const char * das_get_architecture_name() {
#if defined(__x86_64__) || defined(_M_X64)
return "x86_64";
#elif defined(__i386) || defined(_M_IX86)
return "x86";
#elif defined(__aarch64__)
return "arm64";
#elif defined(__arm__) || defined(_M_ARM)
return "arm";
#elif defined(__EMSCRIPTEN__)
return "wasm32";
#else
return "unknown";
#endif
}

void Module_BuiltIn::addRuntime(ModuleLibrary & lib) {
// printer flags
addAlias(makePrintFlags());
Expand Down Expand Up @@ -2133,5 +2165,10 @@ namespace das
addExtern<DAS_BIND_FUN(__bit_set64)>(*this, lib, "__bit_set",
SideEffects::modifyArgument, "__bit_set64")
->args({"value","mask","on"});
// platform and architecture
addExtern<DAS_BIND_FUN(das_get_platform_name)>(*this, lib, "get_platform_name",
SideEffects::none, "das_get_platform_name");
addExtern<DAS_BIND_FUN(das_get_architecture_name)>(*this, lib, "get_architecture_name",
SideEffects::none, "das_get_architecture_name");
}
}
Loading