LLVM 20.0.0git
M68kInstrBuilder.h
Go to the documentation of this file.
1//===-- M68kInstrBuilder.h - Functions to build M68k insts ------*- C++ -*-===//
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/// \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.
12///
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.
18///
19/// For reference, the order of operands for memory references is:
20/// (Operand), Base, Scale, Index, Displacement.
21///
22//===----------------------------------------------------------------------===//
23//
24#ifndef LLVM_LIB_TARGET_M68K_M68KINSTRBUILDER_H
25#define LLVM_LIB_TARGET_M68K_M68KINSTRBUILDER_H
26
34#include "llvm/MC/MCInstrDesc.h"
35
36#include <cassert>
37
38namespace llvm {
39namespace M68k {
40static inline const MachineInstrBuilder &
42 return MIB.addImm(Offset);
43}
44
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));
52}
53
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);
73}
74
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);
90}
91} // end namespace M68k
92} // end namespace llvm
93
94#endif // LLVM_LIB_TARGET_M68K_M68KINSTRBUILDER_H
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, LLT MemTy, 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:69
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:480
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.