|
| 1 | +//===-- SPIRVGlobalInstrRegistry.h - SPIR-V Global Instr Registry -*- C++ |
| 2 | +//-*-===// |
| 3 | +// |
| 4 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===------------------------------------------------------------------------===// |
| 9 | +// |
| 10 | +// The SPIRVGlobalInstrRegistry class is used to collect and contain information |
| 11 | +// required for emitting SPIR-V global instructions (instructions which do not |
| 12 | +// belong to any function and are emittied on a module level). |
| 13 | +// |
| 14 | +//===------------------------------------------------------------------------===// |
| 15 | + |
| 16 | +#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVGLOBALINSTRREGISTRY_H |
| 17 | +#define LLVM_LIB_TARGET_SPIRV_SPIRVGLOBALINSTRREGISTRY_H |
| 18 | + |
| 19 | +#include "MCTargetDesc/SPIRVBaseInfo.h" |
| 20 | + |
| 21 | +#include "llvm/ADT/SmallVector.h" |
| 22 | +#include "llvm/IR/Function.h" |
| 23 | + |
| 24 | +namespace llvm { |
| 25 | + |
| 26 | +/// Struct storing info on module's entry point for later printing of global |
| 27 | +/// OpEntryPoint instruction. |
| 28 | +struct SPIRVEntryPoint { |
| 29 | + const SPIRV::ExecutionModel::ExecutionModel ExecModel; |
| 30 | + const Function *const EntryFunction; |
| 31 | + |
| 32 | + SPIRVEntryPoint(const SPIRV::ExecutionModel::ExecutionModel ExecModel, |
| 33 | + const Function *const EntryFunction) |
| 34 | + : ExecModel(ExecModel), EntryFunction(EntryFunction) {} |
| 35 | + SPIRVEntryPoint &operator=(const SPIRVEntryPoint &) = delete; |
| 36 | +}; |
| 37 | + |
| 38 | +/// SPIRVGlobalInstrRegistry collects and stores information required for |
| 39 | +/// emitting SPIR-V global instructions. |
| 40 | +class SPIRVGlobalInstrRegistry { |
| 41 | +private: |
| 42 | + SmallVector<SPIRVEntryPoint> EntryPoints; |
| 43 | + |
| 44 | +public: |
| 45 | + SPIRVGlobalInstrRegistry() {} |
| 46 | + |
| 47 | + /// Declare a new SPIR-V entry point. |
| 48 | + void addEntryPoint(const SPIRV::ExecutionModel::ExecutionModel ExecModel, |
| 49 | + const Function *const EntryFunction) { |
| 50 | + EntryPoints.push_back(SPIRVEntryPoint(ExecModel, EntryFunction)); |
| 51 | + } |
| 52 | + |
| 53 | + /// Get all already declared SPIR-V entry points. |
| 54 | + const SmallVector<SPIRVEntryPoint> &getAllEntryPoints() const { |
| 55 | + return EntryPoints; |
| 56 | + } |
| 57 | +}; |
| 58 | + |
| 59 | +} // end namespace llvm |
| 60 | +#endif // LLVM_LIB_TARGET_SPIRV_SPIRVGLOBALINSTRREGISTRY_H |
0 commit comments