summaryrefslogtreecommitdiff
path: root/src/ir
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir')
-rw-r--r--src/ir/block-utils.h7
-rw-r--r--src/ir/effects.h28
-rw-r--r--src/ir/properties.h2
3 files changed, 30 insertions, 7 deletions
diff --git a/src/ir/block-utils.h b/src/ir/block-utils.h
index f8224186f..be24cf483 100644
--- a/src/ir/block-utils.h
+++ b/src/ir/block-utils.h
@@ -37,10 +37,9 @@ simplifyToContents(Block* block, T* parent, bool allowTypeChange = false) {
!BranchUtils::BranchSeeker::has(list[0], block->name)) {
// just one element. try to replace the block
auto* singleton = list[0];
- auto sideEffects = EffectAnalyzer(parent->getPassOptions(),
- parent->getModule()->features,
- singleton)
- .hasSideEffects();
+ auto sideEffects =
+ EffectAnalyzer(parent->getPassOptions(), *parent->getModule(), singleton)
+ .hasSideEffects();
if (!sideEffects && !singleton->type.isConcrete()) {
// no side effects, and singleton is not returning a value, so we can
// throw away the block and its contents, basically
diff --git a/src/ir/effects.h b/src/ir/effects.h
index e8fba8e3a..d34f8e5b2 100644
--- a/src/ir/effects.h
+++ b/src/ir/effects.h
@@ -31,7 +31,19 @@ public:
Expression* ast = nullptr)
: ignoreImplicitTraps(passOptions.ignoreImplicitTraps),
trapsNeverHappen(passOptions.trapsNeverHappen),
- debugInfo(passOptions.debugInfo), features(features) {
+ debugInfo(passOptions.debugInfo), module(nullptr), features(features) {
+ if (ast) {
+ walk(ast);
+ }
+ }
+
+ EffectAnalyzer(const PassOptions& passOptions,
+ Module& module,
+ Expression* ast = nullptr)
+ : ignoreImplicitTraps(passOptions.ignoreImplicitTraps),
+ trapsNeverHappen(passOptions.trapsNeverHappen),
+ debugInfo(passOptions.debugInfo), module(&module),
+ features(module.features) {
if (ast) {
walk(ast);
}
@@ -40,6 +52,7 @@ public:
bool ignoreImplicitTraps;
bool trapsNeverHappen;
bool debugInfo;
+ Module* module;
FeatureSet features;
// Walk an expression and all its children.
@@ -680,6 +693,15 @@ public:
return !aEffects.invalidates(bEffects);
}
+ static bool canReorder(const PassOptions& passOptions,
+ Module& module,
+ Expression* a,
+ Expression* b) {
+ EffectAnalyzer aEffects(passOptions, module, a);
+ EffectAnalyzer bEffects(passOptions, module, b);
+ return !aEffects.invalidates(bEffects);
+ }
+
// C-API
enum SideEffects : uint32_t {
@@ -767,9 +789,9 @@ private:
class ShallowEffectAnalyzer : public EffectAnalyzer {
public:
ShallowEffectAnalyzer(const PassOptions& passOptions,
- FeatureSet features,
+ Module& module,
Expression* ast = nullptr)
- : EffectAnalyzer(passOptions, features) {
+ : EffectAnalyzer(passOptions, module) {
if (ast) {
visit(ast);
}
diff --git a/src/ir/properties.h b/src/ir/properties.h
index dbf2715ef..2e3f94a06 100644
--- a/src/ir/properties.h
+++ b/src/ir/properties.h
@@ -250,6 +250,8 @@ inline Index getZeroExtBits(Expression* curr) {
// child of this expression. See getFallthrough for a method that looks all the
// way to the final value falling through, potentially through multiple
// intermediate expressions.
+//
+// TODO: Receive a Module instead of FeatureSet, to pass to EffectAnalyzer?
inline Expression* getImmediateFallthrough(Expression* curr,
const PassOptions& passOptions,
FeatureSet features) {