45#define DEBUG_TYPE "asm-printer"
56 std::unique_ptr<MCStreamer>
Streamer)
59 StringRef getPassName()
const override {
return "XCore Assembly Printer"; }
62 const std::string &
directive =
".jmptable");
64 printInlineJT(
MI, opNum, O,
".jmptable32");
75 void emitFunctionEntryLabel()
override;
77 void emitFunctionBodyStart()
override;
78 void emitFunctionBodyEnd()
override;
83 return static_cast<XCoreTargetStreamer&
>(*OutStreamer->getTargetStreamer());
86void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym,
const GlobalVariable *GV) {
89 "Unexpected linkage");
92 MCSymbol *SymGlob = OutContext.getOrCreateSymbol(
93 Twine(Sym->
getName() + StringRef(
".globound")));
94 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Global);
95 OutStreamer->emitAssignment(SymGlob,
100 OutStreamer->emitSymbolAttribute(SymGlob,
MCSA_Weak);
105void XCoreAsmPrinter::emitGlobalVariable(
const GlobalVariable *GV) {
110 const DataLayout &
DL = getDataLayout();
111 OutStreamer->switchSection(getObjFileLowering().SectionForGlobal(GV, TM));
118 getTargetStreamer().emitCCTopData(GVSym->
getName());
129 emitArrayBound(GVSym, GV);
130 OutStreamer->emitSymbolAttribute(GVSym,
MCSA_Global);
134 OutStreamer->emitSymbolAttribute(GVSym,
MCSA_Weak);
143 emitAlignment(std::max(Alignment,
Align(4)), GV);
148 unsigned Size =
DL.getTypeAllocSize(
C->getType());
149 if (MAI.hasDotTypeDotSizeDirective()) {
153 OutStreamer->emitLabel(GVSym);
155 emitGlobalConstant(
DL,
C);
159 OutStreamer->emitZeros(4 -
Size);
162 getTargetStreamer().emitCCBottomData(GVSym->
getName());
165void XCoreAsmPrinter::emitFunctionBodyStart() {
171void XCoreAsmPrinter::emitFunctionBodyEnd() {
173 getTargetStreamer().emitCCBottomFunction(CurrentFnSym->getName());
176void XCoreAsmPrinter::emitFunctionEntryLabel() {
178 getTargetStreamer().emitCCTopFunction(CurrentFnSym->getName());
179 OutStreamer->emitLabel(CurrentFnSym);
182void XCoreAsmPrinter::
183printInlineJT(
const MachineInstr *
MI,
int opNum, raw_ostream &O,
184 const std::string &directive) {
185 unsigned JTI =
MI->getOperand(opNum).getIndex();
188 const std::vector<MachineJumpTableEntry> &JT = MJTI->
getJumpTables();
189 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
190 O <<
"\t" << directive <<
" ";
191 for (
unsigned i = 0, e = JTBBs.size(); i != e; ++i) {
192 MachineBasicBlock *
MBB = JTBBs[i];
199void XCoreAsmPrinter::printOperand(
const MachineInstr *
MI,
int opNum,
201 const DataLayout &
DL = getDataLayout();
202 const MachineOperand &MO =
MI->getOperand(opNum);
214 PrintSymbolOperand(MO, O);
217 O <<
DL.getInternalSymbolPrefix() <<
"CPI" << getFunctionNumber() <<
'_'
230bool XCoreAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
231 const char *ExtraCode, raw_ostream &O) {
233 if (!ExtraCode || !ExtraCode[0]) {
242bool XCoreAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
244 const char *ExtraCode,
246 if (ExtraCode && ExtraCode[0]) {
256void XCoreAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
257 XCore_MC::verifyInstructionPredicates(
MI->getOpcode(),
258 getSubtargetInfo().getFeatureBits());
260 SmallString<128> Str;
261 raw_svector_ostream
O(Str);
263 switch (
MI->getOpcode()) {
264 case XCore::DBG_VALUE:
266 case XCore::ADD_2rus:
267 if (
MI->getOperand(2).getImm() == 0) {
271 OutStreamer->emitRawText(
O.str());
279 if (
MI->getOpcode() == XCore::BR_JT)
280 printInlineJT(
MI, 0, O);
282 printInlineJT32(
MI, 0, O);
284 OutStreamer->emitRawText(
O.str());
289 MCInstLowering.
Lower(
MI, TmpInst);
291 EmitToStreamer(*OutStreamer, TmpInst);
294char XCoreAsmPrinter::ID = 0;
301LLVMInitializeXCoreAsmPrinter() {
307 XCoreAsmPrinter &
AsmPrinter =
static_cast<XCoreAsmPrinter &
>(
317 XCoreAsmPrinter &
AsmPrinter =
static_cast<XCoreAsmPrinter &
>(
328 XCoreAsmPrinter &
AsmPrinter =
static_cast<XCoreAsmPrinter &
>(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
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 ...
ModuleAnalysisManager MAM
#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...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is intended to be used as a driving class for all asm writers.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
bool doFinalization(Module &M) override
Shut down the asmprinter.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
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.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Target & getTheXCoreTarget()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...