Allow MachineFunction to obtain non-const Function (to enable MIR-level debugify)

Summary:
To debugify MIR, we need to be able to create metadata and to do that, we
need a non-const Module. However, MachineFunction only had a const reference
to the Function preventing this.

Reviewers: aprantl, bogner

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77439
This commit is contained in:
Daniel Sanders 2020-04-03 15:55:15 -07:00
parent bcf14f375e
commit 35b7b0851b
4 changed files with 9 additions and 8 deletions

View File

@ -224,7 +224,7 @@ struct LandingPadInfo {
};
class MachineFunction {
const Function &F;
Function &F;
const LLVMTargetMachine &Target;
const TargetSubtargetInfo *STI;
MCContext &Ctx;
@ -435,7 +435,7 @@ public:
using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
VariableDbgInfoMapTy VariableDbgInfos;
MachineFunction(const Function &F, const LLVMTargetMachine &Target,
MachineFunction(Function &F, const LLVMTargetMachine &Target,
const TargetSubtargetInfo &STI, unsigned FunctionNum,
MachineModuleInfo &MMI);
MachineFunction(const MachineFunction &) = delete;
@ -483,6 +483,9 @@ public:
/// Return the DataLayout attached to the Module associated to this MF.
const DataLayout &getDataLayout() const;
/// Return the LLVM function that this machine code represents
Function &getFunction() { return F; }
/// Return the LLVM function that this machine code represents
const Function &getFunction() const { return F; }

View File

@ -165,9 +165,9 @@ public:
/// Returns the MachineFunction constructed for the IR function \p F.
/// Creates a new MachineFunction if none exists yet.
MachineFunction &getOrCreateMachineFunction(const Function &F);
MachineFunction &getOrCreateMachineFunction(Function &F);
/// \bried Returns the MachineFunction associated to IR function \p F if there
/// \brief Returns the MachineFunction associated to IR function \p F if there
/// is one, otherwise nullptr.
MachineFunction *getMachineFunction(const Function &F) const;

View File

@ -133,8 +133,7 @@ static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
return STI->getFrameLowering()->getStackAlign().value();
}
MachineFunction::MachineFunction(const Function &F,
const LLVMTargetMachine &Target,
MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target,
const TargetSubtargetInfo &STI,
unsigned FunctionNum, MachineModuleInfo &mmi)
: F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {

View File

@ -225,8 +225,7 @@ MachineModuleInfo::getMachineFunction(const Function &F) const {
return I != MachineFunctions.end() ? I->second.get() : nullptr;
}
MachineFunction &
MachineModuleInfo::getOrCreateMachineFunction(const Function &F) {
MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F) {
// Shortcut for the common case where a sequence of MachineFunctionPasses
// all query for the same Function.
if (LastRequest == &F)