LLVM  8.0.1
LanaiMCInstLower.cpp
Go to the documentation of this file.
1 //=-- LanaiMCInstLower.cpp - Convert Lanai 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 Lanai MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "LanaiMCInstLower.h"
16 
19 #include "llvm/ADT/SmallString.h"
23 #include "llvm/IR/Constants.h"
24 #include "llvm/MC/MCAsmInfo.h"
25 #include "llvm/MC/MCContext.h"
26 #include "llvm/MC/MCExpr.h"
27 #include "llvm/MC/MCInst.h"
30 
31 using namespace llvm;
32 
33 MCSymbol *
35  return Printer.getSymbol(MO.getGlobal());
36 }
37 
38 MCSymbol *
40  return Printer.GetBlockAddressSymbol(MO.getBlockAddress());
41 }
42 
43 MCSymbol *
45  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
46 }
47 
50  raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "JTI"
51  << Printer.getFunctionNumber() << '_'
52  << MO.getIndex();
53  // Create a symbol for the name.
54  return Ctx.getOrCreateSymbol(Name.str());
55 }
56 
57 MCSymbol *
60  raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "CPI"
61  << Printer.getFunctionNumber() << '_'
62  << MO.getIndex();
63  // Create a symbol for the name.
64  return Ctx.getOrCreateSymbol(Name.str());
65 }
66 
68  MCSymbol *Sym) const {
70 
71  switch (MO.getTargetFlags()) {
74  break;
75  case LanaiII::MO_ABS_HI:
77  break;
78  case LanaiII::MO_ABS_LO:
80  break;
81  default:
82  llvm_unreachable("Unknown target flag on GV operand");
83  }
84 
85  const MCExpr *Expr =
87  if (!MO.isJTI() && MO.getOffset())
89  Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
90  Expr = LanaiMCExpr::create(Kind, Expr, Ctx);
91  return MCOperand::createExpr(Expr);
92 }
93 
94 void LanaiMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
95  OutMI.setOpcode(MI->getOpcode());
96 
97  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
98  const MachineOperand &MO = MI->getOperand(I);
99 
100  MCOperand MCOp;
101  switch (MO.getType()) {
103  // Ignore all implicit register operands.
104  if (MO.isImplicit())
105  continue;
106  MCOp = MCOperand::createReg(MO.getReg());
107  break;
109  MCOp = MCOperand::createImm(MO.getImm());
110  break;
112  MCOp = MCOperand::createExpr(
114  break;
116  continue;
119  break;
122  break;
125  break;
127  MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
128  break;
131  break;
132  default:
133  MI->print(errs());
134  llvm_unreachable("unknown operand type");
135  }
136 
137  OutMI.addOperand(MCOp);
138  }
139 }
unsigned getTargetFlags() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MachineBasicBlock * getMBB() const
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
unsigned getReg() const
getReg - Returns the register number.
Address of indexed Jump Table for switch.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
MachineBasicBlock reference.
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:491
static const LanaiMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: LanaiMCExpr.cpp:18
Mask of preserved registers.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:412
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
const char * getSymbolName() const
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:267
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:461
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
Address of a global value.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:85
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const GlobalValue * getGlobal() const
MCSymbol * GetBlockAddressSymbol(const MachineOperand &MO) const
Address of a basic block.
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
MCSymbol * GetConstantPoolIndexSymbol(const MachineOperand &MO) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:208
void setOpcode(unsigned Op)
Definition: MCInst.h:173
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:430
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
MCSymbol * GetGlobalAddressSymbol(const MachineOperand &MO) const
MCSymbol * GetExternalSymbolSymbol(const MachineOperand &MO) const
Representation of each machine instruction.
Definition: MachineInstr.h:64
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
#define I(x, y, z)
Definition: MD5.cpp:58
MCSymbol * GetJumpTableSymbol(const MachineOperand &MO) const
const unsigned Kind
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:186
Address of indexed Constant in Constant Pool.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:123
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
bool isImplicit() const
void Lower(const MachineInstr *MI, MCInst &OutMI) const