14 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H 15 #define LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H 85 std::vector<unsigned char> buffer;
103 :
size(size), buffer(size),
O(O), AP(AP) {
106 EmitGeneric = AP.EmitGeneric;
109 unsigned addBytes(
unsigned char *Ptr,
int Num,
int Bytes) {
110 assert((curpos + Num) <= size);
111 assert((curpos + Bytes) <= size);
112 for (
int i = 0; i < Num; ++i) {
113 buffer[curpos] = Ptr[i];
116 for (
int i = Num; i < Bytes; ++i) {
123 unsigned addZeros(
int Num) {
124 assert((curpos + Num) <= size);
125 for (
int i = 0; i < Num; ++i) {
132 void addSymbol(
const Value *GVar,
const Value *GVarBeforeStripping) {
135 SymbolsBeforeStripping.
push_back(GVarBeforeStripping);
140 if (numSymbols == 0) {
142 for (
unsigned i = 0; i <
size; i++) {
145 O << (
unsigned int) buffer[i];
149 unsigned int pos = 0;
150 unsigned int nSym = 0;
151 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
152 unsigned int nBytes = 4;
153 if (static_cast<const NVPTXTargetMachine &>(AP.
TM).is64Bit())
155 for (pos = 0; pos <
size; pos += nBytes) {
158 if (pos == nextSymbolPos) {
159 const Value *v = Symbols[nSym];
160 const Value *v0 = SymbolsBeforeStripping[nSym];
161 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
164 bool IsNonGenericPointer =
false;
166 IsNonGenericPointer =
true;
168 if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
175 }
else if (
const ConstantExpr *CExpr = dyn_cast<ConstantExpr>(v0)) {
177 AP.lowerConstantForGV(cast<Constant>(CExpr),
false);
178 AP.printMCExpr(*Expr, O);
182 if (nSym >= numSymbols)
183 nextSymbolPos = size + 1;
185 nextSymbolPos = symbolPosInBuffer[nSym];
186 }
else if (nBytes == 4)
187 O << *(
unsigned int *)(&buffer[pos]);
189 O << *(
unsigned long long *)(&buffer[pos]);
195 friend class AggBuffer;
198 StringRef getPassName()
const override {
return "NVPTX Assembly Printer"; }
201 std::string CurrentFnName;
204 void EmitFunctionEntryLabel()
override;
205 void EmitFunctionBodyStart()
override;
206 void EmitFunctionBodyEnd()
override;
213 unsigned encodeVirtualRegister(
unsigned Reg);
216 const char *Modifier =
nullptr);
221 void emitGlobals(
const Module &M);
224 void emitVirtualRegister(
unsigned int vr,
raw_ostream &);
236 const MCExpr *lowerConstantForGV(
const Constant *CV,
bool ProcessingGeneric);
240 bool doInitialization(
Module &M)
override;
241 bool doFinalization(
Module &M)
override;
253 VRegRCMap VRegMapping;
256 std::map<const Function *, std::vector<const GlobalVariable *>> localDecls;
260 std::string getPTXFundamentalTypeStr(
Type *Ty,
bool =
true)
const;
263 void bufferLEByte(
const Constant *CPV,
int Bytes, AggBuffer *aggBuffer);
264 void bufferAggregateConstant(
const Constant *CV, AggBuffer *aggBuffer);
271 bool lowerImageHandleOperand(
const MachineInstr *
MI,
unsigned OpNo,
303 std::string getVirtualRegisterName(
unsigned)
const;
305 const MCSymbol *getFunctionFrameSymbol()
const override;
310 #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. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void push_back(const T &Elt)
AnalysisUsage & addRequired()
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.
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
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)
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.