Optimize string temporaries - do not localize (#6969)

Minor performance improvement, especially for assertions heavy code.
Strings are often used as temporaries in unlikely branches. Do not
localize them to avoid an unnecessary initialization on function entry.
This commit is contained in:
Geza Lore 2026-01-31 16:05:35 +00:00 committed by GitHub
parent f472c2da6e
commit 0915ae6ba8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -69,6 +69,11 @@ class LocalizeVisitor final : public VNVisitor {
bool isOptimizable(AstVarScope* nodep) {
// Don't want to malloc/free the backing store all the time
if (VN_IS(nodep->dtypep(), NBACommitQueueDType)) return false;
// Do not localize strings. They result in unnecessary initialization
// and bloated code size due to destructor calls when unused.
// TODO: Local variables should be pushed into the narrowest scope rather
// than emitted at the top of the function. See discussion in #6969.
if (nodep->dtypep()->skipRefp()->isString()) return false;
// Variables used in super constructor call can't be localized, because
// in C++ there is no way to declare them before base class constructor call
if (nodep->user4()) return false;