Skip to content

Commit

Permalink
CodeGen: Move current call site out of MachineModuleInfo (llvm#100369)
Browse files Browse the repository at this point in the history
I do not know understand what this is for, but it's only used in
SelectionDAGBuilder, so move it to FunctionLoweringInfo like other
function scope DAG builder state. The intrinsics are not documented
in the LangRef or Intrinsics.td.

This removes the last piece of codegen state from MachineModuleInfo.
  • Loading branch information
arsenm authored Jul 26, 2024
1 parent 3834523 commit 6f83a03
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 deletions.
9 changes: 9 additions & 0 deletions llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class FunctionLoweringInfo {
/// SelectionDAGISel::PrepareEHLandingPad().
unsigned ExceptionPointerVirtReg, ExceptionSelectorVirtReg;

/// The current call site index being processed, if any. 0 if none.
unsigned CurCallSite = 0;

/// Collection of dbg.declare instructions handled after argument
/// lowering and before ISel proper.
SmallPtrSet<const DbgDeclareInst *, 8> PreprocessedDbgDeclares;
Expand Down Expand Up @@ -281,6 +284,12 @@ class FunctionLoweringInfo {
Register getCatchPadExceptionPointerVReg(const Value *CPI,
const TargetRegisterClass *RC);

/// Set the call site currently being processed.
void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }

/// Get the call site currently being processed, if any. Return zero if none.
unsigned getCurrentCallSite() { return CurCallSite; }

private:
/// LiveOutRegInfo - Information about live out vregs.
IndexedMap<LiveOutInfo, VirtReg2IndexFunctor> LiveOutRegInfo;
Expand Down
24 changes: 0 additions & 24 deletions llvm/include/llvm/CodeGen/MachineModuleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@ class MachineModuleInfo {
/// want.
MachineModuleInfoImpl *ObjFileMMI;

/// \name Exception Handling
/// \{

/// The current call site index being processed, if any. 0 if none.
unsigned CurCallSite = 0;

/// \}

// TODO: Ideally, what we'd like is to have a switch that allows emitting
// synchronous (precise at call-sites only) CFA into .eh_frame. However,
// even under this switch, we'd like .debug_frame to be precise when using
// -g. At this moment, there's no way to specify that some CFI directives
// go into .eh_frame only, while others go into .debug_frame only.

/// True if debugging information is available in this module.
bool DbgInfoAvailable = false;

Expand Down Expand Up @@ -185,16 +171,6 @@ class MachineModuleInfo {
/// Returns true if valid debug info is present.
bool hasDebugInfo() const { return DbgInfoAvailable; }

/// \name Exception Handling
/// \{

/// Set the call site currently being processed.
void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }

/// Get the call site currently being processed, if any. return zero if
/// none.
unsigned getCurrentCallSite() { return CurCallSite; }

/// \}
}; // End class MachineModuleInfo

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {

/// True if this function needs frame moves for debug or exceptions.
bool MachineFunction::needsFrameMoves() const {
// TODO: Ideally, what we'd like is to have a switch that allows emitting
// synchronous (precise at call-sites only) CFA into .eh_frame. However, even
// under this switch, we'd like .debug_frame to be precise when using -g. At
// this moment, there's no way to specify that some CFI directives go into
// .eh_frame only, while others go into .debug_frame only.
return getMMI().hasDebugInfo() ||
getTarget().Options.ForceDwarfFrameSection ||
F.needsUnwindTableEntry();
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/CodeGen/MachineModuleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ MachineModuleInfoImpl::~MachineModuleInfoImpl() = default;

void MachineModuleInfo::initialize() {
ObjFileMMI = nullptr;
CurCallSite = 0;
NextFnNum = 0;
DbgInfoAvailable = false;
}
Expand All @@ -46,7 +45,6 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
MachineFunctions(std::move(MMI.MachineFunctions)) {
Context.setObjectFileInfo(TM.getObjFileLowering());
ObjFileMMI = MMI.ObjFileMMI;
CurCallSite = MMI.CurCallSite;
ExternalContext = MMI.ExternalContext;
TheModule = MMI.TheModule;
}
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6708,10 +6708,9 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
return;
case Intrinsic::eh_sjlj_callsite: {
ConstantInt *CI = cast<ConstantInt>(I.getArgOperand(0));
assert(DAG.getMMI()->getCurrentCallSite() == 0 &&
"Overlapping call sites!");
assert(FuncInfo.getCurrentCallSite() == 0 && "Overlapping call sites!");

DAG.getMMI()->setCurrentCallSite(CI->getZExtValue());
FuncInfo.setCurrentCallSite(CI->getZExtValue());
return;
}
case Intrinsic::eh_sjlj_functioncontext: {
Expand Down Expand Up @@ -8619,21 +8618,20 @@ SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
const BasicBlock *EHPadBB,
MCSymbol *&BeginLabel) {
MachineFunction &MF = DAG.getMachineFunction();
MachineModuleInfo &MMI = MF.getMMI();

// Insert a label before the invoke call to mark the try range. This can be
// used to detect deletion of the invoke via the MachineModuleInfo.
BeginLabel = MF.getContext().createTempSymbol();

// For SjLj, keep track of which landing pads go with which invokes
// so as to maintain the ordering of pads in the LSDA.
unsigned CallSiteIndex = MMI.getCurrentCallSite();
unsigned CallSiteIndex = FuncInfo.getCurrentCallSite();
if (CallSiteIndex) {
MF.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
LPadToCallSiteMap[FuncInfo.MBBMap[EHPadBB]].push_back(CallSiteIndex);

// Now that the call site is handled, stop tracking it.
MMI.setCurrentCallSite(0);
FuncInfo.setCurrentCallSite(0);
}

return DAG.getEHLabel(getCurSDLoc(), Chain, BeginLabel);
Expand Down

0 comments on commit 6f83a03

Please sign in to comment.