# Copies some of the LoopVectorization functionality,1# but solely using Julia base functionality. It is equivalent to `@simd`2# at every loop level3macro turbo(exprs...)4# Find the outermost for loop5body = nothing6for expr in exprs7if Meta.isexpr(expr, :for)8body = expr9end10end11@assert body !== nothing1213# We want to visit each nested for loop and insert a `Loopinfo` expression at every level.14function insert_loopinfo!(expr)15recurse = Meta.isexpr(expr, :for) || Meta.isexpr(expr, :block) ||16Meta.isexpr(expr, :let)17if recurse18foreach(insert_loopinfo!, expr.args)19end20if Meta.isexpr(expr, :for)21# We could insert additional LLVM loopinfo or `julia.ivdep`.22# For now we just encourage vectorization.23# `Expr(:loopinfo)` corresponds to https://llvm.org/docs/LangRef.html#llvm-loop with two additional nodes24# `julia.simdloop` & `julia.ivdep`25# x-ref: https://github.com/JuliaLang/julia/pull/3137626push!(expr.args, Expr(:loopinfo, Symbol("julia.simdloop")))27end28end29insert_loopinfo!(body)3031body = Expr(:block,32Expr(:inbounds, true),33body,34Expr(:inbounds, :pop))35return esc(body)36end373839