Skip to content

Commit 35b7b08

Browse files
committed
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
1 parent bcf14f3 commit 35b7b08

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ struct LandingPadInfo {
224224
};
225225

226226
class MachineFunction {
227-
const Function &F;
227+
Function &F;
228228
const LLVMTargetMachine &Target;
229229
const TargetSubtargetInfo *STI;
230230
MCContext &Ctx;
@@ -435,7 +435,7 @@ class MachineFunction {
435435
using VariableDbgInfoMapTy = SmallVector<VariableDbgInfo, 4>;
436436
VariableDbgInfoMapTy VariableDbgInfos;
437437

438-
MachineFunction(const Function &F, const LLVMTargetMachine &Target,
438+
MachineFunction(Function &F, const LLVMTargetMachine &Target,
439439
const TargetSubtargetInfo &STI, unsigned FunctionNum,
440440
MachineModuleInfo &MMI);
441441
MachineFunction(const MachineFunction &) = delete;
@@ -483,6 +483,9 @@ class MachineFunction {
483483
/// Return the DataLayout attached to the Module associated to this MF.
484484
const DataLayout &getDataLayout() const;
485485

486+
/// Return the LLVM function that this machine code represents
487+
Function &getFunction() { return F; }
488+
486489
/// Return the LLVM function that this machine code represents
487490
const Function &getFunction() const { return F; }
488491

llvm/include/llvm/CodeGen/MachineModuleInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ class MachineModuleInfo {
165165

166166
/// Returns the MachineFunction constructed for the IR function \p F.
167167
/// Creates a new MachineFunction if none exists yet.
168-
MachineFunction &getOrCreateMachineFunction(const Function &F);
168+
MachineFunction &getOrCreateMachineFunction(Function &F);
169169

170-
/// \bried Returns the MachineFunction associated to IR function \p F if there
170+
/// \brief Returns the MachineFunction associated to IR function \p F if there
171171
/// is one, otherwise nullptr.
172172
MachineFunction *getMachineFunction(const Function &F) const;
173173

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
133133
return STI->getFrameLowering()->getStackAlign().value();
134134
}
135135

136-
MachineFunction::MachineFunction(const Function &F,
137-
const LLVMTargetMachine &Target,
136+
MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target,
138137
const TargetSubtargetInfo &STI,
139138
unsigned FunctionNum, MachineModuleInfo &mmi)
140139
: F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {

llvm/lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ MachineModuleInfo::getMachineFunction(const Function &F) const {
225225
return I != MachineFunctions.end() ? I->second.get() : nullptr;
226226
}
227227

228-
MachineFunction &
229-
MachineModuleInfo::getOrCreateMachineFunction(const Function &F) {
228+
MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F) {
230229
// Shortcut for the common case where a sequence of MachineFunctionPasses
231230
// all query for the same Function.
232231
if (LastRequest == &F)

0 commit comments

Comments
 (0)