44#define DEBUG_TYPE "asm-printer"
55 std::unique_ptr<MCStreamer> Streamer)
56 :
AsmPrinter(TM, std::move(Streamer),
ID), MCInstLowering(*
this) {}
58 StringRef getPassName()
const override {
return "XCore Assembly Printer"; }
61 const std::string &
directive =
".jmptable");
63 printInlineJT(
MI, opNum, O,
".jmptable32");
74 void emitFunctionEntryLabel()
override;
76 void emitFunctionBodyStart()
override;
77 void emitFunctionBodyEnd()
override;
82 return static_cast<XCoreTargetStreamer&
>(*OutStreamer->getTargetStreamer());
85void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym,
const GlobalVariable *GV) {
88 "Unexpected linkage");
91 MCSymbol *SymGlob = OutContext.getOrCreateSymbol(
92 Twine(Sym->
getName() + StringRef(
".globound")));
93 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Global);
94 OutStreamer->emitAssignment(SymGlob,
99 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Weak);
104void XCoreAsmPrinter::emitGlobalVariable(
const GlobalVariable *GV) {
109 const DataLayout &
DL = getDataLayout();
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() {
170void XCoreAsmPrinter::emitFunctionBodyEnd() {
172 getTargetStreamer().emitCCBottomFunction(CurrentFnSym->getName());
175void XCoreAsmPrinter::emitFunctionEntryLabel() {
177 getTargetStreamer().emitCCTopFunction(CurrentFnSym->getName());
178 OutStreamer->emitLabel(CurrentFnSym);
181void XCoreAsmPrinter::
182printInlineJT(
const MachineInstr *
MI,
int opNum, raw_ostream &O,
183 const std::string &directive) {
184 unsigned JTI =
MI->getOperand(opNum).getIndex();
185 const MachineFunction *MF =
MI->getParent()->getParent();
188 const std::vector<MachineBasicBlock*> &JTBBs =
JT[JTI].MBBs;
189 O <<
"\t" << directive <<
" ";
190 for (
unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
191 MachineBasicBlock *
MBB = JTBBs[i];
198void XCoreAsmPrinter::printOperand(
const MachineInstr *
MI,
int opNum,
200 const DataLayout &
DL = getDataLayout();
201 const MachineOperand &MO =
MI->getOperand(opNum);
213 PrintSymbolOperand(MO, O);
216 O <<
DL.getPrivateGlobalPrefix() <<
"CPI" << getFunctionNumber() <<
'_'
229bool XCoreAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
230 const char *ExtraCode, raw_ostream &O) {
232 if (!ExtraCode || !ExtraCode[0]) {
241bool XCoreAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
243 const char *ExtraCode,
245 if (ExtraCode && ExtraCode[0]) {
255void XCoreAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
256 XCore_MC::verifyInstructionPredicates(
MI->getOpcode(),
257 getSubtargetInfo().getFeatureBits());
259 SmallString<128> Str;
260 raw_svector_ostream
O(Str);
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
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.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton 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 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.
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)
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
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.
StringRef - Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
static const char * getRegisterName(MCRegister Reg)
This class is used to lower an MachineInstr into an MCInst.
void Lower(const MachineInstr *MI, MCInst &OutMI) const
void Initialize(MCContext *C)
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...