summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/AvoidReinterprets.cpp29
-rw-r--r--src/passes/OptimizeInstructions.cpp20
-rw-r--r--src/passes/Precompute.cpp3
3 files changed, 38 insertions, 14 deletions
diff --git a/src/passes/AvoidReinterprets.cpp b/src/passes/AvoidReinterprets.cpp
index 4df75dd15..91a20912d 100644
--- a/src/passes/AvoidReinterprets.cpp
+++ b/src/passes/AvoidReinterprets.cpp
@@ -36,7 +36,10 @@ static bool canReplaceWithReinterpret(Load* load) {
load->bytes == load->type.getByteSize();
}
-static Load* getSingleLoad(LocalGraph* localGraph, LocalGet* get) {
+static Load* getSingleLoad(LocalGraph* localGraph,
+ LocalGet* get,
+ const PassOptions& passOptions,
+ FeatureSet features) {
std::set<LocalGet*> seen;
seen.insert(get);
while (1) {
@@ -48,7 +51,7 @@ static Load* getSingleLoad(LocalGraph* localGraph, LocalGet* get) {
if (!set) {
return nullptr;
}
- auto* value = Properties::getFallthrough(set->value);
+ auto* value = Properties::getFallthrough(set->value, passOptions, features);
if (auto* parentGet = value->dynCast<LocalGet>()) {
if (seen.count(parentGet)) {
// We are in a cycle of gets, in unreachable code.
@@ -98,9 +101,12 @@ struct AvoidReinterprets : public WalkerPass<PostWalker<AvoidReinterprets>> {
void visitUnary(Unary* curr) {
if (isReinterpret(curr)) {
+ FeatureSet features = getModule()->features;
if (auto* get =
- Properties::getFallthrough(curr->value)->dynCast<LocalGet>()) {
- if (auto* load = getSingleLoad(localGraph, get)) {
+ Properties::getFallthrough(curr->value, getPassOptions(), features)
+ ->dynCast<LocalGet>()) {
+ if (auto* load =
+ getSingleLoad(localGraph, get, getPassOptions(), features)) {
auto& info = infos[load];
info.reinterpreted = true;
}
@@ -130,22 +136,27 @@ struct AvoidReinterprets : public WalkerPass<PostWalker<AvoidReinterprets>> {
std::map<Load*, Info>& infos;
LocalGraph* localGraph;
Module* module;
+ const PassOptions& passOptions;
FinalOptimizer(std::map<Load*, Info>& infos,
LocalGraph* localGraph,
- Module* module)
- : infos(infos), localGraph(localGraph), module(module) {}
+ Module* module,
+ const PassOptions& passOptions)
+ : infos(infos), localGraph(localGraph), module(module),
+ passOptions(passOptions) {}
void visitUnary(Unary* curr) {
if (isReinterpret(curr)) {
- auto* value = Properties::getFallthrough(curr->value);
+ auto* value = Properties::getFallthrough(
+ curr->value, passOptions, module->features);
if (auto* load = value->dynCast<Load>()) {
// A reinterpret of a load - flip it right here if we can.
if (canReplaceWithReinterpret(load)) {
replaceCurrent(makeReinterpretedLoad(load, load->ptr));
}
} else if (auto* get = value->dynCast<LocalGet>()) {
- if (auto* load = getSingleLoad(localGraph, get)) {
+ if (auto* load = getSingleLoad(
+ localGraph, get, passOptions, module->features)) {
auto iter = infos.find(load);
if (iter != infos.end()) {
auto& info = iter->second;
@@ -188,7 +199,7 @@ struct AvoidReinterprets : public WalkerPass<PostWalker<AvoidReinterprets>> {
ptr,
load->type.reinterpret());
}
- } finalOptimizer(infos, localGraph, getModule());
+ } finalOptimizer(infos, localGraph, getModule(), getPassOptions());
finalOptimizer.walk(func->body);
}
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 90abed825..3e3863e95 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -200,8 +200,11 @@ struct LocalInfo {
struct LocalScanner : PostWalker<LocalScanner> {
std::vector<LocalInfo>& localInfo;
+ const PassOptions& passOptions;
- LocalScanner(std::vector<LocalInfo>& localInfo) : localInfo(localInfo) {}
+ LocalScanner(std::vector<LocalInfo>& localInfo,
+ const PassOptions& passOptions)
+ : localInfo(localInfo), passOptions(passOptions) {}
void doWalkFunction(Function* func) {
// prepare
@@ -236,7 +239,8 @@ struct LocalScanner : PostWalker<LocalScanner> {
return;
}
// an integer var, worth processing
- auto* value = Properties::getFallthrough(curr->value);
+ auto* value = Properties::getFallthrough(
+ curr->value, passOptions, getModule()->features);
auto& info = localInfo[curr->index];
info.maxBits = std::max(info.maxBits, getMaxBits(value, this));
auto signExtBits = LocalInfo::kUnknown;
@@ -289,7 +293,8 @@ struct OptimizeInstructions
void doWalkFunction(Function* func) {
// first, scan locals
{
- LocalScanner scanner(localInfo);
+ LocalScanner scanner(localInfo, getPassOptions());
+ scanner.setModule(getModule());
scanner.walkFunction(func);
}
// main walk
@@ -347,7 +352,9 @@ struct OptimizeInstructions
Index extraShifts;
auto bits = Properties::getAlmostSignExtBits(binary, extraShifts);
if (extraShifts == 0) {
- if (auto* load = Properties::getFallthrough(ext)->dynCast<Load>()) {
+ if (auto* load =
+ Properties::getFallthrough(ext, getPassOptions(), features)
+ ->dynCast<Load>()) {
// pattern match a load of 8 bits and a sign extend using a shl of
// 24 then shr_s of 24 as well, etc.
if (LoadUtils::canBeSigned(load) &&
@@ -984,6 +991,11 @@ private:
} else if (auto* select = boolean->dynCast<Select>()) {
select->ifTrue = optimizeBoolean(select->ifTrue);
select->ifFalse = optimizeBoolean(select->ifFalse);
+ } else if (auto* tryy = boolean->dynCast<Try>()) {
+ if (tryy->type == Type::i32) {
+ tryy->body = optimizeBoolean(tryy->body);
+ tryy->catchBody = optimizeBoolean(tryy->catchBody);
+ }
}
// TODO: recurse into br values?
return boolean;
diff --git a/src/passes/Precompute.cpp b/src/passes/Precompute.cpp
index 21393c1cf..3a886166c 100644
--- a/src/passes/Precompute.cpp
+++ b/src/passes/Precompute.cpp
@@ -327,7 +327,8 @@ private:
continue; // already known constant
}
auto value = setValues[set] =
- precomputeValue(Properties::getFallthrough(set->value));
+ precomputeValue(Properties::getFallthrough(
+ set->value, getPassOptions(), getModule()->features));
if (value.isConcrete()) {
for (auto* get : localGraph.setInfluences[set]) {
work.insert(get);