From 2b98366e3f4787fc8d3d21ba0c01a577b8ea0d66 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 6 Sep 2016 16:38:16 -0700 Subject: track globals in EffectAnalyzer --- src/ast_utils.h | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ast_utils.h b/src/ast_utils.h index 9b2ff10cd..f7a486332 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -92,13 +92,16 @@ struct EffectAnalyzer : public PostWalker localsRead; std::set localsWritten; + std::set globalsRead; + std::set globalsWritten; bool readsMemory = false; bool writesMemory = false; bool accessesLocal() { return localsRead.size() + localsWritten.size() > 0; } + bool accessesGlobal() { return globalsRead.size() + globalsWritten.size() > 0; } bool accessesMemory() { return calls || readsMemory || writesMemory; } - bool hasSideEffects() { return calls || localsWritten.size() > 0 || writesMemory || branches; } - bool hasAnything() { return branches || calls || accessesLocal() || readsMemory || writesMemory; } + bool hasSideEffects() { return calls || localsWritten.size() > 0 || writesMemory || branches || globalsWritten.size() > 0; } + bool hasAnything() { return branches || calls || accessesLocal() || readsMemory || writesMemory || accessesGlobal(); } // checks if these effects would invalidate another set (e.g., if we write, we invalidate someone that reads, they can't be moved past us) bool invalidates(EffectAnalyzer& other) { @@ -115,6 +118,17 @@ struct EffectAnalyzer : public PostWalkerindex); } - void visitGetGlobal(GetGlobal *curr) { readsMemory = true; } // TODO: global-specific - void visitSetGlobal(SetGlobal *curr) { writesMemory = true; } // stuff? + void visitGetGlobal(GetGlobal *curr) { + globalsRead.insert(curr->name); + } + void visitSetGlobal(SetGlobal *curr) { + globalsWritten.insert(curr->name); + } void visitLoad(Load *curr) { readsMemory = true; } void visitStore(Store *curr) { writesMemory = true; } void visitReturn(Return *curr) { branches = true; } -- cgit v1.2.3