From: Jacob Lifshay Date: Sat, 19 Aug 2017 00:55:15 +0000 (-0700) Subject: add code to get target vector register width X-Git-Tag: gsoc-2017~37 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7574960ab1fdc9f8e12f9b42bd6f2cc7bf1f1798;p=kazan.git add code to get target vector register width --- diff --git a/src/llvm_wrapper/llvm_wrapper.cpp b/src/llvm_wrapper/llvm_wrapper.cpp index 24b579d..e1a4b64 100644 --- a/src/llvm_wrapper/llvm_wrapper.cpp +++ b/src/llvm_wrapper/llvm_wrapper.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -127,6 +128,17 @@ Target_machine Target_machine::create_native_target_machine(::LLVMCodeGenOptLeve return ::LLVMCodeGenLevelDefault; } +unsigned Target_machine::get_biggest_vector_register_bit_width(::LLVMTargetMachineRef tm, + ::LLVMValueRef function) +{ + auto unwrapped_function = llvm::unwrap(function); + llvm::FunctionAnalysisManager function_analysis_manager; + return unwrap(tm) + ->getTargetIRAnalysis() + .run(*unwrapped_function, function_analysis_manager) + .getRegisterBitWidth(true); +} + void Module::set_target_machine(::LLVMModuleRef module, ::LLVMTargetMachineRef target_machine) { ::LLVMSetTarget(module, Target_machine::get_target_triple(target_machine).get()); diff --git a/src/llvm_wrapper/llvm_wrapper.h b/src/llvm_wrapper/llvm_wrapper.h index 62a5e04..f748d2d 100644 --- a/src/llvm_wrapper/llvm_wrapper.h +++ b/src/llvm_wrapper/llvm_wrapper.h @@ -309,6 +309,12 @@ struct Target_machine : public Wrapper<::LLVMTargetMachineRef, Target_machine_de { return get_code_gen_opt_level(get()); } + static unsigned get_biggest_vector_register_bit_width(::LLVMTargetMachineRef tm, + ::LLVMValueRef function); + unsigned get_biggest_vector_register_bit_width(::LLVMValueRef function) const + { + return get_biggest_vector_register_bit_width(get(), function); + } }; struct Module_deleter @@ -374,7 +380,8 @@ struct Builder : public Wrapper<::LLVMBuilderRef, Builder_deleter> if(value == 0) return ::LLVMGetUndef(::LLVMTypeOf(rhs)); if((value & (value - 1)) == 0) - return ::LLVMBuildAnd(builder, lhs, ::LLVMConstInt(::LLVMTypeOf(rhs), value - 1, false), result_name); + return ::LLVMBuildAnd( + builder, lhs, ::LLVMConstInt(::LLVMTypeOf(rhs), value - 1, false), result_name); } auto srem_result = ::LLVMBuildSRem(builder, lhs, rhs, ""); auto zero_constant = ::LLVMConstInt(::LLVMTypeOf(lhs), 0, false); diff --git a/src/pipeline/CMakeLists.txt b/src/pipeline/CMakeLists.txt index 5b4d980..c091aa9 100644 --- a/src/pipeline/CMakeLists.txt +++ b/src/pipeline/CMakeLists.txt @@ -22,4 +22,4 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) set(sources pipeline.cpp) add_library(vulkan_cpu_pipeline STATIC ${sources}) -target_link_libraries(vulkan_cpu_pipeline vulkan_cpu_spirv_to_llvm vulkan_cpu_json vulkan_cpu_util vulkan_cpu_spirv vulkan_cpu_llvm_wrapper vulkan_cpu_vulkan) +target_link_libraries(vulkan_cpu_pipeline vulkan_cpu_spirv_to_llvm vulkan_cpu_json vulkan_cpu_util vulkan_cpu_spirv vulkan_cpu_llvm_wrapper vulkan_cpu_vulkan vulkan_cpu_image) diff --git a/src/pipeline/pipeline.cpp b/src/pipeline/pipeline.cpp index 3882788..cbe9ba2 100644 --- a/src/pipeline/pipeline.cpp +++ b/src/pipeline/pipeline.cpp @@ -93,6 +93,7 @@ llvm_wrapper::Module Pipeline::optimize_module(llvm_wrapper::Module module, #warning finish implementing module optimizations { auto manager = llvm_wrapper::Pass_manager::create_function_pass_manager(module.get()); + ::LLVMAddAnalysisPasses(target_machine, manager.get()); ::LLVMAddPromoteMemoryToRegisterPass(manager.get()); ::LLVMAddScalarReplAggregatesPass(manager.get()); ::LLVMAddScalarizerPass(manager.get()); @@ -112,6 +113,7 @@ llvm_wrapper::Module Pipeline::optimize_module(llvm_wrapper::Module module, } { auto manager = llvm_wrapper::Pass_manager::create_module_pass_manager(); + ::LLVMAddAnalysisPasses(target_machine, manager.get()); ::LLVMAddIPSCCPPass(manager.get()); ::LLVMAddFunctionInliningPass(manager.get()); ::LLVMAddDeadArgEliminationPass(manager.get()); @@ -120,6 +122,7 @@ llvm_wrapper::Module Pipeline::optimize_module(llvm_wrapper::Module module, } { auto manager = llvm_wrapper::Pass_manager::create_function_pass_manager(module.get()); + ::LLVMAddAnalysisPasses(target_machine, manager.get()); ::LLVMAddCFGSimplificationPass(manager.get()); ::LLVMAddPromoteMemoryToRegisterPass(manager.get()); ::LLVMAddScalarReplAggregatesPass(manager.get());