[PATCH] D13193: Add an MCTargetMachine and use it to configure MCAsmInfo

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 03:42:09 PDT 2015


dsanders added a comment.

Having written a couple follow-on patches and reached the point where MCSubtargetInfo can (almost) be migrated and used appropriately, there's an issue I need to bring up.

To avoid dereferencing null MCTargetMachine pointers held by partially initialized TargetMachines there's a need to pass a MCTargetMachine to createTargetMachine(). However, this makes it necessary to call createMCTargetMachine() from LLVMCreateTargetMachine(). We can't change the C-API so we have four options:

1. Allow a memory leak. Obviously this isn't a good choice.
2. Change TargetMachine to an is-a relationship with MCTargetMachine. This doesn't look possible because you end up with MipsTargetMachine is-a TargetMachine is-a MipsMCTargetMachine is-a MCTargetMachine and this can't happen for more than one target.
3. Have Target/TargetMachine own MCTargetMachines allocated by LLVMCreateTargetMachine()
4. Wrap TargetMachine pointers returned by the C-API in a new class that also owns the MCTargetMachine pointer for the existing C-API and have LLVMDisposeTargetMachine() delete the MCTargetMachine if it owns it.

I'm not keen on any of these but the fourth sounds most sensible since it keeps this problem in the C-API's domain without affecting C++. Thoughts?


http://reviews.llvm.org/D13193





More information about the llvm-commits mailing list