This is an archive of the discontinued LLVM Phabricator instance.

[mips] Use MipsMCExpr instead of MCSymbolRefExpr for all relocations.
ClosedPublic

Authored by dsanders on Apr 29 2016, 2:15 AM.

Details

Summary

This is much closer to the way MIPS relocation expressions work
(%hi(foo + 2) rather than %hi(foo) + 2) and removes the need for the
various bodges in MipsAsmParser::evaluateRelocExpr().

Removing those bodges ensures that the constant stored in MCValue is the
full 32 or 64-bit (depending on ABI) offset from the symbol. This will be used
to correct the %hi/%lo matching needed to sort the relocation table correctly.

As part of this:

  • Gave MCExpr::print() the ability to omit parenthesis when emitting a symbol reference inside a MipsMCExpr operator like %hi(X). Without this we print things like %lo(($L1)).
  • %hi(%neg(%gprel(X))) is now three MipsMCExpr's instead of one. Most of the related special cases have been removed or moved to MipsMCExpr. We can remove the rest as we gain support for the less common relocations when they are not part of this specific combination.
  • Renamed MipsMCExpr::VariantKind and the enum prefix ('VK_') to avoid confusion with MCSymbolRefExpr::VariantKind and its prefix (also 'VK_').
  • fixup_Mips_GOT_Local and fixup_Mips_GOT_Global were found to be identical and merged into fixup_Mips_GOT.
  • MO_GOT16 and MO_GOT turned out to be identical and have been merged into MO_GOT.
  • VK_Mips_GOT and VK_Mips_GOT16 turned out to be the same thing so they have been merged into MEK_GOT

Depends on D19714.

Diff Detail

Event Timeline

dsanders updated this revision to Diff 55552.Apr 29 2016, 2:15 AM
dsanders retitled this revision from to [mips] Use MipsMCExpr instead of MCSymbolRefExpr for all relocations..
dsanders updated this object.
dsanders added a reviewer: sdardis.
dsanders added a subscriber: llvm-commits.
sdardis edited edge metadata.May 3 2016, 6:09 AM

This mostly looks LGTM but I have some inlined comments.

lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp
153

Am I missing something here? As far as I can see, you assert that Kind == VK_None on line 143 but here you're testing if Kind != VK_None, which I believe is always false.

lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
467

Nit: overwrite -> overwrites

lib/Target/Mips/MCTargetDesc/MipsMCExpr.h
85–86

Should this be 'return isGpOff(Kind);' as the local declaration of 'Kind' here shadows the class definition.

dsanders added inline comments.May 3 2016, 6:19 AM
lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp
153

It looks like I missed this when I finished emptying out the switch statement. I'll make this unconditional.

lib/Target/Mips/MCTargetDesc/MipsMCExpr.h
85–86

This is intended to discard the MipsExprKind result from the other isGpOff predicate. I can call it 'Unused' if that's preferable.

sdardis accepted this revision.May 3 2016, 6:30 AM
sdardis edited edge metadata.

LGTM with the two nits (spelling/control flow) addressed.

lib/Target/Mips/MCTargetDesc/MipsMCExpr.h
85–86

No, that's fine as is.

This revision is now accepted and ready to land.May 3 2016, 6:30 AM
dsanders closed this revision.May 3 2016, 6:41 AM