add code to get target vector register width
authorJacob Lifshay <programmerjake@gmail.com>
Sat, 19 Aug 2017 00:55:15 +0000 (17:55 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Sat, 19 Aug 2017 00:55:15 +0000 (17:55 -0700)
src/llvm_wrapper/llvm_wrapper.cpp
src/llvm_wrapper/llvm_wrapper.h
src/pipeline/CMakeLists.txt
src/pipeline/pipeline.cpp

index 24b579d07206a15aec46eeb5da8a45391b5f908c..e1a4b64f8818c6e5951b85d7dbb9a7272cbf1d71 100644 (file)
@@ -26,6 +26,7 @@
 #include <llvm-c/ExecutionEngine.h>
 #include <llvm/IR/DataLayout.h>
 #include <llvm/Target/TargetMachine.h>
+#include <llvm/Analysis/TargetTransformInfo.h>
 #include <iostream>
 #include <cstdlib>
 #include <algorithm>
@@ -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<llvm::Function>(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());
index 62a5e040c84cd12c9c927db9d14b27377f48cab8..f748d2dff39007bd42241ced2feb35a821946cd1 100644 (file)
@@ -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);
index 5b4d9807302fe2a242bb56834e750359101c5714..c091aa9d1c66d77d2f7075bc3dffa04f17b23fa9 100644 (file)
@@ -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)
index 38827882b879bd955794edafd4349f55501dcb1d..cbe9ba2f9fc2a2db792672106f4e694ef0b54bee 100644 (file)
@@ -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());