2004-08-16 23:15:22 +00:00
|
|
|
//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-08-16 23:15:22 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the AsmPrinter class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-03-03 02:04:29 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2006-03-01 22:18:09 +00: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
}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24616 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-06 06:18:55 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2004-08-16 23:15:22 +00:00
|
|
|
#include "llvm/Constants.h"
|
2005-11-10 18:36:17 +00:00
|
|
|
#include "llvm/Module.h"
|
2008-08-17 18:44:35 +00:00
|
|
|
#include "llvm/CodeGen/GCMetadataPrinter.h"
|
2005-11-21 08:25:09 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2009-08-18 19:22:55 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2006-04-22 18:53:45 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2009-08-10 16:38:07 +00:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2009-01-13 21:44:10 +00:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2009-05-07 13:55:51 +00:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-07-27 21:28:04 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-07-16 22:24:20 +00:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-07-31 18:48:30 +00:00
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-09-12 23:02:08 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2009-03-25 01:47:28 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-11 13:10:19 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-13 20:25:48 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2004-08-16 23:15:22 +00:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2006-05-12 06:33:49 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-10-06 22:50:56 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2009-07-28 03:13:23 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2008-07-01 23:18:29 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2008-03-15 00:03:38 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2008-08-17 07:19:36 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2008-08-21 00:14:44 +00:00
|
|
|
#include "llvm/ADT/StringExtras.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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
#include <cerrno>
|
2004-08-16 23:15:22 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-03-25 01:47:28 +00:00
|
|
|
static cl::opt<cl::boolOrDefault>
|
|
|
|
AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
|
|
|
|
cl::init(cl::BOU_UNSET));
|
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char AsmPrinter::ID = 0;
|
2009-07-14 20:18:05 +00:00
|
|
|
AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
2009-08-22 20:48:53 +00:00
|
|
|
const MCAsmInfo *T, bool VDef)
|
2009-07-01 01:48:54 +00:00
|
|
|
: MachineFunctionPass(&ID), FunctionNumber(0), O(o),
|
2009-08-22 21:43:10 +00:00
|
|
|
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
2009-07-27 21:28:04 +00:00
|
|
|
|
|
|
|
OutContext(*new MCContext()),
|
2009-09-14 03:02:37 +00:00
|
|
|
// FIXME: Pass instprinter to streamer.
|
|
|
|
OutStreamer(*createAsmStreamer(OutContext, O, *T, 0)),
|
2009-07-27 21:28:04 +00:00
|
|
|
|
2009-08-03 23:20:21 +00:00
|
|
|
LastMI(0), LastFn(0), Counter(~0U),
|
2009-10-01 01:15:28 +00:00
|
|
|
PrevDLT(0, 0, ~0U, ~0U) {
|
2009-06-24 19:09:55 +00:00
|
|
|
DW = 0; MMI = 0;
|
2009-03-25 01:47:28 +00: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 06:32:10 +00:00
|
|
|
|
2008-08-17 12:08:44 +00:00
|
|
|
AsmPrinter::~AsmPrinter() {
|
|
|
|
for (gcp_iterator I = GCMetadataPrinters.begin(),
|
|
|
|
E = GCMetadataPrinters.end(); I != E; ++I)
|
|
|
|
delete I->second;
|
2009-07-27 21:28:04 +00:00
|
|
|
|
|
|
|
delete &OutStreamer;
|
|
|
|
delete &OutContext;
|
2008-08-17 12:08:44 +00:00
|
|
|
}
|
2005-12-13 06:32:10 +00:00
|
|
|
|
2009-08-03 19:12:26 +00:00
|
|
|
TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
|
2009-07-28 03:13:23 +00:00
|
|
|
return TM.getTargetLowering()->getObjFileLowering();
|
|
|
|
}
|
|
|
|
|
2009-08-18 06:15:16 +00:00
|
|
|
/// getCurrentSection() - Return the current section we are emitting to.
|
|
|
|
const MCSection *AsmPrinter::getCurrentSection() const {
|
|
|
|
return OutStreamer.getCurrentSection();
|
2008-09-24 22:12:10 +00:00
|
|
|
}
|
2006-05-09 04:59:56 +00:00
|
|
|
|
2009-08-18 06:15:16 +00:00
|
|
|
|
2008-01-07 01:30:38 +00:00
|
|
|
void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
|
2009-07-31 23:37:33 +00:00
|
|
|
AU.setPreservesAll();
|
2008-01-07 01:30:38 +00:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2008-08-17 18:44:35 +00:00
|
|
|
AU.addRequired<GCModuleInfo>();
|
2009-08-18 19:22:55 +00:00
|
|
|
if (VerboseAsm)
|
2009-08-10 16:38:07 +00:00
|
|
|
AU.addRequired<MachineLoopInfo>();
|
2008-01-07 01:30:38 +00:00
|
|
|
}
|
|
|
|
|
2004-08-16 23:15:22 +00:00
|
|
|
bool AsmPrinter::doInitialization(Module &M) {
|
2009-07-31 17:42:42 +00:00
|
|
|
// Initialize TargetLoweringObjectFile.
|
|
|
|
const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
|
|
|
|
.Initialize(OutContext, TM);
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
Mang = new Mangler(M, MAI->getGlobalPrefix(), MAI->getPrivateGlobalPrefix(),
|
|
|
|
MAI->getLinkerPrivateGlobalPrefix());
|
2006-01-23 23:47:53 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->doesAllowQuotesInName())
|
2009-06-18 23:41:35 +00:00
|
|
|
Mang->setUseQuotes(true);
|
2009-09-18 16:57:42 +00:00
|
|
|
|
|
|
|
if (MAI->doesAllowNameToStartWithDigit())
|
|
|
|
Mang->setSymbolsCanStartWithDigit(true);
|
2009-06-18 23:41:35 +00:00
|
|
|
|
2009-09-30 22:06:26 +00:00
|
|
|
// Allow the target to emit any magic that it wants at the start of the file.
|
|
|
|
EmitStartOfAsmFile(M);
|
2008-12-03 11:01:37 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->hasSingleParameterDotFile()) {
|
2008-12-03 11:01:37 +00:00
|
|
|
/* Very minimal debug info. It is ignored if we emit actual
|
2009-09-30 21:26:13 +00:00
|
|
|
debug info. If we don't, this at least helps the user find where
|
2008-12-03 11:01:37 +00:00
|
|
|
a function came from. */
|
|
|
|
O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
|
|
|
|
}
|
|
|
|
|
2009-09-30 22:06:26 +00:00
|
|
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
|
|
|
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
|
2008-08-17 18:44:35 +00:00
|
|
|
for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
|
|
|
|
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
|
2009-08-22 21:43:10 +00:00
|
|
|
MP->beginAssembly(O, *this, *MAI);
|
2008-01-07 01:30:38 +00:00
|
|
|
|
2006-01-24 04:16:34 +00:00
|
|
|
if (!M.getModuleInlineAsm().empty())
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString() << " Start of file scope inline assembly\n"
|
2006-01-24 04:16:34 +00:00
|
|
|
<< M.getModuleInlineAsm()
|
2009-08-22 21:43:10 +00:00
|
|
|
<< '\n' << MAI->getCommentString()
|
2006-09-06 18:34:40 +00:00
|
|
|
<< " End of file scope inline assembly\n";
|
2006-01-23 23:47:53 +00:00
|
|
|
|
2009-09-24 05:44:53 +00:00
|
|
|
MMI = getAnalysisIfAvailable<MachineModuleInfo>();
|
|
|
|
if (MMI)
|
|
|
|
MMI->AnalyzeModule(M);
|
|
|
|
DW = getAnalysisIfAvailable<DwarfWriter>();
|
|
|
|
if (DW)
|
|
|
|
DW->BeginModule(&M, MMI, O, this, MAI);
|
2009-06-19 21:54:26 +00:00
|
|
|
|
2004-08-16 23:15:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsmPrinter::doFinalization(Module &M) {
|
2009-07-21 18:38:57 +00:00
|
|
|
// Emit global variables.
|
|
|
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ++I)
|
|
|
|
PrintGlobalVariable(I);
|
|
|
|
|
2009-06-24 18:54:37 +00:00
|
|
|
// Emit final debug information.
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling())
|
2009-06-24 18:54:37 +00:00
|
|
|
DW->EndModule();
|
|
|
|
|
2009-06-24 18:52:01 +00:00
|
|
|
// If the target wants to know about weak references, print them all.
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getWeakRefDirective()) {
|
2009-06-24 18:52:01 +00: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) {
|
|
|
|
if (I->hasExternalWeakLinkage())
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
|
2009-06-24 18:52:01 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 23:10:34 +00:00
|
|
|
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
2009-06-24 18:52:01 +00:00
|
|
|
if (I->hasExternalWeakLinkage())
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
|
2009-06-24 18:52:01 +00:00
|
|
|
}
|
2006-12-18 03:37:18 +00:00
|
|
|
}
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getSetDirective()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2007-04-25 14:27:10 +00:00
|
|
|
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
|
2009-06-24 18:52:01 +00:00
|
|
|
I != E; ++I) {
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string Name = Mang->getMangledName(I);
|
2007-09-06 17:21:48 +00:00
|
|
|
|
|
|
|
const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
|
2009-07-14 18:17:16 +00:00
|
|
|
std::string Target = Mang->getMangledName(GV);
|
2008-09-24 22:21:04 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())
|
2008-06-30 22:03:41 +00:00
|
|
|
O << "\t.globl\t" << Name << '\n';
|
2007-04-25 14:27:10 +00:00
|
|
|
else if (I->hasWeakLinkage())
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getWeakRefDirective() << Name << '\n';
|
2009-01-15 20:18:42 +00:00
|
|
|
else if (!I->hasLocalLinkage())
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Invalid alias linkage");
|
2008-03-11 21:41:14 +00:00
|
|
|
|
2008-09-24 22:21:04 +00:00
|
|
|
printVisibility(Name, I->getVisibility());
|
2008-03-11 21:41:14 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getSetDirective() << ' ' << Name << ", " << Target << '\n';
|
2007-04-25 14:27:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 13:14:17 +00:00
|
|
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
2008-08-17 18:44:35 +00: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-22 21:43:10 +00:00
|
|
|
MP->finishAssembly(O, *this, *MAI);
|
2008-01-07 01:30:38 +00:00
|
|
|
|
2008-05-05 00:28:39 +00: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-24 18:52:01 +00:00
|
|
|
Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
|
2008-05-05 00:28:39 +00:00
|
|
|
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getNonexecutableStackDirective())
|
|
|
|
O << MAI->getNonexecutableStackDirective() << '\n';
|
2008-05-05 00:28:39 +00:00
|
|
|
|
2009-09-18 20:17:03 +00: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-16 23:15:22 +00:00
|
|
|
delete Mang; Mang = 0;
|
2009-06-24 19:09:55 +00:00
|
|
|
DW = 0; MMI = 0;
|
2009-07-27 21:28:04 +00:00
|
|
|
|
|
|
|
OutStreamer.Finish();
|
2004-08-16 23:15:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-11-21 07:51:36 +00:00
|
|
|
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
|
2004-08-16 23:15:22 +00:00
|
|
|
// What's my mangled name?
|
2009-07-14 18:17:16 +00:00
|
|
|
CurrentFnName = Mang->getMangledName(MF.getFunction());
|
2007-10-14 05:57:21 +00:00
|
|
|
IncrementFunctionNumber();
|
2009-08-10 16:38:07 +00:00
|
|
|
|
2009-09-16 00:35:39 +00:00
|
|
|
if (VerboseAsm)
|
2009-08-10 16:38:07 +00:00
|
|
|
LI = &getAnalysis<MachineLoopInfo>();
|
2004-08-16 23:15:22 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 07:51:59 +00:00
|
|
|
namespace {
|
|
|
|
// SectionCPs - Keep track the alignment, constpool entries per Section.
|
|
|
|
struct SectionCPs {
|
2009-07-31 18:48:30 +00:00
|
|
|
const MCSection *S;
|
2009-03-13 07:51:59 +00:00
|
|
|
unsigned Alignment;
|
|
|
|
SmallVector<unsigned, 4> CPEs;
|
2009-07-31 18:48:30 +00:00
|
|
|
SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {};
|
2009-03-13 07:51:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-11-21 08:25:09 +00: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 04:22:52 +00:00
|
|
|
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
|
2005-11-21 08:25:09 +00:00
|
|
|
if (CP.empty()) return;
|
2006-06-29 00:26:09 +00:00
|
|
|
|
2008-09-24 22:17:59 +00: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 07:51:59 +00:00
|
|
|
SmallVector<SectionCPs, 4> CPSections;
|
2006-06-29 00:26:09 +00:00
|
|
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
2009-07-22 00:28:43 +00:00
|
|
|
const MachineConstantPoolEntry &CPE = CP[i];
|
2009-03-13 07:51:59 +00:00
|
|
|
unsigned Align = CPE.getAlignment();
|
2009-07-26 06:26:55 +00:00
|
|
|
|
|
|
|
SectionKind Kind;
|
|
|
|
switch (CPE.getRelocationInfo()) {
|
|
|
|
default: llvm_unreachable("Unknown section kind");
|
2009-08-01 23:57:16 +00:00
|
|
|
case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
|
2009-07-26 07:00:12 +00:00
|
|
|
case 1:
|
2009-08-01 23:57:16 +00:00
|
|
|
Kind = SectionKind::getReadOnlyWithRelLocal();
|
2009-07-26 07:00:12 +00:00
|
|
|
break;
|
2009-07-26 06:26:55 +00:00
|
|
|
case 0:
|
2009-07-26 07:00:12 +00:00
|
|
|
switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
|
2009-08-01 23:57:16 +00: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 07:00:12 +00:00
|
|
|
}
|
2009-07-26 06:26:55 +00:00
|
|
|
}
|
|
|
|
|
2009-08-01 23:46:12 +00:00
|
|
|
const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);
|
2009-07-22 00:28:43 +00:00
|
|
|
|
2009-03-13 07:51:59 +00: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 00:26:09 +00:00
|
|
|
}
|
|
|
|
|
2008-09-24 22:17:59 +00:00
|
|
|
// Now print stuff into the calculated sections.
|
2009-03-13 07:51:59 +00:00
|
|
|
for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
|
2009-08-19 05:49:37 +00:00
|
|
|
OutStreamer.SwitchSection(CPSections[i].S);
|
2009-03-13 07:51:59 +00:00
|
|
|
EmitAlignment(Log2_32(CPSections[i].Alignment));
|
2006-06-29 00:26:09 +00:00
|
|
|
|
2009-03-13 07:51:59 +00: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;
|
|
|
|
EmitZeros(NewOffset - Offset);
|
|
|
|
|
|
|
|
const Type *Ty = CPE.getType();
|
2009-05-09 07:06:46 +00:00
|
|
|
Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
|
2006-06-29 00:26:09 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
|
2009-08-12 18:32:22 +00:00
|
|
|
<< CPI << ':';
|
2009-03-13 07:51:59 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " constant ";
|
2009-08-13 01:36:44 +00:00
|
|
|
WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent());
|
2009-03-13 07:51:59 +00:00
|
|
|
}
|
2008-09-24 22:17:59 +00:00
|
|
|
O << '\n';
|
2009-03-13 07:51:59 +00:00
|
|
|
if (CPE.isMachineConstantPoolEntry())
|
|
|
|
EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
|
2008-09-24 22:17:59 +00:00
|
|
|
else
|
2009-03-13 07:51:59 +00:00
|
|
|
EmitGlobalConstant(CPE.Val.ConstVal);
|
2006-02-09 04:46:04 +00:00
|
|
|
}
|
2005-11-21 08:25:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
/// EmitJumpTableInfo - Print assembly representations of the jump tables used
|
|
|
|
/// by the current function to the current output stream.
|
|
|
|
///
|
2006-10-05 03:01:21 +00:00
|
|
|
void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
|
|
|
MachineFunction &MF) {
|
2006-04-22 18:53:45 +00:00
|
|
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
|
|
|
if (JT.empty()) return;
|
2007-11-14 09:18:41 +00:00
|
|
|
|
2006-12-14 19:17:33 +00:00
|
|
|
bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
|
2006-07-27 16:46:58 +00:00
|
|
|
|
2006-07-27 01:13:04 +00:00
|
|
|
// Pick the directive to use to print the jump table entries, and switch to
|
|
|
|
// the appropriate section.
|
2006-12-14 19:17:33 +00:00
|
|
|
TargetLowering *LoweringInfo = TM.getTargetLowering();
|
2006-12-19 21:04:20 +00:00
|
|
|
|
2008-07-09 13:27:16 +00:00
|
|
|
const Function *F = MF.getFunction();
|
2009-06-18 20:37:15 +00:00
|
|
|
bool JTInDiffSection = false;
|
2009-08-01 23:46:12 +00:00
|
|
|
if (F->isWeakForLinker() ||
|
|
|
|
(IsPic && !LoweringInfo->usesGlobalOffsetTable())) {
|
2006-12-14 19:17:33 +00: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 13:27:16 +00:00
|
|
|
// We should also do if the section name is NULL or function is declared in
|
|
|
|
// discardable section.
|
2009-08-19 05:49:37 +00:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang,
|
|
|
|
TM));
|
2006-07-27 01:13:04 +00:00
|
|
|
} else {
|
2009-08-01 23:46:12 +00:00
|
|
|
// Otherwise, drop it in the readonly section.
|
|
|
|
const MCSection *ReadOnlySection =
|
2009-08-01 23:57:16 +00:00
|
|
|
getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());
|
2009-08-19 05:49:37 +00:00
|
|
|
OutStreamer.SwitchSection(ReadOnlySection);
|
2009-06-18 20:37:15 +00:00
|
|
|
JTInDiffSection = true;
|
2006-07-27 01:13:04 +00:00
|
|
|
}
|
2006-12-14 19:17:33 +00:00
|
|
|
|
|
|
|
EmitAlignment(Log2_32(MJTI->getAlignment()));
|
2006-07-15 01:34:12 +00:00
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
for (unsigned i = 0, e = JT.size(); i != e; ++i) {
|
2006-08-12 21:29:52 +00:00
|
|
|
const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
|
2006-10-28 18:10:06 +00:00
|
|
|
|
|
|
|
// If this jump table was deleted, ignore it.
|
|
|
|
if (JTBBs.empty()) continue;
|
2006-08-12 21:29:52 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getSetDirective() && IsPic)
|
2006-08-12 21:29:52 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
if (EmittedSets.insert(JTBBs[ii]))
|
|
|
|
printPICJumpTableSetLabel(i, JTBBs[ii]);
|
2006-08-12 21:29:52 +00:00
|
|
|
|
2009-09-13 19:02:16 +00:00
|
|
|
// On some targets (e.g. Darwin) we want to emit two consequtive labels
|
2007-01-18 01:12:56 +00: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-13 19:02:16 +00:00
|
|
|
if (JTInDiffSection && MAI->getLinkerPrivateGlobalPrefix()[0]) {
|
|
|
|
O << MAI->getLinkerPrivateGlobalPrefix()
|
|
|
|
<< "JTI" << getFunctionNumber() << '_' << i << ":\n";
|
2009-06-18 20:37:15 +00:00
|
|
|
}
|
2007-01-18 01:12:56 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 05:57:21 +00:00
|
|
|
<< '_' << i << ":\n";
|
2006-08-12 21:29:52 +00:00
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
|
2007-11-14 09:18:41 +00:00
|
|
|
printPICJumpTableEntry(MJTI, JTBBs[ii], i);
|
2006-04-22 18:53:45 +00:00
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 09:18:41 +00:00
|
|
|
void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
|
|
|
const MachineBasicBlock *MBB,
|
|
|
|
unsigned uid) const {
|
2009-08-11 20:29:57 +00:00
|
|
|
bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
|
2007-11-14 09:18:41 +00:00
|
|
|
|
|
|
|
// Use JumpTableDirective otherwise honor the entry size from the jump table
|
|
|
|
// info.
|
2009-08-22 21:43:10 +00:00
|
|
|
const char *JTEntryDirective = MAI->getJumpTableDirective(isPIC);
|
2007-11-14 09:18:41 +00:00
|
|
|
bool HadJTEntryDirective = JTEntryDirective != NULL;
|
|
|
|
if (!HadJTEntryDirective) {
|
|
|
|
JTEntryDirective = MJTI->getEntrySize() == 4 ?
|
2009-08-22 21:43:10 +00:00
|
|
|
MAI->getData32bitsDirective() : MAI->getData64bitsDirective();
|
2007-11-14 09:18:41 +00: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-11 20:29:57 +00:00
|
|
|
if (!isPIC) {
|
2009-09-13 17:14:04 +00:00
|
|
|
GetMBBSymbol(MBB->getNumber())->print(O, MAI);
|
2009-08-22 21:43:10 +00:00
|
|
|
} else if (MAI->getSetDirective()) {
|
|
|
|
O << MAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
2009-08-11 20:29:57 +00:00
|
|
|
<< '_' << uid << "_set_" << MBB->getNumber();
|
2007-11-14 09:18:41 +00:00
|
|
|
} else {
|
2009-09-13 17:14:04 +00:00
|
|
|
GetMBBSymbol(MBB->getNumber())->print(O, MAI);
|
2009-08-11 20:29:57 +00:00
|
|
|
// If the arch uses custom Jump Table directives, don't calc relative to
|
|
|
|
// JT
|
|
|
|
if (!HadJTEntryDirective)
|
2009-08-22 21:43:10 +00:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI"
|
2009-08-11 20:29:57 +00:00
|
|
|
<< getFunctionNumber() << '_' << uid;
|
2007-11-14 09:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-13 06:32:10 +00: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-25 23:55:21 +00:00
|
|
|
if (GV->getName() == "llvm.used") {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getUsedDirective() != 0) // No need to emit this at all.
|
2007-08-22 19:33:11 +00:00
|
|
|
EmitLLVMUsedList(GV->getInitializer());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-20 06:14:25 +00:00
|
|
|
// Ignore debug and non-emitted data. This handles llvm.compiler.used.
|
2009-04-13 05:44:34 +00:00
|
|
|
if (GV->getSection() == "llvm.metadata" ||
|
|
|
|
GV->hasAvailableExternallyLinkage())
|
|
|
|
return true;
|
2006-03-07 22:00:35 +00:00
|
|
|
|
|
|
|
if (!GV->hasAppendingLinkage()) return false;
|
|
|
|
|
|
|
|
assert(GV->hasInitializer() && "Not a special LLVM global!");
|
2005-12-13 06:32:10 +00:00
|
|
|
|
2007-06-04 20:39:18 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
unsigned Align = Log2_32(TD->getPointerPrefAlignment());
|
2009-03-09 05:52:15 +00:00
|
|
|
if (GV->getName() == "llvm.global_ctors") {
|
2009-08-19 05:49:37 +00:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
|
2009-03-09 08:18:48 +00:00
|
|
|
EmitAlignment(Align, 0);
|
|
|
|
EmitXXStructorList(GV->getInitializer());
|
|
|
|
return true;
|
2005-12-13 06:32:10 +00:00
|
|
|
}
|
|
|
|
|
2009-03-09 05:52:15 +00:00
|
|
|
if (GV->getName() == "llvm.global_dtors") {
|
2009-08-19 05:49:37 +00:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
|
2009-03-09 08:18:48 +00:00
|
|
|
EmitAlignment(Align, 0);
|
|
|
|
EmitXXStructorList(GV->getInitializer());
|
|
|
|
return true;
|
2005-12-13 06:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
/// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
|
2008-09-09 22:29:13 +00:00
|
|
|
/// global in the specified llvm.used list for which emitUsedDirectiveFor
|
|
|
|
/// is true, as being used with this directive.
|
2006-09-26 03:38:18 +00:00
|
|
|
void AsmPrinter::EmitLLVMUsedList(Constant *List) {
|
2009-08-22 21:43:10 +00:00
|
|
|
const char *Directive = MAI->getUsedDirective();
|
2006-09-26 03:38:18 +00:00
|
|
|
|
2009-06-14 23:30:43 +00:00
|
|
|
// Should be an array of 'i8*'.
|
2006-09-26 03:38:18 +00:00
|
|
|
ConstantArray *InitList = dyn_cast<ConstantArray>(List);
|
|
|
|
if (InitList == 0) return;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
2009-07-17 22:00:23 +00:00
|
|
|
const GlobalValue *GV =
|
|
|
|
dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
|
2009-07-31 20:52:39 +00:00
|
|
|
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) {
|
2008-09-03 20:34:58 +00:00
|
|
|
O << Directive;
|
|
|
|
EmitConstantValueOnly(InitList->getOperand(i));
|
|
|
|
O << '\n';
|
|
|
|
}
|
2006-09-26 03:38:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-13 06:32:10 +00: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 01:17:37 +00:00
|
|
|
|
|
|
|
if (CS->getOperand(1)->isNullValue())
|
|
|
|
return; // Found a null terminator, exit printing.
|
|
|
|
// Emit the function pointer.
|
2005-12-13 06:32:10 +00:00
|
|
|
EmitGlobalConstant(CS->getOperand(1));
|
|
|
|
}
|
|
|
|
}
|
2005-11-21 08:25:09 +00:00
|
|
|
|
2007-02-21 22:47:38 +00:00
|
|
|
|
2007-01-25 15:12:02 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// LEB 128 number encoding.
|
|
|
|
|
|
|
|
/// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
|
|
|
|
/// representing an unsigned leb128 value.
|
|
|
|
void AsmPrinter::PrintULEB128(unsigned Value) const {
|
2008-11-10 04:35:24 +00:00
|
|
|
char Buffer[20];
|
2007-01-25 15:12:02 +00:00
|
|
|
do {
|
2008-11-10 04:35:24 +00:00
|
|
|
unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
|
2007-01-25 15:12:02 +00:00
|
|
|
Value >>= 7;
|
|
|
|
if (Value) Byte |= 0x80;
|
2008-11-10 04:35:24 +00:00
|
|
|
O << "0x" << utohex_buffer(Byte, Buffer+20);
|
2007-01-25 15:12:02 +00:00
|
|
|
if (Value) O << ", ";
|
|
|
|
} while (Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
|
|
|
|
/// representing a signed leb128 value.
|
|
|
|
void AsmPrinter::PrintSLEB128(int Value) const {
|
|
|
|
int Sign = Value >> (8 * sizeof(Value) - 1);
|
|
|
|
bool IsMore;
|
2008-11-10 04:35:24 +00:00
|
|
|
char Buffer[20];
|
2008-08-16 12:57:46 +00:00
|
|
|
|
2007-01-25 15:12:02 +00:00
|
|
|
do {
|
2008-11-10 04:35:24 +00:00
|
|
|
unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
|
2007-01-25 15:12:02 +00:00
|
|
|
Value >>= 7;
|
|
|
|
IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
|
|
|
|
if (IsMore) Byte |= 0x80;
|
2008-11-10 04:35:24 +00:00
|
|
|
O << "0x" << utohex_buffer(Byte, Buffer+20);
|
2007-01-25 15:12:02 +00:00
|
|
|
if (IsMore) O << ", ";
|
|
|
|
} while (IsMore);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Emission and print routines
|
|
|
|
//
|
|
|
|
|
|
|
|
/// PrintHex - Print a value as a hexidecimal value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::PrintHex(int Value) const {
|
2008-11-10 04:30:26 +00:00
|
|
|
char Buffer[20];
|
|
|
|
O << "0x" << utohex_buffer(static_cast<unsigned>(Value), Buffer+20);
|
2007-01-25 15:12:02 +00: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-21 22:47:38 +00:00
|
|
|
void AsmPrinter::EOL() const {
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2007-02-21 22:47:38 +00:00
|
|
|
}
|
2008-07-01 21:16:27 +00:00
|
|
|
|
2007-01-25 15:12:02 +00:00
|
|
|
void AsmPrinter::EOL(const std::string &Comment) const {
|
2008-07-01 23:18:29 +00:00
|
|
|
if (VerboseAsm && !Comment.empty()) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2008-06-30 22:03:41 +00:00
|
|
|
<< ' '
|
2007-01-25 15:12:02 +00:00
|
|
|
<< Comment;
|
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2007-01-25 15:12:02 +00:00
|
|
|
}
|
|
|
|
|
2008-07-01 21:16:27 +00:00
|
|
|
void AsmPrinter::EOL(const char* Comment) const {
|
2008-07-01 23:18:29 +00:00
|
|
|
if (VerboseAsm && *Comment) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2008-07-01 21:16:27 +00:00
|
|
|
<< ' '
|
|
|
|
<< Comment;
|
|
|
|
}
|
|
|
|
O << '\n';
|
|
|
|
}
|
2009-08-29 12:17:53 +00: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-09 21:26:19 +00: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 12:17:53 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsmPrinter::EOL(const char *Comment, unsigned Encoding) const {
|
|
|
|
if (VerboseAsm && *Comment) {
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
|
|
|
<< ' '
|
|
|
|
<< Comment;
|
|
|
|
|
|
|
|
if (const char *EncStr = DecodeDWARFEncoding(Encoding))
|
|
|
|
O << " (" << EncStr << ')';
|
|
|
|
}
|
|
|
|
O << '\n';
|
|
|
|
}
|
2008-07-01 21:16:27 +00:00
|
|
|
|
2007-01-25 15:12:02 +00:00
|
|
|
/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
|
|
|
|
/// unsigned leb128 value.
|
|
|
|
void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->hasLEB128()) {
|
2007-01-25 15:12:02 +00:00
|
|
|
O << "\t.uleb128\t"
|
|
|
|
<< Value;
|
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 15:12:02 +00:00
|
|
|
PrintULEB128(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
|
|
|
|
/// signed leb128 value.
|
|
|
|
void AsmPrinter::EmitSLEB128Bytes(int Value) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->hasLEB128()) {
|
2007-01-25 15:12:02 +00:00
|
|
|
O << "\t.sleb128\t"
|
|
|
|
<< Value;
|
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 15:12:02 +00:00
|
|
|
PrintSLEB128(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt8 - Emit a byte directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt8(int Value) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 15:12:02 +00:00
|
|
|
PrintHex(Value & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt16 - Emit a short directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt16(int Value) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective();
|
2007-01-25 15:12:02 +00:00
|
|
|
PrintHex(Value & 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt32 - Emit a long directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt32(int Value) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective();
|
2007-01-25 15:12:02 +00:00
|
|
|
PrintHex(Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt64 - Emit a long long directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt64(uint64_t Value) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getData64bitsDirective()) {
|
|
|
|
O << MAI->getData64bitsDirective();
|
2007-01-25 15:12:02 +00:00
|
|
|
PrintHex(Value);
|
|
|
|
} else {
|
|
|
|
if (TM.getTargetData()->isBigEndian()) {
|
2008-06-30 22:03:41 +00:00
|
|
|
EmitInt32(unsigned(Value >> 32)); O << '\n';
|
2007-01-25 15:12:02 +00:00
|
|
|
EmitInt32(unsigned(Value));
|
|
|
|
} else {
|
2008-06-30 22:03:41 +00:00
|
|
|
EmitInt32(unsigned(Value)); O << '\n';
|
2007-01-25 15:12:02 +00:00
|
|
|
EmitInt32(unsigned(Value >> 32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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-14 20:18:05 +00:00
|
|
|
static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
|
2007-01-25 15:12:02 +00:00
|
|
|
if (C == '"') {
|
|
|
|
O << "\\\"";
|
|
|
|
} else if (C == '\\') {
|
|
|
|
O << "\\\\";
|
2009-01-22 23:38:45 +00:00
|
|
|
} else if (isprint((unsigned char)C)) {
|
2007-01-25 15:12:02 +00: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
|
|
|
|
void AsmPrinter::EmitString(const std::string &String) const {
|
2009-04-09 23:51:31 +00:00
|
|
|
EmitString(String.c_str(), String.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsmPrinter::EmitString(const char *String, unsigned Size) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
const char* AscizDirective = MAI->getAscizDirective();
|
2007-03-06 19:25:02 +00:00
|
|
|
if (AscizDirective)
|
|
|
|
O << AscizDirective;
|
|
|
|
else
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getAsciiDirective();
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\"';
|
2009-04-09 23:51:31 +00:00
|
|
|
for (unsigned i = 0; i < Size; ++i)
|
2009-04-08 00:28:38 +00:00
|
|
|
printStringChar(O, String[i]);
|
2007-03-06 19:25:02 +00:00
|
|
|
if (AscizDirective)
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\"';
|
2007-03-06 19:25:02 +00:00
|
|
|
else
|
|
|
|
O << "\\0\"";
|
2007-01-25 15:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-24 20:58:13 +00:00
|
|
|
/// EmitFile - Emit a .file directive.
|
|
|
|
void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
|
|
|
|
O << "\t.file\t" << Number << " \"";
|
2009-04-08 00:28:38 +00:00
|
|
|
for (unsigned i = 0, N = Name.size(); i < N; ++i)
|
|
|
|
printStringChar(O, Name[i]);
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\"';
|
2007-09-24 20:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-25 15:12:02 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-05-31 18:57:45 +00: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-02-29 19:36:59 +00:00
|
|
|
unsigned ForcedAlignBits,
|
|
|
|
bool UseFillExpr) const {
|
2007-04-23 23:33:31 +00:00
|
|
|
if (GV && GV->getAlignment())
|
2007-05-31 18:57:45 +00:00
|
|
|
NumBits = Log2_32(GV->getAlignment());
|
|
|
|
NumBits = std::max(NumBits, ForcedAlignBits);
|
|
|
|
|
2005-11-10 18:09:27 +00:00
|
|
|
if (NumBits == 0) return; // No need to emit alignment.
|
2009-08-19 06:12:02 +00:00
|
|
|
|
|
|
|
unsigned FillValue = 0;
|
2009-08-18 06:15:16 +00:00
|
|
|
if (getCurrentSection()->getKind().isText())
|
2009-08-22 21:43:10 +00:00
|
|
|
FillValue = MAI->getTextAlignFillValue();
|
2009-08-19 06:12:02 +00:00
|
|
|
|
|
|
|
OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0);
|
2004-08-17 19:14:29 +00:00
|
|
|
}
|
2009-08-05 21:00:52 +00:00
|
|
|
|
2005-11-21 07:51:36 +00:00
|
|
|
/// EmitZeros - Emit a block of zeros.
|
2004-08-17 21:38:40 +00:00
|
|
|
///
|
2009-01-30 04:25:10 +00:00
|
|
|
void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
|
2004-08-17 21:38:40 +00:00
|
|
|
if (NumZeros) {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getZeroDirective()) {
|
|
|
|
O << MAI->getZeroDirective() << NumZeros;
|
|
|
|
if (MAI->getZeroDirectiveSuffix())
|
|
|
|
O << MAI->getZeroDirectiveSuffix();
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2006-05-02 03:46:13 +00:00
|
|
|
} else {
|
2004-08-17 21:38:40 +00:00
|
|
|
for (; NumZeros; --NumZeros)
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData8bitsDirective(AddrSpace) << "0\n";
|
2004-08-17 21:38:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-16 23:15:22 +00:00
|
|
|
// Print out the specified constant, without a storage class. Only the
|
|
|
|
// constants valid in constant expressions can occur here.
|
2005-11-21 07:51:36 +00:00
|
|
|
void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
|
2004-10-16 18:19:26 +00:00
|
|
|
if (CV->isNullValue() || isa<UndefValue>(CV))
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '0';
|
2007-01-11 12:24:14 +00:00
|
|
|
else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
2008-06-03 06:18:19 +00:00
|
|
|
O << CI->getZExtValue();
|
2006-10-20 07:07:24 +00:00
|
|
|
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
|
2005-04-02 12:21:51 +00:00
|
|
|
// This is a constant address for a global variable or function. Use the
|
2009-09-15 23:11:32 +00:00
|
|
|
// name of the variable or function as the address value.
|
|
|
|
O << Mang->getMangledName(GV);
|
2005-04-02 12:21:51 +00:00
|
|
|
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
|
2006-05-03 01:29:57 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2007-02-04 23:27:42 +00:00
|
|
|
unsigned Opcode = CE->getOpcode();
|
|
|
|
switch (Opcode) {
|
2009-08-01 22:25:12 +00:00
|
|
|
case Instruction::Trunc:
|
|
|
|
case Instruction::ZExt:
|
|
|
|
case Instruction::SExt:
|
|
|
|
case Instruction::FPTrunc:
|
|
|
|
case Instruction::FPExt:
|
|
|
|
case Instruction::UIToFP:
|
|
|
|
case Instruction::SIToFP:
|
|
|
|
case Instruction::FPToUI:
|
|
|
|
case Instruction::FPToSI:
|
|
|
|
llvm_unreachable("FIXME: Don't support this constant cast expr");
|
2004-08-16 23:15:22 +00:00
|
|
|
case Instruction::GetElementPtr: {
|
|
|
|
// generate a symbolic expression for the byte address
|
|
|
|
const Constant *ptrVal = CE->getOperand(0);
|
2007-02-10 20:31:59 +00:00
|
|
|
SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
|
|
|
|
if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
|
|
|
|
idxVec.size())) {
|
2009-02-05 06:55:21 +00:00
|
|
|
// Truncate/sext the offset to the pointer size.
|
|
|
|
if (TD->getPointerSizeInBits() != 64) {
|
|
|
|
int SExtAmount = 64-TD->getPointerSizeInBits();
|
|
|
|
Offset = (Offset << SExtAmount) >> SExtAmount;
|
|
|
|
}
|
|
|
|
|
2005-02-14 21:40:26 +00:00
|
|
|
if (Offset)
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '(';
|
2005-11-21 07:51:36 +00:00
|
|
|
EmitConstantValueOnly(ptrVal);
|
2005-02-14 21:40:26 +00:00
|
|
|
if (Offset > 0)
|
|
|
|
O << ") + " << Offset;
|
|
|
|
else if (Offset < 0)
|
|
|
|
O << ") - " << -Offset;
|
2004-08-16 23:15:22 +00:00
|
|
|
} else {
|
2005-11-21 07:51:36 +00:00
|
|
|
EmitConstantValueOnly(ptrVal);
|
2004-08-16 23:15:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-12-12 05:14:13 +00:00
|
|
|
case Instruction::BitCast:
|
|
|
|
return EmitConstantValueOnly(CE->getOperand(0));
|
|
|
|
|
2006-12-12 05:18:19 +00:00
|
|
|
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.
|
|
|
|
Constant *Op = CE->getOperand(0);
|
2009-08-13 21:58:54 +00:00
|
|
|
Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
|
|
|
|
false/*ZExt*/);
|
2006-12-12 05:18:19 +00:00
|
|
|
return EmitConstantValueOnly(Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case Instruction::PtrToInt: {
|
2006-07-29 01:57:19 +00:00
|
|
|
// Support only foldable casts to/from pointers that can be eliminated by
|
|
|
|
// changing the pointer to the appropriately sized integer type.
|
2004-08-16 23:15:22 +00:00
|
|
|
Constant *Op = CE->getOperand(0);
|
2006-12-12 05:18:19 +00:00
|
|
|
const Type *Ty = CE->getType();
|
2004-08-16 23:15:22 +00:00
|
|
|
|
2006-12-12 05:18:19 +00:00
|
|
|
// 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.
|
2009-08-01 22:25:12 +00:00
|
|
|
if (TD->getTypeAllocSize(Ty) == TD->getTypeAllocSize(Op->getType()))
|
2006-07-29 01:57:19 +00:00
|
|
|
return EmitConstantValueOnly(Op);
|
2008-08-08 06:34:07 +00:00
|
|
|
|
|
|
|
O << "((";
|
2005-11-21 07:51:36 +00:00
|
|
|
EmitConstantValueOnly(Op);
|
2009-08-01 22:25:12 +00:00
|
|
|
APInt ptrMask =
|
|
|
|
APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Op->getType()));
|
2008-08-17 07:19:36 +00:00
|
|
|
|
|
|
|
SmallString<40> S;
|
|
|
|
ptrMask.toStringUnsigned(S);
|
2009-08-19 20:07:03 +00:00
|
|
|
O << ") & " << S.str() << ')';
|
2004-08-16 23:15:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Instruction::Add:
|
2007-02-04 23:27:42 +00:00
|
|
|
case Instruction::Sub:
|
2007-12-18 20:53:41 +00:00
|
|
|
case Instruction::And:
|
|
|
|
case Instruction::Or:
|
|
|
|
case Instruction::Xor:
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '(';
|
2005-11-21 07:51:36 +00:00
|
|
|
EmitConstantValueOnly(CE->getOperand(0));
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ')';
|
2007-12-18 20:53:41 +00:00
|
|
|
switch (Opcode) {
|
|
|
|
case Instruction::Add:
|
|
|
|
O << " + ";
|
|
|
|
break;
|
|
|
|
case Instruction::Sub:
|
|
|
|
O << " - ";
|
|
|
|
break;
|
|
|
|
case Instruction::And:
|
|
|
|
O << " & ";
|
|
|
|
break;
|
|
|
|
case Instruction::Or:
|
|
|
|
O << " | ";
|
|
|
|
break;
|
|
|
|
case Instruction::Xor:
|
|
|
|
O << " ^ ";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '(';
|
2005-11-21 07:51:36 +00:00
|
|
|
EmitConstantValueOnly(CE->getOperand(1));
|
2008-06-30 22:03:41 +00:00
|
|
|
O << ')';
|
2004-08-16 23:15:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unsupported operator!");
|
2004-08-16 23:15:22 +00:00
|
|
|
}
|
2009-10-30 01:45:18 +00:00
|
|
|
} else if (const BlockAddress *BA = dyn_cast<BlockAddress>(CV)) {
|
|
|
|
GetBlockAddressSymbol(BA)->print(O, MAI);
|
2004-08-16 23:15:22 +00:00
|
|
|
} else {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unknown constant value!");
|
2004-08-16 23:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-17 06:36:49 +00:00
|
|
|
|
2005-11-10 18:06:33 +00:00
|
|
|
/// printAsCString - Print the specified array as a C compatible string, only if
|
2004-08-17 06:36:49 +00:00
|
|
|
/// the predicate isString is true.
|
|
|
|
///
|
2009-07-14 20:18:05 +00:00
|
|
|
static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
|
2005-11-10 18:06:33 +00:00
|
|
|
unsigned LastElt) {
|
2004-08-17 06:36:49 +00:00
|
|
|
assert(CVA->isString() && "Array is not string compatible!");
|
|
|
|
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\"';
|
2005-11-10 18:06:33 +00:00
|
|
|
for (unsigned i = 0; i != LastElt; ++i) {
|
2005-04-21 22:36:52 +00:00
|
|
|
unsigned char C =
|
2006-10-20 07:07:24 +00:00
|
|
|
(unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
|
2007-01-25 15:12:02 +00:00
|
|
|
printStringChar(O, C);
|
2004-08-17 06:36:49 +00:00
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\"';
|
2004-08-17 06:36:49 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 01:16:28 +00:00
|
|
|
/// EmitString - Emit a zero-byte-terminated string constant.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitString(const ConstantArray *CVA) const {
|
|
|
|
unsigned NumElts = CVA->getNumOperands();
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getAscizDirective() && NumElts &&
|
2006-10-20 07:07:24 +00:00
|
|
|
cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getAscizDirective();
|
2006-05-02 01:16:28 +00:00
|
|
|
printAsCString(O, CVA, NumElts-1);
|
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getAsciiDirective();
|
2006-05-02 01:16:28 +00:00
|
|
|
printAsCString(O, CVA, NumElts);
|
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2006-05-02 01:16:28 +00:00
|
|
|
}
|
|
|
|
|
2009-04-28 16:34:20 +00:00
|
|
|
void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 21:14:27 +00:00
|
|
|
if (CVA->isString()) {
|
|
|
|
EmitString(CVA);
|
|
|
|
} else { // Not a string. Print the values in successive locations
|
|
|
|
for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
|
2009-04-28 16:34:20 +00:00
|
|
|
EmitGlobalConstant(CVA->getOperand(i), AddrSpace);
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) {
|
|
|
|
const VectorType *PTy = CP->getType();
|
|
|
|
|
|
|
|
for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
|
|
|
|
EmitGlobalConstant(CP->getOperand(I));
|
|
|
|
}
|
|
|
|
|
2009-01-30 04:25:10 +00:00
|
|
|
void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 21:14:27 +00:00
|
|
|
// Print the fields in successive locations. Pad to align if needed!
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-05-09 07:06:46 +00:00
|
|
|
unsigned Size = TD->getTypeAllocSize(CVS->getType());
|
2008-12-22 21:14:27 +00:00
|
|
|
const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
|
|
|
|
uint64_t sizeSoFar = 0;
|
|
|
|
for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
|
|
|
|
const Constant* field = CVS->getOperand(i);
|
|
|
|
|
|
|
|
// Check if padding is needed and insert one or more 0s.
|
2009-05-09 07:06:46 +00:00
|
|
|
uint64_t fieldSize = TD->getTypeAllocSize(field->getType());
|
2008-12-22 21:14:27 +00:00
|
|
|
uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
|
|
|
|
- cvsLayout->getElementOffset(i)) - fieldSize;
|
|
|
|
sizeSoFar += fieldSize + padSize;
|
|
|
|
|
|
|
|
// Now print the actual field value.
|
2009-01-30 04:25:10 +00:00
|
|
|
EmitGlobalConstant(field, AddrSpace);
|
2008-12-22 21:14:27 +00: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.
|
2009-01-30 04:25:10 +00:00
|
|
|
EmitZeros(padSize, AddrSpace);
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
|
|
|
assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
|
|
|
|
"Layout of constant struct may be incorrect!");
|
|
|
|
}
|
|
|
|
|
2009-01-30 04:25:10 +00:00
|
|
|
void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 21:14:27 +00:00
|
|
|
// FP Constants are printed as integer constants to avoid losing
|
|
|
|
// precision...
|
2009-08-13 21:58:54 +00:00
|
|
|
LLVMContext &Context = CFP->getContext();
|
2008-12-22 21:14:27 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-10-05 05:54:46 +00:00
|
|
|
if (CFP->getType()->isDoubleTy()) {
|
2008-12-22 21:14:27 +00:00
|
|
|
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
|
|
|
|
uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getData64bitsDirective(AddrSpace)) {
|
|
|
|
O << MAI->getData64bitsDirective(AddrSpace) << i;
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " double " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
|
|
|
} else if (TD->isBigEndian()) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant word of double " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant word of double " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant word of double " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant word of double " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
|
|
|
return;
|
2009-10-05 05:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CFP->getType()->isFloatTy()) {
|
2008-12-22 21:14:27 +00:00
|
|
|
float Val = CFP->getValueAPF().convertToFloat(); // for comment only
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace)
|
2009-03-24 00:17:40 +00:00
|
|
|
<< CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " float " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
return;
|
2009-10-05 05:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CFP->getType()->isX86_FP80Ty()) {
|
2008-12-22 21:14:27 +00:00
|
|
|
// 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();
|
|
|
|
// 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);
|
|
|
|
if (TD->isBigEndian()) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant halfword of x86_fp80 ~"
|
2009-03-24 00:17:40 +00:00
|
|
|
<< DoubleVal.convertToDouble();
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " next halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " next halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " next halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant halfword of x86_fp80 ~"
|
2009-03-24 00:17:40 +00:00
|
|
|
<< DoubleVal.convertToDouble();
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant halfword";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
2009-08-13 21:58:54 +00:00
|
|
|
EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) -
|
|
|
|
TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace);
|
2008-12-22 21:14:27 +00:00
|
|
|
return;
|
2009-10-05 05:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CFP->getType()->isPPC_FP128Ty()) {
|
2008-12-22 21:14:27 +00:00
|
|
|
// 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();
|
|
|
|
if (TD->isBigEndian()) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant word of ppc_fp128";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next word";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next word";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant word";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant word of ppc_fp128";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next word";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " next word";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant word";
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
|
|
|
return;
|
2009-07-14 16:55:14 +00:00
|
|
|
} else llvm_unreachable("Floating point constant type not handled");
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 04:25:10 +00:00
|
|
|
void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 21:14:27 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
unsigned BitWidth = CI->getBitWidth();
|
|
|
|
assert(isPowerOf2_32(BitWidth) &&
|
|
|
|
"Non-power-of-2-sized integers not handled!");
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
uint64_t Val;
|
|
|
|
if (TD->isBigEndian())
|
|
|
|
Val = RawData[e - i - 1];
|
|
|
|
else
|
|
|
|
Val = RawData[i];
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->getData64bitsDirective(AddrSpace))
|
|
|
|
O << MAI->getData64bitsDirective(AddrSpace) << Val << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
else if (TD->isBigEndian()) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant half of i64 " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant half of i64 " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " least significant half of i64 " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
|
2009-08-12 18:32:22 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 01:36:44 +00:00
|
|
|
<< " most significant half of i64 " << Val;
|
2009-08-12 18:32:22 +00:00
|
|
|
}
|
2009-03-24 00:17:40 +00:00
|
|
|
O << '\n';
|
2008-12-22 21:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-21 07:51:36 +00:00
|
|
|
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
|
2009-01-30 04:25:10 +00:00
|
|
|
void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
|
2006-05-03 01:29:57 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2008-12-22 21:14:27 +00:00
|
|
|
const Type *type = CV->getType();
|
2009-05-09 07:06:46 +00:00
|
|
|
unsigned Size = TD->getTypeAllocSize(type);
|
2004-08-17 06:36:49 +00:00
|
|
|
|
2004-10-16 18:19:26 +00:00
|
|
|
if (CV->isNullValue() || isa<UndefValue>(CV)) {
|
2009-01-30 04:25:10 +00:00
|
|
|
EmitZeros(Size, AddrSpace);
|
2004-08-17 06:36:49 +00:00
|
|
|
return;
|
|
|
|
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
|
2009-04-28 16:34:20 +00:00
|
|
|
EmitGlobalConstantArray(CVA , AddrSpace);
|
2004-08-17 06:36:49 +00:00
|
|
|
return;
|
|
|
|
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
|
2009-01-30 04:25:10 +00:00
|
|
|
EmitGlobalConstantStruct(CVS, AddrSpace);
|
2004-08-17 06:36:49 +00:00
|
|
|
return;
|
|
|
|
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
|
2009-01-30 04:25:10 +00:00
|
|
|
EmitGlobalConstantFP(CFP, AddrSpace);
|
2008-12-22 21:14:27 +00:00
|
|
|
return;
|
|
|
|
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
|
|
|
// Small integers are handled below; large integers are handled here.
|
|
|
|
if (Size > 4) {
|
2009-01-30 04:25:10 +00:00
|
|
|
EmitGlobalConstantLargeInt(CI, AddrSpace);
|
2004-08-17 06:36:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-02-15 02:26:10 +00:00
|
|
|
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
|
2008-12-22 21:14:27 +00:00
|
|
|
EmitGlobalConstantVector(CP);
|
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
}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24616 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-06 06:18:55 +00:00
|
|
|
return;
|
2004-08-17 06:36:49 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 04:25:10 +00:00
|
|
|
printDataDirective(type, AddrSpace);
|
2005-11-21 07:51:36 +00:00
|
|
|
EmitConstantValueOnly(CV);
|
2009-03-24 00:17:40 +00:00
|
|
|
if (VerboseAsm) {
|
|
|
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
|
|
|
SmallString<40> S;
|
|
|
|
CI->getValue().toStringUnsigned(S, 16);
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " 0x" << S.str();
|
2009-03-24 00:17:40 +00:00
|
|
|
}
|
2008-06-03 15:39:51 +00:00
|
|
|
}
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n';
|
2004-08-17 06:36:49 +00:00
|
|
|
}
|
2006-01-27 02:10:10 +00:00
|
|
|
|
2008-08-17 07:19:36 +00:00
|
|
|
void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
2006-09-12 21:00:35 +00:00
|
|
|
// Target doesn't support this yet!
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
|
2006-09-12 21:00:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-26 23:59:50 +00: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 05:37:13 +00:00
|
|
|
void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
|
2006-09-27 00:06:07 +00:00
|
|
|
if (!strcmp(Code, "private")) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getPrivateGlobalPrefix();
|
2006-09-27 00:06:07 +00:00
|
|
|
} else if (!strcmp(Code, "comment")) {
|
2009-03-24 00:17:40 +00:00
|
|
|
if (VerboseAsm)
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString();
|
2006-09-26 23:59:50 +00:00
|
|
|
} else if (!strcmp(Code, "uid")) {
|
2007-02-05 21:23:52 +00: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-24 22:28:12 +00:00
|
|
|
// If this is a new LastFn instruction, bump the counter.
|
|
|
|
if (LastMI != MI || LastFn != ThisF) {
|
2007-02-05 21:23:52 +00:00
|
|
|
++Counter;
|
|
|
|
LastMI = MI;
|
2009-06-24 22:28:12 +00:00
|
|
|
LastFn = ThisF;
|
2007-02-05 21:23:52 +00:00
|
|
|
}
|
2006-09-26 23:59:50 +00:00
|
|
|
O << Counter;
|
|
|
|
} else {
|
2009-07-11 13:10:19 +00:00
|
|
|
std::string msg;
|
|
|
|
raw_string_ostream Msg(msg);
|
|
|
|
Msg << "Unknown special formatter '" << Code
|
2006-12-07 01:30:32 +00:00
|
|
|
<< "' for machine instr: " << *MI;
|
2009-07-11 13:10:19 +00:00
|
|
|
llvm_report_error(Msg.str());
|
2006-09-26 23:59:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 13:55:51 +00:00
|
|
|
/// processDebugLoc - Processes the debug information of each machine
|
|
|
|
/// instruction's DebugLoc.
|
2009-10-06 02:19:11 +00:00
|
|
|
void AsmPrinter::processDebugLoc(const MachineInstr *MI,
|
|
|
|
bool BeforePrintingInsn) {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (!MAI || !DW)
|
2009-08-05 04:09:18 +00:00
|
|
|
return;
|
2009-09-30 23:12:50 +00:00
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
2009-08-22 21:43:10 +00:00
|
|
|
if (MAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) {
|
2009-05-07 13:55:51 +00:00
|
|
|
if (!DL.isUnknown()) {
|
|
|
|
DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
|
2009-10-06 02:19:11 +00:00
|
|
|
if (BeforePrintingInsn) {
|
2009-10-13 23:28:53 +00:00
|
|
|
if (CurDLT.Scope != 0 && PrevDLT != CurDLT) {
|
2009-10-06 18:37:31 +00:00
|
|
|
unsigned L = DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
|
2009-10-13 23:28:53 +00:00
|
|
|
CurDLT.Scope);
|
2009-10-06 18:37:31 +00:00
|
|
|
printLabel(L);
|
2009-10-31 20:59:09 +00:00
|
|
|
O << '\n';
|
2009-10-06 18:37:31 +00:00
|
|
|
#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
|
|
|
|
DW->SetDbgScopeBeginLabels(MI, L);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
|
|
|
|
DW->SetDbgScopeEndLabels(MI, 0);
|
|
|
|
#endif
|
2009-10-06 02:19:11 +00:00
|
|
|
}
|
2009-10-06 18:37:31 +00:00
|
|
|
}
|
2009-05-07 13:55:51 +00:00
|
|
|
PrevDLT = CurDLT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-26 23:59:50 +00:00
|
|
|
|
2006-01-27 02:10:10 +00: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-30 23:00:08 +00:00
|
|
|
unsigned NumOperands = MI->getNumOperands();
|
|
|
|
|
|
|
|
// Count the number of register definitions.
|
|
|
|
unsigned NumDefs = 0;
|
2008-10-03 15:45:36 +00:00
|
|
|
for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
|
2006-09-05 20:02:51 +00:00
|
|
|
++NumDefs)
|
2006-01-30 23:00:08 +00:00
|
|
|
assert(NumDefs != NumOperands-1 && "No asm string?");
|
|
|
|
|
2008-10-03 15:45:36 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
|
|
|
|
// Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
|
2006-01-30 23:00:08 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
|
2008-01-29 02:21:21 +00: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 00:17:20 +00:00
|
|
|
if (AsmStr[0] == 0) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
|
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
|
2006-07-28 00:17:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
|
2006-07-28 00:17:20 +00:00
|
|
|
|
2007-01-16 03:42:04 +00:00
|
|
|
// The variant of the current asmprinter.
|
2009-08-22 21:43:10 +00:00
|
|
|
int AsmPrinterVariant = MAI->getAssemblerDialect();
|
2007-01-16 03:42:04 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00: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 01:28:23 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00: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-05 21:47:05 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
++LiteralEnd;
|
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
|
|
|
|
O.write(LastEmitted, LiteralEnd-LastEmitted);
|
|
|
|
LastEmitted = LiteralEnd;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-05 21:47:05 +00:00
|
|
|
case '\n':
|
|
|
|
++LastEmitted; // Consume newline character.
|
2008-06-30 22:03:41 +00:00
|
|
|
O << '\n'; // Indent code with newline.
|
2006-05-05 21:47:05 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
case '$': {
|
|
|
|
++LastEmitted; // Consume '$' character.
|
2006-10-03 23:27:09 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
|
|
|
|
O << '$';
|
|
|
|
++LastEmitted; // Consume second '$' character.
|
|
|
|
break;
|
2006-10-03 23:27:09 +00:00
|
|
|
case '(': // $( -> same as GCC's { character.
|
|
|
|
++LastEmitted; // Consume '(' character.
|
|
|
|
if (CurVariant != -1) {
|
2009-07-11 13:10:19 +00:00
|
|
|
llvm_report_error("Nested variants found in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2006-10-03 23:27:09 +00:00
|
|
|
}
|
|
|
|
CurVariant = 0; // We're in the first variant now.
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
++LastEmitted; // consume '|' character.
|
2008-10-10 21:04:42 +00:00
|
|
|
if (CurVariant == -1)
|
|
|
|
O << '|'; // this is gcc's behavior for | outside a variant
|
|
|
|
else
|
|
|
|
++CurVariant; // We're in the next variant.
|
2006-10-03 23:27:09 +00:00
|
|
|
break;
|
|
|
|
case ')': // $) -> same as GCC's } char.
|
|
|
|
++LastEmitted; // consume ')' character.
|
2008-10-10 21:04:42 +00:00
|
|
|
if (CurVariant == -1)
|
|
|
|
O << '}'; // this is gcc's behavior for } outside a variant
|
|
|
|
else
|
|
|
|
CurVariant = -1;
|
2006-10-03 23:27:09 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
}
|
2006-10-03 23:27:09 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
|
|
|
|
bool HasCurlyBraces = false;
|
|
|
|
if (*LastEmitted == '{') { // ${variable}
|
|
|
|
++LastEmitted; // Consume '{' character.
|
|
|
|
HasCurlyBraces = true;
|
|
|
|
}
|
|
|
|
|
2009-03-10 05:37:13 +00: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 13:10:19 +00:00
|
|
|
llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2009-03-10 05:37:13 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
const char *IDStart = LastEmitted;
|
|
|
|
char *IDEnd;
|
2007-01-23 00:36:17 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
|
|
|
|
if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
|
2009-07-11 13:10:19 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
}
|
|
|
|
LastEmitted = IDEnd;
|
|
|
|
|
2006-02-06 22:17:23 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
if (HasCurlyBraces) {
|
2006-02-06 22:17:23 +00: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 13:10:19 +00:00
|
|
|
llvm_report_error("Bad ${:} expression in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2006-02-06 22:17:23 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
if (*LastEmitted != '}') {
|
2009-07-11 13:10:19 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
}
|
|
|
|
++LastEmitted; // Consume '}' character.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned)Val >= NumOperands-1) {
|
2009-07-11 13:10:19 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 19:21:04 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
// operand!
|
2006-02-23 19:21:04 +00:00
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
|
|
|
|
unsigned OpNo = 1;
|
2006-06-08 18:00:47 +00:00
|
|
|
|
|
|
|
bool Error = false;
|
|
|
|
|
2006-02-23 19:21:04 +00:00
|
|
|
// Scan to find the machine operand number for the operand.
|
2006-02-24 19:50:58 +00:00
|
|
|
for (; Val; --Val) {
|
2006-06-08 18:00:47 +00:00
|
|
|
if (OpNo >= MI->getNumOperands()) break;
|
2007-12-30 20:50:28 +00:00
|
|
|
unsigned OpFlags = MI->getOperand(OpNo).getImm();
|
2009-03-20 18:03:34 +00:00
|
|
|
OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
|
2006-02-24 19:50:58 +00:00
|
|
|
}
|
2006-06-08 18:00:47 +00:00
|
|
|
|
|
|
|
if (OpNo >= MI->getNumOperands()) {
|
|
|
|
Error = true;
|
2006-02-24 20:21:58 +00:00
|
|
|
} else {
|
2007-12-30 20:50:28 +00:00
|
|
|
unsigned OpFlags = MI->getOperand(OpNo).getImm();
|
2006-06-08 18:00:47 +00:00
|
|
|
++OpNo; // Skip over the ID number.
|
|
|
|
|
2007-11-05 21:20:28 +00:00
|
|
|
if (Modifier[0]=='l') // labels are target independent
|
2009-09-13 17:14:04 +00:00
|
|
|
GetMBBSymbol(MI->getOperand(OpNo).getMBB()
|
|
|
|
->getNumber())->print(O, MAI);
|
2007-11-05 21:20:28 +00:00
|
|
|
else {
|
|
|
|
AsmPrinter *AP = const_cast<AsmPrinter*>(this);
|
2008-09-24 01:07:17 +00:00
|
|
|
if ((OpFlags & 7) == 4) {
|
2007-11-05 21:20:28 +00:00
|
|
|
Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
|
|
|
|
Modifier[0] ? Modifier : 0);
|
|
|
|
} else {
|
|
|
|
Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
|
|
|
|
Modifier[0] ? Modifier : 0);
|
|
|
|
}
|
2006-06-08 18:00:47 +00:00
|
|
|
}
|
2006-02-24 20:21:58 +00:00
|
|
|
}
|
|
|
|
if (Error) {
|
2009-07-11 13:10:19 +00:00
|
|
|
std::string msg;
|
|
|
|
raw_string_ostream Msg(msg);
|
|
|
|
Msg << "Invalid operand found in inline asm: '"
|
2006-12-07 01:30:32 +00:00
|
|
|
<< AsmStr << "'\n";
|
2009-07-11 13:10:19 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
}
|
2006-02-23 19:21:04 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-09 23:14:36 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 00:03:38 +00:00
|
|
|
/// printImplicitDef - This method prints the specified machine instruction
|
|
|
|
/// that is an implicit def.
|
|
|
|
void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
|
2009-09-09 23:14:36 +00:00
|
|
|
if (!VerboseAsm) return;
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " implicit-def: "
|
2009-09-13 19:48:37 +00:00
|
|
|
<< TRI->getName(MI->getOperand(0).getReg());
|
2008-03-15 00:03:38 +00:00
|
|
|
}
|
|
|
|
|
2007-01-26 14:34:52 +00: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 00:16:26 +00:00
|
|
|
printLabel(MI->getOperand(0).getImm());
|
2007-01-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2008-02-01 09:10:45 +00:00
|
|
|
void AsmPrinter::printLabel(unsigned Id) const {
|
2009-09-09 23:14:36 +00:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "label" << Id << ':';
|
2008-02-01 09:10:45 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
|
|
|
|
/// instruction, using the specified assembler variant. Targets should
|
|
|
|
/// overried this to format as appropriate.
|
|
|
|
bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2006-02-06 22:17:23 +00: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. :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25886 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-01 22:41:11 +00:00
|
|
|
// Target doesn't support this yet!
|
|
|
|
return true;
|
2006-01-27 02:10:10 +00:00
|
|
|
}
|
2006-02-24 20:21:58 +00:00
|
|
|
|
|
|
|
bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode) {
|
|
|
|
// Target doesn't support this yet!
|
|
|
|
return true;
|
|
|
|
}
|
2006-04-22 18:53:45 +00:00
|
|
|
|
2009-10-30 01:27:03 +00:00
|
|
|
MCSymbol *AsmPrinter::GetBlockAddressSymbol(const BlockAddress *BA) const {
|
|
|
|
return GetBlockAddressSymbol(BA->getFunction(), BA->getBasicBlock());
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSymbol *AsmPrinter::GetBlockAddressSymbol(const Function *F,
|
|
|
|
const BasicBlock *BB) const {
|
|
|
|
assert(BB->hasName() &&
|
|
|
|
"Address of anonymous basic block not supported yet!");
|
|
|
|
|
2009-10-30 01:38:20 +00:00
|
|
|
// FIXME: This isn't guaranteed to produce a unique name even if the
|
|
|
|
// block and function have a name.
|
2009-10-30 01:27:03 +00:00
|
|
|
std::string Mangled =
|
|
|
|
Mang->getMangledName(F, Mang->makeNameProper(BB->getName()).c_str(),
|
|
|
|
/*ForcePrivate=*/true);
|
|
|
|
|
|
|
|
return OutContext.GetOrCreateSymbol(StringRef(Mangled));
|
|
|
|
}
|
|
|
|
|
2009-09-12 23:02:08 +00:00
|
|
|
MCSymbol *AsmPrinter::GetMBBSymbol(unsigned MBBID) const {
|
|
|
|
SmallString<60> Name;
|
|
|
|
raw_svector_ostream(Name) << MAI->getPrivateGlobalPrefix() << "BB"
|
|
|
|
<< getFunctionNumber() << '_' << MBBID;
|
|
|
|
|
|
|
|
return OutContext.GetOrCreateSymbol(Name.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-13 18:25:37 +00: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 03:15:54 +00:00
|
|
|
void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
|
2009-10-30 01:34:35 +00:00
|
|
|
// Emit an alignment directive for this block, if needed.
|
2009-09-13 18:25:37 +00:00
|
|
|
if (unsigned Align = MBB->getAlignment())
|
|
|
|
EmitAlignment(Log2_32(Align));
|
2008-02-28 00:43:03 +00:00
|
|
|
|
2009-10-30 01:34:35 +00: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 01:27:03 +00:00
|
|
|
if (MBB->hasAddressTaken()) {
|
|
|
|
GetBlockAddressSymbol(MBB->getBasicBlock()->getParent(),
|
|
|
|
MBB->getBasicBlock())->print(O, MAI);
|
|
|
|
O << ':';
|
|
|
|
if (VerboseAsm) {
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Address Taken";
|
|
|
|
}
|
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
|
2009-10-30 01:34:35 +00:00
|
|
|
// Print the main label for the block.
|
2009-10-06 17:38:38 +00:00
|
|
|
if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
|
|
|
|
if (VerboseAsm)
|
|
|
|
O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
|
|
|
|
} else {
|
|
|
|
GetMBBSymbol(MBB->getNumber())->print(O, MAI);
|
|
|
|
O << ':';
|
|
|
|
if (!VerboseAsm)
|
|
|
|
O << '\n';
|
|
|
|
}
|
2009-09-13 18:25:37 +00:00
|
|
|
|
2009-10-30 01:34:35 +00:00
|
|
|
// Print some comments to accompany the label.
|
2009-09-13 18:25:37 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-12 18:47:05 +00:00
|
|
|
if (const BasicBlock *BB = MBB->getBasicBlock())
|
|
|
|
if (BB->hasName()) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << ' ';
|
2009-08-12 20:56:56 +00:00
|
|
|
WriteAsOperand(O, BB, /*PrintType=*/false);
|
2009-08-12 18:47:05 +00:00
|
|
|
}
|
2009-08-10 16:38:07 +00:00
|
|
|
|
2009-09-13 18:25:37 +00:00
|
|
|
EmitComments(*MBB);
|
2009-10-06 17:38:38 +00:00
|
|
|
O << '\n';
|
2009-08-10 16:38:07 +00:00
|
|
|
}
|
2006-04-22 18:53:45 +00:00
|
|
|
}
|
2006-08-12 21:29:52 +00:00
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
/// 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-22 21:43:10 +00:00
|
|
|
if (!MAI->getSetDirective())
|
2006-08-12 21:29:52 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
|
2007-10-14 05:57:21 +00:00
|
|
|
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
|
2009-09-13 17:14:04 +00:00
|
|
|
GetMBBSymbol(MBB->getNumber())->print(O, MAI);
|
2009-08-22 21:43:10 +00:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 05:57:21 +00:00
|
|
|
<< '_' << uid << '\n';
|
2006-08-12 21:29:52 +00:00
|
|
|
}
|
2006-09-12 21:00:35 +00:00
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
|
|
|
|
const MachineBasicBlock *MBB) const {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (!MAI->getSetDirective())
|
2006-11-01 09:23:08 +00:00
|
|
|
return;
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
|
2007-10-14 05:57:21 +00:00
|
|
|
<< getFunctionNumber() << '_' << uid << '_' << uid2
|
|
|
|
<< "_set_" << MBB->getNumber() << ',';
|
2009-09-13 17:14:04 +00:00
|
|
|
GetMBBSymbol(MBB->getNumber())->print(O, MAI);
|
2009-08-22 21:43:10 +00:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 05:57:21 +00:00
|
|
|
<< '_' << uid << '_' << uid2 << '\n';
|
2006-11-01 09:23:08 +00:00
|
|
|
}
|
|
|
|
|
2006-09-12 21:00:35 +00:00
|
|
|
/// printDataDirective - This method prints the asm directive for the
|
|
|
|
/// specified type.
|
2009-01-30 04:25:10 +00:00
|
|
|
void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
|
2006-09-12 21:00:35 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
switch (type->getTypeID()) {
|
2009-07-15 04:42:49 +00:00
|
|
|
case Type::FloatTyID: case Type::DoubleTyID:
|
|
|
|
case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
|
|
|
|
assert(0 && "Should have already output floating point constant.");
|
|
|
|
default:
|
|
|
|
assert(0 && "Can't handle printing this type of thing");
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
case Type::IntegerTyID: {
|
|
|
|
unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
|
|
|
|
if (BitWidth <= 8)
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData8bitsDirective(AddrSpace);
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
else if (BitWidth <= 16)
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace);
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
else if (BitWidth <= 32)
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace);
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
else if (BitWidth <= 64) {
|
2009-08-22 21:43:10 +00:00
|
|
|
assert(MAI->getData64bitsDirective(AddrSpace) &&
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
"Target cannot handle 64-bit constant exprs!");
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData64bitsDirective(AddrSpace);
|
2008-09-08 16:40:13 +00:00
|
|
|
} else {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Target cannot handle given data directive width!");
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
}
|
2006-09-12 21:00:35 +00:00
|
|
|
break;
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
}
|
2006-09-12 21:00:35 +00:00
|
|
|
case Type::PointerTyID:
|
|
|
|
if (TD->getPointerSize() == 8) {
|
2009-08-22 21:43:10 +00:00
|
|
|
assert(MAI->getData64bitsDirective(AddrSpace) &&
|
2006-09-12 21:00:35 +00:00
|
|
|
"Target cannot handle 64-bit pointer exprs!");
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData64bitsDirective(AddrSpace);
|
2009-01-22 10:14:21 +00:00
|
|
|
} else if (TD->getPointerSize() == 2) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace);
|
2009-01-22 10:14:21 +00:00
|
|
|
} else if (TD->getPointerSize() == 1) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData8bitsDirective(AddrSpace);
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
} else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace);
|
2006-09-12 21:00:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 01:54:53 +00:00
|
|
|
|
2008-08-08 18:25:07 +00:00
|
|
|
void AsmPrinter::printVisibility(const std::string& Name,
|
|
|
|
unsigned Visibility) const {
|
|
|
|
if (Visibility == GlobalValue::HiddenVisibility) {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (const char *Directive = MAI->getHiddenDirective())
|
2008-08-08 18:25:07 +00:00
|
|
|
O << Directive << Name << '\n';
|
|
|
|
} else if (Visibility == GlobalValue::ProtectedVisibility) {
|
2009-08-22 21:43:10 +00:00
|
|
|
if (const char *Directive = MAI->getProtectedDirective())
|
2008-08-08 18:25:07 +00:00
|
|
|
O << Directive << Name << '\n';
|
|
|
|
}
|
|
|
|
}
|
2008-08-17 12:08:44 +00:00
|
|
|
|
2008-11-22 16:15:34 +00:00
|
|
|
void AsmPrinter::printOffset(int64_t Offset) const {
|
|
|
|
if (Offset > 0)
|
|
|
|
O << '+' << Offset;
|
|
|
|
else if (Offset < 0)
|
|
|
|
O << Offset;
|
|
|
|
}
|
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
|
|
|
|
if (!S->usesMetadata())
|
2008-08-17 12:08:44 +00:00
|
|
|
return 0;
|
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
gcp_iterator GCPI = GCMetadataPrinters.find(S);
|
2008-08-17 12:08:44 +00:00
|
|
|
if (GCPI != GCMetadataPrinters.end())
|
|
|
|
return GCPI->second;
|
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
const char *Name = S->getName().c_str();
|
2008-08-17 12:08:44 +00:00
|
|
|
|
|
|
|
for (GCMetadataPrinterRegistry::iterator
|
|
|
|
I = GCMetadataPrinterRegistry::begin(),
|
|
|
|
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
|
|
|
|
if (strcmp(Name, I->getName()) == 0) {
|
2008-08-17 18:44:35 +00:00
|
|
|
GCMetadataPrinter *GMP = I->instantiate();
|
|
|
|
GMP->S = S;
|
|
|
|
GCMetadataPrinters.insert(std::make_pair(S, GMP));
|
|
|
|
return GMP;
|
2008-08-17 12:08:44 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 07:19:13 +00:00
|
|
|
errs() << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable(0);
|
2008-08-17 12:08:44 +00:00
|
|
|
}
|
2009-07-13 20:25:48 +00:00
|
|
|
|
|
|
|
/// EmitComments - Pretty-print comments for instructions
|
2009-08-07 23:42:01 +00:00
|
|
|
void AsmPrinter::EmitComments(const MachineInstr &MI) const {
|
2009-09-09 23:14:36 +00:00
|
|
|
assert(VerboseAsm && !MI.getDebugLoc().isUnknown());
|
2009-08-07 23:42:01 +00:00
|
|
|
|
|
|
|
DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
|
|
|
|
|
2009-08-17 15:48:08 +00:00
|
|
|
// Print source line info.
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " SrcLine ";
|
2009-10-13 23:28:53 +00:00
|
|
|
if (DLT.Scope) {
|
|
|
|
DICompileUnit CU(DLT.Scope);
|
|
|
|
if (!CU.isNull())
|
|
|
|
O << CU.getFilename() << " ";
|
2009-07-16 22:24:20 +00:00
|
|
|
}
|
2009-08-07 23:42:01 +00:00
|
|
|
O << DLT.Line;
|
|
|
|
if (DLT.Col != 0)
|
|
|
|
O << ":" << DLT.Col;
|
2009-07-13 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 19:22:55 +00: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-22 21:43:10 +00:00
|
|
|
const MCAsmInfo *MAI,
|
2009-08-18 19:22:55 +00: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-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-08-18 19:22:55 +00:00
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString();
|
2009-08-23 00:51:00 +00:00
|
|
|
O.indent(((*cl)->getLoopDepth()-1)*2)
|
2009-08-18 19:22:55 +00:00
|
|
|
<< " Child Loop BB" << FunctionNumber << "_"
|
|
|
|
<< Header->getNumber() << " Depth " << (*cl)->getLoopDepth();
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
PrintChildLoopComment(O, *cl, MAI, FunctionNumber);
|
2009-08-18 19:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-10 16:38:07 +00:00
|
|
|
/// EmitComments - Pretty-print comments for basic blocks
|
|
|
|
void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const
|
|
|
|
{
|
2009-08-18 19:22:55 +00:00
|
|
|
if (VerboseAsm) {
|
2009-08-10 16:38:07 +00:00
|
|
|
// Add loop depth information
|
|
|
|
const MachineLoop *loop = LI->getLoopFor(&MBB);
|
|
|
|
|
|
|
|
if (loop) {
|
|
|
|
// Print a newline after bb# annotation.
|
|
|
|
O << "\n";
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth()
|
2009-08-10 16:38:07 +00:00
|
|
|
<< '\n';
|
|
|
|
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-08-10 16:38:07 +00:00
|
|
|
|
|
|
|
MachineBasicBlock *Header = loop->getHeader();
|
|
|
|
assert(Header && "No header for loop");
|
|
|
|
|
|
|
|
if (Header == &MBB) {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString() << " Loop Header";
|
|
|
|
PrintChildLoopComment(O, loop, MAI, getFunctionNumber());
|
2009-08-10 16:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-08-22 21:43:10 +00:00
|
|
|
O << MAI->getCommentString() << " Loop Header is BB"
|
2009-08-10 16:38:07 +00:00
|
|
|
<< getFunctionNumber() << "_" << loop->getHeader()->getNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loop->empty()) {
|
|
|
|
O << '\n';
|
2009-08-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Inner Loop";
|
2009-08-10 16:38:07 +00: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-22 21:43:10 +00:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString();
|
2009-08-23 00:51:00 +00:00
|
|
|
O.indent((CurLoop->getLoopDepth()-1)*2)
|
2009-08-18 19:22:55 +00:00
|
|
|
<< " Inside Loop BB" << getFunctionNumber() << "_"
|
2009-08-10 16:38:07 +00:00
|
|
|
<< Header->getNumber() << " Depth " << CurLoop->getLoopDepth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|