2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// 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.
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#ifndef SOURCE_OPCODE_H_
|
|
|
|
#define SOURCE_OPCODE_H_
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/instruction.h"
|
|
|
|
#include "source/latest_version_spirv_header.h"
|
|
|
|
#include "source/table.h"
|
2016-02-17 19:44:00 +00:00
|
|
|
#include "spirv-tools/libspirv.h"
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-16 15:48:43 +00:00
|
|
|
// Returns the name of a registered SPIR-V generator as a null-terminated
|
|
|
|
// string. If the generator is not known, then returns the string "Unknown".
|
|
|
|
// The generator parameter should be most significant 16-bits of the generator
|
|
|
|
// word in the SPIR-V module header.
|
|
|
|
//
|
|
|
|
// See the registry at https://www.khronos.org/registry/spir-v/api/spir-v.xml.
|
2015-11-02 14:41:20 +00:00
|
|
|
const char* spvGeneratorStr(uint32_t generator);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-16 15:48:43 +00:00
|
|
|
// Combines word_count and opcode enumerant in single word.
|
2022-11-04 21:27:10 +00:00
|
|
|
uint32_t spvOpcodeMake(uint16_t word_count, spv::Op opcode);
|
2015-11-16 15:48:43 +00:00
|
|
|
|
|
|
|
// Splits word into into two constituent parts: word_count and opcode.
|
2016-03-31 21:26:31 +00:00
|
|
|
void spvOpcodeSplit(const uint32_t word, uint16_t* word_count,
|
|
|
|
uint16_t* opcode);
|
2015-11-16 15:48:43 +00:00
|
|
|
|
|
|
|
// Finds the named opcode in the given opcode table. On success, returns
|
|
|
|
// SPV_SUCCESS and writes a handle of the table entry into *entry.
|
2018-03-14 17:06:18 +00:00
|
|
|
spv_result_t spvOpcodeTableNameLookup(spv_target_env,
|
|
|
|
const spv_opcode_table table,
|
2015-11-16 15:48:43 +00:00
|
|
|
const char* name, spv_opcode_desc* entry);
|
|
|
|
|
|
|
|
// Finds the opcode by enumerant in the given opcode table. On success, returns
|
|
|
|
// SPV_SUCCESS and writes a handle of the table entry into *entry.
|
2018-03-14 17:06:18 +00:00
|
|
|
spv_result_t spvOpcodeTableValueLookup(spv_target_env,
|
|
|
|
const spv_opcode_table table,
|
2022-11-04 21:27:10 +00:00
|
|
|
const spv::Op opcode,
|
2015-11-16 15:48:43 +00:00
|
|
|
spv_opcode_desc* entry);
|
|
|
|
|
|
|
|
// Copies an instruction's word and fixes the endianness to host native. The
|
|
|
|
// source instruction's stream/opcode/endianness is in the words/opcode/endian
|
|
|
|
// parameter. The word_count parameter specifies the number of words to copy.
|
|
|
|
// Writes copied instruction into *inst.
|
2022-11-04 21:27:10 +00:00
|
|
|
void spvInstructionCopy(const uint32_t* words, const spv::Op opcode,
|
2015-11-16 15:48:43 +00:00
|
|
|
const uint16_t word_count,
|
|
|
|
const spv_endianness_t endian, spv_instruction_t* inst);
|
|
|
|
|
|
|
|
// Determine if the given opcode is a scalar type. Returns zero if false,
|
|
|
|
// non-zero otherwise.
|
2022-11-04 21:27:10 +00:00
|
|
|
int32_t spvOpcodeIsScalarType(const spv::Op opcode);
|
2018-03-23 18:18:54 +00:00
|
|
|
|
|
|
|
// Determines if the given opcode is a specialization constant. Returns zero if
|
|
|
|
// false, non-zero otherwise.
|
2022-11-04 21:27:10 +00:00
|
|
|
int32_t spvOpcodeIsSpecConstant(const spv::Op opcode);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2015-11-16 15:48:43 +00:00
|
|
|
// Determines if the given opcode is a constant. Returns zero if false, non-zero
|
|
|
|
// otherwise.
|
2022-11-04 21:27:10 +00:00
|
|
|
int32_t spvOpcodeIsConstant(const spv::Op opcode);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-09-14 15:57:20 +00:00
|
|
|
// Returns true if the given opcode is a constant or undef.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsConstantOrUndef(const spv::Op opcode);
|
2016-09-14 15:57:20 +00:00
|
|
|
|
2017-02-25 01:43:28 +00:00
|
|
|
// Returns true if the given opcode is a scalar specialization constant.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsScalarSpecConstant(const spv::Op opcode);
|
2017-02-25 01:43:28 +00:00
|
|
|
|
2015-11-16 15:48:43 +00:00
|
|
|
// Determines if the given opcode is a composite type. Returns zero if false,
|
|
|
|
// non-zero otherwise.
|
2022-11-04 21:27:10 +00:00
|
|
|
int32_t spvOpcodeIsComposite(const spv::Op opcode);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-03-02 21:17:54 +00:00
|
|
|
// Determines if the given opcode results in a pointer when using the logical
|
|
|
|
// addressing model. Returns zero if false, non-zero otherwise.
|
2022-11-04 21:27:10 +00:00
|
|
|
int32_t spvOpcodeReturnsLogicalPointer(const spv::Op opcode);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-02-01 20:37:39 +00:00
|
|
|
// Returns whether the given opcode could result in a pointer or a variable
|
|
|
|
// pointer when using the logical addressing model.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeReturnsLogicalVariablePointer(const spv::Op opcode);
|
2017-02-01 20:37:39 +00:00
|
|
|
|
2015-11-16 15:48:43 +00:00
|
|
|
// Determines if the given opcode generates a type. Returns zero if false,
|
|
|
|
// non-zero otherwise.
|
2022-11-04 21:27:10 +00:00
|
|
|
int32_t spvOpcodeGeneratesType(spv::Op opcode);
|
2015-09-29 15:28:34 +00:00
|
|
|
|
2017-11-11 01:26:55 +00:00
|
|
|
// Returns true if the opcode adds a decoration to an id.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsDecoration(const spv::Op opcode);
|
2017-11-13 20:31:43 +00:00
|
|
|
|
2017-11-11 01:26:55 +00:00
|
|
|
// Returns true if the opcode is a load from memory into a result id. This
|
|
|
|
// function only considers core instructions.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsLoad(const spv::Op opcode);
|
2018-10-12 12:46:35 +00:00
|
|
|
|
|
|
|
// Returns true if the opcode is an atomic operation that uses the original
|
|
|
|
// value.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsAtomicWithLoad(const spv::Op opcode);
|
2017-11-11 01:26:55 +00:00
|
|
|
|
|
|
|
// Returns true if the opcode is an atomic operation.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsAtomicOp(const spv::Op opcode);
|
2017-11-11 01:26:55 +00:00
|
|
|
|
2017-11-17 13:59:25 +00:00
|
|
|
// Returns true if the given opcode is a branch instruction.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsBranch(spv::Op opcode);
|
2017-11-17 13:59:25 +00:00
|
|
|
|
|
|
|
// Returns true if the given opcode is a return instruction.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsReturn(spv::Op opcode);
|
2017-11-17 13:59:25 +00:00
|
|
|
|
2022-09-21 20:10:58 +00:00
|
|
|
// Returns true if the given opcode aborts execution. To abort means that after
|
|
|
|
// executing that instruction, no other instructions will be executed regardless
|
|
|
|
// of the context in which the instruction appears. Note that `OpUnreachable`
|
|
|
|
// is considered an abort even if its behaviour is undefined.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsAbort(spv::Op opcode);
|
2020-12-07 15:26:05 +00:00
|
|
|
|
2018-01-03 20:25:03 +00:00
|
|
|
// Returns true if the given opcode is a return instruction or it aborts
|
|
|
|
// execution.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsReturnOrAbort(spv::Op opcode);
|
2018-01-03 20:25:03 +00:00
|
|
|
|
2017-11-17 13:59:25 +00:00
|
|
|
// Returns true if the given opcode is a basic block terminator.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsBlockTerminator(spv::Op opcode);
|
2017-11-17 13:59:25 +00:00
|
|
|
|
2017-12-11 18:10:24 +00:00
|
|
|
// Returns true if the given opcode always defines an opaque type.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsBaseOpaqueType(spv::Op opcode);
|
2018-04-17 14:18:59 +00:00
|
|
|
|
|
|
|
// Returns true if the given opcode is a non-uniform group operation.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsNonUniformGroupOperation(spv::Op opcode);
|
2018-04-23 15:13:07 +00:00
|
|
|
|
2018-04-23 15:17:07 +00:00
|
|
|
// Returns true if the opcode with vector inputs could be divided into a series
|
|
|
|
// of independent scalar operations that would give the same result.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsScalarizable(spv::Op opcode);
|
2018-11-20 21:12:28 +00:00
|
|
|
|
|
|
|
// Returns true if the given opcode is a debug instruction.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsDebug(spv::Op opcode);
|
2018-11-20 21:12:28 +00:00
|
|
|
|
2020-03-05 08:18:39 +00:00
|
|
|
// Returns true for opcodes that are binary operators,
|
|
|
|
// where the order of the operands is irrelevant.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsCommutativeBinaryOperator(spv::Op opcode);
|
2020-03-05 08:18:39 +00:00
|
|
|
|
2020-09-15 22:36:23 +00:00
|
|
|
// Returns true for opcodes that represent linear algebra instructions.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsLinearAlgebra(spv::Op opcode);
|
2020-06-16 10:20:51 +00:00
|
|
|
|
2020-09-15 22:36:23 +00:00
|
|
|
// Returns true for opcodes that represent image sample instructions.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsImageSample(spv::Op opcode);
|
2020-07-08 16:07:04 +00:00
|
|
|
|
2024-06-06 10:17:51 +00:00
|
|
|
// Returns true if the opcode is either OpExtInst or OpExtInstWithForwardRefsKHR
|
2024-06-04 14:18:06 +00:00
|
|
|
bool spvIsExtendedInstruction(spv::Op opcode);
|
|
|
|
|
2019-03-14 17:34:33 +00:00
|
|
|
// Returns a vector containing the indices of the memory semantics <id>
|
|
|
|
// operands for |opcode|.
|
2022-11-04 21:27:10 +00:00
|
|
|
std::vector<uint32_t> spvOpcodeMemorySemanticsOperandIndices(spv::Op opcode);
|
2019-03-14 17:34:33 +00:00
|
|
|
|
2020-09-15 22:36:23 +00:00
|
|
|
// Returns true for opcodes that represent access chain instructions.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsAccessChain(spv::Op opcode);
|
2020-08-11 15:21:36 +00:00
|
|
|
|
2020-09-15 22:36:23 +00:00
|
|
|
// Returns true for opcodes that represent bit instructions.
|
2022-11-04 21:27:10 +00:00
|
|
|
bool spvOpcodeIsBit(spv::Op opcode);
|
|
|
|
|
|
|
|
// Gets the name of an instruction, without the "Op" prefix.
|
|
|
|
const char* spvOpcodeString(const spv::Op opcode);
|
2020-09-15 22:36:23 +00:00
|
|
|
|
2024-07-17 18:51:37 +00:00
|
|
|
// Returns true for opcodes that generate an untyped pointer result.
|
|
|
|
bool spvOpcodeGeneratesUntypedPointer(spv::Op opcode);
|
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#endif // SOURCE_OPCODE_H_
|