diff options
author | David Faust <david.faust@oracle.com> | 2022-04-07 09:41:37 -0700 |
---|---|---|
committer | David Faust <david.faust@oracle.com> | 2022-04-07 09:57:46 -0700 |
commit | 5559bdc86635b2ff6cbaa60e933a7989ff212e1f (patch) | |
tree | 96e6621e8cb28606efa91c030d2b9de4c77339f6 /gcc/rust/backend/rust-compile-context.h | |
parent | b829e7c0a21c94672d09732e4a791e0471f41c13 (diff) | |
download | gcc-5559bdc86635b2ff6cbaa60e933a7989ff212e1f.zip gcc-5559bdc86635b2ff6cbaa60e933a7989ff212e1f.tar.gz gcc-5559bdc86635b2ff6cbaa60e933a7989ff212e1f.tar.bz2 |
Emit loop initializer for repeat arrays
This commit changes how arrays of repeating elements, e.g. [5; 12] are
compiled. Rather than create a constructor which explicitly initializes
each element to the given value (which causes compiler OOM for large
arrays), we emit instructions to allocate the array then initialize the
elements in a loop.
However, we can only take this approach outside of const contexts -
const arrays must still use the old approach.
Diffstat (limited to 'gcc/rust/backend/rust-compile-context.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 4bade5c..de9d03f 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -250,6 +250,10 @@ public: fn_stack.push_back (fncontext{fn, ret_addr}); } void pop_fn () { fn_stack.pop_back (); } + + bool in_fn () { return fn_stack.size () != 0; } + + // Note: it is undefined behavior to call peek_fn () if fn_stack is empty. fncontext peek_fn () { return fn_stack.back (); } void push_type (tree t) { type_decls.push_back (t); } @@ -301,6 +305,14 @@ public: return pop; } + void push_const_context (void) { const_context++; } + void pop_const_context (void) + { + if (const_context > 0) + const_context--; + } + bool const_context_p (void) { return (const_context > 0); } + std::string mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path) const { @@ -341,6 +353,9 @@ private: std::vector<::Bvariable *> var_decls; std::vector<tree> const_decls; std::vector<tree> func_decls; + + // Nonzero iff we are currently compiling something inside a constant context. + unsigned int const_context = 0; }; } // namespace Compile |