blob: 957deba45230806b017955d448345624bcfbc0f3 [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"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000025#include "llvm/CodeGen/MachineFunctionPass.h"
Jim Laskey563321a2006-09-06 18:34:40 +000026#include "llvm/Target/TargetAsmInfo.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000027#include "llvm/Target/TargetMachine.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000028#include "llvm/Support/Mangler.h"
Owen Andersoncb371882008-08-21 00:14:44 +000029#include "llvm/Support/raw_ostream.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000030#include "llvm/ADT/Statistic.h"
Duraid Madina9b9d45f2005-03-17 18:17:03 +000031using namespace llvm;
32
Chris Lattner95b2c7d2006-12-19 22:59:26 +000033STATISTIC(EmittedInsts, "Number of machine instrs printed");
34
Duraid Madina9b9d45f2005-03-17 18:17:03 +000035namespace {
Jim Laskey563321a2006-09-06 18:34:40 +000036 struct IA64AsmPrinter : public AsmPrinter {
37 std::set<std::string> ExternalFunctionNames, ExternalObjectNames;
38
Owen Andersoncb371882008-08-21 00:14:44 +000039 IA64AsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
Jim Laskey563321a2006-09-06 18:34:40 +000040 : AsmPrinter(O, TM, T) {
41 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +000042
43 virtual const char *getPassName() const {
44 return "IA64 Assembly Printer";
45 }
46
47 /// printInstruction - This method is automatically generated by tablegen
48 /// from the instruction set description. This method returns true if the
49 /// machine instruction was sufficiently described to print it, otherwise it
50 /// returns false.
51 bool printInstruction(const MachineInstr *MI);
52
53 // This method is used by the tablegen'erated instruction printer.
Nate Begeman391c5d22005-11-30 18:54:35 +000054 void printOperand(const MachineInstr *MI, unsigned OpNo){
Duraid Madina9b9d45f2005-03-17 18:17:03 +000055 const MachineOperand &MO = MI->getOperand(OpNo);
Chris Lattner2d90ac72006-05-04 18:05:43 +000056 if (MO.getType() == MachineOperand::MO_Register) {
Dan Gohman6f0d0242008-02-10 18:45:23 +000057 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
58 "Not physref??");
Duraid Madina9b9d45f2005-03-17 18:17:03 +000059 //XXX Bug Workaround: See note in Printer::doInitialization about %.
Bill Wendling74ab84c2008-02-26 21:11:01 +000060 O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
Duraid Madina9b9d45f2005-03-17 18:17:03 +000061 } else {
62 printOp(MO);
63 }
64 }
Misha Brukman4633f1c2005-04-21 23:13:11 +000065
Nate Begeman391c5d22005-11-30 18:54:35 +000066 void printS8ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000067 int val=(unsigned int)MI->getOperand(OpNo).getImm();
Duraid Madinae6a0b6c2005-04-07 12:34:36 +000068 if(val>=128) val=val-256; // if negative, flip sign
69 O << val;
70 }
Nate Begeman391c5d22005-11-30 18:54:35 +000071 void printS14ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000072 int val=(unsigned int)MI->getOperand(OpNo).getImm();
Duraid Madinae6a0b6c2005-04-07 12:34:36 +000073 if(val>=8192) val=val-16384; // if negative, flip sign
74 O << val;
75 }
Nate Begeman391c5d22005-11-30 18:54:35 +000076 void printS22ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000077 int val=(unsigned int)MI->getOperand(OpNo).getImm();
Duraid Madina5ef2ec92005-04-11 05:55:56 +000078 if(val>=2097152) val=val-4194304; // if negative, flip sign
79 O << val;
Duraid Madina9b9d45f2005-03-17 18:17:03 +000080 }
Nate Begeman391c5d22005-11-30 18:54:35 +000081 void printU64ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000082 O << (uint64_t)MI->getOperand(OpNo).getImm();
Duraid Madina9b9d45f2005-03-17 18:17:03 +000083 }
Nate Begeman391c5d22005-11-30 18:54:35 +000084 void printS64ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Duraid Madinaf2db9b82005-10-28 17:46:35 +000085// XXX : nasty hack to avoid GPREL22 "relocation truncated to fit" linker
86// errors - instead of add rX = @gprel(CPI<whatever>), r1;; we now
87// emit movl rX = @gprel(CPI<whatever);;
Anton Korobeynikov003bcab2008-08-07 09:52:13 +000088// add rX = rX, r1;
Duraid Madinaf2db9b82005-10-28 17:46:35 +000089// this gives us 64 bits instead of 22 (for the add long imm) to play
90// with, which shuts up the linker. The problem is that the constant
Anton Korobeynikov003bcab2008-08-07 09:52:13 +000091// pool entries aren't immediates at this stage, so we check here.
Duraid Madinaf2db9b82005-10-28 17:46:35 +000092// If it's an immediate, print it the old fashioned way. If it's
Anton Korobeynikov003bcab2008-08-07 09:52:13 +000093// not, we print it as a constant pool index.
Duraid Madinaf2db9b82005-10-28 17:46:35 +000094 if(MI->getOperand(OpNo).isImmediate()) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +000095 O << (int64_t)MI->getOperand(OpNo).getImm();
Duraid Madinaf2db9b82005-10-28 17:46:35 +000096 } else { // this is a constant pool reference: FIXME: assert this
97 printOp(MI->getOperand(OpNo));
98 }
99 }
100
Nate Begeman391c5d22005-11-30 18:54:35 +0000101 void printGlobalOperand(const MachineInstr *MI, unsigned OpNo) {
Duraid Madinaf2db9b82005-10-28 17:46:35 +0000102 printOp(MI->getOperand(OpNo), false); // this is NOT a br.call instruction
Duraid Madina1ce0c012005-04-14 10:08:01 +0000103 }
Misha Brukman4633f1c2005-04-21 23:13:11 +0000104
Nate Begeman391c5d22005-11-30 18:54:35 +0000105 void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
Misha Brukman4633f1c2005-04-21 23:13:11 +0000106 printOp(MI->getOperand(OpNo), true); // this is a br.call instruction
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000107 }
108
Chris Lattneredad2b72006-10-05 02:51:36 +0000109 std::string getSectionForFunction(const Function &F) const;
110
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000111 void printMachineInstruction(const MachineInstr *MI);
112 void printOp(const MachineOperand &MO, bool isBRCALLinsn= false);
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000113 void printModuleLevelGV(const GlobalVariable* GVar);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000114 bool runOnMachineFunction(MachineFunction &F);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000115 bool doInitialization(Module &M);
Chris Lattner42a76cd2005-11-21 08:40:17 +0000116 bool doFinalization(Module &M);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000117 };
118} // end of anonymous namespace
119
120
121// Include the auto-generated portion of the assembly writer.
122#include "IA64GenAsmWriter.inc"
123
124
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000125// Substitute old hook with new one temporary
Chris Lattneredad2b72006-10-05 02:51:36 +0000126std::string IA64AsmPrinter::getSectionForFunction(const Function &F) const {
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000127 return TAI->SectionForGlobal(&F);
Chris Lattneredad2b72006-10-05 02:51:36 +0000128}
129
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000130/// runOnMachineFunction - This uses the printMachineInstruction()
131/// method to print assembly for each instruction.
132///
133bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Chris Lattner8b8b9512005-11-21 07:51:23 +0000134 SetupMachineFunction(MF);
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000135 O << "\n\n";
136
137 // Print out constants referenced by the function
Chris Lattner3dfbe2e2005-11-21 08:38:26 +0000138 EmitConstantPool(MF.getConstantPool());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000139
Chris Lattneredad2b72006-10-05 02:51:36 +0000140 const Function *F = MF.getFunction();
141 SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
142
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000143 // Print out labels for the function.
Chris Lattner8b8b9512005-11-21 07:51:23 +0000144 EmitAlignment(5);
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000145 O << "\t.global\t" << CurrentFnName << '\n';
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000146
147 printVisibility(CurrentFnName, F->getVisibility());
148
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000149 O << "\t.type\t" << CurrentFnName << ", @function\n";
150 O << CurrentFnName << ":\n";
151
152 // Print out code for the function.
153 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
154 I != E; ++I) {
155 // Print a label for the basic block if there are any predecessors.
Dan Gohmancb406c22007-10-03 19:26:29 +0000156 if (!I->pred_empty()) {
Evan Chengfb8075d2008-02-28 00:43:03 +0000157 printBasicBlockLabel(I, true, true);
Nate Begemancdf38c42006-05-02 05:37:32 +0000158 O << '\n';
159 }
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000160 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
161 II != E; ++II) {
162 // Print the assembly for the instruction.
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000163 printMachineInstruction(II);
164 }
165 }
166
167 // We didn't modify anything.
168 return false;
169}
170
171void IA64AsmPrinter::printOp(const MachineOperand &MO,
Chris Lattner63b3d712006-05-04 17:21:20 +0000172 bool isBRCALLinsn /* = false */) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000173 const TargetRegisterInfo &RI = *TM.getRegisterInfo();
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000174 switch (MO.getType()) {
Chris Lattner2d90ac72006-05-04 18:05:43 +0000175 case MachineOperand::MO_Register:
Bill Wendling74ab84c2008-02-26 21:11:01 +0000176 O << RI.get(MO.getReg()).AsmName;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000177 return;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000178
Chris Lattner63b3d712006-05-04 17:21:20 +0000179 case MachineOperand::MO_Immediate:
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000180 O << MO.getImm();
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000181 return;
Nate Begeman37efe672006-04-22 18:53:45 +0000182 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000183 printBasicBlockLabel(MO.getMBB());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000184 return;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000185 case MachineOperand::MO_ConstantPoolIndex: {
Jim Laskey563321a2006-09-06 18:34:40 +0000186 O << "@gprel(" << TAI->getPrivateGlobalPrefix()
Chris Lattner8aa797a2007-12-30 23:10:15 +0000187 << "CPI" << getFunctionNumber() << "_" << MO.getIndex() << ")";
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000188 return;
189 }
190
191 case MachineOperand::MO_GlobalAddress: {
192
193 // functions need @ltoff(@fptr(fn_name)) form
194 GlobalValue *GV = MO.getGlobal();
195 Function *F = dyn_cast<Function>(GV);
196
197 bool Needfptr=false; // if we're computing an address @ltoff(X), do
198 // we need to decorate it so it becomes
Misha Brukman7847fca2005-04-22 17:54:37 +0000199 // @ltoff(@fptr(X)) ?
Reid Spencer5cbf9852007-01-30 20:08:39 +0000200 if (F && !isBRCALLinsn /*&& F->isDeclaration()*/)
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000201 Needfptr=true;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000202
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000203 // if this is the target of a call instruction, we should define
204 // the function somewhere (GNU gas has no problem without this, but
205 // Intel ias rightly complains of an 'undefined symbol')
Misha Brukman4633f1c2005-04-21 23:13:11 +0000206
Reid Spencer5cbf9852007-01-30 20:08:39 +0000207 if (F /*&& isBRCALLinsn*/ && F->isDeclaration())
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000208 ExternalFunctionNames.insert(Mang->getValueName(MO.getGlobal()));
Duraid Madinaae8bd732005-03-28 15:21:43 +0000209 else
Reid Spencer5cbf9852007-01-30 20:08:39 +0000210 if (GV->isDeclaration()) // e.g. stuff like 'stdin'
Misha Brukman7847fca2005-04-22 17:54:37 +0000211 ExternalObjectNames.insert(Mang->getValueName(MO.getGlobal()));
Duraid Madinaae8bd732005-03-28 15:21:43 +0000212
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000213 if (!isBRCALLinsn)
214 O << "@ltoff(";
215 if (Needfptr)
216 O << "@fptr(";
217 O << Mang->getValueName(MO.getGlobal());
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000218
Duraid Madina00d3d442006-02-16 13:12:57 +0000219 if (Needfptr && !isBRCALLinsn)
220 O << "#))"; // close both fptr( and ltoff(
221 else {
222 if (Needfptr)
223 O << "#)"; // close only fptr(
224 if (!isBRCALLinsn)
225 O << "#)"; // close only ltoff(
226 }
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000227
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000228 int Offset = MO.getOffset();
229 if (Offset > 0)
230 O << " + " << Offset;
231 else if (Offset < 0)
232 O << " - " << -Offset;
233 return;
234 }
235 case MachineOperand::MO_ExternalSymbol:
236 O << MO.getSymbolName();
Duraid Madinaae8bd732005-03-28 15:21:43 +0000237 ExternalFunctionNames.insert(MO.getSymbolName());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000238 return;
239 default:
Misha Brukman4633f1c2005-04-21 23:13:11 +0000240 O << "<AsmPrinter: unknown operand type: " << MO.getType() << " >"; return;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000241 }
242}
243
244/// printMachineInstruction -- Print out a single IA64 LLVM instruction
245/// MI to the current output stream.
246///
247void IA64AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000248 ++EmittedInsts;
Misha Brukman4633f1c2005-04-21 23:13:11 +0000249
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000250 // Call the autogenerated instruction printer routines.
251 printInstruction(MI);
252}
253
254bool IA64AsmPrinter::doInitialization(Module &M) {
Dan Gohmanb8275a32007-07-25 19:33:14 +0000255 bool Result = AsmPrinter::doInitialization(M);
Misha Brukman4633f1c2005-04-21 23:13:11 +0000256
Duraid Madinaae8bd732005-03-28 15:21:43 +0000257 O << "\n.ident \"LLVM-ia64\"\n\n"
Misha Brukman7847fca2005-04-22 17:54:37 +0000258 << "\t.psr lsb\n" // should be "msb" on HP-UX, for starters
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000259 << "\t.radix C\n"
Misha Brukman7847fca2005-04-22 17:54:37 +0000260 << "\t.psr abi64\n"; // we only support 64 bits for now
Dan Gohmanb8275a32007-07-25 19:33:14 +0000261 return Result;
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000262}
263
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000264void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
Owen Andersona69571c2006-05-03 01:29:57 +0000265 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000266
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000267 if (!GVar->hasInitializer())
268 return; // External global require no code
269
270 // Check to see if this is a special global used by LLVM, if so, emit it.
271 if (EmitSpecialLLVMGlobal(GVar))
272 return;
273
274 O << "\n\n";
275 std::string SectionName = TAI->SectionForGlobal(GVar);
276 std::string name = Mang->getValueName(GVar);
277 Constant *C = GVar->getInitializer();
278 unsigned Size = TD->getABITypeSize(C->getType());
279 unsigned Align = TD->getPreferredAlignmentLog(GVar);
280
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000281 printVisibility(name, GVar->getVisibility());
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000282
283 SwitchToDataSection(SectionName.c_str());
284
285 if (C->isNullValue() && !GVar->hasSection()) {
286 if (!GVar->isThreadLocal() &&
287 (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
288 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
289
290 if (GVar->hasInternalLinkage()) {
291 O << "\t.lcomm " << name << "#," << Size
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000292 << ',' << (1 << Align);
293 O << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000294 } else {
295 O << "\t.common " << name << "#," << Size
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000296 << ',' << (1 << Align);
297 O << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000298 }
299
300 return;
301 }
302 }
303
304 switch (GVar->getLinkage()) {
305 case GlobalValue::LinkOnceLinkage:
306 case GlobalValue::CommonLinkage:
307 case GlobalValue::WeakLinkage:
308 // Nonnull linkonce -> weak
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000309 O << "\t.weak " << name << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000310 break;
311 case GlobalValue::AppendingLinkage:
312 // FIXME: appending linkage variables should go into a section of
313 // their name or something. For now, just emit them as external.
314 case GlobalValue::ExternalLinkage:
315 // If external or appending, declare as a global symbol
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000316 O << TAI->getGlobalDirective() << name << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000317 // FALL THROUGH
318 case GlobalValue::InternalLinkage:
319 break;
320 case GlobalValue::GhostLinkage:
321 cerr << "GhostLinkage cannot appear in IA64AsmPrinter!\n";
322 abort();
323 case GlobalValue::DLLImportLinkage:
324 cerr << "DLLImport linkage is not supported by this target!\n";
325 abort();
326 case GlobalValue::DLLExportLinkage:
327 cerr << "DLLExport linkage is not supported by this target!\n";
328 abort();
329 default:
330 assert(0 && "Unknown linkage type!");
331 }
332
Anton Korobeynikovfcd99bb2008-08-07 09:53:38 +0000333 EmitAlignment(Align, GVar);
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000334
335 if (TAI->hasDotTypeDotSizeDirective()) {
336 O << "\t.type " << name << ",@object\n";
Anton Korobeynikov98a6dd02008-08-07 09:52:54 +0000337 O << "\t.size " << name << ',' << Size << '\n';
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000338 }
339
Owen Andersoncb371882008-08-21 00:14:44 +0000340 O << name << ":\n";
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000341 EmitGlobalConstant(C);
342}
343
344
345bool IA64AsmPrinter::doFinalization(Module &M) {
Chris Lattner42a76cd2005-11-21 08:40:17 +0000346 // Print out module-level global variables here.
347 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
348 I != E; ++I)
Anton Korobeynikovdc3ca2e2008-08-07 09:52:35 +0000349 printModuleLevelGV(I);
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000350
351 // we print out ".global X \n .type X, @function" for each external function
352 O << "\n\n// br.call targets referenced (and not defined) above: \n";
Chris Lattner42a76cd2005-11-21 08:40:17 +0000353 for (std::set<std::string>::iterator i = ExternalFunctionNames.begin(),
354 e = ExternalFunctionNames.end(); i!=e; ++i) {
355 O << "\t.global " << *i << "\n\t.type " << *i << ", @function\n";
356 }
357 O << "\n\n";
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000358
Chris Lattner42a76cd2005-11-21 08:40:17 +0000359 // we print out ".global X \n .type X, @object" for each external object
360 O << "\n\n// (external) symbols referenced (and not defined) above: \n";
361 for (std::set<std::string>::iterator i = ExternalObjectNames.begin(),
362 e = ExternalObjectNames.end(); i!=e; ++i) {
363 O << "\t.global " << *i << "\n\t.type " << *i << ", @object\n";
364 }
365 O << "\n\n";
Anton Korobeynikov003bcab2008-08-07 09:52:13 +0000366
Dan Gohmanb8275a32007-07-25 19:33:14 +0000367 return AsmPrinter::doFinalization(M);
Chris Lattner42a76cd2005-11-21 08:40:17 +0000368}
369
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000370/// createIA64CodePrinterPass - Returns a pass that prints the IA64
371/// assembly code for a MachineFunction to the given output stream, using
372/// the given target machine description.
373///
Owen Andersoncb371882008-08-21 00:14:44 +0000374FunctionPass *llvm::createIA64CodePrinterPass(raw_ostream &o,
Evan Chengc4c62572006-03-13 23:20:37 +0000375 IA64TargetMachine &tm) {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000376 return new IA64AsmPrinter(o, tm, tm.getTargetAsmInfo());
Duraid Madina9b9d45f2005-03-17 18:17:03 +0000377}