[LLVMdev] Docs question: legality of inspecting other functions in a function pass

Duncan Sands baldrick at free.fr
Fri Jul 5 06:03:49 PDT 2013


Hi Stephen,

On 04/07/13 20:21, Stephen Lin wrote:
> On Thu, Jul 4, 2013 at 1:45 AM, David Chisnall
> <David.Chisnall at cl.cam.ac.uk> wrote:
>> On 3 Jul 2013, at 23:05, Stephen Lin <swlin at post.harvard.edu> wrote:
>>
>>> Does anyone know if there's a defined policy about this, either way?
>>> If so, I think it ought to be noted in the docs, for consistency.
>>
>> The prohibition exists, at least in part, because in theory it would be nice to be able to run passes in parallel.  It's not a real limitation at the moment because updating instructions in a module is not thread safe (and making it so with the current APIs would probably be somewhat problematic in terms of performance) and so when we do eventually get the ability to run FunctionPasses in parallel they will most likely need new APIs.  That said, it's a good idea structurally to view the Function / Block as synchronisation boundaries so that it will be easier to support concurrent execution in the future.
>>
>
> I understand the rationale but are you sure that the prohibition
> against *inspecting* other functions during a function pass does exist
> and is currently followed? If it does I think the docs ought to make
> that clear so I want to make sure if the omission is not deliberate.
>
> In theory you could still parallelize function pass execution if they
> inspected other functions if they used some kind of read/write locking
> and used transactional updates; I would think the main point is that
> we want the results to be deterministic and not dependent on the order
> in which functions are processed, which applies regardless of what
> kind of parallelization and/or synchronization is used.

both dragonegg and clang (AFAIK) run some function passes on each function
in turn as they are turned into LLVM IR.  If such a function pass tried to
inspect other functions then they won't be able to see all function bodies
because they haven't all been output yet.  And which functions do have bodies
available to be inspected depends on the order in which clang decides to
output functions, so the results of running the pass would depend on that
order.

Ciao, Duncan.



More information about the llvm-dev mailing list