From 5168e3507ac5acf1f04f18133424d3c3fd04b3a7 Mon Sep 17 00:00:00 2001 From: Nicolau Werneck Date: Tue, 30 Apr 2019 17:12:11 +0200 Subject: [PATCH] Recover meta nodes in replace_code_newstyle (#31871) Copy meta nodes from IRCode to CodeInfo --- base/compiler/ssair/legacy.jl | 6 ++++++ test/compiler/ssair.jl | 9 +++++++++ test/llvmpasses/noinline.jl | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 test/llvmpasses/noinline.jl diff --git a/base/compiler/ssair/legacy.jl b/base/compiler/ssair/legacy.jl index 88bfd419a842b..038bd75daa011 100644 --- a/base/compiler/ssair/legacy.jl +++ b/base/compiler/ssair/legacy.jl @@ -57,6 +57,12 @@ function replace_code_newstyle!(ci::CodeInfo, ir::IRCode, nargs::Int) ci.linetable = ir.linetable ci.ssavaluetypes = ir.types ci.ssaflags = ir.flags + for metanode in ir.meta + push!(ci.code, metanode) + push!(ci.codelocs, 1) + push!(ci.ssavaluetypes, Any) + push!(ci.ssaflags, 0x00) + end # Translate BB Edges to statement edges # (and undo normalization for now) for i = 1:length(ci.code) diff --git a/test/compiler/ssair.jl b/test/compiler/ssair.jl index cb25bf588b029..88ce5985a23ac 100644 --- a/test/compiler/ssair.jl +++ b/test/compiler/ssair.jl @@ -87,3 +87,12 @@ for compile in ("min", "yes") error("Interpreter test failed, cmd : $cmd") end end + +# Issue #27104 +# Test whether meta nodes are still present after code optimization. +let + @noinline f(x, y) = x + y + @test any(code_typed(f)[1][1].code) do ex + Meta.isexpr(ex, :meta) + end +end diff --git a/test/llvmpasses/noinline.jl b/test/llvmpasses/noinline.jl new file mode 100644 index 0000000000000..f542968b21979 --- /dev/null +++ b/test/llvmpasses/noinline.jl @@ -0,0 +1,21 @@ +# This file is a part of Julia. License is MIT: https://julialang.org/license + +# RUN: julia --startup-file=no %s %t && llvm-link -S %t/* -o %t/module.ll +# RUN: cat %t/module.ll | FileCheck %s + +## Notes: +# This script uses the `emit` function (defined llvmpasses.jl) to emit either +# optimized or unoptimized LLVM IR. Each function is emitted individually and +# `llvm-link` is used to create a single module that can be passed to opt. +# The order in which files are emitted and linked is important since `lit` will +# process the test cases in order. + +include(joinpath("..", "testhelpers", "llvmpasses.jl")) + +# CHECK-LABEL: @julia_simple_noinline +@noinline function simple_noinline(A, B) + return A + B +end + +# CHECK: attributes #{{[0-9]+}} = {{{([a-z]+ )*}} noinline {{([a-z]+ )*}}} +emit(simple_noinline, Float64, Float64)