[Mesa-dev] [PATCH 1/4] amd/common: add nir->llvm translation.

Nicolai Hähnle nhaehnle at gmail.com
Tue Oct 4 10:09:52 UTC 2016


On 04.10.2016 03:48, Dave Airlie wrote:
> From: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
>
> This adds the basic files for the NIR->LLVM translation layer,
> along with some hopefully generic code to load the binary
> result, and other helpers required.
>
> The hope is in the future we could share this with an
> GL_ARB_spirv implementation or a push to replace TGSI
> with NIR in radeonsi.

Indeed. :)

Skimming over this, two remarks:

1. In ac_binary.c, just include sid.h instead of duplicating #defines.
2. There are several files with missing copyright headers -- that's an 
absolute no-go.

Two more remarks inline.

>
> Authors: Bas Nieuwenhuizen and Dave Airlie
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/amd/common/Makefile.am        |   52 +
>  src/amd/common/Makefile.sources   |   26 +
>  src/amd/common/ac_binary.c        |  330 +++
>  src/amd/common/ac_binary.h        |   88 +
>  src/amd/common/ac_llvm_helper.cpp |   22 +
>  src/amd/common/ac_llvm_util.c     |  117 +
>  src/amd/common/ac_llvm_util.h     |    7 +
>  src/amd/common/ac_nir_to_llvm.c   | 4531 +++++++++++++++++++++++++++++++++++++
>  src/amd/common/ac_nir_to_llvm.h   |  102 +
>  src/amd/common/ac_radeon_winsys.h |   85 +
>  10 files changed, 5360 insertions(+)
>  create mode 100644 src/amd/common/Makefile.am
>  create mode 100644 src/amd/common/Makefile.sources
>  create mode 100644 src/amd/common/ac_binary.c
>  create mode 100644 src/amd/common/ac_binary.h
>  create mode 100644 src/amd/common/ac_llvm_helper.cpp
>  create mode 100644 src/amd/common/ac_llvm_util.c
>  create mode 100644 src/amd/common/ac_llvm_util.h
>  create mode 100644 src/amd/common/ac_nir_to_llvm.c
>  create mode 100644 src/amd/common/ac_nir_to_llvm.h
>  create mode 100644 src/amd/common/ac_radeon_winsys.h
>
> diff --git a/src/amd/common/Makefile.am b/src/amd/common/Makefile.am
> new file mode 100644
> index 0000000..d711dd9
> --- /dev/null
> +++ b/src/amd/common/Makefile.am
> @@ -0,0 +1,52 @@
> +# Copyright © 2016 Bas Nieuwenhuizen
> +#
> +# Permission is hereby granted, free of charge, to any person obtaining a
> +# copy of this software and associated documentation files (the "Software"),
> +# to deal in the Software without restriction, including without limitation
> +# the rights to use, copy, modify, merge, publish, distribute, sublicense,
> +# and/or sell copies of the Software, and to permit persons to whom the
> +# Software is furnished to do so, subject to the following conditions:
> +#
> +# The above copyright notice and this permission notice (including the next
> +# paragraph) shall be included in all copies or substantial portions of the
> +# Software.
> +#
> +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> +# IN THE SOFTWARE.
> +
> +include Makefile.sources
> +
> +AM_CPPFLAGS = \
> +	$(VALGRIND_CFLAGS) \
> +	$(DEFINES) \
> +	-I$(top_srcdir)/include \
> +	-I$(top_builddir)/src \
> +	-I$(top_srcdir)/src \
> +	-I$(top_builddir)/src/compiler \
> +	-I$(top_builddir)/src/compiler/nir \
> +	-I$(top_srcdir)/src/compiler \
> +	-I$(top_srcdir)/src/mapi \
> +	-I$(top_srcdir)/src/mesa \
> +	-I$(top_srcdir)/src/mesa/drivers/dri/common \
> +	-I$(top_srcdir)/src/gallium/auxiliary \
> +	-I$(top_srcdir)/src/gallium/include
> +
> +AM_CFLAGS = -Wno-override-init -msse2 \

Why the -Wno-override-init? The -msse2 is probably fine, but let's not 
leak it to someone who uses r300 on an ancient system...


> +	$(VISIBILITY_CFLAGS) \
> +	$(PTHREAD_CFLAGS) \
> +	$(LLVM_CFLAGS) \
> +	$(LIBELF_CFLAGS)
> +
> +AM_CXXFLAGS = \
> +	$(VISIBILITY_CXXFLAGS) \
> +	$(MSVC2013_COMPAT_CXXFLAGS) \
> +	$(LLVM_CXXFLAGS)
> +
> +noinst_LTLIBRARIES = libamd_common.la
> +
> +libamd_common_la_SOURCES = $(AMD_COMPILER_SOURCES)
[snip]
> diff --git a/src/amd/common/ac_llvm_helper.cpp b/src/amd/common/ac_llvm_helper.cpp
> new file mode 100644
> index 0000000..feafdaf
> --- /dev/null
> +++ b/src/amd/common/ac_llvm_helper.cpp
> @@ -0,0 +1,22 @@
> +
> +// Workaround http://llvm.org/PR23628
> +#if HAVE_LLVM >= 0x0307
> +#  pragma push_macro("DEBUG")
> +#  undef DEBUG
> +#endif
> +
> +#include "ac_nir_to_llvm.h"
> +#include <llvm-c/Core.h>
> +#include <llvm/Target/TargetOptions.h>
> +#include <llvm/ExecutionEngine/ExecutionEngine.h>
> +
> +extern "C" void
> +ac_add_attr_dereferenceable(LLVMValueRef val, uint64_t bytes)
> +{
> +#if HAVE_LLVM >= 0x0306

We only build with LLVM >= 3.6, so drop this check.

Cheers,
Nicolai

> +   llvm::Argument *A = llvm::unwrap<llvm::Argument>(val);
> +   llvm::AttrBuilder B;
> +   B.addDereferenceableAttr(bytes);
> +   A->addAttr(llvm::AttributeSet::get(A->getContext(), A->getArgNo() + 1,  B));
> +#endif
> +}


More information about the mesa-dev mailing list