lib/Target/X86/InstSelectSimple.cpp: Start counting arguments with 2,
authorBrian Gaeke <gaeke@uiuc.edu>
Fri, 13 Dec 2002 09:28:50 +0000 (09:28 +0000)
committerBrian Gaeke <gaeke@uiuc.edu>
Fri, 13 Dec 2002 09:28:50 +0000 (09:28 +0000)
 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

lib/Target/X86/InstSelectSimple.cpp
lib/Target/X86/X86ISelSimple.cpp
lib/Target/X86/X86InstrBuilder.h
test/ExecutionEngine/test-loadstore.ll

index 40d757b645af08b77d53a2cf64f455e05f39e66c..54cf29229d7916f7202f34434304387632beb79c 100644 (file)
@@ -159,23 +159,24 @@ namespace {
       } else if (Argument *A = dyn_cast<Argument>(V)) {
        // Find the position of the argument in the argument list.
        const Function *f = F->getFunction ();
-       int counter = 0, argPosition = -1;
+       // The function's arguments look like this:
+       // [EBP]     -- copy of old EBP
+       // [EBP + 4] -- return address
+       // [EBP + 8] -- first argument (leftmost lexically)
+       // So we want to start with counter = 2.
+       int counter = 2, argPosition = -1;
        for (Function::const_aiterator ai = f->abegin (), ae = f->aend ();
             ai != ae; ++ai) {
-         ++counter;
          if (&(*ai) == A) {
            argPosition = counter;
+           break; // Only need to find it once. ;-)
          }
+         ++counter;
        }
        assert (argPosition != -1
                && "Argument not found in current function's argument list");
        // Load it out of the stack frame at EBP + 4*argPosition.
-       // (First, load Reg with argPosition, then load Reg with DWORD
-       // PTR [EBP + 4*Reg].)
-       BuildMI (BB, X86::MOVir32, 1, Reg).addZImm (argPosition);
-       BuildMI (BB, X86::MOVmr32, 4,
-                Reg).addReg (X86::EBP).addZImm (4).addReg (Reg).addSImm (0);
-        // std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
+       addRegOffset (BuildMI (BB, X86::MOVmr32, 4, Reg), X86::EBP, 4*argPosition);
       }
 
       return Reg;
index 40d757b645af08b77d53a2cf64f455e05f39e66c..54cf29229d7916f7202f34434304387632beb79c 100644 (file)
@@ -159,23 +159,24 @@ namespace {
       } else if (Argument *A = dyn_cast<Argument>(V)) {
        // Find the position of the argument in the argument list.
        const Function *f = F->getFunction ();
-       int counter = 0, argPosition = -1;
+       // The function's arguments look like this:
+       // [EBP]     -- copy of old EBP
+       // [EBP + 4] -- return address
+       // [EBP + 8] -- first argument (leftmost lexically)
+       // So we want to start with counter = 2.
+       int counter = 2, argPosition = -1;
        for (Function::const_aiterator ai = f->abegin (), ae = f->aend ();
             ai != ae; ++ai) {
-         ++counter;
          if (&(*ai) == A) {
            argPosition = counter;
+           break; // Only need to find it once. ;-)
          }
+         ++counter;
        }
        assert (argPosition != -1
                && "Argument not found in current function's argument list");
        // Load it out of the stack frame at EBP + 4*argPosition.
-       // (First, load Reg with argPosition, then load Reg with DWORD
-       // PTR [EBP + 4*Reg].)
-       BuildMI (BB, X86::MOVir32, 1, Reg).addZImm (argPosition);
-       BuildMI (BB, X86::MOVmr32, 4,
-                Reg).addReg (X86::EBP).addZImm (4).addReg (Reg).addSImm (0);
-        // std::cerr << "ERROR: Arguments not implemented in SimpleInstSel\n";
+       addRegOffset (BuildMI (BB, X86::MOVmr32, 4, Reg), X86::EBP, 4*argPosition);
       }
 
       return Reg;
index 2558a96c04ed043814bbb4f389c6582a746ea044..af3b5221673f778bd90540567be57585ca859ce3 100644 (file)
@@ -9,6 +9,9 @@
 // up behind an easier to use interface makes sense.  Descriptions of the
 // functions are included below.
 //
+// For reference, the order of operands for memory references is:
+// (Operand), Base, Scale, Index, Displacement.
+//
 //===----------------------------------------------------------------------===//
 
 #ifndef X86INSTRBUILDER_H
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 
 /// addDirectMem - This function is used to add a direct memory reference to the
-/// current instruction.  Because memory references are always represented with
-/// four values, this adds: Reg, [1, NoReg, 0] to the instruction
-///
+/// current instruction -- that is, a dereference of an address in a register, with
+/// no scale, index or displacement. An example is: DWORD PTR [EAX].
 inline const MachineInstrBuilder &addDirectMem(const MachineInstrBuilder &MIB,
                                                unsigned Reg) {
+  // Because memory references are always represented with four
+  // values, this adds: Reg, [1, NoReg, 0] to the instruction.
   return MIB.addReg(Reg).addZImm(1).addMReg(0).addSImm(0);
 }
 
 
-/// addRegOffset -
-/// 
-///
+/// addRegOffset - This function is used to add a memory reference of
+/// the form [Reg + Offset], i.e., one with no scale or index, but
+/// with a displacement. An example is: DWORD PTR [EAX + 4].
 inline const MachineInstrBuilder &addRegOffset(const MachineInstrBuilder &MIB,
                                                unsigned Reg, unsigned Offset) {
   return MIB.addReg(Reg).addZImm(1).addMReg(0).addSImm(Offset);
index 936aa5f744348204c8d8ad6ee4707c4bb6b6a45d..f301e66be5aff1c82b5c983af809889e23025d8c 100644 (file)
@@ -11,10 +11,10 @@ void %test(sbyte* %P, short* %P, int* %P) {
        ret void
 }
 
-void %main() {
+int %main() {
        %A = alloca sbyte
        %B = alloca short
        %C = alloca int
        call void %test(sbyte* %A, short* %B, int* %C)
-       ret void
+       ret int 0
 }