1 //===- SystemZInstrBuilder.h - Functions to aid building insts -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes functions that may be used with BuildMI from the
11 // MachineInstrBuilder.h file to handle SystemZ'isms in a clean way.
13 // The BuildMem function may be used with the BuildMI function to add entire
14 // memory references in a single, typed, function call.
16 // For reference, the order of operands for memory references is:
17 // (Operand), Base, Displacement, Index.
19 //===----------------------------------------------------------------------===//
21 #ifndef SYSTEMZINSTRBUILDER_H
22 #define SYSTEMZINSTRBUILDER_H
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/CodeGen/MachineMemOperand.h"
27 #include "llvm/CodeGen/PseudoSourceValue.h"
31 /// SystemZAddressMode - This struct holds a generalized full x86 address mode.
32 /// The base register can be a frame index, which will eventually be replaced
33 /// with R15 or R11 and Disp being offsetted accordingly.
34 struct SystemZAddressMode
{
47 const GlobalValue
*GV
;
49 SystemZAddressMode() : BaseType(RegBase
), IndexReg(0), Disp(0) {
54 /// addDirectMem - This function is used to add a direct memory reference to the
55 /// current instruction -- that is, a dereference of an address in a register,
56 /// with no index or displacement.
58 static inline const MachineInstrBuilder
&
59 addDirectMem(const MachineInstrBuilder
&MIB
, unsigned Reg
) {
60 // Because memory references are always represented with 3
61 // values, this adds: Reg, [0, NoReg] to the instruction.
62 return MIB
.addReg(Reg
).addImm(0).addReg(0);
65 static inline const MachineInstrBuilder
&
66 addOffset(const MachineInstrBuilder
&MIB
, int Offset
) {
67 return MIB
.addImm(Offset
).addReg(0);
70 /// addRegOffset - This function is used to add a memory reference of the form
71 /// [Reg + Offset], i.e., one with no or index, but with a
72 /// displacement. An example is: 10(%r15).
74 static inline const MachineInstrBuilder
&
75 addRegOffset(const MachineInstrBuilder
&MIB
,
76 unsigned Reg
, bool isKill
, int Offset
) {
77 return addOffset(MIB
.addReg(Reg
, getKillRegState(isKill
)), Offset
);
80 /// addRegReg - This function is used to add a memory reference of the form:
82 static inline const MachineInstrBuilder
&
83 addRegReg(const MachineInstrBuilder
&MIB
,
84 unsigned Reg1
, bool isKill1
, unsigned Reg2
, bool isKill2
) {
85 return MIB
.addReg(Reg1
, getKillRegState(isKill1
)).addImm(0)
86 .addReg(Reg2
, getKillRegState(isKill2
));
89 static inline const MachineInstrBuilder
&
90 addFullAddress(const MachineInstrBuilder
&MIB
, const SystemZAddressMode
&AM
) {
91 if (AM
.BaseType
== SystemZAddressMode::RegBase
)
92 MIB
.addReg(AM
.Base
.Reg
);
93 else if (AM
.BaseType
== SystemZAddressMode::FrameIndexBase
)
94 MIB
.addFrameIndex(AM
.Base
.FrameIndex
);
98 return MIB
.addImm(AM
.Disp
).addReg(AM
.IndexReg
);
101 /// addFrameReference - This function is used to add a reference to the base of
102 /// an abstract object on the stack frame of the current function. This
103 /// reference has base register as the FrameIndex offset until it is resolved.
104 /// This allows a constant offset to be specified as well...
106 static inline const MachineInstrBuilder
&
107 addFrameReference(const MachineInstrBuilder
&MIB
, int FI
, int Offset
= 0) {
108 MachineInstr
*MI
= MIB
;
109 MachineFunction
&MF
= *MI
->getParent()->getParent();
110 MachineFrameInfo
&MFI
= *MF
.getFrameInfo();
111 const MCInstrDesc
&MCID
= MI
->getDesc();
114 Flags
|= MachineMemOperand::MOLoad
;
116 Flags
|= MachineMemOperand::MOStore
;
117 MachineMemOperand
*MMO
=
118 MF
.getMachineMemOperand(MachinePointerInfo(
119 PseudoSourceValue::getFixedStack(FI
), Offset
),
120 Flags
, MFI
.getObjectSize(FI
),
121 MFI
.getObjectAlignment(FI
));
122 return addOffset(MIB
.addFrameIndex(FI
), Offset
)
126 } // End llvm namespace