// Copyright 2023 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_TURBOSHAFT_OPMASKS_H_ #define V8_COMPILER_TURBOSHAFT_OPMASKS_H_ #include "src/compiler/turboshaft/operations.h" #include "src/compiler/turboshaft/representations.h" // The Opmasks allow performing a type check or cast with an operation mask // that doesn't only encode the opcode but also additional properties, i.e. // fields of an operation. // The type check will be expressed by masking out the first 8 bytes of the // object based on a generic Opmask and then comparing it against a specific // shape of that mask. // // Given the following operation and mask definitions: // // struct ConvertOp : FixedArityOperationT<1, ConvertOp> { // enum Type : int8_t {kBool, kInt, kFloat}; // Type from; // Type to; // }; // // using ConvertOpMask = // MaskBuilder<ConvertOp, FIELD(ConvertOp, from), FIELD(ConvertOp, to)>; // using ConvertOpTargetMask = MaskBuilder<ConvertOp, FIELD(ConvertOp, to)>; // // using ConvertFloatToInt = // ConvertOpMask::For<ConvertOp::kFloat, ConvertOp::kInt>; // using ConvertToInt = // ConvertOpTargetMask::For<ConvertOp::kInt>; // // The masks can be used in the following way: // // const Operation& my_op = ...; // bool is_float_to_int = my_op.Is<ConvertFloatToInt>(); // const ConvertOp* to_int = my_op.TryCast<ConvertToInt>(); // // Where to_int will be non-null iff my_op is a ConvertOp *and* the target type // is int. namespace v8::internal::compiler::turboshaftOpmask // namespace v8::internal::compiler::turboshaft::Opmask #endif // V8_COMPILER_TURBOSHAFT_OPMASKS_H_