LLVM API Documentation
00001 //===- SystemZInstrBuilder.h - Functions to aid building insts -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file exposes functions that may be used with BuildMI from the 00011 // MachineInstrBuilder.h file to handle SystemZ'isms in a clean way. 00012 // 00013 // The BuildMem function may be used with the BuildMI function to add entire 00014 // memory references in a single, typed, function call. 00015 // 00016 // For reference, the order of operands for memory references is: 00017 // (Operand), Base, Displacement, Index. 00018 // 00019 //===----------------------------------------------------------------------===// 00020 00021 #ifndef SYSTEMZINSTRBUILDER_H 00022 #define SYSTEMZINSTRBUILDER_H 00023 00024 #include "llvm/CodeGen/MachineFrameInfo.h" 00025 #include "llvm/CodeGen/MachineInstrBuilder.h" 00026 #include "llvm/CodeGen/PseudoSourceValue.h" 00027 00028 namespace llvm { 00029 00030 /// SystemZAddressMode - This struct holds a generalized full x86 address mode. 00031 /// The base register can be a frame index, which will eventually be replaced 00032 /// with R15 or R11 and Disp being offsetted accordingly. 00033 struct SystemZAddressMode { 00034 enum { 00035 RegBase, 00036 FrameIndexBase 00037 } BaseType; 00038 00039 union { 00040 unsigned Reg; 00041 int FrameIndex; 00042 } Base; 00043 00044 unsigned IndexReg; 00045 int32_t Disp; 00046 GlobalValue *GV; 00047 00048 SystemZAddressMode() : BaseType(RegBase), IndexReg(0), Disp(0) { 00049 Base.Reg = 0; 00050 } 00051 }; 00052 00053 /// addDirectMem - This function is used to add a direct memory reference to the 00054 /// current instruction -- that is, a dereference of an address in a register, 00055 /// with no index or displacement. 00056 /// 00057 static inline const MachineInstrBuilder & 00058 addDirectMem(const MachineInstrBuilder &MIB, unsigned Reg) { 00059 // Because memory references are always represented with 3 00060 // values, this adds: Reg, [0, NoReg] to the instruction. 00061 return MIB.addReg(Reg).addImm(0).addReg(0); 00062 } 00063 00064 static inline const MachineInstrBuilder & 00065 addOffset(const MachineInstrBuilder &MIB, int Offset) { 00066 return MIB.addImm(Offset).addReg(0); 00067 } 00068 00069 /// addRegOffset - This function is used to add a memory reference of the form 00070 /// [Reg + Offset], i.e., one with no or index, but with a 00071 /// displacement. An example is: 10(%r15). 00072 /// 00073 static inline const MachineInstrBuilder & 00074 addRegOffset(const MachineInstrBuilder &MIB, 00075 unsigned Reg, bool isKill, int Offset) { 00076 return addOffset(MIB.addReg(Reg, getKillRegState(isKill)), Offset); 00077 } 00078 00079 /// addRegReg - This function is used to add a memory reference of the form: 00080 /// [Reg + Reg]. 00081 static inline const MachineInstrBuilder & 00082 addRegReg(const MachineInstrBuilder &MIB, 00083 unsigned Reg1, bool isKill1, unsigned Reg2, bool isKill2) { 00084 return MIB.addReg(Reg1, getKillRegState(isKill1)).addImm(0) 00085 .addReg(Reg2, getKillRegState(isKill2)); 00086 } 00087 00088 static inline const MachineInstrBuilder & 00089 addFullAddress(const MachineInstrBuilder &MIB, const SystemZAddressMode &AM) { 00090 if (AM.BaseType == SystemZAddressMode::RegBase) 00091 MIB.addReg(AM.Base.Reg); 00092 else if (AM.BaseType == SystemZAddressMode::FrameIndexBase) 00093 MIB.addFrameIndex(AM.Base.FrameIndex); 00094 else 00095 assert(0); 00096 00097 return MIB.addImm(AM.Disp).addReg(AM.IndexReg); 00098 } 00099 00100 /// addFrameReference - This function is used to add a reference to the base of 00101 /// an abstract object on the stack frame of the current function. This 00102 /// reference has base register as the FrameIndex offset until it is resolved. 00103 /// This allows a constant offset to be specified as well... 00104 /// 00105 static inline const MachineInstrBuilder & 00106 addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset = 0) { 00107 MachineInstr *MI = MIB; 00108 MachineFunction &MF = *MI->getParent()->getParent(); 00109 MachineFrameInfo &MFI = *MF.getFrameInfo(); 00110 const TargetInstrDesc &TID = MI->getDesc(); 00111 unsigned Flags = 0; 00112 if (TID.mayLoad()) 00113 Flags |= MachineMemOperand::MOLoad; 00114 if (TID.mayStore()) 00115 Flags |= MachineMemOperand::MOStore; 00116 MachineMemOperand MMO(PseudoSourceValue::getFixedStack(FI), 00117 Flags, 00118 MFI.getObjectOffset(FI) + Offset, 00119 MFI.getObjectSize(FI), 00120 MFI.getObjectAlignment(FI)); 00121 return addOffset(MIB.addFrameIndex(FI), Offset) 00122 .addMemOperand(MMO); 00123 } 00124 00125 } // End llvm namespace 00126 00127 #endif