LLVM: lib/Target/X86/X86ArgumentStackSlotRebase.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

30

31using namespace llvm;

32

33#define DEBUG_TYPE "x86argumentstackrebase"

34

35namespace {

36

38

39public:

40 static char ID;

41

43

45

46 void getAnalysisUsage(AnalysisUsage &AU) const override {

49 }

50};

51

52}

53

54char X86ArgumentStackSlotPass::ID = 0;

55

57 false, false)

58

60 return new X86ArgumentStackSlotPass();

61}

62

70 switch (CC) {

71

72

74 RC = STI.is64Bit() ? &X86::GR64_ArgRefRegClass : &X86::GR32_ArgRefRegClass;

75 break;

77

78

79

80

81

82

83

84

85

86

87

88 RC = STI.is64Bit() ? &X86::GR64_ArgRefRegClass : nullptr;

89 break;

90

91 default:

92 break;

93 }

94 if (RC)

95 return MRI.createVirtualRegister(RC);

96 else

97 return NoReg;

98}

99

100bool X86ArgumentStackSlotPass::runOnMachineFunction(MachineFunction &MF) {

103 const X86Subtarget &STI = MF.getSubtarget();

106 X86MachineFunctionInfo *X86FI = MF.getInfo();

108

109 if (F.hasFnAttribute(Attribute::Naked))

110 return false;

111

113 return false;

114 if (TRI->hasBasePointer(MF))

115 return false;

116

118 return false;

119

121 auto IsBaseRegisterClobbered = [&]() {

122 for (MachineBasicBlock &MBB : MF) {

123 for (MachineInstr &MI : MBB) {

124 if (MI.isInlineAsm())

125 continue;

126 for (MachineOperand &MO : MI.operands()) {

127 if (!MO.isReg())

128 continue;

131 continue;

132 if (TRI->isSuperOrSubRegisterEq(BasePtr, Reg))

133 return true;

134 }

135 }

136 }

137 return false;

138 };

139 if (!IsBaseRegisterClobbered())

140 return false;

141

143 if (!ArgBaseReg.isValid())

144 return false;

145

146 MachineBasicBlock &MBB = MF.front();

149

150

151

152

153

154 unsigned SlotSize = TRI->getSlotSize();

156

157

158 MachineInstr *LEA =

160 TII->get(STI.is64Bit() ? X86::PLEA64r : X86::PLEA32r), ArgBaseReg)

163 .addUse(X86::NoRegister)

165 .addUse(X86::NoRegister)

168

169 for (MachineBasicBlock &MBB : MF) {

170 for (MachineInstr &MI : MBB) {

171 int I = 0;

172 for (MachineOperand &MO : MI.operands()) {

173 if (MO.isFI()) {

174 int Idx = MO.getIndex();

176 continue;

179 continue;

180

181 if (MI.isDebugInstr())

182 continue;

183

184 TRI->eliminateFrameIndex(MI.getIterator(), I, ArgBaseReg, Offset);

186 }

187 ++I;

188 }

189 }

190 }

191

193}

unsigned const MachineRegisterInfo * MRI

const TargetInstrInfo & TII

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

MachineBasicBlock MachineBasicBlock::iterator MBBI

This file contains the simple types necessary to represent the attributes associated with functions a...

Register const TargetRegisterInfo * TRI

Promote Memory to Register

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

static Register getArgBaseReg(MachineFunction &MF)

Definition X86ArgumentStackSlotRebase.cpp:63

Represent the analysis usage information of a pass.

LLVM_ABI void setPreservesCFG()

This function should be called by the pass, iff they do not:

FunctionPass class - This class is used to implement most global optimizations.

const MCInstrDesc & get(unsigned Opcode) const

Return the machine instruction descriptor that corresponds to the specified instruction opcode.

MachineInstrBundleIterator< MachineInstr > iterator

LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment)

Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...

int64_t getObjectOffset(int ObjectIdx) const

Return the assigned stack offset of the specified object from the incoming stack pointer.

bool isFixedObjectIndex(int ObjectIdx) const

Returns true if the specified index corresponds to a fixed stack object.

MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

MachineFrameInfo & getFrameInfo()

getFrameInfo - Return the frame info object for the current function.

MachineRegisterInfo & getRegInfo()

getRegInfo - Return information about the registers currently in use.

Function & getFunction()

Return the LLVM function that this machine code represents.

Ty * getInfo()

getInfo - Keep track of various per-function pieces of information for backends that would like to do...

const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const

const MachineInstrBuilder & addImm(int64_t Val) const

Add a new immediate operand.

const MachineInstrBuilder & addFrameIndex(int Idx) const

const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const

Add a virtual register use operand.

MachineRegisterInfo - Keep track of information for virtual and physical registers,...

Wrapper class representing virtual and physical registers.

constexpr bool isValid() const

constexpr bool isPhysical() const

Return true if the specified register number is in the physical register namespace.

void setStackPtrSaveMI(MachineInstr *MI)

bool isTarget64BitILP32() const

Is this x86_64 with the ILP32 programming model (x32 ABI)?

const X86InstrInfo * getInstrInfo() const override

const X86RegisterInfo * getRegisterInfo() const override

bool isTargetLinux() const

constexpr char Align[]

Key for Kernel::Arg::Metadata::mAlign.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

@ X86_RegCall

Register calling convention used for parameters transfer optimization.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)

Builder interface. Specify how to create the initial instruction itself.

FunctionPass * createX86ArgumentStackSlotPass()