Skip to content

Commit

Permalink
[MC][mips] Replace setRType## methods by single setRTypes function. NFC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
atanasyan committed Apr 24, 2020
1 parent 9aa6792 commit 0eec666
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 44 deletions.
12 changes: 4 additions & 8 deletions llvm/include/llvm/MC/MCELFObjectWriter.h
Expand Up @@ -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);
Expand Down
49 changes: 13 additions & 36 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0eec666

Please sign in to comment.