mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[AVR] Add the AVRMCInstLower class
Summary: This class deals with the lowering of CodeGen `MachineInstr` objects to MC `MCInst` objects. Reviewers: kparzysz, arsenm Subscribers: wdng, beanz, japaric, mgorny Differential Revision: https://reviews.llvm.org/D25269 llvm-svn: 283522
This commit is contained in:
parent
c295321dee
commit
da0a66f223
100
lib/Target/AVR/AVRMCInstLower.cpp
Normal file
100
lib/Target/AVR/AVRMCInstLower.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
//===-- AVRMCInstLower.cpp - Convert AVR MachineInstr to an MCInst --------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains code to lower AVR MachineInstrs to their corresponding
|
||||
// MCInst records.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "AVRMCInstLower.h"
|
||||
|
||||
#include "AVRInstrInfo.h"
|
||||
#include "MCTargetDesc/AVRMCExpr.h"
|
||||
|
||||
#include "llvm/CodeGen/AsmPrinter.h"
|
||||
#include "llvm/IR/Mangler.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
MCOperand AVRMCInstLower::lowerSymbolOperand(const MachineOperand &MO,
|
||||
MCSymbol *Sym) const {
|
||||
unsigned char TF = MO.getTargetFlags();
|
||||
const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
|
||||
|
||||
bool IsNegated = false;
|
||||
if (TF & AVRII::MO_NEG) { IsNegated = true; }
|
||||
|
||||
if (!MO.isJTI() && MO.getOffset()) {
|
||||
Expr = MCBinaryExpr::createAdd(
|
||||
Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
|
||||
}
|
||||
|
||||
if (TF & AVRII::MO_LO) {
|
||||
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_LO8, Expr, IsNegated, Ctx);
|
||||
} else if (TF & AVRII::MO_HI) {
|
||||
Expr = AVRMCExpr::create(AVRMCExpr::VK_AVR_HI8, Expr, IsNegated, Ctx);
|
||||
} else if (TF != 0) {
|
||||
llvm_unreachable("Unknown target flag on symbol operand");
|
||||
}
|
||||
|
||||
return MCOperand::createExpr(Expr);
|
||||
}
|
||||
|
||||
void AVRMCInstLower::lowerInstruction(const MachineInstr &MI, MCInst &OutMI) const {
|
||||
OutMI.setOpcode(MI.getOpcode());
|
||||
|
||||
for (MachineOperand const &MO : MI.operands()) {
|
||||
MCOperand MCOp;
|
||||
|
||||
switch (MO.getType()) {
|
||||
default:
|
||||
MI.dump();
|
||||
llvm_unreachable("unknown operand type");
|
||||
case MachineOperand::MO_Register:
|
||||
// Ignore all implicit register operands.
|
||||
if (MO.isImplicit())
|
||||
continue;
|
||||
MCOp = MCOperand::createReg(MO.getReg());
|
||||
break;
|
||||
case MachineOperand::MO_Immediate:
|
||||
MCOp = MCOperand::createImm(MO.getImm());
|
||||
break;
|
||||
case MachineOperand::MO_GlobalAddress:
|
||||
MCOp = lowerSymbolOperand(MO, Printer.getSymbol(MO.getGlobal()));
|
||||
break;
|
||||
case MachineOperand::MO_ExternalSymbol:
|
||||
MCOp = lowerSymbolOperand(
|
||||
MO, Printer.GetExternalSymbolSymbol(MO.getSymbolName()));
|
||||
break;
|
||||
case MachineOperand::MO_MachineBasicBlock:
|
||||
MCOp = MCOperand::createExpr(
|
||||
MCSymbolRefExpr::create(MO.getMBB()->getSymbol(), Ctx));
|
||||
break;
|
||||
case MachineOperand::MO_RegisterMask:
|
||||
continue;
|
||||
case MachineOperand::MO_BlockAddress:
|
||||
MCOp = lowerSymbolOperand(
|
||||
MO, Printer.GetBlockAddressSymbol(MO.getBlockAddress()));
|
||||
break;
|
||||
case MachineOperand::MO_JumpTableIndex:
|
||||
MCOp = lowerSymbolOperand(MO, Printer.GetJTISymbol(MO.getIndex()));
|
||||
break;
|
||||
case MachineOperand::MO_ConstantPoolIndex:
|
||||
MCOp = lowerSymbolOperand(MO, Printer.GetCPISymbol(MO.getIndex()));
|
||||
break;
|
||||
}
|
||||
|
||||
OutMI.addOperand(MCOp);
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace llvm
|
||||
|
43
lib/Target/AVR/AVRMCInstLower.h
Normal file
43
lib/Target/AVR/AVRMCInstLower.h
Normal file
@ -0,0 +1,43 @@
|
||||
//===-- AVRMCInstLower.h - Lower MachineInstr to MCInst ---------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_AVR_MCINST_LOWER_H
|
||||
#define LLVM_AVR_MCINST_LOWER_H
|
||||
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class AsmPrinter;
|
||||
class MachineInstr;
|
||||
class MachineOperand;
|
||||
class MCContext;
|
||||
class MCInst;
|
||||
class MCOperand;
|
||||
class MCSymbol;
|
||||
|
||||
/// Lowers `MachineInstr` objects into `MCInst` objects.
|
||||
class AVRMCInstLower {
|
||||
public:
|
||||
AVRMCInstLower(MCContext &Ctx, AsmPrinter &Printer)
|
||||
: Ctx(Ctx), Printer(Printer) {}
|
||||
|
||||
/// Lowers a `MachineInstr` into a `MCInst`.
|
||||
void lowerInstruction(const MachineInstr &MI, MCInst &OutMI) const;
|
||||
MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
|
||||
|
||||
private:
|
||||
MCContext &Ctx;
|
||||
AsmPrinter &Printer;
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_AVR_MCINST_LOWER_H
|
||||
|
@ -10,6 +10,7 @@ add_public_tablegen_target(AVRCommonTableGen)
|
||||
add_llvm_target(AVRCodeGen
|
||||
AVRFrameLowering.cpp
|
||||
AVRInstrInfo.cpp
|
||||
AVRMCInstLower.cpp
|
||||
AVRRegisterInfo.cpp
|
||||
AVRSubtarget.cpp
|
||||
AVRTargetMachine.cpp
|
||||
|
Loading…
x
Reference in New Issue
Block a user