chromium/third_party/spirv-tools/src/source/opt/instruction.h

// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SOURCE_OPT_INSTRUCTION_H_
#define SOURCE_OPT_INSTRUCTION_H_

#include <cassert>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "NonSemanticShaderDebugInfo100.h"
#include "OpenCLDebugInfo100.h"
#include "source/binary.h"
#include "source/common_debug_info.h"
#include "source/latest_version_glsl_std_450_header.h"
#include "source/latest_version_spirv_header.h"
#include "source/opcode.h"
#include "source/operand.h"
#include "source/opt/reflect.h"
#include "source/util/ilist_node.h"
#include "source/util/small_vector.h"
#include "source/util/string_utils.h"
#include "spirv-tools/libspirv.h"

constexpr uint32_t kNoDebugScope =;
constexpr uint32_t kNoInlinedAt =;

namespace spvtools {
namespace opt {

class Function;
class IRContext;
class Module;
class InstructionList;

// Relaxed logical addressing:
//
// In the logical addressing model, pointers cannot be stored or loaded.  This
// is a useful assumption because it simplifies the aliasing significantly.
// However, for the purpose of legalizing code generated from HLSL, we will have
// to allow storing and loading of pointers to opaque objects and runtime
// arrays.  This relaxation of the rule still implies that function and private
// scope variables do not have any aliasing, so we can treat them as before.
// This will be call the relaxed logical addressing model.
//
// This relaxation of the rule will be allowed by |GetBaseAddress|, but it will
// enforce that no other pointers are stored or loaded.

// About operand:
//
// In the SPIR-V specification, the term "operand" is used to mean any single
// SPIR-V word following the leading wordcount-opcode word. Here, the term
// "operand" is used to mean a *logical* operand. A logical operand may consist
// of multiple SPIR-V words, which together make up the same component. For
// example, a logical operand of a 64-bit integer needs two words to express.
//
// Further, we categorize logical operands into *in* and *out* operands.
// In operands are operands actually serve as input to operations, while out
// operands are operands that represent ids generated from operations (result
// type id or result id). For example, for "OpIAdd %rtype %rid %inop1 %inop2",
// "%inop1" and "%inop2" are in operands, while "%rtype" and "%rid" are out
// operands.

// A *logical* operand to a SPIR-V instruction. It can be the type id, result
// id, or other additional operands carried in an instruction.
struct Operand {};

inline bool operator!=(const Operand& o1, const Operand& o2) {}

// This structure is used to represent a DebugScope instruction from
// the OpenCL.100.DebugInfo extended instruction set. Note that we can
// ignore the result id of DebugScope instruction because it is not
// used for anything. We do not keep it to reduce the size of
// structure.
// TODO: Let validator check that the result id is not used anywhere.
class DebugScope {};

// A SPIR-V instruction. It contains the opcode and any additional logical
// operand, including the result id (if any) and result type id (if any). It
// may also contain line-related debug instruction (OpLine, OpNoLine) directly
// appearing before this instruction. Note that the result id of an instruction
// should never change after the instruction being built. If the result id
// needs to change, the user should create a new instruction instead.
class Instruction : public utils::IntrusiveNodeBase<Instruction> {};

// Pretty-prints |inst| to |str| and returns |str|.
//
// Provides the disassembly of a specific instruction. Utilizes |inst|'s context
// to provide the correct interpretation of types, constants, etc.
//
// Disassembly uses raw ids (not pretty printed names).
std::ostream& operator<<(std::ostream& str, const Instruction& inst);

inline bool Instruction::operator==(const Instruction& other) const {}

inline bool Instruction::operator!=(const Instruction& other) const {}

inline bool Instruction::operator<(const Instruction& other) const {}

inline Operand& Instruction::GetOperand(uint32_t index) {}

inline const Operand& Instruction::GetOperand(uint32_t index) const {}

inline void Instruction::AddOperand(Operand&& operand) {}

inline void Instruction::AddOperand(const Operand& operand) {}

inline void Instruction::SetInOperand(uint32_t index,
                                      Operand::OperandData&& data) {}

inline void Instruction::SetOperand(uint32_t index,
                                    Operand::OperandData&& data) {}

inline void Instruction::SetInOperands(OperandList&& new_operands) {}

inline void Instruction::SetResultId(uint32_t res_id) {}

inline void Instruction::SetDebugScope(const DebugScope& scope) {}

inline void Instruction::SetResultType(uint32_t ty_id) {}

inline bool Instruction::IsNop() const {}

inline void Instruction::ToNop() {}

inline bool Instruction::WhileEachInst(
    const std::function<bool(Instruction*)>& f, bool run_on_debug_line_insts) {}

inline bool Instruction::WhileEachInst(
    const std::function<bool(const Instruction*)>& f,
    bool run_on_debug_line_insts) const {}

inline void Instruction::ForEachInst(const std::function<void(Instruction*)>& f,
                                     bool run_on_debug_line_insts) {}

inline void Instruction::ForEachInst(
    const std::function<void(const Instruction*)>& f,
    bool run_on_debug_line_insts) const {}

inline void Instruction::ForEachId(const std::function<void(uint32_t*)>& f) {}

inline void Instruction::ForEachId(
    const std::function<void(const uint32_t*)>& f) const {}

inline bool Instruction::WhileEachInId(
    const std::function<bool(uint32_t*)>& f) {}

inline bool Instruction::WhileEachInId(
    const std::function<bool(const uint32_t*)>& f) const {}

inline void Instruction::ForEachInId(const std::function<void(uint32_t*)>& f) {}

inline void Instruction::ForEachInId(
    const std::function<void(const uint32_t*)>& f) const {}

inline bool Instruction::WhileEachInOperand(
    const std::function<bool(uint32_t*)>& f) {}

inline bool Instruction::WhileEachInOperand(
    const std::function<bool(const uint32_t*)>& f) const {}

inline void Instruction::ForEachInOperand(
    const std::function<void(uint32_t*)>& f) {}

inline void Instruction::ForEachInOperand(
    const std::function<void(const uint32_t*)>& f) const {}

inline bool Instruction::HasLabels() const {}

bool Instruction::IsDecoration() const {}

bool Instruction::IsLoad() const {}

bool Instruction::IsAtomicWithLoad() const {}

bool Instruction::IsAtomicOp() const {}

bool Instruction::IsConstant() const {}
}  // namespace opt
}  // namespace spvtools

#endif  // SOURCE_OPT_INSTRUCTION_H_