blob: ed6ccec0c578bdbcf8a1419906aa45640575104a [file] [log] [blame]
Chris Lattnera80ba712004-08-16 23:15:22 +00001//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
2//
3// 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.
Chris Lattnera80ba712004-08-16 23:15:22 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
Evan Cheng932f0222006-03-03 02:04:29 +000014#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng246ae0d2006-03-01 22:18:09 +000015#include "llvm/Assembly/Writer.h"
Nate Begeman8cfa57b2005-12-06 06:18:55 +000016#include "llvm/DerivedTypes.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000017#include "llvm/Constants.h"
Chris Lattner450de392005-11-10 18:36:17 +000018#include "llvm/Module.h"
Gordon Henriksen5eca0752008-08-17 18:44:35 +000019#include "llvm/CodeGen/GCMetadataPrinter.h"
Chris Lattner3b4fd322005-11-21 08:25:09 +000020#include "llvm/CodeGen/MachineConstantPool.h"
David Greene1924aab2009-11-13 21:34:57 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
David Greenefe37ab32009-08-18 19:22:55 +000022#include "llvm/CodeGen/MachineFunction.h"
Nate Begeman37efe672006-04-22 18:53:45 +000023#include "llvm/CodeGen/MachineJumpTableInfo.h"
David Greeneb71d1b22009-08-10 16:38:07 +000024#include "llvm/CodeGen/MachineLoopInfo.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000025#include "llvm/CodeGen/MachineModuleInfo.h"
Devang Patelc48c5502009-01-13 21:44:10 +000026#include "llvm/CodeGen/DwarfWriter.h"
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +000027#include "llvm/Analysis/DebugInfo.h"
Chris Lattner2b2954f2009-07-27 21:28:04 +000028#include "llvm/MC/MCContext.h"
David Greene3ac1ab82009-07-16 22:24:20 +000029#include "llvm/MC/MCInst.h"
Chris Lattnera87dea42009-07-31 18:48:30 +000030#include "llvm/MC/MCSection.h"
31#include "llvm/MC/MCStreamer.h"
Chris Lattner7cb384d2009-09-12 23:02:08 +000032#include "llvm/MC/MCSymbol.h"
Evan Cheng42bf74b2009-03-25 01:47:28 +000033#include "llvm/Support/CommandLine.h"
Torok Edwin7d696d82009-07-11 13:10:19 +000034#include "llvm/Support/ErrorHandling.h"
David Greene014700c2009-07-13 20:25:48 +000035#include "llvm/Support/FormattedStream.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000036#include "llvm/Support/Mangler.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000037#include "llvm/MC/MCAsmInfo.h"
Owen Anderson07000c62006-05-12 06:33:49 +000038#include "llvm/Target/TargetData.h"
David Greene1924aab2009-11-13 21:34:57 +000039#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner0336fdb2006-10-06 22:50:56 +000040#include "llvm/Target/TargetLowering.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000041#include "llvm/Target/TargetLoweringObjectFile.h"
Evan Cheng6547e402008-07-01 23:18:29 +000042#include "llvm/Target/TargetOptions.h"
Evan Chengda47e6e2008-03-15 00:03:38 +000043#include "llvm/Target/TargetRegisterInfo.h"
Evan Chengcc415862007-11-09 01:32:10 +000044#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnerfad86b02008-08-17 07:19:36 +000045#include "llvm/ADT/SmallString.h"
Owen Andersoncb371882008-08-21 00:14:44 +000046#include "llvm/ADT/StringExtras.h"
Chris Lattner66099132006-02-01 22:41:11 +000047#include <cerrno>
Chris Lattnera80ba712004-08-16 23:15:22 +000048using namespace llvm;
49
Evan Cheng42bf74b2009-03-25 01:47:28 +000050static cl::opt<cl::boolOrDefault>
51AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
52 cl::init(cl::BOU_UNSET));
53
Devang Patel19974732007-05-03 01:11:54 +000054char AsmPrinter::ID = 0;
David Greene71847812009-07-14 20:18:05 +000055AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
Chris Lattneraf76e592009-08-22 20:48:53 +000056 const MCAsmInfo *T, bool VDef)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +000057 : MachineFunctionPass(&ID), FunctionNumber(0), O(o),
Chris Lattner33adcfb2009-08-22 21:43:10 +000058 TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
Chris Lattner2b2954f2009-07-27 21:28:04 +000059
60 OutContext(*new MCContext()),
Chris Lattner90edac02009-09-14 03:02:37 +000061 // FIXME: Pass instprinter to streamer.
62 OutStreamer(*createAsmStreamer(OutContext, O, *T, 0)),
Chris Lattner2b2954f2009-07-27 21:28:04 +000063
Devang Patel6b61f582010-01-16 06:09:35 +000064 LastMI(0), LastFn(0), Counter(~0U), PrevDLT(NULL) {
Chris Lattner0de1fc42009-06-24 19:09:55 +000065 DW = 0; MMI = 0;
Evan Cheng42bf74b2009-03-25 01:47:28 +000066 switch (AsmVerbose) {
67 case cl::BOU_UNSET: VerboseAsm = VDef; break;
68 case cl::BOU_TRUE: VerboseAsm = true; break;
69 case cl::BOU_FALSE: VerboseAsm = false; break;
70 }
71}
Chris Lattnered138932005-12-13 06:32:10 +000072
Gordon Henriksenc317a602008-08-17 12:08:44 +000073AsmPrinter::~AsmPrinter() {
74 for (gcp_iterator I = GCMetadataPrinters.begin(),
75 E = GCMetadataPrinters.end(); I != E; ++I)
76 delete I->second;
Chris Lattner2b2954f2009-07-27 21:28:04 +000077
78 delete &OutStreamer;
79 delete &OutContext;
Gordon Henriksenc317a602008-08-17 12:08:44 +000080}
Chris Lattnered138932005-12-13 06:32:10 +000081
Chris Lattner38c39882009-08-03 19:12:26 +000082TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
Chris Lattnerf0144122009-07-28 03:13:23 +000083 return TM.getTargetLowering()->getObjFileLowering();
84}
85
Chris Lattnerdabf07c2009-08-18 06:15:16 +000086/// getCurrentSection() - Return the current section we are emitting to.
87const MCSection *AsmPrinter::getCurrentSection() const {
88 return OutStreamer.getCurrentSection();
89}
90
91
Gordon Henriksence224772008-01-07 01:30:38 +000092void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
Dan Gohman845012e2009-07-31 23:37:33 +000093 AU.setPreservesAll();
Gordon Henriksence224772008-01-07 01:30:38 +000094 MachineFunctionPass::getAnalysisUsage(AU);
Gordon Henriksen5eca0752008-08-17 18:44:35 +000095 AU.addRequired<GCModuleInfo>();
David Greenefe37ab32009-08-18 19:22:55 +000096 if (VerboseAsm)
David Greeneb71d1b22009-08-10 16:38:07 +000097 AU.addRequired<MachineLoopInfo>();
Gordon Henriksence224772008-01-07 01:30:38 +000098}
99
Chris Lattnera80ba712004-08-16 23:15:22 +0000100bool AsmPrinter::doInitialization(Module &M) {
Chris Lattnerf26e03b2009-07-31 17:42:42 +0000101 // Initialize TargetLoweringObjectFile.
102 const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
103 .Initialize(OutContext, TM);
104
Chris Lattner33adcfb2009-08-22 21:43:10 +0000105 Mang = new Mangler(M, MAI->getGlobalPrefix(), MAI->getPrivateGlobalPrefix(),
106 MAI->getLinkerPrivateGlobalPrefix());
Chris Lattner2c1b1592006-01-23 23:47:53 +0000107
Chris Lattner33adcfb2009-08-22 21:43:10 +0000108 if (MAI->doesAllowQuotesInName())
Chris Lattnera93ca922009-06-18 23:41:35 +0000109 Mang->setUseQuotes(true);
Anton Korobeynikovc6f729e2009-09-18 16:57:42 +0000110
111 if (MAI->doesAllowNameToStartWithDigit())
112 Mang->setSymbolsCanStartWithDigit(true);
Chris Lattnera93ca922009-06-18 23:41:35 +0000113
Bob Wilson812209a2009-09-30 22:06:26 +0000114 // Allow the target to emit any magic that it wants at the start of the file.
115 EmitStartOfAsmFile(M);
Rafael Espindola952b8392008-12-03 11:01:37 +0000116
Chris Lattner33adcfb2009-08-22 21:43:10 +0000117 if (MAI->hasSingleParameterDotFile()) {
Rafael Espindola952b8392008-12-03 11:01:37 +0000118 /* Very minimal debug info. It is ignored if we emit actual
Bob Wilsonbc9506f2009-09-30 21:26:13 +0000119 debug info. If we don't, this at least helps the user find where
Rafael Espindola952b8392008-12-03 11:01:37 +0000120 a function came from. */
121 O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
122 }
123
Bob Wilson812209a2009-09-30 22:06:26 +0000124 GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
125 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000126 for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
127 if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
Chris Lattner33adcfb2009-08-22 21:43:10 +0000128 MP->beginAssembly(O, *this, *MAI);
Gordon Henriksence224772008-01-07 01:30:38 +0000129
Chris Lattner3e2fa7a2006-01-24 04:16:34 +0000130 if (!M.getModuleInlineAsm().empty())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000131 O << MAI->getCommentString() << " Start of file scope inline assembly\n"
Chris Lattner3e2fa7a2006-01-24 04:16:34 +0000132 << M.getModuleInlineAsm()
Chris Lattner33adcfb2009-08-22 21:43:10 +0000133 << '\n' << MAI->getCommentString()
Jim Laskey563321a2006-09-06 18:34:40 +0000134 << " End of file scope inline assembly\n";
Chris Lattner2c1b1592006-01-23 23:47:53 +0000135
Chris Lattnerb55e0682009-09-24 05:44:53 +0000136 MMI = getAnalysisIfAvailable<MachineModuleInfo>();
137 if (MMI)
138 MMI->AnalyzeModule(M);
139 DW = getAnalysisIfAvailable<DwarfWriter>();
Sanjiv Gupta9a501cf2009-11-14 07:22:25 +0000140 if (DW)
Chris Lattnerb55e0682009-09-24 05:44:53 +0000141 DW->BeginModule(&M, MMI, O, this, MAI);
Devang Patel14a55d92009-06-19 21:54:26 +0000142
Chris Lattnera80ba712004-08-16 23:15:22 +0000143 return false;
144}
145
146bool AsmPrinter::doFinalization(Module &M) {
Chris Lattner40bbebd2009-07-21 18:38:57 +0000147 // Emit global variables.
148 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
149 I != E; ++I)
150 PrintGlobalVariable(I);
151
Chris Lattner1f522fe2009-06-24 18:54:37 +0000152 // Emit final debug information.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000153 if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling())
Chris Lattner1f522fe2009-06-24 18:54:37 +0000154 DW->EndModule();
155
Chris Lattner0a7befa2009-06-24 18:52:01 +0000156 // If the target wants to know about weak references, print them all.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000157 if (MAI->getWeakRefDirective()) {
Chris Lattner0a7befa2009-06-24 18:52:01 +0000158 // FIXME: This is not lazy, it would be nice to only print weak references
159 // to stuff that is actually used. Note that doing so would require targets
160 // to notice uses in operands (due to constant exprs etc). This should
161 // happen with the MC stuff eventually.
Rafael Espindola15404d02006-12-18 03:37:18 +0000162
Chris Lattner0a7befa2009-06-24 18:52:01 +0000163 // Print out module-level global variables here.
164 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
165 I != E; ++I) {
166 if (I->hasExternalWeakLinkage())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000167 O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
Chris Lattner0a7befa2009-06-24 18:52:01 +0000168 }
169
Chris Lattnerc6fdced2009-08-03 23:10:34 +0000170 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
Chris Lattner0a7befa2009-06-24 18:52:01 +0000171 if (I->hasExternalWeakLinkage())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000172 O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
Chris Lattner0a7befa2009-06-24 18:52:01 +0000173 }
Rafael Espindola15404d02006-12-18 03:37:18 +0000174 }
175
Chris Lattner33adcfb2009-08-22 21:43:10 +0000176 if (MAI->getSetDirective()) {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000177 O << '\n';
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000178 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
Chris Lattner0a7befa2009-06-24 18:52:01 +0000179 I != E; ++I) {
Chris Lattner5c40e692010-01-16 01:17:26 +0000180 MCSymbol *Name = GetGlobalValueSymbol(I);
Anton Korobeynikov325be7c2007-09-06 17:21:48 +0000181
182 const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
Chris Lattner5c40e692010-01-16 01:17:26 +0000183 MCSymbol *Target = GetGlobalValueSymbol(GV);
Anton Korobeynikov541af7f2008-09-24 22:21:04 +0000184
Chris Lattner5c40e692010-01-16 01:17:26 +0000185 if (I->hasExternalLinkage() || !MAI->getWeakRefDirective()) {
186 O << "\t.globl\t";
187 Name->print(O, MAI);
188 O << '\n';
189 } else if (I->hasWeakLinkage()) {
190 O << MAI->getWeakRefDirective();
191 Name->print(O, MAI);
192 O << '\n';
193 } else {
Chris Lattner10595492010-01-16 01:37:14 +0000194 assert(I->hasLocalLinkage() && "Invalid alias linkage");
Chris Lattner5c40e692010-01-16 01:17:26 +0000195 }
Anton Korobeynikov22c9e652008-03-11 21:41:14 +0000196
Anton Korobeynikov541af7f2008-09-24 22:21:04 +0000197 printVisibility(Name, I->getVisibility());
Anton Korobeynikov22c9e652008-03-11 21:41:14 +0000198
Chris Lattner5c40e692010-01-16 01:17:26 +0000199 O << MAI->getSetDirective() << ' ';
200 Name->print(O, MAI);
201 O << ", ";
202 Target->print(O, MAI);
203 O << '\n';
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000204 }
205 }
206
Duncan Sands1465d612009-01-28 13:14:17 +0000207 GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000208 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
209 for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
210 if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
Chris Lattner33adcfb2009-08-22 21:43:10 +0000211 MP->finishAssembly(O, *this, *MAI);
Gordon Henriksence224772008-01-07 01:30:38 +0000212
Dan Gohmana779a982008-05-05 00:28:39 +0000213 // If we don't have any trampolines, then we don't require stack memory
214 // to be executable. Some targets have a directive to declare this.
Chris Lattner0a7befa2009-06-24 18:52:01 +0000215 Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
Dan Gohmana779a982008-05-05 00:28:39 +0000216 if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000217 if (MAI->getNonexecutableStackDirective())
218 O << MAI->getNonexecutableStackDirective() << '\n';
Dan Gohmana779a982008-05-05 00:28:39 +0000219
Chris Lattnerbd23d5f2009-09-18 20:17:03 +0000220
221 // Allow the target to emit any magic that it wants at the end of the file,
222 // after everything else has gone out.
223 EmitEndOfAsmFile(M);
224
Chris Lattnera80ba712004-08-16 23:15:22 +0000225 delete Mang; Mang = 0;
Chris Lattner0de1fc42009-06-24 19:09:55 +0000226 DW = 0; MMI = 0;
Chris Lattner2b2954f2009-07-27 21:28:04 +0000227
228 OutStreamer.Finish();
Chris Lattnera80ba712004-08-16 23:15:22 +0000229 return false;
230}
231
Chris Lattner25045bd2005-11-21 07:51:36 +0000232void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattner412c3a52010-01-16 01:24:10 +0000233 // Get the function symbol.
Chris Lattnerd1947ed2010-01-15 23:55:16 +0000234 CurrentFnSym = GetGlobalValueSymbol(MF.getFunction());
Evan Cheng347d39f2007-10-14 05:57:21 +0000235 IncrementFunctionNumber();
David Greeneb71d1b22009-08-10 16:38:07 +0000236
Chris Lattner25d812b2009-09-16 00:35:39 +0000237 if (VerboseAsm)
David Greeneb71d1b22009-08-10 16:38:07 +0000238 LI = &getAnalysis<MachineLoopInfo>();
Chris Lattnera80ba712004-08-16 23:15:22 +0000239}
240
Evan Cheng1606e8e2009-03-13 07:51:59 +0000241namespace {
242 // SectionCPs - Keep track the alignment, constpool entries per Section.
243 struct SectionCPs {
Chris Lattnera87dea42009-07-31 18:48:30 +0000244 const MCSection *S;
Evan Cheng1606e8e2009-03-13 07:51:59 +0000245 unsigned Alignment;
246 SmallVector<unsigned, 4> CPEs;
Douglas Gregorcabdd742009-12-19 07:05:23 +0000247 SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {}
Evan Cheng1606e8e2009-03-13 07:51:59 +0000248 };
249}
250
Chris Lattner3b4fd322005-11-21 08:25:09 +0000251/// EmitConstantPool - Print to the current output stream assembly
252/// representations of the constants in the constant pool MCP. This is
253/// used to print out constants which have been "spilled to memory" by
254/// the code generator.
255///
256void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerfa77d432006-02-09 04:22:52 +0000257 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattner3b4fd322005-11-21 08:25:09 +0000258 if (CP.empty()) return;
Evan Cheng2d2cec12006-06-29 00:26:09 +0000259
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000260 // Calculate sections for constant pool entries. We collect entries to go into
261 // the same section together to reduce amount of section switch statements.
Evan Cheng1606e8e2009-03-13 07:51:59 +0000262 SmallVector<SectionCPs, 4> CPSections;
Chris Lattner3b4fd322005-11-21 08:25:09 +0000263 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Chris Lattner298414e2009-07-22 00:28:43 +0000264 const MachineConstantPoolEntry &CPE = CP[i];
Evan Cheng1606e8e2009-03-13 07:51:59 +0000265 unsigned Align = CPE.getAlignment();
Chris Lattner5c2f7892009-07-26 06:26:55 +0000266
267 SectionKind Kind;
268 switch (CPE.getRelocationInfo()) {
269 default: llvm_unreachable("Unknown section kind");
Chris Lattner27981192009-08-01 23:57:16 +0000270 case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
Chris Lattner4c509222009-07-26 07:00:12 +0000271 case 1:
Chris Lattner27981192009-08-01 23:57:16 +0000272 Kind = SectionKind::getReadOnlyWithRelLocal();
Chris Lattner4c509222009-07-26 07:00:12 +0000273 break;
Chris Lattner5c2f7892009-07-26 06:26:55 +0000274 case 0:
Chris Lattner4c509222009-07-26 07:00:12 +0000275 switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
Chris Lattner27981192009-08-01 23:57:16 +0000276 case 4: Kind = SectionKind::getMergeableConst4(); break;
277 case 8: Kind = SectionKind::getMergeableConst8(); break;
278 case 16: Kind = SectionKind::getMergeableConst16();break;
279 default: Kind = SectionKind::getMergeableConst(); break;
Chris Lattner4c509222009-07-26 07:00:12 +0000280 }
Chris Lattner5c2f7892009-07-26 06:26:55 +0000281 }
282
Chris Lattner83d77fa2009-08-01 23:46:12 +0000283 const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);
Chris Lattner298414e2009-07-22 00:28:43 +0000284
Evan Cheng1606e8e2009-03-13 07:51:59 +0000285 // The number of sections are small, just do a linear search from the
286 // last section to the first.
287 bool Found = false;
288 unsigned SecIdx = CPSections.size();
289 while (SecIdx != 0) {
290 if (CPSections[--SecIdx].S == S) {
291 Found = true;
292 break;
293 }
294 }
295 if (!Found) {
296 SecIdx = CPSections.size();
297 CPSections.push_back(SectionCPs(S, Align));
298 }
299
300 if (Align > CPSections[SecIdx].Alignment)
301 CPSections[SecIdx].Alignment = Align;
302 CPSections[SecIdx].CPEs.push_back(i);
Evan Cheng2d2cec12006-06-29 00:26:09 +0000303 }
304
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000305 // Now print stuff into the calculated sections.
Evan Cheng1606e8e2009-03-13 07:51:59 +0000306 for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000307 OutStreamer.SwitchSection(CPSections[i].S);
Evan Cheng1606e8e2009-03-13 07:51:59 +0000308 EmitAlignment(Log2_32(CPSections[i].Alignment));
Evan Cheng2d2cec12006-06-29 00:26:09 +0000309
Evan Cheng1606e8e2009-03-13 07:51:59 +0000310 unsigned Offset = 0;
311 for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
312 unsigned CPI = CPSections[i].CPEs[j];
313 MachineConstantPoolEntry CPE = CP[CPI];
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000314
Chris Lattner3029f922006-02-09 04:46:04 +0000315 // Emit inter-object padding for alignment.
Evan Cheng1606e8e2009-03-13 07:51:59 +0000316 unsigned AlignMask = CPE.getAlignment() - 1;
317 unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
318 EmitZeros(NewOffset - Offset);
319
320 const Type *Ty = CPE.getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000321 Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
Evan Cheng1606e8e2009-03-13 07:51:59 +0000322
Chris Lattner33adcfb2009-08-22 21:43:10 +0000323 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
Dan Gohmana12e9d72009-08-12 18:32:22 +0000324 << CPI << ':';
Evan Cheng1606e8e2009-03-13 07:51:59 +0000325 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000326 O.PadToColumn(MAI->getCommentColumn());
327 O << MAI->getCommentString() << " constant ";
Dan Gohmancf20ac42009-08-13 01:36:44 +0000328 WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent());
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000329 }
Evan Cheng1606e8e2009-03-13 07:51:59 +0000330 O << '\n';
331 if (CPE.isMachineConstantPoolEntry())
332 EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
333 else
334 EmitGlobalConstant(CPE.Val.ConstVal);
Chris Lattner3029f922006-02-09 04:46:04 +0000335 }
Chris Lattner3b4fd322005-11-21 08:25:09 +0000336 }
337}
338
Nate Begeman37efe672006-04-22 18:53:45 +0000339/// EmitJumpTableInfo - Print assembly representations of the jump tables used
340/// by the current function to the current output stream.
341///
Chris Lattner1da31ee2006-10-05 03:01:21 +0000342void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
343 MachineFunction &MF) {
Nate Begeman37efe672006-04-22 18:53:45 +0000344 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
345 if (JT.empty()) return;
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000346
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000347 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
Nate Begeman4d9bbdc2006-07-27 16:46:58 +0000348
Nate Begeman2f1ae882006-07-27 01:13:04 +0000349 // Pick the directive to use to print the jump table entries, and switch to
350 // the appropriate section.
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000351 TargetLowering *LoweringInfo = TM.getTargetLowering();
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000352
Anton Korobeynikove87f52d2008-07-09 13:27:16 +0000353 const Function *F = MF.getFunction();
Evan Chengb13bafe2009-06-18 20:37:15 +0000354 bool JTInDiffSection = false;
Chris Lattner83d77fa2009-08-01 23:46:12 +0000355 if (F->isWeakForLinker() ||
356 (IsPic && !LoweringInfo->usesGlobalOffsetTable())) {
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000357 // In PIC mode, we need to emit the jump table to the same section as the
358 // function body itself, otherwise the label differences won't make sense.
Anton Korobeynikove87f52d2008-07-09 13:27:16 +0000359 // We should also do if the section name is NULL or function is declared in
360 // discardable section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000361 OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang,
362 TM));
Nate Begeman2f1ae882006-07-27 01:13:04 +0000363 } else {
Chris Lattner83d77fa2009-08-01 23:46:12 +0000364 // Otherwise, drop it in the readonly section.
365 const MCSection *ReadOnlySection =
Chris Lattner27981192009-08-01 23:57:16 +0000366 getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000367 OutStreamer.SwitchSection(ReadOnlySection);
Evan Chengb13bafe2009-06-18 20:37:15 +0000368 JTInDiffSection = true;
Nate Begeman2f1ae882006-07-27 01:13:04 +0000369 }
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000370
371 EmitAlignment(Log2_32(MJTI->getAlignment()));
Chris Lattner0c4e6782006-07-15 01:34:12 +0000372
Nate Begeman37efe672006-04-22 18:53:45 +0000373 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
Nate Begeman52a51e382006-08-12 21:29:52 +0000374 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
Chris Lattner07371882006-10-28 18:10:06 +0000375
376 // If this jump table was deleted, ignore it.
377 if (JTBBs.empty()) continue;
Nate Begeman52a51e382006-08-12 21:29:52 +0000378
379 // For PIC codegen, if possible we want to use the SetDirective to reduce
380 // the number of relocations the assembler will generate for the jump table.
381 // Set directives are all printed before the jump table itself.
Evan Chengcc415862007-11-09 01:32:10 +0000382 SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
Chris Lattner33adcfb2009-08-22 21:43:10 +0000383 if (MAI->getSetDirective() && IsPic)
Nate Begeman52a51e382006-08-12 21:29:52 +0000384 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
Evan Chengcc415862007-11-09 01:32:10 +0000385 if (EmittedSets.insert(JTBBs[ii]))
386 printPICJumpTableSetLabel(i, JTBBs[ii]);
Nate Begeman52a51e382006-08-12 21:29:52 +0000387
Chris Lattner7c301912009-09-13 19:02:16 +0000388 // On some targets (e.g. Darwin) we want to emit two consequtive labels
Chris Lattner393a8ee2007-01-18 01:12:56 +0000389 // before each jump table. The first label is never referenced, but tells
390 // the assembler and linker the extents of the jump table object. The
391 // second label is actually referenced by the code.
Chris Lattner7c301912009-09-13 19:02:16 +0000392 if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0]) {
393 O << MAI->getLinkerPrivateGlobalPrefix()
394 << "JTI" << getFunctionNumber() << '_' << i << ":\n";
Evan Chengb13bafe2009-06-18 20:37:15 +0000395 }
Chris Lattner393a8ee2007-01-18 01:12:56 +0000396
Chris Lattner33adcfb2009-08-22 21:43:10 +0000397 O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng347d39f2007-10-14 05:57:21 +0000398 << '_' << i << ":\n";
Nate Begeman52a51e382006-08-12 21:29:52 +0000399
Nate Begeman37efe672006-04-22 18:53:45 +0000400 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000401 printPICJumpTableEntry(MJTI, JTBBs[ii], i);
Nate Begeman37efe672006-04-22 18:53:45 +0000402 O << '\n';
403 }
404 }
405}
406
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000407void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
408 const MachineBasicBlock *MBB,
409 unsigned uid) const {
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000410 bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000411
412 // Use JumpTableDirective otherwise honor the entry size from the jump table
413 // info.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000414 const char *JTEntryDirective = MAI->getJumpTableDirective(isPIC);
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000415 bool HadJTEntryDirective = JTEntryDirective != NULL;
416 if (!HadJTEntryDirective) {
417 JTEntryDirective = MJTI->getEntrySize() == 4 ?
Chris Lattner33adcfb2009-08-22 21:43:10 +0000418 MAI->getData32bitsDirective() : MAI->getData64bitsDirective();
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000419 }
420
421 O << JTEntryDirective << ' ';
422
423 // If we have emitted set directives for the jump table entries, print
424 // them rather than the entries themselves. If we're emitting PIC, then
425 // emit the table entries as differences between two text section labels.
426 // If we're emitting non-PIC code, then emit the entries as direct
427 // references to the target basic blocks.
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000428 if (!isPIC) {
Chris Lattner325d3dc2009-09-13 17:14:04 +0000429 GetMBBSymbol(MBB->getNumber())->print(O, MAI);
Chris Lattner33adcfb2009-08-22 21:43:10 +0000430 } else if (MAI->getSetDirective()) {
431 O << MAI->getPrivateGlobalPrefix() << getFunctionNumber()
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000432 << '_' << uid << "_set_" << MBB->getNumber();
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000433 } else {
Chris Lattner325d3dc2009-09-13 17:14:04 +0000434 GetMBBSymbol(MBB->getNumber())->print(O, MAI);
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000435 // If the arch uses custom Jump Table directives, don't calc relative to
436 // JT
437 if (!HadJTEntryDirective)
Chris Lattner33adcfb2009-08-22 21:43:10 +0000438 O << '-' << MAI->getPrivateGlobalPrefix() << "JTI"
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000439 << getFunctionNumber() << '_' << uid;
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000440 }
441}
442
443
Chris Lattnered138932005-12-13 06:32:10 +0000444/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
445/// special global used by LLVM. If so, emit it and return true, otherwise
446/// do nothing and return false.
447bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Daniel Dunbar03d76512009-07-25 23:55:21 +0000448 if (GV->getName() == "llvm.used") {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000449 if (MAI->getUsedDirective() != 0) // No need to emit this at all.
Andrew Lenharthb753a9b2007-08-22 19:33:11 +0000450 EmitLLVMUsedList(GV->getInitializer());
451 return true;
452 }
453
Chris Lattner401e10c2009-07-20 06:14:25 +0000454 // Ignore debug and non-emitted data. This handles llvm.compiler.used.
Chris Lattner266c7bb2009-04-13 05:44:34 +0000455 if (GV->getSection() == "llvm.metadata" ||
456 GV->hasAvailableExternallyLinkage())
457 return true;
Jim Laskey78098112006-03-07 22:00:35 +0000458
459 if (!GV->hasAppendingLinkage()) return false;
460
461 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnered138932005-12-13 06:32:10 +0000462
Evan Cheng916d07c2007-06-04 20:39:18 +0000463 const TargetData *TD = TM.getTargetData();
464 unsigned Align = Log2_32(TD->getPointerPrefAlignment());
Chris Lattnerf231c072009-03-09 05:52:15 +0000465 if (GV->getName() == "llvm.global_ctors") {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000466 OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
Chris Lattnerea3a9ff2009-03-09 08:18:48 +0000467 EmitAlignment(Align, 0);
468 EmitXXStructorList(GV->getInitializer());
469 return true;
Chris Lattnered138932005-12-13 06:32:10 +0000470 }
471
Chris Lattnerf231c072009-03-09 05:52:15 +0000472 if (GV->getName() == "llvm.global_dtors") {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000473 OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
Chris Lattnerea3a9ff2009-03-09 08:18:48 +0000474 EmitAlignment(Align, 0);
475 EmitXXStructorList(GV->getInitializer());
476 return true;
Chris Lattnered138932005-12-13 06:32:10 +0000477 }
478
479 return false;
480}
481
Chris Lattner33adcfb2009-08-22 21:43:10 +0000482/// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
Dale Johannesend2e51af2008-09-09 22:29:13 +0000483/// global in the specified llvm.used list for which emitUsedDirectiveFor
484/// is true, as being used with this directive.
Chris Lattnercb05af82006-09-26 03:38:18 +0000485void AsmPrinter::EmitLLVMUsedList(Constant *List) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000486 const char *Directive = MAI->getUsedDirective();
Chris Lattnercb05af82006-09-26 03:38:18 +0000487
Dan Gohmana119de82009-06-14 23:30:43 +0000488 // Should be an array of 'i8*'.
Chris Lattnercb05af82006-09-26 03:38:18 +0000489 ConstantArray *InitList = dyn_cast<ConstantArray>(List);
490 if (InitList == 0) return;
491
492 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
Chris Lattner16fe9902009-07-17 22:00:23 +0000493 const GlobalValue *GV =
494 dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
Chris Lattner26630c12009-07-31 20:52:39 +0000495 if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) {
Dale Johannesen61e60932008-09-03 20:34:58 +0000496 O << Directive;
497 EmitConstantValueOnly(InitList->getOperand(i));
498 O << '\n';
499 }
Chris Lattnercb05af82006-09-26 03:38:18 +0000500 }
501}
502
Chris Lattnered138932005-12-13 06:32:10 +0000503/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
504/// function pointers, ignoring the init priority.
505void AsmPrinter::EmitXXStructorList(Constant *List) {
506 // Should be an array of '{ int, void ()* }' structs. The first value is the
507 // init priority, which we ignore.
508 if (!isa<ConstantArray>(List)) return;
509 ConstantArray *InitList = cast<ConstantArray>(List);
510 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
511 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
512 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner8de324b2005-12-21 01:17:37 +0000513
514 if (CS->getOperand(1)->isNullValue())
515 return; // Found a null terminator, exit printing.
516 // Emit the function pointer.
Chris Lattnered138932005-12-13 06:32:10 +0000517 EmitGlobalConstant(CS->getOperand(1));
518 }
519}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000520
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000521
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000522//===----------------------------------------------------------------------===//
523/// LEB 128 number encoding.
524
Bob Wilsonc0ef2442009-11-06 22:38:38 +0000525/// PrintULEB128 - Print a series of hexadecimal values (separated by commas)
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000526/// representing an unsigned leb128 value.
527void AsmPrinter::PrintULEB128(unsigned Value) const {
Chris Lattnera64f4632008-11-10 04:35:24 +0000528 char Buffer[20];
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000529 do {
Chris Lattnera64f4632008-11-10 04:35:24 +0000530 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000531 Value >>= 7;
532 if (Value) Byte |= 0x80;
Chris Lattnera64f4632008-11-10 04:35:24 +0000533 O << "0x" << utohex_buffer(Byte, Buffer+20);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000534 if (Value) O << ", ";
535 } while (Value);
536}
537
Bob Wilsonc0ef2442009-11-06 22:38:38 +0000538/// PrintSLEB128 - Print a series of hexadecimal values (separated by commas)
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000539/// representing a signed leb128 value.
540void AsmPrinter::PrintSLEB128(int Value) const {
541 int Sign = Value >> (8 * sizeof(Value) - 1);
542 bool IsMore;
Chris Lattnera64f4632008-11-10 04:35:24 +0000543 char Buffer[20];
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000544
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000545 do {
Chris Lattnera64f4632008-11-10 04:35:24 +0000546 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000547 Value >>= 7;
548 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
549 if (IsMore) Byte |= 0x80;
Chris Lattnera64f4632008-11-10 04:35:24 +0000550 O << "0x" << utohex_buffer(Byte, Buffer+20);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000551 if (IsMore) O << ", ";
552 } while (IsMore);
553}
554
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000555//===--------------------------------------------------------------------===//
556// Emission and print routines
557//
558
Bob Wilsonc0ef2442009-11-06 22:38:38 +0000559/// PrintHex - Print a value as a hexadecimal value.
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000560///
561void AsmPrinter::PrintHex(int Value) const {
Chris Lattnerc6a13462008-11-10 04:30:26 +0000562 char Buffer[20];
Chris Lattnerc6a13462008-11-10 04:30:26 +0000563 O << "0x" << utohex_buffer(static_cast<unsigned>(Value), Buffer+20);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000564}
565
566/// EOL - Print a newline character to asm stream. If a comment is present
567/// then it will be printed first. Comments should not contain '\n'.
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000568void AsmPrinter::EOL() const {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000569 O << '\n';
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000570}
Owen Anderson25995092008-07-01 21:16:27 +0000571
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000572void AsmPrinter::EOL(const std::string &Comment) const {
Evan Cheng6547e402008-07-01 23:18:29 +0000573 if (VerboseAsm && !Comment.empty()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000574 O.PadToColumn(MAI->getCommentColumn());
575 O << MAI->getCommentString()
Dan Gohmand19a53b2008-06-30 22:03:41 +0000576 << ' '
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000577 << Comment;
578 }
Dan Gohmand19a53b2008-06-30 22:03:41 +0000579 O << '\n';
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000580}
581
Owen Anderson25995092008-07-01 21:16:27 +0000582void AsmPrinter::EOL(const char* Comment) const {
Evan Cheng6547e402008-07-01 23:18:29 +0000583 if (VerboseAsm && *Comment) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000584 O.PadToColumn(MAI->getCommentColumn());
585 O << MAI->getCommentString()
Owen Anderson25995092008-07-01 21:16:27 +0000586 << ' '
587 << Comment;
588 }
589 O << '\n';
590}
591
Bill Wendlingb5abecd2009-08-29 12:17:53 +0000592static const char *DecodeDWARFEncoding(unsigned Encoding) {
593 switch (Encoding) {
594 case dwarf::DW_EH_PE_absptr:
595 return "absptr";
596 case dwarf::DW_EH_PE_omit:
597 return "omit";
598 case dwarf::DW_EH_PE_pcrel:
599 return "pcrel";
Bill Wendling0734d352009-09-09 21:26:19 +0000600 case dwarf::DW_EH_PE_udata4:
601 return "udata4";
602 case dwarf::DW_EH_PE_udata8:
603 return "udata8";
604 case dwarf::DW_EH_PE_sdata4:
605 return "sdata4";
606 case dwarf::DW_EH_PE_sdata8:
607 return "sdata8";
Bill Wendlingb5abecd2009-08-29 12:17:53 +0000608 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4:
609 return "pcrel udata4";
610 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4:
611 return "pcrel sdata4";
612 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8:
613 return "pcrel udata8";
614 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8:
615 return "pcrel sdata8";
616 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4:
617 return "indirect pcrel udata4";
618 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4:
619 return "indirect pcrel sdata4";
620 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8:
621 return "indirect pcrel udata8";
622 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8:
623 return "indirect pcrel sdata8";
624 }
625
626 return 0;
627}
628
Bill Wendlingb5abecd2009-08-29 12:17:53 +0000629void AsmPrinter::EOL(const char *Comment, unsigned Encoding) const {
630 if (VerboseAsm && *Comment) {
631 O.PadToColumn(MAI->getCommentColumn());
632 O << MAI->getCommentString()
633 << ' '
634 << Comment;
635
636 if (const char *EncStr = DecodeDWARFEncoding(Encoding))
637 O << " (" << EncStr << ')';
638 }
639 O << '\n';
640}
641
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000642/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
643/// unsigned leb128 value.
644void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000645 if (MAI->hasLEB128()) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000646 O << "\t.uleb128\t"
647 << Value;
648 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000649 O << MAI->getData8bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000650 PrintULEB128(Value);
651 }
652}
653
654/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
655/// signed leb128 value.
656void AsmPrinter::EmitSLEB128Bytes(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000657 if (MAI->hasLEB128()) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000658 O << "\t.sleb128\t"
659 << Value;
660 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000661 O << MAI->getData8bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000662 PrintSLEB128(Value);
663 }
664}
665
666/// EmitInt8 - Emit a byte directive and value.
667///
668void AsmPrinter::EmitInt8(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000669 O << MAI->getData8bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000670 PrintHex(Value & 0xFF);
671}
672
673/// EmitInt16 - Emit a short directive and value.
674///
675void AsmPrinter::EmitInt16(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000676 O << MAI->getData16bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000677 PrintHex(Value & 0xFFFF);
678}
679
680/// EmitInt32 - Emit a long directive and value.
681///
682void AsmPrinter::EmitInt32(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000683 O << MAI->getData32bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000684 PrintHex(Value);
685}
686
687/// EmitInt64 - Emit a long long directive and value.
688///
689void AsmPrinter::EmitInt64(uint64_t Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000690 if (MAI->getData64bitsDirective()) {
691 O << MAI->getData64bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000692 PrintHex(Value);
693 } else {
694 if (TM.getTargetData()->isBigEndian()) {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000695 EmitInt32(unsigned(Value >> 32)); O << '\n';
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000696 EmitInt32(unsigned(Value));
697 } else {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000698 EmitInt32(unsigned(Value)); O << '\n';
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000699 EmitInt32(unsigned(Value >> 32));
700 }
701 }
702}
703
704/// toOctal - Convert the low order bits of X into an octal digit.
705///
706static inline char toOctal(int X) {
707 return (X&7)+'0';
708}
709
710/// printStringChar - Print a char, escaped if necessary.
711///
David Greene71847812009-07-14 20:18:05 +0000712static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000713 if (C == '"') {
714 O << "\\\"";
715 } else if (C == '\\') {
716 O << "\\\\";
Chris Lattnerbbfa2442009-01-22 23:38:45 +0000717 } else if (isprint((unsigned char)C)) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000718 O << C;
719 } else {
720 switch(C) {
721 case '\b': O << "\\b"; break;
722 case '\f': O << "\\f"; break;
723 case '\n': O << "\\n"; break;
724 case '\r': O << "\\r"; break;
725 case '\t': O << "\\t"; break;
726 default:
727 O << '\\';
728 O << toOctal(C >> 6);
729 O << toOctal(C >> 3);
730 O << toOctal(C >> 0);
731 break;
732 }
733 }
734}
735
736/// EmitString - Emit a string with quotes and a null terminator.
737/// Special characters are emitted properly.
738/// \literal (Eg. '\t') \endliteral
Devang Patele9a05972009-11-24 19:42:17 +0000739void AsmPrinter::EmitString(const StringRef String) const {
Dan Gohman24f8e292009-11-13 21:55:31 +0000740 EmitString(String.data(), String.size());
Bill Wendlingf34be822009-04-09 23:51:31 +0000741}
742
743void AsmPrinter::EmitString(const char *String, unsigned Size) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000744 const char* AscizDirective = MAI->getAscizDirective();
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000745 if (AscizDirective)
746 O << AscizDirective;
747 else
Chris Lattner33adcfb2009-08-22 21:43:10 +0000748 O << MAI->getAsciiDirective();
Dan Gohmand19a53b2008-06-30 22:03:41 +0000749 O << '\"';
Bill Wendlingf34be822009-04-09 23:51:31 +0000750 for (unsigned i = 0; i < Size; ++i)
Chris Lattnera118c2e2009-04-08 00:28:38 +0000751 printStringChar(O, String[i]);
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000752 if (AscizDirective)
Dan Gohmand19a53b2008-06-30 22:03:41 +0000753 O << '\"';
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000754 else
755 O << "\\0\"";
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000756}
757
758
Dan Gohman189f80d2007-09-24 20:58:13 +0000759/// EmitFile - Emit a .file directive.
760void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
761 O << "\t.file\t" << Number << " \"";
Chris Lattnera118c2e2009-04-08 00:28:38 +0000762 for (unsigned i = 0, N = Name.size(); i < N; ++i)
763 printStringChar(O, Name[i]);
Dan Gohmand19a53b2008-06-30 22:03:41 +0000764 O << '\"';
Dan Gohman189f80d2007-09-24 20:58:13 +0000765}
766
767
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000768//===----------------------------------------------------------------------===//
769
Chris Lattner3a420532007-05-31 18:57:45 +0000770// EmitAlignment - Emit an alignment directive to the specified power of
771// two boundary. For example, if you pass in 3 here, you will get an 8
772// byte alignment. If a global value is specified, and if that global has
773// an explicit alignment requested, it will unconditionally override the
774// alignment request. However, if ForcedAlignBits is specified, this value
775// has final say: the ultimate alignment will be the max of ForcedAlignBits
776// and the alignment computed with NumBits and the global.
777//
778// The algorithm is:
779// Align = NumBits;
780// if (GV && GV->hasalignment) Align = GV->getalignment();
781// Align = std::max(Align, ForcedAlignBits);
782//
783void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
Evan Cheng05548eb2008-02-29 19:36:59 +0000784 unsigned ForcedAlignBits,
785 bool UseFillExpr) const {
Dale Johannesen00d56b92007-04-23 23:33:31 +0000786 if (GV && GV->getAlignment())
Chris Lattner3a420532007-05-31 18:57:45 +0000787 NumBits = Log2_32(GV->getAlignment());
788 NumBits = std::max(NumBits, ForcedAlignBits);
789
Chris Lattner2a21c6e2005-11-10 18:09:27 +0000790 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattner663c2d22009-08-19 06:12:02 +0000791
792 unsigned FillValue = 0;
Chris Lattnerdabf07c2009-08-18 06:15:16 +0000793 if (getCurrentSection()->getKind().isText())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000794 FillValue = MAI->getTextAlignFillValue();
Chris Lattner663c2d22009-08-19 06:12:02 +0000795
796 OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0);
Chris Lattnerbfddc202004-08-17 19:14:29 +0000797}
David Greenea5bb59f2009-08-05 21:00:52 +0000798
Chris Lattner25045bd2005-11-21 07:51:36 +0000799/// EmitZeros - Emit a block of zeros.
Chris Lattner7d057a32004-08-17 21:38:40 +0000800///
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000801void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
Chris Lattner7d057a32004-08-17 21:38:40 +0000802 if (NumZeros) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000803 if (MAI->getZeroDirective()) {
804 O << MAI->getZeroDirective() << NumZeros;
805 if (MAI->getZeroDirectiveSuffix())
806 O << MAI->getZeroDirectiveSuffix();
Dan Gohmand19a53b2008-06-30 22:03:41 +0000807 O << '\n';
Jeff Cohenc6a057b2006-05-02 03:46:13 +0000808 } else {
Chris Lattner7d057a32004-08-17 21:38:40 +0000809 for (; NumZeros; --NumZeros)
Chris Lattner33adcfb2009-08-22 21:43:10 +0000810 O << MAI->getData8bitsDirective(AddrSpace) << "0\n";
Chris Lattner7d057a32004-08-17 21:38:40 +0000811 }
812 }
813}
814
Chris Lattnera80ba712004-08-16 23:15:22 +0000815// Print out the specified constant, without a storage class. Only the
816// constants valid in constant expressions can occur here.
Chris Lattner25045bd2005-11-21 07:51:36 +0000817void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000818 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000819 O << '0';
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000820 return;
821 }
822
823 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Scott Michel4315eee2008-06-03 06:18:19 +0000824 O << CI->getZExtValue();
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000825 return;
826 }
827
828 if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina855a5192005-04-02 12:21:51 +0000829 // This is a constant address for a global variable or function. Use the
Chris Lattnerbfd1e502009-09-15 23:11:32 +0000830 // name of the variable or function as the address value.
831 O << Mang->getMangledName(GV);
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000832 return;
833 }
834
835 if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
Dan Gohman6a55e622009-10-30 01:45:18 +0000836 GetBlockAddressSymbol(BA)->print(O, MAI);
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000837 return;
838 }
839
840 const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
841 if (CE == 0) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000842 llvm_unreachable("Unknown constant value!");
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000843 O << '0';
844 return;
845 }
846
847 switch (CE->getOpcode()) {
848 case Instruction::ZExt:
849 case Instruction::SExt:
850 case Instruction::FPTrunc:
851 case Instruction::FPExt:
852 case Instruction::UIToFP:
853 case Instruction::SIToFP:
854 case Instruction::FPToUI:
855 case Instruction::FPToSI:
856 default:
857 llvm_unreachable("FIXME: Don't support this constant cast expr");
858 case Instruction::GetElementPtr: {
859 // generate a symbolic expression for the byte address
860 const TargetData *TD = TM.getTargetData();
861 const Constant *ptrVal = CE->getOperand(0);
862 SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
863 int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
864 idxVec.size());
865 if (Offset == 0)
866 return EmitConstantValueOnly(ptrVal);
867
868 // Truncate/sext the offset to the pointer size.
869 if (TD->getPointerSizeInBits() != 64) {
870 int SExtAmount = 64-TD->getPointerSizeInBits();
871 Offset = (Offset << SExtAmount) >> SExtAmount;
872 }
873
874 if (Offset)
875 O << '(';
876 EmitConstantValueOnly(ptrVal);
877 if (Offset > 0)
878 O << ") + " << Offset;
879 else
880 O << ") - " << -Offset;
881 return;
882 }
883 case Instruction::BitCast:
884 return EmitConstantValueOnly(CE->getOperand(0));
885
886 case Instruction::IntToPtr: {
887 // Handle casts to pointers by changing them into casts to the appropriate
888 // integer type. This promotes constant folding and simplifies this code.
889 const TargetData *TD = TM.getTargetData();
890 Constant *Op = CE->getOperand(0);
891 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
892 false/*ZExt*/);
893 return EmitConstantValueOnly(Op);
894 }
895
896 case Instruction::PtrToInt: {
897 // Support only foldable casts to/from pointers that can be eliminated by
898 // changing the pointer to the appropriately sized integer type.
899 Constant *Op = CE->getOperand(0);
900 const Type *Ty = CE->getType();
901 const TargetData *TD = TM.getTargetData();
902
903 // We can emit the pointer value into this slot if the slot is an
904 // integer slot greater or equal to the size of the pointer.
905 if (TD->getTypeAllocSize(Ty) == TD->getTypeAllocSize(Op->getType()))
906 return EmitConstantValueOnly(Op);
907
908 O << "((";
909 EmitConstantValueOnly(Op);
910 APInt ptrMask =
911 APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Op->getType()));
912
913 SmallString<40> S;
914 ptrMask.toStringUnsigned(S);
915 O << ") & " << S.str() << ')';
916 return;
917 }
918
919 case Instruction::Trunc:
920 // We emit the value and depend on the assembler to truncate the generated
921 // expression properly. This is important for differences between
922 // blockaddress labels. Since the two labels are in the same function, it
923 // is reasonable to treat their delta as a 32-bit value.
924 return EmitConstantValueOnly(CE->getOperand(0));
925
926 case Instruction::Add:
927 case Instruction::Sub:
928 case Instruction::And:
929 case Instruction::Or:
930 case Instruction::Xor:
931 O << '(';
932 EmitConstantValueOnly(CE->getOperand(0));
933 O << ')';
934 switch (CE->getOpcode()) {
935 case Instruction::Add:
936 O << " + ";
937 break;
938 case Instruction::Sub:
939 O << " - ";
940 break;
941 case Instruction::And:
942 O << " & ";
943 break;
944 case Instruction::Or:
945 O << " | ";
946 break;
947 case Instruction::Xor:
948 O << " ^ ";
949 break;
950 default:
951 break;
952 }
953 O << '(';
954 EmitConstantValueOnly(CE->getOperand(1));
955 O << ')';
956 break;
Chris Lattnera80ba712004-08-16 23:15:22 +0000957 }
958}
Chris Lattner1b7e2352004-08-17 06:36:49 +0000959
Chris Lattner2980cef2005-11-10 18:06:33 +0000960/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner1b7e2352004-08-17 06:36:49 +0000961/// the predicate isString is true.
962///
David Greene71847812009-07-14 20:18:05 +0000963static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
Chris Lattner2980cef2005-11-10 18:06:33 +0000964 unsigned LastElt) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000965 assert(CVA->isString() && "Array is not string compatible!");
966
Dan Gohmand19a53b2008-06-30 22:03:41 +0000967 O << '\"';
Chris Lattner2980cef2005-11-10 18:06:33 +0000968 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000969 unsigned char C =
Reid Spencerb83eb642006-10-20 07:07:24 +0000970 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000971 printStringChar(O, C);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000972 }
Dan Gohmand19a53b2008-06-30 22:03:41 +0000973 O << '\"';
Chris Lattner1b7e2352004-08-17 06:36:49 +0000974}
975
Jeff Cohenc884db42006-05-02 01:16:28 +0000976/// EmitString - Emit a zero-byte-terminated string constant.
977///
978void AsmPrinter::EmitString(const ConstantArray *CVA) const {
979 unsigned NumElts = CVA->getNumOperands();
Chris Lattner33adcfb2009-08-22 21:43:10 +0000980 if (MAI->getAscizDirective() && NumElts &&
Reid Spencerb83eb642006-10-20 07:07:24 +0000981 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000982 O << MAI->getAscizDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000983 printAsCString(O, CVA, NumElts-1);
984 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000985 O << MAI->getAsciiDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000986 printAsCString(O, CVA, NumElts);
987 }
Dan Gohmand19a53b2008-06-30 22:03:41 +0000988 O << '\n';
Jeff Cohenc884db42006-05-02 01:16:28 +0000989}
990
Sanjiv Guptad3d96572009-04-28 16:34:20 +0000991void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA,
992 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +0000993 if (CVA->isString()) {
994 EmitString(CVA);
995 } else { // Not a string. Print the values in successive locations
996 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Sanjiv Guptad3d96572009-04-28 16:34:20 +0000997 EmitGlobalConstant(CVA->getOperand(i), AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +0000998 }
999}
1000
1001void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) {
1002 const VectorType *PTy = CP->getType();
1003
1004 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
1005 EmitGlobalConstant(CP->getOperand(I));
1006}
1007
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001008void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
1009 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001010 // Print the fields in successive locations. Pad to align if needed!
1011 const TargetData *TD = TM.getTargetData();
Duncan Sands777d2302009-05-09 07:06:46 +00001012 unsigned Size = TD->getTypeAllocSize(CVS->getType());
Dan Gohman00d448a2008-12-22 21:14:27 +00001013 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
1014 uint64_t sizeSoFar = 0;
1015 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
1016 const Constant* field = CVS->getOperand(i);
1017
1018 // Check if padding is needed and insert one or more 0s.
Duncan Sands777d2302009-05-09 07:06:46 +00001019 uint64_t fieldSize = TD->getTypeAllocSize(field->getType());
Dan Gohman00d448a2008-12-22 21:14:27 +00001020 uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
1021 - cvsLayout->getElementOffset(i)) - fieldSize;
1022 sizeSoFar += fieldSize + padSize;
1023
1024 // Now print the actual field value.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001025 EmitGlobalConstant(field, AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001026
1027 // Insert padding - this may include padding to increase the size of the
1028 // current field up to the ABI size (if the struct is not packed) as well
1029 // as padding to ensure that the next field starts at the right offset.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001030 EmitZeros(padSize, AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001031 }
1032 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
1033 "Layout of constant struct may be incorrect!");
1034}
1035
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001036void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
1037 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001038 // FP Constants are printed as integer constants to avoid losing
1039 // precision...
Owen Anderson1d0be152009-08-13 21:58:54 +00001040 LLVMContext &Context = CFP->getContext();
Dan Gohman00d448a2008-12-22 21:14:27 +00001041 const TargetData *TD = TM.getTargetData();
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001042 if (CFP->getType()->isDoubleTy()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001043 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
1044 uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
Chris Lattner33adcfb2009-08-22 21:43:10 +00001045 if (MAI->getData64bitsDirective(AddrSpace)) {
1046 O << MAI->getData64bitsDirective(AddrSpace) << i;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001047 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001048 O.PadToColumn(MAI->getCommentColumn());
1049 O << MAI->getCommentString() << " double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001050 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001051 O << '\n';
1052 } else if (TD->isBigEndian()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001053 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001054 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001055 O.PadToColumn(MAI->getCommentColumn());
1056 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001057 << " most significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001058 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001059 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001060 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001061 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001062 O.PadToColumn(MAI->getCommentColumn());
1063 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001064 << " least significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001065 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001066 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001067 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001068 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001069 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001070 O.PadToColumn(MAI->getCommentColumn());
1071 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001072 << " least significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001073 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001074 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001075 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001076 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001077 O.PadToColumn(MAI->getCommentColumn());
1078 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001079 << " most significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001080 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001081 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001082 }
1083 return;
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001084 }
1085
1086 if (CFP->getType()->isFloatTy()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001087 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
Chris Lattner33adcfb2009-08-22 21:43:10 +00001088 O << MAI->getData32bitsDirective(AddrSpace)
Evan Chengf1c0ae92009-03-24 00:17:40 +00001089 << CFP->getValueAPF().bitcastToAPInt().getZExtValue();
Dan Gohmana12e9d72009-08-12 18:32:22 +00001090 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001091 O.PadToColumn(MAI->getCommentColumn());
1092 O << MAI->getCommentString() << " float " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001093 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001094 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001095 return;
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001096 }
1097
1098 if (CFP->getType()->isX86_FP80Ty()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001099 // all long double variants are printed as hex
1100 // api needed to prevent premature destruction
1101 APInt api = CFP->getValueAPF().bitcastToAPInt();
1102 const uint64_t *p = api.getRawData();
1103 // Convert to double so we can print the approximate val as a comment.
1104 APFloat DoubleVal = CFP->getValueAPF();
1105 bool ignored;
1106 DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1107 &ignored);
1108 if (TD->isBigEndian()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001109 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001110 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001111 O.PadToColumn(MAI->getCommentColumn());
1112 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001113 << " most significant halfword of x86_fp80 ~"
Evan Chengf1c0ae92009-03-24 00:17:40 +00001114 << DoubleVal.convertToDouble();
Dan Gohmana12e9d72009-08-12 18:32:22 +00001115 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001116 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001117 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001118 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001119 O.PadToColumn(MAI->getCommentColumn());
1120 O << MAI->getCommentString() << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001121 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001122 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001123 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001124 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001125 O.PadToColumn(MAI->getCommentColumn());
1126 O << MAI->getCommentString() << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001127 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001128 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001129 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001130 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001131 O.PadToColumn(MAI->getCommentColumn());
1132 O << MAI->getCommentString() << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001133 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001134 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001135 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001136 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001137 O.PadToColumn(MAI->getCommentColumn());
1138 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001139 << " least significant halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001140 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001141 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001142 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001143 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001144 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001145 O.PadToColumn(MAI->getCommentColumn());
1146 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001147 << " least significant halfword of x86_fp80 ~"
Evan Chengf1c0ae92009-03-24 00:17:40 +00001148 << DoubleVal.convertToDouble();
Dan Gohmana12e9d72009-08-12 18:32:22 +00001149 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001150 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001151 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001152 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001153 O.PadToColumn(MAI->getCommentColumn());
1154 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001155 << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001156 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001157 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001158 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001159 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001160 O.PadToColumn(MAI->getCommentColumn());
1161 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001162 << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001163 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001164 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001165 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001166 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001167 O.PadToColumn(MAI->getCommentColumn());
1168 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001169 << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001170 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001171 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001172 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001173 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001174 O.PadToColumn(MAI->getCommentColumn());
1175 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001176 << " most significant halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001177 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001178 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001179 }
Owen Anderson1d0be152009-08-13 21:58:54 +00001180 EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) -
1181 TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001182 return;
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001183 }
1184
1185 if (CFP->getType()->isPPC_FP128Ty()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001186 // all long double variants are printed as hex
1187 // api needed to prevent premature destruction
1188 APInt api = CFP->getValueAPF().bitcastToAPInt();
1189 const uint64_t *p = api.getRawData();
1190 if (TD->isBigEndian()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001191 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001192 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001193 O.PadToColumn(MAI->getCommentColumn());
1194 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001195 << " most significant word of ppc_fp128";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001196 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001197 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001198 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001199 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001200 O.PadToColumn(MAI->getCommentColumn());
1201 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001202 << " next word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001203 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001204 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001205 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001206 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001207 O.PadToColumn(MAI->getCommentColumn());
1208 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001209 << " next word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001210 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001211 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001212 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001213 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001214 O.PadToColumn(MAI->getCommentColumn());
1215 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001216 << " least significant word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001217 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001218 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001219 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001220 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001221 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001222 O.PadToColumn(MAI->getCommentColumn());
1223 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001224 << " least significant word of ppc_fp128";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001225 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001226 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001227 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001228 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001229 O.PadToColumn(MAI->getCommentColumn());
1230 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001231 << " next word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001232 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001233 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001234 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001235 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001236 O.PadToColumn(MAI->getCommentColumn());
1237 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001238 << " next word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001239 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001240 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001241 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001242 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001243 O.PadToColumn(MAI->getCommentColumn());
1244 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001245 << " most significant word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001246 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001247 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001248 }
1249 return;
Torok Edwinc23197a2009-07-14 16:55:14 +00001250 } else llvm_unreachable("Floating point constant type not handled");
Dan Gohman00d448a2008-12-22 21:14:27 +00001251}
1252
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001253void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
1254 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001255 const TargetData *TD = TM.getTargetData();
1256 unsigned BitWidth = CI->getBitWidth();
Chris Lattner38c2b0a2010-01-13 04:39:46 +00001257 assert((BitWidth & 63) == 0 && "only support multiples of 64-bits");
Dan Gohman00d448a2008-12-22 21:14:27 +00001258
1259 // We don't expect assemblers to support integer data directives
1260 // for more than 64 bits, so we emit the data in at most 64-bit
1261 // quantities at a time.
1262 const uint64_t *RawData = CI->getValue().getRawData();
1263 for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
1264 uint64_t Val;
1265 if (TD->isBigEndian())
1266 Val = RawData[e - i - 1];
1267 else
1268 Val = RawData[i];
1269
Chris Lattner5979dff2010-01-13 04:38:16 +00001270 if (MAI->getData64bitsDirective(AddrSpace)) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001271 O << MAI->getData64bitsDirective(AddrSpace) << Val << '\n';
Chris Lattner5979dff2010-01-13 04:38:16 +00001272 continue;
Dan Gohman00d448a2008-12-22 21:14:27 +00001273 }
Chris Lattner5979dff2010-01-13 04:38:16 +00001274
1275 // Emit two 32-bit chunks, order depends on endianness.
1276 unsigned FirstChunk = unsigned(Val), SecondChunk = unsigned(Val >> 32);
1277 const char *FirstName = " least", *SecondName = " most";
1278 if (TD->isBigEndian()) {
1279 std::swap(FirstChunk, SecondChunk);
1280 std::swap(FirstName, SecondName);
1281 }
1282
1283 O << MAI->getData32bitsDirective(AddrSpace) << FirstChunk;
1284 if (VerboseAsm) {
1285 O.PadToColumn(MAI->getCommentColumn());
1286 O << MAI->getCommentString()
1287 << FirstName << " significant half of i64 " << Val;
1288 }
1289 O << '\n';
1290
1291 O << MAI->getData32bitsDirective(AddrSpace) << SecondChunk;
1292 if (VerboseAsm) {
1293 O.PadToColumn(MAI->getCommentColumn());
1294 O << MAI->getCommentString()
1295 << SecondName << " significant half of i64 " << Val;
1296 }
1297 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001298 }
1299}
1300
Chris Lattner25045bd2005-11-21 07:51:36 +00001301/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001302void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
Owen Andersona69571c2006-05-03 01:29:57 +00001303 const TargetData *TD = TM.getTargetData();
Dan Gohman00d448a2008-12-22 21:14:27 +00001304 const Type *type = CV->getType();
Duncan Sands777d2302009-05-09 07:06:46 +00001305 unsigned Size = TD->getTypeAllocSize(type);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001306
Chris Lattnerbd1d3822004-10-16 18:19:26 +00001307 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001308 EmitZeros(Size, AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001309 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001310 }
1311
1312 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
Sanjiv Guptad3d96572009-04-28 16:34:20 +00001313 EmitGlobalConstantArray(CVA , AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001314 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001315 }
1316
1317 if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001318 EmitGlobalConstantStruct(CVS, AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001319 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001320 }
1321
1322 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001323 EmitGlobalConstantFP(CFP, AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001324 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001325 }
1326
1327 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1328 // If we can directly emit an 8-byte constant, do it.
1329 if (Size == 8)
1330 if (const char *Data64Dir = MAI->getData64bitsDirective(AddrSpace)) {
1331 O << Data64Dir << CI->getZExtValue() << '\n';
1332 return;
1333 }
1334
Dan Gohman00d448a2008-12-22 21:14:27 +00001335 // Small integers are handled below; large integers are handled here.
1336 if (Size > 4) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001337 EmitGlobalConstantLargeInt(CI, AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001338 return;
1339 }
Chris Lattner3cc3a002010-01-13 04:34:19 +00001340 }
1341
1342 if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001343 EmitGlobalConstantVector(CP);
Nate Begeman8cfa57b2005-12-06 06:18:55 +00001344 return;
Chris Lattner1b7e2352004-08-17 06:36:49 +00001345 }
1346
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001347 printDataDirective(type, AddrSpace);
Chris Lattner25045bd2005-11-21 07:51:36 +00001348 EmitConstantValueOnly(CV);
Evan Chengf1c0ae92009-03-24 00:17:40 +00001349 if (VerboseAsm) {
1350 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1351 SmallString<40> S;
1352 CI->getValue().toStringUnsigned(S, 16);
Chris Lattner33adcfb2009-08-22 21:43:10 +00001353 O.PadToColumn(MAI->getCommentColumn());
1354 O << MAI->getCommentString() << " 0x" << S.str();
Evan Chengf1c0ae92009-03-24 00:17:40 +00001355 }
Scott Micheleefc8452008-06-03 15:39:51 +00001356 }
Dan Gohmand19a53b2008-06-30 22:03:41 +00001357 O << '\n';
Chris Lattner1b7e2352004-08-17 06:36:49 +00001358}
Chris Lattner0264d1a2006-01-27 02:10:10 +00001359
Chris Lattnerfad86b02008-08-17 07:19:36 +00001360void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
Evan Chengd6594ae2006-09-12 21:00:35 +00001361 // Target doesn't support this yet!
Torok Edwinc23197a2009-07-14 16:55:14 +00001362 llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
Evan Chengd6594ae2006-09-12 21:00:35 +00001363}
1364
Chris Lattner3ce9b672006-09-26 23:59:50 +00001365/// PrintSpecial - Print information related to the specified machine instr
1366/// that is independent of the operand, and may be independent of the instr
1367/// itself. This can be useful for portably encoding the comment character
1368/// or other bits of target-specific knowledge into the asmstrings. The
1369/// syntax used is ${:comment}. Targets can override this to add support
1370/// for their own strange codes.
Chris Lattner3e0cc262009-03-10 05:37:13 +00001371void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
Chris Lattnerbae02cf2006-09-27 00:06:07 +00001372 if (!strcmp(Code, "private")) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001373 O << MAI->getPrivateGlobalPrefix();
Chris Lattnerbae02cf2006-09-27 00:06:07 +00001374 } else if (!strcmp(Code, "comment")) {
Evan Chengf1c0ae92009-03-24 00:17:40 +00001375 if (VerboseAsm)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001376 O << MAI->getCommentString();
Chris Lattner3ce9b672006-09-26 23:59:50 +00001377 } else if (!strcmp(Code, "uid")) {
Chris Lattnerb6a24bf2007-02-05 21:23:52 +00001378 // Comparing the address of MI isn't sufficient, because machineinstrs may
1379 // be allocated to the same address across functions.
1380 const Function *ThisF = MI->getParent()->getParent()->getFunction();
1381
Owen Andersonbd58edf2009-06-24 22:28:12 +00001382 // If this is a new LastFn instruction, bump the counter.
1383 if (LastMI != MI || LastFn != ThisF) {
Chris Lattnerb6a24bf2007-02-05 21:23:52 +00001384 ++Counter;
1385 LastMI = MI;
Owen Andersonbd58edf2009-06-24 22:28:12 +00001386 LastFn = ThisF;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +00001387 }
Chris Lattner3ce9b672006-09-26 23:59:50 +00001388 O << Counter;
1389 } else {
Torok Edwin7d696d82009-07-11 13:10:19 +00001390 std::string msg;
1391 raw_string_ostream Msg(msg);
1392 Msg << "Unknown special formatter '" << Code
Bill Wendlinge8156192006-12-07 01:30:32 +00001393 << "' for machine instr: " << *MI;
Torok Edwin7d696d82009-07-11 13:10:19 +00001394 llvm_report_error(Msg.str());
Chris Lattner3ce9b672006-09-26 23:59:50 +00001395 }
1396}
1397
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +00001398/// processDebugLoc - Processes the debug information of each machine
1399/// instruction's DebugLoc.
Devang Patelaf0e2722009-10-06 02:19:11 +00001400void AsmPrinter::processDebugLoc(const MachineInstr *MI,
1401 bool BeforePrintingInsn) {
Devang Patel53bb5c92009-11-10 23:06:00 +00001402 if (!MAI || !DW || !MAI->doesSupportDebugInformation()
1403 || !DW->ShouldEmitDwarfDebug())
Chris Lattnerd2503292009-08-05 04:09:18 +00001404 return;
Devang Patelb0fdedb2009-09-30 23:12:50 +00001405 DebugLoc DL = MI->getDebugLoc();
Devang Patel53bb5c92009-11-10 23:06:00 +00001406 if (DL.isUnknown())
1407 return;
Devang Patel6b61f582010-01-16 06:09:35 +00001408 DILocation CurDLT = MF->getDILocation(DL);
1409 if (CurDLT.getScope().isNull())
Devang Patel53bb5c92009-11-10 23:06:00 +00001410 return;
1411
1412 if (BeforePrintingInsn) {
Devang Patel6b61f582010-01-16 06:09:35 +00001413 if (CurDLT.getNode() != PrevDLT.getNode()) {
1414 unsigned L = DW->RecordSourceLine(CurDLT.getLineNumber(),
1415 CurDLT.getColumnNumber(),
1416 CurDLT.getScope().getNode());
Devang Patel53bb5c92009-11-10 23:06:00 +00001417 printLabel(L);
Dan Gohmaneecb9912009-12-05 01:42:34 +00001418 O << '\n';
Devang Patel53bb5c92009-11-10 23:06:00 +00001419 DW->BeginScope(MI, L);
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +00001420 PrevDLT = CurDLT;
1421 }
Devang Patel53bb5c92009-11-10 23:06:00 +00001422 } else {
1423 // After printing instruction
1424 DW->EndScope(MI);
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +00001425 }
1426}
Chris Lattner3ce9b672006-09-26 23:59:50 +00001427
Devang Patel53bb5c92009-11-10 23:06:00 +00001428
Chris Lattner0264d1a2006-01-27 02:10:10 +00001429/// printInlineAsm - This method formats and prints the specified machine
1430/// instruction that is an inline asm.
1431void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattnerf2b67cf2006-01-30 23:00:08 +00001432 unsigned NumOperands = MI->getNumOperands();
1433
1434 // Count the number of register definitions.
1435 unsigned NumDefs = 0;
Dan Gohmand735b802008-10-03 15:45:36 +00001436 for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
Chris Lattner67942f52006-09-05 20:02:51 +00001437 ++NumDefs)
Chris Lattnerf2b67cf2006-01-30 23:00:08 +00001438 assert(NumDefs != NumOperands-1 && "No asm string?");
1439
Dan Gohmand735b802008-10-03 15:45:36 +00001440 assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
Chris Lattner66099132006-02-01 22:41:11 +00001441
1442 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattnerf2b67cf2006-01-30 23:00:08 +00001443 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattner66099132006-02-01 22:41:11 +00001444
Dan Gohman40c57862009-11-06 00:04:54 +00001445 O << '\t';
1446
Dale Johannesenba2a0b92008-01-29 02:21:21 +00001447 // If this asmstr is empty, just print the #APP/#NOAPP markers.
1448 // These are useful to see where empty asm's wound up.
Chris Lattnerf26f5dd2006-07-28 00:17:20 +00001449 if (AsmStr[0] == 0) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001450 O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
1451 O << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
Chris Lattnerf26f5dd2006-07-28 00:17:20 +00001452 return;
1453 }
1454
Chris Lattner33adcfb2009-08-22 21:43:10 +00001455 O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
Chris Lattnerf26f5dd2006-07-28 00:17:20 +00001456
Bill Wendlingeb9a42c2007-01-16 03:42:04 +00001457 // The variant of the current asmprinter.
Chris Lattner33adcfb2009-08-22 21:43:10 +00001458 int AsmPrinterVariant = MAI->getAssemblerDialect();
Bill Wendlingeb9a42c2007-01-16 03:42:04 +00001459
Chris Lattner66099132006-02-01 22:41:11 +00001460 int CurVariant = -1; // The number of the {.|.|.} region we are in.
1461 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner2cc2f662006-02-01 01:28:23 +00001462
Chris Lattner66099132006-02-01 22:41:11 +00001463 while (*LastEmitted) {
1464 switch (*LastEmitted) {
1465 default: {
1466 // Not a special case, emit the string section literally.
1467 const char *LiteralEnd = LastEmitted+1;
1468 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattner1c059972006-05-05 21:47:05 +00001469 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattner66099132006-02-01 22:41:11 +00001470 ++LiteralEnd;
1471 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1472 O.write(LastEmitted, LiteralEnd-LastEmitted);
1473 LastEmitted = LiteralEnd;
1474 break;
1475 }
Chris Lattner1c059972006-05-05 21:47:05 +00001476 case '\n':
1477 ++LastEmitted; // Consume newline character.
Dan Gohmand19a53b2008-06-30 22:03:41 +00001478 O << '\n'; // Indent code with newline.
Chris Lattner1c059972006-05-05 21:47:05 +00001479 break;
Chris Lattner66099132006-02-01 22:41:11 +00001480 case '$': {
1481 ++LastEmitted; // Consume '$' character.
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001482 bool Done = true;
1483
1484 // Handle escapes.
1485 switch (*LastEmitted) {
1486 default: Done = false; break;
1487 case '$': // $$ -> $
Chris Lattner66099132006-02-01 22:41:11 +00001488 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1489 O << '$';
1490 ++LastEmitted; // Consume second '$' character.
1491 break;
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001492 case '(': // $( -> same as GCC's { character.
1493 ++LastEmitted; // Consume '(' character.
1494 if (CurVariant != -1) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001495 llvm_report_error("Nested variants found in inline asm string: '"
1496 + std::string(AsmStr) + "'");
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001497 }
1498 CurVariant = 0; // We're in the first variant now.
1499 break;
1500 case '|':
1501 ++LastEmitted; // consume '|' character.
Dale Johannesen8b1e0542008-10-10 21:04:42 +00001502 if (CurVariant == -1)
1503 O << '|'; // this is gcc's behavior for | outside a variant
1504 else
1505 ++CurVariant; // We're in the next variant.
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001506 break;
1507 case ')': // $) -> same as GCC's } char.
1508 ++LastEmitted; // consume ')' character.
Dale Johannesen8b1e0542008-10-10 21:04:42 +00001509 if (CurVariant == -1)
1510 O << '}'; // this is gcc's behavior for } outside a variant
1511 else
1512 CurVariant = -1;
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001513 break;
Chris Lattner66099132006-02-01 22:41:11 +00001514 }
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001515 if (Done) break;
Chris Lattner66099132006-02-01 22:41:11 +00001516
1517 bool HasCurlyBraces = false;
1518 if (*LastEmitted == '{') { // ${variable}
1519 ++LastEmitted; // Consume '{' character.
1520 HasCurlyBraces = true;
1521 }
1522
Chris Lattner3e0cc262009-03-10 05:37:13 +00001523 // If we have ${:foo}, then this is not a real operand reference, it is a
1524 // "magic" string reference, just like in .td files. Arrange to call
1525 // PrintSpecial.
1526 if (HasCurlyBraces && *LastEmitted == ':') {
1527 ++LastEmitted;
1528 const char *StrStart = LastEmitted;
1529 const char *StrEnd = strchr(StrStart, '}');
1530 if (StrEnd == 0) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001531 llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
1532 + std::string(AsmStr) + "'");
Chris Lattner3e0cc262009-03-10 05:37:13 +00001533 }
1534
1535 std::string Val(StrStart, StrEnd);
1536 PrintSpecial(MI, Val.c_str());
1537 LastEmitted = StrEnd+1;
1538 break;
1539 }
1540
Chris Lattner66099132006-02-01 22:41:11 +00001541 const char *IDStart = LastEmitted;
1542 char *IDEnd;
Chris Lattnerfad29122007-01-23 00:36:17 +00001543 errno = 0;
Chris Lattner66099132006-02-01 22:41:11 +00001544 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1545 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001546 llvm_report_error("Bad $ operand number in inline asm string: '"
1547 + std::string(AsmStr) + "'");
Chris Lattner66099132006-02-01 22:41:11 +00001548 }
1549 LastEmitted = IDEnd;
1550
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001551 char Modifier[2] = { 0, 0 };
1552
Chris Lattner66099132006-02-01 22:41:11 +00001553 if (HasCurlyBraces) {
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001554 // If we have curly braces, check for a modifier character. This
1555 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1556 if (*LastEmitted == ':') {
1557 ++LastEmitted; // Consume ':' character.
1558 if (*LastEmitted == 0) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001559 llvm_report_error("Bad ${:} expression in inline asm string: '"
1560 + std::string(AsmStr) + "'");
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001561 }
1562
1563 Modifier[0] = *LastEmitted;
1564 ++LastEmitted; // Consume modifier character.
1565 }
1566
Chris Lattner66099132006-02-01 22:41:11 +00001567 if (*LastEmitted != '}') {
Torok Edwin7d696d82009-07-11 13:10:19 +00001568 llvm_report_error("Bad ${} expression in inline asm string: '"
1569 + std::string(AsmStr) + "'");
Chris Lattner66099132006-02-01 22:41:11 +00001570 }
1571 ++LastEmitted; // Consume '}' character.
1572 }
1573
1574 if ((unsigned)Val >= NumOperands-1) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001575 llvm_report_error("Invalid $ operand number in inline asm string: '"
1576 + std::string(AsmStr) + "'");
Chris Lattner66099132006-02-01 22:41:11 +00001577 }
1578
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001579 // Okay, we finally have a value number. Ask the target to print this
Chris Lattner66099132006-02-01 22:41:11 +00001580 // operand!
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001581 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1582 unsigned OpNo = 1;
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001583
1584 bool Error = false;
1585
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001586 // Scan to find the machine operand number for the operand.
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001587 for (; Val; --Val) {
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001588 if (OpNo >= MI->getNumOperands()) break;
Chris Lattner9e330492007-12-30 20:50:28 +00001589 unsigned OpFlags = MI->getOperand(OpNo).getImm();
Evan Cheng697cbbf2009-03-20 18:03:34 +00001590 OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001591 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001592
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001593 if (OpNo >= MI->getNumOperands()) {
1594 Error = true;
Chris Lattnerdd260332006-02-24 20:21:58 +00001595 } else {
Chris Lattner9e330492007-12-30 20:50:28 +00001596 unsigned OpFlags = MI->getOperand(OpNo).getImm();
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001597 ++OpNo; // Skip over the ID number.
1598
Dale Johanneseneb57ea72007-11-05 21:20:28 +00001599 if (Modifier[0]=='l') // labels are target independent
Chris Lattner325d3dc2009-09-13 17:14:04 +00001600 GetMBBSymbol(MI->getOperand(OpNo).getMBB()
1601 ->getNumber())->print(O, MAI);
Dale Johanneseneb57ea72007-11-05 21:20:28 +00001602 else {
1603 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
Dale Johannesen86b49f82008-09-24 01:07:17 +00001604 if ((OpFlags & 7) == 4) {
Dale Johanneseneb57ea72007-11-05 21:20:28 +00001605 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1606 Modifier[0] ? Modifier : 0);
1607 } else {
1608 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1609 Modifier[0] ? Modifier : 0);
1610 }
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001611 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001612 }
1613 if (Error) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001614 std::string msg;
1615 raw_string_ostream Msg(msg);
1616 Msg << "Invalid operand found in inline asm: '"
Bill Wendlinge8156192006-12-07 01:30:32 +00001617 << AsmStr << "'\n";
Torok Edwin7d696d82009-07-11 13:10:19 +00001618 MI->print(Msg);
1619 llvm_report_error(Msg.str());
Chris Lattner66099132006-02-01 22:41:11 +00001620 }
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001621 }
Chris Lattner66099132006-02-01 22:41:11 +00001622 break;
1623 }
Chris Lattner66099132006-02-01 22:41:11 +00001624 }
1625 }
Chris Lattnerc5ea2632009-09-09 23:14:36 +00001626 O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd();
Chris Lattner66099132006-02-01 22:41:11 +00001627}
1628
Evan Chengda47e6e2008-03-15 00:03:38 +00001629/// printImplicitDef - This method prints the specified machine instruction
1630/// that is an implicit def.
1631void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
Chris Lattnerc5ea2632009-09-09 23:14:36 +00001632 if (!VerboseAsm) return;
1633 O.PadToColumn(MAI->getCommentColumn());
1634 O << MAI->getCommentString() << " implicit-def: "
Chris Lattnerf806c232009-09-13 19:48:37 +00001635 << TRI->getName(MI->getOperand(0).getReg());
Evan Chengda47e6e2008-03-15 00:03:38 +00001636}
1637
Jakob Stoklund Olesenad682642009-11-04 19:24:37 +00001638void AsmPrinter::printKill(const MachineInstr *MI) const {
1639 if (!VerboseAsm) return;
1640 O.PadToColumn(MAI->getCommentColumn());
1641 O << MAI->getCommentString() << " kill:";
1642 for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) {
1643 const MachineOperand &op = MI->getOperand(n);
1644 assert(op.isReg() && "KILL instruction must have only register operands");
1645 O << ' ' << TRI->getName(op.getReg()) << (op.isDef() ? "<def>" : "<kill>");
1646 }
1647}
1648
Jim Laskey1ee29252007-01-26 14:34:52 +00001649/// printLabel - This method prints a local label used by debug and
1650/// exception handling tables.
1651void AsmPrinter::printLabel(const MachineInstr *MI) const {
Dan Gohman528bc022008-07-01 00:16:26 +00001652 printLabel(MI->getOperand(0).getImm());
Jim Laskey1ee29252007-01-26 14:34:52 +00001653}
1654
Evan Cheng1b08bbc2008-02-01 09:10:45 +00001655void AsmPrinter::printLabel(unsigned Id) const {
Chris Lattnerc5ea2632009-09-09 23:14:36 +00001656 O << MAI->getPrivateGlobalPrefix() << "label" << Id << ':';
Evan Cheng1b08bbc2008-02-01 09:10:45 +00001657}
1658
Chris Lattner66099132006-02-01 22:41:11 +00001659/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1660/// instruction, using the specified assembler variant. Targets should
Dale Johannesencf0b7662010-01-14 21:50:17 +00001661/// override this to format as appropriate.
Chris Lattner66099132006-02-01 22:41:11 +00001662bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001663 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattner66099132006-02-01 22:41:11 +00001664 // Target doesn't support this yet!
1665 return true;
Chris Lattner0264d1a2006-01-27 02:10:10 +00001666}
Chris Lattnerdd260332006-02-24 20:21:58 +00001667
1668bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1669 unsigned AsmVariant,
1670 const char *ExtraCode) {
1671 // Target doesn't support this yet!
1672 return true;
1673}
Nate Begeman37efe672006-04-22 18:53:45 +00001674
Dan Gohman29cbade2009-11-20 23:18:13 +00001675MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA,
1676 const char *Suffix) const {
1677 return GetBlockAddressSymbol(BA->getFunction(), BA->getBasicBlock(), Suffix);
Dan Gohman8c2b5252009-10-30 01:27:03 +00001678}
1679
1680MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
Dan Gohman29cbade2009-11-20 23:18:13 +00001681 const BasicBlock *BB,
1682 const char *Suffix) const {
Dan Gohman8c2b5252009-10-30 01:27:03 +00001683 assert(BB->hasName() &&
1684 "Address of anonymous basic block not supported yet!");
1685
Dan Gohman568a3be2009-11-05 23:14:35 +00001686 // This code must use the function name itself, and not the function number,
1687 // since it must be possible to generate the label name from within other
1688 // functions.
Chris Lattner2f8cc262010-01-13 07:30:49 +00001689 SmallString<60> FnName;
1690 Mang->getNameWithPrefix(FnName, F, false);
Dan Gohman8c2b5252009-10-30 01:27:03 +00001691
Chris Lattner2f8cc262010-01-13 07:30:49 +00001692 // FIXME: THIS IS BROKEN IF THE LLVM BASIC BLOCK DOESN'T HAVE A NAME!
Chris Lattner48130352010-01-13 06:38:18 +00001693 SmallString<60> NameResult;
Chris Lattner2f8cc262010-01-13 07:30:49 +00001694 Mang->getNameWithPrefix(NameResult,
1695 StringRef("BA") + Twine((unsigned)FnName.size()) +
1696 "_" + FnName.str() + "_" + BB->getName() + Suffix,
1697 Mangler::Private);
Dan Gohman568a3be2009-11-05 23:14:35 +00001698
Chris Lattner48130352010-01-13 06:38:18 +00001699 return OutContext.GetOrCreateSymbol(NameResult.str());
Dan Gohman8c2b5252009-10-30 01:27:03 +00001700}
1701
Chris Lattner7cb384d2009-09-12 23:02:08 +00001702MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
1703 SmallString<60> Name;
1704 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
1705 << getFunctionNumber() << '_' << MBBID;
1706
1707 return OutContext.GetOrCreateSymbol(Name.str());
1708}
1709
Chris Lattner6b04ede2010-01-15 23:18:17 +00001710/// GetGlobalValueSymbol - Return the MCSymbol for the specified global
1711/// value.
1712MCSymbol *AsmPrinter::GetGlobalValueSymbol(const GlobalValue *GV) const {
1713 SmallString<60> NameStr;
1714 Mang->getNameWithPrefix(NameStr, GV, false);
1715 return OutContext.GetOrCreateSymbol(NameStr.str());
1716}
1717
Chris Lattnerd588b972010-01-15 23:25:11 +00001718/// GetPrivateGlobalValueSymbolStub - Return the MCSymbol for a symbol with
1719/// global value name as its base, with the specified suffix, and where the
1720/// symbol is forced to have private linkage.
1721MCSymbol *AsmPrinter::GetPrivateGlobalValueSymbolStub(const GlobalValue *GV,
1722 StringRef Suffix) const {
1723 SmallString<60> NameStr;
1724 Mang->getNameWithPrefix(NameStr, GV, true);
1725 NameStr.append(Suffix.begin(), Suffix.end());
1726 return OutContext.GetOrCreateSymbol(NameStr.str());
1727}
1728
Chris Lattner6b04ede2010-01-15 23:18:17 +00001729/// GetExternalSymbolSymbol - Return the MCSymbol for the specified
1730/// ExternalSymbol.
1731MCSymbol *AsmPrinter::GetExternalSymbolSymbol(StringRef Sym) const {
1732 SmallString<60> NameStr;
1733 Mang->getNameWithPrefix(NameStr, Sym);
1734 return OutContext.GetOrCreateSymbol(NameStr.str());
1735}
1736
Chris Lattner7cb384d2009-09-12 23:02:08 +00001737
Chris Lattner70a54c02009-09-13 18:25:37 +00001738/// EmitBasicBlockStart - This method prints the label for the specified
1739/// MachineBasicBlock, an alignment (if present) and a comment describing
1740/// it if appropriate.
Chris Lattner662316c2009-09-14 03:15:54 +00001741void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
Dan Gohmanb1cac332009-10-30 01:34:35 +00001742 // Emit an alignment directive for this block, if needed.
Chris Lattner70a54c02009-09-13 18:25:37 +00001743 if (unsigned Align = MBB->getAlignment())
1744 EmitAlignment(Log2_32(Align));
Evan Chengfb8075d2008-02-28 00:43:03 +00001745
Dan Gohmanb1cac332009-10-30 01:34:35 +00001746 // If the block has its address taken, emit a special label to satisfy
1747 // references to the block. This is done so that we don't need to
1748 // remember the number of this label, and so that we can make
1749 // forward references to labels without knowing what their numbers
1750 // will be.
Dan Gohman8c2b5252009-10-30 01:27:03 +00001751 if (MBB->hasAddressTaken()) {
1752 GetBlockAddressSymbol(MBB->getBasicBlock()->getParent(),
1753 MBB->getBasicBlock())->print(O, MAI);
1754 O << ':';
1755 if (VerboseAsm) {
1756 O.PadToColumn(MAI->getCommentColumn());
1757 O << MAI->getCommentString() << " Address Taken";
1758 }
1759 O << '\n';
1760 }
1761
Dan Gohmanb1cac332009-10-30 01:34:35 +00001762 // Print the main label for the block.
Dan Gohmane3cc3f32009-10-06 17:38:38 +00001763 if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
1764 if (VerboseAsm)
1765 O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
1766 } else {
1767 GetMBBSymbol(MBB->getNumber())->print(O, MAI);
1768 O << ':';
1769 if (!VerboseAsm)
1770 O << '\n';
1771 }
Chris Lattner70a54c02009-09-13 18:25:37 +00001772
Dan Gohmanb1cac332009-10-30 01:34:35 +00001773 // Print some comments to accompany the label.
Chris Lattner70a54c02009-09-13 18:25:37 +00001774 if (VerboseAsm) {
Dan Gohmane45da0d2009-08-12 18:47:05 +00001775 if (const BasicBlock *BB = MBB->getBasicBlock())
1776 if (BB->hasName()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001777 O.PadToColumn(MAI->getCommentColumn());
1778 O << MAI->getCommentString() << ' ';
Dan Gohman46d50562009-08-12 20:56:56 +00001779 WriteAsOperand(O, BB, /*PrintType=*/false);
Dan Gohmane45da0d2009-08-12 18:47:05 +00001780 }
David Greeneb71d1b22009-08-10 16:38:07 +00001781
Chris Lattner70a54c02009-09-13 18:25:37 +00001782 EmitComments(*MBB);
Dan Gohmane3cc3f32009-10-06 17:38:38 +00001783 O << '\n';
David Greeneb71d1b22009-08-10 16:38:07 +00001784 }
Nate Begeman37efe672006-04-22 18:53:45 +00001785}
Nate Begeman52a51e382006-08-12 21:29:52 +00001786
Evan Chengcc415862007-11-09 01:32:10 +00001787/// printPICJumpTableSetLabel - This method prints a set label for the
1788/// specified MachineBasicBlock for a jumptable entry.
1789void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
1790 const MachineBasicBlock *MBB) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001791 if (!MAI->getSetDirective())
Nate Begeman52a51e382006-08-12 21:29:52 +00001792 return;
1793
Chris Lattner33adcfb2009-08-22 21:43:10 +00001794 O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
Evan Cheng347d39f2007-10-14 05:57:21 +00001795 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
Chris Lattner325d3dc2009-09-13 17:14:04 +00001796 GetMBBSymbol(MBB->getNumber())->print(O, MAI);
Chris Lattner33adcfb2009-08-22 21:43:10 +00001797 O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng347d39f2007-10-14 05:57:21 +00001798 << '_' << uid << '\n';
Nate Begeman52a51e382006-08-12 21:29:52 +00001799}
Evan Chengd6594ae2006-09-12 21:00:35 +00001800
Evan Chengcc415862007-11-09 01:32:10 +00001801void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
1802 const MachineBasicBlock *MBB) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001803 if (!MAI->getSetDirective())
Evan Cheng41349c12006-11-01 09:23:08 +00001804 return;
1805
Chris Lattner33adcfb2009-08-22 21:43:10 +00001806 O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
Evan Cheng347d39f2007-10-14 05:57:21 +00001807 << getFunctionNumber() << '_' << uid << '_' << uid2
1808 << "_set_" << MBB->getNumber() << ',';
Chris Lattner325d3dc2009-09-13 17:14:04 +00001809 GetMBBSymbol(MBB->getNumber())->print(O, MAI);
Chris Lattner33adcfb2009-08-22 21:43:10 +00001810 O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng347d39f2007-10-14 05:57:21 +00001811 << '_' << uid << '_' << uid2 << '\n';
Evan Cheng41349c12006-11-01 09:23:08 +00001812}
1813
Evan Chengd6594ae2006-09-12 21:00:35 +00001814/// printDataDirective - This method prints the asm directive for the
1815/// specified type.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001816void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
Evan Chengd6594ae2006-09-12 21:00:35 +00001817 const TargetData *TD = TM.getTargetData();
1818 switch (type->getTypeID()) {
Chris Lattnerf1cfea22009-07-15 04:42:49 +00001819 case Type::FloatTyID: case Type::DoubleTyID:
1820 case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
1821 assert(0 && "Should have already output floating point constant.");
1822 default:
1823 assert(0 && "Can't handle printing this type of thing");
Reid Spencera54b7cb2007-01-12 07:05:14 +00001824 case Type::IntegerTyID: {
1825 unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1826 if (BitWidth <= 8)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001827 O << MAI->getData8bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001828 else if (BitWidth <= 16)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001829 O << MAI->getData16bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001830 else if (BitWidth <= 32)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001831 O << MAI->getData32bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001832 else if (BitWidth <= 64) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001833 assert(MAI->getData64bitsDirective(AddrSpace) &&
Reid Spencera54b7cb2007-01-12 07:05:14 +00001834 "Target cannot handle 64-bit constant exprs!");
Chris Lattner33adcfb2009-08-22 21:43:10 +00001835 O << MAI->getData64bitsDirective(AddrSpace);
Dan Gohman82f94f12008-09-08 16:40:13 +00001836 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +00001837 llvm_unreachable("Target cannot handle given data directive width!");
Reid Spencera54b7cb2007-01-12 07:05:14 +00001838 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001839 break;
Reid Spencera54b7cb2007-01-12 07:05:14 +00001840 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001841 case Type::PointerTyID:
1842 if (TD->getPointerSize() == 8) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001843 assert(MAI->getData64bitsDirective(AddrSpace) &&
Evan Chengd6594ae2006-09-12 21:00:35 +00001844 "Target cannot handle 64-bit pointer exprs!");
Chris Lattner33adcfb2009-08-22 21:43:10 +00001845 O << MAI->getData64bitsDirective(AddrSpace);
Sanjiv Guptafcc6f152009-01-22 10:14:21 +00001846 } else if (TD->getPointerSize() == 2) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001847 O << MAI->getData16bitsDirective(AddrSpace);
Sanjiv Guptafcc6f152009-01-22 10:14:21 +00001848 } else if (TD->getPointerSize() == 1) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001849 O << MAI->getData8bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001850 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001851 O << MAI->getData32bitsDirective(AddrSpace);
Evan Chengd6594ae2006-09-12 21:00:35 +00001852 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001853 break;
Evan Chengd6594ae2006-09-12 21:00:35 +00001854 }
1855}
Dale Johannesen4c3a5f82007-02-16 01:54:53 +00001856
Chris Lattner53d4d782010-01-15 23:38:51 +00001857void AsmPrinter::printVisibility(const MCSymbol *Sym,
1858 unsigned Visibility) const {
1859 if (Visibility == GlobalValue::HiddenVisibility) {
1860 if (const char *Directive = MAI->getHiddenDirective()) {
1861 O << Directive;
1862 Sym->print(O, MAI);
1863 O << '\n';
1864 }
1865 } else if (Visibility == GlobalValue::ProtectedVisibility) {
1866 if (const char *Directive = MAI->getProtectedDirective()) {
1867 O << Directive;
1868 Sym->print(O, MAI);
1869 O << '\n';
1870 }
1871 }
1872}
1873
Anton Korobeynikov7751ad92008-11-22 16:15:34 +00001874void AsmPrinter::printOffset(int64_t Offset) const {
1875 if (Offset > 0)
1876 O << '+' << Offset;
1877 else if (Offset < 0)
1878 O << Offset;
1879}
1880
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001881GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
1882 if (!S->usesMetadata())
Gordon Henriksenc317a602008-08-17 12:08:44 +00001883 return 0;
1884
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001885 gcp_iterator GCPI = GCMetadataPrinters.find(S);
Gordon Henriksenc317a602008-08-17 12:08:44 +00001886 if (GCPI != GCMetadataPrinters.end())
1887 return GCPI->second;
1888
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001889 const char *Name = S->getName().c_str();
Gordon Henriksenc317a602008-08-17 12:08:44 +00001890
1891 for (GCMetadataPrinterRegistry::iterator
1892 I = GCMetadataPrinterRegistry::begin(),
1893 E = GCMetadataPrinterRegistry::end(); I != E; ++I)
1894 if (strcmp(Name, I->getName()) == 0) {
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001895 GCMetadataPrinter *GMP = I->instantiate();
1896 GMP->S = S;
1897 GCMetadataPrinters.insert(std::make_pair(S, GMP));
1898 return GMP;
Gordon Henriksenc317a602008-08-17 12:08:44 +00001899 }
1900
Chris Lattner103289e2009-08-23 07:19:13 +00001901 errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n";
Torok Edwinc23197a2009-07-14 16:55:14 +00001902 llvm_unreachable(0);
Gordon Henriksenc317a602008-08-17 12:08:44 +00001903}
David Greene014700c2009-07-13 20:25:48 +00001904
1905/// EmitComments - Pretty-print comments for instructions
Chris Lattner5f51cd02009-08-07 23:42:01 +00001906void AsmPrinter::EmitComments(const MachineInstr &MI) const {
David Greene1924aab2009-11-13 21:34:57 +00001907 if (!VerboseAsm)
1908 return;
David Greene3ac1ab82009-07-16 22:24:20 +00001909
David Greene1924aab2009-11-13 21:34:57 +00001910 bool Newline = false;
1911
1912 if (!MI.getDebugLoc().isUnknown()) {
Devang Patel6b61f582010-01-16 06:09:35 +00001913 DILocation DLT = MF->getDILocation(MI.getDebugLoc());
David Greene1924aab2009-11-13 21:34:57 +00001914
1915 // Print source line info.
1916 O.PadToColumn(MAI->getCommentColumn());
Dan Gohman3b9bc042009-12-05 00:23:29 +00001917 O << MAI->getCommentString() << ' ';
Devang Patel6b61f582010-01-16 06:09:35 +00001918 DIScope Scope = DLT.getScope();
Dan Gohman3b9bc042009-12-05 00:23:29 +00001919 // Omit the directory, because it's likely to be long and uninteresting.
1920 if (!Scope.isNull())
1921 O << Scope.getFilename();
1922 else
1923 O << "<unknown>";
Devang Patel6b61f582010-01-16 06:09:35 +00001924 O << ':' << DLT.getLineNumber();
1925 if (DLT.getColumnNumber() != 0)
1926 O << ':' << DLT.getColumnNumber();
David Greene1924aab2009-11-13 21:34:57 +00001927 Newline = true;
David Greene3ac1ab82009-07-16 22:24:20 +00001928 }
David Greene1924aab2009-11-13 21:34:57 +00001929
David Greeneddff9412009-11-16 15:12:23 +00001930 // Check for spills and reloads
1931 int FI;
1932
1933 const MachineFrameInfo *FrameInfo =
1934 MI.getParent()->getParent()->getFrameInfo();
1935
1936 // We assume a single instruction only has a spill or reload, not
1937 // both.
David Greenef7ea2a52009-12-04 22:46:04 +00001938 const MachineMemOperand *MMO;
David Greeneddff9412009-11-16 15:12:23 +00001939 if (TM.getInstrInfo()->isLoadFromStackSlotPostFE(&MI, FI)) {
1940 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
David Greenef7ea2a52009-12-04 22:46:04 +00001941 MMO = *MI.memoperands_begin();
David Greeneddff9412009-11-16 15:12:23 +00001942 if (Newline) O << '\n';
1943 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001944 O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Reload";
David Greeneddff9412009-11-16 15:12:23 +00001945 Newline = true;
1946 }
1947 }
David Greenef7ea2a52009-12-04 22:46:04 +00001948 else if (TM.getInstrInfo()->hasLoadFromStackSlot(&MI, MMO, FI)) {
David Greeneddff9412009-11-16 15:12:23 +00001949 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
1950 if (Newline) O << '\n';
1951 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001952 O << MAI->getCommentString() << ' '
1953 << MMO->getSize() << "-byte Folded Reload";
David Greeneddff9412009-11-16 15:12:23 +00001954 Newline = true;
1955 }
1956 }
1957 else if (TM.getInstrInfo()->isStoreToStackSlotPostFE(&MI, FI)) {
1958 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
David Greenef7ea2a52009-12-04 22:46:04 +00001959 MMO = *MI.memoperands_begin();
David Greeneddff9412009-11-16 15:12:23 +00001960 if (Newline) O << '\n';
1961 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001962 O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Spill";
David Greeneddff9412009-11-16 15:12:23 +00001963 Newline = true;
1964 }
1965 }
David Greenef7ea2a52009-12-04 22:46:04 +00001966 else if (TM.getInstrInfo()->hasStoreToStackSlot(&MI, MMO, FI)) {
David Greeneddff9412009-11-16 15:12:23 +00001967 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
1968 if (Newline) O << '\n';
1969 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001970 O << MAI->getCommentString() << ' '
1971 << MMO->getSize() << "-byte Folded Spill";
David Greeneddff9412009-11-16 15:12:23 +00001972 Newline = true;
1973 }
1974 }
1975
1976 // Check for spill-induced copies
1977 unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
1978 if (TM.getInstrInfo()->isMoveInstr(MI, SrcReg, DstReg,
1979 SrcSubIdx, DstSubIdx)) {
1980 if (MI.getAsmPrinterFlag(ReloadReuse)) {
1981 if (Newline) O << '\n';
1982 O.PadToColumn(MAI->getCommentColumn());
1983 O << MAI->getCommentString() << " Reload Reuse";
David Greeneddff9412009-11-16 15:12:23 +00001984 }
1985 }
David Greene014700c2009-07-13 20:25:48 +00001986}
1987
David Greenefe37ab32009-08-18 19:22:55 +00001988/// PrintChildLoopComment - Print comments about child loops within
1989/// the loop for this basic block, with nesting.
1990///
1991static void PrintChildLoopComment(formatted_raw_ostream &O,
1992 const MachineLoop *loop,
Chris Lattner33adcfb2009-08-22 21:43:10 +00001993 const MCAsmInfo *MAI,
David Greenefe37ab32009-08-18 19:22:55 +00001994 int FunctionNumber) {
1995 // Add child loop information
1996 for(MachineLoop::iterator cl = loop->begin(),
1997 clend = loop->end();
1998 cl != clend;
1999 ++cl) {
2000 MachineBasicBlock *Header = (*cl)->getHeader();
2001 assert(Header && "No header for loop");
2002
2003 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00002004 O.PadToColumn(MAI->getCommentColumn());
David Greenefe37ab32009-08-18 19:22:55 +00002005
Chris Lattner33adcfb2009-08-22 21:43:10 +00002006 O << MAI->getCommentString();
Chris Lattnerc281de12009-08-23 00:51:00 +00002007 O.indent(((*cl)->getLoopDepth()-1)*2)
David Greenefe37ab32009-08-18 19:22:55 +00002008 << " Child Loop BB" << FunctionNumber << "_"
2009 << Header->getNumber() << " Depth " << (*cl)->getLoopDepth();
2010
Chris Lattner33adcfb2009-08-22 21:43:10 +00002011 PrintChildLoopComment(O, *cl, MAI, FunctionNumber);
David Greenefe37ab32009-08-18 19:22:55 +00002012 }
2013}
2014
David Greeneb71d1b22009-08-10 16:38:07 +00002015/// EmitComments - Pretty-print comments for basic blocks
David Greene1924aab2009-11-13 21:34:57 +00002016void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const {
David Greenefe37ab32009-08-18 19:22:55 +00002017 if (VerboseAsm) {
David Greeneb71d1b22009-08-10 16:38:07 +00002018 // Add loop depth information
2019 const MachineLoop *loop = LI->getLoopFor(&MBB);
2020
2021 if (loop) {
2022 // Print a newline after bb# annotation.
2023 O << "\n";
Chris Lattner33adcfb2009-08-22 21:43:10 +00002024 O.PadToColumn(MAI->getCommentColumn());
2025 O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth()
David Greeneb71d1b22009-08-10 16:38:07 +00002026 << '\n';
2027
Chris Lattner33adcfb2009-08-22 21:43:10 +00002028 O.PadToColumn(MAI->getCommentColumn());
David Greeneb71d1b22009-08-10 16:38:07 +00002029
2030 MachineBasicBlock *Header = loop->getHeader();
2031 assert(Header && "No header for loop");
2032
2033 if (Header == &MBB) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00002034 O << MAI->getCommentString() << " Loop Header";
2035 PrintChildLoopComment(O, loop, MAI, getFunctionNumber());
David Greeneb71d1b22009-08-10 16:38:07 +00002036 }
2037 else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00002038 O << MAI->getCommentString() << " Loop Header is BB"
David Greeneb71d1b22009-08-10 16:38:07 +00002039 << getFunctionNumber() << "_" << loop->getHeader()->getNumber();
2040 }
2041
2042 if (loop->empty()) {
2043 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00002044 O.PadToColumn(MAI->getCommentColumn());
2045 O << MAI->getCommentString() << " Inner Loop";
David Greeneb71d1b22009-08-10 16:38:07 +00002046 }
2047
2048 // Add parent loop information
2049 for (const MachineLoop *CurLoop = loop->getParentLoop();
2050 CurLoop;
2051 CurLoop = CurLoop->getParentLoop()) {
2052 MachineBasicBlock *Header = CurLoop->getHeader();
2053 assert(Header && "No header for loop");
2054
2055 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00002056 O.PadToColumn(MAI->getCommentColumn());
2057 O << MAI->getCommentString();
Chris Lattnerc281de12009-08-23 00:51:00 +00002058 O.indent((CurLoop->getLoopDepth()-1)*2)
David Greenefe37ab32009-08-18 19:22:55 +00002059 << " Inside Loop BB" << getFunctionNumber() << "_"
David Greeneb71d1b22009-08-10 16:38:07 +00002060 << Header->getNumber() << " Depth " << CurLoop->getLoopDepth();
2061 }
2062 }
2063 }
2064}