44#define DEBUG_TYPE "asm-printer"
55 std::unique_ptr<MCStreamer> Streamer)
56 :
AsmPrinter(TM, std::move(Streamer),
ID), MCInstLowering(*
this) {}
61 const std::string &directive =
".jmptable");
63 printInlineJT(
MI, opNum, O,
".jmptable32");
88 "Unexpected linkage");
91 MCSymbol *SymGlob = OutContext.getOrCreateSymbol(
93 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Global);
94 OutStreamer->emitAssignment(SymGlob,
99 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Weak);
104void XCoreAsmPrinter::emitGlobalVariable(
const GlobalVariable *GV) {
110 OutStreamer->switchSection(getObjFileLowering().SectionForGlobal(GV, TM));
114 const Align Alignment =
DL.getPrefTypeAlign(
C->getType());
117 getTargetStreamer().emitCCTopData(GVSym->
getName());
128 emitArrayBound(GVSym, GV);
129 OutStreamer->emitSymbolAttribute(GVSym,
MCSA_Global);
133 OutStreamer->emitSymbolAttribute(GVSym,
MCSA_Weak);
142 emitAlignment(std::max(Alignment,
Align(4)), GV);
147 unsigned Size =
DL.getTypeAllocSize(
C->getType());
148 if (MAI->hasDotTypeDotSizeDirective()) {
152 OutStreamer->emitLabel(GVSym);
154 emitGlobalConstant(
DL,
C);
158 OutStreamer->emitZeros(4 -
Size);
161 getTargetStreamer().emitCCBottomData(GVSym->
getName());
164void XCoreAsmPrinter::emitFunctionBodyStart() {
165 MCInstLowering.Initialize(&MF->getContext());
170void XCoreAsmPrinter::emitFunctionBodyEnd() {
172 getTargetStreamer().emitCCBottomFunction(CurrentFnSym->getName());
175void XCoreAsmPrinter::emitFunctionEntryLabel() {
177 getTargetStreamer().emitCCTopFunction(CurrentFnSym->getName());
178 OutStreamer->emitLabel(CurrentFnSym);
181void XCoreAsmPrinter::
183 const std::string &directive) {
184 unsigned JTI =
MI->getOperand(opNum).getIndex();
188 const std::vector<MachineBasicBlock*> &JTBBs =
JT[JTI].MBBs;
189 O <<
"\t" << directive <<
" ";
190 for (
unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
198void XCoreAsmPrinter::printOperand(
const MachineInstr *
MI,
int opNum,
213 PrintSymbolOperand(MO, O);
216 O <<
DL.getPrivateGlobalPrefix() <<
"CPI" << getFunctionNumber() <<
'_'
229bool XCoreAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
232 if (!ExtraCode || !ExtraCode[0]) {
241bool XCoreAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
243 const char *ExtraCode,
245 if (ExtraCode && ExtraCode[0]) {
256 XCore_MC::verifyInstructionPredicates(
MI->getOpcode(),
257 getSubtargetInfo().getFeatureBits());
262 switch (
MI->getOpcode()) {
263 case XCore::DBG_VALUE:
265 case XCore::ADD_2rus:
266 if (
MI->getOperand(2).getImm() == 0) {
270 OutStreamer->emitRawText(
O.str());
278 if (
MI->getOpcode() == XCore::BR_JT)
279 printInlineJT(
MI, 0, O);
281 printInlineJT32(
MI, 0, O);
283 OutStreamer->emitRawText(
O.str());
288 MCInstLowering.Lower(
MI, TmpInst);
290 EmitToStreamer(*OutStreamer, TmpInst);
293char XCoreAsmPrinter::ID = 0;
300LLVMInitializeXCoreAsmPrinter() {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_EXTERNAL_VISIBILITY
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
This file defines the SmallString class.
This file contains the declaration of the XCoreInstPrinter class, which is used to print XCore MCInst...
This class is intended to be used as a driving class for all asm writers.
virtual void emitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
virtual void emitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
virtual void emitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
bool hasLinkOnceLinkage() const
bool hasExternalLinkage() const
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
LinkageTypes getLinkage() const
bool hasWeakLinkage() const
bool hasCommonLinkage() const
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Instances of this class represent a single low-level machine instruction.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
StringRef getName() const
getName - Get the symbol name.
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
Representation of each machine instruction.
const std::vector< MachineJumpTableEntry > & getJumpTables() const
MachineOperand class - Representation of each machine instruction operand.
MachineBasicBlock * getMBB() const
const BlockAddress * getBlockAddress() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static const char * getRegisterName(MCRegister Reg)
This class is used to lower an MachineInstr into an MCInst.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheXCoreTarget()
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
This struct is a compact representation of a valid (non-zero power of two) alignment.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...