1 //===-- EmitAssembly.cpp - Emit SparcV9 Specific .s File -------------------==//
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 implements all of the stuff necessary to output a .s file from
11 // LLVM. The code in this file assumes that the specified module has already
12 // been compiled into the internal data structures of the Module.
14 // This code largely consists of two LLVM Pass's: a FunctionPass and a Pass.
15 // The FunctionPass is pipelined together with all of the rest of the code
16 // generation stages, and the Pass runs at the end to emit code for global
17 // variables and such.
19 //===----------------------------------------------------------------------===//
21 #include "llvm/Constants.h"
22 #include "llvm/DerivedTypes.h"
23 #include "llvm/Module.h"
24 #include "llvm/Pass.h"
25 #include "llvm/Assembly/Writer.h"
26 #include "llvm/CodeGen/MachineConstantPool.h"
27 #include "llvm/CodeGen/MachineFunction.h"
28 #include "llvm/CodeGen/MachineFunctionInfo.h"
29 #include "llvm/CodeGen/MachineInstr.h"
30 #include "llvm/Support/Mangler.h"
31 #include "Support/StringExtras.h"
32 #include "Support/Statistic.h"
33 #include "SparcV9Internals.h"
38 Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
40 //===--------------------------------------------------------------------===//
43 /// getAsCString - Return the specified array as a C compatible string, only
44 /// if the predicate isString() is true.
46 std::string getAsCString(const ConstantArray *CVA) {
47 assert(CVA->isString() && "Array is not string compatible!");
49 std::string Result = "\"";
50 for (unsigned i = 0; i != CVA->getNumOperands(); ++i) {
51 unsigned char C = cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
55 } else if (C == '\\') {
57 } else if (isprint(C)) {
60 Result += '\\'; // print all other chars as octal value
61 // Convert C to octal representation
62 Result += ((C >> 6) & 7) + '0';
63 Result += ((C >> 3) & 7) + '0';
64 Result += ((C >> 0) & 7) + '0';
72 inline bool ArrayTypeIsString(const ArrayType* arrayType) {
73 return (arrayType->getElementType() == Type::UByteTy ||
74 arrayType->getElementType() == Type::SByteTy);
77 unsigned findOptimalStorageSize(const TargetMachine &TM, const Type *Ty) {
78 // All integer types smaller than ints promote to 4 byte integers.
79 if (Ty->isIntegral() && Ty->getPrimitiveSize() < 4)
82 return TM.getTargetData().getTypeSize(Ty);
86 inline const std::string
87 TypeToDataDirective(const Type* type) {
88 switch(type->getPrimitiveID())
90 case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID:
92 case Type::UShortTyID: case Type::ShortTyID:
94 case Type::UIntTyID: case Type::IntTyID:
96 case Type::ULongTyID: case Type::LongTyID: case Type::PointerTyID:
100 case Type::DoubleTyID:
102 case Type::ArrayTyID:
103 if (ArrayTypeIsString((ArrayType*) type))
106 return "<InvaliDataTypeForPrinting>";
108 return "<InvaliDataTypeForPrinting>";
112 /// Get the size of the constant for the given target.
113 /// If this is an unsized array, return 0.
116 ConstantToSize(const Constant* CV, const TargetMachine& target) {
117 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV)) {
118 const ArrayType *aty = cast<ArrayType>(CVA->getType());
119 if (ArrayTypeIsString(aty))
120 return 1 + CVA->getNumOperands();
123 return findOptimalStorageSize(target, CV->getType());
126 /// Align data larger than one L1 cache line on L1 cache line boundaries.
127 /// Align all smaller data on the next higher 2^x boundary (4, 8, ...).
130 SizeToAlignment(unsigned int size, const TargetMachine& target) {
131 const unsigned short cacheLineSize = 16;
132 if (size > (unsigned) cacheLineSize / 2)
133 return cacheLineSize;
135 for (unsigned sz=1; /*no condition*/; sz *= 2)
140 /// Get the size of the type and then use SizeToAlignment.
143 TypeToAlignment(const Type* type, const TargetMachine& target) {
144 return SizeToAlignment(findOptimalStorageSize(target, type), target);
147 /// Get the size of the constant and then use SizeToAlignment.
148 /// Handles strings as a special case;
150 ConstantToAlignment(const Constant* CV, const TargetMachine& target) {
151 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV))
152 if (ArrayTypeIsString(cast<ArrayType>(CVA->getType())))
153 return SizeToAlignment(1 + CVA->getNumOperands(), target);
155 return TypeToAlignment(CV->getType(), target);
158 } // End anonymous namespace
162 //===---------------------------------------------------------------------===//
163 // Code abstracted away from the AsmPrinter
164 //===---------------------------------------------------------------------===//
168 // Mangle symbol names appropriately
173 const TargetMachine &Target;
183 AsmPrinter(std::ostream &os, const TargetMachine &T)
184 : /* idTable(0), */ toAsm(os), Target(T), CurSection(Unknown) {}
190 // (start|end)(Module|Function) - Callback methods invoked by subclasses
191 void startModule(Module &M) {
192 Mang = new Mangler(M);
195 void PrintZeroBytesToPad(int numBytes) {
197 // Always use single unsigned bytes for padding. We don't know upon
198 // what data size the beginning address is aligned, so using anything
199 // other than a byte may cause alignment errors in the assembler.
202 printSingleConstantValue(Constant::getNullValue(Type::UByteTy));
205 /// Print a single constant value.
207 void printSingleConstantValue(const Constant* CV);
209 /// Print a constant value or values (it may be an aggregate).
210 /// Uses printSingleConstantValue() to print each individual value.
212 void printConstantValueOnly(const Constant* CV, int numPadBytesAfter = 0);
214 // Print a constant (which may be an aggregate) prefixed by all the
215 // appropriate directives. Uses printConstantValueOnly() to print the
217 void printConstant(const Constant* CV, std::string valID = "") {
218 if (valID.length() == 0)
221 toAsm << "\t.align\t" << ConstantToAlignment(CV, Target) << "\n";
223 // Print .size and .type only if it is not a string.
224 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
225 if (CVA->isString()) {
226 // print it as a string and return
227 toAsm << valID << ":\n";
228 toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
232 toAsm << "\t.type" << "\t" << valID << ",#object\n";
234 unsigned int constSize = ConstantToSize(CV, Target);
236 toAsm << "\t.size" << "\t" << valID << "," << constSize << "\n";
238 toAsm << valID << ":\n";
240 printConstantValueOnly(CV);
243 // enterSection - Use this method to enter a different section of the output
244 // executable. This is used to only output necessary section transitions.
246 void enterSection(enum Sections S) {
247 if (S == CurSection) return; // Only switch section if necessary
250 toAsm << "\n\t.section ";
253 default: assert(0 && "Bad section name!");
254 case Text: toAsm << "\".text\""; break;
255 case ReadOnlyData: toAsm << "\".rodata\",#alloc"; break;
256 case InitRWData: toAsm << "\".data\",#alloc,#write"; break;
257 case ZeroInitRWData: toAsm << "\".bss\",#alloc,#write"; break;
262 // getID Wrappers - Ensure consistent usage
263 // Symbol names in SparcV9 assembly language have these rules:
264 // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
265 // (b) A name beginning in "." is treated as a local name.
266 std::string getID(const Function *F) {
267 return Mang->getValueName(F);
269 std::string getID(const BasicBlock *BB) {
270 return ".L_" + getID(BB->getParent()) + "_" + Mang->getValueName(BB);
272 std::string getID(const GlobalVariable *GV) {
273 return Mang->getValueName(GV);
275 std::string getID(const Constant *CV) {
276 return ".C_" + Mang->getValueName(CV);
278 std::string getID(const GlobalValue *GV) {
279 if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
281 else if (const Function *F = dyn_cast<Function>(GV))
283 assert(0 && "Unexpected type of GlobalValue!");
287 // Combines expressions
288 inline std::string ConstantArithExprToString(const ConstantExpr* CE,
289 const TargetMachine &TM,
290 const std::string &op) {
291 return "(" + valToExprString(CE->getOperand(0), TM) + op
292 + valToExprString(CE->getOperand(1), TM) + ")";
295 /// ConstantExprToString() - Convert a ConstantExpr to an asm expression
296 /// and return this as a string.
298 std::string ConstantExprToString(const ConstantExpr* CE,
299 const TargetMachine& target);
301 /// valToExprString - Helper function for ConstantExprToString().
302 /// Appends result to argument string S.
304 std::string valToExprString(const Value* V, const TargetMachine& target);
306 } // End anonymous namespace
309 /// Print a single constant value.
311 void AsmPrinter::printSingleConstantValue(const Constant* CV) {
312 assert(CV->getType() != Type::VoidTy &&
313 CV->getType() != Type::LabelTy &&
314 "Unexpected type for Constant");
316 assert((!isa<ConstantArray>(CV) && ! isa<ConstantStruct>(CV))
317 && "Aggregate types should be handled outside this function");
319 toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
321 if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(CV)) {
322 // This is a constant address for a global variable or method.
323 // Use the name of the variable or method as the address value.
324 assert(isa<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
325 toAsm << getID(CPR->getValue()) << "\n";
326 } else if (isa<ConstantPointerNull>(CV)) {
327 // Null pointer value
329 } else if (const ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) {
330 // Constant expression built from operators, constants, and symbolic addrs
331 toAsm << ConstantExprToString(CE, Target) << "\n";
332 } else if (CV->getType()->isPrimitiveType()) {
333 // Check primitive types last
334 if (CV->getType()->isFloatingPoint()) {
335 // FP Constants are printed as integer constants to avoid losing
337 double Val = cast<ConstantFP>(CV)->getValue();
338 if (CV->getType() == Type::FloatTy) {
339 float FVal = (float)Val;
340 char *ProxyPtr = (char*)&FVal; // Abide by C TBAA rules
341 toAsm << *(unsigned int*)ProxyPtr;
342 } else if (CV->getType() == Type::DoubleTy) {
343 char *ProxyPtr = (char*)&Val; // Abide by C TBAA rules
344 toAsm << *(uint64_t*)ProxyPtr;
346 assert(0 && "Unknown floating point type!");
349 toAsm << "\t! " << CV->getType()->getDescription()
350 << " value: " << Val << "\n";
351 } else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
352 toAsm << (int)CB->getValue() << "\n";
354 WriteAsOperand(toAsm, CV, false, false) << "\n";
357 assert(0 && "Unknown elementary type for constant");
361 /// Print a constant value or values (it may be an aggregate).
362 /// Uses printSingleConstantValue() to print each individual value.
364 void AsmPrinter::printConstantValueOnly(const Constant* CV,
365 int numPadBytesAfter) {
366 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
367 if (CVA->isString()) {
368 // print the string alone and return
369 toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
371 // Not a string. Print the values in successive locations
372 const std::vector<Use> &constValues = CVA->getValues();
373 for (unsigned i=0; i < constValues.size(); i++)
374 printConstantValueOnly(cast<Constant>(constValues[i].get()));
376 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
377 // Print the fields in successive locations. Pad to align if needed!
378 const StructLayout *cvsLayout =
379 Target.getTargetData().getStructLayout(CVS->getType());
380 const std::vector<Use>& constValues = CVS->getValues();
381 unsigned sizeSoFar = 0;
382 for (unsigned i=0, N = constValues.size(); i < N; i++) {
383 const Constant* field = cast<Constant>(constValues[i].get());
385 // Check if padding is needed and insert one or more 0s.
387 Target.getTargetData().getTypeSize(field->getType());
388 int padSize = ((i == N-1? cvsLayout->StructSize
389 : cvsLayout->MemberOffsets[i+1])
390 - cvsLayout->MemberOffsets[i]) - fieldSize;
391 sizeSoFar += (fieldSize + padSize);
393 // Now print the actual field value
394 printConstantValueOnly(field, padSize);
396 assert(sizeSoFar == cvsLayout->StructSize &&
397 "Layout of constant struct may be incorrect!");
398 } else if (isa<ConstantAggregateZero>(CV)) {
399 PrintZeroBytesToPad(Target.getTargetData().getTypeSize(CV->getType()));
401 printSingleConstantValue(CV);
403 if (numPadBytesAfter)
404 PrintZeroBytesToPad(numPadBytesAfter);
407 /// ConstantExprToString() - Convert a ConstantExpr to an asm expression
408 /// and return this as a string.
410 std::string AsmPrinter::ConstantExprToString(const ConstantExpr* CE,
411 const TargetMachine& target) {
413 switch(CE->getOpcode()) {
414 case Instruction::GetElementPtr:
415 { // generate a symbolic expression for the byte address
416 const Value* ptrVal = CE->getOperand(0);
417 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
418 const TargetData &TD = target.getTargetData();
419 S += "(" + valToExprString(ptrVal, target) + ") + ("
420 + utostr(TD.getIndexedOffset(ptrVal->getType(),idxVec)) + ")";
424 case Instruction::Cast:
425 // Support only non-converting casts for now, i.e., a no-op.
426 // This assertion is not a complete check.
427 assert(target.getTargetData().getTypeSize(CE->getType()) ==
428 target.getTargetData().getTypeSize(CE->getOperand(0)->getType()));
429 S += "(" + valToExprString(CE->getOperand(0), target) + ")";
432 case Instruction::Add:
433 S += ConstantArithExprToString(CE, target, ") + (");
436 case Instruction::Sub:
437 S += ConstantArithExprToString(CE, target, ") - (");
440 case Instruction::Mul:
441 S += ConstantArithExprToString(CE, target, ") * (");
444 case Instruction::Div:
445 S += ConstantArithExprToString(CE, target, ") / (");
448 case Instruction::Rem:
449 S += ConstantArithExprToString(CE, target, ") % (");
452 case Instruction::And:
453 // Logical && for booleans; bitwise & otherwise
454 S += ConstantArithExprToString(CE, target,
455 ((CE->getType() == Type::BoolTy)? ") && (" : ") & ("));
458 case Instruction::Or:
459 // Logical || for booleans; bitwise | otherwise
460 S += ConstantArithExprToString(CE, target,
461 ((CE->getType() == Type::BoolTy)? ") || (" : ") | ("));
464 case Instruction::Xor:
465 // Bitwise ^ for all types
466 S += ConstantArithExprToString(CE, target, ") ^ (");
470 assert(0 && "Unsupported operator in ConstantExprToString()");
477 /// valToExprString - Helper function for ConstantExprToString().
478 /// Appends result to argument string S.
480 std::string AsmPrinter::valToExprString(const Value* V,
481 const TargetMachine& target) {
484 if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
485 if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
486 S += std::string(CB == ConstantBool::True ? "1" : "0");
487 else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
488 S += itostr(CI->getValue());
489 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
490 S += utostr(CI->getValue());
491 else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
492 S += ftostr(CFP->getValue());
493 else if (isa<ConstantPointerNull>(CV))
495 else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
496 S += valToExprString(CPR->getValue(), target);
497 else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
498 S += ConstantExprToString(CE, target);
501 } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
507 assert(0 && "Cannot convert value to string");
508 S += "<illegal-value>";
514 //===----------------------------------------------------------------------===//
515 // SparcV9AsmPrinter Code
516 //===----------------------------------------------------------------------===//
520 struct SparcV9AsmPrinter : public FunctionPass, public AsmPrinter {
521 inline SparcV9AsmPrinter(std::ostream &os, const TargetMachine &t)
522 : AsmPrinter(os, t) {}
524 const Function *currFunction;
526 const char *getPassName() const {
527 return "Output SparcV9 Assembly for Functions";
530 virtual bool doInitialization(Module &M) {
535 virtual bool runOnFunction(Function &F) {
541 virtual bool doFinalization(Module &M) {
546 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
547 AU.setPreservesAll();
550 void emitFunction(const Function &F);
552 void emitBasicBlock(const MachineBasicBlock &MBB);
553 void emitMachineInst(const MachineInstr *MI);
555 unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
556 void printOneOperand(const MachineOperand &Op, MachineOpCode opCode);
558 bool OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum);
559 bool OpIsMemoryAddressBase(const MachineInstr *MI, unsigned int opNum);
561 unsigned getOperandMask(unsigned Opcode) {
564 case V9::SUBcci: return 1 << 3; // Remove CC argument
565 default: return 0; // By default, don't hack operands...
569 void emitGlobals(const Module &M);
570 void printGlobalVariable(const GlobalVariable *GV);
573 } // End anonymous namespace
576 SparcV9AsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
577 unsigned int opNum) {
578 switch (MI->getOpcode()) {
590 SparcV9AsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
591 unsigned int opNum) {
592 if (Target.getInstrInfo()->isLoad(MI->getOpcode()))
594 else if (Target.getInstrInfo()->isStore(MI->getOpcode()))
601 #define PrintOp1PlusOp2(mop1, mop2, opCode) \
602 printOneOperand(mop1, opCode); \
604 printOneOperand(mop2, opCode);
607 SparcV9AsmPrinter::printOperands(const MachineInstr *MI,
610 const MachineOperand& mop = MI->getOperand(opNum);
612 if (OpIsBranchTargetLabel(MI, opNum)) {
613 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpcode());
615 } else if (OpIsMemoryAddressBase(MI, opNum)) {
617 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpcode());
621 printOneOperand(mop, MI->getOpcode());
627 SparcV9AsmPrinter::printOneOperand(const MachineOperand &mop,
628 MachineOpCode opCode)
630 bool needBitsFlag = true;
632 if (mop.isHiBits32())
634 else if (mop.isLoBits32())
636 else if (mop.isHiBits64())
638 else if (mop.isLoBits64())
641 needBitsFlag = false;
643 switch (mop.getType())
645 case MachineOperand::MO_VirtualRegister:
646 case MachineOperand::MO_CCRegister:
647 case MachineOperand::MO_MachineRegister:
649 int regNum = (int)mop.getReg();
651 if (regNum == Target.getRegInfo()->getInvalidRegNum()) {
652 // better to print code with NULL registers than to die
653 toAsm << "<NULL VALUE>";
655 toAsm << "%" << Target.getRegInfo()->getUnifiedRegName(regNum);
660 case MachineOperand::MO_ConstantPoolIndex:
662 toAsm << ".CPI_" << getID(currFunction)
663 << "_" << mop.getConstantPoolIndex();
667 case MachineOperand::MO_PCRelativeDisp:
669 const Value *Val = mop.getVRegValue();
670 assert(Val && "\tNULL Value in SparcV9AsmPrinter");
672 if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
674 else if (const Function *F = dyn_cast<Function>(Val))
676 else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
678 else if (const Constant *CV = dyn_cast<Constant>(Val))
681 assert(0 && "Unrecognized value in SparcV9AsmPrinter");
685 case MachineOperand::MO_SignExtendedImmed:
686 toAsm << mop.getImmedValue();
689 case MachineOperand::MO_UnextendedImmed:
690 toAsm << (uint64_t) mop.getImmedValue();
694 toAsm << mop; // use dump field
702 void SparcV9AsmPrinter::emitMachineInst(const MachineInstr *MI) {
703 unsigned Opcode = MI->getOpcode();
705 if (Target.getInstrInfo()->isDummyPhiInstr(Opcode))
706 return; // IGNORE PHI NODES
708 toAsm << "\t" << Target.getInstrInfo()->getName(Opcode) << "\t";
710 unsigned Mask = getOperandMask(Opcode);
712 bool NeedComma = false;
714 for (unsigned OpNum = 0; OpNum < MI->getNumOperands(); OpNum += N)
715 if (! ((1 << OpNum) & Mask)) { // Ignore this operand?
716 if (NeedComma) toAsm << ", "; // Handle comma outputting
718 N = printOperands(MI, OpNum);
726 void SparcV9AsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
727 // Emit a label for the basic block
728 toAsm << getID(MBB.getBasicBlock()) << ":\n";
730 // Loop over all of the instructions in the basic block...
731 for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
733 emitMachineInst(MII);
734 toAsm << "\n"; // Separate BB's with newlines
737 void SparcV9AsmPrinter::emitFunction(const Function &F) {
738 std::string methName = getID(&F);
739 toAsm << "!****** Outputing Function: " << methName << " ******\n";
741 // Emit constant pool for this function
742 const MachineConstantPool *MCP = MachineFunction::get(&F).getConstantPool();
743 const std::vector<Constant*> &CP = MCP->getConstants();
745 enterSection(AsmPrinter::ReadOnlyData);
746 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
747 std::string cpiName = ".CPI_" + methName + "_" + utostr(i);
748 printConstant(CP[i], cpiName);
751 enterSection(AsmPrinter::Text);
752 toAsm << "\t.align\t4\n\t.global\t" << methName << "\n";
753 //toAsm << "\t.type\t" << methName << ",#function\n";
754 toAsm << "\t.type\t" << methName << ", 2\n";
755 toAsm << methName << ":\n";
757 // Output code for all of the basic blocks in the function...
758 MachineFunction &MF = MachineFunction::get(&F);
759 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E;++I)
762 // Output a .size directive so the debugger knows the extents of the function
763 toAsm << ".EndOf_" << methName << ":\n\t.size "
764 << methName << ", .EndOf_"
765 << methName << "-" << methName << "\n";
767 // Put some spaces between the functions
771 void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
772 if (GV->hasExternalLinkage())
773 toAsm << "\t.global\t" << getID(GV) << "\n";
775 if (GV->hasInitializer() && ! GV->getInitializer()->isNullValue()) {
776 printConstant(GV->getInitializer(), getID(GV));
778 toAsm << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
780 toAsm << "\t.type\t" << getID(GV) << ",#object\n";
781 toAsm << "\t.reserve\t" << getID(GV) << ","
782 << findOptimalStorageSize(Target, GV->getType()->getElementType())
787 void SparcV9AsmPrinter::emitGlobals(const Module &M) {
788 // Output global variables...
789 for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI)
790 if (! GI->isExternal()) {
791 assert(GI->hasInitializer());
792 if (GI->isConstant())
793 enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
794 else if (GI->getInitializer()->isNullValue())
795 enterSection(AsmPrinter::ZeroInitRWData); // read-write zero data
797 enterSection(AsmPrinter::InitRWData); // read-write non-zero data
799 printGlobalVariable(GI);
805 FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out,
806 const TargetMachine &TM) {
807 return new SparcV9AsmPrinter(Out, TM);