Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1 | //===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --------=// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to PowerPC assembly language. This printer is |
Chris Lattner | 83660c5 | 2004-07-28 20:18:53 +0000 | [diff] [blame] | 12 | // the output mechanism used by `llc'. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 13 | // |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 14 | // Documentation at http://developer.apple.com/documentation/DeveloperTools/ |
| 15 | // Reference/Assembler/ASMIntroduction/chapter_1_section_1.html |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 16 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 19 | #define DEBUG_TYPE "asmprinter" |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 20 | #include "PPC.h" |
Chris Lattner | 16e71f2 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 21 | #include "PPCTargetMachine.h" |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 22 | #include "PPCSubtarget.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 23 | #include "llvm/Constants.h" |
| 24 | #include "llvm/DerivedTypes.h" |
| 25 | #include "llvm/Module.h" |
| 26 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/AsmPrinter.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/DwarfWriter.h" |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineDebugInfo.h" |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineInstr.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Mangler.h" |
Nate Begeman | a11c2e8 | 2004-09-04 14:51:26 +0000 | [diff] [blame] | 33 | #include "llvm/Support/MathExtras.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 34 | #include "llvm/Support/CommandLine.h" |
| 35 | #include "llvm/Support/Debug.h" |
Nate Begeman | 17304c3 | 2004-10-26 06:02:38 +0000 | [diff] [blame] | 36 | #include "llvm/Target/MRegisterInfo.h" |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 37 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | d2ee218 | 2006-02-18 00:08:58 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetOptions.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/Statistic.h" |
| 40 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 2c2c6c6 | 2006-01-22 23:41:00 +0000 | [diff] [blame] | 41 | #include <iostream> |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 42 | #include <set> |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 43 | using namespace llvm; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 44 | |
| 45 | namespace { |
| 46 | Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); |
| 47 | |
Chris Lattner | ac7fd7f | 2005-11-14 18:52:46 +0000 | [diff] [blame] | 48 | class PPCAsmPrinter : public AsmPrinter { |
Chris Lattner | d717b19 | 2005-12-11 07:45:47 +0000 | [diff] [blame] | 49 | public: |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 50 | std::set<std::string> FnStubs, GVStubs; |
Chris Lattner | ac7fd7f | 2005-11-14 18:52:46 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 52 | PPCAsmPrinter(std::ostream &O, TargetMachine &TM) |
Chris Lattner | 0745536 | 2005-11-21 08:14:07 +0000 | [diff] [blame] | 53 | : AsmPrinter(O, TM) {} |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 54 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 55 | virtual const char *getPassName() const { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 56 | return "PowerPC Assembly Printer"; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 59 | PPCTargetMachine &getTM() { |
| 60 | return static_cast<PPCTargetMachine&>(TM); |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Nate Begeman | adeb43d | 2005-07-20 22:42:00 +0000 | [diff] [blame] | 63 | unsigned enumRegToMachineReg(unsigned enumReg) { |
| 64 | switch (enumReg) { |
| 65 | default: assert(0 && "Unhandled register!"); break; |
| 66 | case PPC::CR0: return 0; |
| 67 | case PPC::CR1: return 1; |
| 68 | case PPC::CR2: return 2; |
| 69 | case PPC::CR3: return 3; |
| 70 | case PPC::CR4: return 4; |
| 71 | case PPC::CR5: return 5; |
| 72 | case PPC::CR6: return 6; |
| 73 | case PPC::CR7: return 7; |
| 74 | } |
| 75 | abort(); |
| 76 | } |
| 77 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 78 | /// printInstruction - This method is automatically generated by tablegen |
| 79 | /// from the instruction set description. This method returns true if the |
| 80 | /// machine instruction was sufficiently described to print it, otherwise it |
| 81 | /// returns false. |
| 82 | bool printInstruction(const MachineInstr *MI); |
| 83 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 84 | void printMachineInstruction(const MachineInstr *MI); |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 85 | void printOp(const MachineOperand &MO); |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 5887327 | 2006-02-01 22:38:46 +0000 | [diff] [blame] | 87 | void printOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 88 | const MachineOperand &MO = MI->getOperand(OpNo); |
Chris Lattner | 2d90ac7 | 2006-05-04 18:05:43 +0000 | [diff] [blame] | 89 | if (MO.isRegister()) { |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 90 | assert(MRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physreg??"); |
Chris Lattner | 9dc4d3c | 2005-08-22 22:00:02 +0000 | [diff] [blame] | 91 | O << TM.getRegisterInfo()->get(MO.getReg()).Name; |
Chris Lattner | 0ea3171 | 2004-08-15 05:46:14 +0000 | [diff] [blame] | 92 | } else if (MO.isImmediate()) { |
| 93 | O << MO.getImmedValue(); |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 94 | } else { |
| 95 | printOp(MO); |
| 96 | } |
| 97 | } |
Chris Lattner | 5887327 | 2006-02-01 22:38:46 +0000 | [diff] [blame] | 98 | |
| 99 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 100 | unsigned AsmVariant, const char *ExtraCode); |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 101 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 102 | unsigned AsmVariant, const char *ExtraCode); |
| 103 | |
Chris Lattner | 5887327 | 2006-02-01 22:38:46 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 105 | void printS5ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
| 106 | char value = MI->getOperand(OpNo).getImmedValue(); |
| 107 | value = (value << (32-5)) >> (32-5); |
| 108 | O << (int)value; |
| 109 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 110 | void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | c330612 | 2004-08-21 05:56:39 +0000 | [diff] [blame] | 111 | unsigned char value = MI->getOperand(OpNo).getImmedValue(); |
Chris Lattner | 12585ba | 2004-08-21 19:11:03 +0000 | [diff] [blame] | 112 | assert(value <= 31 && "Invalid u5imm argument!"); |
Nate Begeman | c330612 | 2004-08-21 05:56:39 +0000 | [diff] [blame] | 113 | O << (unsigned int)value; |
| 114 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 115 | void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 07aada8 | 2004-08-30 02:28:06 +0000 | [diff] [blame] | 116 | unsigned char value = MI->getOperand(OpNo).getImmedValue(); |
| 117 | assert(value <= 63 && "Invalid u6imm argument!"); |
| 118 | O << (unsigned int)value; |
| 119 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 120 | void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 121 | O << (short)MI->getOperand(OpNo).getImmedValue(); |
| 122 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 123 | void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 97b2a2e | 2004-08-15 05:20:16 +0000 | [diff] [blame] | 124 | O << (unsigned short)MI->getOperand(OpNo).getImmedValue(); |
| 125 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 126 | void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 841d12d | 2005-10-18 16:51:22 +0000 | [diff] [blame] | 127 | O << (short)MI->getOperand(OpNo).getImmedValue()*4; |
| 128 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 129 | void printBranchOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 130 | // Branches can take an immediate operand. This is used by the branch |
| 131 | // selection pass to print $+8, an eight byte displacement from the PC. |
| 132 | if (MI->getOperand(OpNo).isImmediate()) { |
Nate Begeman | 27499e3 | 2005-04-10 01:48:29 +0000 | [diff] [blame] | 133 | O << "$+" << MI->getOperand(OpNo).getImmedValue(); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 134 | } else { |
Chris Lattner | 3e7f86a | 2005-11-17 19:16:08 +0000 | [diff] [blame] | 135 | printOp(MI->getOperand(OpNo)); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 136 | } |
Nate Begeman | b7a8f2c | 2004-09-02 08:13:00 +0000 | [diff] [blame] | 137 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 138 | void printCallOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 139 | const MachineOperand &MO = MI->getOperand(OpNo); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 140 | if (TM.getRelocationModel() != Reloc::Static) { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 141 | if (MO.getType() == MachineOperand::MO_GlobalAddress) { |
| 142 | GlobalValue *GV = MO.getGlobal(); |
| 143 | if (((GV->isExternal() || GV->hasWeakLinkage() || |
| 144 | GV->hasLinkOnceLinkage()))) { |
| 145 | // Dynamically-resolved functions need a stub for the function. |
| 146 | std::string Name = Mang->getValueName(GV); |
| 147 | FnStubs.insert(Name); |
| 148 | O << "L" << Name << "$stub"; |
| 149 | return; |
| 150 | } |
| 151 | } |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 152 | if (MO.getType() == MachineOperand::MO_ExternalSymbol) { |
| 153 | std::string Name(GlobalPrefix); Name += MO.getSymbolName(); |
| 154 | FnStubs.insert(Name); |
| 155 | O << "L" << Name << "$stub"; |
| 156 | return; |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 157 | } |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 158 | } |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 159 | |
| 160 | printOp(MI->getOperand(OpNo)); |
Chris Lattner | 3e7f86a | 2005-11-17 19:16:08 +0000 | [diff] [blame] | 161 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 162 | void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 422b0ce | 2005-11-16 00:48:01 +0000 | [diff] [blame] | 163 | O << (int)MI->getOperand(OpNo).getImmedValue()*4; |
| 164 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 165 | void printPICLabel(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 166 | O << "\"L" << getFunctionNumber() << "$pb\"\n"; |
| 167 | O << "\"L" << getFunctionNumber() << "$pb\":"; |
Nate Begeman | b7a8f2c | 2004-09-02 08:13:00 +0000 | [diff] [blame] | 168 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 169 | void printSymbolHi(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 170 | if (MI->getOperand(OpNo).isImmediate()) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 171 | printS16ImmOperand(MI, OpNo); |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 172 | } else { |
| 173 | O << "ha16("; |
| 174 | printOp(MI->getOperand(OpNo)); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 175 | if (TM.getRelocationModel() == Reloc::PIC) |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 176 | O << "-\"L" << getFunctionNumber() << "$pb\")"; |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 177 | else |
| 178 | O << ')'; |
| 179 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 180 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 181 | void printSymbolLo(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 182 | if (MI->getOperand(OpNo).isImmediate()) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 183 | printS16ImmOperand(MI, OpNo); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 184 | } else { |
| 185 | O << "lo16("; |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 186 | printOp(MI->getOperand(OpNo)); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 187 | if (TM.getRelocationModel() == Reloc::PIC) |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 188 | O << "-\"L" << getFunctionNumber() << "$pb\")"; |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 189 | else |
| 190 | O << ')'; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 191 | } |
| 192 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 193 | void printcrbitm(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | adeb43d | 2005-07-20 22:42:00 +0000 | [diff] [blame] | 194 | unsigned CCReg = MI->getOperand(OpNo).getReg(); |
| 195 | unsigned RegNo = enumRegToMachineReg(CCReg); |
| 196 | O << (0x80 >> RegNo); |
| 197 | } |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 198 | // The new addressing mode printers. |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 199 | void printMemRegImm(const MachineInstr *MI, unsigned OpNo) { |
| 200 | printSymbolLo(MI, OpNo); |
| 201 | O << '('; |
Chris Lattner | 13feb58 | 2006-03-21 17:21:13 +0000 | [diff] [blame] | 202 | if (MI->getOperand(OpNo+1).isRegister() && |
| 203 | MI->getOperand(OpNo+1).getReg() == PPC::R0) |
| 204 | O << "0"; |
| 205 | else |
| 206 | printOperand(MI, OpNo+1); |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 207 | O << ')'; |
| 208 | } |
Chris Lattner | e5ba580 | 2006-03-22 05:26:03 +0000 | [diff] [blame] | 209 | void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) { |
| 210 | if (MI->getOperand(OpNo).isImmediate()) |
| 211 | printS16X4ImmOperand(MI, OpNo); |
| 212 | else |
| 213 | printSymbolLo(MI, OpNo); |
| 214 | O << '('; |
| 215 | if (MI->getOperand(OpNo+1).isRegister() && |
| 216 | MI->getOperand(OpNo+1).getReg() == PPC::R0) |
| 217 | O << "0"; |
| 218 | else |
| 219 | printOperand(MI, OpNo+1); |
| 220 | O << ')'; |
| 221 | } |
| 222 | |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 223 | void printMemRegReg(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 88276b8 | 2005-12-19 23:40:42 +0000 | [diff] [blame] | 224 | // When used as the base register, r0 reads constant zero rather than |
| 225 | // the value contained in the register. For this reason, the darwin |
| 226 | // assembler requires that we print r0 as 0 (no r) when used as the base. |
| 227 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 228 | if (MO.getReg() == PPC::R0) |
| 229 | O << '0'; |
| 230 | else |
| 231 | O << TM.getRegisterInfo()->get(MO.getReg()).Name; |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 232 | O << ", "; |
| 233 | printOperand(MI, OpNo+1); |
| 234 | } |
| 235 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 236 | virtual bool runOnMachineFunction(MachineFunction &F) = 0; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 237 | virtual bool doFinalization(Module &M) = 0; |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 238 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 239 | }; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 240 | |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 241 | /// DarwinDwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X |
| 242 | /// |
| 243 | struct DarwinDwarfWriter : public DwarfWriter { |
| 244 | // Ctor. |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 245 | DarwinDwarfWriter(std::ostream &o, AsmPrinter *ap) |
| 246 | : DwarfWriter(o, ap) |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 247 | { |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 248 | needsSet = true; |
Jim Laskey | f8a01a9 | 2006-06-15 20:51:43 +0000 | [diff] [blame] | 249 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev"; |
| 250 | DwarfInfoSection = ".section __DWARF,__debug_info"; |
| 251 | DwarfLineSection = ".section __DWARF,__debug_line"; |
| 252 | DwarfFrameSection = ".section __DWARF,__debug_frame"; |
| 253 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames"; |
| 254 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes"; |
| 255 | DwarfStrSection = ".section __DWARF,__debug_str"; |
| 256 | DwarfLocSection = ".section __DWARF,__debug_loc"; |
| 257 | DwarfARangesSection = ".section __DWARF,__debug_aranges"; |
| 258 | DwarfRangesSection = ".section __DWARF,__debug_ranges"; |
| 259 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo"; |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 260 | TextSection = ".text"; |
| 261 | DataSection = ".data"; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 262 | } |
| 263 | }; |
| 264 | |
Misha Brukman | 3e0b51a | 2004-09-05 02:42:44 +0000 | [diff] [blame] | 265 | /// DarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac OS |
| 266 | /// X |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 267 | struct DarwinAsmPrinter : public PPCAsmPrinter { |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 268 | |
| 269 | DarwinDwarfWriter DW; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 270 | |
| 271 | DarwinAsmPrinter(std::ostream &O, TargetMachine &TM) |
Chris Lattner | 418caa1 | 2006-02-08 23:42:22 +0000 | [diff] [blame] | 272 | : PPCAsmPrinter(O, TM), DW(O, this) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 273 | CommentString = ";"; |
| 274 | GlobalPrefix = "_"; |
Chris Lattner | f55366e | 2005-11-21 06:47:58 +0000 | [diff] [blame] | 275 | PrivateGlobalPrefix = "L"; // Marker for constant pool idxs |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 276 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 277 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 278 | AlignmentIsInBytes = false; // Alignment is by power of 2. |
Chris Lattner | c569e61 | 2005-11-21 08:26:15 +0000 | [diff] [blame] | 279 | ConstantPoolSection = "\t.const\t"; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 280 | // FIXME: Conditionalize jump table section based on PIC |
| 281 | JumpTableSection = ".const"; |
Chris Lattner | d717b19 | 2005-12-11 07:45:47 +0000 | [diff] [blame] | 282 | LCOMMDirective = "\t.lcomm\t"; |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 283 | StaticCtorsSection = ".mod_init_func"; |
| 284 | StaticDtorsSection = ".mod_term_func"; |
Chris Lattner | 35c3913 | 2006-05-05 21:50:04 +0000 | [diff] [blame] | 285 | InlineAsmStart = "# InlineAsm Start"; |
| 286 | InlineAsmEnd = "# InlineAsm End"; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | virtual const char *getPassName() const { |
| 290 | return "Darwin PPC Assembly Printer"; |
| 291 | } |
Chris Lattner | 646f7af | 2005-12-09 18:24:29 +0000 | [diff] [blame] | 292 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 293 | bool runOnMachineFunction(MachineFunction &F); |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 294 | bool doInitialization(Module &M); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 295 | bool doFinalization(Module &M); |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 296 | |
| 297 | void getAnalysisUsage(AnalysisUsage &AU) const { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 298 | AU.setPreservesAll(); |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 299 | AU.addRequired<MachineDebugInfo>(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 300 | PPCAsmPrinter::getAnalysisUsage(AU); |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 303 | }; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 304 | |
Misha Brukman | 3e0b51a | 2004-09-05 02:42:44 +0000 | [diff] [blame] | 305 | /// AIXAsmPrinter - PowerPC assembly printer, customized for AIX |
| 306 | /// |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 307 | struct AIXAsmPrinter : public PPCAsmPrinter { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 308 | /// Map for labels corresponding to global variables |
| 309 | /// |
| 310 | std::map<const GlobalVariable*,std::string> GVToLabelMap; |
| 311 | |
| 312 | AIXAsmPrinter(std::ostream &O, TargetMachine &TM) |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 313 | : PPCAsmPrinter(O, TM) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 314 | CommentString = "#"; |
Chris Lattner | 3459bfb | 2005-11-10 18:20:29 +0000 | [diff] [blame] | 315 | GlobalPrefix = "."; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 316 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 317 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 318 | AlignmentIsInBytes = false; // Alignment is by power of 2. |
Chris Lattner | c569e61 | 2005-11-21 08:26:15 +0000 | [diff] [blame] | 319 | ConstantPoolSection = "\t.const\t"; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 320 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 321 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 322 | virtual const char *getPassName() const { |
| 323 | return "AIX PPC Assembly Printer"; |
| 324 | } |
| 325 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 326 | bool runOnMachineFunction(MachineFunction &F); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 327 | bool doInitialization(Module &M); |
| 328 | bool doFinalization(Module &M); |
| 329 | }; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 330 | } // end of anonymous namespace |
| 331 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 332 | /// createDarwinAsmPrinterPass - Returns a pass that prints the PPC assembly |
| 333 | /// code for a MachineFunction to the given output stream, in a format that the |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 334 | /// Darwin assembler can deal with. |
| 335 | /// |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 336 | FunctionPass *llvm::createDarwinAsmPrinter(std::ostream &o, |
| 337 | PPCTargetMachine &tm) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 338 | return new DarwinAsmPrinter(o, tm); |
| 339 | } |
| 340 | |
| 341 | /// createAIXAsmPrinterPass - Returns a pass that prints the PPC assembly code |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 342 | /// for a MachineFunction to the given output stream, in a format that the |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 343 | /// AIX 5L assembler can deal with. |
| 344 | /// |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 345 | FunctionPass *llvm::createAIXAsmPrinter(std::ostream &o, PPCTargetMachine &tm) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 346 | return new AIXAsmPrinter(o, tm); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 349 | // Include the auto-generated portion of the assembly writer |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 350 | #include "PPCGenAsmWriter.inc" |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 351 | |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 352 | void PPCAsmPrinter::printOp(const MachineOperand &MO) { |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 353 | switch (MO.getType()) { |
Chris Lattner | 63b3d71 | 2006-05-04 17:21:20 +0000 | [diff] [blame] | 354 | case MachineOperand::MO_Immediate: |
Misha Brukman | af313fb | 2004-07-28 00:00:48 +0000 | [diff] [blame] | 355 | std::cerr << "printOp() does not handle immediate values\n"; |
| 356 | abort(); |
Misha Brukman | 97a296f | 2004-07-21 20:11:11 +0000 | [diff] [blame] | 357 | return; |
| 358 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 359 | case MachineOperand::MO_MachineBasicBlock: |
| 360 | printBasicBlockLabel(MO.getMachineBasicBlock()); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 361 | return; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 362 | case MachineOperand::MO_JumpTableIndex: |
| 363 | O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() |
| 364 | << '_' << MO.getJumpTableIndex(); |
| 365 | // FIXME: PIC relocation model |
| 366 | return; |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 367 | case MachineOperand::MO_ConstantPoolIndex: |
Chris Lattner | 0745536 | 2005-11-21 08:14:07 +0000 | [diff] [blame] | 368 | O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() |
Chris Lattner | f55366e | 2005-11-21 06:47:58 +0000 | [diff] [blame] | 369 | << '_' << MO.getConstantPoolIndex(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 370 | return; |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 371 | case MachineOperand::MO_ExternalSymbol: |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 372 | // Computing the address of an external symbol, not calling it. |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 373 | if (TM.getRelocationModel() != Reloc::Static) { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 374 | std::string Name(GlobalPrefix); Name += MO.getSymbolName(); |
| 375 | GVStubs.insert(Name); |
| 376 | O << "L" << Name << "$non_lazy_ptr"; |
| 377 | return; |
| 378 | } |
Nate Begeman | 01d0526 | 2005-03-30 01:45:43 +0000 | [diff] [blame] | 379 | O << GlobalPrefix << MO.getSymbolName(); |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 380 | return; |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 381 | case MachineOperand::MO_GlobalAddress: { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 382 | // Computing the address of a global symbol, not calling it. |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 383 | GlobalValue *GV = MO.getGlobal(); |
| 384 | std::string Name = Mang->getValueName(GV); |
Nate Begeman | 50fb3c4 | 2005-12-24 01:00:15 +0000 | [diff] [blame] | 385 | int offset = MO.getOffset(); |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 386 | |
Nate Begeman | fcf4a42 | 2004-10-17 23:01:34 +0000 | [diff] [blame] | 387 | // External or weakly linked global variables need non-lazily-resolved stubs |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 388 | if (TM.getRelocationModel() != Reloc::Static) { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 389 | if (((GV->isExternal() || GV->hasWeakLinkage() || |
| 390 | GV->hasLinkOnceLinkage()))) { |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 391 | GVStubs.insert(Name); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 392 | O << "L" << Name << "$non_lazy_ptr"; |
| 393 | return; |
| 394 | } |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 395 | } |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 396 | |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 397 | O << Name; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 398 | return; |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 399 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 400 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 401 | default: |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 402 | O << "<unknown operand type: " << MO.getType() << ">"; |
Misha Brukman | 22e1207 | 2004-06-25 15:11:34 +0000 | [diff] [blame] | 403 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 407 | /// PrintAsmOperand - Print out an operand for an inline asm expression. |
| 408 | /// |
| 409 | bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 410 | unsigned AsmVariant, |
| 411 | const char *ExtraCode) { |
| 412 | // Does this asm operand have a single letter operand modifier? |
| 413 | if (ExtraCode && ExtraCode[0]) { |
| 414 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
| 415 | |
| 416 | switch (ExtraCode[0]) { |
| 417 | default: return true; // Unknown modifier. |
| 418 | case 'L': // Write second word of DImode reference. |
| 419 | // Verify that this operand has two consecutive registers. |
| 420 | if (!MI->getOperand(OpNo).isRegister() || |
| 421 | OpNo+1 == MI->getNumOperands() || |
| 422 | !MI->getOperand(OpNo+1).isRegister()) |
| 423 | return true; |
| 424 | ++OpNo; // Return the high-part. |
| 425 | break; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | printOperand(MI, OpNo); |
| 430 | return false; |
| 431 | } |
| 432 | |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 433 | bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 434 | unsigned AsmVariant, |
| 435 | const char *ExtraCode) { |
| 436 | if (ExtraCode && ExtraCode[0]) |
| 437 | return true; // Unknown modifier. |
| 438 | printMemRegReg(MI, OpNo); |
| 439 | return false; |
| 440 | } |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 441 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 442 | /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to |
| 443 | /// the current output stream. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 444 | /// |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 445 | void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) { |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 446 | ++EmittedInsts; |
Chris Lattner | 617742b | 2005-10-14 22:44:13 +0000 | [diff] [blame] | 447 | |
Nate Begeman | ad5f65c | 2005-04-05 18:19:50 +0000 | [diff] [blame] | 448 | // Check for slwi/srwi mnemonics. |
| 449 | if (MI->getOpcode() == PPC::RLWINM) { |
| 450 | bool FoundMnemonic = false; |
| 451 | unsigned char SH = MI->getOperand(2).getImmedValue(); |
| 452 | unsigned char MB = MI->getOperand(3).getImmedValue(); |
| 453 | unsigned char ME = MI->getOperand(4).getImmedValue(); |
| 454 | if (SH <= 31 && MB == 0 && ME == (31-SH)) { |
| 455 | O << "slwi "; FoundMnemonic = true; |
| 456 | } |
| 457 | if (SH <= 31 && MB == (32-SH) && ME == 31) { |
| 458 | O << "srwi "; FoundMnemonic = true; |
| 459 | SH = 32-SH; |
| 460 | } |
| 461 | if (FoundMnemonic) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 462 | printOperand(MI, 0); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 463 | O << ", "; |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 464 | printOperand(MI, 1); |
Nate Begeman | ad5f65c | 2005-04-05 18:19:50 +0000 | [diff] [blame] | 465 | O << ", " << (unsigned int)SH << "\n"; |
| 466 | return; |
| 467 | } |
Chris Lattner | b410dc9 | 2006-06-20 23:18:58 +0000 | [diff] [blame] | 468 | } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) { |
Chris Lattner | 4d73a5a | 2006-02-08 06:56:40 +0000 | [diff] [blame] | 469 | if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) { |
| 470 | O << "mr "; |
| 471 | printOperand(MI, 0); |
| 472 | O << ", "; |
| 473 | printOperand(MI, 1); |
| 474 | O << "\n"; |
| 475 | return; |
| 476 | } |
Nate Begeman | ad5f65c | 2005-04-05 18:19:50 +0000 | [diff] [blame] | 477 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 478 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 479 | if (printInstruction(MI)) |
| 480 | return; // Printer was automatically generated |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 481 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 482 | assert(0 && "Unhandled instruction in asm writer!"); |
| 483 | abort(); |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 484 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 487 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 488 | /// method to print assembly for each instruction. |
| 489 | /// |
| 490 | bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 491 | DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>()); |
| 492 | |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 493 | SetupMachineFunction(MF); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 494 | O << "\n\n"; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 495 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 496 | // Print out constants referenced by the function |
Chris Lattner | c569e61 | 2005-11-21 08:26:15 +0000 | [diff] [blame] | 497 | EmitConstantPool(MF.getConstantPool()); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 498 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 499 | // Print out jump tables referenced by the function |
| 500 | EmitJumpTableInfo(MF.getJumpTableInfo()); |
| 501 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 502 | // Print out labels for the function. |
Chris Lattner | ac7fd7f | 2005-11-14 18:52:46 +0000 | [diff] [blame] | 503 | const Function *F = MF.getFunction(); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 504 | switch (F->getLinkage()) { |
| 505 | default: assert(0 && "Unknown linkage type!"); |
| 506 | case Function::InternalLinkage: // Symbols default to internal. |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 507 | SwitchToTextSection("\t.text", F); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 508 | break; |
| 509 | case Function::ExternalLinkage: |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 510 | SwitchToTextSection("\t.text", F); |
Chris Lattner | f02a916 | 2005-10-28 18:44:07 +0000 | [diff] [blame] | 511 | O << "\t.globl\t" << CurrentFnName << "\n"; |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 512 | break; |
| 513 | case Function::WeakLinkage: |
| 514 | case Function::LinkOnceLinkage: |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 515 | SwitchToTextSection( |
| 516 | ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 517 | O << "\t.globl\t" << CurrentFnName << "\n"; |
| 518 | O << "\t.weak_definition\t" << CurrentFnName << "\n"; |
| 519 | break; |
| 520 | } |
Chris Lattner | 33d5082 | 2006-02-14 20:42:33 +0000 | [diff] [blame] | 521 | EmitAlignment(4, F); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 522 | O << CurrentFnName << ":\n"; |
| 523 | |
Jim Laskey | 6b92b8e | 2006-04-07 20:44:42 +0000 | [diff] [blame] | 524 | // Emit pre-function debug information. |
Jim Laskey | 89d67fa | 2006-06-23 12:51:53 +0000 | [diff] [blame^] | 525 | DW.BeginFunction(&MF); |
Jim Laskey | 6b92b8e | 2006-04-07 20:44:42 +0000 | [diff] [blame] | 526 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 527 | // Print out code for the function. |
| 528 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 529 | I != E; ++I) { |
| 530 | // Print a label for the basic block. |
Chris Lattner | 1db1adb | 2005-08-21 19:09:33 +0000 | [diff] [blame] | 531 | if (I != MF.begin()) { |
Nate Begeman | cdf38c4 | 2006-05-02 05:37:32 +0000 | [diff] [blame] | 532 | printBasicBlockLabel(I, true); |
| 533 | O << '\n'; |
Chris Lattner | 1db1adb | 2005-08-21 19:09:33 +0000 | [diff] [blame] | 534 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 535 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 536 | II != E; ++II) { |
| 537 | // Print the assembly for the instruction. |
| 538 | O << "\t"; |
| 539 | printMachineInstruction(II); |
| 540 | } |
| 541 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 542 | |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 543 | // Emit post-function debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 544 | DW.EndFunction(); |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 545 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 546 | // We didn't modify anything. |
| 547 | return false; |
| 548 | } |
| 549 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 550 | |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 551 | bool DarwinAsmPrinter::doInitialization(Module &M) { |
Chris Lattner | 3c304a3 | 2005-08-05 22:05:03 +0000 | [diff] [blame] | 552 | if (TM.getSubtarget<PPCSubtarget>().isGigaProcessor()) |
| 553 | O << "\t.machine ppc970\n"; |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 554 | AsmPrinter::doInitialization(M); |
Chris Lattner | 85eac0d | 2005-11-10 19:33:43 +0000 | [diff] [blame] | 555 | |
| 556 | // Darwin wants symbols to be quoted if they have complex names. |
| 557 | Mang->setUseQuotes(true); |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 558 | |
| 559 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 560 | DW.BeginModule(&M); |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 561 | return false; |
| 562 | } |
| 563 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 564 | bool DarwinAsmPrinter::doFinalization(Module &M) { |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 565 | const TargetData *TD = TM.getTargetData(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 566 | |
| 567 | // Print out module-level global variables here. |
Chris Lattner | ced704b | 2005-11-14 19:00:30 +0000 | [diff] [blame] | 568 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 569 | I != E; ++I) { |
| 570 | if (!I->hasInitializer()) continue; // External global require no code |
| 571 | |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 572 | // Check to see if this is a special global used by LLVM, if so, emit it. |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 573 | if (EmitSpecialLLVMGlobal(I)) |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 574 | continue; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 575 | |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 576 | std::string name = Mang->getValueName(I); |
| 577 | Constant *C = I->getInitializer(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 578 | unsigned Size = TD->getTypeSize(C->getType()); |
Chris Lattner | 7d8d5a5 | 2006-02-05 01:30:45 +0000 | [diff] [blame] | 579 | unsigned Align = getPreferredAlignmentLog(I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 580 | |
| 581 | if (C->isNullValue() && /* FIXME: Verify correct */ |
| 582 | (I->hasInternalLinkage() || I->hasWeakLinkage() || |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 583 | I->hasLinkOnceLinkage() || |
| 584 | (I->hasExternalLinkage() && !I->hasSection()))) { |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 585 | if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 586 | if (I->hasExternalLinkage()) { |
| 587 | O << "\t.globl " << name << '\n'; |
| 588 | O << "\t.zerofill __DATA, __common, " << name << ", " |
| 589 | << Size << ", " << Align; |
| 590 | } else if (I->hasInternalLinkage()) { |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 591 | SwitchToDataSection("\t.data", I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 592 | O << LCOMMDirective << name << "," << Size << "," << Align; |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 593 | } else { |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 594 | SwitchToDataSection("\t.data", I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 595 | O << ".comm " << name << "," << Size; |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 596 | } |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 597 | O << "\t\t; '" << I->getName() << "'\n"; |
| 598 | } else { |
| 599 | switch (I->getLinkage()) { |
| 600 | case GlobalValue::LinkOnceLinkage: |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 601 | case GlobalValue::WeakLinkage: |
Chris Lattner | cec26fc | 2005-12-22 21:15:17 +0000 | [diff] [blame] | 602 | O << "\t.globl " << name << '\n' |
| 603 | << "\t.weak_definition " << name << '\n'; |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 604 | SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 605 | break; |
| 606 | case GlobalValue::AppendingLinkage: |
| 607 | // FIXME: appending linkage variables should go into a section of |
| 608 | // their name or something. For now, just emit them as external. |
| 609 | case GlobalValue::ExternalLinkage: |
| 610 | // If external or appending, declare as a global symbol |
| 611 | O << "\t.globl " << name << "\n"; |
| 612 | // FALL THROUGH |
| 613 | case GlobalValue::InternalLinkage: |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 614 | SwitchToDataSection("\t.data", I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 615 | break; |
| 616 | default: |
| 617 | std::cerr << "Unknown linkage type!"; |
| 618 | abort(); |
| 619 | } |
| 620 | |
| 621 | EmitAlignment(Align, I); |
| 622 | O << name << ":\t\t\t\t; '" << I->getName() << "'\n"; |
| 623 | EmitGlobalConstant(C); |
Chris Lattner | bc1c215 | 2006-01-21 01:35:26 +0000 | [diff] [blame] | 624 | O << '\n'; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 625 | } |
| 626 | } |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 627 | |
| 628 | // Output stubs for dynamically-linked functions |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 629 | if (TM.getRelocationModel() == Reloc::PIC) { |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 630 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
| 631 | i != e; ++i) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 632 | SwitchToTextSection(".section __TEXT,__picsymbolstub1,symbol_stubs," |
| 633 | "pure_instructions,32", 0); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 634 | EmitAlignment(2); |
| 635 | O << "L" << *i << "$stub:\n"; |
| 636 | O << "\t.indirect_symbol " << *i << "\n"; |
| 637 | O << "\tmflr r0\n"; |
| 638 | O << "\tbcl 20,31,L0$" << *i << "\n"; |
| 639 | O << "L0$" << *i << ":\n"; |
| 640 | O << "\tmflr r11\n"; |
| 641 | O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n"; |
| 642 | O << "\tmtlr r0\n"; |
| 643 | O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n"; |
| 644 | O << "\tmtctr r12\n"; |
| 645 | O << "\tbctr\n"; |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 646 | SwitchToDataSection(".lazy_symbol_pointer", 0); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 647 | O << "L" << *i << "$lazy_ptr:\n"; |
| 648 | O << "\t.indirect_symbol " << *i << "\n"; |
| 649 | O << "\t.long dyld_stub_binding_helper\n"; |
| 650 | } |
| 651 | } else { |
| 652 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
| 653 | i != e; ++i) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 654 | SwitchToTextSection(".section __TEXT,__symbol_stub1,symbol_stubs," |
| 655 | "pure_instructions,16", 0); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 656 | EmitAlignment(4); |
| 657 | O << "L" << *i << "$stub:\n"; |
| 658 | O << "\t.indirect_symbol " << *i << "\n"; |
| 659 | O << "\tlis r11,ha16(L" << *i << "$lazy_ptr)\n"; |
| 660 | O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n"; |
| 661 | O << "\tmtctr r12\n"; |
| 662 | O << "\tbctr\n"; |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 663 | SwitchToDataSection(".lazy_symbol_pointer", 0); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 664 | O << "L" << *i << "$lazy_ptr:\n"; |
| 665 | O << "\t.indirect_symbol " << *i << "\n"; |
| 666 | O << "\t.long dyld_stub_binding_helper\n"; |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 667 | } |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 668 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 669 | |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 670 | O << "\n"; |
| 671 | |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 672 | // Output stubs for external and common global variables. |
| 673 | if (GVStubs.begin() != GVStubs.end()) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 674 | SwitchToDataSection(".non_lazy_symbol_pointer", 0); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 675 | for (std::set<std::string>::iterator I = GVStubs.begin(), |
| 676 | E = GVStubs.end(); I != E; ++I) { |
| 677 | O << "L" << *I << "$non_lazy_ptr:\n"; |
| 678 | O << "\t.indirect_symbol " << *I << "\n"; |
| 679 | O << "\t.long\t0\n"; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 680 | } |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 681 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 682 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 683 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 684 | DW.EndModule(); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 685 | |
Chris Lattner | 5b0ac99 | 2005-11-01 00:12:36 +0000 | [diff] [blame] | 686 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 687 | // contain code that falls through to other global symbols (e.g. the obvious |
| 688 | // implementation of multiple entry points). If this doesn't occur, the |
| 689 | // linker can safely perform dead code stripping. Since LLVM never generates |
| 690 | // code that does this, it is always safe to set. |
| 691 | O << "\t.subsections_via_symbols\n"; |
| 692 | |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 693 | AsmPrinter::doFinalization(M); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 694 | return false; // success |
| 695 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 696 | |
Nate Begeman | 6e0f386 | 2006-05-02 17:34:51 +0000 | [diff] [blame] | 697 | /// runOnMachineFunction - This uses the printMachineInstruction() |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 698 | /// method to print assembly for each instruction. |
| 699 | /// |
| 700 | bool AIXAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Chris Lattner | 6d5a4f6 | 2005-11-21 08:02:41 +0000 | [diff] [blame] | 701 | SetupMachineFunction(MF); |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 702 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 703 | // Print out constants referenced by the function |
Chris Lattner | c569e61 | 2005-11-21 08:26:15 +0000 | [diff] [blame] | 704 | EmitConstantPool(MF.getConstantPool()); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 705 | |
| 706 | // Print out header for the function. |
| 707 | O << "\t.csect .text[PR]\n" |
| 708 | << "\t.align 2\n" |
| 709 | << "\t.globl " << CurrentFnName << '\n' |
| 710 | << "\t.globl ." << CurrentFnName << '\n' |
| 711 | << "\t.csect " << CurrentFnName << "[DS],3\n" |
| 712 | << CurrentFnName << ":\n" |
| 713 | << "\t.llong ." << CurrentFnName << ", TOC[tc0], 0\n" |
| 714 | << "\t.csect .text[PR]\n" |
| 715 | << '.' << CurrentFnName << ":\n"; |
| 716 | |
| 717 | // Print out code for the function. |
| 718 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 719 | I != E; ++I) { |
Nate Begeman | 6e0f386 | 2006-05-02 17:34:51 +0000 | [diff] [blame] | 720 | printBasicBlockLabel(I); |
| 721 | O << '\n'; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 722 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 723 | II != E; ++II) { |
| 724 | // Print the assembly for the instruction. |
| 725 | O << "\t"; |
| 726 | printMachineInstruction(II); |
| 727 | } |
| 728 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 729 | |
| 730 | O << "LT.." << CurrentFnName << ":\n" |
| 731 | << "\t.long 0\n" |
| 732 | << "\t.byte 0,0,32,65,128,0,0,0\n" |
| 733 | << "\t.long LT.." << CurrentFnName << "-." << CurrentFnName << '\n' |
| 734 | << "\t.short 3\n" |
| 735 | << "\t.byte \"" << CurrentFnName << "\"\n" |
| 736 | << "\t.align 2\n"; |
| 737 | |
| 738 | // We didn't modify anything. |
| 739 | return false; |
| 740 | } |
| 741 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 742 | bool AIXAsmPrinter::doInitialization(Module &M) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 743 | SwitchToDataSection("", 0); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 744 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 745 | O << "\t.machine \"ppc64\"\n" |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 746 | << "\t.toc\n" |
| 747 | << "\t.csect .text[PR]\n"; |
| 748 | |
| 749 | // Print out module-level global variables |
Chris Lattner | 2e00d7d | 2005-07-26 19:03:27 +0000 | [diff] [blame] | 750 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 751 | I != E; ++I) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 752 | if (!I->hasInitializer()) |
| 753 | continue; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 754 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 755 | std::string Name = I->getName(); |
| 756 | Constant *C = I->getInitializer(); |
| 757 | // N.B.: We are defaulting to writable strings |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 758 | if (I->hasExternalLinkage()) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 759 | O << "\t.globl " << Name << '\n' |
| 760 | << "\t.csect .data[RW],3\n"; |
| 761 | } else { |
| 762 | O << "\t.csect _global.rw_c[RW],3\n"; |
| 763 | } |
| 764 | O << Name << ":\n"; |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 765 | EmitGlobalConstant(C); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | // Output labels for globals |
Chris Lattner | e4d5c44 | 2005-03-15 04:54:21 +0000 | [diff] [blame] | 769 | if (M.global_begin() != M.global_end()) O << "\t.toc\n"; |
Chris Lattner | 2e00d7d | 2005-07-26 19:03:27 +0000 | [diff] [blame] | 770 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 771 | I != E; ++I) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 772 | const GlobalVariable *GV = I; |
| 773 | // Do not output labels for unused variables |
| 774 | if (GV->isExternal() && GV->use_begin() == GV->use_end()) |
| 775 | continue; |
| 776 | |
Chris Lattner | 0745536 | 2005-11-21 08:14:07 +0000 | [diff] [blame] | 777 | IncrementFunctionNumber(); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 778 | std::string Name = GV->getName(); |
Chris Lattner | 0745536 | 2005-11-21 08:14:07 +0000 | [diff] [blame] | 779 | std::string Label = "LC.." + utostr(getFunctionNumber()); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 780 | GVToLabelMap[GV] = Label; |
| 781 | O << Label << ":\n" |
| 782 | << "\t.tc " << Name << "[TC]," << Name; |
| 783 | if (GV->isExternal()) O << "[RW]"; |
| 784 | O << '\n'; |
Chris Lattner | 0745536 | 2005-11-21 08:14:07 +0000 | [diff] [blame] | 785 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 786 | |
Chris Lattner | 3459bfb | 2005-11-10 18:20:29 +0000 | [diff] [blame] | 787 | AsmPrinter::doInitialization(M); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 788 | return false; // success |
| 789 | } |
| 790 | |
| 791 | bool AIXAsmPrinter::doFinalization(Module &M) { |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 792 | const TargetData *TD = TM.getTargetData(); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 793 | // Print out module-level global variables |
Chris Lattner | 2e00d7d | 2005-07-26 19:03:27 +0000 | [diff] [blame] | 794 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 795 | I != E; ++I) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 796 | if (I->hasInitializer() || I->hasExternalLinkage()) |
| 797 | continue; |
| 798 | |
| 799 | std::string Name = I->getName(); |
| 800 | if (I->hasInternalLinkage()) { |
| 801 | O << "\t.lcomm " << Name << ",16,_global.bss_c"; |
| 802 | } else { |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 803 | O << "\t.comm " << Name << "," << TD->getTypeSize(I->getType()) |
| 804 | << "," << Log2_32((unsigned)TD->getTypeAlignment(I->getType())); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 805 | } |
Chris Lattner | 6d5a4f6 | 2005-11-21 08:02:41 +0000 | [diff] [blame] | 806 | O << "\t\t" << CommentString << " "; |
Chris Lattner | 8ca0291 | 2005-10-03 07:08:36 +0000 | [diff] [blame] | 807 | WriteAsOperand(O, I, false, true, &M); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 808 | O << "\n"; |
| 809 | } |
| 810 | |
| 811 | O << "_section_.text:\n" |
| 812 | << "\t.csect .data[RW],3\n" |
| 813 | << "\t.llong _section_.text\n"; |
Chris Lattner | 3459bfb | 2005-11-10 18:20:29 +0000 | [diff] [blame] | 814 | AsmPrinter::doFinalization(M); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 815 | return false; // success |
| 816 | } |