LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AArch64MCInstLower.cpp
Go to the documentation of this file.
1 //===-- AArch64MCInstLower.cpp - Convert AArch64 MachineInstr to an MCInst -==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains code to lower AArch64 MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "AArch64AsmPrinter.h"
16 #include "AArch64TargetMachine.h"
18 #include "Utils/AArch64BaseInfo.h"
19 #include "llvm/ADT/SmallString.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCInst.h"
26 #include "llvm/Target/Mangler.h"
27 
28 using namespace llvm;
29 
32  const MCSymbol *Sym) const {
33  const MCExpr *Expr = 0;
34 
36 
37  switch (MO.getTargetFlags()) {
38  case AArch64II::MO_GOT:
40  break;
43  break;
44  case AArch64II::MO_LO12:
46  break;
49  break;
52  break;
55  break;
58  break;
61  break;
64  break;
67  break;
70  break;
73  break;
76  break;
79  break;
82  break;
84  // Expr is already correct
85  break;
86  default:
87  llvm_unreachable("Unexpected MachineOperand flag");
88  }
89 
90  if (!MO.isJTI() && MO.getOffset())
91  Expr = MCBinaryExpr::CreateAdd(Expr,
93  OutContext),
94  OutContext);
95 
96  return MCOperand::CreateExpr(Expr);
97 }
98 
100  MCOperand &MCOp) const {
101  switch (MO.getType()) {
102  default: llvm_unreachable("unknown operand type");
104  if (MO.isImplicit())
105  return false;
106  assert(!MO.getSubReg() && "Subregs should be eliminated!");
107  MCOp = MCOperand::CreateReg(MO.getReg());
108  break;
110  MCOp = MCOperand::CreateImm(MO.getImm());
111  break;
113  assert(MO.getFPImm()->isZero() && "Only fp imm 0.0 is supported");
114  MCOp = MCOperand::CreateFPImm(0.0);
115  break;
116  }
119  break;
122  break;
124  MCOp = lowerSymbolOperand(MO, getSymbol(MO.getGlobal()));
125  break;
128  MO.getMBB()->getSymbol(), OutContext));
129  break;
131  MCOp = lowerSymbolOperand(MO, GetJTISymbol(MO.getIndex()));
132  break;
134  MCOp = lowerSymbolOperand(MO, GetCPISymbol(MO.getIndex()));
135  break;
137  // Ignore call clobbers
138  return false;
139 
140  }
141 
142  return true;
143 }
144 
146  MCInst &OutMI,
147  AArch64AsmPrinter &AP) {
148  OutMI.setOpcode(MI->getOpcode());
149 
150  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
151  const MachineOperand &MO = MI->getOperand(i);
152 
153  MCOperand MCOp;
154  if (AP.lowerOperand(MO, MCOp))
155  OutMI.addOperand(MCOp);
156  }
157 }
bool isImplicit() const
const GlobalValue * getGlobal() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:277
static MCOperand CreateReg(unsigned Reg)
Definition: MCInst.h:111
const ConstantFP * getFPImm() const
MachineBasicBlock * getMBB() const
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:152
MCContext & OutContext
Definition: AsmPrinter.h:72
void LowerAArch64MachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AArch64AsmPrinter &AP)
static MCOperand CreateExpr(const MCExpr *Val)
Definition: MCInst.h:129
static const AArch64MCExpr * CreateTLSDesc(const MCExpr *Expr, MCContext &Ctx)
const char * getSymbolName() const
Address of indexed Jump Table for switch.
static const AArch64MCExpr * CreateDTPREL_G1(const MCExpr *Expr, MCContext &Ctx)
Definition: AArch64MCExpr.h:96
static const AArch64MCExpr * CreateABS_G2_NC(const MCExpr *Expr, MCContext &Ctx)
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
static const AArch64MCExpr * CreateGOTTPRELLo12(const MCExpr *Expr, MCContext &Ctx)
#define llvm_unreachable(msg)
static const AArch64MCExpr * CreateDTPREL_G0_NC(const MCExpr *Expr, MCContext &Ctx)
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
GetJTISymbol - Return the symbol for the specified jump table entry.
unsigned getNumOperands() const
Definition: MachineInstr.h:265
static const AArch64MCExpr * CreateTPREL_G1(const MCExpr *Expr, MCContext &Ctx)
int getOpcode() const
Definition: MachineInstr.h:261
bool isZero() const
isZero - Return true if the value is positive or negative zero.
Definition: Constants.h:266
int64_t getImm() const
Address of indexed Constant in Constant Pool.
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
unsigned getTargetFlags() const
static const AArch64MCExpr * CreateABS_G1_NC(const MCExpr *Expr, MCContext &Ctx)
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
static const AArch64MCExpr * CreateLo12(const MCExpr *Expr, MCContext &Ctx)
Definition: AArch64MCExpr.h:83
static const AArch64MCExpr * CreateGOTLo12(const MCExpr *Expr, MCContext &Ctx)
Definition: AArch64MCExpr.h:91
int64_t getOffset() const
Floating-point immediate operand.
unsigned getSubReg() const
MCSymbol * getSymbol() const
void setOpcode(unsigned Op)
Definition: MCInst.h:157
static const AArch64MCExpr * CreateTLSDescLo12(const MCExpr *Expr, MCContext &Ctx)
static const AArch64MCExpr * CreateTPREL_G0_NC(const MCExpr *Expr, MCContext &Ctx)
MCOperand lowerSymbolOperand(const MachineOperand &MO, const MCSymbol *Sym) const
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:396
MachineOperandType getType() const
static MCOperand CreateImm(int64_t Val)
Definition: MCInst.h:117
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
static MCOperand CreateFPImm(double Val)
Definition: MCInst.h:123
Mask of preserved registers.
static const AArch64MCExpr * CreateGOTTPREL(const MCExpr *Expr, MCContext &Ctx)
static const AArch64MCExpr * CreateABS_G0_NC(const MCExpr *Expr, MCContext &Ctx)
MCSymbol * GetCPISymbol(unsigned CPID) const
GetCPISymbol - Return the symbol for the specified constant pool entry.
unsigned getReg() const
getReg - Returns the register number.
static const AArch64MCExpr * CreateABS_G3(const MCExpr *Expr, MCContext &Ctx)
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const
Address of a basic block.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:167
const BlockAddress * getBlockAddress() const
static const AArch64MCExpr * CreateGOT(const MCExpr *Expr, MCContext &Ctx)
Definition: AArch64MCExpr.h:87
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
MachineBasicBlock reference.
Address of a global value.
Name of external global symbol.