> On Jun 9, 2015, at 9:15 AM, Czurda Christoph
> After some experiments I think it works like this: A pass is not allowed
to maintain any pointers or references to llvm Codegen or IR objects, such
as MachineFunction*, MachineInstr*, and so on. Of course it is allowed to
maintain other objects, for example objects from the standard library, in
its state. Can someone confirm that please?
> Von: Czurda Christoph
> Gesendet: Dienstag, 9. Juni 2015 15:00
> An: '[email protected]'
> Betreff: Constraints of MachineFunctionPasses
> I’m having troubles understanding the requirements for machine function
> It says that they are not allowed to “Maintain state across invocations
of runOnMachineFunction (including global data).”
What you need to understand here, is that the state of a machine function
pass is supposed to be valid for the current machine function and is not
supposed to reference anything aside that scope.
The rationale is that at a machine function scope, we only guarantee that
the pointers to the current machine function are valid. I.e., if you store
information about other machine functions, then we do not guarantee those
to still be valid, and thus you may reference freed memory.
If you want to keep references across several functions, you need a context
> However, doesn’t for example the LiveVariables Pass do exactly that?
Besides, how should an analysis pass be of any use if it’s not allowed to
build up data structures that persist after the pass has been run?
Yes, in one sense, LiveVariables pass does that. That being said, most of
the information it sets is attached to the MachineOperand, but yes,
technically, it records some pointers on MIs. However, it uses those values
only if the client asks for it. So the assumption is that the related
function is still valid.
Note: I just quickly scan the LiveVariables pass, I may have miss
> What I actually want to do is to remember for each function call, which
physical registers are live at the time of the call. Therefore I want to
fill a map that contains functions as keys and lists of registers as
values. Wouldn’t a machine function pass be the natural solution to this?
Since you want this information for each function call it sounds like a
context pass would be theoretically better. However, we do not have machine
context pass. So either you can use a context pass, or be very careful with
how you use your machine function pass.
> Best regards,
> LLVM Developers mailing list
> [email protected] http://llvm.cs.uiuc.edu