llvm.org GIT mirror llvm / b499866
Add API to check and fold memory operands into instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11519 91177308-0d34-0410-b5e6-96231b3b80d8 Alkis Evlogimenos 16 years ago
3 changed file(s) with 96 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
241241 const TargetRegisterClass *RC) const = 0;
242242
243243
244 virtual bool canFoldMemoryOperand(MachineInstr* MI, unsigned i) const {
245 return false;
246 }
247
248 virtual int foldMemoryOperand(MachineInstr* MI,
249 unsigned i,
250 int FrameIndex) const {
251 return 0;
252 }
253
244254 /// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the
245255 /// frame setup/destroy instructions if they exist (-1 otherwise). Some
246256 /// targets use pseudo instructions in order to abstract away the difference
7676 { X86::MOVrr8, X86::MOVrr16, X86::MOVrr32, X86::FpMOV };
7777 MBB.insert(MI, BuildMI(Opcode[getIdx(RC)],1,DestReg).addReg(SrcReg));
7878 return 1;
79 }
80
81 bool X86RegisterInfo::canFoldMemoryOperand(MachineInstr* MI,
82 unsigned i) const
83 {
84 switch(MI->getOpcode()) {
85 case X86::ADDrr8: case X86::ADDrr16: case X86::ADDrr32:
86 case X86::ADDri8: case X86::ADDri16: case X86::ADDri32:
87 case X86::MOVrr8: case X86::MOVrr16: case X86::MOVrr32:
88 return true;
89 default:
90 return false;
91 }
92 }
93
94 int X86RegisterInfo::foldMemoryOperand(MachineInstr* MI,
95 unsigned i,
96 int FrameIndex) const
97 {
98 MachineBasicBlock& MBB = *MI->getParent();
99 MachineInstr* NI = 0;
100 if (i == 0)
101 switch(MI->getOpcode()) {
102 case X86::MOVrr8:
103 NI = addFrameReference(BuildMI(X86::MOVmr8, 5), FrameIndex).addReg(MI->getOperand(1).getReg());
104 break;
105 case X86::MOVrr16:
106 NI = addFrameReference(BuildMI(X86::MOVmr16, 5), FrameIndex).addReg(MI->getOperand(1).getReg());
107 break;
108 case X86::MOVrr32:
109 NI = addFrameReference(BuildMI(X86::MOVmr32, 5), FrameIndex).addReg(MI->getOperand(1).getReg());
110 break;
111 case X86::ADDrr8:
112 NI = addFrameReference(BuildMI(X86::ADDmr8, 5), FrameIndex).addReg(MI->getOperand(1).getReg());
113 break;
114 case X86::ADDrr16:
115 NI = addFrameReference(BuildMI(X86::ADDmr16, 5), FrameIndex).addReg(MI->getOperand(1).getReg());
116 break;
117 case X86::ADDrr32:
118 NI = addFrameReference(BuildMI(X86::ADDmr32, 5), FrameIndex).addReg(MI->getOperand(1).getReg());
119 break;
120 case X86::ADDri8:
121 NI = addFrameReference(BuildMI(X86::ADDmi8, 5), FrameIndex).addZImm(MI->getOperand(1).getImmedValue());
122 break;
123 case X86::ADDri16:
124 NI = addFrameReference(BuildMI(X86::ADDmi16, 5), FrameIndex).addZImm(MI->getOperand(1).getImmedValue());
125 break;
126 case X86::ADDri32:
127 NI = addFrameReference(BuildMI(X86::ADDmi32, 5), FrameIndex).addZImm(MI->getOperand(1).getImmedValue());
128 break;
129 default:
130 assert(0 && "Operand cannot be folded");
131 }
132 else if (i == 1)
133 switch(MI->getOpcode()) {
134 case X86::MOVrr8:
135 NI = addFrameReference(BuildMI(X86::MOVrm8, 5).addReg(MI->getOperand(0).getReg()), FrameIndex);
136 break;
137 case X86::MOVrr16:
138 NI = addFrameReference(BuildMI(X86::MOVrm16, 5).addReg(MI->getOperand(0).getReg()), FrameIndex);
139 break;
140 case X86::MOVrr32:
141 NI = addFrameReference(BuildMI(X86::MOVrm32, 5).addReg(MI->getOperand(0).getReg()), FrameIndex);
142 break;
143 case X86::ADDrr8:
144 NI = addFrameReference(BuildMI(X86::ADDrm8, 5).addReg(MI->getOperand(0).getReg()), FrameIndex);
145 break;
146 case X86::ADDrr16:
147 NI = addFrameReference(BuildMI(X86::ADDrm16, 5).addReg(MI->getOperand(0).getReg()), FrameIndex);
148 break;
149 case X86::ADDrr32:
150 NI = addFrameReference(BuildMI(X86::ADDrm32, 5).addReg(MI->getOperand(0).getReg()), FrameIndex);
151 break;
152 default:
153 assert(0 && "Operand cannot be folded");
154 }
155 else
156 assert(0 && "Operand cannot be folded");
157
158 MBB.insert(MBB.erase(MI), NI);
159 return 0;
79160 }
80161
81162 //===----------------------------------------------------------------------===//
4141 unsigned DestReg, unsigned SrcReg,
4242 const TargetRegisterClass *RC) const;
4343
44 virtual bool canFoldMemoryOperand(MachineInstr* MI, unsigned i) const;
45
46 virtual int foldMemoryOperand(MachineInstr* MI, unsigned i,
47 int FrameIndex) const;
48
4449 void eliminateCallFramePseudoInstr(MachineFunction &MF,
4550 MachineBasicBlock &MBB,
4651 MachineBasicBlock::iterator MI) const;