[llvm] 0eec666 - [MC][mips] Replace setRType## methods by single setRTypes function. NFC
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 02:13:57 PDT 2020
Author: Simon Atanasyan
Date: 2020-04-24T12:13:27+03:00
New Revision: 0eec6662f66930fa72553731744b50b820d3405b
URL: https://github.com/llvm/llvm-project/commit/0eec6662f66930fa72553731744b50b820d3405b
DIFF: https://github.com/llvm/llvm-project/commit/0eec6662f66930fa72553731744b50b820d3405b.diff
LOG: [MC][mips] Replace setRType## methods by single setRTypes function. NFC
MCELFObjectWriter::setRType## methods are always used altogether to
build complete MIPS N64 ABI "chain" of relocations. Using single
function for this task makes code less verbose.
Added:
Modified:
llvm/include/llvm/MC/MCELFObjectWriter.h
llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCELFObjectWriter.h b/llvm/include/llvm/MC/MCELFObjectWriter.h
index 2d441fdeee28..faf5e330afcf 100644
--- a/llvm/include/llvm/MC/MCELFObjectWriter.h
+++ b/llvm/include/llvm/MC/MCELFObjectWriter.h
@@ -130,14 +130,10 @@ class MCELFObjectTargetWriter : public MCObjectTargetWriter {
}
// N64 relocation type setting
- unsigned setRType(unsigned Value, unsigned Type) const {
- return ((Type & R_TYPE_MASK) | ((Value & 0xff) << R_TYPE_SHIFT));
- }
- unsigned setRType2(unsigned Value, unsigned Type) const {
- return (Type & R_TYPE2_MASK) | ((Value & 0xff) << R_TYPE2_SHIFT);
- }
- unsigned setRType3(unsigned Value, unsigned Type) const {
- return (Type & R_TYPE3_MASK) | ((Value & 0xff) << R_TYPE3_SHIFT);
+ static unsigned setRTypes(unsigned Value1, unsigned Value2, unsigned Value3) {
+ return ((Value1 & 0xff) << R_TYPE_SHIFT) |
+ ((Value2 & 0xff) << R_TYPE2_SHIFT) |
+ ((Value3 & 0xff) << R_TYPE3_SHIFT);
}
unsigned setRSsym(unsigned Value, unsigned Type) const {
return (Type & R_SSYM_MASK) | ((Value & 0xff) << R_SSYM_SHIFT);
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index cc3168790b98..ee2e8779eb0d 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -289,14 +289,9 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
case FK_TPRel_8:
return ELF::R_MIPS_TLS_TPREL64;
case FK_GPRel_4:
- if (is64Bit()) {
- unsigned Type = (unsigned)ELF::R_MIPS_NONE;
- Type = setRType((unsigned)ELF::R_MIPS_GPREL32, Type);
- Type = setRType2((unsigned)ELF::R_MIPS_64, Type);
- Type = setRType3((unsigned)ELF::R_MIPS_NONE, Type);
- return Type;
- }
- return ELF::R_MIPS_GPREL32;
+ return setRTypes(ELF::R_MIPS_GPREL32,
+ is64Bit() ? ELF::R_MIPS_64 : ELF::R_MIPS_NONE,
+ ELF::R_MIPS_NONE);
case Mips::fixup_Mips_GPREL16:
return ELF::R_MIPS_GPREL16;
case Mips::fixup_Mips_26:
@@ -329,34 +324,16 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_MIPS_GOT_OFST;
case Mips::fixup_Mips_GOT_DISP:
return ELF::R_MIPS_GOT_DISP;
- case Mips::fixup_Mips_GPOFF_HI: {
- unsigned Type = (unsigned)ELF::R_MIPS_NONE;
- Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type);
- Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type);
- Type = setRType3((unsigned)ELF::R_MIPS_HI16, Type);
- return Type;
- }
- case Mips::fixup_MICROMIPS_GPOFF_HI: {
- unsigned Type = (unsigned)ELF::R_MIPS_NONE;
- Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type);
- Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type);
- Type = setRType3((unsigned)ELF::R_MICROMIPS_HI16, Type);
- return Type;
- }
- case Mips::fixup_Mips_GPOFF_LO: {
- unsigned Type = (unsigned)ELF::R_MIPS_NONE;
- Type = setRType((unsigned)ELF::R_MIPS_GPREL16, Type);
- Type = setRType2((unsigned)ELF::R_MIPS_SUB, Type);
- Type = setRType3((unsigned)ELF::R_MIPS_LO16, Type);
- return Type;
- }
- case Mips::fixup_MICROMIPS_GPOFF_LO: {
- unsigned Type = (unsigned)ELF::R_MIPS_NONE;
- Type = setRType((unsigned)ELF::R_MICROMIPS_GPREL16, Type);
- Type = setRType2((unsigned)ELF::R_MICROMIPS_SUB, Type);
- Type = setRType3((unsigned)ELF::R_MICROMIPS_LO16, Type);
- return Type;
- }
+ case Mips::fixup_Mips_GPOFF_HI:
+ return setRTypes(ELF::R_MIPS_GPREL16, ELF::R_MIPS_SUB, ELF::R_MIPS_HI16);
+ case Mips::fixup_MICROMIPS_GPOFF_HI:
+ return setRTypes(ELF::R_MICROMIPS_GPREL16, ELF::R_MICROMIPS_SUB,
+ ELF::R_MICROMIPS_HI16);
+ case Mips::fixup_Mips_GPOFF_LO:
+ return setRTypes(ELF::R_MIPS_GPREL16, ELF::R_MIPS_SUB, ELF::R_MIPS_LO16);
+ case Mips::fixup_MICROMIPS_GPOFF_LO:
+ return setRTypes(ELF::R_MICROMIPS_GPREL16, ELF::R_MICROMIPS_SUB,
+ ELF::R_MICROMIPS_LO16);
case Mips::fixup_Mips_HIGHER:
return ELF::R_MIPS_HIGHER;
case Mips::fixup_Mips_HIGHEST:
More information about the llvm-commits
mailing list