[LLVMdev] Constraints of MachineFunctionPasses

Quentin Colombet qcolombet at apple.com
Thu Jun 11 10:14:20 PDT 2015


Hi Czurda,

> On Jun 9, 2015, at 9:15 AM, Czurda Christoph <Christoph.Czurda.fl at ait.ac.at> wrote:
> 
> 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: 'llvmdev at cs.uiuc.edu'
> Betreff: Constraints of MachineFunctionPasses
>  
> Hello,
>  
> I’m having troubles understanding the requirements for machine function passes:http://llvm.org/releases/3.4/docs/WritingAnLLVMPass.html#the-machinefunctionpass-class <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_releases_3.4_docs_WritingAnLLVMPass.html-23the-2Dmachinefunctionpass-2Dclass&d=AwMFAg&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ZfybqLPGgzux8FmKK6mQsmg_W8uJI32RgHbr25OOSmw&s=VcT7iP37FwHMqLQCCLdxjoMJ1WEQW_3UsbatepvE7Z4&e=>
> 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 pass.

>  
> 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 something!

>  
> 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.

Cheers,
-Quentin
>  
> Best regards,
> Christoph
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150611/624044be/attachment.html>


More information about the llvm-dev mailing list