2004-08-16 23:15:22 +00:00
|
|
|
//===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2004-08-16 23:15:22 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:39:54 +00:00
|
|
|
//
|
2004-08-16 23:15:22 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-09-06 18:34:40 +00:00
|
|
|
// This file contains a class to be used as the base class for target specific
|
|
|
|
// asm writers. This class primarily handles common functionality used by
|
|
|
|
// all asm writers.
|
2004-08-16 23:15:22 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_ASMPRINTER_H
|
|
|
|
#define LLVM_CODEGEN_ASMPRINTER_H
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2005-01-08 19:57:49 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2006-12-18 03:37:18 +00:00
|
|
|
#include <set>
|
2004-08-16 23:15:22 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Constant;
|
2006-05-02 01:16:28 +00:00
|
|
|
class ConstantArray;
|
2005-12-13 06:32:10 +00:00
|
|
|
class GlobalVariable;
|
2007-04-25 14:27:10 +00:00
|
|
|
class GlobalAlias;
|
2006-06-29 00:26:09 +00:00
|
|
|
class MachineConstantPoolEntry;
|
2006-09-12 21:00:35 +00:00
|
|
|
class MachineConstantPoolValue;
|
2006-09-06 18:34:40 +00:00
|
|
|
class Mangler;
|
|
|
|
class TargetAsmInfo;
|
2007-12-31 04:13:23 +00:00
|
|
|
class Type;
|
2004-08-16 23:15:22 +00:00
|
|
|
|
2006-09-06 18:34:40 +00:00
|
|
|
/// AsmPrinter - This class is intended to be used as a driving class for all
|
|
|
|
/// asm writers.
|
2004-08-16 23:15:22 +00:00
|
|
|
class AsmPrinter : public MachineFunctionPass {
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2007-10-14 05:57:21 +00:00
|
|
|
/// FunctionNumber - This provides a unique ID for each function emitted in
|
|
|
|
/// this translation unit. It is autoincremented by SetupMachineFunction,
|
|
|
|
/// and can be accessed with getFunctionNumber() and
|
|
|
|
/// IncrementFunctionNumber().
|
|
|
|
///
|
|
|
|
unsigned FunctionNumber;
|
|
|
|
|
2006-12-18 03:37:18 +00:00
|
|
|
protected:
|
|
|
|
// Necessary for external weak linkage support
|
|
|
|
std::set<const GlobalValue*> ExtWeakSymbols;
|
|
|
|
|
2006-01-04 22:28:25 +00:00
|
|
|
public:
|
2004-08-16 23:15:22 +00:00
|
|
|
/// Output stream on which we're printing assembly code.
|
|
|
|
///
|
|
|
|
std::ostream &O;
|
|
|
|
|
|
|
|
/// Target machine description.
|
|
|
|
///
|
|
|
|
TargetMachine &TM;
|
2006-09-06 18:34:40 +00:00
|
|
|
|
|
|
|
/// Target Asm Printer information.
|
|
|
|
///
|
2006-09-07 22:06:40 +00:00
|
|
|
const TargetAsmInfo *TAI;
|
2004-08-16 23:15:22 +00:00
|
|
|
|
|
|
|
/// Name-mangler for global names.
|
|
|
|
///
|
|
|
|
Mangler *Mang;
|
|
|
|
|
|
|
|
/// Cache of mangled name for current function. This is recalculated at the
|
|
|
|
/// beginning of each call to runOnMachineFunction().
|
|
|
|
///
|
|
|
|
std::string CurrentFnName;
|
2005-11-21 08:24:11 +00:00
|
|
|
|
2006-06-23 12:51:53 +00:00
|
|
|
/// CurrentSection - The current section we are emitting to. This is
|
|
|
|
/// controlled and used by the SwitchSection method.
|
|
|
|
std::string CurrentSection;
|
2006-01-04 22:28:25 +00:00
|
|
|
|
|
|
|
protected:
|
2006-09-07 22:06:40 +00:00
|
|
|
AsmPrinter(std::ostream &o, TargetMachine &TM, const TargetAsmInfo *T);
|
2005-12-13 06:32:10 +00:00
|
|
|
|
2006-01-04 13:52:30 +00:00
|
|
|
public:
|
2006-05-09 04:59:30 +00:00
|
|
|
/// SwitchToTextSection - Switch to the specified section of the executable
|
|
|
|
/// if we are not already in it! If GV is non-null and if the global has an
|
2005-11-21 07:05:42 +00:00
|
|
|
/// explicitly requested section, we switch to the section indicated for the
|
|
|
|
/// global instead of NewSection.
|
|
|
|
///
|
|
|
|
/// If the new section is an empty string, this method forgets what the
|
|
|
|
/// current section is, but does not emit a .section directive.
|
|
|
|
///
|
2006-05-09 04:59:30 +00:00
|
|
|
/// This method is used when about to emit executable code.
|
|
|
|
///
|
2006-10-31 06:11:06 +00:00
|
|
|
void SwitchToTextSection(const char *NewSection, const GlobalValue *GV = NULL);
|
2005-11-21 08:12:47 +00:00
|
|
|
|
2006-05-09 04:59:30 +00:00
|
|
|
/// SwitchToDataSection - Switch to the specified section of the executable
|
|
|
|
/// if we are not already in it! If GV is non-null and if the global has an
|
|
|
|
/// explicitly requested section, we switch to the section indicated for the
|
|
|
|
/// global instead of NewSection.
|
|
|
|
///
|
|
|
|
/// If the new section is an empty string, this method forgets what the
|
|
|
|
/// current section is, but does not emit a .section directive.
|
|
|
|
///
|
|
|
|
/// This method is used when about to emit data. For most assemblers, this
|
|
|
|
/// is the same as the SwitchToTextSection method, but not all assemblers
|
|
|
|
/// are the same.
|
|
|
|
///
|
2006-10-31 06:11:06 +00:00
|
|
|
void SwitchToDataSection(const char *NewSection, const GlobalValue *GV = NULL);
|
2006-05-09 04:59:30 +00:00
|
|
|
|
2006-10-17 13:41:07 +00: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.
|
2006-10-17 17:17:24 +00:00
|
|
|
virtual const std::string getGlobalLinkName(const GlobalVariable *GV) const;
|
2006-10-17 13:41:07 +00:00
|
|
|
|
2007-02-21 22:47:38 +00:00
|
|
|
/// EmitExternalGlobal - Emit the external reference to a global variable.
|
|
|
|
/// Should be overridden if an indirect reference should be used.
|
|
|
|
virtual void EmitExternalGlobal(const GlobalVariable *GV);
|
|
|
|
|
2007-09-18 01:47:22 +00:00
|
|
|
/// getCurrentFunctionEHName - Called to return (and cache) the
|
|
|
|
/// CurrentFnEHName.
|
|
|
|
///
|
2007-09-18 09:10:16 +00:00
|
|
|
std::string getCurrentFunctionEHName(const MachineFunction *MF);
|
2007-09-18 01:47:22 +00:00
|
|
|
|
2006-01-04 13:52:30 +00:00
|
|
|
protected:
|
2008-01-07 01:30:38 +00:00
|
|
|
/// getAnalysisUsage - Record analysis usage.
|
|
|
|
///
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
|
2004-08-16 23:15:22 +00:00
|
|
|
/// doInitialization - Set up the AsmPrinter when we are working on a new
|
|
|
|
/// module. If your pass overrides this, it must make sure to explicitly
|
|
|
|
/// call this implementation.
|
|
|
|
bool doInitialization(Module &M);
|
|
|
|
|
|
|
|
/// doFinalization - Shut down the asmprinter. If you override this in your
|
|
|
|
/// pass, you must make sure to call it explicitly.
|
|
|
|
bool doFinalization(Module &M);
|
2006-09-26 23:59:50 +00:00
|
|
|
|
|
|
|
/// PrintSpecial - Print information related to the specified machine instr
|
|
|
|
/// that is independent of the operand, and may be independent of the instr
|
|
|
|
/// itself. This can be useful for portably encoding the comment character
|
|
|
|
/// or other bits of target-specific knowledge into the asmstrings. The
|
|
|
|
/// syntax used is ${:comment}. Targets can override this to add support
|
|
|
|
/// for their own strange codes.
|
|
|
|
virtual void PrintSpecial(const MachineInstr *MI, const char *Code);
|
2006-02-01 22:39:30 +00:00
|
|
|
|
|
|
|
/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
|
|
|
|
/// instruction, using the specified assembler variant. Targets should
|
2006-02-24 20:21:12 +00:00
|
|
|
/// override this to format as appropriate. This method can return true if
|
2006-02-01 22:39:30 +00:00
|
|
|
/// the operand is erroneous.
|
|
|
|
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2006-02-06 22:16:41 +00:00
|
|
|
unsigned AsmVariant, const char *ExtraCode);
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2006-02-24 20:21:12 +00:00
|
|
|
/// PrintAsmMemoryOperand - Print the specified operand of MI, an INLINEASM
|
|
|
|
/// instruction, using the specified assembler variant as an address.
|
|
|
|
/// Targets should override this to format as appropriate. This method can
|
|
|
|
/// return true if the operand is erroneous.
|
|
|
|
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode);
|
|
|
|
|
2006-10-05 02:41:43 +00:00
|
|
|
/// getSectionForFunction - Return the section that we should emit the
|
|
|
|
/// specified function body into. This defaults to 'TextSection'. This
|
|
|
|
/// should most likely be overridden by the target to put linkonce/weak
|
|
|
|
/// functions into special sections.
|
|
|
|
virtual std::string getSectionForFunction(const Function &F) const;
|
|
|
|
|
2005-11-21 07:51:06 +00:00
|
|
|
/// SetupMachineFunction - This should be called when a new MachineFunction
|
2004-08-16 23:15:22 +00:00
|
|
|
/// is being processed from runOnMachineFunction.
|
2005-11-21 07:51:06 +00:00
|
|
|
void SetupMachineFunction(MachineFunction &MF);
|
2005-11-21 08:24:11 +00:00
|
|
|
|
2007-10-14 05:57:21 +00:00
|
|
|
/// getFunctionNumber - Return a unique ID for the current function.
|
|
|
|
///
|
|
|
|
unsigned getFunctionNumber() const { return FunctionNumber; }
|
|
|
|
|
|
|
|
/// IncrementFunctionNumber - Increase Function Number. AsmPrinters should
|
|
|
|
/// not normally call this, as the counter is automatically bumped by
|
|
|
|
/// SetupMachineFunction.
|
|
|
|
void IncrementFunctionNumber() { FunctionNumber++; }
|
|
|
|
|
2005-12-13 06:32:10 +00:00
|
|
|
/// EmitConstantPool - Print to the current output stream assembly
|
|
|
|
/// representations of the constants in the constant pool MCP. This is
|
|
|
|
/// used to print out constants which have been "spilled to memory" by
|
|
|
|
/// the code generator.
|
|
|
|
///
|
2006-06-29 00:26:09 +00:00
|
|
|
void EmitConstantPool(MachineConstantPool *MCP);
|
2004-08-16 23:15:22 +00:00
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
/// EmitJumpTableInfo - Print assembly representations of the jump tables
|
|
|
|
/// used by the current function to the current output stream.
|
|
|
|
///
|
2006-10-05 03:01:21 +00:00
|
|
|
void EmitJumpTableInfo(MachineJumpTableInfo *MJTI, MachineFunction &MF);
|
2006-04-22 18:53:45 +00:00
|
|
|
|
2005-12-13 06:32:10 +00:00
|
|
|
/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
|
|
|
|
/// special global used by LLVM. If so, emit it and return true, otherwise
|
|
|
|
/// do nothing and return false.
|
|
|
|
bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
|
2006-10-17 13:41:07 +00:00
|
|
|
|
2007-01-24 13:12:32 +00:00
|
|
|
public:
|
2007-01-25 15:12:02 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
/// LEB 128 number encoding.
|
|
|
|
|
|
|
|
/// PrintULEB128 - Print a series of hexidecimal values(separated by commas)
|
|
|
|
/// representing an unsigned leb128 value.
|
|
|
|
void PrintULEB128(unsigned Value) const;
|
|
|
|
|
|
|
|
/// SizeULEB128 - Compute the number of bytes required for an unsigned
|
|
|
|
/// leb128 value.
|
|
|
|
static unsigned SizeULEB128(unsigned Value);
|
|
|
|
|
|
|
|
/// PrintSLEB128 - Print a series of hexidecimal values(separated by commas)
|
|
|
|
/// representing a signed leb128 value.
|
|
|
|
void PrintSLEB128(int Value) const;
|
|
|
|
|
|
|
|
/// SizeSLEB128 - Compute the number of bytes required for a signed leb128
|
|
|
|
/// value.
|
|
|
|
static unsigned SizeSLEB128(int Value);
|
|
|
|
|
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
// Emission and print routines
|
|
|
|
//
|
|
|
|
|
|
|
|
/// PrintHex - Print a value as a hexidecimal value.
|
|
|
|
///
|
|
|
|
void PrintHex(int Value) const;
|
|
|
|
|
|
|
|
/// EOL - Print a newline character to asm stream. If a comment is present
|
|
|
|
/// then it will be printed first. Comments should not contain '\n'.
|
2007-02-21 22:47:38 +00:00
|
|
|
void EOL() const;
|
2007-01-25 15:12:02 +00:00
|
|
|
void EOL(const std::string &Comment) const;
|
|
|
|
|
|
|
|
/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
|
|
|
|
/// unsigned leb128 value.
|
|
|
|
void EmitULEB128Bytes(unsigned Value) const;
|
|
|
|
|
|
|
|
/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
|
|
|
|
/// signed leb128 value.
|
|
|
|
void EmitSLEB128Bytes(int Value) const;
|
|
|
|
|
|
|
|
/// EmitInt8 - Emit a byte directive and value.
|
|
|
|
///
|
|
|
|
void EmitInt8(int Value) const;
|
|
|
|
|
|
|
|
/// EmitInt16 - Emit a short directive and value.
|
|
|
|
///
|
|
|
|
void EmitInt16(int Value) const;
|
|
|
|
|
|
|
|
/// EmitInt32 - Emit a long directive and value.
|
|
|
|
///
|
|
|
|
void EmitInt32(int Value) const;
|
|
|
|
|
|
|
|
/// EmitInt64 - Emit a long long directive and value.
|
|
|
|
///
|
|
|
|
void EmitInt64(uint64_t Value) const;
|
|
|
|
|
|
|
|
/// EmitString - Emit a string with quotes and a null terminator.
|
|
|
|
/// Special characters are emitted properly.
|
2007-08-05 20:06:04 +00:00
|
|
|
/// @verbatim (Eg. '\t') @endverbatim
|
2007-01-25 15:12:02 +00:00
|
|
|
void EmitString(const std::string &String) const;
|
|
|
|
|
2007-09-24 20:58:13 +00:00
|
|
|
/// EmitFile - Emit a .file directive.
|
|
|
|
void EmitFile(unsigned Number, const std::string &Name) const;
|
|
|
|
|
2007-01-25 15:12:02 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
|
2005-11-21 07:51:06 +00:00
|
|
|
/// EmitAlignment - Emit an alignment directive to the specified power of
|
2004-08-17 19:14:29 +00:00
|
|
|
/// two boundary. For example, if you pass in 3 here, you will get an 8
|
2005-11-14 19:00:06 +00:00
|
|
|
/// byte alignment. If a global value is specified, and if that global has
|
2007-05-31 18:57:45 +00:00
|
|
|
/// 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
|
2007-07-25 23:35:07 +00:00
|
|
|
/// and the alignment computed with NumBits and the global. If UseFillExpr
|
|
|
|
/// is true, it also emits an optional second value FillValue which the
|
|
|
|
/// assembler uses to fill gaps to match alignment.
|
2007-05-31 18:57:45 +00:00
|
|
|
///
|
|
|
|
/// The algorithm is:
|
|
|
|
/// Align = NumBits;
|
|
|
|
/// if (GV && GV->hasalignment) Align = GV->getalignment();
|
|
|
|
/// Align = std::max(Align, ForcedAlignBits);
|
|
|
|
///
|
|
|
|
void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0,
|
2007-07-25 23:35:07 +00:00
|
|
|
unsigned ForcedAlignBits = 0, bool UseFillExpr = false,
|
|
|
|
unsigned FillValue = 0) const;
|
2004-08-17 19:14:29 +00:00
|
|
|
|
2007-01-24 13:12:32 +00:00
|
|
|
protected:
|
2005-11-21 07:51:06 +00:00
|
|
|
/// EmitZeros - Emit a block of zeros.
|
2004-08-17 21:38:51 +00:00
|
|
|
///
|
2006-05-02 03:46:13 +00:00
|
|
|
void EmitZeros(uint64_t NumZeros) const;
|
2006-05-02 01:16:28 +00:00
|
|
|
|
|
|
|
/// EmitString - Emit a zero-byte-terminated string constant.
|
|
|
|
///
|
|
|
|
virtual void EmitString(const ConstantArray *CVA) const;
|
2004-08-17 21:38:51 +00:00
|
|
|
|
2005-11-21 07:51:06 +00:00
|
|
|
/// EmitConstantValueOnly - Print out the specified constant, without a
|
2004-08-16 23:15:22 +00:00
|
|
|
/// storage class. Only constants of first-class type are allowed here.
|
2005-11-21 07:51:06 +00:00
|
|
|
void EmitConstantValueOnly(const Constant *CV);
|
2004-08-17 06:36:27 +00:00
|
|
|
|
2005-11-21 07:51:06 +00:00
|
|
|
/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
|
2007-11-05 00:04:43 +00:00
|
|
|
/// If Packed is false, pad to the ABI size.
|
|
|
|
void EmitGlobalConstant(const Constant* CV, bool Packed = false);
|
2006-09-12 21:00:35 +00:00
|
|
|
|
|
|
|
virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
|
2005-12-13 06:32:10 +00:00
|
|
|
|
2006-01-27 02:09:16 +00:00
|
|
|
/// printInlineAsm - This method formats and prints the specified machine
|
|
|
|
/// instruction that is an inline asm.
|
|
|
|
void printInlineAsm(const MachineInstr *MI) const;
|
2006-04-22 18:53:45 +00:00
|
|
|
|
2007-01-26 14:34:52 +00:00
|
|
|
/// printLabel - This method prints a local label used by debug and
|
|
|
|
/// exception handling tables.
|
|
|
|
void printLabel(const MachineInstr *MI) const;
|
|
|
|
|
2006-04-22 18:53:45 +00:00
|
|
|
/// printBasicBlockLabel - This method prints the label for the specified
|
|
|
|
/// MachineBasicBlock
|
2006-05-02 05:37:32 +00:00
|
|
|
virtual void printBasicBlockLabel(const MachineBasicBlock *MBB,
|
|
|
|
bool printColon = false,
|
|
|
|
bool printComment = true) const;
|
2006-08-12 21:29:52 +00:00
|
|
|
|
Much improved pic jumptable codegen:
Then:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
imull $4, %ecx, %ecx
leal LJTI1_0-"L1$pb"(%eax), %edx
addl LJTI1_0-"L1$pb"(%ecx,%eax), %edx
jmpl *%edx
.align 2
.set L1_0_set_3,LBB1_3-LJTI1_0
.set L1_0_set_2,LBB1_2-LJTI1_0
.set L1_0_set_5,LBB1_5-LJTI1_0
.set L1_0_set_4,LBB1_4-LJTI1_0
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
Now:
call "L1$pb"
"L1$pb":
popl %eax
...
LBB1_1: # entry
addl LJTI1_0-"L1$pb"(%eax,%ecx,4), %eax
jmpl *%eax
.align 2
.set L1_0_set_3,LBB1_3-"L1$pb"
.set L1_0_set_2,LBB1_2-"L1$pb"
.set L1_0_set_5,LBB1_5-"L1$pb"
.set L1_0_set_4,LBB1_4-"L1$pb"
LJTI1_0:
.long L1_0_set_3
.long L1_0_set_2
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43924 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-09 01:32:10 +00:00
|
|
|
/// printPICJumpTableSetLabel - This method prints a set label for the
|
|
|
|
/// specified MachineBasicBlock for a jumptable entry.
|
|
|
|
virtual void printPICJumpTableSetLabel(unsigned uid,
|
|
|
|
const MachineBasicBlock *MBB) const;
|
|
|
|
virtual void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
|
|
|
|
const MachineBasicBlock *MBB) const;
|
2007-11-14 09:18:41 +00:00
|
|
|
virtual void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
|
|
|
|
const MachineBasicBlock *MBB,
|
|
|
|
unsigned uid) const;
|
|
|
|
|
2006-09-12 21:00:35 +00:00
|
|
|
/// printDataDirective - This method prints the asm directive for the
|
|
|
|
/// specified type.
|
|
|
|
void printDataDirective(const Type *type);
|
|
|
|
|
2005-12-13 06:32:10 +00:00
|
|
|
private:
|
2006-09-26 03:38:18 +00:00
|
|
|
void EmitLLVMUsedList(Constant *List);
|
2005-12-13 06:32:10 +00:00
|
|
|
void EmitXXStructorList(Constant *List);
|
2006-06-29 00:26:09 +00:00
|
|
|
void EmitConstantPool(unsigned Alignment, const char *Section,
|
|
|
|
std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP);
|
2006-01-04 22:28:25 +00:00
|
|
|
|
2004-08-16 23:15:22 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|