[cfe-dev] How Pragma Unroll works in clang and llvm

Friedman, Eli via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 10 12:02:10 PDT 2017


On 8/10/2017 10:48 AM, Nisal Menuka via cfe-dev wrote:
> Hi,
> I am trying to understand how Pragma Unroll is implemented in clang and llvm.
>
> According to my understanding, this pragma is processed and new token
> is generated in clang/lib/Parse/ParsePragma.cpp
> PragmaUnrollHintHandler::HandlePragma function.
> Then the token is processed in *handleLoopHintAttr in
> clang/lib/Sema/SemaStmtAttr.cpp file.
>
> But its not clear to me how this information is parsed to LLVM and processed.

clang annotates the IR for the loop with metadata, then the loop unroll 
pass uses that metadata to unroll the loop as requested.  See 
http://llvm.org/docs/LangRef.html#llvm-loop-unroll for a description of 
the metadata.  If you want to read the related code, grep for 
"llvm.loop.unroll".

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project




More information about the cfe-dev mailing list