decompression-elimination.h 3.13 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2019 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.

#ifndef V8_COMPILER_DECOMPRESSION_ELIMINATION_H_
#define V8_COMPILER_DECOMPRESSION_ELIMINATION_H_

8
#include "src/compiler/common-operator.h"
9
#include "src/compiler/graph-reducer.h"
10 11
#include "src/compiler/graph.h"
#include "src/compiler/machine-operator.h"
12 13 14 15 16 17 18 19 20

namespace v8 {
namespace internal {
namespace compiler {

// Performs elimination of redundant decompressions within the graph.
class V8_EXPORT_PRIVATE DecompressionElimination final
    : public NON_EXPORTED_BASE(AdvancedReducer) {
 public:
21
  explicit DecompressionElimination(Editor* editor, Graph* graph,
22 23
                                    MachineOperatorBuilder* machine,
                                    CommonOperatorBuilder* common);
24 25 26 27 28 29 30 31 32
  ~DecompressionElimination() final = default;

  const char* reducer_name() const override {
    return "DecompressionElimination";
  }

  Reduction Reduce(Node* node) final;

 private:
33 34 35 36
  // Returns true if the decompress opcode is valid for the compressed one.
  bool IsValidDecompress(IrOpcode::Value compressOpcode,
                         IrOpcode::Value decompressOpcode);

37
  // Returns true if the constant opcode is a reducible one in decompression
38
  // elimination.
39
  bool IsReducibleConstantOpcode(IrOpcode::Value opcode);
40

41
  // Get the new 32 bit node constant given the 64 bit one.
42 43
  Node* GetCompressedConstant(Node* constant);

44 45 46 47 48 49 50
  // Removes direct Decompressions & Compressions, going from
  //     Parent <- Decompression <- Compression <- Child
  // to
  //     Parent <- Child
  // Can be used for Any, Signed, and Pointer compressions.
  Reduction ReduceCompress(Node* node);

51 52 53
  // Removes direct Compressions & Decompressions, analogously to ReduceCompress
  Reduction ReduceDecompress(Node* node);

54 55 56 57 58
  // Replaces Phi's input decompressions with their input node, if and only if
  // all of the Phi's inputs are Decompress nodes.
  Reduction ReducePhi(Node* node);

  // Replaces TypedStateValues's input decompressions with their input node.
59 60
  Reduction ReduceTypedStateValues(Node* node);

61
  // Replaces a Word64Equal with a Word32Equal if both of its inputs are
62 63 64 65
  // Decompress nodes, or if one is a Decompress node and the other a constant.
  // In the case of two decompresses, it uses the original inputs before they
  // are decompressed. In the case of having a constant, it uses the compressed
  // value of that constant.
66 67
  Reduction ReduceWord64Equal(Node* node);

68 69 70 71 72
  // This is a workaround for load elimination test.
  // Replaces Compress -> BitcastWordToTaggedSigned -> ReducibleConstant
  // to CompressedConstant on both inputs of Word32Equal operation.
  Reduction ReduceWord32Equal(Node* node);

73 74
  Graph* graph() const { return graph_; }
  MachineOperatorBuilder* machine() const { return machine_; }
75 76
  CommonOperatorBuilder* common() const { return common_; }

77 78
  Graph* const graph_;
  MachineOperatorBuilder* const machine_;
79
  CommonOperatorBuilder* const common_;
80 81 82 83 84 85 86
};

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

#endif  // V8_COMPILER_DECOMPRESSION_ELIMINATION_H_