1/* Functions for high level gimple building routines. 2 Copyright (C) 2013-2015 Free Software Foundation, Inc. 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" 23#include "hash-set.h" 24#include "machmode.h" 25#include "vec.h" 26#include "double-int.h" 27#include "input.h" 28#include "alias.h" 29#include "symtab.h" 30#include "options.h" 31#include "wide-int.h" 32#include "inchash.h" 33#include "tree.h" 34#include "fold-const.h" 35#include "stringpool.h" 36#include "predict.h" 37#include "tm.h" 38#include "hard-reg-set.h" 39#include "input.h" 40#include "function.h" 41#include "basic-block.h" 42#include "tree-ssa-alias.h" 43#include "internal-fn.h" 44#include "gimple-expr.h" 45#include "is-a.h" 46#include "gimple.h" 47#include "tree-ssanames.h" 48 49 50/* Return the expression type to use based on the CODE and type of 51 the given operand OP. If the expression CODE is a comparison, 52 the returned type is boolean_type_node. Otherwise, it returns 53 the type of OP. */ 54 55static tree 56get_expr_type (enum tree_code code, tree op) 57{ 58 return (TREE_CODE_CLASS (code) == tcc_comparison) 59 ? boolean_type_node 60 : TREE_TYPE (op); 61} 62 63 64/* Build a new gimple assignment. The LHS of the assignment is a new 65 temporary whose type matches the given expression. MODE indicates 66 whether the LHS should be an SSA or a normal temporary. CODE is 67 the expression code for the RHS. OP1 is the first operand and VAL 68 is an integer value to be used as the second operand. */ 69 70gassign * 71build_assign (enum tree_code code, tree op1, int val, tree lhs) 72{ 73 tree op2 = build_int_cst (TREE_TYPE (op1), val); 74 if (lhs == NULL_TREE) 75 lhs = make_ssa_name (get_expr_type (code, op1)); 76 return gimple_build_assign (lhs, code, op1, op2); 77} 78 79gassign * 80build_assign (enum tree_code code, gimple g, int val, tree lhs ) 81{ 82 return build_assign (code, gimple_assign_lhs (g), val, lhs); 83} 84 85 86/* Build and return a new GIMPLE assignment. The new assignment will 87 have the opcode CODE and operands OP1 and OP2. The type of the 88 expression on the RHS is inferred to be the type of OP1. 89 90 The LHS of the statement will be an SSA name or a GIMPLE temporary 91 in normal form depending on the type of builder invoking this 92 function. */ 93 94gassign * 95build_assign (enum tree_code code, tree op1, tree op2, tree lhs) 96{ 97 if (lhs == NULL_TREE) 98 lhs = make_ssa_name (get_expr_type (code, op1)); 99 return gimple_build_assign (lhs, code, op1, op2); 100} 101 102gassign * 103build_assign (enum tree_code code, gimple op1, tree op2, tree lhs) 104{ 105 return build_assign (code, gimple_assign_lhs (op1), op2, lhs); 106} 107 108gassign * 109build_assign (enum tree_code code, tree op1, gimple op2, tree lhs) 110{ 111 return build_assign (code, op1, gimple_assign_lhs (op2), lhs); 112} 113 114gassign * 115build_assign (enum tree_code code, gimple op1, gimple op2, tree lhs) 116{ 117 return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2), 118 lhs); 119} 120 121 122/* Create and return a type cast assignment. This creates a NOP_EXPR 123 that converts OP to TO_TYPE. */ 124 125gassign * 126build_type_cast (tree to_type, tree op, tree lhs) 127{ 128 if (lhs == NULL_TREE) 129 lhs = make_ssa_name (to_type); 130 return gimple_build_assign (lhs, NOP_EXPR, op); 131} 132 133gassign * 134build_type_cast (tree to_type, gimple op, tree lhs) 135{ 136 return build_type_cast (to_type, gimple_assign_lhs (op), lhs); 137} 138 139 140 141