libresoc_device_dispatch_table.entrypoints[i];
}
}
- instance->physical_devices_enumerated = false;
- list_inithead(&instance->physical_devices);
- glsl_type_singleton_init_or_ref();
- libresoc_init_dri_options(instance);
- *pInstance = libresoc_instance_to_handle(instance);
+ instance->physical_devices_enumerated = false;
+ list_inithead(&instance->physical_devices);
+ glsl_type_singleton_init_or_ref();
+ libresoc_init_dri_options(instance);
+ InitLLVM(&instance->llvm_ref);
+ *pInstance = libresoc_instance_to_handle(instance);
return VK_SUCCESS;
}
--- /dev/null
+#include "libresoc_llvm.h"
+#include <llvm-c/OrcBindings.h>
+#include <llvm-c/Core.h>
+#include <llvm-c/Analysis.h>
+#include "nir/nir.h"
+#include "nir/nir_deref.h"
+
+void InitLLVM(struct libresoc_llvm *llvm_ref)
+{
+ LLVMInitializeNativeTarget();
+ LLVMInitializeNativeAsmPrinter();
+ //LLVMLinkInMCJIT();
+ char *def_triple = LLVMGetDefaultTargetTriple(); // E.g. "x86_64-linux-gnu"
+ char *error;
+ LLVMTargetRef target_ref;
+ if (LLVMGetTargetFromTriple(def_triple, &target_ref, &error)) {
+ // Fatal error
+ }
+
+ if (!LLVMTargetHasJIT(target_ref)) {
+ // Fatal error, cannot do JIT on this platform
+ }
+
+ LLVMTargetMachineRef tm_ref =
+ LLVMCreateTargetMachine(target_ref, def_triple, "", "",
+ LLVMCodeGenLevelDefault,
+ LLVMRelocDefault,
+ LLVMCodeModelJITDefault);
+ //assert(tm_ref);
+ LLVMDisposeErrorMessage(def_triple);
+ llvm_ref->orc_ref = LLVMOrcCreateInstance(tm_ref);
+ llvm_ref->context = LLVMContextCreate();
+ llvm_ref->builder = LLVMCreateBuilderInContext(llvm_ref->context);
+}
+
+void DestroyLLVM(struct libresoc_llvm *llvm_ref)
+{
+ LLVMErrorRef error_ref = LLVMOrcDisposeInstance(llvm_ref->orc_ref);
+}
+
+static uint64_t orc_sym_resolver(const char *name, void *ctx)
+{
+ LLVMOrcJITStackRef orc_ref = (LLVMOrcJITStackRef) (ctx);
+ LLVMOrcTargetAddress address;
+ LLVMOrcGetSymbolAddress(orc_ref, &address, name);
+ return (uint64_t)address;
+}
+
+void libresoc_nir_translate(struct libresoc_llvm *llvm_ref, struct nir_shader *nir)
+{
+ LLVMModuleRef mod = LLVMModuleCreateWithName("libresoc_mod");
+ LLVMTypeRef param_types[] = { LLVMInt32Type(), LLVMInt32Type() };
+ LLVMTypeRef ret_type = LLVMFunctionType(LLVMInt32Type(), param_types, 2, 0);
+ LLVMValueRef sum = LLVMAddFunction(mod, "sum", ret_type);
+ LLVMBasicBlockRef entry = LLVMAppendBasicBlock(sum, "entry");
+ LLVMBuilderRef builder = LLVMCreateBuilder();
+ LLVMPositionBuilderAtEnd(builder, entry);
+ LLVMValueRef tmp = LLVMBuildAdd(builder, LLVMGetParam(sum, 0), LLVMGetParam(sum, 1), "tmp");
+ LLVMBuildRet(builder, tmp);
+ char *error = NULL;
+ LLVMVerifyModule(mod, LLVMAbortProcessAction, &error);
+ LLVMDumpModule(mod);
+ LLVMDisposeMessage(error);
+ LLVMOrcModuleHandle mod_handle;
+ LLVMErrorRef error_ref = LLVMOrcAddEagerlyCompiledIR(llvm_ref->orc_ref,
+ &mod_handle,
+ mod,
+ orc_sym_resolver,
+ (void *)(llvm_ref->orc_ref));
+}