[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / lib / Target / AArch64 / AArch64StackOffset.h
blob5f5cdfa2fad1cb7d2ebe6c472e8cb26813c907c7
1 //==--AArch64StackOffset.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 // This file contains the declaration of the StackOffset class, which is used to
10 // describe scalable and non-scalable offsets during frame lowering.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64STACKOFFSET_H
15 #define LLVM_LIB_TARGET_AARCH64_AARCH64STACKOFFSET_H
17 #include "llvm/Support/MachineValueType.h"
19 namespace llvm {
21 /// StackOffset is a wrapper around scalable and non-scalable offsets and is
22 /// used in several functions such as 'isAArch64FrameOffsetLegal' and
23 /// 'emitFrameOffset()'. StackOffsets are described by MVTs, e.g.
25 /// StackOffset(1, MVT::nxv16i8)
27 /// would describe an offset as being the size of a single SVE vector.
28 ///
29 /// The class also implements simple arithmetic (addition/subtraction) on these
30 /// offsets, e.g.
32 /// StackOffset(1, MVT::nxv16i8) + StackOffset(1, MVT::i64)
34 /// describes an offset that spans the combined storage required for an SVE
35 /// vector and a 64bit GPR.
36 class StackOffset {
37 int64_t Bytes;
39 explicit operator int() const;
41 public:
42 using Part = std::pair<int64_t, MVT>;
44 StackOffset() : Bytes(0) {}
46 StackOffset(int64_t Offset, MVT::SimpleValueType T) : StackOffset() {
47 assert(!MVT(T).isScalableVector() && "Scalable types not supported");
48 *this += Part(Offset, T);
51 StackOffset(const StackOffset &Other) : Bytes(Other.Bytes) {}
53 StackOffset &operator=(const StackOffset &) = default;
55 StackOffset &operator+=(const StackOffset::Part &Other) {
56 assert(Other.second.getSizeInBits() % 8 == 0 &&
57 "Offset type is not a multiple of bytes");
58 Bytes += Other.first * (Other.second.getSizeInBits() / 8);
59 return *this;
62 StackOffset &operator+=(const StackOffset &Other) {
63 Bytes += Other.Bytes;
64 return *this;
67 StackOffset operator+(const StackOffset &Other) const {
68 StackOffset Res(*this);
69 Res += Other;
70 return Res;
73 StackOffset &operator-=(const StackOffset &Other) {
74 Bytes -= Other.Bytes;
75 return *this;
78 StackOffset operator-(const StackOffset &Other) const {
79 StackOffset Res(*this);
80 Res -= Other;
81 return Res;
84 StackOffset operator-() const {
85 StackOffset Res = {};
86 const StackOffset Other(*this);
87 Res -= Other;
88 return Res;
91 /// Returns the non-scalable part of the offset in bytes.
92 int64_t getBytes() const { return Bytes; }
94 /// Returns the offset in parts to which this frame offset can be
95 /// decomposed for the purpose of describing a frame offset.
96 /// For non-scalable offsets this is simply its byte size.
97 void getForFrameOffset(int64_t &ByteSized) const { ByteSized = Bytes; }
99 /// Returns whether the offset is known zero.
100 explicit operator bool() const { return Bytes; }
103 } // end namespace llvm
105 #endif