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)
45 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
46 return TAI->getTextSection();
50 /// SwitchToTextSection - Switch to the specified text section of the executable
51 /// if we are not already in it!
53 void AsmPrinter::SwitchToTextSection(const char *NewSection,
54 const GlobalValue *GV) {
56 if (GV && GV->hasSection())
57 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
61 // If we're already in this section, we're done.
62 if (CurrentSection == NS) return;
64 // Close the current section, if applicable.
65 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
66 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
70 if (!CurrentSection.empty())
71 O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
74 /// SwitchToDataSection - Switch to the specified data section of the executable
75 /// if we are not already in it!
77 void AsmPrinter::SwitchToDataSection(const char *NewSection,
78 const GlobalValue *GV) {
80 if (GV && GV->hasSection())
81 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
85 // If we're already in this section, we're done.
86 if (CurrentSection == NS) return;
88 // Close the current section, if applicable.
89 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
90 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
94 if (!CurrentSection.empty())
95 O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
99 void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
100 MachineFunctionPass::getAnalysisUsage(AU);
101 AU.addRequired<CollectorModuleMetadata>();
104 bool AsmPrinter::doInitialization(Module &M) {
105 Mang = new Mangler(M, TAI->getGlobalPrefix());
107 CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
108 assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
109 for (CollectorModuleMetadata::iterator I = CMM->begin(),
110 E = CMM->end(); I != E; ++I)
111 (*I)->beginAssembly(O, *this, *TAI);
113 if (!M.getModuleInlineAsm().empty())
114 O << TAI->getCommentString() << " Start of file scope inline assembly\n"
115 << M.getModuleInlineAsm()
116 << "\n" << TAI->getCommentString()
117 << " End of file scope inline assembly\n";
119 SwitchToDataSection(""); // Reset back to no section.
121 MMI = getAnalysisToUpdate<MachineModuleInfo>();
122 if (MMI) MMI->AnalyzeModule(M);
127 bool AsmPrinter::doFinalization(Module &M) {
128 if (TAI->getWeakRefDirective()) {
129 if (!ExtWeakSymbols.empty())
130 SwitchToDataSection("");
132 for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
133 e = ExtWeakSymbols.end(); i != e; ++i) {
134 const GlobalValue *GV = *i;
135 std::string Name = Mang->getValueName(GV);
136 O << TAI->getWeakRefDirective() << Name << "\n";
140 if (TAI->getSetDirective()) {
141 if (!M.alias_empty())
142 SwitchToTextSection(TAI->getTextSection());
145 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
147 std::string Name = Mang->getValueName(I);
150 const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
151 Target = Mang->getValueName(GV);
153 if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
154 O << "\t.globl\t" << Name << "\n";
155 else if (I->hasWeakLinkage())
156 O << TAI->getWeakRefDirective() << Name << "\n";
157 else if (!I->hasInternalLinkage())
158 assert(0 && "Invalid alias linkage");
160 O << TAI->getSetDirective() << ' ' << Name << ", " << Target << "\n";
162 // If the aliasee has external weak linkage it can be referenced only by
163 // alias itself. In this case it can be not in ExtWeakSymbols list. Emit
164 // weak reference in such case.
165 if (GV->hasExternalWeakLinkage())
166 if (TAI->getWeakRefDirective())
167 O << TAI->getWeakRefDirective() << Target << "\n";
169 O << "\t.globl\t" << Target << "\n";
173 CollectorModuleMetadata *CMM = getAnalysisToUpdate<CollectorModuleMetadata>();
174 assert(CMM && "AsmPrinter didn't require CollectorModuleMetadata?");
175 for (CollectorModuleMetadata::iterator I = CMM->end(),
176 E = CMM->begin(); I != E; )
177 (*--I)->finishAssembly(O, *this, *TAI);
179 delete Mang; Mang = 0;
183 std::string AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) {
184 assert(MF && "No machine function?");
185 return Mang->makeNameProper(MF->getFunction()->getName() + ".eh",
186 TAI->getGlobalPrefix());
189 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
190 // What's my mangled name?
191 CurrentFnName = Mang->getValueName(MF.getFunction());
192 IncrementFunctionNumber();
195 /// EmitConstantPool - Print to the current output stream assembly
196 /// representations of the constants in the constant pool MCP. This is
197 /// used to print out constants which have been "spilled to memory" by
198 /// the code generator.
200 void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
201 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
202 if (CP.empty()) return;
204 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
205 // in special sections.
206 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
207 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
208 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
209 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
210 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > TargetCPs;
211 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
212 MachineConstantPoolEntry CPE = CP[i];
213 const Type *Ty = CPE.getType();
214 if (TAI->getFourByteConstantSection() &&
215 TM.getTargetData()->getABITypeSize(Ty) == 4)
216 FourByteCPs.push_back(std::make_pair(CPE, i));
217 else if (TAI->getEightByteConstantSection() &&
218 TM.getTargetData()->getABITypeSize(Ty) == 8)
219 EightByteCPs.push_back(std::make_pair(CPE, i));
220 else if (TAI->getSixteenByteConstantSection() &&
221 TM.getTargetData()->getABITypeSize(Ty) == 16)
222 SixteenByteCPs.push_back(std::make_pair(CPE, i));
224 OtherCPs.push_back(std::make_pair(CPE, i));
227 unsigned Alignment = MCP->getConstantPoolAlignment();
228 EmitConstantPool(Alignment, TAI->getFourByteConstantSection(), FourByteCPs);
229 EmitConstantPool(Alignment, TAI->getEightByteConstantSection(), EightByteCPs);
230 EmitConstantPool(Alignment, TAI->getSixteenByteConstantSection(),
232 EmitConstantPool(Alignment, TAI->getConstantPoolSection(), OtherCPs);
235 void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
236 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
237 if (CP.empty()) return;
239 SwitchToDataSection(Section);
240 EmitAlignment(Alignment);
241 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
242 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
243 << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
244 WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
245 if (CP[i].first.isMachineConstantPoolEntry())
246 EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
248 EmitGlobalConstant(CP[i].first.Val.ConstVal);
250 const Type *Ty = CP[i].first.getType();
252 TM.getTargetData()->getABITypeSize(Ty);
253 unsigned ValEnd = CP[i].first.getOffset() + EntSize;
254 // Emit inter-object padding for alignment.
255 EmitZeros(CP[i+1].first.getOffset()-ValEnd);
260 /// EmitJumpTableInfo - Print assembly representations of the jump tables used
261 /// by the current function to the current output stream.
263 void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
264 MachineFunction &MF) {
265 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
266 if (JT.empty()) return;
268 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
270 // Pick the directive to use to print the jump table entries, and switch to
271 // the appropriate section.
272 TargetLowering *LoweringInfo = TM.getTargetLowering();
274 const char* JumpTableDataSection = TAI->getJumpTableDataSection();
275 if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
276 !JumpTableDataSection) {
277 // In PIC mode, we need to emit the jump table to the same section as the
278 // function body itself, otherwise the label differences won't make sense.
279 // We should also do if the section name is NULL.
280 const Function *F = MF.getFunction();
281 SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
283 SwitchToDataSection(JumpTableDataSection);
286 EmitAlignment(Log2_32(MJTI->getAlignment()));
288 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
289 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
291 // If this jump table was deleted, ignore it.
292 if (JTBBs.empty()) continue;
294 // For PIC codegen, if possible we want to use the SetDirective to reduce
295 // the number of relocations the assembler will generate for the jump table.
296 // Set directives are all printed before the jump table itself.
297 SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
298 if (TAI->getSetDirective() && IsPic)
299 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
300 if (EmittedSets.insert(JTBBs[ii]))
301 printPICJumpTableSetLabel(i, JTBBs[ii]);
303 // On some targets (e.g. darwin) we want to emit two consequtive labels
304 // before each jump table. The first label is never referenced, but tells
305 // the assembler and linker the extents of the jump table object. The
306 // second label is actually referenced by the code.
307 if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
308 O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
310 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
311 << '_' << i << ":\n";
313 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
314 printPICJumpTableEntry(MJTI, JTBBs[ii], i);
320 void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
321 const MachineBasicBlock *MBB,
322 unsigned uid) const {
323 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
325 // Use JumpTableDirective otherwise honor the entry size from the jump table
327 const char *JTEntryDirective = TAI->getJumpTableDirective();
328 bool HadJTEntryDirective = JTEntryDirective != NULL;
329 if (!HadJTEntryDirective) {
330 JTEntryDirective = MJTI->getEntrySize() == 4 ?
331 TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
334 O << JTEntryDirective << ' ';
336 // If we have emitted set directives for the jump table entries, print
337 // them rather than the entries themselves. If we're emitting PIC, then
338 // emit the table entries as differences between two text section labels.
339 // If we're emitting non-PIC code, then emit the entries as direct
340 // references to the target basic blocks.
342 if (TAI->getSetDirective()) {
343 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
344 << '_' << uid << "_set_" << MBB->getNumber();
346 printBasicBlockLabel(MBB, false, false);
347 // If the arch uses custom Jump Table directives, don't calc relative to
349 if (!HadJTEntryDirective)
350 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
351 << getFunctionNumber() << '_' << uid;
354 printBasicBlockLabel(MBB, false, false);
359 /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
360 /// special global used by LLVM. If so, emit it and return true, otherwise
361 /// do nothing and return false.
362 bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
363 if (GV->getName() == "llvm.used") {
364 if (TAI->getUsedDirective() != 0) // No need to emit this at all.
365 EmitLLVMUsedList(GV->getInitializer());
369 // Ignore debug and non-emitted data.
370 if (GV->getSection() == "llvm.metadata") return true;
372 if (!GV->hasAppendingLinkage()) return false;
374 assert(GV->hasInitializer() && "Not a special LLVM global!");
376 const TargetData *TD = TM.getTargetData();
377 unsigned Align = Log2_32(TD->getPointerPrefAlignment());
378 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
379 SwitchToDataSection(TAI->getStaticCtorsSection());
380 EmitAlignment(Align, 0);
381 EmitXXStructorList(GV->getInitializer());
385 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
386 SwitchToDataSection(TAI->getStaticDtorsSection());
387 EmitAlignment(Align, 0);
388 EmitXXStructorList(GV->getInitializer());
395 /// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
396 /// global in the specified llvm.used list as being used with this directive.
397 void AsmPrinter::EmitLLVMUsedList(Constant *List) {
398 const char *Directive = TAI->getUsedDirective();
400 // Should be an array of 'sbyte*'.
401 ConstantArray *InitList = dyn_cast<ConstantArray>(List);
402 if (InitList == 0) return;
404 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
406 EmitConstantValueOnly(InitList->getOperand(i));
411 /// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
412 /// function pointers, ignoring the init priority.
413 void AsmPrinter::EmitXXStructorList(Constant *List) {
414 // Should be an array of '{ int, void ()* }' structs. The first value is the
415 // init priority, which we ignore.
416 if (!isa<ConstantArray>(List)) return;
417 ConstantArray *InitList = cast<ConstantArray>(List);
418 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
419 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
420 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
422 if (CS->getOperand(1)->isNullValue())
423 return; // Found a null terminator, exit printing.
424 // Emit the function pointer.
425 EmitGlobalConstant(CS->getOperand(1));
429 /// getGlobalLinkName - Returns the asm/link name of of the specified
430 /// global variable. Should be overridden by each target asm printer to
431 /// generate the appropriate value.
432 const std::string AsmPrinter::getGlobalLinkName(const GlobalVariable *GV) const{
433 std::string LinkName;
435 if (isa<Function>(GV)) {
436 LinkName += TAI->getFunctionAddrPrefix();
437 LinkName += Mang->getValueName(GV);
438 LinkName += TAI->getFunctionAddrSuffix();
440 LinkName += TAI->getGlobalVarAddrPrefix();
441 LinkName += Mang->getValueName(GV);
442 LinkName += TAI->getGlobalVarAddrSuffix();
448 /// EmitExternalGlobal - Emit the external reference to a global variable.
449 /// Should be overridden if an indirect reference should be used.
450 void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
451 O << getGlobalLinkName(GV);
456 //===----------------------------------------------------------------------===//
457 /// LEB 128 number encoding.
459 /// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
460 /// representing an unsigned leb128 value.
461 void AsmPrinter::PrintULEB128(unsigned Value) const {
463 unsigned Byte = Value & 0x7f;
465 if (Value) Byte |= 0x80;
466 O << "0x" << std::hex << Byte << std::dec;
467 if (Value) O << ", ";
471 /// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
473 unsigned AsmPrinter::SizeULEB128(unsigned Value) {
477 Size += sizeof(int8_t);
482 /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
483 /// representing a signed leb128 value.
484 void AsmPrinter::PrintSLEB128(int Value) const {
485 int Sign = Value >> (8 * sizeof(Value) - 1);
489 unsigned Byte = Value & 0x7f;
491 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
492 if (IsMore) Byte |= 0x80;
493 O << "0x" << std::hex << Byte << std::dec;
494 if (IsMore) O << ", ";
498 /// SizeSLEB128 - Compute the number of bytes required for a signed leb128
500 unsigned AsmPrinter::SizeSLEB128(int Value) {
502 int Sign = Value >> (8 * sizeof(Value) - 1);
506 unsigned Byte = Value & 0x7f;
508 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
509 Size += sizeof(int8_t);
514 //===--------------------------------------------------------------------===//
515 // Emission and print routines
518 /// PrintHex - Print a value as a hexidecimal value.
520 void AsmPrinter::PrintHex(int Value) const {
521 O << "0x" << std::hex << Value << std::dec;
524 /// EOL - Print a newline character to asm stream. If a comment is present
525 /// then it will be printed first. Comments should not contain '\n'.
526 void AsmPrinter::EOL() const {
529 void AsmPrinter::EOL(const std::string &Comment) const {
530 if (AsmVerbose && !Comment.empty()) {
532 << TAI->getCommentString()
539 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
540 /// unsigned leb128 value.
541 void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
542 if (TAI->hasLEB128()) {
546 O << TAI->getData8bitsDirective();
551 /// EmitSLEB128Bytes - print an assembler byte data directive to compose a
552 /// signed leb128 value.
553 void AsmPrinter::EmitSLEB128Bytes(int Value) const {
554 if (TAI->hasLEB128()) {
558 O << TAI->getData8bitsDirective();
563 /// EmitInt8 - Emit a byte directive and value.
565 void AsmPrinter::EmitInt8(int Value) const {
566 O << TAI->getData8bitsDirective();
567 PrintHex(Value & 0xFF);
570 /// EmitInt16 - Emit a short directive and value.
572 void AsmPrinter::EmitInt16(int Value) const {
573 O << TAI->getData16bitsDirective();
574 PrintHex(Value & 0xFFFF);
577 /// EmitInt32 - Emit a long directive and value.
579 void AsmPrinter::EmitInt32(int Value) const {
580 O << TAI->getData32bitsDirective();
584 /// EmitInt64 - Emit a long long directive and value.
586 void AsmPrinter::EmitInt64(uint64_t Value) const {
587 if (TAI->getData64bitsDirective()) {
588 O << TAI->getData64bitsDirective();
591 if (TM.getTargetData()->isBigEndian()) {
592 EmitInt32(unsigned(Value >> 32)); O << "\n";
593 EmitInt32(unsigned(Value));
595 EmitInt32(unsigned(Value)); O << "\n";
596 EmitInt32(unsigned(Value >> 32));
601 /// toOctal - Convert the low order bits of X into an octal digit.
603 static inline char toOctal(int X) {
607 /// printStringChar - Print a char, escaped if necessary.
609 static void printStringChar(std::ostream &O, unsigned char C) {
612 } else if (C == '\\') {
614 } else if (isprint(C)) {
618 case '\b': O << "\\b"; break;
619 case '\f': O << "\\f"; break;
620 case '\n': O << "\\n"; break;
621 case '\r': O << "\\r"; break;
622 case '\t': O << "\\t"; break;
625 O << toOctal(C >> 6);
626 O << toOctal(C >> 3);
627 O << toOctal(C >> 0);
633 /// EmitString - Emit a string with quotes and a null terminator.
634 /// Special characters are emitted properly.
635 /// \literal (Eg. '\t') \endliteral
636 void AsmPrinter::EmitString(const std::string &String) const {
637 const char* AscizDirective = TAI->getAscizDirective();
641 O << TAI->getAsciiDirective();
643 for (unsigned i = 0, N = String.size(); i < N; ++i) {
644 unsigned char C = String[i];
645 printStringChar(O, C);
654 /// EmitFile - Emit a .file directive.
655 void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
656 O << "\t.file\t" << Number << " \"";
657 for (unsigned i = 0, N = Name.size(); i < N; ++i) {
658 unsigned char C = Name[i];
659 printStringChar(O, C);
665 //===----------------------------------------------------------------------===//
667 // EmitAlignment - Emit an alignment directive to the specified power of
668 // two boundary. For example, if you pass in 3 here, you will get an 8
669 // byte alignment. If a global value is specified, and if that global has
670 // an explicit alignment requested, it will unconditionally override the
671 // alignment request. However, if ForcedAlignBits is specified, this value
672 // has final say: the ultimate alignment will be the max of ForcedAlignBits
673 // and the alignment computed with NumBits and the global.
677 // if (GV && GV->hasalignment) Align = GV->getalignment();
678 // Align = std::max(Align, ForcedAlignBits);
680 void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
681 unsigned ForcedAlignBits, bool UseFillExpr,
682 unsigned FillValue) const {
683 if (GV && GV->getAlignment())
684 NumBits = Log2_32(GV->getAlignment());
685 NumBits = std::max(NumBits, ForcedAlignBits);
687 if (NumBits == 0) return; // No need to emit alignment.
688 if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
689 O << TAI->getAlignDirective() << NumBits;
690 if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
695 /// EmitZeros - Emit a block of zeros.
697 void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
699 if (TAI->getZeroDirective()) {
700 O << TAI->getZeroDirective() << NumZeros;
701 if (TAI->getZeroDirectiveSuffix())
702 O << TAI->getZeroDirectiveSuffix();
705 for (; NumZeros; --NumZeros)
706 O << TAI->getData8bitsDirective() << "0\n";
711 // Print out the specified constant, without a storage class. Only the
712 // constants valid in constant expressions can occur here.
713 void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
714 if (CV->isNullValue() || isa<UndefValue>(CV))
716 else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
717 O << CI->getZExtValue();
718 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
719 // This is a constant address for a global variable or function. Use the
720 // name of the variable or function as the address value, possibly
721 // decorating it with GlobalVarAddrPrefix/Suffix or
722 // FunctionAddrPrefix/Suffix (these all default to "" )
723 if (isa<Function>(GV)) {
724 O << TAI->getFunctionAddrPrefix()
725 << Mang->getValueName(GV)
726 << TAI->getFunctionAddrSuffix();
728 O << TAI->getGlobalVarAddrPrefix()
729 << Mang->getValueName(GV)
730 << TAI->getGlobalVarAddrSuffix();
732 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
733 const TargetData *TD = TM.getTargetData();
734 unsigned Opcode = CE->getOpcode();
736 case Instruction::GetElementPtr: {
737 // generate a symbolic expression for the byte address
738 const Constant *ptrVal = CE->getOperand(0);
739 SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
740 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
744 EmitConstantValueOnly(ptrVal);
746 O << ") + " << Offset;
748 O << ") - " << -Offset;
750 EmitConstantValueOnly(ptrVal);
754 case Instruction::Trunc:
755 case Instruction::ZExt:
756 case Instruction::SExt:
757 case Instruction::FPTrunc:
758 case Instruction::FPExt:
759 case Instruction::UIToFP:
760 case Instruction::SIToFP:
761 case Instruction::FPToUI:
762 case Instruction::FPToSI:
763 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
765 case Instruction::BitCast:
766 return EmitConstantValueOnly(CE->getOperand(0));
768 case Instruction::IntToPtr: {
769 // Handle casts to pointers by changing them into casts to the appropriate
770 // integer type. This promotes constant folding and simplifies this code.
771 Constant *Op = CE->getOperand(0);
772 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
773 return EmitConstantValueOnly(Op);
777 case Instruction::PtrToInt: {
778 // Support only foldable casts to/from pointers that can be eliminated by
779 // changing the pointer to the appropriately sized integer type.
780 Constant *Op = CE->getOperand(0);
781 const Type *Ty = CE->getType();
783 // We can emit the pointer value into this slot if the slot is an
784 // integer slot greater or equal to the size of the pointer.
785 if (Ty->isInteger() &&
786 TD->getABITypeSize(Ty) >= TD->getABITypeSize(Op->getType()))
787 return EmitConstantValueOnly(Op);
789 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
790 EmitConstantValueOnly(Op);
793 case Instruction::Add:
794 case Instruction::Sub:
795 case Instruction::And:
796 case Instruction::Or:
797 case Instruction::Xor:
799 EmitConstantValueOnly(CE->getOperand(0));
802 case Instruction::Add:
805 case Instruction::Sub:
808 case Instruction::And:
811 case Instruction::Or:
814 case Instruction::Xor:
821 EmitConstantValueOnly(CE->getOperand(1));
825 assert(0 && "Unsupported operator!");
828 assert(0 && "Unknown constant value!");
832 /// printAsCString - Print the specified array as a C compatible string, only if
833 /// the predicate isString is true.
835 static void printAsCString(std::ostream &O, const ConstantArray *CVA,
837 assert(CVA->isString() && "Array is not string compatible!");
840 for (unsigned i = 0; i != LastElt; ++i) {
842 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
843 printStringChar(O, C);
848 /// EmitString - Emit a zero-byte-terminated string constant.
850 void AsmPrinter::EmitString(const ConstantArray *CVA) const {
851 unsigned NumElts = CVA->getNumOperands();
852 if (TAI->getAscizDirective() && NumElts &&
853 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
854 O << TAI->getAscizDirective();
855 printAsCString(O, CVA, NumElts-1);
857 O << TAI->getAsciiDirective();
858 printAsCString(O, CVA, NumElts);
863 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
864 /// If Packed is false, pad to the ABI size.
865 void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) {
866 const TargetData *TD = TM.getTargetData();
867 unsigned Size = Packed ?
868 TD->getTypeStoreSize(CV->getType()) : TD->getABITypeSize(CV->getType());
870 if (CV->isNullValue() || isa<UndefValue>(CV)) {
873 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
874 if (CVA->isString()) {
876 } else { // Not a string. Print the values in successive locations
877 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
878 EmitGlobalConstant(CVA->getOperand(i), false);
881 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
882 // Print the fields in successive locations. Pad to align if needed!
883 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
884 uint64_t sizeSoFar = 0;
885 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
886 const Constant* field = CVS->getOperand(i);
888 // Check if padding is needed and insert one or more 0s.
889 uint64_t fieldSize = TD->getTypeStoreSize(field->getType());
890 uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
891 - cvsLayout->getElementOffset(i)) - fieldSize;
892 sizeSoFar += fieldSize + padSize;
894 // Now print the actual field value without ABI size padding.
895 EmitGlobalConstant(field, true);
897 // Insert padding - this may include padding to increase the size of the
898 // current field up to the ABI size (if the struct is not packed) as well
899 // as padding to ensure that the next field starts at the right offset.
902 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
903 "Layout of constant struct may be incorrect!");
905 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
906 // FP Constants are printed as integer constants to avoid losing
908 if (CFP->getType() == Type::DoubleTy) {
909 double Val = CFP->getValueAPF().convertToDouble(); // for comment only
910 uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
911 if (TAI->getData64bitsDirective())
912 O << TAI->getData64bitsDirective() << i << "\t"
913 << TAI->getCommentString() << " double value: " << Val << "\n";
914 else if (TD->isBigEndian()) {
915 O << TAI->getData32bitsDirective() << unsigned(i >> 32)
916 << "\t" << TAI->getCommentString()
917 << " double most significant word " << Val << "\n";
918 O << TAI->getData32bitsDirective() << unsigned(i)
919 << "\t" << TAI->getCommentString()
920 << " double least significant word " << Val << "\n";
922 O << TAI->getData32bitsDirective() << unsigned(i)
923 << "\t" << TAI->getCommentString()
924 << " double least significant word " << Val << "\n";
925 O << TAI->getData32bitsDirective() << unsigned(i >> 32)
926 << "\t" << TAI->getCommentString()
927 << " double most significant word " << Val << "\n";
930 } else if (CFP->getType() == Type::FloatTy) {
931 float Val = CFP->getValueAPF().convertToFloat(); // for comment only
932 O << TAI->getData32bitsDirective()
933 << CFP->getValueAPF().convertToAPInt().getZExtValue()
934 << "\t" << TAI->getCommentString() << " float " << Val << "\n";
936 } else if (CFP->getType() == Type::X86_FP80Ty) {
937 // all long double variants are printed as hex
938 // api needed to prevent premature destruction
939 APInt api = CFP->getValueAPF().convertToAPInt();
940 const uint64_t *p = api.getRawData();
941 APFloat DoubleVal = CFP->getValueAPF();
942 DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
943 if (TD->isBigEndian()) {
944 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
945 << "\t" << TAI->getCommentString()
946 << " long double most significant halfword of ~"
947 << DoubleVal.convertToDouble() << "\n";
948 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
949 << "\t" << TAI->getCommentString()
950 << " long double next halfword\n";
951 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
952 << "\t" << TAI->getCommentString()
953 << " long double next halfword\n";
954 O << TAI->getData16bitsDirective() << uint16_t(p[0])
955 << "\t" << TAI->getCommentString()
956 << " long double next halfword\n";
957 O << TAI->getData16bitsDirective() << uint16_t(p[1])
958 << "\t" << TAI->getCommentString()
959 << " long double least significant halfword\n";
961 O << TAI->getData16bitsDirective() << uint16_t(p[1])
962 << "\t" << TAI->getCommentString()
963 << " long double least significant halfword of ~"
964 << DoubleVal.convertToDouble() << "\n";
965 O << TAI->getData16bitsDirective() << uint16_t(p[0])
966 << "\t" << TAI->getCommentString()
967 << " long double next halfword\n";
968 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
969 << "\t" << TAI->getCommentString()
970 << " long double next halfword\n";
971 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
972 << "\t" << TAI->getCommentString()
973 << " long double next halfword\n";
974 O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
975 << "\t" << TAI->getCommentString()
976 << " long double most significant halfword\n";
978 EmitZeros(Size - TD->getTypeStoreSize(Type::X86_FP80Ty));
980 } else if (CFP->getType() == Type::PPC_FP128Ty) {
981 // all long double variants are printed as hex
982 // api needed to prevent premature destruction
983 APInt api = CFP->getValueAPF().convertToAPInt();
984 const uint64_t *p = api.getRawData();
985 if (TD->isBigEndian()) {
986 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
987 << "\t" << TAI->getCommentString()
988 << " long double most significant word\n";
989 O << TAI->getData32bitsDirective() << uint32_t(p[0])
990 << "\t" << TAI->getCommentString()
991 << " long double next word\n";
992 O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
993 << "\t" << TAI->getCommentString()
994 << " long double next word\n";
995 O << TAI->getData32bitsDirective() << uint32_t(p[1])
996 << "\t" << TAI->getCommentString()
997 << " long double least significant word\n";
999 O << TAI->getData32bitsDirective() << uint32_t(p[1])
1000 << "\t" << TAI->getCommentString()
1001 << " long double least significant word\n";
1002 O << TAI->getData32bitsDirective() << uint32_t(p[1] >> 32)
1003 << "\t" << TAI->getCommentString()
1004 << " long double next word\n";
1005 O << TAI->getData32bitsDirective() << uint32_t(p[0])
1006 << "\t" << TAI->getCommentString()
1007 << " long double next word\n";
1008 O << TAI->getData32bitsDirective() << uint32_t(p[0] >> 32)
1009 << "\t" << TAI->getCommentString()
1010 << " long double most significant word\n";
1013 } else assert(0 && "Floating point constant type not handled");
1014 } else if (CV->getType() == Type::Int64Ty) {
1015 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1016 uint64_t Val = CI->getZExtValue();
1018 if (TAI->getData64bitsDirective())
1019 O << TAI->getData64bitsDirective() << Val << "\n";
1020 else if (TD->isBigEndian()) {
1021 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
1022 << "\t" << TAI->getCommentString()
1023 << " Double-word most significant word " << Val << "\n";
1024 O << TAI->getData32bitsDirective() << unsigned(Val)
1025 << "\t" << TAI->getCommentString()
1026 << " Double-word least significant word " << Val << "\n";
1028 O << TAI->getData32bitsDirective() << unsigned(Val)
1029 << "\t" << TAI->getCommentString()
1030 << " Double-word least significant word " << Val << "\n";
1031 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
1032 << "\t" << TAI->getCommentString()
1033 << " Double-word most significant word " << Val << "\n";
1037 } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
1038 const VectorType *PTy = CP->getType();
1040 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
1041 EmitGlobalConstant(CP->getOperand(I), false);
1046 const Type *type = CV->getType();
1047 printDataDirective(type);
1048 EmitConstantValueOnly(CV);
1053 AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
1054 // Target doesn't support this yet!
1058 /// PrintSpecial - Print information related to the specified machine instr
1059 /// that is independent of the operand, and may be independent of the instr
1060 /// itself. This can be useful for portably encoding the comment character
1061 /// or other bits of target-specific knowledge into the asmstrings. The
1062 /// syntax used is ${:comment}. Targets can override this to add support
1063 /// for their own strange codes.
1064 void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) {
1065 if (!strcmp(Code, "private")) {
1066 O << TAI->getPrivateGlobalPrefix();
1067 } else if (!strcmp(Code, "comment")) {
1068 O << TAI->getCommentString();
1069 } else if (!strcmp(Code, "uid")) {
1070 // Assign a unique ID to this machine instruction.
1071 static const MachineInstr *LastMI = 0;
1072 static const Function *F = 0;
1073 static unsigned Counter = 0U-1;
1075 // Comparing the address of MI isn't sufficient, because machineinstrs may
1076 // be allocated to the same address across functions.
1077 const Function *ThisF = MI->getParent()->getParent()->getFunction();
1079 // If this is a new machine instruction, bump the counter.
1080 if (LastMI != MI || F != ThisF) {
1087 cerr << "Unknown special formatter '" << Code
1088 << "' for machine instr: " << *MI;
1094 /// printInlineAsm - This method formats and prints the specified machine
1095 /// instruction that is an inline asm.
1096 void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
1097 unsigned NumOperands = MI->getNumOperands();
1099 // Count the number of register definitions.
1100 unsigned NumDefs = 0;
1101 for (; MI->getOperand(NumDefs).isRegister() && MI->getOperand(NumDefs).isDef();
1103 assert(NumDefs != NumOperands-1 && "No asm string?");
1105 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
1107 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
1108 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
1110 // If this asmstr is empty, just print the #APP/#NOAPP markers.
1111 // These are useful to see where empty asm's wound up.
1112 if (AsmStr[0] == 0) {
1113 O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << "\n";
1117 O << TAI->getInlineAsmStart() << "\n\t";
1119 // The variant of the current asmprinter.
1120 int AsmPrinterVariant = TAI->getAssemblerDialect();
1122 int CurVariant = -1; // The number of the {.|.|.} region we are in.
1123 const char *LastEmitted = AsmStr; // One past the last character emitted.
1125 while (*LastEmitted) {
1126 switch (*LastEmitted) {
1128 // Not a special case, emit the string section literally.
1129 const char *LiteralEnd = LastEmitted+1;
1130 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
1131 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
1133 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1134 O.write(LastEmitted, LiteralEnd-LastEmitted);
1135 LastEmitted = LiteralEnd;
1139 ++LastEmitted; // Consume newline character.
1140 O << "\n"; // Indent code with newline.
1143 ++LastEmitted; // Consume '$' character.
1147 switch (*LastEmitted) {
1148 default: Done = false; break;
1149 case '$': // $$ -> $
1150 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1152 ++LastEmitted; // Consume second '$' character.
1154 case '(': // $( -> same as GCC's { character.
1155 ++LastEmitted; // Consume '(' character.
1156 if (CurVariant != -1) {
1157 cerr << "Nested variants found in inline asm string: '"
1161 CurVariant = 0; // We're in the first variant now.
1164 ++LastEmitted; // consume '|' character.
1165 if (CurVariant == -1) {
1166 cerr << "Found '|' character outside of variant in inline asm "
1167 << "string: '" << AsmStr << "'\n";
1170 ++CurVariant; // We're in the next variant.
1172 case ')': // $) -> same as GCC's } char.
1173 ++LastEmitted; // consume ')' character.
1174 if (CurVariant == -1) {
1175 cerr << "Found '}' character outside of variant in inline asm "
1176 << "string: '" << AsmStr << "'\n";
1184 bool HasCurlyBraces = false;
1185 if (*LastEmitted == '{') { // ${variable}
1186 ++LastEmitted; // Consume '{' character.
1187 HasCurlyBraces = true;
1190 const char *IDStart = LastEmitted;
1193 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1194 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
1195 cerr << "Bad $ operand number in inline asm string: '"
1199 LastEmitted = IDEnd;
1201 char Modifier[2] = { 0, 0 };
1203 if (HasCurlyBraces) {
1204 // If we have curly braces, check for a modifier character. This
1205 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1206 if (*LastEmitted == ':') {
1207 ++LastEmitted; // Consume ':' character.
1208 if (*LastEmitted == 0) {
1209 cerr << "Bad ${:} expression in inline asm string: '"
1214 Modifier[0] = *LastEmitted;
1215 ++LastEmitted; // Consume modifier character.
1218 if (*LastEmitted != '}') {
1219 cerr << "Bad ${} expression in inline asm string: '"
1223 ++LastEmitted; // Consume '}' character.
1226 if ((unsigned)Val >= NumOperands-1) {
1227 cerr << "Invalid $ operand number in inline asm string: '"
1232 // Okay, we finally have a value number. Ask the target to print this
1234 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1239 // Scan to find the machine operand number for the operand.
1240 for (; Val; --Val) {
1241 if (OpNo >= MI->getNumOperands()) break;
1242 unsigned OpFlags = MI->getOperand(OpNo).getImm();
1243 OpNo += (OpFlags >> 3) + 1;
1246 if (OpNo >= MI->getNumOperands()) {
1249 unsigned OpFlags = MI->getOperand(OpNo).getImm();
1250 ++OpNo; // Skip over the ID number.
1252 if (Modifier[0]=='l') // labels are target independent
1253 printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
1256 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1257 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
1258 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1259 Modifier[0] ? Modifier : 0);
1261 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1262 Modifier[0] ? Modifier : 0);
1267 cerr << "Invalid operand found in inline asm: '"
1277 O << "\n\t" << TAI->getInlineAsmEnd() << "\n";
1280 /// printLabel - This method prints a local label used by debug and
1281 /// exception handling tables.
1282 void AsmPrinter::printLabel(const MachineInstr *MI) const {
1283 O << TAI->getPrivateGlobalPrefix()
1284 << "label" << MI->getOperand(0).getImm() << ":\n";
1287 void AsmPrinter::printLabel(unsigned Id) const {
1288 O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
1291 /// printDeclare - This method prints a local variable declaration used by
1293 /// FIXME: It doesn't really print anything rather it inserts a DebugVariable
1294 /// entry into dwarf table.
1295 void AsmPrinter::printDeclare(const MachineInstr *MI) const {
1296 int FI = MI->getOperand(0).getIndex();
1297 GlobalValue *GV = MI->getOperand(1).getGlobal();
1298 MMI->RecordVariable(GV, FI);
1301 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1302 /// instruction, using the specified assembler variant. Targets should
1303 /// overried this to format as appropriate.
1304 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
1305 unsigned AsmVariant, const char *ExtraCode) {
1306 // Target doesn't support this yet!
1310 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1311 unsigned AsmVariant,
1312 const char *ExtraCode) {
1313 // Target doesn't support this yet!
1317 /// printBasicBlockLabel - This method prints the label for the specified
1318 /// MachineBasicBlock
1319 void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1321 bool printComment) const {
1322 O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_"
1323 << MBB->getNumber();
1326 if (printComment && MBB->getBasicBlock())
1327 O << '\t' << TAI->getCommentString() << ' '
1328 << MBB->getBasicBlock()->getName();
1331 /// printPICJumpTableSetLabel - This method prints a set label for the
1332 /// specified MachineBasicBlock for a jumptable entry.
1333 void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
1334 const MachineBasicBlock *MBB) const {
1335 if (!TAI->getSetDirective())
1338 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1339 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
1340 printBasicBlockLabel(MBB, false, false);
1341 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1342 << '_' << uid << '\n';
1345 void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
1346 const MachineBasicBlock *MBB) const {
1347 if (!TAI->getSetDirective())
1350 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1351 << getFunctionNumber() << '_' << uid << '_' << uid2
1352 << "_set_" << MBB->getNumber() << ',';
1353 printBasicBlockLabel(MBB, false, false);
1354 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1355 << '_' << uid << '_' << uid2 << '\n';
1358 /// printDataDirective - This method prints the asm directive for the
1360 void AsmPrinter::printDataDirective(const Type *type) {
1361 const TargetData *TD = TM.getTargetData();
1362 switch (type->getTypeID()) {
1363 case Type::IntegerTyID: {
1364 unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1366 O << TAI->getData8bitsDirective();
1367 else if (BitWidth <= 16)
1368 O << TAI->getData16bitsDirective();
1369 else if (BitWidth <= 32)
1370 O << TAI->getData32bitsDirective();
1371 else if (BitWidth <= 64) {
1372 assert(TAI->getData64bitsDirective() &&
1373 "Target cannot handle 64-bit constant exprs!");
1374 O << TAI->getData64bitsDirective();
1378 case Type::PointerTyID:
1379 if (TD->getPointerSize() == 8) {
1380 assert(TAI->getData64bitsDirective() &&
1381 "Target cannot handle 64-bit pointer exprs!");
1382 O << TAI->getData64bitsDirective();
1384 O << TAI->getData32bitsDirective();
1387 case Type::FloatTyID: case Type::DoubleTyID:
1388 case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
1389 assert (0 && "Should have already output floating point constant.");
1391 assert (0 && "Can't handle printing this type of thing");