1//===-- AVRMachineFuctionInfo.h - AVR machine function info -----*- 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 declares AVR-specific per-machine-function information.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_AVR_MACHINE_FUNCTION_INFO_H
14#define LLVM_AVR_MACHINE_FUNCTION_INFO_H
15
16#include "llvm/CodeGen/MachineFunction.h"
17#include "llvm/CodeGen/Register.h"
18
19namespace llvm {
20
21/// Contains AVR-specific information for each MachineFunction.
22class AVRMachineFunctionInfo : public MachineFunctionInfo {
23 /// Indicates if a register has been spilled by the register
24 /// allocator.
25 bool HasSpills;
26
27 /// Indicates if there are any fixed size allocas present.
28 /// Note that if there are only variable sized allocas this is set to false.
29 bool HasAllocas;
30
31 /// Indicates if arguments passed using the stack are being
32 /// used inside the function.
33 bool HasStackArgs;
34
35 /// Whether or not the function is an interrupt handler.
36 bool IsInterruptHandler;
37
38 /// Whether or not the function is an non-blocking interrupt handler.
39 bool IsSignalHandler;
40
41 /// Size of the callee-saved register portion of the
42 /// stack frame in bytes.
43 unsigned CalleeSavedFrameSize;
44
45 /// FrameIndex for start of varargs area.
46 int VarArgsFrameIndex;
47
48public:
49 Register AlignedStackReg;
50 unsigned AlignedStackObjectIdx;
51
52 AVRMachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI)
53 : HasSpills(false), HasAllocas(false), HasStackArgs(false),
54 CalleeSavedFrameSize(0), VarArgsFrameIndex(0) {
55 CallingConv::ID CallConv = F.getCallingConv();
56
57 this->IsInterruptHandler =
58 CallConv == CallingConv::AVR_INTR || F.hasFnAttribute(Kind: "interrupt");
59
60 this->IsSignalHandler =
61 CallConv == CallingConv::AVR_SIGNAL || F.hasFnAttribute(Kind: "signal");
62
63 this->AlignedStackReg = 0;
64 this->AlignedStackObjectIdx = 0;
65 }
66
67 MachineFunctionInfo *
68 clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
69 const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
70 const override {
71 return DestMF.cloneInfo<AVRMachineFunctionInfo>(Old: *this);
72 }
73
74 bool getHasSpills() const { return HasSpills; }
75 void setHasSpills(bool B) { HasSpills = B; }
76
77 bool getHasAllocas() const { return HasAllocas; }
78 void setHasAllocas(bool B) { HasAllocas = B; }
79
80 bool getHasStackArgs() const { return HasStackArgs; }
81 void setHasStackArgs(bool B) { HasStackArgs = B; }
82
83 /// Checks if the function is some form of interrupt service routine.
84 bool isInterruptOrSignalHandler() const {
85 return isInterruptHandler() || isSignalHandler();
86 }
87
88 bool isInterruptHandler() const { return IsInterruptHandler; }
89 bool isSignalHandler() const { return IsSignalHandler; }
90
91 unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
92 void setCalleeSavedFrameSize(unsigned Bytes) { CalleeSavedFrameSize = Bytes; }
93
94 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
95 void setVarArgsFrameIndex(int Idx) { VarArgsFrameIndex = Idx; }
96};
97
98} // namespace llvm
99
100#endif // LLVM_AVR_MACHINE_FUNCTION_INFO_H
101