LLVM  14.0.0git
SystemZMCInstLower.cpp
Go to the documentation of this file.
1 //===-- SystemZMCInstLower.cpp - Lower MachineInstr to MCInst -------------===//
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 #include "SystemZMCInstLower.h"
10 #include "SystemZAsmPrinter.h"
11 #include "llvm/IR/Mangler.h"
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCInst.h"
14 #include "llvm/MC/MCStreamer.h"
15 
16 using namespace llvm;
17 
18 // Return the VK_* enumeration for MachineOperand target flags Flags.
20  switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
21  case 0:
23  case SystemZII::MO_GOT:
27  }
28  llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
29 }
30 
32  SystemZAsmPrinter &asmprinter)
33  : Ctx(ctx), AsmPrinter(asmprinter) {}
34 
35 const MCExpr *
38  const MCSymbol *Symbol;
39  bool HasOffset = true;
40  switch (MO.getType()) {
42  Symbol = MO.getMBB()->getSymbol();
43  HasOffset = false;
44  break;
45 
48  break;
49 
52  break;
53 
56  HasOffset = false;
57  break;
58 
61  break;
62 
65  break;
66 
67  default:
68  llvm_unreachable("unknown operand type");
69  }
70  const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Kind, Ctx);
71  if (HasOffset)
72  if (int64_t Offset = MO.getOffset()) {
73  const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, Ctx);
74  Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx);
75  }
76  return Expr;
77 }
78 
80  switch (MO.getType()) {
82  return MCOperand::createReg(MO.getReg());
83 
85  return MCOperand::createImm(MO.getImm());
86 
87  default: {
89  return MCOperand::createExpr(getExpr(MO, Kind));
90  }
91  }
92 }
93 
94 void SystemZMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
95  OutMI.setOpcode(MI->getOpcode());
96  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
97  const MachineOperand &MO = MI->getOperand(I);
98  // Ignore all implicit register operands.
99  if (!MO.isReg() || !MO.isImplicit())
100  OutMI.addOperand(lowerOperand(MO));
101  }
102 }
llvm::MachineOperand::MO_BlockAddress
@ MO_BlockAddress
Address of a basic block.
Definition: MachineOperand.h:63
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm::MachineOperand::MO_Immediate
@ MO_Immediate
Immediate operand.
Definition: MachineOperand.h:53
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCSymbolRefExpr::VK_GOT
@ VK_GOT
Definition: MCExpr.h:198
llvm::MCOperand::createExpr
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:162
llvm::SystemZMCInstLower::lowerOperand
MCOperand lowerOperand(const MachineOperand &MO) const
Definition: SystemZMCInstLower.cpp:79
llvm::MachineOperand::getGlobal
const GlobalValue * getGlobal() const
Definition: MachineOperand.h:563
llvm::MCSymbolRefExpr::VK_INDNTPOFF
@ VK_INDNTPOFF
Definition: MCExpr.h:204
llvm::MCOperand::createImm
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
getVariantKind
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags)
Definition: SystemZMCInstLower.cpp:19
llvm::MachineOperand::getBlockAddress
const BlockAddress * getBlockAddress() const
Definition: MachineOperand.h:568
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MachineOperand::getOffset
int64_t getOffset() const
Return the offset from the symbol in this operand.
Definition: MachineOperand.h:600
SystemZAsmPrinter.h
llvm::MachineOperand::MO_Register
@ MO_Register
Register operand.
Definition: MachineOperand.h:52
llvm::MCInst::setOpcode
void setOpcode(unsigned Op)
Definition: MCInst.h:197
llvm::MachineBasicBlock::getSymbol
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Definition: MachineBasicBlock.cpp:60
llvm::MachineOperand::isImplicit
bool isImplicit() const
Definition: MachineOperand.h:380
llvm::MachineOperand::MO_GlobalAddress
@ MO_GlobalAddress
Address of a global value.
Definition: MachineOperand.h:62
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MachineOperand::getImm
int64_t getImm() const
Definition: MachineOperand.h:537
llvm::SystemZMCInstLower::SystemZMCInstLower
SystemZMCInstLower(MCContext &ctx, SystemZAsmPrinter &asmPrinter)
Definition: SystemZMCInstLower.cpp:31
MCInst.h
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::SystemZMCInstLower::getExpr
const MCExpr * getExpr(const MachineOperand &MO, MCSymbolRefExpr::VariantKind Kind) const
Definition: SystemZMCInstLower.cpp:36
llvm::SystemZII::MO_INDNTPOFF
@ MO_INDNTPOFF
Definition: SystemZInstrInfo.h:74
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MCInst::addOperand
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
llvm::MachineOperand::getTargetFlags
unsigned getTargetFlags() const
Definition: MachineOperand.h:221
llvm::AsmPrinter::GetCPISymbol
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
Definition: AsmPrinter.cpp:3125
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
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:3116
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MachineOperand::getType
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Definition: MachineOperand.h:219
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:486
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::SystemZII::MO_SYMBOL_MODIFIER
@ MO_SYMBOL_MODIFIER
Definition: SystemZInstrInfo.h:68
Mangler.h
llvm::MachineOperand::MO_JumpTableIndex
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
Definition: MachineOperand.h:60
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:524
llvm::AsmPrinter::GetExternalSymbolSymbol
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
Definition: AsmPrinter.cpp:3172
llvm::MachineOperand::getMBB
MachineBasicBlock * getMBB() const
Definition: MachineOperand.h:552
llvm::SystemZMCInstLower::lower
void lower(const MachineInstr *MI, MCInst &OutMI) const
Definition: SystemZMCInstLower.cpp:94
llvm::SystemZII::MO_GOT
@ MO_GOT
Definition: SystemZInstrInfo.h:71
llvm::AsmPrinter::GetJTISymbol
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
Definition: AsmPrinter.cpp:3153
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::MCOperand::createReg
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
llvm::MachineOperand::MO_MachineBasicBlock
@ MO_MachineBasicBlock
MachineBasicBlock reference.
Definition: MachineOperand.h:56
llvm::MachineOperand::MO_ExternalSymbol
@ MO_ExternalSymbol
Name of external global symbol.
Definition: MachineOperand.h:61
llvm::MachineOperand::getIndex
int getIndex() const
Definition: MachineOperand.h:557
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MachineOperand::getSymbolName
const char * getSymbolName() const
Definition: MachineOperand.h:608
MCStreamer.h
llvm::MCOperand
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
SystemZMCInstLower.h
llvm::SystemZAsmPrinter
Definition: SystemZAsmPrinter.h:26
llvm::MachineOperand::MO_ConstantPoolIndex
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
Definition: MachineOperand.h:58