[LLVMdev] [PATCH] parallel loop metadata

Sebastian Pop spop at codeaurora.org
Thu Jan 31 08:27:24 PST 2013


Pekka Jääskeläinen wrote:
> +'``llvm.loop``'
> +^^^^^^^^^^^^^^^
> +
> +It is sometimes useful to attach information to loop constructs. Currently,
> +loop metadata is implemented as metadata attached to the branch instruction
> +in the loop latch block. Loop-level metadata is prefixed with ``llvm.loop``.
> +
> +'``llvm.loop.parallel``' Metadata
> +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +This loop metadata can be used to communicate that a loop should be considered
> +a parallel loop. The semantics of parallel loops in this case is the one
> +with the strongest cross-iteration instruction ordering freedom: the
> +iterations in the loop can be considered completely independent of each
> +other (also known as embarrasingly parallel loops).
> +
> +This metadata can originate from a programming language with parallel loop
> +constructs. In such a case it is completely the programmer's responsibility
> +to ensure the instructions from the different iterations of the loop can be
> +executed in an arbitrary order, in parallel, or intertwined. No loop-carried
> +dependency checking at all must be expected from the compiler.
> +
> +In order to fulfil the LLVM requirement for metadata to be ignorable

I would avoid using "ignorable": just use "for metadata to be safely ignored".

> +safely, it is important to ensure that a parallel loop is converted to
> +a sequential loop in case an optimization (unknowingly of the parallel loop

"unknowingly" is an adverb, what you need here is an adjective qualifying "an
optimization", so I would use "agnostic".

> +semantics) converts the loop back to such. This happens when new memory
> +accesses that do not fulfil the requirement of free ordering across iterations
> +are added to the loop. Therefore, this metadata is required, but not
> +sufficient, to consider the loop at hand a parallel loop. In order to consider
> +a loop a parallel loop, also all of its memory accessing instructions need to be

s/In order to consider a loop a parallel loop, also all of its memory accessing instructions/
For a loop to be parallel, all its memory accesses/

> +marked with the ```llvm.mem.parallel_loop_access``` metadata.

Why do you use 3 backquotes instead of only 2? Here and below.

> +
> +'``llvm.mem``'
> +^^^^^^^^^^^^^^^
> +
> +Metadata types used to annotate memory accesses with information helpful
> +for optimizations are prefixed with ``llvm.mem``.
> +
> +'``llvm.mem.parallel_loop_access``' Metadata
> +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +In order to consider a loop a parallel loop, in addition to using

s/In order to consider a loop a parallel loop/For a loop to be parallel/

> +the ``llvm.loop.parallel`` metadata to mark the loop latch branch instruction,
> +also all of the memory accessing instructions in the loop body need to be
> +marked with the ``llvm.mem.parallel_loop_access`` metadata. If there
> +is at least one memory accessing instruction not marked with the metadata,
> +the loop, despite it possibly using the ``llvm.loop.parallel`` metadata,
> +must be considered a sequential loop. This causes parallel loops to be
> +converted to sequential loops due to optimization passes that are unaware of
> +the parallel semantics and that insert new memory instructions to the loop
> +body.
> +
> +Example of a loop that is considered parallel due to its correct use of
> +both ``llvm.loop.parallel`` and ```llvm.mem.parallel_loop_access```
> +metadata types:
> +
> +.. code-block:: llvm
> +
> +   for.body:
> +   %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
> +   %arrayidx = getelementptr inbounds i32* %b, i64 %indvars.iv
> +   %0 = load i32* %arrayidx, align 4, !llvm.mem.parallel_loop_access !0
> +   ...
> +   store i32 %0, i32* %arrayidx4, align 4, !llvm.mem.parallel_loop_access !0
> +   ...
> +   br i1 %exitcond, label %for.end, label %for.body, !llvm.loop.parallel !0
> +   for.end:                                          ; preds = %for.body
> +   ret void
> +   ...
> +   !0 = metadata !{i32 1}

Can you please also explain how global variables are handled?

Thanks,
Sebastian
-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation



More information about the llvm-dev mailing list