Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/M68kInstrBuilder.h
35269 views
//===-- M68kInstrBuilder.h - Functions to build M68k insts ------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file exposes functions that may be used with BuildMI from the10/// MachineInstrBuilder.h file to handle M68k'isms in a clean way.11///12/// TODO The BuildMem function may be used with the BuildMI function to add13/// entire memory references in a single, typed, function call. M68k memory14/// references can be very complex expressions (described in the README), so15/// wrapping them up behind an easier to use interface makes sense.16/// Descriptions of the functions are included below.17///18/// For reference, the order of operands for memory references is:19/// (Operand), Base, Scale, Index, Displacement.20///21//===----------------------------------------------------------------------===//22//23#ifndef LLVM_LIB_TARGET_M68K_M68KINSTRBUILDER_H24#define LLVM_LIB_TARGET_M68K_M68KINSTRBUILDER_H2526#include "llvm/ADT/SmallVector.h"27#include "llvm/CodeGen/MachineFrameInfo.h"28#include "llvm/CodeGen/MachineFunction.h"29#include "llvm/CodeGen/MachineInstr.h"30#include "llvm/CodeGen/MachineInstrBuilder.h"31#include "llvm/CodeGen/MachineMemOperand.h"32#include "llvm/CodeGen/MachineOperand.h"33#include "llvm/MC/MCInstrDesc.h"3435#include <cassert>3637namespace llvm {38namespace M68k {39static inline const MachineInstrBuilder &40addOffset(const MachineInstrBuilder &MIB, int Offset) {41return MIB.addImm(Offset);42}4344/// addRegIndirectWithDisp - This function is used to add a memory reference45/// of the form (Offset, Base), i.e., one with no scale or index, but with a46/// displacement. An example is: (4,D0).47static inline const MachineInstrBuilder &48addRegIndirectWithDisp(const MachineInstrBuilder &MIB, Register Reg,49bool IsKill, int Offset) {50return MIB.addImm(Offset).addReg(Reg, getKillRegState(IsKill));51}5253/// addFrameReference - This function is used to add a reference to the base of54/// an abstract object on the stack frame of the current function. This55/// reference has base register as the FrameIndex offset until it is resolved.56/// This allows a constant offset to be specified as well...57static inline const MachineInstrBuilder &58addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset = 0) {59MachineInstr *MI = MIB;60MachineFunction &MF = *MI->getParent()->getParent();61MachineFrameInfo &MFI = MF.getFrameInfo();62const MCInstrDesc &MCID = MI->getDesc();63auto Flags = MachineMemOperand::MONone;64if (MCID.mayLoad())65Flags |= MachineMemOperand::MOLoad;66if (MCID.mayStore())67Flags |= MachineMemOperand::MOStore;68MachineMemOperand *MMO = MF.getMachineMemOperand(69MachinePointerInfo::getFixedStack(MF, FI, Offset), Flags,70MFI.getObjectSize(FI), MFI.getObjectAlign(FI));71return MIB.addImm(Offset).addFrameIndex(FI).addMemOperand(MMO);72}7374static inline const MachineInstrBuilder &75addMemOperand(const MachineInstrBuilder &MIB, int FI, int Offset = 0) {76MachineInstr *MI = MIB;77MachineFunction &MF = *MI->getParent()->getParent();78MachineFrameInfo &MFI = MF.getFrameInfo();79const MCInstrDesc &MCID = MI->getDesc();80auto Flags = MachineMemOperand::MONone;81if (MCID.mayLoad())82Flags |= MachineMemOperand::MOLoad;83if (MCID.mayStore())84Flags |= MachineMemOperand::MOStore;85MachineMemOperand *MMO = MF.getMachineMemOperand(86MachinePointerInfo::getFixedStack(MF, FI, Offset), Flags,87MFI.getObjectSize(FI), MFI.getObjectAlign(FI));88return MIB.addMemOperand(MMO);89}90} // end namespace M68k91} // end namespace llvm9293#endif // LLVM_LIB_TARGET_M68K_M68KINSTRBUILDER_H949596