[PATCH] D72068: [IR] Refactor SubclassData

Ehud Katz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 23:58:04 PST 2020


ekatz created this revision.
ekatz added reviewers: lattner, craig.topper, chandlerc, rnk, riccibruno.
ekatz added a project: LLVM.
Herald added subscribers: llvm-commits, jfb, dexonsmith, hiraditya.

A new implementation of the Subclass Data exposed from `llvm::Value`, which simplifies the process of adding new data/flags into the `llvm::Value::SubclassData`.

In detail, the new implementation offers the following new features:

- static assert - that the declared accumulated bitfields do not exceed the underlying subclass data size (note that int the New implementation it is automatically added on declaration)
- runtime assert - that a new value set, fits into the the bitfield (without truncation).
- typed - as opposed to using a representative type (like `int`) and then cast to the actual required type (like `bool` or `enum`). Typed (ordinary) bitfields cannot be implemented correctly in MSVC, as the types of all the bitfields must be of the same type. Using typed bitfields also saves us the need to synchronize the use of `unsigned/signed int` with the actual type needed.
- declare (a bitfield) in a single line - as opposed to the need to declare helpers or somekind, like `enum` (manually).
- clean bitfields - without exposing a bit manipulation `enum`.
- automatic inheritance of unused bits - no need to get offset from super (manually).
- automatic calculation of unused bits - changing a single bitfield doesn't require any other change, but the actual bitfield itself (as opposed to changing also the sum of the bit count used by the class, in an `enum` - for exmple).
- implicit reference to superclass - as opposed to the need to use the base class' info explicitly.
- no need to know anything about any of the base classes.

The core of the change is present in the 2 new files: BitField.h and SubclassData.h (while the other changed files are just refactored to use the new implementation).

An example of the run-time benefits (to add to the compile-time benefits mentioned above):
By using the new implementation, I have managed to move the SSID field (that some Instructions have) into the Subclass Data of the Instructions, and in turn reduce the size of those instructions by 8 bytes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72068

Files:
  llvm/include/llvm/ADT/BitField.h
  llvm/include/llvm/ADT/STLExtras.h
  llvm/include/llvm/ADT/SubclassData.h
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/IR/BasicBlock.h
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/Function.h
  llvm/include/llvm/IR/GlobalObject.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/IR/Instructions.h
  llvm/include/llvm/IR/Operator.h
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/IR/User.h
  llvm/include/llvm/IR/Value.h
  llvm/include/llvm/Support/AtomicOrdering.h
  llvm/include/llvm/Support/type_traits.h
  llvm/include/llvm/Transforms/Utils/FunctionComparator.h
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/ConstantsContext.h
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Globals.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/IR/User.cpp
  llvm/lib/IR/Value.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Scalar/Reassociate.cpp
  llvm/lib/Transforms/Utils/FunctionComparator.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72068.235831.patch
Type: text/x-patch
Size: 139195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200102/3931f8df/attachment-0001.bin>


More information about the llvm-commits mailing list