#include "vl/vl_decoder.h"
#include "driver_ddebug/dd_util.h"
+#include <llvm-c/Transforms/IPO.h>
+#include <llvm-c/Transforms/Scalar.h>
+#if HAVE_LLVM >= 0x0700
+#include <llvm-c/Transforms/Utils.h>
+#endif
+
static const struct debug_named_value debug_options[] = {
/* Shader logging options: */
{ "vs", DBG(VS), "Print vertex shaders" },
gallivm_create_target_library_info(compiler->triple);
if (!compiler->target_library_info)
return;
+
+ compiler->passmgr = LLVMCreatePassManager();
+ if (!compiler->passmgr)
+ return;
+
+ LLVMAddTargetLibraryInfo(compiler->target_library_info,
+ compiler->passmgr);
+
+ /* Add LLVM passes into the pass manager. */
+ if (sscreen->debug_flags & DBG(CHECK_IR))
+ LLVMAddVerifierPass(compiler->passmgr);
+
+ LLVMAddAlwaysInlinerPass(compiler->passmgr);
+ /* This pass should eliminate all the load and store instructions. */
+ LLVMAddPromoteMemoryToRegisterPass(compiler->passmgr);
+ LLVMAddScalarReplAggregatesPass(compiler->passmgr);
+ LLVMAddLICMPass(compiler->passmgr);
+ LLVMAddAggressiveDCEPass(compiler->passmgr);
+ LLVMAddCFGSimplificationPass(compiler->passmgr);
+ /* This is recommended by the instruction combining pass. */
+ LLVMAddEarlyCSEMemSSAPass(compiler->passmgr);
+ LLVMAddInstructionCombiningPass(compiler->passmgr);
}
static void si_destroy_compiler(struct si_compiler *compiler)
{
+ if (compiler->passmgr)
+ LLVMDisposePassManager(compiler->passmgr);
if (compiler->target_library_info)
gallivm_dispose_target_library_info(compiler->target_library_info);
if (compiler->tm)
return sscreen->debug_flags & (1 << processor);
}
-static inline bool si_extra_shader_checks(struct si_screen *sscreen,
- unsigned processor)
-{
- return (sscreen->debug_flags & DBG(CHECK_IR)) ||
- si_can_dump_shader(sscreen, processor);
-}
-
static inline bool si_get_strmout_en(struct si_context *sctx)
{
return sctx->streamout.streamout_enabled ||
LLVMTargetMachineRef tm;
const char *triple;
LLVMTargetLibraryInfoRef target_library_info;
+ LLVMPassManagerRef passmgr;
};
/* State of the context creating the shader object. */
#include "util/u_debug.h"
#include <stdio.h>
-#include <llvm-c/Transforms/IPO.h>
-#include <llvm-c/Transforms/Scalar.h>
-#if HAVE_LLVM >= 0x0700
-#include <llvm-c/Transforms/Utils.h>
-#endif
enum si_llvm_calling_convention {
RADEON_LLVM_AMDGPU_VS = 87,
void si_llvm_optimize_module(struct si_shader_context *ctx)
{
- struct gallivm_state *gallivm = &ctx->gallivm;
-
/* Dump LLVM IR before any optimization passes */
if (ctx->screen->debug_flags & DBG(PREOPT_IR) &&
si_can_dump_shader(ctx->screen, ctx->type))
LLVMDumpModule(ctx->gallivm.module);
- /* Create the pass manager */
- gallivm->passmgr = LLVMCreatePassManager();
-
- LLVMAddTargetLibraryInfo(ctx->compiler->target_library_info,
- gallivm->passmgr);
-
- if (si_extra_shader_checks(ctx->screen, ctx->type))
- LLVMAddVerifierPass(gallivm->passmgr);
-
- LLVMAddAlwaysInlinerPass(gallivm->passmgr);
-
- /* This pass should eliminate all the load and store instructions */
- LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
-
- /* Add some optimization passes */
- LLVMAddScalarReplAggregatesPass(gallivm->passmgr);
- LLVMAddLICMPass(gallivm->passmgr);
- LLVMAddAggressiveDCEPass(gallivm->passmgr);
- LLVMAddCFGSimplificationPass(gallivm->passmgr);
- /* This is recommended by the instruction combining pass. */
- LLVMAddEarlyCSEMemSSAPass(gallivm->passmgr);
- LLVMAddInstructionCombiningPass(gallivm->passmgr);
-
/* Run the pass */
- LLVMRunPassManager(gallivm->passmgr, ctx->gallivm.module);
-
+ LLVMRunPassManager(ctx->compiler->passmgr, ctx->gallivm.module);
LLVMDisposeBuilder(ctx->ac.builder);
- LLVMDisposePassManager(gallivm->passmgr);
}
void si_llvm_dispose(struct si_shader_context *ctx)