1 //===-- PowerPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to PowerPC assembly language. This printer is
12 // the output mechanism used by `llc'.
14 // Documentation at http://developer.apple.com/documentation/DeveloperTools/
15 // Reference/Assembler/ASMIntroduction/chapter_1_section_1.html
17 //===----------------------------------------------------------------------===//
19 #define DEBUG_TYPE "asmprinter"
21 #include "PowerPCTargetMachine.h"
22 #include "llvm/Constants.h"
23 #include "llvm/DerivedTypes.h"
24 #include "llvm/Module.h"
25 #include "llvm/Assembly/Writer.h"
26 #include "llvm/CodeGen/AsmPrinter.h"
27 #include "llvm/CodeGen/MachineConstantPool.h"
28 #include "llvm/CodeGen/MachineFunctionPass.h"
29 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/CodeGen/ValueTypes.h"
31 #include "llvm/Support/Mangler.h"
32 #include "llvm/Support/MathExtras.h"
33 #include "llvm/Support/CommandLine.h"
34 #include "llvm/Support/Debug.h"
35 #include "llvm/Target/MRegisterInfo.h"
36 #include "llvm/Target/TargetInstrInfo.h"
37 #include "llvm/ADT/Statistic.h"
38 #include "llvm/ADT/StringExtras.h"
43 Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
45 struct PowerPCAsmPrinter : public AsmPrinter {
46 std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
47 std::set<std::string> Strings;
49 PowerPCAsmPrinter(std::ostream &O, TargetMachine &TM)
50 : AsmPrinter(O, TM), LabelNumber(0) {}
52 /// Unique incrementer for label values for referencing Global values.
56 virtual const char *getPassName() const {
57 return "PowerPC Assembly Printer";
60 PowerPCTargetMachine &getTM() {
61 return static_cast<PowerPCTargetMachine&>(TM);
64 /// printInstruction - This method is automatically generated by tablegen
65 /// from the instruction set description. This method returns true if the
66 /// machine instruction was sufficiently described to print it, otherwise it
68 bool printInstruction(const MachineInstr *MI);
70 void printMachineInstruction(const MachineInstr *MI);
71 void printOp(const MachineOperand &MO, bool IsCallOp = false);
73 void printOperand(const MachineInstr *MI, unsigned OpNo, MVT::ValueType VT){
74 const MachineOperand &MO = MI->getOperand(OpNo);
75 if (MO.getType() == MachineOperand::MO_MachineRegister) {
76 assert(MRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physreg??");
77 O << LowercaseString(TM.getRegisterInfo()->get(MO.getReg()).Name);
78 } else if (MO.isImmediate()) {
79 O << MO.getImmedValue();
85 void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo,
87 unsigned char value = MI->getOperand(OpNo).getImmedValue();
88 assert(value <= 31 && "Invalid u5imm argument!");
89 O << (unsigned int)value;
91 void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo,
93 unsigned char value = MI->getOperand(OpNo).getImmedValue();
94 assert(value <= 63 && "Invalid u6imm argument!");
95 O << (unsigned int)value;
97 void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo,
99 O << (short)MI->getOperand(OpNo).getImmedValue();
101 void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo,
103 O << (unsigned short)MI->getOperand(OpNo).getImmedValue();
105 void printBranchOperand(const MachineInstr *MI, unsigned OpNo,
107 // Branches can take an immediate operand. This is used by the branch
108 // selection pass to print $+8, an eight byte displacement from the PC.
109 if (MI->getOperand(OpNo).isImmediate()) {
110 O << "$+" << MI->getOperand(OpNo).getImmedValue();
112 printOp(MI->getOperand(OpNo),
113 TM.getInstrInfo()->isCall(MI->getOpcode()));
116 void printPICLabel(const MachineInstr *MI, unsigned OpNo,
118 // FIXME: should probably be converted to cout.width and cout.fill
119 O << "\"L0000" << LabelNumber << "$pb\"\n";
120 O << "\"L0000" << LabelNumber << "$pb\":";
122 void printSymbolHi(const MachineInstr *MI, unsigned OpNo,
125 printOp(MI->getOperand(OpNo));
126 O << "-\"L0000" << LabelNumber << "$pb\")";
128 void printSymbolLo(const MachineInstr *MI, unsigned OpNo,
130 // FIXME: Because LFS, LFD, and LWZ can be used either with a s16imm or
131 // a lo16 of a global or constant pool operand, we must handle both here.
132 // this isn't a great design, but it works for now.
133 if (MI->getOperand(OpNo).isImmediate()) {
134 O << (short)MI->getOperand(OpNo).getImmedValue();
137 printOp(MI->getOperand(OpNo));
138 O << "-\"L0000" << LabelNumber << "$pb\")";
141 void printcrbit(const MachineInstr *MI, unsigned OpNo,
143 unsigned char value = MI->getOperand(OpNo).getImmedValue();
144 assert(value <= 3 && "Invalid crbit argument!");
145 unsigned RegNo, CCReg = MI->getOperand(OpNo-1).getReg();
147 case PPC::CR0: RegNo = 0; break;
148 case PPC::CR1: RegNo = 1; break;
149 case PPC::CR2: RegNo = 2; break;
150 case PPC::CR3: RegNo = 3; break;
151 case PPC::CR4: RegNo = 4; break;
152 case PPC::CR5: RegNo = 5; break;
153 case PPC::CR6: RegNo = 6; break;
154 case PPC::CR7: RegNo = 7; break;
156 std::cerr << "Unhandled reg in enumRegToRealReg!\n";
159 O << 4 * RegNo + value;
162 virtual void printConstantPool(MachineConstantPool *MCP) = 0;
163 virtual bool runOnMachineFunction(MachineFunction &F) = 0;
164 virtual bool doFinalization(Module &M) = 0;
167 /// DarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac OS
170 struct DarwinAsmPrinter : public PowerPCAsmPrinter {
172 DarwinAsmPrinter(std::ostream &O, TargetMachine &TM)
173 : PowerPCAsmPrinter(O, TM) {
176 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
177 Data64bitsDirective = 0; // we can't emit a 64-bit unit
178 AlignmentIsInBytes = false; // Alignment is by power of 2.
181 virtual const char *getPassName() const {
182 return "Darwin PPC Assembly Printer";
185 void printConstantPool(MachineConstantPool *MCP);
186 bool runOnMachineFunction(MachineFunction &F);
187 bool doFinalization(Module &M);
190 /// AIXAsmPrinter - PowerPC assembly printer, customized for AIX
192 struct AIXAsmPrinter : public PowerPCAsmPrinter {
193 /// Map for labels corresponding to global variables
195 std::map<const GlobalVariable*,std::string> GVToLabelMap;
197 AIXAsmPrinter(std::ostream &O, TargetMachine &TM)
198 : PowerPCAsmPrinter(O, TM) {
201 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
202 Data64bitsDirective = 0; // we can't emit a 64-bit unit
203 AlignmentIsInBytes = false; // Alignment is by power of 2.
206 virtual const char *getPassName() const {
207 return "AIX PPC Assembly Printer";
210 void printConstantPool(MachineConstantPool *MCP);
211 bool runOnMachineFunction(MachineFunction &F);
212 bool doInitialization(Module &M);
213 bool doFinalization(Module &M);
215 } // end of anonymous namespace
217 // SwitchSection - Switch to the specified section of the executable if we are
218 // not already in it!
220 static void SwitchSection(std::ostream &OS, std::string &CurSection,
221 const char *NewSection) {
222 if (CurSection != NewSection) {
223 CurSection = NewSection;
224 if (!CurSection.empty())
225 OS << "\t" << NewSection << "\n";
229 /// isStringCompatible - Can we treat the specified array as a string?
230 /// Only if it is an array of ubytes or non-negative sbytes.
232 static bool isStringCompatible(const ConstantArray *CVA) {
233 const Type *ETy = cast<ArrayType>(CVA->getType())->getElementType();
234 if (ETy == Type::UByteTy) return true;
235 if (ETy != Type::SByteTy) return false;
237 for (unsigned i = 0; i < CVA->getNumOperands(); ++i)
238 if (cast<ConstantSInt>(CVA->getOperand(i))->getValue() < 0)
244 /// toOctal - Convert the low order bits of X into an octal digit.
246 static inline char toOctal(int X) {
250 // Possible states while outputting ASCII strings
259 /// SwitchStringSection - manage the changes required to output bytes as
260 /// characters in a string vs. numeric decimal values
262 static inline void SwitchStringSection(std::ostream &O, StringSection NewSect,
263 StringSection &Current) {
264 if (Current == None) {
265 if (NewSect == Alpha)
267 else if (NewSect == Numeric)
269 } else if (Current == Alpha) {
272 else if (NewSect == Numeric)
275 } else if (Current == Numeric) {
276 if (NewSect == Alpha)
279 else if (NewSect == Numeric)
286 /// getAsCString - Return the specified array as a C compatible
287 /// string, only if the predicate isStringCompatible is true.
289 static void printAsCString(std::ostream &O, const ConstantArray *CVA) {
290 assert(isStringCompatible(CVA) && "Array is not string compatible!");
292 if (CVA->getNumOperands() == 0)
295 StringSection Current = None;
296 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) {
297 unsigned char C = cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
299 SwitchStringSection(O, Alpha, Current);
301 } else if (isprint(C)) {
302 SwitchStringSection(O, Alpha, Current);
305 SwitchStringSection(O, Numeric, Current);
306 O << utostr((unsigned)C);
309 SwitchStringSection(O, None, Current);
313 /// createDarwinAsmPrinterPass - Returns a pass that prints the PPC assembly
314 /// code for a MachineFunction to the given output stream, in a format that the
315 /// Darwin assembler can deal with.
317 FunctionPass *llvm::createDarwinAsmPrinter(std::ostream &o, TargetMachine &tm) {
318 return new DarwinAsmPrinter(o, tm);
321 /// createAIXAsmPrinterPass - Returns a pass that prints the PPC assembly code
322 /// for a MachineFunction to the given output stream, in a format that the
323 /// AIX 5L assembler can deal with.
325 FunctionPass *llvm::createAIXAsmPrinter(std::ostream &o, TargetMachine &tm) {
326 return new AIXAsmPrinter(o, tm);
329 // Include the auto-generated portion of the assembly writer
330 #include "PowerPCGenAsmWriter.inc"
332 void PowerPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
333 const MRegisterInfo &RI = *TM.getRegisterInfo();
336 switch (MO.getType()) {
337 case MachineOperand::MO_VirtualRegister:
338 if (Value *V = MO.getVRegValueOrNull()) {
339 O << "<" << V->getName() << ">";
343 case MachineOperand::MO_MachineRegister:
344 case MachineOperand::MO_CCRegister:
345 O << LowercaseString(RI.get(MO.getReg()).Name);
348 case MachineOperand::MO_SignExtendedImmed:
349 case MachineOperand::MO_UnextendedImmed:
350 std::cerr << "printOp() does not handle immediate values\n";
354 case MachineOperand::MO_PCRelativeDisp:
355 std::cerr << "Shouldn't use addPCDisp() when building PPC MachineInstrs";
359 case MachineOperand::MO_MachineBasicBlock: {
360 MachineBasicBlock *MBBOp = MO.getMachineBasicBlock();
361 O << ".LBB" << Mang->getValueName(MBBOp->getParent()->getFunction())
362 << "_" << MBBOp->getNumber() << "\t; "
363 << MBBOp->getBasicBlock()->getName();
367 case MachineOperand::MO_ConstantPoolIndex:
368 O << ".CPI" << CurrentFnName << "_" << MO.getConstantPoolIndex();
371 case MachineOperand::MO_ExternalSymbol:
373 std::string Name(GlobalPrefix); Name += MO.getSymbolName();
374 FnStubs.insert(Name);
375 O << "L" << Name << "$stub";
378 O << GlobalPrefix << MO.getSymbolName();
381 case MachineOperand::MO_GlobalAddress: {
382 GlobalValue *GV = MO.getGlobal();
383 std::string Name = Mang->getValueName(GV);
385 // Dynamically-resolved functions need a stub for the function. Be
386 // wary however not to output $stub for external functions whose addresses
387 // are taken. Those should be emitted as $non_lazy_ptr below.
388 Function *F = dyn_cast<Function>(GV);
389 if (F && IsCallOp && F->isExternal()) {
390 FnStubs.insert(Name);
391 O << "L" << Name << "$stub";
395 // External or weakly linked global variables need non-lazily-resolved stubs
396 if ((GV->isExternal() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())){
397 if (GV->hasLinkOnceLinkage())
398 LinkOnceStubs.insert(Name);
400 GVStubs.insert(Name);
401 O << "L" << Name << "$non_lazy_ptr";
405 O << Mang->getValueName(GV);
410 O << "<unknown operand type: " << MO.getType() << ">";
415 /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
416 /// the current output stream.
418 void PowerPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
420 // Check for slwi/srwi mnemonics.
421 if (MI->getOpcode() == PPC::RLWINM) {
422 bool FoundMnemonic = false;
423 unsigned char SH = MI->getOperand(2).getImmedValue();
424 unsigned char MB = MI->getOperand(3).getImmedValue();
425 unsigned char ME = MI->getOperand(4).getImmedValue();
426 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
427 O << "slwi "; FoundMnemonic = true;
429 if (SH <= 31 && MB == (32-SH) && ME == 31) {
430 O << "srwi "; FoundMnemonic = true;
434 printOperand(MI, 0, MVT::i64);
436 printOperand(MI, 1, MVT::i64);
437 O << ", " << (unsigned int)SH << "\n";
442 if (printInstruction(MI))
443 return; // Printer was automatically generated
445 assert(0 && "Unhandled instruction in asm writer!");
450 /// runOnMachineFunction - This uses the printMachineInstruction()
451 /// method to print assembly for each instruction.
453 bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
454 setupMachineFunction(MF);
457 // Print out constants referenced by the function
458 printConstantPool(MF.getConstantPool());
460 // Print out labels for the function.
463 O << "\t.globl\t" << CurrentFnName << "\n";
464 O << CurrentFnName << ":\n";
466 // Print out code for the function.
467 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
469 // Print a label for the basic block.
470 O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t"
471 << CommentString << " " << I->getBasicBlock()->getName() << "\n";
472 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
474 // Print the assembly for the instruction.
476 printMachineInstruction(II);
481 // We didn't modify anything.
485 /// printConstantPool - Print to the current output stream assembly
486 /// representations of the constants in the constant pool MCP. This is
487 /// used to print out constants which have been "spilled to memory" by
488 /// the code generator.
490 void DarwinAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
491 const std::vector<Constant*> &CP = MCP->getConstants();
492 const TargetData &TD = TM.getTargetData();
494 if (CP.empty()) return;
496 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
498 emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
499 O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString
501 emitGlobalConstant(CP[i]);
505 bool DarwinAsmPrinter::doFinalization(Module &M) {
506 const TargetData &TD = TM.getTargetData();
507 std::string CurSection;
509 // Print out module-level global variables here.
510 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
511 if (I->hasInitializer()) { // External global require no code
513 std::string name = Mang->getValueName(I);
514 Constant *C = I->getInitializer();
515 unsigned Size = TD.getTypeSize(C->getType());
516 unsigned Align = TD.getTypeAlignmentShift(C->getType());
518 if (C->isNullValue() && /* FIXME: Verify correct */
519 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
520 I->hasLinkOnceLinkage())) {
521 SwitchSection(O, CurSection, ".data");
522 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
523 if (I->hasInternalLinkage())
524 O << ".lcomm " << name << "," << Size << "," << Align;
526 O << ".comm " << name << "," << Size;
528 WriteAsOperand(O, I, true, true, &M);
531 switch (I->getLinkage()) {
532 case GlobalValue::LinkOnceLinkage:
533 O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n"
534 << ".weak_definition " << name << '\n'
535 << ".private_extern " << name << '\n'
536 << ".section __DATA,__datacoal_nt,coalesced,no_toc\n";
537 LinkOnceStubs.insert(name);
539 case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
540 // Nonnull linkonce -> weak
541 O << "\t.weak " << name << "\n";
542 SwitchSection(O, CurSection, "");
543 O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
545 case GlobalValue::AppendingLinkage:
546 // FIXME: appending linkage variables should go into a section of
547 // their name or something. For now, just emit them as external.
548 case GlobalValue::ExternalLinkage:
549 // If external or appending, declare as a global symbol
550 O << "\t.globl " << name << "\n";
552 case GlobalValue::InternalLinkage:
553 SwitchSection(O, CurSection, ".data");
555 case GlobalValue::GhostLinkage:
556 std::cerr << "Error: unmaterialized (GhostLinkage) function in asm!";
560 emitAlignment(Align);
561 O << name << ":\t\t\t\t; ";
562 WriteAsOperand(O, I, true, true, &M);
564 WriteAsOperand(O, C, false, false, &M);
566 emitGlobalConstant(C);
570 // Output stubs for dynamically-linked functions
571 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
575 O << ".section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n";
577 O << "L" << *i << "$stub:\n";
578 O << "\t.indirect_symbol " << *i << "\n";
580 O << "\tbcl 20,31,L0$" << *i << "\n";
581 O << "L0$" << *i << ":\n";
583 O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n";
585 O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n";
586 O << "\tmtctr r12\n";
589 O << ".lazy_symbol_pointer\n";
590 O << "L" << *i << "$lazy_ptr:\n";
591 O << "\t.indirect_symbol " << *i << "\n";
592 O << "\t.long dyld_stub_binding_helper\n";
597 // Output stubs for external global variables
598 if (GVStubs.begin() != GVStubs.end())
599 O << ".data\n.non_lazy_symbol_pointer\n";
600 for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
602 O << "L" << *i << "$non_lazy_ptr:\n";
603 O << "\t.indirect_symbol " << *i << "\n";
607 // Output stubs for link-once variables
608 if (LinkOnceStubs.begin() != LinkOnceStubs.end())
609 O << ".data\n.align 2\n";
610 for (std::set<std::string>::iterator i = LinkOnceStubs.begin(),
611 e = LinkOnceStubs.end(); i != e; ++i) {
612 O << "L" << *i << "$non_lazy_ptr:\n"
613 << "\t.long\t" << *i << '\n';
616 AsmPrinter::doFinalization(M);
617 return false; // success
620 /// runOnMachineFunction - This uses the printMachineInstruction()
621 /// method to print assembly for each instruction.
623 bool AIXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
624 CurrentFnName = MF.getFunction()->getName();
626 // Print out constants referenced by the function
627 printConstantPool(MF.getConstantPool());
629 // Print out header for the function.
630 O << "\t.csect .text[PR]\n"
632 << "\t.globl " << CurrentFnName << '\n'
633 << "\t.globl ." << CurrentFnName << '\n'
634 << "\t.csect " << CurrentFnName << "[DS],3\n"
635 << CurrentFnName << ":\n"
636 << "\t.llong ." << CurrentFnName << ", TOC[tc0], 0\n"
637 << "\t.csect .text[PR]\n"
638 << '.' << CurrentFnName << ":\n";
640 // Print out code for the function.
641 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
643 // Print a label for the basic block.
644 O << "LBB" << CurrentFnName << "_" << I->getNumber() << ":\t# "
645 << I->getBasicBlock()->getName() << "\n";
646 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
648 // Print the assembly for the instruction.
650 printMachineInstruction(II);
655 O << "LT.." << CurrentFnName << ":\n"
657 << "\t.byte 0,0,32,65,128,0,0,0\n"
658 << "\t.long LT.." << CurrentFnName << "-." << CurrentFnName << '\n'
660 << "\t.byte \"" << CurrentFnName << "\"\n"
663 // We didn't modify anything.
667 /// printConstantPool - Print to the current output stream assembly
668 /// representations of the constants in the constant pool MCP. This is
669 /// used to print out constants which have been "spilled to memory" by
670 /// the code generator.
672 void AIXAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
673 const std::vector<Constant*> &CP = MCP->getConstants();
674 const TargetData &TD = TM.getTargetData();
676 if (CP.empty()) return;
678 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
680 O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType())
682 O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t;"
684 emitGlobalConstant(CP[i]);
688 bool AIXAsmPrinter::doInitialization(Module &M) {
689 const TargetData &TD = TM.getTargetData();
690 std::string CurSection;
692 O << "\t.machine \"ppc64\"\n"
694 << "\t.csect .text[PR]\n";
696 // Print out module-level global variables
697 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
698 if (!I->hasInitializer())
701 std::string Name = I->getName();
702 Constant *C = I->getInitializer();
703 // N.B.: We are defaulting to writable strings
704 if (I->hasExternalLinkage()) {
705 O << "\t.globl " << Name << '\n'
706 << "\t.csect .data[RW],3\n";
708 O << "\t.csect _global.rw_c[RW],3\n";
711 emitGlobalConstant(C);
714 // Output labels for globals
715 if (M.global_begin() != M.global_end()) O << "\t.toc\n";
716 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
717 const GlobalVariable *GV = I;
718 // Do not output labels for unused variables
719 if (GV->isExternal() && GV->use_begin() == GV->use_end())
722 std::string Name = GV->getName();
723 std::string Label = "LC.." + utostr(LabelNumber++);
724 GVToLabelMap[GV] = Label;
726 << "\t.tc " << Name << "[TC]," << Name;
727 if (GV->isExternal()) O << "[RW]";
731 Mang = new Mangler(M, ".");
732 return false; // success
735 bool AIXAsmPrinter::doFinalization(Module &M) {
736 const TargetData &TD = TM.getTargetData();
737 // Print out module-level global variables
738 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
739 if (I->hasInitializer() || I->hasExternalLinkage())
742 std::string Name = I->getName();
743 if (I->hasInternalLinkage()) {
744 O << "\t.lcomm " << Name << ",16,_global.bss_c";
746 O << "\t.comm " << Name << "," << TD.getTypeSize(I->getType())
747 << "," << log2((unsigned)TD.getTypeAlignment(I->getType()));
750 WriteAsOperand(O, I, true, true, &M);
754 O << "_section_.text:\n"
755 << "\t.csect .data[RW],3\n"
756 << "\t.llong _section_.text\n";
759 return false; // success