aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target/PTX/PTXAsmPrinter.cpp
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@gmail.com>2010-11-30 07:34:44 +0000
committerChe-Liang Chiou <clchiou@gmail.com>2010-11-30 07:34:44 +0000
commit3f8e61789100ee411d0bfe00fb90df60eaed65f5 (patch)
tree33671cfae297cc53b60c110f8fbbb500a565ff66 /lib/Target/PTX/PTXAsmPrinter.cpp
parentcf82dc376a11acb1b5d46d56c032bb0b9326c682 (diff)
downloadexternal_llvm-3f8e61789100ee411d0bfe00fb90df60eaed65f5.zip
external_llvm-3f8e61789100ee411d0bfe00fb90df60eaed65f5.tar.gz
external_llvm-3f8e61789100ee411d0bfe00fb90df60eaed65f5.tar.bz2
ptx: add ld instruction
support register and register-immediate addressing mode todo: immediate and register-register addressing mode git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120407 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/PTX/PTXAsmPrinter.cpp')
-rw-r--r--lib/Target/PTX/PTXAsmPrinter.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/Target/PTX/PTXAsmPrinter.cpp b/lib/Target/PTX/PTXAsmPrinter.cpp
index 175b3c4..03f177b 100644
--- a/lib/Target/PTX/PTXAsmPrinter.cpp
+++ b/lib/Target/PTX/PTXAsmPrinter.cpp
@@ -49,6 +49,8 @@ public:
virtual void EmitInstruction(const MachineInstr *MI);
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
+ void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
+ const char *Modifier = 0);
// autogen'd.
void printInstruction(const MachineInstr *MI, raw_ostream &OS);
@@ -61,7 +63,7 @@ private:
static const char PARAM_PREFIX[] = "__param_";
-static const char *getRegisterTypeName(unsigned RegNo){
+static const char *getRegisterTypeName(unsigned RegNo) {
#define TEST_REGCLS(cls, clsstr) \
if (PTX::cls ## RegisterClass->contains(RegNo)) return # clsstr;
TEST_REGCLS(RRegs32, s32);
@@ -72,8 +74,7 @@ static const char *getRegisterTypeName(unsigned RegNo){
return NULL;
}
-static const char *getInstructionTypeName(const MachineInstr *MI)
-{
+static const char *getInstructionTypeName(const MachineInstr *MI) {
for (int i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
if (MO.getType() == MachineOperand::MO_Register)
@@ -119,13 +120,13 @@ void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
// Replace "%type" if found
StringRef strref = OS.str();
size_t pos;
- if ((pos = strref.find("%type")) == StringRef::npos) {
- OutStreamer.EmitRawText(strref);
- return;
+ if ((pos = strref.find("%type")) != StringRef::npos) {
+ std::string str = strref;
+ str.replace(pos, /*strlen("%type")==*/5, getInstructionTypeName(MI));
+ strref = StringRef(str);
}
- std::string str = strref;
- str.replace(pos, /*strlen("%type")==*/5, getInstructionTypeName(MI));
- OutStreamer.EmitRawText(StringRef(str));
+
+ OutStreamer.EmitRawText(strref);
}
void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
@@ -145,6 +146,17 @@ void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
}
}
+void PTXAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
+ raw_ostream &OS, const char *Modifier) {
+ printOperand(MI, opNum, OS);
+
+ if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0)
+ return; // don't print "+0"
+
+ OS << "+";
+ printOperand(MI, opNum+1, OS);
+}
+
void PTXAsmPrinter::EmitFunctionDeclaration() {
// The function label could have already been emitted if two symbols end up
// conflicting due to asm renaming. Detect this and emit an error.