Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1 | //===-- IA64AsmPrinter.cpp - Print out IA64 LLVM as assembly --------------===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Duraid Madina and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 7 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to assembly accepted by the GNU binutils 'gas' |
| 12 | // assembler. The Intel 'ias' and HP-UX 'as' assemblers *may* choke on this |
| 13 | // output, but if so that's a bug I'd like to hear about: please file a bug |
Duraid Madina | f2db9b8 | 2005-10-28 17:46:35 +0000 | [diff] [blame] | 14 | // report in bugzilla. FYI, the not too bad 'ias' assembler is bundled with |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 15 | // the Intel C/C++ compiler for Itanium Linux. |
| 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | #include "IA64.h" |
| 20 | #include "IA64TargetMachine.h" |
| 21 | #include "llvm/Module.h" |
Chris Lattner | 3c61f70 | 2005-03-24 05:12:48 +0000 | [diff] [blame] | 22 | #include "llvm/Type.h" |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 23 | #include "llvm/Assembly/Writer.h" |
| 24 | #include "llvm/CodeGen/AsmPrinter.h" |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 26 | #include "llvm/CodeGen/ValueTypes.h" |
| 27 | #include "llvm/Target/TargetMachine.h" |
| 28 | #include "llvm/Support/Mangler.h" |
| 29 | #include "llvm/ADT/Statistic.h" |
| 30 | #include "llvm/Support/CommandLine.h" |
| 31 | using namespace llvm; |
| 32 | |
| 33 | namespace { |
| 34 | Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); |
| 35 | |
| 36 | struct IA64SharedAsmPrinter : public AsmPrinter { |
| 37 | |
Duraid Madina | ae8bd73 | 2005-03-28 15:21:43 +0000 | [diff] [blame] | 38 | std::set<std::string> ExternalFunctionNames, ExternalObjectNames; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 39 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 40 | IA64SharedAsmPrinter(std::ostream &O, TargetMachine &TM) |
| 41 | : AsmPrinter(O, TM) { } |
| 42 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 43 | bool doFinalization(Module &M); |
| 44 | }; |
| 45 | } |
| 46 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 47 | bool IA64SharedAsmPrinter::doFinalization(Module &M) { |
| 48 | const TargetData &TD = TM.getTargetData(); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 49 | |
| 50 | // Print out module-level global variables here. |
Alkis Evlogimenos | 12cf385 | 2005-03-19 09:22:17 +0000 | [diff] [blame] | 51 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 52 | I != E; ++I) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 53 | if (I->hasInitializer()) { // External global require no code |
| 54 | O << "\n\n"; |
| 55 | std::string name = Mang->getValueName(I); |
| 56 | Constant *C = I->getInitializer(); |
| 57 | unsigned Size = TD.getTypeSize(C->getType()); |
| 58 | unsigned Align = TD.getTypeAlignmentShift(C->getType()); |
| 59 | |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 60 | if (C->isNullValue() && |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 61 | (I->hasLinkOnceLinkage() || I->hasInternalLinkage() || |
| 62 | I->hasWeakLinkage() /* FIXME: Verify correct */)) { |
Chris Lattner | 4bfa3a3 | 2005-11-21 07:26:04 +0000 | [diff] [blame] | 63 | SwitchSection(".data", I); |
Duraid Madina | 1f867b1 | 2005-03-31 07:40:24 +0000 | [diff] [blame] | 64 | if (I->hasInternalLinkage()) { |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 65 | O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType()) |
| 66 | << "," << (1 << Align); |
| 67 | O << "\t\t// "; |
| 68 | } else { |
| 69 | O << "\t.common " << name << "," << TD.getTypeSize(C->getType()) |
| 70 | << "," << (1 << Align); |
| 71 | O << "\t\t// "; |
| 72 | } |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 73 | WriteAsOperand(O, I, true, true, &M); |
| 74 | O << "\n"; |
| 75 | } else { |
| 76 | switch (I->getLinkage()) { |
| 77 | case GlobalValue::LinkOnceLinkage: |
| 78 | case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. |
| 79 | // Nonnull linkonce -> weak |
| 80 | O << "\t.weak " << name << "\n"; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 81 | O << "\t.section\t.llvm.linkonce.d." << name |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 82 | << ", \"aw\", \"progbits\"\n"; |
Chris Lattner | 4bfa3a3 | 2005-11-21 07:26:04 +0000 | [diff] [blame] | 83 | SwitchSection("", I); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 84 | break; |
| 85 | case GlobalValue::AppendingLinkage: |
| 86 | // FIXME: appending linkage variables should go into a section of |
| 87 | // their name or something. For now, just emit them as external. |
| 88 | case GlobalValue::ExternalLinkage: |
| 89 | // If external or appending, declare as a global symbol |
| 90 | O << "\t.global " << name << "\n"; |
| 91 | // FALL THROUGH |
| 92 | case GlobalValue::InternalLinkage: |
Chris Lattner | 4bfa3a3 | 2005-11-21 07:26:04 +0000 | [diff] [blame] | 93 | SwitchSection(C->isNullValue() ? ".bss" : ".data", I); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 94 | break; |
| 95 | case GlobalValue::GhostLinkage: |
| 96 | std::cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n"; |
| 97 | abort(); |
| 98 | } |
| 99 | |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 100 | EmitAlignment(Align); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 101 | O << "\t.type " << name << ",@object\n"; |
| 102 | O << "\t.size " << name << "," << Size << "\n"; |
| 103 | O << name << ":\t\t\t\t// "; |
| 104 | WriteAsOperand(O, I, true, true, &M); |
| 105 | O << " = "; |
| 106 | WriteAsOperand(O, C, false, false, &M); |
| 107 | O << "\n"; |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 108 | EmitGlobalConstant(C); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
| 112 | // we print out ".global X \n .type X, @function" for each external function |
| 113 | O << "\n\n// br.call targets referenced (and not defined) above: \n"; |
| 114 | for (std::set<std::string>::iterator i = ExternalFunctionNames.begin(), |
| 115 | e = ExternalFunctionNames.end(); i!=e; ++i) { |
| 116 | O << "\t.global " << *i << "\n\t.type " << *i << ", @function\n"; |
| 117 | } |
| 118 | O << "\n\n"; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 119 | |
Duraid Madina | ae8bd73 | 2005-03-28 15:21:43 +0000 | [diff] [blame] | 120 | // we print out ".global X \n .type X, @object" for each external object |
| 121 | O << "\n\n// (external) symbols referenced (and not defined) above: \n"; |
| 122 | for (std::set<std::string>::iterator i = ExternalObjectNames.begin(), |
| 123 | e = ExternalObjectNames.end(); i!=e; ++i) { |
| 124 | O << "\t.global " << *i << "\n\t.type " << *i << ", @object\n"; |
| 125 | } |
| 126 | O << "\n\n"; |
| 127 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 128 | AsmPrinter::doFinalization(M); |
| 129 | return false; // success |
| 130 | } |
| 131 | |
| 132 | namespace { |
| 133 | struct IA64AsmPrinter : public IA64SharedAsmPrinter { |
| 134 | IA64AsmPrinter(std::ostream &O, TargetMachine &TM) |
| 135 | : IA64SharedAsmPrinter(O, TM) { |
| 136 | |
| 137 | CommentString = "//"; |
Duraid Madina | 32c46f3 | 2005-04-02 12:30:47 +0000 | [diff] [blame] | 138 | Data8bitsDirective = "\tdata1\t"; // FIXME: check that we are |
| 139 | Data16bitsDirective = "\tdata2.ua\t"; // disabling auto-alignment |
| 140 | Data32bitsDirective = "\tdata4.ua\t"; // properly |
| 141 | Data64bitsDirective = "\tdata8.ua\t"; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 142 | ZeroDirective = "\t.skip\t"; |
| 143 | AsciiDirective = "\tstring\t"; |
| 144 | |
Duraid Madina | 32c46f3 | 2005-04-02 12:30:47 +0000 | [diff] [blame] | 145 | GlobalVarAddrPrefix=""; |
| 146 | GlobalVarAddrSuffix=""; |
| 147 | FunctionAddrPrefix="@fptr("; |
| 148 | FunctionAddrSuffix=")"; |
Chris Lattner | 3dfbe2e | 2005-11-21 08:38:26 +0000 | [diff] [blame^] | 149 | |
| 150 | // FIXME: would be nice to have rodata (no 'w') when appropriate? |
| 151 | ConstantPoolSection = "\n\t.section .data, \"aw\", \"progbits\"\n"; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | virtual const char *getPassName() const { |
| 155 | return "IA64 Assembly Printer"; |
| 156 | } |
| 157 | |
| 158 | /// printInstruction - This method is automatically generated by tablegen |
| 159 | /// from the instruction set description. This method returns true if the |
| 160 | /// machine instruction was sufficiently described to print it, otherwise it |
| 161 | /// returns false. |
| 162 | bool printInstruction(const MachineInstr *MI); |
| 163 | |
| 164 | // This method is used by the tablegen'erated instruction printer. |
| 165 | void printOperand(const MachineInstr *MI, unsigned OpNo, MVT::ValueType VT){ |
| 166 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 167 | if (MO.getType() == MachineOperand::MO_MachineRegister) { |
| 168 | assert(MRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physref??"); |
| 169 | //XXX Bug Workaround: See note in Printer::doInitialization about %. |
| 170 | O << TM.getRegisterInfo()->get(MO.getReg()).Name; |
| 171 | } else { |
| 172 | printOp(MO); |
| 173 | } |
| 174 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 175 | |
Duraid Madina | e6a0b6c | 2005-04-07 12:34:36 +0000 | [diff] [blame] | 176 | void printS8ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 177 | MVT::ValueType VT) { |
| 178 | int val=(unsigned int)MI->getOperand(OpNo).getImmedValue(); |
| 179 | if(val>=128) val=val-256; // if negative, flip sign |
| 180 | O << val; |
| 181 | } |
| 182 | void printS14ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 183 | MVT::ValueType VT) { |
| 184 | int val=(unsigned int)MI->getOperand(OpNo).getImmedValue(); |
| 185 | if(val>=8192) val=val-16384; // if negative, flip sign |
| 186 | O << val; |
| 187 | } |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 188 | void printS22ImmOperand(const MachineInstr *MI, unsigned OpNo, |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 189 | MVT::ValueType VT) { |
Duraid Madina | 5ef2ec9 | 2005-04-11 05:55:56 +0000 | [diff] [blame] | 190 | int val=(unsigned int)MI->getOperand(OpNo).getImmedValue(); |
| 191 | if(val>=2097152) val=val-4194304; // if negative, flip sign |
| 192 | O << val; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 193 | } |
| 194 | void printU64ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 195 | MVT::ValueType VT) { |
| 196 | O << (uint64_t)MI->getOperand(OpNo).getImmedValue(); |
| 197 | } |
Duraid Madina | 1ce0c01 | 2005-04-14 10:08:01 +0000 | [diff] [blame] | 198 | void printS64ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 199 | MVT::ValueType VT) { |
Duraid Madina | f2db9b8 | 2005-10-28 17:46:35 +0000 | [diff] [blame] | 200 | // XXX : nasty hack to avoid GPREL22 "relocation truncated to fit" linker |
| 201 | // errors - instead of add rX = @gprel(CPI<whatever>), r1;; we now |
| 202 | // emit movl rX = @gprel(CPI<whatever);; |
| 203 | // add rX = rX, r1; |
| 204 | // this gives us 64 bits instead of 22 (for the add long imm) to play |
| 205 | // with, which shuts up the linker. The problem is that the constant |
| 206 | // pool entries aren't immediates at this stage, so we check here. |
| 207 | // If it's an immediate, print it the old fashioned way. If it's |
| 208 | // not, we print it as a constant pool index. |
| 209 | if(MI->getOperand(OpNo).isImmediate()) { |
| 210 | O << (int64_t)MI->getOperand(OpNo).getImmedValue(); |
| 211 | } else { // this is a constant pool reference: FIXME: assert this |
| 212 | printOp(MI->getOperand(OpNo)); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void printGlobalOperand(const MachineInstr *MI, unsigned OpNo, |
| 217 | MVT::ValueType VT) { |
| 218 | printOp(MI->getOperand(OpNo), false); // this is NOT a br.call instruction |
Duraid Madina | 1ce0c01 | 2005-04-14 10:08:01 +0000 | [diff] [blame] | 219 | } |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 220 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 221 | void printCallOperand(const MachineInstr *MI, unsigned OpNo, |
| 222 | MVT::ValueType VT) { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 223 | printOp(MI->getOperand(OpNo), true); // this is a br.call instruction |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void printMachineInstruction(const MachineInstr *MI); |
| 227 | void printOp(const MachineOperand &MO, bool isBRCALLinsn= false); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 228 | bool runOnMachineFunction(MachineFunction &F); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 229 | bool doInitialization(Module &M); |
| 230 | }; |
| 231 | } // end of anonymous namespace |
| 232 | |
| 233 | |
| 234 | // Include the auto-generated portion of the assembly writer. |
| 235 | #include "IA64GenAsmWriter.inc" |
| 236 | |
| 237 | |
| 238 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 239 | /// method to print assembly for each instruction. |
| 240 | /// |
| 241 | bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 242 | SetupMachineFunction(MF); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 243 | O << "\n\n"; |
| 244 | |
| 245 | // Print out constants referenced by the function |
Chris Lattner | 3dfbe2e | 2005-11-21 08:38:26 +0000 | [diff] [blame^] | 246 | EmitConstantPool(MF.getConstantPool()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 247 | |
| 248 | // Print out labels for the function. |
Chris Lattner | 4bfa3a3 | 2005-11-21 07:26:04 +0000 | [diff] [blame] | 249 | SwitchSection("\n\t.section .text, \"ax\", \"progbits\"\n", MF.getFunction()); |
| 250 | // ^^ means "Allocated instruXions in mem, initialized" |
Chris Lattner | 8b8b951 | 2005-11-21 07:51:23 +0000 | [diff] [blame] | 251 | EmitAlignment(5); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 252 | O << "\t.global\t" << CurrentFnName << "\n"; |
| 253 | O << "\t.type\t" << CurrentFnName << ", @function\n"; |
| 254 | O << CurrentFnName << ":\n"; |
| 255 | |
| 256 | // Print out code for the function. |
| 257 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 258 | I != E; ++I) { |
| 259 | // Print a label for the basic block if there are any predecessors. |
| 260 | if (I->pred_begin() != I->pred_end()) |
Chris Lattner | 2ec30b5 | 2005-11-21 07:39:22 +0000 | [diff] [blame] | 261 | O << PrivateGlobalPrefix << "LBB" << CurrentFnName << "_" |
| 262 | << I->getNumber() << ":\t" |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 263 | << CommentString << " " << I->getBasicBlock()->getName() << "\n"; |
| 264 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 265 | II != E; ++II) { |
| 266 | // Print the assembly for the instruction. |
| 267 | O << "\t"; |
| 268 | printMachineInstruction(II); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // We didn't modify anything. |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | void IA64AsmPrinter::printOp(const MachineOperand &MO, |
| 277 | bool isBRCALLinsn /* = false */) { |
| 278 | const MRegisterInfo &RI = *TM.getRegisterInfo(); |
| 279 | switch (MO.getType()) { |
| 280 | case MachineOperand::MO_VirtualRegister: |
| 281 | if (Value *V = MO.getVRegValueOrNull()) { |
| 282 | O << "<" << V->getName() << ">"; |
| 283 | return; |
| 284 | } |
| 285 | // FALLTHROUGH |
| 286 | case MachineOperand::MO_MachineRegister: |
| 287 | case MachineOperand::MO_CCRegister: { |
| 288 | O << RI.get(MO.getReg()).Name; |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | case MachineOperand::MO_SignExtendedImmed: |
| 293 | case MachineOperand::MO_UnextendedImmed: |
| 294 | O << /*(unsigned int)*/MO.getImmedValue(); |
| 295 | return; |
| 296 | case MachineOperand::MO_MachineBasicBlock: { |
| 297 | MachineBasicBlock *MBBOp = MO.getMachineBasicBlock(); |
Chris Lattner | 2ec30b5 | 2005-11-21 07:39:22 +0000 | [diff] [blame] | 298 | O << PrivateGlobalPrefix << "LBB" |
| 299 | << Mang->getValueName(MBBOp->getParent()->getFunction()) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 300 | << "_" << MBBOp->getNumber () << "\t// " |
| 301 | << MBBOp->getBasicBlock ()->getName (); |
| 302 | return; |
| 303 | } |
| 304 | case MachineOperand::MO_PCRelativeDisp: |
| 305 | std::cerr << "Shouldn't use addPCDisp() when building IA64 MachineInstrs"; |
| 306 | abort (); |
| 307 | return; |
| 308 | |
| 309 | case MachineOperand::MO_ConstantPoolIndex: { |
Chris Lattner | 3dfbe2e | 2005-11-21 08:38:26 +0000 | [diff] [blame^] | 310 | O << "@gprel(" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 311 | << MO.getConstantPoolIndex() << ")"; |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | case MachineOperand::MO_GlobalAddress: { |
| 316 | |
| 317 | // functions need @ltoff(@fptr(fn_name)) form |
| 318 | GlobalValue *GV = MO.getGlobal(); |
| 319 | Function *F = dyn_cast<Function>(GV); |
| 320 | |
| 321 | bool Needfptr=false; // if we're computing an address @ltoff(X), do |
| 322 | // we need to decorate it so it becomes |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 323 | // @ltoff(@fptr(X)) ? |
| 324 | if (F && !isBRCALLinsn /*&& F->isExternal()*/) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 325 | Needfptr=true; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 326 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 327 | // if this is the target of a call instruction, we should define |
| 328 | // the function somewhere (GNU gas has no problem without this, but |
| 329 | // Intel ias rightly complains of an 'undefined symbol') |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 330 | |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 331 | if (F /*&& isBRCALLinsn*/ && F->isExternal()) |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 332 | ExternalFunctionNames.insert(Mang->getValueName(MO.getGlobal())); |
Duraid Madina | ae8bd73 | 2005-03-28 15:21:43 +0000 | [diff] [blame] | 333 | else |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 334 | if (GV->isExternal()) // e.g. stuff like 'stdin' |
| 335 | ExternalObjectNames.insert(Mang->getValueName(MO.getGlobal())); |
Duraid Madina | ae8bd73 | 2005-03-28 15:21:43 +0000 | [diff] [blame] | 336 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 337 | if (!isBRCALLinsn) |
| 338 | O << "@ltoff("; |
| 339 | if (Needfptr) |
| 340 | O << "@fptr("; |
| 341 | O << Mang->getValueName(MO.getGlobal()); |
| 342 | if (Needfptr) |
| 343 | O << ")"; // close fptr( |
| 344 | if (!isBRCALLinsn) |
| 345 | O << ")"; // close ltoff( |
| 346 | int Offset = MO.getOffset(); |
| 347 | if (Offset > 0) |
| 348 | O << " + " << Offset; |
| 349 | else if (Offset < 0) |
| 350 | O << " - " << -Offset; |
| 351 | return; |
| 352 | } |
| 353 | case MachineOperand::MO_ExternalSymbol: |
| 354 | O << MO.getSymbolName(); |
Duraid Madina | ae8bd73 | 2005-03-28 15:21:43 +0000 | [diff] [blame] | 355 | ExternalFunctionNames.insert(MO.getSymbolName()); |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 356 | return; |
| 357 | default: |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 358 | O << "<AsmPrinter: unknown operand type: " << MO.getType() << " >"; return; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | /// printMachineInstruction -- Print out a single IA64 LLVM instruction |
| 363 | /// MI to the current output stream. |
| 364 | /// |
| 365 | void IA64AsmPrinter::printMachineInstruction(const MachineInstr *MI) { |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 366 | ++EmittedInsts; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 367 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 368 | // Call the autogenerated instruction printer routines. |
| 369 | printInstruction(MI); |
| 370 | } |
| 371 | |
| 372 | bool IA64AsmPrinter::doInitialization(Module &M) { |
| 373 | AsmPrinter::doInitialization(M); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 374 | |
Duraid Madina | ae8bd73 | 2005-03-28 15:21:43 +0000 | [diff] [blame] | 375 | O << "\n.ident \"LLVM-ia64\"\n\n" |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 376 | << "\t.psr lsb\n" // should be "msb" on HP-UX, for starters |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 377 | << "\t.radix C\n" |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 378 | << "\t.psr abi64\n"; // we only support 64 bits for now |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 379 | return false; |
| 380 | } |
| 381 | |
| 382 | /// createIA64CodePrinterPass - Returns a pass that prints the IA64 |
| 383 | /// assembly code for a MachineFunction to the given output stream, using |
| 384 | /// the given target machine description. |
| 385 | /// |
| 386 | FunctionPass *llvm::createIA64CodePrinterPass(std::ostream &o,TargetMachine &tm){ |
| 387 | return new IA64AsmPrinter(o, tm); |
| 388 | } |
| 389 | |
| 390 | |