glsl_to_tgsi: Assert that the _mesa_sysval_to_semantic mapping is correct
[mesa.git] / src / mesa / state_tracker / st_glsl_to_tgsi.cpp
index d660a6be7cbcedffd1d8429ce0fb02bc2823e48a..b4638dd6f5ec1fcfac94816aeac05b98ca7bc4fd 100644 (file)
@@ -919,9 +919,7 @@ glsl_to_tgsi_visitor::add_constant(gl_register_file file,
       /* Search immediate storage to see if we already have an identical
        * immediate that we can use instead of adding a duplicate entry.
        */
-      foreach_list(node, &this->immediates) {
-         entry = (immediate_storage *) node;
-         
+      foreach_in_list(immediate_storage, entry, &this->immediates) {
          if (entry->size == size &&
              entry->type == datatype &&
              !memcmp(entry->values, values, size * sizeof(gl_constant_value))) {
@@ -1061,11 +1059,7 @@ variable_storage *
 glsl_to_tgsi_visitor::find_variable_storage(ir_variable *var)
 {
    
-   variable_storage *entry;
-
-   foreach_list(node, &this->variables) {
-      entry = (variable_storage *) node;
-
+   foreach_in_list(variable_storage, entry, &this->variables) {
       if (entry->var == var)
          return entry;
    }
@@ -1198,13 +1192,11 @@ glsl_to_tgsi_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(NULL, &empty);
+      sig = ir->matching_signature(NULL, &empty, false);
 
       assert(sig);
 
-      foreach_list(node, &sig->body) {
-         ir_instruction *ir = (ir_instruction *) node;
-
+      foreach_in_list(ir_instruction, ir, &sig->body) {
          ir->accept(this);
       }
    }
@@ -1362,7 +1354,7 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
 
    /* Quick peephole: Emit OPCODE_MAD(-a, -b, a) instead of AND(a, NOT(b))
     */
-   if (ir->operation == ir_binop_logic_and) {
+   if (!native_integers && ir->operation == ir_binop_logic_and) {
       if (try_emit_mad_for_and_not(ir, 1))
         return;
       if (try_emit_mad_for_and_not(ir, 0))
@@ -1955,25 +1947,46 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
       break;
 
    case ir_binop_ubo_load: {
-      ir_constant *uniform_block = ir->operands[0]->as_constant();
+      ir_constant *const_uniform_block = ir->operands[0]->as_constant();
       ir_constant *const_offset_ir = ir->operands[1]->as_constant();
       unsigned const_offset = const_offset_ir ? const_offset_ir->value.u[0] : 0;
+      unsigned const_block = const_uniform_block ? const_uniform_block->value.u[0] + 1 : 0;
       st_src_reg index_reg = get_temp(glsl_type::uint_type);
       st_src_reg cbuf;
 
       cbuf.type = glsl_type::vec4_type->base_type;
       cbuf.file = PROGRAM_CONSTANT;
       cbuf.index = 0;
-      cbuf.index2D = uniform_block->value.u[0] + 1;
       cbuf.reladdr = NULL;
       cbuf.negate = 0;
       
       assert(ir->type->is_vector() || ir->type->is_scalar());
 
       if (const_offset_ir) {
-         index_reg = st_src_reg_for_int(const_offset / 16);
-      } else {
-         emit(ir, TGSI_OPCODE_USHR, st_dst_reg(index_reg), op[1], st_src_reg_for_int(4));
+         /* Constant index into constant buffer */
+         cbuf.reladdr = NULL;
+         cbuf.index = const_offset / 16;
+      }
+      else {
+         /* Relative/variable index into constant buffer */
+         emit(ir, TGSI_OPCODE_USHR, st_dst_reg(index_reg), op[1],
+              st_src_reg_for_int(4));
+         cbuf.reladdr = ralloc(mem_ctx, st_src_reg);
+         memcpy(cbuf.reladdr, &index_reg, sizeof(index_reg));
+      }
+
+      if (const_uniform_block) {
+         /* Constant constant buffer */
+         cbuf.reladdr2 = NULL;
+         cbuf.index2D = const_block;
+         cbuf.has_index2 = true;
+      }
+      else {
+         /* Relative/variable constant buffer */
+         cbuf.reladdr2 = ralloc(mem_ctx, st_src_reg);
+         cbuf.index2D = 1;
+         memcpy(cbuf.reladdr2, &op[0], sizeof(st_src_reg));
+         cbuf.has_index2 = true;
       }
 
       cbuf.swizzle = swizzle_for_size(ir->type->vector_elements);
@@ -1982,9 +1995,6 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
                                     const_offset % 16 / 4,
                                     const_offset % 16 / 4);
 
-      cbuf.reladdr = ralloc(mem_ctx, st_src_reg);
-      memcpy(cbuf.reladdr, &index_reg, sizeof(index_reg));
-
       if (ir->type->base_type == GLSL_TYPE_BOOL) {
          emit(ir, TGSI_OPCODE_USNE, result_dst, cbuf, st_src_reg_for_int(0));
       } else {
@@ -2031,6 +2041,15 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
        */
       emit(ir, TGSI_OPCODE_MAD, result_dst, op[0], op[1], op[2]);
       break;
+   case ir_unop_interpolate_at_centroid:
+      emit(ir, TGSI_OPCODE_INTERP_CENTROID, result_dst, op[0]);
+      break;
+   case ir_binop_interpolate_at_offset:
+      emit(ir, TGSI_OPCODE_INTERP_OFFSET, result_dst, op[0], op[1]);
+      break;
+   case ir_binop_interpolate_at_sample:
+      emit(ir, TGSI_OPCODE_INTERP_SAMPLE, result_dst, op[0], op[1]);
+      break;
    case ir_unop_pack_snorm_2x16:
    case ir_unop_pack_unorm_2x16:
    case ir_unop_pack_half_2x16:
@@ -2549,8 +2568,7 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
       st_src_reg temp_base = get_temp(ir->type);
       st_dst_reg temp = st_dst_reg(temp_base);
 
-      foreach_list(node, &ir->components) {
-         ir_constant *field_value = (ir_constant *) node;
+      foreach_in_list(ir_constant, field_value, &ir->components) {
          int size = type_size(field_value->type);
 
          assert(size > 0);
@@ -2664,11 +2682,7 @@ glsl_to_tgsi_visitor::visit(ir_constant *ir)
 function_entry *
 glsl_to_tgsi_visitor::get_function_signature(ir_function_signature *sig)
 {
-   function_entry *entry;
-
-   foreach_list(node, &this->function_signatures) {
-      entry = (function_entry *) node;
-
+   foreach_in_list_use_after(function_entry, entry, &this->function_signatures) {
       if (entry->sig == sig)
          return entry;
    }
@@ -2679,8 +2693,7 @@ glsl_to_tgsi_visitor::get_function_signature(ir_function_signature *sig)
    entry->bgn_inst = NULL;
 
    /* Allocate storage for all the parameters. */
-   foreach_list(node, &sig->parameters) {
-      ir_variable *param = (ir_variable *) node;
+   foreach_in_list(ir_variable, param, &sig->parameters) {
       variable_storage *storage;
 
       storage = find_variable_storage(param);
@@ -2829,7 +2842,13 @@ glsl_to_tgsi_visitor::visit(ir_texture *ir)
       }
       break;
    case ir_txb:
-      opcode = is_cube_array ? TGSI_OPCODE_TXB2 : TGSI_OPCODE_TXB;
+      if (is_cube_array ||
+          sampler_type == glsl_type::samplerCubeShadow_type) {
+         opcode = TGSI_OPCODE_TXB2;
+      }
+      else {
+         opcode = TGSI_OPCODE_TXB;
+      }
       ir->lod_info.bias->accept(this);
       lod_info = this->result;
       if (ir->offset) {
@@ -3194,9 +3213,7 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
 {
    v->samplers_used = 0;
 
-   foreach_list(node, &v->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &v->instructions) {
       if (is_tex_instruction(inst->op)) {
          v->samplers_used |= 1 << inst->sampler;
 
@@ -3340,8 +3357,7 @@ glsl_to_tgsi_visitor::simplify_cmp(void)
    memset(tempWrites, 0, sizeof(unsigned) * MAX_TEMPS);
    memset(outputWrites, 0, sizeof(outputWrites));
 
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       unsigned prevWriteMask = 0;
 
       /* Give up if we encounter relative addressing or flow control. */
@@ -3386,8 +3402,7 @@ glsl_to_tgsi_visitor::simplify_cmp(void)
 void
 glsl_to_tgsi_visitor::rename_temp_register(int index, int new_index)
 {
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       unsigned j;
       
       for (j=0; j < num_inst_src_regs(inst->op); j++) {
@@ -3417,9 +3432,7 @@ glsl_to_tgsi_visitor::get_first_temp_read(int index)
    int loop_start = -1; /* index of the first active BGNLOOP (if any) */
    unsigned i = 0, j;
    
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-      
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       for (j=0; j < num_inst_src_regs(inst->op); j++) {
          if (inst->src[j].file == PROGRAM_TEMPORARY && 
              inst->src[j].index == index) {
@@ -3455,9 +3468,7 @@ glsl_to_tgsi_visitor::get_first_temp_write(int index)
    int loop_start = -1; /* index of the first active BGNLOOP (if any) */
    int i = 0;
    
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-      
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       if (inst->dst.file == PROGRAM_TEMPORARY && inst->dst.index == index) {
          return (depth == 0) ? i : loop_start;
       }
@@ -3484,9 +3495,7 @@ glsl_to_tgsi_visitor::get_last_temp_read(int index)
    int last = -1; /* index of last instruction that reads the temporary */
    unsigned i = 0, j;
    
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-      
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       for (j=0; j < num_inst_src_regs(inst->op); j++) {
          if (inst->src[j].file == PROGRAM_TEMPORARY && 
              inst->src[j].index == index) {
@@ -3520,9 +3529,7 @@ glsl_to_tgsi_visitor::get_last_temp_write(int index)
    int last = -1; /* index of last instruction that writes to the temporary */
    int i = 0;
    
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-      
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       if (inst->dst.file == PROGRAM_TEMPORARY && inst->dst.index == index)
          last = (depth == 0) ? i : -2;
       
@@ -3569,9 +3576,7 @@ glsl_to_tgsi_visitor::copy_propagate(void)
    int *acp_level = rzalloc_array(mem_ctx, int, this->next_temp * 4);
    int level = 0;
 
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       assert(inst->dst.file != PROGRAM_TEMPORARY
              || inst->dst.index < this->next_temp);
 
@@ -3765,9 +3770,7 @@ glsl_to_tgsi_visitor::eliminate_dead_code(void)
    int level = 0;
    int removed = 0;
 
-   foreach_list(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &this->instructions) {
       assert(inst->dst.file != PROGRAM_TEMPORARY
              || inst->dst.index < this->next_temp);
       
@@ -3893,9 +3896,7 @@ glsl_to_tgsi_visitor::eliminate_dead_code(void)
    /* Now actually remove the instructions that are completely dead and update
     * the writemask of other instructions with dead channels.
     */
-   foreach_list_safe(node, &this->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
-      
+   foreach_in_list_safe(glsl_to_tgsi_instruction, inst, &this->instructions) {
       if (!inst->dead_mask || !inst->dst.writemask)
          continue;
       else if ((inst->dst.writemask & ~inst->dead_mask) == 0) {
@@ -4081,8 +4082,7 @@ get_pixel_transfer_visitor(struct st_fragment_program *fp,
 
    /* Now copy the instructions from the original glsl_to_tgsi_visitor into the
     * new visitor. */
-   foreach_list(node, &original->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &original->instructions) {
       glsl_to_tgsi_instruction *newinst;
       st_src_reg src_regs[3];
 
@@ -4166,8 +4166,7 @@ get_bitmap_visitor(struct st_fragment_program *fp,
 
    /* Now copy the instructions from the original glsl_to_tgsi_visitor into the
     * new visitor. */
-   foreach_list(node, &original->instructions) {
-      glsl_to_tgsi_instruction *inst = (glsl_to_tgsi_instruction *) node;
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &original->instructions) {
       glsl_to_tgsi_instruction *newinst;
       st_src_reg src_regs[3];
 
@@ -4239,7 +4238,7 @@ struct st_translate {
 };
 
 /** Map Mesa's SYSTEM_VALUE_x to TGSI_SEMANTIC_x */
-static unsigned mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
+const unsigned _mesa_sysval_to_semantic[SYSTEM_VALUE_MAX] = {
    TGSI_SEMANTIC_FACE,
    TGSI_SEMANTIC_VERTEXID,
    TGSI_SEMANTIC_INSTANCEID,
@@ -4335,9 +4334,8 @@ dst_register(struct st_translate *t,
       return ureg_dst_undef();
 
    case PROGRAM_TEMPORARY:
-      assert(index >= 0);
-      assert(index < (int) Elements(t->temps));
+      assert(index < Elements(t->temps));
+
       if (ureg_dst_is_undef(t->temps[index]))
          t->temps[index] = ureg_DECL_local_temporary(t->ureg);
 
@@ -4346,8 +4344,7 @@ dst_register(struct st_translate *t,
    case PROGRAM_ARRAY:
       array = index >> 16;
 
-      assert(array >= 0);
-      assert(array < (int) Elements(t->arrays));
+      assert(array < Elements(t->arrays));
 
       if (ureg_dst_is_undef(t->arrays[array]))
          t->arrays[array] = ureg_DECL_array_temporary(
@@ -4381,51 +4378,45 @@ dst_register(struct st_translate *t,
  * Map a glsl_to_tgsi src register to a TGSI ureg_src register.
  */
 static struct ureg_src
-src_register(struct st_translate *t,
-             gl_register_file file,
-             GLint index, GLint index2D)
+src_register(struct st_translate *t, const struct st_src_reg *reg)
 {
-   switch(file) {
+   switch(reg->file) {
    case PROGRAM_UNDEFINED:
       return ureg_src_undef();
 
    case PROGRAM_TEMPORARY:
    case PROGRAM_ARRAY:
-      return ureg_src(dst_register(t, file, index));
+      return ureg_src(dst_register(t, reg->file, reg->index));
 
    case PROGRAM_UNIFORM:
-      assert(index >= 0);
-      return t->constants[index];
+      assert(reg->index >= 0);
+      return t->constants[reg->index];
    case PROGRAM_STATE_VAR:
    case PROGRAM_CONSTANT:       /* ie, immediate */
-      if (index2D) {
-         struct ureg_src src;
-         src = ureg_src_register(TGSI_FILE_CONSTANT, index);
-         src.Dimension = 1;
-         src.DimensionIndex = index2D;
-         return src;
-      } else if (index < 0)
+      if (reg->has_index2)
+         return ureg_src_register(TGSI_FILE_CONSTANT, reg->index);
+      else if (reg->index < 0)
          return ureg_DECL_constant(t->ureg, 0);
       else
-         return t->constants[index];
+         return t->constants[reg->index];
 
    case PROGRAM_IMMEDIATE:
-      return t->immediates[index];
+      return t->immediates[reg->index];
 
    case PROGRAM_INPUT:
-      assert(t->inputMapping[index] < Elements(t->inputs));
-      return t->inputs[t->inputMapping[index]];
+      assert(t->inputMapping[reg->index] < Elements(t->inputs));
+      return t->inputs[t->inputMapping[reg->index]];
 
    case PROGRAM_OUTPUT:
-      assert(t->outputMapping[index] < Elements(t->outputs));
-      return ureg_src(t->outputs[t->outputMapping[index]]); /* not needed? */
+      assert(t->outputMapping[reg->index] < Elements(t->outputs));
+      return ureg_src(t->outputs[t->outputMapping[reg->index]]); /* not needed? */
 
    case PROGRAM_ADDRESS:
-      return ureg_src(t->address[index]);
+      return ureg_src(t->address[reg->index]);
 
    case PROGRAM_SYSTEM_VALUE:
-      assert(index < (int) Elements(t->systemValues));
-      return t->systemValues[index];
+      assert(reg->index < (int) Elements(t->systemValues));
+      return t->systemValues[reg->index];
 
    default:
       assert(!"unknown src register file");
@@ -4486,13 +4477,12 @@ translate_dst(struct st_translate *t,
 static struct ureg_src
 translate_src(struct st_translate *t, const st_src_reg *src_reg)
 {
-   struct ureg_src src = src_register(t, src_reg->file, src_reg->index, src_reg->index2D);
+   struct ureg_src src = src_register(t, src_reg);
 
    if (src_reg->has_index2) {
       /* 2D indexes occur with geometry shader inputs (attrib, vertex)
        * and UBO constant buffers (buffer, position).
        */
-      src = src_register(t, src_reg->file, src_reg->index, src_reg->index2D);
       if (src_reg->reladdr2)
          src = ureg_src_dimension_indirect(src, ureg_src(t->address[1]),
                                            src_reg->index2D);
@@ -4877,6 +4867,7 @@ emit_edgeflags(struct st_translate *t)
  * \param inputSemanticIndex  the semantic index (ex: which texcoord) for
  *                            each input
  * \param interpMode  the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input
+ * \param interpLocation the TGSI_INTERPOLATE_LOC_* location for each input
  * \param numOutputs  number of output registers used
  * \param outputMapping  maps Mesa fragment program outputs to TGSI
  *                       generic outputs
@@ -4898,7 +4889,7 @@ st_translate_program(
    const ubyte inputSemanticName[],
    const ubyte inputSemanticIndex[],
    const GLuint interpMode[],
-   const GLboolean is_centroid[],
+   const GLuint interpLocation[],
    GLuint numOutputs,
    const GLuint outputMapping[],
    const ubyte outputSemanticName[],
@@ -4913,6 +4904,21 @@ st_translate_program(
    assert(numInputs <= Elements(t->inputs));
    assert(numOutputs <= Elements(t->outputs));
 
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_FRONT_FACE] ==
+          TGSI_SEMANTIC_FACE);
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_VERTEX_ID] ==
+          TGSI_SEMANTIC_VERTEXID);
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_INSTANCE_ID] ==
+          TGSI_SEMANTIC_INSTANCEID);
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_SAMPLE_ID] ==
+          TGSI_SEMANTIC_SAMPLEID);
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_SAMPLE_POS] ==
+          TGSI_SEMANTIC_SAMPLEPOS);
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_SAMPLE_MASK_IN] ==
+          TGSI_SEMANTIC_SAMPLEMASK);
+   assert(_mesa_sysval_to_semantic[SYSTEM_VALUE_INVOCATION_ID] ==
+          TGSI_SEMANTIC_INVOCATIONID);
+
    t = CALLOC_STRUCT(st_translate);
    if (!t) {
       ret = PIPE_ERROR_OUT_OF_MEMORY;
@@ -4944,7 +4950,7 @@ st_translate_program(
                                                         inputSemanticName[i],
                                                         inputSemanticIndex[i],
                                                         interpMode[i], 0,
-                                                        is_centroid[i]);
+                                                        interpLocation[i]);
       }
 
       if (proginfo->InputsRead & VARYING_BIT_POS) {
@@ -5048,7 +5054,7 @@ st_translate_program(
       unsigned numSys = 0;
       for (i = 0; sysInputs; i++) {
          if (sysInputs & (1 << i)) {
-            unsigned semName = mesa_sysval_to_semantic[i];
+            unsigned semName = _mesa_sysval_to_semantic[i];
             t->systemValues[i] = ureg_DECL_system_value(ureg, numSys, semName, 0);
             if (semName == TGSI_SEMANTIC_INSTANCEID ||
                 semName == TGSI_SEMANTIC_VERTEXID) {
@@ -5122,7 +5128,13 @@ st_translate_program(
       unsigned num_ubos = program->shader->NumUniformBlocks;
 
       for (i = 0; i < num_ubos; i++) {
-         ureg_DECL_constant2D(t->ureg, 0, program->shader->UniformBlocks[i].UniformBufferSize / 4, i + 1);
+         unsigned size = program->shader->UniformBlocks[i].UniformBufferSize;
+         unsigned num_const_vecs = (size + 15) / 16;
+         unsigned first, last;
+         assert(num_const_vecs > 0);
+         first = 0;
+         last = num_const_vecs > 0 ? num_const_vecs - 1 : 0;
+         ureg_DECL_constant2D(t->ureg, first, last, i + 1);
       }
    }
    
@@ -5135,8 +5147,7 @@ st_translate_program(
       goto out;
    }
    i = 0;
-   foreach_list(node, &program->immediates) {
-      immediate_storage *imm = (immediate_storage *) node;
+   foreach_in_list(immediate_storage, imm, &program->immediates) {
       assert(i < program->num_immediates);
       t->immediates[i++] = emit_immediate(t, imm->values, imm->type, imm->size);
    }
@@ -5151,9 +5162,9 @@ st_translate_program(
 
    /* Emit each instruction in turn:
     */
-   foreach_list(n, &program->instructions) {
+   foreach_in_list(glsl_to_tgsi_instruction, inst, &program->instructions) {
       set_insn_start(t, ureg_get_instruction_number(ureg));
-      compile_tgsi_instruction(t, (glsl_to_tgsi_instruction *) n, clamp_color);
+      compile_tgsi_instruction(t, inst, clamp_color);
    }
 
    /* Fix up all emitted labels:
@@ -5264,9 +5275,7 @@ get_mesa_program(struct gl_context *ctx,
    do {
       progress = GL_FALSE;
 
-      foreach_list(node, &v->function_signatures) {
-         function_entry *entry = (function_entry *) node;
-
+      foreach_in_list(function_entry, entry, &v->function_signatures) {
          if (!entry->bgn_inst) {
             v->current_function = entry;