Home | History | Annotate | Download | only in gallivm
      1 /*
      2  * Copyright 2011-2012 Advanced Micro Devices, Inc.
      3  * All Rights Reserved.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining a
      6  * copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sub license, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice (including the
     14  * next paragraph) shall be included in all copies or substantial portions
     15  * of the Software.
     16  *
     17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     20  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
     21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24  *
     25  **************************************************************************/
     26 
     27 /**
     28  *
     29  * @author Tom Stellard <thomas.stellard (at) amd.com>
     30  *
     31  */
     32 
     33 
     34 #ifndef LP_BLD_TGSI_ACTION_H
     35 #define LP_BLD_TGSI_ACTION_H
     36 
     37 #include <llvm-c/Core.h>
     38 
     39 struct lp_build_tgsi_context;
     40 
     41 struct lp_build_emit_data {
     42    /** Arguments that are passed to lp_build_tgsi_action::emit.  The
     43     * order of the arguments should be as follows:
     44     * SOA: s0.x, s0.y, s0.z, s0.w, s1.x, s1.y, s1.z, s1.w, s2.x, s2.y, s2.x, s2.w
     45     * AOS: s0.xyzw, s1.xyzw, s2.xyzw
     46     * TEXTURE Instructions: coord.xyzw
     47     *
     48     * Arguments should be packed into the args array.  For example an SOA
     49     * instructions that reads s0.x and s1.x args should look like this:
     50     * args[0] = s0.x;
     51     * args[1] = s1.x;
     52     */
     53    LLVMValueRef args[12];
     54 
     55    /**
     56     * Number of arguments in the args array.
     57     */
     58    unsigned arg_count;
     59 
     60    /**
     61     * The type output type of the opcode.  This should be set in the
     62     * lp_build_tgsi_action::fetch_args function.
     63     */
     64    LLVMTypeRef dst_type;
     65 
     66    /** This is used by the lp_build_tgsi_action::fetch_args function to
     67     * determine which channel to read from the opcode arguments.  It also
     68     * specifies which index of the output array should be written to by
     69     * the lp_build_tgsi_action::emit function.  However, this value is
     70     * usually ignored by any opcodes that are not TGSI_OUTPUT_COMPONENTWISE.
     71     */
     72    unsigned chan;
     73 
     74    /**
     75     * This is used to specify the src channel to read from for doubles.
     76     */
     77    unsigned src_chan;
     78 
     79    /** The lp_build_tgsi_action::emit 'executes' the opcode and writes the
     80     * results to this array.
     81     */
     82    LLVMValueRef output[4];
     83 
     84    /**
     85     * The current instruction that is being 'executed'.
     86     */
     87    const struct tgsi_full_instruction * inst;
     88    const struct tgsi_opcode_info * info;
     89 };
     90 
     91 struct lp_build_tgsi_action
     92 {
     93 
     94    /**
     95     * This function is responsible for doing 2-3 things:
     96     * 1. Fetching the instruction arguments into the emit_data->args array.
     97     * 2. Setting the number of arguments in emit_data->arg_count.
     98     * 3. Setting the destination type in emit_data->dst_type (usually only
     99     *    necessary for opcodes that are TGSI_OUTPUT_COMPONENTWISE).
    100     */
    101    void (*fetch_args)(struct lp_build_tgsi_context *,
    102                       struct lp_build_emit_data *);
    103 
    104 
    105    /**
    106     * This function is responsible for emitting LLVM IR for a TGSI opcode.
    107     * It should store the values it generates in the emit_data->output array
    108     * and for TGSI_OUTPUT_COMPONENTWISE and TGSI_OUTPUT_REPLICATE instructions
    109     * (and possibly others depending on the specific implementation), it should
    110     * make sure to store the values in the array slot indexed by emit_data->chan.
    111     */
    112    void (*emit)(const struct lp_build_tgsi_action *,
    113                         struct lp_build_tgsi_context *,
    114                         struct lp_build_emit_data *);
    115 
    116    /**
    117     * This variable can be used to store an intrinsic name, in case the TGSI
    118     * opcode will be replaced by a target specific intrinsic.  (There is a
    119     * convenience function in lp_bld_tgsi.c called lp_build_tgsi_intrinsic()
    120     * that can be assigned to lp_build_tgsi_action::emit and used for
    121     * generating intrinsics).
    122     */
    123    const char * intr_name;
    124 };
    125 
    126 /**
    127  * This function initializes the bld_base->op_actions array with some
    128  * generic operand actions.
    129  */
    130 void
    131 lp_set_default_actions(
    132    struct lp_build_tgsi_context * bld_base);
    133 
    134 /*
    135  * This function initialize the bld_base->op_actions array with some
    136  * operand actions that are intended only for use when generating
    137  * instructions to be executed on a CPU.
    138  */
    139 void
    140 lp_set_default_actions_cpu(
    141    struct lp_build_tgsi_context * bld_base);
    142 
    143 #endif /* LP_BLD_TGSI_ACTION_H */
    144