LLVM 18.0.0git
Go to the documentation of this file.
1//===-- M68kInstrBuilder.h - Functions to build M68k insts ------*- C++ -*-===//
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
9/// \file
10/// This file exposes functions that may be used with BuildMI from the
11/// MachineInstrBuilder.h file to handle M68k'isms in a clean way.
13/// TODO The BuildMem function may be used with the BuildMI function to add
14/// entire memory references in a single, typed, function call. M68k memory
15/// references can be very complex expressions (described in the README), so
16/// wrapping them up behind an easier to use interface makes sense.
17/// Descriptions of the functions are included below.
19/// For reference, the order of operands for memory references is:
20/// (Operand), Base, Scale, Index, Displacement.
34#include "llvm/MC/MCInstrDesc.h"
36#include <cassert>
38namespace llvm {
39namespace M68k {
40static inline const MachineInstrBuilder &
42 return MIB.addImm(Offset);
45/// addRegIndirectWithDisp - This function is used to add a memory reference
46/// of the form (Offset, Base), i.e., one with no scale or index, but with a
47/// displacement. An example is: (4,D0).
48static inline const MachineInstrBuilder &
50 bool IsKill, int Offset) {
51 return MIB.addImm(Offset).addReg(Reg, getKillRegState(IsKill));
54/// addFrameReference - This function is used to add a reference to the base of
55/// an abstract object on the stack frame of the current function. This
56/// reference has base register as the FrameIndex offset until it is resolved.
57/// This allows a constant offset to be specified as well...
58static inline const MachineInstrBuilder &
59addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset = 0) {
60 MachineInstr *MI = MIB;
61 MachineFunction &MF = *MI->getParent()->getParent();
63 const MCInstrDesc &MCID = MI->getDesc();
64 auto Flags = MachineMemOperand::MONone;
65 if (MCID.mayLoad())
67 if (MCID.mayStore())
71 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
72 return MIB.addImm(Offset).addFrameIndex(FI).addMemOperand(MMO);
75static inline const MachineInstrBuilder &
76addMemOperand(const MachineInstrBuilder &MIB, int FI, int Offset = 0) {
77 MachineInstr *MI = MIB;
78 MachineFunction &MF = *MI->getParent()->getParent();
80 const MCInstrDesc &MCID = MI->getDesc();
81 auto Flags = MachineMemOperand::MONone;
82 if (MCID.mayLoad())
84 if (MCID.mayStore())
88 MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
89 return MIB.addMemOperand(MMO);
91} // end namespace M68k
92} // end namespace llvm
IRTranslator LLVM IR MI
unsigned Reg
This file defines the SmallVector class.
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:198
bool mayStore() const
Return true if this instruction could possibly modify memory.
Definition: MCInstrDesc.h:444
bool mayLoad() const
Return true if this instruction could possibly read memory.
Definition: MCInstrDesc.h:438
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
Definition: MachineInstr.h:68
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static const MachineInstrBuilder & addMemOperand(const MachineInstrBuilder &MIB, int FI, int Offset=0)
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
static const MachineInstrBuilder & addRegIndirectWithDisp(const MachineInstrBuilder &MIB, Register Reg, bool IsKill, int Offset)
addRegIndirectWithDisp - This function is used to add a memory reference of the form (Offset,...
static const MachineInstrBuilder & addOffset(const MachineInstrBuilder &MIB, int Offset)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
unsigned getKillRegState(bool B)
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.