Advertisement

このページを編集する際は,編集に関する方針に従ってください.

概要

865 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL.  DECL should
866    have static storage duration.  In other words, it should not be an
867    automatic variable, including PARM_DECLs.
868 
869    There is, however, one exception: this function handles variables
870    explicitly placed in a particular register by the user.
871 
872    This is never called for PARM_DECL nodes.  */

引数

  • tree decl
    • 宣言の構文木

実装

874 void
875 make_decl_rtl (tree decl)
876 {
877   const char *name = 0;
878   int reg_number;
879   rtx x;
880 
881   /* Check that we are not being given an automatic variable.  */
882   gcc_assert (TREE_CODE (decl) != PARM_DECL
883               && TREE_CODE (decl) != RESULT_DECL);
884 
885   /* A weak alias has TREE_PUBLIC set but not the other bits.  */
886   gcc_assert (TREE_CODE (decl) != VAR_DECL
887               || TREE_STATIC (decl)
888               || TREE_PUBLIC (decl)
889               || DECL_EXTERNAL (decl)
890               || DECL_REGISTER (decl));
891   
892   /* And that we were not given a type or a label.  */
893   gcc_assert (TREE_CODE (decl) != TYPE_DECL
894               && TREE_CODE (decl) != LABEL_DECL);
895 
896   /* For a duplicate declaration, we can be called twice on the
897      same DECL node.  Don't discard the RTL already made.  */
898   if (DECL_RTL_SET_P (decl))
899     {
900       /* If the old RTL had the wrong mode, fix the mode.  */
901       if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
902         SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
903                                                DECL_MODE (decl), 0));
904 
905       if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
906         return;
907 
908       /* ??? Another way to do this would be to maintain a hashed
909          table of such critters.  Instead of adding stuff to a DECL
910          to give certain attributes to it, we could use an external
911          hash map from DECL to set of attributes.  */
912 
913       /* Let the target reassign the RTL if it wants.
914          This is necessary, for example, when one machine specific
915          decl attribute overrides another.  */
916       targetm.encode_section_info (decl, DECL_RTL (decl), false);
917 
918       /* Make this function static known to the mudflap runtime.  */
919       if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
920         mudflap_enqueue_decl (decl);
921 
922       return;
923     }
924 
925   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
926   
927   if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
928       && DECL_REGISTER (decl))
929     {
930       error ("register name not specified for %q+D", decl);     
931     }
932   else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
933     {
934       const char *asmspec = name+1;
935       reg_number = decode_reg_name (asmspec);
936       /* First detect errors in declaring global registers.  */
937       if (reg_number == -1)
938         error ("register name not specified for %q+D", decl);
939       else if (reg_number < 0)
940         error ("invalid register name for %q+D", decl);
941       else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
942         error ("data type of %q+D isn%'t suitable for a register",
943                decl);
944       else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
945         error ("register specified for %q+D isn%'t suitable for data type",
946                decl);
947       /* Now handle properly declared static register variables.  */
948       else
949         {
950           int nregs;
951 
952           if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
953             {
954               DECL_INITIAL (decl) = 0;
955               error ("global register variable has initial value");
956             }
957           if (TREE_THIS_VOLATILE (decl))
958             warning (OPT_Wvolatile_register_var,
959                      "optimization may eliminate reads and/or "
960                      "writes to register variables");
961 
962           /* If the user specified one of the eliminables registers here,
963              e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
964              confused with that register and be eliminated.  This usage is
965              somewhat suspect...  */
66 
967           SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
968           ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
969           REG_USERVAR_P (DECL_RTL (decl)) = 1;
970 
971           if (TREE_STATIC (decl))
972             {
973               /* Make this register global, so not usable for anything
974                  else.  */
975 #ifdef ASM_DECLARE_REGISTER_GLOBAL
976               name = IDENTIFIER_POINTER (DECL_NAME (decl));
977               ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
978 #endif
979               nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
980               while (nregs > 0)
981                 globalize_reg (reg_number + --nregs);
982             }
983 
984           /* As a register variable, it has no section.  */
985           return;
986         }
987     }
988   /* Now handle ordinary static variables and functions (in memory).
989      Also handle vars declared register invalidly.  */
990   else if (name[0] == '*')
991   {
992 #ifdef REGISTER_PREFIX
993     if (strlen (REGISTER_PREFIX) != 0)
994       {
995         reg_number = decode_reg_name (name);
996         if (reg_number >= 0 || reg_number == -3)
997           error ("register name given for non-register variable %q+D", decl);
998       }
999 #endif
1000   }
1001 
1002   /* Specifying a section attribute on a variable forces it into a
1003      non-.bss section, and thus it cannot be common.  */
1004   if (TREE_CODE (decl) == VAR_DECL
1005       && DECL_SECTION_NAME (decl) != NULL_TREE
1006       && DECL_INITIAL (decl) == NULL_TREE
1007       && DECL_COMMON (decl))
1008     DECL_COMMON (decl) = 0;
1009 
1010   /* Variables can't be both common and weak.  */
1011   if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1012     DECL_COMMON (decl) = 0;
1013 
1014   x = gen_rtx_SYMBOL_REF (Pmode, name);
1015   SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1016   SYMBOL_REF_DECL (x) = decl;
1017 
1018   x = gen_rtx_MEM (DECL_MODE (decl), x);
1019   if (TREE_CODE (decl) != FUNCTION_DECL)
1020     set_mem_attributes (x, decl, 1);
1021   SET_DECL_RTL (decl, x);
1022 
1023   /* Optionally set flags or add text to the name to record information
1024      such as that it is a function name.
1025      If the name is changed, the macro ASM_OUTPUT_LABELREF
1026      will have to know how to strip this information.  */
1027   targetm.encode_section_info (decl, DECL_RTL (decl), true);
1028 
1029   /* Make this function static known to the mudflap runtime.  */
1030   if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1031     mudflap_enqueue_decl (decl);
1032 


リンク元

特に記載のない限り、コミュニティのコンテンツはCC-BY-SAライセンスの下で利用可能です。