This is an archive of the discontinued LLVM Phabricator instance.

[mips][microMIPS] Implement DBITSWAP, DLSA and LWUPC and add tests for AUI instructions
ClosedPublic

Authored by mamidzic on Jan 21 2016, 11:25 PM.

Details

Summary

The patch implements microMIPS64r6 DBITSWAP, DLSA, LWUPC and adds tests for AUI instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

hvarga updated this revision to Diff 45654.Jan 21 2016, 11:25 PM
hvarga retitled this revision from to [mips][microMIPS] AUI, DBITSWAP, LDPC, LLDX, DLSA, LWUPC, SCDX instructions.
hvarga updated this object.
hvarga added subscribers: llvm-commits, petarj.
sdardis requested changes to this revision.Apr 22 2016, 5:14 AM
sdardis added a reviewer: sdardis.
sdardis added a subscriber: sdardis.

The LLX/SCX family of instructions are being changed, so they can be dropped from this patch.

You should retitle this patch to reflect that you're adding tests for aui, rather than implementing it.

Can you rebase and repost?

lib/Target/Mips/MicroMips64r6InstrInfo.td
111 ↗(On Diff #45654)

Needs MayLoad = 1.

125 ↗(On Diff #45654)

Needs mayLoad = 1

lib/Target/Mips/Mips64r6InstrInfo.td
96 ↗(On Diff #45654)

DLSA also needs to have the NotInMicroMips predicate.

This revision now requires changes to proceed.Apr 22 2016, 5:14 AM
hvarga updated this revision to Diff 56665.May 10 2016, 12:03 AM
hvarga edited edge metadata.

Updated according to the comments from sdardis.

hvarga retitled this revision from [mips][microMIPS] AUI, DBITSWAP, LDPC, LLDX, DLSA, LWUPC, SCDX instructions to [mips][microMIPS] Implement DBITSWAP, DLSA and LWUPC and add tests for AUI instructions.May 10 2016, 12:03 AM
hvarga edited edge metadata.
sdardis requested changes to this revision.May 10 2016, 2:51 AM
sdardis edited edge metadata.

Some small nits.

Thanks,
Simon

lib/Target/Mips/MicroMips64r6InstrFormats.td
169–170 ↗(On Diff #56665)

Nit, bits 25-21 encode rt, 20-16 encode rs.

178–184 ↗(On Diff #56665)

Nit: rs should be rt here.

lib/Target/Mips/MicroMips64r6InstrInfo.td
188–190 ↗(On Diff #56665)

Nit, rs -> rt.

194–202 ↗(On Diff #56665)

I believe this is redundant, I'm not seeing anything use this.

test/MC/Mips/micromips64r6/invalid.s
233 ↗(On Diff #56665)

Check that a signed immediate offset > 19 bits is rejected for lwupc.
Check that a signed immediate > 16 bits is rejected for aui.

This revision now requires changes to proceed.May 10 2016, 2:51 AM
hvarga updated this revision to Diff 59036.May 31 2016, 3:44 AM
hvarga edited edge metadata.

Updated according to the comments from sdardis.

sdardis requested changes to this revision.Jun 1 2016, 5:37 AM
sdardis edited edge metadata.

Some small nits. There's only one significant change required for the predicate for lwupc. We need to see if we can evaluate it as something relocatable and that the constant part is scaled too.

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
1110–1116 ↗(On Diff #59036)

This almost correct. We need to check for constants, symbols and symbols + offsets. The offset then has to be in the scaled form. I've given this an attempt with:

if (isConstantImm() && isShiftedInt<Bits, ShiftLeftAmount>(getConstantImm()))                                      
  return true; 
// Operand can also be a symbol or symbol plus offset in case of relocations.
if (Kind != k_Immediate)
  return false;
MCValue Res;
bool Success = getImm()->evaluateAsRelocatable(Res, nullptr, nullptr);
return Success && isShiftedInt<Bits, ShiftLeftAmount>(Res.getConstant());

Which also checks the offset. The code would also need to check that it's an immediate.

lib/Target/Mips/MicroMips64r6InstrFormats.td
189 ↗(On Diff #59036)

This should be called POOL32S_DBITSWAP_FM_MMR6, as it's in pool32s.

207–215 ↗(On Diff #59036)

'imm' should be 'sa' to match the documentation

lib/Target/Mips/MicroMips64r6InstrInfo.td
257–258 ↗(On Diff #59036)

Nit: imm should be sa.

262–267 ↗(On Diff #59036)

Needs MayLoad = 1.

lib/Target/Mips/Mips32r6InstrInfo.td
769–772 ↗(On Diff #59036)

Join these "let AdditionalPredicates =" blocks together.

lib/Target/Mips/MipsInstrInfo.td
409 ↗(On Diff #59036)

I think this should have a different name, as lwupc doesn't jump.

test/MC/Mips/micromips64r6/invalid.s
282 ↗(On Diff #59036)

Check that symbol + offset where the offset is not a multiple of 4 is rejected as well and that register + register is rejected as well.

test/MC/Mips/micromips64r6/valid.s
283 ↗(On Diff #59036)

Also check that a symbol and symbol + offset where the offset is a multiple of 4 is also accepted for lwupc.

This revision now requires changes to proceed.Jun 1 2016, 5:37 AM

Also, the patch summary needs to be updated.

hvarga updated this revision to Diff 64109.Jul 15 2016, 1:37 AM
hvarga updated this object.
hvarga edited edge metadata.
hvarga added a subscriber: mamidzic.

isScaledSimm code replaced with the code you suggested.
Changed FM classes so that they inherit from MipsR6Inst and MMR6Arch.
Changed DESC classes so that they don't inherit from MipsR6Inst and MMR6Arch.
Changed name of MipsJumpTargetAsmOperandClass to MipsSimmAsmOperandClass.
Added DBITSWAP, LWUPC and DLCA to instruction mapping tables.
Added valid and invalid tests for LWUPC with symbols.

Note: Didn't set the MayLoad flag to 1 in LWUPC DESC class, because with it, LWUPC tests with symbols cause an assertion fail: "Assertion `isReg() && "This is not a register operand!"' failed.". I didn't find a way around that.

sdardis requested changes to this revision.Jul 21 2016, 8:58 AM
sdardis edited edge metadata.

Note: Didn't set the MayLoad flag to 1 in LWUPC DESC class, because with it, LWUPC tests with symbols cause an assertion fail: "Assertion `isReg() && "This is not a register operand!"' failed.". I didn't find a way around that.

Yes, when an instruction with mayLoad/myStore is processed in MipsAsmParser::expandLoadInst assumes that all load instructions have both a source and destination register. lwupc however doesn't have a source register, merely an enlarged offset or symbol.

Tablegen has inferred that lwupc doesn't load, and so doesn't mark it as a load, the symbol 'bar' gets handled with a relocation. This leads to a correct result but it has a mis-defined instruction.

You can fix this easily enough by making some fairly simple changes. Extend the MipsInst class to have a "isPCRelativeLoad" member in MipsInstrFormats.td, make the corresponding change in MipsInstrInfo.h, then only check normal load/store instructions for expansion in processInstruction. Look at isCTI for an example.

I have some more comments inline.

Thanks

lib/Target/Mips/MicroMips64r6InstrInfo.td
319 ↗(On Diff #64109)

This requires the instruction itinerary, II_DBITSWAP.

325 ↗(On Diff #64109)

This requires the instruction itinerary, II_DLSA.

lib/Target/Mips/MipsInstrInfo.td
416–424 ↗(On Diff #64109)

Calll this SimmLslAsmOperandClass instead, change the Name to reflect the class and remove the ParserMethod, the generic parser can handle the necessary cases.

631–632 ↗(On Diff #64109)

Drop the 'Mips' from the names here.

This revision now requires changes to proceed.Jul 21 2016, 8:58 AM
mamidzic commandeered this revision.Aug 23 2016, 12:49 AM
mamidzic added a reviewer: hvarga.
mamidzic updated this revision to Diff 69560.Aug 29 2016, 5:40 AM
mamidzic edited edge metadata.

Added instruction itineraries to DBITSWAP and DLSA instructions.
Changed to MipsSimmAsmOperandClass to SimmLslAsmOperandClass, removed the parser method and changed the Name.
Changed MipsSimm19Lsl2AsmOperand to Simm19Lsl2AsmOperand.
Added isPCRelativeLoad flag to TSFlags.
Added mayLoad and is PCRelativeLoad to LWUPC instruction.
Added isPCRelativeLoad check to processInstruction.

sdardis accepted this revision.Aug 31 2016, 6:08 AM
sdardis edited edge metadata.

LGTM. Add the relevant disassembler tests when you commit.

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
1848 ↗(On Diff #69560)

Add a space before this line for vertical separation, so it's clear the the following code is unrelated to the block above.

lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h
124–126 ↗(On Diff #69560)

Nit: Style, capitalize the first letter in IsPCRelativeLoad.

A better description is 'A Load instruction with implicit source register ($pc) with explicit offset and destination register'.

lib/Target/Mips/MipsInstrFormats.td
101 ↗(On Diff #69560)

See my comment about IsPCRelativeLoad in MipsBaseInfo.h

This revision is now accepted and ready to land.Aug 31 2016, 6:08 AM
This revision was automatically updated to reflect the committed changes.