1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 * @author Jose Fonseca <jfonseca@vmware.com>
36 #include <llvm-c/Transforms/Scalar.h>
38 #include "util/u_memory.h"
39 #include "lp_screen.h"
40 #include "lp_bld_intr.h"
45 lp_jit_init_globals(struct llvmpipe_screen
*screen
)
47 /* struct lp_jit_context */
49 LLVMTypeRef elem_types
[4];
50 LLVMTypeRef context_type
;
52 elem_types
[0] = LLVMPointerType(LLVMFloatType(), 0); /* constants */
53 elem_types
[1] = LLVMPointerType(LLVMInt8Type(), 0); /* samplers */
54 elem_types
[2] = LLVMFloatType(); /* alpha_ref_value */
55 elem_types
[3] = LLVMPointerType(LLVMInt8Type(), 0); /* blend_color */
57 context_type
= LLVMStructType(elem_types
, Elements(elem_types
), 0);
59 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, constants
,
60 screen
->target
, context_type
, 0);
61 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, samplers
,
62 screen
->target
, context_type
, 1);
63 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, alpha_ref_value
,
64 screen
->target
, context_type
, 2);
65 LP_CHECK_MEMBER_OFFSET(struct lp_jit_context
, blend_color
,
66 screen
->target
, context_type
, 3);
67 LP_CHECK_STRUCT_SIZE(struct lp_jit_context
,
68 screen
->target
, context_type
);
70 LLVMAddTypeName(screen
->module
, "context", context_type
);
72 screen
->context_ptr_type
= LLVMPointerType(context_type
, 0);
79 LLVMTypeRef arg_types
[3];
80 LLVMValueRef fetch_texel
;
82 ret_type
= LLVMVoidType();
83 arg_types
[0] = LLVMPointerType(LLVMInt8Type(), 0); /* samplers */
84 arg_types
[1] = LLVMInt32Type(); /* unit */
85 arg_types
[2] = LLVMPointerType(LLVMVectorType(LLVMFloatType(), 4), 0); /* store */
87 fetch_texel
= lp_declare_intrinsic(screen
->module
, "fetch_texel",
88 ret_type
, arg_types
, Elements(arg_types
));
90 LLVMAddGlobalMapping(screen
->engine
, fetch_texel
, lp_fetch_texel_soa
);
94 LLVMDumpModule(screen
->module
);
100 lp_jit_screen_cleanup(struct llvmpipe_screen
*screen
)
103 LLVMDisposeExecutionEngine(screen
->engine
);
106 LLVMDisposePassManager(screen
->pass
);
111 lp_jit_screen_init(struct llvmpipe_screen
*screen
)
115 screen
->module
= LLVMModuleCreateWithName("llvmpipe");
117 screen
->provider
= LLVMCreateModuleProviderForExistingModule(screen
->module
);
119 if (LLVMCreateJITCompiler(&screen
->engine
, screen
->provider
, 1, &error
)) {
120 fprintf(stderr
, "%s\n", error
);
121 LLVMDisposeMessage(error
);
125 screen
->target
= LLVMGetExecutionEngineTargetData(screen
->engine
);
127 screen
->pass
= LLVMCreateFunctionPassManager(screen
->provider
);
128 LLVMAddTargetData(screen
->target
, screen
->pass
);
129 /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
130 * but there are more on SVN. */
131 LLVMAddConstantPropagationPass(screen
->pass
);
132 LLVMAddInstructionCombiningPass(screen
->pass
);
133 LLVMAddPromoteMemoryToRegisterPass(screen
->pass
);
134 LLVMAddGVNPass(screen
->pass
);
135 LLVMAddCFGSimplificationPass(screen
->pass
);
137 lp_jit_init_globals(screen
);