blob: 4b604e03ab62786c3e0c1eeabe3fafb74dad0ca5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// slang-ir-ssa-simplification.cpp
#include "slang-ir-ssa-simplification.h"
#include "slang-ir.h"
#include "slang-ir-ssa.h"
#include "slang-ir-sccp.h"
#include "slang-ir-dce.h"
#include "slang-ir-simplify-cfg.h"
#include "slang-ir-peephole.h"
#include "slang-ir-hoist-constants.h"
namespace Slang
{
// Run a combination of SSA, SCCP, SimplifyCFG, and DeadCodeElimination pass
// until no more changes are possible.
void simplifyIR(IRModule* module)
{
bool changed = true;
const int kMaxIterations = 8;
int iterationCounter = 0;
while (changed && iterationCounter < kMaxIterations)
{
changed = false;
changed |= hoistConstants(module);
changed |= applySparseConditionalConstantPropagation(module);
changed |= peepholeOptimize(module);
changed |= simplifyCFG(module);
// Note: we disregard the `changed` state from dead code elimination pass since
// SCCP pass could be generating temporarily evaluated constant values and never actually use them.
// DCE will always remove those nearly generated consts and always returns true here.
eliminateDeadCode(module);
changed |= constructSSA(module);
iterationCounter++;
}
}
void simplifyFunc(IRGlobalValueWithCode* func)
{
bool changed = true;
const int kMaxIterations = 8;
int iterationCounter = 0;
while (changed && iterationCounter < kMaxIterations)
{
changed = false;
changed |= applySparseConditionalConstantPropagation(func);
changed |= peepholeOptimize(func);
changed |= simplifyCFG(func);
// Note: we disregard the `changed` state from dead code elimination pass since
// SCCP pass could be generating temporarily evaluated constant values and never actually use them.
// DCE will always remove those nearly generated consts and always returns true here.
eliminateDeadCode(func);
changed |= constructSSA(func);
iterationCounter++;
}
}
}
|