LLVM 23.0.0git
CHERICapabilityFormat.h
Go to the documentation of this file.
1//===--- CHERICapabilityFormat.h --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_SUPPORT_CHERICAPABILITYFORMAT_H
10#define LLVM_SUPPORT_CHERICAPABILITYFORMAT_H
11
12#include "llvm/ADT/ArrayRef.h"
14
15namespace llvm {
16
17template <typename Derived, typename AddressType>
20
21 static constexpr AddressType AddressMask = ~static_cast<AddressType>(0);
22
23 /// Returns the "alignment mask" for an allocation of size \p Length. This
24 /// mask is 0 where the capability format alignment requires the
25 /// address to be 0, and 1 otherwise.
26 static AddressType getAlignmentMask(AddressType Length) {
27 return Derived::getAlignmentMaskImpl(Length);
28 }
29
30 /// Returns the required alignment for an allocation of size \p Length.
31 static Align getRequiredAlignment(AddressType Length) {
32 return Align((~getAlignmentMask(Length) + 1) & AddressMask);
33 }
34
35 /// Returns \p Length rounded up to the nearest representable allocation
36 /// length.
37 static AddressType getRepresentableLength(AddressType Length) {
38 AddressType Mask = getAlignmentMask(Length);
39 return (Length + ~Mask) & Mask;
40 }
41};
42
43template <typename AddressType, unsigned MW, unsigned MAX_E>
46 RVYCapabilityFormat<AddressType, MW, MAX_E>, AddressType> {
47 friend struct CHERICapabilityFormatBase<
48 RVYCapabilityFormat<AddressType, MW, MAX_E>, AddressType>;
49
50private:
51 LLVM_ABI static AddressType getAlignmentMaskImpl(uint64_t Length);
52};
53
56
58 : public CHERICapabilityFormatBase<CHERIoTCapabilityFormat, uint32_t> {
60
61private:
62 LLVM_ABI static uint32_t getAlignmentMaskImpl(uint32_t Length);
63};
64
65} // namespace llvm
66
67#endif
#define LLVM_ABI
Definition Compiler.h:215
This is an optimization pass for GlobalISel generic memory operations.
@ Length
Definition DWP.cpp:573
RVYCapabilityFormat< uint64_t, 14, 52 > RV64YCapabilityFormat
RVYCapabilityFormat< uint32_t, 10, 24 > RV32YCapabilityFormat
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static Align getRequiredAlignment(AddressType Length)
Returns the required alignment for an allocation of size Length.
static AddressType getRepresentableLength(AddressType Length)
Returns Length rounded up to the nearest representable allocation length.
static AddressType getAlignmentMask(AddressType Length)
Returns the "alignment mask" for an allocation of size Length.
static constexpr AddressType AddressMask