LLVM 23.0.0git
SPIRVAuxDataHandler.h
Go to the documentation of this file.
1//===-- SPIRVAuxDataHandler.h - NonSemantic.AuxData emitter -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Emits NonSemantic.AuxData ExtInst annotations (mirrors SPIRV-LLVM-Translator
10// --spirv-preserve-auxdata).
11// Otherwise, AE-tagged functions emit plain Export linkage via
12// LinkageAttributes.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVAUXDATAHANDLER_H
17#define LLVM_LIB_TARGET_SPIRV_SPIRVAUXDATAHANDLER_H
18
19#include "SPIRVModuleAnalysis.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/MC/MCRegister.h"
27
28namespace llvm {
29
30class AsmPrinter;
31class Constant;
32class Function;
33class GlobalObject;
34class Module;
35class SPIRVSubtarget;
36
37// Khronos NonSemantic.AuxData opcodes (int64_t to drop casts at MCOperand
38// boundaries).
46
48public:
50
51 bool hasWork() const;
52
53 /// Register extension + ext-inst-set; call before output of section 1.
56
57 /// Emit OpStrings and stage ExtInst records; call in module section 7.
59
60 /// Emit the staged ExtInst records; call in module section 10.
62
63private:
64 // An ExtInst operand is either an already-emitted OpString (Reg valid) or a
65 // ValueAsMetadata constant whose OpConstant is emitted lazily at section 10
66 // (Const set). Exactly one is populated.
67 struct Operand {
69 const Constant *Const = nullptr;
70 };
71 // The Target operand (the OpFunction / OpVariable <id>) is resolved from
72 // GlobalObjMap at emit time, so records keep the GlobalObject, not a reg.
73 struct ExtInstRecord {
74 AuxDataOpcode Opcode;
75 const GlobalObject *Target;
77 };
78
79 AsmPrinter &Asm;
80 const Module &Mod;
81
82 SmallVector<const GlobalObject *> LinkagePreservedGOs;
83
84 // Backing storage for non-string-attribute strings; StringRegs keys are
85 // StringRefs into it.
86 BumpPtrAllocator StringAlloc;
87 UniqueStringSaver StringPool{StringAlloc};
88
91 SmallVector<ExtInstRecord> PendingRecords;
92
93 MCRegister getOrEmitString(StringRef S, SPIRV::ModuleAnalysisInfo &MAI);
94 void collectAttributesFor(const GlobalObject *GO,
96 void collectMetadataFor(const GlobalObject *GO, ArrayRef<StringRef> MDNames,
98
99 void emitMCInst(MCInst &Inst);
100 MCRegister findOrEmitOpTypeVoid(SPIRV::ModuleAnalysisInfo &MAI);
101 MCRegister findOrEmitOpTypeInt(unsigned BitWidth,
103 MCRegister findOrEmitOpTypeUInt32(SPIRV::ModuleAnalysisInfo &MAI);
104 MCRegister findOrEmitOpTypeFloat(unsigned BitWidth,
106 MCRegister emitOpConstantUInt32(uint32_t Value, MCRegister UInt32TypeReg,
108 MCRegister emitConstant(const Constant *C, SPIRV::ModuleAnalysisInfo &MAI);
109 void emitAuxDataExtInst(AuxDataOpcode Opcode, MCRegister VoidTypeReg,
110 MCRegister ExtSetReg, ArrayRef<MCRegister> Operands,
112};
113
114} // namespace llvm
115
116#endif // LLVM_LIB_TARGET_SPIRV_SPIRVAUXDATAHANDLER_H
This file defines the BumpPtrAllocator interface.
This file defines the DenseMap class.
Register Reg
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:91
This is an important base class in LLVM.
Definition Constant.h:43
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
SPIRVAuxDataHandler(AsmPrinter &AP, const Module &M)
void emitAuxDataStrings(SPIRV::ModuleAnalysisInfo &MAI)
Emit OpStrings and stage ExtInst records; call in module section 7.
void emitAuxData(SPIRV::ModuleAnalysisInfo &MAI)
Emit the staged ExtInst records; call in module section 10.
void prepareModuleOutput(const SPIRVSubtarget &ST, SPIRV::ModuleAnalysisInfo &MAI)
Register extension + ext-inst-set; call before output of section 1.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Target - Wrapper for Target specific information.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition StringSaver.h:45
LLVM Value Representation.
Definition Value.h:75
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
@ GlobalVariableMetadataOpcode
@ FunctionAttributeOpcode
@ GlobalVariableAttributeOpcode
@ FunctionMetadataOpcode
constexpr unsigned BitWidth
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383