15 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H
16 #define LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H
68 std::string theFileName;
74 fstr.open(filename.c_str());
108 std::vector<unsigned char> buffer;
126 : size(size), buffer(size), O(O), AP(AP) {
129 EmitGeneric = AP.EmitGeneric;
132 unsigned addBytes(
unsigned char *
Ptr,
int Num,
int Bytes) {
133 assert((curpos + Num) <= size);
134 assert((curpos + Bytes) <= size);
135 for (
int i = 0;
i < Num; ++
i) {
136 buffer[curpos] = Ptr[
i];
139 for (
int i = Num;
i < Bytes; ++
i) {
146 unsigned addZeros(
int Num) {
147 assert((curpos + Num) <= size);
148 for (
int i = 0;
i < Num; ++
i) {
155 void addSymbol(
const Value *GVar,
const Value *GVarBeforeStripping) {
156 symbolPosInBuffer.push_back(curpos);
157 Symbols.push_back(GVar);
158 SymbolsBeforeStripping.push_back(GVarBeforeStripping);
163 if (numSymbols == 0) {
165 for (
unsigned i = 0;
i < size;
i++) {
168 O << (
unsigned int) buffer[
i];
172 unsigned int pos = 0;
173 unsigned int nSym = 0;
174 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
175 unsigned int nBytes = 4;
176 if (static_cast<const NVPTXTargetMachine &>(AP.
TM).is64Bit())
178 for (pos = 0; pos < size; pos += nBytes) {
181 if (pos == nextSymbolPos) {
182 const Value *v = Symbols[nSym];
183 const Value *v0 = SymbolsBeforeStripping[nSym];
184 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
187 bool IsNonGenericPointer =
false;
189 IsNonGenericPointer =
true;
191 if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
198 }
else if (
const ConstantExpr *CExpr = dyn_cast<ConstantExpr>(v0)) {
200 AP.lowerConstantForGV(cast<Constant>(CExpr),
false);
201 AP.printMCExpr(*Expr, O);
205 if (nSym >= numSymbols)
206 nextSymbolPos = size + 1;
208 nextSymbolPos = symbolPosInBuffer[nSym];
209 }
else if (nBytes == 4)
210 O << *(
unsigned int *)(&buffer[pos]);
212 O << *(
unsigned long long *)(&buffer[pos]);
218 friend class AggBuffer;
223 StringRef getPassName()
const override {
return "NVPTX Assembly Printer"; }
226 std::string CurrentFnName;
229 void EmitFunctionEntryLabel()
override;
230 void EmitFunctionBodyStart()
override;
231 void EmitFunctionBodyEnd()
override;
238 unsigned encodeVirtualRegister(
unsigned Reg);
240 void printVecModifiedImmediate(
const MachineOperand &MO,
const char *Modifier,
243 const char *Modifier =
nullptr);
248 void emitGlobals(
const Module &M);
251 void emitVirtualRegister(
unsigned int vr,
raw_ostream &);
258 unsigned AsmVariant,
const char *ExtraCode,
261 const char *Modifier =
nullptr);
263 unsigned AsmVariant,
const char *ExtraCode,
266 const MCExpr *lowerConstantForGV(
const Constant *CV,
bool ProcessingGeneric);
270 bool doInitialization(
Module &M)
override;
271 bool doFinalization(
Module &M)
override;
274 std::string CurrentBankselLabelInBasicBlock;
285 VRegRCMap VRegMapping;
292 std::map<Type *, std::string> TypeNameMap;
295 std::map<const Function *, std::vector<const GlobalVariable *>> localDecls;
298 std::map<std::string, unsigned> filenameMap;
299 void recordAndEmitFilenames(
Module &);
303 std::string getPTXFundamentalTypeStr(
Type *Ty,
bool =
true)
const;
306 void bufferLEByte(
const Constant *CPV,
int Bytes, AggBuffer *aggBuffer);
307 void bufferAggregateConstant(
const Constant *CV, AggBuffer *aggBuffer);
314 bool lowerImageHandleOperand(
const MachineInstr *
MI,
unsigned OpNo,
316 void lowerImageHandleSymbol(
unsigned Index,
MCOperand &MCOp);
359 std::string getVirtualRegisterName(
unsigned)
const;
367 #endif // LLVM_LIB_TARGET_NVPTX_NVPTXASMPRINTER_H
~NVPTXAsmPrinter() override
MCSymbol * getSymbol(const GlobalValue *GV) const
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
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. ...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
std::string readLine(unsigned line)
AnalysisUsage & addRequired()
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Base class for the full range of assembler expressions which are needed for parsing.
Reg
All possible values of the reg field in the ModR/M byte.
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
A constant value that is initialized with an expression using other constant values.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Instances of this class represent a single low-level machine instruction.
Class to represent pointers.
LineReader(std::string filename)
void getAnalysisUsage(AnalysisUsage &AU) const override
Record analysis usage.
StringRef filename(StringRef path)
Get filename.
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.
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
NVPTXAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Iterator for intrusive lists based on ilist_node.
MachineOperand class - Representation of each machine instruction operand.
Type * getType() const
All values are typed, get the type of this value.
bool runOnMachineFunction(MachineFunction &F) override
Emit the specified function out to the OutStreamer.
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.