LLVM  14.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 
27 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/MC/MCInstrDesc.h"
35 
36 #include <cassert>
37 
38 namespace llvm {
39 namespace M68k {
40 static 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).
48 static 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...
58 static inline const MachineInstrBuilder &
59 addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset = 0) {
60  MachineInstr *MI = MIB;
61  MachineFunction &MF = *MI->getParent()->getParent();
62  MachineFrameInfo &MFI = MF.getFrameInfo();
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 
75 static inline const MachineInstrBuilder &
76 addMemOperand(const MachineInstrBuilder &MIB, int FI, int Offset = 0) {
77  MachineInstr *MI = MIB;
78  MachineFunction &MF = *MI->getParent()->getParent();
79  MachineFrameInfo &MFI = MF.getFrameInfo();
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_M6800_M6800INSTRBUILDER_H
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
MachineInstr.h
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition: MachineInstrBuilder.h:131
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
MCInstrDesc.h
llvm::M68k::addMemOperand
static const MachineInstrBuilder & addMemOperand(const MachineInstrBuilder &MIB, int FI, int Offset=0)
Definition: M68kInstrBuilder.h:76
llvm::MachineFunction::getMachineMemOperand
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.
Definition: MachineFunction.cpp:431
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:128
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::MCInstrDesc
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:195
llvm::M68k::addFrameReference
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...
Definition: M68kInstrBuilder.h:59
llvm::M68k::addRegIndirectWithDisp
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,...
Definition: M68kInstrBuilder.h:49
llvm::MachineInstrBuilder::addFrameIndex
const MachineInstrBuilder & addFrameIndex(int Idx) const
Definition: MachineInstrBuilder.h:152
llvm::MCInstrDesc::mayLoad
bool mayLoad() const
Return true if this instruction could possibly read memory.
Definition: MCInstrDesc.h:429
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MachineInstrBuilder
Definition: MachineInstrBuilder.h:69
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition: MachineFrameInfo.h:453
llvm::M68k::addOffset
static const MachineInstrBuilder & addOffset(const MachineInstrBuilder &MIB, int Offset)
Definition: M68kInstrBuilder.h:41
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition: MachineFrameInfo.h:467
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:650
llvm::MachineInstrBuilder::addMemOperand
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Definition: MachineInstrBuilder.h:202
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition: MachineInstrBuilder.h:97
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::MCInstrDesc::mayStore
bool mayStore() const
Return true if this instruction could possibly modify memory.
Definition: MCInstrDesc.h:435
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:135
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MachineFrameInfo.h
llvm::MachineMemOperand::MOStore
@ MOStore
The memory access writes data.
Definition: MachineMemOperand.h:137
llvm::getKillRegState
unsigned getKillRegState(bool B)
Definition: MachineInstrBuilder.h:508
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
SmallVector.h
llvm::MachinePointerInfo::getFixedStack
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Definition: MachineOperand.cpp:1008
MachineInstrBuilder.h
MachineMemOperand.h
MachineOperand.h
MachineFunction.h
llvm::MachineMemOperand::MONone
@ MONone
Definition: MachineMemOperand.h:133