Skip to content

Commit 1e659e3

Browse files
authored
[NFC] Avoid some unnecessary copies of PassOptions (#4361)
PassOptions is a fairly large structure and even includes a std::map. I also have plans to add further fields there to make it even larger. Before doing that I noticed that in some places we copy it instead of being consistent and taking it by reference, which this PR fixes.
1 parent 5f6911f commit 1e659e3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/passes/LocalCSE.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ struct RequestInfoMap : public std::unordered_map<Expression*, RequestInfo> {
204204

205205
struct Scanner
206206
: public LinearExecutionWalker<Scanner, UnifiedExpressionVisitor<Scanner>> {
207-
PassOptions options;
207+
PassOptions& options;
208208

209209
// Request info for all expressions ever seen.
210210
RequestInfoMap& requestInfos;
211211

212-
Scanner(PassOptions options, RequestInfoMap& requestInfos)
212+
Scanner(PassOptions& options, RequestInfoMap& requestInfos)
213213
: options(options), requestInfos(requestInfos) {}
214214

215215
// Currently active hashed expressions in the current basic block. If we see
@@ -351,10 +351,10 @@ struct Scanner
351351
// make Applier ignore them.
352352
struct Checker
353353
: public LinearExecutionWalker<Checker, UnifiedExpressionVisitor<Checker>> {
354-
PassOptions options;
354+
PassOptions& options;
355355
RequestInfoMap& requestInfos;
356356

357-
Checker(PassOptions options, RequestInfoMap& requestInfos)
357+
Checker(PassOptions& options, RequestInfoMap& requestInfos)
358358
: options(options), requestInfos(requestInfos) {}
359359

360360
struct ActiveOriginalInfo {
@@ -529,7 +529,7 @@ struct LocalCSE : public WalkerPass<PostWalker<LocalCSE>> {
529529
Pass* create() override { return new LocalCSE(); }
530530

531531
void doWalkFunction(Function* func) {
532-
auto options = getPassOptions();
532+
auto& options = getPassOptions();
533533

534534
RequestInfoMap requestInfos;
535535

src/passes/OptimizeInstructions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ struct OptimizeInstructions
11291129
// Otherwise, if this is not a tee, then no value falls through. The
11301130
// ref.as_non_null acts as a null check here, basically. If we are
11311131
// ignoring such traps, we can remove it.
1132-
auto passOptions = getPassOptions();
1132+
auto& passOptions = getPassOptions();
11331133
if (passOptions.ignoreImplicitTraps || passOptions.trapsNeverHappen) {
11341134
curr->value = as->value;
11351135
}
@@ -1540,7 +1540,7 @@ struct OptimizeInstructions
15401540
}
15411541

15421542
Builder builder(*getModule());
1543-
auto passOptions = getPassOptions();
1543+
auto& passOptions = getPassOptions();
15441544

15451545
auto fallthrough =
15461546
Properties::getFallthrough(curr->ref, getPassOptions(), *getModule());
@@ -1869,7 +1869,7 @@ struct OptimizeInstructions
18691869
// assume things like local.get's of the same index being identical. (It is
18701870
// also ok to have side effects here, if we can remove them, as we are also
18711871
// checking if we can remove the two inputs anyhow.)
1872-
auto passOptions = getPassOptions();
1872+
auto& passOptions = getPassOptions();
18731873
if (EffectAnalyzer(passOptions, *getModule(), left)
18741874
.hasUnremovableSideEffects() ||
18751875
EffectAnalyzer(passOptions, *getModule(), right)
@@ -3292,7 +3292,7 @@ struct OptimizeInstructions
32923292
}
32933293

32943294
Expression* optimizeMemoryCopy(MemoryCopy* memCopy) {
3295-
PassOptions options = getPassOptions();
3295+
auto& options = getPassOptions();
32963296

32973297
if (options.ignoreImplicitTraps || options.trapsNeverHappen) {
32983298
if (ExpressionAnalyzer::equal(memCopy->dest, memCopy->source)) {
@@ -3371,7 +3371,7 @@ struct OptimizeInstructions
33713371
return nullptr;
33723372
}
33733373

3374-
PassOptions options = getPassOptions();
3374+
auto& options = getPassOptions();
33753375
Builder builder(*getModule());
33763376

33773377
auto* csize = memFill->size->cast<Const>();

0 commit comments

Comments
 (0)