llvm-project/llvm/lib/Target/CSKY/CSKYMachineFunctionInfo.h
Matt Arsenault 69e75ae695 CodeGen: Don't lazily construct MachineFunctionInfo
This fixes what I consider to be an API flaw I've tripped over
multiple times. The point this is constructed isn't well defined, so
depending on where this is first called, you can conclude different
information based on the MachineFunction. For example, the AMDGPU
implementation inspected the MachineFrameInfo on construction for the
stack objects and if the frame has calls. This kind of worked in
SelectionDAG which visited all allocas up front, but broke in
GlobalISel which hasn't visited any of the IR when arguments are
lowered.

I've run into similar problems before with the MIR parser and trying
to make use of other MachineFunction fields, so I think it's best to
just categorically disallow dependency on the MachineFunction state in
the constructor and to always construct this at the same time as the
MachineFunction itself.

A missing feature I still could use is a way to access an custom
analysis pass on the IR here.
2022-12-21 10:49:32 -05:00

68 lines
2.1 KiB
C++

//=- CSKYMachineFunctionInfo.h - CSKY machine function info -------*- C++ -*-=//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares CSKY-specific per-machine-function information.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_CSKY_CSKYMACHINEFUNCTIONINFO_H
#define LLVM_LIB_TARGET_CSKY_CSKYMACHINEFUNCTIONINFO_H
#include "llvm/CodeGen/MachineFunction.h"
namespace llvm {
class CSKYMachineFunctionInfo : public MachineFunctionInfo {
Register GlobalBaseReg = 0;
bool SpillsCR = false;
int VarArgsFrameIndex = 0;
unsigned VarArgsSaveSize = 0;
int spillAreaSize = 0;
bool LRSpilled = false;
unsigned PICLabelUId = 0;
public:
CSKYMachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI) {}
MachineFunctionInfo *
clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
const override {
return DestMF.cloneInfo<CSKYMachineFunctionInfo>(*this);
}
Register getGlobalBaseReg() const { return GlobalBaseReg; }
void setGlobalBaseReg(Register Reg) { GlobalBaseReg = Reg; }
void setSpillsCR() { SpillsCR = true; }
bool isCRSpilled() const { return SpillsCR; }
void setVarArgsFrameIndex(int v) { VarArgsFrameIndex = v; }
int getVarArgsFrameIndex() { return VarArgsFrameIndex; }
unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
bool isLRSpilled() const { return LRSpilled; }
void setLRIsSpilled(bool s) { LRSpilled = s; }
void setCalleeSaveAreaSize(int v) { spillAreaSize = v; }
int getCalleeSaveAreaSize() const { return spillAreaSize; }
unsigned createPICLabelUId() { return ++PICLabelUId; }
void initPICLabelUId(unsigned UId) { PICLabelUId = UId; }
};
} // namespace llvm
#endif // LLVM_LIB_TARGET_CSKY_CSKYMACHINEFUNCTIONINFO_H