Commit fa69cbb8 authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Allow OptionalOperator to return a placeholder.

R=bmeurer@chromium.org, ahaas@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2112733003
Cr-Commit-Position: refs/heads/master@{#37445}
parent eb2a84d2
......@@ -601,10 +601,10 @@ MachineOperatorBuilder::MachineOperatorBuilder(
PURE_OP_LIST(PURE)
#undef PURE
#define PURE(Name, properties, value_input_count, control_input_count, \
output_count) \
const OptionalOperator MachineOperatorBuilder::Name() { \
return OptionalOperator(flags_ & k##Name ? &cache_.k##Name : nullptr); \
#define PURE(Name, properties, value_input_count, control_input_count, \
output_count) \
const OptionalOperator MachineOperatorBuilder::Name() { \
return OptionalOperator(flags_ & k##Name, &cache_.k##Name); \
}
PURE_OPTIONAL_OP_LIST(PURE)
#undef PURE
......@@ -698,20 +698,6 @@ const Operator* MachineOperatorBuilder::CheckedStore(
return nullptr;
}
// On 32 bit platforms we need to get a reference to optional operators of
// 64-bit instructions for later Int64Lowering, even though 32 bit platforms
// don't support the original 64-bit instruction.
const Operator* MachineOperatorBuilder::Word64PopcntPlaceholder() {
return &cache_.kWord64Popcnt;
}
// On 32 bit platforms we need to get a reference to optional operators of
// 64-bit instructions for later Int64Lowering, even though 32 bit platforms
// don't support the original 64-bit instruction.
const Operator* MachineOperatorBuilder::Word64CtzPlaceholder() {
return &cache_.kWord64Ctz;
}
const Operator* MachineOperatorBuilder::AtomicLoad(LoadRepresentation rep) {
#define LOAD(Type) \
if (rep == MachineType::Type()) { \
......
......@@ -20,15 +20,21 @@ class Operator;
// For operators that are not supported on all platforms.
class OptionalOperator final {
public:
explicit OptionalOperator(const Operator* op) : op_(op) {}
OptionalOperator(bool supported, const Operator* op)
: supported_(supported), op_(op) {}
bool IsSupported() const { return op_ != nullptr; }
bool IsSupported() const { return supported_; }
// Gets the operator only if it is supported.
const Operator* op() const {
DCHECK_NOT_NULL(op_);
DCHECK(supported_);
return op_;
}
// Always gets the operator, even for unsupported operators. This is useful to
// use the operator as a placeholder in a graph, for instance.
const Operator* placeholder() const { return op_; }
private:
bool supported_;
const Operator* const op_;
};
......@@ -209,7 +215,6 @@ class MachineOperatorBuilder final : public ZoneObject {
const OptionalOperator Word32Ctz();
const OptionalOperator Word32Popcnt();
const OptionalOperator Word64Popcnt();
const Operator* Word64PopcntPlaceholder();
const OptionalOperator Word32ReverseBits();
const OptionalOperator Word64ReverseBits();
bool Word32ShiftIsSafe() const { return flags_ & kWord32ShiftIsSafe; }
......@@ -223,7 +228,6 @@ class MachineOperatorBuilder final : public ZoneObject {
const Operator* Word64Ror();
const Operator* Word64Clz();
const OptionalOperator Word64Ctz();
const Operator* Word64CtzPlaceholder();
const Operator* Word64Equal();
const Operator* Int32PairAdd();
......
......@@ -823,11 +823,12 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input,
op = m->Word64Clz();
break;
case wasm::kExprI64Ctz: {
if (m->Word64Ctz().IsSupported()) {
op = m->Word64Ctz().op();
OptionalOperator ctz64 = m->Word64Ctz();
if (ctz64.IsSupported()) {
op = ctz64.op();
break;
} else if (m->Is32() && m->Word32Ctz().IsSupported()) {
op = m->Word64CtzPlaceholder();
op = ctz64.placeholder();
break;
} else if (m->Word64ReverseBits().IsSupported()) {
Node* reversed = graph()->NewNode(m->Word64ReverseBits().op(), input);
......@@ -838,10 +839,11 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input,
}
}
case wasm::kExprI64Popcnt: {
if (m->Word64Popcnt().IsSupported()) {
op = m->Word64Popcnt().op();
OptionalOperator popcnt64 = m->Word64Popcnt();
if (popcnt64.IsSupported()) {
op = popcnt64.op();
} else if (m->Is32() && m->Word32Popcnt().IsSupported()) {
op = m->Word64PopcntPlaceholder();
op = popcnt64.placeholder();
} else {
return BuildI64Popcnt(input);
}
......
......@@ -628,7 +628,7 @@ TEST_F(Int64LoweringTest, I64Clz) {
}
TEST_F(Int64LoweringTest, I64Ctz) {
LowerGraph(graph()->NewNode(machine()->Word64CtzPlaceholder(),
LowerGraph(graph()->NewNode(machine()->Word64Ctz().placeholder(),
Int64Constant(value(0))),
MachineRepresentation::kWord64);
Capture<Node*> branch_capture;
......@@ -668,7 +668,7 @@ TEST_F(Int64LoweringTest, Dfs) {
}
TEST_F(Int64LoweringTest, I64Popcnt) {
LowerGraph(graph()->NewNode(machine()->Word64PopcntPlaceholder(),
LowerGraph(graph()->NewNode(machine()->Word64Popcnt().placeholder(),
Int64Constant(value(0))),
MachineRepresentation::kWord64);
......
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