Skip to content

Commit e52b7cd

Browse files
committed
Switch try_catch to the region API
1 parent e77fc74 commit e52b7cd

6 files changed

Lines changed: 74 additions & 68 deletions

File tree

gcc/jit/jit-playback.cc

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,42 +2616,47 @@ add_eval (location *loc,
26162616
void
26172617
playback::block::
26182618
add_try_catch (location *loc,
2619-
block *try_block,
2620-
block *catch_block,
2619+
recording::region *try_region,
2620+
recording::region *catch_region,
26212621
bool is_finally)
26222622
{
2623-
gcc_assert (try_block);
2624-
gcc_assert (catch_block);
2623+
gcc_assert (try_region);
2624+
gcc_assert (catch_region);
26252625

2626-
try_block->m_is_try_or_catch = true;
2627-
catch_block->m_is_try_or_catch = true;
2628-
2629-
if (loc)
2626+
auto_vec<block *> try_blocks;
2627+
auto_vec<block *> handler_blocks;
2628+
unsigned i;
2629+
recording::block *try_block;
2630+
FOR_EACH_VEC_ELT (try_region->get_blocks (), i, try_block)
26302631
{
2631-
set_tree_location (try_block->as_label_decl (), loc);
2632-
set_tree_location (catch_block->as_label_decl (), loc);
2632+
block *b = try_block->playback_block ();
2633+
gcc_assert (b);
2634+
try_blocks.safe_push (b);
26332635
}
2634-
2635-
tree try_body = alloc_stmt_list ();
2636-
unsigned int i;
2637-
tree stmt;
2638-
FOR_EACH_VEC_ELT (try_block->m_stmts, i, stmt) {
2639-
append_to_statement_list (stmt, &try_body);
2636+
FOR_EACH_VEC_ELT (catch_region->get_blocks (), i, try_block)
2637+
{
2638+
block *b = try_block->playback_block ();
2639+
gcc_assert (b);
2640+
handler_blocks.safe_push (b);
26402641
}
26412642

2642-
tree handler_body = alloc_stmt_list ();
2643-
unsigned int j;
2644-
tree handler_stmt;
2645-
FOR_EACH_VEC_ELT (catch_block->m_stmts, j, handler_stmt) {
2646-
append_to_statement_list (handler_stmt, &handler_body);
2647-
}
2643+
tree try_body
2644+
= block::assemble_region_body (&try_blocks);
2645+
tree handler_body
2646+
= block::assemble_region_body (&handler_blocks);
26482647

2648+
tree stmt;
26492649
if (is_finally)
2650-
add_stmt (build2 (TRY_FINALLY_EXPR, void_type_node,
2651-
try_body, handler_body));
2650+
stmt = build2 (TRY_FINALLY_EXPR, void_type_node,
2651+
try_body, handler_body);
26522652
else
2653-
add_stmt (build2 (TRY_CATCH_EXPR, void_type_node, try_body,
2654-
build2 (CATCH_EXPR, void_type_node, NULL, handler_body)));
2653+
stmt = build2 (TRY_CATCH_EXPR, void_type_node, try_body,
2654+
build2 (CATCH_EXPR, void_type_node, NULL, handler_body));
2655+
2656+
if (loc)
2657+
set_tree_location (stmt, loc);
2658+
2659+
add_stmt (stmt);
26552660
}
26562661

26572662
/* Add an assignment to the function's statement list. */

gcc/jit/jit-playback.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,8 @@ class block : public wrapper
704704

705705
void
706706
add_try_catch (location *loc,
707-
block *try_block,
708-
block *catch_block,
707+
recording::region *try_region,
708+
recording::region *catch_region,
709709
bool is_finally);
710710

711711
void

gcc/jit/jit-recording.cc

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5398,14 +5398,11 @@ recording::block::add_eval (recording::location *loc,
53985398

53995399
recording::statement *
54005400
recording::block::add_try_catch (location *loc,
5401-
block *try_block,
5402-
block *catch_block,
5401+
recording::region *try_region,
5402+
recording::region *catch_region,
54035403
bool is_finally)
54045404
{
5405-
statement *result = new try_catch (this, loc, try_block, catch_block, is_finally);
5406-
// TODO: explain why we set the blocks reachable state.
5407-
try_block->m_is_reachable = true;
5408-
catch_block->m_is_reachable = true;
5405+
statement *result = new try_catch (this, loc, try_region, catch_region, is_finally);
54095406
m_ctxt->record (result);
54105407
m_statements.safe_push (result);
54115408
return result;
@@ -8080,16 +8077,20 @@ void
80808077
recording::try_catch::clone_into (block_cloner &cloner, block *dest) const
80818078
{
80828079
dest->add_try_catch (get_loc (),
8083-
cloner.remap (m_try_block),
8084-
cloner.remap (m_catch_block),
8080+
cloner.clone_region (m_try_region),
8081+
cloner.clone_region (m_catch_region),
80858082
m_is_finally);
80868083
}
80878084

80888085
void
80898086
recording::try_catch::get_inlined_blocks (auto_vec<block *> &out) const
80908087
{
8091-
out.safe_push (m_try_block);
8092-
out.safe_push (m_catch_block);
8088+
unsigned i;
8089+
block *b;
8090+
FOR_EACH_VEC_ELT (m_try_region->get_blocks (), i, b)
8091+
out.safe_push (b);
8092+
FOR_EACH_VEC_ELT (m_catch_region->get_blocks (), i, b)
8093+
out.safe_push (b);
80938094
}
80948095

80958096
void
@@ -8225,8 +8226,8 @@ recording::try_catch::replay_into (replayer *r)
82258226
{
82268227
playback_block (get_block ())
82278228
->add_try_catch (playback_location (r),
8228-
m_try_block->playback_block (),
8229-
m_catch_block->playback_block (),
8229+
m_try_region,
8230+
m_catch_region,
82308231
m_is_finally);
82318232
}
82328233

@@ -8239,13 +8240,13 @@ recording::try_catch::make_debug_string ()
82398240
if (m_is_finally)
82408241
return string::from_printf (m_ctxt,
82418242
"try { %s } finally { %s };",
8242-
m_try_block->get_debug_string (),
8243-
m_catch_block->get_debug_string ());
8243+
m_try_region->get_debug_string (),
8244+
m_catch_region->get_debug_string ());
82448245
else
82458246
return string::from_printf (m_ctxt,
82468247
"try { %s } catch { %s };",
8247-
m_try_block->get_debug_string (),
8248-
m_catch_block->get_debug_string ());
8248+
m_try_region->get_debug_string (),
8249+
m_catch_region->get_debug_string ());
82498250
}
82508251

82518252
/* Implementation of recording::memento::write_reproducer for
@@ -8264,8 +8265,8 @@ recording::try_catch::write_reproducer (reproducer &r)
82648265
func_name,
82658266
r.get_identifier (get_block ()),
82668267
r.get_identifier (get_loc ()),
8267-
r.get_identifier (m_try_block),
8268-
r.get_identifier (m_catch_block));
8268+
r.get_identifier (m_try_region),
8269+
r.get_identifier (m_catch_region));
82698270
}
82708271

82718272
/* The implementation of class gcc::jit::recording::cleanup. */

gcc/jit/jit-recording.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ class block : public memento
17471747

17481748
statement *
17491749
add_try_catch (location *loc,
1750-
block *try_block,
1751-
block *catch_block,
1750+
region *try_region,
1751+
region *catch_region,
17521752
bool is_finally = false);
17531753

17541754
statement *
@@ -3025,12 +3025,12 @@ class try_catch : public statement
30253025
public:
30263026
try_catch (block *b,
30273027
location *loc,
3028-
block *try_block,
3029-
block *catch_block,
3028+
region *try_region,
3029+
region *catch_region,
30303030
bool is_finally = false)
30313031
: statement (b, loc),
3032-
m_try_block (try_block),
3033-
m_catch_block (catch_block),
3032+
m_try_region (try_region),
3033+
m_catch_region (catch_region),
30343034
m_is_finally (is_finally) {}
30353035

30363036
void replay_into (replayer *r) final override;
@@ -3043,8 +3043,8 @@ class try_catch : public statement
30433043
void write_reproducer (reproducer &r) final override;
30443044

30453045
private:
3046-
block *m_try_block;
3047-
block *m_catch_block;
3046+
region *m_try_region;
3047+
region *m_catch_region;
30483048
bool m_is_finally;
30493049
};
30503050

gcc/jit/libgccjit.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,17 +3119,17 @@ gcc_jit_block_add_eval (gcc_jit_block *block,
31193119
void
31203120
gcc_jit_block_add_try_catch (gcc_jit_block *block,
31213121
gcc_jit_location *loc,
3122-
gcc_jit_block *try_block,
3123-
gcc_jit_block *catch_block)
3122+
gcc_jit_region *try_region,
3123+
gcc_jit_region *catch_region)
31243124
{
31253125
RETURN_IF_NOT_VALID_BLOCK (block, loc);
31263126
gcc::jit::recording::context *ctxt = block->get_context ();
31273127
JIT_LOG_FUNC (ctxt->get_logger ());
31283128
/* LOC can be NULL. */
3129-
RETURN_IF_FAIL (try_block, ctxt, loc, "NULL rvalue");
3130-
RETURN_IF_FAIL (catch_block, ctxt, loc, "NULL rvalue");
3129+
RETURN_IF_FAIL (try_region, ctxt, loc, "NULL try_region");
3130+
RETURN_IF_FAIL (catch_region, ctxt, loc, "NULL cleanup_region");
31313131

3132-
/*gcc::jit::recording::statement *stmt =*/ block->add_try_catch (loc, try_block, catch_block);
3132+
/*gcc::jit::recording::statement *stmt =*/ block->add_try_catch (loc, try_region, catch_region);
31333133

31343134
// TODO: remove this or use it.
31353135
/* "stmt" should be good enough to be usable in error-messages,
@@ -3148,17 +3148,17 @@ gcc_jit_block_add_try_catch (gcc_jit_block *block,
31483148
void
31493149
gcc_jit_block_add_try_finally (gcc_jit_block *block,
31503150
gcc_jit_location *loc,
3151-
gcc_jit_block *try_block,
3152-
gcc_jit_block *finally_block)
3151+
gcc_jit_region *try_region,
3152+
gcc_jit_region *finally_region)
31533153
{
31543154
RETURN_IF_NOT_VALID_BLOCK (block, loc);
31553155
gcc::jit::recording::context *ctxt = block->get_context ();
31563156
JIT_LOG_FUNC (ctxt->get_logger ());
31573157
/* LOC can be NULL. */
3158-
RETURN_IF_FAIL (try_block, ctxt, loc, "NULL rvalue");
3159-
RETURN_IF_FAIL (finally_block, ctxt, loc, "NULL rvalue");
3158+
RETURN_IF_FAIL (try_region, ctxt, loc, "NULL try_region");
3159+
RETURN_IF_FAIL (finally_region, ctxt, loc, "NULL finally_region");
31603160

3161-
/*gcc::jit::recording::statement *stmt =*/ block->add_try_catch (loc, try_block, finally_block, true);
3161+
/*gcc::jit::recording::statement *stmt =*/ block->add_try_catch (loc, try_region, finally_region, true);
31623162

31633163
// TODO: remove this or use it.
31643164
/* "stmt" should be good enough to be usable in error-messages,

gcc/jit/libgccjit.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,8 +1559,8 @@ gcc_jit_block_add_eval (gcc_jit_block *block,
15591559
void
15601560
gcc_jit_block_add_try_catch (gcc_jit_block *block,
15611561
gcc_jit_location *loc,
1562-
gcc_jit_block *try_block,
1563-
gcc_jit_block *catch_block);
1562+
gcc_jit_region *try_region,
1563+
gcc_jit_region *catch_region);
15641564

15651565
/* Add a try/finally statement.
15661566
This is equivalent to this C++-like code:
@@ -1575,8 +1575,8 @@ gcc_jit_block_add_try_catch (gcc_jit_block *block,
15751575
void
15761576
gcc_jit_block_add_try_finally (gcc_jit_block *block,
15771577
gcc_jit_location *loc,
1578-
gcc_jit_block *try_block,
1579-
gcc_jit_block *finally_block);
1578+
gcc_jit_region *try_region,
1579+
gcc_jit_region *finally_region);
15801580

15811581
/* Create a new region within func, for use as the body of an
15821582
exception-handling construct (see gcc_jit_block_add_cleanup).

0 commit comments

Comments
 (0)