Is it possible to AddRequired<...> a pass that is dynamically loaded? This would be very convenient for a course project but the documentation about pass interactions says nothing about dynamically loaded passes and vice versa. More specifically, to refer to the pass name in AddRequired, I need to declare it first but then I can't think of a way to load the module implementing the pass dynamically instead of linking it statically. --Vikram http://www.cs.uiuc.edu/~vadve http://llvm.org
Adve, Vikram Sadanand wrote:> Is it possible to AddRequired<...> a pass that is dynamically > loaded? This would be very convenient for a course project but the > documentation about pass interactions says nothing about dynamically > loaded passes and vice versa. > > More specifically, to refer to the pass name in AddRequired, I need > to declare it first but then I can't think of a way to load the > module implementing the pass dynamically instead of linking it > statically. >I believe SAFECode and Pool Allocation already do this. You can use addRequired to specify that a pass is required; the header file defined the pass to be required must be #include'd into the source of the your pass. Everything should compile, but you'll have undefined symbols. When you use opt, you'll need to use multiple -load options to load your passes. I believe you should load the prerequisite pass first and then your pass. Just make sure that there are no circular dependences between the two passes. If that doesn't work, use gcc to create a new dynamic library that contains the prerequisite pass library and your pass library; you can load that with a single -load option to opt. -- John T.> --Vikram > http://www.cs.uiuc.edu/~vadve > http://llvm.org > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Dec 4, 2007, at 11:24, Vikram S. Adve wrote:> Is it possible to AddRequired<...> a pass that is dynamically > loaded? This would be very convenient for a course project but the > documentation about pass interactions says nothing about dynamically > loaded passes and vice versa. > > More specifically, to refer to the pass name in AddRequired, I need > to declare it first but then I can't think of a way to load the > module implementing the pass dynamically instead of linking it > statically.I think if you define the pass ID in your host and use AddRequiredID instead of AddRequired: char LoadablePassID = 0; ... AU.addRequiredID(lookupPassInfo((intptr_t) &LoadablePassID)); then it should work if the loadable module references the same pass ID as an extern: extern char ExternalPassID; class ThePass : public ImmutablePass { public: ThePass : ImmutablePass(&ExternalPassID) {} }; An analysis group may also be a viable option. — Gordon
Thanks for the suggestions, Gordon and John. I tried the approach below, which sounds more like the right way to do it, but ran into 2 problems (which indicate to me that this capability is not really supported right now). First, RegisterPass *assumes* that the pass ID is a field within the pass class, so it cannot be an extern variable as you suggested below below. This can be fixed by making that assumption only be a default (via a default argument), not a requirement, in RegisterPass. But second, I ran into what looks like an unsupported case: PMDataManager::addLowerLevelRequiredPass which asserts out. This could be just a default method that is supposed to be redefined by a subclass, but it wasn't clear why it hit this case. I found another way to do what I needed. --Vikram http://www.cs.uiuc.edu/~vadve http://llvm.org On Dec 4, 2007, at 10:58 AM, Gordon Henriksen wrote:> On Dec 4, 2007, at 11:24, Vikram S. Adve wrote: > >> Is it possible to AddRequired<...> a pass that is dynamically >> loaded? This would be very convenient for a course project but the >> documentation about pass interactions says nothing about dynamically >> loaded passes and vice versa. >> >> More specifically, to refer to the pass name in AddRequired, I need >> to declare it first but then I can't think of a way to load the >> module implementing the pass dynamically instead of linking it >> statically. > > I think if you define the pass ID in your host and use AddRequiredID > instead of AddRequired: > > char LoadablePassID = 0; > ... > AU.addRequiredID(lookupPassInfo((intptr_t) &LoadablePassID)); > > then it should work if the loadable module references the same pass ID > as an extern: > > extern char ExternalPassID; > > class ThePass : public ImmutablePass { > public: > ThePass : ImmutablePass(&ExternalPassID) {} > }; > > An analysis group may also be a viable option. > > — Gordon > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev