2007-06-25 15:11:25 +00:00
|
|
|
//===-- X86ATTAsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly -----===//
|
2005-07-01 22:44:09 +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-07-01 22:44:09 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to AT&T format assembly
|
|
|
|
// language. This printer is the output mechanism used by `llc'.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
2005-07-01 22:44:09 +00:00
|
|
|
#include "X86ATTAsmPrinter.h"
|
2008-08-24 12:30:46 +00:00
|
|
|
#include "X86.h"
|
|
|
|
#include "X86COFF.h"
|
|
|
|
#include "X86MachineFunctionInfo.h"
|
|
|
|
#include "X86TargetMachine.h"
|
|
|
|
#include "X86TargetAsmInfo.h"
|
2006-09-20 22:03:51 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2008-06-28 11:08:27 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2005-07-01 22:44:09 +00:00
|
|
|
#include "llvm/Module.h"
|
2008-06-28 11:08:27 +00:00
|
|
|
#include "llvm/Type.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-02-18 23:12:06 +00:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2008-06-28 11:08:27 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2005-07-01 22:44:09 +00:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2008-08-21 00:14:44 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-09-07 22:06:40 +00:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2006-02-18 00:15:05 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2005-07-01 22:44:09 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
|
|
|
|
2008-01-05 00:41:47 +00:00
|
|
|
static std::string getPICLabelString(unsigned FnNum,
|
|
|
|
const TargetAsmInfo *TAI,
|
|
|
|
const X86Subtarget* Subtarget) {
|
2007-01-12 19:20:47 +00:00
|
|
|
std::string label;
|
2007-01-18 01:49:58 +00:00
|
|
|
if (Subtarget->isTargetDarwin())
|
2007-10-14 05:57:21 +00:00
|
|
|
label = "\"L" + utostr_32(FnNum) + "$pb\"";
|
2007-01-18 01:49:58 +00:00
|
|
|
else if (Subtarget->isTargetELF())
|
2008-06-30 22:03:41 +00:00
|
|
|
label = ".Lllvm$" + utostr_32(FnNum) + "." "$piclabel";
|
2007-01-18 01:49:58 +00:00
|
|
|
else
|
2007-01-12 19:20:47 +00:00
|
|
|
assert(0 && "Don't know how to print PIC label!\n");
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
|
|
|
|
const TargetData *TD) {
|
|
|
|
X86MachineFunctionInfo Info;
|
|
|
|
uint64_t Size = 0;
|
|
|
|
|
|
|
|
switch (F->getCallingConv()) {
|
|
|
|
case CallingConv::X86_StdCall:
|
|
|
|
Info.setDecorationStyle(StdCall);
|
|
|
|
break;
|
|
|
|
case CallingConv::X86_FastCall:
|
|
|
|
Info.setDecorationStyle(FastCall);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned argNum = 1;
|
|
|
|
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
|
|
|
|
AI != AE; ++AI, ++argNum) {
|
|
|
|
const Type* Ty = AI->getType();
|
|
|
|
|
|
|
|
// 'Dereference' type in case of byval parameter attribute
|
2008-09-25 21:00:45 +00:00
|
|
|
if (F->paramHasAttr(argNum, Attribute::ByVal))
|
2008-06-28 11:08:27 +00:00
|
|
|
Ty = cast<PointerType>(Ty)->getElementType();
|
|
|
|
|
|
|
|
// Size should be aligned to DWORD boundary
|
2009-05-09 07:06:46 +00:00
|
|
|
Size += ((TD->getTypeAllocSize(Ty) + 3)/4)*4;
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We're not supporting tooooo huge arguments :)
|
|
|
|
Info.setBytesToPopOnReturn((unsigned int)Size);
|
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PrintUnmangledNameSafely - Print out the printable characters in the name.
|
2009-03-03 02:55:14 +00:00
|
|
|
/// Don't print things like \\n or \\0.
|
2008-08-21 00:14:44 +00:00
|
|
|
static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
|
2008-06-28 11:08:27 +00:00
|
|
|
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
|
|
|
|
Name != E; ++Name)
|
|
|
|
if (isprint(*Name))
|
|
|
|
OS << *Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// decorateName - Query FunctionInfoMap and use this information for various
|
|
|
|
/// name decoration.
|
|
|
|
void X86ATTAsmPrinter::decorateName(std::string &Name,
|
|
|
|
const GlobalValue *GV) {
|
|
|
|
const Function *F = dyn_cast<Function>(GV);
|
|
|
|
if (!F) return;
|
|
|
|
|
|
|
|
// We don't want to decorate non-stdcall or non-fastcall functions right now
|
|
|
|
unsigned CC = F->getCallingConv();
|
|
|
|
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Decorate names only when we're targeting Cygwin/Mingw32 targets
|
|
|
|
if (!Subtarget->isTargetCygMing())
|
|
|
|
return;
|
|
|
|
|
|
|
|
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
|
|
|
|
|
|
|
const X86MachineFunctionInfo *Info;
|
|
|
|
if (info_item == FunctionInfoMap.end()) {
|
|
|
|
// Calculate apropriate function info and populate map
|
|
|
|
FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
|
|
|
|
Info = &FunctionInfoMap[F];
|
|
|
|
} else {
|
|
|
|
Info = &info_item->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionType *FT = F->getFunctionType();
|
|
|
|
switch (Info->getDecorationStyle()) {
|
|
|
|
case None:
|
|
|
|
break;
|
|
|
|
case StdCall:
|
|
|
|
// "Pure" variadic functions do not receive @0 suffix.
|
|
|
|
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
|
|
|
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
|
|
|
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
|
|
|
break;
|
|
|
|
case FastCall:
|
|
|
|
// "Pure" variadic functions do not receive @0 suffix.
|
|
|
|
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
|
|
|
(FT->getNumParams() == 1 && F->hasStructRetAttr()))
|
|
|
|
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
|
|
|
|
|
|
|
if (Name[0] == '_') {
|
|
|
|
Name[0] = '@';
|
|
|
|
} else {
|
|
|
|
Name = '@' + Name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0 && "Unsupported DecorationStyle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:09:01 +00:00
|
|
|
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
2006-02-07 08:38:37 +00:00
|
|
|
const Function *F = MF.getFunction();
|
2006-09-20 22:03:51 +00:00
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
decorateName(CurrentFnName, F);
|
2006-09-20 22:03:51 +00:00
|
|
|
|
2008-09-24 22:14:23 +00:00
|
|
|
SwitchToSection(TAI->SectionForGlobal(F));
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2008-10-01 23:18:38 +00:00
|
|
|
unsigned FnAlign = 4;
|
2008-10-06 17:30:07 +00:00
|
|
|
if (F->hasFnAttr(Attribute::OptimizeForSize))
|
2008-09-04 21:03:41 +00:00
|
|
|
FnAlign = 1;
|
2006-02-07 08:38:37 +00:00
|
|
|
switch (F->getLinkage()) {
|
|
|
|
default: assert(0 && "Unknown linkage type!");
|
|
|
|
case Function::InternalLinkage: // Symbols default to internal.
|
2009-01-15 20:18:42 +00:00
|
|
|
case Function::PrivateLinkage:
|
2008-03-25 22:29:46 +00:00
|
|
|
EmitAlignment(FnAlign, F);
|
2006-02-07 08:38:37 +00:00
|
|
|
break;
|
2006-09-14 18:23:27 +00:00
|
|
|
case Function::DLLExportLinkage:
|
2006-02-07 08:38:37 +00:00
|
|
|
case Function::ExternalLinkage:
|
2008-03-25 22:29:46 +00:00
|
|
|
EmitAlignment(FnAlign, F);
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl\t" << CurrentFnName << '\n';
|
2006-02-07 08:38:37 +00:00
|
|
|
break;
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
case Function::LinkOnceAnyLinkage:
|
|
|
|
case Function::LinkOnceODRLinkage:
|
|
|
|
case Function::WeakAnyLinkage:
|
|
|
|
case Function::WeakODRLinkage:
|
2008-03-25 22:29:46 +00:00
|
|
|
EmitAlignment(FnAlign, F);
|
2006-07-27 02:05:13 +00:00
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl\t" << CurrentFnName << '\n';
|
|
|
|
O << TAI->getWeakDefDirective() << CurrentFnName << '\n';
|
2007-01-03 11:43:14 +00:00
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl\t" << CurrentFnName << "\n"
|
|
|
|
"\t.linkonce discard\n";
|
2006-10-17 20:29:49 +00:00
|
|
|
} else {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.weak\t" << CurrentFnName << '\n';
|
2006-10-17 20:29:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-02-07 08:38:37 +00:00
|
|
|
}
|
2008-08-08 18:25:07 +00:00
|
|
|
|
|
|
|
printVisibility(CurrentFnName, F->getVisibility());
|
2007-01-16 16:41:57 +00:00
|
|
|
|
|
|
|
if (Subtarget->isTargetELF())
|
2007-07-30 15:08:02 +00:00
|
|
|
O << "\t.type\t" << CurrentFnName << ",@function\n";
|
2007-01-16 16:41:57 +00:00
|
|
|
else if (Subtarget->isTargetCygMing()) {
|
|
|
|
O << "\t.def\t " << CurrentFnName
|
|
|
|
<< ";\t.scl\t" <<
|
2009-01-15 20:18:42 +00:00
|
|
|
(F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
|
2007-01-16 16:41:57 +00:00
|
|
|
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
|
|
|
|
<< ";\t.endef\n";
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
O << CurrentFnName << ":\n";
|
2006-10-18 09:12:29 +00:00
|
|
|
// Add some workaround for linkonce linkage on Cygwin\MinGW
|
2007-01-03 11:43:14 +00:00
|
|
|
if (Subtarget->isTargetCygMing() &&
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
(F->hasLinkOnceLinkage() || F->hasWeakLinkage()))
|
2007-01-12 19:20:47 +00:00
|
|
|
O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
|
2008-06-28 11:09:01 +00:00
|
|
|
}
|
2005-07-01 22:44:09 +00:00
|
|
|
|
2008-06-28 11:09:01 +00:00
|
|
|
/// runOnMachineFunction - This uses the printMachineInstruction()
|
|
|
|
/// method to print assembly for each instruction.
|
|
|
|
///
|
|
|
|
bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
const Function *F = MF.getFunction();
|
2009-02-06 21:45:08 +00:00
|
|
|
this->MF = &MF;
|
2008-06-28 11:09:01 +00:00
|
|
|
unsigned CC = F->getCallingConv();
|
|
|
|
|
|
|
|
SetupMachineFunction(MF);
|
|
|
|
O << "\n\n";
|
|
|
|
|
|
|
|
// Populate function information map. Actually, We don't want to populate
|
|
|
|
// non-stdcall or non-fastcall functions' information right now.
|
|
|
|
if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
|
|
|
|
FunctionInfoMap[F] = *MF.getInfo<X86MachineFunctionInfo>();
|
|
|
|
|
|
|
|
// Print out constants referenced by the function
|
|
|
|
EmitConstantPool(MF.getConstantPool());
|
|
|
|
|
|
|
|
if (F->hasDLLExportLinkage())
|
|
|
|
DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
|
|
|
|
|
|
|
|
// Print the 'header' of function
|
|
|
|
emitFunctionHeader(MF);
|
|
|
|
|
|
|
|
// Emit pre-function debug and/or EH information.
|
|
|
|
if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
|
2009-01-08 23:40:34 +00:00
|
|
|
DW->BeginFunction(&MF);
|
2008-06-28 11:09:01 +00:00
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// Print out code for the function.
|
2008-04-08 00:37:56 +00:00
|
|
|
bool hasAnyRealCode = false;
|
2005-07-01 22:44:09 +00:00
|
|
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
// Print a label for the basic block.
|
2009-03-31 18:39:13 +00:00
|
|
|
if (!VerboseAsm && (I->pred_empty() || I->isOnlyReachableByFallthrough())) {
|
|
|
|
// This is an entry block or a block that's only reachable via a
|
|
|
|
// fallthrough edge. In non-VerboseAsm mode, don't print the label.
|
|
|
|
} else {
|
2009-03-24 00:17:40 +00:00
|
|
|
printBasicBlockLabel(I, true, true, VerboseAsm);
|
2006-05-02 05:37:32 +00:00
|
|
|
O << '\n';
|
|
|
|
}
|
2008-01-26 09:03:52 +00:00
|
|
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
|
|
|
II != IE; ++II) {
|
2005-07-01 22:44:09 +00:00
|
|
|
// Print the assembly for the instruction.
|
2008-07-01 00:05:16 +00:00
|
|
|
if (!II->isLabel())
|
2008-04-08 00:37:56 +00:00
|
|
|
hasAnyRealCode = true;
|
2005-07-01 22:44:09 +00:00
|
|
|
printMachineInstruction(II);
|
|
|
|
}
|
|
|
|
}
|
2006-08-28 22:14:16 +00:00
|
|
|
|
2008-04-08 00:37:56 +00:00
|
|
|
if (Subtarget->isTargetDarwin() && !hasAnyRealCode) {
|
|
|
|
// If the function is empty, then we need to emit *something*. Otherwise,
|
|
|
|
// the function's label might be associated with something that it wasn't
|
|
|
|
// meant to be associated with. We emit a noop in this situation.
|
|
|
|
// We are assuming inline asms are code.
|
|
|
|
O << "\tnop\n";
|
|
|
|
}
|
|
|
|
|
2006-09-06 18:34:40 +00:00
|
|
|
if (TAI->hasDotTypeDotSizeDirective())
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
|
2005-07-01 22:44:09 +00:00
|
|
|
|
2008-06-28 11:09:01 +00:00
|
|
|
// Emit post-function debug information.
|
|
|
|
if (TAI->doesSupportDebugInformation())
|
2009-01-08 23:40:34 +00:00
|
|
|
DW->EndFunction(&MF);
|
2006-03-07 02:02:57 +00:00
|
|
|
|
2007-05-05 09:04:50 +00:00
|
|
|
// Print out jump tables referenced by the function.
|
|
|
|
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2008-11-07 19:49:17 +00:00
|
|
|
O.flush();
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-09 09:52:31 +00:00
|
|
|
static inline bool shouldPrintGOT(TargetMachine &TM, const X86Subtarget* ST) {
|
2007-01-18 22:27:12 +00:00
|
|
|
return ST->isPICStyleGOT() && TM.getRelocationModel() == Reloc::PIC_;
|
|
|
|
}
|
|
|
|
|
2008-06-09 09:52:31 +00:00
|
|
|
static inline bool shouldPrintPLT(TargetMachine &TM, const X86Subtarget* ST) {
|
|
|
|
return ST->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_ &&
|
|
|
|
(ST->isPICStyleRIPRel() || ST->isPICStyleGOT());
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool shouldPrintStub(TargetMachine &TM, const X86Subtarget* ST) {
|
2007-01-18 22:27:12 +00:00
|
|
|
return ST->isPICStyleStub() && TM.getRelocationModel() != Reloc::Static;
|
|
|
|
}
|
|
|
|
|
2006-02-06 23:41:19 +00:00
|
|
|
void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
2006-12-05 19:50:18 +00:00
|
|
|
const char *Modifier, bool NotRIPRel) {
|
2006-02-06 23:41:19 +00:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
2005-07-01 22:44:09 +00:00
|
|
|
switch (MO.getType()) {
|
2006-05-05 05:40:20 +00:00
|
|
|
case MachineOperand::MO_Register: {
|
2008-02-10 18:45:23 +00:00
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
|
2005-07-01 22:44:09 +00:00
|
|
|
"Virtual registers should not make it this far!");
|
|
|
|
O << '%';
|
2006-05-05 05:40:20 +00:00
|
|
|
unsigned Reg = MO.getReg();
|
2006-05-31 22:34:26 +00:00
|
|
|
if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = (strcmp(Modifier+6,"64") == 0) ?
|
2006-09-08 06:48:29 +00:00
|
|
|
MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
|
|
|
|
((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
|
2006-05-05 05:40:20 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, VT);
|
|
|
|
}
|
2008-07-07 22:21:06 +00:00
|
|
|
O << TRI->getAsmName(Reg);
|
2005-07-01 22:44:09 +00:00
|
|
|
return;
|
2006-05-05 05:40:20 +00:00
|
|
|
}
|
2005-07-01 22:44:09 +00:00
|
|
|
|
2006-05-04 17:21:20 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
2009-03-12 18:15:39 +00:00
|
|
|
if (!Modifier || (strcmp(Modifier, "debug") &&
|
|
|
|
strcmp(Modifier, "mem") &&
|
|
|
|
strcmp(Modifier, "call")))
|
2006-03-07 02:02:57 +00:00
|
|
|
O << '$';
|
2007-12-30 20:49:49 +00:00
|
|
|
O << MO.getImm();
|
2005-07-01 22:44:09 +00:00
|
|
|
return;
|
2006-04-22 18:53:45 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2009-03-24 00:17:40 +00:00
|
|
|
printBasicBlockLabel(MO.getMBB(), false, false, VerboseAsm);
|
2005-07-01 22:44:09 +00:00
|
|
|
return;
|
2006-04-22 18:53:45 +00:00
|
|
|
case MachineOperand::MO_JumpTableIndex: {
|
|
|
|
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
|
|
|
|
if (!isMemOp) O << '$';
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
|
2007-12-30 23:10:15 +00:00
|
|
|
<< MO.getIndex();
|
2007-01-12 19:20:47 +00:00
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::PIC_) {
|
|
|
|
if (Subtarget->isPICStyleStub())
|
2007-10-14 05:57:21 +00:00
|
|
|
O << "-\"" << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
|
|
|
<< "$pb\"";
|
2007-01-12 19:20:47 +00:00
|
|
|
else if (Subtarget->isPICStyleGOT())
|
|
|
|
O << "@GOTOFF";
|
|
|
|
}
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2007-01-18 22:27:12 +00:00
|
|
|
if (isMemOp && Subtarget->isPICStyleRIPRel() && !NotRIPRel)
|
2006-09-08 06:48:29 +00:00
|
|
|
O << "(%rip)";
|
2006-04-22 18:53:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-26 08:28:12 +00:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex: {
|
|
|
|
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
|
|
|
|
if (!isMemOp) O << '$';
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
|
2007-12-30 23:10:15 +00:00
|
|
|
<< MO.getIndex();
|
2007-01-12 19:20:47 +00:00
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::PIC_) {
|
|
|
|
if (Subtarget->isPICStyleStub())
|
2007-10-14 05:57:21 +00:00
|
|
|
O << "-\"" << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
|
|
|
<< "$pb\"";
|
2007-01-18 22:27:12 +00:00
|
|
|
else if (Subtarget->isPICStyleGOT())
|
2007-01-12 19:20:47 +00:00
|
|
|
O << "@GOTOFF";
|
|
|
|
}
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2008-11-22 16:15:34 +00:00
|
|
|
printOffset(MO.getOffset());
|
2006-09-08 06:48:29 +00:00
|
|
|
|
2007-01-18 22:27:12 +00:00
|
|
|
if (isMemOp && Subtarget->isPICStyleRIPRel() && !NotRIPRel)
|
2006-09-08 06:48:29 +00:00
|
|
|
O << "(%rip)";
|
2006-02-26 08:28:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-01 22:44:09 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2006-02-06 23:41:19 +00:00
|
|
|
bool isCallOp = Modifier && !strcmp(Modifier, "call");
|
2006-02-07 08:38:37 +00:00
|
|
|
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
|
2007-04-26 21:07:05 +00:00
|
|
|
bool needCloseParen = false;
|
2006-09-08 06:48:29 +00:00
|
|
|
|
2008-03-11 22:38:53 +00:00
|
|
|
const GlobalValue *GV = MO.getGlobal();
|
|
|
|
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
|
|
|
if (!GVar) {
|
2008-03-22 07:53:40 +00:00
|
|
|
// If GV is an alias then use the aliasee for determining
|
|
|
|
// thread-localness.
|
2008-03-11 22:38:53 +00:00
|
|
|
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
|
2008-09-09 20:05:04 +00:00
|
|
|
GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false));
|
2008-03-11 22:38:53 +00:00
|
|
|
}
|
|
|
|
|
2007-04-20 21:38:10 +00:00
|
|
|
bool isThreadLocal = GVar && GVar->isThreadLocal();
|
|
|
|
|
2006-09-08 06:48:29 +00:00
|
|
|
std::string Name = Mang->getValueName(GV);
|
2008-06-28 11:08:27 +00:00
|
|
|
decorateName(Name, GV);
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2007-04-26 21:07:05 +00:00
|
|
|
if (!isMemOp && !isCallOp)
|
|
|
|
O << '$';
|
|
|
|
else if (Name[0] == '$') {
|
|
|
|
// The name begins with a dollar-sign. In order to avoid having it look
|
|
|
|
// like an integer immediate to the assembler, enclose it in parens.
|
|
|
|
O << '(';
|
|
|
|
needCloseParen = true;
|
|
|
|
}
|
|
|
|
|
2008-06-09 09:52:31 +00:00
|
|
|
if (shouldPrintStub(TM, Subtarget)) {
|
2007-06-04 18:54:57 +00:00
|
|
|
// Link-once, declaration, or Weakly-linked global variables need
|
2006-02-07 08:38:37 +00:00
|
|
|
// non-lazily-resolved stubs
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
if (GV->isDeclaration() || GV->isWeakForLinker()) {
|
2006-02-07 08:38:37 +00:00
|
|
|
// Dynamically-resolved functions need a stub for the function.
|
2006-09-08 06:48:29 +00:00
|
|
|
if (isCallOp && isa<Function>(GV)) {
|
2008-09-20 00:13:45 +00:00
|
|
|
// Function stubs are no longer needed for Mac OS X 10.5 and up.
|
|
|
|
if (Subtarget->isTargetDarwin() && Subtarget->getDarwinVers() >= 9) {
|
|
|
|
O << Name;
|
|
|
|
} else {
|
|
|
|
FnStubs.insert(Name);
|
|
|
|
printSuffixedName(Name, "$stub");
|
|
|
|
}
|
2008-12-05 01:06:39 +00:00
|
|
|
} else if (GV->hasHiddenVisibility()) {
|
|
|
|
if (!GV->isDeclaration() && !GV->hasCommonLinkage())
|
|
|
|
// Definition is not definitely in the current translation unit.
|
|
|
|
O << Name;
|
|
|
|
else {
|
|
|
|
HiddenGVStubs.insert(Name);
|
|
|
|
printSuffixedName(Name, "$non_lazy_ptr");
|
|
|
|
}
|
2006-02-07 08:38:37 +00:00
|
|
|
} else {
|
|
|
|
GVStubs.insert(Name);
|
2008-05-19 21:38:18 +00:00
|
|
|
printSuffixedName(Name, "$non_lazy_ptr");
|
2006-02-07 08:38:37 +00:00
|
|
|
}
|
2006-09-14 18:23:27 +00:00
|
|
|
} else {
|
2007-01-18 22:27:12 +00:00
|
|
|
if (GV->hasDLLImportLinkage())
|
2008-06-28 11:08:09 +00:00
|
|
|
O << "__imp_";
|
2006-09-08 06:48:29 +00:00
|
|
|
O << Name;
|
2006-09-14 18:23:27 +00:00
|
|
|
}
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2006-07-26 21:12:04 +00:00
|
|
|
if (!isCallOp && TM.getRelocationModel() == Reloc::PIC_)
|
2008-01-05 00:41:47 +00:00
|
|
|
O << '-' << getPICLabelString(getFunctionNumber(), TAI, Subtarget);
|
2006-09-14 18:23:27 +00:00
|
|
|
} else {
|
|
|
|
if (GV->hasDLLImportLinkage()) {
|
2008-06-28 11:08:09 +00:00
|
|
|
O << "__imp_";
|
|
|
|
}
|
2006-09-08 06:48:29 +00:00
|
|
|
O << Name;
|
2007-01-12 19:20:47 +00:00
|
|
|
|
2008-06-09 09:52:31 +00:00
|
|
|
if (isCallOp) {
|
|
|
|
if (shouldPrintPLT(TM, Subtarget)) {
|
|
|
|
// Assemble call via PLT for externally visible symbols
|
|
|
|
if (!GV->hasHiddenVisibility() && !GV->hasProtectedVisibility() &&
|
2009-01-15 20:18:42 +00:00
|
|
|
!GV->hasLocalLinkage())
|
2007-01-16 16:41:57 +00:00
|
|
|
O << "@PLT";
|
|
|
|
}
|
2007-01-30 20:08:39 +00:00
|
|
|
if (Subtarget->isTargetCygMing() && GV->isDeclaration())
|
2007-01-16 16:41:57 +00:00
|
|
|
// Save function name for later type emission
|
|
|
|
FnStubs.insert(Name);
|
2007-01-12 19:20:47 +00:00
|
|
|
}
|
2006-09-14 18:23:27 +00:00
|
|
|
}
|
2006-12-01 00:25:12 +00:00
|
|
|
|
2006-12-01 07:38:23 +00:00
|
|
|
if (GV->hasExternalWeakLinkage())
|
2006-12-18 03:37:18 +00:00
|
|
|
ExtWeakSymbols.insert(GV);
|
2008-05-04 21:36:32 +00:00
|
|
|
|
2008-11-22 16:15:34 +00:00
|
|
|
printOffset(MO.getOffset());
|
2006-09-08 06:48:29 +00:00
|
|
|
|
2007-04-20 21:38:10 +00:00
|
|
|
if (isThreadLocal) {
|
2009-02-27 13:37:18 +00:00
|
|
|
TLSModel::Model model = getTLSModel(GVar, TM.getRelocationModel());
|
|
|
|
switch (model) {
|
|
|
|
case TLSModel::GeneralDynamic:
|
|
|
|
O << "@TLSGD";
|
|
|
|
break;
|
|
|
|
case TLSModel::LocalDynamic:
|
|
|
|
// O << "@TLSLD"; // local dynamic not implemented
|
2009-05-30 01:09:53 +00:00
|
|
|
O << "@TLSGD";
|
2009-02-27 13:37:18 +00:00
|
|
|
break;
|
|
|
|
case TLSModel::InitialExec:
|
2009-04-13 13:02:49 +00:00
|
|
|
if (Subtarget->is64Bit()) {
|
|
|
|
assert (!NotRIPRel);
|
|
|
|
O << "@GOTTPOFF(%rip)";
|
|
|
|
} else {
|
2009-02-27 13:37:18 +00:00
|
|
|
O << "@INDNTPOFF";
|
2009-04-13 13:02:49 +00:00
|
|
|
}
|
2009-02-27 13:37:18 +00:00
|
|
|
break;
|
|
|
|
case TLSModel::LocalExec:
|
|
|
|
if (Subtarget->is64Bit())
|
2009-04-13 13:02:49 +00:00
|
|
|
O << "@TPOFF";
|
2009-02-27 13:37:18 +00:00
|
|
|
else
|
2009-05-30 01:09:53 +00:00
|
|
|
O << "@NTPOFF";
|
2009-02-27 13:37:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert (0 && "Unknown TLS model");
|
|
|
|
}
|
2007-04-20 21:38:10 +00:00
|
|
|
} else if (isMemOp) {
|
2008-06-09 09:52:31 +00:00
|
|
|
if (shouldPrintGOT(TM, Subtarget)) {
|
2007-01-17 10:33:08 +00:00
|
|
|
if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
|
2007-01-12 19:20:47 +00:00
|
|
|
O << "@GOT";
|
2007-01-17 10:33:08 +00:00
|
|
|
else
|
|
|
|
O << "@GOTOFF";
|
2009-03-14 02:33:41 +00:00
|
|
|
} else if (Subtarget->isPICStyleRIPRel() && !NotRIPRel) {
|
|
|
|
if (TM.getRelocationModel() != Reloc::Static) {
|
|
|
|
if (Subtarget->GVRequiresExtraLoad(GV, TM, false))
|
|
|
|
O << "@GOTPCREL";
|
|
|
|
|
|
|
|
if (needCloseParen) {
|
|
|
|
needCloseParen = false;
|
|
|
|
O << ')';
|
|
|
|
}
|
2007-04-26 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 22:27:12 +00:00
|
|
|
// Use rip when possible to reduce code size, except when
|
|
|
|
// index or base register are also part of the address. e.g.
|
|
|
|
// foo(%rip)(%rcx,%rax,4) is not legal
|
|
|
|
O << "(%rip)";
|
|
|
|
}
|
2006-09-08 06:48:29 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 21:07:05 +00:00
|
|
|
if (needCloseParen)
|
|
|
|
O << ')';
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-02-06 23:41:19 +00:00
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
|
|
|
bool isCallOp = Modifier && !strcmp(Modifier, "call");
|
2009-04-23 00:57:37 +00:00
|
|
|
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
|
2007-04-26 21:07:05 +00:00
|
|
|
bool needCloseParen = false;
|
2007-01-12 19:20:47 +00:00
|
|
|
std::string Name(TAI->getGlobalPrefix());
|
|
|
|
Name += MO.getSymbolName();
|
2008-09-20 00:13:45 +00:00
|
|
|
// Print function stub suffix unless it's Mac OS X 10.5 and up.
|
|
|
|
if (isCallOp && shouldPrintStub(TM, Subtarget) &&
|
|
|
|
!(Subtarget->isTargetDarwin() && Subtarget->getDarwinVers() >= 9)) {
|
2005-07-08 00:23:26 +00:00
|
|
|
FnStubs.insert(Name);
|
2008-05-19 21:38:18 +00:00
|
|
|
printSuffixedName(Name, "$stub");
|
2005-07-08 00:23:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-04-23 00:57:37 +00:00
|
|
|
if (!isMemOp && !isCallOp)
|
2007-04-26 21:07:05 +00:00
|
|
|
O << '$';
|
|
|
|
else if (Name[0] == '$') {
|
|
|
|
// The name begins with a dollar-sign. In order to avoid having it look
|
|
|
|
// like an integer immediate to the assembler, enclose it in parens.
|
|
|
|
O << '(';
|
|
|
|
needCloseParen = true;
|
|
|
|
}
|
|
|
|
|
2007-01-12 19:20:47 +00:00
|
|
|
O << Name;
|
|
|
|
|
2008-06-09 09:52:31 +00:00
|
|
|
if (shouldPrintPLT(TM, Subtarget)) {
|
2007-01-12 19:20:47 +00:00
|
|
|
std::string GOTName(TAI->getGlobalPrefix());
|
|
|
|
GOTName+="_GLOBAL_OFFSET_TABLE_";
|
|
|
|
if (Name == GOTName)
|
2007-01-18 22:27:12 +00:00
|
|
|
// HACK! Emit extra offset to PC during printing GOT offset to
|
|
|
|
// compensate for the size of popl instruction. The resulting code
|
|
|
|
// should look like:
|
2007-01-12 19:20:47 +00:00
|
|
|
// call .piclabel
|
|
|
|
// piclabel:
|
|
|
|
// popl %some_register
|
|
|
|
// addl $_GLOBAL_ADDRESS_TABLE_ + [.-piclabel], %some_register
|
2007-01-18 01:49:58 +00:00
|
|
|
O << " + [.-"
|
2008-06-30 22:03:41 +00:00
|
|
|
<< getPICLabelString(getFunctionNumber(), TAI, Subtarget) << ']';
|
2007-01-12 19:20:47 +00:00
|
|
|
|
2007-01-18 22:27:12 +00:00
|
|
|
if (isCallOp)
|
|
|
|
O << "@PLT";
|
|
|
|
}
|
2006-09-08 06:48:29 +00:00
|
|
|
|
2007-04-26 21:07:05 +00:00
|
|
|
if (needCloseParen)
|
|
|
|
O << ')';
|
|
|
|
|
2007-01-18 22:27:12 +00:00
|
|
|
if (!isCallOp && Subtarget->isPICStyleRIPRel())
|
2006-09-08 06:48:29 +00:00
|
|
|
O << "(%rip)";
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
return;
|
2006-02-06 23:41:19 +00:00
|
|
|
}
|
2005-07-01 22:44:09 +00:00
|
|
|
default:
|
|
|
|
O << "<unknown operand type>"; return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-30 18:54:35 +00:00
|
|
|
void X86ATTAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
|
2007-12-30 20:49:49 +00:00
|
|
|
unsigned char value = MI->getOperand(Op).getImm();
|
2005-07-14 22:52:25 +00:00
|
|
|
assert(value <= 7 && "Invalid ssecc argument!");
|
|
|
|
switch (value) {
|
|
|
|
case 0: O << "eq"; break;
|
|
|
|
case 1: O << "lt"; break;
|
|
|
|
case 2: O << "le"; break;
|
|
|
|
case 3: O << "unord"; break;
|
|
|
|
case 4: O << "neq"; break;
|
|
|
|
case 5: O << "nlt"; break;
|
|
|
|
case 6: O << "nle"; break;
|
|
|
|
case 7: O << "ord"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 21:14:34 +00:00
|
|
|
void X86ATTAsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
|
2009-04-28 21:49:33 +00:00
|
|
|
const char *Modifier,
|
|
|
|
bool NotRIPRel) {
|
2007-01-14 00:13:07 +00:00
|
|
|
MachineOperand BaseReg = MI->getOperand(Op);
|
|
|
|
MachineOperand IndexReg = MI->getOperand(Op+2);
|
2005-07-01 22:44:09 +00:00
|
|
|
const MachineOperand &DispSpec = MI->getOperand(Op+3);
|
|
|
|
|
2009-04-28 21:49:33 +00:00
|
|
|
NotRIPRel |= IndexReg.getReg() || BaseReg.getReg();
|
2008-10-03 15:45:36 +00:00
|
|
|
if (DispSpec.isGlobal() ||
|
|
|
|
DispSpec.isCPI() ||
|
2009-04-23 00:57:37 +00:00
|
|
|
DispSpec.isJTI() ||
|
|
|
|
DispSpec.isSymbol()) {
|
2006-12-05 19:50:18 +00:00
|
|
|
printOperand(MI, Op+3, "mem", NotRIPRel);
|
2005-07-01 22:44:09 +00:00
|
|
|
} else {
|
2007-12-30 20:49:49 +00:00
|
|
|
int DispVal = DispSpec.getImm();
|
2005-07-01 22:44:09 +00:00
|
|
|
if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
|
|
|
|
O << DispVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IndexReg.getReg() || BaseReg.getReg()) {
|
2007-12-30 20:49:49 +00:00
|
|
|
unsigned ScaleVal = MI->getOperand(Op+1).getImm();
|
2007-01-14 00:13:07 +00:00
|
|
|
unsigned BaseRegOperand = 0, IndexRegOperand = 2;
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2007-01-14 00:13:07 +00:00
|
|
|
// There are cases where we can end up with ESP/RSP in the indexreg slot.
|
|
|
|
// If this happens, swap the base/index register to support assemblers that
|
|
|
|
// don't work when the index is *SP.
|
|
|
|
if (IndexReg.getReg() == X86::ESP || IndexReg.getReg() == X86::RSP) {
|
|
|
|
assert(ScaleVal == 1 && "Scale not supported for stack pointer!");
|
|
|
|
std::swap(BaseReg, IndexReg);
|
|
|
|
std::swap(BaseRegOperand, IndexRegOperand);
|
2006-09-08 06:48:29 +00:00
|
|
|
}
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '(';
|
2007-01-14 00:13:07 +00:00
|
|
|
if (BaseReg.getReg())
|
|
|
|
printOperand(MI, Op+BaseRegOperand, Modifier);
|
2005-07-01 22:44:09 +00:00
|
|
|
|
|
|
|
if (IndexReg.getReg()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ',';
|
2007-01-14 00:13:07 +00:00
|
|
|
printOperand(MI, Op+IndexRegOperand, Modifier);
|
2005-07-01 22:44:09 +00:00
|
|
|
if (ScaleVal != 1)
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ',' << ScaleVal;
|
2005-07-01 22:44:09 +00:00
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ')';
|
2005-07-01 22:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-08 21:14:34 +00:00
|
|
|
void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
|
2009-04-28 21:49:33 +00:00
|
|
|
const char *Modifier, bool NotRIPRel){
|
2009-04-08 21:14:34 +00:00
|
|
|
assert(isMem(MI, Op) && "Invalid memory reference!");
|
|
|
|
MachineOperand Segment = MI->getOperand(Op+4);
|
|
|
|
if (Segment.getReg()) {
|
|
|
|
printOperand(MI, Op+4, Modifier);
|
|
|
|
O << ':';
|
|
|
|
}
|
2009-04-28 21:49:33 +00:00
|
|
|
printLeaMemReference(MI, Op, Modifier, NotRIPRel);
|
2009-04-08 21:14:34 +00:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:09 +00:00
|
|
|
void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
const MachineBasicBlock *MBB) const {
|
|
|
|
if (!TAI->getSetDirective())
|
|
|
|
return;
|
2007-11-14 09:18:41 +00:00
|
|
|
|
|
|
|
// We don't need .set machinery if we have GOT-style relocations
|
|
|
|
if (Subtarget->isPICStyleGOT())
|
|
|
|
return;
|
2008-06-28 11:08:09 +00:00
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
|
|
|
|
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
|
2008-02-28 00:43:03 +00:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2007-11-09 19:11:23 +00:00
|
|
|
if (Subtarget->isPICStyleRIPRel())
|
2008-06-28 11:08:09 +00:00
|
|
|
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-11-09 19:11:23 +00:00
|
|
|
<< '_' << uid << '\n';
|
|
|
|
else
|
2008-01-05 00:41:47 +00:00
|
|
|
O << '-' << getPICLabelString(getFunctionNumber(), TAI, Subtarget) << '\n';
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
}
|
|
|
|
|
2006-02-18 00:15:05 +00:00
|
|
|
void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
|
2008-01-05 00:41:47 +00:00
|
|
|
std::string label = getPICLabelString(getFunctionNumber(), TAI, Subtarget);
|
2008-06-30 22:03:41 +00:00
|
|
|
O << label << '\n' << label << ':';
|
2006-02-18 00:15:05 +00:00
|
|
|
}
|
|
|
|
|
2006-04-28 23:11:40 +00:00
|
|
|
|
2007-11-14 09:18:41 +00:00
|
|
|
void X86ATTAsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
|
|
|
const MachineBasicBlock *MBB,
|
2008-06-28 11:08:09 +00:00
|
|
|
unsigned uid) const
|
|
|
|
{
|
2007-11-14 09:18:41 +00:00
|
|
|
const char *JTEntryDirective = MJTI->getEntrySize() == 4 ?
|
|
|
|
TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
|
|
|
|
|
|
|
|
O << JTEntryDirective << ' ';
|
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::PIC_) {
|
|
|
|
if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStub()) {
|
|
|
|
O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
|
|
|
<< '_' << uid << "_set_" << MBB->getNumber();
|
|
|
|
} else if (Subtarget->isPICStyleGOT()) {
|
2008-02-28 00:43:03 +00:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2007-11-14 09:18:41 +00:00
|
|
|
O << "@GOTOFF";
|
|
|
|
} else
|
|
|
|
assert(0 && "Don't know how to print MBB label for this PIC mode");
|
|
|
|
} else
|
2008-02-28 00:43:03 +00:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2007-11-14 09:18:41 +00:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:10:06 +00:00
|
|
|
bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO,
|
2006-04-28 23:11:40 +00:00
|
|
|
const char Mode) {
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
switch (Mode) {
|
|
|
|
default: return true; // Unknown mode.
|
|
|
|
case 'b': // Print QImode register
|
2006-05-05 05:40:20 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i8);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
|
|
|
case 'h': // Print QImode high register
|
2006-05-05 05:40:20 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
|
|
|
case 'w': // Print HImode register
|
2006-05-05 05:40:20 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i16);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
|
|
|
case 'k': // Print SImode register
|
2006-05-05 05:40:20 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i32);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
2007-10-29 03:09:07 +00:00
|
|
|
case 'q': // Print DImode register
|
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i64);
|
|
|
|
break;
|
2006-04-28 23:11:40 +00:00
|
|
|
}
|
|
|
|
|
2008-07-07 22:21:06 +00:00
|
|
|
O << '%'<< TRI->getAsmName(Reg);
|
2006-04-28 23:11:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-04-28 21:19:05 +00:00
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
2008-06-28 11:09:48 +00:00
|
|
|
bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2008-06-28 11:08:09 +00:00
|
|
|
unsigned AsmVariant,
|
2006-04-28 21:19:05 +00:00
|
|
|
const char *ExtraCode) {
|
|
|
|
// Does this asm operand have a single letter operand modifier?
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2006-04-28 21:19:05 +00:00
|
|
|
switch (ExtraCode[0]) {
|
|
|
|
default: return true; // Unknown modifier.
|
2007-01-25 02:53:24 +00:00
|
|
|
case 'c': // Don't print "$" before a global var name or constant.
|
2009-03-14 02:33:41 +00:00
|
|
|
printOperand(MI, OpNo, "mem", /*NotRIPRel=*/true);
|
2006-10-31 20:12:30 +00:00
|
|
|
return false;
|
2006-04-28 23:11:40 +00:00
|
|
|
case 'b': // Print QImode register
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
case 'k': // Print SImode register
|
2007-10-29 03:09:07 +00:00
|
|
|
case 'q': // Print DImode register
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(OpNo).isReg())
|
2007-03-25 02:01:03 +00:00
|
|
|
return printAsmMRegister(MI->getOperand(OpNo), ExtraCode[0]);
|
|
|
|
printOperand(MI, OpNo);
|
|
|
|
return false;
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2007-03-25 01:44:57 +00:00
|
|
|
case 'P': // Don't print @PLT, but do print as memory.
|
2009-04-28 21:49:33 +00:00
|
|
|
printOperand(MI, OpNo, "mem", /*NotRIPRel=*/true);
|
2007-03-25 01:44:57 +00:00
|
|
|
return false;
|
2006-04-28 21:19:05 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2006-04-28 21:19:05 +00:00
|
|
|
printOperand(MI, OpNo);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:10:06 +00:00
|
|
|
bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
2006-04-28 21:19:05 +00:00
|
|
|
unsigned OpNo,
|
2008-06-28 11:08:09 +00:00
|
|
|
unsigned AsmVariant,
|
2006-04-28 21:19:05 +00:00
|
|
|
const char *ExtraCode) {
|
2007-10-29 03:09:07 +00:00
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2007-10-29 03:09:07 +00:00
|
|
|
switch (ExtraCode[0]) {
|
|
|
|
default: return true; // Unknown modifier.
|
|
|
|
case 'b': // Print QImode register
|
|
|
|
case 'h': // Print QImode high register
|
|
|
|
case 'w': // Print HImode register
|
|
|
|
case 'k': // Print SImode register
|
|
|
|
case 'q': // Print SImode register
|
|
|
|
// These only apply to registers, ignore on mem.
|
|
|
|
break;
|
2009-01-23 22:33:40 +00:00
|
|
|
case 'P': // Don't print @PLT, but do print as memory.
|
2009-04-28 21:49:33 +00:00
|
|
|
printMemReference(MI, OpNo, "mem", /*NotRIPRel=*/true);
|
2009-01-23 22:33:40 +00:00
|
|
|
return false;
|
2007-10-29 03:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-28 21:19:05 +00:00
|
|
|
printMemReference(MI, OpNo);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-06 21:45:08 +00:00
|
|
|
/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
|
|
|
|
/// AT&T syntax to the current output stream.
|
2005-07-01 22:44:09 +00:00
|
|
|
///
|
|
|
|
void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|
|
|
++EmittedInsts;
|
2006-01-26 02:27:43 +00:00
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// Call the autogenerated instruction printer routines.
|
|
|
|
printInstruction(MI);
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
/// doInitialization
|
|
|
|
bool X86ATTAsmPrinter::doInitialization(Module &M) {
|
|
|
|
|
2008-07-09 06:36:53 +00:00
|
|
|
bool Result = AsmPrinter::doInitialization(M);
|
|
|
|
|
2008-07-09 20:55:35 +00:00
|
|
|
if (TAI->doesSupportDebugInformation()) {
|
|
|
|
// Let PassManager know we need debug information and relay
|
|
|
|
// the MachineModuleInfo address on to DwarfWriter.
|
|
|
|
// AsmPrinter::doInitialization did this analysis.
|
2009-01-28 13:14:17 +00:00
|
|
|
MMI = getAnalysisIfAvailable<MachineModuleInfo>();
|
|
|
|
DW = getAnalysisIfAvailable<DwarfWriter>();
|
2009-01-08 23:40:34 +00:00
|
|
|
DW->BeginModule(&M, MMI, O, this, TAI);
|
2008-07-09 20:55:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
// Darwin wants symbols to be quoted if they have complex names.
|
|
|
|
if (Subtarget->isTargetDarwin())
|
|
|
|
Mang->setUseQuotes(true);
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
2008-06-28 11:08:27 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
if (!GVar->hasInitializer())
|
|
|
|
return; // External global require no code
|
|
|
|
|
|
|
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
|
|
|
if (EmitSpecialLLVMGlobal(GVar)) {
|
|
|
|
if (Subtarget->isTargetDarwin() &&
|
|
|
|
TM.getRelocationModel() == Reloc::Static) {
|
|
|
|
if (GVar->getName() == "llvm.global_ctors")
|
|
|
|
O << ".reference .constructors_used\n";
|
|
|
|
else if (GVar->getName() == "llvm.global_dtors")
|
|
|
|
O << ".reference .destructors_used\n";
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
2008-06-28 11:09:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
std::string name = Mang->getValueName(GVar);
|
|
|
|
Constant *C = GVar->getInitializer();
|
|
|
|
const Type *Type = C->getType();
|
2009-05-09 07:06:46 +00:00
|
|
|
unsigned Size = TD->getTypeAllocSize(Type);
|
2008-06-28 11:09:32 +00:00
|
|
|
unsigned Align = TD->getPreferredAlignmentLog(GVar);
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-08-08 18:25:07 +00:00
|
|
|
printVisibility(name, GVar->getVisibility());
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
if (Subtarget->isTargetELF())
|
|
|
|
O << "\t.type\t" << name << ",@object\n";
|
|
|
|
|
2008-09-24 22:14:23 +00:00
|
|
|
SwitchToSection(TAI->SectionForGlobal(GVar));
|
2008-07-09 13:27:16 +00:00
|
|
|
|
2009-02-18 02:19:52 +00:00
|
|
|
if (C->isNullValue() && !GVar->hasSection() &&
|
|
|
|
!(Subtarget->isTargetDarwin() &&
|
|
|
|
TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) {
|
2008-07-09 13:27:16 +00:00
|
|
|
// FIXME: This seems to be pretty darwin-specific
|
2008-06-28 11:09:32 +00:00
|
|
|
if (GVar->hasExternalLinkage()) {
|
|
|
|
if (const char *Directive = TAI->getZeroFillDirective()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl " << name << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
O << Directive << "__DATA, __common, " << name << ", "
|
2008-06-30 22:03:41 +00:00
|
|
|
<< Size << ", " << Align << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
return;
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
2008-06-28 11:09:32 +00:00
|
|
|
}
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
if (!GVar->isThreadLocal() &&
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
(GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
|
2008-06-28 11:09:32 +00:00
|
|
|
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
2008-07-09 13:27:16 +00:00
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
if (TAI->getLCOMMDirective() != NULL) {
|
2009-01-15 20:18:42 +00:00
|
|
|
if (GVar->hasLocalLinkage()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getLCOMMDirective() << name << ',' << Size;
|
2008-06-28 11:09:32 +00:00
|
|
|
if (Subtarget->isTargetDarwin())
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ',' << Align;
|
2008-06-28 11:09:32 +00:00
|
|
|
} else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl " << name << '\n'
|
|
|
|
<< TAI->getWeakDefDirective() << name << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
EmitAlignment(Align, GVar);
|
2009-03-24 00:17:40 +00:00
|
|
|
O << name << ":";
|
|
|
|
if (VerboseAsm) {
|
2009-03-25 01:08:42 +00:00
|
|
|
O << "\t\t\t\t" << TAI->getCommentString() << ' ';
|
2009-03-24 00:17:40 +00:00
|
|
|
PrintUnmangledNameSafely(GVar, O);
|
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
EmitGlobalConstant(C);
|
|
|
|
return;
|
2008-06-28 11:08:27 +00:00
|
|
|
} else {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getCOMMDirective() << name << ',' << Size;
|
2008-08-08 18:25:52 +00:00
|
|
|
if (TAI->getCOMMDirectiveTakesAlignment())
|
|
|
|
O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-28 11:09:32 +00:00
|
|
|
if (!Subtarget->isTargetCygMing()) {
|
2009-01-15 20:18:42 +00:00
|
|
|
if (GVar->hasLocalLinkage())
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.local\t" << name << '\n';
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getCOMMDirective() << name << ',' << Size;
|
2008-06-28 11:09:32 +00:00
|
|
|
if (TAI->getCOMMDirectiveTakesAlignment())
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
if (VerboseAsm) {
|
|
|
|
O << "\t\t" << TAI->getCommentString() << ' ';
|
|
|
|
PrintUnmangledNameSafely(GVar, O);
|
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
return;
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
2008-06-28 11:09:32 +00:00
|
|
|
}
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
switch (GVar->getLinkage()) {
|
2009-03-11 20:14:15 +00:00
|
|
|
case GlobalValue::CommonLinkage:
|
Introduce new linkage types linkonce_odr, weak_odr, common_odr
and extern_weak_odr. These are the same as the non-odr versions,
except that they indicate that the global will only be overridden
by an *equivalent* global. In C, a function with weak linkage can
be overridden by a function which behaves completely differently.
This means that IP passes have to skip weak functions, since any
deductions made from the function definition might be wrong, since
the definition could be replaced by something completely different
at link time. This is not allowed in C++, thanks to the ODR
(One-Definition-Rule): if a function is replaced by another at
link-time, then the new function must be the same as the original
function. If a language knows that a function or other global can
only be overridden by an equivalent global, it can give it the
weak_odr linkage type, and the optimizers will understand that it
is alright to make deductions based on the function body. The
code generators on the other hand map weak and weak_odr linkage
to the same thing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66339 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-07 15:45:40 +00:00
|
|
|
case GlobalValue::LinkOnceAnyLinkage:
|
|
|
|
case GlobalValue::LinkOnceODRLinkage:
|
|
|
|
case GlobalValue::WeakAnyLinkage:
|
|
|
|
case GlobalValue::WeakODRLinkage:
|
2008-06-28 11:09:32 +00:00
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl " << name << '\n'
|
|
|
|
<< TAI->getWeakDefDirective() << name << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
|
|
|
O << "\t.globl\t" << name << "\n"
|
2008-06-30 22:03:41 +00:00
|
|
|
"\t.linkonce same_size\n";
|
2008-06-28 11:09:32 +00:00
|
|
|
} else {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.weak\t" << name << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-08-08 06:43:59 +00:00
|
|
|
case GlobalValue::DLLExportLinkage:
|
|
|
|
case GlobalValue::AppendingLinkage:
|
2008-06-28 11:09:32 +00:00
|
|
|
// FIXME: appending linkage variables should go into a section of
|
|
|
|
// their name or something. For now, just emit them as external.
|
2008-08-08 06:43:59 +00:00
|
|
|
case GlobalValue::ExternalLinkage:
|
2008-06-28 11:09:32 +00:00
|
|
|
// If external or appending, declare as a global symbol
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl " << name << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
// FALL THROUGH
|
2009-01-15 20:18:42 +00:00
|
|
|
case GlobalValue::PrivateLinkage:
|
2008-08-08 06:43:59 +00:00
|
|
|
case GlobalValue::InternalLinkage:
|
2008-06-28 11:09:32 +00:00
|
|
|
break;
|
2008-08-08 06:43:59 +00:00
|
|
|
default:
|
2008-06-28 11:09:32 +00:00
|
|
|
assert(0 && "Unknown linkage type!");
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
EmitAlignment(Align, GVar);
|
2009-03-24 00:17:40 +00:00
|
|
|
O << name << ":";
|
|
|
|
if (VerboseAsm){
|
2009-03-25 01:08:42 +00:00
|
|
|
O << "\t\t\t\t" << TAI->getCommentString() << ' ';
|
2009-03-24 00:17:40 +00:00
|
|
|
PrintUnmangledNameSafely(GVar, O);
|
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
if (TAI->hasDotTypeDotSizeDirective())
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.size\t" << name << ", " << Size << '\n';
|
2008-06-28 11:09:32 +00:00
|
|
|
|
|
|
|
EmitGlobalConstant(C);
|
|
|
|
}
|
|
|
|
|
2008-07-08 00:55:58 +00:00
|
|
|
/// printGVStub - Print stub for a global value.
|
|
|
|
///
|
|
|
|
void X86ATTAsmPrinter::printGVStub(const char *GV, const char *Prefix) {
|
2008-07-08 16:40:43 +00:00
|
|
|
printSuffixedName(GV, "$non_lazy_ptr", Prefix);
|
2008-07-08 00:55:58 +00:00
|
|
|
O << ":\n\t.indirect_symbol ";
|
|
|
|
if (Prefix) O << Prefix;
|
|
|
|
O << GV << "\n\t.long\t0\n";
|
|
|
|
}
|
|
|
|
|
2008-12-05 01:06:39 +00:00
|
|
|
/// printHiddenGVStub - Print stub for a hidden global value.
|
|
|
|
///
|
|
|
|
void X86ATTAsmPrinter::printHiddenGVStub(const char *GV, const char *Prefix) {
|
|
|
|
EmitAlignment(2);
|
|
|
|
printSuffixedName(GV, "$non_lazy_ptr", Prefix);
|
|
|
|
if (Prefix) O << Prefix;
|
|
|
|
O << ":\n" << TAI->getData32bitsDirective() << GV << '\n';
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:09:32 +00:00
|
|
|
|
|
|
|
bool X86ATTAsmPrinter::doFinalization(Module &M) {
|
|
|
|
// Print out module-level global variables here.
|
|
|
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
2008-06-28 11:09:48 +00:00
|
|
|
I != E; ++I) {
|
2008-06-28 11:09:32 +00:00
|
|
|
printModuleLevelGV(I);
|
|
|
|
|
2008-06-28 11:09:48 +00:00
|
|
|
if (I->hasDLLExportLinkage())
|
|
|
|
DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
|
2009-02-21 11:53:32 +00:00
|
|
|
|
|
|
|
// If the global is a extern weak symbol, remember to emit the weak
|
|
|
|
// reference!
|
2009-05-14 23:22:47 +00:00
|
|
|
// FIXME: This is rather hacky, since we'll emit references to ALL weak
|
|
|
|
// stuff, not used. But currently it's the only way to deal with extern weak
|
2009-02-21 11:53:32 +00:00
|
|
|
// initializers hidden deep inside constant expressions.
|
|
|
|
if (I->hasExternalWeakLinkage())
|
|
|
|
ExtWeakSymbols.insert(I);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Module::const_iterator I = M.begin(), E = M.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
// If the global is a extern weak symbol, remember to emit the weak
|
|
|
|
// reference!
|
2009-05-14 23:23:37 +00:00
|
|
|
// FIXME: This is rather hacky, since we'll emit references to ALL weak
|
|
|
|
// stuff, not used. But currently it's the only way to deal with extern weak
|
2009-02-21 11:53:32 +00:00
|
|
|
// initializers hidden deep inside constant expressions.
|
|
|
|
if (I->hasExternalWeakLinkage())
|
|
|
|
ExtWeakSymbols.insert(I);
|
2008-06-28 11:09:48 +00:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
// Output linker support code for dllexported globals
|
2008-06-28 11:08:44 +00:00
|
|
|
if (!DLLExportedGVs.empty())
|
2008-06-28 11:08:27 +00:00
|
|
|
SwitchToDataSection(".section .drectve");
|
|
|
|
|
|
|
|
for (StringSet<>::iterator i = DLLExportedGVs.begin(),
|
|
|
|
e = DLLExportedGVs.end();
|
2008-06-28 11:08:44 +00:00
|
|
|
i != e; ++i)
|
2008-06-28 11:08:27 +00:00
|
|
|
O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
|
|
|
|
|
|
|
|
if (!DLLExportedFns.empty()) {
|
|
|
|
SwitchToDataSection(".section .drectve");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (StringSet<>::iterator i = DLLExportedFns.begin(),
|
|
|
|
e = DLLExportedFns.end();
|
2008-06-28 11:08:44 +00:00
|
|
|
i != e; ++i)
|
2008-06-28 11:08:27 +00:00
|
|
|
O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
|
|
|
|
|
|
|
|
if (Subtarget->isTargetDarwin()) {
|
|
|
|
SwitchToDataSection("");
|
|
|
|
|
|
|
|
// Output stubs for dynamically-linked functions
|
|
|
|
for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
2008-12-05 01:06:39 +00:00
|
|
|
i != e; ++i) {
|
2008-06-28 11:08:27 +00:00
|
|
|
SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
|
|
|
|
"self_modifying_code+pure_instructions,5", 0);
|
2008-07-08 00:55:58 +00:00
|
|
|
const char *p = i->getKeyData();
|
2008-06-28 11:08:27 +00:00
|
|
|
printSuffixedName(p, "$stub");
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ":\n"
|
|
|
|
"\t.indirect_symbol " << p << "\n"
|
|
|
|
"\thlt ; hlt ; hlt ; hlt ; hlt\n";
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-07-08 00:55:58 +00:00
|
|
|
// Print global value stubs.
|
|
|
|
bool InStubSection = false;
|
2008-06-28 11:08:27 +00:00
|
|
|
if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
|
|
|
|
// Add the (possibly multiple) personalities to the set of global values.
|
|
|
|
// Only referenced functions get into the Personalities list.
|
|
|
|
const std::vector<Function *>& Personalities = MMI->getPersonalities();
|
|
|
|
for (std::vector<Function *>::const_iterator I = Personalities.begin(),
|
2008-07-08 00:55:58 +00:00
|
|
|
E = Personalities.end(); I != E; ++I) {
|
|
|
|
if (!*I)
|
|
|
|
continue;
|
|
|
|
if (!InStubSection) {
|
|
|
|
SwitchToDataSection(
|
|
|
|
"\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
|
|
|
|
InStubSection = true;
|
|
|
|
}
|
|
|
|
printGVStub((*I)->getNameStart(), "_");
|
|
|
|
}
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Output stubs for external and common global variables.
|
2008-07-08 00:55:58 +00:00
|
|
|
if (!InStubSection && !GVStubs.empty())
|
2008-06-28 11:08:27 +00:00
|
|
|
SwitchToDataSection(
|
|
|
|
"\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
|
|
|
|
for (StringSet<>::iterator i = GVStubs.begin(), e = GVStubs.end();
|
2008-07-08 00:55:58 +00:00
|
|
|
i != e; ++i)
|
|
|
|
printGVStub(i->getKeyData());
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-12-05 01:06:39 +00:00
|
|
|
if (!HiddenGVStubs.empty()) {
|
|
|
|
SwitchToSection(TAI->getDataSection());
|
|
|
|
for (StringSet<>::iterator i = HiddenGVStubs.begin(), e = HiddenGVStubs.end();
|
|
|
|
i != e; ++i)
|
|
|
|
printHiddenGVStub(i->getKeyData());
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
// Emit final debug information.
|
2009-01-28 13:14:17 +00:00
|
|
|
DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
|
2009-01-08 23:40:34 +00:00
|
|
|
DW->EndModule();
|
2008-06-28 11:08:27 +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
|
|
|
|
// linker can safely perform dead code stripping. Since LLVM never
|
|
|
|
// generates code that does this, it is always safe to set.
|
|
|
|
O << "\t.subsections_via_symbols\n";
|
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
|
|
|
// Emit type information for external functions
|
|
|
|
for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
|
|
|
i != e; ++i) {
|
|
|
|
O << "\t.def\t " << i->getKeyData()
|
|
|
|
<< ";\t.scl\t" << COFF::C_EXT
|
|
|
|
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
|
|
|
|
<< ";\t.endef\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit final debug information.
|
2009-01-28 13:14:17 +00:00
|
|
|
DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
|
2009-01-08 23:40:34 +00:00
|
|
|
DW->EndModule();
|
2008-06-28 11:08:27 +00:00
|
|
|
} else if (Subtarget->isTargetELF()) {
|
|
|
|
// Emit final debug information.
|
2009-01-28 13:14:17 +00:00
|
|
|
DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
|
2009-01-08 23:40:34 +00:00
|
|
|
DW->EndModule();
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return AsmPrinter::doFinalization(M);
|
|
|
|
}
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// Include the auto-generated portion of the assembly writer.
|
|
|
|
#include "X86GenAsmWriter.inc"
|