This is an archive of the discontinued LLVM Phabricator instance.

[tablegen] Merge duplicate definitions of getMinimalTypeForRange. NFC.
ClosedPublic

Authored by dsanders on Oct 14 2016, 6:54 AM.

Event Timeline

dsanders updated this revision to Diff 74680.Oct 14 2016, 6:54 AM
dsanders retitled this revision from to [tablegen] Merge duplicate definitions of getMinimalTypeForRange. NFC..
dsanders updated this object.
dsanders added a subscriber: llvm-commits.

ping

This is a pre-requisite of D25618 which has been LGTM'd

qcolombet added inline comments.
utils/TableGen/Types.cpp
18

Get rid of that if.

23

Adapt the assert to the MaxSize.
Also check that MaxSize is smaller or equal than 64.

utils/TableGen/Types.h
20

I would move a bit differently with the implementation.

I would say that MaxSize is just for static assert and that it must be smaller or equal to 64.

dsanders added inline comments.Nov 15 2016, 3:32 AM
utils/TableGen/Types.cpp
18
utils/TableGen/Types.h
20

The MaxSize argument is only there to avoid a functional change in this particular change. Two of the getMinimalTypeForRange() implementations (RegisterInfoEmitter.cpp and AsmWriterEmitter.cpp) didn't allow uint64_t while the third did allow it. I suspect the only reason the limitation was there is that the relevant enums haven't grown large enough to warrant uint64_t yet. I was thinking that a follow-up patch could lift this limitation and remove the MaxSize argument but I didn't want to make that functional change a prerequisite of D25618. If you prefer, then I can make all three callers allow uint64_t in this change and remove MaxSize.

qcolombet added inline comments.Nov 15 2016, 2:18 PM
utils/TableGen/Types.h
20

I know :).
What I am saying is that the MaxSize should be used in the assert, but not in the if.
I.e., I want straight line code for all the cases.

dsanders added inline comments.Nov 16 2016, 3:14 AM
utils/TableGen/Types.h
20

I think I see what you're saying now. You're looking for something like this:

assert((MaxSize == 64 ? Range <= 0xFFFFFFFFFFFFFFFFULL : Range <= 0xFFFFFFFFULL) && "Enum too large");
if (Range > 0xFFFFFFFFULL)
  return "uint64_t";
if (Range > 0xFFFF)
  return "uint32_t";
if (Range > 0xFF)
  return "uint16_t";
return "uint8_t";
dsanders updated this revision to Diff 78221.Nov 16 2016, 10:51 AM

Only use MaxSize in an assert() and mark it unused to avoid issues with -Werror

qcolombet accepted this revision.Nov 17 2016, 1:07 PM
qcolombet added a reviewer: qcolombet.

LGTM

One nitpick.

Thanks Daniel!

utils/TableGen/Types.h
20

Yep, that's it.
Also add a MaxSize <= 64 assert.

This revision is now accepted and ready to land.Nov 17 2016, 1:07 PM
dsanders closed this revision.Nov 19 2016, 4:31 AM

Thanks

utils/TableGen/Types.h
20

I've added a MaxSize <= 64 assert in the commit.