[lld] r312495 - [MIPS] Convert template parameters to function arguments. NFC

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 4 09:16:46 PDT 2017


Author: atanasyan
Date: Mon Sep  4 09:16:46 2017
New Revision: 312495

URL: http://llvm.org/viewvc/llvm-project?rev=312495&view=rev
Log:
[MIPS] Convert template parameters to function arguments. NFC

Pass BSIZE and SHIFT as a function arguments to the `writeRelocation`
routine. It does not make a sense to have so many `writeRelocation's`
instances.

Modified:
    lld/trunk/ELF/Arch/Mips.cpp

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=312495&r1=312494&r2=312495&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Mon Sep  4 09:16:46 2017
@@ -142,11 +142,12 @@ void MIPS<ELFT>::writeGotPlt(uint8_t *Bu
   write32<ELFT::TargetEndianness>(Buf, InX::Plt->getVA());
 }
 
-template <endianness E, uint8_t BSIZE, uint8_t SHIFT>
-static void writeRelocation(uint8_t *Loc, uint64_t V) {
+template <endianness E>
+static void writeRelocation(uint8_t *Loc, uint64_t V, uint8_t BitsSize,
+                            uint8_t Shift) {
   uint32_t Instr = read32<E>(Loc);
-  uint32_t Mask = 0xffffffff >> (32 - BSIZE);
-  uint32_t Data = (Instr & ~Mask) | ((V >> SHIFT) & Mask);
+  uint32_t Mask = 0xffffffff >> (32 - BitsSize);
+  uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);
   write32<E>(Loc, Data);
 }
 
@@ -176,9 +177,9 @@ template <class ELFT> void MIPS<ELFT>::w
   write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2
 
   uint64_t GotPlt = InX::GotPlt->getVA();
-  writeRelocation<E, 16, 16>(Buf, GotPlt + 0x8000);
-  writeRelocation<E, 16, 0>(Buf + 4, GotPlt);
-  writeRelocation<E, 16, 0>(Buf + 8, GotPlt);
+  writeRelocation<E>(Buf, GotPlt + 0x8000, 16, 16);
+  writeRelocation<E>(Buf + 4, GotPlt, 16, 0);
+  writeRelocation<E>(Buf + 8, GotPlt, 16, 0);
 }
 
 template <class ELFT>
@@ -191,9 +192,9 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf,
                                    // jr    $25
   write32<E>(Buf + 8, isMipsR6<ELFT>() ? 0x03200009 : 0x03200008);
   write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)
-  writeRelocation<E, 16, 16>(Buf, GotPltEntryAddr + 0x8000);
-  writeRelocation<E, 16, 0>(Buf + 4, GotPltEntryAddr);
-  writeRelocation<E, 16, 0>(Buf + 12, GotPltEntryAddr);
+  writeRelocation<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
+  writeRelocation<E>(Buf + 4, GotPltEntryAddr, 16, 0);
+  writeRelocation<E>(Buf + 12, GotPltEntryAddr, 16, 0);
 }
 
 template <class ELFT>
@@ -312,17 +313,17 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo
     write64<E>(Loc, Val);
     break;
   case R_MIPS_26:
-    writeRelocation<E, 26, 2>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 26, 2);
     break;
   case R_MIPS_GOT16:
     // The R_MIPS_GOT16 relocation's value in "relocatable" linking mode
     // is updated addend (not a GOT index). In that case write high 16 bits
     // to store a correct addend value.
     if (Config->Relocatable) {
-      writeRelocation<E, 16, 16>(Loc, Val + 0x8000);
+      writeRelocation<E>(Loc, Val + 0x8000, 16, 16);
     } else {
       checkInt<16>(Loc, Val, Type);
-      writeRelocation<E, 16, 0>(Loc, Val);
+      writeRelocation<E>(Loc, Val, 16, 0);
     }
     break;
   case R_MIPS_GOT_DISP:
@@ -341,7 +342,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo
   case R_MIPS_TLS_DTPREL_LO16:
   case R_MIPS_TLS_GOTTPREL:
   case R_MIPS_TLS_TPREL_LO16:
-    writeRelocation<E, 16, 0>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 16, 0);
     break;
   case R_MIPS_CALL_HI16:
   case R_MIPS_GOT_HI16:
@@ -349,13 +350,13 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo
   case R_MIPS_PCHI16:
   case R_MIPS_TLS_DTPREL_HI16:
   case R_MIPS_TLS_TPREL_HI16:
-    writeRelocation<E, 16, 16>(Loc, Val + 0x8000);
+    writeRelocation<E>(Loc, Val + 0x8000, 16, 16);
     break;
   case R_MIPS_HIGHER:
-    writeRelocation<E, 16, 32>(Loc, Val + 0x80008000);
+    writeRelocation<E>(Loc, Val + 0x80008000, 16, 32);
     break;
   case R_MIPS_HIGHEST:
-    writeRelocation<E, 16, 48>(Loc, Val + 0x800080008000);
+    writeRelocation<E>(Loc, Val + 0x800080008000, 16, 48);
     break;
   case R_MIPS_JALR:
     // Ignore this optimization relocation for now
@@ -363,25 +364,25 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo
   case R_MIPS_PC16:
     checkAlignment<4>(Loc, Val, Type);
     checkInt<18>(Loc, Val, Type);
-    writeRelocation<E, 16, 2>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 16, 2);
     break;
   case R_MIPS_PC19_S2:
     checkAlignment<4>(Loc, Val, Type);
     checkInt<21>(Loc, Val, Type);
-    writeRelocation<E, 19, 2>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 19, 2);
     break;
   case R_MIPS_PC21_S2:
     checkAlignment<4>(Loc, Val, Type);
     checkInt<23>(Loc, Val, Type);
-    writeRelocation<E, 21, 2>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 21, 2);
     break;
   case R_MIPS_PC26_S2:
     checkAlignment<4>(Loc, Val, Type);
     checkInt<28>(Loc, Val, Type);
-    writeRelocation<E, 26, 2>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 26, 2);
     break;
   case R_MIPS_PC32:
-    writeRelocation<E, 32, 0>(Loc, Val);
+    writeRelocation<E>(Loc, Val, 32, 0);
     break;
   default:
     error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));




More information about the llvm-commits mailing list