41#define DEBUG_TYPE "avr-asm-printer"
73 bool EmittedStructorSymbolAttrs =
false;
110 if (ExtraCode && ExtraCode[0]) {
112 if (ExtraCode[1] != 0 || ExtraCode[0] <
'A' || ExtraCode[0] >
'Z')
121 unsigned ByteNumber = ExtraCode[0] -
'A';
129 unsigned BytesPerReg =
TRI.getRegSizeInBits(*RC) / 8;
130 assert(BytesPerReg <= 2 &&
"Only 8 and 16 bit regs are supported.");
132 unsigned RegIdx = ByteNumber / BytesPerReg;
133 if (RegIdx >= NumOpRegs)
135 Reg =
MI->getOperand(OpNum + RegIdx).getReg();
137 if (BytesPerReg == 2) {
138 Reg =
TRI.getSubReg(
Reg, (ByteNumber % BytesPerReg) ? AVR::sub_hi
155 unsigned OpNum,
const char *ExtraCode,
157 if (ExtraCode && ExtraCode[0])
162 assert(MO.
isReg() &&
"Unexpected inline asm memory operand");
168 if (
MI->getOperand(OpNum).getReg() == AVR::R31R30) {
170 }
else if (
MI->getOperand(OpNum).getReg() == AVR::R29R28) {
172 }
else if (
MI->getOperand(OpNum).getReg() == AVR::R27R26) {
175 assert(
false &&
"Wrong register class for memory operand.");
183 if (NumOpRegs == 2) {
184 assert(
MI->getOperand(OpNum).getReg() != AVR::R27R26 &&
185 "Base register X can not have offset/displacement.");
186 O <<
'+' <<
MI->getOperand(OpNum + 1).getImm();
193 AVR_MC::verifyInstructionPredicates(
MI->getOpcode(),
206 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
218 if (!EmittedStructorSymbolAttrs) {
220 " Emitting these undefined symbol references causes us to link the"
221 " libgcc code that runs our constructors/destructors");
222 OutStreamer->emitRawComment(
" This matches GCC's behavior");
230 EmittedStructorSymbolAttrs =
true;
241 bool NeedsCopyData =
false;
242 bool NeedsClearBSS =
false;
243 for (
const auto &GO : M.globals()) {
244 if (!GO.hasInitializer() || GO.hasAvailableExternallyLinkage())
248 if (GO.hasCommonLinkage()) {
250 NeedsClearBSS =
true;
255 if (Section->getName().starts_with(
".data"))
256 NeedsCopyData =
true;
257 else if (Section->getName().starts_with(
".rodata") && SubTM->hasLPM())
260 NeedsCopyData =
true;
261 else if (Section->getName().starts_with(
".bss"))
262 NeedsClearBSS =
true;
270 " Declaring this symbol tells the CRT that it should");
272 "copy all variables from program memory to RAM on startup");
278 " Declaring this symbol tells the CRT that it should");
279 OutStreamer->emitRawComment(
"clear the zeroed data section on startup");
305 if (!SubTM->hasSmallStack())
314 if (SubTM->hasEIJMPCALL())
319 if (SubTM->hasELPM())
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRAsmPrinter()
#define LLVM_EXTERNAL_VISIBILITY
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned const TargetRegisterInfo * TRI
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
An AVR assembly code printer.
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
const MCExpr * lowerConstant(const Constant *CV) override
Lower the specified LLVM Constant to an MCExpr.
bool doFinalization(Module &M) override
Shut down the asmprinter.
void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O)
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void emitXXStructor(const DataLayout &DL, const Constant *CV) override
Targets can override this to change how global constants that are part of a C++ static/global constru...
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
AVRAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
static const char * getPrettyRegisterName(unsigned RegNo, MCRegisterInfo const &MRI)
static const AVRMCExpr * create(VariantKind Kind, const MCExpr *Expr, bool isNegated, MCContext &Ctx)
Creates an AVR machine code expression.
@ VK_AVR_PM
Corresponds to pm(), reference to program memory.
Lowers MachineInstr objects into MCInst objects.
void lowerInstruction(const MachineInstr &MI, MCInst &OutMI) const
Lowers a MachineInstr into a MCInst.
A specific AVR target MCU.
int getIORegRAMPZ() const
Get I/O register addresses.
int getRegTmpIndex() const
Get GPR aliases.
int getRegZeroIndex() const
const AVRRegisterInfo * getRegisterInfo() const override
A generic AVR implementation.
This class is intended to be used as a driving class for all asm writers.
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
MCSymbol * getSymbol(const GlobalValue *GV) const
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
MachineFunction * MF
The current machine function.
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
MCContext & OutContext
This is the context for the output file that we are streaming.
bool doFinalization(Module &M) override
Shut down the asmprinter.
MCSymbol * GetExternalSymbolSymbol(Twine Sym) const
Return the MCSymbol for the specified ExternalSymbol.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
virtual void emitXXStructor(const DataLayout &DL, const Constant *CV)
Targets can override this to change how global constants that are part of a C++ static/global constru...
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
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.
unsigned getNumOperandRegisters() const
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
const MCContext & getContext() const
const LLVMTargetMachine & getTarget() const
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_GlobalAddress
Address of a global value.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
A Module instance is used to store all the information related to an LLVM module.
Wrapper class representing virtual and physical registers.
StringRef - Represent a constant reference to a string, i.e.
MCSection * SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const
This method computes the appropriate section to emit the specified global variable or function defini...
Primary interface to the complete machine description for the target machine.
virtual const TargetSubtargetInfo * getSubtargetImpl(const Function &) const
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
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.
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheAVRTarget()
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
@ MCSA_Global
.type _foo, @gnu_unique_object
Implement std::hash so that hash_code can be used in STL containers.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...