2016-05-22 18:11:24 +00:00
|
|
|
// Copyright (c) 2016 Google Inc.
|
|
|
|
//
|
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
|
2016-05-22 18:11:24 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2016-05-22 18:11:24 +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.
|
2016-05-22 18:11:24 +00:00
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#ifndef SOURCE_OPT_MODULE_H_
|
|
|
|
#define SOURCE_OPT_MODULE_H_
|
2016-05-22 18:11:24 +00:00
|
|
|
|
|
|
|
#include <functional>
|
2016-07-27 21:31:23 +00:00
|
|
|
#include <memory>
|
2023-07-17 15:15:08 +00:00
|
|
|
#include <string_view>
|
2020-03-23 15:01:18 +00:00
|
|
|
#include <unordered_map>
|
2016-05-22 18:11:24 +00:00
|
|
|
#include <utility>
|
2016-05-22 18:17:39 +00:00
|
|
|
#include <vector>
|
2016-05-22 18:11:24 +00:00
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/opt/function.h"
|
|
|
|
#include "source/opt/instruction.h"
|
|
|
|
#include "source/opt/iterator.h"
|
2016-05-22 18:11:24 +00:00
|
|
|
|
|
|
|
namespace spvtools {
|
2018-07-09 15:32:29 +00:00
|
|
|
namespace opt {
|
2016-05-22 18:11:24 +00:00
|
|
|
|
2017-11-14 19:11:50 +00:00
|
|
|
class IRContext;
|
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// A struct for containing the module header information.
|
|
|
|
struct ModuleHeader {
|
|
|
|
uint32_t magic_number;
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t generator;
|
|
|
|
uint32_t bound;
|
2021-12-08 16:55:36 +00:00
|
|
|
uint32_t schema;
|
2016-05-22 18:11:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// A SPIR-V module. It contains all the information for a SPIR-V module and
|
|
|
|
// serves as the backbone of optimization transformations.
|
|
|
|
class Module {
|
|
|
|
public:
|
2016-08-10 14:02:28 +00:00
|
|
|
using iterator = UptrVectorIterator<Function>;
|
|
|
|
using const_iterator = UptrVectorIterator<Function, true>;
|
2017-10-13 18:25:21 +00:00
|
|
|
using inst_iterator = InstructionList::iterator;
|
|
|
|
using const_inst_iterator = InstructionList::const_iterator;
|
2016-08-10 14:02:28 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Creates an empty module with zero'd header.
|
2021-01-13 14:08:28 +00:00
|
|
|
Module() : header_({}), contains_debug_info_(false) {}
|
2016-05-22 18:11:24 +00:00
|
|
|
|
|
|
|
// Sets the header to the given |header|.
|
|
|
|
void SetHeader(const ModuleHeader& header) { header_ = header; }
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2018-09-10 15:49:41 +00:00
|
|
|
// Sets the Id bound. The Id bound cannot be set to 0.
|
|
|
|
void SetIdBound(uint32_t bound) {
|
|
|
|
assert(bound != 0);
|
|
|
|
header_.bound = bound;
|
|
|
|
}
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2017-03-26 19:08:41 +00:00
|
|
|
// Returns the Id bound.
|
2021-12-08 16:55:36 +00:00
|
|
|
uint32_t IdBound() const { return header_.bound; }
|
2017-12-07 21:42:27 +00:00
|
|
|
|
|
|
|
// Returns the current Id bound and increases it to the next available value.
|
2018-09-10 15:49:41 +00:00
|
|
|
// If the id bound has already reached its maximum value, then 0 is returned.
|
|
|
|
// The maximum value for the id bound is obtained from the context. If there
|
|
|
|
// is none, then the minimum that limit can be according to the spir-v
|
|
|
|
// specification.
|
|
|
|
// TODO(1841): Update the uses to check for a 0 return value.
|
|
|
|
uint32_t TakeNextIdBound();
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends a capability instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddCapability(std::unique_ptr<Instruction> c);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends an extension instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddExtension(std::unique_ptr<Instruction> e);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends an extended instruction set instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddExtInstImport(std::unique_ptr<Instruction> e);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-08-09 23:20:35 +00:00
|
|
|
// Set the memory model for this module.
|
|
|
|
inline void SetMemoryModel(std::unique_ptr<Instruction> m);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2022-07-29 19:28:27 +00:00
|
|
|
// Set the sampled image addressing mode for this module.
|
|
|
|
inline void SetSampledImageAddressMode(std::unique_ptr<Instruction> m);
|
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends an entry point instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddEntryPoint(std::unique_ptr<Instruction> e);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends an execution mode instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddExecutionMode(std::unique_ptr<Instruction> e);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
// Appends a debug 1 instruction (excluding OpLine & OpNoLine) to this module.
|
|
|
|
// "debug 1" instructions are the ones in layout section 7.a), see section
|
|
|
|
// 2.4 Logical Layout of a Module from the SPIR-V specification.
|
|
|
|
inline void AddDebug1Inst(std::unique_ptr<Instruction> d);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
// Appends a debug 2 instruction (excluding OpLine & OpNoLine) to this module.
|
|
|
|
// "debug 2" instructions are the ones in layout section 7.b), see section
|
|
|
|
// 2.4 Logical Layout of a Module from the SPIR-V specification.
|
|
|
|
inline void AddDebug2Inst(std::unique_ptr<Instruction> d);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2017-10-20 22:04:20 +00:00
|
|
|
// Appends a debug 3 instruction (OpModuleProcessed) to this module.
|
|
|
|
// This is due to decision by the SPIR Working Group, pending publication.
|
|
|
|
inline void AddDebug3Inst(std::unique_ptr<Instruction> d);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2021-07-21 16:04:38 +00:00
|
|
|
// Appends a debug info extension (OpenCL.DebugInfo.100,
|
2021-09-15 18:38:53 +00:00
|
|
|
// NonSemantic.Shader.DebugInfo.100, or DebugInfo) instruction to this module.
|
2020-01-23 22:04:30 +00:00
|
|
|
inline void AddExtInstDebugInfo(std::unique_ptr<Instruction> d);
|
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends an annotation instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddAnnotationInst(std::unique_ptr<Instruction> a);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends a type-declaration instruction to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddType(std::unique_ptr<Instruction> t);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2016-08-12 18:59:56 +00:00
|
|
|
// Appends a constant, global variable, or OpUndef instruction to this module.
|
|
|
|
inline void AddGlobalValue(std::unique_ptr<Instruction> v);
|
2017-12-07 21:42:27 +00:00
|
|
|
|
2023-09-20 16:50:30 +00:00
|
|
|
// Prepends a function declaration to this module.
|
|
|
|
inline void AddFunctionDeclaration(std::unique_ptr<Function> f);
|
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Appends a function to this module.
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void AddFunction(std::unique_ptr<Function> f);
|
2016-05-22 18:11:24 +00:00
|
|
|
|
2021-01-13 14:08:28 +00:00
|
|
|
// Sets |contains_debug_info_| as true.
|
|
|
|
inline void SetContainsDebugInfo();
|
|
|
|
inline bool ContainsDebugInfo() { return contains_debug_info_; }
|
2020-03-23 15:01:18 +00:00
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
// Returns a vector of pointers to type-declaration instructions in this
|
|
|
|
// module.
|
2016-07-28 16:15:14 +00:00
|
|
|
std::vector<Instruction*> GetTypes();
|
|
|
|
std::vector<const Instruction*> GetTypes() const;
|
2016-08-10 14:02:28 +00:00
|
|
|
// Returns a vector of pointers to constant-creation instructions in this
|
|
|
|
// module.
|
2016-07-29 15:35:58 +00:00
|
|
|
std::vector<Instruction*> GetConstants();
|
2016-08-12 13:13:04 +00:00
|
|
|
std::vector<const Instruction*> GetConstants() const;
|
2016-08-10 14:02:28 +00:00
|
|
|
|
2017-05-05 02:55:53 +00:00
|
|
|
// Return result id of global value with |opcode|, 0 if not present.
|
2022-11-04 21:27:10 +00:00
|
|
|
uint32_t GetGlobalValue(spv::Op opcode) const;
|
2017-05-05 02:55:53 +00:00
|
|
|
|
|
|
|
// Add global value with |opcode|, |result_id| and |type_id|
|
2022-11-04 21:27:10 +00:00
|
|
|
void AddGlobalValue(spv::Op opcode, uint32_t result_id, uint32_t type_id);
|
2017-05-05 02:55:53 +00:00
|
|
|
|
2016-11-10 17:11:50 +00:00
|
|
|
inline uint32_t id_bound() const { return header_.bound; }
|
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
inline uint32_t version() const { return header_.version; }
|
2021-12-08 16:55:36 +00:00
|
|
|
inline uint32_t generator() const { return header_.generator; }
|
|
|
|
inline uint32_t schema() const { return header_.schema; }
|
2017-07-13 00:16:51 +00:00
|
|
|
|
2019-08-29 16:48:17 +00:00
|
|
|
inline void set_version(uint32_t v) { header_.version = v; }
|
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
// Iterators for capabilities instructions contained in this module.
|
|
|
|
inline inst_iterator capability_begin();
|
|
|
|
inline inst_iterator capability_end();
|
|
|
|
inline IteratorRange<inst_iterator> capabilities();
|
|
|
|
inline IteratorRange<const_inst_iterator> capabilities() const;
|
|
|
|
|
|
|
|
// Iterators for ext_inst_imports instructions contained in this module.
|
|
|
|
inline inst_iterator ext_inst_import_begin();
|
|
|
|
inline inst_iterator ext_inst_import_end();
|
|
|
|
inline IteratorRange<inst_iterator> ext_inst_imports();
|
|
|
|
inline IteratorRange<const_inst_iterator> ext_inst_imports() const;
|
|
|
|
|
2022-07-29 19:28:27 +00:00
|
|
|
// Return the memory model instruction contained in this module.
|
2017-07-13 00:16:51 +00:00
|
|
|
inline Instruction* GetMemoryModel() { return memory_model_.get(); }
|
2017-10-13 18:25:21 +00:00
|
|
|
inline const Instruction* GetMemoryModel() const {
|
|
|
|
return memory_model_.get();
|
|
|
|
}
|
2017-07-13 00:16:51 +00:00
|
|
|
|
2022-07-29 19:28:27 +00:00
|
|
|
// Return the sampled image address mode instruction contained in this module.
|
|
|
|
inline Instruction* GetSampledImageAddressMode() {
|
|
|
|
return sampled_image_address_mode_.get();
|
|
|
|
}
|
|
|
|
inline const Instruction* GetSampledImageAddressMode() const {
|
|
|
|
return sampled_image_address_mode_.get();
|
|
|
|
}
|
|
|
|
|
2017-10-20 22:04:20 +00:00
|
|
|
// There are several kinds of debug instructions, according to where they can
|
|
|
|
// appear in the logical layout of a module:
|
|
|
|
// - Section 7a: OpString, OpSourceExtension, OpSource, OpSourceContinued
|
|
|
|
// - Section 7b: OpName, OpMemberName
|
|
|
|
// - Section 7c: OpModuleProcessed
|
|
|
|
// - Mostly anywhere: OpLine and OpNoLine
|
|
|
|
//
|
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
// Iterators for debug 1 instructions (excluding OpLine & OpNoLine) contained
|
2017-10-20 22:04:20 +00:00
|
|
|
// in this module. These are for layout section 7a.
|
2017-07-13 00:16:51 +00:00
|
|
|
inline inst_iterator debug1_begin();
|
|
|
|
inline inst_iterator debug1_end();
|
|
|
|
inline IteratorRange<inst_iterator> debugs1();
|
|
|
|
inline IteratorRange<const_inst_iterator> debugs1() const;
|
|
|
|
|
|
|
|
// Iterators for debug 2 instructions (excluding OpLine & OpNoLine) contained
|
2017-10-20 22:04:20 +00:00
|
|
|
// in this module. These are for layout section 7b.
|
2017-07-13 00:16:51 +00:00
|
|
|
inline inst_iterator debug2_begin();
|
|
|
|
inline inst_iterator debug2_end();
|
|
|
|
inline IteratorRange<inst_iterator> debugs2();
|
|
|
|
inline IteratorRange<const_inst_iterator> debugs2() const;
|
2016-08-10 14:02:28 +00:00
|
|
|
|
2017-10-20 22:04:20 +00:00
|
|
|
// Iterators for debug 3 instructions (excluding OpLine & OpNoLine) contained
|
|
|
|
// in this module. These are for layout section 7c.
|
|
|
|
inline inst_iterator debug3_begin();
|
|
|
|
inline inst_iterator debug3_end();
|
|
|
|
inline IteratorRange<inst_iterator> debugs3();
|
|
|
|
inline IteratorRange<const_inst_iterator> debugs3() const;
|
|
|
|
|
2020-01-23 22:04:30 +00:00
|
|
|
// Iterators for debug info instructions (excluding OpLine & OpNoLine)
|
2021-07-21 16:04:38 +00:00
|
|
|
// contained in this module. These are OpExtInst for DebugInfo extension
|
|
|
|
// placed between section 9 and 10.
|
2020-01-23 22:04:30 +00:00
|
|
|
inline inst_iterator ext_inst_debuginfo_begin();
|
|
|
|
inline inst_iterator ext_inst_debuginfo_end();
|
|
|
|
inline IteratorRange<inst_iterator> ext_inst_debuginfo();
|
|
|
|
inline IteratorRange<const_inst_iterator> ext_inst_debuginfo() const;
|
|
|
|
|
2016-11-10 17:11:50 +00:00
|
|
|
// Iterators for entry point instructions contained in this module
|
|
|
|
inline IteratorRange<inst_iterator> entry_points();
|
|
|
|
inline IteratorRange<const_inst_iterator> entry_points() const;
|
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
// Iterators for execution_modes instructions contained in this module.
|
|
|
|
inline inst_iterator execution_mode_begin();
|
|
|
|
inline inst_iterator execution_mode_end();
|
|
|
|
inline IteratorRange<inst_iterator> execution_modes();
|
|
|
|
inline IteratorRange<const_inst_iterator> execution_modes() const;
|
|
|
|
|
2016-08-10 14:02:28 +00:00
|
|
|
// Iterators for annotation instructions contained in this module.
|
2017-07-13 00:16:51 +00:00
|
|
|
inline inst_iterator annotation_begin();
|
|
|
|
inline inst_iterator annotation_end();
|
2016-08-10 14:02:28 +00:00
|
|
|
IteratorRange<inst_iterator> annotations();
|
|
|
|
IteratorRange<const_inst_iterator> annotations() const;
|
|
|
|
|
2017-06-16 21:37:31 +00:00
|
|
|
// Iterators for extension instructions contained in this module.
|
2017-07-13 00:16:51 +00:00
|
|
|
inline inst_iterator extension_begin();
|
|
|
|
inline inst_iterator extension_end();
|
2017-06-16 21:37:31 +00:00
|
|
|
IteratorRange<inst_iterator> extensions();
|
|
|
|
IteratorRange<const_inst_iterator> extensions() const;
|
|
|
|
|
2016-08-12 17:12:43 +00:00
|
|
|
// Iterators for types, constants and global variables instructions.
|
|
|
|
inline inst_iterator types_values_begin();
|
|
|
|
inline inst_iterator types_values_end();
|
|
|
|
inline IteratorRange<inst_iterator> types_values();
|
|
|
|
inline IteratorRange<const_inst_iterator> types_values() const;
|
|
|
|
|
2016-08-10 14:02:28 +00:00
|
|
|
// Iterators for functions contained in this module.
|
|
|
|
iterator begin() { return iterator(&functions_, functions_.begin()); }
|
|
|
|
iterator end() { return iterator(&functions_, functions_.end()); }
|
2017-11-27 21:21:26 +00:00
|
|
|
const_iterator begin() const { return cbegin(); }
|
|
|
|
const_iterator end() const { return cend(); }
|
2016-08-10 14:02:28 +00:00
|
|
|
inline const_iterator cbegin() const;
|
|
|
|
inline const_iterator cend() const;
|
2016-05-22 18:11:24 +00:00
|
|
|
|
2016-08-20 13:47:00 +00:00
|
|
|
// Invokes function |f| on all instructions in this module, and optionally on
|
|
|
|
// the debug line instructions that precede them.
|
|
|
|
void ForEachInst(const std::function<void(Instruction*)>& f,
|
|
|
|
bool run_on_debug_line_insts = false);
|
|
|
|
void ForEachInst(const std::function<void(const Instruction*)>& f,
|
|
|
|
bool run_on_debug_line_insts = false) const;
|
2016-05-22 18:11:24 +00:00
|
|
|
|
|
|
|
// Pushes the binary segments for this instruction into the back of *|binary|.
|
|
|
|
// If |skip_nop| is true and this is a OpNop, do nothing.
|
|
|
|
void ToBinary(std::vector<uint32_t>* binary, bool skip_nop) const;
|
|
|
|
|
2016-08-23 15:41:28 +00:00
|
|
|
// Returns 1 more than the maximum Id value mentioned in the module.
|
|
|
|
uint32_t ComputeIdBound() const;
|
|
|
|
|
2017-05-05 02:55:53 +00:00
|
|
|
// Returns true if module has capability |cap|
|
2017-12-19 19:18:13 +00:00
|
|
|
bool HasExplicitCapability(uint32_t cap);
|
2017-05-05 02:55:53 +00:00
|
|
|
|
2017-06-08 16:37:21 +00:00
|
|
|
// Returns id for OpExtInst instruction for extension |extstr|.
|
|
|
|
// Returns 0 if not found.
|
|
|
|
uint32_t GetExtInstImportId(const char* extstr);
|
|
|
|
|
2017-11-14 19:11:50 +00:00
|
|
|
// Sets the associated context for this module
|
|
|
|
void SetContext(IRContext* c) { context_ = c; }
|
|
|
|
|
|
|
|
// Gets the associated context for this module
|
|
|
|
IRContext* context() const { return context_; }
|
|
|
|
|
2019-09-27 20:03:45 +00:00
|
|
|
// Sets the trailing debug line info to |dbg_line_info|.
|
|
|
|
void SetTrailingDbgLineInfo(std::vector<Instruction>&& dbg_line_info) {
|
|
|
|
trailing_dbg_line_info_ = std::move(dbg_line_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Instruction>& trailing_dbg_line_info() {
|
|
|
|
return trailing_dbg_line_info_;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Instruction>& trailing_dbg_line_info() const {
|
|
|
|
return trailing_dbg_line_info_;
|
|
|
|
}
|
|
|
|
|
2016-05-22 18:11:24 +00:00
|
|
|
private:
|
|
|
|
ModuleHeader header_; // Module header
|
|
|
|
|
|
|
|
// The following fields respect the "Logical Layout of a Module" in
|
|
|
|
// Section 2.4 of the SPIR-V specification.
|
2017-11-14 19:11:50 +00:00
|
|
|
IRContext* context_;
|
2017-10-13 18:25:21 +00:00
|
|
|
InstructionList capabilities_;
|
|
|
|
InstructionList extensions_;
|
|
|
|
InstructionList ext_inst_imports_;
|
2016-08-09 23:20:35 +00:00
|
|
|
// A module only has one memory model instruction.
|
|
|
|
std::unique_ptr<Instruction> memory_model_;
|
2022-07-29 19:28:27 +00:00
|
|
|
// A module can only have one optional sampled image addressing mode
|
|
|
|
std::unique_ptr<Instruction> sampled_image_address_mode_;
|
2017-10-13 18:25:21 +00:00
|
|
|
InstructionList entry_points_;
|
|
|
|
InstructionList execution_modes_;
|
|
|
|
InstructionList debugs1_;
|
|
|
|
InstructionList debugs2_;
|
|
|
|
InstructionList debugs3_;
|
2020-01-23 22:04:30 +00:00
|
|
|
InstructionList ext_inst_debuginfo_;
|
2017-10-13 18:25:21 +00:00
|
|
|
InstructionList annotations_;
|
2016-05-22 18:17:39 +00:00
|
|
|
// Type declarations, constants, and global variable declarations.
|
2017-10-13 18:25:21 +00:00
|
|
|
InstructionList types_values_;
|
2016-08-09 23:20:35 +00:00
|
|
|
std::vector<std::unique_ptr<Function>> functions_;
|
2019-09-27 20:03:45 +00:00
|
|
|
|
|
|
|
// If the module ends with Op*Line instruction, they will not be attached to
|
|
|
|
// any instruction. We record them here, so they will not be lost.
|
|
|
|
std::vector<Instruction> trailing_dbg_line_info_;
|
2020-03-23 15:01:18 +00:00
|
|
|
|
2021-01-13 14:08:28 +00:00
|
|
|
// This module contains DebugScope/DebugNoScope or OpLine/OpNoLine.
|
|
|
|
bool contains_debug_info_;
|
2016-05-22 18:11:24 +00:00
|
|
|
};
|
|
|
|
|
2018-01-10 19:23:47 +00:00
|
|
|
// Pretty-prints |module| to |str|. Returns |str|.
|
|
|
|
std::ostream& operator<<(std::ostream& str, const Module& module);
|
|
|
|
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void Module::AddCapability(std::unique_ptr<Instruction> c) {
|
2017-10-13 18:25:21 +00:00
|
|
|
capabilities_.push_back(std::move(c));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Module::AddExtension(std::unique_ptr<Instruction> e) {
|
2017-10-13 18:25:21 +00:00
|
|
|
extensions_.push_back(std::move(e));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Module::AddExtInstImport(std::unique_ptr<Instruction> e) {
|
2017-10-13 18:25:21 +00:00
|
|
|
ext_inst_imports_.push_back(std::move(e));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Module::SetMemoryModel(std::unique_ptr<Instruction> m) {
|
|
|
|
memory_model_ = std::move(m);
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:28:27 +00:00
|
|
|
inline void Module::SetSampledImageAddressMode(std::unique_ptr<Instruction> m) {
|
|
|
|
sampled_image_address_mode_ = std::move(m);
|
|
|
|
}
|
|
|
|
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void Module::AddEntryPoint(std::unique_ptr<Instruction> e) {
|
2017-10-13 18:25:21 +00:00
|
|
|
entry_points_.push_back(std::move(e));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Module::AddExecutionMode(std::unique_ptr<Instruction> e) {
|
2017-10-13 18:25:21 +00:00
|
|
|
execution_modes_.push_back(std::move(e));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
inline void Module::AddDebug1Inst(std::unique_ptr<Instruction> d) {
|
2017-10-13 18:25:21 +00:00
|
|
|
debugs1_.push_back(std::move(d));
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Module::AddDebug2Inst(std::unique_ptr<Instruction> d) {
|
2017-10-13 18:25:21 +00:00
|
|
|
debugs2_.push_back(std::move(d));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 22:04:20 +00:00
|
|
|
inline void Module::AddDebug3Inst(std::unique_ptr<Instruction> d) {
|
2017-10-13 18:25:21 +00:00
|
|
|
debugs3_.push_back(std::move(d));
|
2017-10-20 22:04:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 22:04:30 +00:00
|
|
|
inline void Module::AddExtInstDebugInfo(std::unique_ptr<Instruction> d) {
|
|
|
|
ext_inst_debuginfo_.push_back(std::move(d));
|
|
|
|
}
|
|
|
|
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void Module::AddAnnotationInst(std::unique_ptr<Instruction> a) {
|
2017-10-13 18:25:21 +00:00
|
|
|
annotations_.push_back(std::move(a));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void Module::AddType(std::unique_ptr<Instruction> t) {
|
2017-10-13 18:25:21 +00:00
|
|
|
types_values_.push_back(std::move(t));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 18:59:56 +00:00
|
|
|
inline void Module::AddGlobalValue(std::unique_ptr<Instruction> v) {
|
2017-10-13 18:25:21 +00:00
|
|
|
types_values_.push_back(std::move(v));
|
2016-08-09 23:20:35 +00:00
|
|
|
}
|
|
|
|
|
2023-09-20 16:50:30 +00:00
|
|
|
inline void Module::AddFunctionDeclaration(std::unique_ptr<Function> f) {
|
|
|
|
// function declarations must come before function definitions.
|
|
|
|
functions_.emplace(functions_.begin(), std::move(f));
|
|
|
|
}
|
|
|
|
|
2016-08-09 23:20:35 +00:00
|
|
|
inline void Module::AddFunction(std::unique_ptr<Function> f) {
|
|
|
|
functions_.emplace_back(std::move(f));
|
|
|
|
}
|
|
|
|
|
2021-01-13 14:08:28 +00:00
|
|
|
inline void Module::SetContainsDebugInfo() { contains_debug_info_ = true; }
|
2020-03-23 15:01:18 +00:00
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
inline Module::inst_iterator Module::capability_begin() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return capabilities_.begin();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
inline Module::inst_iterator Module::capability_end() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return capabilities_.end();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::capabilities() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(capabilities_.begin(), capabilities_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::capabilities() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(capabilities_.begin(), capabilities_.end());
|
2016-08-10 14:02:28 +00:00
|
|
|
}
|
2017-07-13 00:16:51 +00:00
|
|
|
|
|
|
|
inline Module::inst_iterator Module::ext_inst_import_begin() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return ext_inst_imports_.begin();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
inline Module::inst_iterator Module::ext_inst_import_end() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return ext_inst_imports_.end();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::ext_inst_imports() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(ext_inst_imports_.begin(), ext_inst_imports_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:25:21 +00:00
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::ext_inst_imports()
|
2017-11-08 17:40:02 +00:00
|
|
|
const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(ext_inst_imports_.begin(), ext_inst_imports_.end());
|
2016-08-10 14:02:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:25:21 +00:00
|
|
|
inline Module::inst_iterator Module::debug1_begin() { return debugs1_.begin(); }
|
|
|
|
inline Module::inst_iterator Module::debug1_end() { return debugs1_.end(); }
|
2016-08-10 14:02:28 +00:00
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
inline IteratorRange<Module::inst_iterator> Module::debugs1() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(debugs1_.begin(), debugs1_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::debugs1() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(debugs1_.begin(), debugs1_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:25:21 +00:00
|
|
|
inline Module::inst_iterator Module::debug2_begin() { return debugs2_.begin(); }
|
|
|
|
inline Module::inst_iterator Module::debug2_end() { return debugs2_.end(); }
|
2017-07-13 00:16:51 +00:00
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::debugs2() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(debugs2_.begin(), debugs2_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::debugs2() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(debugs2_.begin(), debugs2_.end());
|
2016-08-10 14:02:28 +00:00
|
|
|
}
|
2016-11-10 17:11:50 +00:00
|
|
|
|
2017-10-13 18:25:21 +00:00
|
|
|
inline Module::inst_iterator Module::debug3_begin() { return debugs3_.begin(); }
|
|
|
|
inline Module::inst_iterator Module::debug3_end() { return debugs3_.end(); }
|
2017-10-20 22:04:20 +00:00
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::debugs3() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(debugs3_.begin(), debugs3_.end());
|
2017-10-20 22:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::debugs3() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(debugs3_.begin(), debugs3_.end());
|
2017-10-20 22:04:20 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 22:04:30 +00:00
|
|
|
inline Module::inst_iterator Module::ext_inst_debuginfo_begin() {
|
|
|
|
return ext_inst_debuginfo_.begin();
|
|
|
|
}
|
|
|
|
inline Module::inst_iterator Module::ext_inst_debuginfo_end() {
|
|
|
|
return ext_inst_debuginfo_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::ext_inst_debuginfo() {
|
|
|
|
return make_range(ext_inst_debuginfo_.begin(), ext_inst_debuginfo_.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::ext_inst_debuginfo()
|
|
|
|
const {
|
|
|
|
return make_range(ext_inst_debuginfo_.begin(), ext_inst_debuginfo_.end());
|
|
|
|
}
|
|
|
|
|
2016-11-10 17:11:50 +00:00
|
|
|
inline IteratorRange<Module::inst_iterator> Module::entry_points() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(entry_points_.begin(), entry_points_.end());
|
2016-11-10 17:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::entry_points() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(entry_points_.begin(), entry_points_.end());
|
2016-11-10 17:11:50 +00:00
|
|
|
}
|
2016-08-10 14:02:28 +00:00
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
inline Module::inst_iterator Module::execution_mode_begin() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return execution_modes_.begin();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
inline Module::inst_iterator Module::execution_mode_end() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return execution_modes_.end();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::execution_modes() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(execution_modes_.begin(), execution_modes_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 18:25:21 +00:00
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::execution_modes()
|
2017-11-08 17:40:02 +00:00
|
|
|
const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(execution_modes_.begin(), execution_modes_.end());
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Module::inst_iterator Module::annotation_begin() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return annotations_.begin();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
inline Module::inst_iterator Module::annotation_end() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return annotations_.end();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 14:02:28 +00:00
|
|
|
inline IteratorRange<Module::inst_iterator> Module::annotations() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(annotations_.begin(), annotations_.end());
|
2016-08-10 14:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::annotations() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(annotations_.begin(), annotations_.end());
|
2016-08-10 14:02:28 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 00:16:51 +00:00
|
|
|
inline Module::inst_iterator Module::extension_begin() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return extensions_.begin();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
inline Module::inst_iterator Module::extension_end() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return extensions_.end();
|
2017-07-13 00:16:51 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 21:37:31 +00:00
|
|
|
inline IteratorRange<Module::inst_iterator> Module::extensions() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(extensions_.begin(), extensions_.end());
|
2017-06-16 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::extensions() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(extensions_.begin(), extensions_.end());
|
2017-06-16 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 17:12:43 +00:00
|
|
|
inline Module::inst_iterator Module::types_values_begin() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return types_values_.begin();
|
2016-08-12 17:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Module::inst_iterator Module::types_values_end() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return types_values_.end();
|
2016-08-12 17:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::inst_iterator> Module::types_values() {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(types_values_.begin(), types_values_.end());
|
2016-08-12 17:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline IteratorRange<Module::const_inst_iterator> Module::types_values() const {
|
2017-10-13 18:25:21 +00:00
|
|
|
return make_range(types_values_.begin(), types_values_.end());
|
2016-08-12 17:12:43 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 14:02:28 +00:00
|
|
|
inline Module::const_iterator Module::cbegin() const {
|
|
|
|
return const_iterator(&functions_, functions_.cbegin());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Module::const_iterator Module::cend() const {
|
|
|
|
return const_iterator(&functions_, functions_.cend());
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:32:29 +00:00
|
|
|
} // namespace opt
|
2016-05-22 18:11:24 +00:00
|
|
|
} // namespace spvtools
|
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#endif // SOURCE_OPT_MODULE_H_
|