This is an archive of the discontinued LLVM Phabricator instance.

[CodeEmitter] Support instruction widths > 64 bits
ClosedPublic

Authored by jmolloy on Sep 12 2019, 3:24 AM.

Details

Summary

Some VLIW instruction sets are Very Long Indeed. Using uint64_t constricts the Inst encoding to 64 bits (naturally).

This change switches CodeEmitter to a mode that uses APInts when Inst's bitwidth is > 64 bits (NFC for existing targets).

When Inst.BitWidth > 64 the prototype changes to:

void TargetMCCodeEmitter::getBinaryCodeForInstr(const MCInst &MI,
                                                SmallVectorImpl<MCFixup> &Fixups,
                                                APInt &Inst,
                                                APInt &Scratch,
                                                const MCSubtargetInfo &STI);

The Inst parameter returns the encoded instruction, the Scratch parameter is used internally for manipulating operands and is exposed so that the underlying storage can be reused between calls to getBinaryCodeForInstr. The goal is to elide any APInt constructions that we can.

Similarly the operand encoding prototype changes to:

getMachineOpValue(const MCInst &MI, const MCOperand &MO, APInt &op, SmallVectorImpl<MCFixup> &Fixups, const MCSubtargetInfo &STI);

That is, the operand is passed by reference as APInt rather than returned as uint64_t.

To reiterate, this APInt mode is enabled only when Inst.BitWidth > 64, so while no existing in-tree target makes use of that,
there's basic test coverage in llvm/test/TableGen/RegisterEncoder.td.

Diff Detail

Repository
rL LLVM

Event Timeline

jmolloy created this revision.Sep 12 2019, 3:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2019, 3:24 AM
bkramer accepted this revision.Sep 13 2019, 3:51 AM
bkramer added a subscriber: bkramer.

I think this is fine. Features like this might bitrot quickly but that's on you ;)

llvm/utils/TableGen/CodeEmitterGen.cpp
309 ↗(On Diff #219875)

utostr() isn't needed when printing to a raw_ostream

This revision is now accepted and ready to land.Sep 13 2019, 3:51 AM

Can you quote where https://llvm.org/docs/DeveloperPolicy.html#test-cases says it's okay to commit dead code with no test coverage?

There are tests in llvm/test/TableGen/BigEncoder.td.

lebedev.ri edited the summary of this revision. (Show Details)Sep 13 2019, 4:23 AM

On Fri, Sep 13, 2019 at 2:03 PM James Molloy <jmolloy@google.com> wrote:

Hi Roman,

There is one diff to a test and one brand new test in this change (llvm/test/TableGen/BigEncoder.td).

Re test coverage: that is not really how the patch description was being read, usually that wording means something different.

As a sidenote, your message could be considered by some unnecessarily passive-aggressive.

Cheers,

James

tra added a subscriber: tra.Sep 13 2019, 9:46 AM
tra added inline comments.
llvm/test/TableGen/BigEncoder.td
2 ↗(On Diff #219875)

I'd add some details explaining what the test does and why.
Otherwise it's not clear what this test does and why without the full context of the patch.
Those bits<65> are not very noticeable on their own.

59–69 ↗(On Diff #219875)

checks for results of bar/baz are missing.

This revision was automatically updated to reflect the committed changes.