Skip to content

Commit 04a3af9

Browse files
committed
Add a way to remove a global
1 parent cfc4e90 commit 04a3af9

File tree

7 files changed

+63
-16
lines changed

7 files changed

+63
-16
lines changed

gcc/jit/jit-playback.cc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -780,20 +780,30 @@ global_new_decl (location *loc,
780780
enum global_var_flags flags,
781781
const std::vector<std::pair<gcc_jit_variable_attribute,
782782
std::string>> &attributes,
783-
bool readonly)
783+
bool readonly,
784+
bool removed)
784785
{
785786
gcc_assert (type);
786787
gcc_assert (name);
787788

788789
tree type_tree = type->as_tree ();
789790

791+
if (removed)
792+
{
793+
tree inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
794+
get_identifier (name),
795+
type_tree);
796+
// TODO: make it weak?
797+
DECL_EXTERNAL (inner) = 1;
798+
return inner;
799+
}
800+
790801
tree inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
791802
get_identifier (name),
792803
type_tree);
793804

794805
TREE_PUBLIC (inner) = (kind != GCC_JIT_GLOBAL_INTERNAL);
795806

796-
797807
int will_be_init = flags & (GLOBAL_VAR_FLAGS_WILL_BE_RVAL_INIT |
798808
GLOBAL_VAR_FLAGS_WILL_BE_BLOB_INIT);
799809

@@ -855,9 +865,10 @@ set_variable_string_attribute (
855865

856866
playback::lvalue *
857867
playback::context::
858-
global_finalize_lvalue (tree inner)
868+
global_finalize_lvalue (tree inner, bool removed)
859869
{
860-
m_globals.safe_push (inner);
870+
if (!removed)
871+
m_globals.safe_push (inner);
861872

862873
return new lvalue (this, inner);
863874
}
@@ -873,12 +884,13 @@ new_global (location *loc,
873884
enum global_var_flags flags,
874885
const std::vector<std::pair<gcc_jit_variable_attribute,
875886
std::string>> &attributes,
876-
bool readonly)
887+
bool readonly,
888+
bool removed)
877889
{
878890
tree inner =
879-
global_new_decl (loc, kind, type, name, flags, attributes, readonly);
891+
global_new_decl (loc, kind, type, name, flags, attributes, readonly, removed);
880892

881-
return global_finalize_lvalue (inner);
893+
return global_finalize_lvalue (inner, removed);
882894
}
883895

884896
void
@@ -1024,9 +1036,10 @@ new_global_initialized (location *loc,
10241036
enum global_var_flags flags,
10251037
const std::vector<std::pair<gcc_jit_variable_attribute,
10261038
std::string>> &attributes,
1027-
bool readonly)
1039+
bool readonly,
1040+
bool removed)
10281041
{
1029-
tree inner = global_new_decl (loc, kind, type, name, flags, attributes, readonly);
1042+
tree inner = global_new_decl (loc, kind, type, name, flags, attributes, readonly, removed);
10301043

10311044
vec<constructor_elt, va_gc> *constructor_elements = NULL;
10321045

@@ -1060,7 +1073,7 @@ new_global_initialized (location *loc,
10601073
/* Compare with 'store_init_value' c-typeck.cc:7555. */
10611074
DECL_INITIAL (inner) = ctor;
10621075

1063-
return global_finalize_lvalue (inner);
1076+
return global_finalize_lvalue (inner, removed);
10641077
}
10651078

10661079
/* Implementation of the various

gcc/jit/jit-playback.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class context : public log_user
137137
enum global_var_flags flags,
138138
const std::vector<std::pair<gcc_jit_variable_attribute,
139139
std::string>> &attributes,
140-
bool readonly);
140+
bool readonly,
141+
bool removed);
141142

142143
lvalue *
143144
new_global_initialized (location *loc,
@@ -152,7 +153,8 @@ class context : public log_user
152153
gcc_jit_variable_attribute,
153154
std::string>>
154155
&attributes,
155-
bool readonly);
156+
bool readonly,
157+
bool removed);
156158

157159
rvalue *
158160
new_ctor (location *log,
@@ -362,9 +364,10 @@ class context : public log_user
362364
enum global_var_flags flags,
363365
const std::vector<std::pair<gcc_jit_variable_attribute,
364366
std::string>> &attributes,
365-
bool readonly);
367+
bool readonly,
368+
bool removed);
366369
lvalue *
367-
global_finalize_lvalue (tree inner);
370+
global_finalize_lvalue (tree inner, bool removed);
368371

369372
private:
370373

gcc/jit/jit-recording.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,14 +5412,16 @@ recording::global::replay_into (replayer *r)
54125412
playback_string (m_name),
54135413
m_flags,
54145414
m_string_attributes,
5415-
m_readonly)
5415+
m_readonly,
5416+
m_removed)
54165417
: r->new_global (playback_location (r, m_loc),
54175418
m_kind,
54185419
m_type->playback_type (),
54195420
playback_string (m_name),
54205421
m_flags,
54215422
m_string_attributes,
5422-
m_readonly);
5423+
m_readonly,
5424+
m_removed);
54235425

54245426
if (m_tls_model != GCC_JIT_TLS_MODEL_NONE)
54255427
global->set_tls_model (recording::tls_models[m_tls_model]);

gcc/jit/jit-recording.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,11 @@ class lvalue : public rvalue
14601460
m_readonly = true;
14611461
}
14621462

1463+
void remove ()
1464+
{
1465+
m_removed = true;
1466+
}
1467+
14631468
virtual const char *access_as_lvalue (reproducer &r);
14641469
virtual bool is_global () const { return false; }
14651470
virtual bool is_local () const { return false; }
@@ -1477,6 +1482,7 @@ class lvalue : public rvalue
14771482
std::vector<std::pair<gcc_jit_variable_attribute,
14781483
std::string>> m_string_attributes;
14791484
bool m_readonly = false;
1485+
bool m_removed = false;
14801486
};
14811487

14821488
class param : public lvalue

gcc/jit/libgccjit.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,6 +2007,12 @@ gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue)
20072007
return static_cast <gcc_jit_type *> (rvalue->get_type ());
20082008
}
20092009

2010+
void
2011+
gcc_jit_lvalue_remove (gcc_jit_lvalue *lvalue)
2012+
{
2013+
lvalue->remove ();
2014+
}
2015+
20102016
/* Verify that NUMERIC_TYPE is non-NULL, and that it is a "numeric"
20112017
type i.e. it satisfies gcc::jit::type::is_numeric (), such as the
20122018
result of gcc_jit_context_get_type (GCC_JIT_TYPE_INT). */

gcc/jit/libgccjit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,9 @@ gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue);
10841084
extern gcc_jit_type *
10851085
gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue);
10861086

1087+
extern void
1088+
gcc_jit_lvalue_remove (gcc_jit_lvalue *lvalue);
1089+
10871090
/* Integer constants. */
10881091
extern gcc_jit_rvalue *
10891092
gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,

gcc/jit/libgccjit.map

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,17 @@ LIBGCCJIT_ABI_40 {
364364
global:
365365
gcc_jit_type_is_floating_point;
366366
} LIBGCCJIT_ABI_39;
367+
368+
LIBGCCJIT_ABI_41 {
369+
global:
370+
gcc_jit_lvalue_remove;
371+
} LIBGCCJIT_ABI_40;
372+
373+
LIBGCCJIT_ABI_42 {
374+
global:
375+
gcc_jit_rvalue_set_type;
376+
} LIBGCCJIT_ABI_41;
377+
378+
LIBGCCJIT_ABI_43 {
379+
gcc_jit_lvalue_add_attribute;
380+
} LIBGCCJIT_ABI_42;

0 commit comments

Comments
 (0)