Path: blob/21.2-virgl/src/gallium/frontends/clover/core/compiler.hpp
4572 views
//1// Copyright 2019 Red Hat, Inc.2//3// Permission is hereby granted, free of charge, to any person obtaining a4// copy of this software and associated documentation files (the "Software"),5// to deal in the Software without restriction, including without limitation6// the rights to use, copy, modify, merge, publish, distribute, sublicense,7// and/or sell copies of the Software, and to permit persons to whom the8// Software is furnished to do so, subject to the following conditions:9//10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19// OTHER DEALINGS IN THE SOFTWARE.20//2122#ifndef CLOVER_CORE_COMPILER_HPP23#define CLOVER_CORE_COMPILER_HPP2425#include "core/device.hpp"26#include "core/module.hpp"27#include "llvm/invocation.hpp"28#include "nir/invocation.hpp"29#include "spirv/invocation.hpp"3031namespace clover {32namespace compiler {33static inline module34compile_program(const program &prog, const header_map &headers,35const device &dev, const std::string &opts,36std::string &log) {37switch (dev.ir_format()) {38#ifdef HAVE_CLOVER_SPIRV39case PIPE_SHADER_IR_NIR_SERIALIZED:40switch (prog.il_type()) {41case program::il_type::source:42return llvm::compile_to_spirv(prog.source(), headers, dev, opts, log);43case program::il_type::spirv:44return spirv::compile_program(prog.source(), dev, log);45default:46unreachable("device with unsupported IL");47throw error(CL_INVALID_VALUE);48}49#endif50case PIPE_SHADER_IR_NATIVE:51if (prog.il_type() == program::il_type::source)52return llvm::compile_program(prog.source(), headers, dev, opts, log);53else54throw error(CL_INVALID_VALUE);55default:56unreachable("device with unsupported IR");57throw error(CL_INVALID_VALUE);58}59}6061static inline module62link_program(const std::vector<module> &ms, const device &dev,63const std::string &opts, std::string &log) {64switch (dev.ir_format()) {65case PIPE_SHADER_IR_NIR_SERIALIZED:66return nir::spirv_to_nir(spirv::link_program(ms, dev, opts, log),67dev, log);68case PIPE_SHADER_IR_NATIVE:69return llvm::link_program(ms, dev, opts, log);70default:71unreachable("device with unsupported IR");72throw error(CL_INVALID_VALUE);73}74}75}76}7778#endif798081