Get constant pools working. This fixes even more programs, allowing us to
authorChris Lattner <sabre@nondot.org>
Wed, 24 Nov 2004 01:56:12 +0000 (01:56 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 24 Nov 2004 01:56:12 +0000 (01:56 +0000)
pass 24/42 in UnitTests (up from 20).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18196 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCCodeEmitter.cpp

index 8d21557b90a0dd4150a84dcfd28a2d7dff916352..14dbcff2dbfec7569b9144f8d0dbdde7deceaca8 100644 (file)
@@ -199,6 +199,7 @@ int PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
     } else {
       assert(0 && "Unknown instruction for relocation!");
     }
+    assert(MovePCtoLROffset && "MovePCtoLR not seen yet?");
     MCE.addRelocation(MachineRelocation(MCE.getCurrentPCOffset(),
                                         Reloc, MO.getGlobal(),
                                         -((intptr_t)MovePCtoLROffset+4)));
@@ -208,27 +209,26 @@ int PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI, MachineOperand &MO) {
     BBRefs.push_back(std::make_pair(BB, CurrPC));
   } else if (MO.isConstantPoolIndex()) {
     unsigned index = MO.getConstantPoolIndex();
-    rv = MCE.getConstantPoolEntryAddress(index);
-  } else {
-    std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
-    abort();
-  }
-
-  // Special treatment for global symbols: constants and vars
-  if ((MO.isConstantPoolIndex() || MO.isGlobalAddress()) &&
-      MI.getOpcode() != PPC::CALLpcrel) {
-    unsigned Opcode = MI.getOpcode();
     assert(MovePCtoLROffset && "MovePCtoLR not seen yet?");
+    rv = MCE.getConstantPoolEntryAddress(index) - (intptr_t)MovePCtoLROffset-4;
 
+    unsigned Opcode = MI.getOpcode();
     if (Opcode == PPC::LOADHiAddr) {
       // LoadHiAddr wants hi16(addr - &MovePCtoLR)
+      if ((short)rv < 0) rv += 1 << 16;
       rv >>= 16;
     } else if (Opcode == PPC::LWZ || Opcode == PPC::LA ||
                Opcode == PPC::LFS || Opcode == PPC::LFD) {
       // These load opcodes want lo16(addr - &MovePCtoLR)
       rv &= 0xffff;
+    } else {
+      assert(0 && "Unknown constant pool using instruction!");
     }
+  } else {
+    std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n";
+    abort();
   }
+
   return rv;
 }