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-06-24 05:46:28 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-06-19 00:47:33 +00:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-08-10 18:15:01 +00:00
|
|
|
#include "llvm/MC/MCSectionMachO.h"
|
2009-06-24 05:46:28 +00:00
|
|
|
#include "llvm/MC/MCStreamer.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"
|
2009-06-19 00:47:33 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-14 20:18:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2005-07-01 22:44:09 +00:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2006-09-07 22:06:40 +00:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2009-07-28 03:13:23 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.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");
|
|
|
|
|
2009-06-19 00:47:33 +00:00
|
|
|
static cl::opt<bool> NewAsmPrinter("experimental-asm-printer",
|
|
|
|
cl::Hidden);
|
|
|
|
|
2009-06-24 19:44:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Primitive Helper Functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-24 19:19:16 +00:00
|
|
|
|
|
|
|
void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
|
2007-01-18 01:49:58 +00:00
|
|
|
if (Subtarget->isTargetDarwin())
|
2009-06-24 19:19:16 +00:00
|
|
|
O << "\"L" << getFunctionNumber() << "$pb\"";
|
2007-01-18 01:49:58 +00:00
|
|
|
else if (Subtarget->isTargetELF())
|
2009-07-08 23:09:14 +00:00
|
|
|
O << ".Lllvm$" << getFunctionNumber() << ".$piclabel";
|
2007-01-18 01:49:58 +00:00
|
|
|
else
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Don't know how to print PIC label!");
|
2007-01-12 19:20:47 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 19:44:36 +00:00
|
|
|
/// PrintUnmangledNameSafely - Print out the printable characters in the name.
|
|
|
|
/// Don't print things like \\n or \\0.
|
2009-07-26 07:49:05 +00:00
|
|
|
static void PrintUnmangledNameSafely(const Value *V,
|
2009-07-14 20:18:05 +00:00
|
|
|
formatted_raw_ostream &OS) {
|
2009-07-26 07:49:05 +00:00
|
|
|
for (StringRef::iterator it = V->getName().begin(),
|
|
|
|
ie = V->getName().end(); it != ie; ++it)
|
|
|
|
if (isprint(*it))
|
|
|
|
OS << *it;
|
2009-06-24 19:44:36 +00:00
|
|
|
}
|
2009-06-24 19:19:16 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-07-15 04:55:56 +00:00
|
|
|
/// DecorateCygMingName - Query FunctionInfoMap and use this information for
|
|
|
|
/// various name decorations for Cygwin and MingW.
|
|
|
|
void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name,
|
|
|
|
const GlobalValue *GV) {
|
|
|
|
assert(Subtarget->isTargetCygMing() && "This is only for cygwin and mingw");
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
const Function *F = dyn_cast<Function>(GV);
|
|
|
|
if (!F) return;
|
|
|
|
|
2009-07-10 21:57:21 +00:00
|
|
|
// Save function name for later type emission.
|
2009-07-15 04:55:56 +00:00
|
|
|
if (F->isDeclaration())
|
2009-07-10 21:57:21 +00:00
|
|
|
CygMingStubs.insert(Name);
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
|
|
const X86MachineFunctionInfo *Info;
|
2009-07-15 04:55:56 +00:00
|
|
|
|
|
|
|
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
2008-06-28 11:08:27 +00:00
|
|
|
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:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unsupported DecorationStyle");
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:09:01 +00:00
|
|
|
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
2009-06-30 22:38:32 +00:00
|
|
|
unsigned FnAlign = MF.getAlignment();
|
2006-02-07 08:38:37 +00:00
|
|
|
const Function *F = MF.getFunction();
|
2006-09-20 22:03:51 +00:00
|
|
|
|
2009-07-15 04:55:56 +00:00
|
|
|
if (Subtarget->isTargetCygMing())
|
|
|
|
DecorateCygMingName(CurrentFnName, F);
|
2006-09-20 22:03:51 +00:00
|
|
|
|
2009-07-29 05:09:30 +00:00
|
|
|
SwitchToSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
|
2009-08-03 22:16:57 +00:00
|
|
|
EmitAlignment(FnAlign, F);
|
|
|
|
|
2006-02-07 08:38:37 +00:00
|
|
|
switch (F->getLinkage()) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Unknown linkage type!");
|
2006-02-07 08:38:37 +00:00
|
|
|
case Function::InternalLinkage: // Symbols default to internal.
|
2009-01-15 20:18:42 +00:00
|
|
|
case Function::PrivateLinkage:
|
2009-07-20 01:03:30 +00:00
|
|
|
case Function::LinkerPrivateLinkage:
|
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-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:
|
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())
|
2009-07-14 18:17:16 +00:00
|
|
|
DLLExportedFns.insert(Mang->getMangledName(F));
|
2008-06-28 11:09:01 +00:00
|
|
|
|
|
|
|
// 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.
|
2009-06-19 23:21:20 +00:00
|
|
|
if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
|
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
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// We didn't modify anything.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-13 21:53:19 +00:00
|
|
|
/// printSymbolOperand - Print a raw symbol reference operand. This handles
|
|
|
|
/// jump tables, constant pools, global address and external symbols, all of
|
|
|
|
/// which print to a label with various suffixes for relocation types etc.
|
2009-07-13 21:41:08 +00:00
|
|
|
void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
|
|
|
|
switch (MO.getType()) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("unknown symbol type!");
|
2009-07-13 22:28:21 +00:00
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
|
2007-12-30 23:10:15 +00:00
|
|
|
<< MO.getIndex();
|
2009-06-27 05:46:24 +00:00
|
|
|
break;
|
2009-07-13 22:28:21 +00:00
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2008-06-30 22:03:41 +00:00
|
|
|
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
|
2007-12-30 23:10:15 +00:00
|
|
|
<< MO.getIndex();
|
2009-06-26 20:00:05 +00:00
|
|
|
printOffset(MO.getOffset());
|
2009-06-27 05:46:24 +00:00
|
|
|
break;
|
2005-07-01 22:44:09 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress: {
|
2008-03-11 22:38:53 +00:00
|
|
|
const GlobalValue *GV = MO.getGlobal();
|
2009-07-13 21:41:08 +00:00
|
|
|
|
2009-07-14 18:17:16 +00:00
|
|
|
const char *Suffix = "";
|
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
|
|
|
Suffix = "$stub";
|
|
|
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
|
2009-07-15 01:53:36 +00:00
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
2009-07-14 18:17:16 +00:00
|
|
|
Suffix = "$non_lazy_ptr";
|
|
|
|
|
2009-07-15 01:53:36 +00:00
|
|
|
std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
|
2009-07-15 04:55:56 +00:00
|
|
|
if (Subtarget->isTargetCygMing())
|
|
|
|
DecorateCygMingName(Name, GV);
|
2009-07-14 06:04:35 +00:00
|
|
|
|
2009-07-14 15:57:55 +00:00
|
|
|
// Handle dllimport linkage.
|
2009-07-14 18:17:16 +00:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
|
|
|
|
Name = "__imp_" + Name;
|
2009-07-14 15:57:55 +00:00
|
|
|
|
2009-07-14 18:17:16 +00:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
|
|
|
|
GVStubs[Name] = Mang->getMangledName(GV);
|
|
|
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
|
|
|
|
MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
|
|
|
|
HiddenGVStubs[Name] = Mang->getMangledName(GV);
|
|
|
|
else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
|
|
|
|
FnStubs[Name] = Mang->getMangledName(GV);
|
|
|
|
|
|
|
|
// If the name begins with a dollar-sign, enclose it in parens. We do this
|
|
|
|
// to avoid having it look like an integer immediate to the assembler.
|
|
|
|
if (Name[0] == '$')
|
|
|
|
O << '(' << Name << ')';
|
|
|
|
else
|
|
|
|
O << Name;
|
2009-06-21 02:22:53 +00:00
|
|
|
|
2009-07-09 05:42:07 +00:00
|
|
|
printOffset(MO.getOffset());
|
2009-06-27 05:46:24 +00:00
|
|
|
break;
|
2005-07-01 22:44:09 +00:00
|
|
|
}
|
2009-07-13 22:28:21 +00:00
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
2009-07-15 03:01:23 +00:00
|
|
|
std::string Name = Mang->makeNameProper(MO.getSymbolName());
|
2009-07-13 22:07:30 +00:00
|
|
|
if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
|
2009-07-14 18:17:16 +00:00
|
|
|
FnStubs[Name+"$stub"] = Name;
|
|
|
|
Name += "$stub";
|
2009-07-13 22:07:30 +00:00
|
|
|
}
|
|
|
|
|
2009-07-14 18:17:16 +00:00
|
|
|
// If the name begins with a dollar-sign, enclose it in parens. We do this
|
|
|
|
// to avoid having it look like an integer immediate to the assembler.
|
|
|
|
if (Name[0] == '$')
|
|
|
|
O << '(' << Name << ')';
|
|
|
|
else
|
|
|
|
O << Name;
|
2009-06-27 05:46:24 +00:00
|
|
|
break;
|
2006-02-06 23:41:19 +00:00
|
|
|
}
|
2009-07-13 22:28:21 +00:00
|
|
|
}
|
2009-06-27 05:46:24 +00:00
|
|
|
|
|
|
|
switch (MO.getTargetFlags()) {
|
2005-07-01 22:44:09 +00:00
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unknown target flag on GV operand");
|
2009-07-09 00:58:53 +00:00
|
|
|
case X86II::MO_NO_FLAG: // No flag.
|
2009-07-09 06:59:17 +00:00
|
|
|
break;
|
|
|
|
case X86II::MO_DARWIN_NONLAZY:
|
|
|
|
case X86II::MO_DARWIN_HIDDEN_NONLAZY:
|
|
|
|
case X86II::MO_DLLIMPORT:
|
2009-07-13 22:07:30 +00:00
|
|
|
case X86II::MO_DARWIN_STUB:
|
2009-07-09 06:59:17 +00:00
|
|
|
// These affect the name of the symbol, not any suffix.
|
2009-06-27 05:46:24 +00:00
|
|
|
break;
|
|
|
|
case X86II::MO_GOT_ABSOLUTE_ADDRESS:
|
|
|
|
O << " + [.-";
|
|
|
|
PrintPICBaseSymbol();
|
|
|
|
O << ']';
|
|
|
|
break;
|
|
|
|
case X86II::MO_PIC_BASE_OFFSET:
|
2009-07-09 06:59:17 +00:00
|
|
|
case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
|
|
|
|
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
|
2009-06-27 05:46:24 +00:00
|
|
|
O << '-';
|
|
|
|
PrintPICBaseSymbol();
|
|
|
|
break;
|
|
|
|
case X86II::MO_TLSGD: O << "@TLSGD"; break;
|
|
|
|
case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
|
|
|
|
case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
|
|
|
|
case X86II::MO_TPOFF: O << "@TPOFF"; break;
|
|
|
|
case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
|
|
|
|
case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
|
|
|
|
case X86II::MO_GOT: O << "@GOT"; break;
|
|
|
|
case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
|
2009-07-13 22:07:30 +00:00
|
|
|
case X86II::MO_PLT: O << "@PLT"; break;
|
2005-07-01 22:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-13 21:53:19 +00:00
|
|
|
/// print_pcrel_imm - This is used to print an immediate value that ends up
|
|
|
|
/// being encoded as a pc-relative value. These print slightly differently, for
|
|
|
|
/// example, a $ is not emitted.
|
|
|
|
void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Unknown pcrel immediate operand");
|
2009-07-13 21:53:19 +00:00
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
O << MO.getImm();
|
|
|
|
return;
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
printBasicBlockLabel(MO.getMBB(), false, false, VerboseAsm);
|
|
|
|
return;
|
2009-07-13 22:07:30 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
printSymbolOperand(MO);
|
2009-07-13 21:53:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 21:41:08 +00:00
|
|
|
|
|
|
|
void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
const char *Modifier) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
switch (MO.getType()) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("unknown operand type!");
|
2009-07-13 21:41:08 +00:00
|
|
|
case MachineOperand::MO_Register: {
|
|
|
|
assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
|
|
|
|
"Virtual registers should not make it this far!");
|
|
|
|
O << '%';
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT VT = (strcmp(Modifier+6,"64") == 0) ?
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
|
|
|
|
((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
|
2009-07-13 21:41:08 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, VT);
|
|
|
|
}
|
|
|
|
O << TRI->getAsmName(Reg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
O << '$' << MO.getImm();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
case MachineOperand::MO_ExternalSymbol: {
|
2009-07-13 21:48:33 +00:00
|
|
|
O << '$';
|
2009-07-13 21:41:08 +00:00
|
|
|
printSymbolOperand(MO);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
Reimplement rip-relative addressing in the X86-64 backend. The new
implementation primarily differs from the former in that the asmprinter
doesn't make a zillion decisions about whether or not something will be
RIP relative or not. Instead, those decisions are made by isel lowering
and propagated through to the asm printer. To achieve this, we:
1. Represent RIP relative addresses by setting the base of the X86 addr
mode to X86::RIP.
2. When ISel Lowering decides that it is safe to use RIP, it lowers to
X86ISD::WrapperRIP. When it is unsafe to use RIP, it lowers to
X86ISD::Wrapper as before.
3. This removes isRIPRel from X86ISelAddressMode, representing it with
a basereg of RIP instead.
4. The addressing mode matching logic in isel is greatly simplified.
5. The asmprinter is greatly simplified, notably the "NotRIPRel" predicate
passed through various printoperand routines is gone now.
6. The various symbol printing routines in asmprinter now no longer infer
when to emit (%rip), they just print the symbol.
I think this is a big improvement over the previous situation. It does have
two small caveats though: 1. I implemented a horrible "no-rip" modifier for
the inline asm "P" constraint modifier. This is a short term hack, there is
a much better, but more involved, solution. 2. I had to xfail an
-aggressive-remat testcase because it isn't handling the use of RIP in the
constant-pool reading instruction. This specific test is easy to fix without
-aggressive-remat, which I intend to do next.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74372 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-27 04:16:01 +00:00
|
|
|
const char *Modifier) {
|
2009-07-09 00:27:29 +00:00
|
|
|
const MachineOperand &BaseReg = MI->getOperand(Op);
|
|
|
|
const MachineOperand &IndexReg = MI->getOperand(Op+2);
|
2005-07-01 22:44:09 +00:00
|
|
|
const MachineOperand &DispSpec = MI->getOperand(Op+3);
|
|
|
|
|
2009-07-09 00:27:29 +00:00
|
|
|
// If we really don't want to print out (rip), don't.
|
|
|
|
bool HasBaseReg = BaseReg.getReg() != 0;
|
|
|
|
if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
|
|
|
|
BaseReg.getReg() == X86::RIP)
|
|
|
|
HasBaseReg = false;
|
2009-07-09 00:32:12 +00:00
|
|
|
|
|
|
|
// HasParenPart - True if we will print out the () part of the mem ref.
|
|
|
|
bool HasParenPart = IndexReg.getReg() || HasBaseReg;
|
|
|
|
|
|
|
|
if (DispSpec.isImm()) {
|
|
|
|
int DispVal = DispSpec.getImm();
|
|
|
|
if (DispVal || !HasParenPart)
|
|
|
|
O << DispVal;
|
|
|
|
} else {
|
|
|
|
assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
|
|
|
|
DispSpec.isJTI() || DispSpec.isSymbol());
|
2009-07-13 21:48:33 +00:00
|
|
|
printSymbolOperand(MI->getOperand(Op+3));
|
2009-07-09 00:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (HasParenPart) {
|
2009-07-09 00:27:29 +00:00
|
|
|
assert(IndexReg.getReg() != X86::ESP &&
|
|
|
|
"X86 doesn't allow scaling by ESP");
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '(';
|
2009-07-09 00:27:29 +00:00
|
|
|
if (HasBaseReg)
|
|
|
|
printOperand(MI, Op, Modifier);
|
2005-07-01 22:44:09 +00:00
|
|
|
|
|
|
|
if (IndexReg.getReg()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ',';
|
2009-07-09 00:27:29 +00:00
|
|
|
printOperand(MI, Op+2, Modifier);
|
|
|
|
unsigned ScaleVal = MI->getOperand(Op+1).getImm();
|
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,
|
Reimplement rip-relative addressing in the X86-64 backend. The new
implementation primarily differs from the former in that the asmprinter
doesn't make a zillion decisions about whether or not something will be
RIP relative or not. Instead, those decisions are made by isel lowering
and propagated through to the asm printer. To achieve this, we:
1. Represent RIP relative addresses by setting the base of the X86 addr
mode to X86::RIP.
2. When ISel Lowering decides that it is safe to use RIP, it lowers to
X86ISD::WrapperRIP. When it is unsafe to use RIP, it lowers to
X86ISD::Wrapper as before.
3. This removes isRIPRel from X86ISelAddressMode, representing it with
a basereg of RIP instead.
4. The addressing mode matching logic in isel is greatly simplified.
5. The asmprinter is greatly simplified, notably the "NotRIPRel" predicate
passed through various printoperand routines is gone now.
6. The various symbol printing routines in asmprinter now no longer infer
when to emit (%rip), they just print the symbol.
I think this is a big improvement over the previous situation. It does have
two small caveats though: 1. I implemented a horrible "no-rip" modifier for
the inline asm "P" constraint modifier. This is a short term hack, there is
a much better, but more involved, solution. 2. I had to xfail an
-aggressive-remat testcase because it isn't handling the use of RIP in the
constant-pool reading instruction. This specific test is easy to fix without
-aggressive-remat, which I intend to do next.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74372 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-27 04:16:01 +00:00
|
|
|
const char *Modifier) {
|
2009-04-08 21:14:34 +00:00
|
|
|
assert(isMem(MI, Op) && "Invalid memory reference!");
|
2009-07-09 00:27:29 +00:00
|
|
|
const MachineOperand &Segment = MI->getOperand(Op+4);
|
2009-04-08 21:14:34 +00:00
|
|
|
if (Segment.getReg()) {
|
2009-07-09 00:27:29 +00:00
|
|
|
printOperand(MI, Op+4, Modifier);
|
|
|
|
O << ':';
|
|
|
|
}
|
Reimplement rip-relative addressing in the X86-64 backend. The new
implementation primarily differs from the former in that the asmprinter
doesn't make a zillion decisions about whether or not something will be
RIP relative or not. Instead, those decisions are made by isel lowering
and propagated through to the asm printer. To achieve this, we:
1. Represent RIP relative addresses by setting the base of the X86 addr
mode to X86::RIP.
2. When ISel Lowering decides that it is safe to use RIP, it lowers to
X86ISD::WrapperRIP. When it is unsafe to use RIP, it lowers to
X86ISD::Wrapper as before.
3. This removes isRIPRel from X86ISelAddressMode, representing it with
a basereg of RIP instead.
4. The addressing mode matching logic in isel is greatly simplified.
5. The asmprinter is greatly simplified, notably the "NotRIPRel" predicate
passed through various printoperand routines is gone now.
6. The various symbol printing routines in asmprinter now no longer infer
when to emit (%rip), they just print the symbol.
I think this is a big improvement over the previous situation. It does have
two small caveats though: 1. I implemented a horrible "no-rip" modifier for
the inline asm "P" constraint modifier. This is a short term hack, there is
a much better, but more involved, solution. 2. I had to xfail an
-aggressive-remat testcase because it isn't handling the use of RIP in the
constant-pool reading instruction. This specific test is easy to fix without
-aggressive-remat, which I intend to do next.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74372 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-27 04:16:01 +00:00
|
|
|
printLeaMemReference(MI, Op, Modifier);
|
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';
|
2009-06-24 19:19:16 +00:00
|
|
|
else {
|
|
|
|
O << '-';
|
|
|
|
PrintPICBaseSymbol();
|
|
|
|
O << '\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
|
|
|
}
|
|
|
|
|
2009-06-24 19:19:16 +00:00
|
|
|
|
2006-02-18 00:15:05 +00:00
|
|
|
void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
|
2009-06-24 19:19:16 +00:00
|
|
|
PrintPICBaseSymbol();
|
|
|
|
O << '\n';
|
|
|
|
PrintPICBaseSymbol();
|
|
|
|
O << ':';
|
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,
|
2009-07-10 21:57:21 +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 << ' ';
|
|
|
|
|
2009-07-10 21:00:45 +00:00
|
|
|
if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStubPIC()) {
|
2009-07-10 20:47:30 +00:00
|
|
|
O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
|
|
|
<< '_' << uid << "_set_" << MBB->getNumber();
|
|
|
|
} else if (Subtarget->isPICStyleGOT()) {
|
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
|
|
|
O << "@GOTOFF";
|
2007-11-14 09:18:41 +00:00
|
|
|
} else
|
2008-02-28 00:43:03 +00:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2007-11-14 09:18:41 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 04:42:32 +00:00
|
|
|
bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode) {
|
2006-04-28 23:11:40 +00:00
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
switch (Mode) {
|
|
|
|
default: return true; // Unknown mode.
|
|
|
|
case 'b': // Print QImode register
|
2009-08-11 20:47:22 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i8);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
|
|
|
case 'h': // Print QImode high register
|
2009-08-11 20:47:22 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
|
|
|
case 'w': // Print HImode register
|
2009-08-11 20:47:22 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i16);
|
2006-04-28 23:11:40 +00:00
|
|
|
break;
|
|
|
|
case 'k': // Print SImode register
|
2009-08-11 20:47:22 +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
|
2009-08-11 20:47:22 +00:00
|
|
|
Reg = getX86SubSuperRegister(Reg, MVT::i64);
|
2007-10-29 03:09:07 +00:00
|
|
|
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
|
|
|
|
2009-07-13 21:48:33 +00:00
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
|
|
|
|
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-07-13 21:48:33 +00:00
|
|
|
if (MO.isImm())
|
|
|
|
O << MO.getImm();
|
|
|
|
else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol())
|
|
|
|
printSymbolOperand(MO);
|
2009-07-13 21:41:08 +00:00
|
|
|
else
|
2009-07-13 21:48:33 +00:00
|
|
|
printOperand(MI, OpNo);
|
2006-10-31 20:12:30 +00:00
|
|
|
return false;
|
2009-07-09 20:06:27 +00:00
|
|
|
|
|
|
|
case 'A': // Print '*' before a register (it must be a register)
|
2009-07-13 21:48:33 +00:00
|
|
|
if (MO.isReg()) {
|
2009-07-09 20:06:27 +00:00
|
|
|
O << '*';
|
|
|
|
printOperand(MI, OpNo);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
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
|
2009-07-13 21:48:33 +00:00
|
|
|
if (MO.isReg())
|
|
|
|
return printAsmMRegister(MO, ExtraCode[0]);
|
2007-03-25 02:01:03 +00:00
|
|
|
printOperand(MI, OpNo);
|
|
|
|
return false;
|
2008-06-28 11:08:09 +00:00
|
|
|
|
2009-07-07 23:28:22 +00:00
|
|
|
case 'P': // This is the operand of a call, treat specially.
|
2009-07-09 00:39:19 +00:00
|
|
|
print_pcrel_imm(MI, OpNo);
|
2007-03-25 01:44:57 +00:00
|
|
|
return false;
|
2009-06-26 22:00:19 +00:00
|
|
|
|
2009-07-13 21:48:33 +00:00
|
|
|
case 'n': // Negate the immediate or print a '-' before the operand.
|
2009-06-26 22:00:19 +00:00
|
|
|
// Note: this is a temporary solution. It should be handled target
|
|
|
|
// independently as part of the 'MC' work.
|
|
|
|
if (MO.isImm()) {
|
|
|
|
O << -MO.getImm();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
O << '-';
|
|
|
|
}
|
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.
|
Reimplement rip-relative addressing in the X86-64 backend. The new
implementation primarily differs from the former in that the asmprinter
doesn't make a zillion decisions about whether or not something will be
RIP relative or not. Instead, those decisions are made by isel lowering
and propagated through to the asm printer. To achieve this, we:
1. Represent RIP relative addresses by setting the base of the X86 addr
mode to X86::RIP.
2. When ISel Lowering decides that it is safe to use RIP, it lowers to
X86ISD::WrapperRIP. When it is unsafe to use RIP, it lowers to
X86ISD::Wrapper as before.
3. This removes isRIPRel from X86ISelAddressMode, representing it with
a basereg of RIP instead.
4. The addressing mode matching logic in isel is greatly simplified.
5. The asmprinter is greatly simplified, notably the "NotRIPRel" predicate
passed through various printoperand routines is gone now.
6. The various symbol printing routines in asmprinter now no longer infer
when to emit (%rip), they just print the symbol.
I think this is a big improvement over the previous situation. It does have
two small caveats though: 1. I implemented a horrible "no-rip" modifier for
the inline asm "P" constraint modifier. This is a short term hack, there is
a much better, but more involved, solution. 2. I had to xfail an
-aggressive-remat testcase because it isn't handling the use of RIP in the
constant-pool reading instruction. This specific test is easy to fix without
-aggressive-remat, which I intend to do next.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74372 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-27 04:16:01 +00:00
|
|
|
printMemReference(MI, OpNo, "no-rip");
|
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-06-20 07:03:18 +00:00
|
|
|
static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
|
|
|
|
// Convert registers in the addr mode according to subreg64.
|
|
|
|
for (unsigned i = 0; i != 4; ++i) {
|
|
|
|
if (!MI->getOperand(i).isReg()) continue;
|
|
|
|
|
|
|
|
unsigned Reg = MI->getOperand(i).getReg();
|
|
|
|
if (Reg == 0) continue;
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
MI->getOperand(i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
|
2009-06-20 07:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-06-19 00:47:33 +00:00
|
|
|
if (NewAsmPrinter) {
|
2009-06-20 07:03:18 +00:00
|
|
|
if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {
|
|
|
|
O << "\t";
|
|
|
|
printInlineAsm(MI);
|
|
|
|
return;
|
|
|
|
} else if (MI->isLabel()) {
|
|
|
|
printLabel(MI);
|
|
|
|
return;
|
|
|
|
} else if (MI->getOpcode() == TargetInstrInfo::DECLARE) {
|
|
|
|
printDeclare(MI);
|
|
|
|
return;
|
|
|
|
} else if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
|
|
|
|
printImplicitDef(MI);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-19 23:59:57 +00:00
|
|
|
O << "NEW: ";
|
2009-06-19 00:47:33 +00:00
|
|
|
MCInst TmpInst;
|
2009-06-20 00:49:26 +00:00
|
|
|
|
|
|
|
TmpInst.setOpcode(MI->getOpcode());
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
|
|
|
|
|
|
|
MCOperand MCOp;
|
|
|
|
if (MO.isReg()) {
|
2009-08-02 00:09:22 +00:00
|
|
|
MCOp = MCOperand::CreateReg(MO.getReg());
|
2009-06-20 00:49:26 +00:00
|
|
|
} else if (MO.isImm()) {
|
2009-08-02 00:09:22 +00:00
|
|
|
MCOp = MCOperand::CreateImm(MO.getImm());
|
2009-06-20 07:03:18 +00:00
|
|
|
} else if (MO.isMBB()) {
|
2009-08-02 00:09:22 +00:00
|
|
|
MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
|
|
|
|
MO.getMBB()->getNumber());
|
2009-06-20 00:49:26 +00:00
|
|
|
} else {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unimp");
|
2009-06-20 00:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TmpInst.addOperand(MCOp);
|
|
|
|
}
|
|
|
|
|
2009-06-20 07:59:10 +00:00
|
|
|
switch (TmpInst.getOpcode()) {
|
|
|
|
case X86::LEA64_32r:
|
|
|
|
// Handle the 'subreg rewriting' for the lea64_32mem operand.
|
2009-06-20 07:03:18 +00:00
|
|
|
lower_lea64_32mem(&TmpInst, 1);
|
2009-06-20 07:59:10 +00:00
|
|
|
break;
|
2009-06-20 00:49:26 +00:00
|
|
|
}
|
|
|
|
|
2009-06-19 00:47:33 +00:00
|
|
|
// FIXME: Convert TmpInst.
|
2009-06-19 23:59:57 +00:00
|
|
|
printInstruction(&TmpInst);
|
|
|
|
O << "OLD: ";
|
2009-06-19 00:47:33 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// Call the autogenerated instruction printer routines.
|
|
|
|
printInstruction(MI);
|
|
|
|
}
|
|
|
|
|
2009-07-21 18:38:57 +00:00
|
|
|
void X86ATTAsmPrinter::PrintGlobalVariable(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) {
|
2009-07-25 23:55:21 +00:00
|
|
|
if (GVar->getName() == "llvm.global_ctors")
|
2008-06-28 11:09:32 +00:00
|
|
|
O << ".reference .constructors_used\n";
|
2009-07-25 23:55:21 +00:00
|
|
|
else if (GVar->getName() == "llvm.global_dtors")
|
2008-06-28 11:09:32 +00:00
|
|
|
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
|
|
|
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string name = Mang->getMangledName(GVar);
|
2008-06-28 11:09:32 +00:00
|
|
|
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";
|
|
|
|
|
2009-08-05 05:21:07 +00:00
|
|
|
|
|
|
|
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-31 18:48:30 +00:00
|
|
|
const MCSection *TheSection =
|
2009-08-05 05:21:07 +00:00
|
|
|
getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
|
2009-07-24 03:49:17 +00:00
|
|
|
SwitchToSection(TheSection);
|
2008-07-09 13:27:16 +00:00
|
|
|
|
2009-08-04 05:35:56 +00:00
|
|
|
// FIXME: get this stuff from section kind flags.
|
2009-02-18 02:19:52 +00:00
|
|
|
if (C->isNullValue() && !GVar->hasSection() &&
|
2009-07-24 04:08:17 +00:00
|
|
|
// Don't put things that should go in the cstring section into "comm".
|
2009-07-27 05:32:16 +00:00
|
|
|
!TheSection->getKind().isMergeableCString()) {
|
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:
|
2009-07-20 01:03:30 +00:00
|
|
|
case GlobalValue::LinkerPrivateLinkage:
|
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:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (I->hasDLLExportLinkage())
|
2009-07-14 18:17:16 +00:00
|
|
|
DLLExportedGVs.insert(Mang->getMangledName(I));
|
2009-02-21 11:53:32 +00:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2009-08-03 21:53:27 +00:00
|
|
|
// All darwin targets use mach-o.
|
|
|
|
TargetLoweringObjectFileMachO &TLOFMacho =
|
|
|
|
static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
|
2009-06-24 18:24:09 +00:00
|
|
|
|
2009-06-24 18:17:00 +00:00
|
|
|
// Add the (possibly multiple) personalities to the set of global value
|
|
|
|
// stubs. Only referenced functions get into the Personalities list.
|
2008-06-28 11:08:27 +00:00
|
|
|
if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
|
2009-06-24 18:17:00 +00:00
|
|
|
const std::vector<Function*> &Personalities = MMI->getPersonalities();
|
|
|
|
for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
|
2009-07-14 18:17:16 +00:00
|
|
|
if (Personalities[i])
|
|
|
|
GVStubs[Mang->getMangledName(Personalities[i], "$non_lazy_ptr",
|
|
|
|
true /*private label*/)] =
|
|
|
|
Mang->getMangledName(Personalities[i]);
|
2008-07-08 00:55:58 +00:00
|
|
|
}
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 18:24:09 +00:00
|
|
|
// Output stubs for dynamically-linked functions
|
|
|
|
if (!FnStubs.empty()) {
|
2009-08-03 21:53:27 +00:00
|
|
|
const MCSection *TheSection =
|
2009-08-10 01:39:42 +00:00
|
|
|
TLOFMacho.getMachOSection("__IMPORT", "__jump_table",
|
|
|
|
MCSectionMachO::S_SYMBOL_STUBS |
|
|
|
|
MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE |
|
|
|
|
MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
|
|
|
|
5, SectionKind::getMetadata());
|
2009-08-03 21:53:27 +00:00
|
|
|
SwitchToSection(TheSection);
|
2009-07-14 18:17:16 +00:00
|
|
|
for (StringMap<std::string>::iterator I = FnStubs.begin(),
|
|
|
|
E = FnStubs.end(); I != E; ++I)
|
|
|
|
O << I->getKeyData() << ":\n" << "\t.indirect_symbol " << I->second
|
|
|
|
<< "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
|
2009-06-24 18:24:09 +00:00
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
|
2008-06-28 11:08:27 +00:00
|
|
|
// Output stubs for external and common global variables.
|
2009-06-24 18:24:09 +00:00
|
|
|
if (!GVStubs.empty()) {
|
2009-08-03 21:53:27 +00:00
|
|
|
const MCSection *TheSection =
|
2009-08-10 01:39:42 +00:00
|
|
|
TLOFMacho.getMachOSection("__IMPORT", "__pointers",
|
|
|
|
MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
|
2009-08-03 21:53:27 +00:00
|
|
|
SectionKind::getMetadata());
|
|
|
|
SwitchToSection(TheSection);
|
2009-07-14 18:17:16 +00:00
|
|
|
for (StringMap<std::string>::iterator I = GVStubs.begin(),
|
|
|
|
E = GVStubs.end(); I != E; ++I)
|
|
|
|
O << I->getKeyData() << ":\n\t.indirect_symbol "
|
|
|
|
<< I->second << "\n\t.long\t0\n";
|
2009-06-24 18:24:09 +00:00
|
|
|
}
|
2008-06-28 11:08:27 +00:00
|
|
|
|
2008-12-05 01:06:39 +00:00
|
|
|
if (!HiddenGVStubs.empty()) {
|
2009-07-28 03:13:23 +00:00
|
|
|
SwitchToSection(getObjFileLowering().getDataSection());
|
2009-06-24 18:24:42 +00:00
|
|
|
EmitAlignment(2);
|
2009-07-14 18:17:16 +00:00
|
|
|
for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
|
|
|
|
E = HiddenGVStubs.end(); I != E; ++I)
|
|
|
|
O << I->getKeyData() << ":\n" << TAI->getData32bitsDirective()
|
|
|
|
<< I->second << '\n';
|
2008-12-05 01:06:39 +00:00
|
|
|
}
|
|
|
|
|
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
|
2009-07-09 05:09:24 +00:00
|
|
|
for (StringSet<>::iterator i = CygMingStubs.begin(), e = CygMingStubs.end();
|
2008-06-28 11:08:27 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
2009-06-24 05:47:59 +00:00
|
|
|
|
2009-06-24 18:52:01 +00:00
|
|
|
|
|
|
|
// Output linker support code for dllexported globals on windows.
|
2009-08-03 21:53:27 +00:00
|
|
|
if (!DLLExportedGVs.empty() || !DLLExportedFns.empty()) {
|
|
|
|
// dllexport symbols only exist on coff targets.
|
|
|
|
TargetLoweringObjectFileCOFF &TLOFMacho =
|
|
|
|
static_cast<TargetLoweringObjectFileCOFF&>(getObjFileLowering());
|
|
|
|
|
|
|
|
SwitchToSection(TLOFMacho.getCOFFSection(".section .drectve", true,
|
|
|
|
SectionKind::getMetadata()));
|
2009-06-24 18:52:01 +00:00
|
|
|
|
|
|
|
for (StringSet<>::iterator i = DLLExportedGVs.begin(),
|
|
|
|
e = DLLExportedGVs.end(); i != e; ++i)
|
|
|
|
O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
|
|
|
|
|
|
|
|
for (StringSet<>::iterator i = DLLExportedFns.begin(),
|
|
|
|
e = DLLExportedFns.end();
|
|
|
|
i != e; ++i)
|
|
|
|
O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do common shutdown.
|
2009-07-27 21:28:04 +00:00
|
|
|
return AsmPrinter::doFinalization(M);
|
2008-06-28 11:08:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 22:44:09 +00:00
|
|
|
// Include the auto-generated portion of the assembly writer.
|
|
|
|
#include "X86GenAsmWriter.inc"
|