Commit 90a18f42 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm][cleanup] Use GraphAssembler for number conversions

Using the GraphAssembler instead of creating nodes "manually" results in
much smaller code. This allows us then to use ternary operators to make
the implementation even more concise.

R=ahaas@chromium.org

Bug: v8:10123
Change-Id: I154ffb436f414da14e932138911f35d251363083
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2489686Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70686}
parent 0b5ceda4
...@@ -3182,59 +3182,44 @@ Node* WasmGraphBuilder::Invert(Node* node) { ...@@ -3182,59 +3182,44 @@ Node* WasmGraphBuilder::Invert(Node* node) {
} }
Node* WasmGraphBuilder::BuildTruncateIntPtrToInt32(Node* value) { Node* WasmGraphBuilder::BuildTruncateIntPtrToInt32(Node* value) {
if (mcgraph()->machine()->Is64()) { return mcgraph()->machine()->Is64() ? gasm_->TruncateInt64ToInt32(value)
value = : value;
graph()->NewNode(mcgraph()->machine()->TruncateInt64ToInt32(), value);
}
return value;
} }
Node* WasmGraphBuilder::BuildChangeInt32ToIntPtr(Node* value) { Node* WasmGraphBuilder::BuildChangeInt32ToIntPtr(Node* value) {
if (mcgraph()->machine()->Is64()) { return mcgraph()->machine()->Is64() ? gasm_->ChangeInt32ToInt64(value)
value = graph()->NewNode(mcgraph()->machine()->ChangeInt32ToInt64(), value); : value;
}
return value;
} }
Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) {
// With pointer compression, only the lower 32 bits are used. // With pointer compression, only the lower 32 bits are used.
if (COMPRESS_POINTERS_BOOL) { return COMPRESS_POINTERS_BOOL
return graph()->NewNode(mcgraph()->machine()->Word32Shl(), value, ? gasm_->Word32Shl(value, BuildSmiShiftBitsConstant32())
BuildSmiShiftBitsConstant32()); : gasm_->WordShl(BuildChangeInt32ToIntPtr(value),
} BuildSmiShiftBitsConstant());
value = BuildChangeInt32ToIntPtr(value);
return graph()->NewNode(mcgraph()->machine()->WordShl(), value,
BuildSmiShiftBitsConstant());
} }
Node* WasmGraphBuilder::BuildChangeUint31ToSmi(Node* value) { Node* WasmGraphBuilder::BuildChangeUint31ToSmi(Node* value) {
if (COMPRESS_POINTERS_BOOL) { return COMPRESS_POINTERS_BOOL
return graph()->NewNode(mcgraph()->machine()->Word32Shl(), value, ? gasm_->Word32Shl(value, BuildSmiShiftBitsConstant32())
BuildSmiShiftBitsConstant32()); : graph()->NewNode(mcgraph()->machine()->WordShl(),
} Uint32ToUintptr(value),
return graph()->NewNode(mcgraph()->machine()->WordShl(), BuildSmiShiftBitsConstant());
Uint32ToUintptr(value), BuildSmiShiftBitsConstant());
} }
Node* WasmGraphBuilder::BuildSmiShiftBitsConstant() { Node* WasmGraphBuilder::BuildSmiShiftBitsConstant() {
return mcgraph()->IntPtrConstant(kSmiShiftSize + kSmiTagSize); return gasm_->IntPtrConstant(kSmiShiftSize + kSmiTagSize);
} }
Node* WasmGraphBuilder::BuildSmiShiftBitsConstant32() { Node* WasmGraphBuilder::BuildSmiShiftBitsConstant32() {
return mcgraph()->Int32Constant(kSmiShiftSize + kSmiTagSize); return gasm_->Int32Constant(kSmiShiftSize + kSmiTagSize);
} }
Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) { Node* WasmGraphBuilder::BuildChangeSmiToInt32(Node* value) {
if (COMPRESS_POINTERS_BOOL) { return COMPRESS_POINTERS_BOOL
value = ? gasm_->Word32Sar(gasm_->TruncateInt64ToInt32(value),
graph()->NewNode(mcgraph()->machine()->TruncateInt64ToInt32(), value); BuildSmiShiftBitsConstant32())
value = graph()->NewNode(mcgraph()->machine()->Word32Sar(), value, : BuildTruncateIntPtrToInt32(BuildChangeSmiToIntPtr(value));
BuildSmiShiftBitsConstant32());
} else {
value = BuildChangeSmiToIntPtr(value);
value = BuildTruncateIntPtrToInt32(value);
}
return value;
} }
Node* WasmGraphBuilder::BuildChangeSmiToIntPtr(Node* value) { Node* WasmGraphBuilder::BuildChangeSmiToIntPtr(Node* value) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment