Commit 204441b2 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Make some fields const in WasmGraphBuilder

WasmGraphBuilder contains fields which store state which is modified
during graph construction, other fields store information which is
never modified. Make the latter fields const.

R=mtrofin@chromium.org

Change-Id: I3ea57fbca6b24247989f5ae7260ffed2013ad82a
Reviewed-on: https://chromium-review.googlesource.com/850396
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50371}
parent 37d325a3
......@@ -69,6 +69,13 @@ void MergeControlToEnd(JSGraph* jsgraph, Node* node) {
}
}
bool ContainsSimd(wasm::FunctionSig* sig) {
for (wasm::ValueType t : sig->all()) {
if (t == wasm::kWasmS128) return true;
}
return false;
}
} // namespace
WasmGraphBuilder::WasmGraphBuilder(
......@@ -85,17 +92,12 @@ WasmGraphBuilder::WasmGraphBuilder(
function_table_sizes_(zone),
cur_buffer_(def_buffer_),
cur_bufsize_(kDefaultBufferSize),
has_simd_(ContainsSimd(sig)),
untrusted_code_mitigations_(FLAG_untrusted_code_mitigations),
runtime_exception_support_(exception_support),
sig_(sig),
source_position_table_(source_position_table) {
DCHECK_IMPLIES(use_trap_handler(), trap_handler::IsTrapHandlerEnabled());
for (size_t i = sig->parameter_count(); i > 0 && !has_simd_; --i) {
if (sig->GetParam(i - 1) == wasm::kWasmS128) has_simd_ = true;
}
for (size_t i = sig->return_count(); i > 0 && !has_simd_; --i) {
if (sig->GetReturn(i - 1) == wasm::kWasmS128) has_simd_ = true;
}
DCHECK_NOT_NULL(jsgraph_);
}
......@@ -2356,7 +2358,7 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args,
// Make room for the wasm_context parameter at index 1, just after code.
memmove(&args[2], &args[1], params * sizeof(Node*));
args[1] = wasm_context_;
args[1] = wasm_context_.get();
// Add effect and control inputs.
args[params + 2] = *effect_;
......@@ -2848,7 +2850,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(WasmCodeWrapper wasm_code,
// the wasm function could not be re-imported into another wasm module.
int pos = 0;
args[pos++] = wasm_code_node;
args[pos++] = wasm_context_;
args[pos++] = wasm_context_.get();
args[pos++] = *effect_;
args[pos++] = *control_;
......@@ -2863,7 +2865,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(WasmCodeWrapper wasm_code,
int pos = 0;
args[pos++] = wasm_code_node;
args[pos++] = wasm_context_;
args[pos++] = wasm_context_.get();
// Convert JS parameters to wasm numbers.
for (int i = 0; i < wasm_count; ++i) {
......@@ -3199,7 +3201,7 @@ void WasmGraphBuilder::BuildCWasmEntry(Address wasm_context_address) {
int pos = 0;
args[pos++] = code_obj;
args[pos++] = wasm_context_;
args[pos++] = wasm_context_.get();
int offset = 0;
for (wasm::ValueType type : sig_->parameters()) {
......@@ -3254,7 +3256,7 @@ void WasmGraphBuilder::InitContextCache(WasmContextCacheNodes* context_cache) {
// Load the memory start.
Node* mem_start = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::UintPtr()), wasm_context_,
jsgraph()->machine()->Load(MachineType::UintPtr()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, mem_start))),
*effect_, *control_);
......@@ -3263,7 +3265,7 @@ void WasmGraphBuilder::InitContextCache(WasmContextCacheNodes* context_cache) {
// Load the memory size.
Node* mem_size = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::Uint32()), wasm_context_,
jsgraph()->machine()->Load(MachineType::Uint32()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, mem_size))),
*effect_, *control_);
......@@ -3273,7 +3275,7 @@ void WasmGraphBuilder::InitContextCache(WasmContextCacheNodes* context_cache) {
if (untrusted_code_mitigations_) {
// Load the memory mask.
Node* mem_mask = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::Uint32()), wasm_context_,
jsgraph()->machine()->Load(MachineType::Uint32()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, mem_mask))),
*effect_, *control_);
......@@ -3375,12 +3377,12 @@ void WasmGraphBuilder::GetGlobalBaseAndOffset(MachineType mem_type,
// possible to express in the graph, and would essentially constitute a
// "mem2reg" optimization in TurboFan.
globals_start_ = graph()->NewNode(
jsgraph()->machine()->Load(MachineType::UintPtr()), wasm_context_,
jsgraph()->machine()->Load(MachineType::UintPtr()), wasm_context_.get(),
jsgraph()->Int32Constant(
static_cast<int32_t>(offsetof(WasmContext, globals_start))),
graph()->start(), graph()->start());
}
*base_node = globals_start_;
*base_node = globals_start_.get();
*offset_node = jsgraph()->Int32Constant(offset);
if (mem_type == MachineType::Simd128() && offset != 0) {
......
......@@ -425,35 +425,35 @@ class WasmGraphBuilder {
enum class NumericImplementation : uint8_t { kTrap, kSaturate };
static const int kDefaultBufferSize = 16;
Zone* zone_;
JSGraph* jsgraph_;
Node* centry_stub_node_;
Zone* const zone_;
JSGraph* const jsgraph_;
Node* const centry_stub_node_;
// env_ == nullptr means we're not compiling Wasm functions, such as for
// wrappers or interpreter stubs.
ModuleEnv* env_ = nullptr;
Node* wasm_context_ = nullptr;
ModuleEnv* const env_ = nullptr;
SetOncePointer<Node> wasm_context_;
NodeVector signature_tables_;
NodeVector function_tables_;
NodeVector function_table_sizes_;
Node** control_ = nullptr;
Node** effect_ = nullptr;
WasmContextCacheNodes* context_cache_ = nullptr;
Node* globals_start_ = nullptr;
SetOncePointer<Node> globals_start_;
Node** cur_buffer_;
size_t cur_bufsize_;
Node* def_buffer_[kDefaultBufferSize];
bool has_simd_ = false;
bool needs_stack_check_ = false;
bool untrusted_code_mitigations_ = true;
const bool untrusted_code_mitigations_ = true;
// If the runtime doesn't support exception propagation,
// we won't generate stack checks, and trap handling will also
// be generated differently.
RuntimeExceptionSupport runtime_exception_support_;
const RuntimeExceptionSupport runtime_exception_support_;
wasm::FunctionSig* sig_;
wasm::FunctionSig* const sig_;
SetOncePointer<const Operator> allocate_heap_number_operator_;
compiler::SourcePositionTable* source_position_table_ = nullptr;
compiler::SourcePositionTable* const source_position_table_ = nullptr;
// Internal helper methods.
JSGraph* jsgraph() { return jsgraph_; }
......
......@@ -641,7 +641,7 @@ class Access {
template<typename T>
class SetOncePointer {
public:
SetOncePointer() : pointer_(nullptr) {}
SetOncePointer() = default;
bool is_set() const { return pointer_ != nullptr; }
......@@ -655,8 +655,16 @@ class SetOncePointer {
pointer_ = value;
}
T* operator=(T* value) {
set(value);
return value;
}
bool operator==(std::nullptr_t) const { return pointer_ == nullptr; }
bool operator!=(std::nullptr_t) const { return pointer_ != nullptr; }
private:
T* pointer_;
T* pointer_ = nullptr;
};
......
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