2004-08-17 01:15:22 +02:00
|
|
|
//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-08-17 01:15:22 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the AsmPrinter class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-03-03 03:04:29 +01:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2006-03-01 23:18:09 +01:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
Teach the SelectionDAG ISel how to turn ConstantPacked values into
constant nodes with vector types. Also teach the asm printer how to print
ConstantPacked constant pool entries. This allows us to generate altivec
code such as the following, which adds a vector constantto a packed float.
LCPI1_0: <4 x float> < float 0.0e+0, float 0.0e+0, float 0.0e+0, float 1.0e+0 >
.space 4
.space 4
.space 4
.long 1065353216 ; float 1
.text
.align 4
.globl _foo
_foo:
lis r2, ha16(LCPI1_0)
la r2, lo16(LCPI1_0)(r2)
li r4, 0
lvx v0, r4, r2
lvx v1, r4, r3
vaddfp v0, v1, v0
stvx v0, r4, r3
blr
For the llvm code:
void %foo(<4 x float> * %a) {
entry:
%tmp1 = load <4 x float> * %a;
%tmp2 = add <4 x float> %tmp1, < float 0.0, float 0.0, float 0.0, float 1.0 >
store <4 x float> %tmp2, <4 x float> *%a
ret void
}
llvm-svn: 24616
2005-12-06 07:18:55 +01:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2004-08-17 01:15:22 +02:00
|
|
|
#include "llvm/Constants.h"
|
2005-11-10 19:36:17 +01:00
|
|
|
#include "llvm/Module.h"
|
2008-08-17 20:44:35 +02:00
|
|
|
#include "llvm/CodeGen/GCMetadataPrinter.h"
|
2005-11-21 09:25:09 +01:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2009-08-18 21:22:55 +02:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2006-04-22 20:53:45 +02:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2009-08-10 18:38:07 +02:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2007-12-31 05:13:23 +01:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2009-01-13 22:44:10 +01:00
|
|
|
#include "llvm/CodeGen/DwarfWriter.h"
|
2009-05-07 15:55:51 +02:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-07-27 23:28:04 +02:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2009-07-17 00:24:20 +02:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2009-07-31 20:48:30 +02:00
|
|
|
#include "llvm/MC/MCSection.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-03-25 02:47:28 +01:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-11 15:10:19 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-13 22:25:48 +02:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2004-08-17 01:15:22 +02:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2009-08-22 22:48:53 +02:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2006-05-12 08:33:49 +02:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2006-10-07 00:50:56 +02:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2009-07-28 05:13:23 +02:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2008-07-02 01:18:29 +02:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2008-03-15 01:03:38 +01:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
llvm-svn: 43924
2007-11-09 02:32:10 +01:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2008-08-17 09:19:36 +02:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2008-08-21 02:14:44 +02: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. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
#include <cerrno>
|
2004-08-17 01:15:22 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-03-25 02:47:28 +01:00
|
|
|
static cl::opt<cl::boolOrDefault>
|
|
|
|
AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
|
|
|
|
cl::init(cl::BOU_UNSET));
|
|
|
|
|
2007-05-03 03:11:54 +02:00
|
|
|
char AsmPrinter::ID = 0;
|
2009-07-14 22:18:05 +02:00
|
|
|
AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
|
2009-08-22 22:48:53 +02:00
|
|
|
const MCAsmInfo *T, bool VDef)
|
2009-07-01 03:48:54 +02:00
|
|
|
: MachineFunctionPass(&ID), FunctionNumber(0), O(o),
|
2009-08-22 23:43:10 +02:00
|
|
|
TM(tm), MAI(T), TRI(tm.getRegisterInfo()),
|
2009-07-27 23:28:04 +02:00
|
|
|
|
|
|
|
OutContext(*new MCContext()),
|
2009-08-17 06:23:44 +02:00
|
|
|
OutStreamer(*createAsmStreamer(OutContext, O, *T, this)),
|
2009-07-27 23:28:04 +02:00
|
|
|
|
2009-08-04 01:20:21 +02:00
|
|
|
LastMI(0), LastFn(0), Counter(~0U),
|
2009-06-25 18:55:32 +02:00
|
|
|
PrevDLT(0, ~0U, ~0U) {
|
2009-06-24 21:09:55 +02:00
|
|
|
DW = 0; MMI = 0;
|
2009-03-25 02:47:28 +01: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 07:32:10 +01:00
|
|
|
|
2008-08-17 14:08:44 +02:00
|
|
|
AsmPrinter::~AsmPrinter() {
|
|
|
|
for (gcp_iterator I = GCMetadataPrinters.begin(),
|
|
|
|
E = GCMetadataPrinters.end(); I != E; ++I)
|
|
|
|
delete I->second;
|
2009-07-27 23:28:04 +02:00
|
|
|
|
|
|
|
delete &OutStreamer;
|
|
|
|
delete &OutContext;
|
2008-08-17 14:08:44 +02:00
|
|
|
}
|
2005-12-13 07:32:10 +01:00
|
|
|
|
2009-08-03 21:12:26 +02:00
|
|
|
TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
|
2009-07-28 05:13:23 +02:00
|
|
|
return TM.getTargetLowering()->getObjFileLowering();
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:15:16 +02:00
|
|
|
/// getCurrentSection() - Return the current section we are emitting to.
|
|
|
|
const MCSection *AsmPrinter::getCurrentSection() const {
|
|
|
|
return OutStreamer.getCurrentSection();
|
2008-09-25 00:12:10 +02:00
|
|
|
}
|
2006-05-09 06:59:56 +02:00
|
|
|
|
2009-08-18 08:15:16 +02:00
|
|
|
|
2008-01-07 02:30:38 +01:00
|
|
|
void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
|
2009-08-01 01:37:33 +02:00
|
|
|
AU.setPreservesAll();
|
2008-01-07 02:30:38 +01:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2008-08-17 20:44:35 +02:00
|
|
|
AU.addRequired<GCModuleInfo>();
|
2009-08-18 21:22:55 +02:00
|
|
|
if (VerboseAsm)
|
2009-08-10 18:38:07 +02:00
|
|
|
AU.addRequired<MachineLoopInfo>();
|
2008-01-07 02:30:38 +01:00
|
|
|
}
|
|
|
|
|
2004-08-17 01:15:22 +02:00
|
|
|
bool AsmPrinter::doInitialization(Module &M) {
|
2009-07-31 19:42:42 +02:00
|
|
|
// Initialize TargetLoweringObjectFile.
|
|
|
|
const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
|
|
|
|
.Initialize(OutContext, TM);
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
Mang = new Mangler(M, MAI->getGlobalPrefix(), MAI->getPrivateGlobalPrefix(),
|
|
|
|
MAI->getLinkerPrivateGlobalPrefix());
|
2006-01-24 00:47:53 +01:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->doesAllowQuotesInName())
|
2009-06-19 01:41:35 +02:00
|
|
|
Mang->setUseQuotes(true);
|
|
|
|
|
2009-01-28 14:14:17 +01:00
|
|
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
2008-08-17 20:44:35 +02:00
|
|
|
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
|
2008-12-03 12:01:37 +01:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->hasSingleParameterDotFile()) {
|
2008-12-03 12:01:37 +01:00
|
|
|
/* Very minimal debug info. It is ignored if we emit actual
|
|
|
|
debug info. If we don't, this at helps the user find where
|
|
|
|
a function came from. */
|
|
|
|
O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
|
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
|
|
|
|
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
|
2009-08-22 23:43:10 +02:00
|
|
|
MP->beginAssembly(O, *this, *MAI);
|
2008-01-07 02:30:38 +01:00
|
|
|
|
2006-01-24 05:16:34 +01:00
|
|
|
if (!M.getModuleInlineAsm().empty())
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString() << " Start of file scope inline assembly\n"
|
2006-01-24 05:16:34 +01:00
|
|
|
<< M.getModuleInlineAsm()
|
2009-08-22 23:43:10 +02:00
|
|
|
<< '\n' << MAI->getCommentString()
|
2006-09-06 20:34:40 +02:00
|
|
|
<< " End of file scope inline assembly\n";
|
2006-01-24 00:47:53 +01:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->doesSupportDebugInformation() ||
|
|
|
|
MAI->doesSupportExceptionHandling()) {
|
2009-06-24 21:09:55 +02:00
|
|
|
MMI = getAnalysisIfAvailable<MachineModuleInfo>();
|
|
|
|
if (MMI)
|
2009-06-19 23:54:26 +02:00
|
|
|
MMI->AnalyzeModule(M);
|
2009-06-24 21:09:55 +02:00
|
|
|
DW = getAnalysisIfAvailable<DwarfWriter>();
|
|
|
|
if (DW)
|
2009-08-22 23:43:10 +02:00
|
|
|
DW->BeginModule(&M, MMI, O, this, MAI);
|
2009-06-19 23:54:26 +02:00
|
|
|
}
|
|
|
|
|
2004-08-17 01:15:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsmPrinter::doFinalization(Module &M) {
|
2009-07-21 20:38:57 +02: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 20:54:37 +02:00
|
|
|
// Emit final debug information.
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling())
|
2009-06-24 20:54:37 +02:00
|
|
|
DW->EndModule();
|
|
|
|
|
2009-06-24 20:52:01 +02:00
|
|
|
// If the target wants to know about weak references, print them all.
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getWeakRefDirective()) {
|
2009-06-24 20:52:01 +02: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 23:43:10 +02:00
|
|
|
O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
|
2009-06-24 20:52:01 +02:00
|
|
|
}
|
|
|
|
|
2009-08-04 01:10:34 +02:00
|
|
|
for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
|
2009-06-24 20:52:01 +02:00
|
|
|
if (I->hasExternalWeakLinkage())
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
|
2009-06-24 20:52:01 +02:00
|
|
|
}
|
2006-12-18 04:37:18 +01:00
|
|
|
}
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getSetDirective()) {
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n';
|
2007-04-25 16:27:10 +02:00
|
|
|
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
|
2009-06-24 20:52:01 +02:00
|
|
|
I != E; ++I) {
|
2009-07-14 20:17:16 +02:00
|
|
|
std::string Name = Mang->getMangledName(I);
|
2007-09-06 19:21:48 +02:00
|
|
|
|
|
|
|
const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
|
2009-07-14 20:17:16 +02:00
|
|
|
std::string Target = Mang->getMangledName(GV);
|
2008-09-25 00:21:04 +02:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())
|
2008-07-01 00:03:41 +02:00
|
|
|
O << "\t.globl\t" << Name << '\n';
|
2007-04-25 16:27:10 +02:00
|
|
|
else if (I->hasWeakLinkage())
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getWeakRefDirective() << Name << '\n';
|
2009-01-15 21:18:42 +01:00
|
|
|
else if (!I->hasLocalLinkage())
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Invalid alias linkage");
|
2008-03-11 22:41:14 +01:00
|
|
|
|
2008-09-25 00:21:04 +02:00
|
|
|
printVisibility(Name, I->getVisibility());
|
2008-03-11 22:41:14 +01:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getSetDirective() << ' ' << Name << ", " << Target << '\n';
|
2007-04-25 16:27:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-28 14:14:17 +01:00
|
|
|
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
|
2008-08-17 20:44:35 +02: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 23:43:10 +02:00
|
|
|
MP->finishAssembly(O, *this, *MAI);
|
2008-01-07 02:30:38 +01:00
|
|
|
|
2008-05-05 02:28:39 +02: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 20:52:01 +02:00
|
|
|
Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
|
2008-05-05 02:28:39 +02:00
|
|
|
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getNonexecutableStackDirective())
|
|
|
|
O << MAI->getNonexecutableStackDirective() << '\n';
|
2008-05-05 02:28:39 +02:00
|
|
|
|
2004-08-17 01:15:22 +02:00
|
|
|
delete Mang; Mang = 0;
|
2009-06-24 21:09:55 +02:00
|
|
|
DW = 0; MMI = 0;
|
2009-07-27 23:28:04 +02:00
|
|
|
|
|
|
|
OutStreamer.Finish();
|
2004-08-17 01:15:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-17 22:46:40 +02:00
|
|
|
std::string
|
|
|
|
AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) const {
|
2007-09-18 03:47:22 +02:00
|
|
|
assert(MF && "No machine function?");
|
2009-07-17 22:46:40 +02:00
|
|
|
return Mang->getMangledName(MF->getFunction(), ".eh",
|
2009-08-22 23:43:10 +02:00
|
|
|
MAI->is_EHSymbolPrivate());
|
2007-09-18 03:47:22 +02:00
|
|
|
}
|
|
|
|
|
2005-11-21 08:51:36 +01:00
|
|
|
void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
|
2004-08-17 01:15:22 +02:00
|
|
|
// What's my mangled name?
|
2009-07-14 20:17:16 +02:00
|
|
|
CurrentFnName = Mang->getMangledName(MF.getFunction());
|
2007-10-14 07:57:21 +02:00
|
|
|
IncrementFunctionNumber();
|
2009-08-10 18:38:07 +02:00
|
|
|
|
2009-08-18 21:22:55 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-10 18:38:07 +02:00
|
|
|
LI = &getAnalysis<MachineLoopInfo>();
|
|
|
|
}
|
2004-08-17 01:15:22 +02:00
|
|
|
}
|
|
|
|
|
2009-03-13 08:51:59 +01:00
|
|
|
namespace {
|
|
|
|
// SectionCPs - Keep track the alignment, constpool entries per Section.
|
|
|
|
struct SectionCPs {
|
2009-07-31 20:48:30 +02:00
|
|
|
const MCSection *S;
|
2009-03-13 08:51:59 +01:00
|
|
|
unsigned Alignment;
|
|
|
|
SmallVector<unsigned, 4> CPEs;
|
2009-07-31 20:48:30 +02:00
|
|
|
SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {};
|
2009-03-13 08:51:59 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-11-21 09:25:09 +01: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 05:22:52 +01:00
|
|
|
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
|
2005-11-21 09:25:09 +01:00
|
|
|
if (CP.empty()) return;
|
2006-06-29 02:26:09 +02:00
|
|
|
|
2008-09-25 00:17:59 +02: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 08:51:59 +01:00
|
|
|
SmallVector<SectionCPs, 4> CPSections;
|
2006-06-29 02:26:09 +02:00
|
|
|
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
|
2009-07-22 02:28:43 +02:00
|
|
|
const MachineConstantPoolEntry &CPE = CP[i];
|
2009-03-13 08:51:59 +01:00
|
|
|
unsigned Align = CPE.getAlignment();
|
2009-07-26 08:26:55 +02:00
|
|
|
|
|
|
|
SectionKind Kind;
|
|
|
|
switch (CPE.getRelocationInfo()) {
|
|
|
|
default: llvm_unreachable("Unknown section kind");
|
2009-08-02 01:57:16 +02:00
|
|
|
case 2: Kind = SectionKind::getReadOnlyWithRel(); break;
|
2009-07-26 09:00:12 +02:00
|
|
|
case 1:
|
2009-08-02 01:57:16 +02:00
|
|
|
Kind = SectionKind::getReadOnlyWithRelLocal();
|
2009-07-26 09:00:12 +02:00
|
|
|
break;
|
2009-07-26 08:26:55 +02:00
|
|
|
case 0:
|
2009-07-26 09:00:12 +02:00
|
|
|
switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
|
2009-08-02 01:57:16 +02: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 09:00:12 +02:00
|
|
|
}
|
2009-07-26 08:26:55 +02:00
|
|
|
}
|
|
|
|
|
2009-08-02 01:46:12 +02:00
|
|
|
const MCSection *S = getObjFileLowering().getSectionForConstant(Kind);
|
2009-07-22 02:28:43 +02:00
|
|
|
|
2009-03-13 08:51:59 +01: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 02:26:09 +02:00
|
|
|
}
|
|
|
|
|
2008-09-25 00:17:59 +02:00
|
|
|
// Now print stuff into the calculated sections.
|
2009-03-13 08:51:59 +01:00
|
|
|
for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
|
2009-08-19 07:49:37 +02:00
|
|
|
OutStreamer.SwitchSection(CPSections[i].S);
|
2009-03-13 08:51:59 +01:00
|
|
|
EmitAlignment(Log2_32(CPSections[i].Alignment));
|
2006-06-29 02:26:09 +02:00
|
|
|
|
2009-03-13 08:51:59 +01: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 09:06:46 +02:00
|
|
|
Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
|
2006-06-29 02:26:09 +02:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
|
2009-08-12 20:32:22 +02:00
|
|
|
<< CPI << ':';
|
2009-03-13 08:51:59 +01:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " constant ";
|
2009-08-13 03:36:44 +02:00
|
|
|
WriteTypeSymbolic(O, CPE.getType(), MF->getFunction()->getParent());
|
2009-03-13 08:51:59 +01:00
|
|
|
}
|
2008-09-25 00:17:59 +02:00
|
|
|
O << '\n';
|
2009-03-13 08:51:59 +01:00
|
|
|
if (CPE.isMachineConstantPoolEntry())
|
|
|
|
EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
|
2008-09-25 00:17:59 +02:00
|
|
|
else
|
2009-03-13 08:51:59 +01:00
|
|
|
EmitGlobalConstant(CPE.Val.ConstVal);
|
2006-02-09 05:46:04 +01:00
|
|
|
}
|
2005-11-21 09:25:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-22 20:53:45 +02:00
|
|
|
/// EmitJumpTableInfo - Print assembly representations of the jump tables used
|
|
|
|
/// by the current function to the current output stream.
|
|
|
|
///
|
2006-10-05 05:01:21 +02:00
|
|
|
void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
|
|
|
|
MachineFunction &MF) {
|
2006-04-22 20:53:45 +02:00
|
|
|
const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
|
|
|
|
if (JT.empty()) return;
|
2007-11-14 10:18:41 +01:00
|
|
|
|
2006-12-14 20:17:33 +01:00
|
|
|
bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
|
2006-07-27 18:46:58 +02:00
|
|
|
|
2006-07-27 03:13:04 +02:00
|
|
|
// Pick the directive to use to print the jump table entries, and switch to
|
|
|
|
// the appropriate section.
|
2006-12-14 20:17:33 +01:00
|
|
|
TargetLowering *LoweringInfo = TM.getTargetLowering();
|
2006-12-19 22:04:20 +01:00
|
|
|
|
2008-07-09 15:27:16 +02:00
|
|
|
const Function *F = MF.getFunction();
|
2009-06-18 22:37:15 +02:00
|
|
|
bool JTInDiffSection = false;
|
2009-08-02 01:46:12 +02:00
|
|
|
if (F->isWeakForLinker() ||
|
|
|
|
(IsPic && !LoweringInfo->usesGlobalOffsetTable())) {
|
2006-12-14 20:17:33 +01: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 15:27:16 +02:00
|
|
|
// We should also do if the section name is NULL or function is declared in
|
|
|
|
// discardable section.
|
2009-08-19 07:49:37 +02:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang,
|
|
|
|
TM));
|
2006-07-27 03:13:04 +02:00
|
|
|
} else {
|
2009-08-02 01:46:12 +02:00
|
|
|
// Otherwise, drop it in the readonly section.
|
|
|
|
const MCSection *ReadOnlySection =
|
2009-08-02 01:57:16 +02:00
|
|
|
getObjFileLowering().getSectionForConstant(SectionKind::getReadOnly());
|
2009-08-19 07:49:37 +02:00
|
|
|
OutStreamer.SwitchSection(ReadOnlySection);
|
2009-06-18 22:37:15 +02:00
|
|
|
JTInDiffSection = true;
|
2006-07-27 03:13:04 +02:00
|
|
|
}
|
2006-12-14 20:17:33 +01:00
|
|
|
|
|
|
|
EmitAlignment(Log2_32(MJTI->getAlignment()));
|
2006-07-15 03:34:12 +02:00
|
|
|
|
2006-04-22 20:53:45 +02:00
|
|
|
for (unsigned i = 0, e = JT.size(); i != e; ++i) {
|
2006-08-12 23:29:52 +02:00
|
|
|
const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
|
2006-10-28 20:10:06 +02:00
|
|
|
|
|
|
|
// If this jump table was deleted, ignore it.
|
|
|
|
if (JTBBs.empty()) continue;
|
2006-08-12 23:29:52 +02:00
|
|
|
|
|
|
|
// For PIC codegen, if possible we want to use the SetDirective to reduce
|
|
|
|
// the number of relocations the assembler will generate for the jump table.
|
|
|
|
// Set directives are all printed before the jump table itself.
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
llvm-svn: 43924
2007-11-09 02:32:10 +01:00
|
|
|
SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getSetDirective() && IsPic)
|
2006-08-12 23:29:52 +02:00
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
llvm-svn: 43924
2007-11-09 02:32:10 +01:00
|
|
|
if (EmittedSets.insert(JTBBs[ii]))
|
|
|
|
printPICJumpTableSetLabel(i, JTBBs[ii]);
|
2006-08-12 23:29:52 +02:00
|
|
|
|
2007-01-18 02:12:56 +01:00
|
|
|
// On some targets (e.g. darwin) we want to emit two consequtive labels
|
|
|
|
// 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-06-18 22:37:15 +02:00
|
|
|
if (JTInDiffSection) {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (const char *JTLabelPrefix = MAI->getJumpTableSpecialLabelPrefix())
|
2009-06-18 22:37:15 +02:00
|
|
|
O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
|
|
|
|
}
|
2007-01-18 02:12:56 +01:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 07:57:21 +02:00
|
|
|
<< '_' << i << ":\n";
|
2006-08-12 23:29:52 +02:00
|
|
|
|
2006-04-22 20:53:45 +02:00
|
|
|
for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
|
2007-11-14 10:18:41 +01:00
|
|
|
printPICJumpTableEntry(MJTI, JTBBs[ii], i);
|
2006-04-22 20:53:45 +02:00
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 10:18:41 +01:00
|
|
|
void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
|
|
|
const MachineBasicBlock *MBB,
|
|
|
|
unsigned uid) const {
|
2009-08-11 22:29:57 +02:00
|
|
|
bool isPIC = TM.getRelocationModel() == Reloc::PIC_;
|
2007-11-14 10:18:41 +01:00
|
|
|
|
|
|
|
// Use JumpTableDirective otherwise honor the entry size from the jump table
|
|
|
|
// info.
|
2009-08-22 23:43:10 +02:00
|
|
|
const char *JTEntryDirective = MAI->getJumpTableDirective(isPIC);
|
2007-11-14 10:18:41 +01:00
|
|
|
bool HadJTEntryDirective = JTEntryDirective != NULL;
|
|
|
|
if (!HadJTEntryDirective) {
|
|
|
|
JTEntryDirective = MJTI->getEntrySize() == 4 ?
|
2009-08-22 23:43:10 +02:00
|
|
|
MAI->getData32bitsDirective() : MAI->getData64bitsDirective();
|
2007-11-14 10:18:41 +01: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 22:29:57 +02:00
|
|
|
if (!isPIC) {
|
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2009-08-22 23:43:10 +02:00
|
|
|
} else if (MAI->getSetDirective()) {
|
|
|
|
O << MAI->getPrivateGlobalPrefix() << getFunctionNumber()
|
2009-08-11 22:29:57 +02:00
|
|
|
<< '_' << uid << "_set_" << MBB->getNumber();
|
2007-11-14 10:18:41 +01:00
|
|
|
} else {
|
2008-02-28 01:43:03 +01:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2009-08-11 22:29:57 +02:00
|
|
|
// If the arch uses custom Jump Table directives, don't calc relative to
|
|
|
|
// JT
|
|
|
|
if (!HadJTEntryDirective)
|
2009-08-22 23:43:10 +02:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI"
|
2009-08-11 22:29:57 +02:00
|
|
|
<< getFunctionNumber() << '_' << uid;
|
2007-11-14 10:18:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-13 07:32:10 +01:00
|
|
|
/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
|
|
|
|
/// special global used by LLVM. If so, emit it and return true, otherwise
|
|
|
|
/// do nothing and return false.
|
|
|
|
bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
|
2009-07-26 01:55:21 +02:00
|
|
|
if (GV->getName() == "llvm.used") {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getUsedDirective() != 0) // No need to emit this at all.
|
2007-08-22 21:33:11 +02:00
|
|
|
EmitLLVMUsedList(GV->getInitializer());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-20 08:14:25 +02:00
|
|
|
// Ignore debug and non-emitted data. This handles llvm.compiler.used.
|
2009-04-13 07:44:34 +02:00
|
|
|
if (GV->getSection() == "llvm.metadata" ||
|
|
|
|
GV->hasAvailableExternallyLinkage())
|
|
|
|
return true;
|
2006-03-07 23:00:35 +01:00
|
|
|
|
|
|
|
if (!GV->hasAppendingLinkage()) return false;
|
|
|
|
|
|
|
|
assert(GV->hasInitializer() && "Not a special LLVM global!");
|
2005-12-13 07:32:10 +01:00
|
|
|
|
2007-06-04 22:39:18 +02:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
unsigned Align = Log2_32(TD->getPointerPrefAlignment());
|
2009-03-09 06:52:15 +01:00
|
|
|
if (GV->getName() == "llvm.global_ctors") {
|
2009-08-19 07:49:37 +02:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
|
2009-03-09 09:18:48 +01:00
|
|
|
EmitAlignment(Align, 0);
|
|
|
|
EmitXXStructorList(GV->getInitializer());
|
|
|
|
return true;
|
2005-12-13 07:32:10 +01:00
|
|
|
}
|
|
|
|
|
2009-03-09 06:52:15 +01:00
|
|
|
if (GV->getName() == "llvm.global_dtors") {
|
2009-08-19 07:49:37 +02:00
|
|
|
OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
|
2009-03-09 09:18:48 +01:00
|
|
|
EmitAlignment(Align, 0);
|
|
|
|
EmitXXStructorList(GV->getInitializer());
|
|
|
|
return true;
|
2005-12-13 07:32:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
/// EmitLLVMUsedList - For targets that define a MAI::UsedDirective, mark each
|
2008-09-10 00:29:13 +02:00
|
|
|
/// global in the specified llvm.used list for which emitUsedDirectiveFor
|
|
|
|
/// is true, as being used with this directive.
|
2006-09-26 05:38:18 +02:00
|
|
|
void AsmPrinter::EmitLLVMUsedList(Constant *List) {
|
2009-08-22 23:43:10 +02:00
|
|
|
const char *Directive = MAI->getUsedDirective();
|
2006-09-26 05:38:18 +02:00
|
|
|
|
2009-06-15 01:30:43 +02:00
|
|
|
// Should be an array of 'i8*'.
|
2006-09-26 05:38:18 +02:00
|
|
|
ConstantArray *InitList = dyn_cast<ConstantArray>(List);
|
|
|
|
if (InitList == 0) return;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
2009-07-18 00:00:23 +02:00
|
|
|
const GlobalValue *GV =
|
|
|
|
dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
|
2009-07-31 22:52:39 +02:00
|
|
|
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) {
|
2008-09-03 22:34:58 +02:00
|
|
|
O << Directive;
|
|
|
|
EmitConstantValueOnly(InitList->getOperand(i));
|
|
|
|
O << '\n';
|
|
|
|
}
|
2006-09-26 05:38:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-13 07:32:10 +01: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 02:17:37 +01:00
|
|
|
|
|
|
|
if (CS->getOperand(1)->isNullValue())
|
|
|
|
return; // Found a null terminator, exit printing.
|
|
|
|
// Emit the function pointer.
|
2005-12-13 07:32:10 +01:00
|
|
|
EmitGlobalConstant(CS->getOperand(1));
|
|
|
|
}
|
|
|
|
}
|
2005-11-21 09:25:09 +01:00
|
|
|
|
2006-10-17 15:41:07 +02:00
|
|
|
/// getGlobalLinkName - Returns the asm/link name of of the specified
|
|
|
|
/// global variable. Should be overridden by each target asm printer to
|
|
|
|
/// generate the appropriate value.
|
2009-04-10 02:12:49 +02:00
|
|
|
const std::string &AsmPrinter::getGlobalLinkName(const GlobalVariable *GV,
|
|
|
|
std::string &LinkName) const {
|
2006-11-20 21:29:06 +01:00
|
|
|
if (isa<Function>(GV)) {
|
2009-08-22 23:43:10 +02:00
|
|
|
LinkName += MAI->getFunctionAddrPrefix();
|
2009-07-14 20:17:16 +02:00
|
|
|
LinkName += Mang->getMangledName(GV);
|
2009-08-22 23:43:10 +02:00
|
|
|
LinkName += MAI->getFunctionAddrSuffix();
|
2006-11-20 21:29:06 +01:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
LinkName += MAI->getGlobalVarAddrPrefix();
|
2009-07-14 20:17:16 +02:00
|
|
|
LinkName += Mang->getMangledName(GV);
|
2009-08-22 23:43:10 +02:00
|
|
|
LinkName += MAI->getGlobalVarAddrSuffix();
|
2006-11-20 21:29:06 +01:00
|
|
|
}
|
|
|
|
|
2006-10-17 19:17:24 +02:00
|
|
|
return LinkName;
|
2006-10-17 15:41:07 +02:00
|
|
|
}
|
|
|
|
|
2007-02-21 23:47:38 +01:00
|
|
|
/// EmitExternalGlobal - Emit the external reference to a global variable.
|
|
|
|
/// Should be overridden if an indirect reference should be used.
|
|
|
|
void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
|
2009-04-10 02:12:49 +02:00
|
|
|
std::string GLN;
|
|
|
|
O << getGlobalLinkName(GV, GLN);
|
2007-02-21 23:47:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-25 16:12:02 +01: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 05:35:24 +01:00
|
|
|
char Buffer[20];
|
2007-01-25 16:12:02 +01:00
|
|
|
do {
|
2008-11-10 05:35:24 +01:00
|
|
|
unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
|
2007-01-25 16:12:02 +01:00
|
|
|
Value >>= 7;
|
|
|
|
if (Value) Byte |= 0x80;
|
2008-11-10 05:35:24 +01:00
|
|
|
O << "0x" << utohex_buffer(Byte, Buffer+20);
|
2007-01-25 16:12:02 +01: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 05:35:24 +01:00
|
|
|
char Buffer[20];
|
2008-08-16 14:57:46 +02:00
|
|
|
|
2007-01-25 16:12:02 +01:00
|
|
|
do {
|
2008-11-10 05:35:24 +01:00
|
|
|
unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
|
2007-01-25 16:12:02 +01:00
|
|
|
Value >>= 7;
|
|
|
|
IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
|
|
|
|
if (IsMore) Byte |= 0x80;
|
2008-11-10 05:35:24 +01:00
|
|
|
O << "0x" << utohex_buffer(Byte, Buffer+20);
|
2007-01-25 16:12:02 +01: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 05:30:26 +01:00
|
|
|
char Buffer[20];
|
|
|
|
O << "0x" << utohex_buffer(static_cast<unsigned>(Value), Buffer+20);
|
2007-01-25 16:12:02 +01: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 23:47:38 +01:00
|
|
|
void AsmPrinter::EOL() const {
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n';
|
2007-02-21 23:47:38 +01:00
|
|
|
}
|
2008-07-01 23:16:27 +02:00
|
|
|
|
2007-01-25 16:12:02 +01:00
|
|
|
void AsmPrinter::EOL(const std::string &Comment) const {
|
2008-07-02 01:18:29 +02:00
|
|
|
if (VerboseAsm && !Comment.empty()) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2008-07-01 00:03:41 +02:00
|
|
|
<< ' '
|
2007-01-25 16:12:02 +01:00
|
|
|
<< Comment;
|
|
|
|
}
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n';
|
2007-01-25 16:12:02 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 23:16:27 +02:00
|
|
|
void AsmPrinter::EOL(const char* Comment) const {
|
2008-07-02 01:18:29 +02:00
|
|
|
if (VerboseAsm && *Comment) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2008-07-01 23:16:27 +02:00
|
|
|
<< ' '
|
|
|
|
<< Comment;
|
|
|
|
}
|
|
|
|
O << '\n';
|
|
|
|
}
|
|
|
|
|
2007-01-25 16:12:02 +01:00
|
|
|
/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
|
|
|
|
/// unsigned leb128 value.
|
|
|
|
void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->hasLEB128()) {
|
2007-01-25 16:12:02 +01:00
|
|
|
O << "\t.uleb128\t"
|
|
|
|
<< Value;
|
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 16:12:02 +01: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 23:43:10 +02:00
|
|
|
if (MAI->hasLEB128()) {
|
2007-01-25 16:12:02 +01:00
|
|
|
O << "\t.sleb128\t"
|
|
|
|
<< Value;
|
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 16:12:02 +01:00
|
|
|
PrintSLEB128(Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt8 - Emit a byte directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt8(int Value) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData8bitsDirective();
|
2007-01-25 16:12:02 +01:00
|
|
|
PrintHex(Value & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt16 - Emit a short directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt16(int Value) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective();
|
2007-01-25 16:12:02 +01:00
|
|
|
PrintHex(Value & 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt32 - Emit a long directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt32(int Value) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective();
|
2007-01-25 16:12:02 +01:00
|
|
|
PrintHex(Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitInt64 - Emit a long long directive and value.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitInt64(uint64_t Value) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getData64bitsDirective()) {
|
|
|
|
O << MAI->getData64bitsDirective();
|
2007-01-25 16:12:02 +01:00
|
|
|
PrintHex(Value);
|
|
|
|
} else {
|
|
|
|
if (TM.getTargetData()->isBigEndian()) {
|
2008-07-01 00:03:41 +02:00
|
|
|
EmitInt32(unsigned(Value >> 32)); O << '\n';
|
2007-01-25 16:12:02 +01:00
|
|
|
EmitInt32(unsigned(Value));
|
|
|
|
} else {
|
2008-07-01 00:03:41 +02:00
|
|
|
EmitInt32(unsigned(Value)); O << '\n';
|
2007-01-25 16:12:02 +01: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 22:18:05 +02:00
|
|
|
static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
|
2007-01-25 16:12:02 +01:00
|
|
|
if (C == '"') {
|
|
|
|
O << "\\\"";
|
|
|
|
} else if (C == '\\') {
|
|
|
|
O << "\\\\";
|
2009-01-23 00:38:45 +01:00
|
|
|
} else if (isprint((unsigned char)C)) {
|
2007-01-25 16:12:02 +01: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-10 01:51:31 +02:00
|
|
|
EmitString(String.c_str(), String.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsmPrinter::EmitString(const char *String, unsigned Size) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
const char* AscizDirective = MAI->getAscizDirective();
|
2007-03-06 20:25:02 +01:00
|
|
|
if (AscizDirective)
|
|
|
|
O << AscizDirective;
|
|
|
|
else
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getAsciiDirective();
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\"';
|
2009-04-10 01:51:31 +02:00
|
|
|
for (unsigned i = 0; i < Size; ++i)
|
2009-04-08 02:28:38 +02:00
|
|
|
printStringChar(O, String[i]);
|
2007-03-06 20:25:02 +01:00
|
|
|
if (AscizDirective)
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\"';
|
2007-03-06 20:25:02 +01:00
|
|
|
else
|
|
|
|
O << "\\0\"";
|
2007-01-25 16:12:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-24 22:58:13 +02:00
|
|
|
/// EmitFile - Emit a .file directive.
|
|
|
|
void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
|
|
|
|
O << "\t.file\t" << Number << " \"";
|
2009-04-08 02:28:38 +02:00
|
|
|
for (unsigned i = 0, N = Name.size(); i < N; ++i)
|
|
|
|
printStringChar(O, Name[i]);
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\"';
|
2007-09-24 22:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-25 16:12:02 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-05-31 20:57:45 +02: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 20:36:59 +01:00
|
|
|
unsigned ForcedAlignBits,
|
|
|
|
bool UseFillExpr) const {
|
2007-04-24 01:33:31 +02:00
|
|
|
if (GV && GV->getAlignment())
|
2007-05-31 20:57:45 +02:00
|
|
|
NumBits = Log2_32(GV->getAlignment());
|
|
|
|
NumBits = std::max(NumBits, ForcedAlignBits);
|
|
|
|
|
2005-11-10 19:09:27 +01:00
|
|
|
if (NumBits == 0) return; // No need to emit alignment.
|
2009-08-19 08:12:02 +02:00
|
|
|
|
|
|
|
unsigned FillValue = 0;
|
2009-08-18 08:15:16 +02:00
|
|
|
if (getCurrentSection()->getKind().isText())
|
2009-08-22 23:43:10 +02:00
|
|
|
FillValue = MAI->getTextAlignFillValue();
|
2009-08-19 08:12:02 +02:00
|
|
|
|
|
|
|
OutStreamer.EmitValueToAlignment(1 << NumBits, FillValue, 1, 0);
|
2004-08-17 21:14:29 +02:00
|
|
|
}
|
2009-08-05 23:00:52 +02:00
|
|
|
|
2005-11-21 08:51:36 +01:00
|
|
|
/// EmitZeros - Emit a block of zeros.
|
2004-08-17 23:38:40 +02:00
|
|
|
///
|
2009-01-30 05:25:10 +01:00
|
|
|
void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
|
2004-08-17 23:38:40 +02:00
|
|
|
if (NumZeros) {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getZeroDirective()) {
|
|
|
|
O << MAI->getZeroDirective() << NumZeros;
|
|
|
|
if (MAI->getZeroDirectiveSuffix())
|
|
|
|
O << MAI->getZeroDirectiveSuffix();
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n';
|
2006-05-02 05:46:13 +02:00
|
|
|
} else {
|
2004-08-17 23:38:40 +02:00
|
|
|
for (; NumZeros; --NumZeros)
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData8bitsDirective(AddrSpace) << "0\n";
|
2004-08-17 23:38:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-17 01:15:22 +02:00
|
|
|
// Print out the specified constant, without a storage class. Only the
|
|
|
|
// constants valid in constant expressions can occur here.
|
2005-11-21 08:51:36 +01:00
|
|
|
void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
|
2004-10-16 20:19:26 +02:00
|
|
|
if (CV->isNullValue() || isa<UndefValue>(CV))
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '0';
|
2007-01-11 13:24:14 +01:00
|
|
|
else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
2008-06-03 08:18:19 +02:00
|
|
|
O << CI->getZExtValue();
|
2006-10-20 09:07:24 +02:00
|
|
|
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
|
2005-04-02 14:21:51 +02:00
|
|
|
// This is a constant address for a global variable or function. Use the
|
|
|
|
// name of the variable or function as the address value, possibly
|
|
|
|
// decorating it with GlobalVarAddrPrefix/Suffix or
|
|
|
|
// FunctionAddrPrefix/Suffix (these all default to "" )
|
2006-09-06 20:34:40 +02:00
|
|
|
if (isa<Function>(GV)) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getFunctionAddrPrefix()
|
2009-07-14 20:17:16 +02:00
|
|
|
<< Mang->getMangledName(GV)
|
2009-08-22 23:43:10 +02:00
|
|
|
<< MAI->getFunctionAddrSuffix();
|
2006-09-06 20:34:40 +02:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getGlobalVarAddrPrefix()
|
2009-07-14 20:17:16 +02:00
|
|
|
<< Mang->getMangledName(GV)
|
2009-08-22 23:43:10 +02:00
|
|
|
<< MAI->getGlobalVarAddrSuffix();
|
2006-09-06 20:34:40 +02:00
|
|
|
}
|
2005-04-02 14:21:51 +02:00
|
|
|
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
|
2006-05-03 03:29:57 +02:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2007-02-05 00:27:42 +01:00
|
|
|
unsigned Opcode = CE->getOpcode();
|
|
|
|
switch (Opcode) {
|
2009-08-02 00:25:12 +02: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-17 01:15:22 +02:00
|
|
|
case Instruction::GetElementPtr: {
|
|
|
|
// generate a symbolic expression for the byte address
|
|
|
|
const Constant *ptrVal = CE->getOperand(0);
|
2007-02-10 21:31:59 +01: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 07:55:21 +01: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 22:40:26 +01:00
|
|
|
if (Offset)
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '(';
|
2005-11-21 08:51:36 +01:00
|
|
|
EmitConstantValueOnly(ptrVal);
|
2005-02-14 22:40:26 +01:00
|
|
|
if (Offset > 0)
|
|
|
|
O << ") + " << Offset;
|
|
|
|
else if (Offset < 0)
|
|
|
|
O << ") - " << -Offset;
|
2004-08-17 01:15:22 +02:00
|
|
|
} else {
|
2005-11-21 08:51:36 +01:00
|
|
|
EmitConstantValueOnly(ptrVal);
|
2004-08-17 01:15:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-12-12 06:14:13 +01:00
|
|
|
case Instruction::BitCast:
|
|
|
|
return EmitConstantValueOnly(CE->getOperand(0));
|
|
|
|
|
2006-12-12 06:18:19 +01: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 23:58:54 +02:00
|
|
|
Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(CV->getContext()),
|
|
|
|
false/*ZExt*/);
|
2006-12-12 06:18:19 +01:00
|
|
|
return EmitConstantValueOnly(Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case Instruction::PtrToInt: {
|
2006-07-29 03:57:19 +02:00
|
|
|
// Support only foldable casts to/from pointers that can be eliminated by
|
|
|
|
// changing the pointer to the appropriately sized integer type.
|
2004-08-17 01:15:22 +02:00
|
|
|
Constant *Op = CE->getOperand(0);
|
2006-12-12 06:18:19 +01:00
|
|
|
const Type *Ty = CE->getType();
|
2004-08-17 01:15:22 +02:00
|
|
|
|
2006-12-12 06:18:19 +01: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-02 00:25:12 +02:00
|
|
|
if (TD->getTypeAllocSize(Ty) == TD->getTypeAllocSize(Op->getType()))
|
2006-07-29 03:57:19 +02:00
|
|
|
return EmitConstantValueOnly(Op);
|
2008-08-08 08:34:07 +02:00
|
|
|
|
|
|
|
O << "((";
|
2005-11-21 08:51:36 +01:00
|
|
|
EmitConstantValueOnly(Op);
|
2009-08-02 00:25:12 +02:00
|
|
|
APInt ptrMask =
|
|
|
|
APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Op->getType()));
|
2008-08-17 09:19:36 +02:00
|
|
|
|
|
|
|
SmallString<40> S;
|
|
|
|
ptrMask.toStringUnsigned(S);
|
2009-08-19 22:07:03 +02:00
|
|
|
O << ") & " << S.str() << ')';
|
2004-08-17 01:15:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Instruction::Add:
|
2007-02-05 00:27:42 +01:00
|
|
|
case Instruction::Sub:
|
2007-12-18 21:53:41 +01:00
|
|
|
case Instruction::And:
|
|
|
|
case Instruction::Or:
|
|
|
|
case Instruction::Xor:
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '(';
|
2005-11-21 08:51:36 +01:00
|
|
|
EmitConstantValueOnly(CE->getOperand(0));
|
2008-07-01 00:03:41 +02:00
|
|
|
O << ')';
|
2007-12-18 21:53:41 +01: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-07-01 00:03:41 +02:00
|
|
|
O << '(';
|
2005-11-21 08:51:36 +01:00
|
|
|
EmitConstantValueOnly(CE->getOperand(1));
|
2008-07-01 00:03:41 +02:00
|
|
|
O << ')';
|
2004-08-17 01:15:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unsupported operator!");
|
2004-08-17 01:15:22 +02:00
|
|
|
}
|
|
|
|
} else {
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unknown constant value!");
|
2004-08-17 01:15:22 +02:00
|
|
|
}
|
|
|
|
}
|
2004-08-17 08:36:49 +02:00
|
|
|
|
2005-11-10 19:06:33 +01:00
|
|
|
/// printAsCString - Print the specified array as a C compatible string, only if
|
2004-08-17 08:36:49 +02:00
|
|
|
/// the predicate isString is true.
|
|
|
|
///
|
2009-07-14 22:18:05 +02:00
|
|
|
static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
|
2005-11-10 19:06:33 +01:00
|
|
|
unsigned LastElt) {
|
2004-08-17 08:36:49 +02:00
|
|
|
assert(CVA->isString() && "Array is not string compatible!");
|
|
|
|
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\"';
|
2005-11-10 19:06:33 +01:00
|
|
|
for (unsigned i = 0; i != LastElt; ++i) {
|
2005-04-22 00:36:52 +02:00
|
|
|
unsigned char C =
|
2006-10-20 09:07:24 +02:00
|
|
|
(unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
|
2007-01-25 16:12:02 +01:00
|
|
|
printStringChar(O, C);
|
2004-08-17 08:36:49 +02:00
|
|
|
}
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\"';
|
2004-08-17 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
2006-05-02 03:16:28 +02:00
|
|
|
/// EmitString - Emit a zero-byte-terminated string constant.
|
|
|
|
///
|
|
|
|
void AsmPrinter::EmitString(const ConstantArray *CVA) const {
|
|
|
|
unsigned NumElts = CVA->getNumOperands();
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getAscizDirective() && NumElts &&
|
2006-10-20 09:07:24 +02:00
|
|
|
cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getAscizDirective();
|
2006-05-02 03:16:28 +02:00
|
|
|
printAsCString(O, CVA, NumElts-1);
|
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getAsciiDirective();
|
2006-05-02 03:16:28 +02:00
|
|
|
printAsCString(O, CVA, NumElts);
|
|
|
|
}
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n';
|
2006-05-02 03:16:28 +02:00
|
|
|
}
|
|
|
|
|
2009-04-28 18:34:20 +02:00
|
|
|
void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 22:14:27 +01: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 18:34:20 +02:00
|
|
|
EmitGlobalConstant(CVA->getOperand(i), AddrSpace);
|
2008-12-22 22:14:27 +01: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 05:25:10 +01:00
|
|
|
void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 22:14:27 +01:00
|
|
|
// Print the fields in successive locations. Pad to align if needed!
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-05-09 09:06:46 +02:00
|
|
|
unsigned Size = TD->getTypeAllocSize(CVS->getType());
|
2008-12-22 22:14:27 +01: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 09:06:46 +02:00
|
|
|
uint64_t fieldSize = TD->getTypeAllocSize(field->getType());
|
2008-12-22 22:14:27 +01: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 05:25:10 +01:00
|
|
|
EmitGlobalConstant(field, AddrSpace);
|
2008-12-22 22:14:27 +01: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 05:25:10 +01:00
|
|
|
EmitZeros(padSize, AddrSpace);
|
2008-12-22 22:14:27 +01:00
|
|
|
}
|
|
|
|
assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
|
|
|
|
"Layout of constant struct may be incorrect!");
|
|
|
|
}
|
|
|
|
|
2009-01-30 05:25:10 +01:00
|
|
|
void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 22:14:27 +01:00
|
|
|
// FP Constants are printed as integer constants to avoid losing
|
|
|
|
// precision...
|
2009-08-13 23:58:54 +02:00
|
|
|
LLVMContext &Context = CFP->getContext();
|
2008-12-22 22:14:27 +01:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-08-13 23:58:54 +02:00
|
|
|
if (CFP->getType() == Type::getDoubleTy(Context)) {
|
2008-12-22 22:14:27 +01:00
|
|
|
double Val = CFP->getValueAPF().convertToDouble(); // for comment only
|
|
|
|
uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->getData64bitsDirective(AddrSpace)) {
|
|
|
|
O << MAI->getData64bitsDirective(AddrSpace) << i;
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " double " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
|
|
|
} else if (TD->isBigEndian()) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant word of double " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant word of double " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant word of double " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant word of double " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
}
|
|
|
|
return;
|
2009-08-13 23:58:54 +02:00
|
|
|
} else if (CFP->getType() == Type::getFloatTy(Context)) {
|
2008-12-22 22:14:27 +01:00
|
|
|
float Val = CFP->getValueAPF().convertToFloat(); // for comment only
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace)
|
2009-03-24 01:17:40 +01:00
|
|
|
<< CFP->getValueAPF().bitcastToAPInt().getZExtValue();
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " float " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
return;
|
2009-08-13 23:58:54 +02:00
|
|
|
} else if (CFP->getType() == Type::getX86_FP80Ty(Context)) {
|
2008-12-22 22:14:27 +01: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 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant halfword of x86_fp80 ~"
|
2009-03-24 01:17:40 +01:00
|
|
|
<< DoubleVal.convertToDouble();
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " next halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " next halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " next halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant halfword of x86_fp80 ~"
|
2009-03-24 01:17:40 +01:00
|
|
|
<< DoubleVal.convertToDouble();
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant halfword";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
}
|
2009-08-13 23:58:54 +02:00
|
|
|
EmitZeros(TD->getTypeAllocSize(Type::getX86_FP80Ty(Context)) -
|
|
|
|
TD->getTypeStoreSize(Type::getX86_FP80Ty(Context)), AddrSpace);
|
2008-12-22 22:14:27 +01:00
|
|
|
return;
|
2009-08-13 23:58:54 +02:00
|
|
|
} else if (CFP->getType() == Type::getPPC_FP128Ty(Context)) {
|
2008-12-22 22:14:27 +01: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 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant word of ppc_fp128";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next word";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next word";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant word";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant word of ppc_fp128";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next word";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " next word";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant word";
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
}
|
|
|
|
return;
|
2009-07-14 18:55:14 +02:00
|
|
|
} else llvm_unreachable("Floating point constant type not handled");
|
2008-12-22 22:14:27 +01:00
|
|
|
}
|
|
|
|
|
2009-01-30 05:25:10 +01:00
|
|
|
void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
|
|
|
|
unsigned AddrSpace) {
|
2008-12-22 22:14:27 +01: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 23:43:10 +02:00
|
|
|
if (MAI->getData64bitsDirective(AddrSpace))
|
|
|
|
O << MAI->getData64bitsDirective(AddrSpace) << Val << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
else if (TD->isBigEndian()) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant half of i64 " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant half of i64 " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " least significant half of i64 " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString()
|
2009-08-13 03:36:44 +02:00
|
|
|
<< " most significant half of i64 " << Val;
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2009-03-24 01:17:40 +01:00
|
|
|
O << '\n';
|
2008-12-22 22:14:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-21 08:51:36 +01:00
|
|
|
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
|
2009-01-30 05:25:10 +01:00
|
|
|
void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
|
2006-05-03 03:29:57 +02:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2008-12-22 22:14:27 +01:00
|
|
|
const Type *type = CV->getType();
|
2009-05-09 09:06:46 +02:00
|
|
|
unsigned Size = TD->getTypeAllocSize(type);
|
2004-08-17 08:36:49 +02:00
|
|
|
|
2004-10-16 20:19:26 +02:00
|
|
|
if (CV->isNullValue() || isa<UndefValue>(CV)) {
|
2009-01-30 05:25:10 +01:00
|
|
|
EmitZeros(Size, AddrSpace);
|
2004-08-17 08:36:49 +02:00
|
|
|
return;
|
|
|
|
} else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
|
2009-04-28 18:34:20 +02:00
|
|
|
EmitGlobalConstantArray(CVA , AddrSpace);
|
2004-08-17 08:36:49 +02:00
|
|
|
return;
|
|
|
|
} else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
|
2009-01-30 05:25:10 +01:00
|
|
|
EmitGlobalConstantStruct(CVS, AddrSpace);
|
2004-08-17 08:36:49 +02:00
|
|
|
return;
|
|
|
|
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
|
2009-01-30 05:25:10 +01:00
|
|
|
EmitGlobalConstantFP(CFP, AddrSpace);
|
2008-12-22 22:14:27 +01: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 05:25:10 +01:00
|
|
|
EmitGlobalConstantLargeInt(CI, AddrSpace);
|
2004-08-17 08:36:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-02-15 03:26:10 +01:00
|
|
|
} else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
|
2008-12-22 22:14:27 +01: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
}
llvm-svn: 24616
2005-12-06 07:18:55 +01:00
|
|
|
return;
|
2004-08-17 08:36:49 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 05:25:10 +01:00
|
|
|
printDataDirective(type, AddrSpace);
|
2005-11-21 08:51:36 +01:00
|
|
|
EmitConstantValueOnly(CV);
|
2009-03-24 01:17:40 +01:00
|
|
|
if (VerboseAsm) {
|
|
|
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
|
|
|
SmallString<40> S;
|
|
|
|
CI->getValue().toStringUnsigned(S, 16);
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " 0x" << S.str();
|
2009-03-24 01:17:40 +01:00
|
|
|
}
|
2008-06-03 17:39:51 +02:00
|
|
|
}
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n';
|
2004-08-17 08:36:49 +02:00
|
|
|
}
|
2006-01-27 03:10:10 +01:00
|
|
|
|
2008-08-17 09:19:36 +02:00
|
|
|
void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
2006-09-12 23:00:35 +02:00
|
|
|
// Target doesn't support this yet!
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
|
2006-09-12 23:00:35 +02:00
|
|
|
}
|
|
|
|
|
2006-09-27 01:59:50 +02: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 06:37:13 +01:00
|
|
|
void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
|
2006-09-27 02:06:07 +02:00
|
|
|
if (!strcmp(Code, "private")) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getPrivateGlobalPrefix();
|
2006-09-27 02:06:07 +02:00
|
|
|
} else if (!strcmp(Code, "comment")) {
|
2009-03-24 01:17:40 +01:00
|
|
|
if (VerboseAsm)
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString();
|
2006-09-27 01:59:50 +02:00
|
|
|
} else if (!strcmp(Code, "uid")) {
|
2007-02-05 22:23:52 +01:00
|
|
|
// Comparing the address of MI isn't sufficient, because machineinstrs may
|
|
|
|
// be allocated to the same address across functions.
|
|
|
|
const Function *ThisF = MI->getParent()->getParent()->getFunction();
|
|
|
|
|
2009-06-25 00:28:12 +02:00
|
|
|
// If this is a new LastFn instruction, bump the counter.
|
|
|
|
if (LastMI != MI || LastFn != ThisF) {
|
2007-02-05 22:23:52 +01:00
|
|
|
++Counter;
|
|
|
|
LastMI = MI;
|
2009-06-25 00:28:12 +02:00
|
|
|
LastFn = ThisF;
|
2007-02-05 22:23:52 +01:00
|
|
|
}
|
2006-09-27 01:59:50 +02:00
|
|
|
O << Counter;
|
|
|
|
} else {
|
2009-07-11 15:10:19 +02:00
|
|
|
std::string msg;
|
|
|
|
raw_string_ostream Msg(msg);
|
|
|
|
Msg << "Unknown special formatter '" << Code
|
2006-12-07 02:30:32 +01:00
|
|
|
<< "' for machine instr: " << *MI;
|
2009-07-11 15:10:19 +02:00
|
|
|
llvm_report_error(Msg.str());
|
2006-09-27 01:59:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 15:55:51 +02:00
|
|
|
/// processDebugLoc - Processes the debug information of each machine
|
|
|
|
/// instruction's DebugLoc.
|
|
|
|
void AsmPrinter::processDebugLoc(DebugLoc DL) {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (!MAI || !DW)
|
2009-08-05 06:09:18 +02:00
|
|
|
return;
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
if (MAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) {
|
2009-05-07 15:55:51 +02:00
|
|
|
if (!DL.isUnknown()) {
|
|
|
|
DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
|
|
|
|
|
|
|
|
if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT)
|
|
|
|
printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
|
|
|
|
DICompileUnit(CurDLT.CompileUnit)));
|
|
|
|
|
|
|
|
PrevDLT = CurDLT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-27 01:59:50 +02:00
|
|
|
|
2006-01-27 03:10:10 +01:00
|
|
|
/// printInlineAsm - This method formats and prints the specified machine
|
|
|
|
/// instruction that is an inline asm.
|
|
|
|
void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
|
2006-01-31 00:00:08 +01:00
|
|
|
unsigned NumOperands = MI->getNumOperands();
|
|
|
|
|
|
|
|
// Count the number of register definitions.
|
|
|
|
unsigned NumDefs = 0;
|
2008-10-03 17:45:36 +02:00
|
|
|
for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
|
2006-09-05 22:02:51 +02:00
|
|
|
++NumDefs)
|
2006-01-31 00:00:08 +01:00
|
|
|
assert(NumDefs != NumOperands-1 && "No asm string?");
|
|
|
|
|
2008-10-03 17:45:36 +02:00
|
|
|
assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
|
|
|
|
// Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
|
2006-01-31 00:00:08 +01:00
|
|
|
const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
|
2008-01-29 03:21:21 +01: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 02:17:20 +02:00
|
|
|
if (AsmStr[0] == 0) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
|
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
|
2006-07-28 02:17:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString() << MAI->getInlineAsmStart() << "\n\t";
|
2006-07-28 02:17:20 +02:00
|
|
|
|
2007-01-16 04:42:04 +01:00
|
|
|
// The variant of the current asmprinter.
|
2009-08-22 23:43:10 +02:00
|
|
|
int AsmPrinterVariant = MAI->getAssemblerDialect();
|
2007-01-16 04:42:04 +01:00
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01: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 02:28:23 +01:00
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01: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 23:47:05 +02:00
|
|
|
*LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
++LiteralEnd;
|
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
|
|
|
|
O.write(LastEmitted, LiteralEnd-LastEmitted);
|
|
|
|
LastEmitted = LiteralEnd;
|
|
|
|
break;
|
|
|
|
}
|
2006-05-05 23:47:05 +02:00
|
|
|
case '\n':
|
|
|
|
++LastEmitted; // Consume newline character.
|
2008-07-01 00:03:41 +02:00
|
|
|
O << '\n'; // Indent code with newline.
|
2006-05-05 23:47:05 +02:00
|
|
|
break;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
case '$': {
|
|
|
|
++LastEmitted; // Consume '$' character.
|
2006-10-04 01:27:09 +02:00
|
|
|
bool Done = true;
|
|
|
|
|
|
|
|
// Handle escapes.
|
|
|
|
switch (*LastEmitted) {
|
|
|
|
default: Done = false; break;
|
|
|
|
case '$': // $$ -> $
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
|
|
|
|
O << '$';
|
|
|
|
++LastEmitted; // Consume second '$' character.
|
|
|
|
break;
|
2006-10-04 01:27:09 +02:00
|
|
|
case '(': // $( -> same as GCC's { character.
|
|
|
|
++LastEmitted; // Consume '(' character.
|
|
|
|
if (CurVariant != -1) {
|
2009-07-11 15:10:19 +02:00
|
|
|
llvm_report_error("Nested variants found in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2006-10-04 01:27:09 +02:00
|
|
|
}
|
|
|
|
CurVariant = 0; // We're in the first variant now.
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
++LastEmitted; // consume '|' character.
|
2008-10-10 23:04:42 +02:00
|
|
|
if (CurVariant == -1)
|
|
|
|
O << '|'; // this is gcc's behavior for | outside a variant
|
|
|
|
else
|
|
|
|
++CurVariant; // We're in the next variant.
|
2006-10-04 01:27:09 +02:00
|
|
|
break;
|
|
|
|
case ')': // $) -> same as GCC's } char.
|
|
|
|
++LastEmitted; // consume ')' character.
|
2008-10-10 23:04:42 +02:00
|
|
|
if (CurVariant == -1)
|
|
|
|
O << '}'; // this is gcc's behavior for } outside a variant
|
|
|
|
else
|
|
|
|
CurVariant = -1;
|
2006-10-04 01:27:09 +02:00
|
|
|
break;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
}
|
2006-10-04 01:27:09 +02:00
|
|
|
if (Done) break;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
|
|
|
|
bool HasCurlyBraces = false;
|
|
|
|
if (*LastEmitted == '{') { // ${variable}
|
|
|
|
++LastEmitted; // Consume '{' character.
|
|
|
|
HasCurlyBraces = true;
|
|
|
|
}
|
|
|
|
|
2009-03-10 06:37:13 +01: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 15:10:19 +02:00
|
|
|
llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2009-03-10 06:37:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Val(StrStart, StrEnd);
|
|
|
|
PrintSpecial(MI, Val.c_str());
|
|
|
|
LastEmitted = StrEnd+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
const char *IDStart = LastEmitted;
|
|
|
|
char *IDEnd;
|
2007-01-23 01:36:17 +01:00
|
|
|
errno = 0;
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
|
|
|
|
if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
|
2009-07-11 15:10:19 +02:00
|
|
|
llvm_report_error("Bad $ operand number in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
}
|
|
|
|
LastEmitted = IDEnd;
|
|
|
|
|
2006-02-06 23:17:23 +01:00
|
|
|
char Modifier[2] = { 0, 0 };
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
if (HasCurlyBraces) {
|
2006-02-06 23:17:23 +01: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 15:10:19 +02:00
|
|
|
llvm_report_error("Bad ${:} expression in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
2006-02-06 23:17:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Modifier[0] = *LastEmitted;
|
|
|
|
++LastEmitted; // Consume modifier character.
|
|
|
|
}
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
if (*LastEmitted != '}') {
|
2009-07-11 15:10:19 +02:00
|
|
|
llvm_report_error("Bad ${} expression in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
}
|
|
|
|
++LastEmitted; // Consume '}' character.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unsigned)Val >= NumOperands-1) {
|
2009-07-11 15:10:19 +02:00
|
|
|
llvm_report_error("Invalid $ operand number in inline asm string: '"
|
|
|
|
+ std::string(AsmStr) + "'");
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
2006-02-23 20:21:04 +01:00
|
|
|
// Okay, we finally have a value number. Ask the target to print this
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
// operand!
|
2006-02-23 20:21:04 +01:00
|
|
|
if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
|
|
|
|
unsigned OpNo = 1;
|
2006-06-08 20:00:47 +02:00
|
|
|
|
|
|
|
bool Error = false;
|
|
|
|
|
2006-02-23 20:21:04 +01:00
|
|
|
// Scan to find the machine operand number for the operand.
|
2006-02-24 20:50:58 +01:00
|
|
|
for (; Val; --Val) {
|
2006-06-08 20:00:47 +02:00
|
|
|
if (OpNo >= MI->getNumOperands()) break;
|
2007-12-30 21:50:28 +01:00
|
|
|
unsigned OpFlags = MI->getOperand(OpNo).getImm();
|
2009-03-20 19:03:34 +01:00
|
|
|
OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
|
2006-02-24 20:50:58 +01:00
|
|
|
}
|
2006-06-08 20:00:47 +02:00
|
|
|
|
|
|
|
if (OpNo >= MI->getNumOperands()) {
|
|
|
|
Error = true;
|
2006-02-24 21:21:58 +01:00
|
|
|
} else {
|
2007-12-30 21:50:28 +01:00
|
|
|
unsigned OpFlags = MI->getOperand(OpNo).getImm();
|
2006-06-08 20:00:47 +02:00
|
|
|
++OpNo; // Skip over the ID number.
|
|
|
|
|
2007-11-05 22:20:28 +01:00
|
|
|
if (Modifier[0]=='l') // labels are target independent
|
2007-12-31 00:10:15 +01:00
|
|
|
printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
|
2008-02-28 01:43:03 +01:00
|
|
|
false, false, false);
|
2007-11-05 22:20:28 +01:00
|
|
|
else {
|
|
|
|
AsmPrinter *AP = const_cast<AsmPrinter*>(this);
|
2008-09-24 03:07:17 +02:00
|
|
|
if ((OpFlags & 7) == 4) {
|
2007-11-05 22:20:28 +01: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 20:00:47 +02:00
|
|
|
}
|
2006-02-24 21:21:58 +01:00
|
|
|
}
|
|
|
|
if (Error) {
|
2009-07-11 15:10:19 +02:00
|
|
|
std::string msg;
|
|
|
|
raw_string_ostream Msg(msg);
|
|
|
|
Msg << "Invalid operand found in inline asm: '"
|
2006-12-07 02:30:32 +01:00
|
|
|
<< AsmStr << "'\n";
|
2009-07-11 15:10:19 +02:00
|
|
|
MI->print(Msg);
|
|
|
|
llvm_report_error(Msg.str());
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
}
|
2006-02-23 20:21:04 +01:00
|
|
|
}
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-22 23:43:10 +02:00
|
|
|
O << "\n\t" << MAI->getCommentString() << MAI->getInlineAsmEnd() << '\n';
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
}
|
|
|
|
|
2008-03-15 01:03:38 +01:00
|
|
|
/// printImplicitDef - This method prints the specified machine instruction
|
|
|
|
/// that is an implicit def.
|
|
|
|
void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
|
2009-08-12 20:32:22 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " implicit-def: "
|
2009-03-24 01:17:40 +01:00
|
|
|
<< TRI->getAsmName(MI->getOperand(0).getReg()) << '\n';
|
2009-08-12 20:32:22 +02:00
|
|
|
}
|
2008-03-15 01:03:38 +01:00
|
|
|
}
|
|
|
|
|
2007-01-26 15:34:52 +01: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 02:16:26 +02:00
|
|
|
printLabel(MI->getOperand(0).getImm());
|
2007-01-26 15:34:52 +01:00
|
|
|
}
|
|
|
|
|
2008-02-01 10:10:45 +01:00
|
|
|
void AsmPrinter::printLabel(unsigned Id) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
|
2008-02-01 10:10:45 +01:00
|
|
|
}
|
|
|
|
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01: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 23:17:23 +01:00
|
|
|
unsigned AsmVariant, const char *ExtraCode) {
|
Implement smart printing of inline asm strings, handling variants and
substituted operands. For this testcase:
int %test(int %A, int %B) {
%C = call int asm "xyz $0, $1, $2", "=r,r,r"(int %A, int %B)
ret int %C
}
we now emit:
_test:
or r2, r3, r3
or r3, r4, r4
xyz r2, r2, r3 ;; look here
or r3, r2, r2
blr
... note the substituted operands. :)
llvm-svn: 25886
2006-02-01 23:41:11 +01:00
|
|
|
// Target doesn't support this yet!
|
|
|
|
return true;
|
2006-01-27 03:10:10 +01:00
|
|
|
}
|
2006-02-24 21:21:58 +01: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 20:53:45 +02:00
|
|
|
|
|
|
|
/// printBasicBlockLabel - This method prints the label for the specified
|
|
|
|
/// MachineBasicBlock
|
2006-05-02 07:37:32 +02:00
|
|
|
void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
|
2008-02-28 01:43:03 +01:00
|
|
|
bool printAlign,
|
2006-05-02 07:37:32 +02:00
|
|
|
bool printColon,
|
|
|
|
bool printComment) const {
|
2008-02-28 01:43:03 +01:00
|
|
|
if (printAlign) {
|
|
|
|
unsigned Align = MBB->getAlignment();
|
|
|
|
if (Align)
|
|
|
|
EmitAlignment(Log2_32(Align));
|
|
|
|
}
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << '_'
|
2007-10-14 07:57:21 +02:00
|
|
|
<< MBB->getNumber();
|
2006-05-02 07:37:32 +02:00
|
|
|
if (printColon)
|
|
|
|
O << ':';
|
2009-08-10 18:38:07 +02:00
|
|
|
if (printComment) {
|
2009-08-12 20:47:05 +02:00
|
|
|
if (const BasicBlock *BB = MBB->getBasicBlock())
|
|
|
|
if (BB->hasName()) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << ' ';
|
2009-08-12 22:56:56 +02:00
|
|
|
WriteAsOperand(O, BB, /*PrintType=*/false);
|
2009-08-12 20:47:05 +02:00
|
|
|
}
|
2009-08-10 18:38:07 +02:00
|
|
|
|
|
|
|
if (printColon)
|
|
|
|
EmitComments(*MBB);
|
|
|
|
}
|
2006-04-22 20:53:45 +02:00
|
|
|
}
|
2006-08-12 23:29:52 +02:00
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
llvm-svn: 43924
2007-11-09 02:32:10 +01: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 23:43:10 +02:00
|
|
|
if (!MAI->getSetDirective())
|
2006-08-12 23:29:52 +02:00
|
|
|
return;
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
|
2007-10-14 07:57:21 +02:00
|
|
|
<< getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
|
2008-02-28 01:43:03 +01:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2009-08-22 23:43:10 +02:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 07:57:21 +02:00
|
|
|
<< '_' << uid << '\n';
|
2006-08-12 23:29:52 +02:00
|
|
|
}
|
2006-09-12 23:00:35 +02:00
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
llvm-svn: 43924
2007-11-09 02:32:10 +01:00
|
|
|
void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
|
|
|
|
const MachineBasicBlock *MBB) const {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (!MAI->getSetDirective())
|
2006-11-01 10:23:08 +01:00
|
|
|
return;
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getSetDirective() << ' ' << MAI->getPrivateGlobalPrefix()
|
2007-10-14 07:57:21 +02:00
|
|
|
<< getFunctionNumber() << '_' << uid << '_' << uid2
|
|
|
|
<< "_set_" << MBB->getNumber() << ',';
|
2008-02-28 01:43:03 +01:00
|
|
|
printBasicBlockLabel(MBB, false, false, false);
|
2009-08-22 23:43:10 +02:00
|
|
|
O << '-' << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
|
2007-10-14 07:57:21 +02:00
|
|
|
<< '_' << uid << '_' << uid2 << '\n';
|
2006-11-01 10:23:08 +01:00
|
|
|
}
|
|
|
|
|
2006-09-12 23:00:35 +02:00
|
|
|
/// printDataDirective - This method prints the asm directive for the
|
|
|
|
/// specified type.
|
2009-01-30 05:25:10 +01:00
|
|
|
void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
|
2006-09-12 23:00:35 +02:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
switch (type->getTypeID()) {
|
2009-07-15 06:42:49 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
case Type::IntegerTyID: {
|
|
|
|
unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
|
|
|
|
if (BitWidth <= 8)
|
2009-08-22 23:43:10 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
else if (BitWidth <= 16)
|
2009-08-22 23:43:10 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
else if (BitWidth <= 32)
|
2009-08-22 23:43:10 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
else if (BitWidth <= 64) {
|
2009-08-22 23:43:10 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
"Target cannot handle 64-bit constant exprs!");
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData64bitsDirective(AddrSpace);
|
2008-09-08 18:40:13 +02:00
|
|
|
} else {
|
2009-07-14 18:55:14 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
}
|
2006-09-12 23:00:35 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
}
|
2006-09-12 23:00:35 +02:00
|
|
|
case Type::PointerTyID:
|
|
|
|
if (TD->getPointerSize() == 8) {
|
2009-08-22 23:43:10 +02:00
|
|
|
assert(MAI->getData64bitsDirective(AddrSpace) &&
|
2006-09-12 23:00:35 +02:00
|
|
|
"Target cannot handle 64-bit pointer exprs!");
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData64bitsDirective(AddrSpace);
|
2009-01-22 11:14:21 +01:00
|
|
|
} else if (TD->getPointerSize() == 2) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData16bitsDirective(AddrSpace);
|
2009-01-22 11:14:21 +01:00
|
|
|
} else if (TD->getPointerSize() == 1) {
|
2009-08-22 23:43:10 +02: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.
llvm-svn: 33113
2007-01-12 08:05:14 +01:00
|
|
|
} else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getData32bitsDirective(AddrSpace);
|
2006-09-12 23:00:35 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-02-16 02:54:53 +01:00
|
|
|
|
2008-08-08 20:25:07 +02:00
|
|
|
void AsmPrinter::printVisibility(const std::string& Name,
|
|
|
|
unsigned Visibility) const {
|
|
|
|
if (Visibility == GlobalValue::HiddenVisibility) {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (const char *Directive = MAI->getHiddenDirective())
|
2008-08-08 20:25:07 +02:00
|
|
|
O << Directive << Name << '\n';
|
|
|
|
} else if (Visibility == GlobalValue::ProtectedVisibility) {
|
2009-08-22 23:43:10 +02:00
|
|
|
if (const char *Directive = MAI->getProtectedDirective())
|
2008-08-08 20:25:07 +02:00
|
|
|
O << Directive << Name << '\n';
|
|
|
|
}
|
|
|
|
}
|
2008-08-17 14:08:44 +02:00
|
|
|
|
2008-11-22 17:15:34 +01:00
|
|
|
void AsmPrinter::printOffset(int64_t Offset) const {
|
|
|
|
if (Offset > 0)
|
|
|
|
O << '+' << Offset;
|
|
|
|
else if (Offset < 0)
|
|
|
|
O << Offset;
|
|
|
|
}
|
|
|
|
|
2009-08-14 05:43:57 +02:00
|
|
|
void AsmPrinter::printMCInst(const MCInst *MI) {
|
|
|
|
llvm_unreachable("MCInst printing unavailable on this target!");
|
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
|
|
|
|
if (!S->usesMetadata())
|
2008-08-17 14:08:44 +02:00
|
|
|
return 0;
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
gcp_iterator GCPI = GCMetadataPrinters.find(S);
|
2008-08-17 14:08:44 +02:00
|
|
|
if (GCPI != GCMetadataPrinters.end())
|
|
|
|
return GCPI->second;
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
const char *Name = S->getName().c_str();
|
2008-08-17 14:08:44 +02:00
|
|
|
|
|
|
|
for (GCMetadataPrinterRegistry::iterator
|
|
|
|
I = GCMetadataPrinterRegistry::begin(),
|
|
|
|
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
|
|
|
|
if (strcmp(Name, I->getName()) == 0) {
|
2008-08-17 20:44:35 +02:00
|
|
|
GCMetadataPrinter *GMP = I->instantiate();
|
|
|
|
GMP->S = S;
|
|
|
|
GCMetadataPrinters.insert(std::make_pair(S, GMP));
|
|
|
|
return GMP;
|
2008-08-17 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
2008-08-17 20:44:35 +02:00
|
|
|
cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable(0);
|
2008-08-17 14:08:44 +02:00
|
|
|
}
|
2009-07-13 22:25:48 +02:00
|
|
|
|
|
|
|
/// EmitComments - Pretty-print comments for instructions
|
2009-08-08 01:42:01 +02:00
|
|
|
void AsmPrinter::EmitComments(const MachineInstr &MI) const {
|
|
|
|
if (!VerboseAsm ||
|
|
|
|
MI.getDebugLoc().isUnknown())
|
|
|
|
return;
|
|
|
|
|
|
|
|
DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
|
|
|
|
|
2009-08-17 17:48:08 +02:00
|
|
|
// Print source line info.
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " SrcLine ";
|
2009-08-08 01:42:01 +02:00
|
|
|
if (DLT.CompileUnit->hasInitializer()) {
|
|
|
|
Constant *Name = DLT.CompileUnit->getInitializer();
|
|
|
|
if (ConstantArray *NameString = dyn_cast<ConstantArray>(Name))
|
|
|
|
if (NameString->isString())
|
|
|
|
O << NameString->getAsString() << " ";
|
2009-07-17 00:24:20 +02:00
|
|
|
}
|
2009-08-08 01:42:01 +02:00
|
|
|
O << DLT.Line;
|
|
|
|
if (DLT.Col != 0)
|
|
|
|
O << ":" << DLT.Col;
|
2009-07-13 22:25:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitComments - Pretty-print comments for instructions
|
2009-08-23 02:51:47 +02:00
|
|
|
void AsmPrinter::EmitComments(const MCInst &MI) const {
|
|
|
|
if (!VerboseAsm ||
|
|
|
|
MI.getDebugLoc().isUnknown())
|
|
|
|
return;
|
|
|
|
|
|
|
|
DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
|
2009-07-22 22:33:26 +02:00
|
|
|
|
2009-08-23 02:51:47 +02:00
|
|
|
// Print source line info
|
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " SrcLine ";
|
|
|
|
if (DLT.CompileUnit->hasInitializer()) {
|
|
|
|
Constant *Name = DLT.CompileUnit->getInitializer();
|
|
|
|
if (ConstantArray *NameString = dyn_cast<ConstantArray>(Name))
|
|
|
|
if (NameString->isString())
|
|
|
|
O << NameString->getAsString() << " ";
|
2009-07-17 00:24:20 +02:00
|
|
|
}
|
2009-08-23 02:51:47 +02:00
|
|
|
O << DLT.Line;
|
|
|
|
if (DLT.Col != 0)
|
|
|
|
O << ":" << DLT.Col;
|
2009-07-13 22:25:48 +02:00
|
|
|
}
|
2009-08-10 18:38:07 +02:00
|
|
|
|
2009-08-18 21:22:55 +02: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 23:43:10 +02:00
|
|
|
const MCAsmInfo *MAI,
|
2009-08-18 21:22:55 +02: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 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-08-18 21:22:55 +02:00
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString();
|
2009-08-23 02:51:00 +02:00
|
|
|
O.indent(((*cl)->getLoopDepth()-1)*2)
|
2009-08-18 21:22:55 +02:00
|
|
|
<< " Child Loop BB" << FunctionNumber << "_"
|
|
|
|
<< Header->getNumber() << " Depth " << (*cl)->getLoopDepth();
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
PrintChildLoopComment(O, *cl, MAI, FunctionNumber);
|
2009-08-18 21:22:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-10 18:38:07 +02:00
|
|
|
/// EmitComments - Pretty-print comments for basic blocks
|
|
|
|
void AsmPrinter::EmitComments(const MachineBasicBlock &MBB) const
|
|
|
|
{
|
2009-08-18 21:22:55 +02:00
|
|
|
if (VerboseAsm) {
|
2009-08-10 18:38:07 +02:00
|
|
|
// Add loop depth information
|
|
|
|
const MachineLoop *loop = LI->getLoopFor(&MBB);
|
|
|
|
|
|
|
|
if (loop) {
|
|
|
|
// Print a newline after bb# annotation.
|
|
|
|
O << "\n";
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Loop Depth " << loop->getLoopDepth()
|
2009-08-10 18:38:07 +02:00
|
|
|
<< '\n';
|
|
|
|
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
2009-08-10 18:38:07 +02:00
|
|
|
|
|
|
|
MachineBasicBlock *Header = loop->getHeader();
|
|
|
|
assert(Header && "No header for loop");
|
|
|
|
|
|
|
|
if (Header == &MBB) {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString() << " Loop Header";
|
|
|
|
PrintChildLoopComment(O, loop, MAI, getFunctionNumber());
|
2009-08-10 18:38:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-08-22 23:43:10 +02:00
|
|
|
O << MAI->getCommentString() << " Loop Header is BB"
|
2009-08-10 18:38:07 +02:00
|
|
|
<< getFunctionNumber() << "_" << loop->getHeader()->getNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loop->empty()) {
|
|
|
|
O << '\n';
|
2009-08-22 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString() << " Inner Loop";
|
2009-08-10 18:38:07 +02: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 23:43:10 +02:00
|
|
|
O.PadToColumn(MAI->getCommentColumn());
|
|
|
|
O << MAI->getCommentString();
|
2009-08-23 02:51:00 +02:00
|
|
|
O.indent((CurLoop->getLoopDepth()-1)*2)
|
2009-08-18 21:22:55 +02:00
|
|
|
<< " Inside Loop BB" << getFunctionNumber() << "_"
|
2009-08-10 18:38:07 +02:00
|
|
|
<< Header->getNumber() << " Depth " << CurLoop->getLoopDepth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|