1 //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the AsmPrinter class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/Assembly/Writer.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Constants.h"
18 #include "llvm/Module.h"
19 #include "llvm/CodeGen/Collector.h"
20 #include "llvm/CodeGen/CollectorMetadata.h"
21 #include "llvm/CodeGen/MachineConstantPool.h"
22 #include "llvm/CodeGen/MachineJumpTableInfo.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/Support/CommandLine.h"
25 #include "llvm/Support/Mangler.h"
26 #include "llvm/Support/MathExtras.h"
27 #include "llvm/Support/Streams.h"
28 #include "llvm/Target/TargetAsmInfo.h"
29 #include "llvm/Target/TargetData.h"
30 #include "llvm/Target/TargetLowering.h"
31 #include "llvm/Target/TargetMachine.h"
32 #include "llvm/ADT/SmallPtrSet.h"
37 AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
39 char AsmPrinter::ID = 0;
40 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
41 const TargetAsmInfo *T)
42 : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T),
43 IsInTextSection(false)
46 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
47 return TAI->getTextSection();
51 /// SwitchToTextSection - Switch to the specified text section of the executable
52 /// if we are not already in it!
54 void AsmPrinter::SwitchToTextSection(const char *NewSection,
55 const GlobalValue *GV) {
57 if (GV && GV->hasSection())
58 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
62 // If we're already in this section, we're done.
63 if (CurrentSection == NS) return;
65 // Close the current section, if applicable.
66 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
67 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
71 if (!CurrentSection.empty())
72 O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
74 IsInTextSection = true;
77 /// SwitchToDataSection - Switch to the specified data section of the executable
78 /// if we are not already in it!
80 void AsmPrinter::SwitchToDataSection(const char *NewSection,
81 const GlobalValue *GV) {
83 if (GV && GV->hasSection())
84 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
88 // If we're already in this section, we're done.
89 if (CurrentSection == NS) return;
91 // Close the current section, if applicable.
92 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
93 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
97 if (!CurrentSection.empty())
98 O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
100 IsInTextSection = false;
104 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
105 MachineFunctionPass::getAnalysisUsage(AU);
106 AU.addRequired<CollectorModuleMetadata>();
109 bool AsmPrinter::doInitialization(Module &M) {
110 Mang = new Mangler(M, TAI->getGlobalPrefix());
112 CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
113 assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
114 for (CollectorModuleMetadata::iterator I = CMM->begin(),
115 E = CMM->end(); I != E; ++I)
116 (*I)->beginAssembly(O, *this, *TAI);
118 if (!M.getModuleInlineAsm().empty())
119 O << TAI->getCommentString() << " Start of file scope inline assembly\n"
120 << M.getModuleInlineAsm()
121 << "\n" << TAI->getCommentString()
122 << " End of file scope inline assembly\n";
124 SwitchToDataSection(""); // Reset back to no section.
126 MMI = getAnalysisToUpdate<MachineModuleInfo>();
127 if (MMI) MMI->AnalyzeModule(M);
132 bool AsmPrinter::doFinalization(Module &M) {
133 if (TAI->getWeakRefDirective()) {
134 if (!ExtWeakSymbols.empty())
135 SwitchToDataSection("");
137 for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
138 e = ExtWeakSymbols.end(); i != e; ++i) {
139 const GlobalValue *GV = *i;
140 std::string Name = Mang->getValueName(GV);
141 O << TAI->getWeakRefDirective() << Name << "\n";
145 if (TAI->getSetDirective()) {
146 if (!M.alias_empty())
147 SwitchToTextSection(TAI->getTextSection());
150 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
152 std::string Name = Mang->getValueName(I);
155 const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
156 Target = Mang->getValueName(GV);
158 if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
159 O << "\t.globl\t" << Name << "\n";
160 else if (I->hasWeakLinkage())
161 O << TAI->getWeakRefDirective() << Name << "\n";
162 else if (!I->hasInternalLinkage())
163 assert(0 && "Invalid alias linkage");
165 O << TAI->getSetDirective() << ' ' << Name << ", " << Target << "\n";
167 // If the aliasee has external weak linkage it can be referenced only by
168 // alias itself. In this case it can be not in ExtWeakSymbols list. Emit
169 // weak reference in such case.
170 if (GV->hasExternalWeakLinkage()) {
171 if (TAI->getWeakRefDirective())
172 O << TAI->getWeakRefDirective() << Target << "\n";
174 O << "\t.globl\t" << Target << "\n";
179 CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
180 assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
181 for (CollectorModuleMetadata::iterator I = CMM->end(),
182 E = CMM->begin(); I != E; )
183 (*--I)->finishAssembly(O, *this, *TAI);
185 delete Mang; Mang = 0;
189 std::string AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) {
190 assert(MF && "No machine function?");
191 return Mang->makeNameProper(MF->getFunction()->getName() + ".eh",
192 TAI->getGlobalPrefix());
195 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
196 // What's my mangled name?
197 CurrentFnName = Mang->getValueName(MF.getFunction());
198 IncrementFunctionNumber();
201 /// EmitConstantPool - Print to the current output stream assembly
202 /// representations of the constants in the constant pool MCP. This is
203 /// used to print out constants which have been "spilled to memory" by
204 /// the code generator.
206 void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
207 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
208 if (CP.empty()) return;
210 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
211 // in special sections.
212 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
213 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
214 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
215 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
216 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > TargetCPs;
217 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
218 MachineConstantPoolEntry CPE = CP[i];
219 const Type *Ty = CPE.getType();
220 if (TAI->getFourByteConstantSection() &&
221 TM.getTargetData()->getABITypeSize(Ty) == 4)
222 FourByteCPs.push_back(std::make_pair(CPE, i));
223 else if (TAI->getEightByteConstantSection() &&
224 TM.getTargetData()->getABITypeSize(Ty) == 8)
225 EightByteCPs.push_back(std::make_pair(CPE, i));
226 else if (TAI->getSixteenByteConstantSection() &&
227 TM.getTargetData()->getABITypeSize(Ty) == 16)
228 SixteenByteCPs.push_back(std::make_pair(CPE, i));
230 OtherCPs.push_back(std::make_pair(CPE, i));
233 unsigned Alignment = MCP->getConstantPoolAlignment();
234 EmitConstantPool(Alignment, TAI->getFourByteConstantSection(), FourByteCPs);
235 EmitConstantPool(Alignment, TAI->getEightByteConstantSection(), EightByteCPs);
236 EmitConstantPool(Alignment, TAI->getSixteenByteConstantSection(),
238 EmitConstantPool(Alignment, TAI->getConstantPoolSection(), OtherCPs);
241 void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
242 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
243 if (CP.empty()) return;
245 SwitchToDataSection(Section);
246 EmitAlignment(Alignment);
247 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
248 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
249 << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
250 WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
251 if (CP[i].first.isMachineConstantPoolEntry())
252 EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
254 EmitGlobalConstant(CP[i].first.Val.ConstVal);
256 const Type *Ty = CP[i].first.getType();
258 TM.getTargetData()->getABITypeSize(Ty);
259 unsigned ValEnd = CP[i].first.getOffset() + EntSize;
260 // Emit inter-object padding for alignment.
261 EmitZeros(CP[i+1].first.getOffset()-ValEnd);
266 /// EmitJumpTableInfo - Print assembly representations of the jump tables used
267 /// by the current function to the current output stream.
269 void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
270 MachineFunction &MF) {
271 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
272 if (JT.empty()) return;
274 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
276 // Pick the directive to use to print the jump table entries, and switch to
277 // the appropriate section.
278 TargetLowering *LoweringInfo = TM.getTargetLowering();
280 const char* JumpTableDataSection = TAI->getJumpTableDataSection();
281 if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
282 !JumpTableDataSection) {
283 // In PIC mode, we need to emit the jump table to the same section as the
284 // function body itself, otherwise the label differences won't make sense.
285 // We should also do if the section name is NULL.
286 const Function *F = MF.getFunction();
287 SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
289 SwitchToDataSection(JumpTableDataSection);
292 EmitAlignment(Log2_32(MJTI->getAlignment()));
294 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
295 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
297 // If this jump table was deleted, ignore it.
298 if (JTBBs.empty()) continue;
300 // For PIC codegen, if possible we want to use the SetDirective to reduce
301 // the number of relocations the assembler will generate for the jump table.
302 // Set directives are all printed before the jump table itself.
303 SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
304 if (TAI->getSetDirective() && IsPic)
305 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
306 if (EmittedSets.insert(JTBBs[ii]))
307 printPICJumpTableSetLabel(i, JTBBs[ii]);
309 // On some targets (e.g. darwin) we want to emit two consequtive labels
310 // before each jump table. The first label is never referenced, but tells
311 // the assembler and linker the extents of the jump table object. The
312 // second label is actually referenced by the code.
313 if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
314 O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
316 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
317 << '_' << i << ":\n";
319 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
320 printPICJumpTableEntry(MJTI, JTBBs[ii], i);
326 void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
327 const MachineBasicBlock *MBB,
328 unsigned uid) const {
329 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
331 // Use JumpTableDirective otherwise honor the entry size from the jump table
333 const char *JTEntryDirective = TAI->getJumpTableDirective();
334 bool HadJTEntryDirective = JTEntryDirective != NULL;
335 if (!HadJTEntryDirective) {
336 JTEntryDirective = MJTI->getEntrySize() == 4 ?
337 TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
340 O << JTEntryDirective << ' ';
342 // If we have emitted set directives for the jump table entries, print
343 // them rather than the entries themselves. If we're emitting PIC, then
344 // emit the table entries as differences between two text section labels.
345 // If we're emitting non-PIC code, then emit the entries as direct
346 // references to the target basic blocks.
348 if (TAI->getSetDirective()) {
349 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
350 << '_' << uid << "_set_" << MBB->getNumber();
352 printBasicBlockLabel(MBB, false, false, false);
353 // If the arch uses custom Jump Table directives, don't calc relative to
355 if (!HadJTEntryDirective)
356 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
357 << getFunctionNumber() << '_' << uid;
360 printBasicBlockLabel(MBB, false, false, false);
365 /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
366 /// special global used by LLVM. If so, emit it and return true, otherwise
367 /// do nothing and return false.
368 bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
369 if (GV->getName() == "llvm.used") {
370 if (TAI->getUsedDirective() != 0) // No need to emit this at all.
371 EmitLLVMUsedList(GV->getInitializer());
375 // Ignore debug and non-emitted data.
376 if (GV->getSection() == "llvm.metadata") return true;
378 if (!GV->hasAppendingLinkage()) return false;
380 assert(GV->hasInitializer() && "Not a special LLVM global!");
382 const TargetData *TD = TM.getTargetData();
383 unsigned Align = Log2_32(TD->getPointerPrefAlignment());
384 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
385 SwitchToDataSection(TAI->getStaticCtorsSection());
386 EmitAlignment(Align, 0);
387 EmitXXStructorList(GV->getInitializer());
391 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
392 SwitchToDataSection(TAI->getStaticDtorsSection());
393 EmitAlignment(Align, 0);
394 EmitXXStructorList(GV->getInitializer());
401 /// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
402 /// global in the specified llvm.used list as being used with this directive.
403 void AsmPrinter::EmitLLVMUsedList(Constant *List) {
404 const char *Directive = TAI->getUsedDirective();
406 // Should be an array of 'sbyte*'.
407 ConstantArray *InitList = dyn_cast<ConstantArray>(List);
408 if (InitList == 0) return;
410 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
412 EmitConstantValueOnly(InitList->getOperand(i));
417 /// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
418 /// function pointers, ignoring the init priority.
419 void AsmPrinter::EmitXXStructorList(Constant *List) {
420 // Should be an array of '{ int, void ()* }' structs. The first value is the
421 // init priority, which we ignore.
422 if (!isa<ConstantArray>(List)) return;
423 ConstantArray *InitList = cast<ConstantArray>(List);
424 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
425 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
426 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
428 if (CS->getOperand(1)->isNullValue())
429 return; // Found a null terminator, exit printing.
430 // Emit the function pointer.
431 EmitGlobalConstant(CS->getOperand(1));
435 /// getGlobalLinkName - Returns the asm/link name of of the specified
436 /// global variable. Should be overridden by each target asm printer to
437 /// generate the appropriate value.
438 const std::string AsmPrinter::getGlobalLinkName(const GlobalVariable *GV) const{
439 std::string LinkName;
441 if (isa<Function>(GV)) {
442 LinkName += TAI->getFunctionAddrPrefix();
443 LinkName += Mang->getValueName(GV);
444 LinkName += TAI->getFunctionAddrSuffix();
446 LinkName += TAI->getGlobalVarAddrPrefix();
447 LinkName += Mang->getValueName(GV);
448 LinkName += TAI->getGlobalVarAddrSuffix();
454 /// EmitExternalGlobal - Emit the external reference to a global variable.
455 /// Should be overridden if an indirect reference should be used.
456 void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
457 O << getGlobalLinkName(GV);
462 //===----------------------------------------------------------------------===//
463 /// LEB 128 number encoding.
465 /// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
466 /// representing an unsigned leb128 value.
467 void AsmPrinter::PrintULEB128(unsigned Value) const {
469 unsigned Byte = Value & 0x7f;
471 if (Value) Byte |= 0x80;
472 O << "0x" << std::hex << Byte << std::dec;
473 if (Value) O << ", ";
477 /// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
479 unsigned AsmPrinter::SizeULEB128(unsigned Value) {
483 Size += sizeof(int8_t);
488 /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
489 /// representing a signed leb128 value.
490 void AsmPrinter::PrintSLEB128(int Value) const {
491 int Sign = Value >> (8 * sizeof(Value) - 1);
495 unsigned Byte = Value & 0x7f;
497 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
498 if (IsMore) Byte |= 0x80;
499 O << "0x" << std::hex << Byte << std::dec;
500 if (IsMore) O << ", ";
504 /// SizeSLEB128 - Compute the number of bytes required for a signed leb128
506 unsigned AsmPrinter::SizeSLEB128(int Value) {
508 int Sign = Value >> (8 * sizeof(Value) - 1);
512 unsigned Byte = Value & 0x7f;
514 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
515 Size += sizeof(int8_t);
520 //===--------------------------------------------------------------------===//
521 // Emission and print routines
524 /// PrintHex - Print a value as a hexidecimal value.
526 void AsmPrinter::PrintHex(int Value) const {
527 O << "0x" << std::hex << Value << std::dec;
530 /// EOL - Print a newline character to asm stream. If a comment is present
531 /// then it will be printed first. Comments should not contain '\n'.
532 void AsmPrinter::EOL() const {
535 void AsmPrinter::EOL(const std::string &Comment) const {
536 if (AsmVerbose && !Comment.empty()) {
538 << TAI->getCommentString()
545 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
546 /// unsigned leb128 value.
547 void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
548 if (TAI->hasLEB128()) {
552 O << TAI->getData8bitsDirective();
557 /// EmitSLEB128Bytes - print an assembler byte data directive to compose a
558 /// signed leb128 value.
559 void AsmPrinter::EmitSLEB128Bytes(int Value) const {
560 if (TAI->hasLEB128()) {
564 O << TAI->getData8bitsDirective();
569 /// EmitInt8 - Emit a byte directive and value.
571 void AsmPrinter::EmitInt8(int Value) const {
572 O << TAI->getData8bitsDirective();
573 PrintHex(Value & 0xFF);
576 /// EmitInt16 - Emit a short directive and value.
578 void AsmPrinter::EmitInt16(int Value) const {
579 O << TAI->getData16bitsDirective();
580 PrintHex(Value & 0xFFFF);
583 /// EmitInt32 - Emit a long directive and value.
585 void AsmPrinter::EmitInt32(int Value) const {
586 O << TAI->getData32bitsDirective();
590 /// EmitInt64 - Emit a long long directive and value.
592 void AsmPrinter::EmitInt64(uint64_t Value) const {
593 if (TAI->getData64bitsDirective()) {
594 O << TAI->getData64bitsDirective();
597 if (TM.getTargetData()->isBigEndian()) {
598 EmitInt32(unsigned(Value >> 32)); O << "\n";
599 EmitInt32(unsigned(Value));
601 EmitInt32(unsigned(Value)); O << "\n";
602 EmitInt32(unsigned(Value >> 32));
607 /// toOctal - Convert the low order bits of X into an octal digit.
609 static inline char toOctal(int X) {
613 /// printStringChar - Print a char, escaped if necessary.
615 static void printStringChar(std::ostream &O, unsigned char C) {
618 } else if (C == '\\') {
620 } else if (isprint(C)) {
624 case '\b': O << "\\b"; break;
625 case '\f': O << "\\f"; break;
626 case '\n': O << "\\n"; break;
627 case '\r': O << "\\r"; break;
628 case '\t': O << "\\t"; break;
631 O << toOctal(C >> 6);
632 O << toOctal(C >> 3);
633 O << toOctal(C >> 0);
639 /// EmitString - Emit a string with quotes and a null terminator.
640 /// Special characters are emitted properly.
641 /// \literal (Eg. '\t') \endliteral
642 void AsmPrinter::EmitString(const std::string &String) const {
643 const char* AscizDirective = TAI->getAscizDirective();
647 O << TAI->getAsciiDirective();
649 for (unsigned i = 0, N = String.size(); i < N; ++i) {
650 unsigned char C = String[i];
651 printStringChar(O, C);
660 /// EmitFile - Emit a .file directive.
661 void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
662 O << "\t.file\t" << Number << " \"";
663 for (unsigned i = 0, N = Name.size(); i < N; ++i) {
664 unsigned char C = Name[i];
665 printStringChar(O, C);
671 //===----------------------------------------------------------------------===//
673 // EmitAlignment - Emit an alignment directive to the specified power of
674 // two boundary. For example, if you pass in 3 here, you will get an 8
675 // byte alignment. If a global value is specified, and if that global has
676 // an explicit alignment requested, it will unconditionally override the
677 // alignment request. However, if ForcedAlignBits is specified, this value
678 // has final say: the ultimate alignment will be the max of ForcedAlignBits
679 // and the alignment computed with NumBits and the global.
683 // if (GV && GV->hasalignment) Align = GV->getalignment();
684 // Align = std::max(Align, ForcedAlignBits);
686 void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
687 unsigned ForcedAlignBits,
688 bool UseFillExpr) const {
689 if (GV && GV->getAlignment())
690 NumBits = Log2_32(GV->getAlignment());
691 NumBits = std::max(NumBits, ForcedAlignBits);
693 if (NumBits == 0) return; // No need to emit alignment.
694 if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
695 O << TAI->getAlignDirective() << NumBits;
697 unsigned FillValue = TAI->getTextAlignFillValue();
698 UseFillExpr &= IsInTextSection && FillValue;
699 if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
704 /// EmitZeros - Emit a block of zeros.
706 void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
708 if (TAI->getZeroDirective()) {
709 O << TAI->getZeroDirective() << NumZeros;
710 if (TAI->getZeroDirectiveSuffix())
711 O << TAI->getZeroDirectiveSuffix();
714 for (; NumZeros; --NumZeros)
715 O << TAI->getData8bitsDirective() << "0\n";
720 // Print out the specified constant, without a storage class. Only the
721 // constants valid in constant expressions can occur here.
722 void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
723 if (CV->isNullValue() || isa<UndefValue>(CV))
725 else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
726 O << CI->getZExtValue();
727 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
728 // This is a constant address for a global variable or function. Use the
729 // name of the variable or function as the address value, possibly
730 // decorating it with GlobalVarAddrPrefix/Suffix or
731 // FunctionAddrPrefix/Suffix (these all default to "" )
732 if (isa<Function>(GV)) {
733 O << TAI->getFunctionAddrPrefix()
734 << Mang->getValueName(GV)
735 << TAI->getFunctionAddrSuffix();
737 O << TAI->getGlobalVarAddrPrefix()
738 << Mang->getValueName(GV)
739 << TAI->getGlobalVarAddrSuffix();
741 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
742 const TargetData *TD = TM.getTargetData();
743 unsigned Opcode = CE->getOpcode();
745 case Instruction::GetElementPtr: {
746 // generate a symbolic expression for the byte address
747 const Constant *ptrVal = CE->getOperand(0);
748 SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
749 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
753 EmitConstantValueOnly(ptrVal);
755 O << ") + " << Offset;
757 O << ") - " << -Offset;
759 EmitConstantValueOnly(ptrVal);
763 case Instruction::Trunc:
764 case Instruction::ZExt:
765 case Instruction::SExt:
766 case Instruction::FPTrunc:
767 case Instruction::FPExt:
768 case Instruction::UIToFP:
769 case Instruction::SIToFP:
770 case Instruction::FPToUI:
771 case Instruction::FPToSI:
772 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
774 case Instruction::BitCast:
775 return EmitConstantValueOnly(CE->getOperand(0));
777 case Instruction::IntToPtr: {
778 // Handle casts to pointers by changing them into casts to the appropriate
779 // integer type. This promotes constant folding and simplifies this code.
780 Constant *Op = CE->getOperand(0);
781 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
782 return EmitConstantValueOnly(Op);
786 case Instruction::PtrToInt: {
787 // Support only foldable casts to/from pointers that can be eliminated by
788 // changing the pointer to the appropriately sized integer type.
789 Constant *Op = CE->getOperand(0);
790 const Type *Ty = CE->getType();
792 // We can emit the pointer value into this slot if the slot is an
793 // integer slot greater or equal to the size of the pointer.
794 if (Ty->isInteger() &&
795 TD->getABITypeSize(Ty) >= TD->getABITypeSize(Op->getType()))
796 return EmitConstantValueOnly(Op);
798 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
799 EmitConstantValueOnly(Op);
802 case Instruction::Add:
803 case Instruction::Sub:
804 case Instruction::And:
805 case Instruction::Or:
806 case Instruction::Xor:
808 EmitConstantValueOnly(CE->getOperand(0));
811 case Instruction::Add:
814 case Instruction::Sub:
817 case Instruction::And:
820 case Instruction::Or:
823 case Instruction::Xor:
830 EmitConstantValueOnly(CE->getOperand(1));
834 assert(0 && "Unsupported operator!");
837 assert(0 && "Unknown constant value!");
841 /// printAsCString - Print the specified array as a C compatible string, only if
842 /// the predicate isString is true.
844 static void printAsCString(std::ostream &O, const ConstantArray *CVA,
846 assert(CVA->isString() && "Array is not string compatible!");
849 for (unsigned i = 0; i != LastElt; ++i) {
851 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
852 printStringChar(O, C);
857 /// EmitString - Emit a zero-byte-terminated string constant.
859 void AsmPrinter::EmitString(const ConstantArray *CVA) const {
860 unsigned NumElts = CVA->getNumOperands();
861 if (TAI->getAscizDirective() && NumElts &&
862 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
863 O << TAI->getAscizDirective();
864 printAsCString(O, CVA, NumElts-1);
866 O << TAI->getAsciiDirective();
867 printAsCString(O, CVA, NumElts);
872 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
873 /// If Packed is false, pad to the ABI size.
874 void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) {
875 const TargetData *TD = TM.getTargetData();
876 unsigned Size = Packed ?
877 TD->getTypeStoreSize(CV->getType()) : TD->getABITypeSize(CV->getType());
879 if (CV->isNullValue() || isa<UndefValue>(CV)) {
882 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
883 if (CVA->isString()) {
885 } else { // Not a string. Print the values in successive locations
886 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
887 EmitGlobalConstant(CVA->getOperand(i), false);
890 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
891 // Print the fields in successive locations. Pad to align if needed!
892 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
893 uint64_t sizeSoFar = 0;
894 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
895 const Constant* field = CVS->getOperand(i);
897 // Check if padding is needed and insert one or more 0s.
898 uint64_t fieldSize = TD->getTypeStoreSize(field->getType());
899 uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
900 - cvsLayout->getElementOffset(i)) - fieldSize;
901 sizeSoFar += fieldSize + padSize;
903 // Now print the actual field value without ABI size padding.
904 EmitGlobalConstant(field, true);
906 // Insert padding - this may include padding to increase the size of the
907 // current field up to the ABI size (if the struct is not packed) as well
908 // as padding to ensure that the next field starts at the right offset.
911 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
912 "Layout of constant struct may be incorrect!");
914 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
915 // FP Constants are printed as integer constants to avoid losing
917 if (CFP->getType() == Type::DoubleTy) {
918 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
919 uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
920 if (TAI->getData64bitsDirective())
921 O << TAI->getData64bitsDirective() << i << "\t"
922 << TAI->getCommentString() << " double value: " << Val << "\n";
923 else if (TD->isBigEndian()) {
924 O << TAI->getData32bitsDirective() << unsigned(i >> 32)
925 << "\t" << TAI->getCommentString()
926 << " double most significant word " << Val << "\n";
927 O << TAI->getData32bitsDirective() << unsigned(i)
928 << "\t" << TAI->getCommentString()
929 << " double least significant word " << Val << "\n";
931 O << TAI->getData32bitsDirective() << unsigned(i)
932 << "\t" << TAI->getCommentString()
933 << " double least significant word " << Val << "\n";
934 O << TAI->getData32bitsDirective() << unsigned(i >> 32)
935 << "\t" << TAI->getCommentString()
936 << " double most significant word " << Val << "\n";
939 } else if (CFP->getType() == Type::FloatTy) {
940 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
941 O << TAI->getData32bitsDirective()
942 << CFP->getValueAPF().convertToAPInt().getZExtValue()
943 << "\t" << TAI->getCommentString() << " float " << Val << "\n";
945 } else if (CFP->getType() == Type::X86_FP80Ty) {
946 // all long double variants are printed as hex
947 // api needed to prevent premature destruction
948 APInt api = CFP->getValueAPF().convertToAPInt();
949 const uint64_t *p = api.getRawData();
950 APFloat DoubleVal = CFP->getValueAPF();
951 DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
952 if (TD->isBigEndian()) {
953 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
954 << "\t" << TAI->getCommentString()
955 << " long double most significant halfword of ~"
956 << DoubleVal.convertToDouble() << "\n";
957 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
958 << "\t" << TAI->getCommentString()
959 << " long double next halfword\n";
960 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
961 << "\t" << TAI->getCommentString()
962 << " long double next halfword\n";
963 O << TAI->getData16bitsDirective() << uint16_t(p[0])
964 << "\t" << TAI->getCommentString()
965 << " long double next halfword\n";
966 O << TAI->getData16bitsDirective() << uint16_t(p[1])
967 << "\t" << TAI->getCommentString()
968 << " long double least significant halfword\n";
970 O << TAI->getData16bitsDirective() << uint16_t(p[1])
971 << "\t" << TAI->getCommentString()
972 << " long double least significant halfword of ~"
973 << DoubleVal.convertToDouble() << "\n";
974 O << TAI->getData16bitsDirective() << uint16_t(p[0])
975 << "\t" << TAI->getCommentString()
976 << " long double next halfword\n";
977 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
978 << "\t" << TAI->getCommentString()
979 << " long double next halfword\n";
980 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
981 << "\t" << TAI->getCommentString()
982 << " long double next halfword\n";
983 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
984 << "\t" << TAI->getCommentString()
985 << " long double most significant halfword\n";
987 EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty));
989 } else if (CFP->getType() == Type::PPC_FP128Ty) {
990 // all long double variants are printed as hex
991 // api needed to prevent premature destruction
992 APInt api = CFP->getValueAPF().convertToAPInt();
993 const uint64_t *p = api.getRawData();
994 if (TD->isBigEndian()) {
995 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
996 << "\t" << TAI->getCommentString()
997 << " long double most significant word\n";
998 O << TAI->getData32bitsDirective() << uint32_t(p[0])
999 << "\t" << TAI->getCommentString()
1000 << " long double next word\n";
1001 O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
1002 << "\t" << TAI->getCommentString()
1003 << " long double next word\n";
1004 O << TAI->getData32bitsDirective() << uint32_t(p[1])
1005 << "\t" << TAI->getCommentString()
1006 << " long double least significant word\n";
1008 O << TAI->getData32bitsDirective() << uint32_t(p[1])
1009 << "\t" << TAI->getCommentString()
1010 << " long double least significant word\n";
1011 O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
1012 << "\t" << TAI->getCommentString()
1013 << " long double next word\n";
1014 O << TAI->getData32bitsDirective() << uint32_t(p[0])
1015 << "\t" << TAI->getCommentString()
1016 << " long double next word\n";
1017 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
1018 << "\t" << TAI->getCommentString()
1019 << " long double most significant word\n";
1022 } else assert(0 && "Floating point constant type not handled");
1023 } else if (CV->getType() == Type::Int64Ty) {
1024 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1025 uint64_t Val = CI->getZExtValue();
1027 if (TAI->getData64bitsDirective())
1028 O << TAI->getData64bitsDirective() << Val << "\n";
1029 else if (TD->isBigEndian()) {
1030 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
1031 << "\t" << TAI->getCommentString()
1032 << " Double-word most significant word " << Val << "\n";
1033 O << TAI->getData32bitsDirective() << unsigned(Val)
1034 << "\t" << TAI->getCommentString()
1035 << " Double-word least significant word " << Val << "\n";
1037 O << TAI->getData32bitsDirective() << unsigned(Val)
1038 << "\t" << TAI->getCommentString()
1039 << " Double-word least significant word " << Val << "\n";
1040 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
1041 << "\t" << TAI->getCommentString()
1042 << " Double-word most significant word " << Val << "\n";
1046 } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
1047 const VectorType *PTy = CP->getType();
1049 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
1050 EmitGlobalConstant(CP->getOperand(I), false);
1055 const Type *type = CV->getType();
1056 printDataDirective(type);
1057 EmitConstantValueOnly(CV);
1062 AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
1063 // Target doesn't support this yet!
1067 /// PrintSpecial - Print information related to the specified machine instr
1068 /// that is independent of the operand, and may be independent of the instr
1069 /// itself. This can be useful for portably encoding the comment character
1070 /// or other bits of target-specific knowledge into the asmstrings. The
1071 /// syntax used is ${:comment}. Targets can override this to add support
1072 /// for their own strange codes.
1073 void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) {
1074 if (!strcmp(Code, "private")) {
1075 O << TAI->getPrivateGlobalPrefix();
1076 } else if (!strcmp(Code, "comment")) {
1077 O << TAI->getCommentString();
1078 } else if (!strcmp(Code, "uid")) {
1079 // Assign a unique ID to this machine instruction.
1080 static const MachineInstr *LastMI = 0;
1081 static const Function *F = 0;
1082 static unsigned Counter = 0U-1;
1084 // Comparing the address of MI isn't sufficient, because machineinstrs may
1085 // be allocated to the same address across functions.
1086 const Function *ThisF = MI->getParent()->getParent()->getFunction();
1088 // If this is a new machine instruction, bump the counter.
1089 if (LastMI != MI || F != ThisF) {
1096 cerr << "Unknown special formatter '" << Code
1097 << "' for machine instr: " << *MI;
1103 /// printInlineAsm - This method formats and prints the specified machine
1104 /// instruction that is an inline asm.
1105 void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
1106 unsigned NumOperands = MI->getNumOperands();
1108 // Count the number of register definitions.
1109 unsigned NumDefs = 0;
1110 for (; MI->getOperand(NumDefs).isRegister() && MI->getOperand(NumDefs).isDef();
1112 assert(NumDefs != NumOperands-1 && "No asm string?");
1114 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
1116 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
1117 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
1119 // If this asmstr is empty, just print the #APP/#NOAPP markers.
1120 // These are useful to see where empty asm's wound up.
1121 if (AsmStr[0] == 0) {
1122 O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << "\n";
1126 O << TAI->getInlineAsmStart() << "\n\t";
1128 // The variant of the current asmprinter.
1129 int AsmPrinterVariant = TAI->getAssemblerDialect();
1131 int CurVariant = -1; // The number of the {.|.|.} region we are in.
1132 const char *LastEmitted = AsmStr; // One past the last character emitted.
1134 while (*LastEmitted) {
1135 switch (*LastEmitted) {
1137 // Not a special case, emit the string section literally.
1138 const char *LiteralEnd = LastEmitted+1;
1139 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
1140 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
1142 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1143 O.write(LastEmitted, LiteralEnd-LastEmitted);
1144 LastEmitted = LiteralEnd;
1148 ++LastEmitted; // Consume newline character.
1149 O << "\n"; // Indent code with newline.
1152 ++LastEmitted; // Consume '$' character.
1156 switch (*LastEmitted) {
1157 default: Done = false; break;
1158 case '$': // $$ -> $
1159 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1161 ++LastEmitted; // Consume second '$' character.
1163 case '(': // $( -> same as GCC's { character.
1164 ++LastEmitted; // Consume '(' character.
1165 if (CurVariant != -1) {
1166 cerr << "Nested variants found in inline asm string: '"
1170 CurVariant = 0; // We're in the first variant now.
1173 ++LastEmitted; // consume '|' character.
1174 if (CurVariant == -1) {
1175 cerr << "Found '|' character outside of variant in inline asm "
1176 << "string: '" << AsmStr << "'\n";
1179 ++CurVariant; // We're in the next variant.
1181 case ')': // $) -> same as GCC's } char.
1182 ++LastEmitted; // consume ')' character.
1183 if (CurVariant == -1) {
1184 cerr << "Found '}' character outside of variant in inline asm "
1185 << "string: '" << AsmStr << "'\n";
1193 bool HasCurlyBraces = false;
1194 if (*LastEmitted == '{') { // ${variable}
1195 ++LastEmitted; // Consume '{' character.
1196 HasCurlyBraces = true;
1199 const char *IDStart = LastEmitted;
1202 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1203 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
1204 cerr << "Bad $ operand number in inline asm string: '"
1208 LastEmitted = IDEnd;
1210 char Modifier[2] = { 0, 0 };
1212 if (HasCurlyBraces) {
1213 // If we have curly braces, check for a modifier character. This
1214 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1215 if (*LastEmitted == ':') {
1216 ++LastEmitted; // Consume ':' character.
1217 if (*LastEmitted == 0) {
1218 cerr << "Bad ${:} expression in inline asm string: '"
1223 Modifier[0] = *LastEmitted;
1224 ++LastEmitted; // Consume modifier character.
1227 if (*LastEmitted != '}') {
1228 cerr << "Bad ${} expression in inline asm string: '"
1232 ++LastEmitted; // Consume '}' character.
1235 if ((unsigned)Val >= NumOperands-1) {
1236 cerr << "Invalid $ operand number in inline asm string: '"
1241 // Okay, we finally have a value number. Ask the target to print this
1243 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1248 // Scan to find the machine operand number for the operand.
1249 for (; Val; --Val) {
1250 if (OpNo >= MI->getNumOperands()) break;
1251 unsigned OpFlags = MI->getOperand(OpNo).getImm();
1252 OpNo += (OpFlags >> 3) + 1;
1255 if (OpNo >= MI->getNumOperands()) {
1258 unsigned OpFlags = MI->getOperand(OpNo).getImm();
1259 ++OpNo; // Skip over the ID number.
1261 if (Modifier[0]=='l') // labels are target independent
1262 printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
1263 false, false, false);
1265 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1266 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
1267 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1268 Modifier[0] ? Modifier : 0);
1270 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1271 Modifier[0] ? Modifier : 0);
1276 cerr << "Invalid operand found in inline asm: '"
1286 O << "\n\t" << TAI->getInlineAsmEnd() << "\n";
1289 /// printLabel - This method prints a local label used by debug and
1290 /// exception handling tables.
1291 void AsmPrinter::printLabel(const MachineInstr *MI) const {
1292 O << TAI->getPrivateGlobalPrefix()
1293 << "label" << MI->getOperand(0).getImm() << ":\n";
1296 void AsmPrinter::printLabel(unsigned Id) const {
1297 O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
1300 /// printDeclare - This method prints a local variable declaration used by
1302 /// FIXME: It doesn't really print anything rather it inserts a DebugVariable
1303 /// entry into dwarf table.
1304 void AsmPrinter::printDeclare(const MachineInstr *MI) const {
1305 int FI = MI->getOperand(0).getIndex();
1306 GlobalValue *GV = MI->getOperand(1).getGlobal();
1307 MMI->RecordVariable(GV, FI);
1310 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1311 /// instruction, using the specified assembler variant. Targets should
1312 /// overried this to format as appropriate.
1313 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
1314 unsigned AsmVariant, const char *ExtraCode) {
1315 // Target doesn't support this yet!
1319 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1320 unsigned AsmVariant,
1321 const char *ExtraCode) {
1322 // Target doesn't support this yet!
1326 /// printBasicBlockLabel - This method prints the label for the specified
1327 /// MachineBasicBlock
1328 void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1331 bool printComment) const {
1333 unsigned Align = MBB->getAlignment();
1335 EmitAlignment(Log2_32(Align));
1338 O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_"
1339 << MBB->getNumber();
1342 if (printComment && MBB->getBasicBlock())
1343 O << '\t' << TAI->getCommentString() << ' '
1344 << MBB->getBasicBlock()->getName();
1347 /// printPICJumpTableSetLabel - This method prints a set label for the
1348 /// specified MachineBasicBlock for a jumptable entry.
1349 void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
1350 const MachineBasicBlock *MBB) const {
1351 if (!TAI->getSetDirective())
1354 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1355 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
1356 printBasicBlockLabel(MBB, false, false, false);
1357 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1358 << '_' << uid << '\n';
1361 void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
1362 const MachineBasicBlock *MBB) const {
1363 if (!TAI->getSetDirective())
1366 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1367 << getFunctionNumber() << '_' << uid << '_' << uid2
1368 << "_set_" << MBB->getNumber() << ',';
1369 printBasicBlockLabel(MBB, false, false, false);
1370 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1371 << '_' << uid << '_' << uid2 << '\n';
1374 /// printDataDirective - This method prints the asm directive for the
1376 void AsmPrinter::printDataDirective(const Type *type) {
1377 const TargetData *TD = TM.getTargetData();
1378 switch (type->getTypeID()) {
1379 case Type::IntegerTyID: {
1380 unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1382 O << TAI->getData8bitsDirective();
1383 else if (BitWidth <= 16)
1384 O << TAI->getData16bitsDirective();
1385 else if (BitWidth <= 32)
1386 O << TAI->getData32bitsDirective();
1387 else if (BitWidth <= 64) {
1388 assert(TAI->getData64bitsDirective() &&
1389 "Target cannot handle 64-bit constant exprs!");
1390 O << TAI->getData64bitsDirective();
1394 case Type::PointerTyID:
1395 if (TD->getPointerSize() == 8) {
1396 assert(TAI->getData64bitsDirective() &&
1397 "Target cannot handle 64-bit pointer exprs!");
1398 O << TAI->getData64bitsDirective();
1400 O << TAI->getData32bitsDirective();
1403 case Type::FloatTyID: case Type::DoubleTyID:
1404 case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
1405 assert (0 && "Should have already output floating point constant.");
1407 assert (0 && "Can't handle printing this type of thing");