chromium/v8/src/compiler/machine-operator-reducer.cc

// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/machine-operator-reducer.h"

#include <cmath>
#include <cstdint>
#include <limits>
#include <optional>

#include "src/base/bits.h"
#include "src/base/division-by-constant.h"
#include "src/base/ieee754.h"
#include "src/base/logging.h"
#include "src/base/overflowing-math.h"
#include "src/builtins/builtins.h"
#include "src/compiler/diamond.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/machine-graph.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/opcodes.h"
#include "src/numbers/conversions-inl.h"

namespace v8 {
namespace internal {
namespace compiler {

// Some optimizations performed by the MachineOperatorReducer can be applied
// to both Word32 and Word64 operations. Those are implemented in a generic
// way to be reused for different word sizes.
// This class adapts a generic algorithm to Word32 operations.
class Word32Adapter {};

// Some optimizations performed by the MachineOperatorReducer can be applied
// to both Word32 and Word64 operations. Those are implemented in a generic
// way to be reused for different word sizes.
// This class adapts a generic algorithm to Word64 operations.
class Word64Adapter {};

namespace {

// TODO(jgruber): Consider replacing all uses of this function by
// std::numeric_limits<T>::quiet_NaN().
template <class T>
T SilenceNaN(T x) {}

}  // namespace

MachineOperatorReducer::MachineOperatorReducer(
    Editor* editor, MachineGraph* mcgraph,
    SignallingNanPropagation signalling_nan_propagation)
    :{}

MachineOperatorReducer::~MachineOperatorReducer() = default;

Node* MachineOperatorReducer::Float32Constant(float value) {}

Node* MachineOperatorReducer::Float64Constant(double value) {}

Node* MachineOperatorReducer::Int32Constant(int32_t value) {}

Node* MachineOperatorReducer::Int64Constant(int64_t value) {}

Node* MachineOperatorReducer::Float64Mul(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Float64PowHalf(Node* value) {}

Node* MachineOperatorReducer::Word32And(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Word32Sar(Node* lhs, uint32_t rhs) {}

Node* MachineOperatorReducer::Word64Sar(Node* lhs, uint32_t rhs) {}

Node* MachineOperatorReducer::Word32Shr(Node* lhs, uint32_t rhs) {}

Node* MachineOperatorReducer::Word64Shr(Node* lhs, uint32_t rhs) {}

Node* MachineOperatorReducer::Word32Equal(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Word64Equal(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Word64And(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int32Add(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int64Add(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int32Sub(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int64Sub(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int32Mul(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int64Mul(Node* lhs, Node* rhs) {}

Node* MachineOperatorReducer::Int32Div(Node* dividend, int32_t divisor) {}

Node* MachineOperatorReducer::Int64Div(Node* dividend, int64_t divisor) {}

Node* MachineOperatorReducer::Uint32Div(Node* dividend, uint32_t divisor) {}

Node* MachineOperatorReducer::Uint64Div(Node* dividend, uint64_t divisor) {}

Node* MachineOperatorReducer::TruncateInt64ToInt32(Node* value) {}

Node* MachineOperatorReducer::ChangeInt32ToInt64(Node* value) {}

// Perform constant folding and strength reduction on machine operators.
Reduction MachineOperatorReducer::Reduce(Node* node) {}

Reduction MachineOperatorReducer::ReduceTruncateInt64ToInt32(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt32Add(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt64Add(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt32Sub(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt64Sub(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt64Mul(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt64Div(Node* node) {}

Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {}

Reduction MachineOperatorReducer::ReduceUint64Div(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) {}

Reduction MachineOperatorReducer::ReduceInt64Mod(Node* node) {}

Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {}

Reduction MachineOperatorReducer::ReduceUint64Mod(Node* node) {}

Reduction MachineOperatorReducer::ReduceStore(Node* node) {}

Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) {}

namespace {

// Returns true if "value << shift >> shift == value". This can be interpreted
// as "left shifting |value| by |shift| doesn't shift away significant bits".
// Or, equivalently, "left shifting |value| by |shift| doesn't have signed
// overflow".
template <typename T>
bool CanRevertLeftShiftWithRightShift(T value, T shift) {}

bool CanTruncate(int64_t value) {}

}  // namespace

Reduction MachineOperatorReducer::ReduceWord32Comparisons(Node* node) {}

const Operator* MachineOperatorReducer::Map64To32Comparison(
    const Operator* op, bool sign_extended) {}

Reduction MachineOperatorReducer::ReduceWord64Comparisons(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Shifts(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Shl(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64Shl(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Shr(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64Shr(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64Sar(Node* node) {}

template <typename WordNAdapter>
Reduction MachineOperatorReducer::ReduceWordNAnd(Node* node) {}

template <typename WordNAdapter>
Reduction MachineOperatorReducer::ReduceUintNLessThanOrEqual(Node* node) {}

namespace {

// Represents an operation of the form `(source & mask) == masked_value`.
// where each bit set in masked_value also has to be set in mask.
struct BitfieldCheck {};

}  // namespace

Reduction MachineOperatorReducer::ReduceWord32And(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64And(Node* node) {}

Reduction MachineOperatorReducer::TryMatchWord32Ror(Node* node) {}

template <typename WordNAdapter>
Reduction MachineOperatorReducer::ReduceWordNOr(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64Or(Node* node) {}

template <typename WordNAdapter>
Reduction MachineOperatorReducer::ReduceWordNXor(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Xor(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64Xor(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord32Equal(Node* node) {}

Reduction MachineOperatorReducer::ReduceWord64Equal(Node* node) {}

Reduction MachineOperatorReducer::ReduceFloat64InsertLowWord32(Node* node) {}

Reduction MachineOperatorReducer::ReduceFloat64InsertHighWord32(Node* node) {}

namespace {

bool IsFloat64RepresentableAsFloat32(const Float64Matcher& m) {}

}  // namespace

Reduction MachineOperatorReducer::ReduceFloat64Compare(Node* node) {}

Reduction MachineOperatorReducer::ReduceFloat64RoundDown(Node* node) {}

namespace {

// Returns true if |node| is a constant whose value is 0.
bool IsZero(Node* node) {}

// If |node| is of the form "x == 0", then return "x" (in order to remove the
// "== 0" part).
std::optional<Node*> TryGetInvertedCondition(Node* cond) {}

struct SimplifiedCondition {};

// Tries to simplifies |cond| by removing all top-level "== 0". Everytime such a
// construction is removed, the meaning of the comparison is inverted. This is
// recorded by the variable |is_inverted| throughout this function, and returned
// at the end. If |is_inverted| is true at the end, the caller should invert the
// if/else branches following the comparison.
std::optional<SimplifiedCondition> TrySimplifyCompareZero(Node* cond) {}

/*
Remove WordEqual after WordAnd if it aims to test a bit.
For Example:
------------------------
691:  Int32Constant[8]
1857: Word32And(1838,691)
1858: Word32Equal(1857,691)
1859: Branch(1858,2141)
======>
691:  Int32Constant[8]
1857: Word32And(1838,691)
1859: Branch(1857,2141)
------------------------

Assembly code:
------------------------
andl r9,0x8
cmpb r9l,0x8
jz 0x7f242017bf3c
======>
testb r9,0x8
jnz 0x7f56c017be2e
------------------------
*/
Node* TrySimplifyCompareForTestBit(Node* cond) {}

}  // namespace

void MachineOperatorReducer::SwapBranches(Node* node) {}

// If |node| is a branch, removes all top-level 32-bit "== 0" from |node|.
Reduction MachineOperatorReducer::SimplifyBranch(Node* node) {}

Reduction MachineOperatorReducer::ReduceConditional(Node* node) {}

template <typename WordNAdapter>
std::optional<Node*> MachineOperatorReducer::ReduceConditionalN(Node* node) {}

template <typename WordNAdapter, typename uintN_t, typename intN_t>
std::optional<std::pair<Node*, uintN_t>>
MachineOperatorReducer::ReduceWordEqualForConstantRhs(Node* lhs, uintN_t rhs) {}

CommonOperatorBuilder* MachineOperatorReducer::common() const {}

MachineOperatorBuilder* MachineOperatorReducer::machine() const {}

Graph* MachineOperatorReducer::graph() const {}

}  // namespace compiler
}  // namespace internal
}  // namespace v8