blob: 6898704191ade720f15c7b1f7a82fa872ac29cb9 [file] [log] [blame]
Brian Gaeke3ca4fcc2004-04-25 07:04:49 +00001//===-- EmitAssembly.cpp - Emit SparcV9 Specific .s File -------------------==//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
Chris Lattnere88f78c2001-09-19 13:47:27 +00009//
Misha Brukman5560c9d2003-08-18 14:43:39 +000010// This file implements all of the stuff necessary to output a .s file from
Chris Lattnere88f78c2001-09-19 13:47:27 +000011// LLVM. The code in this file assumes that the specified module has already
12// been compiled into the internal data structures of the Module.
13//
Chris Lattnerf57b8452002-04-27 06:56:12 +000014// 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.
Chris Lattnere88f78c2001-09-19 13:47:27 +000018//
19//===----------------------------------------------------------------------===//
20
Chris Lattner31bcdb82002-04-28 19:55:58 +000021#include "llvm/Constants.h"
Vikram S. Adve953c83e2001-10-28 21:38:52 +000022#include "llvm/DerivedTypes.h"
Chris Lattnere88f78c2001-09-19 13:47:27 +000023#include "llvm/Module.h"
Chris Lattnerd50b6712002-04-28 20:40:59 +000024#include "llvm/Pass.h"
Chris Lattner4b1de8e2002-04-18 18:15:38 +000025#include "llvm/Assembly/Writer.h"
Misha Brukman3d0ad412003-12-17 22:06:28 +000026#include "llvm/CodeGen/MachineConstantPool.h"
27#include "llvm/CodeGen/MachineFunction.h"
28#include "llvm/CodeGen/MachineFunctionInfo.h"
29#include "llvm/CodeGen/MachineInstr.h"
Misha Brukmancbbbdf72004-01-15 22:44:19 +000030#include "llvm/Support/Mangler.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000031#include "Support/StringExtras.h"
Brian Gaeke2c9b9132003-10-06 15:41:21 +000032#include "Support/Statistic.h"
Brian Gaekee3d68072004-02-25 18:44:15 +000033#include "SparcV9Internals.h"
Misha Brukmanf4de7832003-08-05 16:01:50 +000034#include <string>
Misha Brukman6275a042003-11-13 00:22:19 +000035using namespace llvm;
36
Chris Lattnere88f78c2001-09-19 13:47:27 +000037namespace {
Misha Brukman6275a042003-11-13 00:22:19 +000038 Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
Brian Gaeke2c9b9132003-10-06 15:41:21 +000039
Misha Brukman6275a042003-11-13 00:22:19 +000040 //===--------------------------------------------------------------------===//
41 // Utility functions
Misha Brukmanf905ed52003-11-07 17:45:28 +000042
Misha Brukman6275a042003-11-13 00:22:19 +000043 /// getAsCString - Return the specified array as a C compatible string, only
Chris Lattner07ad6422004-01-14 17:15:17 +000044 /// if the predicate isString() is true.
Misha Brukman6275a042003-11-13 00:22:19 +000045 ///
46 std::string getAsCString(const ConstantArray *CVA) {
Chris Lattner07ad6422004-01-14 17:15:17 +000047 assert(CVA->isString() && "Array is not string compatible!");
Misha Brukmanf905ed52003-11-07 17:45:28 +000048
Chris Lattner07ad6422004-01-14 17:15:17 +000049 std::string Result = "\"";
50 for (unsigned i = 0; i != CVA->getNumOperands(); ++i) {
Misha Brukman6275a042003-11-13 00:22:19 +000051 unsigned char C = cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Misha Brukmanf905ed52003-11-07 17:45:28 +000052
Misha Brukman6275a042003-11-13 00:22:19 +000053 if (C == '"') {
54 Result += "\\\"";
55 } else if (C == '\\') {
56 Result += "\\\\";
57 } else if (isprint(C)) {
58 Result += C;
59 } else {
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';
65 }
66 }
67 Result += "\"";
Misha Brukmanf905ed52003-11-07 17:45:28 +000068
Misha Brukman6275a042003-11-13 00:22:19 +000069 return Result;
70 }
71
72 inline bool ArrayTypeIsString(const ArrayType* arrayType) {
73 return (arrayType->getElementType() == Type::UByteTy ||
74 arrayType->getElementType() == Type::SByteTy);
75 }
76
Chris Lattnerd029cd22004-06-02 05:55:25 +000077 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)
80 return 4;
81
82 return TM.getTargetData().getTypeSize(Ty);
83 }
84
85
Misha Brukman6275a042003-11-13 00:22:19 +000086 inline const std::string
87 TypeToDataDirective(const Type* type) {
88 switch(type->getPrimitiveID())
Misha Brukmanf905ed52003-11-07 17:45:28 +000089 {
90 case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID:
91 return ".byte";
92 case Type::UShortTyID: case Type::ShortTyID:
93 return ".half";
94 case Type::UIntTyID: case Type::IntTyID:
95 return ".word";
96 case Type::ULongTyID: case Type::LongTyID: case Type::PointerTyID:
97 return ".xword";
98 case Type::FloatTyID:
99 return ".word";
100 case Type::DoubleTyID:
101 return ".xword";
102 case Type::ArrayTyID:
103 if (ArrayTypeIsString((ArrayType*) type))
104 return ".ascii";
105 else
106 return "<InvaliDataTypeForPrinting>";
107 default:
108 return "<InvaliDataTypeForPrinting>";
109 }
Misha Brukman6275a042003-11-13 00:22:19 +0000110 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000111
Misha Brukman6275a042003-11-13 00:22:19 +0000112 /// Get the size of the constant for the given target.
113 /// If this is an unsized array, return 0.
114 ///
115 inline unsigned int
116 ConstantToSize(const Constant* CV, const TargetMachine& target) {
117 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV)) {
Misha Brukmanf905ed52003-11-07 17:45:28 +0000118 const ArrayType *aty = cast<ArrayType>(CVA->getType());
119 if (ArrayTypeIsString(aty))
120 return 1 + CVA->getNumOperands();
121 }
122
Chris Lattnerd029cd22004-06-02 05:55:25 +0000123 return findOptimalStorageSize(target, CV->getType());
Misha Brukman6275a042003-11-13 00:22:19 +0000124 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000125
Misha Brukman6275a042003-11-13 00:22:19 +0000126 /// 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, ...).
128 ///
129 inline unsigned int
130 SizeToAlignment(unsigned int size, const TargetMachine& target) {
Brian Gaeke05b15fb2004-03-01 06:43:29 +0000131 const unsigned short cacheLineSize = 16;
Misha Brukman6275a042003-11-13 00:22:19 +0000132 if (size > (unsigned) cacheLineSize / 2)
133 return cacheLineSize;
134 else
135 for (unsigned sz=1; /*no condition*/; sz *= 2)
136 if (sz >= size)
137 return sz;
138 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000139
Misha Brukman6275a042003-11-13 00:22:19 +0000140 /// Get the size of the type and then use SizeToAlignment.
141 ///
142 inline unsigned int
143 TypeToAlignment(const Type* type, const TargetMachine& target) {
Chris Lattnerd029cd22004-06-02 05:55:25 +0000144 return SizeToAlignment(findOptimalStorageSize(target, type), target);
Misha Brukman6275a042003-11-13 00:22:19 +0000145 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000146
Misha Brukman6275a042003-11-13 00:22:19 +0000147 /// Get the size of the constant and then use SizeToAlignment.
148 /// Handles strings as a special case;
149 inline unsigned int
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);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000154
Misha Brukman6275a042003-11-13 00:22:19 +0000155 return TypeToAlignment(CV->getType(), target);
156 }
157
158} // End anonymous namespace
159
Misha Brukman6275a042003-11-13 00:22:19 +0000160
161
Vikram S. Adved198c472002-03-18 03:07:26 +0000162//===---------------------------------------------------------------------===//
Misha Brukman6275a042003-11-13 00:22:19 +0000163// Code abstracted away from the AsmPrinter
Vikram S. Adved198c472002-03-18 03:07:26 +0000164//===---------------------------------------------------------------------===//
165
Misha Brukman6275a042003-11-13 00:22:19 +0000166namespace {
Misha Brukman6275a042003-11-13 00:22:19 +0000167 class AsmPrinter {
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000168 // Mangle symbol names appropriately
169 Mangler *Mang;
170
Misha Brukman6275a042003-11-13 00:22:19 +0000171 public:
172 std::ostream &toAsm;
173 const TargetMachine &Target;
Misha Brukmanf905ed52003-11-07 17:45:28 +0000174
Misha Brukman6275a042003-11-13 00:22:19 +0000175 enum Sections {
176 Unknown,
177 Text,
178 ReadOnlyData,
179 InitRWData,
180 ZeroInitRWData,
181 } CurSection;
182
183 AsmPrinter(std::ostream &os, const TargetMachine &T)
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000184 : /* idTable(0), */ toAsm(os), Target(T), CurSection(Unknown) {}
Misha Brukmanf905ed52003-11-07 17:45:28 +0000185
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000186 ~AsmPrinter() {
187 delete Mang;
188 }
189
Misha Brukman6275a042003-11-13 00:22:19 +0000190 // (start|end)(Module|Function) - Callback methods invoked by subclasses
191 void startModule(Module &M) {
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000192 Mang = new Mangler(M);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000193 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000194
Misha Brukman6275a042003-11-13 00:22:19 +0000195 void PrintZeroBytesToPad(int numBytes) {
John Criswellccb2a672004-02-09 22:15:33 +0000196 //
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.
200 //
Misha Brukman6275a042003-11-13 00:22:19 +0000201 while (numBytes--)
202 printSingleConstantValue(Constant::getNullValue(Type::UByteTy));
Misha Brukmanf905ed52003-11-07 17:45:28 +0000203 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000204
Misha Brukman6275a042003-11-13 00:22:19 +0000205 /// Print a single constant value.
206 ///
207 void printSingleConstantValue(const Constant* CV);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000208
Misha Brukman6275a042003-11-13 00:22:19 +0000209 /// Print a constant value or values (it may be an aggregate).
210 /// Uses printSingleConstantValue() to print each individual value.
211 ///
212 void printConstantValueOnly(const Constant* CV, int numPadBytesAfter = 0);
213
214 // Print a constant (which may be an aggregate) prefixed by all the
215 // appropriate directives. Uses printConstantValueOnly() to print the
216 // value or values.
217 void printConstant(const Constant* CV, std::string valID = "") {
218 if (valID.length() == 0)
219 valID = getID(CV);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000220
Misha Brukman6275a042003-11-13 00:22:19 +0000221 toAsm << "\t.align\t" << ConstantToAlignment(CV, Target) << "\n";
Misha Brukmanf905ed52003-11-07 17:45:28 +0000222
Misha Brukman6275a042003-11-13 00:22:19 +0000223 // Print .size and .type only if it is not a string.
Chris Lattner07ad6422004-01-14 17:15:17 +0000224 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";
229 return;
230 }
Misha Brukman6275a042003-11-13 00:22:19 +0000231
232 toAsm << "\t.type" << "\t" << valID << ",#object\n";
233
234 unsigned int constSize = ConstantToSize(CV, Target);
235 if (constSize)
236 toAsm << "\t.size" << "\t" << valID << "," << constSize << "\n";
237
Misha Brukmanf905ed52003-11-07 17:45:28 +0000238 toAsm << valID << ":\n";
Misha Brukman6275a042003-11-13 00:22:19 +0000239
240 printConstantValueOnly(CV);
241 }
242
Misha Brukman6275a042003-11-13 00:22:19 +0000243 // enterSection - Use this method to enter a different section of the output
244 // executable. This is used to only output necessary section transitions.
245 //
246 void enterSection(enum Sections S) {
247 if (S == CurSection) return; // Only switch section if necessary
248 CurSection = S;
Misha Brukmanf905ed52003-11-07 17:45:28 +0000249
Misha Brukman6275a042003-11-13 00:22:19 +0000250 toAsm << "\n\t.section ";
251 switch (S)
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000252 {
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;
258 }
Misha Brukman6275a042003-11-13 00:22:19 +0000259 toAsm << "\n";
260 }
Chris Lattnere88f78c2001-09-19 13:47:27 +0000261
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000262 // getID Wrappers - Ensure consistent usage
Brian Gaekee3d68072004-02-25 18:44:15 +0000263 // Symbol names in SparcV9 assembly language have these rules:
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000264 // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
265 // (b) A name beginning in "." is treated as a local name.
Misha Brukman6275a042003-11-13 00:22:19 +0000266 std::string getID(const Function *F) {
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000267 return Mang->getValueName(F);
Misha Brukman6275a042003-11-13 00:22:19 +0000268 }
269 std::string getID(const BasicBlock *BB) {
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000270 return ".L_" + getID(BB->getParent()) + "_" + Mang->getValueName(BB);
Misha Brukman6275a042003-11-13 00:22:19 +0000271 }
272 std::string getID(const GlobalVariable *GV) {
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000273 return Mang->getValueName(GV);
Misha Brukman6275a042003-11-13 00:22:19 +0000274 }
275 std::string getID(const Constant *CV) {
Misha Brukmancbbbdf72004-01-15 22:44:19 +0000276 return ".C_" + Mang->getValueName(CV);
Misha Brukman6275a042003-11-13 00:22:19 +0000277 }
278 std::string getID(const GlobalValue *GV) {
279 if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
280 return getID(V);
281 else if (const Function *F = dyn_cast<Function>(GV))
282 return getID(F);
283 assert(0 && "Unexpected type of GlobalValue!");
284 return "";
285 }
Vikram S. Advee99941a2002-08-22 02:58:36 +0000286
Misha Brukman6275a042003-11-13 00:22:19 +0000287 // 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) + ")";
293 }
Misha Brukmanf4de7832003-08-05 16:01:50 +0000294
Misha Brukman6275a042003-11-13 00:22:19 +0000295 /// ConstantExprToString() - Convert a ConstantExpr to an asm expression
296 /// and return this as a string.
297 ///
298 std::string ConstantExprToString(const ConstantExpr* CE,
299 const TargetMachine& target);
300
301 /// valToExprString - Helper function for ConstantExprToString().
302 /// Appends result to argument string S.
303 ///
304 std::string valToExprString(const Value* V, const TargetMachine& target);
305 };
Misha Brukman6275a042003-11-13 00:22:19 +0000306} // End anonymous namespace
307
Misha Brukman6275a042003-11-13 00:22:19 +0000308
309/// Print a single constant value.
310///
311void AsmPrinter::printSingleConstantValue(const Constant* CV) {
312 assert(CV->getType() != Type::VoidTy &&
Misha Brukman6275a042003-11-13 00:22:19 +0000313 CV->getType() != Type::LabelTy &&
314 "Unexpected type for Constant");
315
316 assert((!isa<ConstantArray>(CV) && ! isa<ConstantStruct>(CV))
317 && "Aggregate types should be handled outside this function");
318
319 toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
320
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
328 toAsm << "0\n";
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
336 // precision...
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;
345 } else {
346 assert(0 && "Unknown floating point type!");
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000347 }
Misha Brukman6275a042003-11-13 00:22:19 +0000348
349 toAsm << "\t! " << CV->getType()->getDescription()
350 << " value: " << Val << "\n";
Chris Lattner21e79cb2004-02-10 05:16:44 +0000351 } else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
352 toAsm << (int)CB->getValue() << "\n";
Misha Brukman6275a042003-11-13 00:22:19 +0000353 } else {
354 WriteAsOperand(toAsm, CV, false, false) << "\n";
355 }
356 } else {
357 assert(0 && "Unknown elementary type for constant");
358 }
359}
Vikram S. Advee99941a2002-08-22 02:58:36 +0000360
Misha Brukman6275a042003-11-13 00:22:19 +0000361/// Print a constant value or values (it may be an aggregate).
362/// Uses printSingleConstantValue() to print each individual value.
363///
364void AsmPrinter::printConstantValueOnly(const Constant* CV,
Chris Lattner07ad6422004-01-14 17:15:17 +0000365 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";
370 } else {
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()));
375 }
Misha Brukman6275a042003-11-13 00:22:19 +0000376 } 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());
Vikram S. Adve537a8772002-09-05 18:28:10 +0000384
Misha Brukman6275a042003-11-13 00:22:19 +0000385 // Check if padding is needed and insert one or more 0s.
386 unsigned fieldSize =
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);
Vikram S. Adve72666e62003-08-01 15:55:53 +0000392
Misha Brukman6275a042003-11-13 00:22:19 +0000393 // Now print the actual field value
394 printConstantValueOnly(field, padSize);
395 }
396 assert(sizeSoFar == cvsLayout->StructSize &&
397 "Layout of constant struct may be incorrect!");
Chris Lattnerde512b52004-02-15 05:55:15 +0000398 } else if (isa<ConstantAggregateZero>(CV)) {
399 PrintZeroBytesToPad(Target.getTargetData().getTypeSize(CV->getType()));
400 } else
Misha Brukman6275a042003-11-13 00:22:19 +0000401 printSingleConstantValue(CV);
Vikram S. Adve72666e62003-08-01 15:55:53 +0000402
Misha Brukman6275a042003-11-13 00:22:19 +0000403 if (numPadBytesAfter)
404 PrintZeroBytesToPad(numPadBytesAfter);
405}
Vikram S. Adve72666e62003-08-01 15:55:53 +0000406
Misha Brukman6275a042003-11-13 00:22:19 +0000407/// ConstantExprToString() - Convert a ConstantExpr to an asm expression
408/// and return this as a string.
409///
410std::string AsmPrinter::ConstantExprToString(const ConstantExpr* CE,
411 const TargetMachine& target) {
412 std::string S;
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)) + ")";
Vikram S. Advee99941a2002-08-22 02:58:36 +0000421 break;
422 }
423
Misha Brukman6275a042003-11-13 00:22:19 +0000424 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) + ")";
430 break;
431
432 case Instruction::Add:
433 S += ConstantArithExprToString(CE, target, ") + (");
434 break;
435
436 case Instruction::Sub:
437 S += ConstantArithExprToString(CE, target, ") - (");
438 break;
439
440 case Instruction::Mul:
441 S += ConstantArithExprToString(CE, target, ") * (");
442 break;
443
444 case Instruction::Div:
445 S += ConstantArithExprToString(CE, target, ") / (");
446 break;
447
448 case Instruction::Rem:
449 S += ConstantArithExprToString(CE, target, ") % (");
450 break;
451
452 case Instruction::And:
453 // Logical && for booleans; bitwise & otherwise
454 S += ConstantArithExprToString(CE, target,
455 ((CE->getType() == Type::BoolTy)? ") && (" : ") & ("));
456 break;
457
458 case Instruction::Or:
459 // Logical || for booleans; bitwise | otherwise
460 S += ConstantArithExprToString(CE, target,
461 ((CE->getType() == Type::BoolTy)? ") || (" : ") | ("));
462 break;
463
464 case Instruction::Xor:
465 // Bitwise ^ for all types
466 S += ConstantArithExprToString(CE, target, ") ^ (");
467 break;
468
469 default:
470 assert(0 && "Unsupported operator in ConstantExprToString()");
471 break;
Vikram S. Advee99941a2002-08-22 02:58:36 +0000472 }
473
Misha Brukman6275a042003-11-13 00:22:19 +0000474 return S;
475}
Vikram S. Advee99941a2002-08-22 02:58:36 +0000476
Misha Brukman6275a042003-11-13 00:22:19 +0000477/// valToExprString - Helper function for ConstantExprToString().
478/// Appends result to argument string S.
479///
480std::string AsmPrinter::valToExprString(const Value* V,
481 const TargetMachine& target) {
482 std::string S;
483 bool failed = false;
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))
494 S += "0";
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);
Vikram S. Advee99941a2002-08-22 02:58:36 +0000499 else
500 failed = true;
Misha Brukman6275a042003-11-13 00:22:19 +0000501 } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
502 S += getID(GV);
503 } else
504 failed = true;
Vikram S. Advee99941a2002-08-22 02:58:36 +0000505
Misha Brukman6275a042003-11-13 00:22:19 +0000506 if (failed) {
507 assert(0 && "Cannot convert value to string");
508 S += "<illegal-value>";
Vikram S. Advee99941a2002-08-22 02:58:36 +0000509 }
Misha Brukman6275a042003-11-13 00:22:19 +0000510 return S;
511}
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000512
513
514//===----------------------------------------------------------------------===//
Brian Gaekee3d68072004-02-25 18:44:15 +0000515// SparcV9AsmPrinter Code
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000516//===----------------------------------------------------------------------===//
517
Misha Brukman6275a042003-11-13 00:22:19 +0000518namespace {
Misha Brukmanf905ed52003-11-07 17:45:28 +0000519
Brian Gaekee3d68072004-02-25 18:44:15 +0000520 struct SparcV9AsmPrinter : public FunctionPass, public AsmPrinter {
521 inline SparcV9AsmPrinter(std::ostream &os, const TargetMachine &t)
Misha Brukman6275a042003-11-13 00:22:19 +0000522 : AsmPrinter(os, t) {}
Chris Lattner96c466b2002-04-29 14:57:45 +0000523
Misha Brukman6275a042003-11-13 00:22:19 +0000524 const Function *currFunction;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000525
Misha Brukman6275a042003-11-13 00:22:19 +0000526 const char *getPassName() const {
Brian Gaekee3d68072004-02-25 18:44:15 +0000527 return "Output SparcV9 Assembly for Functions";
Chris Lattnere88f78c2001-09-19 13:47:27 +0000528 }
Misha Brukman6275a042003-11-13 00:22:19 +0000529
530 virtual bool doInitialization(Module &M) {
531 startModule(M);
532 return false;
533 }
534
535 virtual bool runOnFunction(Function &F) {
536 currFunction = &F;
Misha Brukman6275a042003-11-13 00:22:19 +0000537 emitFunction(F);
Misha Brukman6275a042003-11-13 00:22:19 +0000538 return false;
539 }
540
541 virtual bool doFinalization(Module &M) {
542 emitGlobals(M);
543 return false;
544 }
545
546 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
547 AU.setPreservesAll();
548 }
549
550 void emitFunction(const Function &F);
551 private :
552 void emitBasicBlock(const MachineBasicBlock &MBB);
553 void emitMachineInst(const MachineInstr *MI);
554
555 unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
556 void printOneOperand(const MachineOperand &Op, MachineOpCode opCode);
557
558 bool OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum);
559 bool OpIsMemoryAddressBase(const MachineInstr *MI, unsigned int opNum);
560
561 unsigned getOperandMask(unsigned Opcode) {
562 switch (Opcode) {
563 case V9::SUBccr:
564 case V9::SUBcci: return 1 << 3; // Remove CC argument
565 default: return 0; // By default, don't hack operands...
566 }
567 }
568
569 void emitGlobals(const Module &M);
570 void printGlobalVariable(const GlobalVariable *GV);
571 };
572
573} // End anonymous namespace
Chris Lattnere88f78c2001-09-19 13:47:27 +0000574
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000575inline bool
Brian Gaekee3d68072004-02-25 18:44:15 +0000576SparcV9AsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
Misha Brukman6275a042003-11-13 00:22:19 +0000577 unsigned int opNum) {
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000578 switch (MI->getOpcode()) {
Misha Brukman71ed1c92003-05-27 22:35:43 +0000579 case V9::JMPLCALLr:
580 case V9::JMPLCALLi:
581 case V9::JMPLRETr:
582 case V9::JMPLRETi:
Misha Brukmana98cd452003-05-20 20:32:24 +0000583 return (opNum == 0);
584 default:
585 return false;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000586 }
587}
588
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000589inline bool
Brian Gaekee3d68072004-02-25 18:44:15 +0000590SparcV9AsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
Misha Brukman6275a042003-11-13 00:22:19 +0000591 unsigned int opNum) {
Chris Lattnerd029cd22004-06-02 05:55:25 +0000592 if (Target.getInstrInfo()->isLoad(MI->getOpcode()))
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000593 return (opNum == 0);
Chris Lattnerd029cd22004-06-02 05:55:25 +0000594 else if (Target.getInstrInfo()->isStore(MI->getOpcode()))
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000595 return (opNum == 1);
596 else
597 return false;
598}
599
600
Vikram S. Adve78a4f232003-05-27 00:02:22 +0000601#define PrintOp1PlusOp2(mop1, mop2, opCode) \
602 printOneOperand(mop1, opCode); \
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000603 toAsm << "+"; \
Vikram S. Adve78a4f232003-05-27 00:02:22 +0000604 printOneOperand(mop2, opCode);
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000605
606unsigned int
Brian Gaekee3d68072004-02-25 18:44:15 +0000607SparcV9AsmPrinter::printOperands(const MachineInstr *MI,
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000608 unsigned int opNum)
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000609{
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000610 const MachineOperand& mop = MI->getOperand(opNum);
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000611
Misha Brukman6275a042003-11-13 00:22:19 +0000612 if (OpIsBranchTargetLabel(MI, opNum)) {
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000613 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpcode());
Misha Brukman6275a042003-11-13 00:22:19 +0000614 return 2;
615 } else if (OpIsMemoryAddressBase(MI, opNum)) {
616 toAsm << "[";
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000617 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpcode());
Misha Brukman6275a042003-11-13 00:22:19 +0000618 toAsm << "]";
619 return 2;
620 } else {
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000621 printOneOperand(mop, MI->getOpcode());
Misha Brukman6275a042003-11-13 00:22:19 +0000622 return 1;
623 }
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000624}
625
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000626void
Brian Gaekee3d68072004-02-25 18:44:15 +0000627SparcV9AsmPrinter::printOneOperand(const MachineOperand &mop,
Misha Brukman6275a042003-11-13 00:22:19 +0000628 MachineOpCode opCode)
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000629{
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000630 bool needBitsFlag = true;
631
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000632 if (mop.isHiBits32())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000633 toAsm << "%lm(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000634 else if (mop.isLoBits32())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000635 toAsm << "%lo(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000636 else if (mop.isHiBits64())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000637 toAsm << "%hh(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000638 else if (mop.isLoBits64())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000639 toAsm << "%hm(";
640 else
641 needBitsFlag = false;
642
Chris Lattner133f0792002-10-28 04:45:29 +0000643 switch (mop.getType())
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000644 {
Vikram S. Adve786833a2003-07-06 20:13:59 +0000645 case MachineOperand::MO_VirtualRegister:
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000646 case MachineOperand::MO_CCRegister:
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000647 case MachineOperand::MO_MachineRegister:
648 {
Alkis Evlogimenosbe766c72004-02-13 21:01:20 +0000649 int regNum = (int)mop.getReg();
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000650
Chris Lattnerd029cd22004-06-02 05:55:25 +0000651 if (regNum == Target.getRegInfo()->getInvalidRegNum()) {
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000652 // better to print code with NULL registers than to die
653 toAsm << "<NULL VALUE>";
654 } else {
Chris Lattnerd029cd22004-06-02 05:55:25 +0000655 toAsm << "%" << Target.getRegInfo()->getUnifiedRegName(regNum);
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000656 }
657 break;
658 }
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000659
Misha Brukmanf905ed52003-11-07 17:45:28 +0000660 case MachineOperand::MO_ConstantPoolIndex:
661 {
Brian Gaeke7e437532004-05-04 21:09:02 +0000662 toAsm << ".CPI_" << getID(currFunction)
Misha Brukmanf905ed52003-11-07 17:45:28 +0000663 << "_" << mop.getConstantPoolIndex();
664 break;
665 }
666
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000667 case MachineOperand::MO_PCRelativeDisp:
668 {
669 const Value *Val = mop.getVRegValue();
Brian Gaekee3d68072004-02-25 18:44:15 +0000670 assert(Val && "\tNULL Value in SparcV9AsmPrinter");
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000671
Chris Lattner949a3622003-07-23 15:30:06 +0000672 if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000673 toAsm << getID(BB);
Brian Gaeke7e437532004-05-04 21:09:02 +0000674 else if (const Function *F = dyn_cast<Function>(Val))
675 toAsm << getID(F);
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000676 else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
677 toAsm << getID(GV);
678 else if (const Constant *CV = dyn_cast<Constant>(Val))
679 toAsm << getID(CV);
680 else
Brian Gaekee3d68072004-02-25 18:44:15 +0000681 assert(0 && "Unrecognized value in SparcV9AsmPrinter");
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000682 break;
683 }
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000684
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000685 case MachineOperand::MO_SignExtendedImmed:
686 toAsm << mop.getImmedValue();
687 break;
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000688
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000689 case MachineOperand::MO_UnextendedImmed:
690 toAsm << (uint64_t) mop.getImmedValue();
691 break;
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000692
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000693 default:
694 toAsm << mop; // use dump field
695 break;
696 }
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000697
698 if (needBitsFlag)
699 toAsm << ")";
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000700}
701
Brian Gaekee3d68072004-02-25 18:44:15 +0000702void SparcV9AsmPrinter::emitMachineInst(const MachineInstr *MI) {
Brian Gaeke12c1d2c2004-02-11 20:47:34 +0000703 unsigned Opcode = MI->getOpcode();
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000704
Chris Lattnerd029cd22004-06-02 05:55:25 +0000705 if (Target.getInstrInfo()->isDummyPhiInstr(Opcode))
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000706 return; // IGNORE PHI NODES
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000707
Chris Lattnerd029cd22004-06-02 05:55:25 +0000708 toAsm << "\t" << Target.getInstrInfo()->getName(Opcode) << "\t";
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000709
710 unsigned Mask = getOperandMask(Opcode);
711
712 bool NeedComma = false;
713 unsigned N = 1;
714 for (unsigned OpNum = 0; OpNum < MI->getNumOperands(); OpNum += N)
715 if (! ((1 << OpNum) & Mask)) { // Ignore this operand?
Misha Brukman8b2fe192003-09-23 17:27:28 +0000716 if (NeedComma) toAsm << ", "; // Handle comma outputting
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000717 NeedComma = true;
718 N = printOperands(MI, OpNum);
Chris Lattnerebdc7f32002-11-17 22:57:23 +0000719 } else
720 N = 1;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000721
722 toAsm << "\n";
Brian Gaeke2c9b9132003-10-06 15:41:21 +0000723 ++EmittedInsts;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000724}
725
Brian Gaekee3d68072004-02-25 18:44:15 +0000726void SparcV9AsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000727 // Emit a label for the basic block
Misha Brukmane585a7d2002-10-28 20:01:13 +0000728 toAsm << getID(MBB.getBasicBlock()) << ":\n";
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000729
730 // Loop over all of the instructions in the basic block...
Misha Brukmane585a7d2002-10-28 20:01:13 +0000731 for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
Chris Lattner55291ea2002-10-28 01:41:47 +0000732 MII != MIE; ++MII)
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000733 emitMachineInst(MII);
Misha Brukmanbc0e9982003-07-14 17:20:40 +0000734 toAsm << "\n"; // Separate BB's with newlines
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000735}
736
Brian Gaekee3d68072004-02-25 18:44:15 +0000737void SparcV9AsmPrinter::emitFunction(const Function &F) {
Misha Brukmanf4de7832003-08-05 16:01:50 +0000738 std::string methName = getID(&F);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000739 toAsm << "!****** Outputing Function: " << methName << " ******\n";
Misha Brukmanf905ed52003-11-07 17:45:28 +0000740
741 // Emit constant pool for this function
742 const MachineConstantPool *MCP = MachineFunction::get(&F).getConstantPool();
743 const std::vector<Constant*> &CP = MCP->getConstants();
744
745 enterSection(AsmPrinter::ReadOnlyData);
746 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Brian Gaeke7ca67122004-05-04 21:41:45 +0000747 std::string cpiName = ".CPI_" + methName + "_" + utostr(i);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000748 printConstant(CP[i], cpiName);
749 }
750
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000751 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";
756
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000757 // Output code for all of the basic blocks in the function...
Misha Brukmane585a7d2002-10-28 20:01:13 +0000758 MachineFunction &MF = MachineFunction::get(&F);
Chris Lattnerd0fe5f52002-12-28 20:15:01 +0000759 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E;++I)
Misha Brukmane585a7d2002-10-28 20:01:13 +0000760 emitBasicBlock(*I);
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000761
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";
766
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000767 // Put some spaces between the functions
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000768 toAsm << "\n\n";
769}
770
Brian Gaekee3d68072004-02-25 18:44:15 +0000771void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
Vikram S. Adve13f1d712002-09-16 15:54:02 +0000772 if (GV->hasExternalLinkage())
773 toAsm << "\t.global\t" << getID(GV) << "\n";
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000774
Misha Brukman6275a042003-11-13 00:22:19 +0000775 if (GV->hasInitializer() && ! GV->getInitializer()->isNullValue()) {
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000776 printConstant(GV->getInitializer(), getID(GV));
Misha Brukman6275a042003-11-13 00:22:19 +0000777 } else {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000778 toAsm << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
779 Target) << "\n";
Chris Lattner697954c2002-01-20 22:54:45 +0000780 toAsm << "\t.type\t" << getID(GV) << ",#object\n";
Vikram S. Adveffbba0f2001-11-08 14:29:57 +0000781 toAsm << "\t.reserve\t" << getID(GV) << ","
Chris Lattnerd029cd22004-06-02 05:55:25 +0000782 << findOptimalStorageSize(Target, GV->getType()->getElementType())
Chris Lattner697954c2002-01-20 22:54:45 +0000783 << "\n";
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000784 }
785}
786
Brian Gaekee3d68072004-02-25 18:44:15 +0000787void SparcV9AsmPrinter::emitGlobals(const Module &M) {
Chris Lattner637ed862002-08-07 21:39:48 +0000788 // Output global variables...
Vikram S. Advefee76262002-10-13 00:32:18 +0000789 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
796 else
797 enterSection(AsmPrinter::InitRWData); // read-write non-zero data
798
799 printGlobalVariable(GI);
Chris Lattner637ed862002-08-07 21:39:48 +0000800 }
Chris Lattner637ed862002-08-07 21:39:48 +0000801
Chris Lattner697954c2002-01-20 22:54:45 +0000802 toAsm << "\n";
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000803}
804
Chris Lattner7446dc02004-01-13 21:27:59 +0000805FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out,
806 const TargetMachine &TM) {
Brian Gaekee3d68072004-02-25 18:44:15 +0000807 return new SparcV9AsmPrinter(Out, TM);
Chris Lattnerc019a172002-02-03 07:48:06 +0000808}