diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-09-12 15:09:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-12 15:09:21 -0700 |
commit | c6729400f68a346c1d51702946bf6026638782a6 (patch) | |
tree | a564073fbc079a88df43e12f177c8f2753670bfa /src/literal.h | |
parent | 40f52f2ca41822e9dc47ff57239cdf299f7e1ce5 (diff) | |
download | binaryen-c6729400f68a346c1d51702946bf6026638782a6.tar.gz binaryen-c6729400f68a346c1d51702946bf6026638782a6.tar.bz2 binaryen-c6729400f68a346c1d51702946bf6026638782a6.zip |
precompute-propagate pass (#1179)
Implements #1172: this adds a variant of precompute, "precompute-propagate", which also does constant propagation. Precompute by itself just runs the interpreter on each expression and sees if it is in fact a constant; precompute-propagate also looks at the graph of connections between get and set locals, and propagates those constant values.
This helps with cases as noticed in #1168 - while in most cases LLVM will do this already, it's important when inlining, e.g. inlining of the clamping math functions. This new pass is run when inlining, and otherwise only in -O3/-Oz, as it does increase compilation time noticeably if run on everything (and for almost no benefit if LLVM has run).
Most of the code here is just refactoring out from the ssa pass the get/set graph computation, so it can now be used by both the ssa pass and precompute-propagate.
Diffstat (limited to 'src/literal.h')
-rw-r--r-- | src/literal.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/literal.h b/src/literal.h index 560895e7a..c55d645ad 100644 --- a/src/literal.h +++ b/src/literal.h @@ -44,7 +44,7 @@ private: return val & (sizeof(T) * 8 - 1); } - public: +public: Literal() : type(WasmType::none), i64(0) {} explicit Literal(WasmType type) : type(type), i64(0) {} explicit Literal(int32_t init) : type(WasmType::i32), i32(init) {} @@ -54,6 +54,9 @@ private: explicit Literal(float init) : type(WasmType::f32), i32(bit_cast<int32_t>(init)) {} explicit Literal(double init) : type(WasmType::f64), i64(bit_cast<int64_t>(init)) {} + bool isConcrete() { return type != none; } + bool isNull() { return type == none; } + Literal castToF32(); Literal castToF64(); Literal castToI32(); @@ -76,6 +79,7 @@ private: int64_t getBits() const; bool operator==(const Literal& other) const; bool operator!=(const Literal& other) const; + bool bitwiseEqual(const Literal& other) const; static uint32_t NaNPayload(float f); static uint64_t NaNPayload(double f); |