blob: 0ae3ecb363ca3f7a1066940f06695555f57bec03 [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"
Chris Lattner45111d12010-01-16 21:57:06 +000019#include "llvm/CodeGen/DwarfWriter.h"
Gordon Henriksen5eca0752008-08-17 18:44:35 +000020#include "llvm/CodeGen/GCMetadataPrinter.h"
Chris Lattner3b4fd322005-11-21 08:25:09 +000021#include "llvm/CodeGen/MachineConstantPool.h"
David Greene1924aab2009-11-13 21:34:57 +000022#include "llvm/CodeGen/MachineFrameInfo.h"
David Greenefe37ab32009-08-18 19:22:55 +000023#include "llvm/CodeGen/MachineFunction.h"
Nate Begeman37efe672006-04-22 18:53:45 +000024#include "llvm/CodeGen/MachineJumpTableInfo.h"
David Greeneb71d1b22009-08-10 16:38:07 +000025#include "llvm/CodeGen/MachineLoopInfo.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000026#include "llvm/CodeGen/MachineModuleInfo.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 Lattneraf76e592009-08-22 20:48:53 +000036#include "llvm/MC/MCAsmInfo.h"
Chris Lattner45111d12010-01-16 21:57:06 +000037#include "llvm/Target/Mangler.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"
Chris Lattner66099132006-02-01 22:41:11 +000046#include <cerrno>
Chris Lattnera80ba712004-08-16 23:15:22 +000047using namespace llvm;
48
Evan Cheng42bf74b2009-03-25 01:47:28 +000049static cl::opt<cl::boolOrDefault>
50AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
51 cl::init(cl::BOU_UNSET));
52
Devang Patel19974732007-05-03 01:11:54 +000053char AsmPrinter::ID = 0;
David Greene71847812009-07-14 20:18:05 +000054AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
Chris Lattneraf76e592009-08-22 20:48:53 +000055 const MCAsmInfo *T, bool VDef)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +000056 : MachineFunctionPass(&ID), FunctionNumber(0), O(o),
Chris Lattner33adcfb2009-08-22 21:43:10 +000057 TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
Chris Lattner2b2954f2009-07-27 21:28:04 +000058
59 OutContext(*new MCContext()),
Chris Lattner90edac02009-09-14 03:02:37 +000060 // FIXME: Pass instprinter to streamer.
61 OutStreamer(*createAsmStreamer(OutContext, O, *T, 0)),
Chris Lattner2b2954f2009-07-27 21:28:04 +000062
Devang Patel6b61f582010-01-16 06:09:35 +000063 LastMI(0), LastFn(0), Counter(~0U), PrevDLT(NULL) {
Chris Lattner0de1fc42009-06-24 19:09:55 +000064 DW = 0; MMI = 0;
Evan Cheng42bf74b2009-03-25 01:47:28 +000065 switch (AsmVerbose) {
66 case cl::BOU_UNSET: VerboseAsm = VDef; break;
67 case cl::BOU_TRUE: VerboseAsm = true; break;
68 case cl::BOU_FALSE: VerboseAsm = false; break;
69 }
70}
Chris Lattnered138932005-12-13 06:32:10 +000071
Gordon Henriksenc317a602008-08-17 12:08:44 +000072AsmPrinter::~AsmPrinter() {
73 for (gcp_iterator I = GCMetadataPrinters.begin(),
74 E = GCMetadataPrinters.end(); I != E; ++I)
75 delete I->second;
Chris Lattner2b2954f2009-07-27 21:28:04 +000076
77 delete &OutStreamer;
78 delete &OutContext;
Gordon Henriksenc317a602008-08-17 12:08:44 +000079}
Chris Lattnered138932005-12-13 06:32:10 +000080
Chris Lattner38c39882009-08-03 19:12:26 +000081TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
Chris Lattnerf0144122009-07-28 03:13:23 +000082 return TM.getTargetLowering()->getObjFileLowering();
83}
84
Chris Lattnerdabf07c2009-08-18 06:15:16 +000085/// getCurrentSection() - Return the current section we are emitting to.
86const MCSection *AsmPrinter::getCurrentSection() const {
87 return OutStreamer.getCurrentSection();
88}
89
90
Gordon Henriksence224772008-01-07 01:30:38 +000091void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
Dan Gohman845012e2009-07-31 23:37:33 +000092 AU.setPreservesAll();
Gordon Henriksence224772008-01-07 01:30:38 +000093 MachineFunctionPass::getAnalysisUsage(AU);
Gordon Henriksen5eca0752008-08-17 18:44:35 +000094 AU.addRequired<GCModuleInfo>();
David Greenefe37ab32009-08-18 19:22:55 +000095 if (VerboseAsm)
David Greeneb71d1b22009-08-10 16:38:07 +000096 AU.addRequired<MachineLoopInfo>();
Gordon Henriksence224772008-01-07 01:30:38 +000097}
98
Chris Lattnera80ba712004-08-16 23:15:22 +000099bool AsmPrinter::doInitialization(Module &M) {
Chris Lattnerf26e03b2009-07-31 17:42:42 +0000100 // Initialize TargetLoweringObjectFile.
101 const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
102 .Initialize(OutContext, TM);
103
Chris Lattnerc0dba722010-01-17 18:22:35 +0000104 Mang = new Mangler(*MAI);
Chris Lattner2c1b1592006-01-23 23:47:53 +0000105
Bob Wilson812209a2009-09-30 22:06:26 +0000106 // Allow the target to emit any magic that it wants at the start of the file.
107 EmitStartOfAsmFile(M);
Rafael Espindola952b8392008-12-03 11:01:37 +0000108
Chris Lattner33adcfb2009-08-22 21:43:10 +0000109 if (MAI->hasSingleParameterDotFile()) {
Rafael Espindola952b8392008-12-03 11:01:37 +0000110 /* Very minimal debug info. It is ignored if we emit actual
Bob Wilsonbc9506f2009-09-30 21:26:13 +0000111 debug info. If we don't, this at least helps the user find where
Rafael Espindola952b8392008-12-03 11:01:37 +0000112 a function came from. */
113 O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
114 }
115
Bob Wilson812209a2009-09-30 22:06:26 +0000116 GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
117 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000118 for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
119 if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
Chris Lattner33adcfb2009-08-22 21:43:10 +0000120 MP->beginAssembly(O, *this, *MAI);
Gordon Henriksence224772008-01-07 01:30:38 +0000121
Chris Lattner3e2fa7a2006-01-24 04:16:34 +0000122 if (!M.getModuleInlineAsm().empty())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000123 O << MAI->getCommentString() << " Start of file scope inline assembly\n"
Chris Lattner3e2fa7a2006-01-24 04:16:34 +0000124 << M.getModuleInlineAsm()
Chris Lattner33adcfb2009-08-22 21:43:10 +0000125 << '\n' << MAI->getCommentString()
Jim Laskey563321a2006-09-06 18:34:40 +0000126 << " End of file scope inline assembly\n";
Chris Lattner2c1b1592006-01-23 23:47:53 +0000127
Chris Lattnerb55e0682009-09-24 05:44:53 +0000128 MMI = getAnalysisIfAvailable<MachineModuleInfo>();
129 if (MMI)
130 MMI->AnalyzeModule(M);
131 DW = getAnalysisIfAvailable<DwarfWriter>();
Sanjiv Gupta9a501cf2009-11-14 07:22:25 +0000132 if (DW)
Chris Lattnerb55e0682009-09-24 05:44:53 +0000133 DW->BeginModule(&M, MMI, O, this, MAI);
Devang Patel14a55d92009-06-19 21:54:26 +0000134
Chris Lattnera80ba712004-08-16 23:15:22 +0000135 return false;
136}
137
Chris Lattner48d64ba2010-01-19 04:39:15 +0000138/// EmitGlobalVariable - Emit the specified global variable to the .s file.
139void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
140 if (!GV->hasInitializer()) // External globals require no code.
141 return;
142
143 // Check to see if this is a special global used by LLVM, if so, emit it.
144 if (EmitSpecialLLVMGlobal(GV))
145 return;
146
147 // Let the target emit it.
148 PrintGlobalVariable(GV);
149}
150
151
Chris Lattnera80ba712004-08-16 23:15:22 +0000152bool AsmPrinter::doFinalization(Module &M) {
Chris Lattner40bbebd2009-07-21 18:38:57 +0000153 // Emit global variables.
154 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
155 I != E; ++I)
Chris Lattner48d64ba2010-01-19 04:39:15 +0000156 EmitGlobalVariable(I);
Chris Lattner40bbebd2009-07-21 18:38:57 +0000157
Chris Lattner1f522fe2009-06-24 18:54:37 +0000158 // Emit final debug information.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000159 if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling())
Chris Lattner1f522fe2009-06-24 18:54:37 +0000160 DW->EndModule();
161
Chris Lattner0a7befa2009-06-24 18:52:01 +0000162 // If the target wants to know about weak references, print them all.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000163 if (MAI->getWeakRefDirective()) {
Chris Lattner0a7befa2009-06-24 18:52:01 +0000164 // FIXME: This is not lazy, it would be nice to only print weak references
165 // to stuff that is actually used. Note that doing so would require targets
166 // to notice uses in operands (due to constant exprs etc). This should
167 // happen with the MC stuff eventually.
Rafael Espindola15404d02006-12-18 03:37:18 +0000168
Chris Lattner0a7befa2009-06-24 18:52:01 +0000169 // Print out module-level global variables here.
170 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
171 I != E; ++I) {
Chris Lattner08ce3b42010-01-16 18:17:26 +0000172 if (!I->hasExternalWeakLinkage()) continue;
Chris Lattner10b318b2010-01-17 21:43:43 +0000173 O << MAI->getWeakRefDirective() << *GetGlobalValueSymbol(I) << '\n';
Chris Lattner0a7befa2009-06-24 18:52:01 +0000174 }
175
Chris Lattnerc6fdced2009-08-03 23:10:34 +0000176 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
Chris Lattner08ce3b42010-01-16 18:17:26 +0000177 if (!I->hasExternalWeakLinkage()) continue;
Chris Lattner10b318b2010-01-17 21:43:43 +0000178 O << MAI->getWeakRefDirective() << *GetGlobalValueSymbol(I) << '\n';
Chris Lattner0a7befa2009-06-24 18:52:01 +0000179 }
Rafael Espindola15404d02006-12-18 03:37:18 +0000180 }
181
Chris Lattner33adcfb2009-08-22 21:43:10 +0000182 if (MAI->getSetDirective()) {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000183 O << '\n';
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000184 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
Chris Lattner0a7befa2009-06-24 18:52:01 +0000185 I != E; ++I) {
Chris Lattner5c40e692010-01-16 01:17:26 +0000186 MCSymbol *Name = GetGlobalValueSymbol(I);
Anton Korobeynikov325be7c2007-09-06 17:21:48 +0000187
188 const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
Chris Lattner5c40e692010-01-16 01:17:26 +0000189 MCSymbol *Target = GetGlobalValueSymbol(GV);
Anton Korobeynikov541af7f2008-09-24 22:21:04 +0000190
Chris Lattner10b318b2010-01-17 21:43:43 +0000191 if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())
192 O << "\t.globl\t" << *Name << '\n';
193 else if (I->hasWeakLinkage())
194 O << MAI->getWeakRefDirective() << *Name << '\n';
195 else
Chris Lattner10595492010-01-16 01:37:14 +0000196 assert(I->hasLocalLinkage() && "Invalid alias linkage");
Anton Korobeynikov22c9e652008-03-11 21:41:14 +0000197
Anton Korobeynikov541af7f2008-09-24 22:21:04 +0000198 printVisibility(Name, I->getVisibility());
Anton Korobeynikov22c9e652008-03-11 21:41:14 +0000199
Chris Lattner10b318b2010-01-17 21:43:43 +0000200 O << MAI->getSetDirective() << ' ' << *Name << ", " << *Target << '\n';
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000201 }
202 }
203
Duncan Sands1465d612009-01-28 13:14:17 +0000204 GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000205 assert(MI && "AsmPrinter didn't require GCModuleInfo?");
206 for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
207 if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
Chris Lattner33adcfb2009-08-22 21:43:10 +0000208 MP->finishAssembly(O, *this, *MAI);
Gordon Henriksence224772008-01-07 01:30:38 +0000209
Dan Gohmana779a982008-05-05 00:28:39 +0000210 // If we don't have any trampolines, then we don't require stack memory
211 // to be executable. Some targets have a directive to declare this.
Chris Lattner0a7befa2009-06-24 18:52:01 +0000212 Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
Dan Gohmana779a982008-05-05 00:28:39 +0000213 if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000214 if (MAI->getNonexecutableStackDirective())
215 O << MAI->getNonexecutableStackDirective() << '\n';
Dan Gohmana779a982008-05-05 00:28:39 +0000216
Chris Lattnerbd23d5f2009-09-18 20:17:03 +0000217
218 // Allow the target to emit any magic that it wants at the end of the file,
219 // after everything else has gone out.
220 EmitEndOfAsmFile(M);
221
Chris Lattnera80ba712004-08-16 23:15:22 +0000222 delete Mang; Mang = 0;
Chris Lattner0de1fc42009-06-24 19:09:55 +0000223 DW = 0; MMI = 0;
Chris Lattner2b2954f2009-07-27 21:28:04 +0000224
225 OutStreamer.Finish();
Chris Lattnera80ba712004-08-16 23:15:22 +0000226 return false;
227}
228
Chris Lattner25045bd2005-11-21 07:51:36 +0000229void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattner412c3a52010-01-16 01:24:10 +0000230 // Get the function symbol.
Chris Lattnerd1947ed2010-01-15 23:55:16 +0000231 CurrentFnSym = GetGlobalValueSymbol(MF.getFunction());
Evan Cheng347d39f2007-10-14 05:57:21 +0000232 IncrementFunctionNumber();
David Greeneb71d1b22009-08-10 16:38:07 +0000233
Chris Lattner25d812b2009-09-16 00:35:39 +0000234 if (VerboseAsm)
David Greeneb71d1b22009-08-10 16:38:07 +0000235 LI = &getAnalysis<MachineLoopInfo>();
Chris Lattnera80ba712004-08-16 23:15:22 +0000236}
237
Evan Cheng1606e8e2009-03-13 07:51:59 +0000238namespace {
239 // SectionCPs - Keep track the alignment, constpool entries per Section.
240 struct SectionCPs {
Chris Lattnera87dea42009-07-31 18:48:30 +0000241 const MCSection *S;
Evan Cheng1606e8e2009-03-13 07:51:59 +0000242 unsigned Alignment;
243 SmallVector<unsigned, 4> CPEs;
Douglas Gregorcabdd742009-12-19 07:05:23 +0000244 SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {}
Evan Cheng1606e8e2009-03-13 07:51:59 +0000245 };
246}
247
Chris Lattner3b4fd322005-11-21 08:25:09 +0000248/// EmitConstantPool - Print to the current output stream assembly
249/// representations of the constants in the constant pool MCP. This is
250/// used to print out constants which have been "spilled to memory" by
251/// the code generator.
252///
253void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerfa77d432006-02-09 04:22:52 +0000254 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattner3b4fd322005-11-21 08:25:09 +0000255 if (CP.empty()) return;
Evan Cheng2d2cec12006-06-29 00:26:09 +0000256
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000257 // Calculate sections for constant pool entries. We collect entries to go into
258 // the same section together to reduce amount of section switch statements.
Evan Cheng1606e8e2009-03-13 07:51:59 +0000259 SmallVector<SectionCPs, 4> CPSections;
Chris Lattner3b4fd322005-11-21 08:25:09 +0000260 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Chris Lattner298414e2009-07-22 00:28:43 +0000261 const MachineConstantPoolEntry &CPE = CP[i];
Evan Cheng1606e8e2009-03-13 07:51:59 +0000262 unsigned Align = CPE.getAlignment();
Chris Lattner5c2f7892009-07-26 06:26:55 +0000263
264 SectionKind Kind;
265 switch (CPE.getRelocationInfo()) {
266 default: llvm_unreachable("Unknown section kind");
Chris Lattner27981192009-08-01 23:57:16 +0000267 case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
Chris Lattner4c509222009-07-26 07:00:12 +0000268 case 1:
Chris Lattner27981192009-08-01 23:57:16 +0000269 Kind = SectionKind::getReadOnlyWithRelLocal();
Chris Lattner4c509222009-07-26 07:00:12 +0000270 break;
Chris Lattner5c2f7892009-07-26 06:26:55 +0000271 case 0:
Chris Lattner4c509222009-07-26 07:00:12 +0000272 switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
Chris Lattner27981192009-08-01 23:57:16 +0000273 case 4: Kind = SectionKind::getMergeableConst4(); break;
274 case 8: Kind = SectionKind::getMergeableConst8(); break;
275 case 16: Kind = SectionKind::getMergeableConst16();break;
276 default: Kind = SectionKind::getMergeableConst(); break;
Chris Lattner4c509222009-07-26 07:00:12 +0000277 }
Chris Lattner5c2f7892009-07-26 06:26:55 +0000278 }
279
Chris Lattner83d77fa2009-08-01 23:46:12 +0000280 const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);
Chris Lattner298414e2009-07-22 00:28:43 +0000281
Evan Cheng1606e8e2009-03-13 07:51:59 +0000282 // The number of sections are small, just do a linear search from the
283 // last section to the first.
284 bool Found = false;
285 unsigned SecIdx = CPSections.size();
286 while (SecIdx != 0) {
287 if (CPSections[--SecIdx].S == S) {
288 Found = true;
289 break;
290 }
291 }
292 if (!Found) {
293 SecIdx = CPSections.size();
294 CPSections.push_back(SectionCPs(S, Align));
295 }
296
297 if (Align > CPSections[SecIdx].Alignment)
298 CPSections[SecIdx].Alignment = Align;
299 CPSections[SecIdx].CPEs.push_back(i);
Evan Cheng2d2cec12006-06-29 00:26:09 +0000300 }
301
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000302 // Now print stuff into the calculated sections.
Evan Cheng1606e8e2009-03-13 07:51:59 +0000303 for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000304 OutStreamer.SwitchSection(CPSections[i].S);
Evan Cheng1606e8e2009-03-13 07:51:59 +0000305 EmitAlignment(Log2_32(CPSections[i].Alignment));
Evan Cheng2d2cec12006-06-29 00:26:09 +0000306
Evan Cheng1606e8e2009-03-13 07:51:59 +0000307 unsigned Offset = 0;
308 for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
309 unsigned CPI = CPSections[i].CPEs[j];
310 MachineConstantPoolEntry CPE = CP[CPI];
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000311
Chris Lattner3029f922006-02-09 04:46:04 +0000312 // Emit inter-object padding for alignment.
Evan Cheng1606e8e2009-03-13 07:51:59 +0000313 unsigned AlignMask = CPE.getAlignment() - 1;
314 unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
315 EmitZeros(NewOffset - Offset);
316
317 const Type *Ty = CPE.getType();
Duncan Sands777d2302009-05-09 07:06:46 +0000318 Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
Evan Cheng1606e8e2009-03-13 07:51:59 +0000319
Chris Lattner33adcfb2009-08-22 21:43:10 +0000320 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
Dan Gohmana12e9d72009-08-12 18:32:22 +0000321 << CPI << ':';
Evan Cheng1606e8e2009-03-13 07:51:59 +0000322 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000323 O.PadToColumn(MAI->getCommentColumn());
324 O << MAI->getCommentString() << " constant ";
Dan Gohmancf20ac42009-08-13 01:36:44 +0000325 WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent());
Anton Korobeynikov088ae832008-09-24 22:17:59 +0000326 }
Evan Cheng1606e8e2009-03-13 07:51:59 +0000327 O << '\n';
328 if (CPE.isMachineConstantPoolEntry())
329 EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
330 else
331 EmitGlobalConstant(CPE.Val.ConstVal);
Chris Lattner3029f922006-02-09 04:46:04 +0000332 }
Chris Lattner3b4fd322005-11-21 08:25:09 +0000333 }
334}
335
Nate Begeman37efe672006-04-22 18:53:45 +0000336/// EmitJumpTableInfo - Print assembly representations of the jump tables used
337/// by the current function to the current output stream.
338///
Chris Lattner1da31ee2006-10-05 03:01:21 +0000339void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
340 MachineFunction &MF) {
Nate Begeman37efe672006-04-22 18:53:45 +0000341 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
342 if (JT.empty()) return;
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000343
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000344 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
Nate Begeman4d9bbdc2006-07-27 16:46:58 +0000345
Nate Begeman2f1ae882006-07-27 01:13:04 +0000346 // Pick the directive to use to print the jump table entries, and switch to
347 // the appropriate section.
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000348 TargetLowering *LoweringInfo = TM.getTargetLowering();
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000349
Anton Korobeynikove87f52d2008-07-09 13:27:16 +0000350 const Function *F = MF.getFunction();
Evan Chengb13bafe2009-06-18 20:37:15 +0000351 bool JTInDiffSection = false;
Chris Lattner83d77fa2009-08-01 23:46:12 +0000352 if (F->isWeakForLinker() ||
353 (IsPic && !LoweringInfo->usesGlobalOffsetTable())) {
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000354 // In PIC mode, we need to emit the jump table to the same section as the
355 // function body itself, otherwise the label differences won't make sense.
Anton Korobeynikove87f52d2008-07-09 13:27:16 +0000356 // We should also do if the section name is NULL or function is declared in
357 // discardable section.
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000358 OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang,
359 TM));
Nate Begeman2f1ae882006-07-27 01:13:04 +0000360 } else {
Chris Lattner83d77fa2009-08-01 23:46:12 +0000361 // Otherwise, drop it in the readonly section.
362 const MCSection *ReadOnlySection =
Chris Lattner27981192009-08-01 23:57:16 +0000363 getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000364 OutStreamer.SwitchSection(ReadOnlySection);
Evan Chengb13bafe2009-06-18 20:37:15 +0000365 JTInDiffSection = true;
Nate Begeman2f1ae882006-07-27 01:13:04 +0000366 }
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000367
368 EmitAlignment(Log2_32(MJTI->getAlignment()));
Chris Lattner0c4e6782006-07-15 01:34:12 +0000369
Nate Begeman37efe672006-04-22 18:53:45 +0000370 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
Nate Begeman52a51e382006-08-12 21:29:52 +0000371 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
Chris Lattner07371882006-10-28 18:10:06 +0000372
373 // If this jump table was deleted, ignore it.
374 if (JTBBs.empty()) continue;
Nate Begeman52a51e382006-08-12 21:29:52 +0000375
376 // For PIC codegen, if possible we want to use the SetDirective to reduce
377 // the number of relocations the assembler will generate for the jump table.
378 // Set directives are all printed before the jump table itself.
Evan Chengcc415862007-11-09 01:32:10 +0000379 SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
Chris Lattner33adcfb2009-08-22 21:43:10 +0000380 if (MAI->getSetDirective() && IsPic)
Nate Begeman52a51e382006-08-12 21:29:52 +0000381 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
Evan Chengcc415862007-11-09 01:32:10 +0000382 if (EmittedSets.insert(JTBBs[ii]))
383 printPICJumpTableSetLabel(i, JTBBs[ii]);
Nate Begeman52a51e382006-08-12 21:29:52 +0000384
Chris Lattner7c301912009-09-13 19:02:16 +0000385 // On some targets (e.g. Darwin) we want to emit two consequtive labels
Chris Lattner393a8ee2007-01-18 01:12:56 +0000386 // before each jump table. The first label is never referenced, but tells
387 // the assembler and linker the extents of the jump table object. The
388 // second label is actually referenced by the code.
Chris Lattner7c301912009-09-13 19:02:16 +0000389 if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0]) {
390 O << MAI->getLinkerPrivateGlobalPrefix()
391 << "JTI" << getFunctionNumber() << '_' << i << ":\n";
Evan Chengb13bafe2009-06-18 20:37:15 +0000392 }
Chris Lattner393a8ee2007-01-18 01:12:56 +0000393
Chris Lattner33adcfb2009-08-22 21:43:10 +0000394 O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng347d39f2007-10-14 05:57:21 +0000395 << '_' << i << ":\n";
Nate Begeman52a51e382006-08-12 21:29:52 +0000396
Nate Begeman37efe672006-04-22 18:53:45 +0000397 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000398 printPICJumpTableEntry(MJTI, JTBBs[ii], i);
Nate Begeman37efe672006-04-22 18:53:45 +0000399 O << '\n';
400 }
401 }
402}
403
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000404void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
405 const MachineBasicBlock *MBB,
406 unsigned uid) const {
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000407 bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000408
409 // Use JumpTableDirective otherwise honor the entry size from the jump table
410 // info.
Chris Lattner33adcfb2009-08-22 21:43:10 +0000411 const char *JTEntryDirective = MAI->getJumpTableDirective(isPIC);
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000412 bool HadJTEntryDirective = JTEntryDirective != NULL;
413 if (!HadJTEntryDirective) {
414 JTEntryDirective = MJTI->getEntrySize() == 4 ?
Chris Lattner33adcfb2009-08-22 21:43:10 +0000415 MAI->getData32bitsDirective() : MAI->getData64bitsDirective();
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000416 }
417
418 O << JTEntryDirective << ' ';
419
420 // If we have emitted set directives for the jump table entries, print
421 // them rather than the entries themselves. If we're emitting PIC, then
422 // emit the table entries as differences between two text section labels.
423 // If we're emitting non-PIC code, then emit the entries as direct
424 // references to the target basic blocks.
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000425 if (!isPIC) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000426 O << *GetMBBSymbol(MBB->getNumber());
Chris Lattner33adcfb2009-08-22 21:43:10 +0000427 } else if (MAI->getSetDirective()) {
428 O << MAI->getPrivateGlobalPrefix() << getFunctionNumber()
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000429 << '_' << uid << "_set_" << MBB->getNumber();
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000430 } else {
Chris Lattner10b318b2010-01-17 21:43:43 +0000431 O << *GetMBBSymbol(MBB->getNumber());
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000432 // If the arch uses custom Jump Table directives, don't calc relative to
433 // JT
434 if (!HadJTEntryDirective)
Chris Lattner33adcfb2009-08-22 21:43:10 +0000435 O << '-' << MAI->getPrivateGlobalPrefix() << "JTI"
Chris Lattnerb3ac6e42009-08-11 20:29:57 +0000436 << getFunctionNumber() << '_' << uid;
Anton Korobeynikov9de19342007-11-14 09:18:41 +0000437 }
438}
439
440
Chris Lattnered138932005-12-13 06:32:10 +0000441/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
442/// special global used by LLVM. If so, emit it and return true, otherwise
443/// do nothing and return false.
444bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Daniel Dunbar03d76512009-07-25 23:55:21 +0000445 if (GV->getName() == "llvm.used") {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000446 if (MAI->getUsedDirective() != 0) // No need to emit this at all.
Andrew Lenharthb753a9b2007-08-22 19:33:11 +0000447 EmitLLVMUsedList(GV->getInitializer());
448 return true;
449 }
450
Chris Lattner401e10c2009-07-20 06:14:25 +0000451 // Ignore debug and non-emitted data. This handles llvm.compiler.used.
Chris Lattner266c7bb2009-04-13 05:44:34 +0000452 if (GV->getSection() == "llvm.metadata" ||
453 GV->hasAvailableExternallyLinkage())
454 return true;
Jim Laskey78098112006-03-07 22:00:35 +0000455
456 if (!GV->hasAppendingLinkage()) return false;
457
458 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnered138932005-12-13 06:32:10 +0000459
Evan Cheng916d07c2007-06-04 20:39:18 +0000460 const TargetData *TD = TM.getTargetData();
461 unsigned Align = Log2_32(TD->getPointerPrefAlignment());
Chris Lattnerf231c072009-03-09 05:52:15 +0000462 if (GV->getName() == "llvm.global_ctors") {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000463 OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
Chris Lattnerea3a9ff2009-03-09 08:18:48 +0000464 EmitAlignment(Align, 0);
465 EmitXXStructorList(GV->getInitializer());
Chris Lattner71eae712010-01-19 04:34:02 +0000466
467 if (TM.getRelocationModel() == Reloc::Static &&
468 MAI->hasStaticCtorDtorReferenceInStaticMode())
469 O << ".reference .constructors_used\n";
Chris Lattnerea3a9ff2009-03-09 08:18:48 +0000470 return true;
Chris Lattnered138932005-12-13 06:32:10 +0000471 }
472
Chris Lattnerf231c072009-03-09 05:52:15 +0000473 if (GV->getName() == "llvm.global_dtors") {
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000474 OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
Chris Lattnerea3a9ff2009-03-09 08:18:48 +0000475 EmitAlignment(Align, 0);
476 EmitXXStructorList(GV->getInitializer());
Chris Lattner71eae712010-01-19 04:34:02 +0000477
478 if (TM.getRelocationModel() == Reloc::Static &&
479 MAI->hasStaticCtorDtorReferenceInStaticMode())
480 O << ".reference .destructors_used\n";
Chris Lattnerea3a9ff2009-03-09 08:18:48 +0000481 return true;
Chris Lattnered138932005-12-13 06:32:10 +0000482 }
483
484 return false;
485}
486
Chris Lattner33adcfb2009-08-22 21:43:10 +0000487/// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
Dale Johannesend2e51af2008-09-09 22:29:13 +0000488/// global in the specified llvm.used list for which emitUsedDirectiveFor
489/// is true, as being used with this directive.
Chris Lattnercb05af82006-09-26 03:38:18 +0000490void AsmPrinter::EmitLLVMUsedList(Constant *List) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000491 const char *Directive = MAI->getUsedDirective();
Chris Lattnercb05af82006-09-26 03:38:18 +0000492
Dan Gohmana119de82009-06-14 23:30:43 +0000493 // Should be an array of 'i8*'.
Chris Lattnercb05af82006-09-26 03:38:18 +0000494 ConstantArray *InitList = dyn_cast<ConstantArray>(List);
495 if (InitList == 0) return;
496
497 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
Chris Lattner16fe9902009-07-17 22:00:23 +0000498 const GlobalValue *GV =
499 dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
Chris Lattner26630c12009-07-31 20:52:39 +0000500 if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) {
Dale Johannesen61e60932008-09-03 20:34:58 +0000501 O << Directive;
502 EmitConstantValueOnly(InitList->getOperand(i));
503 O << '\n';
504 }
Chris Lattnercb05af82006-09-26 03:38:18 +0000505 }
506}
507
Chris Lattnered138932005-12-13 06:32:10 +0000508/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
509/// function pointers, ignoring the init priority.
510void AsmPrinter::EmitXXStructorList(Constant *List) {
511 // Should be an array of '{ int, void ()* }' structs. The first value is the
512 // init priority, which we ignore.
513 if (!isa<ConstantArray>(List)) return;
514 ConstantArray *InitList = cast<ConstantArray>(List);
515 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
516 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
517 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner8de324b2005-12-21 01:17:37 +0000518
519 if (CS->getOperand(1)->isNullValue())
520 return; // Found a null terminator, exit printing.
521 // Emit the function pointer.
Chris Lattnered138932005-12-13 06:32:10 +0000522 EmitGlobalConstant(CS->getOperand(1));
523 }
524}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000525
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000526
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000527//===----------------------------------------------------------------------===//
528/// LEB 128 number encoding.
529
Bob Wilsonc0ef2442009-11-06 22:38:38 +0000530/// PrintULEB128 - Print a series of hexadecimal values (separated by commas)
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000531/// representing an unsigned leb128 value.
532void AsmPrinter::PrintULEB128(unsigned Value) const {
533 do {
Chris Lattnera64f4632008-11-10 04:35:24 +0000534 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000535 Value >>= 7;
536 if (Value) Byte |= 0x80;
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +0000537 PrintHex(Byte);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000538 if (Value) O << ", ";
539 } while (Value);
540}
541
Bob Wilsonc0ef2442009-11-06 22:38:38 +0000542/// PrintSLEB128 - Print a series of hexadecimal values (separated by commas)
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000543/// representing a signed leb128 value.
544void AsmPrinter::PrintSLEB128(int Value) const {
545 int Sign = Value >> (8 * sizeof(Value) - 1);
546 bool IsMore;
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000547
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000548 do {
Chris Lattnera64f4632008-11-10 04:35:24 +0000549 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000550 Value >>= 7;
551 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
552 if (IsMore) Byte |= 0x80;
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +0000553 PrintHex(Byte);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000554 if (IsMore) O << ", ";
555 } while (IsMore);
556}
557
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000558//===--------------------------------------------------------------------===//
559// Emission and print routines
560//
561
Bob Wilsonc0ef2442009-11-06 22:38:38 +0000562/// PrintHex - Print a value as a hexadecimal value.
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000563///
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +0000564void AsmPrinter::PrintHex(uint64_t Value) const {
565 O << "0x";
566 O.write_hex(Value);
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000567}
568
569/// EOL - Print a newline character to asm stream. If a comment is present
570/// then it will be printed first. Comments should not contain '\n'.
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000571void AsmPrinter::EOL() const {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000572 O << '\n';
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000573}
Owen Anderson25995092008-07-01 21:16:27 +0000574
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +0000575void AsmPrinter::EOL(const Twine &Comment) const {
576 if (VerboseAsm && !Comment.isTriviallyEmpty()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000577 O.PadToColumn(MAI->getCommentColumn());
578 O << MAI->getCommentString()
Owen Anderson25995092008-07-01 21:16:27 +0000579 << ' '
580 << Comment;
581 }
582 O << '\n';
583}
584
Bill Wendlingb5abecd2009-08-29 12:17:53 +0000585static const char *DecodeDWARFEncoding(unsigned Encoding) {
586 switch (Encoding) {
587 case dwarf::DW_EH_PE_absptr:
588 return "absptr";
589 case dwarf::DW_EH_PE_omit:
590 return "omit";
591 case dwarf::DW_EH_PE_pcrel:
592 return "pcrel";
Bill Wendling0734d352009-09-09 21:26:19 +0000593 case dwarf::DW_EH_PE_udata4:
594 return "udata4";
595 case dwarf::DW_EH_PE_udata8:
596 return "udata8";
597 case dwarf::DW_EH_PE_sdata4:
598 return "sdata4";
599 case dwarf::DW_EH_PE_sdata8:
600 return "sdata8";
Bill Wendlingb5abecd2009-08-29 12:17:53 +0000601 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4:
602 return "pcrel udata4";
603 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4:
604 return "pcrel sdata4";
605 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8:
606 return "pcrel udata8";
607 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8:
608 return "pcrel sdata8";
609 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4:
610 return "indirect pcrel udata4";
611 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4:
612 return "indirect pcrel sdata4";
613 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8:
614 return "indirect pcrel udata8";
615 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8:
616 return "indirect pcrel sdata8";
617 }
618
619 return 0;
620}
621
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +0000622void AsmPrinter::EOL(const Twine &Comment, unsigned Encoding) const {
623 if (VerboseAsm && !Comment.isTriviallyEmpty()) {
Bill Wendlingb5abecd2009-08-29 12:17:53 +0000624 O.PadToColumn(MAI->getCommentColumn());
625 O << MAI->getCommentString()
626 << ' '
627 << Comment;
628
629 if (const char *EncStr = DecodeDWARFEncoding(Encoding))
630 O << " (" << EncStr << ')';
631 }
632 O << '\n';
633}
634
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000635/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
636/// unsigned leb128 value.
637void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000638 if (MAI->hasLEB128()) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000639 O << "\t.uleb128\t"
640 << Value;
641 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000642 O << MAI->getData8bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000643 PrintULEB128(Value);
644 }
645}
646
647/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
648/// signed leb128 value.
649void AsmPrinter::EmitSLEB128Bytes(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000650 if (MAI->hasLEB128()) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000651 O << "\t.sleb128\t"
652 << Value;
653 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000654 O << MAI->getData8bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000655 PrintSLEB128(Value);
656 }
657}
658
659/// EmitInt8 - Emit a byte directive and value.
660///
661void AsmPrinter::EmitInt8(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000662 O << MAI->getData8bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000663 PrintHex(Value & 0xFF);
664}
665
666/// EmitInt16 - Emit a short directive and value.
667///
668void AsmPrinter::EmitInt16(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000669 O << MAI->getData16bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000670 PrintHex(Value & 0xFFFF);
671}
672
673/// EmitInt32 - Emit a long directive and value.
674///
675void AsmPrinter::EmitInt32(int Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000676 O << MAI->getData32bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000677 PrintHex(Value);
678}
679
680/// EmitInt64 - Emit a long long directive and value.
681///
682void AsmPrinter::EmitInt64(uint64_t Value) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000683 if (MAI->getData64bitsDirective()) {
684 O << MAI->getData64bitsDirective();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000685 PrintHex(Value);
686 } else {
687 if (TM.getTargetData()->isBigEndian()) {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000688 EmitInt32(unsigned(Value >> 32)); O << '\n';
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000689 EmitInt32(unsigned(Value));
690 } else {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000691 EmitInt32(unsigned(Value)); O << '\n';
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000692 EmitInt32(unsigned(Value >> 32));
693 }
694 }
695}
696
697/// toOctal - Convert the low order bits of X into an octal digit.
698///
699static inline char toOctal(int X) {
700 return (X&7)+'0';
701}
702
703/// printStringChar - Print a char, escaped if necessary.
704///
David Greene71847812009-07-14 20:18:05 +0000705static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000706 if (C == '"') {
707 O << "\\\"";
708 } else if (C == '\\') {
709 O << "\\\\";
Chris Lattnerbbfa2442009-01-22 23:38:45 +0000710 } else if (isprint((unsigned char)C)) {
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000711 O << C;
712 } else {
713 switch(C) {
714 case '\b': O << "\\b"; break;
715 case '\f': O << "\\f"; break;
716 case '\n': O << "\\n"; break;
717 case '\r': O << "\\r"; break;
718 case '\t': O << "\\t"; break;
719 default:
720 O << '\\';
721 O << toOctal(C >> 6);
722 O << toOctal(C >> 3);
723 O << toOctal(C >> 0);
724 break;
725 }
726 }
727}
728
729/// EmitString - Emit a string with quotes and a null terminator.
730/// Special characters are emitted properly.
731/// \literal (Eg. '\t') \endliteral
Devang Patele9a05972009-11-24 19:42:17 +0000732void AsmPrinter::EmitString(const StringRef String) const {
Dan Gohman24f8e292009-11-13 21:55:31 +0000733 EmitString(String.data(), String.size());
Bill Wendlingf34be822009-04-09 23:51:31 +0000734}
735
736void AsmPrinter::EmitString(const char *String, unsigned Size) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000737 const char* AscizDirective = MAI->getAscizDirective();
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000738 if (AscizDirective)
739 O << AscizDirective;
740 else
Chris Lattner33adcfb2009-08-22 21:43:10 +0000741 O << MAI->getAsciiDirective();
Dan Gohmand19a53b2008-06-30 22:03:41 +0000742 O << '\"';
Bill Wendlingf34be822009-04-09 23:51:31 +0000743 for (unsigned i = 0; i < Size; ++i)
Chris Lattnera118c2e2009-04-08 00:28:38 +0000744 printStringChar(O, String[i]);
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000745 if (AscizDirective)
Dan Gohmand19a53b2008-06-30 22:03:41 +0000746 O << '\"';
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000747 else
748 O << "\\0\"";
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000749}
750
751
Dan Gohman189f80d2007-09-24 20:58:13 +0000752/// EmitFile - Emit a .file directive.
Benjamin Kramer1efd4fd52010-01-17 07:46:39 +0000753void AsmPrinter::EmitFile(unsigned Number, StringRef Name) const {
Dan Gohman189f80d2007-09-24 20:58:13 +0000754 O << "\t.file\t" << Number << " \"";
Chris Lattnera118c2e2009-04-08 00:28:38 +0000755 for (unsigned i = 0, N = Name.size(); i < N; ++i)
756 printStringChar(O, Name[i]);
Dan Gohmand19a53b2008-06-30 22:03:41 +0000757 O << '\"';
Dan Gohman189f80d2007-09-24 20:58:13 +0000758}
759
760
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000761//===----------------------------------------------------------------------===//
762
Chris Lattner3a420532007-05-31 18:57:45 +0000763// EmitAlignment - Emit an alignment directive to the specified power of
764// two boundary. For example, if you pass in 3 here, you will get an 8
765// byte alignment. If a global value is specified, and if that global has
766// an explicit alignment requested, it will unconditionally override the
767// alignment request. However, if ForcedAlignBits is specified, this value
768// has final say: the ultimate alignment will be the max of ForcedAlignBits
769// and the alignment computed with NumBits and the global.
770//
771// The algorithm is:
772// Align = NumBits;
773// if (GV && GV->hasalignment) Align = GV->getalignment();
774// Align = std::max(Align, ForcedAlignBits);
775//
776void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
Evan Cheng05548eb2008-02-29 19:36:59 +0000777 unsigned ForcedAlignBits,
778 bool UseFillExpr) const {
Dale Johannesen00d56b92007-04-23 23:33:31 +0000779 if (GV && GV->getAlignment())
Chris Lattner3a420532007-05-31 18:57:45 +0000780 NumBits = Log2_32(GV->getAlignment());
781 NumBits = std::max(NumBits, ForcedAlignBits);
782
Chris Lattner2a21c6e2005-11-10 18:09:27 +0000783 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattner663c2d22009-08-19 06:12:02 +0000784
785 unsigned FillValue = 0;
Chris Lattnerdabf07c2009-08-18 06:15:16 +0000786 if (getCurrentSection()->getKind().isText())
Chris Lattner33adcfb2009-08-22 21:43:10 +0000787 FillValue = MAI->getTextAlignFillValue();
Chris Lattner663c2d22009-08-19 06:12:02 +0000788
789 OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0);
Chris Lattnerbfddc202004-08-17 19:14:29 +0000790}
David Greenea5bb59f2009-08-05 21:00:52 +0000791
Chris Lattner25045bd2005-11-21 07:51:36 +0000792/// EmitZeros - Emit a block of zeros.
Chris Lattner7d057a32004-08-17 21:38:40 +0000793///
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +0000794void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
Chris Lattner7d057a32004-08-17 21:38:40 +0000795 if (NumZeros) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000796 if (MAI->getZeroDirective()) {
797 O << MAI->getZeroDirective() << NumZeros;
798 if (MAI->getZeroDirectiveSuffix())
799 O << MAI->getZeroDirectiveSuffix();
Dan Gohmand19a53b2008-06-30 22:03:41 +0000800 O << '\n';
Jeff Cohenc6a057b2006-05-02 03:46:13 +0000801 } else {
Chris Lattner7d057a32004-08-17 21:38:40 +0000802 for (; NumZeros; --NumZeros)
Chris Lattner33adcfb2009-08-22 21:43:10 +0000803 O << MAI->getData8bitsDirective(AddrSpace) << "0\n";
Chris Lattner7d057a32004-08-17 21:38:40 +0000804 }
805 }
806}
807
Chris Lattnera80ba712004-08-16 23:15:22 +0000808// Print out the specified constant, without a storage class. Only the
809// constants valid in constant expressions can occur here.
Chris Lattner25045bd2005-11-21 07:51:36 +0000810void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000811 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Dan Gohmand19a53b2008-06-30 22:03:41 +0000812 O << '0';
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000813 return;
814 }
815
816 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Scott Michel4315eee2008-06-03 06:18:19 +0000817 O << CI->getZExtValue();
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000818 return;
819 }
820
821 if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina855a5192005-04-02 12:21:51 +0000822 // This is a constant address for a global variable or function. Use the
Chris Lattnerbfd1e502009-09-15 23:11:32 +0000823 // name of the variable or function as the address value.
Chris Lattner10b318b2010-01-17 21:43:43 +0000824 O << *GetGlobalValueSymbol(GV);
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000825 return;
826 }
827
828 if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
Chris Lattner10b318b2010-01-17 21:43:43 +0000829 O << *GetBlockAddressSymbol(BA);
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000830 return;
831 }
832
833 const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
834 if (CE == 0) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000835 llvm_unreachable("Unknown constant value!");
Chris Lattnerfe0e7ed2010-01-13 04:29:19 +0000836 O << '0';
837 return;
838 }
839
840 switch (CE->getOpcode()) {
841 case Instruction::ZExt:
842 case Instruction::SExt:
843 case Instruction::FPTrunc:
844 case Instruction::FPExt:
845 case Instruction::UIToFP:
846 case Instruction::SIToFP:
847 case Instruction::FPToUI:
848 case Instruction::FPToSI:
849 default:
850 llvm_unreachable("FIXME: Don't support this constant cast expr");
851 case Instruction::GetElementPtr: {
852 // generate a symbolic expression for the byte address
853 const TargetData *TD = TM.getTargetData();
854 const Constant *ptrVal = CE->getOperand(0);
855 SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
856 int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
857 idxVec.size());
858 if (Offset == 0)
859 return EmitConstantValueOnly(ptrVal);
860
861 // Truncate/sext the offset to the pointer size.
862 if (TD->getPointerSizeInBits() != 64) {
863 int SExtAmount = 64-TD->getPointerSizeInBits();
864 Offset = (Offset << SExtAmount) >> SExtAmount;
865 }
866
867 if (Offset)
868 O << '(';
869 EmitConstantValueOnly(ptrVal);
870 if (Offset > 0)
871 O << ") + " << Offset;
872 else
873 O << ") - " << -Offset;
874 return;
875 }
876 case Instruction::BitCast:
877 return EmitConstantValueOnly(CE->getOperand(0));
878
879 case Instruction::IntToPtr: {
880 // Handle casts to pointers by changing them into casts to the appropriate
881 // integer type. This promotes constant folding and simplifies this code.
882 const TargetData *TD = TM.getTargetData();
883 Constant *Op = CE->getOperand(0);
884 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
885 false/*ZExt*/);
886 return EmitConstantValueOnly(Op);
887 }
888
889 case Instruction::PtrToInt: {
890 // Support only foldable casts to/from pointers that can be eliminated by
891 // changing the pointer to the appropriately sized integer type.
892 Constant *Op = CE->getOperand(0);
893 const Type *Ty = CE->getType();
894 const TargetData *TD = TM.getTargetData();
895
896 // We can emit the pointer value into this slot if the slot is an
897 // integer slot greater or equal to the size of the pointer.
898 if (TD->getTypeAllocSize(Ty) == TD->getTypeAllocSize(Op->getType()))
899 return EmitConstantValueOnly(Op);
900
901 O << "((";
902 EmitConstantValueOnly(Op);
903 APInt ptrMask =
904 APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Op->getType()));
905
906 SmallString<40> S;
907 ptrMask.toStringUnsigned(S);
908 O << ") & " << S.str() << ')';
909 return;
910 }
911
912 case Instruction::Trunc:
913 // We emit the value and depend on the assembler to truncate the generated
914 // expression properly. This is important for differences between
915 // blockaddress labels. Since the two labels are in the same function, it
916 // is reasonable to treat their delta as a 32-bit value.
917 return EmitConstantValueOnly(CE->getOperand(0));
918
919 case Instruction::Add:
920 case Instruction::Sub:
921 case Instruction::And:
922 case Instruction::Or:
923 case Instruction::Xor:
924 O << '(';
925 EmitConstantValueOnly(CE->getOperand(0));
926 O << ')';
927 switch (CE->getOpcode()) {
928 case Instruction::Add:
929 O << " + ";
930 break;
931 case Instruction::Sub:
932 O << " - ";
933 break;
934 case Instruction::And:
935 O << " & ";
936 break;
937 case Instruction::Or:
938 O << " | ";
939 break;
940 case Instruction::Xor:
941 O << " ^ ";
942 break;
943 default:
944 break;
945 }
946 O << '(';
947 EmitConstantValueOnly(CE->getOperand(1));
948 O << ')';
949 break;
Chris Lattnera80ba712004-08-16 23:15:22 +0000950 }
951}
Chris Lattner1b7e2352004-08-17 06:36:49 +0000952
Chris Lattner2980cef2005-11-10 18:06:33 +0000953/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner1b7e2352004-08-17 06:36:49 +0000954/// the predicate isString is true.
955///
David Greene71847812009-07-14 20:18:05 +0000956static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
Chris Lattner2980cef2005-11-10 18:06:33 +0000957 unsigned LastElt) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000958 assert(CVA->isString() && "Array is not string compatible!");
959
Dan Gohmand19a53b2008-06-30 22:03:41 +0000960 O << '\"';
Chris Lattner2980cef2005-11-10 18:06:33 +0000961 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000962 unsigned char C =
Reid Spencerb83eb642006-10-20 07:07:24 +0000963 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000964 printStringChar(O, C);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000965 }
Dan Gohmand19a53b2008-06-30 22:03:41 +0000966 O << '\"';
Chris Lattner1b7e2352004-08-17 06:36:49 +0000967}
968
Jeff Cohenc884db42006-05-02 01:16:28 +0000969/// EmitString - Emit a zero-byte-terminated string constant.
970///
971void AsmPrinter::EmitString(const ConstantArray *CVA) const {
972 unsigned NumElts = CVA->getNumOperands();
Chris Lattner33adcfb2009-08-22 21:43:10 +0000973 if (MAI->getAscizDirective() && NumElts &&
Reid Spencerb83eb642006-10-20 07:07:24 +0000974 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000975 O << MAI->getAscizDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000976 printAsCString(O, CVA, NumElts-1);
977 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +0000978 O << MAI->getAsciiDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000979 printAsCString(O, CVA, NumElts);
980 }
Dan Gohmand19a53b2008-06-30 22:03:41 +0000981 O << '\n';
Jeff Cohenc884db42006-05-02 01:16:28 +0000982}
983
Sanjiv Guptad3d96572009-04-28 16:34:20 +0000984void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA,
985 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +0000986 if (CVA->isString()) {
987 EmitString(CVA);
988 } else { // Not a string. Print the values in successive locations
989 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Sanjiv Guptad3d96572009-04-28 16:34:20 +0000990 EmitGlobalConstant(CVA->getOperand(i), AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +0000991 }
992}
993
994void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) {
995 const VectorType *PTy = CP->getType();
996
997 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
998 EmitGlobalConstant(CP->getOperand(I));
999}
1000
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001001void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
1002 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001003 // Print the fields in successive locations. Pad to align if needed!
1004 const TargetData *TD = TM.getTargetData();
Duncan Sands777d2302009-05-09 07:06:46 +00001005 unsigned Size = TD->getTypeAllocSize(CVS->getType());
Dan Gohman00d448a2008-12-22 21:14:27 +00001006 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
1007 uint64_t sizeSoFar = 0;
1008 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
1009 const Constant* field = CVS->getOperand(i);
1010
1011 // Check if padding is needed and insert one or more 0s.
Duncan Sands777d2302009-05-09 07:06:46 +00001012 uint64_t fieldSize = TD->getTypeAllocSize(field->getType());
Dan Gohman00d448a2008-12-22 21:14:27 +00001013 uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
1014 - cvsLayout->getElementOffset(i)) - fieldSize;
1015 sizeSoFar += fieldSize + padSize;
1016
1017 // Now print the actual field value.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001018 EmitGlobalConstant(field, AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001019
1020 // Insert padding - this may include padding to increase the size of the
1021 // current field up to the ABI size (if the struct is not packed) as well
1022 // as padding to ensure that the next field starts at the right offset.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001023 EmitZeros(padSize, AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001024 }
1025 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
1026 "Layout of constant struct may be incorrect!");
1027}
1028
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001029void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
1030 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001031 // FP Constants are printed as integer constants to avoid losing
1032 // precision...
Owen Anderson1d0be152009-08-13 21:58:54 +00001033 LLVMContext &Context = CFP->getContext();
Dan Gohman00d448a2008-12-22 21:14:27 +00001034 const TargetData *TD = TM.getTargetData();
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001035 if (CFP->getType()->isDoubleTy()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001036 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
1037 uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
Chris Lattner33adcfb2009-08-22 21:43:10 +00001038 if (MAI->getData64bitsDirective(AddrSpace)) {
1039 O << MAI->getData64bitsDirective(AddrSpace) << i;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001040 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001041 O.PadToColumn(MAI->getCommentColumn());
1042 O << MAI->getCommentString() << " double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001043 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001044 O << '\n';
1045 } else if (TD->isBigEndian()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001046 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
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()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001050 << " most significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001051 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001052 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001053 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
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 << " least significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001058 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001059 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001060 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001061 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001062 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001063 O.PadToColumn(MAI->getCommentColumn());
1064 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001065 << " least significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001066 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001067 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001068 O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
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 << " most significant word of double " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001073 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001074 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001075 }
1076 return;
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001077 }
1078
1079 if (CFP->getType()->isFloatTy()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001080 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
Chris Lattner33adcfb2009-08-22 21:43:10 +00001081 O << MAI->getData32bitsDirective(AddrSpace)
Evan Chengf1c0ae92009-03-24 00:17:40 +00001082 << CFP->getValueAPF().bitcastToAPInt().getZExtValue();
Dan Gohmana12e9d72009-08-12 18:32:22 +00001083 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001084 O.PadToColumn(MAI->getCommentColumn());
1085 O << MAI->getCommentString() << " float " << Val;
Dan Gohmana12e9d72009-08-12 18:32:22 +00001086 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001087 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001088 return;
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001089 }
1090
1091 if (CFP->getType()->isX86_FP80Ty()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001092 // all long double variants are printed as hex
1093 // api needed to prevent premature destruction
1094 APInt api = CFP->getValueAPF().bitcastToAPInt();
1095 const uint64_t *p = api.getRawData();
1096 // Convert to double so we can print the approximate val as a comment.
1097 APFloat DoubleVal = CFP->getValueAPF();
1098 bool ignored;
1099 DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1100 &ignored);
1101 if (TD->isBigEndian()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001102 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001103 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001104 O.PadToColumn(MAI->getCommentColumn());
1105 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001106 << " most significant halfword of x86_fp80 ~"
Evan Chengf1c0ae92009-03-24 00:17:40 +00001107 << DoubleVal.convertToDouble();
Dan Gohmana12e9d72009-08-12 18:32:22 +00001108 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001109 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001110 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001111 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001112 O.PadToColumn(MAI->getCommentColumn());
1113 O << MAI->getCommentString() << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001114 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001115 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001116 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001117 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001118 O.PadToColumn(MAI->getCommentColumn());
1119 O << MAI->getCommentString() << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001120 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001121 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001122 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001123 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001124 O.PadToColumn(MAI->getCommentColumn());
1125 O << MAI->getCommentString() << " next halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001126 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001127 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001128 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001129 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001130 O.PadToColumn(MAI->getCommentColumn());
1131 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001132 << " least significant halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001133 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001134 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001135 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001136 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001137 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001138 O.PadToColumn(MAI->getCommentColumn());
1139 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001140 << " least significant halfword of x86_fp80 ~"
Evan Chengf1c0ae92009-03-24 00:17:40 +00001141 << DoubleVal.convertToDouble();
Dan Gohmana12e9d72009-08-12 18:32:22 +00001142 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001143 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001144 O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001145 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001146 O.PadToColumn(MAI->getCommentColumn());
1147 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001148 << " next halfword";
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] >> 32);
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] >> 48);
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[1]);
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 << " most significant halfword";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001170 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001171 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001172 }
Owen Anderson1d0be152009-08-13 21:58:54 +00001173 EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) -
1174 TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001175 return;
Chris Lattnercf0fe8d2009-10-05 05:54:46 +00001176 }
1177
1178 if (CFP->getType()->isPPC_FP128Ty()) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001179 // all long double variants are printed as hex
1180 // api needed to prevent premature destruction
1181 APInt api = CFP->getValueAPF().bitcastToAPInt();
1182 const uint64_t *p = api.getRawData();
1183 if (TD->isBigEndian()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001184 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001185 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001186 O.PadToColumn(MAI->getCommentColumn());
1187 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001188 << " most significant word of ppc_fp128";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001189 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001190 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001191 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
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 << " next word";
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[1] >> 32);
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]);
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 << " least significant word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001210 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001211 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001212 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001213 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
Dan Gohmana12e9d72009-08-12 18:32:22 +00001214 if (VerboseAsm) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001215 O.PadToColumn(MAI->getCommentColumn());
1216 O << MAI->getCommentString()
Dan Gohmancf20ac42009-08-13 01:36:44 +00001217 << " least significant word of ppc_fp128";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001218 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001219 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001220 O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
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 << " next word";
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[0]);
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] >> 32);
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 << " most significant word";
Dan Gohmana12e9d72009-08-12 18:32:22 +00001239 }
Evan Chengf1c0ae92009-03-24 00:17:40 +00001240 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001241 }
1242 return;
Torok Edwinc23197a2009-07-14 16:55:14 +00001243 } else llvm_unreachable("Floating point constant type not handled");
Dan Gohman00d448a2008-12-22 21:14:27 +00001244}
1245
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001246void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
1247 unsigned AddrSpace) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001248 const TargetData *TD = TM.getTargetData();
1249 unsigned BitWidth = CI->getBitWidth();
Chris Lattner38c2b0a2010-01-13 04:39:46 +00001250 assert((BitWidth & 63) == 0 && "only support multiples of 64-bits");
Dan Gohman00d448a2008-12-22 21:14:27 +00001251
1252 // We don't expect assemblers to support integer data directives
1253 // for more than 64 bits, so we emit the data in at most 64-bit
1254 // quantities at a time.
1255 const uint64_t *RawData = CI->getValue().getRawData();
1256 for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
1257 uint64_t Val;
1258 if (TD->isBigEndian())
1259 Val = RawData[e - i - 1];
1260 else
1261 Val = RawData[i];
1262
Chris Lattner5979dff2010-01-13 04:38:16 +00001263 if (MAI->getData64bitsDirective(AddrSpace)) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001264 O << MAI->getData64bitsDirective(AddrSpace) << Val << '\n';
Chris Lattner5979dff2010-01-13 04:38:16 +00001265 continue;
Dan Gohman00d448a2008-12-22 21:14:27 +00001266 }
Chris Lattner5979dff2010-01-13 04:38:16 +00001267
1268 // Emit two 32-bit chunks, order depends on endianness.
1269 unsigned FirstChunk = unsigned(Val), SecondChunk = unsigned(Val >> 32);
1270 const char *FirstName = " least", *SecondName = " most";
1271 if (TD->isBigEndian()) {
1272 std::swap(FirstChunk, SecondChunk);
1273 std::swap(FirstName, SecondName);
1274 }
1275
1276 O << MAI->getData32bitsDirective(AddrSpace) << FirstChunk;
1277 if (VerboseAsm) {
1278 O.PadToColumn(MAI->getCommentColumn());
1279 O << MAI->getCommentString()
1280 << FirstName << " significant half of i64 " << Val;
1281 }
1282 O << '\n';
1283
1284 O << MAI->getData32bitsDirective(AddrSpace) << SecondChunk;
1285 if (VerboseAsm) {
1286 O.PadToColumn(MAI->getCommentColumn());
1287 O << MAI->getCommentString()
1288 << SecondName << " significant half of i64 " << Val;
1289 }
1290 O << '\n';
Dan Gohman00d448a2008-12-22 21:14:27 +00001291 }
1292}
1293
Chris Lattner25045bd2005-11-21 07:51:36 +00001294/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001295void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
Owen Andersona69571c2006-05-03 01:29:57 +00001296 const TargetData *TD = TM.getTargetData();
Dan Gohman00d448a2008-12-22 21:14:27 +00001297 const Type *type = CV->getType();
Duncan Sands777d2302009-05-09 07:06:46 +00001298 unsigned Size = TD->getTypeAllocSize(type);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001299
Chris Lattnerbd1d3822004-10-16 18:19:26 +00001300 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001301 EmitZeros(Size, AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001302 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001303 }
1304
1305 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
Sanjiv Guptad3d96572009-04-28 16:34:20 +00001306 EmitGlobalConstantArray(CVA , AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001307 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001308 }
1309
1310 if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001311 EmitGlobalConstantStruct(CVS, AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001312 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001313 }
1314
1315 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001316 EmitGlobalConstantFP(CFP, AddrSpace);
Dan Gohman00d448a2008-12-22 21:14:27 +00001317 return;
Chris Lattner3cc3a002010-01-13 04:34:19 +00001318 }
1319
1320 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1321 // If we can directly emit an 8-byte constant, do it.
1322 if (Size == 8)
1323 if (const char *Data64Dir = MAI->getData64bitsDirective(AddrSpace)) {
1324 O << Data64Dir << CI->getZExtValue() << '\n';
1325 return;
1326 }
1327
Dan Gohman00d448a2008-12-22 21:14:27 +00001328 // Small integers are handled below; large integers are handled here.
1329 if (Size > 4) {
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001330 EmitGlobalConstantLargeInt(CI, AddrSpace);
Chris Lattner1b7e2352004-08-17 06:36:49 +00001331 return;
1332 }
Chris Lattner3cc3a002010-01-13 04:34:19 +00001333 }
1334
1335 if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
Dan Gohman00d448a2008-12-22 21:14:27 +00001336 EmitGlobalConstantVector(CP);
Nate Begeman8cfa57b2005-12-06 06:18:55 +00001337 return;
Chris Lattner1b7e2352004-08-17 06:36:49 +00001338 }
1339
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001340 printDataDirective(type, AddrSpace);
Chris Lattner25045bd2005-11-21 07:51:36 +00001341 EmitConstantValueOnly(CV);
Evan Chengf1c0ae92009-03-24 00:17:40 +00001342 if (VerboseAsm) {
1343 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1344 SmallString<40> S;
1345 CI->getValue().toStringUnsigned(S, 16);
Chris Lattner33adcfb2009-08-22 21:43:10 +00001346 O.PadToColumn(MAI->getCommentColumn());
1347 O << MAI->getCommentString() << " 0x" << S.str();
Evan Chengf1c0ae92009-03-24 00:17:40 +00001348 }
Scott Micheleefc8452008-06-03 15:39:51 +00001349 }
Dan Gohmand19a53b2008-06-30 22:03:41 +00001350 O << '\n';
Chris Lattner1b7e2352004-08-17 06:36:49 +00001351}
Chris Lattner0264d1a2006-01-27 02:10:10 +00001352
Chris Lattnerfad86b02008-08-17 07:19:36 +00001353void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
Evan Chengd6594ae2006-09-12 21:00:35 +00001354 // Target doesn't support this yet!
Torok Edwinc23197a2009-07-14 16:55:14 +00001355 llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
Evan Chengd6594ae2006-09-12 21:00:35 +00001356}
1357
Chris Lattner3ce9b672006-09-26 23:59:50 +00001358/// PrintSpecial - Print information related to the specified machine instr
1359/// that is independent of the operand, and may be independent of the instr
1360/// itself. This can be useful for portably encoding the comment character
1361/// or other bits of target-specific knowledge into the asmstrings. The
1362/// syntax used is ${:comment}. Targets can override this to add support
1363/// for their own strange codes.
Chris Lattner3e0cc262009-03-10 05:37:13 +00001364void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
Chris Lattnerbae02cf2006-09-27 00:06:07 +00001365 if (!strcmp(Code, "private")) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001366 O << MAI->getPrivateGlobalPrefix();
Chris Lattnerbae02cf2006-09-27 00:06:07 +00001367 } else if (!strcmp(Code, "comment")) {
Evan Chengf1c0ae92009-03-24 00:17:40 +00001368 if (VerboseAsm)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001369 O << MAI->getCommentString();
Chris Lattner3ce9b672006-09-26 23:59:50 +00001370 } else if (!strcmp(Code, "uid")) {
Chris Lattnerb6a24bf2007-02-05 21:23:52 +00001371 // Comparing the address of MI isn't sufficient, because machineinstrs may
1372 // be allocated to the same address across functions.
1373 const Function *ThisF = MI->getParent()->getParent()->getFunction();
1374
Owen Andersonbd58edf2009-06-24 22:28:12 +00001375 // If this is a new LastFn instruction, bump the counter.
1376 if (LastMI != MI || LastFn != ThisF) {
Chris Lattnerb6a24bf2007-02-05 21:23:52 +00001377 ++Counter;
1378 LastMI = MI;
Owen Andersonbd58edf2009-06-24 22:28:12 +00001379 LastFn = ThisF;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +00001380 }
Chris Lattner3ce9b672006-09-26 23:59:50 +00001381 O << Counter;
1382 } else {
Torok Edwin7d696d82009-07-11 13:10:19 +00001383 std::string msg;
1384 raw_string_ostream Msg(msg);
1385 Msg << "Unknown special formatter '" << Code
Bill Wendlinge8156192006-12-07 01:30:32 +00001386 << "' for machine instr: " << *MI;
Torok Edwin7d696d82009-07-11 13:10:19 +00001387 llvm_report_error(Msg.str());
Chris Lattner3ce9b672006-09-26 23:59:50 +00001388 }
1389}
1390
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +00001391/// processDebugLoc - Processes the debug information of each machine
1392/// instruction's DebugLoc.
Devang Patelaf0e2722009-10-06 02:19:11 +00001393void AsmPrinter::processDebugLoc(const MachineInstr *MI,
1394 bool BeforePrintingInsn) {
Devang Patel53bb5c92009-11-10 23:06:00 +00001395 if (!MAI || !DW || !MAI->doesSupportDebugInformation()
1396 || !DW->ShouldEmitDwarfDebug())
Chris Lattnerd2503292009-08-05 04:09:18 +00001397 return;
Devang Patelb0fdedb2009-09-30 23:12:50 +00001398 DebugLoc DL = MI->getDebugLoc();
Devang Patel53bb5c92009-11-10 23:06:00 +00001399 if (DL.isUnknown())
1400 return;
Devang Patel6b61f582010-01-16 06:09:35 +00001401 DILocation CurDLT = MF->getDILocation(DL);
1402 if (CurDLT.getScope().isNull())
Devang Patel53bb5c92009-11-10 23:06:00 +00001403 return;
1404
1405 if (BeforePrintingInsn) {
Devang Patel6b61f582010-01-16 06:09:35 +00001406 if (CurDLT.getNode() != PrevDLT.getNode()) {
1407 unsigned L = DW->RecordSourceLine(CurDLT.getLineNumber(),
1408 CurDLT.getColumnNumber(),
1409 CurDLT.getScope().getNode());
Devang Patel53bb5c92009-11-10 23:06:00 +00001410 printLabel(L);
Dan Gohmaneecb9912009-12-05 01:42:34 +00001411 O << '\n';
Devang Patel53bb5c92009-11-10 23:06:00 +00001412 DW->BeginScope(MI, L);
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +00001413 PrevDLT = CurDLT;
1414 }
Devang Patel53bb5c92009-11-10 23:06:00 +00001415 } else {
1416 // After printing instruction
1417 DW->EndScope(MI);
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +00001418 }
1419}
Chris Lattner3ce9b672006-09-26 23:59:50 +00001420
Devang Patel53bb5c92009-11-10 23:06:00 +00001421
Chris Lattner0264d1a2006-01-27 02:10:10 +00001422/// printInlineAsm - This method formats and prints the specified machine
1423/// instruction that is an inline asm.
1424void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattnerf2b67cf2006-01-30 23:00:08 +00001425 unsigned NumOperands = MI->getNumOperands();
1426
1427 // Count the number of register definitions.
1428 unsigned NumDefs = 0;
Dan Gohmand735b802008-10-03 15:45:36 +00001429 for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
Chris Lattner67942f52006-09-05 20:02:51 +00001430 ++NumDefs)
Chris Lattnerf2b67cf2006-01-30 23:00:08 +00001431 assert(NumDefs != NumOperands-1 && "No asm string?");
1432
Dan Gohmand735b802008-10-03 15:45:36 +00001433 assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
Chris Lattner66099132006-02-01 22:41:11 +00001434
1435 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattnerf2b67cf2006-01-30 23:00:08 +00001436 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattner66099132006-02-01 22:41:11 +00001437
Dan Gohman40c57862009-11-06 00:04:54 +00001438 O << '\t';
1439
Dale Johannesenba2a0b92008-01-29 02:21:21 +00001440 // If this asmstr is empty, just print the #APP/#NOAPP markers.
1441 // These are useful to see where empty asm's wound up.
Chris Lattnerf26f5dd2006-07-28 00:17:20 +00001442 if (AsmStr[0] == 0) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001443 O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
1444 O << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
Chris Lattnerf26f5dd2006-07-28 00:17:20 +00001445 return;
1446 }
1447
Chris Lattner33adcfb2009-08-22 21:43:10 +00001448 O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
Chris Lattnerf26f5dd2006-07-28 00:17:20 +00001449
Bill Wendlingeb9a42c2007-01-16 03:42:04 +00001450 // The variant of the current asmprinter.
Chris Lattner33adcfb2009-08-22 21:43:10 +00001451 int AsmPrinterVariant = MAI->getAssemblerDialect();
Bill Wendlingeb9a42c2007-01-16 03:42:04 +00001452
Chris Lattner66099132006-02-01 22:41:11 +00001453 int CurVariant = -1; // The number of the {.|.|.} region we are in.
1454 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner2cc2f662006-02-01 01:28:23 +00001455
Chris Lattner66099132006-02-01 22:41:11 +00001456 while (*LastEmitted) {
1457 switch (*LastEmitted) {
1458 default: {
1459 // Not a special case, emit the string section literally.
1460 const char *LiteralEnd = LastEmitted+1;
1461 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattner1c059972006-05-05 21:47:05 +00001462 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattner66099132006-02-01 22:41:11 +00001463 ++LiteralEnd;
1464 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1465 O.write(LastEmitted, LiteralEnd-LastEmitted);
1466 LastEmitted = LiteralEnd;
1467 break;
1468 }
Chris Lattner1c059972006-05-05 21:47:05 +00001469 case '\n':
1470 ++LastEmitted; // Consume newline character.
Dan Gohmand19a53b2008-06-30 22:03:41 +00001471 O << '\n'; // Indent code with newline.
Chris Lattner1c059972006-05-05 21:47:05 +00001472 break;
Chris Lattner66099132006-02-01 22:41:11 +00001473 case '$': {
1474 ++LastEmitted; // Consume '$' character.
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001475 bool Done = true;
1476
1477 // Handle escapes.
1478 switch (*LastEmitted) {
1479 default: Done = false; break;
1480 case '$': // $$ -> $
Chris Lattner66099132006-02-01 22:41:11 +00001481 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1482 O << '$';
1483 ++LastEmitted; // Consume second '$' character.
1484 break;
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001485 case '(': // $( -> same as GCC's { character.
1486 ++LastEmitted; // Consume '(' character.
1487 if (CurVariant != -1) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001488 llvm_report_error("Nested variants found in inline asm string: '"
1489 + std::string(AsmStr) + "'");
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001490 }
1491 CurVariant = 0; // We're in the first variant now.
1492 break;
1493 case '|':
1494 ++LastEmitted; // consume '|' character.
Dale Johannesen8b1e0542008-10-10 21:04:42 +00001495 if (CurVariant == -1)
1496 O << '|'; // this is gcc's behavior for | outside a variant
1497 else
1498 ++CurVariant; // We're in the next variant.
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001499 break;
1500 case ')': // $) -> same as GCC's } char.
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 = -1;
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001506 break;
Chris Lattner66099132006-02-01 22:41:11 +00001507 }
Chris Lattnerfaf1dae2006-10-03 23:27:09 +00001508 if (Done) break;
Chris Lattner66099132006-02-01 22:41:11 +00001509
1510 bool HasCurlyBraces = false;
1511 if (*LastEmitted == '{') { // ${variable}
1512 ++LastEmitted; // Consume '{' character.
1513 HasCurlyBraces = true;
1514 }
1515
Chris Lattner3e0cc262009-03-10 05:37:13 +00001516 // If we have ${:foo}, then this is not a real operand reference, it is a
1517 // "magic" string reference, just like in .td files. Arrange to call
1518 // PrintSpecial.
1519 if (HasCurlyBraces && *LastEmitted == ':') {
1520 ++LastEmitted;
1521 const char *StrStart = LastEmitted;
1522 const char *StrEnd = strchr(StrStart, '}');
1523 if (StrEnd == 0) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001524 llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
1525 + std::string(AsmStr) + "'");
Chris Lattner3e0cc262009-03-10 05:37:13 +00001526 }
1527
1528 std::string Val(StrStart, StrEnd);
1529 PrintSpecial(MI, Val.c_str());
1530 LastEmitted = StrEnd+1;
1531 break;
1532 }
1533
Chris Lattner66099132006-02-01 22:41:11 +00001534 const char *IDStart = LastEmitted;
1535 char *IDEnd;
Chris Lattnerfad29122007-01-23 00:36:17 +00001536 errno = 0;
Chris Lattner66099132006-02-01 22:41:11 +00001537 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1538 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001539 llvm_report_error("Bad $ operand number in inline asm string: '"
1540 + std::string(AsmStr) + "'");
Chris Lattner66099132006-02-01 22:41:11 +00001541 }
1542 LastEmitted = IDEnd;
1543
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001544 char Modifier[2] = { 0, 0 };
1545
Chris Lattner66099132006-02-01 22:41:11 +00001546 if (HasCurlyBraces) {
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001547 // If we have curly braces, check for a modifier character. This
1548 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1549 if (*LastEmitted == ':') {
1550 ++LastEmitted; // Consume ':' character.
1551 if (*LastEmitted == 0) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001552 llvm_report_error("Bad ${:} expression in inline asm string: '"
1553 + std::string(AsmStr) + "'");
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001554 }
1555
1556 Modifier[0] = *LastEmitted;
1557 ++LastEmitted; // Consume modifier character.
1558 }
1559
Chris Lattner66099132006-02-01 22:41:11 +00001560 if (*LastEmitted != '}') {
Torok Edwin7d696d82009-07-11 13:10:19 +00001561 llvm_report_error("Bad ${} expression in inline asm string: '"
1562 + std::string(AsmStr) + "'");
Chris Lattner66099132006-02-01 22:41:11 +00001563 }
1564 ++LastEmitted; // Consume '}' character.
1565 }
1566
1567 if ((unsigned)Val >= NumOperands-1) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001568 llvm_report_error("Invalid $ operand number in inline asm string: '"
1569 + std::string(AsmStr) + "'");
Chris Lattner66099132006-02-01 22:41:11 +00001570 }
1571
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001572 // Okay, we finally have a value number. Ask the target to print this
Chris Lattner66099132006-02-01 22:41:11 +00001573 // operand!
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001574 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1575 unsigned OpNo = 1;
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001576
1577 bool Error = false;
1578
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001579 // Scan to find the machine operand number for the operand.
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001580 for (; Val; --Val) {
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001581 if (OpNo >= MI->getNumOperands()) break;
Chris Lattner9e330492007-12-30 20:50:28 +00001582 unsigned OpFlags = MI->getOperand(OpNo).getImm();
Evan Cheng697cbbf2009-03-20 18:03:34 +00001583 OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001584 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001585
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001586 if (OpNo >= MI->getNumOperands()) {
1587 Error = true;
Chris Lattnerdd260332006-02-24 20:21:58 +00001588 } else {
Chris Lattner9e330492007-12-30 20:50:28 +00001589 unsigned OpFlags = MI->getOperand(OpNo).getImm();
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001590 ++OpNo; // Skip over the ID number.
1591
Chris Lattner10b318b2010-01-17 21:43:43 +00001592 if (Modifier[0] == 'l') // labels are target independent
1593 O << *GetMBBSymbol(MI->getOperand(OpNo).getMBB()->getNumber());
Dale Johanneseneb57ea72007-11-05 21:20:28 +00001594 else {
1595 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
Dale Johannesen86b49f82008-09-24 01:07:17 +00001596 if ((OpFlags & 7) == 4) {
Dale Johanneseneb57ea72007-11-05 21:20:28 +00001597 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1598 Modifier[0] ? Modifier : 0);
1599 } else {
1600 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1601 Modifier[0] ? Modifier : 0);
1602 }
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001603 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001604 }
1605 if (Error) {
Torok Edwin7d696d82009-07-11 13:10:19 +00001606 std::string msg;
1607 raw_string_ostream Msg(msg);
Chris Lattner10b318b2010-01-17 21:43:43 +00001608 Msg << "Invalid operand found in inline asm: '" << AsmStr << "'\n";
Torok Edwin7d696d82009-07-11 13:10:19 +00001609 MI->print(Msg);
1610 llvm_report_error(Msg.str());
Chris Lattner66099132006-02-01 22:41:11 +00001611 }
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001612 }
Chris Lattner66099132006-02-01 22:41:11 +00001613 break;
1614 }
Chris Lattner66099132006-02-01 22:41:11 +00001615 }
1616 }
Chris Lattnerc5ea2632009-09-09 23:14:36 +00001617 O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd();
Chris Lattner66099132006-02-01 22:41:11 +00001618}
1619
Evan Chengda47e6e2008-03-15 00:03:38 +00001620/// printImplicitDef - This method prints the specified machine instruction
1621/// that is an implicit def.
1622void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
Chris Lattnerc5ea2632009-09-09 23:14:36 +00001623 if (!VerboseAsm) return;
1624 O.PadToColumn(MAI->getCommentColumn());
1625 O << MAI->getCommentString() << " implicit-def: "
Chris Lattnerf806c232009-09-13 19:48:37 +00001626 << TRI->getName(MI->getOperand(0).getReg());
Evan Chengda47e6e2008-03-15 00:03:38 +00001627}
1628
Jakob Stoklund Olesenad682642009-11-04 19:24:37 +00001629void AsmPrinter::printKill(const MachineInstr *MI) const {
1630 if (!VerboseAsm) return;
1631 O.PadToColumn(MAI->getCommentColumn());
1632 O << MAI->getCommentString() << " kill:";
1633 for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) {
1634 const MachineOperand &op = MI->getOperand(n);
1635 assert(op.isReg() && "KILL instruction must have only register operands");
1636 O << ' ' << TRI->getName(op.getReg()) << (op.isDef() ? "<def>" : "<kill>");
1637 }
1638}
1639
Jim Laskey1ee29252007-01-26 14:34:52 +00001640/// printLabel - This method prints a local label used by debug and
1641/// exception handling tables.
1642void AsmPrinter::printLabel(const MachineInstr *MI) const {
Dan Gohman528bc022008-07-01 00:16:26 +00001643 printLabel(MI->getOperand(0).getImm());
Jim Laskey1ee29252007-01-26 14:34:52 +00001644}
1645
Evan Cheng1b08bbc2008-02-01 09:10:45 +00001646void AsmPrinter::printLabel(unsigned Id) const {
Chris Lattnerc5ea2632009-09-09 23:14:36 +00001647 O << MAI->getPrivateGlobalPrefix() << "label" << Id << ':';
Evan Cheng1b08bbc2008-02-01 09:10:45 +00001648}
1649
Chris Lattner66099132006-02-01 22:41:11 +00001650/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1651/// instruction, using the specified assembler variant. Targets should
Dale Johannesencf0b7662010-01-14 21:50:17 +00001652/// override this to format as appropriate.
Chris Lattner66099132006-02-01 22:41:11 +00001653bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001654 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattner66099132006-02-01 22:41:11 +00001655 // Target doesn't support this yet!
1656 return true;
Chris Lattner0264d1a2006-01-27 02:10:10 +00001657}
Chris Lattnerdd260332006-02-24 20:21:58 +00001658
1659bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1660 unsigned AsmVariant,
1661 const char *ExtraCode) {
1662 // Target doesn't support this yet!
1663 return true;
1664}
Nate Begeman37efe672006-04-22 18:53:45 +00001665
Dan Gohman29cbade2009-11-20 23:18:13 +00001666MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA,
1667 const char *Suffix) const {
1668 return GetBlockAddressSymbol(BA->getFunction(), BA->getBasicBlock(), Suffix);
Dan Gohman8c2b5252009-10-30 01:27:03 +00001669}
1670
1671MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
Dan Gohman29cbade2009-11-20 23:18:13 +00001672 const BasicBlock *BB,
1673 const char *Suffix) const {
Dan Gohman8c2b5252009-10-30 01:27:03 +00001674 assert(BB->hasName() &&
1675 "Address of anonymous basic block not supported yet!");
1676
Dan Gohman568a3be2009-11-05 23:14:35 +00001677 // This code must use the function name itself, and not the function number,
1678 // since it must be possible to generate the label name from within other
1679 // functions.
Chris Lattner2f8cc262010-01-13 07:30:49 +00001680 SmallString<60> FnName;
1681 Mang->getNameWithPrefix(FnName, F, false);
Dan Gohman8c2b5252009-10-30 01:27:03 +00001682
Chris Lattner2f8cc262010-01-13 07:30:49 +00001683 // FIXME: THIS IS BROKEN IF THE LLVM BASIC BLOCK DOESN'T HAVE A NAME!
Chris Lattner48130352010-01-13 06:38:18 +00001684 SmallString<60> NameResult;
Chris Lattner2f8cc262010-01-13 07:30:49 +00001685 Mang->getNameWithPrefix(NameResult,
1686 StringRef("BA") + Twine((unsigned)FnName.size()) +
1687 "_" + FnName.str() + "_" + BB->getName() + Suffix,
1688 Mangler::Private);
Dan Gohman568a3be2009-11-05 23:14:35 +00001689
Chris Lattner48130352010-01-13 06:38:18 +00001690 return OutContext.GetOrCreateSymbol(NameResult.str());
Dan Gohman8c2b5252009-10-30 01:27:03 +00001691}
1692
Chris Lattner7cb384d2009-09-12 23:02:08 +00001693MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
1694 SmallString<60> Name;
1695 raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
1696 << getFunctionNumber() << '_' << MBBID;
1697
1698 return OutContext.GetOrCreateSymbol(Name.str());
1699}
1700
Chris Lattner6b04ede2010-01-15 23:18:17 +00001701/// GetGlobalValueSymbol - Return the MCSymbol for the specified global
1702/// value.
1703MCSymbol *AsmPrinter::GetGlobalValueSymbol(const GlobalValue *GV) const {
1704 SmallString<60> NameStr;
1705 Mang->getNameWithPrefix(NameStr, GV, false);
1706 return OutContext.GetOrCreateSymbol(NameStr.str());
1707}
1708
Chris Lattner7a2ba942010-01-16 18:37:32 +00001709/// GetSymbolWithGlobalValueBase - Return the MCSymbol for a symbol with
Chris Lattnerd588b972010-01-15 23:25:11 +00001710/// global value name as its base, with the specified suffix, and where the
Chris Lattner7a2ba942010-01-16 18:37:32 +00001711/// symbol is forced to have private linkage if ForcePrivate is true.
1712MCSymbol *AsmPrinter::GetSymbolWithGlobalValueBase(const GlobalValue *GV,
1713 StringRef Suffix,
1714 bool ForcePrivate) const {
Chris Lattnerd588b972010-01-15 23:25:11 +00001715 SmallString<60> NameStr;
Chris Lattner7a2ba942010-01-16 18:37:32 +00001716 Mang->getNameWithPrefix(NameStr, GV, ForcePrivate);
Chris Lattnerd588b972010-01-15 23:25:11 +00001717 NameStr.append(Suffix.begin(), Suffix.end());
1718 return OutContext.GetOrCreateSymbol(NameStr.str());
1719}
1720
Chris Lattner6b04ede2010-01-15 23:18:17 +00001721/// GetExternalSymbolSymbol - Return the MCSymbol for the specified
1722/// ExternalSymbol.
1723MCSymbol *AsmPrinter::GetExternalSymbolSymbol(StringRef Sym) const {
1724 SmallString<60> NameStr;
1725 Mang->getNameWithPrefix(NameStr, Sym);
1726 return OutContext.GetOrCreateSymbol(NameStr.str());
1727}
1728
Chris Lattner7cb384d2009-09-12 23:02:08 +00001729
Chris Lattner70a54c02009-09-13 18:25:37 +00001730/// EmitBasicBlockStart - This method prints the label for the specified
1731/// MachineBasicBlock, an alignment (if present) and a comment describing
1732/// it if appropriate.
Chris Lattner662316c2009-09-14 03:15:54 +00001733void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
Dan Gohmanb1cac332009-10-30 01:34:35 +00001734 // Emit an alignment directive for this block, if needed.
Chris Lattner70a54c02009-09-13 18:25:37 +00001735 if (unsigned Align = MBB->getAlignment())
1736 EmitAlignment(Log2_32(Align));
Evan Chengfb8075d2008-02-28 00:43:03 +00001737
Dan Gohmanb1cac332009-10-30 01:34:35 +00001738 // If the block has its address taken, emit a special label to satisfy
1739 // references to the block. This is done so that we don't need to
1740 // remember the number of this label, and so that we can make
1741 // forward references to labels without knowing what their numbers
1742 // will be.
Dan Gohman8c2b5252009-10-30 01:27:03 +00001743 if (MBB->hasAddressTaken()) {
Chris Lattner10b318b2010-01-17 21:43:43 +00001744 O << *GetBlockAddressSymbol(MBB->getBasicBlock()->getParent(),
1745 MBB->getBasicBlock());
Dan Gohman8c2b5252009-10-30 01:27:03 +00001746 O << ':';
1747 if (VerboseAsm) {
1748 O.PadToColumn(MAI->getCommentColumn());
1749 O << MAI->getCommentString() << " Address Taken";
1750 }
1751 O << '\n';
1752 }
1753
Dan Gohmanb1cac332009-10-30 01:34:35 +00001754 // Print the main label for the block.
Dan Gohmane3cc3f32009-10-06 17:38:38 +00001755 if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
1756 if (VerboseAsm)
1757 O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
1758 } else {
Chris Lattner10b318b2010-01-17 21:43:43 +00001759 O << *GetMBBSymbol(MBB->getNumber()) << ':';
Dan Gohmane3cc3f32009-10-06 17:38:38 +00001760 if (!VerboseAsm)
1761 O << '\n';
1762 }
Chris Lattner70a54c02009-09-13 18:25:37 +00001763
Dan Gohmanb1cac332009-10-30 01:34:35 +00001764 // Print some comments to accompany the label.
Chris Lattner70a54c02009-09-13 18:25:37 +00001765 if (VerboseAsm) {
Dan Gohmane45da0d2009-08-12 18:47:05 +00001766 if (const BasicBlock *BB = MBB->getBasicBlock())
1767 if (BB->hasName()) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001768 O.PadToColumn(MAI->getCommentColumn());
1769 O << MAI->getCommentString() << ' ';
Dan Gohman46d50562009-08-12 20:56:56 +00001770 WriteAsOperand(O, BB, /*PrintType=*/false);
Dan Gohmane45da0d2009-08-12 18:47:05 +00001771 }
David Greeneb71d1b22009-08-10 16:38:07 +00001772
Chris Lattner70a54c02009-09-13 18:25:37 +00001773 EmitComments(*MBB);
Dan Gohmane3cc3f32009-10-06 17:38:38 +00001774 O << '\n';
David Greeneb71d1b22009-08-10 16:38:07 +00001775 }
Nate Begeman37efe672006-04-22 18:53:45 +00001776}
Nate Begeman52a51e382006-08-12 21:29:52 +00001777
Evan Chengcc415862007-11-09 01:32:10 +00001778/// printPICJumpTableSetLabel - This method prints a set label for the
1779/// specified MachineBasicBlock for a jumptable entry.
1780void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
1781 const MachineBasicBlock *MBB) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001782 if (!MAI->getSetDirective())
Nate Begeman52a51e382006-08-12 21:29:52 +00001783 return;
1784
Chris Lattner33adcfb2009-08-22 21:43:10 +00001785 O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
Chris Lattner10b318b2010-01-17 21:43:43 +00001786 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ','
1787 << *GetMBBSymbol(MBB->getNumber())
1788 << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng347d39f2007-10-14 05:57:21 +00001789 << '_' << uid << '\n';
Nate Begeman52a51e382006-08-12 21:29:52 +00001790}
Evan Chengd6594ae2006-09-12 21:00:35 +00001791
Evan Chengcc415862007-11-09 01:32:10 +00001792void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
1793 const MachineBasicBlock *MBB) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001794 if (!MAI->getSetDirective())
Evan Cheng41349c12006-11-01 09:23:08 +00001795 return;
1796
Chris Lattner33adcfb2009-08-22 21:43:10 +00001797 O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
Evan Cheng347d39f2007-10-14 05:57:21 +00001798 << getFunctionNumber() << '_' << uid << '_' << uid2
Chris Lattner10b318b2010-01-17 21:43:43 +00001799 << "_set_" << MBB->getNumber() << ','
1800 << *GetMBBSymbol(MBB->getNumber())
1801 << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng347d39f2007-10-14 05:57:21 +00001802 << '_' << uid << '_' << uid2 << '\n';
Evan Cheng41349c12006-11-01 09:23:08 +00001803}
1804
Evan Chengd6594ae2006-09-12 21:00:35 +00001805/// printDataDirective - This method prints the asm directive for the
1806/// specified type.
Sanjiv Guptac8d7bc82009-01-30 04:25:10 +00001807void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
Evan Chengd6594ae2006-09-12 21:00:35 +00001808 const TargetData *TD = TM.getTargetData();
1809 switch (type->getTypeID()) {
Chris Lattnerf1cfea22009-07-15 04:42:49 +00001810 case Type::FloatTyID: case Type::DoubleTyID:
1811 case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
1812 assert(0 && "Should have already output floating point constant.");
1813 default:
1814 assert(0 && "Can't handle printing this type of thing");
Reid Spencera54b7cb2007-01-12 07:05:14 +00001815 case Type::IntegerTyID: {
1816 unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1817 if (BitWidth <= 8)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001818 O << MAI->getData8bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001819 else if (BitWidth <= 16)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001820 O << MAI->getData16bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001821 else if (BitWidth <= 32)
Chris Lattner33adcfb2009-08-22 21:43:10 +00001822 O << MAI->getData32bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001823 else if (BitWidth <= 64) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001824 assert(MAI->getData64bitsDirective(AddrSpace) &&
Reid Spencera54b7cb2007-01-12 07:05:14 +00001825 "Target cannot handle 64-bit constant exprs!");
Chris Lattner33adcfb2009-08-22 21:43:10 +00001826 O << MAI->getData64bitsDirective(AddrSpace);
Dan Gohman82f94f12008-09-08 16:40:13 +00001827 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +00001828 llvm_unreachable("Target cannot handle given data directive width!");
Reid Spencera54b7cb2007-01-12 07:05:14 +00001829 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001830 break;
Reid Spencera54b7cb2007-01-12 07:05:14 +00001831 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001832 case Type::PointerTyID:
1833 if (TD->getPointerSize() == 8) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001834 assert(MAI->getData64bitsDirective(AddrSpace) &&
Evan Chengd6594ae2006-09-12 21:00:35 +00001835 "Target cannot handle 64-bit pointer exprs!");
Chris Lattner33adcfb2009-08-22 21:43:10 +00001836 O << MAI->getData64bitsDirective(AddrSpace);
Sanjiv Guptafcc6f152009-01-22 10:14:21 +00001837 } else if (TD->getPointerSize() == 2) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001838 O << MAI->getData16bitsDirective(AddrSpace);
Sanjiv Guptafcc6f152009-01-22 10:14:21 +00001839 } else if (TD->getPointerSize() == 1) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001840 O << MAI->getData8bitsDirective(AddrSpace);
Reid Spencera54b7cb2007-01-12 07:05:14 +00001841 } else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00001842 O << MAI->getData32bitsDirective(AddrSpace);
Evan Chengd6594ae2006-09-12 21:00:35 +00001843 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001844 break;
Evan Chengd6594ae2006-09-12 21:00:35 +00001845 }
1846}
Dale Johannesen4c3a5f82007-02-16 01:54:53 +00001847
Chris Lattner53d4d782010-01-15 23:38:51 +00001848void AsmPrinter::printVisibility(const MCSymbol *Sym,
1849 unsigned Visibility) const {
1850 if (Visibility == GlobalValue::HiddenVisibility) {
Chris Lattner10b318b2010-01-17 21:43:43 +00001851 if (const char *Directive = MAI->getHiddenDirective())
1852 O << Directive << *Sym << '\n';
Chris Lattner53d4d782010-01-15 23:38:51 +00001853 } else if (Visibility == GlobalValue::ProtectedVisibility) {
Chris Lattner10b318b2010-01-17 21:43:43 +00001854 if (const char *Directive = MAI->getProtectedDirective())
1855 O << Directive << *Sym << '\n';
Chris Lattner53d4d782010-01-15 23:38:51 +00001856 }
1857}
1858
Anton Korobeynikov7751ad92008-11-22 16:15:34 +00001859void AsmPrinter::printOffset(int64_t Offset) const {
1860 if (Offset > 0)
1861 O << '+' << Offset;
1862 else if (Offset < 0)
1863 O << Offset;
1864}
1865
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001866GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
1867 if (!S->usesMetadata())
Gordon Henriksenc317a602008-08-17 12:08:44 +00001868 return 0;
1869
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001870 gcp_iterator GCPI = GCMetadataPrinters.find(S);
Gordon Henriksenc317a602008-08-17 12:08:44 +00001871 if (GCPI != GCMetadataPrinters.end())
1872 return GCPI->second;
1873
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001874 const char *Name = S->getName().c_str();
Gordon Henriksenc317a602008-08-17 12:08:44 +00001875
1876 for (GCMetadataPrinterRegistry::iterator
1877 I = GCMetadataPrinterRegistry::begin(),
1878 E = GCMetadataPrinterRegistry::end(); I != E; ++I)
1879 if (strcmp(Name, I->getName()) == 0) {
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001880 GCMetadataPrinter *GMP = I->instantiate();
1881 GMP->S = S;
1882 GCMetadataPrinters.insert(std::make_pair(S, GMP));
1883 return GMP;
Gordon Henriksenc317a602008-08-17 12:08:44 +00001884 }
1885
Chris Lattner103289e2009-08-23 07:19:13 +00001886 errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n";
Torok Edwinc23197a2009-07-14 16:55:14 +00001887 llvm_unreachable(0);
Gordon Henriksenc317a602008-08-17 12:08:44 +00001888}
David Greene014700c2009-07-13 20:25:48 +00001889
1890/// EmitComments - Pretty-print comments for instructions
Chris Lattner5f51cd02009-08-07 23:42:01 +00001891void AsmPrinter::EmitComments(const MachineInstr &MI) const {
David Greene1924aab2009-11-13 21:34:57 +00001892 if (!VerboseAsm)
1893 return;
David Greene3ac1ab82009-07-16 22:24:20 +00001894
David Greene1924aab2009-11-13 21:34:57 +00001895 bool Newline = false;
1896
1897 if (!MI.getDebugLoc().isUnknown()) {
Devang Patel6b61f582010-01-16 06:09:35 +00001898 DILocation DLT = MF->getDILocation(MI.getDebugLoc());
David Greene1924aab2009-11-13 21:34:57 +00001899
1900 // Print source line info.
1901 O.PadToColumn(MAI->getCommentColumn());
Dan Gohman3b9bc042009-12-05 00:23:29 +00001902 O << MAI->getCommentString() << ' ';
Devang Patel6b61f582010-01-16 06:09:35 +00001903 DIScope Scope = DLT.getScope();
Dan Gohman3b9bc042009-12-05 00:23:29 +00001904 // Omit the directory, because it's likely to be long and uninteresting.
1905 if (!Scope.isNull())
1906 O << Scope.getFilename();
1907 else
1908 O << "<unknown>";
Devang Patel6b61f582010-01-16 06:09:35 +00001909 O << ':' << DLT.getLineNumber();
1910 if (DLT.getColumnNumber() != 0)
1911 O << ':' << DLT.getColumnNumber();
David Greene1924aab2009-11-13 21:34:57 +00001912 Newline = true;
David Greene3ac1ab82009-07-16 22:24:20 +00001913 }
David Greene1924aab2009-11-13 21:34:57 +00001914
David Greeneddff9412009-11-16 15:12:23 +00001915 // Check for spills and reloads
1916 int FI;
1917
1918 const MachineFrameInfo *FrameInfo =
1919 MI.getParent()->getParent()->getFrameInfo();
1920
1921 // We assume a single instruction only has a spill or reload, not
1922 // both.
David Greenef7ea2a52009-12-04 22:46:04 +00001923 const MachineMemOperand *MMO;
David Greeneddff9412009-11-16 15:12:23 +00001924 if (TM.getInstrInfo()->isLoadFromStackSlotPostFE(&MI, FI)) {
1925 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
David Greenef7ea2a52009-12-04 22:46:04 +00001926 MMO = *MI.memoperands_begin();
David Greeneddff9412009-11-16 15:12:23 +00001927 if (Newline) O << '\n';
1928 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001929 O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Reload";
David Greeneddff9412009-11-16 15:12:23 +00001930 Newline = true;
1931 }
1932 }
David Greenef7ea2a52009-12-04 22:46:04 +00001933 else if (TM.getInstrInfo()->hasLoadFromStackSlot(&MI, MMO, FI)) {
David Greeneddff9412009-11-16 15:12:23 +00001934 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
1935 if (Newline) O << '\n';
1936 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001937 O << MAI->getCommentString() << ' '
1938 << MMO->getSize() << "-byte Folded Reload";
David Greeneddff9412009-11-16 15:12:23 +00001939 Newline = true;
1940 }
1941 }
1942 else if (TM.getInstrInfo()->isStoreToStackSlotPostFE(&MI, FI)) {
1943 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
David Greenef7ea2a52009-12-04 22:46:04 +00001944 MMO = *MI.memoperands_begin();
David Greeneddff9412009-11-16 15:12:23 +00001945 if (Newline) O << '\n';
1946 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001947 O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Spill";
David Greeneddff9412009-11-16 15:12:23 +00001948 Newline = true;
1949 }
1950 }
David Greenef7ea2a52009-12-04 22:46:04 +00001951 else if (TM.getInstrInfo()->hasStoreToStackSlot(&MI, MMO, FI)) {
David Greeneddff9412009-11-16 15:12:23 +00001952 if (FrameInfo->isSpillSlotObjectIndex(FI)) {
1953 if (Newline) O << '\n';
1954 O.PadToColumn(MAI->getCommentColumn());
Dan Gohmanfcafe442009-12-04 23:19:55 +00001955 O << MAI->getCommentString() << ' '
1956 << MMO->getSize() << "-byte Folded Spill";
David Greeneddff9412009-11-16 15:12:23 +00001957 Newline = true;
1958 }
1959 }
1960
1961 // Check for spill-induced copies
1962 unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
1963 if (TM.getInstrInfo()->isMoveInstr(MI, SrcReg, DstReg,
1964 SrcSubIdx, DstSubIdx)) {
1965 if (MI.getAsmPrinterFlag(ReloadReuse)) {
1966 if (Newline) O << '\n';
1967 O.PadToColumn(MAI->getCommentColumn());
1968 O << MAI->getCommentString() << " Reload Reuse";
David Greeneddff9412009-11-16 15:12:23 +00001969 }
1970 }
David Greene014700c2009-07-13 20:25:48 +00001971}
1972
David Greenefe37ab32009-08-18 19:22:55 +00001973/// PrintChildLoopComment - Print comments about child loops within
1974/// the loop for this basic block, with nesting.
1975///
1976static void PrintChildLoopComment(formatted_raw_ostream &O,
1977 const MachineLoop *loop,
Chris Lattner33adcfb2009-08-22 21:43:10 +00001978 const MCAsmInfo *MAI,
David Greenefe37ab32009-08-18 19:22:55 +00001979 int FunctionNumber) {
1980 // Add child loop information
1981 for(MachineLoop::iterator cl = loop->begin(),
1982 clend = loop->end();
1983 cl != clend;
1984 ++cl) {
1985 MachineBasicBlock *Header = (*cl)->getHeader();
1986 assert(Header && "No header for loop");
1987
1988 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00001989 O.PadToColumn(MAI->getCommentColumn());
David Greenefe37ab32009-08-18 19:22:55 +00001990
Chris Lattner33adcfb2009-08-22 21:43:10 +00001991 O << MAI->getCommentString();
Chris Lattnerc281de12009-08-23 00:51:00 +00001992 O.indent(((*cl)->getLoopDepth()-1)*2)
David Greenefe37ab32009-08-18 19:22:55 +00001993 << " Child Loop BB" << FunctionNumber << "_"
1994 << Header->getNumber() << " Depth " << (*cl)->getLoopDepth();
1995
Chris Lattner33adcfb2009-08-22 21:43:10 +00001996 PrintChildLoopComment(O, *cl, MAI, FunctionNumber);
David Greenefe37ab32009-08-18 19:22:55 +00001997 }
1998}
1999
David Greeneb71d1b22009-08-10 16:38:07 +00002000/// EmitComments - Pretty-print comments for basic blocks
David Greene1924aab2009-11-13 21:34:57 +00002001void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const {
David Greenefe37ab32009-08-18 19:22:55 +00002002 if (VerboseAsm) {
David Greeneb71d1b22009-08-10 16:38:07 +00002003 // Add loop depth information
2004 const MachineLoop *loop = LI->getLoopFor(&MBB);
2005
2006 if (loop) {
2007 // Print a newline after bb# annotation.
2008 O << "\n";
Chris Lattner33adcfb2009-08-22 21:43:10 +00002009 O.PadToColumn(MAI->getCommentColumn());
2010 O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth()
David Greeneb71d1b22009-08-10 16:38:07 +00002011 << '\n';
2012
Chris Lattner33adcfb2009-08-22 21:43:10 +00002013 O.PadToColumn(MAI->getCommentColumn());
David Greeneb71d1b22009-08-10 16:38:07 +00002014
2015 MachineBasicBlock *Header = loop->getHeader();
2016 assert(Header && "No header for loop");
2017
2018 if (Header == &MBB) {
Chris Lattner33adcfb2009-08-22 21:43:10 +00002019 O << MAI->getCommentString() << " Loop Header";
2020 PrintChildLoopComment(O, loop, MAI, getFunctionNumber());
David Greeneb71d1b22009-08-10 16:38:07 +00002021 }
2022 else {
Chris Lattner33adcfb2009-08-22 21:43:10 +00002023 O << MAI->getCommentString() << " Loop Header is BB"
David Greeneb71d1b22009-08-10 16:38:07 +00002024 << getFunctionNumber() << "_" << loop->getHeader()->getNumber();
2025 }
2026
2027 if (loop->empty()) {
2028 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00002029 O.PadToColumn(MAI->getCommentColumn());
2030 O << MAI->getCommentString() << " Inner Loop";
David Greeneb71d1b22009-08-10 16:38:07 +00002031 }
2032
2033 // Add parent loop information
2034 for (const MachineLoop *CurLoop = loop->getParentLoop();
2035 CurLoop;
2036 CurLoop = CurLoop->getParentLoop()) {
2037 MachineBasicBlock *Header = CurLoop->getHeader();
2038 assert(Header && "No header for loop");
2039
2040 O << '\n';
Chris Lattner33adcfb2009-08-22 21:43:10 +00002041 O.PadToColumn(MAI->getCommentColumn());
2042 O << MAI->getCommentString();
Chris Lattnerc281de12009-08-23 00:51:00 +00002043 O.indent((CurLoop->getLoopDepth()-1)*2)
David Greenefe37ab32009-08-18 19:22:55 +00002044 << " Inside Loop BB" << getFunctionNumber() << "_"
David Greeneb71d1b22009-08-10 16:38:07 +00002045 << Header->getNumber() << " Depth " << CurLoop->getLoopDepth();
2046 }
2047 }
2048 }
2049}