2005-07-01 22:44:09 +00:00
|
|
|
//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-25 22:55:53 +00:00
|
|
|
//
|
2005-07-01 22:44:09 +00:00
|
|
|
// This file the shared super class printer that converts from our internal
|
|
|
|
// representation of machine-dependent LLVM code to Intel and AT&T format
|
|
|
|
// assembly language.
|
|
|
|
// This printer is the output mechanism used by `llc'.
|
2002-10-25 22:55:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-03-13 23:20:37 +00:00
|
|
|
#include "X86AsmPrinter.h"
|
2005-07-01 22:44:09 +00:00
|
|
|
#include "X86ATTAsmPrinter.h"
|
2007-01-16 16:41:57 +00:00
|
|
|
#include "X86COFF.h"
|
2005-07-01 22:44:09 +00:00
|
|
|
#include "X86IntelAsmPrinter.h"
|
2006-09-20 22:03:51 +00:00
|
|
|
#include "X86MachineFunctionInfo.h"
|
2005-11-21 22:39:40 +00:00
|
|
|
#include "X86Subtarget.h"
|
2006-09-20 22:03:51 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/CallingConv.h"
|
2005-12-13 04:53:51 +00:00
|
|
|
#include "llvm/Constants.h"
|
2003-08-11 20:06:16 +00:00
|
|
|
#include "llvm/Module.h"
|
2007-03-31 13:11:52 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2008-01-20 14:00:07 +00:00
|
|
|
#include "llvm/ParameterAttributes.h"
|
2005-11-21 06:46:22 +00:00
|
|
|
#include "llvm/Type.h"
|
2003-08-11 20:06:16 +00:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2003-07-24 20:20:44 +00:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2006-09-07 22:06:40 +00:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2007-01-17 10:33:08 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2004-02-14 06:00:36 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2007-04-17 17:21:52 +00:00
|
|
|
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
|
|
|
|
const TargetData *TD) {
|
|
|
|
X86MachineFunctionInfo Info;
|
2006-09-26 03:57:53 +00:00
|
|
|
uint64_t Size = 0;
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2006-09-20 22:03:51 +00:00
|
|
|
switch (F->getCallingConv()) {
|
2006-09-26 03:57:53 +00:00
|
|
|
case CallingConv::X86_StdCall:
|
2006-09-20 22:03:51 +00:00
|
|
|
Info.setDecorationStyle(StdCall);
|
|
|
|
break;
|
2006-09-26 03:57:53 +00:00
|
|
|
case CallingConv::X86_FastCall:
|
2006-09-20 22:03:51 +00:00
|
|
|
Info.setDecorationStyle(FastCall);
|
|
|
|
break;
|
2006-09-26 03:57:53 +00:00
|
|
|
default:
|
2006-09-20 22:03:51 +00:00
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
2008-01-20 14:00:07 +00:00
|
|
|
unsigned argNum = 1;
|
2006-09-26 03:57:53 +00:00
|
|
|
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
|
2008-01-20 14:00:07 +00:00
|
|
|
AI != AE; ++AI, ++argNum) {
|
|
|
|
const Type* Ty = AI->getType();
|
|
|
|
|
|
|
|
// 'Dereference' type in case of byval parameter attribute
|
|
|
|
if (F->paramHasAttr(argNum, ParamAttr::ByVal))
|
|
|
|
Ty = cast<PointerType>(Ty)->getElementType();
|
|
|
|
|
2007-03-01 16:29:22 +00:00
|
|
|
// Size should be aligned to DWORD boundary
|
2008-01-20 14:00:07 +00:00
|
|
|
Size += ((TD->getABITypeSize(Ty) + 3)/4)*4;
|
|
|
|
}
|
|
|
|
|
2006-09-20 22:03:51 +00:00
|
|
|
// We're not supporting tooooo huge arguments :)
|
2006-09-26 03:57:53 +00:00
|
|
|
Info.setBytesToPopOnReturn((unsigned int)Size);
|
2006-09-20 22:03:51 +00:00
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-26 03:57:53 +00:00
|
|
|
/// decorateName - Query FunctionInfoMap and use this information for various
|
|
|
|
/// name decoration.
|
|
|
|
void X86SharedAsmPrinter::decorateName(std::string &Name,
|
|
|
|
const GlobalValue *GV) {
|
|
|
|
const Function *F = dyn_cast<Function>(GV);
|
|
|
|
if (!F) return;
|
2006-09-20 22:03:51 +00:00
|
|
|
|
|
|
|
// We don't want to decorate non-stdcall or non-fastcall functions right now
|
2006-09-26 03:57:53 +00:00
|
|
|
unsigned CC = F->getCallingConv();
|
|
|
|
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
2006-09-20 22:03:51 +00:00
|
|
|
return;
|
2007-01-28 13:31:35 +00:00
|
|
|
|
|
|
|
// Decorate names only when we're targeting Cygwin/Mingw32 targets
|
|
|
|
if (!Subtarget->isTargetCygMing())
|
|
|
|
return;
|
2006-09-20 22:03:51 +00:00
|
|
|
|
|
|
|
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
|
|
|
|
2007-04-17 17:21:52 +00:00
|
|
|
const X86MachineFunctionInfo *Info;
|
2006-09-20 22:03:51 +00:00
|
|
|
if (info_item == FunctionInfoMap.end()) {
|
|
|
|
// Calculate apropriate function info and populate map
|
|
|
|
FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
|
|
|
|
Info = &FunctionInfoMap[F];
|
|
|
|
} else {
|
2006-09-26 03:57:53 +00:00
|
|
|
Info = &info_item->second;
|
2006-09-20 22:03:51 +00:00
|
|
|
}
|
2007-03-31 13:11:52 +00:00
|
|
|
|
|
|
|
const FunctionType *FT = F->getFunctionType();
|
2006-09-20 22:03:51 +00:00
|
|
|
switch (Info->getDecorationStyle()) {
|
2006-09-26 03:57:53 +00:00
|
|
|
case None:
|
2006-09-20 22:03:51 +00:00
|
|
|
break;
|
2006-09-26 03:57:53 +00:00
|
|
|
case StdCall:
|
2007-03-31 13:11:52 +00:00
|
|
|
// "Pure" variadic functions do not receive @0 suffix.
|
|
|
|
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
2008-03-03 21:46:28 +00:00
|
|
|
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
2006-09-20 22:03:51 +00:00
|
|
|
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
|
|
|
break;
|
2006-09-26 03:57:53 +00:00
|
|
|
case FastCall:
|
2007-03-31 13:11:52 +00:00
|
|
|
// "Pure" variadic functions do not receive @0 suffix.
|
|
|
|
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
2008-03-03 21:46:28 +00:00
|
|
|
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
2006-09-20 22:03:51 +00:00
|
|
|
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
2006-09-26 03:57:53 +00:00
|
|
|
|
2006-09-20 22:03:51 +00:00
|
|
|
if (Name[0] == '_') {
|
|
|
|
Name[0] = '@';
|
|
|
|
} else {
|
|
|
|
Name = '@' + Name;
|
|
|
|
}
|
|
|
|
break;
|
2006-09-26 03:57:53 +00:00
|
|
|
default:
|
2006-09-20 22:03:51 +00:00
|
|
|
assert(0 && "Unsupported DecorationStyle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-06 18:34:40 +00:00
|
|
|
/// doInitialization
|
2006-09-08 06:48:29 +00:00
|
|
|
bool X86SharedAsmPrinter::doInitialization(Module &M) {
|
2007-05-05 09:04:50 +00:00
|
|
|
if (TAI->doesSupportDebugInformation()) {
|
2006-03-07 02:23:26 +00:00
|
|
|
// Emit initial debug information.
|
2006-03-23 18:09:44 +00:00
|
|
|
DW.BeginModule(&M);
|
2006-03-07 02:23:26 +00:00
|
|
|
}
|
2006-03-07 02:02:57 +00:00
|
|
|
|
2007-07-25 19:33:14 +00:00
|
|
|
bool Result = AsmPrinter::doInitialization(M);
|
2007-06-22 00:54:56 +00:00
|
|
|
|
|
|
|
// Darwin wants symbols to be quoted if they have complex names.
|
|
|
|
if (Subtarget->isTargetDarwin())
|
|
|
|
Mang->setUseQuotes(true);
|
|
|
|
|
2007-07-25 19:33:14 +00:00
|
|
|
return Result;
|
2005-01-23 03:52:14 +00:00
|
|
|
}
|
|
|
|
|
2008-02-15 19:04:54 +00:00
|
|
|
/// PrintUnmangledNameSafely - Print out the printable characters in the name.
|
2008-02-15 18:56:05 +00:00
|
|
|
/// Don't print things like \n or \0.
|
2008-02-15 19:04:54 +00:00
|
|
|
static void PrintUnmangledNameSafely(const Value *V, std::ostream &OS) {
|
2008-02-15 18:56:05 +00:00
|
|
|
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
|
|
|
|
Name != E; ++Name)
|
|
|
|
if (isprint(*Name))
|
|
|
|
OS << *Name;
|
|
|
|
}
|
|
|
|
|
2004-10-04 07:24:48 +00:00
|
|
|
bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
2006-05-06 21:27:14 +00:00
|
|
|
// Note: this code is not shared by the Intel printer as it is too different
|
|
|
|
// from how MASM does things. When making changes here don't forget to look
|
|
|
|
// at X86IntelAsmPrinter::doFinalization().
|
2006-05-03 01:29:57 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2006-12-01 00:25:12 +00:00
|
|
|
|
2004-10-04 07:24:48 +00:00
|
|
|
// Print out module-level global variables here.
|
2006-02-07 08:38:37 +00:00
|
|
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ++I) {
|
2006-12-09 23:14:08 +00:00
|
|
|
if (!I->hasInitializer())
|
2006-12-01 00:25:12 +00:00
|
|
|
continue; // External global require no code
|
2005-11-21 22:48:18 +00:00
|
|
|
|
2005-12-13 06:32:50 +00:00
|
|
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
2007-01-30 08:04:53 +00:00
|
|
|
if (EmitSpecialLLVMGlobal(I)) {
|
|
|
|
if (Subtarget->isTargetDarwin() &&
|
|
|
|
TM.getRelocationModel() == Reloc::Static) {
|
|
|
|
if (I->getName() == "llvm.global_ctors")
|
|
|
|
O << ".reference .constructors_used\n";
|
|
|
|
else if (I->getName() == "llvm.global_dtors")
|
|
|
|
O << ".reference .destructors_used\n";
|
|
|
|
}
|
2005-12-13 06:32:50 +00:00
|
|
|
continue;
|
2007-01-30 08:04:53 +00:00
|
|
|
}
|
2005-12-13 04:53:51 +00:00
|
|
|
|
2005-11-21 22:48:18 +00:00
|
|
|
std::string name = Mang->getValueName(I);
|
|
|
|
Constant *C = I->getInitializer();
|
2007-03-08 01:07:07 +00:00
|
|
|
const Type *Type = C->getType();
|
2007-11-05 00:04:43 +00:00
|
|
|
unsigned Size = TD->getABITypeSize(Type);
|
2006-10-24 20:32:14 +00:00
|
|
|
unsigned Align = TD->getPreferredAlignmentLog(I);
|
2005-07-27 06:12:32 +00:00
|
|
|
|
2007-04-29 18:35:00 +00:00
|
|
|
if (I->hasHiddenVisibility()) {
|
2007-01-17 17:44:25 +00:00
|
|
|
if (const char *Directive = TAI->getHiddenDirective())
|
|
|
|
O << Directive << name << "\n";
|
2007-04-29 18:35:00 +00:00
|
|
|
} else if (I->hasProtectedVisibility()) {
|
|
|
|
if (const char *Directive = TAI->getProtectedDirective())
|
|
|
|
O << Directive << name << "\n";
|
|
|
|
}
|
|
|
|
|
2007-01-17 17:44:25 +00:00
|
|
|
if (Subtarget->isTargetELF())
|
2007-07-30 15:08:02 +00:00
|
|
|
O << "\t.type\t" << name << ",@object\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
|
2007-09-21 00:41:19 +00:00
|
|
|
if (C->isNullValue() && !I->hasSection()) {
|
2006-02-15 01:56:23 +00:00
|
|
|
if (I->hasExternalLinkage()) {
|
2007-01-17 17:44:25 +00:00
|
|
|
if (const char *Directive = TAI->getZeroFillDirective()) {
|
2008-01-11 00:54:37 +00:00
|
|
|
O << "\t.globl " << name << "\n";
|
2008-02-12 23:35:09 +00:00
|
|
|
O << Directive << "__DATA, __common, " << name << ", "
|
2007-01-18 02:30:19 +00:00
|
|
|
<< Size << ", " << Align << "\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-21 00:41:19 +00:00
|
|
|
if (!I->isThreadLocal() &&
|
2008-01-17 23:04:07 +00:00
|
|
|
(I->hasInternalLinkage() || I->hasWeakLinkage() ||
|
2008-05-14 20:12:51 +00:00
|
|
|
I->hasLinkOnceLinkage() || I->hasCommonLinkage())) {
|
2007-01-17 17:44:25 +00:00
|
|
|
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
2007-01-17 10:33:08 +00:00
|
|
|
if (!NoZerosInBSS && TAI->getBSSSection())
|
|
|
|
SwitchToDataSection(TAI->getBSSSection(), I);
|
|
|
|
else
|
|
|
|
SwitchToDataSection(TAI->getDataSection(), I);
|
2006-09-06 18:34:40 +00:00
|
|
|
if (TAI->getLCOMMDirective() != NULL) {
|
2006-02-15 01:56:23 +00:00
|
|
|
if (I->hasInternalLinkage()) {
|
2006-09-06 18:34:40 +00:00
|
|
|
O << TAI->getLCOMMDirective() << name << "," << Size;
|
2006-07-27 02:05:13 +00:00
|
|
|
if (Subtarget->isTargetDarwin())
|
2007-01-18 01:49:58 +00:00
|
|
|
O << "," << Align;
|
2008-05-16 00:52:06 +00:00
|
|
|
} else if (Subtarget->isTargetDarwin() && !I->hasCommonLinkage()) {
|
|
|
|
O << "\t.globl " << name << "\n"
|
|
|
|
<< TAI->getWeakDefDirective() << name << "\n";
|
|
|
|
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
|
|
|
|
EmitAlignment(Align, I);
|
|
|
|
O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
|
|
|
|
PrintUnmangledNameSafely(I, O);
|
|
|
|
O << "\n";
|
|
|
|
EmitGlobalConstant(C);
|
|
|
|
continue;
|
2008-01-02 19:44:55 +00:00
|
|
|
} else {
|
2006-09-06 18:34:40 +00:00
|
|
|
O << TAI->getCOMMDirective() << name << "," << Size;
|
2008-01-02 19:44:55 +00:00
|
|
|
|
|
|
|
// Leopard and above support aligned common symbols.
|
|
|
|
if (Subtarget->getDarwinVers() >= 9)
|
|
|
|
O << "," << Align;
|
|
|
|
}
|
2006-02-15 01:56:23 +00:00
|
|
|
} else {
|
2007-01-03 11:43:14 +00:00
|
|
|
if (!Subtarget->isTargetCygMing()) {
|
2006-05-25 21:59:08 +00:00
|
|
|
if (I->hasInternalLinkage())
|
|
|
|
O << "\t.local\t" << name << "\n";
|
|
|
|
}
|
2006-09-06 18:34:40 +00:00
|
|
|
O << TAI->getCOMMDirective() << name << "," << Size;
|
|
|
|
if (TAI->getCOMMDirectiveTakesAlignment())
|
|
|
|
O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
|
2006-02-15 01:56:23 +00:00
|
|
|
}
|
2008-02-15 18:56:05 +00:00
|
|
|
O << "\t\t" << TAI->getCommentString() << " ";
|
2008-02-15 19:04:54 +00:00
|
|
|
PrintUnmangledNameSafely(I, O);
|
2008-02-15 18:56:05 +00:00
|
|
|
O << "\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
continue;
|
2006-02-07 08:38:37 +00:00
|
|
|
}
|
2007-01-17 17:44:25 +00:00
|
|
|
}
|
2006-10-31 01:26:55 +00:00
|
|
|
|
2007-01-17 17:44:25 +00:00
|
|
|
switch (I->getLinkage()) {
|
2008-05-14 20:12:51 +00:00
|
|
|
case GlobalValue::CommonLinkage:
|
2007-01-17 17:44:25 +00:00
|
|
|
case GlobalValue::LinkOnceLinkage:
|
|
|
|
case GlobalValue::WeakLinkage:
|
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2008-01-11 00:54:37 +00:00
|
|
|
O << "\t.globl " << name << "\n"
|
2007-11-20 23:24:42 +00:00
|
|
|
<< TAI->getWeakDefDirective() << name << "\n";
|
2008-05-23 00:16:59 +00:00
|
|
|
if (!I->isConstant())
|
|
|
|
SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
|
|
|
|
else {
|
|
|
|
const ArrayType *AT = dyn_cast<ArrayType>(Type);
|
|
|
|
if (AT && AT->getElementType()==Type::Int8Ty)
|
|
|
|
SwitchToDataSection("\t.section __TEXT,__const_coal,coalesced", I);
|
|
|
|
else
|
|
|
|
SwitchToDataSection("\t.section __DATA,__const_coal,coalesced", I);
|
|
|
|
}
|
2007-01-17 17:44:25 +00:00
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
|
|
|
std::string SectionName(".section\t.data$linkonce." +
|
|
|
|
name +
|
|
|
|
",\"aw\"");
|
|
|
|
SwitchToDataSection(SectionName.c_str(), I);
|
2007-10-05 15:58:41 +00:00
|
|
|
O << "\t.globl\t" << name << "\n"
|
2007-01-17 17:44:25 +00:00
|
|
|
<< "\t.linkonce same_size\n";
|
|
|
|
} else {
|
|
|
|
std::string SectionName("\t.section\t.llvm.linkonce.d." +
|
|
|
|
name +
|
|
|
|
",\"aw\",@progbits");
|
|
|
|
SwitchToDataSection(SectionName.c_str(), I);
|
2007-07-30 15:08:02 +00:00
|
|
|
O << "\t.weak\t" << name << "\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GlobalValue::DLLExportLinkage:
|
|
|
|
DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
|
|
|
|
// FALL THROUGH
|
2007-08-13 18:42:37 +00:00
|
|
|
case GlobalValue::AppendingLinkage:
|
|
|
|
// FIXME: appending linkage variables should go into a section of
|
|
|
|
// their name or something. For now, just emit them as external.
|
2007-01-17 17:44:25 +00:00
|
|
|
case GlobalValue::ExternalLinkage:
|
|
|
|
// If external or appending, declare as a global symbol
|
2008-01-11 00:54:37 +00:00
|
|
|
O << "\t.globl " << name << "\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
// FALL THROUGH
|
|
|
|
case GlobalValue::InternalLinkage: {
|
|
|
|
if (I->isConstant()) {
|
|
|
|
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
|
|
|
if (TAI->getCStringSection() && CVA && CVA->isCString()) {
|
|
|
|
SwitchToDataSection(TAI->getCStringSection(), I);
|
|
|
|
break;
|
2006-10-31 01:26:55 +00:00
|
|
|
}
|
2006-10-26 19:18:18 +00:00
|
|
|
}
|
2007-01-17 17:44:25 +00:00
|
|
|
// FIXME: special handling for ".ctors" & ".dtors" sections
|
|
|
|
if (I->hasSection() &&
|
|
|
|
(I->getSection() == ".ctors" ||
|
|
|
|
I->getSection() == ".dtors")) {
|
|
|
|
std::string SectionName = ".section " + I->getSection();
|
|
|
|
|
|
|
|
if (Subtarget->isTargetCygMing()) {
|
|
|
|
SectionName += ",\"aw\"";
|
|
|
|
} else {
|
|
|
|
assert(!Subtarget->isTargetDarwin());
|
|
|
|
SectionName += ",\"aw\",@progbits";
|
|
|
|
}
|
2008-01-23 00:58:14 +00:00
|
|
|
SwitchToDataSection(SectionName.c_str());
|
|
|
|
} else if (I->hasSection() && Subtarget->isTargetDarwin()) {
|
|
|
|
// Honor all section names on Darwin; ObjC uses this
|
|
|
|
std::string SectionName = ".section " + I->getSection();
|
2007-01-17 17:44:25 +00:00
|
|
|
SwitchToDataSection(SectionName.c_str());
|
|
|
|
} else {
|
|
|
|
if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
|
2007-04-20 21:38:10 +00:00
|
|
|
SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSBSSSection() :
|
|
|
|
TAI->getBSSSection(), I);
|
2007-03-08 01:07:07 +00:00
|
|
|
else if (!I->isConstant())
|
2007-04-20 21:38:10 +00:00
|
|
|
SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSDataSection() :
|
|
|
|
TAI->getDataSection(), I);
|
|
|
|
else if (I->isThreadLocal())
|
|
|
|
SwitchToDataSection(TAI->getTLSDataSection());
|
2007-03-08 01:07:07 +00:00
|
|
|
else {
|
|
|
|
// Read-only data.
|
2007-03-08 08:31:54 +00:00
|
|
|
bool HasReloc = C->ContainsRelocations();
|
|
|
|
if (HasReloc &&
|
|
|
|
Subtarget->isTargetDarwin() &&
|
2007-03-08 01:07:07 +00:00
|
|
|
TM.getRelocationModel() != Reloc::Static)
|
|
|
|
SwitchToDataSection("\t.const_data\n");
|
2007-03-08 08:31:54 +00:00
|
|
|
else if (!HasReloc && Size == 4 &&
|
2007-03-08 01:07:07 +00:00
|
|
|
TAI->getFourByteConstantSection())
|
|
|
|
SwitchToDataSection(TAI->getFourByteConstantSection(), I);
|
2007-03-08 08:31:54 +00:00
|
|
|
else if (!HasReloc && Size == 8 &&
|
2007-03-08 01:07:07 +00:00
|
|
|
TAI->getEightByteConstantSection())
|
|
|
|
SwitchToDataSection(TAI->getEightByteConstantSection(), I);
|
2007-03-08 08:31:54 +00:00
|
|
|
else if (!HasReloc && Size == 16 &&
|
2007-03-08 01:07:07 +00:00
|
|
|
TAI->getSixteenByteConstantSection())
|
|
|
|
SwitchToDataSection(TAI->getSixteenByteConstantSection(), I);
|
|
|
|
else if (TAI->getReadOnlySection())
|
|
|
|
SwitchToDataSection(TAI->getReadOnlySection(), I);
|
|
|
|
else
|
|
|
|
SwitchToDataSection(TAI->getDataSection(), I);
|
|
|
|
}
|
2005-11-21 19:50:31 +00:00
|
|
|
}
|
2007-01-17 17:44:25 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown linkage type!");
|
|
|
|
}
|
2005-11-21 19:50:31 +00:00
|
|
|
|
2007-01-17 17:44:25 +00:00
|
|
|
EmitAlignment(Align, I);
|
2008-02-15 18:56:05 +00:00
|
|
|
O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
|
2008-02-15 19:04:54 +00:00
|
|
|
PrintUnmangledNameSafely(I, O);
|
2008-02-15 18:56:05 +00:00
|
|
|
O << "\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
if (TAI->hasDotTypeDotSizeDirective())
|
2007-07-30 15:08:02 +00:00
|
|
|
O << "\t.size\t" << name << ", " << Size << "\n";
|
2007-01-17 17:44:25 +00:00
|
|
|
// If the initializer is a extern weak symbol, remember to emit the weak
|
|
|
|
// reference!
|
|
|
|
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
|
|
|
if (GV->hasExternalWeakLinkage())
|
|
|
|
ExtWeakSymbols.insert(GV);
|
2006-12-01 09:13:26 +00:00
|
|
|
|
2007-01-17 17:44:25 +00:00
|
|
|
EmitGlobalConstant(C);
|
2005-11-21 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 18:23:27 +00:00
|
|
|
// Output linker support code for dllexported globals
|
2007-10-03 19:26:29 +00:00
|
|
|
if (!DLLExportedGVs.empty()) {
|
2006-10-31 08:31:24 +00:00
|
|
|
SwitchToDataSection(".section .drectve");
|
2006-09-14 18:23:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-27 21:22:49 +00:00
|
|
|
for (StringSet<>::iterator i = DLLExportedGVs.begin(),
|
2006-09-14 18:23:27 +00:00
|
|
|
e = DLLExportedGVs.end();
|
|
|
|
i != e; ++i) {
|
2008-06-27 21:22:49 +00:00
|
|
|
O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
|
|
|
|
}
|
2006-09-14 18:23:27 +00:00
|
|
|
|
2007-10-03 19:26:29 +00:00
|
|
|
if (!DLLExportedFns.empty()) {
|
2006-10-31 08:31:24 +00:00
|
|
|
SwitchToDataSection(".section .drectve");
|
2006-09-14 18:23:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-27 21:22:49 +00:00
|
|
|
for (StringSet<>::iterator i = DLLExportedFns.begin(),
|
2006-09-14 18:23:27 +00:00
|
|
|
e = DLLExportedFns.end();
|
|
|
|
i != e; ++i) {
|
2008-06-27 21:22:49 +00:00
|
|
|
O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
|
|
|
|
}
|
2006-12-01 00:25:12 +00:00
|
|
|
|
2006-07-27 02:05:13 +00:00
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2006-10-31 08:31:24 +00:00
|
|
|
SwitchToDataSection("");
|
2005-07-12 01:37:28 +00:00
|
|
|
|
2005-07-08 00:23:26 +00:00
|
|
|
// Output stubs for dynamically-linked functions
|
|
|
|
unsigned j = 1;
|
2008-06-27 21:22:49 +00:00
|
|
|
for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
2005-07-11 06:25:47 +00:00
|
|
|
i != e; ++i, ++j) {
|
2008-01-11 00:54:37 +00:00
|
|
|
SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
|
2006-05-09 04:59:56 +00:00
|
|
|
"self_modifying_code+pure_instructions,5", 0);
|
2008-06-27 21:22:49 +00:00
|
|
|
std::string p = i->getKeyData();
|
2008-05-19 21:38:18 +00:00
|
|
|
printSuffixedName(p, "$stub");
|
|
|
|
O << ":\n";
|
|
|
|
O << "\t.indirect_symbol " << p << "\n";
|
2006-02-07 08:38:37 +00:00
|
|
|
O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
|
2005-07-08 00:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
O << "\n";
|
2005-07-27 06:12:32 +00:00
|
|
|
|
2008-04-02 00:25:04 +00:00
|
|
|
if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
|
2007-09-11 08:27:17 +00:00
|
|
|
// Add the (possibly multiple) personalities to the set of global values.
|
2008-04-02 00:25:04 +00:00
|
|
|
// Only referenced functions get into the Personalities list.
|
2007-09-11 08:27:17 +00:00
|
|
|
const std::vector<Function *>& Personalities = MMI->getPersonalities();
|
|
|
|
|
|
|
|
for (std::vector<Function *>::const_iterator I = Personalities.begin(),
|
|
|
|
E = Personalities.end(); I != E; ++I)
|
|
|
|
if (*I) GVStubs.insert("_" + (*I)->getName());
|
|
|
|
}
|
|
|
|
|
2006-02-07 08:38:37 +00:00
|
|
|
// Output stubs for external and common global variables.
|
2007-10-03 19:26:29 +00:00
|
|
|
if (!GVStubs.empty())
|
2006-05-09 04:59:56 +00:00
|
|
|
SwitchToDataSection(
|
2008-01-11 00:54:37 +00:00
|
|
|
"\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
|
2008-06-27 21:22:49 +00:00
|
|
|
for (StringSet<>::iterator i = GVStubs.begin(), e = GVStubs.end();
|
2006-02-07 08:38:37 +00:00
|
|
|
i != e; ++i) {
|
2008-06-27 21:22:49 +00:00
|
|
|
std::string p = i->getKeyData();
|
2008-05-19 21:38:18 +00:00
|
|
|
printSuffixedName(p, "$non_lazy_ptr");
|
|
|
|
O << ":\n";
|
|
|
|
O << "\t.indirect_symbol " << p << "\n";
|
2006-02-07 08:38:37 +00:00
|
|
|
O << "\t.long\t0\n";
|
2005-07-08 00:23:26 +00:00
|
|
|
}
|
2004-10-04 07:24:48 +00:00
|
|
|
|
2006-10-30 22:32:30 +00:00
|
|
|
// Emit final debug information.
|
2006-03-23 18:09:44 +00:00
|
|
|
DW.EndModule();
|
2006-03-07 02:23:26 +00:00
|
|
|
|
|
|
|
// Funny Darwin hack: This flag tells the linker that no global symbols
|
|
|
|
// contain code that falls through to other global symbols (e.g. the obvious
|
|
|
|
// implementation of multiple entry points). If this doesn't occur, the
|
2006-03-23 18:09:44 +00:00
|
|
|
// linker can safely perform dead code stripping. Since LLVM never
|
|
|
|
// generates code that does this, it is always safe to set.
|
2006-03-07 02:23:26 +00:00
|
|
|
O << "\t.subsections_via_symbols\n";
|
2007-01-16 16:41:57 +00:00
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
|
|
|
// Emit type information for external functions
|
2008-06-27 21:22:49 +00:00
|
|
|
for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
2007-01-16 16:41:57 +00:00
|
|
|
i != e; ++i) {
|
2008-06-27 21:22:49 +00:00
|
|
|
O << "\t.def\t " << i->getKeyData()
|
2007-01-16 16:41:57 +00:00
|
|
|
<< ";\t.scl\t" << COFF::C_EXT
|
|
|
|
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
|
|
|
|
<< ";\t.endef\n";
|
|
|
|
}
|
2008-06-27 21:22:49 +00:00
|
|
|
|
2007-01-16 16:41:57 +00:00
|
|
|
// Emit final debug information.
|
2008-06-27 21:22:49 +00:00
|
|
|
DW.EndModule();
|
2007-01-16 16:41:57 +00:00
|
|
|
} else if (Subtarget->isTargetELF()) {
|
2006-10-30 22:32:30 +00:00
|
|
|
// Emit final debug information.
|
|
|
|
DW.EndModule();
|
2006-03-07 02:23:26 +00:00
|
|
|
}
|
2006-03-07 02:02:57 +00:00
|
|
|
|
2007-07-25 19:33:14 +00:00
|
|
|
return AsmPrinter::doFinalization(M);
|
2004-10-04 07:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
|
|
|
|
/// for a MachineFunction to the given output stream, using the given target
|
|
|
|
/// machine description.
|
|
|
|
///
|
2006-03-13 23:20:37 +00:00
|
|
|
FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
|
2006-09-06 18:34:40 +00:00
|
|
|
X86TargetMachine &tm) {
|
2006-09-07 12:23:47 +00:00
|
|
|
const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>();
|
2006-09-06 18:34:40 +00:00
|
|
|
|
2006-09-07 12:23:47 +00:00
|
|
|
if (Subtarget->isFlavorIntel()) {
|
2006-09-07 22:06:40 +00:00
|
|
|
return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo());
|
2006-09-07 12:23:47 +00:00
|
|
|
} else {
|
2006-09-07 22:06:40 +00:00
|
|
|
return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo());
|
2004-10-04 07:24:48 +00:00
|
|
|
}
|
2003-06-19 19:32:32 +00:00
|
|
|
}
|