Skip to content

Commit

Permalink
Add a 'mono.this' custom metadata, this is used to mark an 'alloca' w…
Browse files Browse the repository at this point in the history
…hose associated stack slot index will be saved in MachineFunction, and later can be saved in the mono specific EH tables.
  • Loading branch information
vargaz committed Mar 26, 2022
1 parent 8d01bed commit d8126bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
/// \pre Fn, Target, MMI, and FunctionNumber are properly set.
void init();

// Stack slot containing the this pointer for mono compiled functions
int MonoThisSlot;

public:
struct VariableDbgInfo {
const DILocalVariable *Var;
Expand Down Expand Up @@ -600,6 +603,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {

PseudoSourceValueManager &getPSVManager() const { return *PSVManager; }

int getMonoThisSlot() const { return MonoThisSlot; }
void setMonoThisSlot(int Slot) { MonoThisSlot = Slot; }

/// Return the DataLayout attached to the Module associated to this MF.
const DataLayout &getDataLayout() const;

Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ void MachineFunction::init() {
PSVManager =
std::make_unique<PseudoSourceValueManager>(*(getSubtarget().
getInstrInfo()));

MonoThisSlot = -1;
}

MachineFunction::~MachineFunction() {
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
for (int *CatchObjPtr : Iter->second)
*CatchObjPtr = FrameIndex;
}

//
// The mono exception handling code needs to location of the 'this' pointer
// to handle stack traces containing generic shared methods.
// To implement this, it saves the this pointer to an alloca which is marked with
// the 'mono.this' custom metadata. We save the stack slot used by this alloca
// in MachineFunction, so the dwarf exception info emission code can use it to
// compute the reg+offset for it, and save it into the LSDA.
//
if (AI->getMetadata("mono.this"))
MF->setMonoThisSlot(StaticAllocaMap[AI]);
} else {
// FIXME: Overaligned static allocas should be grouped into
// a single dynamic allocation instead of using a separate
Expand Down

0 comments on commit d8126bd

Please sign in to comment.