1//= HexagonMachineFunctionInfo.cpp - Hexagon 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#include "HexagonMachineFunctionInfo.h"
10#include "llvm/CodeGen/TargetRegisterInfo.h"
11#include "llvm/Support/raw_ostream.h"
12
13using namespace llvm;
14
15// pin vtable to this file
16void HexagonMachineFunctionInfo::anchor() {}
17
18HexagonMachineFunctionInfo::HexagonMachineFunctionInfo(
19 const HexagonMachineFunctionInfo &Other)
20 : SRetReturnReg(Other.SRetReturnReg),
21 StackAlignBaseReg(Other.StackAlignBaseReg),
22 VarArgsFrameIndex(Other.VarArgsFrameIndex),
23 RegSavedAreaStartFrameIndex(Other.RegSavedAreaStartFrameIndex),
24 FirstNamedArgFrameIndex(Other.FirstNamedArgFrameIndex),
25 LastNamedArgFrameIndex(Other.LastNamedArgFrameIndex),
26 HasClobberLR(Other.HasClobberLR), HasEHReturn(Other.HasEHReturn),
27 MaxVTCMCallFrameSize(Other.MaxVTCMCallFrameSize),
28 PacketInfo(Other.PacketInfo) {
29 DenseMap<int, int> ClonedIndices;
30 const MachineFrameInfo &OtherMFI = Other.VTCMFrameInfo;
31 for (int I = OtherMFI.getObjectIndexBegin(), E = OtherMFI.getObjectIndexEnd();
32 I != E; ++I) {
33 if (OtherMFI.isDeadObjectIndex(ObjectIdx: I))
34 continue;
35 int NewI = OtherMFI.isFixedObjectIndex(ObjectIdx: I)
36 ? VTCMFrameInfo.CreateFixedObject(
37 Size: OtherMFI.getObjectSize(ObjectIdx: I), SPOffset: OtherMFI.getObjectOffset(ObjectIdx: I),
38 /*IsImmutable=*/true)
39 : VTCMFrameInfo.CreateStackObject(
40 Size: OtherMFI.getObjectSize(ObjectIdx: I), Alignment: OtherMFI.getObjectAlign(ObjectIdx: I),
41 isSpillSlot: OtherMFI.isSpillSlotObjectIndex(ObjectIdx: I),
42 Alloca: OtherMFI.getObjectAllocation(ObjectIdx: I));
43 VTCMFrameInfo.setObjectOffset(ObjectIdx: NewI, SPOffset: OtherMFI.getObjectOffset(ObjectIdx: I));
44 ClonedIndices[I] = NewI;
45 }
46 VTCMFrameInfo.setStackSize(OtherMFI.getStackSize());
47 for (const auto &[From, To] : Other.VTCMMap)
48 VTCMMap[From] = ClonedIndices.lookup(Val: To);
49}
50
51MachineFunctionInfo *HexagonMachineFunctionInfo::clone(
52 BumpPtrAllocator &Allocator, MachineFunction &DestMF,
53 const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
54 const {
55 return DestMF.cloneInfo<HexagonMachineFunctionInfo>(Old: *this);
56}
57
58static yaml::StringValue regToString(Register Reg,
59 const TargetRegisterInfo &TRI) {
60 yaml::StringValue Dest;
61 if (Reg.isValid()) {
62 raw_string_ostream OS(Dest.Value);
63 OS << printReg(Reg, TRI: &TRI);
64 }
65 return Dest;
66}
67
68yaml::HexagonFunctionInfo::HexagonFunctionInfo(
69 const llvm::HexagonMachineFunctionInfo &MFI, const TargetRegisterInfo &TRI)
70 : StackAlignBaseReg(regToString(Reg: MFI.getStackAlignBaseReg(), TRI)),
71 MaxVTCMCallFrameSize(MFI.getMaxVTCMCallFrameSize()) {}
72
73void yaml::HexagonFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
74 MappingTraits<HexagonFunctionInfo>::mapping(YamlIO, MFI&: *this);
75}
76
77void HexagonMachineFunctionInfo::initializeBaseYamlFields(
78 const yaml::HexagonFunctionInfo &YamlMFI) {
79 MaxVTCMCallFrameSize = YamlMFI.MaxVTCMCallFrameSize;
80}
81