1 //===- RISCVCompressedCap.cpp - CHERI compression helpers ------*- 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 #include "RISCVCompressedCap.h"
10 #include "llvm/CHERI/cheri-compressed-cap/cheri_compressed_cap.h"
11 #include "llvm/Support/ErrorHandling.h"
12
13 namespace llvm {
14
15 namespace RISCVCompressedCap {
getRepresentableLength(uint64_t Length,bool IsRV64)16 uint64_t getRepresentableLength(uint64_t Length, bool IsRV64) {
17 if (IsRV64) {
18 return cc128_get_representable_length(Length);
19 } else {
20 // TODO: cc64 helpers
21 llvm_unreachable("RV32 getRepresentableLength requires cc64_* helper");
22 }
23 }
24
getAlignmentMask(uint64_t Length,bool IsRV64)25 uint64_t getAlignmentMask(uint64_t Length, bool IsRV64) {
26 if (IsRV64) {
27 return cc128_get_alignment_mask(Length);
28 } else {
29 // TODO: cc64 helpers
30 llvm_unreachable("RV32 getAlignmentMask requires cc64_* helper");
31 }
32 }
33
getRequiredTailPadding(uint64_t Size,bool IsRV64)34 TailPaddingAmount getRequiredTailPadding(uint64_t Size, bool IsRV64) {
35 if (IsRV64) {
36 return static_cast<TailPaddingAmount>(
37 llvm::alignTo(Size, cc128_get_required_alignment(Size)) - Size);
38 } else {
39 // TODO: cc64 helpers
40 return TailPaddingAmount::None;
41 }
42 }
43
getRequiredAlignment(uint64_t Size,bool IsRV64)44 Align getRequiredAlignment(uint64_t Size, bool IsRV64) {
45 if (IsRV64) {
46 return Align(cc128_get_required_alignment(Size));
47 } else {
48 // TODO: cc64 helpers
49 return Align();
50 }
51 }
52 } // namespace RISCVCompressedCap
53 } // namespace llvm
54