LLVM  9.0.0svn
LanaiMCInstLower.cpp
Go to the documentation of this file.
1 //=-- LanaiMCInstLower.cpp - Convert Lanai MachineInstr to an 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 // This file contains code to lower Lanai MachineInstrs to their corresponding
10 // MCInst records.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "LanaiMCInstLower.h"
15 
18 #include "llvm/ADT/SmallString.h"
22 #include "llvm/IR/Constants.h"
23 #include "llvm/MC/MCAsmInfo.h"
24 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCInst.h"
29 
30 using namespace llvm;
31 
32 MCSymbol *
34  return Printer.getSymbol(MO.getGlobal());
35 }
36 
37 MCSymbol *
39  return Printer.GetBlockAddressSymbol(MO.getBlockAddress());
40 }
41 
42 MCSymbol *
44  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
45 }
46 
49  raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "JTI"
50  << Printer.getFunctionNumber() << '_'
51  << MO.getIndex();
52  // Create a symbol for the name.
53  return Ctx.getOrCreateSymbol(Name.str());
54 }
55 
56 MCSymbol *
59  raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "CPI"
60  << Printer.getFunctionNumber() << '_'
61  << MO.getIndex();
62  // Create a symbol for the name.
63  return Ctx.getOrCreateSymbol(Name.str());
64 }
65 
67  MCSymbol *Sym) const {
69 
70  switch (MO.getTargetFlags()) {
73  break;
74  case LanaiII::MO_ABS_HI:
76  break;
77  case LanaiII::MO_ABS_LO:
79  break;
80  default:
81  llvm_unreachable("Unknown target flag on GV operand");
82  }
83 
84  const MCExpr *Expr =
86  if (!MO.isJTI() && MO.getOffset())
88  Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
89  Expr = LanaiMCExpr::create(Kind, Expr, Ctx);
90  return MCOperand::createExpr(Expr);
91 }
92 
93 void LanaiMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
94  OutMI.setOpcode(MI->getOpcode());
95 
96  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
97  const MachineOperand &MO = MI->getOperand(I);
98 
99  MCOperand MCOp;
100  switch (MO.getType()) {
102  // Ignore all implicit register operands.
103  if (MO.isImplicit())
104  continue;
105  MCOp = MCOperand::createReg(MO.getReg());
106  break;
108  MCOp = MCOperand::createImm(MO.getImm());
109  break;
111  MCOp = MCOperand::createExpr(
113  break;
115  continue;
118  break;
121  break;
124  break;
126  MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
127  break;
130  break;
131  default:
132  MI->print(errs());
133  llvm_unreachable("unknown operand type");
134  }
135 
136  OutMI.addOperand(MCOp);
137  }
138 }
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:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:136
Address of indexed Jump Table for switch.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:509
MachineBasicBlock reference.
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:497
static const LanaiMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: LanaiMCExpr.cpp:17
Mask of preserved registers.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:115
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:414
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:411
const char * getSymbolName() const
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:266
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:158
Address of a global value.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
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:210
void setOpcode(unsigned Op)
Definition: MCInst.h:170
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:443
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:127
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
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:183
Address of indexed Constant in Constant Pool.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:416
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:122
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:163
bool isImplicit() const
void Lower(const MachineInstr *MI, MCInst &OutMI) const