llvm.org GIT mirror llvm / ed6902c
lib/Target/X86/InstSelectSimple.cpp: Start counting arguments with 2, because arguments start two stack slots off of EBP. Break out of the for loop once the argument is found. Increment the counter at the end of the loop instead of the beginning. Use addRegOffset and compute the scale * index part at compile time instead of using the fancy load instruction. Just because an instruction set has wacky addressing modes doesn't mean we ought to use them (at least, if you believe Dave Patterson). lib/Target/X86/X86InstrBuilder.h: Add some comments. test/Regression/Jello/test-loadstore.ll: Let main return int 0. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4999 91177308-0d34-0410-b5e6-96231b3b80d8 Brian Gaeke 17 years ago
4 changed file(s) with 30 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
158158 } else if (Argument *A = dyn_cast(V)) {
159159 // Find the position of the argument in the argument list.
160160 const Function *f = F->getFunction ();
161 int counter = 0, argPosition = -1;
161 // The function's arguments look like this:
162 // [EBP] -- copy of old EBP
163 // [EBP + 4] -- return address
164 // [EBP + 8] -- first argument (leftmost lexically)
165 // So we want to start with counter = 2.
166 int counter = 2, argPosition = -1;
162167 for (Function::const_aiterator ai = f->abegin (), ae = f->aend ();
163168 ai != ae; ++ai) {
164 ++counter;
165169 if (&(*ai) == A) {
166170 argPosition = counter;
171 break; // Only need to find it once. ;-)
167172 }
173 ++counter;
168174 }
169175 assert (argPosition != -1
170176 && "Argument not found in current function's argument list");
171177 // Load it out of the stack frame at EBP + 4*argPosition.
172 // (First, load Reg with argPosition, then load Reg with DWORD
173 // PTR [EBP + 4*Reg].)
174 BuildMI (BB, X86::MOVir32, 1, Reg).addZImm (argPosition);
175 BuildMI (BB, X86::MOVmr32, 4,
176 Reg).addReg (X86::EBP).addZImm (4).addReg (Reg).addSImm (0);
177 // std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
178 addRegOffset (BuildMI (BB, X86::MOVmr32, 4, Reg), X86::EBP, 4*argPosition);
178179 }
179180
180181 return Reg;
158158 } else if (Argument *A = dyn_cast(V)) {
159159 // Find the position of the argument in the argument list.
160160 const Function *f = F->getFunction ();
161 int counter = 0, argPosition = -1;
161 // The function's arguments look like this:
162 // [EBP] -- copy of old EBP
163 // [EBP + 4] -- return address
164 // [EBP + 8] -- first argument (leftmost lexically)
165 // So we want to start with counter = 2.
166 int counter = 2, argPosition = -1;
162167 for (Function::const_aiterator ai = f->abegin (), ae = f->aend ();
163168 ai != ae; ++ai) {
164 ++counter;
165169 if (&(*ai) == A) {
166170 argPosition = counter;
171 break; // Only need to find it once. ;-)
167172 }
173 ++counter;
168174 }
169175 assert (argPosition != -1
170176 && "Argument not found in current function's argument list");
171177 // Load it out of the stack frame at EBP + 4*argPosition.
172 // (First, load Reg with argPosition, then load Reg with DWORD
173 // PTR [EBP + 4*Reg].)
174 BuildMI (BB, X86::MOVir32, 1, Reg).addZImm (argPosition);
175 BuildMI (BB, X86::MOVmr32, 4,
176 Reg).addReg (X86::EBP).addZImm (4).addReg (Reg).addSImm (0);
177 // std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
178 addRegOffset (BuildMI (BB, X86::MOVmr32, 4, Reg), X86::EBP, 4*argPosition);
178179 }
179180
180181 return Reg;
88 // up behind an easier to use interface makes sense. Descriptions of the
99 // functions are included below.
1010 //
11 // For reference, the order of operands for memory references is:
12 // (Operand), Base, Scale, Index, Displacement.
13 //
1114 //===----------------------------------------------------------------------===//
1215
1316 #ifndef X86INSTRBUILDER_H
1619 #include "llvm/CodeGen/MachineInstrBuilder.h"
1720
1821 /// addDirectMem - This function is used to add a direct memory reference to the
19 /// current instruction. Because memory references are always represented with
20 /// four values, this adds: Reg, [1, NoReg, 0] to the instruction
21 ///
22 /// current instruction -- that is, a dereference of an address in a register, with
23 /// no scale, index or displacement. An example is: DWORD PTR [EAX].
2224 inline const MachineInstrBuilder &addDirectMem(const MachineInstrBuilder &MIB,
2325 unsigned Reg) {
26 // Because memory references are always represented with four
27 // values, this adds: Reg, [1, NoReg, 0] to the instruction.
2428 return MIB.addReg(Reg).addZImm(1).addMReg(0).addSImm(0);
2529 }
2630
2731
28 /// addRegOffset -
29 ///
30 ///
32 /// addRegOffset - This function is used to add a memory reference of
33 /// the form [Reg + Offset], i.e., one with no scale or index, but
34 /// with a displacement. An example is: DWORD PTR [EAX + 4].
3135 inline const MachineInstrBuilder &addRegOffset(const MachineInstrBuilder &MIB,
3236 unsigned Reg, unsigned Offset) {
3337 return MIB.addReg(Reg).addZImm(1).addMReg(0).addSImm(Offset);
1010 ret void
1111 }
1212
13 void %main() {
13 int %main() {
1414 %A = alloca sbyte
1515 %B = alloca short
1616 %C = alloca int
1717 call void %test(sbyte* %A, short* %B, int* %C)
18 ret void
18 ret int 0
1919 }