2004-08-17 07:15:22 +08:00
|
|
|
//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-08-17 07:15:22 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the AsmPrinter class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-03-03 10:04:29 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2006-03-02 06:18:09 +08:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
Teach the SelectionDAG ISel how to turn ConstantPacked values into
constant nodes with vector types. Also teach the asm printer how to print
ConstantPacked constant pool entries. This allows us to generate altivec
code such as the following, which adds a vector constantto a packed float.
LCPI1_0: <4 x float> < float 0.0e+0, float 0.0e+0, float 0.0e+0, float 1.0e+0 >
.space 4
.space 4
.space 4
.long 1065353216 ; float 1
.text
.align 4
.globl _foo
_foo:
lis r2, ha16(LCPI1_0)
la r2, lo16(LCPI1_0)(r2)
li r4, 0
lvx v0, r4, r2
lvx v1, r4, r3
vaddfp v0, v1, v0
stvx v0, r4, r3
blr
For the llvm code:
void %foo(<4 x float> * %a) {
entry:
%tmp1 = load <4 x float> * %a;
%tmp2 = add <4 x float> %tmp1, < float 0.0, float 0.0, float 0.0, float 1.0 >
store <4 x float> %tmp2, <4 x float> *%a
ret void
}
llvm-svn: 24616
2005-12-06 14:18:55 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2004-08-17 07:15:22 +08:00
|
|
|
#include "llvm/Constants.h"
|
2005-11-11 02:36:17 +08:00
|
|
|
#include "llvm/Module.h"
|
2010-01-17 05:57:06 +08:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2008-08-18 02:44:35 +08:00
|
|
|
#include "llvm/CodeGen/GCMetadataPrinter.h"
|
2005-11-21 16:25:09 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2009-11-14 05:34:57 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2009-08-19 03:22:55 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2006-04-23 02:53:45 +08:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2009-08-11 00:38:07 +08:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2007-12-31 12:13:23 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2009-05-07 21:55:51 +08:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-07-28 05:28:04 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2010-01-23 14:17:14 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2009-07-17 06:24:20 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-08-01 02:48:30 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-09-13 07:02:08 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2009-03-25 09:47:28 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-11 21:10:19 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-01-23 03:52:01 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2009-07-14 04:25:48 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2009-08-23 04:48:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2010-01-17 05:57:06 +08:00
|
|
|
#include "llvm/Target/Mangler.h"
|
2006-05-12 14:33:49 +08:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2009-11-14 05:34:57 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-10-07 06:50:56 +08:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2009-07-28 11:13:23 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2008-07-02 07:18:29 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2008-03-15 08:03:38 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
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
llvm-svn: 43924
2007-11-09 09:32:10 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2008-08-17 15:19:36 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
#include <cerrno>
|
2004-08-17 07:15:22 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-03-25 09:47:28 +08:00
|
|
|
static cl::opt<cl::boolOrDefault>
|
|
|
|
AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
|
|
|
|
cl::init(cl::BOU_UNSET));
|
|
|
|
|
2010-01-22 15:06:15 +08:00
|
|
|
static bool getVerboseAsm(bool VDef) {
|
|
|
|
switch (AsmVerbose) {
|
|
|
|
default:
|
|
|
|
case cl::BOU_UNSET: return VDef;
|
|
|
|
case cl::BOU_TRUE: return true;
|
|
|
|
case cl::BOU_FALSE: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char AsmPrinter::ID = 0;
|
2009-07-15 04:18:05 +08:00
|
|
|
AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
2009-08-23 04:48:53 +08:00
|
|
|
const MCAsmInfo *T, bool VDef)
|
2009-07-01 09:48:54 +08:00
|
|
|
: MachineFunctionPass(&ID), FunctionNumber(0), O(o),
|
2009-08-23 05:43:10 +08:00
|
|
|
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
2009-07-28 05:28:04 +08:00
|
|
|
|
|
|
|
OutContext(*new MCContext()),
|
2009-09-14 11:02:37 +08:00
|
|
|
// FIXME: Pass instprinter to streamer.
|
2010-01-20 14:39:07 +08:00
|
|
|
OutStreamer(*createAsmStreamer(OutContext, O, *T,
|
2010-01-22 15:06:15 +08:00
|
|
|
TM.getTargetData()->isLittleEndian(),
|
|
|
|
getVerboseAsm(VDef), 0)),
|
2009-07-28 05:28:04 +08:00
|
|
|
|
2010-01-16 14:09:35 +08:00
|
|
|
LastMI(0), LastFn(0), Counter(~0U), PrevDLT(NULL) {
|
2009-06-25 03:09:55 +08:00
|
|
|
DW = 0; MMI = 0;
|
2010-01-22 15:06:15 +08:00
|
|
|
VerboseAsm = getVerboseAsm(VDef);
|
2009-03-25 09:47:28 +08:00
|
|
|
}
|
2005-12-13 14:32:10 +08:00
|
|
|
|
2008-08-17 20:08:44 +08:00
|
|
|
AsmPrinter::~AsmPrinter() {
|
|
|
|
for (gcp_iterator I = GCMetadataPrinters.begin(),
|
|
|
|
E = GCMetadataPrinters.end(); I != E; ++I)
|
|
|
|
delete I->second;
|
2009-07-28 05:28:04 +08:00
|
|
|
|
|
|
|
delete &OutStreamer;
|
|
|
|
delete &OutContext;
|
2008-08-17 20:08:44 +08:00
|
|
|
}
|
2005-12-13 14:32:10 +08:00
|
|
|
|
2009-08-04 03:12:26 +08:00
|
|
|
TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
|
2009-07-28 11:13:23 +08:00
|
|
|
return TM.getTargetLowering()->getObjFileLowering();
|
|
|
|
}
|
|
|
|
|
2009-08-18 14:15:16 +08:00
|
|
|
/// getCurrentSection() - Return the current section we are emitting to.
|
|
|
|
const MCSection *AsmPrinter::getCurrentSection() const {
|
|
|
|
return OutStreamer.getCurrentSection();
|
2008-09-25 06:12:10 +08:00
|
|
|
}
|
2006-05-09 12:59:56 +08:00
|
|
|
|
2009-08-18 14:15:16 +08:00
|
|
|
|
2008-01-07 09:30:38 +08:00
|
|
|
void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
|
2009-08-01 07:37:33 +08:00
|
|
|
AU.setPreservesAll();
|
2008-01-07 09:30:38 +08:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2008-08-18 02:44:35 +08:00
|
|
|
AU.addRequired<GCModuleInfo>();
|
2009-08-19 03:22:55 +08:00
|
|
|
if (VerboseAsm)
|
2009-08-11 00:38:07 +08:00
|
|
|
AU.addRequired<MachineLoopInfo>();
|
2008-01-07 09:30:38 +08:00
|
|
|
}
|
|
|
|
|
2004-08-17 07:15:22 +08:00
|
|
|
bool AsmPrinter::doInitialization(Module &M) {
|
2009-08-01 01:42:42 +08:00
|
|
|
// Initialize TargetLoweringObjectFile.
|
|
|
|
const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
|
|
|
|
.Initialize(OutContext, TM);
|
|
|
|
|
2010-01-18 02:22:35 +08:00
|
|
|
Mang = new Mangler(*MAI);
|
2006-01-24 07:47:53 +08:00
|
|
|
|
2009-10-01 06:06:26 +08:00
|
|
|
// Allow the target to emit any magic that it wants at the start of the file.
|
|
|
|
EmitStartOfAsmFile(M);
|
2008-12-03 19:01:37 +08:00
|
|
|
|
2010-01-26 02:58:59 +08:00
|
|
|
// Very minimal debug info. It is ignored if we emit actual debug info. If we
|
|
|
|
// don't, this at least helps the user find where a global came from.
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->hasSingleParameterDotFile()) {
|
2010-01-26 02:58:59 +08:00
|
|
|
// .file "foo.c"
|
|
|
|
OutStreamer.EmitFileDirective(M.getModuleIdentifier());
|
2008-12-03 19:01:37 +08:00
|
|
|
}
|
|
|
|
|
2009-10-01 06:06:26 +08:00
|
|
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
|
|
|
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
|
2008-08-18 02:44:35 +08:00
|
|
|
for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
|
|
|
|
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
|
2009-08-23 05:43:10 +08:00
|
|
|
MP->beginAssembly(O, *this, *MAI);
|
2008-01-07 09:30:38 +08:00
|
|
|
|
2006-01-24 12:16:34 +08:00
|
|
|
if (!M.getModuleInlineAsm().empty())
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString() << " Start of file scope inline assembly\n"
|
2006-01-24 12:16:34 +08:00
|
|
|
<< M.getModuleInlineAsm()
|
2009-08-23 05:43:10 +08:00
|
|
|
<< '\n' << MAI->getCommentString()
|
2006-09-07 02:34:40 +08:00
|
|
|
<< " End of file scope inline assembly\n";
|
2006-01-24 07:47:53 +08:00
|
|
|
|
2009-09-24 13:44:53 +08:00
|
|
|
MMI = getAnalysisIfAvailable<MachineModuleInfo>();
|
|
|
|
if (MMI)
|
|
|
|
MMI->AnalyzeModule(M);
|
|
|
|
DW = getAnalysisIfAvailable<DwarfWriter>();
|
2009-11-14 15:22:25 +08:00
|
|
|
if (DW)
|
2009-09-24 13:44:53 +08:00
|
|
|
DW->BeginModule(&M, MMI, O, this, MAI);
|
2009-06-20 05:54:26 +08:00
|
|
|
|
2004-08-17 07:15:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-19 12:39:15 +08:00
|
|
|
/// EmitGlobalVariable - Emit the specified global variable to the .s file.
|
|
|
|
void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
|
|
|
|
if (!GV->hasInitializer()) // External globals require no code.
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
|
|
|
if (EmitSpecialLLVMGlobal(GV))
|
|
|
|
return;
|
2010-01-19 13:38:33 +08:00
|
|
|
|
|
|
|
MCSymbol *GVSym = GetGlobalValueSymbol(GV);
|
|
|
|
printVisibility(GVSym, GV->getVisibility());
|
|
|
|
|
2010-01-26 02:33:40 +08:00
|
|
|
if (MAI->hasDotTypeDotSizeDirective())
|
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_ELF_TypeObject);
|
2010-01-19 13:38:33 +08:00
|
|
|
|
|
|
|
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
|
|
|
|
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
unsigned Size = TD->getTypeAllocSize(GV->getType()->getElementType());
|
|
|
|
unsigned AlignLog = TD->getPreferredAlignmentLog(GV);
|
|
|
|
|
2010-01-19 13:51:42 +08:00
|
|
|
// Handle common and BSS local symbols (.lcomm).
|
|
|
|
if (GVKind.isCommon() || GVKind.isBSSLocal()) {
|
2010-01-19 13:38:33 +08:00
|
|
|
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
|
|
|
|
|
|
|
if (VerboseAsm) {
|
2010-01-23 03:52:01 +08:00
|
|
|
WriteAsOperand(OutStreamer.GetCommentOS(), GV,
|
|
|
|
/*PrintType=*/false, GV->getParent());
|
|
|
|
OutStreamer.GetCommentOS() << '\n';
|
2010-01-19 13:38:33 +08:00
|
|
|
}
|
2010-01-19 14:25:51 +08:00
|
|
|
|
|
|
|
// Handle common symbols.
|
2010-01-19 13:51:42 +08:00
|
|
|
if (GVKind.isCommon()) {
|
|
|
|
// .comm _foo, 42, 4
|
2010-01-19 14:01:04 +08:00
|
|
|
OutStreamer.EmitCommonSymbol(GVSym, Size, 1 << AlignLog);
|
2010-01-19 14:25:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle local BSS symbols.
|
|
|
|
if (MAI->hasMachoZeroFillDirective()) {
|
|
|
|
const MCSection *TheSection =
|
|
|
|
getObjFileLowering().SectionForGlobal(GV, GVKind, Mang, TM);
|
|
|
|
// .zerofill __DATA, __bss, _foo, 400, 5
|
|
|
|
OutStreamer.EmitZerofill(TheSection, GVSym, Size, 1 << AlignLog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-23 15:47:02 +08:00
|
|
|
if (MAI->hasLCOMMDirective()) {
|
2010-01-19 14:25:51 +08:00
|
|
|
// .lcomm _foo, 42
|
2010-01-23 15:47:02 +08:00
|
|
|
OutStreamer.EmitLocalCommonSymbol(GVSym, Size);
|
2010-01-19 14:25:51 +08:00
|
|
|
return;
|
2010-01-19 13:38:33 +08:00
|
|
|
}
|
2010-01-19 14:25:51 +08:00
|
|
|
|
|
|
|
// .local _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Local);
|
2010-01-19 14:25:51 +08:00
|
|
|
// .comm _foo, 42, 4
|
|
|
|
OutStreamer.EmitCommonSymbol(GVSym, Size, 1 << AlignLog);
|
2010-01-19 13:38:33 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-01-19 12:39:15 +08:00
|
|
|
|
2010-01-19 13:38:33 +08:00
|
|
|
const MCSection *TheSection =
|
|
|
|
getObjFileLowering().SectionForGlobal(GV, GVKind, Mang, TM);
|
|
|
|
|
|
|
|
// Handle the zerofill directive on darwin, which is a special form of BSS
|
|
|
|
// emission.
|
|
|
|
if (GVKind.isBSSExtern() && MAI->hasMachoZeroFillDirective()) {
|
|
|
|
// .globl _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
2010-01-19 13:38:33 +08:00
|
|
|
// .zerofill __DATA, __common, _foo, 400, 5
|
|
|
|
OutStreamer.EmitZerofill(TheSection, GVSym, Size, 1 << AlignLog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutStreamer.SwitchSection(TheSection);
|
|
|
|
|
|
|
|
// TODO: Factor into an 'emit linkage' thing that is shared with function
|
|
|
|
// bodies.
|
|
|
|
switch (GV->getLinkage()) {
|
|
|
|
case GlobalValue::CommonLinkage:
|
|
|
|
case GlobalValue::LinkOnceAnyLinkage:
|
|
|
|
case GlobalValue::LinkOnceODRLinkage:
|
|
|
|
case GlobalValue::WeakAnyLinkage:
|
|
|
|
case GlobalValue::WeakODRLinkage:
|
|
|
|
case GlobalValue::LinkerPrivateLinkage:
|
2010-01-19 14:41:24 +08:00
|
|
|
if (MAI->getWeakDefDirective() != 0) {
|
2010-01-19 13:38:33 +08:00
|
|
|
// .globl _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
2010-01-19 13:38:33 +08:00
|
|
|
// .weak_definition _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_WeakDefinition);
|
2010-01-19 13:38:33 +08:00
|
|
|
} else if (const char *LinkOnce = MAI->getLinkOnceDirective()) {
|
|
|
|
// .globl _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
2010-01-26 02:58:59 +08:00
|
|
|
// FIXME: linkonce should be a section attribute, handled by COFF Section
|
|
|
|
// assignment.
|
|
|
|
// http://sourceware.org/binutils/docs-2.20/as/Linkonce.html#Linkonce
|
2010-01-19 13:38:33 +08:00
|
|
|
// .linkonce same_size
|
|
|
|
O << LinkOnce;
|
2010-01-19 14:41:24 +08:00
|
|
|
} else {
|
|
|
|
// .weak _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
|
2010-01-19 14:41:24 +08:00
|
|
|
}
|
2010-01-19 13:38:33 +08:00
|
|
|
break;
|
|
|
|
case GlobalValue::DLLExportLinkage:
|
|
|
|
case GlobalValue::AppendingLinkage:
|
|
|
|
// FIXME: appending linkage variables should go into a section of
|
|
|
|
// their name or something. For now, just emit them as external.
|
|
|
|
case GlobalValue::ExternalLinkage:
|
|
|
|
// If external or appending, declare as a global symbol.
|
|
|
|
// .globl _foo
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
|
2010-01-19 13:38:33 +08:00
|
|
|
break;
|
|
|
|
case GlobalValue::PrivateLinkage:
|
|
|
|
case GlobalValue::InternalLinkage:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown linkage type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitAlignment(AlignLog, GV);
|
|
|
|
if (VerboseAsm) {
|
2010-01-23 03:52:01 +08:00
|
|
|
WriteAsOperand(OutStreamer.GetCommentOS(), GV,
|
|
|
|
/*PrintType=*/false, GV->getParent());
|
|
|
|
OutStreamer.GetCommentOS() << '\n';
|
2010-01-19 13:38:33 +08:00
|
|
|
}
|
2010-01-19 14:41:24 +08:00
|
|
|
OutStreamer.EmitLabel(GVSym);
|
2010-01-19 13:38:33 +08:00
|
|
|
|
|
|
|
EmitGlobalConstant(GV->getInitializer());
|
|
|
|
|
|
|
|
if (MAI->hasDotTypeDotSizeDirective())
|
2010-01-25 15:53:05 +08:00
|
|
|
// .size foo, 42
|
2010-01-25 15:52:13 +08:00
|
|
|
OutStreamer.EmitELFSize(GVSym, MCConstantExpr::Create(Size, OutContext));
|
2010-01-23 03:52:01 +08:00
|
|
|
|
|
|
|
OutStreamer.AddBlankLine();
|
2010-01-19 12:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-17 07:15:22 +08:00
|
|
|
bool AsmPrinter::doFinalization(Module &M) {
|
2009-07-22 02:38:57 +08:00
|
|
|
// Emit global variables.
|
|
|
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ++I)
|
2010-01-19 12:39:15 +08:00
|
|
|
EmitGlobalVariable(I);
|
2009-07-22 02:38:57 +08:00
|
|
|
|
2009-06-25 02:54:37 +08:00
|
|
|
// Emit final debug information.
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling())
|
2009-06-25 02:54:37 +08:00
|
|
|
DW->EndModule();
|
|
|
|
|
2009-06-25 02:52:01 +08:00
|
|
|
// If the target wants to know about weak references, print them all.
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->getWeakRefDirective()) {
|
2009-06-25 02:52:01 +08:00
|
|
|
// FIXME: This is not lazy, it would be nice to only print weak references
|
|
|
|
// to stuff that is actually used. Note that doing so would require targets
|
|
|
|
// to notice uses in operands (due to constant exprs etc). This should
|
|
|
|
// happen with the MC stuff eventually.
|
|
|
|
|
|
|
|
// Print out module-level global variables here.
|
|
|
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ++I) {
|
2010-01-17 02:17:26 +08:00
|
|
|
if (!I->hasExternalWeakLinkage()) continue;
|
2010-01-23 13:19:23 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(I),
|
2010-01-23 14:39:22 +08:00
|
|
|
MCSA_WeakReference);
|
2009-06-25 02:52:01 +08:00
|
|
|
}
|
|
|
|
|
2009-08-04 07:10:34 +08:00
|
|
|
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
2010-01-17 02:17:26 +08:00
|
|
|
if (!I->hasExternalWeakLinkage()) continue;
|
2010-01-23 13:19:23 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(I),
|
2010-01-23 14:39:22 +08:00
|
|
|
MCSA_WeakReference);
|
2009-06-25 02:52:01 +08:00
|
|
|
}
|
2006-12-18 11:37:18 +08:00
|
|
|
}
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->getSetDirective()) {
|
2010-01-23 13:51:36 +08:00
|
|
|
OutStreamer.AddBlankLine();
|
2007-04-25 22:27:10 +08:00
|
|
|
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
|
2009-06-25 02:52:01 +08:00
|
|
|
I != E; ++I) {
|
2010-01-16 09:17:26 +08:00
|
|
|
MCSymbol *Name = GetGlobalValueSymbol(I);
|
2007-09-07 01:21:48 +08:00
|
|
|
|
|
|
|
const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
|
2010-01-16 09:17:26 +08:00
|
|
|
MCSymbol *Target = GetGlobalValueSymbol(GV);
|
|
|
|
|
2010-01-18 05:43:43 +08:00
|
|
|
if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(Name, MCSA_Global);
|
2010-01-18 05:43:43 +08:00
|
|
|
else if (I->hasWeakLinkage())
|
2010-01-23 14:39:22 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(Name, MCSA_WeakReference);
|
2010-01-18 05:43:43 +08:00
|
|
|
else
|
2010-01-16 09:37:14 +08:00
|
|
|
assert(I->hasLocalLinkage() && "Invalid alias linkage");
|
2008-03-12 05:41:14 +08:00
|
|
|
|
2008-09-25 06:21:04 +08:00
|
|
|
printVisibility(Name, I->getVisibility());
|
2008-03-12 05:41:14 +08:00
|
|
|
|
2010-01-18 05:43:43 +08:00
|
|
|
O << MAI->getSetDirective() << ' ' << *Name << ", " << *Target << '\n';
|
2007-04-25 22:27:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 21:14:17 +08:00
|
|
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
2008-08-18 02:44:35 +08:00
|
|
|
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
|
|
|
|
for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
|
|
|
|
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
|
2009-08-23 05:43:10 +08:00
|
|
|
MP->finishAssembly(O, *this, *MAI);
|
2008-01-07 09:30:38 +08:00
|
|
|
|
2008-05-05 08:28:39 +08:00
|
|
|
// If we don't have any trampolines, then we don't require stack memory
|
|
|
|
// to be executable. Some targets have a directive to declare this.
|
2009-06-25 02:52:01 +08:00
|
|
|
Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
|
2008-05-05 08:28:39 +08:00
|
|
|
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
|
2010-01-23 15:21:06 +08:00
|
|
|
if (MCSection *S = MAI->getNonexecutableStackSection(OutContext))
|
|
|
|
OutStreamer.SwitchSection(S);
|
2009-09-19 04:17:03 +08:00
|
|
|
|
|
|
|
// Allow the target to emit any magic that it wants at the end of the file,
|
|
|
|
// after everything else has gone out.
|
|
|
|
EmitEndOfAsmFile(M);
|
|
|
|
|
2004-08-17 07:15:22 +08:00
|
|
|
delete Mang; Mang = 0;
|
2009-06-25 03:09:55 +08:00
|
|
|
DW = 0; MMI = 0;
|
2009-07-28 05:28:04 +08:00
|
|
|
|
|
|
|
OutStreamer.Finish();
|
2004-08-17 07:15:22 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-11-21 15:51:36 +08:00
|
|
|
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
|
2010-01-16 09:24:10 +08:00
|
|
|
// Get the function symbol.
|
2010-01-16 07:55:16 +08:00
|
|
|
CurrentFnSym = GetGlobalValueSymbol(MF.getFunction());
|
2007-10-14 13:57:21 +08:00
|
|
|
IncrementFunctionNumber();
|
2009-08-11 00:38:07 +08:00
|
|
|
|
2009-09-16 08:35:39 +08:00
|
|
|
if (VerboseAsm)
|
2009-08-11 00:38:07 +08:00
|
|
|
LI = &getAnalysis<MachineLoopInfo>();
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
|
|
|
|
2009-03-13 15:51:59 +08:00
|
|
|
namespace {
|
|
|
|
// SectionCPs - Keep track the alignment, constpool entries per Section.
|
|
|
|
struct SectionCPs {
|
2009-08-01 02:48:30 +08:00
|
|
|
const MCSection *S;
|
2009-03-13 15:51:59 +08:00
|
|
|
unsigned Alignment;
|
|
|
|
SmallVector<unsigned, 4> CPEs;
|
2009-12-19 15:05:23 +08:00
|
|
|
SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {}
|
2009-03-13 15:51:59 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-11-21 16:25:09 +08:00
|
|
|
/// EmitConstantPool - Print to the current output stream assembly
|
|
|
|
/// representations of the constants in the constant pool MCP. This is
|
|
|
|
/// used to print out constants which have been "spilled to memory" by
|
|
|
|
/// the code generator.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
|
2006-02-09 12:22:52 +08:00
|
|
|
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
|
2005-11-21 16:25:09 +08:00
|
|
|
if (CP.empty()) return;
|
2006-06-29 08:26:09 +08:00
|
|
|
|
2008-09-25 06:17:59 +08:00
|
|
|
// Calculate sections for constant pool entries. We collect entries to go into
|
|
|
|
// the same section together to reduce amount of section switch statements.
|
2009-03-13 15:51:59 +08:00
|
|
|
SmallVector<SectionCPs, 4> CPSections;
|
2006-06-29 08:26:09 +08:00
|
|
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
2009-07-22 08:28:43 +08:00
|
|
|
const MachineConstantPoolEntry &CPE = CP[i];
|
2009-03-13 15:51:59 +08:00
|
|
|
unsigned Align = CPE.getAlignment();
|
2009-07-26 14:26:55 +08:00
|
|
|
|
|
|
|
SectionKind Kind;
|
|
|
|
switch (CPE.getRelocationInfo()) {
|
|
|
|
default: llvm_unreachable("Unknown section kind");
|
2009-08-02 07:57:16 +08:00
|
|
|
case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
|
2009-07-26 15:00:12 +08:00
|
|
|
case 1:
|
2009-08-02 07:57:16 +08:00
|
|
|
Kind = SectionKind::getReadOnlyWithRelLocal();
|
2009-07-26 15:00:12 +08:00
|
|
|
break;
|
2009-07-26 14:26:55 +08:00
|
|
|
case 0:
|
2009-07-26 15:00:12 +08:00
|
|
|
switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
|
2009-08-02 07:57:16 +08:00
|
|
|
case 4: Kind = SectionKind::getMergeableConst4(); break;
|
|
|
|
case 8: Kind = SectionKind::getMergeableConst8(); break;
|
|
|
|
case 16: Kind = SectionKind::getMergeableConst16();break;
|
|
|
|
default: Kind = SectionKind::getMergeableConst(); break;
|
2009-07-26 15:00:12 +08:00
|
|
|
}
|
2009-07-26 14:26:55 +08:00
|
|
|
}
|
|
|
|
|
2009-08-02 07:46:12 +08:00
|
|
|
const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);
|
2009-07-22 08:28:43 +08:00
|
|
|
|
2009-03-13 15:51:59 +08:00
|
|
|
// The number of sections are small, just do a linear search from the
|
|
|
|
// last section to the first.
|
|
|
|
bool Found = false;
|
|
|
|
unsigned SecIdx = CPSections.size();
|
|
|
|
while (SecIdx != 0) {
|
|
|
|
if (CPSections[--SecIdx].S == S) {
|
|
|
|
Found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Found) {
|
|
|
|
SecIdx = CPSections.size();
|
|
|
|
CPSections.push_back(SectionCPs(S, Align));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Align > CPSections[SecIdx].Alignment)
|
|
|
|
CPSections[SecIdx].Alignment = Align;
|
|
|
|
CPSections[SecIdx].CPEs.push_back(i);
|
2006-06-29 08:26:09 +08:00
|
|
|
}
|
|
|
|
|
2008-09-25 06:17:59 +08:00
|
|
|
// Now print stuff into the calculated sections.
|
2009-03-13 15:51:59 +08:00
|
|
|
for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
|
2009-08-19 13:49:37 +08:00
|
|
|
OutStreamer.SwitchSection(CPSections[i].S);
|
2009-03-13 15:51:59 +08:00
|
|
|
EmitAlignment(Log2_32(CPSections[i].Alignment));
|
2006-06-29 08:26:09 +08:00
|
|
|
|
2009-03-13 15:51:59 +08:00
|
|
|
unsigned Offset = 0;
|
|
|
|
for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
|
|
|
|
unsigned CPI = CPSections[i].CPEs[j];
|
|
|
|
MachineConstantPoolEntry CPE = CP[CPI];
|
|
|
|
|
|
|
|
// Emit inter-object padding for alignment.
|
|
|
|
unsigned AlignMask = CPE.getAlignment() - 1;
|
|
|
|
unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
|
2010-01-20 03:46:13 +08:00
|
|
|
OutStreamer.EmitFill(NewOffset - Offset, 0/*fillval*/, 0/*addrspace*/);
|
2009-03-13 15:51:59 +08:00
|
|
|
|
|
|
|
const Type *Ty = CPE.getType();
|
2009-05-09 15:06:46 +08:00
|
|
|
Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
|
2006-06-29 08:26:09 +08:00
|
|
|
|
2010-01-23 13:19:23 +08:00
|
|
|
// Emit the label with a comment on it.
|
2009-03-13 15:51:59 +08:00
|
|
|
if (VerboseAsm) {
|
2010-01-23 13:19:23 +08:00
|
|
|
OutStreamer.GetCommentOS() << "constant pool ";
|
|
|
|
WriteTypeSymbolic(OutStreamer.GetCommentOS(), CPE.getType(),
|
|
|
|
MF->getFunction()->getParent());
|
|
|
|
OutStreamer.GetCommentOS() << '\n';
|
2009-03-13 15:51:59 +08:00
|
|
|
}
|
2010-01-23 13:19:23 +08:00
|
|
|
OutStreamer.EmitLabel(GetCPISymbol(CPI));
|
|
|
|
|
2009-03-13 15:51:59 +08:00
|
|
|
if (CPE.isMachineConstantPoolEntry())
|
|
|
|
EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
|
2008-09-25 06:17:59 +08:00
|
|
|
else
|
2009-03-13 15:51:59 +08:00
|
|
|
EmitGlobalConstant(CPE.Val.ConstVal);
|
2006-02-09 12:46:04 +08:00
|
|
|
}
|
2005-11-21 16:25:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-23 02:53:45 +08:00
|
|
|
/// EmitJumpTableInfo - Print assembly representations of the jump tables used
|
|
|
|
/// by the current function to the current output stream.
|
|
|
|
///
|
2006-10-05 11:01:21 +08:00
|
|
|
void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
|
|
|
MachineFunction &MF) {
|
2006-04-23 02:53:45 +08:00
|
|
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
|
|
|
if (JT.empty()) return;
|
2007-11-14 17:18:41 +08:00
|
|
|
|
2006-12-15 03:17:33 +08:00
|
|
|
bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
|
2006-07-28 00:46:58 +08:00
|
|
|
|
2006-07-27 09:13:04 +08:00
|
|
|
// Pick the directive to use to print the jump table entries, and switch to
|
|
|
|
// the appropriate section.
|
2006-12-15 03:17:33 +08:00
|
|
|
TargetLowering *LoweringInfo = TM.getTargetLowering();
|
2006-12-20 05:04:20 +08:00
|
|
|
|
2008-07-09 21:27:16 +08:00
|
|
|
const Function *F = MF.getFunction();
|
2009-06-19 04:37:15 +08:00
|
|
|
bool JTInDiffSection = false;
|
2009-08-02 07:46:12 +08:00
|
|
|
if (F->isWeakForLinker() ||
|
|
|
|
(IsPic && !LoweringInfo->usesGlobalOffsetTable())) {
|
2006-12-15 03:17:33 +08:00
|
|
|
// In PIC mode, we need to emit the jump table to the same section as the
|
|
|
|
// function body itself, otherwise the label differences won't make sense.
|
2008-07-09 21:27:16 +08:00
|
|
|
// We should also do if the section name is NULL or function is declared in
|
|
|
|
// discardable section.
|
2009-08-19 13:49:37 +08:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang,
|
|
|
|
TM));
|
2006-07-27 09:13:04 +08:00
|
|
|
} else {
|
2009-08-02 07:46:12 +08:00
|
|
|
// Otherwise, drop it in the readonly section.
|
|
|
|
const MCSection *ReadOnlySection =
|
2009-08-02 07:57:16 +08:00
|
|
|
getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());
|
2009-08-19 13:49:37 +08:00
|
|
|
OutStreamer.SwitchSection(ReadOnlySection);
|
2009-06-19 04:37:15 +08:00
|
|
|
JTInDiffSection = true;
|
2006-07-27 09:13:04 +08:00
|
|
|
}
|
2006-12-15 03:17:33 +08:00
|
|
|
|
|
|
|
EmitAlignment(Log2_32(MJTI->getAlignment()));
|
2006-07-15 09:34:12 +08:00
|
|
|
|
2006-04-23 02:53:45 +08:00
|
|
|
for (unsigned i = 0, e = JT.size(); i != e; ++i) {
|
2006-08-13 05:29:52 +08:00
|
|
|
const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
|
2006-10-29 02:10:06 +08:00
|
|
|
|
|
|
|
// If this jump table was deleted, ignore it.
|
|
|
|
if (JTBBs.empty()) continue;
|
2006-08-13 05:29:52 +08:00
|
|
|
|
|
|
|
// For PIC codegen, if possible we want to use the SetDirective to reduce
|
|
|
|
// the number of relocations the assembler will generate for the jump table.
|
|
|
|
// Set directives are all printed before the jump table itself.
|
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
llvm-svn: 43924
2007-11-09 09:32:10 +08:00
|
|
|
SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->getSetDirective() && IsPic)
|
2006-08-13 05:29:52 +08:00
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
|
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
llvm-svn: 43924
2007-11-09 09:32:10 +08:00
|
|
|
if (EmittedSets.insert(JTBBs[ii]))
|
|
|
|
printPICJumpTableSetLabel(i, JTBBs[ii]);
|
2006-08-13 05:29:52 +08:00
|
|
|
|
2009-09-14 03:02:16 +08:00
|
|
|
// On some targets (e.g. Darwin) we want to emit two consequtive labels
|
2007-01-18 09:12:56 +08:00
|
|
|
// before each jump table. The first label is never referenced, but tells
|
|
|
|
// the assembler and linker the extents of the jump table object. The
|
|
|
|
// second label is actually referenced by the code.
|
2010-01-23 13:19:23 +08:00
|
|
|
if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0])
|
|
|
|
OutStreamer.EmitLabel(GetJTISymbol(i, true));
|
|
|
|
|
|
|
|
OutStreamer.EmitLabel(GetJTISymbol(i));
|
|
|
|
|
2010-01-26 05:01:58 +08:00
|
|
|
if (!IsPic) {
|
|
|
|
unsigned EntrySize = MJTI->getEntrySize();
|
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
|
|
|
|
MCSymbol *MBBSym = GetMBBSymbol(JTBBs[ii]->getNumber());
|
|
|
|
OutStreamer.EmitValue(MCSymbolRefExpr::Create(MBBSym, OutContext),
|
|
|
|
EntrySize, /*addrspace*/0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
|
|
|
|
printPICJumpTableEntry(MJTI, JTBBs[ii], i);
|
2006-04-23 02:53:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 17:18:41 +08:00
|
|
|
void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
|
|
|
const MachineBasicBlock *MBB,
|
|
|
|
unsigned uid) const {
|
|
|
|
// Use JumpTableDirective otherwise honor the entry size from the jump table
|
|
|
|
// info.
|
2010-01-26 05:01:58 +08:00
|
|
|
const char *JTEntryDirective = MAI->getPICJumpTableDirective();
|
2007-11-14 17:18:41 +08:00
|
|
|
bool HadJTEntryDirective = JTEntryDirective != NULL;
|
|
|
|
if (!HadJTEntryDirective) {
|
|
|
|
JTEntryDirective = MJTI->getEntrySize() == 4 ?
|
2009-08-23 05:43:10 +08:00
|
|
|
MAI->getData32bitsDirective() : MAI->getData64bitsDirective();
|
2007-11-14 17:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
O << JTEntryDirective << ' ';
|
|
|
|
|
|
|
|
// If we have emitted set directives for the jump table entries, print
|
|
|
|
// them rather than the entries themselves. If we're emitting PIC, then
|
|
|
|
// emit the table entries as differences between two text section labels.
|
|
|
|
// If we're emitting non-PIC code, then emit the entries as direct
|
|
|
|
// references to the target basic blocks.
|
2010-01-26 05:01:58 +08:00
|
|
|
if (MAI->getSetDirective()) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
2009-08-12 04:29:57 +08:00
|
|
|
<< '_' << uid << "_set_" << MBB->getNumber();
|
2007-11-14 17:18:41 +08:00
|
|
|
} else {
|
2010-01-18 05:43:43 +08:00
|
|
|
O << *GetMBBSymbol(MBB->getNumber());
|
2009-08-12 04:29:57 +08:00
|
|
|
// If the arch uses custom Jump Table directives, don't calc relative to
|
2010-01-23 13:51:36 +08:00
|
|
|
// JT.
|
2009-08-12 04:29:57 +08:00
|
|
|
if (!HadJTEntryDirective)
|
2010-01-23 13:19:23 +08:00
|
|
|
O << '-' << *GetJTISymbol(uid);
|
2007-11-14 17:18:41 +08:00
|
|
|
}
|
2010-01-26 05:01:58 +08:00
|
|
|
O << '\n';
|
2007-11-14 17:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-13 14:32:10 +08:00
|
|
|
/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
|
|
|
|
/// special global used by LLVM. If so, emit it and return true, otherwise
|
|
|
|
/// do nothing and return false.
|
|
|
|
bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
|
2009-07-26 07:55:21 +08:00
|
|
|
if (GV->getName() == "llvm.used") {
|
2010-01-23 13:51:36 +08:00
|
|
|
if (MAI->hasNoDeadStrip()) // No need to emit this at all.
|
2007-08-23 03:33:11 +08:00
|
|
|
EmitLLVMUsedList(GV->getInitializer());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-20 14:14:25 +08:00
|
|
|
// Ignore debug and non-emitted data. This handles llvm.compiler.used.
|
2009-04-13 13:44:34 +08:00
|
|
|
if (GV->getSection() == "llvm.metadata" ||
|
|
|
|
GV->hasAvailableExternallyLinkage())
|
|
|
|
return true;
|
2006-03-08 06:00:35 +08:00
|
|
|
|
|
|
|
if (!GV->hasAppendingLinkage()) return false;
|
|
|
|
|
|
|
|
assert(GV->hasInitializer() && "Not a special LLVM global!");
|
2005-12-13 14:32:10 +08:00
|
|
|
|
2007-06-05 04:39:18 +08:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
unsigned Align = Log2_32(TD->getPointerPrefAlignment());
|
2009-03-09 13:52:15 +08:00
|
|
|
if (GV->getName() == "llvm.global_ctors") {
|
2009-08-19 13:49:37 +08:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
|
2009-03-09 16:18:48 +08:00
|
|
|
EmitAlignment(Align, 0);
|
|
|
|
EmitXXStructorList(GV->getInitializer());
|
2010-01-19 12:34:02 +08:00
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::Static &&
|
2010-01-23 13:51:36 +08:00
|
|
|
MAI->hasStaticCtorDtorReferenceInStaticMode()) {
|
|
|
|
StringRef Sym(".constructors_used");
|
|
|
|
OutStreamer.EmitSymbolAttribute(OutContext.GetOrCreateSymbol(Sym),
|
2010-01-23 14:39:22 +08:00
|
|
|
MCSA_Reference);
|
2010-01-23 13:51:36 +08:00
|
|
|
}
|
2009-03-09 16:18:48 +08:00
|
|
|
return true;
|
2005-12-13 14:32:10 +08:00
|
|
|
}
|
|
|
|
|
2009-03-09 13:52:15 +08:00
|
|
|
if (GV->getName() == "llvm.global_dtors") {
|
2009-08-19 13:49:37 +08:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
|
2009-03-09 16:18:48 +08:00
|
|
|
EmitAlignment(Align, 0);
|
|
|
|
EmitXXStructorList(GV->getInitializer());
|
2010-01-19 12:34:02 +08:00
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::Static &&
|
2010-01-23 13:51:36 +08:00
|
|
|
MAI->hasStaticCtorDtorReferenceInStaticMode()) {
|
|
|
|
StringRef Sym(".destructors_used");
|
|
|
|
OutStreamer.EmitSymbolAttribute(OutContext.GetOrCreateSymbol(Sym),
|
2010-01-23 14:39:22 +08:00
|
|
|
MCSA_Reference);
|
2010-01-23 13:51:36 +08:00
|
|
|
}
|
2009-03-09 16:18:48 +08:00
|
|
|
return true;
|
2005-12-13 14:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
/// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
|
2008-09-10 06:29:13 +08:00
|
|
|
/// global in the specified llvm.used list for which emitUsedDirectiveFor
|
|
|
|
/// is true, as being used with this directive.
|
2006-09-26 11:38:18 +08:00
|
|
|
void AsmPrinter::EmitLLVMUsedList(Constant *List) {
|
2009-06-15 07:30:43 +08:00
|
|
|
// Should be an array of 'i8*'.
|
2006-09-26 11:38:18 +08:00
|
|
|
ConstantArray *InitList = dyn_cast<ConstantArray>(List);
|
|
|
|
if (InitList == 0) return;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
2009-07-18 06:00:23 +08:00
|
|
|
const GlobalValue *GV =
|
|
|
|
dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
|
2010-01-23 13:51:36 +08:00
|
|
|
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang))
|
|
|
|
OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(GV),
|
2010-01-23 14:39:22 +08:00
|
|
|
MCSA_NoDeadStrip);
|
2006-09-26 11:38:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-13 14:32:10 +08:00
|
|
|
/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
|
|
|
|
/// function pointers, ignoring the init priority.
|
|
|
|
void AsmPrinter::EmitXXStructorList(Constant *List) {
|
|
|
|
// Should be an array of '{ int, void ()* }' structs. The first value is the
|
|
|
|
// init priority, which we ignore.
|
|
|
|
if (!isa<ConstantArray>(List)) return;
|
|
|
|
ConstantArray *InitList = cast<ConstantArray>(List);
|
|
|
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
|
|
|
|
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
|
|
|
|
if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
|
2005-12-21 09:17:37 +08:00
|
|
|
|
|
|
|
if (CS->getOperand(1)->isNullValue())
|
|
|
|
return; // Found a null terminator, exit printing.
|
|
|
|
// Emit the function pointer.
|
2005-12-13 14:32:10 +08:00
|
|
|
EmitGlobalConstant(CS->getOperand(1));
|
|
|
|
}
|
|
|
|
}
|
2005-11-21 16:25:09 +08:00
|
|
|
|
2007-01-25 23:12:02 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Emission and print routines
|
|
|
|
//
|
|
|
|
|
|
|
|
/// EmitInt8 - Emit a byte directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt8(int Value) const {
|
2010-01-20 14:45:39 +08:00
|
|
|
OutStreamer.EmitIntValue(Value, 1, 0/*addrspace*/);
|
2007-01-25 23:12:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt16 - Emit a short directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt16(int Value) const {
|
2010-01-20 14:45:39 +08:00
|
|
|
OutStreamer.EmitIntValue(Value, 2, 0/*addrspace*/);
|
2007-01-25 23:12:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt32 - Emit a long directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt32(int Value) const {
|
2010-01-20 14:45:39 +08:00
|
|
|
OutStreamer.EmitIntValue(Value, 4, 0/*addrspace*/);
|
2007-01-25 23:12:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt64 - Emit a long long directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt64(uint64_t Value) const {
|
2010-01-20 14:45:39 +08:00
|
|
|
OutStreamer.EmitIntValue(Value, 8, 0/*addrspace*/);
|
2007-01-25 23:12:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-06-01 02:57:45 +08:00
|
|
|
// EmitAlignment - Emit an alignment directive to the specified power of
|
|
|
|
// two boundary. For example, if you pass in 3 here, you will get an 8
|
|
|
|
// byte alignment. If a global value is specified, and if that global has
|
|
|
|
// an explicit alignment requested, it will unconditionally override the
|
|
|
|
// alignment request. However, if ForcedAlignBits is specified, this value
|
|
|
|
// has final say: the ultimate alignment will be the max of ForcedAlignBits
|
|
|
|
// and the alignment computed with NumBits and the global.
|
|
|
|
//
|
|
|
|
// The algorithm is:
|
|
|
|
// Align = NumBits;
|
|
|
|
// if (GV && GV->hasalignment) Align = GV->getalignment();
|
|
|
|
// Align = std::max(Align, ForcedAlignBits);
|
|
|
|
//
|
|
|
|
void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
|
2008-03-01 03:36:59 +08:00
|
|
|
unsigned ForcedAlignBits,
|
|
|
|
bool UseFillExpr) const {
|
2007-04-24 07:33:31 +08:00
|
|
|
if (GV && GV->getAlignment())
|
2007-06-01 02:57:45 +08:00
|
|
|
NumBits = Log2_32(GV->getAlignment());
|
|
|
|
NumBits = std::max(NumBits, ForcedAlignBits);
|
|
|
|
|
2005-11-11 02:09:27 +08:00
|
|
|
if (NumBits == 0) return; // No need to emit alignment.
|
2009-08-19 14:12:02 +08:00
|
|
|
|
|
|
|
unsigned FillValue = 0;
|
2009-08-18 14:15:16 +08:00
|
|
|
if (getCurrentSection()->getKind().isText())
|
2009-08-23 05:43:10 +08:00
|
|
|
FillValue = MAI->getTextAlignFillValue();
|
2009-08-19 14:12:02 +08:00
|
|
|
|
|
|
|
OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0);
|
2004-08-18 03:14:29 +08:00
|
|
|
}
|
2009-08-06 05:00:52 +08:00
|
|
|
|
2010-01-23 14:17:14 +08:00
|
|
|
/// LowerConstant - Lower the specified LLVM Constant to an MCExpr.
|
|
|
|
///
|
|
|
|
static const MCExpr *LowerConstant(const Constant *CV, AsmPrinter &AP) {
|
|
|
|
MCContext &Ctx = AP.OutContext;
|
2010-01-13 12:29:19 +08:00
|
|
|
|
2010-01-23 14:17:14 +08:00
|
|
|
if (CV->isNullValue() || isa<UndefValue>(CV))
|
|
|
|
return MCConstantExpr::Create(0, Ctx);
|
|
|
|
|
|
|
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV))
|
|
|
|
return MCConstantExpr::Create(CI->getZExtValue(), Ctx);
|
2010-01-13 12:29:19 +08:00
|
|
|
|
2010-01-23 14:17:14 +08:00
|
|
|
if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
|
|
|
|
return MCSymbolRefExpr::Create(AP.GetGlobalValueSymbol(GV), Ctx);
|
|
|
|
if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV))
|
|
|
|
return MCSymbolRefExpr::Create(AP.GetBlockAddressSymbol(BA), Ctx);
|
2010-01-13 12:29:19 +08:00
|
|
|
|
|
|
|
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
|
|
|
|
if (CE == 0) {
|
2010-01-23 14:17:14 +08:00
|
|
|
llvm_unreachable("Unknown constant value to lower!");
|
|
|
|
return MCConstantExpr::Create(0, Ctx);
|
2010-01-13 12:29:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (CE->getOpcode()) {
|
|
|
|
case Instruction::ZExt:
|
|
|
|
case Instruction::SExt:
|
|
|
|
case Instruction::FPTrunc:
|
|
|
|
case Instruction::FPExt:
|
|
|
|
case Instruction::UIToFP:
|
|
|
|
case Instruction::SIToFP:
|
|
|
|
case Instruction::FPToUI:
|
|
|
|
case Instruction::FPToSI:
|
2010-01-23 14:17:14 +08:00
|
|
|
default: llvm_unreachable("FIXME: Don't support this constant cast expr");
|
2010-01-13 12:29:19 +08:00
|
|
|
case Instruction::GetElementPtr: {
|
2010-01-23 14:17:14 +08:00
|
|
|
const TargetData &TD = *AP.TM.getTargetData();
|
|
|
|
// Generate a symbolic expression for the byte address
|
|
|
|
const Constant *PtrVal = CE->getOperand(0);
|
|
|
|
SmallVector<Value*, 8> IdxVec(CE->op_begin()+1, CE->op_end());
|
|
|
|
int64_t Offset = TD.getIndexedOffset(PtrVal->getType(), &IdxVec[0],
|
|
|
|
IdxVec.size());
|
|
|
|
|
|
|
|
const MCExpr *Base = LowerConstant(CE->getOperand(0), AP);
|
2010-01-13 12:29:19 +08:00
|
|
|
if (Offset == 0)
|
2010-01-23 14:17:14 +08:00
|
|
|
return Base;
|
2010-01-13 12:29:19 +08:00
|
|
|
|
|
|
|
// Truncate/sext the offset to the pointer size.
|
2010-01-23 14:17:14 +08:00
|
|
|
if (TD.getPointerSizeInBits() != 64) {
|
|
|
|
int SExtAmount = 64-TD.getPointerSizeInBits();
|
2010-01-13 12:29:19 +08:00
|
|
|
Offset = (Offset << SExtAmount) >> SExtAmount;
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
2010-01-13 12:29:19 +08:00
|
|
|
|
2010-01-23 14:17:14 +08:00
|
|
|
return MCBinaryExpr::CreateAdd(Base, MCConstantExpr::Create(Offset, Ctx),
|
|
|
|
Ctx);
|
2010-01-13 12:29:19 +08:00
|
|
|
}
|
2010-01-23 14:17:14 +08:00
|
|
|
|
|
|
|
case Instruction::Trunc:
|
|
|
|
// We emit the value and depend on the assembler to truncate the generated
|
|
|
|
// expression properly. This is important for differences between
|
|
|
|
// blockaddress labels. Since the two labels are in the same function, it
|
|
|
|
// is reasonable to treat their delta as a 32-bit value.
|
|
|
|
// FALL THROUGH.
|
2010-01-13 12:29:19 +08:00
|
|
|
case Instruction::BitCast:
|
2010-01-23 14:17:14 +08:00
|
|
|
return LowerConstant(CE->getOperand(0), AP);
|
2010-01-13 12:29:19 +08:00
|
|
|
|
|
|
|
case Instruction::IntToPtr: {
|
2010-01-23 14:17:14 +08:00
|
|
|
const TargetData &TD = *AP.TM.getTargetData();
|
2010-01-13 12:29:19 +08:00
|
|
|
// Handle casts to pointers by changing them into casts to the appropriate
|
|
|
|
// integer type. This promotes constant folding and simplifies this code.
|
|
|
|
Constant *Op = CE->getOperand(0);
|
2010-01-23 14:17:14 +08:00
|
|
|
Op = ConstantExpr::getIntegerCast(Op, TD.getIntPtrType(CV->getContext()),
|
2010-01-13 12:29:19 +08:00
|
|
|
false/*ZExt*/);
|
2010-01-23 14:17:14 +08:00
|
|
|
return LowerConstant(Op, AP);
|
2010-01-13 12:29:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case Instruction::PtrToInt: {
|
2010-01-23 14:17:14 +08:00
|
|
|
const TargetData &TD = *AP.TM.getTargetData();
|
2010-01-13 12:29:19 +08:00
|
|
|
// Support only foldable casts to/from pointers that can be eliminated by
|
|
|
|
// changing the pointer to the appropriately sized integer type.
|
|
|
|
Constant *Op = CE->getOperand(0);
|
|
|
|
const Type *Ty = CE->getType();
|
2010-01-23 14:17:14 +08:00
|
|
|
|
|
|
|
const MCExpr *OpExpr = LowerConstant(Op, AP);
|
2010-01-13 12:29:19 +08:00
|
|
|
|
|
|
|
// We can emit the pointer value into this slot if the slot is an
|
2010-01-23 14:17:14 +08:00
|
|
|
// integer slot equal to the size of the pointer.
|
|
|
|
if (TD.getTypeAllocSize(Ty) == TD.getTypeAllocSize(Op->getType()))
|
|
|
|
return OpExpr;
|
|
|
|
|
|
|
|
// Otherwise the pointer is smaller than the resultant integer, mask off
|
|
|
|
// the high bits so we are sure to get a proper truncation if the input is
|
|
|
|
// a constant expr.
|
|
|
|
unsigned InBits = TD.getTypeAllocSizeInBits(Op->getType());
|
|
|
|
const MCExpr *MaskExpr = MCConstantExpr::Create(~0ULL >> (64-InBits), Ctx);
|
|
|
|
return MCBinaryExpr::CreateAnd(OpExpr, MaskExpr, Ctx);
|
2010-01-13 12:29:19 +08:00
|
|
|
}
|
2006-12-12 13:18:19 +08:00
|
|
|
|
2010-01-13 12:29:19 +08:00
|
|
|
case Instruction::Add:
|
|
|
|
case Instruction::Sub:
|
|
|
|
case Instruction::And:
|
|
|
|
case Instruction::Or:
|
2010-01-23 14:17:14 +08:00
|
|
|
case Instruction::Xor: {
|
|
|
|
const MCExpr *LHS = LowerConstant(CE->getOperand(0), AP);
|
|
|
|
const MCExpr *RHS = LowerConstant(CE->getOperand(1), AP);
|
2010-01-13 12:29:19 +08:00
|
|
|
switch (CE->getOpcode()) {
|
2010-01-23 14:17:14 +08:00
|
|
|
default: llvm_unreachable("Unknown binary operator constant cast expr");
|
|
|
|
case Instruction::Add: return MCBinaryExpr::CreateAdd(LHS, RHS, Ctx);
|
|
|
|
case Instruction::Sub: return MCBinaryExpr::CreateSub(LHS, RHS, Ctx);
|
|
|
|
case Instruction::And: return MCBinaryExpr::CreateAnd(LHS, RHS, Ctx);
|
|
|
|
case Instruction::Or: return MCBinaryExpr::CreateOr (LHS, RHS, Ctx);
|
|
|
|
case Instruction::Xor: return MCBinaryExpr::CreateXor(LHS, RHS, Ctx);
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
2010-01-23 14:17:14 +08:00
|
|
|
}
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-17 14:36:49 +08:00
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
static void EmitGlobalConstantArray(const ConstantArray *CA, unsigned AddrSpace,
|
|
|
|
AsmPrinter &AP) {
|
2010-01-23 12:54:10 +08:00
|
|
|
if (AddrSpace != 0 || !CA->isString()) {
|
|
|
|
// Not a string. Print the values in successive locations
|
2010-01-20 03:10:44 +08:00
|
|
|
for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
|
|
|
|
AP.EmitGlobalConstant(CA->getOperand(i), AddrSpace);
|
2010-01-23 12:54:10 +08:00
|
|
|
return;
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
2010-01-23 12:54:10 +08:00
|
|
|
|
|
|
|
// Otherwise, it can be emitted as .ascii.
|
|
|
|
SmallVector<char, 128> TmpVec;
|
|
|
|
TmpVec.reserve(CA->getNumOperands());
|
|
|
|
for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
|
|
|
|
TmpVec.push_back(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());
|
|
|
|
|
|
|
|
AP.OutStreamer.EmitBytes(StringRef(TmpVec.data(), TmpVec.size()), AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
static void EmitGlobalConstantVector(const ConstantVector *CV,
|
|
|
|
unsigned AddrSpace, AsmPrinter &AP) {
|
2010-01-20 15:41:15 +08:00
|
|
|
for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
|
2010-01-20 03:10:44 +08:00
|
|
|
AP.EmitGlobalConstant(CV->getOperand(i), AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
static void EmitGlobalConstantStruct(const ConstantStruct *CS,
|
|
|
|
unsigned AddrSpace, AsmPrinter &AP) {
|
2008-12-23 05:14:27 +08:00
|
|
|
// Print the fields in successive locations. Pad to align if needed!
|
2010-01-20 03:10:44 +08:00
|
|
|
const TargetData *TD = AP.TM.getTargetData();
|
|
|
|
unsigned Size = TD->getTypeAllocSize(CS->getType());
|
2010-01-20 15:11:32 +08:00
|
|
|
const StructLayout *Layout = TD->getStructLayout(CS->getType());
|
2010-01-20 03:10:44 +08:00
|
|
|
uint64_t SizeSoFar = 0;
|
|
|
|
for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
|
2010-01-20 15:41:15 +08:00
|
|
|
const Constant *Field = CS->getOperand(i);
|
2008-12-23 05:14:27 +08:00
|
|
|
|
|
|
|
// Check if padding is needed and insert one or more 0s.
|
2010-01-20 15:41:15 +08:00
|
|
|
uint64_t FieldSize = TD->getTypeAllocSize(Field->getType());
|
2010-01-20 15:11:32 +08:00
|
|
|
uint64_t PadSize = ((i == e-1 ? Size : Layout->getElementOffset(i+1))
|
|
|
|
- Layout->getElementOffset(i)) - FieldSize;
|
|
|
|
SizeSoFar += FieldSize + PadSize;
|
2008-12-23 05:14:27 +08:00
|
|
|
|
|
|
|
// Now print the actual field value.
|
2010-01-20 15:41:15 +08:00
|
|
|
AP.EmitGlobalConstant(Field, AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
|
|
|
|
// Insert padding - this may include padding to increase the size of the
|
|
|
|
// current field up to the ABI size (if the struct is not packed) as well
|
|
|
|
// as padding to ensure that the next field starts at the right offset.
|
2010-01-20 15:11:32 +08:00
|
|
|
AP.OutStreamer.EmitZeros(PadSize, AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
2010-01-20 15:11:32 +08:00
|
|
|
assert(SizeSoFar == Layout->getSizeInBytes() &&
|
2008-12-23 05:14:27 +08:00
|
|
|
"Layout of constant struct may be incorrect!");
|
|
|
|
}
|
|
|
|
|
2010-01-20 15:11:32 +08:00
|
|
|
static void EmitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
|
|
|
|
AsmPrinter &AP) {
|
2008-12-23 05:14:27 +08:00
|
|
|
// FP Constants are printed as integer constants to avoid losing
|
2010-01-20 14:53:37 +08:00
|
|
|
// precision.
|
2009-10-05 13:54:46 +08:00
|
|
|
if (CFP->getType()->isDoubleTy()) {
|
2010-01-20 15:11:32 +08:00
|
|
|
if (AP.VerboseAsm) {
|
2010-01-23 03:17:48 +08:00
|
|
|
double Val = CFP->getValueAPF().convertToDouble();
|
|
|
|
AP.OutStreamer.GetCommentOS() << "double " << Val << '\n';
|
2010-01-20 06:16:33 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 15:11:32 +08:00
|
|
|
uint64_t Val = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
|
|
|
AP.OutStreamer.EmitIntValue(Val, 8, AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
return;
|
2009-10-05 13:54:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CFP->getType()->isFloatTy()) {
|
2010-01-20 15:11:32 +08:00
|
|
|
if (AP.VerboseAsm) {
|
2010-01-23 03:52:01 +08:00
|
|
|
float Val = CFP->getValueAPF().convertToFloat();
|
|
|
|
AP.OutStreamer.GetCommentOS() << "float " << Val << '\n';
|
2009-08-13 02:32:22 +08:00
|
|
|
}
|
2010-01-20 15:11:32 +08:00
|
|
|
uint64_t Val = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
|
|
|
AP.OutStreamer.EmitIntValue(Val, 4, AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
return;
|
2009-10-05 13:54:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CFP->getType()->isX86_FP80Ty()) {
|
2008-12-23 05:14:27 +08:00
|
|
|
// all long double variants are printed as hex
|
|
|
|
// api needed to prevent premature destruction
|
2010-01-20 06:16:33 +08:00
|
|
|
APInt API = CFP->getValueAPF().bitcastToAPInt();
|
|
|
|
const uint64_t *p = API.getRawData();
|
2010-01-20 15:11:32 +08:00
|
|
|
if (AP.VerboseAsm) {
|
2010-01-20 06:11:05 +08:00
|
|
|
// Convert to double so we can print the approximate val as a comment.
|
|
|
|
APFloat DoubleVal = CFP->getValueAPF();
|
|
|
|
bool ignored;
|
|
|
|
DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
|
|
|
|
&ignored);
|
2010-01-23 03:52:01 +08:00
|
|
|
AP.OutStreamer.GetCommentOS() << "x86_fp80 ~= "
|
|
|
|
<< DoubleVal.convertToDouble() << '\n';
|
2010-01-20 06:11:05 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 15:11:32 +08:00
|
|
|
if (AP.TM.getTargetData()->isBigEndian()) {
|
|
|
|
AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
|
|
|
|
AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
|
2010-01-20 06:11:05 +08:00
|
|
|
} else {
|
2010-01-20 15:11:32 +08:00
|
|
|
AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
|
|
|
|
AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
2010-01-20 14:53:37 +08:00
|
|
|
|
|
|
|
// Emit the tail padding for the long double.
|
2010-01-20 15:11:32 +08:00
|
|
|
const TargetData &TD = *AP.TM.getTargetData();
|
|
|
|
AP.OutStreamer.EmitZeros(TD.getTypeAllocSize(CFP->getType()) -
|
|
|
|
TD.getTypeStoreSize(CFP->getType()), AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
return;
|
2009-10-05 13:54:46 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 06:16:33 +08:00
|
|
|
assert(CFP->getType()->isPPC_FP128Ty() &&
|
|
|
|
"Floating point constant type not handled");
|
|
|
|
// All long double variants are printed as hex api needed to prevent
|
|
|
|
// premature destruction.
|
|
|
|
APInt API = CFP->getValueAPF().bitcastToAPInt();
|
|
|
|
const uint64_t *p = API.getRawData();
|
2010-01-20 15:11:32 +08:00
|
|
|
if (AP.TM.getTargetData()->isBigEndian()) {
|
|
|
|
AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
|
|
|
|
AP.OutStreamer.EmitIntValue(p[1], 8, AddrSpace);
|
2010-01-20 14:53:37 +08:00
|
|
|
} else {
|
2010-01-20 15:11:32 +08:00
|
|
|
AP.OutStreamer.EmitIntValue(p[1], 8, AddrSpace);
|
|
|
|
AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
|
2010-01-20 06:16:33 +08:00
|
|
|
}
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 15:11:32 +08:00
|
|
|
static void EmitGlobalConstantLargeInt(const ConstantInt *CI,
|
|
|
|
unsigned AddrSpace, AsmPrinter &AP) {
|
|
|
|
const TargetData *TD = AP.TM.getTargetData();
|
2008-12-23 05:14:27 +08:00
|
|
|
unsigned BitWidth = CI->getBitWidth();
|
2010-01-13 12:39:46 +08:00
|
|
|
assert((BitWidth & 63) == 0 && "only support multiples of 64-bits");
|
2008-12-23 05:14:27 +08:00
|
|
|
|
|
|
|
// We don't expect assemblers to support integer data directives
|
|
|
|
// for more than 64 bits, so we emit the data in at most 64-bit
|
|
|
|
// quantities at a time.
|
|
|
|
const uint64_t *RawData = CI->getValue().getRawData();
|
|
|
|
for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
|
2010-01-20 15:11:32 +08:00
|
|
|
uint64_t Val = TD->isBigEndian() ? RawData[e - i - 1] : RawData[i];
|
|
|
|
AP.OutStreamer.EmitIntValue(Val, 8, AddrSpace);
|
2008-12-23 05:14:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-21 15:51:36 +08:00
|
|
|
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
|
2009-01-30 12:25:10 +08:00
|
|
|
void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
|
2010-01-20 15:19:19 +08:00
|
|
|
if (isa<ConstantAggregateZero>(CV) || isa<UndefValue>(CV)) {
|
2010-01-20 15:11:32 +08:00
|
|
|
uint64_t Size = TM.getTargetData()->getTypeAllocSize(CV->getType());
|
2010-01-20 05:51:22 +08:00
|
|
|
return OutStreamer.EmitZeros(Size, AddrSpace);
|
2010-01-20 15:11:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
|
|
|
unsigned Size = TM.getTargetData()->getTypeAllocSize(CV->getType());
|
|
|
|
switch (Size) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
2010-01-23 03:52:01 +08:00
|
|
|
if (VerboseAsm)
|
|
|
|
OutStreamer.GetCommentOS() << format("0x%llx\n", CI->getZExtValue());
|
2010-01-20 15:11:32 +08:00
|
|
|
OutStreamer.EmitIntValue(CI->getZExtValue(), Size, AddrSpace);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
EmitGlobalConstantLargeInt(CI, AddrSpace, *this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 12:34:19 +08:00
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
|
|
|
|
return EmitGlobalConstantArray(CVA, AddrSpace, *this);
|
2010-01-13 12:34:19 +08:00
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV))
|
|
|
|
return EmitGlobalConstantStruct(CVS, AddrSpace, *this);
|
2010-01-13 12:34:19 +08:00
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
|
2010-01-20 15:11:32 +08:00
|
|
|
return EmitGlobalConstantFP(CFP, AddrSpace, *this);
|
2010-01-13 12:34:19 +08:00
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
if (const ConstantVector *V = dyn_cast<ConstantVector>(CV))
|
|
|
|
return EmitGlobalConstantVector(V, AddrSpace, *this);
|
2004-08-17 14:36:49 +08:00
|
|
|
|
2010-01-21 01:57:50 +08:00
|
|
|
if (isa<ConstantPointerNull>(CV)) {
|
|
|
|
unsigned Size = TM.getTargetData()->getTypeAllocSize(CV->getType());
|
|
|
|
OutStreamer.EmitIntValue(0, Size, AddrSpace);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-23 14:17:14 +08:00
|
|
|
// Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it
|
|
|
|
// thread the streamer with EmitValue.
|
|
|
|
OutStreamer.EmitValue(LowerConstant(CV, *this),
|
|
|
|
TM.getTargetData()->getTypeAllocSize(CV->getType()),
|
|
|
|
AddrSpace);
|
2004-08-17 14:36:49 +08:00
|
|
|
}
|
2006-01-27 10:10:10 +08:00
|
|
|
|
2008-08-17 15:19:36 +08:00
|
|
|
void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
2006-09-13 05:00:35 +08:00
|
|
|
// Target doesn't support this yet!
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
|
2006-09-13 05:00:35 +08:00
|
|
|
}
|
|
|
|
|
2006-09-27 07:59:50 +08:00
|
|
|
/// PrintSpecial - Print information related to the specified machine instr
|
|
|
|
/// that is independent of the operand, and may be independent of the instr
|
|
|
|
/// itself. This can be useful for portably encoding the comment character
|
|
|
|
/// or other bits of target-specific knowledge into the asmstrings. The
|
|
|
|
/// syntax used is ${:comment}. Targets can override this to add support
|
|
|
|
/// for their own strange codes.
|
2009-03-10 13:37:13 +08:00
|
|
|
void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
|
2006-09-27 08:06:07 +08:00
|
|
|
if (!strcmp(Code, "private")) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getPrivateGlobalPrefix();
|
2006-09-27 08:06:07 +08:00
|
|
|
} else if (!strcmp(Code, "comment")) {
|
2009-03-24 08:17:40 +08:00
|
|
|
if (VerboseAsm)
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString();
|
2006-09-27 07:59:50 +08:00
|
|
|
} else if (!strcmp(Code, "uid")) {
|
2007-02-06 05:23:52 +08:00
|
|
|
// Comparing the address of MI isn't sufficient, because machineinstrs may
|
|
|
|
// be allocated to the same address across functions.
|
|
|
|
const Function *ThisF = MI->getParent()->getParent()->getFunction();
|
|
|
|
|
2009-06-25 06:28:12 +08:00
|
|
|
// If this is a new LastFn instruction, bump the counter.
|
|
|
|
if (LastMI != MI || LastFn != ThisF) {
|
2007-02-06 05:23:52 +08:00
|
|
|
++Counter;
|
|
|
|
LastMI = MI;
|
2009-06-25 06:28:12 +08:00
|
|
|
LastFn = ThisF;
|
2007-02-06 05:23:52 +08:00
|
|
|
}
|
2006-09-27 07:59:50 +08:00
|
|
|
O << Counter;
|
|
|
|
} else {
|
2009-07-11 21:10:19 +08:00
|
|
|
std::string msg;
|
|
|
|
raw_string_ostream Msg(msg);
|
|
|
|
Msg << "Unknown special formatter '" << Code
|
2006-12-07 09:30:32 +08:00
|
|
|
<< "' for machine instr: " << *MI;
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error(Msg.str());
|
2006-09-27 07:59:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 21:55:51 +08:00
|
|
|
/// processDebugLoc - Processes the debug information of each machine
|
|
|
|
/// instruction's DebugLoc.
|
2009-10-06 10:19:11 +08:00
|
|
|
void AsmPrinter::processDebugLoc(const MachineInstr *MI,
|
|
|
|
bool BeforePrintingInsn) {
|
2009-11-11 07:06:00 +08:00
|
|
|
if (!MAI || !DW || !MAI->doesSupportDebugInformation()
|
|
|
|
|| !DW->ShouldEmitDwarfDebug())
|
2009-08-05 12:09:18 +08:00
|
|
|
return;
|
2009-10-01 07:12:50 +08:00
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
2009-11-11 07:06:00 +08:00
|
|
|
if (DL.isUnknown())
|
|
|
|
return;
|
2010-01-16 14:09:35 +08:00
|
|
|
DILocation CurDLT = MF->getDILocation(DL);
|
|
|
|
if (CurDLT.getScope().isNull())
|
2009-11-11 07:06:00 +08:00
|
|
|
return;
|
|
|
|
|
2010-01-20 15:19:19 +08:00
|
|
|
if (!BeforePrintingInsn) {
|
2009-11-11 07:06:00 +08:00
|
|
|
// After printing instruction
|
|
|
|
DW->EndScope(MI);
|
2010-01-20 15:19:19 +08:00
|
|
|
} else if (CurDLT.getNode() != PrevDLT) {
|
|
|
|
unsigned L = DW->RecordSourceLine(CurDLT.getLineNumber(),
|
|
|
|
CurDLT.getColumnNumber(),
|
|
|
|
CurDLT.getScope().getNode());
|
|
|
|
printLabel(L);
|
|
|
|
O << '\n';
|
|
|
|
DW->BeginScope(MI, L);
|
|
|
|
PrevDLT = CurDLT.getNode();
|
2009-05-07 21:55:51 +08:00
|
|
|
}
|
|
|
|
}
|
2006-09-27 07:59:50 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
|
2006-01-27 10:10:10 +08:00
|
|
|
/// printInlineAsm - This method formats and prints the specified machine
|
|
|
|
/// instruction that is an inline asm.
|
|
|
|
void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
|
2006-01-31 07:00:08 +08:00
|
|
|
unsigned NumOperands = MI->getNumOperands();
|
|
|
|
|
|
|
|
// Count the number of register definitions.
|
|
|
|
unsigned NumDefs = 0;
|
2008-10-03 23:45:36 +08:00
|
|
|
for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
|
2006-09-06 04:02:51 +08:00
|
|
|
++NumDefs)
|
2006-01-31 07:00:08 +08:00
|
|
|
assert(NumDefs != NumOperands-1 && "No asm string?");
|
|
|
|
|
2008-10-03 23:45:36 +08:00
|
|
|
assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
|
|
|
|
// Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
|
2006-01-31 07:00:08 +08:00
|
|
|
const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
|
2009-11-06 08:04:54 +08:00
|
|
|
O << '\t';
|
|
|
|
|
2008-01-29 10:21:21 +08:00
|
|
|
// If this asmstr is empty, just print the #APP/#NOAPP markers.
|
|
|
|
// These are useful to see where empty asm's wound up.
|
2006-07-28 08:17:20 +08:00
|
|
|
if (AsmStr[0] == 0) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
|
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
|
2006-07-28 08:17:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
|
2006-07-28 08:17:20 +08:00
|
|
|
|
2007-01-16 11:42:04 +08:00
|
|
|
// The variant of the current asmprinter.
|
2009-08-23 05:43:10 +08:00
|
|
|
int AsmPrinterVariant = MAI->getAssemblerDialect();
|
2007-01-16 11:42:04 +08:00
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
int CurVariant = -1; // The number of the {.|.|.} region we are in.
|
|
|
|
const char *LastEmitted = AsmStr; // One past the last character emitted.
|
2006-02-01 09:28:23 +08:00
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
while (*LastEmitted) {
|
|
|
|
switch (*LastEmitted) {
|
|
|
|
default: {
|
|
|
|
// Not a special case, emit the string section literally.
|
|
|
|
const char *LiteralEnd = LastEmitted+1;
|
|
|
|
while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
|
2006-05-06 05:47:05 +08:00
|
|
|
*LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
++LiteralEnd;
|
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
|
|
|
|
O.write(LastEmitted, LiteralEnd-LastEmitted);
|
|
|
|
LastEmitted = LiteralEnd;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-06 05:47:05 +08:00
|
|
|
case '\n':
|
|
|
|
++LastEmitted; // Consume newline character.
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\n'; // Indent code with newline.
|
2006-05-06 05:47:05 +08:00
|
|
|
break;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
case '$': {
|
|
|
|
++LastEmitted; // Consume '$' character.
|
2006-10-04 07:27:09 +08:00
|
|
|
bool Done = true;
|
|
|
|
|
|
|
|
// Handle escapes.
|
|
|
|
switch (*LastEmitted) {
|
|
|
|
default: Done = false; break;
|
|
|
|
case '$': // $$ -> $
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
|
|
|
|
O << '$';
|
|
|
|
++LastEmitted; // Consume second '$' character.
|
|
|
|
break;
|
2006-10-04 07:27:09 +08:00
|
|
|
case '(': // $( -> same as GCC's { character.
|
|
|
|
++LastEmitted; // Consume '(' character.
|
|
|
|
if (CurVariant != -1) {
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error("Nested variants found in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2006-10-04 07:27:09 +08:00
|
|
|
}
|
|
|
|
CurVariant = 0; // We're in the first variant now.
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
++LastEmitted; // consume '|' character.
|
2008-10-11 05:04:42 +08:00
|
|
|
if (CurVariant == -1)
|
|
|
|
O << '|'; // this is gcc's behavior for | outside a variant
|
|
|
|
else
|
|
|
|
++CurVariant; // We're in the next variant.
|
2006-10-04 07:27:09 +08:00
|
|
|
break;
|
|
|
|
case ')': // $) -> same as GCC's } char.
|
|
|
|
++LastEmitted; // consume ')' character.
|
2008-10-11 05:04:42 +08:00
|
|
|
if (CurVariant == -1)
|
|
|
|
O << '}'; // this is gcc's behavior for } outside a variant
|
|
|
|
else
|
|
|
|
CurVariant = -1;
|
2006-10-04 07:27:09 +08:00
|
|
|
break;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
}
|
2006-10-04 07:27:09 +08:00
|
|
|
if (Done) break;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
|
|
|
|
bool HasCurlyBraces = false;
|
|
|
|
if (*LastEmitted == '{') { // ${variable}
|
|
|
|
++LastEmitted; // Consume '{' character.
|
|
|
|
HasCurlyBraces = true;
|
|
|
|
}
|
|
|
|
|
2009-03-10 13:37:13 +08:00
|
|
|
// If we have ${:foo}, then this is not a real operand reference, it is a
|
|
|
|
// "magic" string reference, just like in .td files. Arrange to call
|
|
|
|
// PrintSpecial.
|
|
|
|
if (HasCurlyBraces && *LastEmitted == ':') {
|
|
|
|
++LastEmitted;
|
|
|
|
const char *StrStart = LastEmitted;
|
|
|
|
const char *StrEnd = strchr(StrStart, '}');
|
|
|
|
if (StrEnd == 0) {
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2009-03-10 13:37:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Val(StrStart, StrEnd);
|
|
|
|
PrintSpecial(MI, Val.c_str());
|
|
|
|
LastEmitted = StrEnd+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
const char *IDStart = LastEmitted;
|
|
|
|
char *IDEnd;
|
2007-01-23 08:36:17 +08:00
|
|
|
errno = 0;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
|
|
|
|
if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error("Bad $ operand number in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
}
|
|
|
|
LastEmitted = IDEnd;
|
|
|
|
|
2006-02-07 06:17:23 +08:00
|
|
|
char Modifier[2] = { 0, 0 };
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
if (HasCurlyBraces) {
|
2006-02-07 06:17:23 +08:00
|
|
|
// If we have curly braces, check for a modifier character. This
|
|
|
|
// supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
|
|
|
|
if (*LastEmitted == ':') {
|
|
|
|
++LastEmitted; // Consume ':' character.
|
|
|
|
if (*LastEmitted == 0) {
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error("Bad ${:} expression in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2006-02-07 06:17:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Modifier[0] = *LastEmitted;
|
|
|
|
++LastEmitted; // Consume modifier character.
|
|
|
|
}
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
if (*LastEmitted != '}') {
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error("Bad ${} expression in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
}
|
|
|
|
++LastEmitted; // Consume '}' character.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned)Val >= NumOperands-1) {
|
2009-07-11 21:10:19 +08:00
|
|
|
llvm_report_error("Invalid $ operand number in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
}
|
|
|
|
|
2006-02-24 03:21:04 +08:00
|
|
|
// Okay, we finally have a value number. Ask the target to print this
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
// operand!
|
2006-02-24 03:21:04 +08:00
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
|
|
|
|
unsigned OpNo = 1;
|
2006-06-09 02:00:47 +08:00
|
|
|
|
|
|
|
bool Error = false;
|
|
|
|
|
2006-02-24 03:21:04 +08:00
|
|
|
// Scan to find the machine operand number for the operand.
|
2006-02-25 03:50:58 +08:00
|
|
|
for (; Val; --Val) {
|
2006-06-09 02:00:47 +08:00
|
|
|
if (OpNo >= MI->getNumOperands()) break;
|
2007-12-31 04:50:28 +08:00
|
|
|
unsigned OpFlags = MI->getOperand(OpNo).getImm();
|
2009-03-21 02:03:34 +08:00
|
|
|
OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
|
2006-02-25 03:50:58 +08:00
|
|
|
}
|
2006-06-09 02:00:47 +08:00
|
|
|
|
|
|
|
if (OpNo >= MI->getNumOperands()) {
|
|
|
|
Error = true;
|
2006-02-25 04:21:58 +08:00
|
|
|
} else {
|
2007-12-31 04:50:28 +08:00
|
|
|
unsigned OpFlags = MI->getOperand(OpNo).getImm();
|
2006-06-09 02:00:47 +08:00
|
|
|
++OpNo; // Skip over the ID number.
|
|
|
|
|
2010-01-18 05:43:43 +08:00
|
|
|
if (Modifier[0] == 'l') // labels are target independent
|
|
|
|
O << *GetMBBSymbol(MI->getOperand(OpNo).getMBB()->getNumber());
|
2007-11-06 05:20:28 +08:00
|
|
|
else {
|
|
|
|
AsmPrinter *AP = const_cast<AsmPrinter*>(this);
|
2008-09-24 09:07:17 +08:00
|
|
|
if ((OpFlags & 7) == 4) {
|
2007-11-06 05:20:28 +08:00
|
|
|
Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
|
|
|
|
Modifier[0] ? Modifier : 0);
|
|
|
|
} else {
|
|
|
|
Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
|
|
|
|
Modifier[0] ? Modifier : 0);
|
|
|
|
}
|
2006-06-09 02:00:47 +08:00
|
|
|
}
|
2006-02-25 04:21:58 +08:00
|
|
|
}
|
|
|
|
if (Error) {
|
2009-07-11 21:10:19 +08:00
|
|
|
std::string msg;
|
|
|
|
raw_string_ostream Msg(msg);
|
2010-01-18 05:43:43 +08:00
|
|
|
Msg << "Invalid operand found in inline asm: '" << AsmStr << "'\n";
|
2009-07-11 21:10:19 +08:00
|
|
|
MI->print(Msg);
|
|
|
|
llvm_report_error(Msg.str());
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
}
|
2006-02-24 03:21:04 +08:00
|
|
|
}
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-10 07:14:36 +08:00
|
|
|
O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd();
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
}
|
|
|
|
|
2008-03-15 08:03:38 +08:00
|
|
|
/// printImplicitDef - This method prints the specified machine instruction
|
|
|
|
/// that is an implicit def.
|
|
|
|
void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
|
2009-09-10 07:14:36 +08:00
|
|
|
if (!VerboseAsm) return;
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " implicit-def: "
|
2009-09-14 03:48:37 +08:00
|
|
|
<< TRI->getName(MI->getOperand(0).getReg());
|
2008-03-15 08:03:38 +08:00
|
|
|
}
|
|
|
|
|
2009-11-05 03:24:37 +08:00
|
|
|
void AsmPrinter::printKill(const MachineInstr *MI) const {
|
|
|
|
if (!VerboseAsm) return;
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " kill:";
|
|
|
|
for (unsigned n = 0, e = MI->getNumOperands(); n != e; ++n) {
|
|
|
|
const MachineOperand &op = MI->getOperand(n);
|
|
|
|
assert(op.isReg() && "KILL instruction must have only register operands");
|
|
|
|
O << ' ' << TRI->getName(op.getReg()) << (op.isDef() ? "<def>" : "<kill>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 22:34:52 +08:00
|
|
|
/// printLabel - This method prints a local label used by debug and
|
|
|
|
/// exception handling tables.
|
|
|
|
void AsmPrinter::printLabel(const MachineInstr *MI) const {
|
2008-07-01 08:16:26 +08:00
|
|
|
printLabel(MI->getOperand(0).getImm());
|
2007-01-26 22:34:52 +08:00
|
|
|
}
|
|
|
|
|
2008-02-01 17:10:45 +08:00
|
|
|
void AsmPrinter::printLabel(unsigned Id) const {
|
2009-09-10 07:14:36 +08:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "label" << Id << ':';
|
2008-02-01 17:10:45 +08:00
|
|
|
}
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
|
|
|
|
/// instruction, using the specified assembler variant. Targets should
|
2010-01-15 05:50:17 +08:00
|
|
|
/// override this to format as appropriate.
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2006-02-07 06:17:23 +08:00
|
|
|
unsigned AsmVariant, const char *ExtraCode) {
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-02 06:41:11 +08:00
|
|
|
// Target doesn't support this yet!
|
|
|
|
return true;
|
2006-01-27 10:10:10 +08:00
|
|
|
}
|
2006-02-25 04:21:58 +08:00
|
|
|
|
|
|
|
bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode) {
|
|
|
|
// Target doesn't support this yet!
|
|
|
|
return true;
|
|
|
|
}
|
2006-04-23 02:53:45 +08:00
|
|
|
|
2009-11-21 07:18:13 +08:00
|
|
|
MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA,
|
|
|
|
const char *Suffix) const {
|
|
|
|
return GetBlockAddressSymbol(BA->getFunction(), BA->getBasicBlock(), Suffix);
|
2009-10-30 09:27:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
|
2009-11-21 07:18:13 +08:00
|
|
|
const BasicBlock *BB,
|
|
|
|
const char *Suffix) const {
|
2009-10-30 09:27:03 +08:00
|
|
|
assert(BB->hasName() &&
|
|
|
|
"Address of anonymous basic block not supported yet!");
|
|
|
|
|
2009-11-06 07:14:35 +08:00
|
|
|
// This code must use the function name itself, and not the function number,
|
|
|
|
// since it must be possible to generate the label name from within other
|
|
|
|
// functions.
|
2010-01-13 15:30:49 +08:00
|
|
|
SmallString<60> FnName;
|
|
|
|
Mang->getNameWithPrefix(FnName, F, false);
|
2009-10-30 09:27:03 +08:00
|
|
|
|
2010-01-13 15:30:49 +08:00
|
|
|
// FIXME: THIS IS BROKEN IF THE LLVM BASIC BLOCK DOESN'T HAVE A NAME!
|
2010-01-13 14:38:18 +08:00
|
|
|
SmallString<60> NameResult;
|
2010-01-13 15:30:49 +08:00
|
|
|
Mang->getNameWithPrefix(NameResult,
|
|
|
|
StringRef("BA") + Twine((unsigned)FnName.size()) +
|
|
|
|
"_" + FnName.str() + "_" + BB->getName() + Suffix,
|
|
|
|
Mangler::Private);
|
2010-01-13 14:38:18 +08:00
|
|
|
|
|
|
|
return OutContext.GetOrCreateSymbol(NameResult.str());
|
2009-10-30 09:27:03 +08:00
|
|
|
}
|
|
|
|
|
2009-09-13 07:02:08 +08:00
|
|
|
MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
|
|
|
|
SmallString<60> Name;
|
|
|
|
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
|
|
|
|
<< getFunctionNumber() << '_' << MBBID;
|
2010-01-23 13:19:23 +08:00
|
|
|
return OutContext.GetOrCreateSymbol(Name.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetCPISymbol - Return the symbol for the specified constant pool entry.
|
|
|
|
MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
|
|
|
|
SmallString<60> Name;
|
|
|
|
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "CPI"
|
|
|
|
<< getFunctionNumber() << '_' << CPID;
|
|
|
|
return OutContext.GetOrCreateSymbol(Name.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetJTISymbol - Return the symbol for the specified jump table entry.
|
|
|
|
MCSymbol *AsmPrinter::GetJTISymbol(unsigned JTID, bool isLinkerPrivate) const {
|
|
|
|
const char *Prefix = isLinkerPrivate ? MAI->getLinkerPrivateGlobalPrefix() :
|
|
|
|
MAI->getPrivateGlobalPrefix();
|
|
|
|
SmallString<60> Name;
|
|
|
|
raw_svector_ostream(Name) << Prefix << "JTI" << getFunctionNumber() << '_'
|
|
|
|
<< JTID;
|
2009-09-13 07:02:08 +08:00
|
|
|
return OutContext.GetOrCreateSymbol(Name.str());
|
|
|
|
}
|
|
|
|
|
2010-01-16 07:18:17 +08:00
|
|
|
/// GetGlobalValueSymbol - Return the MCSymbol for the specified global
|
|
|
|
/// value.
|
|
|
|
MCSymbol *AsmPrinter::GetGlobalValueSymbol(const GlobalValue *GV) const {
|
|
|
|
SmallString<60> NameStr;
|
|
|
|
Mang->getNameWithPrefix(NameStr, GV, false);
|
|
|
|
return OutContext.GetOrCreateSymbol(NameStr.str());
|
|
|
|
}
|
|
|
|
|
2010-01-17 02:37:32 +08:00
|
|
|
/// GetSymbolWithGlobalValueBase - Return the MCSymbol for a symbol with
|
2010-01-16 07:25:11 +08:00
|
|
|
/// global value name as its base, with the specified suffix, and where the
|
2010-01-17 02:37:32 +08:00
|
|
|
/// symbol is forced to have private linkage if ForcePrivate is true.
|
|
|
|
MCSymbol *AsmPrinter::GetSymbolWithGlobalValueBase(const GlobalValue *GV,
|
|
|
|
StringRef Suffix,
|
|
|
|
bool ForcePrivate) const {
|
2010-01-16 07:25:11 +08:00
|
|
|
SmallString<60> NameStr;
|
2010-01-17 02:37:32 +08:00
|
|
|
Mang->getNameWithPrefix(NameStr, GV, ForcePrivate);
|
2010-01-16 07:25:11 +08:00
|
|
|
NameStr.append(Suffix.begin(), Suffix.end());
|
|
|
|
return OutContext.GetOrCreateSymbol(NameStr.str());
|
|
|
|
}
|
|
|
|
|
2010-01-16 07:18:17 +08:00
|
|
|
/// GetExternalSymbolSymbol - Return the MCSymbol for the specified
|
|
|
|
/// ExternalSymbol.
|
|
|
|
MCSymbol *AsmPrinter::GetExternalSymbolSymbol(StringRef Sym) const {
|
|
|
|
SmallString<60> NameStr;
|
|
|
|
Mang->getNameWithPrefix(NameStr, Sym);
|
|
|
|
return OutContext.GetOrCreateSymbol(NameStr.str());
|
|
|
|
}
|
|
|
|
|
2009-09-13 07:02:08 +08:00
|
|
|
|
2010-01-23 05:50:41 +08:00
|
|
|
|
|
|
|
/// PrintParentLoopComment - Print comments about parent loops of this one.
|
|
|
|
static void PrintParentLoopComment(raw_ostream &OS, const MachineLoop *Loop,
|
|
|
|
unsigned FunctionNumber) {
|
|
|
|
if (Loop == 0) return;
|
|
|
|
PrintParentLoopComment(OS, Loop->getParentLoop(), FunctionNumber);
|
|
|
|
OS.indent(Loop->getLoopDepth()*2)
|
|
|
|
<< "Parent Loop BB" << FunctionNumber << "_"
|
|
|
|
<< Loop->getHeader()->getNumber()
|
|
|
|
<< " Depth=" << Loop->getLoopDepth() << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// PrintChildLoopComment - Print comments about child loops within
|
|
|
|
/// the loop for this basic block, with nesting.
|
|
|
|
static void PrintChildLoopComment(raw_ostream &OS, const MachineLoop *Loop,
|
|
|
|
unsigned FunctionNumber) {
|
|
|
|
// Add child loop information
|
|
|
|
for (MachineLoop::iterator CL = Loop->begin(), E = Loop->end();CL != E; ++CL){
|
|
|
|
OS.indent((*CL)->getLoopDepth()*2)
|
|
|
|
<< "Child Loop BB" << FunctionNumber << "_"
|
|
|
|
<< (*CL)->getHeader()->getNumber() << " Depth " << (*CL)->getLoopDepth()
|
|
|
|
<< '\n';
|
|
|
|
PrintChildLoopComment(OS, *CL, FunctionNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitComments - Pretty-print comments for basic blocks.
|
|
|
|
static void PrintBasicBlockLoopComments(const MachineBasicBlock &MBB,
|
|
|
|
const MachineLoopInfo *LI,
|
|
|
|
const AsmPrinter &AP) {
|
|
|
|
// Add loop depth information
|
|
|
|
const MachineLoop *Loop = LI->getLoopFor(&MBB);
|
|
|
|
if (Loop == 0) return;
|
|
|
|
|
|
|
|
MachineBasicBlock *Header = Loop->getHeader();
|
|
|
|
assert(Header && "No header for loop");
|
|
|
|
|
|
|
|
// If this block is not a loop header, just print out what is the loop header
|
|
|
|
// and return.
|
|
|
|
if (Header != &MBB) {
|
|
|
|
AP.OutStreamer.AddComment(" in Loop: Header=BB" +
|
|
|
|
Twine(AP.getFunctionNumber())+"_" +
|
|
|
|
Twine(Loop->getHeader()->getNumber())+
|
|
|
|
" Depth="+Twine(Loop->getLoopDepth()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, it is a loop header. Print out information about child and
|
|
|
|
// parent loops.
|
|
|
|
raw_ostream &OS = AP.OutStreamer.GetCommentOS();
|
|
|
|
|
|
|
|
PrintParentLoopComment(OS, Loop->getParentLoop(), AP.getFunctionNumber());
|
|
|
|
|
|
|
|
OS << "=>";
|
|
|
|
OS.indent(Loop->getLoopDepth()*2-2);
|
|
|
|
|
|
|
|
OS << "This ";
|
|
|
|
if (Loop->empty())
|
|
|
|
OS << "Inner ";
|
|
|
|
OS << "Loop Header: Depth=" + Twine(Loop->getLoopDepth()) << '\n';
|
|
|
|
|
|
|
|
PrintChildLoopComment(OS, Loop, AP.getFunctionNumber());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-14 02:25:37 +08:00
|
|
|
/// EmitBasicBlockStart - This method prints the label for the specified
|
|
|
|
/// MachineBasicBlock, an alignment (if present) and a comment describing
|
|
|
|
/// it if appropriate.
|
2009-09-14 11:15:54 +08:00
|
|
|
void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
|
2009-10-30 09:34:35 +08:00
|
|
|
// Emit an alignment directive for this block, if needed.
|
2009-09-14 02:25:37 +08:00
|
|
|
if (unsigned Align = MBB->getAlignment())
|
|
|
|
EmitAlignment(Log2_32(Align));
|
2008-02-28 08:43:03 +08:00
|
|
|
|
2009-10-30 09:34:35 +08:00
|
|
|
// If the block has its address taken, emit a special label to satisfy
|
|
|
|
// references to the block. This is done so that we don't need to
|
|
|
|
// remember the number of this label, and so that we can make
|
|
|
|
// forward references to labels without knowing what their numbers
|
|
|
|
// will be.
|
2009-10-30 09:27:03 +08:00
|
|
|
if (MBB->hasAddressTaken()) {
|
2010-01-20 15:24:05 +08:00
|
|
|
const BasicBlock *BB = MBB->getBasicBlock();
|
2010-01-23 03:52:01 +08:00
|
|
|
if (VerboseAsm)
|
|
|
|
OutStreamer.AddComment("Address Taken");
|
2010-01-20 15:24:05 +08:00
|
|
|
OutStreamer.EmitLabel(GetBlockAddressSymbol(BB->getParent(), BB));
|
2009-10-30 09:27:03 +08:00
|
|
|
}
|
|
|
|
|
2009-10-30 09:34:35 +08:00
|
|
|
// Print the main label for the block.
|
2009-10-07 01:38:38 +08:00
|
|
|
if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
|
2010-01-23 03:52:01 +08:00
|
|
|
if (VerboseAsm) {
|
2010-01-23 13:51:36 +08:00
|
|
|
// NOTE: Want this comment at start of line.
|
2009-10-07 01:38:38 +08:00
|
|
|
O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
|
2010-01-23 03:52:01 +08:00
|
|
|
if (const BasicBlock *BB = MBB->getBasicBlock())
|
|
|
|
if (BB->hasName())
|
|
|
|
OutStreamer.AddComment("%" + BB->getName());
|
2010-01-23 05:00:45 +08:00
|
|
|
|
2010-01-23 05:50:41 +08:00
|
|
|
PrintBasicBlockLoopComments(*MBB, LI, *this);
|
2010-01-23 03:52:01 +08:00
|
|
|
OutStreamer.AddBlankLine();
|
|
|
|
}
|
2009-10-07 01:38:38 +08:00
|
|
|
} else {
|
2010-01-23 03:52:01 +08:00
|
|
|
if (VerboseAsm) {
|
|
|
|
if (const BasicBlock *BB = MBB->getBasicBlock())
|
|
|
|
if (BB->hasName())
|
|
|
|
OutStreamer.AddComment("%" + BB->getName());
|
2010-01-23 05:50:41 +08:00
|
|
|
PrintBasicBlockLoopComments(*MBB, LI, *this);
|
2010-01-23 03:52:01 +08:00
|
|
|
}
|
2010-01-23 05:00:45 +08:00
|
|
|
|
2010-01-20 15:24:05 +08:00
|
|
|
OutStreamer.EmitLabel(GetMBBSymbol(MBB->getNumber()));
|
2009-10-07 01:38:38 +08:00
|
|
|
}
|
2006-04-23 02:53:45 +08:00
|
|
|
}
|
2006-08-13 05:29:52 +08: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
llvm-svn: 43924
2007-11-09 09:32:10 +08:00
|
|
|
/// printPICJumpTableSetLabel - This method prints a set label for the
|
|
|
|
/// specified MachineBasicBlock for a jumptable entry.
|
|
|
|
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
|
|
|
|
const MachineBasicBlock *MBB) const {
|
2009-08-23 05:43:10 +08:00
|
|
|
if (!MAI->getSetDirective())
|
2006-08-13 05:29:52 +08:00
|
|
|
return;
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
|
2010-01-18 05:43:43 +08:00
|
|
|
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ','
|
|
|
|
<< *GetMBBSymbol(MBB->getNumber())
|
2010-01-23 13:19:23 +08:00
|
|
|
<< '-' << *GetJTISymbol(uid) << '\n';
|
2006-08-13 05:29:52 +08:00
|
|
|
}
|
2006-09-13 05:00:35 +08:00
|
|
|
|
2010-01-23 14:53:23 +08:00
|
|
|
void AsmPrinter::printVisibility(MCSymbol *Sym, unsigned Visibility) const {
|
|
|
|
MCSymbolAttr Attr = MCSA_Invalid;
|
|
|
|
|
|
|
|
switch (Visibility) {
|
|
|
|
default: break;
|
|
|
|
case GlobalValue::HiddenVisibility:
|
|
|
|
Attr = MAI->getHiddenVisibilityAttr();
|
|
|
|
break;
|
|
|
|
case GlobalValue::ProtectedVisibility:
|
|
|
|
Attr = MAI->getProtectedVisibilityAttr();
|
|
|
|
break;
|
2010-01-16 07:38:51 +08:00
|
|
|
}
|
2010-01-23 14:53:23 +08:00
|
|
|
|
|
|
|
if (Attr != MCSA_Invalid)
|
|
|
|
OutStreamer.EmitSymbolAttribute(Sym, Attr);
|
2010-01-16 07:38:51 +08:00
|
|
|
}
|
|
|
|
|
2008-11-23 00:15:34 +08:00
|
|
|
void AsmPrinter::printOffset(int64_t Offset) const {
|
|
|
|
if (Offset > 0)
|
|
|
|
O << '+' << Offset;
|
|
|
|
else if (Offset < 0)
|
|
|
|
O << Offset;
|
|
|
|
}
|
|
|
|
|
2008-08-18 02:44:35 +08:00
|
|
|
GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
|
|
|
|
if (!S->usesMetadata())
|
2008-08-17 20:08:44 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-08-18 02:44:35 +08:00
|
|
|
gcp_iterator GCPI = GCMetadataPrinters.find(S);
|
2008-08-17 20:08:44 +08:00
|
|
|
if (GCPI != GCMetadataPrinters.end())
|
|
|
|
return GCPI->second;
|
|
|
|
|
2008-08-18 02:44:35 +08:00
|
|
|
const char *Name = S->getName().c_str();
|
2008-08-17 20:08:44 +08:00
|
|
|
|
|
|
|
for (GCMetadataPrinterRegistry::iterator
|
|
|
|
I = GCMetadataPrinterRegistry::begin(),
|
|
|
|
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
|
|
|
|
if (strcmp(Name, I->getName()) == 0) {
|
2008-08-18 02:44:35 +08:00
|
|
|
GCMetadataPrinter *GMP = I->instantiate();
|
|
|
|
GMP->S = S;
|
|
|
|
GCMetadataPrinters.insert(std::make_pair(S, GMP));
|
|
|
|
return GMP;
|
2008-08-17 20:08:44 +08:00
|
|
|
}
|
|
|
|
|
2010-01-23 14:17:14 +08:00
|
|
|
llvm_report_error("no GCMetadataPrinter registered for GC: " + Twine(Name));
|
|
|
|
return 0;
|
2008-08-17 20:08:44 +08:00
|
|
|
}
|
2009-07-14 04:25:48 +08:00
|
|
|
|
|
|
|
/// EmitComments - Pretty-print comments for instructions
|
2009-08-08 07:42:01 +08:00
|
|
|
void AsmPrinter::EmitComments(const MachineInstr &MI) const {
|
2009-11-14 05:34:57 +08:00
|
|
|
if (!VerboseAsm)
|
|
|
|
return;
|
2009-08-08 07:42:01 +08:00
|
|
|
|
2009-11-14 05:34:57 +08:00
|
|
|
bool Newline = false;
|
|
|
|
|
|
|
|
if (!MI.getDebugLoc().isUnknown()) {
|
2010-01-16 14:09:35 +08:00
|
|
|
DILocation DLT = MF->getDILocation(MI.getDebugLoc());
|
2009-11-14 05:34:57 +08:00
|
|
|
|
|
|
|
// Print source line info.
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-12-05 08:23:29 +08:00
|
|
|
O << MAI->getCommentString() << ' ';
|
2010-01-16 14:09:35 +08:00
|
|
|
DIScope Scope = DLT.getScope();
|
2009-12-05 08:23:29 +08:00
|
|
|
// Omit the directory, because it's likely to be long and uninteresting.
|
|
|
|
if (!Scope.isNull())
|
|
|
|
O << Scope.getFilename();
|
|
|
|
else
|
|
|
|
O << "<unknown>";
|
2010-01-16 14:09:35 +08:00
|
|
|
O << ':' << DLT.getLineNumber();
|
|
|
|
if (DLT.getColumnNumber() != 0)
|
|
|
|
O << ':' << DLT.getColumnNumber();
|
2009-11-14 05:34:57 +08:00
|
|
|
Newline = true;
|
2009-07-17 06:24:20 +08:00
|
|
|
}
|
2009-11-14 05:34:57 +08:00
|
|
|
|
2009-11-16 23:12:23 +08:00
|
|
|
// Check for spills and reloads
|
|
|
|
int FI;
|
|
|
|
|
|
|
|
const MachineFrameInfo *FrameInfo =
|
|
|
|
MI.getParent()->getParent()->getFrameInfo();
|
|
|
|
|
|
|
|
// We assume a single instruction only has a spill or reload, not
|
|
|
|
// both.
|
2009-12-05 06:46:04 +08:00
|
|
|
const MachineMemOperand *MMO;
|
2009-11-16 23:12:23 +08:00
|
|
|
if (TM.getInstrInfo()->isLoadFromStackSlotPostFE(&MI, FI)) {
|
|
|
|
if (FrameInfo->isSpillSlotObjectIndex(FI)) {
|
2009-12-05 06:46:04 +08:00
|
|
|
MMO = *MI.memoperands_begin();
|
2009-11-16 23:12:23 +08:00
|
|
|
if (Newline) O << '\n';
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-12-05 07:19:55 +08:00
|
|
|
O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Reload";
|
2009-11-16 23:12:23 +08:00
|
|
|
Newline = true;
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 06:46:04 +08:00
|
|
|
else if (TM.getInstrInfo()->hasLoadFromStackSlot(&MI, MMO, FI)) {
|
2009-11-16 23:12:23 +08:00
|
|
|
if (FrameInfo->isSpillSlotObjectIndex(FI)) {
|
|
|
|
if (Newline) O << '\n';
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-12-05 07:19:55 +08:00
|
|
|
O << MAI->getCommentString() << ' '
|
|
|
|
<< MMO->getSize() << "-byte Folded Reload";
|
2009-11-16 23:12:23 +08:00
|
|
|
Newline = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (TM.getInstrInfo()->isStoreToStackSlotPostFE(&MI, FI)) {
|
|
|
|
if (FrameInfo->isSpillSlotObjectIndex(FI)) {
|
2009-12-05 06:46:04 +08:00
|
|
|
MMO = *MI.memoperands_begin();
|
2009-11-16 23:12:23 +08:00
|
|
|
if (Newline) O << '\n';
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-12-05 07:19:55 +08:00
|
|
|
O << MAI->getCommentString() << ' ' << MMO->getSize() << "-byte Spill";
|
2009-11-16 23:12:23 +08:00
|
|
|
Newline = true;
|
|
|
|
}
|
|
|
|
}
|
2009-12-05 06:46:04 +08:00
|
|
|
else if (TM.getInstrInfo()->hasStoreToStackSlot(&MI, MMO, FI)) {
|
2009-11-16 23:12:23 +08:00
|
|
|
if (FrameInfo->isSpillSlotObjectIndex(FI)) {
|
|
|
|
if (Newline) O << '\n';
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-12-05 07:19:55 +08:00
|
|
|
O << MAI->getCommentString() << ' '
|
|
|
|
<< MMO->getSize() << "-byte Folded Spill";
|
2009-11-16 23:12:23 +08:00
|
|
|
Newline = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for spill-induced copies
|
|
|
|
unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx;
|
|
|
|
if (TM.getInstrInfo()->isMoveInstr(MI, SrcReg, DstReg,
|
|
|
|
SrcSubIdx, DstSubIdx)) {
|
|
|
|
if (MI.getAsmPrinterFlag(ReloadReuse)) {
|
|
|
|
if (Newline) O << '\n';
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Reload Reuse";
|
|
|
|
}
|
|
|
|
}
|
2009-07-14 04:25:48 +08:00
|
|
|
}
|
|
|
|
|