This showed up in https://reviews.llvm.org/D153308
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
@nikic I agree this is not ideal. Whether it is APInt.h including Alignment.h or the opposite...
Do you have a suggestion on where this should land? If at all?
An alternative would be to document how to handle APInt in Alignment.h but not include the code (it wouldn't be tested though).
Make it a template in the header ;)
template<typename APIntTy> bool isAligned(Align LHS, const APIntTy &SizeInBytes) { ... }
Yep courbet@ made the same suggestion to me but then it conflicts with various types that have implicit conversion to uin64_t most notably TypeSize.
It could work with some enable_it_t incantation but I'm not sure it bears its own weight.
There's no dependency if you just use the raw value instead of the Align wrapper. Also could forward declare Align?
I just checked and it seems that clang is able to optimize out the additional operations
https://godbolt.org/z/G65eKTY3b
Now it's a bit of a bummer to lose the type since you also lose the isPowerOfTwo semantic associated with it :-/
That was the original motivation behind Align.
Forward declaring wouldn't work as-is because Log2 takes Align by value.
I can try to make it take a const ref instead... let's see.
llvm/include/llvm/ADT/APInt.h | ||
---|---|---|
439 | Pass by value or just use the unsigned? |
llvm/include/llvm/ADT/APInt.h | ||
---|---|---|
439 | If we pass by value then we can't forward declare anymore as layout information is needed to copy the value. |
Does isAligned() need to be defined in the header? If it's in the source file then we just need the forward declaration.
I never thought it would work to forward declare and pass by value even if the implementation is in the source file. Thx for the suggestion!
Pass by value or just use the unsigned?