Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp
//=- LoongArchMCInstLower.cpp - Convert LoongArch MachineInstr to an MCInst -=// | //=- LoongArchMCInstLower.cpp - Convert LoongArch MachineInstr to an MCInst -=// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// This file contains code to lower LoongArch MachineInstrs to their | // This file contains code to lower LoongArch MachineInstrs to their | ||||
// corresponding MCInst records. | // corresponding MCInst records. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "LoongArch.h" | #include "LoongArch.h" | ||||
#include "LoongArchSubtarget.h" | #include "LoongArchSubtarget.h" | ||||
#include "MCTargetDesc/LoongArchBaseInfo.h" | |||||
#include "MCTargetDesc/LoongArchMCExpr.h" | |||||
#include "llvm/CodeGen/AsmPrinter.h" | #include "llvm/CodeGen/AsmPrinter.h" | ||||
#include "llvm/CodeGen/MachineBasicBlock.h" | #include "llvm/CodeGen/MachineBasicBlock.h" | ||||
#include "llvm/CodeGen/MachineInstr.h" | #include "llvm/CodeGen/MachineInstr.h" | ||||
#include "llvm/MC/MCAsmInfo.h" | #include "llvm/MC/MCAsmInfo.h" | ||||
#include "llvm/MC/MCContext.h" | #include "llvm/MC/MCContext.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
using namespace llvm; | using namespace llvm; | ||||
static MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym, | static MCOperand lowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym, | ||||
const AsmPrinter &AP) { | const AsmPrinter &AP) { | ||||
MCContext &Ctx = AP.OutContext; | MCContext &Ctx = AP.OutContext; | ||||
LoongArchMCExpr::VariantKind Kind; | |||||
// TODO: Processing target flags. | switch (MO.getTargetFlags()) { | ||||
default: | |||||
llvm_unreachable("Unknown target flag on GV operand"); | |||||
case LoongArchII::MO_None: | |||||
Kind = LoongArchMCExpr::VK_LoongArch_None; | |||||
break; | |||||
case LoongArchII::MO_CALL: | |||||
Kind = LoongArchMCExpr::VK_LoongArch_CALL; | |||||
break; | |||||
case LoongArchII::MO_CALL_PLT: | |||||
Kind = LoongArchMCExpr::VK_LoongArch_CALL_PLT; | |||||
break; | |||||
case LoongArchII::MO_PCREL_HI: | |||||
Kind = LoongArchMCExpr::VK_LoongArch_PCREL_HI; | |||||
break; | |||||
case LoongArchII::MO_PCREL_LO: | |||||
Kind = LoongArchMCExpr::VK_LoongArch_PCREL_LO; | |||||
break; | |||||
// TODO: Handle more target-flags. | |||||
} | |||||
const MCExpr *ME = | const MCExpr *ME = | ||||
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx); | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx); | ||||
if (!MO.isJTI() && !MO.isMBB() && MO.getOffset()) | if (!MO.isJTI() && !MO.isMBB() && MO.getOffset()) | ||||
ME = MCBinaryExpr::createAdd( | ME = MCBinaryExpr::createAdd( | ||||
ME, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx); | ME, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx); | ||||
if (Kind != LoongArchMCExpr::VK_LoongArch_None) | |||||
ME = LoongArchMCExpr::create(ME, Kind, Ctx); | |||||
return MCOperand::createExpr(ME); | return MCOperand::createExpr(ME); | ||||
} | } | ||||
bool llvm::lowerLoongArchMachineOperandToMCOperand(const MachineOperand &MO, | bool llvm::lowerLoongArchMachineOperandToMCOperand(const MachineOperand &MO, | ||||
MCOperand &MCOp, | MCOperand &MCOp, | ||||
const AsmPrinter &AP) { | const AsmPrinter &AP) { | ||||
switch (MO.getType()) { | switch (MO.getType()) { | ||||
default: | default: | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |