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->getTypeID()) {
89 case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID:
91 case Type::UShortTyID: case Type::ShortTyID:
93 case Type::UIntTyID: case Type::IntTyID:
95 case Type::ULongTyID: case Type::LongTyID: case Type::PointerTyID:
99 case Type::DoubleTyID:
101 case Type::ArrayTyID:
102 if (ArrayTypeIsString((ArrayType*) type))
105 return "<InvaliDataTypeForPrinting>";
107 return "<InvaliDataTypeForPrinting>";
111 /// Get the size of the constant for the given target.
112 /// If this is an unsized array, return 0.
115 ConstantToSize(const Constant* CV, const TargetMachine& target) {
116 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV)) {
117 const ArrayType *aty = cast<ArrayType>(CVA->getType());
118 if (ArrayTypeIsString(aty))
119 return 1 + CVA->getNumOperands();
122 return findOptimalStorageSize(target, CV->getType());
125 /// Align data larger than one L1 cache line on L1 cache line boundaries.
126 /// Align all smaller data on the next higher 2^x boundary (4, 8, ...).
129 SizeToAlignment(unsigned int size, const TargetMachine& target) {
130 const unsigned short cacheLineSize = 16;
131 if (size > (unsigned) cacheLineSize / 2)
132 return cacheLineSize;
134 for (unsigned sz=1; /*no condition*/; sz *= 2)
139 /// Get the size of the type and then use SizeToAlignment.
142 TypeToAlignment(const Type* type, const TargetMachine& target) {
143 return SizeToAlignment(findOptimalStorageSize(target, type), target);
146 /// Get the size of the constant and then use SizeToAlignment.
147 /// Handles strings as a special case;
149 ConstantToAlignment(const Constant* CV, const TargetMachine& target) {
150 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV))
151 if (ArrayTypeIsString(cast<ArrayType>(CVA->getType())))
152 return SizeToAlignment(1 + CVA->getNumOperands(), target);
154 return TypeToAlignment(CV->getType(), target);
157 } // End anonymous namespace
161 //===---------------------------------------------------------------------===//
162 // Code abstracted away from the AsmPrinter
163 //===---------------------------------------------------------------------===//
167 // Mangle symbol names appropriately
172 const TargetMachine &Target;
182 AsmPrinter(std::ostream &os, const TargetMachine &T)
183 : /* idTable(0), */ toAsm(os), Target(T), CurSection(Unknown) {}
189 // (start|end)(Module|Function) - Callback methods invoked by subclasses
190 void startModule(Module &M) {
191 Mang = new Mangler(M);
194 void PrintZeroBytesToPad(int numBytes) {
196 // Always use single unsigned bytes for padding. We don't know upon
197 // what data size the beginning address is aligned, so using anything
198 // other than a byte may cause alignment errors in the assembler.
201 printSingleConstantValue(Constant::getNullValue(Type::UByteTy));
204 /// Print a single constant value.
206 void printSingleConstantValue(const Constant* CV);
208 /// Print a constant value or values (it may be an aggregate).
209 /// Uses printSingleConstantValue() to print each individual value.
211 void printConstantValueOnly(const Constant* CV, int numPadBytesAfter = 0);
213 // Print a constant (which may be an aggregate) prefixed by all the
214 // appropriate directives. Uses printConstantValueOnly() to print the
216 void printConstant(const Constant* CV, std::string valID = "") {
217 if (valID.length() == 0)
220 toAsm << "\t.align\t" << ConstantToAlignment(CV, Target) << "\n";
222 // Print .size and .type only if it is not a string.
223 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
224 if (CVA->isString()) {
225 // print it as a string and return
226 toAsm << valID << ":\n";
227 toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
231 toAsm << "\t.type" << "\t" << valID << ",#object\n";
233 unsigned int constSize = ConstantToSize(CV, Target);
235 toAsm << "\t.size" << "\t" << valID << "," << constSize << "\n";
237 toAsm << valID << ":\n";
239 printConstantValueOnly(CV);
242 // enterSection - Use this method to enter a different section of the output
243 // executable. This is used to only output necessary section transitions.
245 void enterSection(enum Sections S) {
246 if (S == CurSection) return; // Only switch section if necessary
249 toAsm << "\n\t.section ";
252 default: assert(0 && "Bad section name!");
253 case Text: toAsm << "\".text\""; break;
254 case ReadOnlyData: toAsm << "\".rodata\",#alloc"; break;
255 case InitRWData: toAsm << "\".data\",#alloc,#write"; break;
256 case ZeroInitRWData: toAsm << "\".bss\",#alloc,#write"; break;
261 // getID Wrappers - Ensure consistent usage
262 // Symbol names in SparcV9 assembly language have these rules:
263 // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
264 // (b) A name beginning in "." is treated as a local name.
265 std::string getID(const Function *F) {
266 return Mang->getValueName(F);
268 std::string getID(const BasicBlock *BB) {
269 return ".L_" + getID(BB->getParent()) + "_" + Mang->getValueName(BB);
271 std::string getID(const GlobalVariable *GV) {
272 return Mang->getValueName(GV);
274 std::string getID(const Constant *CV) {
275 return ".C_" + Mang->getValueName(CV);
277 std::string getID(const GlobalValue *GV) {
278 if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
280 else if (const Function *F = dyn_cast<Function>(GV))
282 assert(0 && "Unexpected type of GlobalValue!");
286 // Combines expressions
287 inline std::string ConstantArithExprToString(const ConstantExpr* CE,
288 const TargetMachine &TM,
289 const std::string &op) {
290 return "(" + valToExprString(CE->getOperand(0), TM) + op
291 + valToExprString(CE->getOperand(1), TM) + ")";
294 /// ConstantExprToString() - Convert a ConstantExpr to an asm expression
295 /// and return this as a string.
297 std::string ConstantExprToString(const ConstantExpr* CE,
298 const TargetMachine& target);
300 /// valToExprString - Helper function for ConstantExprToString().
301 /// Appends result to argument string S.
303 std::string valToExprString(const Value* V, const TargetMachine& target);
305 } // End anonymous namespace
308 /// Print a single constant value.
310 void AsmPrinter::printSingleConstantValue(const Constant* CV) {
311 assert(CV->getType() != Type::VoidTy &&
312 CV->getType() != Type::LabelTy &&
313 "Unexpected type for Constant");
315 assert((!isa<ConstantArray>(CV) && ! isa<ConstantStruct>(CV))
316 && "Aggregate types should be handled outside this function");
318 toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
320 if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(CV)) {
321 // This is a constant address for a global variable or method.
322 // Use the name of the variable or method as the address value.
323 assert(isa<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
324 toAsm << getID(CPR->getValue()) << "\n";
325 } else if (isa<ConstantPointerNull>(CV)) {
326 // Null pointer value
328 } else if (const ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) {
329 // Constant expression built from operators, constants, and symbolic addrs
330 toAsm << ConstantExprToString(CE, Target) << "\n";
331 } else if (CV->getType()->isPrimitiveType()) {
332 // Check primitive types last
333 if (CV->getType()->isFloatingPoint()) {
334 // FP Constants are printed as integer constants to avoid losing
336 double Val = cast<ConstantFP>(CV)->getValue();
337 if (CV->getType() == Type::FloatTy) {
338 float FVal = (float)Val;
339 char *ProxyPtr = (char*)&FVal; // Abide by C TBAA rules
340 toAsm << *(unsigned int*)ProxyPtr;
341 } else if (CV->getType() == Type::DoubleTy) {
342 char *ProxyPtr = (char*)&Val; // Abide by C TBAA rules
343 toAsm << *(uint64_t*)ProxyPtr;
345 assert(0 && "Unknown floating point type!");
348 toAsm << "\t! " << CV->getType()->getDescription()
349 << " value: " << Val << "\n";
350 } else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
351 toAsm << (int)CB->getValue() << "\n";
353 WriteAsOperand(toAsm, CV, false, false) << "\n";
356 assert(0 && "Unknown elementary type for constant");
360 /// Print a constant value or values (it may be an aggregate).
361 /// Uses printSingleConstantValue() to print each individual value.
363 void AsmPrinter::printConstantValueOnly(const Constant* CV,
364 int numPadBytesAfter) {
365 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
366 if (CVA->isString()) {
367 // print the string alone and return
368 toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
370 // Not a string. Print the values in successive locations
371 const std::vector<Use> &constValues = CVA->getValues();
372 for (unsigned i=0; i < constValues.size(); i++)
373 printConstantValueOnly(cast<Constant>(constValues[i].get()));
375 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
376 // Print the fields in successive locations. Pad to align if needed!
377 const StructLayout *cvsLayout =
378 Target.getTargetData().getStructLayout(CVS->getType());
379 const std::vector<Use>& constValues = CVS->getValues();
380 unsigned sizeSoFar = 0;
381 for (unsigned i=0, N = constValues.size(); i < N; i++) {
382 const Constant* field = cast<Constant>(constValues[i].get());
384 // Check if padding is needed and insert one or more 0s.
386 Target.getTargetData().getTypeSize(field->getType());
387 int padSize = ((i == N-1? cvsLayout->StructSize
388 : cvsLayout->MemberOffsets[i+1])
389 - cvsLayout->MemberOffsets[i]) - fieldSize;
390 sizeSoFar += (fieldSize + padSize);
392 // Now print the actual field value
393 printConstantValueOnly(field, padSize);
395 assert(sizeSoFar == cvsLayout->StructSize &&
396 "Layout of constant struct may be incorrect!");
397 } else if (isa<ConstantAggregateZero>(CV)) {
398 PrintZeroBytesToPad(Target.getTargetData().getTypeSize(CV->getType()));
400 printSingleConstantValue(CV);
402 if (numPadBytesAfter)
403 PrintZeroBytesToPad(numPadBytesAfter);
406 /// ConstantExprToString() - Convert a ConstantExpr to an asm expression
407 /// and return this as a string.
409 std::string AsmPrinter::ConstantExprToString(const ConstantExpr* CE,
410 const TargetMachine& target) {
412 switch(CE->getOpcode()) {
413 case Instruction::GetElementPtr:
414 { // generate a symbolic expression for the byte address
415 const Value* ptrVal = CE->getOperand(0);
416 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
417 const TargetData &TD = target.getTargetData();
418 S += "(" + valToExprString(ptrVal, target) + ") + ("
419 + utostr(TD.getIndexedOffset(ptrVal->getType(),idxVec)) + ")";
423 case Instruction::Cast:
424 // Support only non-converting casts for now, i.e., a no-op.
425 // This assertion is not a complete check.
426 assert(target.getTargetData().getTypeSize(CE->getType()) ==
427 target.getTargetData().getTypeSize(CE->getOperand(0)->getType()));
428 S += "(" + valToExprString(CE->getOperand(0), target) + ")";
431 case Instruction::Add:
432 S += ConstantArithExprToString(CE, target, ") + (");
435 case Instruction::Sub:
436 S += ConstantArithExprToString(CE, target, ") - (");
439 case Instruction::Mul:
440 S += ConstantArithExprToString(CE, target, ") * (");
443 case Instruction::Div:
444 S += ConstantArithExprToString(CE, target, ") / (");
447 case Instruction::Rem:
448 S += ConstantArithExprToString(CE, target, ") % (");
451 case Instruction::And:
452 // Logical && for booleans; bitwise & otherwise
453 S += ConstantArithExprToString(CE, target,
454 ((CE->getType() == Type::BoolTy)? ") && (" : ") & ("));
457 case Instruction::Or:
458 // Logical || for booleans; bitwise | otherwise
459 S += ConstantArithExprToString(CE, target,
460 ((CE->getType() == Type::BoolTy)? ") || (" : ") | ("));
463 case Instruction::Xor:
464 // Bitwise ^ for all types
465 S += ConstantArithExprToString(CE, target, ") ^ (");
469 assert(0 && "Unsupported operator in ConstantExprToString()");
476 /// valToExprString - Helper function for ConstantExprToString().
477 /// Appends result to argument string S.
479 std::string AsmPrinter::valToExprString(const Value* V,
480 const TargetMachine& target) {
483 if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
484 if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
485 S += std::string(CB == ConstantBool::True ? "1" : "0");
486 else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
487 S += itostr(CI->getValue());
488 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
489 S += utostr(CI->getValue());
490 else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
491 S += ftostr(CFP->getValue());
492 else if (isa<ConstantPointerNull>(CV))
494 else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
495 S += valToExprString(CPR->getValue(), target);
496 else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
497 S += ConstantExprToString(CE, target);
500 } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
506 assert(0 && "Cannot convert value to string");
507 S += "<illegal-value>";
513 //===----------------------------------------------------------------------===//
514 // SparcV9AsmPrinter Code
515 //===----------------------------------------------------------------------===//
519 struct SparcV9AsmPrinter : public FunctionPass, public AsmPrinter {
520 inline SparcV9AsmPrinter(std::ostream &os, const TargetMachine &t)
521 : AsmPrinter(os, t) {}
523 const Function *currFunction;
525 const char *getPassName() const {
526 return "Output SparcV9 Assembly for Functions";
529 virtual bool doInitialization(Module &M) {
534 virtual bool runOnFunction(Function &F) {
540 virtual bool doFinalization(Module &M) {
545 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
546 AU.setPreservesAll();
549 void emitFunction(const Function &F);
551 void emitBasicBlock(const MachineBasicBlock &MBB);
552 void emitMachineInst(const MachineInstr *MI);
554 unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
555 void printOneOperand(const MachineOperand &Op, MachineOpCode opCode);
557 bool OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum);
558 bool OpIsMemoryAddressBase(const MachineInstr *MI, unsigned int opNum);
560 unsigned getOperandMask(unsigned Opcode) {
563 case V9::SUBcci: return 1 << 3; // Remove CC argument
564 default: return 0; // By default, don't hack operands...
568 void emitGlobals(const Module &M);
569 void printGlobalVariable(const GlobalVariable *GV);
572 } // End anonymous namespace
575 SparcV9AsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
576 unsigned int opNum) {
577 switch (MI->getOpcode()) {
589 SparcV9AsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
590 unsigned int opNum) {
591 if (Target.getInstrInfo()->isLoad(MI->getOpcode()))
593 else if (Target.getInstrInfo()->isStore(MI->getOpcode()))
600 #define PrintOp1PlusOp2(mop1, mop2, opCode) \
601 printOneOperand(mop1, opCode); \
603 printOneOperand(mop2, opCode);
606 SparcV9AsmPrinter::printOperands(const MachineInstr *MI,
609 const MachineOperand& mop = MI->getOperand(opNum);
611 if (OpIsBranchTargetLabel(MI, opNum)) {
612 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpcode());
614 } else if (OpIsMemoryAddressBase(MI, opNum)) {
616 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpcode());
620 printOneOperand(mop, MI->getOpcode());
626 SparcV9AsmPrinter::printOneOperand(const MachineOperand &mop,
627 MachineOpCode opCode)
629 bool needBitsFlag = true;
631 if (mop.isHiBits32())
633 else if (mop.isLoBits32())
635 else if (mop.isHiBits64())
637 else if (mop.isLoBits64())
640 needBitsFlag = false;
642 switch (mop.getType())
644 case MachineOperand::MO_VirtualRegister:
645 case MachineOperand::MO_CCRegister:
646 case MachineOperand::MO_MachineRegister:
648 int regNum = (int)mop.getReg();
650 if (regNum == Target.getRegInfo()->getInvalidRegNum()) {
651 // better to print code with NULL registers than to die
652 toAsm << "<NULL VALUE>";
654 toAsm << "%" << Target.getRegInfo()->getUnifiedRegName(regNum);
659 case MachineOperand::MO_ConstantPoolIndex:
661 toAsm << ".CPI_" << getID(currFunction)
662 << "_" << mop.getConstantPoolIndex();
666 case MachineOperand::MO_PCRelativeDisp:
668 const Value *Val = mop.getVRegValue();
669 assert(Val && "\tNULL Value in SparcV9AsmPrinter");
671 if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
673 else if (const Function *F = dyn_cast<Function>(Val))
675 else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
677 else if (const Constant *CV = dyn_cast<Constant>(Val))
680 assert(0 && "Unrecognized value in SparcV9AsmPrinter");
684 case MachineOperand::MO_SignExtendedImmed:
685 toAsm << mop.getImmedValue();
688 case MachineOperand::MO_UnextendedImmed:
689 toAsm << (uint64_t) mop.getImmedValue();
693 toAsm << mop; // use dump field
701 void SparcV9AsmPrinter::emitMachineInst(const MachineInstr *MI) {
702 unsigned Opcode = MI->getOpcode();
704 if (Target.getInstrInfo()->isDummyPhiInstr(Opcode))
705 return; // IGNORE PHI NODES
707 toAsm << "\t" << Target.getInstrInfo()->getName(Opcode) << "\t";
709 unsigned Mask = getOperandMask(Opcode);
711 bool NeedComma = false;
713 for (unsigned OpNum = 0; OpNum < MI->getNumOperands(); OpNum += N)
714 if (! ((1 << OpNum) & Mask)) { // Ignore this operand?
715 if (NeedComma) toAsm << ", "; // Handle comma outputting
717 N = printOperands(MI, OpNum);
725 void SparcV9AsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
726 // Emit a label for the basic block
727 toAsm << getID(MBB.getBasicBlock()) << ":\n";
729 // Loop over all of the instructions in the basic block...
730 for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
732 emitMachineInst(MII);
733 toAsm << "\n"; // Separate BB's with newlines
736 void SparcV9AsmPrinter::emitFunction(const Function &F) {
737 std::string methName = getID(&F);
738 toAsm << "!****** Outputing Function: " << methName << " ******\n";
740 // Emit constant pool for this function
741 const MachineConstantPool *MCP = MachineFunction::get(&F).getConstantPool();
742 const std::vector<Constant*> &CP = MCP->getConstants();
744 enterSection(AsmPrinter::ReadOnlyData);
745 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
746 std::string cpiName = ".CPI_" + methName + "_" + utostr(i);
747 printConstant(CP[i], cpiName);
750 enterSection(AsmPrinter::Text);
751 toAsm << "\t.align\t4\n\t.global\t" << methName << "\n";
752 //toAsm << "\t.type\t" << methName << ",#function\n";
753 toAsm << "\t.type\t" << methName << ", 2\n";
754 toAsm << methName << ":\n";
756 // Output code for all of the basic blocks in the function...
757 MachineFunction &MF = MachineFunction::get(&F);
758 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E;++I)
761 // Output a .size directive so the debugger knows the extents of the function
762 toAsm << ".EndOf_" << methName << ":\n\t.size "
763 << methName << ", .EndOf_"
764 << methName << "-" << methName << "\n";
766 // Put some spaces between the functions
770 void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
771 if (GV->hasExternalLinkage())
772 toAsm << "\t.global\t" << getID(GV) << "\n";
774 if (GV->hasInitializer() && ! GV->getInitializer()->isNullValue()) {
775 printConstant(GV->getInitializer(), getID(GV));
777 toAsm << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
779 toAsm << "\t.type\t" << getID(GV) << ",#object\n";
780 toAsm << "\t.reserve\t" << getID(GV) << ","
781 << findOptimalStorageSize(Target, GV->getType()->getElementType())
786 void SparcV9AsmPrinter::emitGlobals(const Module &M) {
787 // Output global variables...
788 for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI)
789 if (! GI->isExternal()) {
790 assert(GI->hasInitializer());
791 if (GI->isConstant())
792 enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
793 else if (GI->getInitializer()->isNullValue())
794 enterSection(AsmPrinter::ZeroInitRWData); // read-write zero data
796 enterSection(AsmPrinter::InitRWData); // read-write non-zero data
798 printGlobalVariable(GI);
804 FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out,
805 const TargetMachine &TM) {
806 return new SparcV9AsmPrinter(Out, TM);