blob: 4c225a0d4f91af0b7d3b50fbbf2ce78b9e71ab62 [file] [log] [blame]
José Fonseca87837322009-07-27 01:23:15 +01001/**************************************************************************
2 *
José Fonseca9a519ec2009-07-28 08:14:10 +01003 * Copyright 2009 VMware, Inc.
José Fonseca87837322009-07-27 01:23:15 +01004 * 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
José Fonsecac5531f52009-08-21 10:57:48 +010028/**
29 * LLVM control flow build helpers.
30 *
31 * @author Jose Fonseca <jfonseca@vmware.com>
32 */
33
34#ifndef LP_BLD_FLOW_H
35#define LP_BLD_FLOW_H
36
37
38#include <llvm-c/Core.h>
José Fonseca87837322009-07-27 01:23:15 +010039
40
José Fonsecab4835ea2009-09-14 11:05:06 +010041struct lp_type;
José Fonseca3d7a8862009-08-21 13:49:10 +010042
43
José Fonseca8e6b9252009-09-10 11:44:03 +010044struct lp_build_flow_context;
45
46
47struct lp_build_flow_context *
48lp_build_flow_create(LLVMBuilderRef builder);
49
50void
51lp_build_flow_destroy(struct lp_build_flow_context *flow);
52
53void
54lp_build_flow_scope_begin(struct lp_build_flow_context *flow);
55
56void
57lp_build_flow_scope_declare(struct lp_build_flow_context *flow,
58 LLVMValueRef *variable);
59
60void
61lp_build_flow_scope_end(struct lp_build_flow_context *flow);
62
63void
64lp_build_flow_skip_begin(struct lp_build_flow_context *flow);
65
66void
67lp_build_flow_skip_cond_break(struct lp_build_flow_context *flow,
68 LLVMValueRef cond);
69
70void
71lp_build_flow_skip_end(struct lp_build_flow_context *flow);
72
73
José Fonseca3d7a8862009-08-21 13:49:10 +010074struct lp_build_mask_context
75{
José Fonseca8e6b9252009-09-10 11:44:03 +010076 struct lp_build_flow_context *flow;
José Fonseca3d7a8862009-08-21 13:49:10 +010077
78 LLVMTypeRef reg_type;
79
80 LLVMValueRef value;
José Fonseca3d7a8862009-08-21 13:49:10 +010081};
82
83
84void
85lp_build_mask_begin(struct lp_build_mask_context *mask,
José Fonseca8e6b9252009-09-10 11:44:03 +010086 struct lp_build_flow_context *flow,
José Fonsecab4835ea2009-09-14 11:05:06 +010087 struct lp_type type,
José Fonseca3d7a8862009-08-21 13:49:10 +010088 LLVMValueRef value);
89
90/**
91 * Bitwise AND the mask with the given value, if a previous mask was set.
92 */
93void
94lp_build_mask_update(struct lp_build_mask_context *mask,
95 LLVMValueRef value);
96
97LLVMValueRef
98lp_build_mask_end(struct lp_build_mask_context *mask);
99
100
José Fonseca87837322009-07-27 01:23:15 +0100101/**
José Fonseca87837322009-07-27 01:23:15 +0100102 * LLVM's IR doesn't represent for-loops directly. Furthermore it
103 * it requires creating code blocks, branches, phi variables, so it
104 * requires a fair amount of code.
105 *
106 * @sa http://www.llvm.org/docs/tutorial/LangImpl5.html#for
107 */
José Fonsecac5531f52009-08-21 10:57:48 +0100108struct lp_build_loop_state
109{
110 LLVMBasicBlockRef block;
111 LLVMValueRef counter;
112};
José Fonseca87837322009-07-27 01:23:15 +0100113
114
115void
116lp_build_loop_begin(LLVMBuilderRef builder,
117 LLVMValueRef start,
José Fonsecac5531f52009-08-21 10:57:48 +0100118 struct lp_build_loop_state *state);
José Fonseca87837322009-07-27 01:23:15 +0100119
120
121void
122lp_build_loop_end(LLVMBuilderRef builder,
123 LLVMValueRef end,
124 LLVMValueRef step,
José Fonsecac5531f52009-08-21 10:57:48 +0100125 struct lp_build_loop_state *state);
José Fonseca87837322009-07-27 01:23:15 +0100126
José Fonseca87837322009-07-27 01:23:15 +0100127
José Fonseca87837322009-07-27 01:23:15 +0100128
Brian Paulbaeb3a22010-01-06 17:53:12 -0700129
130struct lp_build_if_state
131{
132 LLVMBuilderRef builder;
133 struct lp_build_flow_context *flow;
Brian Paulbaeb3a22010-01-06 17:53:12 -0700134};
135
136
137void
138lp_build_if(struct lp_build_if_state *ctx,
139 struct lp_build_flow_context *flow,
140 LLVMBuilderRef builder,
141 LLVMValueRef condition);
142
143void
Brian Paulbaeb3a22010-01-06 17:53:12 -0700144lp_build_else(struct lp_build_if_state *ctx);
145
146void
147lp_build_endif(struct lp_build_if_state *ctx);
148
149
150
José Fonsecac5531f52009-08-21 10:57:48 +0100151#endif /* !LP_BLD_FLOW_H */