]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-builder.c
switch from gimple to gimple*
[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 23#include "alias.h"
c7131fb2 24#include "backend.h"
ff2a63a7 25#include "tree.h"
c7131fb2
AM
26#include "gimple.h"
27#include "hard-reg-set.h"
28#include "options.h"
40e23961 29#include "fold-const.h"
d8a2d370 30#include "stringpool.h"
2fb9a547 31#include "internal-fn.h"
442b4905 32#include "tree-ssanames.h"
ff2a63a7
AM
33
34
35/* Return the expression type to use based on the CODE and type of
36 the given operand OP. If the expression CODE is a comparison,
37 the returned type is boolean_type_node. Otherwise, it returns
38 the type of OP. */
39
40static tree
41get_expr_type (enum tree_code code, tree op)
42{
43 return (TREE_CODE_CLASS (code) == tcc_comparison)
44 ? boolean_type_node
45 : TREE_TYPE (op);
46}
47
48
49/* Build a new gimple assignment. The LHS of the assignment is a new
50 temporary whose type matches the given expression. MODE indicates
51 whether the LHS should be an SSA or a normal temporary. CODE is
52 the expression code for the RHS. OP1 is the first operand and VAL
53 is an integer value to be used as the second operand. */
54
538dd0b7 55gassign *
ff2a63a7
AM
56build_assign (enum tree_code code, tree op1, int val, tree lhs)
57{
58 tree op2 = build_int_cst (TREE_TYPE (op1), val);
59 if (lhs == NULL_TREE)
b731b390 60 lhs = make_ssa_name (get_expr_type (code, op1));
0d0e4a03 61 return gimple_build_assign (lhs, code, op1, op2);
ff2a63a7
AM
62}
63
538dd0b7 64gassign *
355fe088 65build_assign (enum tree_code code, gimple *g, int val, tree lhs )
ff2a63a7
AM
66{
67 return build_assign (code, gimple_assign_lhs (g), val, lhs);
68}
69
70
71/* Build and return a new GIMPLE assignment. The new assignment will
72 have the opcode CODE and operands OP1 and OP2. The type of the
73 expression on the RHS is inferred to be the type of OP1.
74
75 The LHS of the statement will be an SSA name or a GIMPLE temporary
76 in normal form depending on the type of builder invoking this
77 function. */
78
538dd0b7 79gassign *
ff2a63a7
AM
80build_assign (enum tree_code code, tree op1, tree op2, tree lhs)
81{
82 if (lhs == NULL_TREE)
b731b390 83 lhs = make_ssa_name (get_expr_type (code, op1));
0d0e4a03 84 return gimple_build_assign (lhs, code, op1, op2);
ff2a63a7
AM
85}
86
538dd0b7 87gassign *
355fe088 88build_assign (enum tree_code code, gimple *op1, tree op2, tree lhs)
ff2a63a7
AM
89{
90 return build_assign (code, gimple_assign_lhs (op1), op2, lhs);
91}
92
538dd0b7 93gassign *
355fe088 94build_assign (enum tree_code code, tree op1, gimple *op2, tree lhs)
ff2a63a7
AM
95{
96 return build_assign (code, op1, gimple_assign_lhs (op2), lhs);
97}
98
538dd0b7 99gassign *
355fe088 100build_assign (enum tree_code code, gimple *op1, gimple *op2, tree lhs)
ff2a63a7
AM
101{
102 return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2),
103 lhs);
104}
105
106
107/* Create and return a type cast assignment. This creates a NOP_EXPR
108 that converts OP to TO_TYPE. */
109
538dd0b7 110gassign *
ff2a63a7
AM
111build_type_cast (tree to_type, tree op, tree lhs)
112{
113 if (lhs == NULL_TREE)
b731b390 114 lhs = make_ssa_name (to_type);
0d0e4a03 115 return gimple_build_assign (lhs, NOP_EXPR, op);
ff2a63a7
AM
116}
117
538dd0b7 118gassign *
355fe088 119build_type_cast (tree to_type, gimple *op, tree lhs)
ff2a63a7
AM
120{
121 return build_type_cast (to_type, gimple_assign_lhs (op), lhs);
122}
123
124
125