Does Fortran resolve optional arguments and present statements during compile-time?

前端 未结 2 1934
我在风中等你
我在风中等你 2021-01-20 14:07

After a search without any result I want to ask you a question regarding subroutines containing optional arguments and how they are treated by the compiler (run time/compile

2条回答
  •  终归单人心
    2021-01-20 14:39

    I will add an example. This is what gfortran-4.8 does with your code with -Ofast (-fdump-tree-optimized). There is only one copy of the subroutine and the if (present()) calls are changed to if (b_1(D) != 0B). Maybe some smaller subroutine would be inlined. Then I would expect such an optimization to kick in, but not here.

    ;; Function abc (__contains_abc_MOD_abc, funcdef_no=0, decl_uid=1875, cgraph_uid=0)
    
    abc (real(kind=4) & restrict a, real(kind=4) * b, real(kind=4) * c)
    {
      struct __st_parameter_dt dt_parm.1;
      struct __st_parameter_dt dt_parm.0;
    
      :
      if (b_1(D) != 0B)
        goto ;
      else
        goto ;
    
      :
      dt_parm.0.common.filename = &"opt.f90"[1]{lb: 1 sz: 1};
      dt_parm.0.common.line = 13;
      dt_parm.0.common.flags = 128;
      dt_parm.0.common.unit = 6;
      _gfortran_st_write (&dt_parm.0);
      _gfortran_transfer_character_write (&dt_parm.0, &"Provide c"[1]{lb: 1 sz: 1}, 9);
      _gfortran_st_write_done (&dt_parm.0);
      dt_parm.0 ={v} {CLOBBER};
      goto ;
    
      :
      if (c_11(D) != 0B)
        goto ;
      else
        goto ;
    
      :
      dt_parm.1.common.filename = &"opt.f90"[1]{lb: 1 sz: 1};
      dt_parm.1.common.line = 15;
      dt_parm.1.common.flags = 128;
      dt_parm.1.common.unit = 6;
      _gfortran_st_write (&dt_parm.1);
      _gfortran_transfer_character_write (&dt_parm.1, &"Provide b"[1]{lb: 1 sz: 1}, 9);
      _gfortran_st_write_done (&dt_parm.1);
      dt_parm.1 ={v} {CLOBBER};
    
      :
      return;
    
    }
    
    
    
    ;; Function main (main, funcdef_no=2, decl_uid=1889, cgraph_uid=2) (executed once)
    
    main (integer(kind=4) argc, character(kind=1) * * argv)
    {
      real(kind=4) aa;
      real(kind=4) bb;
      real(kind=4) cc;
      static integer(kind=4) options.2[7] = {68, 1023, 0, 0, 1, 1, 0};
    
      :
      _gfortran_set_args (argc_2(D), argv_3(D));
      _gfortran_set_options (7, &options.2[0]);
      abc (&aa, &bb, 0B);
      abc (&aa, 0B, &cc);
      aa ={v} {CLOBBER};
      bb ={v} {CLOBBER};
      cc ={v} {CLOBBER};
      return 0;
    
    }
    

    I checked this is also the case for the final assembly, but it is much more clearly visible here in GIMPLE.

提交回复
热议问题