Mercurial > hg > CbC > CbC_gcc
comparison gcc/hsa-gen.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* A pass for lowering gimple to HSAIL | 1 /* A pass for lowering gimple to HSAIL |
2 Copyright (C) 2013-2017 Free Software Foundation, Inc. | 2 Copyright (C) 2013-2018 Free Software Foundation, Inc. |
3 Contributed by Martin Jambor <mjambor@suse.cz> and | 3 Contributed by Martin Jambor <mjambor@suse.cz> and |
4 Martin Liska <mliska@suse.cz>. | 4 Martin Liska <mliska@suse.cz>. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
67 | 67 |
68 #define HSA_SORRY_ATV(location, message, ...) \ | 68 #define HSA_SORRY_ATV(location, message, ...) \ |
69 do \ | 69 do \ |
70 { \ | 70 { \ |
71 hsa_fail_cfun (); \ | 71 hsa_fail_cfun (); \ |
72 auto_diagnostic_group d; \ | |
72 if (warning_at (EXPR_LOCATION (hsa_cfun->m_decl), OPT_Whsa, \ | 73 if (warning_at (EXPR_LOCATION (hsa_cfun->m_decl), OPT_Whsa, \ |
73 HSA_SORRY_MSG)) \ | 74 HSA_SORRY_MSG)) \ |
74 inform (location, message, __VA_ARGS__); \ | 75 inform (location, message, __VA_ARGS__); \ |
75 } \ | 76 } \ |
76 while (false) | 77 while (false) |
79 | 80 |
80 #define HSA_SORRY_AT(location, message) \ | 81 #define HSA_SORRY_AT(location, message) \ |
81 do \ | 82 do \ |
82 { \ | 83 { \ |
83 hsa_fail_cfun (); \ | 84 hsa_fail_cfun (); \ |
85 auto_diagnostic_group d; \ | |
84 if (warning_at (EXPR_LOCATION (hsa_cfun->m_decl), OPT_Whsa, \ | 86 if (warning_at (EXPR_LOCATION (hsa_cfun->m_decl), OPT_Whsa, \ |
85 HSA_SORRY_MSG)) \ | 87 HSA_SORRY_MSG)) \ |
86 inform (location, message); \ | 88 inform (location, message); \ |
87 } \ | 89 } \ |
88 while (false) | 90 while (false) |
209 m_decl (fdecl), m_internal_fn (NULL), m_shadow_reg (NULL), | 211 m_decl (fdecl), m_internal_fn (NULL), m_shadow_reg (NULL), |
210 m_kernel_dispatch_count (0), m_maximum_omp_data_size (0), | 212 m_kernel_dispatch_count (0), m_maximum_omp_data_size (0), |
211 m_seen_error (false), m_temp_symbol_count (0), m_ssa_map (), | 213 m_seen_error (false), m_temp_symbol_count (0), m_ssa_map (), |
212 m_modified_cfg (modified_cfg) | 214 m_modified_cfg (modified_cfg) |
213 { | 215 { |
214 int sym_init_len = (vec_safe_length (cfun->local_decls) / 2) + 1;; | 216 int sym_init_len = (vec_safe_length (cfun->local_decls) / 2) + 1; |
215 m_local_symbols = new hash_table <hsa_noop_symbol_hasher> (sym_init_len); | 217 m_local_symbols = new hash_table <hsa_noop_symbol_hasher> (sym_init_len); |
216 m_ssa_map.safe_grow_cleared (ssa_names_count); | 218 m_ssa_map.safe_grow_cleared (ssa_names_count); |
217 } | 219 } |
218 | 220 |
219 /* Constructor of class representing HSA function information that | 221 /* Constructor of class representing HSA function information that |
689 mem_type_for_type (BrigType16_t type) | 691 mem_type_for_type (BrigType16_t type) |
690 { | 692 { |
691 /* HSA has non-intuitive constraints on load/store types. If it's | 693 /* HSA has non-intuitive constraints on load/store types. If it's |
692 a bit-type it _must_ be B128, if it's not a bit-type it must be | 694 a bit-type it _must_ be B128, if it's not a bit-type it must be |
693 64bit max. So for loading entities of 128 bits (e.g. vectors) | 695 64bit max. So for loading entities of 128 bits (e.g. vectors) |
694 we have to to B128, while for loading the rest we have to use the | 696 we have to use B128, while for loading the rest we have to use the |
695 input type (??? or maybe also flattened to a equally sized non-vector | 697 input type (??? or maybe also flattened to a equally sized non-vector |
696 unsigned type?). */ | 698 unsigned type?). */ |
697 if ((type & BRIG_TYPE_PACK_MASK) == BRIG_TYPE_PACK_128) | 699 if ((type & BRIG_TYPE_PACK_MASK) == BRIG_TYPE_PACK_128) |
698 return BRIG_TYPE_B128; | 700 return BRIG_TYPE_B128; |
699 else if (hsa_btype_p (type) || hsa_type_packed_p (type)) | 701 else if (hsa_btype_p (type) || hsa_type_packed_p (type)) |
930 allocation = BRIG_ALLOCATION_AGENT; | 932 allocation = BRIG_ALLOCATION_AGENT; |
931 } | 933 } |
932 else if (lookup_attribute ("hsa_group_segment", | 934 else if (lookup_attribute ("hsa_group_segment", |
933 DECL_ATTRIBUTES (decl))) | 935 DECL_ATTRIBUTES (decl))) |
934 segment = BRIG_SEGMENT_GROUP; | 936 segment = BRIG_SEGMENT_GROUP; |
935 else if (TREE_STATIC (decl) | 937 else if (TREE_STATIC (decl)) |
936 || lookup_attribute ("hsa_global_segment", | 938 { |
937 DECL_ATTRIBUTES (decl))) | 939 segment = BRIG_SEGMENT_GLOBAL; |
940 allocation = BRIG_ALLOCATION_PROGRAM; | |
941 } | |
942 else if (lookup_attribute ("hsa_global_segment", | |
943 DECL_ATTRIBUTES (decl))) | |
938 segment = BRIG_SEGMENT_GLOBAL; | 944 segment = BRIG_SEGMENT_GLOBAL; |
939 else | 945 else |
940 segment = BRIG_SEGMENT_PRIVATE; | 946 segment = BRIG_SEGMENT_PRIVATE; |
941 | 947 |
942 sym = new hsa_symbol (BRIG_TYPE_NONE, segment, BRIG_LINKAGE_FUNCTION, | 948 sym = new hsa_symbol (BRIG_TYPE_NONE, segment, BRIG_LINKAGE_FUNCTION, |
955 function declaration. */ | 961 function declaration. */ |
956 | 962 |
957 tree | 963 tree |
958 hsa_get_host_function (tree decl) | 964 hsa_get_host_function (tree decl) |
959 { | 965 { |
960 hsa_function_summary *s | 966 hsa_function_summary *s = hsa_summaries->get (cgraph_node::get_create (decl)); |
961 = hsa_summaries->get (cgraph_node::get_create (decl)); | |
962 gcc_assert (s->m_kind != HSA_NONE); | |
963 gcc_assert (s->m_gpu_implementation_p); | 967 gcc_assert (s->m_gpu_implementation_p); |
964 | 968 |
965 return s->m_bound_function ? s->m_bound_function->decl : NULL; | 969 return s->m_bound_function ? s->m_bound_function->decl : NULL; |
966 } | 970 } |
967 | 971 |
971 get_brig_function_name (tree decl) | 975 get_brig_function_name (tree decl) |
972 { | 976 { |
973 tree d = decl; | 977 tree d = decl; |
974 | 978 |
975 hsa_function_summary *s = hsa_summaries->get (cgraph_node::get_create (d)); | 979 hsa_function_summary *s = hsa_summaries->get (cgraph_node::get_create (d)); |
976 if (s->m_kind != HSA_NONE | 980 if (s != NULL |
977 && s->m_gpu_implementation_p | 981 && s->m_gpu_implementation_p |
978 && s->m_bound_function) | 982 && s->m_bound_function) |
979 d = s->m_bound_function->decl; | 983 d = s->m_bound_function->decl; |
980 | 984 |
981 /* IPA split can create a function that has no host equivalent. */ | 985 /* IPA split can create a function that has no host equivalent. */ |
1957 { | 1961 { |
1958 symbol = hsa_get_string_cst_symbol (ref); | 1962 symbol = hsa_get_string_cst_symbol (ref); |
1959 goto out; | 1963 goto out; |
1960 } | 1964 } |
1961 else if (TREE_CODE (ref) == BIT_FIELD_REF | 1965 else if (TREE_CODE (ref) == BIT_FIELD_REF |
1962 && ((tree_to_uhwi (TREE_OPERAND (ref, 1)) % BITS_PER_UNIT) != 0 | 1966 && (!multiple_p (bit_field_size (ref), BITS_PER_UNIT) |
1963 || (tree_to_uhwi (TREE_OPERAND (ref, 2)) % BITS_PER_UNIT) != 0)) | 1967 || !multiple_p (bit_field_offset (ref), BITS_PER_UNIT))) |
1964 { | 1968 { |
1965 HSA_SORRY_ATV (EXPR_LOCATION (origref), | 1969 HSA_SORRY_ATV (EXPR_LOCATION (origref), |
1966 "support for HSA does not implement " | 1970 "support for HSA does not implement " |
1967 "bit field references such as %E", ref); | 1971 "bit field references such as %E", ref); |
1968 goto out; | 1972 goto out; |
1970 | 1974 |
1971 if (handled_component_p (ref)) | 1975 if (handled_component_p (ref)) |
1972 { | 1976 { |
1973 machine_mode mode; | 1977 machine_mode mode; |
1974 int unsignedp, volatilep, preversep; | 1978 int unsignedp, volatilep, preversep; |
1975 | 1979 poly_int64 pbitsize, pbitpos; |
1976 ref = get_inner_reference (ref, &bitsize, &bitpos, &varoffset, &mode, | 1980 tree new_ref; |
1977 &unsignedp, &preversep, &volatilep); | 1981 |
1978 | 1982 new_ref = get_inner_reference (ref, &pbitsize, &pbitpos, &varoffset, |
1979 offset = bitpos; | 1983 &mode, &unsignedp, &preversep, |
1980 offset = wi::rshift (offset, LOG2_BITS_PER_UNIT, SIGNED); | 1984 &volatilep); |
1985 /* When this isn't true, the switch below will report an | |
1986 appropriate error. */ | |
1987 if (pbitsize.is_constant () && pbitpos.is_constant ()) | |
1988 { | |
1989 bitsize = pbitsize.to_constant (); | |
1990 bitpos = pbitpos.to_constant (); | |
1991 ref = new_ref; | |
1992 offset = bitpos; | |
1993 offset = wi::rshift (offset, LOG2_BITS_PER_UNIT, SIGNED); | |
1994 } | |
1981 } | 1995 } |
1982 | 1996 |
1983 switch (TREE_CODE (ref)) | 1997 switch (TREE_CODE (ref)) |
1984 { | 1998 { |
1985 case ADDR_EXPR: | 1999 case ADDR_EXPR: |
3162 "FLOOR_MOD_EXPR or ROUND_MOD_EXPR"); | 3176 "FLOOR_MOD_EXPR or ROUND_MOD_EXPR"); |
3163 return; | 3177 return; |
3164 case NEGATE_EXPR: | 3178 case NEGATE_EXPR: |
3165 opcode = BRIG_OPCODE_NEG; | 3179 opcode = BRIG_OPCODE_NEG; |
3166 break; | 3180 break; |
3167 case FMA_EXPR: | |
3168 /* There is a native HSA instruction for scalar FMAs but not for vector | |
3169 ones. */ | |
3170 if (TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE) | |
3171 { | |
3172 hsa_op_reg *dest | |
3173 = hsa_cfun->reg_for_gimple_ssa (gimple_assign_lhs (assign)); | |
3174 hsa_op_with_type *op1 = hsa_reg_or_immed_for_gimple_op (rhs1, hbb); | |
3175 hsa_op_with_type *op2 = hsa_reg_or_immed_for_gimple_op (rhs2, hbb); | |
3176 hsa_op_with_type *op3 = hsa_reg_or_immed_for_gimple_op (rhs3, hbb); | |
3177 hsa_op_reg *tmp = new hsa_op_reg (dest->m_type); | |
3178 gen_hsa_binary_operation (BRIG_OPCODE_MUL, tmp, op1, op2, hbb); | |
3179 gen_hsa_binary_operation (BRIG_OPCODE_ADD, dest, tmp, op3, hbb); | |
3180 return; | |
3181 } | |
3182 opcode = BRIG_OPCODE_MAD; | |
3183 break; | |
3184 case MIN_EXPR: | 3181 case MIN_EXPR: |
3185 opcode = BRIG_OPCODE_MIN; | 3182 opcode = BRIG_OPCODE_MIN; |
3186 break; | 3183 break; |
3187 case MAX_EXPR: | 3184 case MAX_EXPR: |
3188 opcode = BRIG_OPCODE_MAX; | 3185 opcode = BRIG_OPCODE_MAX; |
3476 /* Create preambule that verifies that index - lowest_label >= 0. */ | 3473 /* Create preambule that verifies that index - lowest_label >= 0. */ |
3477 edge e = split_block (hbb->m_bb, gsi_stmt (it)); | 3474 edge e = split_block (hbb->m_bb, gsi_stmt (it)); |
3478 e->flags &= ~EDGE_FALLTHRU; | 3475 e->flags &= ~EDGE_FALLTHRU; |
3479 e->flags |= EDGE_TRUE_VALUE; | 3476 e->flags |= EDGE_TRUE_VALUE; |
3480 | 3477 |
3481 function *func = DECL_STRUCT_FUNCTION (current_function_decl); | |
3482 tree index_tree = gimple_switch_index (s); | 3478 tree index_tree = gimple_switch_index (s); |
3483 tree lowest = get_switch_low (s); | 3479 tree lowest = get_switch_low (s); |
3484 tree highest = get_switch_high (s); | 3480 tree highest = get_switch_high (s); |
3485 | 3481 |
3486 hsa_op_reg *index = hsa_cfun->reg_for_gimple_ssa (index_tree); | 3482 hsa_op_reg *index = hsa_cfun->reg_for_gimple_ssa (index_tree); |
3500 hbb->append_insn (new hsa_insn_basic (3, BRIG_OPCODE_AND, cmp_reg->m_type, | 3496 hbb->append_insn (new hsa_insn_basic (3, BRIG_OPCODE_AND, cmp_reg->m_type, |
3501 cmp_reg, cmp1_reg, cmp2_reg)); | 3497 cmp_reg, cmp1_reg, cmp2_reg)); |
3502 | 3498 |
3503 hbb->append_insn (new hsa_insn_cbr (cmp_reg)); | 3499 hbb->append_insn (new hsa_insn_cbr (cmp_reg)); |
3504 | 3500 |
3505 tree default_label = gimple_switch_default_label (s); | 3501 basic_block default_label_bb = gimple_switch_default_bb (cfun, s); |
3506 basic_block default_label_bb = label_to_block_fn (func, | |
3507 CASE_LABEL (default_label)); | |
3508 | 3502 |
3509 if (!gimple_seq_empty_p (phi_nodes (default_label_bb))) | 3503 if (!gimple_seq_empty_p (phi_nodes (default_label_bb))) |
3510 { | 3504 { |
3511 default_label_bb = split_edge (find_edge (e->dest, default_label_bb)); | 3505 default_label_bb = split_edge (find_edge (e->dest, default_label_bb)); |
3512 hsa_init_new_bb (default_label_bb); | 3506 hsa_init_new_bb (default_label_bb); |
3537 | 3531 |
3538 /* Iterate all labels and fill up the jump table. */ | 3532 /* Iterate all labels and fill up the jump table. */ |
3539 for (unsigned i = 1; i < labels; i++) | 3533 for (unsigned i = 1; i < labels; i++) |
3540 { | 3534 { |
3541 tree label = gimple_switch_label (s, i); | 3535 tree label = gimple_switch_label (s, i); |
3542 basic_block bb = label_to_block_fn (func, CASE_LABEL (label)); | 3536 basic_block bb = label_to_block (cfun, CASE_LABEL (label)); |
3543 | 3537 |
3544 unsigned HOST_WIDE_INT sub_low | 3538 unsigned HOST_WIDE_INT sub_low |
3545 = tree_to_uhwi (int_const_binop (MINUS_EXPR, CASE_LOW (label), lowest)); | 3539 = tree_to_uhwi (int_const_binop (MINUS_EXPR, CASE_LOW (label), lowest)); |
3546 | 3540 |
3547 unsigned HOST_WIDE_INT sub_high = sub_low; | 3541 unsigned HOST_WIDE_INT sub_high = sub_low; |
4474 src_type, NULL, dest0, dest1); | 4468 src_type, NULL, dest0, dest1); |
4475 hbb->append_insn (insn); | 4469 hbb->append_insn (insn); |
4476 insn->set_output_in_type (dest, 0, hbb); | 4470 insn->set_output_in_type (dest, 0, hbb); |
4477 } | 4471 } |
4478 | 4472 |
4473 /* Emit instructions that implement FMA, FMS, FNMA or FNMS call STMT. | |
4474 Instructions are appended to basic block HBB. NEGATE1 is true for | |
4475 FNMA and FNMS. NEGATE3 is true for FMS and FNMS. */ | |
4476 | |
4477 static void | |
4478 gen_hsa_fma (gcall *call, hsa_bb *hbb, bool negate1, bool negate3) | |
4479 { | |
4480 tree lhs = gimple_call_lhs (call); | |
4481 if (lhs == NULL_TREE) | |
4482 return; | |
4483 | |
4484 tree rhs1 = gimple_call_arg (call, 0); | |
4485 tree rhs2 = gimple_call_arg (call, 1); | |
4486 tree rhs3 = gimple_call_arg (call, 2); | |
4487 | |
4488 hsa_op_reg *dest = hsa_cfun->reg_for_gimple_ssa (lhs); | |
4489 hsa_op_with_type *op1 = hsa_reg_or_immed_for_gimple_op (rhs1, hbb); | |
4490 hsa_op_with_type *op2 = hsa_reg_or_immed_for_gimple_op (rhs2, hbb); | |
4491 hsa_op_with_type *op3 = hsa_reg_or_immed_for_gimple_op (rhs3, hbb); | |
4492 | |
4493 if (negate1) | |
4494 { | |
4495 hsa_op_reg *tmp = new hsa_op_reg (dest->m_type); | |
4496 gen_hsa_unary_operation (BRIG_OPCODE_NEG, tmp, op1, hbb); | |
4497 op1 = tmp; | |
4498 } | |
4499 | |
4500 /* There is a native HSA instruction for scalar FMAs but not for vector | |
4501 ones. */ | |
4502 if (TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE) | |
4503 { | |
4504 hsa_op_reg *tmp = new hsa_op_reg (dest->m_type); | |
4505 gen_hsa_binary_operation (BRIG_OPCODE_MUL, tmp, op1, op2, hbb); | |
4506 gen_hsa_binary_operation (negate3 ? BRIG_OPCODE_SUB : BRIG_OPCODE_ADD, | |
4507 dest, tmp, op3, hbb); | |
4508 } | |
4509 else | |
4510 { | |
4511 if (negate3) | |
4512 { | |
4513 hsa_op_reg *tmp = new hsa_op_reg (dest->m_type); | |
4514 gen_hsa_unary_operation (BRIG_OPCODE_NEG, tmp, op3, hbb); | |
4515 op3 = tmp; | |
4516 } | |
4517 hsa_insn_basic *insn = new hsa_insn_basic (4, BRIG_OPCODE_MAD, | |
4518 dest->m_type, dest, | |
4519 op1, op2, op3); | |
4520 hbb->append_insn (insn); | |
4521 } | |
4522 } | |
4523 | |
4479 /* Set VALUE to a shadow kernel debug argument and append a new instruction | 4524 /* Set VALUE to a shadow kernel debug argument and append a new instruction |
4480 to HBB basic block. */ | 4525 to HBB basic block. */ |
4481 | 4526 |
4482 static void | 4527 static void |
4483 set_debug_value (hsa_bb *hbb, hsa_op_with_type *value) | 4528 set_debug_value (hsa_bb *hbb, hsa_op_with_type *value) |
5208 case IFN_FMIN: | 5253 case IFN_FMIN: |
5209 case IFN_FMAX: | 5254 case IFN_FMAX: |
5210 gen_hsa_insns_for_call_of_internal_fn (stmt, hbb); | 5255 gen_hsa_insns_for_call_of_internal_fn (stmt, hbb); |
5211 break; | 5256 break; |
5212 | 5257 |
5258 case IFN_FMA: | |
5259 gen_hsa_fma (stmt, hbb, false, false); | |
5260 break; | |
5261 | |
5262 case IFN_FMS: | |
5263 gen_hsa_fma (stmt, hbb, false, true); | |
5264 break; | |
5265 | |
5266 case IFN_FNMA: | |
5267 gen_hsa_fma (stmt, hbb, true, false); | |
5268 break; | |
5269 | |
5270 case IFN_FNMS: | |
5271 gen_hsa_fma (stmt, hbb, true, true); | |
5272 break; | |
5273 | |
5213 default: | 5274 default: |
5214 HSA_SORRY_ATV (gimple_location (stmt), | 5275 HSA_SORRY_ATV (gimple_location (stmt), |
5215 "support for HSA does not implement internal function: %s", | 5276 "support for HSA does not implement internal function: %s", |
5216 internal_fn_name (fn)); | 5277 internal_fn_name (fn)); |
5217 break; | 5278 break; |
5237 if (!gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) | 5298 if (!gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) |
5238 { | 5299 { |
5239 tree function_decl = gimple_call_fndecl (stmt); | 5300 tree function_decl = gimple_call_fndecl (stmt); |
5240 /* Prefetch pass can create type-mismatching prefetch builtin calls which | 5301 /* Prefetch pass can create type-mismatching prefetch builtin calls which |
5241 fail the gimple_call_builtin_p test above. Handle them here. */ | 5302 fail the gimple_call_builtin_p test above. Handle them here. */ |
5242 if (DECL_BUILT_IN_CLASS (function_decl) | 5303 if (fndecl_built_in_p (function_decl, BUILT_IN_PREFETCH)) |
5243 && DECL_FUNCTION_CODE (function_decl) == BUILT_IN_PREFETCH) | |
5244 return; | 5304 return; |
5245 | 5305 |
5246 if (function_decl == NULL_TREE) | 5306 if (function_decl == NULL_TREE) |
5247 { | 5307 { |
5248 HSA_SORRY_AT (gimple_location (stmt), | 5308 HSA_SORRY_AT (gimple_location (stmt), |
6224 */ | 6284 */ |
6225 | 6285 |
6226 static bool | 6286 static bool |
6227 convert_switch_statements (void) | 6287 convert_switch_statements (void) |
6228 { | 6288 { |
6229 function *func = DECL_STRUCT_FUNCTION (current_function_decl); | |
6230 basic_block bb; | 6289 basic_block bb; |
6231 | 6290 |
6232 bool modified_cfg = false; | 6291 bool modified_cfg = false; |
6233 | 6292 |
6234 FOR_EACH_BB_FN (bb, func) | 6293 FOR_EACH_BB_FN (bb, cfun) |
6235 { | 6294 { |
6236 gimple_stmt_iterator gsi = gsi_last_bb (bb); | 6295 gimple_stmt_iterator gsi = gsi_last_bb (bb); |
6237 if (gsi_end_p (gsi)) | 6296 if (gsi_end_p (gsi)) |
6238 continue; | 6297 continue; |
6239 | 6298 |
6252 unsigned labels = gimple_switch_num_labels (s); | 6311 unsigned labels = gimple_switch_num_labels (s); |
6253 tree index = gimple_switch_index (s); | 6312 tree index = gimple_switch_index (s); |
6254 tree index_type = TREE_TYPE (index); | 6313 tree index_type = TREE_TYPE (index); |
6255 tree default_label = gimple_switch_default_label (s); | 6314 tree default_label = gimple_switch_default_label (s); |
6256 basic_block default_label_bb | 6315 basic_block default_label_bb |
6257 = label_to_block_fn (func, CASE_LABEL (default_label)); | 6316 = label_to_block (cfun, CASE_LABEL (default_label)); |
6258 basic_block cur_bb = bb; | 6317 basic_block cur_bb = bb; |
6259 | 6318 |
6260 auto_vec <edge> new_edges; | 6319 auto_vec <edge> new_edges; |
6261 auto_vec <phi_definition *> phi_todo_list; | 6320 auto_vec <phi_definition *> phi_todo_list; |
6262 auto_vec <profile_count> edge_counts; | 6321 auto_vec <profile_count> edge_counts; |
6264 | 6323 |
6265 /* Investigate all labels that and PHI nodes in these edges which | 6324 /* Investigate all labels that and PHI nodes in these edges which |
6266 should be fixed after we add new collection of edges. */ | 6325 should be fixed after we add new collection of edges. */ |
6267 for (unsigned i = 0; i < labels; i++) | 6326 for (unsigned i = 0; i < labels; i++) |
6268 { | 6327 { |
6269 tree label = gimple_switch_label (s, i); | 6328 basic_block label_bb = gimple_switch_label_bb (cfun, s, i); |
6270 basic_block label_bb = label_to_block_fn (func, CASE_LABEL (label)); | |
6271 edge e = find_edge (bb, label_bb); | 6329 edge e = find_edge (bb, label_bb); |
6272 edge_counts.safe_push (e->count ()); | 6330 edge_counts.safe_push (e->count ()); |
6273 edge_probabilities.safe_push (e->probability); | 6331 edge_probabilities.safe_push (e->probability); |
6274 gphi_iterator phi_gsi; | 6332 gphi_iterator phi_gsi; |
6275 | 6333 |
6347 | 6405 |
6348 gimple_set_location (c, gimple_location (stmt)); | 6406 gimple_set_location (c, gimple_location (stmt)); |
6349 | 6407 |
6350 gsi_insert_before (&cond_gsi, c, GSI_SAME_STMT); | 6408 gsi_insert_before (&cond_gsi, c, GSI_SAME_STMT); |
6351 | 6409 |
6352 basic_block label_bb | 6410 basic_block label_bb = label_to_block (cfun, CASE_LABEL (label)); |
6353 = label_to_block_fn (func, CASE_LABEL (label)); | |
6354 edge new_edge = make_edge (cur_bb, label_bb, EDGE_TRUE_VALUE); | 6411 edge new_edge = make_edge (cur_bb, label_bb, EDGE_TRUE_VALUE); |
6355 profile_probability prob_sum = sum_slice <profile_probability> | 6412 profile_probability prob_sum = sum_slice <profile_probability> |
6356 (edge_probabilities, i, labels, profile_probability::never ()) | 6413 (edge_probabilities, i, labels, profile_probability::never ()) |
6357 + edge_probabilities[0]; | 6414 + edge_probabilities[0]; |
6358 | 6415 |
6372 loops_state_set (LOOPS_NEED_FIXUP); | 6429 loops_state_set (LOOPS_NEED_FIXUP); |
6373 } | 6430 } |
6374 | 6431 |
6375 edge next_edge = make_edge (cur_bb, next_bb, EDGE_FALSE_VALUE); | 6432 edge next_edge = make_edge (cur_bb, next_bb, EDGE_FALSE_VALUE); |
6376 next_edge->probability = new_edge->probability.invert (); | 6433 next_edge->probability = new_edge->probability.invert (); |
6377 next_bb->frequency = EDGE_FREQUENCY (next_edge); | 6434 next_bb->count = next_edge->count (); |
6378 cur_bb = next_bb; | 6435 cur_bb = next_bb; |
6379 } | 6436 } |
6380 else /* Link last IF statement and default label | 6437 else /* Link last IF statement and default label |
6381 of the switch. */ | 6438 of the switch. */ |
6382 { | 6439 { |
6415 /* Expand builtins that can't be handled by HSA back-end. */ | 6472 /* Expand builtins that can't be handled by HSA back-end. */ |
6416 | 6473 |
6417 static void | 6474 static void |
6418 expand_builtins () | 6475 expand_builtins () |
6419 { | 6476 { |
6420 function *func = DECL_STRUCT_FUNCTION (current_function_decl); | |
6421 basic_block bb; | 6477 basic_block bb; |
6422 | 6478 |
6423 FOR_EACH_BB_FN (bb, func) | 6479 FOR_EACH_BB_FN (bb, cfun) |
6424 { | 6480 { |
6425 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); | 6481 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi); |
6426 gsi_next (&gsi)) | 6482 gsi_next (&gsi)) |
6427 { | 6483 { |
6428 gimple *stmt = gsi_stmt (gsi); | 6484 gimple *stmt = gsi_stmt (gsi); |
6543 init_hsa_num_threads (); | 6599 init_hsa_num_threads (); |
6544 | 6600 |
6545 if (hsa_cfun->m_kern_p) | 6601 if (hsa_cfun->m_kern_p) |
6546 { | 6602 { |
6547 hsa_function_summary *s | 6603 hsa_function_summary *s |
6548 = hsa_summaries->get (cgraph_node::get (hsa_cfun->m_decl)); | 6604 = hsa_summaries->get_create (cgraph_node::get (hsa_cfun->m_decl)); |
6549 hsa_add_kern_decl_mapping (current_function_decl, hsa_cfun->m_name, | 6605 hsa_add_kern_decl_mapping (current_function_decl, hsa_cfun->m_name, |
6550 hsa_cfun->m_maximum_omp_data_size, | 6606 hsa_cfun->m_maximum_omp_data_size, |
6551 s->m_gridified_kernel_p); | 6607 s->m_gridified_kernel_p); |
6552 } | 6608 } |
6553 | 6609 |
6613 } | 6669 } |
6614 | 6670 |
6615 unsigned int | 6671 unsigned int |
6616 pass_gen_hsail::execute (function *) | 6672 pass_gen_hsail::execute (function *) |
6617 { | 6673 { |
6618 hsa_function_summary *s | 6674 cgraph_node *node = cgraph_node::get_create (current_function_decl); |
6619 = hsa_summaries->get (cgraph_node::get_create (current_function_decl)); | 6675 hsa_function_summary *s = hsa_summaries->get_create (node); |
6620 | 6676 |
6621 expand_builtins (); | 6677 expand_builtins (); |
6622 generate_hsa (s->m_kind == HSA_KERNEL); | 6678 generate_hsa (s->m_kind == HSA_KERNEL); |
6623 TREE_ASM_WRITTEN (current_function_decl) = 1; | 6679 TREE_ASM_WRITTEN (current_function_decl) = 1; |
6624 return TODO_discard_function; | 6680 return TODO_discard_function; |