Skip to content

Add a way to remove a global #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions gcc/jit/jit-playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,8 @@ global_new_decl (location *loc,
enum global_var_flags flags,
const std::vector<std::pair<gcc_jit_variable_attribute,
std::string>> &attributes,
bool readonly)
bool readonly,
bool removed)
{
gcc_assert (type);
gcc_assert (name);
Expand All @@ -788,6 +789,8 @@ global_new_decl (location *loc,
type_tree);

TREE_PUBLIC (inner) = (kind != GCC_JIT_GLOBAL_INTERNAL);
if (removed)
TREE_ASM_WRITTEN (inner) = 1;


int will_be_init = flags & (GLOBAL_VAR_FLAGS_WILL_BE_RVAL_INIT |
Expand Down Expand Up @@ -869,10 +872,11 @@ new_global (location *loc,
enum global_var_flags flags,
const std::vector<std::pair<gcc_jit_variable_attribute,
std::string>> &attributes,
bool readonly)
bool readonly,
bool removed)
{
tree inner =
global_new_decl (loc, kind, type, name, flags, attributes, readonly);
global_new_decl (loc, kind, type, name, flags, attributes, readonly, removed);

return global_finalize_lvalue (inner);
}
Expand Down Expand Up @@ -1020,9 +1024,10 @@ new_global_initialized (location *loc,
enum global_var_flags flags,
const std::vector<std::pair<gcc_jit_variable_attribute,
std::string>> &attributes,
bool readonly)
bool readonly,
bool removed)
{
tree inner = global_new_decl (loc, kind, type, name, flags, attributes, readonly);
tree inner = global_new_decl (loc, kind, type, name, flags, attributes, readonly, removed);

vec<constructor_elt, va_gc> *constructor_elements = NULL;

Expand Down
9 changes: 6 additions & 3 deletions gcc/jit/jit-playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class context : public log_user
enum global_var_flags flags,
const std::vector<std::pair<gcc_jit_variable_attribute,
std::string>> &attributes,
bool readonly);
bool readonly,
bool removed);

lvalue *
new_global_initialized (location *loc,
Expand All @@ -152,7 +153,8 @@ class context : public log_user
gcc_jit_variable_attribute,
std::string>>
&attributes,
bool readonly);
bool readonly,
bool removed);

rvalue *
new_ctor (location *log,
Expand Down Expand Up @@ -362,7 +364,8 @@ class context : public log_user
enum global_var_flags flags,
const std::vector<std::pair<gcc_jit_variable_attribute,
std::string>> &attributes,
bool readonly);
bool readonly,
bool removed);
lvalue *
global_finalize_lvalue (tree inner);

Expand Down
6 changes: 4 additions & 2 deletions gcc/jit/jit-recording.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5407,14 +5407,16 @@ recording::global::replay_into (replayer *r)
playback_string (m_name),
m_flags,
m_string_attributes,
m_readonly)
m_readonly,
m_removed)
: r->new_global (playback_location (r, m_loc),
m_kind,
m_type->playback_type (),
playback_string (m_name),
m_flags,
m_string_attributes,
m_readonly);
m_readonly,
m_removed);

if (m_tls_model != GCC_JIT_TLS_MODEL_NONE)
global->set_tls_model (recording::tls_models[m_tls_model]);
Expand Down
6 changes: 6 additions & 0 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,11 @@ class lvalue : public rvalue
m_readonly = true;
}

void remove ()
{
m_removed = true;
}

virtual const char *access_as_lvalue (reproducer &r);
virtual bool is_global () const { return false; }
virtual bool is_local () const { return false; }
Expand All @@ -1472,6 +1477,7 @@ class lvalue : public rvalue
std::vector<std::pair<gcc_jit_variable_attribute,
std::string>> m_string_attributes;
bool m_readonly = false;
bool m_removed = false;
};

class param : public lvalue
Expand Down
6 changes: 6 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,12 @@ gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue)
return static_cast <gcc_jit_type *> (rvalue->get_type ());
}

void
gcc_jit_lvalue_remove (gcc_jit_lvalue *lvalue)
{
lvalue->remove ();
}

/* Verify that NUMERIC_TYPE is non-NULL, and that it is a "numeric"
type i.e. it satisfies gcc::jit::type::is_numeric (), such as the
result of gcc_jit_context_get_type (GCC_JIT_TYPE_INT). */
Expand Down
3 changes: 3 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue);
extern gcc_jit_type *
gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue);

extern void
gcc_jit_lvalue_remove (gcc_jit_lvalue *lvalue);

/* Integer constants. */
extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,
Expand Down
5 changes: 5 additions & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,8 @@ LIBGCCJIT_ABI_40 {
global:
gcc_jit_type_is_floating_point;
} LIBGCCJIT_ABI_39;

LIBGCCJIT_ABI_41 {
global:
gcc_jit_lvalue_remove;
} LIBGCCJIT_ABI_40;