nir: Remove useless ftrunc inside f2i/f2u.
[mesa.git] / src / glsl / ir_function_can_inline.cpp
index 8bb8e0d9ed70f185b371ff4516f8f851419c8e69..3b1d15f80fcc92028d966d7bbca150fd9de23734 100644 (file)
  *
  * Determines if we can inline a function call using ir_function_inlining.cpp.
  *
- * The primary restriction is that we can't return from the function
- * other than as the last instruction.  We could potentially work
- * around this for some constructs by flattening control flow and
- * moving the return to the end, or by using breaks from a do {} while
- * (0) loop surrounding the function body.
+ * The primary restriction is that we can't return from the function other
+ * than as the last instruction.  In lower_jumps.cpp, we can lower return
+ * statements not at the end of the function to other control flow in order to
+ * deal with this restriction.
  */
 
 #include "ir.h"
@@ -59,12 +58,17 @@ bool
 can_inline(ir_call *call)
 {
    ir_function_can_inline_visitor v;
-   const ir_function_signature *callee = call->get_callee();
+   const ir_function_signature *callee = call->callee;
+   if (!callee->is_defined)
+      return false;
 
    v.run((exec_list *) &callee->body);
 
+   /* If the function is empty (no last instruction) or does not end with a
+    * return statement, we need to count the implicit return.
+    */
    ir_instruction *last = (ir_instruction *)callee->body.get_tail();
-   if (last && !last->as_return())
+   if (last == NULL || !last->as_return())
       v.num_returns++;
 
    return v.num_returns == 1;