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 | df4ed63 | 2006-11-17 22:10:59 +0000 | [diff] [blame] | 21 | #include "PPCPredicates.h" |
Chris Lattner | 16e71f2 | 2005-10-14 23:59:06 +0000 | [diff] [blame] | 22 | #include "PPCTargetMachine.h" |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 23 | #include "PPCSubtarget.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 24 | #include "llvm/Constants.h" |
| 25 | #include "llvm/DerivedTypes.h" |
| 26 | #include "llvm/Module.h" |
| 27 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/AsmPrinter.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/DwarfWriter.h" |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineInstr.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Mangler.h" |
Nate Begeman | a11c2e8 | 2004-09-04 14:51:26 +0000 | [diff] [blame] | 34 | #include "llvm/Support/MathExtras.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 35 | #include "llvm/Support/CommandLine.h" |
| 36 | #include "llvm/Support/Debug.h" |
Chris Lattner | a4f0b3a | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 37 | #include "llvm/Support/Compiler.h" |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 38 | #include "llvm/Target/TargetAsmInfo.h" |
Nate Begeman | 17304c3 | 2004-10-26 06:02:38 +0000 | [diff] [blame] | 39 | #include "llvm/Target/MRegisterInfo.h" |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 40 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | d2ee218 | 2006-02-18 00:08:58 +0000 | [diff] [blame] | 41 | #include "llvm/Target/TargetOptions.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/Statistic.h" |
| 43 | #include "llvm/ADT/StringExtras.h" |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 44 | #include <set> |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 45 | using namespace llvm; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 47 | STATISTIC(EmittedInsts, "Number of machine instrs printed"); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 95b2c7d | 2006-12-19 22:59:26 +0000 | [diff] [blame] | 49 | namespace { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 50 | struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 51 | std::set<std::string> FnStubs, GVStubs; |
Chris Lattner | dadceed | 2006-09-20 17:07:15 +0000 | [diff] [blame] | 52 | const PPCSubtarget &Subtarget; |
Evan Cheng | 1c45a66 | 2006-12-01 07:56:37 +0000 | [diff] [blame] | 53 | |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 54 | PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) |
Chris Lattner | dadceed | 2006-09-20 17:07:15 +0000 | [diff] [blame] | 55 | : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget<PPCSubtarget>()) { |
| 56 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 57 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 58 | virtual const char *getPassName() const { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 59 | return "PowerPC Assembly Printer"; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 62 | PPCTargetMachine &getTM() { |
| 63 | return static_cast<PPCTargetMachine&>(TM); |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Nate Begeman | adeb43d | 2005-07-20 22:42:00 +0000 | [diff] [blame] | 66 | unsigned enumRegToMachineReg(unsigned enumReg) { |
| 67 | switch (enumReg) { |
| 68 | default: assert(0 && "Unhandled register!"); break; |
| 69 | case PPC::CR0: return 0; |
| 70 | case PPC::CR1: return 1; |
| 71 | case PPC::CR2: return 2; |
| 72 | case PPC::CR3: return 3; |
| 73 | case PPC::CR4: return 4; |
| 74 | case PPC::CR5: return 5; |
| 75 | case PPC::CR6: return 6; |
| 76 | case PPC::CR7: return 7; |
| 77 | } |
| 78 | abort(); |
| 79 | } |
| 80 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 81 | /// printInstruction - This method is automatically generated by tablegen |
| 82 | /// from the instruction set description. This method returns true if the |
| 83 | /// machine instruction was sufficiently described to print it, otherwise it |
| 84 | /// returns false. |
| 85 | bool printInstruction(const MachineInstr *MI); |
| 86 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 87 | void printMachineInstruction(const MachineInstr *MI); |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 88 | void printOp(const MachineOperand &MO); |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 89 | |
| 90 | /// stripRegisterPrefix - This method strips the character prefix from a |
| 91 | /// register name so that only the number is left. Used by for linux asm. |
Jim Laskey | 40ee69f | 2006-12-20 21:33:34 +0000 | [diff] [blame] | 92 | const char *stripRegisterPrefix(const char *RegName) { |
| 93 | switch (RegName[0]) { |
| 94 | case 'r': |
| 95 | case 'f': |
| 96 | case 'v': return RegName + 1; |
Jim Laskey | 2aa14aa | 2006-12-20 21:35:00 +0000 | [diff] [blame] | 97 | case 'c': if (RegName[1] == 'r') return RegName + 2; |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 98 | } |
Jim Laskey | 40ee69f | 2006-12-20 21:33:34 +0000 | [diff] [blame] | 99 | |
| 100 | return RegName; |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /// printRegister - Print register according to target requirements. |
| 104 | /// |
| 105 | void printRegister(const MachineOperand &MO, bool R0AsZero) { |
| 106 | unsigned RegNo = MO.getReg(); |
| 107 | assert(MRegisterInfo::isPhysicalRegister(RegNo) && "Not physreg??"); |
| 108 | |
| 109 | // If we should use 0 for R0. |
| 110 | if (R0AsZero && RegNo == PPC::R0) { |
| 111 | O << "0"; |
| 112 | return; |
| 113 | } |
| 114 | |
Jim Laskey | 40ee69f | 2006-12-20 21:33:34 +0000 | [diff] [blame] | 115 | const char *RegName = TM.getRegisterInfo()->get(RegNo).Name; |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 116 | // Linux assembler (Others?) does not take register mnemonics. |
| 117 | // FIXME - What about special registers used in mfspr/mtspr? |
Jim Laskey | 40ee69f | 2006-12-20 21:33:34 +0000 | [diff] [blame] | 118 | if (!Subtarget.isDarwin()) RegName = stripRegisterPrefix(RegName); |
| 119 | O << RegName; |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 120 | } |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 5887327 | 2006-02-01 22:38:46 +0000 | [diff] [blame] | 122 | void printOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 123 | const MachineOperand &MO = MI->getOperand(OpNo); |
Chris Lattner | 2d90ac7 | 2006-05-04 18:05:43 +0000 | [diff] [blame] | 124 | if (MO.isRegister()) { |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 125 | printRegister(MO, false); |
Chris Lattner | 0ea3171 | 2004-08-15 05:46:14 +0000 | [diff] [blame] | 126 | } else if (MO.isImmediate()) { |
| 127 | O << MO.getImmedValue(); |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 128 | } else { |
| 129 | printOp(MO); |
| 130 | } |
| 131 | } |
Chris Lattner | 5887327 | 2006-02-01 22:38:46 +0000 | [diff] [blame] | 132 | |
| 133 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 134 | unsigned AsmVariant, const char *ExtraCode); |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 135 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 136 | unsigned AsmVariant, const char *ExtraCode); |
| 137 | |
Chris Lattner | 5887327 | 2006-02-01 22:38:46 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 9c61dcf | 2006-03-25 06:12:06 +0000 | [diff] [blame] | 139 | void printS5ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
| 140 | char value = MI->getOperand(OpNo).getImmedValue(); |
| 141 | value = (value << (32-5)) >> (32-5); |
| 142 | O << (int)value; |
| 143 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 144 | void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | c330612 | 2004-08-21 05:56:39 +0000 | [diff] [blame] | 145 | unsigned char value = MI->getOperand(OpNo).getImmedValue(); |
Chris Lattner | 12585ba | 2004-08-21 19:11:03 +0000 | [diff] [blame] | 146 | assert(value <= 31 && "Invalid u5imm argument!"); |
Nate Begeman | c330612 | 2004-08-21 05:56:39 +0000 | [diff] [blame] | 147 | O << (unsigned int)value; |
| 148 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 149 | void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 07aada8 | 2004-08-30 02:28:06 +0000 | [diff] [blame] | 150 | unsigned char value = MI->getOperand(OpNo).getImmedValue(); |
| 151 | assert(value <= 63 && "Invalid u6imm argument!"); |
| 152 | O << (unsigned int)value; |
| 153 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 154 | void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 155 | O << (short)MI->getOperand(OpNo).getImmedValue(); |
| 156 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 157 | void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 97b2a2e | 2004-08-15 05:20:16 +0000 | [diff] [blame] | 158 | O << (unsigned short)MI->getOperand(OpNo).getImmedValue(); |
| 159 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 160 | void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 1b0a2d8 | 2006-11-16 21:45:30 +0000 | [diff] [blame] | 161 | if (MI->getOperand(OpNo).isImmediate()) { |
| 162 | O << (short)(MI->getOperand(OpNo).getImmedValue()*4); |
| 163 | } else { |
| 164 | O << "lo16("; |
| 165 | printOp(MI->getOperand(OpNo)); |
| 166 | if (TM.getRelocationModel() == Reloc::PIC_) |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 167 | O << "-\"L" << getFunctionNumber() << "$pb\")"; |
Chris Lattner | 1b0a2d8 | 2006-11-16 21:45:30 +0000 | [diff] [blame] | 168 | else |
| 169 | O << ')'; |
| 170 | } |
Chris Lattner | 841d12d | 2005-10-18 16:51:22 +0000 | [diff] [blame] | 171 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 172 | void printBranchOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 173 | // Branches can take an immediate operand. This is used by the branch |
| 174 | // selection pass to print $+8, an eight byte displacement from the PC. |
| 175 | if (MI->getOperand(OpNo).isImmediate()) { |
Evan Cheng | b9ca926 | 2006-08-25 21:54:44 +0000 | [diff] [blame] | 176 | O << "$+" << MI->getOperand(OpNo).getImmedValue()*4; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 177 | } else { |
Chris Lattner | 3e7f86a | 2005-11-17 19:16:08 +0000 | [diff] [blame] | 178 | printOp(MI->getOperand(OpNo)); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 179 | } |
Nate Begeman | b7a8f2c | 2004-09-02 08:13:00 +0000 | [diff] [blame] | 180 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 181 | void printCallOperand(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 182 | const MachineOperand &MO = MI->getOperand(OpNo); |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 183 | if (TM.getRelocationModel() != Reloc::Static) { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 184 | if (MO.getType() == MachineOperand::MO_GlobalAddress) { |
| 185 | GlobalValue *GV = MO.getGlobal(); |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 186 | if (((GV->isDeclaration() || GV->hasWeakLinkage() || |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 187 | GV->hasLinkOnceLinkage()))) { |
| 188 | // Dynamically-resolved functions need a stub for the function. |
| 189 | std::string Name = Mang->getValueName(GV); |
| 190 | FnStubs.insert(Name); |
| 191 | O << "L" << Name << "$stub"; |
Evan Cheng | 1c45a66 | 2006-12-01 07:56:37 +0000 | [diff] [blame] | 192 | if (GV->hasExternalWeakLinkage()) |
Rafael Espindola | 15404d0 | 2006-12-18 03:37:18 +0000 | [diff] [blame] | 193 | ExtWeakSymbols.insert(GV); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 194 | return; |
| 195 | } |
| 196 | } |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 197 | if (MO.getType() == MachineOperand::MO_ExternalSymbol) { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 198 | std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName(); |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 199 | FnStubs.insert(Name); |
| 200 | O << "L" << Name << "$stub"; |
| 201 | return; |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 202 | } |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 203 | } |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 204 | |
| 205 | printOp(MI->getOperand(OpNo)); |
Chris Lattner | 3e7f86a | 2005-11-17 19:16:08 +0000 | [diff] [blame] | 206 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 207 | void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 422b0ce | 2005-11-16 00:48:01 +0000 | [diff] [blame] | 208 | O << (int)MI->getOperand(OpNo).getImmedValue()*4; |
| 209 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 210 | void printPICLabel(const MachineInstr *MI, unsigned OpNo) { |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 211 | O << "\"L" << getFunctionNumber() << "$pb\"\n"; |
| 212 | O << "\"L" << getFunctionNumber() << "$pb\":"; |
Nate Begeman | b7a8f2c | 2004-09-02 08:13:00 +0000 | [diff] [blame] | 213 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 214 | void printSymbolHi(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 215 | if (MI->getOperand(OpNo).isImmediate()) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 216 | printS16ImmOperand(MI, OpNo); |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 217 | } else { |
Nick Lewycky | f54949d | 2007-03-03 05:29:51 +0000 | [diff] [blame] | 218 | if (Subtarget.isDarwin()) O << "ha16("; |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 219 | printOp(MI->getOperand(OpNo)); |
Chris Lattner | 35d86fe | 2006-07-26 21:12:04 +0000 | [diff] [blame] | 220 | if (TM.getRelocationModel() == Reloc::PIC_) |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 221 | O << "-\"L" << getFunctionNumber() << "$pb\""; |
Nick Lewycky | f54949d | 2007-03-03 05:29:51 +0000 | [diff] [blame] | 222 | if (Subtarget.isDarwin()) |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 223 | O << ')'; |
Nick Lewycky | f54949d | 2007-03-03 05:29:51 +0000 | [diff] [blame] | 224 | else |
| 225 | O << "@ha"; |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 226 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 227 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 228 | void printSymbolLo(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 229 | if (MI->getOperand(OpNo).isImmediate()) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 230 | printS16ImmOperand(MI, OpNo); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 231 | } else { |
Nick Lewycky | f54949d | 2007-03-03 05:29:51 +0000 | [diff] [blame] | 232 | if (Subtarget.isDarwin()) O << "lo16("; |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 233 | printOp(MI->getOperand(OpNo)); |
Chris Lattner | 35d86fe | 2006-07-26 21:12:04 +0000 | [diff] [blame] | 234 | if (TM.getRelocationModel() == Reloc::PIC_) |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 235 | O << "-\"L" << getFunctionNumber() << "$pb\""; |
Nick Lewycky | f54949d | 2007-03-03 05:29:51 +0000 | [diff] [blame] | 236 | if (Subtarget.isDarwin()) |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 237 | O << ')'; |
Nick Lewycky | f54949d | 2007-03-03 05:29:51 +0000 | [diff] [blame] | 238 | else |
| 239 | O << "@l"; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 240 | } |
| 241 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 242 | void printcrbitm(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | adeb43d | 2005-07-20 22:42:00 +0000 | [diff] [blame] | 243 | unsigned CCReg = MI->getOperand(OpNo).getReg(); |
| 244 | unsigned RegNo = enumRegToMachineReg(CCReg); |
| 245 | O << (0x80 >> RegNo); |
| 246 | } |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 247 | // The new addressing mode printers. |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 248 | void printMemRegImm(const MachineInstr *MI, unsigned OpNo) { |
| 249 | printSymbolLo(MI, OpNo); |
| 250 | O << '('; |
Chris Lattner | 13feb58 | 2006-03-21 17:21:13 +0000 | [diff] [blame] | 251 | if (MI->getOperand(OpNo+1).isRegister() && |
| 252 | MI->getOperand(OpNo+1).getReg() == PPC::R0) |
| 253 | O << "0"; |
| 254 | else |
| 255 | printOperand(MI, OpNo+1); |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 256 | O << ')'; |
| 257 | } |
Chris Lattner | e5ba580 | 2006-03-22 05:26:03 +0000 | [diff] [blame] | 258 | void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) { |
| 259 | if (MI->getOperand(OpNo).isImmediate()) |
| 260 | printS16X4ImmOperand(MI, OpNo); |
| 261 | else |
| 262 | printSymbolLo(MI, OpNo); |
| 263 | O << '('; |
| 264 | if (MI->getOperand(OpNo+1).isRegister() && |
| 265 | MI->getOperand(OpNo+1).getReg() == PPC::R0) |
| 266 | O << "0"; |
| 267 | else |
| 268 | printOperand(MI, OpNo+1); |
| 269 | O << ')'; |
| 270 | } |
| 271 | |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 272 | void printMemRegReg(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 88276b8 | 2005-12-19 23:40:42 +0000 | [diff] [blame] | 273 | // When used as the base register, r0 reads constant zero rather than |
| 274 | // the value contained in the register. For this reason, the darwin |
| 275 | // assembler requires that we print r0 as 0 (no r) when used as the base. |
| 276 | const MachineOperand &MO = MI->getOperand(OpNo); |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 277 | printRegister(MO, true); |
Nate Begeman | 7fd1edd | 2005-12-19 23:25:09 +0000 | [diff] [blame] | 278 | O << ", "; |
| 279 | printOperand(MI, OpNo+1); |
| 280 | } |
| 281 | |
Chris Lattner | af53a87 | 2006-11-04 05:27:39 +0000 | [diff] [blame] | 282 | void printPredicateOperand(const MachineInstr *MI, unsigned OpNo, |
| 283 | const char *Modifier); |
| 284 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 285 | virtual bool runOnMachineFunction(MachineFunction &F) = 0; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 286 | virtual bool doFinalization(Module &M) = 0; |
Jim Laskey | bda9b0e | 2007-02-21 22:47:38 +0000 | [diff] [blame] | 287 | |
| 288 | virtual void EmitExternalGlobal(const GlobalVariable *GV); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 289 | }; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 290 | |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 291 | /// LinuxAsmPrinter - PowerPC assembly printer, customized for Linux |
| 292 | struct VISIBILITY_HIDDEN LinuxAsmPrinter : public PPCAsmPrinter { |
| 293 | |
| 294 | DwarfWriter DW; |
| 295 | |
| 296 | LinuxAsmPrinter(std::ostream &O, PPCTargetMachine &TM, |
| 297 | const TargetAsmInfo *T) |
| 298 | : PPCAsmPrinter(O, TM, T), DW(O, this, T) { |
| 299 | } |
| 300 | |
| 301 | virtual const char *getPassName() const { |
| 302 | return "Linux PPC Assembly Printer"; |
| 303 | } |
| 304 | |
| 305 | bool runOnMachineFunction(MachineFunction &F); |
| 306 | bool doInitialization(Module &M); |
| 307 | bool doFinalization(Module &M); |
| 308 | |
| 309 | void getAnalysisUsage(AnalysisUsage &AU) const { |
| 310 | AU.setPreservesAll(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 311 | AU.addRequired<MachineModuleInfo>(); |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 312 | PPCAsmPrinter::getAnalysisUsage(AU); |
| 313 | } |
| 314 | |
| 315 | /// getSectionForFunction - Return the section that we should emit the |
| 316 | /// specified function body into. |
| 317 | virtual std::string getSectionForFunction(const Function &F) const; |
| 318 | }; |
| 319 | |
Misha Brukman | 3e0b51a | 2004-09-05 02:42:44 +0000 | [diff] [blame] | 320 | /// DarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac OS |
| 321 | /// X |
Chris Lattner | 9525528 | 2006-06-28 23:17:24 +0000 | [diff] [blame] | 322 | struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter { |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 323 | |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 324 | DwarfWriter DW; |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 325 | MachineModuleInfo *MMI; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 326 | |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 327 | DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM, |
| 328 | const TargetAsmInfo *T) |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 329 | : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | virtual const char *getPassName() const { |
| 333 | return "Darwin PPC Assembly Printer"; |
| 334 | } |
Chris Lattner | 646f7af | 2005-12-09 18:24:29 +0000 | [diff] [blame] | 335 | |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 336 | bool runOnMachineFunction(MachineFunction &F); |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 337 | bool doInitialization(Module &M); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 338 | bool doFinalization(Module &M); |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 339 | |
| 340 | void getAnalysisUsage(AnalysisUsage &AU) const { |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 341 | AU.setPreservesAll(); |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 342 | AU.addRequired<MachineModuleInfo>(); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 343 | PPCAsmPrinter::getAnalysisUsage(AU); |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Chris Lattner | 9b7ce7d | 2006-10-05 02:42:20 +0000 | [diff] [blame] | 346 | /// getSectionForFunction - Return the section that we should emit the |
| 347 | /// specified function body into. |
| 348 | virtual std::string getSectionForFunction(const Function &F) const; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 349 | }; |
| 350 | } // end of anonymous namespace |
| 351 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 352 | // Include the auto-generated portion of the assembly writer |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 353 | #include "PPCGenAsmWriter.inc" |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 354 | |
Chris Lattner | 9ba13e4 | 2005-11-17 19:25:59 +0000 | [diff] [blame] | 355 | void PPCAsmPrinter::printOp(const MachineOperand &MO) { |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 356 | switch (MO.getType()) { |
Chris Lattner | 63b3d71 | 2006-05-04 17:21:20 +0000 | [diff] [blame] | 357 | case MachineOperand::MO_Immediate: |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 358 | cerr << "printOp() does not handle immediate values\n"; |
Misha Brukman | af313fb | 2004-07-28 00:00:48 +0000 | [diff] [blame] | 359 | abort(); |
Misha Brukman | 97a296f | 2004-07-21 20:11:11 +0000 | [diff] [blame] | 360 | return; |
| 361 | |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 362 | case MachineOperand::MO_MachineBasicBlock: |
| 363 | printBasicBlockLabel(MO.getMachineBasicBlock()); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 364 | return; |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 365 | case MachineOperand::MO_JumpTableIndex: |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 366 | O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() |
| 367 | << '_' << MO.getJumpTableIndex(); |
Nate Begeman | 37efe67 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 368 | // FIXME: PIC relocation model |
| 369 | return; |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 370 | case MachineOperand::MO_ConstantPoolIndex: |
Evan Cheng | 347d39f | 2007-10-14 05:57:21 +0000 | [diff] [blame] | 371 | O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() |
| 372 | << '_' << MO.getConstantPoolIndex(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 373 | return; |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 374 | case MachineOperand::MO_ExternalSymbol: |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 375 | // Computing the address of an external symbol, not calling it. |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 376 | if (TM.getRelocationModel() != Reloc::Static) { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 377 | std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName(); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 378 | GVStubs.insert(Name); |
| 379 | O << "L" << Name << "$non_lazy_ptr"; |
| 380 | return; |
| 381 | } |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 382 | O << TAI->getGlobalPrefix() << MO.getSymbolName(); |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 383 | return; |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 384 | case MachineOperand::MO_GlobalAddress: { |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 385 | // Computing the address of a global symbol, not calling it. |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 386 | GlobalValue *GV = MO.getGlobal(); |
| 387 | std::string Name = Mang->getValueName(GV); |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 388 | |
Nate Begeman | fcf4a42 | 2004-10-17 23:01:34 +0000 | [diff] [blame] | 389 | // External or weakly linked global variables need non-lazily-resolved stubs |
Evan Cheng | 4c1aa86 | 2006-02-22 20:19:42 +0000 | [diff] [blame] | 390 | if (TM.getRelocationModel() != Reloc::Static) { |
Reid Spencer | 5cbf985 | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 391 | if (((GV->isDeclaration() || GV->hasWeakLinkage() || |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 392 | GV->hasLinkOnceLinkage()))) { |
Nate Begeman | d4c8bea | 2004-11-25 07:09:01 +0000 | [diff] [blame] | 393 | GVStubs.insert(Name); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 394 | O << "L" << Name << "$non_lazy_ptr"; |
| 395 | return; |
| 396 | } |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 397 | } |
Chris Lattner | 9542f971 | 2005-11-17 19:40:30 +0000 | [diff] [blame] | 398 | O << Name; |
Evan Cheng | 1c45a66 | 2006-12-01 07:56:37 +0000 | [diff] [blame] | 399 | |
Chris Lattner | 4105a9f | 2007-05-03 16:39:48 +0000 | [diff] [blame] | 400 | if (MO.getOffset() > 0) |
| 401 | O << "+" << MO.getOffset(); |
| 402 | else if (MO.getOffset() < 0) |
| 403 | O << MO.getOffset(); |
| 404 | |
Evan Cheng | 1c45a66 | 2006-12-01 07:56:37 +0000 | [diff] [blame] | 405 | if (GV->hasExternalWeakLinkage()) |
Rafael Espindola | 15404d0 | 2006-12-18 03:37:18 +0000 | [diff] [blame] | 406 | ExtWeakSymbols.insert(GV); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 407 | return; |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 408 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 409 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 410 | default: |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 411 | O << "<unknown operand type: " << MO.getType() << ">"; |
Misha Brukman | 22e1207 | 2004-06-25 15:11:34 +0000 | [diff] [blame] | 412 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
Jim Laskey | bda9b0e | 2007-02-21 22:47:38 +0000 | [diff] [blame] | 416 | /// EmitExternalGlobal - In this case we need to use the indirect symbol. |
| 417 | /// |
| 418 | void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) { |
| 419 | std::string Name = getGlobalLinkName(GV); |
| 420 | if (TM.getRelocationModel() != Reloc::Static) { |
| 421 | GVStubs.insert(Name); |
| 422 | O << "L" << Name << "$non_lazy_ptr"; |
| 423 | return; |
| 424 | } |
| 425 | O << Name; |
| 426 | } |
| 427 | |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 428 | /// PrintAsmOperand - Print out an operand for an inline asm expression. |
| 429 | /// |
| 430 | bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 431 | unsigned AsmVariant, |
| 432 | const char *ExtraCode) { |
| 433 | // Does this asm operand have a single letter operand modifier? |
| 434 | if (ExtraCode && ExtraCode[0]) { |
| 435 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
| 436 | |
| 437 | switch (ExtraCode[0]) { |
| 438 | default: return true; // Unknown modifier. |
Chris Lattner | 78192b6 | 2007-01-25 02:52:50 +0000 | [diff] [blame] | 439 | case 'c': // Don't print "$" before a global var name or constant. |
| 440 | // PPC never has a prefix. |
| 441 | printOperand(MI, OpNo); |
| 442 | return false; |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 443 | case 'L': // Write second word of DImode reference. |
| 444 | // Verify that this operand has two consecutive registers. |
| 445 | if (!MI->getOperand(OpNo).isRegister() || |
| 446 | OpNo+1 == MI->getNumOperands() || |
| 447 | !MI->getOperand(OpNo+1).isRegister()) |
| 448 | return true; |
| 449 | ++OpNo; // Return the high-part. |
| 450 | break; |
Chris Lattner | 6c2d260 | 2007-04-24 22:51:03 +0000 | [diff] [blame] | 451 | case 'I': |
| 452 | // Write 'i' if an integer constant, otherwise nothing. Used to print |
| 453 | // addi vs add, etc. |
Dan Gohman | 92dfe20 | 2007-09-14 20:33:02 +0000 | [diff] [blame] | 454 | if (MI->getOperand(OpNo).isImmediate()) |
Chris Lattner | 6c2d260 | 2007-04-24 22:51:03 +0000 | [diff] [blame] | 455 | O << "i"; |
| 456 | return false; |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | printOperand(MI, OpNo); |
| 461 | return false; |
| 462 | } |
| 463 | |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 464 | bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 465 | unsigned AsmVariant, |
| 466 | const char *ExtraCode) { |
| 467 | if (ExtraCode && ExtraCode[0]) |
| 468 | return true; // Unknown modifier. |
Chris Lattner | 9aa2895 | 2007-02-01 00:39:08 +0000 | [diff] [blame] | 469 | if (MI->getOperand(OpNo).isRegister()) |
| 470 | printMemRegReg(MI, OpNo); |
| 471 | else |
| 472 | printMemRegImm(MI, OpNo); |
Chris Lattner | 2c003e2 | 2006-02-24 20:27:40 +0000 | [diff] [blame] | 473 | return false; |
| 474 | } |
Chris Lattner | e3f0157 | 2006-02-23 19:31:10 +0000 | [diff] [blame] | 475 | |
Chris Lattner | af53a87 | 2006-11-04 05:27:39 +0000 | [diff] [blame] | 476 | void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo, |
| 477 | const char *Modifier) { |
| 478 | assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!"); |
| 479 | unsigned Code = MI->getOperand(OpNo).getImm(); |
| 480 | if (!strcmp(Modifier, "cc")) { |
| 481 | switch ((PPC::Predicate)Code) { |
| 482 | case PPC::PRED_ALWAYS: return; // Don't print anything for always. |
| 483 | case PPC::PRED_LT: O << "lt"; return; |
| 484 | case PPC::PRED_LE: O << "le"; return; |
| 485 | case PPC::PRED_EQ: O << "eq"; return; |
| 486 | case PPC::PRED_GE: O << "ge"; return; |
| 487 | case PPC::PRED_GT: O << "gt"; return; |
| 488 | case PPC::PRED_NE: O << "ne"; return; |
| 489 | case PPC::PRED_UN: O << "un"; return; |
| 490 | case PPC::PRED_NU: O << "nu"; return; |
| 491 | } |
| 492 | |
| 493 | } else { |
| 494 | assert(!strcmp(Modifier, "reg") && |
| 495 | "Need to specify 'cc' or 'reg' as predicate op modifier!"); |
| 496 | // Don't print the register for 'always'. |
| 497 | if (Code == PPC::PRED_ALWAYS) return; |
| 498 | printOperand(MI, OpNo+1); |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 503 | /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to |
| 504 | /// the current output stream. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 505 | /// |
Chris Lattner | 4c7b43b | 2005-10-14 23:37:35 +0000 | [diff] [blame] | 506 | void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) { |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 507 | ++EmittedInsts; |
Chris Lattner | 617742b | 2005-10-14 22:44:13 +0000 | [diff] [blame] | 508 | |
Nate Begeman | ad5f65c | 2005-04-05 18:19:50 +0000 | [diff] [blame] | 509 | // Check for slwi/srwi mnemonics. |
| 510 | if (MI->getOpcode() == PPC::RLWINM) { |
| 511 | bool FoundMnemonic = false; |
| 512 | unsigned char SH = MI->getOperand(2).getImmedValue(); |
| 513 | unsigned char MB = MI->getOperand(3).getImmedValue(); |
| 514 | unsigned char ME = MI->getOperand(4).getImmedValue(); |
| 515 | if (SH <= 31 && MB == 0 && ME == (31-SH)) { |
| 516 | O << "slwi "; FoundMnemonic = true; |
| 517 | } |
| 518 | if (SH <= 31 && MB == (32-SH) && ME == 31) { |
| 519 | O << "srwi "; FoundMnemonic = true; |
| 520 | SH = 32-SH; |
| 521 | } |
| 522 | if (FoundMnemonic) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 523 | printOperand(MI, 0); |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 524 | O << ", "; |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 525 | printOperand(MI, 1); |
Nate Begeman | ad5f65c | 2005-04-05 18:19:50 +0000 | [diff] [blame] | 526 | O << ", " << (unsigned int)SH << "\n"; |
| 527 | return; |
| 528 | } |
Chris Lattner | b410dc9 | 2006-06-20 23:18:58 +0000 | [diff] [blame] | 529 | } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) { |
Chris Lattner | 4d73a5a | 2006-02-08 06:56:40 +0000 | [diff] [blame] | 530 | if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) { |
| 531 | O << "mr "; |
| 532 | printOperand(MI, 0); |
| 533 | O << ", "; |
| 534 | printOperand(MI, 1); |
| 535 | O << "\n"; |
| 536 | return; |
| 537 | } |
Chris Lattner | 566c1b1 | 2006-11-18 01:23:56 +0000 | [diff] [blame] | 538 | } else if (MI->getOpcode() == PPC::RLDICR) { |
| 539 | unsigned char SH = MI->getOperand(2).getImmedValue(); |
| 540 | unsigned char ME = MI->getOperand(3).getImmedValue(); |
| 541 | // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH |
| 542 | if (63-SH == ME) { |
| 543 | O << "sldi "; |
| 544 | printOperand(MI, 0); |
| 545 | O << ", "; |
| 546 | printOperand(MI, 1); |
| 547 | O << ", " << (unsigned int)SH << "\n"; |
| 548 | return; |
| 549 | } |
Nate Begeman | ad5f65c | 2005-04-05 18:19:50 +0000 | [diff] [blame] | 550 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 551 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 552 | if (printInstruction(MI)) |
| 553 | return; // Printer was automatically generated |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 554 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 555 | assert(0 && "Unhandled instruction in asm writer!"); |
| 556 | abort(); |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 557 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 560 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 561 | /// method to print assembly for each instruction. |
| 562 | /// |
| 563 | bool LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Jim Laskey | 44c3b9f | 2007-01-26 21:22:28 +0000 | [diff] [blame] | 564 | DW.SetModuleInfo(&getAnalysis<MachineModuleInfo>()); |
Chris Lattner | 9b7ce7d | 2006-10-05 02:42:20 +0000 | [diff] [blame] | 565 | |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 566 | SetupMachineFunction(MF); |
| 567 | O << "\n\n"; |
| 568 | |
| 569 | // Print out constants referenced by the function |
| 570 | EmitConstantPool(MF.getConstantPool()); |
| 571 | |
| 572 | // Print out labels for the function. |
| 573 | const Function *F = MF.getFunction(); |
| 574 | SwitchToTextSection(getSectionForFunction(*F).c_str(), F); |
| 575 | |
| 576 | switch (F->getLinkage()) { |
| 577 | default: assert(0 && "Unknown linkage type!"); |
| 578 | case Function::InternalLinkage: // Symbols default to internal. |
| 579 | break; |
| 580 | case Function::ExternalLinkage: |
| 581 | O << "\t.global\t" << CurrentFnName << '\n' |
| 582 | << "\t.type\t" << CurrentFnName << ", @function\n"; |
| 583 | break; |
| 584 | case Function::WeakLinkage: |
| 585 | case Function::LinkOnceLinkage: |
| 586 | O << "\t.global\t" << CurrentFnName << '\n'; |
| 587 | O << "\t.weak\t" << CurrentFnName << '\n'; |
| 588 | break; |
| 589 | } |
Chris Lattner | 70d4107 | 2007-01-14 06:37:54 +0000 | [diff] [blame] | 590 | |
| 591 | if (F->hasHiddenVisibility()) |
| 592 | if (const char *Directive = TAI->getHiddenDirective()) |
| 593 | O << Directive << CurrentFnName << "\n"; |
| 594 | |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 595 | EmitAlignment(2, F); |
| 596 | O << CurrentFnName << ":\n"; |
| 597 | |
| 598 | // Emit pre-function debug information. |
| 599 | DW.BeginFunction(&MF); |
| 600 | |
| 601 | // Print out code for the function. |
| 602 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 603 | I != E; ++I) { |
| 604 | // Print a label for the basic block. |
| 605 | if (I != MF.begin()) { |
| 606 | printBasicBlockLabel(I, true); |
| 607 | O << '\n'; |
| 608 | } |
| 609 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 610 | II != E; ++II) { |
| 611 | // Print the assembly for the instruction. |
| 612 | O << "\t"; |
| 613 | printMachineInstruction(II); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << "\n"; |
| 618 | |
| 619 | // Print out jump tables referenced by the function. |
| 620 | EmitJumpTableInfo(MF.getJumpTableInfo(), MF); |
| 621 | |
| 622 | // Emit post-function debug information. |
| 623 | DW.EndFunction(); |
| 624 | |
| 625 | // We didn't modify anything. |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | bool LinuxAsmPrinter::doInitialization(Module &M) { |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 630 | bool Result = AsmPrinter::doInitialization(M); |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 631 | |
| 632 | // GNU as handles section names wrapped in quotes |
| 633 | Mang->setUseQuotes(true); |
| 634 | |
| 635 | SwitchToTextSection(TAI->getTextSection()); |
| 636 | |
| 637 | // Emit initial debug information. |
| 638 | DW.BeginModule(&M); |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 639 | return Result; |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | bool LinuxAsmPrinter::doFinalization(Module &M) { |
| 643 | const TargetData *TD = TM.getTargetData(); |
| 644 | |
| 645 | // Print out module-level global variables here. |
| 646 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 647 | I != E; ++I) { |
| 648 | if (!I->hasInitializer()) continue; // External global require no code |
| 649 | |
| 650 | // Check to see if this is a special global used by LLVM, if so, emit it. |
| 651 | if (EmitSpecialLLVMGlobal(I)) |
| 652 | continue; |
Chris Lattner | 70d4107 | 2007-01-14 06:37:54 +0000 | [diff] [blame] | 653 | |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 654 | std::string name = Mang->getValueName(I); |
Chris Lattner | 70d4107 | 2007-01-14 06:37:54 +0000 | [diff] [blame] | 655 | |
| 656 | if (I->hasHiddenVisibility()) |
| 657 | if (const char *Directive = TAI->getHiddenDirective()) |
| 658 | O << Directive << name << "\n"; |
| 659 | |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 660 | Constant *C = I->getInitializer(); |
Duncan Sands | ca0ed74 | 2007-11-05 00:04:43 +0000 | [diff] [blame] | 661 | unsigned Size = TD->getABITypeSize(C->getType()); |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 662 | unsigned Align = TD->getPreferredAlignmentLog(I); |
| 663 | |
| 664 | if (C->isNullValue() && /* FIXME: Verify correct */ |
Evan Cheng | 76a4023 | 2007-09-21 00:41:19 +0000 | [diff] [blame] | 665 | !I->hasSection() && |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 666 | (I->hasInternalLinkage() || I->hasWeakLinkage() || |
Evan Cheng | 76a4023 | 2007-09-21 00:41:19 +0000 | [diff] [blame] | 667 | I->hasLinkOnceLinkage() || I->hasExternalLinkage())) { |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 668 | if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. |
| 669 | if (I->hasExternalLinkage()) { |
| 670 | O << "\t.global " << name << '\n'; |
| 671 | O << "\t.type " << name << ", @object\n"; |
Nick Lewycky | f4c164c | 2007-11-04 17:32:10 +0000 | [diff] [blame] | 672 | if (TAI->getBSSSection()) |
| 673 | SwitchToDataSection(TAI->getBSSSection(), I); |
Nick Lewycky | e2b9052 | 2007-07-25 03:48:45 +0000 | [diff] [blame] | 674 | O << name << ":\n"; |
| 675 | O << "\t.zero " << Size << "\n"; |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 676 | } else if (I->hasInternalLinkage()) { |
| 677 | SwitchToDataSection("\t.data", I); |
| 678 | O << TAI->getLCOMMDirective() << name << "," << Size; |
| 679 | } else { |
| 680 | SwitchToDataSection("\t.data", I); |
| 681 | O << ".comm " << name << "," << Size; |
| 682 | } |
| 683 | O << "\t\t" << TAI->getCommentString() << " '" << I->getName() << "'\n"; |
| 684 | } else { |
| 685 | switch (I->getLinkage()) { |
| 686 | case GlobalValue::LinkOnceLinkage: |
| 687 | case GlobalValue::WeakLinkage: |
| 688 | O << "\t.global " << name << '\n' |
| 689 | << "\t.type " << name << ", @object\n" |
| 690 | << "\t.weak " << name << '\n'; |
| 691 | SwitchToDataSection("\t.data", I); |
| 692 | break; |
| 693 | case GlobalValue::AppendingLinkage: |
| 694 | // FIXME: appending linkage variables should go into a section of |
| 695 | // their name or something. For now, just emit them as external. |
| 696 | case GlobalValue::ExternalLinkage: |
| 697 | // If external or appending, declare as a global symbol |
| 698 | O << "\t.global " << name << "\n" |
| 699 | << "\t.type " << name << ", @object\n"; |
| 700 | // FALL THROUGH |
| 701 | case GlobalValue::InternalLinkage: |
| 702 | if (I->isConstant()) { |
| 703 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
| 704 | if (TAI->getCStringSection() && CVA && CVA->isCString()) { |
| 705 | SwitchToDataSection(TAI->getCStringSection(), I); |
| 706 | break; |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | // FIXME: special handling for ".ctors" & ".dtors" sections |
| 711 | if (I->hasSection() && |
| 712 | (I->getSection() == ".ctors" || |
| 713 | I->getSection() == ".dtors")) { |
| 714 | std::string SectionName = ".section " + I->getSection() |
| 715 | + ",\"aw\",@progbits"; |
| 716 | SwitchToDataSection(SectionName.c_str()); |
| 717 | } else { |
Evan Cheng | 032953d | 2007-03-08 08:31:54 +0000 | [diff] [blame] | 718 | if (I->isConstant() && TAI->getReadOnlySection()) |
| 719 | SwitchToDataSection(TAI->getReadOnlySection(), I); |
| 720 | else |
| 721 | SwitchToDataSection(TAI->getDataSection(), I); |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 722 | } |
| 723 | break; |
| 724 | default: |
| 725 | cerr << "Unknown linkage type!"; |
| 726 | abort(); |
| 727 | } |
| 728 | |
| 729 | EmitAlignment(Align, I); |
| 730 | O << name << ":\t\t\t\t" << TAI->getCommentString() << " '" |
| 731 | << I->getName() << "'\n"; |
| 732 | |
| 733 | // If the initializer is a extern weak symbol, remember to emit the weak |
| 734 | // reference! |
| 735 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 736 | if (GV->hasExternalWeakLinkage()) |
| 737 | ExtWeakSymbols.insert(GV); |
| 738 | |
| 739 | EmitGlobalConstant(C); |
| 740 | O << '\n'; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | // TODO |
| 745 | |
| 746 | // Emit initial debug information. |
| 747 | DW.EndModule(); |
| 748 | |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 749 | return AsmPrinter::doFinalization(M); |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | std::string LinuxAsmPrinter::getSectionForFunction(const Function &F) const { |
| 753 | switch (F.getLinkage()) { |
| 754 | default: assert(0 && "Unknown linkage type!"); |
| 755 | case Function::ExternalLinkage: |
| 756 | case Function::InternalLinkage: return TAI->getTextSection(); |
| 757 | case Function::WeakLinkage: |
| 758 | case Function::LinkOnceLinkage: |
| 759 | return ".text"; |
| 760 | } |
| 761 | } |
Chris Lattner | 9b7ce7d | 2006-10-05 02:42:20 +0000 | [diff] [blame] | 762 | |
| 763 | std::string DarwinAsmPrinter::getSectionForFunction(const Function &F) const { |
| 764 | switch (F.getLinkage()) { |
| 765 | default: assert(0 && "Unknown linkage type!"); |
| 766 | case Function::ExternalLinkage: |
| 767 | case Function::InternalLinkage: return TAI->getTextSection(); |
| 768 | case Function::WeakLinkage: |
| 769 | case Function::LinkOnceLinkage: |
| 770 | return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions"; |
| 771 | } |
| 772 | } |
| 773 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 774 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 775 | /// method to print assembly for each instruction. |
| 776 | /// |
| 777 | bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 778 | // We need this for Personality functions. |
| 779 | MMI = &getAnalysis<MachineModuleInfo>(); |
| 780 | DW.SetModuleInfo(MMI); |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 781 | |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 782 | SetupMachineFunction(MF); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 783 | O << "\n\n"; |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 784 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 785 | // Print out constants referenced by the function |
Chris Lattner | c569e61 | 2005-11-21 08:26:15 +0000 | [diff] [blame] | 786 | EmitConstantPool(MF.getConstantPool()); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 787 | |
| 788 | // Print out labels for the function. |
Chris Lattner | ac7fd7f | 2005-11-14 18:52:46 +0000 | [diff] [blame] | 789 | const Function *F = MF.getFunction(); |
Chris Lattner | 9b7ce7d | 2006-10-05 02:42:20 +0000 | [diff] [blame] | 790 | SwitchToTextSection(getSectionForFunction(*F).c_str(), F); |
Chris Lattner | b56dcc4 | 2006-10-05 00:35:50 +0000 | [diff] [blame] | 791 | |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 792 | switch (F->getLinkage()) { |
| 793 | default: assert(0 && "Unknown linkage type!"); |
| 794 | case Function::InternalLinkage: // Symbols default to internal. |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 795 | break; |
| 796 | case Function::ExternalLinkage: |
Chris Lattner | f02a916 | 2005-10-28 18:44:07 +0000 | [diff] [blame] | 797 | O << "\t.globl\t" << CurrentFnName << "\n"; |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 798 | break; |
| 799 | case Function::WeakLinkage: |
| 800 | case Function::LinkOnceLinkage: |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 801 | O << "\t.globl\t" << CurrentFnName << "\n"; |
| 802 | O << "\t.weak_definition\t" << CurrentFnName << "\n"; |
| 803 | break; |
| 804 | } |
Chris Lattner | 70d4107 | 2007-01-14 06:37:54 +0000 | [diff] [blame] | 805 | |
| 806 | if (F->hasHiddenVisibility()) |
| 807 | if (const char *Directive = TAI->getHiddenDirective()) |
| 808 | O << Directive << CurrentFnName << "\n"; |
| 809 | |
Chris Lattner | 33d5082 | 2006-02-14 20:42:33 +0000 | [diff] [blame] | 810 | EmitAlignment(4, F); |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 811 | O << CurrentFnName << ":\n"; |
| 812 | |
Jim Laskey | 6b92b8e | 2006-04-07 20:44:42 +0000 | [diff] [blame] | 813 | // Emit pre-function debug information. |
Jim Laskey | 89d67fa | 2006-06-23 12:51:53 +0000 | [diff] [blame] | 814 | DW.BeginFunction(&MF); |
Jim Laskey | 6b92b8e | 2006-04-07 20:44:42 +0000 | [diff] [blame] | 815 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 816 | // Print out code for the function. |
| 817 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 818 | I != E; ++I) { |
| 819 | // Print a label for the basic block. |
Chris Lattner | 1db1adb | 2005-08-21 19:09:33 +0000 | [diff] [blame] | 820 | if (I != MF.begin()) { |
Nate Begeman | cdf38c4 | 2006-05-02 05:37:32 +0000 | [diff] [blame] | 821 | printBasicBlockLabel(I, true); |
| 822 | O << '\n'; |
Chris Lattner | 1db1adb | 2005-08-21 19:09:33 +0000 | [diff] [blame] | 823 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 824 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 825 | II != E; ++II) { |
| 826 | // Print the assembly for the instruction. |
| 827 | O << "\t"; |
| 828 | printMachineInstruction(II); |
| 829 | } |
| 830 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 831 | |
Chris Lattner | fea13d3 | 2006-10-05 00:26:05 +0000 | [diff] [blame] | 832 | // Print out jump tables referenced by the function. |
Chris Lattner | 1da31ee | 2006-10-05 03:01:21 +0000 | [diff] [blame] | 833 | EmitJumpTableInfo(MF.getJumpTableInfo(), MF); |
Chris Lattner | fea13d3 | 2006-10-05 00:26:05 +0000 | [diff] [blame] | 834 | |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 835 | // Emit post-function debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 836 | DW.EndFunction(); |
Chris Lattner | 37dfa02 | 2006-10-05 00:24:46 +0000 | [diff] [blame] | 837 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 838 | // We didn't modify anything. |
| 839 | return false; |
| 840 | } |
| 841 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 842 | |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 843 | bool DarwinAsmPrinter::doInitialization(Module &M) { |
Jim Laskey | c35010d | 2006-12-12 20:57:08 +0000 | [diff] [blame] | 844 | static const char *CPUDirectives[] = { |
| 845 | "ppc", |
| 846 | "ppc601", |
| 847 | "ppc602", |
| 848 | "ppc603", |
| 849 | "ppc7400", |
| 850 | "ppc750", |
| 851 | "ppc970", |
| 852 | "ppc64" |
| 853 | }; |
| 854 | |
| 855 | unsigned Directive = Subtarget.getDarwinDirective(); |
| 856 | if (Subtarget.isGigaProcessor() && Directive < PPC::DIR_970) |
| 857 | Directive = PPC::DIR_970; |
| 858 | if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400) |
| 859 | Directive = PPC::DIR_7400; |
| 860 | if (Subtarget.isPPC64() && Directive < PPC::DIR_970) |
| 861 | Directive = PPC::DIR_64; |
| 862 | assert(Directive <= PPC::DIR_64 && "Directive out of range."); |
| 863 | O << "\t.machine " << CPUDirectives[Directive] << "\n"; |
Jim Laskey | 55a7ec3 | 2006-12-12 16:07:33 +0000 | [diff] [blame] | 864 | |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 865 | bool Result = AsmPrinter::doInitialization(M); |
Chris Lattner | 85eac0d | 2005-11-10 19:33:43 +0000 | [diff] [blame] | 866 | |
| 867 | // Darwin wants symbols to be quoted if they have complex names. |
| 868 | Mang->setUseQuotes(true); |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 869 | |
Jim Laskey | 2ada085 | 2006-11-28 18:21:52 +0000 | [diff] [blame] | 870 | // Prime text sections so they are adjacent. This reduces the likelihood a |
| 871 | // large data or debug section causes a branch to exceed 16M limit. |
| 872 | SwitchToTextSection(".section __TEXT,__textcoal_nt,coalesced," |
| 873 | "pure_instructions"); |
| 874 | if (TM.getRelocationModel() == Reloc::PIC_) { |
| 875 | SwitchToTextSection(".section __TEXT,__picsymbolstub1,symbol_stubs," |
| 876 | "pure_instructions,32"); |
| 877 | } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) { |
| 878 | SwitchToTextSection(".section __TEXT,__symbol_stub1,symbol_stubs," |
| 879 | "pure_instructions,16"); |
| 880 | } |
| 881 | SwitchToTextSection(TAI->getTextSection()); |
| 882 | |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 883 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 884 | DW.BeginModule(&M); |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 885 | return Result; |
Nate Begeman | 18ed029 | 2005-07-21 01:25:49 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 888 | bool DarwinAsmPrinter::doFinalization(Module &M) { |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 889 | const TargetData *TD = TM.getTargetData(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 890 | |
| 891 | // Print out module-level global variables here. |
Chris Lattner | ced704b | 2005-11-14 19:00:30 +0000 | [diff] [blame] | 892 | 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] | 893 | I != E; ++I) { |
| 894 | if (!I->hasInitializer()) continue; // External global require no code |
| 895 | |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 896 | // Check to see if this is a special global used by LLVM, if so, emit it. |
Evan Cheng | b267ca1 | 2007-01-30 08:04:53 +0000 | [diff] [blame] | 897 | if (EmitSpecialLLVMGlobal(I)) { |
| 898 | if (TM.getRelocationModel() == Reloc::Static) { |
| 899 | if (I->getName() == "llvm.global_ctors") |
| 900 | O << ".reference .constructors_used\n"; |
| 901 | else if (I->getName() == "llvm.global_dtors") |
| 902 | O << ".reference .destructors_used\n"; |
| 903 | } |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 904 | continue; |
Evan Cheng | b267ca1 | 2007-01-30 08:04:53 +0000 | [diff] [blame] | 905 | } |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 906 | |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 907 | std::string name = Mang->getValueName(I); |
Chris Lattner | 70d4107 | 2007-01-14 06:37:54 +0000 | [diff] [blame] | 908 | |
| 909 | if (I->hasHiddenVisibility()) |
| 910 | if (const char *Directive = TAI->getHiddenDirective()) |
| 911 | O << Directive << name << "\n"; |
| 912 | |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 913 | Constant *C = I->getInitializer(); |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 914 | const Type *Type = C->getType(); |
Duncan Sands | ca0ed74 | 2007-11-05 00:04:43 +0000 | [diff] [blame] | 915 | unsigned Size = TD->getABITypeSize(Type); |
Devang Patel | f9c197e | 2006-10-24 20:32:14 +0000 | [diff] [blame] | 916 | unsigned Align = TD->getPreferredAlignmentLog(I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 917 | |
| 918 | if (C->isNullValue() && /* FIXME: Verify correct */ |
Devang Patel | 0f0daea | 2007-09-20 23:07:37 +0000 | [diff] [blame] | 919 | !I->hasSection() && |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 920 | (I->hasInternalLinkage() || I->hasWeakLinkage() || |
Devang Patel | 0f0daea | 2007-09-20 23:07:37 +0000 | [diff] [blame] | 921 | I->hasLinkOnceLinkage() || I->hasExternalLinkage())) { |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 922 | if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 923 | if (I->hasExternalLinkage()) { |
| 924 | O << "\t.globl " << name << '\n'; |
| 925 | O << "\t.zerofill __DATA, __common, " << name << ", " |
| 926 | << Size << ", " << Align; |
| 927 | } else if (I->hasInternalLinkage()) { |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 928 | SwitchToDataSection("\t.data", I); |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 929 | O << TAI->getLCOMMDirective() << name << "," << Size << "," << Align; |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 930 | } else { |
Chris Lattner | 219f1b5 | 2006-05-09 16:15:00 +0000 | [diff] [blame] | 931 | SwitchToDataSection("\t.data", I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 932 | O << ".comm " << name << "," << Size; |
Chris Lattner | 0d7db6f | 2006-02-14 22:18:23 +0000 | [diff] [blame] | 933 | } |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 934 | O << "\t\t" << TAI->getCommentString() << " '" << I->getName() << "'\n"; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 935 | } else { |
| 936 | switch (I->getLinkage()) { |
Jim Laskey | 45e507c | 2006-12-01 14:37:39 +0000 | [diff] [blame] | 937 | case GlobalValue::LinkOnceLinkage: |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 938 | case GlobalValue::WeakLinkage: |
Chris Lattner | cec26fc | 2005-12-22 21:15:17 +0000 | [diff] [blame] | 939 | O << "\t.globl " << name << '\n' |
| 940 | << "\t.weak_definition " << name << '\n'; |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 941 | SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 942 | break; |
| 943 | case GlobalValue::AppendingLinkage: |
| 944 | // FIXME: appending linkage variables should go into a section of |
| 945 | // their name or something. For now, just emit them as external. |
| 946 | case GlobalValue::ExternalLinkage: |
| 947 | // If external or appending, declare as a global symbol |
| 948 | O << "\t.globl " << name << "\n"; |
| 949 | // FALL THROUGH |
| 950 | case GlobalValue::InternalLinkage: |
Evan Cheng | 31b6dda | 2006-10-28 05:56:51 +0000 | [diff] [blame] | 951 | if (I->isConstant()) { |
Evan Cheng | 80aa9a1 | 2006-10-26 21:48:57 +0000 | [diff] [blame] | 952 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
Evan Cheng | 31b6dda | 2006-10-28 05:56:51 +0000 | [diff] [blame] | 953 | if (TAI->getCStringSection() && CVA && CVA->isCString()) { |
Evan Cheng | 80aa9a1 | 2006-10-26 21:48:57 +0000 | [diff] [blame] | 954 | SwitchToDataSection(TAI->getCStringSection(), I); |
| 955 | break; |
| 956 | } |
| 957 | } |
| 958 | |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 959 | if (!I->isConstant()) |
| 960 | SwitchToDataSection(TAI->getDataSection(), I); |
| 961 | else { |
| 962 | // Read-only data. |
Evan Cheng | 032953d | 2007-03-08 08:31:54 +0000 | [diff] [blame] | 963 | bool HasReloc = C->ContainsRelocations(); |
| 964 | if (HasReloc && |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 965 | TM.getRelocationModel() != Reloc::Static) |
| 966 | SwitchToDataSection("\t.const_data\n"); |
Evan Cheng | 032953d | 2007-03-08 08:31:54 +0000 | [diff] [blame] | 967 | else if (!HasReloc && Size == 4 && |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 968 | TAI->getFourByteConstantSection()) |
| 969 | SwitchToDataSection(TAI->getFourByteConstantSection(), I); |
Evan Cheng | 032953d | 2007-03-08 08:31:54 +0000 | [diff] [blame] | 970 | else if (!HasReloc && Size == 8 && |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 971 | TAI->getEightByteConstantSection()) |
| 972 | SwitchToDataSection(TAI->getEightByteConstantSection(), I); |
Evan Cheng | 032953d | 2007-03-08 08:31:54 +0000 | [diff] [blame] | 973 | else if (!HasReloc && Size == 16 && |
Evan Cheng | 98ded76 | 2007-03-08 01:25:25 +0000 | [diff] [blame] | 974 | TAI->getSixteenByteConstantSection()) |
| 975 | SwitchToDataSection(TAI->getSixteenByteConstantSection(), I); |
| 976 | else if (TAI->getReadOnlySection()) |
| 977 | SwitchToDataSection(TAI->getReadOnlySection(), I); |
| 978 | else |
| 979 | SwitchToDataSection(TAI->getDataSection(), I); |
| 980 | } |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 981 | break; |
| 982 | default: |
Bill Wendling | f5da133 | 2006-12-07 22:21:48 +0000 | [diff] [blame] | 983 | cerr << "Unknown linkage type!"; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 984 | abort(); |
| 985 | } |
| 986 | |
| 987 | EmitAlignment(Align, I); |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 988 | O << name << ":\t\t\t\t" << TAI->getCommentString() << " '" |
| 989 | << I->getName() << "'\n"; |
Evan Cheng | 81cf60f | 2006-12-01 09:13:26 +0000 | [diff] [blame] | 990 | |
| 991 | // If the initializer is a extern weak symbol, remember to emit the weak |
| 992 | // reference! |
| 993 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 994 | if (GV->hasExternalWeakLinkage()) |
Rafael Espindola | 15404d0 | 2006-12-18 03:37:18 +0000 | [diff] [blame] | 995 | ExtWeakSymbols.insert(GV); |
Evan Cheng | 81cf60f | 2006-12-01 09:13:26 +0000 | [diff] [blame] | 996 | |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 997 | EmitGlobalConstant(C); |
Chris Lattner | bc1c215 | 2006-01-21 01:35:26 +0000 | [diff] [blame] | 998 | O << '\n'; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 1001 | |
Chris Lattner | 7e097e4 | 2006-06-27 01:02:25 +0000 | [diff] [blame] | 1002 | bool isPPC64 = TD->getPointerSizeInBits() == 64; |
| 1003 | |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 1004 | // Output stubs for dynamically-linked functions |
Chris Lattner | 35d86fe | 2006-07-26 21:12:04 +0000 | [diff] [blame] | 1005 | if (TM.getRelocationModel() == Reloc::PIC_) { |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1006 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
| 1007 | i != e; ++i) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 1008 | SwitchToTextSection(".section __TEXT,__picsymbolstub1,symbol_stubs," |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 1009 | "pure_instructions,32"); |
Chris Lattner | 7e097e4 | 2006-06-27 01:02:25 +0000 | [diff] [blame] | 1010 | EmitAlignment(4); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1011 | O << "L" << *i << "$stub:\n"; |
| 1012 | O << "\t.indirect_symbol " << *i << "\n"; |
| 1013 | O << "\tmflr r0\n"; |
| 1014 | O << "\tbcl 20,31,L0$" << *i << "\n"; |
| 1015 | O << "L0$" << *i << ":\n"; |
| 1016 | O << "\tmflr r11\n"; |
| 1017 | O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n"; |
| 1018 | O << "\tmtlr r0\n"; |
Chris Lattner | 7e097e4 | 2006-06-27 01:02:25 +0000 | [diff] [blame] | 1019 | if (isPPC64) |
| 1020 | O << "\tldu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n"; |
| 1021 | else |
| 1022 | O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n"; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1023 | O << "\tmtctr r12\n"; |
| 1024 | O << "\tbctr\n"; |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 1025 | SwitchToDataSection(".lazy_symbol_pointer"); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1026 | O << "L" << *i << "$lazy_ptr:\n"; |
| 1027 | O << "\t.indirect_symbol " << *i << "\n"; |
Chris Lattner | 7e097e4 | 2006-06-27 01:02:25 +0000 | [diff] [blame] | 1028 | if (isPPC64) |
| 1029 | O << "\t.quad dyld_stub_binding_helper\n"; |
| 1030 | else |
| 1031 | O << "\t.long dyld_stub_binding_helper\n"; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1032 | } |
| 1033 | } else { |
| 1034 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
| 1035 | i != e; ++i) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 1036 | SwitchToTextSection(".section __TEXT,__symbol_stub1,symbol_stubs," |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 1037 | "pure_instructions,16"); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1038 | EmitAlignment(4); |
| 1039 | O << "L" << *i << "$stub:\n"; |
| 1040 | O << "\t.indirect_symbol " << *i << "\n"; |
| 1041 | O << "\tlis r11,ha16(L" << *i << "$lazy_ptr)\n"; |
Chris Lattner | 7e097e4 | 2006-06-27 01:02:25 +0000 | [diff] [blame] | 1042 | if (isPPC64) |
| 1043 | O << "\tldu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n"; |
| 1044 | else |
| 1045 | O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n"; |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1046 | O << "\tmtctr r12\n"; |
| 1047 | O << "\tbctr\n"; |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 1048 | SwitchToDataSection(".lazy_symbol_pointer"); |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1049 | O << "L" << *i << "$lazy_ptr:\n"; |
| 1050 | O << "\t.indirect_symbol " << *i << "\n"; |
Chris Lattner | 7e097e4 | 2006-06-27 01:02:25 +0000 | [diff] [blame] | 1051 | if (isPPC64) |
| 1052 | O << "\t.quad dyld_stub_binding_helper\n"; |
| 1053 | else |
| 1054 | O << "\t.long dyld_stub_binding_helper\n"; |
Nate Begeman | 2497e63 | 2005-07-21 20:44:43 +0000 | [diff] [blame] | 1055 | } |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 1056 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 1057 | |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 1058 | O << "\n"; |
| 1059 | |
Dale Johannesen | 1d4ce2a | 2007-11-20 23:24:42 +0000 | [diff] [blame] | 1060 | if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) { |
| 1061 | // Add the (possibly multiple) personalities to the set of global values. |
| 1062 | const std::vector<Function *>& Personalities = MMI->getPersonalities(); |
| 1063 | |
| 1064 | for (std::vector<Function *>::const_iterator I = Personalities.begin(), |
| 1065 | E = Personalities.end(); I != E; ++I) |
| 1066 | if (*I) GVStubs.insert("_" + (*I)->getName()); |
| 1067 | } |
| 1068 | |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 1069 | // Output stubs for external and common global variables. |
Dan Gohman | cb406c2 | 2007-10-03 19:26:29 +0000 | [diff] [blame] | 1070 | if (!GVStubs.empty()) { |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 1071 | SwitchToDataSection(".non_lazy_symbol_pointer"); |
Chris Lattner | a637c32 | 2005-12-16 00:22:14 +0000 | [diff] [blame] | 1072 | for (std::set<std::string>::iterator I = GVStubs.begin(), |
| 1073 | E = GVStubs.end(); I != E; ++I) { |
| 1074 | O << "L" << *I << "$non_lazy_ptr:\n"; |
| 1075 | O << "\t.indirect_symbol " << *I << "\n"; |
Chris Lattner | 9f029a6 | 2006-06-27 20:20:53 +0000 | [diff] [blame] | 1076 | if (isPPC64) |
| 1077 | O << "\t.quad\t0\n"; |
| 1078 | else |
| 1079 | O << "\t.long\t0\n"; |
| 1080 | |
Chris Lattner | deea416 | 2005-12-13 04:33:58 +0000 | [diff] [blame] | 1081 | } |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 1082 | } |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 1083 | |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 1084 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 1085 | DW.EndModule(); |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 1086 | |
Chris Lattner | 5b0ac99 | 2005-11-01 00:12:36 +0000 | [diff] [blame] | 1087 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 1088 | // contain code that falls through to other global symbols (e.g. the obvious |
| 1089 | // implementation of multiple entry points). If this doesn't occur, the |
| 1090 | // linker can safely perform dead code stripping. Since LLVM never generates |
| 1091 | // code that does this, it is always safe to set. |
Chris Lattner | 4da1c82 | 2006-09-20 17:12:19 +0000 | [diff] [blame] | 1092 | O << "\t.subsections_via_symbols\n"; |
Chris Lattner | 5b0ac99 | 2005-11-01 00:12:36 +0000 | [diff] [blame] | 1093 | |
Dan Gohman | b8275a3 | 2007-07-25 19:33:14 +0000 | [diff] [blame] | 1094 | return AsmPrinter::doFinalization(M); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 1095 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame] | 1096 | |
Chris Lattner | 4da1c82 | 2006-09-20 17:12:19 +0000 | [diff] [blame] | 1097 | |
| 1098 | |
Jim Laskey | b608a4d | 2006-12-20 20:56:46 +0000 | [diff] [blame] | 1099 | /// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code |
| 1100 | /// for a MachineFunction to the given output stream, in a format that the |
Chris Lattner | 4da1c82 | 2006-09-20 17:12:19 +0000 | [diff] [blame] | 1101 | /// Darwin assembler can deal with. |
| 1102 | /// |
| 1103 | FunctionPass *llvm::createPPCAsmPrinterPass(std::ostream &o, |
| 1104 | PPCTargetMachine &tm) { |
Jim Laskey | bf11182 | 2006-12-21 20:26:09 +0000 | [diff] [blame] | 1105 | const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>(); |
| 1106 | |
| 1107 | if (Subtarget->isDarwin()) { |
| 1108 | return new DarwinAsmPrinter(o, tm, tm.getTargetAsmInfo()); |
| 1109 | } else { |
| 1110 | return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo()); |
| 1111 | } |
Chris Lattner | 4da1c82 | 2006-09-20 17:12:19 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |