c3ba03a5a18d0d98ad70c8f84f17fba95fc2f403
[mesa.git] / src / gallium / drivers / llvmpipe / lp_jit.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * C - JIT interfaces
31 *
32 * @author Jose Fonseca <jfonseca@vmware.com>
33 */
34
35
36 #include <llvm-c/Transforms/Scalar.h>
37
38 #include "lp_screen.h"
39 #include "lp_jit.h"
40
41
42 void
43 lp_jit_screen_cleanup(struct llvmpipe_screen *screen)
44 {
45 if(screen->engine)
46 LLVMDisposeExecutionEngine(screen->engine);
47
48 if(screen->pass)
49 LLVMDisposePassManager(screen->pass);
50 }
51
52
53 void
54 lp_jit_screen_init(struct llvmpipe_screen *screen)
55 {
56 char *error = NULL;
57
58 screen->module = LLVMModuleCreateWithName("llvmpipe");
59
60 screen->provider = LLVMCreateModuleProviderForExistingModule(screen->module);
61
62 if (LLVMCreateJITCompiler(&screen->engine, screen->provider, 1, &error)) {
63 fprintf(stderr, "%s\n", error);
64 LLVMDisposeMessage(error);
65 abort();
66 }
67
68 screen->pass = LLVMCreateFunctionPassManager(screen->provider);
69 LLVMAddTargetData(LLVMGetExecutionEngineTargetData(screen->engine), screen->pass);
70 /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
71 * but there are more on SVN. */
72 LLVMAddConstantPropagationPass(screen->pass);
73 LLVMAddInstructionCombiningPass(screen->pass);
74 LLVMAddPromoteMemoryToRegisterPass(screen->pass);
75 LLVMAddGVNPass(screen->pass);
76 LLVMAddCFGSimplificationPass(screen->pass);
77 }