]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-builder.c
coretypes.h: Include hash-table.h and hash-set.h for host files.
[thirdparty/gcc.git] / gcc / gimple-builder.c
CommitLineData
ff2a63a7 1/* Functions for high level gimple building routines.
5624e564 2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
ff2a63a7
AM
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#include "config.h"
21#include "system.h"
22#include "coretypes.h"
40e23961
MC
23#include "input.h"
24#include "alias.h"
25#include "symtab.h"
26#include "options.h"
ff2a63a7 27#include "tree.h"
40e23961 28#include "fold-const.h"
d8a2d370 29#include "stringpool.h"
60393bbc 30#include "predict.h"
60393bbc
AM
31#include "tm.h"
32#include "hard-reg-set.h"
33#include "input.h"
34#include "function.h"
2fb9a547
AM
35#include "basic-block.h"
36#include "tree-ssa-alias.h"
37#include "internal-fn.h"
38#include "gimple-expr.h"
39#include "is-a.h"
ff2a63a7 40#include "gimple.h"
442b4905 41#include "tree-ssanames.h"
ff2a63a7
AM
42
43
44/* Return the expression type to use based on the CODE and type of
45 the given operand OP. If the expression CODE is a comparison,
46 the returned type is boolean_type_node. Otherwise, it returns
47 the type of OP. */
48
49static tree
50get_expr_type (enum tree_code code, tree op)
51{
52 return (TREE_CODE_CLASS (code) == tcc_comparison)
53 ? boolean_type_node
54 : TREE_TYPE (op);
55}
56
57
58/* Build a new gimple assignment. The LHS of the assignment is a new
59 temporary whose type matches the given expression. MODE indicates
60 whether the LHS should be an SSA or a normal temporary. CODE is
61 the expression code for the RHS. OP1 is the first operand and VAL
62 is an integer value to be used as the second operand. */
63
538dd0b7 64gassign *
ff2a63a7
AM
65build_assign (enum tree_code code, tree op1, int val, tree lhs)
66{
67 tree op2 = build_int_cst (TREE_TYPE (op1), val);
68 if (lhs == NULL_TREE)
b731b390 69 lhs = make_ssa_name (get_expr_type (code, op1));
0d0e4a03 70 return gimple_build_assign (lhs, code, op1, op2);
ff2a63a7
AM
71}
72
538dd0b7 73gassign *
ff2a63a7
AM
74build_assign (enum tree_code code, gimple g, int val, tree lhs )
75{
76 return build_assign (code, gimple_assign_lhs (g), val, lhs);
77}
78
79
80/* Build and return a new GIMPLE assignment. The new assignment will
81 have the opcode CODE and operands OP1 and OP2. The type of the
82 expression on the RHS is inferred to be the type of OP1.
83
84 The LHS of the statement will be an SSA name or a GIMPLE temporary
85 in normal form depending on the type of builder invoking this
86 function. */
87
538dd0b7 88gassign *
ff2a63a7
AM
89build_assign (enum tree_code code, tree op1, tree op2, tree lhs)
90{
91 if (lhs == NULL_TREE)
b731b390 92 lhs = make_ssa_name (get_expr_type (code, op1));
0d0e4a03 93 return gimple_build_assign (lhs, code, op1, op2);
ff2a63a7
AM
94}
95
538dd0b7 96gassign *
ff2a63a7
AM
97build_assign (enum tree_code code, gimple op1, tree op2, tree lhs)
98{
99 return build_assign (code, gimple_assign_lhs (op1), op2, lhs);
100}
101
538dd0b7 102gassign *
ff2a63a7
AM
103build_assign (enum tree_code code, tree op1, gimple op2, tree lhs)
104{
105 return build_assign (code, op1, gimple_assign_lhs (op2), lhs);
106}
107
538dd0b7 108gassign *
ff2a63a7
AM
109build_assign (enum tree_code code, gimple op1, gimple op2, tree lhs)
110{
111 return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2),
112 lhs);
113}
114
115
116/* Create and return a type cast assignment. This creates a NOP_EXPR
117 that converts OP to TO_TYPE. */
118
538dd0b7 119gassign *
ff2a63a7
AM
120build_type_cast (tree to_type, tree op, tree lhs)
121{
122 if (lhs == NULL_TREE)
b731b390 123 lhs = make_ssa_name (to_type);
0d0e4a03 124 return gimple_build_assign (lhs, NOP_EXPR, op);
ff2a63a7
AM
125}
126
538dd0b7 127gassign *
ff2a63a7
AM
128build_type_cast (tree to_type, gimple op, tree lhs)
129{
130 return build_type_cast (to_type, gimple_assign_lhs (op), lhs);
131}
132
133
134