15 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H 16 #define LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H 86 std::vector<unsigned char> buffer;
104 :
size(size), buffer(size),
O(O), AP(AP) {
107 EmitGeneric = AP.EmitGeneric;
110 unsigned addBytes(
unsigned char *Ptr,
int Num,
int Bytes) {
111 assert((curpos + Num) <= size);
112 assert((curpos + Bytes) <= size);
113 for (
int i = 0; i < Num; ++i) {
114 buffer[curpos] = Ptr[i];
117 for (
int i = Num; i < Bytes; ++i) {
124 unsigned addZeros(
int Num) {
125 assert((curpos + Num) <= size);
126 for (
int i = 0; i < Num; ++i) {
133 void addSymbol(
const Value *GVar,
const Value *GVarBeforeStripping) {
136 SymbolsBeforeStripping.
push_back(GVarBeforeStripping);
141 if (numSymbols == 0) {
143 for (
unsigned i = 0; i <
size; i++) {
146 O << (
unsigned int) buffer[i];
150 unsigned int pos = 0;
151 unsigned int nSym = 0;
152 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
153 unsigned int nBytes = 4;
154 if (static_cast<const NVPTXTargetMachine &>(AP.
TM).is64Bit())
156 for (pos = 0; pos <
size; pos += nBytes) {
159 if (pos == nextSymbolPos) {
160 const Value *v = Symbols[nSym];
161 const Value *v0 = SymbolsBeforeStripping[nSym];
162 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
165 bool IsNonGenericPointer =
false;
167 IsNonGenericPointer =
true;
169 if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
176 }
else if (
const ConstantExpr *CExpr = dyn_cast<ConstantExpr>(v0)) {
178 AP.lowerConstantForGV(cast<Constant>(CExpr),
false);
179 AP.printMCExpr(*Expr, O);
183 if (nSym >= numSymbols)
184 nextSymbolPos = size + 1;
186 nextSymbolPos = symbolPosInBuffer[nSym];
187 }
else if (nBytes == 4)
188 O << *(
unsigned int *)(&buffer[pos]);
190 O << *(
unsigned long long *)(&buffer[pos]);
196 friend class AggBuffer;
199 StringRef getPassName()
const override {
return "NVPTX Assembly Printer"; }
202 std::string CurrentFnName;
205 void EmitFunctionEntryLabel()
override;
206 void EmitFunctionBodyStart()
override;
207 void EmitFunctionBodyEnd()
override;
214 unsigned encodeVirtualRegister(
unsigned Reg);
216 void printVecModifiedImmediate(
const MachineOperand &MO,
const char *Modifier,
219 const char *Modifier =
nullptr);
224 void emitGlobals(
const Module &M);
227 void emitVirtualRegister(
unsigned int vr,
raw_ostream &);
234 unsigned AsmVariant,
const char *ExtraCode,
237 const char *Modifier =
nullptr);
239 unsigned AsmVariant,
const char *ExtraCode,
242 const MCExpr *lowerConstantForGV(
const Constant *CV,
bool ProcessingGeneric);
246 bool doInitialization(
Module &M)
override;
247 bool doFinalization(
Module &M)
override;
259 VRegRCMap VRegMapping;
262 std::map<const Function *, std::vector<const GlobalVariable *>> localDecls;
266 std::string getPTXFundamentalTypeStr(
Type *Ty,
bool =
true)
const;
269 void bufferLEByte(
const Constant *CPV,
int Bytes, AggBuffer *aggBuffer);
270 void bufferAggregateConstant(
const Constant *CV, AggBuffer *aggBuffer);
277 bool lowerImageHandleOperand(
const MachineInstr *
MI,
unsigned OpNo,
309 std::string getVirtualRegisterName(
unsigned)
const;
311 const MCSymbol *getFunctionFrameSymbol()
const override;
316 #endif // LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H This class represents an incoming formal argument to a Function.
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
AnalysisUsage & addRequired()
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Base class for the full range of assembler expressions which are needed for parsing.
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
Instances of this class represent a single low-level machine instruction.
Class to represent pointers.
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
unsigned const MachineRegisterInfo * MRI
const MCAsmInfo * MAI
Target Asm Printer information.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, HexagonAsmPrinter &Printer, bool MustExtend)
ConstantFP - Floating Point Values [float, double].
TargetMachine & TM
Target machine description.
This class is intended to be used as a driving class for all asm writers.
Represent the analysis usage information of a pass.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
NVPTXAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, const MachineFunction *MF, const Module *M, const MachineFrameInfo *MFI, const TargetInstrInfo *TII, LLVMContext &Ctx)
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static void printMCExpr(const MCExpr *E, raw_ostream &OS)
MCSymbol * getSymbol(const GlobalValue *GV) const
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
Instances of this class represent operands of the MCInst class.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.