11/*
2- * Copyright (c) 1994-2018 , NVIDIA CORPORATION. All rights reserved.
2+ * Copyright (c) 1994-2019 , NVIDIA CORPORATION. All rights reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3535#include "pd.h"
3636#include "rtlRtns.h"
3737
38- static int exit_point ;
3938static int entry_point ;
4039static int par ; /* in OpenMp parallel region */
4140static int cs ; /* in OpenMp critical section */
@@ -88,6 +87,7 @@ bblock()
8887 INT ent_cnt ;
8988 int ent_select_id ;
9089 int has_kernel = 0 ;
90+ ITEM * itemp ;
9191
9292 if (STD_NEXT (0 ) == STD_PREV (0 )) { /* end only ? */
9393 /* add something for entry -- lfm */
@@ -102,7 +102,7 @@ bblock()
102102
103103 sem .temps_reset = TRUE;
104104 entry_point = 0 ;
105- last_std = STD_PREV ( 0 ) ;
105+ last_std = STD_LAST ;
106106
107107 if (gbl .arets ) {
108108 /* for alternate returns, will use a compiler-created local symbol
@@ -369,35 +369,35 @@ bblock()
369369 ENTSTDP (ent , entry_point );
370370 }
371371
372- /*
373- * gen_auto_dealloc();
374- */
375- {
376- ITEM * itemp ;
372+ if (sem .type_initialize ) {
377373 int std2 ;
378- for (itemp = sem .auto_dealloc ; itemp ; itemp = itemp -> next ) {
379- gen_conditional_dealloc_for_sym (itemp -> t .sptr , gbl .exitstd );
374+ for (std2 = ENTSTDG (gbl .currsub ); STD_LINENO (std2 ) == 0 ;
375+ std2 = STD_NEXT (std2 ))
376+ ;
377+ std2 = STD_PREV (std2 );
378+ for (itemp = sem .type_initialize ; itemp ; itemp = itemp -> next ) {
379+ int stdx = CONSTRUCTSYMG (itemp -> t .sptr ) ?
380+ BLOCK_ENTRY_STD (itemp -> t .sptr ) : std2 ;
381+ gen_type_initialize_for_sym (itemp -> t .sptr , stdx , 0 , 0 );
380382 }
383+ }
381384
382- std2 = gbl .exitstd ;
383- for (itemp = sem .auto_finalize ; itemp ; itemp = itemp -> next ) {
384- std2 = gen_finalization_for_sym (itemp -> t .sptr , gbl .exitstd , 0 );
385- }
386- gbl .exitstd = std2 ;
387-
388- if (sem .type_initialize ) {
389- int std ;
390- for (std = ENTSTDG (gbl .currsub ); STD_LINENO (std ) == 0 ;
391- std = STD_NEXT (std ))
392- ;
393- std = STD_PREV (std );
394- for (itemp = sem .type_initialize ; itemp ; itemp = itemp -> next ) {
395- gen_type_initialize_for_sym (itemp -> t .sptr , std , 0 , 0 );
396- }
397- }
398- for (itemp = sem .alloc_mem_initialize ; itemp ; itemp = itemp -> next ) {
399- gen_alloc_mem_initialize_for_sym (itemp -> t .sptr , ENTSTDG (gbl .currsub ));
400- }
385+ for (itemp = sem .alloc_mem_initialize ; itemp ; itemp = itemp -> next ) {
386+ int stdx = CONSTRUCTSYMG (itemp -> t .sptr ) ?
387+ BLOCK_ENTRY_STD (itemp -> t .sptr ) : ENTSTDG (gbl .currsub );
388+ gen_alloc_mem_initialize_for_sym (itemp -> t .sptr , stdx );
389+ }
390+
391+ for (itemp = sem .auto_dealloc ; itemp ; itemp = itemp -> next ) {
392+ int stdx = CONSTRUCTSYMG (itemp -> t .sptr ) ?
393+ STD_PREV (BLOCK_EXIT_STD (itemp -> t .sptr )) : gbl .exitstd ;
394+ gen_conditional_dealloc_for_sym (itemp -> t .sptr , stdx );
395+ }
396+
397+ for (itemp = sem .auto_finalize ; itemp ; itemp = itemp -> next ) {
398+ int stdx = CONSTRUCTSYMG (itemp -> t .sptr ) ?
399+ STD_PREV (BLOCK_EXIT_STD (itemp -> t .sptr )) : gbl .exitstd ;
400+ gen_finalization_for_sym (itemp -> t .sptr , stdx , 0 );
401401 }
402402
403403#if DEBUG
@@ -676,41 +676,41 @@ gen_early_bnd_dependencies(int ast)
676676 if (!ast )
677677 return ;
678678
679- std = ENTSTDG (
680- gbl .currsub ); /* insert dependencies before dependent bnds exprs */
681679 switch (A_TYPEG (ast )) {
682680 case A_ID :
683681 sptr = A_SPTRG (ast );
684- if (STYPEG (sptr ) == ST_ARRAY && ADJARRG (sptr ) && !ERLYSPECG (sptr )) {
682+ /* insert dependencies before dependent bnds exprs */
683+ std = CONSTRUCTSYMG (sptr ) ? BLOCK_ENTRY_STD (sptr ) : ENTSTDG (gbl .currsub );
684+ if (STYPEG (sptr ) == ST_ARRAY && ADJARRG (sptr ) && !EARLYSPECG (sptr )) {
685685 ad = AD_DPTR (DTYPEG (sptr ));
686686 ndims = AD_NUMDIM (ad );
687687 for (i = 0 ; i < ndims ; i ++ ) {
688688 if (A_TYPEG (AD_LWAST (ad , i )) != A_CNST ) {
689689 bndsptr = A_SPTRG (AD_LWAST (ad , i ));
690- if (!ERLYSPECG (bndsptr )) {
690+ if (!EARLYSPECG (bndsptr )) {
691691 std = add_stmt_after (
692692 mk_assn_stmt (AD_LWAST (ad , i ), AD_LWBD (ad , i ), astb .bnd .dtype ),
693693 std );
694- ERLYSPECP (bndsptr , 1 );
694+ EARLYSPECP (bndsptr , 1 );
695695 gen_early_bnd_dependencies (AD_LWBD (ad , i ));
696696 }
697697 early_spec_gend = TRUE;
698698 }
699699 if (A_TYPEG (AD_UPAST (ad , i )) != A_CNST ) {
700700 bndsptr = A_SPTRG (AD_UPAST (ad , i ));
701- if (!ERLYSPECG (bndsptr )) {
701+ if (!EARLYSPECG (bndsptr )) {
702702 std = add_stmt_after (
703703 mk_assn_stmt (AD_UPAST (ad , i ), AD_UPBD (ad , i ), astb .bnd .dtype ),
704704 std );
705- ERLYSPECP (bndsptr , 1 );
705+ EARLYSPECP (bndsptr , 1 );
706706 gen_early_bnd_dependencies (AD_UPBD (ad , i ));
707707 }
708708 early_spec_gend = TRUE;
709709 }
710710 }
711711 }
712712 if (ADJLENG (sptr )) {
713- if (!ERLYSPECG (sptr )) {
713+ if (!EARLYSPECG (sptr )) {
714714 int rhs , cvlen ;
715715 dtype = DDTG (DTYPEG (sptr ));
716716 if (!CVLENG (sptr )) {
@@ -723,12 +723,12 @@ gen_early_bnd_dependencies(int ast)
723723 std = add_stmt_after (
724724 mk_assn_stmt (mk_id (CVLENG (sptr )), rhs , DTYPEG (cvlen )), std );
725725 add_to_early_bnd_list (rhs );
726- ERLYSPECP (CVLENG (sptr ), 1 );
726+ EARLYSPECP (CVLENG (sptr ), 1 );
727727 }
728728 early_spec_gend = TRUE;
729729 }
730730 if (early_spec_gend ) {
731- ERLYSPECP (sptr , 1 );
731+ EARLYSPECP (sptr , 1 );
732732 }
733733 break ;
734734 case A_FUNC :
@@ -754,7 +754,7 @@ gen_early_bnd_dependencies(int ast)
754754static void
755755gen_early_str_len ()
756756{
757- int sptr ;
757+ SPTR sptr ;
758758 int ast ;
759759 int std ;
760760 int dtype ;
@@ -778,11 +778,16 @@ gen_early_str_len()
778778 rhs = DTY (dtype + 1 );
779779 rhs = mk_convert (rhs , DTYPEG (cvlen ));
780780 rhs = ast_intr (I_MAX , DTYPEG (cvlen ), 2 , rhs , mk_cval (0 , DTYPEG (cvlen )));
781- entry_point = add_stmt_after (
782- mk_assn_stmt (mk_id (CVLENG (sptr )), rhs , DTYPEG (cvlen )), entry_point );
781+ if (CONSTRUCTSYMG (sptr ))
782+ (void )add_stmt_before (
783+ mk_assn_stmt (mk_id (CVLENG (sptr )), rhs , DTYPEG (cvlen )),
784+ BLOCK_ENDPROLOG_STD (sptr ));
785+ else
786+ entry_point = add_stmt_after (
787+ mk_assn_stmt (mk_id (CVLENG (sptr )), rhs , DTYPEG (cvlen )), entry_point );
783788 add_to_early_bnd_list (rhs );
784- ERLYSPECP (sptr , 1 );
785- ERLYSPECP (CVLENG (sptr ), 1 );
789+ EARLYSPECP (sptr , 1 );
790+ EARLYSPECP (CVLENG (sptr ), 1 );
786791 }
787792 }
788793 for (i = erly_bnds_depd .avl ; i ; -- i ) {
@@ -805,31 +810,41 @@ gen_early_array_bnds(int sptr)
805810 int bndsptr ;
806811 bndsptr = A_SPTRG (AD_LWAST (ad , i ));
807812 if (early_specification_stmt_needed (AD_LWBD (ad , i ))) {
808- if (!ERLYSPECG (bndsptr )) {
809- entry_point = add_stmt_after (
810- mk_assn_stmt (AD_LWAST (ad , i ), AD_LWBD (ad , i ), astb .bnd .dtype ),
811- entry_point );
813+ if (!EARLYSPECG (bndsptr )) {
814+ if (CONSTRUCTSYMG (sptr ))
815+ (void )add_stmt_before (
816+ mk_assn_stmt (AD_LWAST (ad , i ), AD_LWBD (ad , i ), astb .bnd .dtype ),
817+ BLOCK_ENDPROLOG_STD (sptr ));
818+ else
819+ entry_point = add_stmt_after (
820+ mk_assn_stmt (AD_LWAST (ad , i ), AD_LWBD (ad , i ), astb .bnd .dtype ),
821+ entry_point );
812822 add_to_early_bnd_list (AD_LWBD (ad , i ));
813- ERLYSPECP (bndsptr , 1 );
823+ EARLYSPECP (bndsptr , 1 );
814824 }
815825 AD_LWBD (ad , i ) = AD_LWAST (ad , i );
816826 early_bnd_emitted = TRUE;
817827 }
818828 bndsptr = A_SPTRG (AD_UPAST (ad , i ));
819829 if (early_specification_stmt_needed (AD_UPBD (ad , i ))) {
820- if (!ERLYSPECG (bndsptr )) {
821- entry_point = add_stmt_after (
822- mk_assn_stmt (AD_UPAST (ad , i ), AD_UPBD (ad , i ), astb .bnd .dtype ),
823- entry_point );
830+ if (!EARLYSPECG (bndsptr )) {
831+ if (CONSTRUCTSYMG (sptr ))
832+ (void )add_stmt_before (
833+ mk_assn_stmt (AD_UPAST (ad , i ), AD_UPBD (ad , i ), astb .bnd .dtype ),
834+ BLOCK_ENDPROLOG_STD (sptr ));
835+ else
836+ entry_point = add_stmt_after (
837+ mk_assn_stmt (AD_UPAST (ad , i ), AD_UPBD (ad , i ), astb .bnd .dtype ),
838+ entry_point );
824839 add_to_early_bnd_list (AD_UPBD (ad , i ));
825- ERLYSPECP (bndsptr , 1 );
840+ EARLYSPECP (bndsptr , 1 );
826841 }
827842 AD_UPBD (ad , i ) = AD_UPAST (ad , i );
828843 early_bnd_emitted = TRUE;
829844 }
830845 }
831846 if (early_bnd_emitted ) {
832- ERLYSPECP (sptr , 1 );
847+ EARLYSPECP (sptr , 1 );
833848 }
834849 for (i = erly_bnds_depd .avl ; i ; -- i ) {
835850 gen_early_bnd_dependencies (erly_bnds_depd .base [i - 1 ]);
@@ -871,6 +886,10 @@ add_bound_assignments(int sym)
871886 int tmp ;
872887 int zbaseast ;
873888 int insertstd = 0 ;
889+ int save_entry_point = entry_point ;
890+
891+ if (CONSTRUCTSYMG (sym ))
892+ entry_point = STD_PREV (BLOCK_ENDPROLOG_STD (sym ));
874893
875894 dtype = DTYPEG (sym );
876895 ad = AD_DPTR (dtype );
@@ -932,6 +951,9 @@ add_bound_assignments(int sym)
932951 ast_visit (tmp , tmp ); /* mark id ast as visited */
933952 }
934953 }
954+
955+ if (CONSTRUCTSYMG (sym ))
956+ entry_point = save_entry_point ;
935957}
936958
937959static void
0 commit comments