xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AVR/AVRAsmPrinter.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- AVRAsmPrinter.cpp - AVR LLVM assembly writer ----------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains a printer that converts from our internal representation
100b57cec5SDimitry Andric // of machine-dependent LLVM code to GAS-format AVR assembly language.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "AVR.h"
150b57cec5SDimitry Andric #include "AVRMCInstLower.h"
160b57cec5SDimitry Andric #include "AVRSubtarget.h"
1781ad6265SDimitry Andric #include "AVRTargetMachine.h"
180b57cec5SDimitry Andric #include "MCTargetDesc/AVRInstPrinter.h"
19fe6060f1SDimitry Andric #include "MCTargetDesc/AVRMCExpr.h"
200b57cec5SDimitry Andric #include "TargetInfo/AVRTargetInfo.h"
210b57cec5SDimitry Andric 
22bdd1243dSDimitry Andric #include "llvm/BinaryFormat/ELF.h"
230b57cec5SDimitry Andric #include "llvm/CodeGen/AsmPrinter.h"
240b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
250b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstr.h"
2681ad6265SDimitry Andric #include "llvm/CodeGen/MachineModuleInfo.h"
270b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
280b57cec5SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
290b57cec5SDimitry Andric #include "llvm/IR/Mangler.h"
30349cc55cSDimitry Andric #include "llvm/MC/MCContext.h"
310b57cec5SDimitry Andric #include "llvm/MC/MCInst.h"
32bdd1243dSDimitry Andric #include "llvm/MC/MCSectionELF.h"
330b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h"
340b57cec5SDimitry Andric #include "llvm/MC/MCSymbol.h"
35349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h"
360b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
370b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
38bdd1243dSDimitry Andric #include "llvm/Target/TargetLoweringObjectFile.h"
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric #define DEBUG_TYPE "avr-asm-printer"
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric namespace llvm {
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric /// An AVR assembly code printer.
450b57cec5SDimitry Andric class AVRAsmPrinter : public AsmPrinter {
460b57cec5SDimitry Andric public:
47349cc55cSDimitry Andric   AVRAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
480b57cec5SDimitry Andric       : AsmPrinter(TM, std::move(Streamer)), MRI(*TM.getMCRegisterInfo()) {}
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric   StringRef getPassName() const override { return "AVR Assembly Printer"; }
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
550b57cec5SDimitry Andric                        const char *ExtraCode, raw_ostream &O) override;
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
580b57cec5SDimitry Andric                              const char *ExtraCode, raw_ostream &O) override;
590b57cec5SDimitry Andric 
605ffd83dbSDimitry Andric   void emitInstruction(const MachineInstr *MI) override;
610b57cec5SDimitry Andric 
62fe6060f1SDimitry Andric   const MCExpr *lowerConstant(const Constant *CV) override;
63fe6060f1SDimitry Andric 
64349cc55cSDimitry Andric   void emitXXStructor(const DataLayout &DL, const Constant *CV) override;
65349cc55cSDimitry Andric 
66349cc55cSDimitry Andric   bool doFinalization(Module &M) override;
67349cc55cSDimitry Andric 
6881ad6265SDimitry Andric   void emitStartOfAsmFile(Module &M) override;
6981ad6265SDimitry Andric 
700b57cec5SDimitry Andric private:
710b57cec5SDimitry Andric   const MCRegisterInfo &MRI;
72349cc55cSDimitry Andric   bool EmittedStructorSymbolAttrs = false;
730b57cec5SDimitry Andric };
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric void AVRAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
760b57cec5SDimitry Andric                                  raw_ostream &O) {
770b57cec5SDimitry Andric   const MachineOperand &MO = MI->getOperand(OpNo);
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   switch (MO.getType()) {
800b57cec5SDimitry Andric   case MachineOperand::MO_Register:
810b57cec5SDimitry Andric     O << AVRInstPrinter::getPrettyRegisterName(MO.getReg(), MRI);
820b57cec5SDimitry Andric     break;
830b57cec5SDimitry Andric   case MachineOperand::MO_Immediate:
840b57cec5SDimitry Andric     O << MO.getImm();
850b57cec5SDimitry Andric     break;
860b57cec5SDimitry Andric   case MachineOperand::MO_GlobalAddress:
870b57cec5SDimitry Andric     O << getSymbol(MO.getGlobal());
880b57cec5SDimitry Andric     break;
890b57cec5SDimitry Andric   case MachineOperand::MO_ExternalSymbol:
900b57cec5SDimitry Andric     O << *GetExternalSymbolSymbol(MO.getSymbolName());
910b57cec5SDimitry Andric     break;
920b57cec5SDimitry Andric   case MachineOperand::MO_MachineBasicBlock:
930b57cec5SDimitry Andric     O << *MO.getMBB()->getSymbol();
940b57cec5SDimitry Andric     break;
950b57cec5SDimitry Andric   default:
960b57cec5SDimitry Andric     llvm_unreachable("Not implemented yet!");
970b57cec5SDimitry Andric   }
980b57cec5SDimitry Andric }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric bool AVRAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
1010b57cec5SDimitry Andric                                     const char *ExtraCode, raw_ostream &O) {
1020b57cec5SDimitry Andric   // Default asm printer can only deal with some extra codes,
1030b57cec5SDimitry Andric   // so try it first.
10406c3fb27SDimitry Andric   if (!AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O))
10506c3fb27SDimitry Andric     return false;
1060b57cec5SDimitry Andric 
10706c3fb27SDimitry Andric   const MachineOperand &MO = MI->getOperand(OpNum);
1080b57cec5SDimitry Andric 
10906c3fb27SDimitry Andric   if (ExtraCode && ExtraCode[0]) {
11006c3fb27SDimitry Andric     // Unknown extra code.
11106c3fb27SDimitry Andric     if (ExtraCode[1] != 0 || ExtraCode[0] < 'A' || ExtraCode[0] > 'Z')
11206c3fb27SDimitry Andric       return true;
1130b57cec5SDimitry Andric 
11406c3fb27SDimitry Andric     // Operand must be a register when using 'A' ~ 'Z' extra code.
11506c3fb27SDimitry Andric     if (!MO.isReg())
11606c3fb27SDimitry Andric       return true;
11706c3fb27SDimitry Andric 
11806c3fb27SDimitry Andric     Register Reg = MO.getReg();
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric     unsigned ByteNumber = ExtraCode[0] - 'A';
121*5f757f3fSDimitry Andric     const InlineAsm::Flag OpFlags(MI->getOperand(OpNum - 1).getImm());
122*5f757f3fSDimitry Andric     const unsigned NumOpRegs = OpFlags.getNumOperandRegisters();
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric     const AVRSubtarget &STI = MF->getSubtarget<AVRSubtarget>();
1250b57cec5SDimitry Andric     const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
1260b57cec5SDimitry Andric 
1270b57cec5SDimitry Andric     const TargetRegisterClass *RC = TRI.getMinimalPhysRegClass(Reg);
1280b57cec5SDimitry Andric     unsigned BytesPerReg = TRI.getRegSizeInBits(*RC) / 8;
1290b57cec5SDimitry Andric     assert(BytesPerReg <= 2 && "Only 8 and 16 bit regs are supported.");
1300b57cec5SDimitry Andric 
1310b57cec5SDimitry Andric     unsigned RegIdx = ByteNumber / BytesPerReg;
132bdd1243dSDimitry Andric     if (RegIdx >= NumOpRegs)
133bdd1243dSDimitry Andric       return true;
1340b57cec5SDimitry Andric     Reg = MI->getOperand(OpNum + RegIdx).getReg();
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric     if (BytesPerReg == 2) {
13706c3fb27SDimitry Andric       Reg = TRI.getSubReg(Reg,
13806c3fb27SDimitry Andric                           ByteNumber % BytesPerReg ? AVR::sub_hi : AVR::sub_lo);
1390b57cec5SDimitry Andric     }
1400b57cec5SDimitry Andric 
1410b57cec5SDimitry Andric     O << AVRInstPrinter::getPrettyRegisterName(Reg, MRI);
1420b57cec5SDimitry Andric     return false;
1430b57cec5SDimitry Andric   }
1440b57cec5SDimitry Andric 
14506c3fb27SDimitry Andric   if (MO.getType() == MachineOperand::MO_GlobalAddress)
14606c3fb27SDimitry Andric     PrintSymbolOperand(MO, O); // Print global symbols.
14706c3fb27SDimitry Andric   else
14806c3fb27SDimitry Andric     printOperand(MI, OpNum, O); // Fallback to ordinary cases.
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric   return false;
1510b57cec5SDimitry Andric }
1520b57cec5SDimitry Andric 
1530b57cec5SDimitry Andric bool AVRAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
1540b57cec5SDimitry Andric                                           unsigned OpNum, const char *ExtraCode,
1550b57cec5SDimitry Andric                                           raw_ostream &O) {
156349cc55cSDimitry Andric   if (ExtraCode && ExtraCode[0])
157349cc55cSDimitry Andric     return true; // Unknown modifier
1580b57cec5SDimitry Andric 
1590b57cec5SDimitry Andric   const MachineOperand &MO = MI->getOperand(OpNum);
1600b57cec5SDimitry Andric   (void)MO;
1610b57cec5SDimitry Andric   assert(MO.isReg() && "Unexpected inline asm memory operand");
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   // TODO: We should be able to look up the alternative name for
1640b57cec5SDimitry Andric   // the register if it's given.
1650b57cec5SDimitry Andric   // TableGen doesn't expose a way of getting retrieving names
1660b57cec5SDimitry Andric   // for registers.
1670b57cec5SDimitry Andric   if (MI->getOperand(OpNum).getReg() == AVR::R31R30) {
1680b57cec5SDimitry Andric     O << "Z";
169bdd1243dSDimitry Andric   } else if (MI->getOperand(OpNum).getReg() == AVR::R29R28) {
1700b57cec5SDimitry Andric     O << "Y";
171bdd1243dSDimitry Andric   } else if (MI->getOperand(OpNum).getReg() == AVR::R27R26) {
172bdd1243dSDimitry Andric     O << "X";
173bdd1243dSDimitry Andric   } else {
174bdd1243dSDimitry Andric     assert(false && "Wrong register class for memory operand.");
1750b57cec5SDimitry Andric   }
1760b57cec5SDimitry Andric 
1770b57cec5SDimitry Andric   // If NumOpRegs == 2, then we assume it is product of a FrameIndex expansion
1780b57cec5SDimitry Andric   // and the second operand is an Imm.
179*5f757f3fSDimitry Andric   const InlineAsm::Flag OpFlags(MI->getOperand(OpNum - 1).getImm());
180*5f757f3fSDimitry Andric   const unsigned NumOpRegs = OpFlags.getNumOperandRegisters();
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric   if (NumOpRegs == 2) {
183bdd1243dSDimitry Andric     assert(MI->getOperand(OpNum).getReg() != AVR::R27R26 &&
184bdd1243dSDimitry Andric            "Base register X can not have offset/displacement.");
1850b57cec5SDimitry Andric     O << '+' << MI->getOperand(OpNum + 1).getImm();
1860b57cec5SDimitry Andric   }
1870b57cec5SDimitry Andric 
1880b57cec5SDimitry Andric   return false;
1890b57cec5SDimitry Andric }
1900b57cec5SDimitry Andric 
1915ffd83dbSDimitry Andric void AVRAsmPrinter::emitInstruction(const MachineInstr *MI) {
19206c3fb27SDimitry Andric   AVR_MC::verifyInstructionPredicates(MI->getOpcode(),
19306c3fb27SDimitry Andric                                       getSubtargetInfo().getFeatureBits());
194753f127fSDimitry Andric 
1950b57cec5SDimitry Andric   AVRMCInstLower MCInstLowering(OutContext, *this);
1960b57cec5SDimitry Andric 
1970b57cec5SDimitry Andric   MCInst I;
1980b57cec5SDimitry Andric   MCInstLowering.lowerInstruction(*MI, I);
1990b57cec5SDimitry Andric   EmitToStreamer(*OutStreamer, I);
2000b57cec5SDimitry Andric }
2010b57cec5SDimitry Andric 
202fe6060f1SDimitry Andric const MCExpr *AVRAsmPrinter::lowerConstant(const Constant *CV) {
203fe6060f1SDimitry Andric   MCContext &Ctx = OutContext;
204fe6060f1SDimitry Andric 
205fe6060f1SDimitry Andric   if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
206fe6060f1SDimitry Andric     bool IsProgMem = GV->getAddressSpace() == AVR::ProgramMemory;
207fe6060f1SDimitry Andric     if (IsProgMem) {
208fe6060f1SDimitry Andric       const MCExpr *Expr = MCSymbolRefExpr::create(getSymbol(GV), Ctx);
209fe6060f1SDimitry Andric       return AVRMCExpr::create(AVRMCExpr::VK_AVR_PM, Expr, false, Ctx);
210fe6060f1SDimitry Andric     }
211fe6060f1SDimitry Andric   }
212fe6060f1SDimitry Andric 
213fe6060f1SDimitry Andric   return AsmPrinter::lowerConstant(CV);
214fe6060f1SDimitry Andric }
215fe6060f1SDimitry Andric 
216349cc55cSDimitry Andric void AVRAsmPrinter::emitXXStructor(const DataLayout &DL, const Constant *CV) {
217349cc55cSDimitry Andric   if (!EmittedStructorSymbolAttrs) {
218349cc55cSDimitry Andric     OutStreamer->emitRawComment(
219349cc55cSDimitry Andric         " Emitting these undefined symbol references causes us to link the"
220349cc55cSDimitry Andric         " libgcc code that runs our constructors/destructors");
221349cc55cSDimitry Andric     OutStreamer->emitRawComment(" This matches GCC's behavior");
222349cc55cSDimitry Andric 
223349cc55cSDimitry Andric     MCSymbol *CtorsSym = OutContext.getOrCreateSymbol("__do_global_ctors");
224349cc55cSDimitry Andric     OutStreamer->emitSymbolAttribute(CtorsSym, MCSA_Global);
225349cc55cSDimitry Andric 
226349cc55cSDimitry Andric     MCSymbol *DtorsSym = OutContext.getOrCreateSymbol("__do_global_dtors");
227349cc55cSDimitry Andric     OutStreamer->emitSymbolAttribute(DtorsSym, MCSA_Global);
228349cc55cSDimitry Andric 
229349cc55cSDimitry Andric     EmittedStructorSymbolAttrs = true;
230349cc55cSDimitry Andric   }
231349cc55cSDimitry Andric 
232349cc55cSDimitry Andric   AsmPrinter::emitXXStructor(DL, CV);
233349cc55cSDimitry Andric }
234349cc55cSDimitry Andric 
235349cc55cSDimitry Andric bool AVRAsmPrinter::doFinalization(Module &M) {
236bdd1243dSDimitry Andric   const TargetLoweringObjectFile &TLOF = getObjFileLowering();
237bdd1243dSDimitry Andric   const AVRTargetMachine &TM = (const AVRTargetMachine &)MMI->getTarget();
238bdd1243dSDimitry Andric   const AVRSubtarget *SubTM = (const AVRSubtarget *)TM.getSubtargetImpl();
239bdd1243dSDimitry Andric 
240bdd1243dSDimitry Andric   bool NeedsCopyData = false;
241bdd1243dSDimitry Andric   bool NeedsClearBSS = false;
242bdd1243dSDimitry Andric   for (const auto &GO : M.globals()) {
243bdd1243dSDimitry Andric     if (!GO.hasInitializer() || GO.hasAvailableExternallyLinkage())
244bdd1243dSDimitry Andric       // These globals aren't defined in the current object file.
245bdd1243dSDimitry Andric       continue;
246bdd1243dSDimitry Andric 
247bdd1243dSDimitry Andric     if (GO.hasCommonLinkage()) {
248bdd1243dSDimitry Andric       // COMMON symbols are put in .bss.
249bdd1243dSDimitry Andric       NeedsClearBSS = true;
250bdd1243dSDimitry Andric       continue;
251bdd1243dSDimitry Andric     }
252bdd1243dSDimitry Andric 
253bdd1243dSDimitry Andric     auto *Section = cast<MCSectionELF>(TLOF.SectionForGlobal(&GO, TM));
254*5f757f3fSDimitry Andric     if (Section->getName().starts_with(".data"))
255bdd1243dSDimitry Andric       NeedsCopyData = true;
256*5f757f3fSDimitry Andric     else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())
25706c3fb27SDimitry Andric       // AVRs that have a separate program memory (that's most AVRs) store
25806c3fb27SDimitry Andric       // .rodata sections in RAM.
259bdd1243dSDimitry Andric       NeedsCopyData = true;
260*5f757f3fSDimitry Andric     else if (Section->getName().starts_with(".bss"))
261bdd1243dSDimitry Andric       NeedsClearBSS = true;
262bdd1243dSDimitry Andric   }
263bdd1243dSDimitry Andric 
264349cc55cSDimitry Andric   MCSymbol *DoCopyData = OutContext.getOrCreateSymbol("__do_copy_data");
265349cc55cSDimitry Andric   MCSymbol *DoClearBss = OutContext.getOrCreateSymbol("__do_clear_bss");
266349cc55cSDimitry Andric 
267bdd1243dSDimitry Andric   if (NeedsCopyData) {
268349cc55cSDimitry Andric     OutStreamer->emitRawComment(
269349cc55cSDimitry Andric         " Declaring this symbol tells the CRT that it should");
270349cc55cSDimitry Andric     OutStreamer->emitRawComment(
271349cc55cSDimitry Andric         "copy all variables from program memory to RAM on startup");
272349cc55cSDimitry Andric     OutStreamer->emitSymbolAttribute(DoCopyData, MCSA_Global);
273bdd1243dSDimitry Andric   }
274349cc55cSDimitry Andric 
275bdd1243dSDimitry Andric   if (NeedsClearBSS) {
276349cc55cSDimitry Andric     OutStreamer->emitRawComment(
277349cc55cSDimitry Andric         " Declaring this symbol tells the CRT that it should");
278349cc55cSDimitry Andric     OutStreamer->emitRawComment("clear the zeroed data section on startup");
279349cc55cSDimitry Andric     OutStreamer->emitSymbolAttribute(DoClearBss, MCSA_Global);
280bdd1243dSDimitry Andric   }
281349cc55cSDimitry Andric 
282349cc55cSDimitry Andric   return AsmPrinter::doFinalization(M);
283349cc55cSDimitry Andric }
284349cc55cSDimitry Andric 
28581ad6265SDimitry Andric void AVRAsmPrinter::emitStartOfAsmFile(Module &M) {
28681ad6265SDimitry Andric   const AVRTargetMachine &TM = (const AVRTargetMachine &)MMI->getTarget();
28781ad6265SDimitry Andric   const AVRSubtarget *SubTM = (const AVRSubtarget *)TM.getSubtargetImpl();
28881ad6265SDimitry Andric   if (!SubTM)
28981ad6265SDimitry Andric     return;
29081ad6265SDimitry Andric 
29181ad6265SDimitry Andric   // Emit __tmp_reg__.
29281ad6265SDimitry Andric   OutStreamer->emitAssignment(
29381ad6265SDimitry Andric       MMI->getContext().getOrCreateSymbol(StringRef("__tmp_reg__")),
29481ad6265SDimitry Andric       MCConstantExpr::create(SubTM->getRegTmpIndex(), MMI->getContext()));
29581ad6265SDimitry Andric   // Emit __zero_reg__.
29681ad6265SDimitry Andric   OutStreamer->emitAssignment(
29781ad6265SDimitry Andric       MMI->getContext().getOrCreateSymbol(StringRef("__zero_reg__")),
29881ad6265SDimitry Andric       MCConstantExpr::create(SubTM->getRegZeroIndex(), MMI->getContext()));
29981ad6265SDimitry Andric   // Emit __SREG__.
30081ad6265SDimitry Andric   OutStreamer->emitAssignment(
30181ad6265SDimitry Andric       MMI->getContext().getOrCreateSymbol(StringRef("__SREG__")),
30281ad6265SDimitry Andric       MCConstantExpr::create(SubTM->getIORegSREG(), MMI->getContext()));
30381ad6265SDimitry Andric   // Emit __SP_H__ if available.
30481ad6265SDimitry Andric   if (!SubTM->hasSmallStack())
30581ad6265SDimitry Andric     OutStreamer->emitAssignment(
30681ad6265SDimitry Andric         MMI->getContext().getOrCreateSymbol(StringRef("__SP_H__")),
30781ad6265SDimitry Andric         MCConstantExpr::create(SubTM->getIORegSPH(), MMI->getContext()));
30881ad6265SDimitry Andric   // Emit __SP_L__.
30981ad6265SDimitry Andric   OutStreamer->emitAssignment(
31081ad6265SDimitry Andric       MMI->getContext().getOrCreateSymbol(StringRef("__SP_L__")),
31181ad6265SDimitry Andric       MCConstantExpr::create(SubTM->getIORegSPL(), MMI->getContext()));
31281ad6265SDimitry Andric   // Emit __EIND__ if available.
31381ad6265SDimitry Andric   if (SubTM->hasEIJMPCALL())
31481ad6265SDimitry Andric     OutStreamer->emitAssignment(
31581ad6265SDimitry Andric         MMI->getContext().getOrCreateSymbol(StringRef("__EIND__")),
31681ad6265SDimitry Andric         MCConstantExpr::create(SubTM->getIORegEIND(), MMI->getContext()));
31781ad6265SDimitry Andric   // Emit __RAMPZ__ if available.
31881ad6265SDimitry Andric   if (SubTM->hasELPM())
31981ad6265SDimitry Andric     OutStreamer->emitAssignment(
32081ad6265SDimitry Andric         MMI->getContext().getOrCreateSymbol(StringRef("__RAMPZ__")),
32181ad6265SDimitry Andric         MCConstantExpr::create(SubTM->getIORegRAMPZ(), MMI->getContext()));
32281ad6265SDimitry Andric }
32381ad6265SDimitry Andric 
3240b57cec5SDimitry Andric } // end of namespace llvm
3250b57cec5SDimitry Andric 
326480093f4SDimitry Andric extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRAsmPrinter() {
3270b57cec5SDimitry Andric   llvm::RegisterAsmPrinter<llvm::AVRAsmPrinter> X(llvm::getTheAVRTarget());
3280b57cec5SDimitry Andric }
329