LLVM  14.0.0git
M68kAsmPrinter.cpp
Go to the documentation of this file.
1 //===----- M68kAsmPrinter.cpp - M68k LLVM Assembly Printer -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains a printer that converts from our internal representation
11 /// of machine-dependent LLVM code to GAS-format M68k assembly language.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 // TODO Conform to Motorola ASM syntax
16 
17 #include "M68kAsmPrinter.h"
18 
19 #include "M68k.h"
20 #include "M68kMachineFunction.h"
23 
24 #include "llvm/MC/TargetRegistry.h"
25 
26 using namespace llvm;
27 
28 #define DEBUG_TYPE "m68k-asm-printer"
29 
32  MCInstLowering = std::make_unique<M68kMCInstLower>(MF, *this);
34  return true;
35 }
36 
37 void M68kAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
38  raw_ostream &OS) {
39  const MachineOperand &MO = MI->getOperand(OpNum);
40  switch (MO.getType()) {
42  OS << "%" << M68kInstPrinter::getRegisterName(MO.getReg());
43  break;
45  OS << '#' << MO.getImm();
46  break;
48  MO.getMBB()->getSymbol()->print(OS, MAI);
49  break;
51  PrintSymbolOperand(MO, OS);
52  break;
55  break;
57  const DataLayout &DL = getDataLayout();
58  OS << DL.getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
59  << MO.getIndex();
60  break;
61  }
62  default:
63  llvm_unreachable("not implemented");
64  }
65 }
66 
67 bool M68kAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
68  const char *ExtraCode, raw_ostream &OS) {
69  // Print the operand if there is no operand modifier.
70  if (!ExtraCode || !ExtraCode[0]) {
71  printOperand(MI, OpNo, OS);
72  return false;
73  }
74 
75  // Fallback to the default implementation.
76  return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
77 }
78 
80  switch (MI->getOpcode()) {
81  default: {
82  if (MI->isPseudo()) {
83  LLVM_DEBUG(dbgs() << "Pseudo opcode(" << MI->getOpcode()
84  << ") found in EmitInstruction()\n");
85  llvm_unreachable("Cannot proceed");
86  }
87  break;
88  }
89  case M68k::TAILJMPj:
90  case M68k::TAILJMPq:
91  // Lower these as normal, but add some comments.
92  OutStreamer->AddComment("TAILCALL");
93  break;
94  }
95 
96  MCInst TmpInst0;
97  MCInstLowering->Lower(MI, TmpInst0);
98  OutStreamer->emitInstruction(TmpInst0, getSubtargetInfo());
99 }
100 
102 
104 
106  OutStreamer->emitSyntaxDirective();
107 }
108 
110 
113 }
llvm::MachineOperand::MO_BlockAddress
@ MO_BlockAddress
Address of a basic block.
Definition: MachineOperand.h:63
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm::MachineOperand::MO_Immediate
@ MO_Immediate
Immediate operand.
Definition: MachineOperand.h:53
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::M68kAsmPrinter::MCInstLowering
std::unique_ptr< M68kMCInstLower > MCInstLowering
Definition: M68kAsmPrinter.h:46
llvm::AsmPrinter::MAI
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:87
llvm::MachineOperand::getBlockAddress
const BlockAddress * getBlockAddress() const
Definition: MachineOperand.h:568
llvm::getTheM68kTarget
Target & getTheM68kTarget()
Definition: M68kTargetInfo.cpp:18
llvm::AsmPrinter::PrintSymbolOperand
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
Definition: AsmPrinterInlineAsm.cpp:589
M68kAsmPrinter.h
printOperand
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
Definition: SelectionDAGDumper.cpp:946
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::M68kAsmPrinter::MMFI
const M68kMachineFunctionInfo * MMFI
Definition: M68kAsmPrinter.h:45
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::MachineOperand::MO_Register
@ MO_Register
Register operand.
Definition: MachineOperand.h:52
M68k.h
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition: MachineBasicBlock.cpp:60
llvm::MachineOperand::MO_GlobalAddress
@ MO_GlobalAddress
Address of a global value.
Definition: MachineOperand.h:62
llvm::MachineOperand::getImm
int64_t getImm() const
Definition: MachineOperand.h:537
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:728
llvm::M68kAsmPrinter::emitStartOfAsmFile
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
Definition: M68kAsmPrinter.cpp:105
LLVMInitializeM68kAsmPrinter
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM68kAsmPrinter()
Definition: M68kAsmPrinter.cpp:111
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:96
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::M68kInstPrinter::getRegisterName
static const char * getRegisterName(unsigned RegNo)
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::M68kAsmPrinter::emitInstruction
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
Definition: M68kAsmPrinter.cpp:79
llvm::MCSymbol::print
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
llvm::AsmPrinter::GetBlockAddressSymbol
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
Definition: AsmPrinter.cpp:3133
llvm::M68kAsmPrinter::emitFunctionBodyEnd
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
Definition: M68kAsmPrinter.cpp:103
llvm::MachineOperand::getType
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Definition: MachineOperand.h:219
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:99
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:340
llvm::MachineOperand::getMBB
MachineBasicBlock * getMBB() const
Definition: MachineOperand.h:552
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::M68kMachineFunctionInfo
Definition: M68kMachineFunction.h:23
llvm::MachineOperand::MO_MachineBasicBlock
@ MO_MachineBasicBlock
MachineBasicBlock reference.
Definition: MachineOperand.h:56
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::M68kAsmPrinter::PrintAsmOperand
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
Definition: M68kAsmPrinter.cpp:67
llvm::M68kAsmPrinter::runOnMachineFunction
virtual bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: M68kAsmPrinter.cpp:30
llvm::AsmPrinter::getSubtargetInfo
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:237
M68kTargetInfo.h
llvm::MachineOperand::getIndex
int getIndex() const
Definition: MachineOperand.h:557
M68kMachineFunction.h
llvm::AsmPrinter::getDataLayout
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:227
llvm::RegisterAsmPrinter
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...
Definition: TargetRegistry.h:1338
llvm::M68kAsmPrinter::emitEndOfAsmFile
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
Definition: M68kAsmPrinter.cpp:109
M68kInstPrinter.h
TargetRegistry.h
llvm::AsmPrinter::getFunctionNumber
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:219
llvm::M68kAsmPrinter::emitFunctionBodyStart
void emitFunctionBodyStart() override
Targets can override this to emit stuff before the first basic block in the function.
Definition: M68kAsmPrinter.cpp:101
llvm::AsmPrinter::PrintAsmOperand
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.
Definition: AsmPrinterInlineAsm.cpp:599
llvm::MachineOperand::MO_ConstantPoolIndex
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
Definition: MachineOperand.h:58