LLVM 20.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
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
16using namespace llvm;
17
18// Return the VK_* enumeration for MachineOperand target flags Flags.
20 switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
21 case 0:
27 }
28 llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
29}
30
32 SystemZAsmPrinter &asmprinter)
33 : Ctx(ctx), AsmPrinter(asmprinter) {}
34
35const MCExpr *
38 const MCSymbol *Symbol;
39 bool HasOffset = true;
40 switch (MO.getType()) {
42 Symbol = MO.getMBB()->getSymbol();
43 HasOffset = false;
44 break;
45
47 Symbol = AsmPrinter.getSymbol(MO.getGlobal());
48 break;
49
52 break;
53
55 Symbol = AsmPrinter.GetJTISymbol(MO.getIndex());
56 HasOffset = false;
57 break;
58
60 Symbol = AsmPrinter.GetCPISymbol(MO.getIndex());
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
94void SystemZMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
95 OutMI.setOpcode(MI->getOpcode());
96 for (const MachineOperand &MO : MI->operands())
97 // Ignore all implicit register operands.
98 if (!MO.isReg() || !MO.isImplicit())
99 OutMI.addOperand(lowerOperand(MO));
100}
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned MOFlags)
IRTranslator LLVM IR MI
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:86
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:676
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
MCSymbol * GetExternalSymbolSymbol(Twine Sym) const
Return the MCSymbol for the specified ExternalSymbol.
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:532
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:193
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
void setOpcode(unsigned Op)
Definition: MCInst.h:197
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:162
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:393
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
MachineBasicBlock * getMBB() const
const BlockAddress * getBlockAddress() const
unsigned getTargetFlags() 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_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.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCOperand lowerOperand(const MachineOperand &MO) const
SystemZMCInstLower(MCContext &ctx, SystemZAsmPrinter &asmPrinter)
void lower(const MachineInstr *MI, MCInst &OutMI) const
const MCExpr * getExpr(const MachineOperand &MO, MCSymbolRefExpr::VariantKind Kind) const
#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.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480