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"
|
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"
|
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));
|
|
|
|
|
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,
|
|
|
|
TM.getTargetData()->isLittleEndian(), 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;
|
2009-03-25 09:47:28 +08:00
|
|
|
switch (AsmVerbose) {
|
|
|
|
case cl::BOU_UNSET: VerboseAsm = VDef; break;
|
|
|
|
case cl::BOU_TRUE: VerboseAsm = true; break;
|
|
|
|
case cl::BOU_FALSE: VerboseAsm = false; break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->hasSingleParameterDotFile()) {
|
2008-12-03 19:01:37 +08:00
|
|
|
/* Very minimal debug info. It is ignored if we emit actual
|
2009-10-01 05:26:13 +08:00
|
|
|
debug info. If we don't, this at least helps the user find where
|
2008-12-03 19:01:37 +08:00
|
|
|
a function came from. */
|
|
|
|
O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
if (MAI->hasDotTypeDotSizeDirective()) {
|
|
|
|
O << "\t.type\t" << *GVSym;
|
|
|
|
if (MAI->getCommentString()[0] != '@')
|
|
|
|
O << ",@object\n";
|
|
|
|
else
|
|
|
|
O << ",%object\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
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-19 13:51:42 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << ' ';
|
2010-01-19 13:38:33 +08:00
|
|
|
WriteAsOperand(O, GV, /*PrintType=*/false, GV->getParent());
|
2010-01-19 14:01:04 +08:00
|
|
|
O << '\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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const char *LComm = MAI->getLCOMMDirective()) {
|
|
|
|
// .lcomm _foo, 42
|
2010-01-19 13:38:33 +08:00
|
|
|
O << LComm << *GVSym << ',' << Size;
|
2010-01-19 14:01:04 +08:00
|
|
|
O << '\n';
|
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
|
|
|
|
O << "\t.local\t" << *GVSym << '\n';
|
|
|
|
// .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
|
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
|
|
|
|
// .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
|
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
|
|
|
|
// .weak_definition _foo
|
2010-01-19 14:41:24 +08:00
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::WeakDefinition);
|
2010-01-19 13:38:33 +08:00
|
|
|
} else if (const char *LinkOnce = MAI->getLinkOnceDirective()) {
|
|
|
|
// .globl _foo
|
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
|
|
|
|
// .linkonce same_size
|
|
|
|
O << LinkOnce;
|
2010-01-19 14:41:24 +08:00
|
|
|
} else {
|
|
|
|
// .weak _foo
|
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Weak);
|
|
|
|
}
|
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
|
|
|
|
OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
|
|
|
|
break;
|
|
|
|
case GlobalValue::PrivateLinkage:
|
|
|
|
case GlobalValue::InternalLinkage:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown linkage type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitAlignment(AlignLog, GV);
|
|
|
|
if (VerboseAsm) {
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << ' ';
|
|
|
|
WriteAsOperand(O, GV, /*PrintType=*/false, GV->getParent());
|
2010-01-19 14:41:24 +08:00
|
|
|
O << '\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())
|
|
|
|
O << "\t.size\t" << *GVSym << ", " << Size << '\n';
|
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-18 05:43:43 +08:00
|
|
|
O << MAI->getWeakRefDirective() << *GetGlobalValueSymbol(I) << '\n';
|
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-18 05:43:43 +08:00
|
|
|
O << MAI->getWeakRefDirective() << *GetGlobalValueSymbol(I) << '\n';
|
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()) {
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\n';
|
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())
|
|
|
|
O << "\t.globl\t" << *Name << '\n';
|
|
|
|
else if (I->hasWeakLinkage())
|
|
|
|
O << MAI->getWeakRefDirective() << *Name << '\n';
|
|
|
|
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())
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->getNonexecutableStackDirective())
|
|
|
|
O << MAI->getNonexecutableStackDirective() << '\n';
|
2008-05-05 08:28:39 +08:00
|
|
|
|
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
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
|
2009-08-13 02:32:22 +08:00
|
|
|
<< CPI << ':';
|
2009-03-13 15:51:59 +08:00
|
|
|
if (VerboseAsm) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " constant ";
|
2009-08-13 09:36:44 +08:00
|
|
|
WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent());
|
2009-03-13 15:51:59 +08:00
|
|
|
}
|
2008-09-25 06:17:59 +08:00
|
|
|
O << '\n';
|
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.
|
2009-09-14 03:02:16 +08:00
|
|
|
if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0]) {
|
|
|
|
O << MAI->getLinkerPrivateGlobalPrefix()
|
|
|
|
<< "JTI" << getFunctionNumber() << '_' << i << ":\n";
|
2009-06-19 04:37:15 +08:00
|
|
|
}
|
2007-01-18 09:12:56 +08:00
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 13:57:21 +08:00
|
|
|
<< '_' << i << ":\n";
|
2006-08-13 05:29:52 +08:00
|
|
|
|
2006-04-23 02:53:45 +08:00
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
|
2007-11-14 17:18:41 +08:00
|
|
|
printPICJumpTableEntry(MJTI, JTBBs[ii], i);
|
2006-04-23 02:53:45 +08:00
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 17:18:41 +08:00
|
|
|
void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
|
|
|
const MachineBasicBlock *MBB,
|
|
|
|
unsigned uid) const {
|
2009-08-12 04:29:57 +08:00
|
|
|
bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
|
2007-11-14 17:18:41 +08:00
|
|
|
|
|
|
|
// Use JumpTableDirective otherwise honor the entry size from the jump table
|
|
|
|
// info.
|
2009-08-23 05:43:10 +08:00
|
|
|
const char *JTEntryDirective = MAI->getJumpTableDirective(isPIC);
|
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.
|
2009-08-12 04:29:57 +08:00
|
|
|
if (!isPIC) {
|
2010-01-18 05:43:43 +08:00
|
|
|
O << *GetMBBSymbol(MBB->getNumber());
|
2009-08-23 05:43:10 +08:00
|
|
|
} else if (MAI->getSetDirective()) {
|
|
|
|
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
|
|
|
|
// JT
|
|
|
|
if (!HadJTEntryDirective)
|
2009-08-23 05:43:10 +08:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI"
|
2009-08-12 04:29:57 +08:00
|
|
|
<< getFunctionNumber() << '_' << uid;
|
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") {
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->getUsedDirective() != 0) // 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 &&
|
|
|
|
MAI->hasStaticCtorDtorReferenceInStaticMode())
|
|
|
|
O << ".reference .constructors_used\n";
|
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 &&
|
|
|
|
MAI->hasStaticCtorDtorReferenceInStaticMode())
|
|
|
|
O << ".reference .destructors_used\n";
|
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-08-23 05:43:10 +08:00
|
|
|
const char *Directive = MAI->getUsedDirective();
|
2006-09-26 11:38:18 +08:00
|
|
|
|
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());
|
2009-08-01 04:52:39 +08:00
|
|
|
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) {
|
2008-09-04 04:34:58 +08:00
|
|
|
O << Directive;
|
|
|
|
EmitConstantValueOnly(InitList->getOperand(i));
|
|
|
|
O << '\n';
|
|
|
|
}
|
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-02-22 06:47:38 +08:00
|
|
|
|
2007-01-25 23:12:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// LEB 128 number encoding.
|
|
|
|
|
2009-11-07 06:38:38 +08:00
|
|
|
/// PrintULEB128 - Print a series of hexadecimal values (separated by commas)
|
2007-01-25 23:12:02 +08:00
|
|
|
/// representing an unsigned leb128 value.
|
|
|
|
void AsmPrinter::PrintULEB128(unsigned Value) const {
|
|
|
|
do {
|
2008-11-10 12:35:24 +08:00
|
|
|
unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
|
2007-01-25 23:12:02 +08:00
|
|
|
Value >>= 7;
|
|
|
|
if (Value) Byte |= 0x80;
|
2010-01-17 15:46:39 +08:00
|
|
|
PrintHex(Byte);
|
2007-01-25 23:12:02 +08:00
|
|
|
if (Value) O << ", ";
|
|
|
|
} while (Value);
|
|
|
|
}
|
|
|
|
|
2009-11-07 06:38:38 +08:00
|
|
|
/// PrintSLEB128 - Print a series of hexadecimal values (separated by commas)
|
2007-01-25 23:12:02 +08:00
|
|
|
/// representing a signed leb128 value.
|
|
|
|
void AsmPrinter::PrintSLEB128(int Value) const {
|
|
|
|
int Sign = Value >> (8 * sizeof(Value) - 1);
|
|
|
|
bool IsMore;
|
2008-08-16 20:57:46 +08:00
|
|
|
|
2007-01-25 23:12:02 +08:00
|
|
|
do {
|
2008-11-10 12:35:24 +08:00
|
|
|
unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
|
2007-01-25 23:12:02 +08:00
|
|
|
Value >>= 7;
|
|
|
|
IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
|
|
|
|
if (IsMore) Byte |= 0x80;
|
2010-01-17 15:46:39 +08:00
|
|
|
PrintHex(Byte);
|
2007-01-25 23:12:02 +08:00
|
|
|
if (IsMore) O << ", ";
|
|
|
|
} while (IsMore);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Emission and print routines
|
|
|
|
//
|
|
|
|
|
2009-11-07 06:38:38 +08:00
|
|
|
/// PrintHex - Print a value as a hexadecimal value.
|
2007-01-25 23:12:02 +08:00
|
|
|
///
|
2010-01-17 15:46:39 +08:00
|
|
|
void AsmPrinter::PrintHex(uint64_t Value) const {
|
|
|
|
O << "0x";
|
|
|
|
O.write_hex(Value);
|
2007-01-25 23:12:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EOL - Print a newline character to asm stream. If a comment is present
|
|
|
|
/// then it will be printed first. Comments should not contain '\n'.
|
2007-02-22 06:47:38 +08:00
|
|
|
void AsmPrinter::EOL() const {
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\n';
|
2007-02-22 06:47:38 +08:00
|
|
|
}
|
2008-07-02 05:16:27 +08:00
|
|
|
|
2010-01-17 15:46:39 +08:00
|
|
|
void AsmPrinter::EOL(const Twine &Comment) const {
|
|
|
|
if (VerboseAsm && !Comment.isTriviallyEmpty()) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2010-01-20 15:19:19 +08:00
|
|
|
O << MAI->getCommentString() << ' ' << Comment;
|
2008-07-02 05:16:27 +08:00
|
|
|
}
|
|
|
|
O << '\n';
|
|
|
|
}
|
2009-08-29 20:17:53 +08:00
|
|
|
|
|
|
|
static const char *DecodeDWARFEncoding(unsigned Encoding) {
|
|
|
|
switch (Encoding) {
|
|
|
|
case dwarf::DW_EH_PE_absptr:
|
|
|
|
return "absptr";
|
|
|
|
case dwarf::DW_EH_PE_omit:
|
|
|
|
return "omit";
|
|
|
|
case dwarf::DW_EH_PE_pcrel:
|
|
|
|
return "pcrel";
|
2009-09-10 05:26:19 +08:00
|
|
|
case dwarf::DW_EH_PE_udata4:
|
|
|
|
return "udata4";
|
|
|
|
case dwarf::DW_EH_PE_udata8:
|
|
|
|
return "udata8";
|
|
|
|
case dwarf::DW_EH_PE_sdata4:
|
|
|
|
return "sdata4";
|
|
|
|
case dwarf::DW_EH_PE_sdata8:
|
|
|
|
return "sdata8";
|
2009-08-29 20:17:53 +08:00
|
|
|
case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4:
|
|
|
|
return "pcrel udata4";
|
|
|
|
case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4:
|
|
|
|
return "pcrel sdata4";
|
|
|
|
case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8:
|
|
|
|
return "pcrel udata8";
|
|
|
|
case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8:
|
|
|
|
return "pcrel sdata8";
|
|
|
|
case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4:
|
|
|
|
return "indirect pcrel udata4";
|
|
|
|
case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4:
|
|
|
|
return "indirect pcrel sdata4";
|
|
|
|
case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8:
|
|
|
|
return "indirect pcrel udata8";
|
|
|
|
case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8:
|
|
|
|
return "indirect pcrel sdata8";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-17 15:46:39 +08:00
|
|
|
void AsmPrinter::EOL(const Twine &Comment, unsigned Encoding) const {
|
|
|
|
if (VerboseAsm && !Comment.isTriviallyEmpty()) {
|
2009-08-29 20:17:53 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
|
|
|
<< ' '
|
|
|
|
<< Comment;
|
|
|
|
|
|
|
|
if (const char *EncStr = DecodeDWARFEncoding(Encoding))
|
|
|
|
O << " (" << EncStr << ')';
|
|
|
|
}
|
|
|
|
O << '\n';
|
|
|
|
}
|
2008-07-02 05:16:27 +08:00
|
|
|
|
2007-01-25 23:12:02 +08:00
|
|
|
/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
|
|
|
|
/// unsigned leb128 value.
|
|
|
|
void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->hasLEB128()) {
|
2007-01-25 23:12:02 +08:00
|
|
|
O << "\t.uleb128\t"
|
|
|
|
<< Value;
|
|
|
|
} else {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 23:12:02 +08:00
|
|
|
PrintULEB128(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
|
|
|
|
/// signed leb128 value.
|
|
|
|
void AsmPrinter::EmitSLEB128Bytes(int Value) const {
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->hasLEB128()) {
|
2007-01-25 23:12:02 +08:00
|
|
|
O << "\t.sleb128\t"
|
|
|
|
<< Value;
|
|
|
|
} else {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 23:12:02 +08:00
|
|
|
PrintSLEB128(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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
|
|
|
}
|
|
|
|
|
|
|
|
/// toOctal - Convert the low order bits of X into an octal digit.
|
|
|
|
///
|
|
|
|
static inline char toOctal(int X) {
|
|
|
|
return (X&7)+'0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/// printStringChar - Print a char, escaped if necessary.
|
|
|
|
///
|
2009-07-15 04:18:05 +08:00
|
|
|
static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
|
2007-01-25 23:12:02 +08:00
|
|
|
if (C == '"') {
|
|
|
|
O << "\\\"";
|
|
|
|
} else if (C == '\\') {
|
|
|
|
O << "\\\\";
|
2009-01-23 07:38:45 +08:00
|
|
|
} else if (isprint((unsigned char)C)) {
|
2007-01-25 23:12:02 +08:00
|
|
|
O << C;
|
|
|
|
} else {
|
|
|
|
switch(C) {
|
|
|
|
case '\b': O << "\\b"; break;
|
|
|
|
case '\f': O << "\\f"; break;
|
|
|
|
case '\n': O << "\\n"; break;
|
|
|
|
case '\r': O << "\\r"; break;
|
|
|
|
case '\t': O << "\\t"; break;
|
|
|
|
default:
|
|
|
|
O << '\\';
|
|
|
|
O << toOctal(C >> 6);
|
|
|
|
O << toOctal(C >> 3);
|
|
|
|
O << toOctal(C >> 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitString - Emit a string with quotes and a null terminator.
|
|
|
|
/// Special characters are emitted properly.
|
|
|
|
/// \literal (Eg. '\t') \endliteral
|
2009-11-25 03:42:17 +08:00
|
|
|
void AsmPrinter::EmitString(const StringRef String) const {
|
2009-11-14 05:55:31 +08:00
|
|
|
EmitString(String.data(), String.size());
|
2009-04-10 07:51:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AsmPrinter::EmitString(const char *String, unsigned Size) const {
|
2009-08-23 05:43:10 +08:00
|
|
|
const char* AscizDirective = MAI->getAscizDirective();
|
2007-03-07 03:25:02 +08:00
|
|
|
if (AscizDirective)
|
|
|
|
O << AscizDirective;
|
|
|
|
else
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getAsciiDirective();
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\"';
|
2009-04-10 07:51:31 +08:00
|
|
|
for (unsigned i = 0; i < Size; ++i)
|
2009-04-08 08:28:38 +08:00
|
|
|
printStringChar(O, String[i]);
|
2007-03-07 03:25:02 +08:00
|
|
|
if (AscizDirective)
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\"';
|
2007-03-07 03:25:02 +08:00
|
|
|
else
|
|
|
|
O << "\\0\"";
|
2007-01-25 23:12:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-25 04:58:13 +08:00
|
|
|
/// EmitFile - Emit a .file directive.
|
2010-01-17 15:46:39 +08:00
|
|
|
void AsmPrinter::EmitFile(unsigned Number, StringRef Name) const {
|
2007-09-25 04:58:13 +08:00
|
|
|
O << "\t.file\t" << Number << " \"";
|
2009-04-08 08:28:38 +08:00
|
|
|
for (unsigned i = 0, N = Name.size(); i < N; ++i)
|
|
|
|
printStringChar(O, Name[i]);
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\"';
|
2007-09-25 04:58:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-08-17 07:15:22 +08:00
|
|
|
// Print out the specified constant, without a storage class. Only the
|
|
|
|
// constants valid in constant expressions can occur here.
|
2005-11-21 15:51:36 +08:00
|
|
|
void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
|
2010-01-13 12:29:19 +08:00
|
|
|
if (CV->isNullValue() || isa<UndefValue>(CV)) {
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '0';
|
2010-01-13 12:29:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
2008-06-03 14:18:19 +08:00
|
|
|
O << CI->getZExtValue();
|
2010-01-13 12:29:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
|
2005-04-02 20:21:51 +08:00
|
|
|
// This is a constant address for a global variable or function. Use the
|
2009-09-16 07:11:32 +08:00
|
|
|
// name of the variable or function as the address value.
|
2010-01-18 05:43:43 +08:00
|
|
|
O << *GetGlobalValueSymbol(GV);
|
2010-01-13 12:29:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
|
2010-01-18 05:43:43 +08:00
|
|
|
O << *GetBlockAddressSymbol(BA);
|
2010-01-13 12:29:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV);
|
|
|
|
if (CE == 0) {
|
|
|
|
llvm_unreachable("Unknown constant value!");
|
|
|
|
O << '0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
default:
|
|
|
|
llvm_unreachable("FIXME: Don't support this constant cast expr");
|
|
|
|
case Instruction::GetElementPtr: {
|
|
|
|
// generate a symbolic expression for the byte address
|
2006-05-03 09:29:57 +08:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2010-01-13 12:29:19 +08:00
|
|
|
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());
|
|
|
|
if (Offset == 0)
|
|
|
|
return EmitConstantValueOnly(ptrVal);
|
|
|
|
|
|
|
|
// Truncate/sext the offset to the pointer size.
|
|
|
|
if (TD->getPointerSizeInBits() != 64) {
|
|
|
|
int SExtAmount = 64-TD->getPointerSizeInBits();
|
|
|
|
Offset = (Offset << SExtAmount) >> SExtAmount;
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
2010-01-13 12:29:19 +08:00
|
|
|
|
|
|
|
if (Offset)
|
|
|
|
O << '(';
|
|
|
|
EmitConstantValueOnly(ptrVal);
|
|
|
|
if (Offset > 0)
|
|
|
|
O << ") + " << Offset;
|
|
|
|
else
|
|
|
|
O << ") - " << -Offset;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Instruction::BitCast:
|
|
|
|
return EmitConstantValueOnly(CE->getOperand(0));
|
|
|
|
|
|
|
|
case Instruction::IntToPtr: {
|
|
|
|
// Handle casts to pointers by changing them into casts to the appropriate
|
|
|
|
// integer type. This promotes constant folding and simplifies this code.
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
Constant *Op = CE->getOperand(0);
|
|
|
|
Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
|
|
|
|
false/*ZExt*/);
|
|
|
|
return EmitConstantValueOnly(Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Instruction::PtrToInt: {
|
|
|
|
// 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();
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
|
|
|
|
// We can emit the pointer value into this slot if the slot is an
|
|
|
|
// integer slot greater or equal to the size of the pointer.
|
|
|
|
if (TD->getTypeAllocSize(Ty) == TD->getTypeAllocSize(Op->getType()))
|
2006-12-12 13:18:19 +08:00
|
|
|
return EmitConstantValueOnly(Op);
|
2010-01-13 12:29:19 +08:00
|
|
|
|
|
|
|
O << "((";
|
|
|
|
EmitConstantValueOnly(Op);
|
|
|
|
APInt ptrMask =
|
|
|
|
APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Op->getType()));
|
|
|
|
|
|
|
|
SmallString<40> S;
|
|
|
|
ptrMask.toStringUnsigned(S);
|
|
|
|
O << ") & " << S.str() << ')';
|
|
|
|
return;
|
|
|
|
}
|
2006-12-12 13:18:19 +08:00
|
|
|
|
2010-01-13 12:29:19 +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.
|
|
|
|
return EmitConstantValueOnly(CE->getOperand(0));
|
2008-08-17 15:19:36 +08:00
|
|
|
|
2010-01-13 12:29:19 +08:00
|
|
|
case Instruction::Add:
|
|
|
|
case Instruction::Sub:
|
|
|
|
case Instruction::And:
|
|
|
|
case Instruction::Or:
|
|
|
|
case Instruction::Xor:
|
|
|
|
O << '(';
|
|
|
|
EmitConstantValueOnly(CE->getOperand(0));
|
|
|
|
O << ')';
|
|
|
|
switch (CE->getOpcode()) {
|
2004-08-17 07:15:22 +08:00
|
|
|
case Instruction::Add:
|
2010-01-13 12:29:19 +08:00
|
|
|
O << " + ";
|
|
|
|
break;
|
2007-02-05 07:27:42 +08:00
|
|
|
case Instruction::Sub:
|
2010-01-13 12:29:19 +08:00
|
|
|
O << " - ";
|
|
|
|
break;
|
2007-12-19 04:53:41 +08:00
|
|
|
case Instruction::And:
|
2010-01-13 12:29:19 +08:00
|
|
|
O << " & ";
|
|
|
|
break;
|
2007-12-19 04:53:41 +08:00
|
|
|
case Instruction::Or:
|
2010-01-13 12:29:19 +08:00
|
|
|
O << " | ";
|
|
|
|
break;
|
2007-12-19 04:53:41 +08:00
|
|
|
case Instruction::Xor:
|
2010-01-13 12:29:19 +08:00
|
|
|
O << " ^ ";
|
|
|
|
break;
|
2004-08-17 07:15:22 +08:00
|
|
|
default:
|
2010-01-13 12:29:19 +08:00
|
|
|
break;
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
2010-01-13 12:29:19 +08:00
|
|
|
O << '(';
|
|
|
|
EmitConstantValueOnly(CE->getOperand(1));
|
|
|
|
O << ')';
|
|
|
|
break;
|
2004-08-17 07:15:22 +08:00
|
|
|
}
|
|
|
|
}
|
2004-08-17 14:36:49 +08:00
|
|
|
|
2005-11-11 02:06:33 +08:00
|
|
|
/// printAsCString - Print the specified array as a C compatible string, only if
|
2004-08-17 14:36:49 +08:00
|
|
|
/// the predicate isString is true.
|
|
|
|
///
|
2009-07-15 04:18:05 +08:00
|
|
|
static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
|
2005-11-11 02:06:33 +08:00
|
|
|
unsigned LastElt) {
|
2004-08-17 14:36:49 +08:00
|
|
|
assert(CVA->isString() && "Array is not string compatible!");
|
|
|
|
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\"';
|
2005-11-11 02:06:33 +08:00
|
|
|
for (unsigned i = 0; i != LastElt; ++i) {
|
2005-04-22 06:36:52 +08:00
|
|
|
unsigned char C =
|
2006-10-20 15:07:24 +08:00
|
|
|
(unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
|
2007-01-25 23:12:02 +08:00
|
|
|
printStringChar(O, C);
|
2004-08-17 14:36:49 +08:00
|
|
|
}
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\"';
|
2004-08-17 14:36:49 +08:00
|
|
|
}
|
|
|
|
|
2006-05-02 09:16:28 +08:00
|
|
|
/// EmitString - Emit a zero-byte-terminated string constant.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitString(const ConstantArray *CVA) const {
|
|
|
|
unsigned NumElts = CVA->getNumOperands();
|
2009-08-23 05:43:10 +08:00
|
|
|
if (MAI->getAscizDirective() && NumElts &&
|
2006-10-20 15:07:24 +08:00
|
|
|
cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getAscizDirective();
|
2006-05-02 09:16:28 +08:00
|
|
|
printAsCString(O, CVA, NumElts-1);
|
|
|
|
} else {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getAsciiDirective();
|
2006-05-02 09:16:28 +08:00
|
|
|
printAsCString(O, CVA, NumElts);
|
|
|
|
}
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\n';
|
2006-05-02 09:16:28 +08:00
|
|
|
}
|
|
|
|
|
2010-01-20 03:10:44 +08:00
|
|
|
static void EmitGlobalConstantArray(const ConstantArray *CA, unsigned AddrSpace,
|
|
|
|
AsmPrinter &AP) {
|
|
|
|
if (AddrSpace == 0 && CA->isString()) {
|
|
|
|
AP.EmitString(CA);
|
2008-12-23 05:14:27 +08:00
|
|
|
} else { // 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);
|
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) {
|
|
|
|
const VectorType *VTy = CV->getType();
|
|
|
|
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
|
|
|
|
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) {
|
|
|
|
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:11:32 +08:00
|
|
|
uint64_t FieldSize = TD->getTypeAllocSize(field->getType());
|
|
|
|
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 03:10:44 +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-20 06:16:33 +08:00
|
|
|
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
|
2010-01-20 15:11:32 +08:00
|
|
|
AP.O.PadToColumn(AP.MAI->getCommentColumn());
|
|
|
|
AP.O << AP.MAI->getCommentString() << " 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-20 06:16:33 +08:00
|
|
|
float Val = CFP->getValueAPF().convertToFloat(); // for comment only
|
2010-01-20 15:11:32 +08:00
|
|
|
AP.O.PadToColumn(AP.MAI->getCommentColumn());
|
|
|
|
AP.O << AP.MAI->getCommentString() << " 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-20 15:11:32 +08:00
|
|
|
AP.O.PadToColumn(AP.MAI->getCommentColumn());
|
|
|
|
AP.O << AP.MAI->getCommentString() << " 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:
|
|
|
|
if (VerboseAsm) {
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " 0x";
|
|
|
|
O.write_hex(CI->getZExtValue());
|
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
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-20 15:33:29 +08:00
|
|
|
// Otherwise, it must be a ConstantExpr. Emit the data directive, then emit
|
|
|
|
// the expression value.
|
|
|
|
switch (TM.getTargetData()->getTypeAllocSize(CV->getType())) {
|
|
|
|
case 0: return;
|
|
|
|
case 1: O << MAI->getData8bitsDirective(AddrSpace); break;
|
|
|
|
case 2: O << MAI->getData16bitsDirective(AddrSpace); break;
|
|
|
|
case 4: O << MAI->getData32bitsDirective(AddrSpace); break;
|
|
|
|
case 8:
|
|
|
|
if (const char *Dir = MAI->getData64bitsDirective(AddrSpace)) {
|
|
|
|
O << Dir;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FALL THROUGH.
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Target cannot handle given data directive width!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-21 15:51:36 +08:00
|
|
|
EmitConstantValueOnly(CV);
|
2008-07-01 06:03:41 +08:00
|
|
|
O << '\n';
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
OutStreamer.EmitLabel(GetBlockAddressSymbol(BB->getParent(), BB));
|
2009-10-30 09:27:03 +08:00
|
|
|
if (VerboseAsm) {
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2010-01-20 15:24:05 +08:00
|
|
|
O << MAI->getCommentString() << " Address Taken" << '\n';
|
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()) {
|
|
|
|
if (VerboseAsm)
|
|
|
|
O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
|
|
|
|
} else {
|
2010-01-20 15:24:05 +08:00
|
|
|
OutStreamer.EmitLabel(GetMBBSymbol(MBB->getNumber()));
|
2009-10-07 01:38:38 +08:00
|
|
|
}
|
2009-09-14 02:25:37 +08:00
|
|
|
|
2009-10-30 09:34:35 +08:00
|
|
|
// Print some comments to accompany the label.
|
2009-09-14 02:25:37 +08:00
|
|
|
if (VerboseAsm) {
|
2009-08-13 02:47:05 +08:00
|
|
|
if (const BasicBlock *BB = MBB->getBasicBlock())
|
|
|
|
if (BB->hasName()) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << ' ';
|
2009-08-13 04:56:56 +08:00
|
|
|
WriteAsOperand(O, BB, /*PrintType=*/false);
|
2009-08-13 02:47:05 +08:00
|
|
|
}
|
2009-08-11 00:38:07 +08:00
|
|
|
|
2009-09-14 02:25:37 +08:00
|
|
|
EmitComments(*MBB);
|
2009-10-07 01:38:38 +08:00
|
|
|
O << '\n';
|
2009-08-11 00:38:07 +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())
|
|
|
|
<< '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 13:57:21 +08:00
|
|
|
<< '_' << uid << '\n';
|
2006-08-13 05:29:52 +08:00
|
|
|
}
|
2006-09-13 05:00:35 +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
|
|
|
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
|
|
|
|
const MachineBasicBlock *MBB) const {
|
2009-08-23 05:43:10 +08:00
|
|
|
if (!MAI->getSetDirective())
|
2006-11-01 17:23:08 +08:00
|
|
|
return;
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
|
2007-10-14 13:57:21 +08:00
|
|
|
<< getFunctionNumber() << '_' << uid << '_' << uid2
|
2010-01-18 05:43:43 +08:00
|
|
|
<< "_set_" << MBB->getNumber() << ','
|
|
|
|
<< *GetMBBSymbol(MBB->getNumber())
|
|
|
|
<< '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 13:57:21 +08:00
|
|
|
<< '_' << uid << '_' << uid2 << '\n';
|
2006-11-01 17:23:08 +08:00
|
|
|
}
|
|
|
|
|
2010-01-16 07:38:51 +08:00
|
|
|
void AsmPrinter::printVisibility(const MCSymbol *Sym,
|
|
|
|
unsigned Visibility) const {
|
|
|
|
if (Visibility == GlobalValue::HiddenVisibility) {
|
2010-01-18 05:43:43 +08:00
|
|
|
if (const char *Directive = MAI->getHiddenDirective())
|
|
|
|
O << Directive << *Sym << '\n';
|
2010-01-16 07:38:51 +08:00
|
|
|
} else if (Visibility == GlobalValue::ProtectedVisibility) {
|
2010-01-18 05:43:43 +08:00
|
|
|
if (const char *Directive = MAI->getProtectedDirective())
|
|
|
|
O << Directive << *Sym << '\n';
|
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
|
|
|
}
|
|
|
|
|
2009-08-23 15:19:13 +08:00
|
|
|
errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable(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
|
|
|
}
|
|
|
|
|
2009-08-19 03:22:55 +08:00
|
|
|
/// PrintChildLoopComment - Print comments about child loops within
|
|
|
|
/// the loop for this basic block, with nesting.
|
|
|
|
///
|
|
|
|
static void PrintChildLoopComment(formatted_raw_ostream &O,
|
|
|
|
const MachineLoop *loop,
|
2009-08-23 05:43:10 +08:00
|
|
|
const MCAsmInfo *MAI,
|
2009-08-19 03:22:55 +08:00
|
|
|
int FunctionNumber) {
|
|
|
|
// Add child loop information
|
|
|
|
for(MachineLoop::iterator cl = loop->begin(),
|
|
|
|
clend = loop->end();
|
|
|
|
cl != clend;
|
|
|
|
++cl) {
|
|
|
|
MachineBasicBlock *Header = (*cl)->getHeader();
|
|
|
|
assert(Header && "No header for loop");
|
|
|
|
|
|
|
|
O << '\n';
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-08-19 03:22:55 +08:00
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString();
|
2009-08-23 08:51:00 +08:00
|
|
|
O.indent(((*cl)->getLoopDepth()-1)*2)
|
2009-08-19 03:22:55 +08:00
|
|
|
<< " Child Loop BB" << FunctionNumber << "_"
|
|
|
|
<< Header->getNumber() << " Depth " << (*cl)->getLoopDepth();
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
PrintChildLoopComment(O, *cl, MAI, FunctionNumber);
|
2009-08-19 03:22:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 00:38:07 +08:00
|
|
|
/// EmitComments - Pretty-print comments for basic blocks
|
2009-11-14 05:34:57 +08:00
|
|
|
void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const {
|
2009-08-19 03:22:55 +08:00
|
|
|
if (VerboseAsm) {
|
2009-08-11 00:38:07 +08:00
|
|
|
// Add loop depth information
|
|
|
|
const MachineLoop *loop = LI->getLoopFor(&MBB);
|
|
|
|
|
|
|
|
if (loop) {
|
|
|
|
// Print a newline after bb# annotation.
|
|
|
|
O << "\n";
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth()
|
2009-08-11 00:38:07 +08:00
|
|
|
<< '\n';
|
|
|
|
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-08-11 00:38:07 +08:00
|
|
|
|
|
|
|
MachineBasicBlock *Header = loop->getHeader();
|
|
|
|
assert(Header && "No header for loop");
|
|
|
|
|
|
|
|
if (Header == &MBB) {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString() << " Loop Header";
|
|
|
|
PrintChildLoopComment(O, loop, MAI, getFunctionNumber());
|
2009-08-11 00:38:07 +08:00
|
|
|
}
|
|
|
|
else {
|
2009-08-23 05:43:10 +08:00
|
|
|
O << MAI->getCommentString() << " Loop Header is BB"
|
2009-08-11 00:38:07 +08:00
|
|
|
<< getFunctionNumber() << "_" << loop->getHeader()->getNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loop->empty()) {
|
|
|
|
O << '\n';
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Inner Loop";
|
2009-08-11 00:38:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add parent loop information
|
|
|
|
for (const MachineLoop *CurLoop = loop->getParentLoop();
|
|
|
|
CurLoop;
|
|
|
|
CurLoop = CurLoop->getParentLoop()) {
|
|
|
|
MachineBasicBlock *Header = CurLoop->getHeader();
|
|
|
|
assert(Header && "No header for loop");
|
|
|
|
|
|
|
|
O << '\n';
|
2009-08-23 05:43:10 +08:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString();
|
2009-08-23 08:51:00 +08:00
|
|
|
O.indent((CurLoop->getLoopDepth()-1)*2)
|
2009-08-19 03:22:55 +08:00
|
|
|
<< " Inside Loop BB" << getFunctionNumber() << "_"
|
2009-08-11 00:38:07 +08:00
|
|
|
<< Header->getNumber() << " Depth " << CurLoop->getLoopDepth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|