15 #ifndef NVPTXASMPRINTER_H
16 #define NVPTXASMPRINTER_H
57 std::string theFileName;
62 fstr.open(filename.c_str());
91 unsigned char *buffer;
104 buffer =
new unsigned char[_size];
109 ~AggBuffer() {
delete[] buffer; }
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) {
123 unsigned addZeros(
int Num) {
124 assert((curpos + Num) <= size);
125 for (
int i = 0; i < Num; ++i) {
131 void addSymbol(
const Value *GVar) {
132 symbolPosInBuffer.push_back(curpos);
133 Symbols.push_back(GVar);
137 if (numSymbols == 0) {
139 for (
unsigned i = 0; i < size; i++) {
142 O << (
unsigned int) buffer[i];
146 unsigned int pos = 0;
147 unsigned int nSym = 0;
148 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
149 unsigned int nBytes = 4;
150 if (AP.nvptxSubtarget.is64Bit())
152 for (pos = 0; pos < size; pos += nBytes) {
155 if (pos == nextSymbolPos) {
156 const Value *v = Symbols[nSym];
157 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
160 }
else if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(v)) {
165 if (nSym >= numSymbols)
166 nextSymbolPos = size + 1;
168 nextSymbolPos = symbolPosInBuffer[nSym];
169 }
else if (nBytes == 4)
170 O << *(
unsigned int *)(buffer + pos);
172 O << *(
unsigned long long *)(buffer + pos);
178 friend class AggBuffer;
183 virtual const char *getPassName()
const {
return "NVPTX Assembly Printer"; }
186 std::string CurrentFnName;
188 void EmitFunctionEntryLabel();
189 void EmitFunctionBodyStart();
190 void EmitFunctionBodyEnd();
197 unsigned encodeVirtualRegister(
unsigned Reg);
199 void EmitAlignment(
unsigned NumBits,
const GlobalValue *GV = 0)
const {}
201 void printGlobalVariable(
const GlobalVariable *GVar);
202 void printVecModifiedImmediate(
const MachineOperand &MO,
const char *Modifier,
204 void printMemOperand(
const MachineInstr *
MI,
int opNum, raw_ostream &O,
205 const char *Modifier = 0);
206 void printImplicitDef(
const MachineInstr *
MI, raw_ostream &O)
const;
208 void printInstruction(
const MachineInstr *
MI, raw_ostream &O);
209 void printModuleLevelGV(
const GlobalVariable *GVar, raw_ostream &O,
211 void printParamName(
int paramIndex, raw_ostream &O);
214 void emitGlobals(
const Module &M);
215 void emitHeader(Module &M, raw_ostream &O);
216 void emitKernelFunctionDirectives(
const Function &
F, raw_ostream &O)
const;
217 void emitVirtualRegister(
unsigned int vr, raw_ostream &);
218 void emitFunctionExternParamList(
const MachineFunction &MF);
219 void emitFunctionParamList(
const Function *, raw_ostream &O);
220 void emitFunctionParamList(
const MachineFunction &MF, raw_ostream &O);
221 void setAndEmitFunctionVirtualRegisters(
const MachineFunction &MF);
222 void emitFunctionTempData(
const MachineFunction &MF,
unsigned &FrameSize);
223 bool isImageType(
const Type *Ty);
224 void printReturnValStr(
const Function *, raw_ostream &O);
225 void printReturnValStr(
const MachineFunction &MF, raw_ostream &O);
226 bool PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
227 unsigned AsmVariant,
const char *ExtraCode,
229 void printOperand(
const MachineInstr *
MI,
int opNum, raw_ostream &O,
230 const char *Modifier = 0);
231 bool PrintAsmMemoryOperand(
const MachineInstr *
MI,
unsigned OpNo,
232 unsigned AsmVariant,
const char *ExtraCode,
235 bool doInitialization(Module &M);
236 bool doFinalization(Module &M);
239 std::string CurrentBankselLabelInBasicBlock;
244 const MachineRegisterInfo *
MRI;
248 typedef DenseMap<unsigned, unsigned> VRegMap;
249 typedef DenseMap<const TargetRegisterClass *, VRegMap> VRegRCMap;
250 VRegRCMap VRegMapping;
252 const NVPTXSubtarget &nvptxSubtarget;
255 std::map<const Type *, std::string> TypeNameMap;
258 std::map<const Function *, std::vector<const GlobalVariable *> > localDecls;
261 std::map<std::string, unsigned> filenameMap;
262 void recordAndEmitFilenames(Module &);
264 void emitPTXGlobalVariable(
const GlobalVariable *GVar, raw_ostream &O);
265 void emitPTXAddressSpace(
unsigned int AddressSpace, raw_ostream &O)
const;
266 std::string getPTXFundamentalTypeStr(
const Type *Ty,
bool =
true)
const;
267 void printScalarConstant(
const Constant *CPV, raw_ostream &O);
268 void printFPConstant(
const ConstantFP *Fp, raw_ostream &O);
269 void bufferLEByte(
const Constant *CPV,
int Bytes, AggBuffer *aggBuffer);
270 void bufferAggregateConstant(
const Constant *CV, AggBuffer *aggBuffer);
272 void printOperandProper(
const MachineOperand &MO);
274 void emitLinkageDirective(
const GlobalValue *V, raw_ostream &O);
275 void emitDeclarations(
const Module &, raw_ostream &O);
276 void emitDeclaration(
const Function *, raw_ostream &O);
278 static const char *getRegisterName(
unsigned RegNo);
279 void emitDemotedVars(
const Function *, raw_ostream &);
282 LineReader *getReader(std::string);
287 CurrentBankselLabelInBasicBlock =
"";
298 std::string getVirtualRegisterName(
unsigned)
const;
COFF::RelocationTypeX86 Type
static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, HexagonAsmPrinter &Printer)
std::string readLine(unsigned line)
#define llvm_unreachable(msg)
NVPTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
const llvm::MCExpr * LowerConstant(const llvm::Constant *CV, llvm::AsmPrinter &AP)
LineReader(std::string filename)
LLVM Constant Representation.
#define LLVM_LIBRARY_VISIBILITY
LLVM Value Representation.
const MCRegisterInfo & MRI
const StringRef filename(StringRef path)
Get filename.
ArgumentListType::const_iterator const_arg_iterator