blob: 567e04c4b150a6bc9a3aebb6aa08d46905d6b04f [file] [log] [blame]
Duraid Madina9b9d45f2005-03-17 18:17:03 +00001//===-- IA64AsmPrinter.cpp - Print out IA64 LLVM as assembly --------------===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Duraid Madina9b9d45f2005-03-17 18:17:03 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Duraid Madina9b9d45f2005-03-17 18:17:03 +00008//===----------------------------------------------------------------------===//
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 Madinaf2db9b82005-10-28 17:46:35 +000014// report in bugzilla. FYI, the not too bad 'ias' assembler is bundled with
Duraid Madina9b9d45f2005-03-17 18:17:03 +000015// the Intel C/C++ compiler for Itanium Linux.
16//
17//===----------------------------------------------------------------------===//
18
Chris Lattner95b2c7d2006-12-19 22:59:26 +000019#define DEBUG_TYPE "asm-printer"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000020#include "IA64.h"
21#include "IA64TargetMachine.h"
22#include "llvm/Module.h"
Chris Lattner3c61f702005-03-24 05:12:48 +000023#include "llvm/Type.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000024#include "llvm/CodeGen/AsmPrinter.h"
Bill Wendlingcb819f12009-02-18 23:12:06 +000025#include "llvm/CodeGen/DwarfWriter.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000026#include "llvm/CodeGen/MachineFunctionPass.h"
Jim Laskey563321a2006-09-06 18:34:40 +000027#include "llvm/Target/TargetAsmInfo.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000028#include "llvm/Target/TargetMachine.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000029#include "llvm/Support/Mangler.h"
Owen Andersoncb371882008-08-21 00:14:44 +000030#include "llvm/Support/raw_ostream.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000031#include "llvm/ADT/Statistic.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000032using namespace llvm;
33
Chris Lattner95b2c7d2006-12-19 22:59:26 +000034STATISTIC(EmittedInsts, "Number of machine instrs printed");
35
Duraid Madina9b9d45f2005-03-17 18:17:03 +000036namespace {
Jim Laskey563321a2006-09-06 18:34:40 +000037 struct IA64AsmPrinter : public AsmPrinter {
38 std::set<std::string> ExternalFunctionNames, ExternalObjectNames;
39
Owen Andersoncb371882008-08-21 00:14:44 +000040 IA64AsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
Jim Laskey563321a2006-09-06 18:34:40 +000041 : AsmPrinter(O, TM, T) {
42 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +000043
44 virtual const char *getPassName() const {
45 return "IA64 Assembly Printer";
46 }
47
48 /// printInstruction - This method is automatically generated by tablegen
49 /// from the instruction set description. This method returns true if the
50 /// machine instruction was sufficiently described to print it, otherwise it
51 /// returns false.
52 bool printInstruction(const MachineInstr *MI);
53
54 // This method is used by the tablegen'erated instruction printer.
Nate Begeman391c5d22005-11-30 18:54:35 +000055 void printOperand(const MachineInstr *MI, unsigned OpNo){
Duraid Madina9b9d45f2005-03-17 18:17:03 +000056 const MachineOperand &MO = MI->getOperand(OpNo);
Chris Lattner2d90ac72006-05-04 18:05:43 +000057 if (MO.getType() == MachineOperand::MO_Register) {
Dan Gohman6f0d0242008-02-10 18:45:23 +000058 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
59 "Not physref??");
Duraid Madina9b9d45f2005-03-17 18:17:03 +000060 //XXX Bug Workaround: See note in Printer::doInitialization about %.
Bill Wendling74ab84c2008-02-26 21:11:01 +000061 O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
Duraid Madina9b9d45f2005-03-17 18:17:03 +000062 } else {
63 printOp(MO);
64 }
65 }
Misha Brukman4633f1c2005-04-21 23:13:11 +000066
Nate Begeman391c5d22005-11-30 18:54:35 +000067 void printS8ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000068 int val=(unsigned int)MI->getOperand(OpNo).getImm();
Duraid Madinae6a0b6c2005-04-07 12:34:36 +000069 if(val>=128) val=val-256; // if negative, flip sign
70 O << val;
71 }
Nate Begeman391c5d22005-11-30 18:54:35 +000072 void printS14ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000073 int val=(unsigned int)MI->getOperand(OpNo).getImm();
Duraid Madinae6a0b6c2005-04-07 12:34:36 +000074 if(val>=8192) val=val-16384; // if negative, flip sign
75 O << val;
76 }
Nate Begeman391c5d22005-11-30 18:54:35 +000077 void printS22ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000078 int val=(unsigned int)MI->getOperand(OpNo).getImm();
Duraid Madina5ef2ec92005-04-11 05:55:56 +000079 if(val>=2097152) val=val-4194304; // if negative, flip sign
80 O << val;
Duraid Madina9b9d45f2005-03-17 18:17:03 +000081 }
Nate Begeman391c5d22005-11-30 18:54:35 +000082 void printU64ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000083 O << (uint64_t)MI->getOperand(OpNo).getImm();
Duraid Madina9b9d45f2005-03-17 18:17:03 +000084 }
Nate Begeman391c5d22005-11-30 18:54:35 +000085 void printS64ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Duraid Madinaf2db9b82005-10-28 17:46:35 +000086// XXX : nasty hack to avoid GPREL22 "relocation truncated to fit" linker
87// errors - instead of add rX = @gprel(CPI<whatever>), r1;; we now
88// emit movl rX = @gprel(CPI<whatever);;
Anton Korobeynikov003bcab2008-08-07 09:52:13 +000089// add rX = rX, r1;
Duraid Madinaf2db9b82005-10-28 17:46:35 +000090// this gives us 64 bits instead of 22 (for the add long imm) to play
91// with, which shuts up the linker. The problem is that the constant
Anton Korobeynikov003bcab2008-08-07 09:52:13 +000092// pool entries aren't immediates at this stage, so we check here.
Duraid Madinaf2db9b82005-10-28 17:46:35 +000093// If it's an immediate, print it the old fashioned way. If it's
Anton Korobeynikov003bcab2008-08-07 09:52:13 +000094// not, we print it as a constant pool index.
Dan Gohmand735b802008-10-03 15:45:36 +000095 if (MI->getOperand(OpNo).isImm()) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000096 O << (int64_t)MI->getOperand(OpNo).getImm();
Duraid Madinaf2db9b82005-10-28 17:46:35 +000097 } else { // this is a constant pool reference: FIXME: assert this
98 printOp(MI->getOperand(OpNo));
99 }
100 }
101
Nate Begeman391c5d22005-11-30 18:54:35 +0000102 void printGlobalOperand(const MachineInstr *MI, unsigned OpNo) {
Duraid Madinaf2db9b82005-10-28 17:46:35 +0000103 printOp(MI->getOperand(OpNo), false); // this is NOT a br.call instruction
Duraid Madina1ce0c012005-04-14 10:08:01 +0000104 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000105
Nate Begeman391c5d22005-11-30 18:54:35 +0000106 void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000107 printOp(MI->getOperand(OpNo), true); // this is a br.call instruction
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000108 }
109
110 void printMachineInstruction(const MachineInstr *MI);
111 void printOp(const MachineOperand &MO, bool isBRCALLinsn= false);
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000112 void printModuleLevelGV(const GlobalVariable* GVar);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000113 bool runOnMachineFunction(MachineFunction &F);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000114 bool doInitialization(Module &M);
Chris Lattner42a76cd2005-11-21 08:40:17 +0000115 bool doFinalization(Module &M);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000116 };
117} // end of anonymous namespace
118
119
120// Include the auto-generated portion of the assembly writer.
121#include "IA64GenAsmWriter.inc"
122
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000123/// runOnMachineFunction - This uses the printMachineInstruction()
124/// method to print assembly for each instruction.
125///
126bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Chris Lattner8b8b9512005-11-21 07:51:23 +0000127 SetupMachineFunction(MF);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000128 O << "\n\n";
129
130 // Print out constants referenced by the function
Chris Lattner3dfbe2e2005-11-21 08:38:26 +0000131 EmitConstantPool(MF.getConstantPool());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000132
Chris Lattneredad2b72006-10-05 02:51:36 +0000133 const Function *F = MF.getFunction();
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000134 SwitchToSection(TAI->SectionForGlobal(F));
Chris Lattneredad2b72006-10-05 02:51:36 +0000135
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000136 // Print out labels for the function.
Chris Lattner8b8b9512005-11-21 07:51:23 +0000137 EmitAlignment(5);
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000138 O << "\t.global\t" << CurrentFnName << '\n';
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000139
140 printVisibility(CurrentFnName, F->getVisibility());
141
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000142 O << "\t.type\t" << CurrentFnName << ", @function\n";
143 O << CurrentFnName << ":\n";
144
145 // Print out code for the function.
146 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
147 I != E; ++I) {
148 // Print a label for the basic block if there are any predecessors.
Dan Gohmancb406c22007-10-03 19:26:29 +0000149 if (!I->pred_empty()) {
Evan Chengfb8075d2008-02-28 00:43:03 +0000150 printBasicBlockLabel(I, true, true);
Nate Begemancdf38c42006-05-02 05:37:32 +0000151 O << '\n';
152 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000153 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
154 II != E; ++II) {
155 // Print the assembly for the instruction.
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000156 printMachineInstruction(II);
157 }
158 }
159
160 // We didn't modify anything.
161 return false;
162}
163
164void IA64AsmPrinter::printOp(const MachineOperand &MO,
Chris Lattner63b3d712006-05-04 17:21:20 +0000165 bool isBRCALLinsn /* = false */) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000166 const TargetRegisterInfo &RI = *TM.getRegisterInfo();
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000167 switch (MO.getType()) {
Chris Lattner2d90ac72006-05-04 18:05:43 +0000168 case MachineOperand::MO_Register:
Bill Wendling74ab84c2008-02-26 21:11:01 +0000169 O << RI.get(MO.getReg()).AsmName;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000170 return;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000171
Chris Lattner63b3d712006-05-04 17:21:20 +0000172 case MachineOperand::MO_Immediate:
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000173 O << MO.getImm();
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000174 return;
Nate Begeman37efe672006-04-22 18:53:45 +0000175 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000176 printBasicBlockLabel(MO.getMBB());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000177 return;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000178 case MachineOperand::MO_ConstantPoolIndex: {
Jim Laskey563321a2006-09-06 18:34:40 +0000179 O << "@gprel(" << TAI->getPrivateGlobalPrefix()
Chris Lattner8aa797a2007-12-30 23:10:15 +0000180 << "CPI" << getFunctionNumber() << "_" << MO.getIndex() << ")";
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000181 return;
182 }
183
184 case MachineOperand::MO_GlobalAddress: {
185
186 // functions need @ltoff(@fptr(fn_name)) form
187 GlobalValue *GV = MO.getGlobal();
188 Function *F = dyn_cast<Function>(GV);
189
190 bool Needfptr=false; // if we're computing an address @ltoff(X), do
191 // we need to decorate it so it becomes
Misha Brukman7847fca2005-04-22 17:54:37 +0000192 // @ltoff(@fptr(X)) ?
Reid Spencer5cbf9852007-01-30 20:08:39 +0000193 if (F && !isBRCALLinsn /*&& F->isDeclaration()*/)
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000194 Needfptr=true;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000195
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000196 // if this is the target of a call instruction, we should define
197 // the function somewhere (GNU gas has no problem without this, but
198 // Intel ias rightly complains of an 'undefined symbol')
Misha Brukman4633f1c2005-04-21 23:13:11 +0000199
Reid Spencer5cbf9852007-01-30 20:08:39 +0000200 if (F /*&& isBRCALLinsn*/ && F->isDeclaration())
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000201 ExternalFunctionNames.insert(Mang->getValueName(MO.getGlobal()));
Duraid Madinaae8bd732005-03-28 15:21:43 +0000202 else
Reid Spencer5cbf9852007-01-30 20:08:39 +0000203 if (GV->isDeclaration()) // e.g. stuff like 'stdin'
Misha Brukman7847fca2005-04-22 17:54:37 +0000204 ExternalObjectNames.insert(Mang->getValueName(MO.getGlobal()));
Duraid Madinaae8bd732005-03-28 15:21:43 +0000205
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000206 if (!isBRCALLinsn)
207 O << "@ltoff(";
208 if (Needfptr)
209 O << "@fptr(";
210 O << Mang->getValueName(MO.getGlobal());
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000211
Duraid Madina00d3d442006-02-16 13:12:57 +0000212 if (Needfptr && !isBRCALLinsn)
213 O << "#))"; // close both fptr( and ltoff(
214 else {
215 if (Needfptr)
216 O << "#)"; // close only fptr(
217 if (!isBRCALLinsn)
218 O << "#)"; // close only ltoff(
219 }
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000220
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000221 int Offset = MO.getOffset();
222 if (Offset > 0)
223 O << " + " << Offset;
224 else if (Offset < 0)
225 O << " - " << -Offset;
226 return;
227 }
228 case MachineOperand::MO_ExternalSymbol:
229 O << MO.getSymbolName();
Duraid Madinaae8bd732005-03-28 15:21:43 +0000230 ExternalFunctionNames.insert(MO.getSymbolName());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000231 return;
232 default:
Misha Brukman4633f1c2005-04-21 23:13:11 +0000233 O << "<AsmPrinter: unknown operand type: " << MO.getType() << " >"; return;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000234 }
235}
236
237/// printMachineInstruction -- Print out a single IA64 LLVM instruction
238/// MI to the current output stream.
239///
240void IA64AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000241 ++EmittedInsts;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000242
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000243 // Call the autogenerated instruction printer routines.
244 printInstruction(MI);
245}
246
247bool IA64AsmPrinter::doInitialization(Module &M) {
Dan Gohmanb8275a32007-07-25 19:33:14 +0000248 bool Result = AsmPrinter::doInitialization(M);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000249
Duraid Madinaae8bd732005-03-28 15:21:43 +0000250 O << "\n.ident \"LLVM-ia64\"\n\n"
Misha Brukman7847fca2005-04-22 17:54:37 +0000251 << "\t.psr lsb\n" // should be "msb" on HP-UX, for starters
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000252 << "\t.radix C\n"
Misha Brukman7847fca2005-04-22 17:54:37 +0000253 << "\t.psr abi64\n"; // we only support 64 bits for now
Dan Gohmanb8275a32007-07-25 19:33:14 +0000254 return Result;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000255}
256
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000257void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
Owen Andersona69571c2006-05-03 01:29:57 +0000258 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000259
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000260 if (!GVar->hasInitializer())
261 return; // External global require no code
262
263 // Check to see if this is a special global used by LLVM, if so, emit it.
264 if (EmitSpecialLLVMGlobal(GVar))
265 return;
266
267 O << "\n\n";
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000268 std::string name = Mang->getValueName(GVar);
269 Constant *C = GVar->getInitializer();
Duncan Sandsceb4d1a2009-01-12 20:38:59 +0000270 unsigned Size = TD->getTypePaddedSize(C->getType());
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000271 unsigned Align = TD->getPreferredAlignmentLog(GVar);
272
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000273 printVisibility(name, GVar->getVisibility());
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000274
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000275 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000276
277 if (C->isNullValue() && !GVar->hasSection()) {
278 if (!GVar->isThreadLocal() &&
Rafael Espindolabb46f522009-01-15 20:18:42 +0000279 (GVar->hasLocalLinkage() || GVar->mayBeOverridden())) {
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000280 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
281
Rafael Espindolabb46f522009-01-15 20:18:42 +0000282 if (GVar->hasLocalLinkage()) {
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000283 O << "\t.lcomm " << name << "#," << Size
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000284 << ',' << (1 << Align);
285 O << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000286 } else {
287 O << "\t.common " << name << "#," << Size
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000288 << ',' << (1 << Align);
289 O << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000290 }
291
292 return;
293 }
294 }
295
296 switch (GVar->getLinkage()) {
297 case GlobalValue::LinkOnceLinkage:
298 case GlobalValue::CommonLinkage:
299 case GlobalValue::WeakLinkage:
300 // Nonnull linkonce -> weak
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000301 O << "\t.weak " << name << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000302 break;
303 case GlobalValue::AppendingLinkage:
304 // FIXME: appending linkage variables should go into a section of
305 // their name or something. For now, just emit them as external.
306 case GlobalValue::ExternalLinkage:
307 // If external or appending, declare as a global symbol
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000308 O << TAI->getGlobalDirective() << name << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000309 // FALL THROUGH
310 case GlobalValue::InternalLinkage:
Rafael Espindolabb46f522009-01-15 20:18:42 +0000311 case GlobalValue::PrivateLinkage:
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000312 break;
313 case GlobalValue::GhostLinkage:
314 cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";
315 abort();
316 case GlobalValue::DLLImportLinkage:
317 cerr << "DLLImport linkage is not supported by this target!\n";
318 abort();
319 case GlobalValue::DLLExportLinkage:
320 cerr << "DLLExport linkage is not supported by this target!\n";
321 abort();
322 default:
323 assert(0 && "Unknown linkage type!");
324 }
325
Anton Korobeynikovfcd99bb2008-08-07 09:53:38 +0000326 EmitAlignment(Align, GVar);
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000327
328 if (TAI->hasDotTypeDotSizeDirective()) {
329 O << "\t.type " << name << ",@object\n";
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000330 O << "\t.size " << name << ',' << Size << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000331 }
332
Owen Andersoncb371882008-08-21 00:14:44 +0000333 O << name << ":\n";
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000334 EmitGlobalConstant(C);
335}
336
337
338bool IA64AsmPrinter::doFinalization(Module &M) {
Chris Lattner42a76cd2005-11-21 08:40:17 +0000339 // Print out module-level global variables here.
340 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
341 I != E; ++I)
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000342 printModuleLevelGV(I);
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000343
344 // we print out ".global X \n .type X, @function" for each external function
345 O << "\n\n// br.call targets referenced (and not defined) above: \n";
Chris Lattner42a76cd2005-11-21 08:40:17 +0000346 for (std::set<std::string>::iterator i = ExternalFunctionNames.begin(),
347 e = ExternalFunctionNames.end(); i!=e; ++i) {
348 O << "\t.global " << *i << "\n\t.type " << *i << ", @function\n";
349 }
350 O << "\n\n";
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000351
Chris Lattner42a76cd2005-11-21 08:40:17 +0000352 // we print out ".global X \n .type X, @object" for each external object
353 O << "\n\n// (external) symbols referenced (and not defined) above: \n";
354 for (std::set<std::string>::iterator i = ExternalObjectNames.begin(),
355 e = ExternalObjectNames.end(); i!=e; ++i) {
356 O << "\t.global " << *i << "\n\t.type " << *i << ", @object\n";
357 }
358 O << "\n\n";
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000359
Dan Gohmanb8275a32007-07-25 19:33:14 +0000360 return AsmPrinter::doFinalization(M);
Chris Lattner42a76cd2005-11-21 08:40:17 +0000361}
362
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000363/// createIA64CodePrinterPass - Returns a pass that prints the IA64
364/// assembly code for a MachineFunction to the given output stream, using
365/// the given target machine description.
366///
Owen Andersoncb371882008-08-21 00:14:44 +0000367FunctionPass *llvm::createIA64CodePrinterPass(raw_ostream &o,
Evan Chengc4c62572006-03-13 23:20:37 +0000368 IA64TargetMachine &tm) {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000369 return new IA64AsmPrinter(o, tm, tm.getTargetAsmInfo());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000370}