OSDN Git Service

[APInt] Add getBitsSetFrom and setBitsFrom to set upper bits starting at a bit
authorCraig Topper <craig.topper@gmail.com>
Tue, 7 Mar 2017 02:58:36 +0000 (02:58 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 7 Mar 2017 02:58:36 +0000 (02:58 +0000)
commita207a853634b1481a3c18f6be4959a3841e3ae91
tree1227acb1d9f4ced3b9b15ee8b355b6d7efa63f62
parentc577b1403ca962a817a3831af1252a2f9aa34484
[APInt] Add getBitsSetFrom and setBitsFrom to set upper bits starting at a bit

We currently have methods to set a specified number of low bits, a specified number of high bits, or a range of bits. But looking at some existing code it seems sometimes we want to set the high bits starting from a certain bit. Currently we do this with something like getHighBits(BitWidth, BitWidth - StartBit). Or once we start switching to setHighBits, setHighBits(BitWidth - StartBit) or setHighBits(getBitWidth() - StartBit).

Particularly for the latter case it would be better to have a convenience method like setBitsFrom(StartBit) so we don't need to mention the bit width that's already known to the APInt object.

I considered just making setBits have a default value of UINT_MAX for the hiBit argument and we would internally MIN it with the bit width. So if it wasn't specified it would be treated as bit width. This would require removing the assertion we currently have on the value of hiBit and may not be as readable.

Differential Revision: https://reviews.llvm.org/D30602

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297114 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/APInt.h
unittests/ADT/APIntTest.cpp