43#define DEBUG_TYPE "asm-printer"
54 std::unique_ptr<MCStreamer>
Streamer)
57 StringRef getPassName()
const override {
return "XCore Assembly Printer"; }
60 const std::string &
directive =
".jmptable");
62 printInlineJT(
MI, opNum, O,
".jmptable32");
73 void emitFunctionEntryLabel()
override;
75 void emitFunctionBodyStart()
override;
76 void emitFunctionBodyEnd()
override;
81 return static_cast<XCoreTargetStreamer&
>(*OutStreamer->getTargetStreamer());
84void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym,
const GlobalVariable *GV) {
87 "Unexpected linkage");
90 MCSymbol *SymGlob = OutContext.getOrCreateSymbol(
91 Twine(Sym->
getName() + StringRef(
".globound")));
92 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Global);
93 OutStreamer->emitAssignment(SymGlob,
98 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Weak);
103void XCoreAsmPrinter::emitGlobalVariable(
const GlobalVariable *GV) {
108 const DataLayout &
DL = getDataLayout();
109 OutStreamer->switchSection(getObjFileLowering().SectionForGlobal(GV, TM));
116 getTargetStreamer().emitCCTopData(GVSym->
getName());
127 emitArrayBound(GVSym, GV);
128 OutStreamer->emitSymbolAttribute(GVSym,
MCSA_Global);
132 OutStreamer->emitSymbolAttribute(GVSym,
MCSA_Weak);
141 emitAlignment(std::max(Alignment,
Align(4)), GV);
146 unsigned Size =
DL.getTypeAllocSize(
C->getType());
147 if (MAI.hasDotTypeDotSizeDirective()) {
151 OutStreamer->emitLabel(GVSym);
153 emitGlobalConstant(
DL,
C);
157 OutStreamer->emitZeros(4 -
Size);
160 getTargetStreamer().emitCCBottomData(GVSym->
getName());
163void XCoreAsmPrinter::emitFunctionBodyStart() {
169void XCoreAsmPrinter::emitFunctionBodyEnd() {
171 getTargetStreamer().emitCCBottomFunction(CurrentFnSym->getName());
174void XCoreAsmPrinter::emitFunctionEntryLabel() {
176 getTargetStreamer().emitCCTopFunction(CurrentFnSym->getName());
177 OutStreamer->emitLabel(CurrentFnSym);
180void XCoreAsmPrinter::
181printInlineJT(
const MachineInstr *
MI,
int opNum, raw_ostream &O,
182 const std::string &directive) {
183 unsigned JTI =
MI->getOperand(opNum).getIndex();
186 const std::vector<MachineJumpTableEntry> &JT = MJTI->
getJumpTables();
187 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
188 O <<
"\t" << directive <<
" ";
189 for (
unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
190 MachineBasicBlock *
MBB = JTBBs[i];
197void XCoreAsmPrinter::printOperand(
const MachineInstr *
MI,
int opNum,
199 const DataLayout &
DL = getDataLayout();
200 const MachineOperand &MO =
MI->getOperand(opNum);
212 PrintSymbolOperand(MO, O);
215 O <<
DL.getInternalSymbolPrefix() <<
"CPI" << getFunctionNumber() <<
'_'
228bool XCoreAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
229 const char *ExtraCode, raw_ostream &O) {
231 if (!ExtraCode || !ExtraCode[0]) {
240bool XCoreAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
242 const char *ExtraCode,
244 if (ExtraCode && ExtraCode[0]) {
254void XCoreAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
255 XCore_MC::verifyInstructionPredicates(
MI->getOpcode(),
256 getSubtargetInfo().getFeatureBits());
258 SmallString<128> Str;
259 raw_svector_ostream
O(Str);
261 switch (
MI->getOpcode()) {
262 case XCore::DBG_VALUE:
264 case XCore::ADD_2rus:
265 if (
MI->getOperand(2).getImm() == 0) {
269 OutStreamer->emitRawText(
O.str());
277 if (
MI->getOpcode() == XCore::BR_JT)
278 printInlineJT(
MI, 0, O);
280 printInlineJT32(
MI, 0, O);
282 OutStreamer->emitRawText(
O.str());
287 MCInstLowering.
Lower(
MI, TmpInst);
289 EmitToStreamer(*OutStreamer, TmpInst);
292char XCoreAsmPrinter::ID = 0;
299LLVMInitializeXCoreAsmPrinter() {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#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.
std::unique_ptr< MCStreamer > && Streamer
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.
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.
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,...