This is an archive of the discontinued LLVM Phabricator instance.

[APInt] Add a utility method to change the bit width and storage size of an APInt.
ClosedPublic

Authored by craig.topper on May 10 2017, 2:42 PM.

Details

Summary

This adds a resize method to APInt that manages deleting/allocating storage for an APInt and changes its bit width. Use this to simplify code in copy assignment and divide.

The assignment code in particular was overly complicated. Treating every possible case as a separate implementation. I'm also pretty sure the clearUnusedBits code at the end was unnecessary. Since we always copying whole words from the source APInt. All unused bits should be clear in the source.

Diff Detail

Event Timeline

craig.topper created this revision.May 10 2017, 2:42 PM
RKSimon added inline comments.May 11 2017, 3:02 AM
include/llvm/ADT/APInt.h
162

Make it clear that none of the bits are guaranteed - not just any 'new' bits.

lib/Support/APInt.cpp
127

Shouldn't this be == ?

hans added inline comments.May 11 2017, 8:59 AM
include/llvm/ADT/APInt.h
163

Since it's nuking the contents of the APInt, I wonder if resize() is the right name; it might confuse users who think it's similar to std::vector's resize() for example.

How about reallocate()?

lib/Support/APInt.cpp
1502

A reader might interpret "clear out" as setting to zero, which resize() doesn't do right?

Rename to reallocate. Clarify comments.

RKSimon accepted this revision.May 11 2017, 2:41 PM

LGTM

lib/Support/APInt.cpp
150

Strip the 'this'?

This revision is now accepted and ready to land.May 11 2017, 2:41 PM
This revision was automatically updated to reflect the committed changes.