]>
git.proxmox.com Git - rustc.git/blob - src/llvm/lib/Target/SystemZ/SystemZMCInstLower.cpp
1 //===-- SystemZMCInstLower.cpp - Lower MachineInstr to MCInst -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "SystemZMCInstLower.h"
11 #include "SystemZAsmPrinter.h"
12 #include "llvm/IR/Mangler.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCStreamer.h"
18 // Return the VK_* enumeration for MachineOperand target flags Flags.
19 static MCSymbolRefExpr::VariantKind
getVariantKind(unsigned Flags
) {
20 switch (Flags
& SystemZII::MO_SYMBOL_MODIFIER
) {
22 return MCSymbolRefExpr::VK_None
;
23 case SystemZII::MO_GOT
:
24 return MCSymbolRefExpr::VK_GOT
;
26 llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
29 SystemZMCInstLower::SystemZMCInstLower(MCContext
&ctx
,
30 SystemZAsmPrinter
&asmprinter
)
31 : Ctx(ctx
), AsmPrinter(asmprinter
) {}
34 SystemZMCInstLower::getExpr(const MachineOperand
&MO
,
35 MCSymbolRefExpr::VariantKind Kind
) const {
36 const MCSymbol
*Symbol
;
37 bool HasOffset
= true;
38 switch (MO
.getType()) {
39 case MachineOperand::MO_MachineBasicBlock
:
40 Symbol
= MO
.getMBB()->getSymbol();
44 case MachineOperand::MO_GlobalAddress
:
45 Symbol
= AsmPrinter
.getSymbol(MO
.getGlobal());
48 case MachineOperand::MO_ExternalSymbol
:
49 Symbol
= AsmPrinter
.GetExternalSymbolSymbol(MO
.getSymbolName());
52 case MachineOperand::MO_JumpTableIndex
:
53 Symbol
= AsmPrinter
.GetJTISymbol(MO
.getIndex());
57 case MachineOperand::MO_ConstantPoolIndex
:
58 Symbol
= AsmPrinter
.GetCPISymbol(MO
.getIndex());
61 case MachineOperand::MO_BlockAddress
:
62 Symbol
= AsmPrinter
.GetBlockAddressSymbol(MO
.getBlockAddress());
66 llvm_unreachable("unknown operand type");
68 const MCExpr
*Expr
= MCSymbolRefExpr::Create(Symbol
, Kind
, Ctx
);
70 if (int64_t Offset
= MO
.getOffset()) {
71 const MCExpr
*OffsetExpr
= MCConstantExpr::Create(Offset
, Ctx
);
72 Expr
= MCBinaryExpr::CreateAdd(Expr
, OffsetExpr
, Ctx
);
77 MCOperand
SystemZMCInstLower::lowerOperand(const MachineOperand
&MO
) const {
78 switch (MO
.getType()) {
79 case MachineOperand::MO_Register
:
80 return MCOperand::CreateReg(MO
.getReg());
82 case MachineOperand::MO_Immediate
:
83 return MCOperand::CreateImm(MO
.getImm());
86 MCSymbolRefExpr::VariantKind Kind
= getVariantKind(MO
.getTargetFlags());
87 return MCOperand::CreateExpr(getExpr(MO
, Kind
));
92 void SystemZMCInstLower::lower(const MachineInstr
*MI
, MCInst
&OutMI
) const {
93 OutMI
.setOpcode(MI
->getOpcode());
94 for (unsigned I
= 0, E
= MI
->getNumOperands(); I
!= E
; ++I
) {
95 const MachineOperand
&MO
= MI
->getOperand(I
);
96 // Ignore all implicit register operands.
97 if (!MO
.isReg() || !MO
.isImplicit())
98 OutMI
.addOperand(lowerOperand(MO
));