This is an archive of the discontinued LLVM Phabricator instance.

Add MachineModuleInfo constructor with external MCContext
ClosedPublic

Authored by hgreving on Nov 11 2020, 6:03 PM.

Details

Summary

Adds a constructor to MachineModuleInfo and MachineModuleInfoWapperPass that
takes an external MCContext. If provided, the external context will be used
throughout codegen instead of MMI's default one.

This enables external drivers to take ownership of data put on the MMI's context
during codegen. The internal context is otherwise used and destroyed upon
finish.

Diff Detail

Event Timeline

hgreving created this revision.Nov 11 2020, 6:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2020, 6:03 PM
hgreving requested review of this revision.Nov 11 2020, 6:03 PM
ychen added a subscriber: ychen.Nov 11 2020, 8:52 PM
hgreving updated this revision to Diff 306289.Nov 18 2020, 7:30 PM
hgreving edited the summary of this revision. (Show Details)

Copy constructor.

majnemer accepted this revision.Nov 19 2020, 5:41 PM

LGTM

llvm/lib/CodeGen/MachineModuleInfo.cpp
172–173

Probably should have a comment saying *not* to clear out ExternalContext.

This revision is now accepted and ready to land.Nov 19 2020, 5:41 PM
hgreving updated this revision to Diff 306697.Nov 20 2020, 8:07 AM
jmolloy accepted this revision.Nov 30 2020, 7:41 AM

Looks reasonable to me. I'd have probably done something like:

MCContext& Context; // not owned, used for all accesses;
optional<MCContext> LocalContextStorage;

MachineModuleInfo() :

LocalContextStorage(), Context(LocalContextStorage) {

}

MachineModuleInfo(MCContext* Context) :

Context(*Context) {

}

But your way is fine too.

This revision was automatically updated to reflect the committed changes.
hgreving marked an inline comment as done.