blob: e5b1187fad3532a4eb14564dff7e7388f795d303 [file] [log] [blame]
Justin Holewinskid8e4ed22011-09-28 14:32:04 +00001//===-- PTXAsmPrinter.h - Print machine code to a PTX file ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// PTX Assembly printer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef PTXASMPRINTER_H
15#define PTXASMPRINTER_H
16
17#include "PTX.h"
18#include "PTXTargetMachine.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/CodeGen/AsmPrinter.h"
21#include "llvm/Support/Compiler.h"
22
23namespace llvm {
24
25class MCOperand;
26
27class LLVM_LIBRARY_VISIBILITY PTXAsmPrinter : public AsmPrinter {
28public:
29 explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
30 : AsmPrinter(TM, Streamer) {}
31
32 const char *getPassName() const { return "PTX Assembly Printer"; }
33
34 bool doFinalization(Module &M);
35
36 virtual void EmitStartOfAsmFile(Module &M);
Justin Holewinskid8e4ed22011-09-28 14:32:04 +000037 virtual void EmitFunctionBodyStart();
38 virtual void EmitFunctionBodyEnd();
Justin Holewinskied0e4c82011-09-28 14:32:06 +000039 virtual void EmitFunctionEntryLabel();
Justin Holewinskid8e4ed22011-09-28 14:32:04 +000040 virtual void EmitInstruction(const MachineInstr *MI);
41
42 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
43 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
44 const char *Modifier = 0);
45 void printReturnOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
46 const char *Modifier = 0);
47 void printPredicateOperand(const MachineInstr *MI, raw_ostream &O);
48
49 void printCall(const MachineInstr *MI, raw_ostream &O);
50
51 unsigned GetOrCreateSourceID(StringRef FileName,
52 StringRef DirName);
53
54 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);
55 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
56
57 // autogen'd.
58 void printInstruction(const MachineInstr *MI, raw_ostream &OS);
59 static const char *getRegisterName(unsigned RegNo);
60
61private:
62 void EmitVariableDeclaration(const GlobalVariable *gv);
63 void EmitFunctionDeclaration();
64
65 StringMap<unsigned> SourceIdMap;
66}; // class PTXAsmPrinter
67} // namespace llvm
68
69#endif
70