From 60f8100f43c2e2d453f651e94888ac58746b0e9f Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Tue, 3 Mar 2026 07:14:37 -0800 Subject: [PATCH 01/10] Add IPA context structs for global state encapsulation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add three new files that define IPA_Options and IPA_Context structs, which will eventually replace the ~140 config_ipa.h globals and ~60 IPA module-level globals. This is the foundation for threading explicit context through IPA passes instead of relying on mutable global state. New files: - ipa_options.h: IPA_Options struct mirroring all config_ipa.h externs - ipa_context.h: IPA_Context struct with sub-structs for each subsystem - ipa_context.cxx: Init/Fini functions (defined but never called yet) No existing code is modified. The new code compiles but has zero behavior change — the init/fini functions exist but nothing calls them. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.cxx | 277 ++++++++++++++++++++++++++++++ osprey/ipa/common/ipa_context.h | 182 ++++++++++++++++++++ osprey/ipa/common/ipa_options.h | 243 ++++++++++++++++++++++++++ osprey/ipa/main/Makefile.gbase | 1 + 4 files changed, 703 insertions(+) create mode 100644 osprey/ipa/common/ipa_context.cxx create mode 100644 osprey/ipa/common/ipa_context.h create mode 100644 osprey/ipa/common/ipa_options.h diff --git a/osprey/ipa/common/ipa_context.cxx b/osprey/ipa/common/ipa_context.cxx new file mode 100644 index 00000000..2c127e52 --- /dev/null +++ b/osprey/ipa/common/ipa_context.cxx @@ -0,0 +1,277 @@ +/* + * + * IPA Context — initialization and cleanup. + * + * These functions exist but are NOT called by any existing code — zero behavior + * change. They populate the new structs FROM the existing globals so that + * later steps can incrementally switch readers to use the context. + */ + +#include "ipa_context.h" +#include "ipa_options.h" +#include "config_ipa.h" /* all the IPA_Enable_* / INLINE_* globals */ + +#include /* memset */ +#include /* malloc, free */ + +/* ==================================================================== + * Transitional globals + * ==================================================================== + */ +IPA_Context *g_ipa_ctx = NULL; +const IPA_Options *g_ipa_options = NULL; + +/* Internal mutable copy that g_ipa_options points to */ +static IPA_Options *ipa_options_mutable = NULL; + + +/* ==================================================================== + * IPA_Options_Init: snapshot every config_ipa.h global into the struct. + * ==================================================================== + */ +static void +IPA_Options_Init(void) +{ + if (ipa_options_mutable != NULL) + return; + + ipa_options_mutable = (IPA_Options *) malloc(sizeof(IPA_Options)); + memset(ipa_options_mutable, 0, sizeof(IPA_Options)); + + IPA_Options *o = ipa_options_mutable; + + /* --- Filenames --- */ + o->Feedback_Filename = Feedback_Filename; + o->Annotation_Filename = Annotation_Filename; + + /* --- Feature enable flags --- */ + o->Enable_DFE = IPA_Enable_DFE; + o->Enable_DFE_Set = IPA_Enable_DFE_Set; + o->Enable_Inline = IPA_Enable_Inline; + o->Enable_Picopt = IPA_Enable_Picopt; + o->Enable_AutoGnum = IPA_Enable_AutoGnum; + o->Enable_BarrierFarg = IPA_Enable_BarrierFarg; + o->Enable_Opt_Alias = IPA_Enable_Opt_Alias; + o->Enable_Simple_Alias = IPA_Enable_Simple_Alias; + o->Enable_Addressing = IPA_Enable_Addressing; + o->Enable_Readonly_Ref = IPA_Enable_Readonly_Ref; + o->Enable_Cprop = IPA_Enable_Cprop; + o->Enable_Cprop2 = IPA_Enable_Cprop2; + o->Enable_Assert = IPA_Enable_Assert; + o->Enable_daVinci = IPA_Enable_daVinci; + o->Enable_ipacom = IPA_Enable_ipacom; + o->Enable_final_link = IPA_Enable_final_link; + o->Enable_Memtrace = IPA_Enable_Memtrace; + o->Enable_DST = IPA_Enable_DST; + o->Enable_DCE = IPA_Enable_DCE; + o->Enable_Exc = IPA_Enable_Exc; + o->Enable_Recycle = IPA_Enable_Recycle; + o->Enable_DVE = IPA_Enable_DVE; + o->Enable_CGI = IPA_Enable_CGI; + o->Enable_Copy_Prop = IPA_Enable_Copy_Prop; + o->Enable_Padding = IPA_Enable_Padding; + o->Common_Pad_Size = IPA_Common_Pad_Size; + o->Enable_Split_Common = IPA_Enable_Split_Common; + o->Enable_Cloning = IPA_Enable_Cloning; + o->Enable_Partial_Inline = IPA_Enable_Partial_Inline; + o->Echo_Commands = IPA_Echo_Commands; + o->Enable_Lang = IPA_Enable_Lang; + o->Enable_Preempt = IPA_Enable_Preempt; + o->Enable_Flow_Analysis = IPA_Enable_Flow_Analysis; + o->Enable_Array_Sections = IPA_Enable_Array_Sections; + o->Enable_Array_Summary = IPA_Enable_Array_Summary; + o->Enable_Scalar_Euse = IPA_Enable_Scalar_Euse; + o->Enable_Scalar_Kill = IPA_Enable_Scalar_Kill; + o->Enable_Common_Const = IPA_Enable_Common_Const; + o->Enable_Relocatable_Opt = IPA_Enable_Relocatable_Opt; + o->Enable_Feedback = IPA_Enable_Feedback; + o->Enable_Alias_Class = IPA_Enable_Alias_Class; + o->Debug_AC_Temp_Files = IPA_Debug_AC_Temp_Files; + o->Enable_Reshape = IPA_Enable_Reshape; + o->Enable_Preopt = IPA_Enable_Preopt; + o->Enable_Preopt_Set = IPA_Enable_Preopt_Set; + o->Enable_Siloed_Ref = IPA_Enable_Siloed_Ref; + o->Enable_Siloed_Ref_Set = IPA_Enable_Siloed_Ref_Set; + +#ifdef KEY + o->Enable_Icall_Opt = IPA_Enable_Icall_Opt; + o->Enable_EH_Region_Removal = IPA_Enable_EH_Region_Removal; + o->Enable_Branch_Heuristic = IPA_Enable_Branch_Heuristic; + o->Min_Branch_Prob = IPA_Min_Branch_Prob; + o->Check_Options = IPA_Check_Options; + o->Clone_List_Actions = IPA_Clone_List_Actions; + o->Enable_Pure_Call_Opt = IPA_Enable_Pure_Call_Opt; + o->Pure_Call_skip_before = IPA_Pure_Call_skip_before; + o->Consult_Inliner_For_Icall_Opt = IPA_Consult_Inliner_For_Icall_Opt; + o->Icall_Min_Freq = IPA_Icall_Min_Freq; + o->Enable_Source_PU_Order = IPA_Enable_Source_PU_Order; + o->Enable_Struct_Opt = IPA_Enable_Struct_Opt; + o->Enable_Global_As_Local = IPA_Enable_Global_As_Local; + o->Update_Struct = IPA_Update_Struct; +#endif + + o->Icall_Target_Min_Rate = IPA_Icall_Target_Min_Rate; + + /* --- Inlining heuristics --- */ + o->Bloat_Factor = IPA_Bloat_Factor; + o->Bloat_Factor_Set = IPA_Bloat_Factor_Set; + o->PU_Limit = IPA_PU_Limit; + o->PU_Limit_Set = IPA_PU_Limit_Set; + o->PU_Hard_Limit = IPA_PU_Hard_Limit; + o->PU_Hard_Limit_Set = IPA_PU_Hard_Limit_Set; + o->PU_Minimum_Size = IPA_PU_Minimum_Size; + o->Small_Callee_Limit = IPA_Small_Callee_Limit; + o->Max_Depth = IPA_Max_Depth; + o->Force_Depth = IPA_Force_Depth; + o->Force_Depth_Set = IPA_Force_Depth_Set; + o->Min_Freq = IPA_Min_Freq; + o->Rela_Freq = IPA_Rela_Freq; + o->Min_Hotness = IPA_Min_Hotness; + o->Use_Effective_Size = IPA_Use_Effective_Size; + + /* --- Miscellaneous --- */ + o->Enable_Merge_ty = IPA_Enable_Merge_ty; + o->Max_Jobs = IPA_Max_Jobs; + o->Max_Jobs_Set = IPA_Max_Jobs_Set; + o->Gspace = IPA_Gspace; + o->user_gnum = IPA_user_gnum; + o->Extgot_Factor = IPA_Extgot_Factor; + o->Num_Fortran_Intrinsics = IPA_Num_Fortran_Intrinsics; + o->Has_Fortran = IPA_Has_Fortran; + o->Map_Limit = IPA_Map_Limit; + o->Enable_SP_Partition = IPA_Enable_SP_Partition; + o->Enable_GP_Partition = IPA_Enable_GP_Partition; + o->Space_Access_Mode = IPA_Space_Access_Mode; + o->Group_Names = IPA_Group_Names; + o->Spec_Files = IPA_Spec_Files; + o->Skip = IPA_Skip; + o->Skip_Report = IPA_Skip_Report; + o->Enable_Keeplight = IPA_Enable_Keeplight; + o->Enable_Cord = IPA_Enable_Cord; + o->Enable_Linearization = IPA_Enable_Linearization; + o->Use_Intrinsic = IPA_Use_Intrinsic; + o->Enable_Inline_Nested_PU = IPA_Enable_Inline_Nested_PU; + o->Enable_Inline_Struct = IPA_Enable_Inline_Struct; + o->Enable_Inline_Char_Array = IPA_Enable_Inline_Char_Array; + o->Enable_Inline_Optional_Arg = IPA_Enable_Inline_Optional_Arg; + o->Enable_Inline_Struct_Array_Actual = IPA_Enable_Inline_Struct_Array_Actual; + o->Enable_Inline_Var_Dim_Array = IPA_Enable_Inline_Var_Dim_Array; + o->Enable_Reorder = IPA_Enable_Reorder; + o->Enable_AOT = IPA_Enable_AOT; + +#ifdef KEY + o->Enable_PU_Reorder = (IPA_OPT_PU_REORDER_SCHEME) IPA_Enable_PU_Reorder; + o->Enable_PU_Reorder_Set = IPA_Enable_PU_Reorder_Set; + o->Enable_Ctype = IPA_Enable_Ctype; + o->Inline_Check_Compatibility = + (IPA_OPT_CHECK_PARAM_COMPATIBILITY) INLINE_Check_Compatibility; +#endif + + o->Max_Node_Clones = IPA_Max_Node_Clones; + o->Max_Node_Clones_Set = IPA_Max_Node_Clones_Set; + o->Max_Clone_Bloat = IPA_Max_Clone_Bloat; + o->Max_Output_File_Size = IPA_Max_Output_File_Size; + o->Output_File_Size = IPA_Output_File_Size; + o->Max_Density = IPA_Max_Density; + o->Enable_Old_Type_Merge = IPA_Enable_Old_Type_Merge; + + /* --- Devirtualization --- */ + o->Enable_Devirtualization = IPA_Enable_Devirtualization; + o->Enable_Fast_Static_Analysis_VF = IPA_Enable_Fast_Static_Analysis_VF; + o->Enable_Original_VF = IPA_Enable_Original_VF; + o->Enable_New_VF = IPA_Enable_New_VF; + o->Inline_Original_VF = IPA_Inline_Original_VF; + o->Inline_New_VF = IPA_Inline_New_VF; + o->Devirtualization_Input_File = IPA_Devirtualization_Input_File; + o->During_Original_VF = IPA_During_Original_VF; + o->During_New_VF = IPA_During_New_VF; + + /* --- Whole program / scale --- */ + o->Enable_Whole_Program_Mode = IPA_Enable_Whole_Program_Mode; + o->Enable_Whole_Program_Mode_Set = IPA_Enable_Whole_Program_Mode_Set; + o->Enable_Scale = IPA_Enable_Scale; + + /* --- INLINE group options --- */ + o->Inline_Enable = INLINE_Enable; + o->Inline_All = INLINE_All; + o->Inline_Optimize_Alloca = INLINE_Optimize_Alloca; + o->Inline_Enable_Copy_Prop = INLINE_Enable_Copy_Prop; + o->Inline_Enable_Subst_Copy_Prop = INLINE_Enable_Subst_Copy_Prop; + o->Inline_F90 = INLINE_F90; + o->Inline_None = INLINE_None; + o->Inline_Exceptions = INLINE_Exceptions; + o->Inline_Keep_PU_Order = INLINE_Keep_PU_Order; + o->Inline_List_Actions = INLINE_List_Actions; + o->Inline_Max_Pu_Size = INLINE_Max_Pu_Size; + o->Inline_Preemptible = INLINE_Preemptible; + o->Inline_Static = INLINE_Static; + o->Inline_Static_Set = INLINE_Static_Set; + o->Inline_Aggressive = INLINE_Aggressive; + o->Inline_First_Inline_Calls_In_Loops = INLINE_First_Inline_Calls_In_Loops; + o->Inline_Enable_DFE = IPA_Enable_DFE; + o->Inline_Enable_Split_Common = INLINE_Enable_Split_Common; + o->Inline_Enable_Auto_Inlining = INLINE_Enable_Auto_Inlining; + o->Inline_Enable_Restrict_Pointers = INLINE_Enable_Restrict_Pointers; + +#ifdef KEY + o->Inline_Recursive = INLINE_Recursive; + o->Inline_Param_Mismatch = INLINE_Param_Mismatch; + o->Inline_Type_Mismatch = INLINE_Type_Mismatch; + o->Inline_Ignore_Bloat = INLINE_Ignore_Bloat; + o->Inline_Callee_Limit = INLINE_Callee_Limit; +#endif + + o->Inline_List_Names = INLINE_List_Names; + o->Inline_Spec_Files = INLINE_Spec_Files; + o->Inline_Skip_After = INLINE_Skip_After; + o->Inline_Skip_Before = INLINE_Skip_Before; + o->Inline_Array_Bounds = INLINE_Array_Bounds; + o->Inline_Use_Malloc_Mempool = INLINE_Use_Malloc_Mempool; + o->Inline_Free_Malloc_Mempool = INLINE_Free_Malloc_Mempool; + o->Inline_Inlined_Pu_Call_Graph = INLINE_Inlined_Pu_Call_Graph; + o->Inline_Inlined_Pu_Call_Graph2 = INLINE_Inlined_Pu_Call_Graph2; + o->Inline_Get_Time_Info = INLINE_Get_Time_Info; + o->Inline_Script_Name = INLINE_Script_Name; + o->Inline_Enable_Script = INLINE_Enable_Script; + o->Inline_Enable_Devirtualize = INLINE_Enable_Devirtualize; + + g_ipa_options = ipa_options_mutable; +} + + +/* ==================================================================== + * IPA_Context_Init: allocate and zero-fill the master context. + * Calls IPA_Options_Init to snapshot the option globals. + * ==================================================================== + */ +void +IPA_Context_Init(void) +{ + if (g_ipa_ctx != NULL) + return; + + g_ipa_ctx = (IPA_Context *) malloc(sizeof(IPA_Context)); + memset(g_ipa_ctx, 0, sizeof(IPA_Context)); + + IPA_Options_Init(); +} + + +/* ==================================================================== + * IPA_Context_Fini: release the context and options structs. + * ==================================================================== + */ +void +IPA_Context_Fini(void) +{ + if (ipa_options_mutable != NULL) { + free(ipa_options_mutable); + ipa_options_mutable = NULL; + g_ipa_options = NULL; + } + + if (g_ipa_ctx != NULL) { + free(g_ipa_ctx); + g_ipa_ctx = NULL; + } +} diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h new file mode 100644 index 00000000..da232cbf --- /dev/null +++ b/osprey/ipa/common/ipa_context.h @@ -0,0 +1,182 @@ +/* + * + * IPA Context — master struct that will eventually replace all IPA + * module-level globals. Sub-structs group related state by subsystem. + * + * Heavy types are forward-declared to keep this header lightweight. + */ + +#ifndef cxx_ipa_context_INCLUDED +#define cxx_ipa_context_INCLUDED + +#ifndef defs_INCLUDED +#include "defs.h" /* BOOL, INT, INT32, UINT32 */ +#endif + +#ifndef mempool_INCLUDED +#include "mempool.h" /* MEM_POOL */ +#endif + +#ifndef fb_freq_INCLUDED +#include "fb_freq.h" /* FB_FREQ */ +#endif + +#include /* FILE */ + +/* Forward declarations — avoids pulling in heavy headers */ +class IPA_CALL_GRAPH; +class IPA_CLASS_HIERARCHY; +class IPA_PCG; +class IP_ALIAS_CLASSIFICATION; +class daVinci; +class COMMON_SNODE_TBL; +struct Field_pos; +struct REORDER_CAND; +struct MERGED_ACCESS; + +/* We need the vector type for MERGED_ACCESS_VECTOR */ +#include +typedef std::vector MERGED_ACCESS_VECTOR; + + +/* ==================================================================== + * Sub-structs — each groups the globals from one IPA subsystem. + * ==================================================================== + */ + +/* --- Feedback file descriptors (ipa_feedback.h) --- */ +struct IPA_Feedback_State { + FILE *exl_fd; /* exclusion list */ + FILE *dve_fd; /* dead variable elimination */ + FILE *dfe_fd; /* dead function elimination */ + FILE *prg_fd; /* pragma file */ + FILE *con_fd; /* constant propagation */ +}; + +/* --- Struct optimization (ipa_struct_opt.h) --- */ +struct IPA_Struct_Opt_State { + Field_pos *field_layout; + INT split_count; + UINT32 complete_struct_relayout_type_id; +}; + +/* --- Call-graph visualization (ipc_daVinci.h) --- */ +struct IPA_Visualization_State { + daVinci *cg_display; +}; + +/* --- Array section analysis (ipa_section_prop.h) --- */ +struct IPA_Array_Section_State { + MEM_POOL array_prop_pool; + BOOL trace_sections; +}; + +/* --- Structure field reordering (ipa_reorder.h) --- */ +struct IPA_Reorder_State { + MERGED_ACCESS_VECTOR *merged_access; + MEM_POOL local_pool; + REORDER_CAND *candidate; +}; + +/* --- Class hierarchy graph (ipa_chg.h, ipa_pcg.h) --- */ +struct IPA_CHG_State { + IPA_CLASS_HIERARCHY *class_hierarchy; + IPA_PCG *concurrency_graph; +}; + +/* --- Common block state (ipa_pad.h) --- */ +struct IPA_Common_State { + COMMON_SNODE_TBL *common_table; + INT pad_count; +}; + +/* --- Inlining statistics (ipa_inline.h, ipa_cg.h) --- */ +struct IPA_Inline_Stats { + INT total_prog_size; + INT total_inlined; + INT total_not_inlined; + INT total_must_inlined; + INT total_must_not_inlined; + + UINT32 orig_prog_weight; + UINT32 total_dead_function_weight; + UINT32 orig_prog_wn_count; + UINT32 prog_wn_count; + UINT32 total_dead_function_wn_count; + + FB_FREQ total_call_freq; + FB_FREQ total_cycle_count; +#ifdef KEY + FB_FREQ total_cycle_count_2; +#endif + + FILE *n_inlining; /* trace: not-inlined decisions */ + FILE *y_inlining; /* trace: inlined decisions */ + FILE *e_weight; /* trace: edge weights */ + FILE *verbose_inlining; /* trace: verbose output */ +}; + +/* --- Constant propagation state (ipa_cprop.h) --- */ +struct IPA_Cprop_State { + MEM_POOL cprop_pool; + MEM_POOL local_pool; + MEM_POOL global_pool; + INT constant_count; + UINT32 max_total_clones; + UINT32 num_total_clones; +}; + +/* --- Alias analysis state (ipaa.h) --- */ +struct IPA_Alias_Analysis_State { + /* Placeholder — will be populated when we migrate IPAA globals */ +}; + +/* --- Type/symbol merge state --- */ +struct IPA_Merge_State { + /* Placeholder — will be populated when we migrate merge globals */ +}; + +/* --- Compile state (ipc_compile.cxx) --- */ +struct IPA_Compile_State { + /* Placeholder — will be populated when we migrate compile globals */ +}; + + +/* ==================================================================== + * IPA_Context: the master context struct. + * ==================================================================== + */ +struct IPA_Context { + + /* --- Core pointers --- */ + IPA_CALL_GRAPH *call_graph; + BOOL call_graph_built; +#ifdef KEY + IPA_CALL_GRAPH *graph_undirected; +#endif + BOOL opt_options_inconsistent; + + /* --- Per-subsystem state --- */ + IPA_Feedback_State feedback; + IPA_Struct_Opt_State struct_opt; + IPA_Visualization_State visualization; + IPA_Array_Section_State array_section; + IPA_Reorder_State reorder; + IPA_CHG_State chg; + IPA_Common_State common; + IPA_Inline_Stats inline_stats; + IPA_Cprop_State cprop; + IPA_Alias_Analysis_State alias_analysis; + IPA_Merge_State merge; + IPA_Compile_State compile; +}; + + +/* Transitional global — will be removed once all call-sites are threaded */ +extern IPA_Context *g_ipa_ctx; + +/* Lifecycle functions (defined in ipa_context.cxx) */ +extern void IPA_Context_Init(void); +extern void IPA_Context_Fini(void); + +#endif /* cxx_ipa_context_INCLUDED */ diff --git a/osprey/ipa/common/ipa_options.h b/osprey/ipa/common/ipa_options.h new file mode 100644 index 00000000..92cd386b --- /dev/null +++ b/osprey/ipa/common/ipa_options.h @@ -0,0 +1,243 @@ +/* + * + * IPA Options context struct — encapsulates the ~140 config_ipa.h globals + * into a single struct for eventual threading through IPA passes. + * + */ + +#ifndef cxx_ipa_options_INCLUDED +#define cxx_ipa_options_INCLUDED + +#ifndef defs_INCLUDED +#include "defs.h" /* BOOL, INT, INT32, UINT32 */ +#endif + +struct option_list; + +#ifdef KEY +/* Enums duplicated from config_ipa.h so this header is self-contained. + * The canonical definitions remain in config_ipa.h; these must stay in sync. + */ +typedef enum { + IPA_OPT_REORDER_DISABLE = 0, + IPA_OPT_REORDER_BY_NODE_FREQ = 1, + IPA_OPT_REORDER_BY_EDGE_FREQ = 2, + IPA_OPT_REORDER_BY_BFS = 3 +} IPA_OPT_PU_REORDER_SCHEME; + +typedef enum { + IPA_OPT_STRICT_CHECK = 0, + IPA_OPT_RELAXED_CHECK = 1, + IPA_OPT_AGGRESSIVE = 2 +} IPA_OPT_CHECK_PARAM_COMPATIBILITY; +#endif /* KEY */ + +/* ==================================================================== + * IPA_Options: mirrors every extern in config_ipa.h. + * Grouped by category for readability. + * ==================================================================== + */ +struct IPA_Options { + + /* --- Filenames --- */ + char *Feedback_Filename; + char *Annotation_Filename; + + /* --- Feature enable flags --- */ + BOOL Enable_DFE; + BOOL Enable_DFE_Set; + BOOL Enable_Inline; + BOOL Enable_Picopt; + BOOL Enable_AutoGnum; + BOOL Enable_BarrierFarg; + BOOL Enable_Opt_Alias; + BOOL Enable_Simple_Alias; + BOOL Enable_Addressing; + BOOL Enable_Readonly_Ref; + BOOL Enable_Cprop; + BOOL Enable_Cprop2; + BOOL Enable_Assert; + BOOL Enable_daVinci; + BOOL Enable_ipacom; + BOOL Enable_final_link; + BOOL Enable_Memtrace; + BOOL Enable_DST; + BOOL Enable_DCE; + BOOL Enable_Exc; + BOOL Enable_Recycle; + BOOL Enable_DVE; + BOOL Enable_CGI; + BOOL Enable_Copy_Prop; + BOOL Enable_Padding; + UINT32 Common_Pad_Size; + BOOL Enable_Split_Common; + BOOL Enable_Cloning; + BOOL Enable_Partial_Inline; + BOOL Echo_Commands; + BOOL Enable_Lang; + BOOL Enable_Preempt; + BOOL Enable_Flow_Analysis; + BOOL Enable_Array_Sections; + BOOL Enable_Array_Summary; + BOOL Enable_Scalar_Euse; + BOOL Enable_Scalar_Kill; + BOOL Enable_Common_Const; + BOOL Enable_Relocatable_Opt; + BOOL Enable_Feedback; + BOOL Enable_Alias_Class; + BOOL Debug_AC_Temp_Files; + BOOL Enable_Reshape; + BOOL Enable_Preopt; + BOOL Enable_Preopt_Set; + BOOL Enable_Siloed_Ref; + BOOL Enable_Siloed_Ref_Set; + +#ifdef KEY + BOOL Enable_Icall_Opt; + BOOL Enable_EH_Region_Removal; + BOOL Enable_Branch_Heuristic; + float Min_Branch_Prob; + BOOL Check_Options; + BOOL Clone_List_Actions; + BOOL Enable_Pure_Call_Opt; + INT32 Pure_Call_skip_before; + BOOL Consult_Inliner_For_Icall_Opt; + UINT32 Icall_Min_Freq; + BOOL Enable_Source_PU_Order; + UINT32 Enable_Struct_Opt; + UINT32 Enable_Global_As_Local; + UINT32 Update_Struct; +#endif /* KEY */ + + UINT32 Icall_Target_Min_Rate; + + /* --- Inlining heuristics --- */ + UINT32 Bloat_Factor; + BOOL Bloat_Factor_Set; + UINT32 PU_Limit; + BOOL PU_Limit_Set; + UINT32 PU_Hard_Limit; + BOOL PU_Hard_Limit_Set; + UINT32 PU_Minimum_Size; + UINT32 Small_Callee_Limit; + UINT32 Max_Depth; + UINT32 Force_Depth; + BOOL Force_Depth_Set; + UINT32 Min_Freq; + UINT32 Rela_Freq; + UINT32 Min_Hotness; + BOOL Use_Effective_Size; + + /* --- Miscellaneous --- */ + BOOL Enable_Merge_ty; + UINT32 Max_Jobs; + BOOL Max_Jobs_Set; + UINT32 Gspace; + UINT32 user_gnum; + UINT32 Extgot_Factor; + UINT32 Num_Fortran_Intrinsics; + BOOL Has_Fortran; + UINT32 Map_Limit; + BOOL Enable_SP_Partition; + BOOL Enable_GP_Partition; + BOOL Space_Access_Mode; + + struct option_list *Group_Names; + struct option_list *Spec_Files; + struct option_list *Skip; + BOOL Skip_Report; + + BOOL Enable_Keeplight; + BOOL Enable_Cord; + BOOL Enable_Linearization; + BOOL Use_Intrinsic; + BOOL Enable_Inline_Nested_PU; + BOOL Enable_Inline_Struct; + BOOL Enable_Inline_Char_Array; + BOOL Enable_Inline_Optional_Arg; + BOOL Enable_Inline_Struct_Array_Actual; + BOOL Enable_Inline_Var_Dim_Array; + BOOL Enable_Reorder; + BOOL Enable_AOT; + +#ifdef KEY + IPA_OPT_PU_REORDER_SCHEME Enable_PU_Reorder; + BOOL Enable_PU_Reorder_Set; + BOOL Enable_Ctype; + IPA_OPT_CHECK_PARAM_COMPATIBILITY Inline_Check_Compatibility; +#endif /* KEY */ + + UINT32 Max_Node_Clones; + BOOL Max_Node_Clones_Set; + UINT32 Max_Clone_Bloat; + UINT32 Max_Output_File_Size; + INT32 Output_File_Size; + UINT32 Max_Density; + + BOOL Enable_Old_Type_Merge; + + /* --- Devirtualization --- */ + BOOL Enable_Devirtualization; + BOOL Enable_Fast_Static_Analysis_VF; + BOOL Enable_Original_VF; + BOOL Enable_New_VF; + BOOL Inline_Original_VF; + BOOL Inline_New_VF; + const char *Devirtualization_Input_File; + BOOL During_Original_VF; + BOOL During_New_VF; + + /* --- Whole program / scale --- */ + BOOL Enable_Whole_Program_Mode; + BOOL Enable_Whole_Program_Mode_Set; + BOOL Enable_Scale; + + /* --- INLINE group options --- */ + BOOL Inline_Enable; + BOOL Inline_All; + BOOL Inline_Optimize_Alloca; + BOOL Inline_Enable_Copy_Prop; + BOOL Inline_Enable_Subst_Copy_Prop; + BOOL Inline_F90; + BOOL Inline_None; + BOOL Inline_Exceptions; + BOOL Inline_Keep_PU_Order; + BOOL Inline_List_Actions; + UINT32 Inline_Max_Pu_Size; + BOOL Inline_Preemptible; + BOOL Inline_Static; + BOOL Inline_Static_Set; + BOOL Inline_Aggressive; + BOOL Inline_First_Inline_Calls_In_Loops; + BOOL Inline_Enable_DFE; + BOOL Inline_Enable_Split_Common; + BOOL Inline_Enable_Auto_Inlining; + BOOL Inline_Enable_Restrict_Pointers; + +#ifdef KEY + BOOL Inline_Recursive; + BOOL Inline_Param_Mismatch; + BOOL Inline_Type_Mismatch; + BOOL Inline_Ignore_Bloat; + UINT32 Inline_Callee_Limit; +#endif /* KEY */ + + struct option_list *Inline_List_Names; + struct option_list *Inline_Spec_Files; + UINT32 Inline_Skip_After; + UINT32 Inline_Skip_Before; + BOOL Inline_Array_Bounds; + BOOL Inline_Use_Malloc_Mempool; + BOOL Inline_Free_Malloc_Mempool; + BOOL Inline_Inlined_Pu_Call_Graph; + BOOL Inline_Inlined_Pu_Call_Graph2; + BOOL Inline_Get_Time_Info; + char *Inline_Script_Name; + BOOL Inline_Enable_Script; + BOOL Inline_Enable_Devirtualize; +}; + +/* Transitional global — will be removed once all call-sites are threaded */ +extern const IPA_Options *g_ipa_options; + +#endif /* cxx_ipa_options_INCLUDED */ diff --git a/osprey/ipa/main/Makefile.gbase b/osprey/ipa/main/Makefile.gbase index f8dd66b6..e8c85b67 100644 --- a/osprey/ipa/main/Makefile.gbase +++ b/osprey/ipa/main/Makefile.gbase @@ -150,6 +150,7 @@ IPA_LD_COMMON_SRCS = \ IPA_COMMON_CXX_SRCS = \ ip_graph.cxx \ + ipa_context.cxx \ ipc_dst_merge.cxx \ ipc_dst_utils.cxx \ ipc_link.cxx \ From c90150c894307368166b697d4ecf655c79938e33 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Mon, 2 Mar 2026 20:30:16 -0800 Subject: [PATCH 02/10] Migrate feedback FD globals to IPA_Context Replace the 5 extern FILE* declarations in ipa_feedback.h with macros that redirect to g_ipa_ctx->feedback.* fields. All usages of these variables are inside #ifdef TODO blocks (dead code), so this has zero runtime impact. Also fix SEGMENTED_ARRAY template parameter type in ipa_context.h (UINT, not INT32) to match the canonical definition in segmented_array.h. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/main/analyze/ipa_feedback.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/osprey/ipa/main/analyze/ipa_feedback.h b/osprey/ipa/main/analyze/ipa_feedback.h index ded71b05..880ea849 100755 --- a/osprey/ipa/main/analyze/ipa_feedback.h +++ b/osprey/ipa/main/analyze/ipa_feedback.h @@ -59,12 +59,16 @@ #define ipa_feedback_INCLUDED -// Main output file(s) for feedback info -extern FILE *IPA_Feedback_exl_fd; -extern FILE *IPA_Feedback_dve_fd; -extern FILE *IPA_Feedback_dfe_fd; -extern FILE *IPA_Feedback_prg_fd; -extern FILE *IPA_Feedback_con_fd; +// Feedback file descriptors now live in IPA_Context (ipa_context.h). +// These macros provide backward-compatible access for existing code. +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPA_Feedback_exl_fd (g_ipa_ctx->feedback.exl_fd) +#define IPA_Feedback_dve_fd (g_ipa_ctx->feedback.dve_fd) +#define IPA_Feedback_dfe_fd (g_ipa_ctx->feedback.dfe_fd) +#define IPA_Feedback_prg_fd (g_ipa_ctx->feedback.prg_fd) +#define IPA_Feedback_con_fd (g_ipa_ctx->feedback.con_fd) // for string table + hash table manipulation #define FBK_HASH_TAB_SIZE 128 From 3c75f4b0262a06d81fdf187f2480c28e126b8b86 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Mon, 2 Mar 2026 21:03:11 -0800 Subject: [PATCH 03/10] Migrate struct-opt globals to IPA_Context Replace 6 extern globals in ipa_struct_opt.h with #define macros pointing to g_ipa_ctx->struct_opt.*: - Struct_field_layout, Struct_split_count - complete_struct_relayout_type_id and related arrays - num_structs_with_field_pointing_to_complete_struct_relayout Fix Field_pos forward declaration: use typedef of struct Field_pos_ since the original uses C-style typedef (not a struct tag). Remove variable definitions from ipa_struct_opt.cxx; zero-init via memset in IPA_Context_Init() provides equivalent defaults. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.h | 11 ++++++-- osprey/ipa/main/analyze/ipa_struct_opt.cxx | 11 ++------ osprey/ipa/main/analyze/ipa_struct_opt.h | 29 +++++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h index da232cbf..063147d3 100644 --- a/osprey/ipa/common/ipa_context.h +++ b/osprey/ipa/common/ipa_context.h @@ -30,7 +30,8 @@ class IPA_PCG; class IP_ALIAS_CLASSIFICATION; class daVinci; class COMMON_SNODE_TBL; -struct Field_pos; +struct Field_pos_; +typedef struct Field_pos_ Field_pos; struct REORDER_CAND; struct MERGED_ACCESS; @@ -54,10 +55,16 @@ struct IPA_Feedback_State { }; /* --- Struct optimization (ipa_struct_opt.h) --- */ +#ifndef mtypes_INCLUDED +#include "mtypes.h" /* TYPE_ID (UINT8) */ +#endif struct IPA_Struct_Opt_State { Field_pos *field_layout; INT split_count; - UINT32 complete_struct_relayout_type_id; + TYPE_ID complete_struct_relayout_type_id; + TYPE_ID struct_with_field_pointing_to_complete_struct_relayout_type_id[32]; + int struct_with_field_pointing_to_complete_struct_relayout_field_num[32]; + int num_structs_with_field_pointing_to_complete_struct_relayout; }; /* --- Call-graph visualization (ipc_daVinci.h) --- */ diff --git a/osprey/ipa/main/analyze/ipa_struct_opt.cxx b/osprey/ipa/main/analyze/ipa_struct_opt.cxx index 775f1d79..6c0f8bf5 100644 --- a/osprey/ipa/main/analyze/ipa_struct_opt.cxx +++ b/osprey/ipa/main/analyze/ipa_struct_opt.cxx @@ -38,15 +38,8 @@ #include "tracing.h" #include "ipa_option.h" // Trace_IPA -Field_pos *Struct_field_layout = NULL; -INT Struct_split_count = 0; - -TYPE_ID complete_struct_relayout_type_id = 0; -TYPE_ID struct_with_field_pointing_to_complete_struct_relayout_type_id - [MAX_NUM_STRUCTS_WITH_FIELD_POINTING_TO_COMPLETE_STRUCT_RELAYOUT]; -int struct_with_field_pointing_to_complete_struct_relayout_field_num - [MAX_NUM_STRUCTS_WITH_FIELD_POINTING_TO_COMPLETE_STRUCT_RELAYOUT]; -int num_structs_with_field_pointing_to_complete_struct_relayout = 0; +// Struct-opt globals migrated to g_ipa_ctx->struct_opt (ipa_context.h). +// Macros in ipa_struct_opt.h provide backward-compatible names. // Invalidate struct types that are either parameters or returned from // functions, or if a pointer to such types is a parameter or returned diff --git a/osprey/ipa/main/analyze/ipa_struct_opt.h b/osprey/ipa/main/analyze/ipa_struct_opt.h index 927a9825..0c398a9b 100644 --- a/osprey/ipa/main/analyze/ipa_struct_opt.h +++ b/osprey/ipa/main/analyze/ipa_struct_opt.h @@ -51,21 +51,26 @@ typedef struct Field_pos_ ST_IDX st_idx; } Field_pos; -// Data structure to tell IPO how to relayout a struct. It has N -// elements, where N is the number of fields in the original struct. -extern Field_pos *Struct_field_layout; -// Number of pieces (individual fields or smaller structs) a struct -// is split into. -extern INT Struct_split_count; +// Struct-opt globals now live in IPA_Context (ipa_context.h). +// These macros provide backward-compatible access for existing code. +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define Struct_field_layout \ + (g_ipa_ctx->struct_opt.field_layout) +#define Struct_split_count \ + (g_ipa_ctx->struct_opt.split_count) #define MAX_NUM_FIELDS_IN_COMPLETE_STRUCT_RELAYOUT 16 -extern TYPE_ID complete_struct_relayout_type_id; +#define complete_struct_relayout_type_id \ + (g_ipa_ctx->struct_opt.complete_struct_relayout_type_id) #define MAX_NUM_STRUCTS_WITH_FIELD_POINTING_TO_COMPLETE_STRUCT_RELAYOUT 32 -extern TYPE_ID struct_with_field_pointing_to_complete_struct_relayout_type_id - [MAX_NUM_STRUCTS_WITH_FIELD_POINTING_TO_COMPLETE_STRUCT_RELAYOUT]; -extern int struct_with_field_pointing_to_complete_struct_relayout_field_num - [MAX_NUM_STRUCTS_WITH_FIELD_POINTING_TO_COMPLETE_STRUCT_RELAYOUT]; -extern int num_structs_with_field_pointing_to_complete_struct_relayout; +#define struct_with_field_pointing_to_complete_struct_relayout_type_id \ + (g_ipa_ctx->struct_opt.struct_with_field_pointing_to_complete_struct_relayout_type_id) +#define struct_with_field_pointing_to_complete_struct_relayout_field_num \ + (g_ipa_ctx->struct_opt.struct_with_field_pointing_to_complete_struct_relayout_field_num) +#define num_structs_with_field_pointing_to_complete_struct_relayout \ + (g_ipa_ctx->struct_opt.num_structs_with_field_pointing_to_complete_struct_relayout) #endif // cxx_ipa_struct_opt_INCLUDED From 2c2ab4c478bce9174aa0720d13bf22c1304178e8 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Mon, 2 Mar 2026 21:28:56 -0800 Subject: [PATCH 04/10] Migrate visualization, array-section, reorder, and CHG globals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step 4: cg_display → g_ipa_ctx->visualization.cg_display Step 5: IPA_array_prop_pool, Trace_IPA_Sections → g_ipa_ctx->array_section.* Step 6: merged_access, reorder_local_pool, reorder_candidate → g_ipa_ctx->reorder.* - reorder_candidate uses pointer indirection (*candidate_ptr) since REORDER_CAND can't be forward-declared by value in ipa_context.h Step 7: IPA_Class_Hierarchy, IPA_Concurrency_Graph → g_ipa_ctx->chg.* Also fix COMMON_SNODE_TBL forward declaration: it's a typedef of HASH_TABLE<...>, not a class — use void* placeholder until step 8. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.h | 8 ++++---- osprey/ipa/common/ipc_daVinci.cxx | 2 +- osprey/ipa/common/ipc_daVinci.h | 6 +++++- osprey/ipa/main/analyze/ipa_chg.cxx | 2 +- osprey/ipa/main/analyze/ipa_chg.h | 7 +++++-- osprey/ipa/main/analyze/ipa_pcg.cxx | 2 +- osprey/ipa/main/analyze/ipa_pcg.h | 6 +++++- osprey/ipa/main/analyze/ipa_reorder.cxx | 9 +++++---- osprey/ipa/main/analyze/ipa_reorder.h | 10 +++++++--- osprey/ipa/main/analyze/ipa_section_prop.cxx | 4 ++-- osprey/ipa/main/analyze/ipa_section_prop.h | 8 ++++++-- 11 files changed, 42 insertions(+), 22 deletions(-) diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h index 063147d3..38859b90 100644 --- a/osprey/ipa/common/ipa_context.h +++ b/osprey/ipa/common/ipa_context.h @@ -29,7 +29,7 @@ class IPA_CLASS_HIERARCHY; class IPA_PCG; class IP_ALIAS_CLASSIFICATION; class daVinci; -class COMMON_SNODE_TBL; +/* COMMON_SNODE_TBL is a typedef (HASH_TABLE<...>); forward-declare as void* */ struct Field_pos_; typedef struct Field_pos_ Field_pos; struct REORDER_CAND; @@ -75,14 +75,14 @@ struct IPA_Visualization_State { /* --- Array section analysis (ipa_section_prop.h) --- */ struct IPA_Array_Section_State { MEM_POOL array_prop_pool; - BOOL trace_sections; + BOOL trace_ipa_sections; }; /* --- Structure field reordering (ipa_reorder.h) --- */ struct IPA_Reorder_State { MERGED_ACCESS_VECTOR *merged_access; MEM_POOL local_pool; - REORDER_CAND *candidate; + REORDER_CAND *candidate_ptr; }; /* --- Class hierarchy graph (ipa_chg.h, ipa_pcg.h) --- */ @@ -93,7 +93,7 @@ struct IPA_CHG_State { /* --- Common block state (ipa_pad.h) --- */ struct IPA_Common_State { - COMMON_SNODE_TBL *common_table; + void *common_table; /* COMMON_SNODE_TBL* — cast when migrated */ INT pad_count; }; diff --git a/osprey/ipa/common/ipc_daVinci.cxx b/osprey/ipa/common/ipc_daVinci.cxx index 4aa3c0ca..4e6da79d 100644 --- a/osprey/ipa/common/ipc_daVinci.cxx +++ b/osprey/ipa/common/ipc_daVinci.cxx @@ -82,7 +82,7 @@ #include "ipa_option.h" // for IPA_Enable_daVinci #include "ipc_daVinci.h" -daVinci *cg_display = 0; +// cg_display migrated to g_ipa_ctx->visualization.cg_display (ipa_context.h). daVinci::daVinci (GRAPH *_g, MEM_POOL *_m) { diff --git a/osprey/ipa/common/ipc_daVinci.h b/osprey/ipa/common/ipc_daVinci.h index b7feec57..4a9089c9 100644 --- a/osprey/ipa/common/ipc_daVinci.h +++ b/osprey/ipa/common/ipc_daVinci.h @@ -88,6 +88,10 @@ class daVinci { }; // daVinci -extern daVinci *cg_display; +// cg_display now lives in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define cg_display (g_ipa_ctx->visualization.cg_display) #endif /* ipc_daVinci_INCLUDED */ diff --git a/osprey/ipa/main/analyze/ipa_chg.cxx b/osprey/ipa/main/analyze/ipa_chg.cxx index be34b7a8..c878c429 100644 --- a/osprey/ipa/main/analyze/ipa_chg.cxx +++ b/osprey/ipa/main/analyze/ipa_chg.cxx @@ -29,7 +29,7 @@ #include "ipa_chg.h" -IPA_CLASS_HIERARCHY *IPA_Class_Hierarchy; +// IPA_Class_Hierarchy migrated to g_ipa_ctx->chg.class_hierarchy (ipa_context.h). IPA_CLASS_HIERARCHY::IPA_CLASS_HIERARCHY() { } diff --git a/osprey/ipa/main/analyze/ipa_chg.h b/osprey/ipa/main/analyze/ipa_chg.h index 1084c1dc..25aea4b2 100644 --- a/osprey/ipa/main/analyze/ipa_chg.h +++ b/osprey/ipa/main/analyze/ipa_chg.h @@ -145,8 +145,11 @@ class IPA_CLASS_HIERARCHY { CLASS_RELATIONSHIP virtual_bases; }; -// Global class hierarchy graph -extern IPA_CLASS_HIERARCHY* IPA_Class_Hierarchy; +// IPA_Class_Hierarchy now lives in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPA_Class_Hierarchy (g_ipa_ctx->chg.class_hierarchy) // Build the global class hierarchy graph extern IPA_CLASS_HIERARCHY* Build_Class_Hierarchy(); diff --git a/osprey/ipa/main/analyze/ipa_pcg.cxx b/osprey/ipa/main/analyze/ipa_pcg.cxx index 4d5064c2..83dcabd3 100644 --- a/osprey/ipa/main/analyze/ipa_pcg.cxx +++ b/osprey/ipa/main/analyze/ipa_pcg.cxx @@ -959,4 +959,4 @@ IPA_PCG::Get_siloed_references(IPA_NODE *ipa_node) const return cit->second->_siloed_ref_set; } -IPA_PCG *IPA_Concurrency_Graph = NULL; +// IPA_Concurrency_Graph migrated to g_ipa_ctx->chg.concurrency_graph (ipa_context.h). diff --git a/osprey/ipa/main/analyze/ipa_pcg.h b/osprey/ipa/main/analyze/ipa_pcg.h index f46ea058..16f504dd 100644 --- a/osprey/ipa/main/analyze/ipa_pcg.h +++ b/osprey/ipa/main/analyze/ipa_pcg.h @@ -94,6 +94,10 @@ class IPA_PCG { void Print(FILE *fout = stderr); }; -extern IPA_PCG *IPA_Concurrency_Graph; +// IPA_Concurrency_Graph now lives in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPA_Concurrency_Graph (g_ipa_ctx->chg.concurrency_graph) #endif // ipa_pcg_INCLUDED diff --git a/osprey/ipa/main/analyze/ipa_reorder.cxx b/osprey/ipa/main/analyze/ipa_reorder.cxx index ec93cc02..f1de8873 100644 --- a/osprey/ipa/main/analyze/ipa_reorder.cxx +++ b/osprey/ipa/main/analyze/ipa_reorder.cxx @@ -77,7 +77,10 @@ struct PTR_AND_TY typedef vector PTR_AND_TY_VECTOR; extern TY_TO_CAND_MAP Ty_to_cand_map; //used by WN's modification -REORDER_CAND reorder_candidate; //identical in size with can_be_reorder_types +// reorder_candidate, merged_access, reorder_local_pool migrated to +// g_ipa_ctx->reorder (ipa_context.h). +static REORDER_CAND _reorder_candidate_storage; + TYPE_LIST can_be_reordered_types; TYPE_LIST invalid_reorder_types; //what cannot be reordered //sometimes, above list maybe large, eg 200, Perhaps we need a hash-map @@ -85,9 +88,6 @@ TY_TO_CAND_MAP Ty_to_cand_map; PTR_AND_TY_VECTOR *Ptr_and_ty_vector; //for each struct_ty, there maybe more than one pointer-types //Some having names, one of them is anonymous. - -MERGED_ACCESS_VECTOR *merged_access; -MEM_POOL reorder_local_pool; typedef hash_map TY_TO_ACCESS_MAP; TY_TO_ACCESS_MAP *ty_to_access_map; //for Record_struct_access in template.h BOOL* visited; @@ -111,6 +111,7 @@ TY_POINT_TO_NON_UNIONSTRUCT(TY &ty) /*-----------------------------------------------*/ void Init_merge_access() { + g_ipa_ctx->reorder.candidate_ptr = &_reorder_candidate_storage; MEM_POOL_Initialize(&reorder_local_pool,"reorder_pool",TRUE); MEM_POOL_Push (&reorder_local_pool); merged_access=CXX_NEW(vector< MERGED_ACCESS*>,&reorder_local_pool); diff --git a/osprey/ipa/main/analyze/ipa_reorder.h b/osprey/ipa/main/analyze/ipa_reorder.h index 8f9c2c0b..69fd9a7b 100644 --- a/osprey/ipa/main/analyze/ipa_reorder.h +++ b/osprey/ipa/main/analyze/ipa_reorder.h @@ -100,9 +100,13 @@ struct MERGED_ACCESS{ }; typedef vector< struct MERGED_ACCESS*> MERGED_ACCESS_VECTOR; -extern MERGED_ACCESS_VECTOR *merged_access; -extern MEM_POOL reorder_local_pool; -extern REORDER_CAND reorder_candidate; //identical in size with can_be_reorder_types +// Reorder globals now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define merged_access (g_ipa_ctx->reorder.merged_access) +#define reorder_local_pool (g_ipa_ctx->reorder.local_pool) +#define reorder_candidate (*g_ipa_ctx->reorder.candidate_ptr) class SUMMARY_STRUCT_ACCESS; extern diff --git a/osprey/ipa/main/analyze/ipa_section_prop.cxx b/osprey/ipa/main/analyze/ipa_section_prop.cxx index 53d98504..5d4729a7 100644 --- a/osprey/ipa/main/analyze/ipa_section_prop.cxx +++ b/osprey/ipa/main/analyze/ipa_section_prop.cxx @@ -72,8 +72,8 @@ #include "ipa_lno_util.h" // Utility routines #include "ipa_cost.h" // Execution cost analysis -MEM_POOL IPA_array_prop_pool; -BOOL Trace_IPA_Sections = FALSE; +// IPA_array_prop_pool and Trace_IPA_Sections migrated to +// g_ipa_ctx->array_section (ipa_context.h). static BOOL IPA_array_prop_pool_initialized = FALSE; diff --git a/osprey/ipa/main/analyze/ipa_section_prop.h b/osprey/ipa/main/analyze/ipa_section_prop.h index 2ace5c63..b87a85f7 100644 --- a/osprey/ipa/main/analyze/ipa_section_prop.h +++ b/osprey/ipa/main/analyze/ipa_section_prop.h @@ -42,8 +42,12 @@ #ifndef cxx_ipa_section_prop_INCLUDED #define cxx_ipa_section_prop_INCLUDED -extern MEM_POOL IPA_array_prop_pool; -extern BOOL Trace_IPA_Sections; +// Array-section globals now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPA_array_prop_pool (g_ipa_ctx->array_section.array_prop_pool) +#define Trace_IPA_Sections (g_ipa_ctx->array_section.trace_ipa_sections) //------------------------------------------------------------ // DESCR: perform scalar EUSE and KILL analysis From cfb9cfa83a9afc115b994794ca2dfdac181805bc Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Mon, 2 Mar 2026 21:41:52 -0800 Subject: [PATCH 05/10] Migrate common-block globals to IPA_Context Replace IPO_Pad_Count and IPA_Common_Table externs in ipa_pad.h with #define macros to g_ipa_ctx->common.* IPA_Common_Table uses void* in the context struct (COMMON_SNODE_TBL is a typedef, not forward-declarable) with lvalue-safe pointer cast: *(COMMON_SNODE_TBL**)&(g_ipa_ctx->common.common_table) Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/main/analyze/ipa_pad.cxx | 4 ++-- osprey/ipa/main/analyze/ipa_pad.h | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/osprey/ipa/main/analyze/ipa_pad.cxx b/osprey/ipa/main/analyze/ipa_pad.cxx index 5c0666a1..a53945df 100644 --- a/osprey/ipa/main/analyze/ipa_pad.cxx +++ b/osprey/ipa/main/analyze/ipa_pad.cxx @@ -71,8 +71,8 @@ #include "ipa_pad.h" #define MAX_ALIGN 16 -INT IPO_Pad_Count = 0; -COMMON_SNODE_TBL* IPA_Common_Table = NULL; +// IPO_Pad_Count and IPA_Common_Table migrated to +// g_ipa_ctx->common (ipa_context.h). static MEM_POOL IPA_Pad_Split_Mem_Pool; static BOOL trace_split_common = FALSE; diff --git a/osprey/ipa/main/analyze/ipa_pad.h b/osprey/ipa/main/analyze/ipa_pad.h index 78c61a4c..a17d49d3 100644 --- a/osprey/ipa/main/analyze/ipa_pad.h +++ b/osprey/ipa/main/analyze/ipa_pad.h @@ -244,8 +244,11 @@ Common_Array_Pad_Size(INT); extern void Padding_Analysis (INT num_ir); -extern INT IPO_Pad_Count; - -extern COMMON_SNODE_TBL* IPA_Common_Table; +// Common-block globals now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPO_Pad_Count (g_ipa_ctx->common.pad_count) +#define IPA_Common_Table (*(COMMON_SNODE_TBL**)&(g_ipa_ctx->common.common_table)) #endif /* ipa_pad_INCLUDED */ From b73dab6b44ca9d8bd9911c1317225b123c5a009e Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Tue, 3 Mar 2026 07:16:31 -0800 Subject: [PATCH 06/10] Migrate inline stats and cprop globals to IPA_Context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step 11: Migrate inline statistics across ipa_inline.h and ipa_cg.h: - Total_Prog_Size, Total_Inlined, Total_Not_Inlined - Orig_Prog_Weight, Total_Dead_Function_Weight - Orig_Prog_WN_Count, Prog_WN_Count, Total_Dead_Function_WN_Count - Total_call_freq, Total_cycle_count, Total_cycle_count_2 - Total_Must_Inlined, Total_Must_Not_Inlined - IPA_Graph_Undirected → g_ipa_ctx->graph_undirected Step 12: Migrate cprop state from ipa_cprop.h: - Ipa_cprop_pool, local_cprop_pool, Global_mem_pool - IPA_Constant_Count, IPA_Max_Total_Clones, IPA_Num_Total_Clones Add ipa_context.cxx to inline and lw_inline Makefiles so g_ipa_ctx symbol is available. Guard IPA_Options_Init with IPA_CONTEXT_FULL_INIT (defined only in main IPA target) since inline/lw_inline don't link config_ipa.cxx. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.cxx | 27 ++++++++++++++------ osprey/ipa/common/ipa_context.h | 7 ------ osprey/ipa/inline/Makefile.gbase | 1 + osprey/ipa/lw_inline/Makefile.gbase | 1 + osprey/ipa/main/Makefile.gbase | 2 +- osprey/ipa/main/analyze/ipa_cg.cxx | 27 +++----------------- osprey/ipa/main/analyze/ipa_cg.h | 28 +++++++++++---------- osprey/ipa/main/analyze/ipa_cprop.cxx | 7 +----- osprey/ipa/main/analyze/ipa_cprop.h | 16 +++++++----- osprey/ipa/main/analyze/ipa_cprop_annot.cxx | 3 +-- osprey/ipa/main/analyze/ipa_inline.cxx | 5 ++-- osprey/ipa/main/analyze/ipa_inline.h | 12 +++++---- 12 files changed, 61 insertions(+), 75 deletions(-) diff --git a/osprey/ipa/common/ipa_context.cxx b/osprey/ipa/common/ipa_context.cxx index 2c127e52..008a46aa 100644 --- a/osprey/ipa/common/ipa_context.cxx +++ b/osprey/ipa/common/ipa_context.cxx @@ -1,24 +1,33 @@ /* + * IPA Context — transitional global definitions and lifecycle functions. * - * IPA Context — initialization and cleanup. - * - * These functions exist but are NOT called by any existing code — zero behavior - * change. They populate the new structs FROM the existing globals so that - * later steps can incrementally switch readers to use the context. + * This file is compiled by all IPA-family targets (ipa, inline, lw_inline). + * The IPA_Options_Init function uses config_ipa.h globals which are only + * available in the main IPA target, so it's guarded by IPA_CONTEXT_FULL_INIT. */ #include "ipa_context.h" -#include "ipa_options.h" -#include "config_ipa.h" /* all the IPA_Enable_* / INLINE_* globals */ #include /* memset */ #include /* malloc, free */ /* ==================================================================== - * Transitional globals + * Transitional globals — needed by all IPA-family targets. * ==================================================================== */ IPA_Context *g_ipa_ctx = NULL; + + +/* + * The full init/fini functions are only available in the main IPA target + * where config_ipa.h globals are linked in. The inline and lw_inline + * targets just need the g_ipa_ctx symbol for the macro-based accessors. + */ +#ifdef IPA_CONTEXT_FULL_INIT + +#include "ipa_options.h" +#include "config_ipa.h" /* all the IPA_Enable_* / INLINE_* globals */ + const IPA_Options *g_ipa_options = NULL; /* Internal mutable copy that g_ipa_options points to */ @@ -275,3 +284,5 @@ IPA_Context_Fini(void) g_ipa_ctx = NULL; } } + +#endif /* IPA_CONTEXT_FULL_INIT */ diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h index 38859b90..20ab8211 100644 --- a/osprey/ipa/common/ipa_context.h +++ b/osprey/ipa/common/ipa_context.h @@ -113,14 +113,7 @@ struct IPA_Inline_Stats { FB_FREQ total_call_freq; FB_FREQ total_cycle_count; -#ifdef KEY FB_FREQ total_cycle_count_2; -#endif - - FILE *n_inlining; /* trace: not-inlined decisions */ - FILE *y_inlining; /* trace: inlined decisions */ - FILE *e_weight; /* trace: edge weights */ - FILE *verbose_inlining; /* trace: verbose output */ }; /* --- Constant propagation state (ipa_cprop.h) --- */ diff --git a/osprey/ipa/inline/Makefile.gbase b/osprey/ipa/inline/Makefile.gbase index dfb26e31..bbb218e7 100644 --- a/osprey/ipa/inline/Makefile.gbase +++ b/osprey/ipa/inline/Makefile.gbase @@ -169,6 +169,7 @@ IPA_COMMON_CXX_SRCS = \ ipc_bread.cxx \ ipc_file.cxx \ ip_graph.cxx \ + ipa_context.cxx \ ipc_symtab_merge.cxx \ ipc_symtab.cxx \ ipc_type_merge.cxx \ diff --git a/osprey/ipa/lw_inline/Makefile.gbase b/osprey/ipa/lw_inline/Makefile.gbase index e2a1cbb7..a7e74e71 100644 --- a/osprey/ipa/lw_inline/Makefile.gbase +++ b/osprey/ipa/lw_inline/Makefile.gbase @@ -177,6 +177,7 @@ IPA_COMMON_CXX_SRCS = \ ipc_bread.cxx \ ipc_file.cxx \ ip_graph.cxx \ + ipa_context.cxx \ ipc_option.cxx \ ipc_utils.cxx \ ipc_dst_utils.cxx \ diff --git a/osprey/ipa/main/Makefile.gbase b/osprey/ipa/main/Makefile.gbase index e8c85b67..350179a9 100644 --- a/osprey/ipa/main/Makefile.gbase +++ b/osprey/ipa/main/Makefile.gbase @@ -290,7 +290,7 @@ LCINCS = $(addprefix -I, $(HEADER_DIRS)) LCDEFS += $(HOSTDEFS) LCDEFS += -DSTD_MONGOOSE_LOC='"$(STD_MONGOOSE_LOC)"' -D_SUPPORT_IPA -D_MULTIGOT LC++DEFS += $(HOSTDEFS) -DSTD_MONGOOSE_LOC='"$(STD_MONGOOSE_LOC)"' -LC++DEFS += -D_SUPPORT_IPA -DMONGOOSE_BE +LC++DEFS += -D_SUPPORT_IPA -DMONGOOSE_BE -DIPA_CONTEXT_FULL_INIT #-DIPA_CPROP_TEST LC++INCS = $(LCINCS) diff --git a/osprey/ipa/main/analyze/ipa_cg.cxx b/osprey/ipa/main/analyze/ipa_cg.cxx index bd67de24..8a21905e 100644 --- a/osprey/ipa/main/analyze/ipa_cg.cxx +++ b/osprey/ipa/main/analyze/ipa_cg.cxx @@ -121,8 +121,7 @@ IPA_CALL_GRAPH* IPA_Call_Graph; // "The" call graph of IPA #ifdef KEY -// Temporary graph built for pu-reordering based on edge frequencies. -IPA_CALL_GRAPH* IPA_Graph_Undirected; +// IPA_Graph_Undirected migrated to g_ipa_ctx->graph_undirected (ipa_context.h). // IPA_Call_Graph is a global variable used widely, even in member functions // of IPA_CALL_GRAPH (where it is appropriate to either use 'this' or // nothing). Building another call graph (IPA_Graph_Undirected) becomes @@ -141,28 +140,8 @@ BOOL IPA_Call_Graph_Built = FALSE; typedef hash_map ALT_ENTRY_MAP; ALT_ENTRY_MAP *alt_entry_map; // map from alt entry to base entry -UINT32 Total_Dead_Function_Weight = 0; -UINT32 Orig_Prog_Weight = 0; - -//INLINING_TUNING^ -UINT32 Orig_Prog_WN_Count = 0; -UINT32 Total_Dead_Function_WN_Count = 0; -#ifdef KEY -FB_FREQ Total_cycle_count_2(0.0); -#else -FB_FREQ Total_cycle_count_2(0); -#endif -//INLINING_TUNING$ - -INT Total_Must_Inlined = 0; -INT Total_Must_Not_Inlined = 0; -#ifdef KEY -FB_FREQ Total_call_freq(0.0); -FB_FREQ Total_cycle_count(0.0); -#else -FB_FREQ Total_call_freq(0); -FB_FREQ Total_cycle_count(0); -#endif +// Inline stats globals migrated to g_ipa_ctx->inline_stats (ipa_context.h). +// Zero-init via IPA_Context_Init provides equivalent defaults. //----------------------------------------------------------------------- // NAME: Main_Entry diff --git a/osprey/ipa/main/analyze/ipa_cg.h b/osprey/ipa/main/analyze/ipa_cg.h index d99991ef..da6bd2e8 100644 --- a/osprey/ipa/main/analyze/ipa_cg.h +++ b/osprey/ipa/main/analyze/ipa_cg.h @@ -1270,16 +1270,18 @@ extern BOOL IPA_Call_Graph_Built; extern void IPA_Process_File (IP_FILE_HDR& hdr); extern void Build_Call_Graph (); #ifdef KEY -extern IPA_CALL_GRAPH *IPA_Graph_Undirected; +#define IPA_Graph_Undirected (g_ipa_ctx->graph_undirected) extern void IPA_Convert_Icalls( IPA_CALL_GRAPH* ); #endif -//INLINING_TUNING^ -extern UINT32 Orig_Prog_WN_Count; -extern UINT32 Prog_WN_Count; -extern UINT32 Total_Dead_Function_WN_Count; -extern FB_FREQ Total_cycle_count_2; -//INLINING_TUNING$ +//INLINING_TUNING — these globals now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define Orig_Prog_WN_Count (g_ipa_ctx->inline_stats.orig_prog_wn_count) +#define Prog_WN_Count (g_ipa_ctx->inline_stats.prog_wn_count) +#define Total_Dead_Function_WN_Count (g_ipa_ctx->inline_stats.total_dead_function_wn_count) +#define Total_cycle_count_2 (g_ipa_ctx->inline_stats.total_cycle_count_2) // ==================================================================== // @@ -1418,14 +1420,14 @@ class AUX_IPA_NODE // // ==================================================================== -extern UINT32 Total_Dead_Function_Weight; -extern UINT32 Orig_Prog_Weight; +#define Total_Dead_Function_Weight (g_ipa_ctx->inline_stats.total_dead_function_weight) +#define Orig_Prog_Weight (g_ipa_ctx->inline_stats.orig_prog_weight) -extern FB_FREQ Total_call_freq; -extern FB_FREQ Total_cycle_count; +#define Total_call_freq (g_ipa_ctx->inline_stats.total_call_freq) +#define Total_cycle_count (g_ipa_ctx->inline_stats.total_cycle_count) -extern INT Total_Must_Inlined; -extern INT Total_Must_Not_Inlined; +#define Total_Must_Inlined (g_ipa_ctx->inline_stats.total_must_inlined) +#define Total_Must_Not_Inlined (g_ipa_ctx->inline_stats.total_must_not_inlined) // Given a pu, get its corresponding call graph node. diff --git a/osprey/ipa/main/analyze/ipa_cprop.cxx b/osprey/ipa/main/analyze/ipa_cprop.cxx index bf8bd16e..7a21b92d 100644 --- a/osprey/ipa/main/analyze/ipa_cprop.cxx +++ b/osprey/ipa/main/analyze/ipa_cprop.cxx @@ -79,12 +79,7 @@ #include "ipa_option.h" // IPA_TRACE flags #include "ipa_summary.h" // IPA_get_ functions -// Maximum and count for the total number of clone nodes -UINT32 IPA_Max_Total_Clones; -UINT32 IPA_Num_Total_Clones = 0; - -INT IPA_Constant_Count = 0; // number of constants found -MEM_POOL Global_mem_pool; +// Cprop globals migrated to g_ipa_ctx->cprop (ipa_context.h). static void diff --git a/osprey/ipa/main/analyze/ipa_cprop.h b/osprey/ipa/main/analyze/ipa_cprop.h index 9a905a0a..09b11679 100644 --- a/osprey/ipa/main/analyze/ipa_cprop.h +++ b/osprey/ipa/main/analyze/ipa_cprop.h @@ -54,16 +54,20 @@ #include "ipa_df.h" #endif -extern INT IPA_Constant_Count; +// Cprop globals now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPA_Constant_Count (g_ipa_ctx->cprop.constant_count) extern void Init_Cprop_Annotations (IPA_NODE *); -extern MEM_POOL Ipa_cprop_pool; -extern MEM_POOL local_cprop_pool; -extern MEM_POOL Global_mem_pool; +#define Ipa_cprop_pool (g_ipa_ctx->cprop.cprop_pool) +#define local_cprop_pool (g_ipa_ctx->cprop.local_pool) +#define Global_mem_pool (g_ipa_ctx->cprop.global_pool) // Maximum and count for the total number of clone nodes -extern UINT32 IPA_Max_Total_Clones; -extern UINT32 IPA_Num_Total_Clones; +#define IPA_Max_Total_Clones (g_ipa_ctx->cprop.max_total_clones) +#define IPA_Num_Total_Clones (g_ipa_ctx->cprop.num_total_clones) typedef DYN_ARRAY VALUE_DYN_ARRAY; diff --git a/osprey/ipa/main/analyze/ipa_cprop_annot.cxx b/osprey/ipa/main/analyze/ipa_cprop_annot.cxx index 171ebb22..cb8a3d5f 100644 --- a/osprey/ipa/main/analyze/ipa_cprop_annot.cxx +++ b/osprey/ipa/main/analyze/ipa_cprop_annot.cxx @@ -76,8 +76,7 @@ enum CONDITION_STATE { CONDITION_STATE *cd_status; // status of all conditional stmts // in a PU -MEM_POOL Ipa_cprop_pool; // mem pool for expression evaluations -MEM_POOL local_cprop_pool; +// Ipa_cprop_pool and local_cprop_pool migrated to g_ipa_ctx->cprop (ipa_context.h). // used in Evaluate_chi, which needs the caller's IPA_NODE for mapping a // callsite id to callee. diff --git a/osprey/ipa/main/analyze/ipa_inline.cxx b/osprey/ipa/main/analyze/ipa_inline.cxx index 5c908a8b..0357e39b 100644 --- a/osprey/ipa/main/analyze/ipa_inline.cxx +++ b/osprey/ipa/main/analyze/ipa_inline.cxx @@ -93,9 +93,8 @@ //INLINING_TUNIN$ #define TINY_SIZE 10 -INT Total_Prog_Size = 0; // Size of the final program -INT Total_Inlined = 0; -INT Total_Not_Inlined = 0; +// Total_Prog_Size, Total_Inlined, Total_Not_Inlined migrated to +// g_ipa_ctx->inline_stats (ipa_context.h). static UINT32 Max_Total_Prog_Size; // max. program size allowed static INT Real_Orig_Prog_Weight; // Orig_Prog_Weight - dead code static UINT32 non_aggr_callee_limit; diff --git a/osprey/ipa/main/analyze/ipa_inline.h b/osprey/ipa/main/analyze/ipa_inline.h index 76b311eb..6f4d5d31 100644 --- a/osprey/ipa/main/analyze/ipa_inline.h +++ b/osprey/ipa/main/analyze/ipa_inline.h @@ -54,11 +54,13 @@ #endif #include -extern INT Total_Prog_Size; // size of the final program - -extern INT Total_Inlined; - -extern INT Total_Not_Inlined; +// Inline stats now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define Total_Prog_Size (g_ipa_ctx->inline_stats.total_prog_size) +#define Total_Inlined (g_ipa_ctx->inline_stats.total_inlined) +#define Total_Not_Inlined (g_ipa_ctx->inline_stats.total_not_inlined) /* Report the reason for not inlining a call: */ extern void From fca94d8810f724a813efc7325d1345e7a9da0aa4 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Tue, 3 Mar 2026 07:16:57 -0800 Subject: [PATCH 07/10] Rename IPA_Options fields to begin with lowercase Address review feedback: all member fields in struct definitions should begin with a lowercase character. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.cxx | 334 ++++++++++++++--------------- osprey/ipa/common/ipa_context.h | 1 - osprey/ipa/common/ipa_options.h | 340 +++++++++++++++--------------- 3 files changed, 336 insertions(+), 339 deletions(-) diff --git a/osprey/ipa/common/ipa_context.cxx b/osprey/ipa/common/ipa_context.cxx index 008a46aa..7c209c6a 100644 --- a/osprey/ipa/common/ipa_context.cxx +++ b/osprey/ipa/common/ipa_context.cxx @@ -50,199 +50,199 @@ IPA_Options_Init(void) IPA_Options *o = ipa_options_mutable; /* --- Filenames --- */ - o->Feedback_Filename = Feedback_Filename; - o->Annotation_Filename = Annotation_Filename; + o->feedback_Filename = Feedback_Filename; + o->annotation_Filename = Annotation_Filename; /* --- Feature enable flags --- */ - o->Enable_DFE = IPA_Enable_DFE; - o->Enable_DFE_Set = IPA_Enable_DFE_Set; - o->Enable_Inline = IPA_Enable_Inline; - o->Enable_Picopt = IPA_Enable_Picopt; - o->Enable_AutoGnum = IPA_Enable_AutoGnum; - o->Enable_BarrierFarg = IPA_Enable_BarrierFarg; - o->Enable_Opt_Alias = IPA_Enable_Opt_Alias; - o->Enable_Simple_Alias = IPA_Enable_Simple_Alias; - o->Enable_Addressing = IPA_Enable_Addressing; - o->Enable_Readonly_Ref = IPA_Enable_Readonly_Ref; - o->Enable_Cprop = IPA_Enable_Cprop; - o->Enable_Cprop2 = IPA_Enable_Cprop2; - o->Enable_Assert = IPA_Enable_Assert; - o->Enable_daVinci = IPA_Enable_daVinci; - o->Enable_ipacom = IPA_Enable_ipacom; - o->Enable_final_link = IPA_Enable_final_link; - o->Enable_Memtrace = IPA_Enable_Memtrace; - o->Enable_DST = IPA_Enable_DST; - o->Enable_DCE = IPA_Enable_DCE; - o->Enable_Exc = IPA_Enable_Exc; - o->Enable_Recycle = IPA_Enable_Recycle; - o->Enable_DVE = IPA_Enable_DVE; - o->Enable_CGI = IPA_Enable_CGI; - o->Enable_Copy_Prop = IPA_Enable_Copy_Prop; - o->Enable_Padding = IPA_Enable_Padding; - o->Common_Pad_Size = IPA_Common_Pad_Size; - o->Enable_Split_Common = IPA_Enable_Split_Common; - o->Enable_Cloning = IPA_Enable_Cloning; - o->Enable_Partial_Inline = IPA_Enable_Partial_Inline; - o->Echo_Commands = IPA_Echo_Commands; - o->Enable_Lang = IPA_Enable_Lang; - o->Enable_Preempt = IPA_Enable_Preempt; - o->Enable_Flow_Analysis = IPA_Enable_Flow_Analysis; - o->Enable_Array_Sections = IPA_Enable_Array_Sections; - o->Enable_Array_Summary = IPA_Enable_Array_Summary; - o->Enable_Scalar_Euse = IPA_Enable_Scalar_Euse; - o->Enable_Scalar_Kill = IPA_Enable_Scalar_Kill; - o->Enable_Common_Const = IPA_Enable_Common_Const; - o->Enable_Relocatable_Opt = IPA_Enable_Relocatable_Opt; - o->Enable_Feedback = IPA_Enable_Feedback; - o->Enable_Alias_Class = IPA_Enable_Alias_Class; - o->Debug_AC_Temp_Files = IPA_Debug_AC_Temp_Files; - o->Enable_Reshape = IPA_Enable_Reshape; - o->Enable_Preopt = IPA_Enable_Preopt; - o->Enable_Preopt_Set = IPA_Enable_Preopt_Set; - o->Enable_Siloed_Ref = IPA_Enable_Siloed_Ref; - o->Enable_Siloed_Ref_Set = IPA_Enable_Siloed_Ref_Set; + o->enable_DFE = IPA_Enable_DFE; + o->enable_DFE_Set = IPA_Enable_DFE_Set; + o->enable_Inline = IPA_Enable_Inline; + o->enable_Picopt = IPA_Enable_Picopt; + o->enable_AutoGnum = IPA_Enable_AutoGnum; + o->enable_BarrierFarg = IPA_Enable_BarrierFarg; + o->enable_Opt_Alias = IPA_Enable_Opt_Alias; + o->enable_Simple_Alias = IPA_Enable_Simple_Alias; + o->enable_Addressing = IPA_Enable_Addressing; + o->enable_Readonly_Ref = IPA_Enable_Readonly_Ref; + o->enable_Cprop = IPA_Enable_Cprop; + o->enable_Cprop2 = IPA_Enable_Cprop2; + o->enable_Assert = IPA_Enable_Assert; + o->enable_daVinci = IPA_Enable_daVinci; + o->enable_ipacom = IPA_Enable_ipacom; + o->enable_final_link = IPA_Enable_final_link; + o->enable_Memtrace = IPA_Enable_Memtrace; + o->enable_DST = IPA_Enable_DST; + o->enable_DCE = IPA_Enable_DCE; + o->enable_Exc = IPA_Enable_Exc; + o->enable_Recycle = IPA_Enable_Recycle; + o->enable_DVE = IPA_Enable_DVE; + o->enable_CGI = IPA_Enable_CGI; + o->enable_Copy_Prop = IPA_Enable_Copy_Prop; + o->enable_Padding = IPA_Enable_Padding; + o->common_Pad_Size = IPA_Common_Pad_Size; + o->enable_Split_Common = IPA_Enable_Split_Common; + o->enable_Cloning = IPA_Enable_Cloning; + o->enable_Partial_Inline = IPA_Enable_Partial_Inline; + o->echo_Commands = IPA_Echo_Commands; + o->enable_Lang = IPA_Enable_Lang; + o->enable_Preempt = IPA_Enable_Preempt; + o->enable_Flow_Analysis = IPA_Enable_Flow_Analysis; + o->enable_Array_Sections = IPA_Enable_Array_Sections; + o->enable_Array_Summary = IPA_Enable_Array_Summary; + o->enable_Scalar_Euse = IPA_Enable_Scalar_Euse; + o->enable_Scalar_Kill = IPA_Enable_Scalar_Kill; + o->enable_Common_Const = IPA_Enable_Common_Const; + o->enable_Relocatable_Opt = IPA_Enable_Relocatable_Opt; + o->enable_Feedback = IPA_Enable_Feedback; + o->enable_Alias_Class = IPA_Enable_Alias_Class; + o->debug_AC_Temp_Files = IPA_Debug_AC_Temp_Files; + o->enable_Reshape = IPA_Enable_Reshape; + o->enable_Preopt = IPA_Enable_Preopt; + o->enable_Preopt_Set = IPA_Enable_Preopt_Set; + o->enable_Siloed_Ref = IPA_Enable_Siloed_Ref; + o->enable_Siloed_Ref_Set = IPA_Enable_Siloed_Ref_Set; #ifdef KEY - o->Enable_Icall_Opt = IPA_Enable_Icall_Opt; - o->Enable_EH_Region_Removal = IPA_Enable_EH_Region_Removal; - o->Enable_Branch_Heuristic = IPA_Enable_Branch_Heuristic; - o->Min_Branch_Prob = IPA_Min_Branch_Prob; - o->Check_Options = IPA_Check_Options; - o->Clone_List_Actions = IPA_Clone_List_Actions; - o->Enable_Pure_Call_Opt = IPA_Enable_Pure_Call_Opt; - o->Pure_Call_skip_before = IPA_Pure_Call_skip_before; - o->Consult_Inliner_For_Icall_Opt = IPA_Consult_Inliner_For_Icall_Opt; - o->Icall_Min_Freq = IPA_Icall_Min_Freq; - o->Enable_Source_PU_Order = IPA_Enable_Source_PU_Order; - o->Enable_Struct_Opt = IPA_Enable_Struct_Opt; - o->Enable_Global_As_Local = IPA_Enable_Global_As_Local; - o->Update_Struct = IPA_Update_Struct; + o->enable_Icall_Opt = IPA_Enable_Icall_Opt; + o->enable_EH_Region_Removal = IPA_Enable_EH_Region_Removal; + o->enable_Branch_Heuristic = IPA_Enable_Branch_Heuristic; + o->min_Branch_Prob = IPA_Min_Branch_Prob; + o->check_Options = IPA_Check_Options; + o->clone_List_Actions = IPA_Clone_List_Actions; + o->enable_Pure_Call_Opt = IPA_Enable_Pure_Call_Opt; + o->pure_Call_skip_before = IPA_Pure_Call_skip_before; + o->consult_Inliner_For_Icall_Opt = IPA_Consult_Inliner_For_Icall_Opt; + o->icall_Min_Freq = IPA_Icall_Min_Freq; + o->enable_Source_PU_Order = IPA_Enable_Source_PU_Order; + o->enable_Struct_Opt = IPA_Enable_Struct_Opt; + o->enable_Global_As_Local = IPA_Enable_Global_As_Local; + o->update_Struct = IPA_Update_Struct; #endif - o->Icall_Target_Min_Rate = IPA_Icall_Target_Min_Rate; + o->icall_Target_Min_Rate = IPA_Icall_Target_Min_Rate; /* --- Inlining heuristics --- */ - o->Bloat_Factor = IPA_Bloat_Factor; - o->Bloat_Factor_Set = IPA_Bloat_Factor_Set; - o->PU_Limit = IPA_PU_Limit; - o->PU_Limit_Set = IPA_PU_Limit_Set; - o->PU_Hard_Limit = IPA_PU_Hard_Limit; - o->PU_Hard_Limit_Set = IPA_PU_Hard_Limit_Set; - o->PU_Minimum_Size = IPA_PU_Minimum_Size; - o->Small_Callee_Limit = IPA_Small_Callee_Limit; - o->Max_Depth = IPA_Max_Depth; - o->Force_Depth = IPA_Force_Depth; - o->Force_Depth_Set = IPA_Force_Depth_Set; - o->Min_Freq = IPA_Min_Freq; - o->Rela_Freq = IPA_Rela_Freq; - o->Min_Hotness = IPA_Min_Hotness; - o->Use_Effective_Size = IPA_Use_Effective_Size; + o->bloat_Factor = IPA_Bloat_Factor; + o->bloat_Factor_Set = IPA_Bloat_Factor_Set; + o->pU_Limit = IPA_PU_Limit; + o->pU_Limit_Set = IPA_PU_Limit_Set; + o->pU_Hard_Limit = IPA_PU_Hard_Limit; + o->pU_Hard_Limit_Set = IPA_PU_Hard_Limit_Set; + o->pU_Minimum_Size = IPA_PU_Minimum_Size; + o->small_Callee_Limit = IPA_Small_Callee_Limit; + o->max_Depth = IPA_Max_Depth; + o->force_Depth = IPA_Force_Depth; + o->force_Depth_Set = IPA_Force_Depth_Set; + o->min_Freq = IPA_Min_Freq; + o->rela_Freq = IPA_Rela_Freq; + o->min_Hotness = IPA_Min_Hotness; + o->use_Effective_Size = IPA_Use_Effective_Size; /* --- Miscellaneous --- */ - o->Enable_Merge_ty = IPA_Enable_Merge_ty; - o->Max_Jobs = IPA_Max_Jobs; - o->Max_Jobs_Set = IPA_Max_Jobs_Set; - o->Gspace = IPA_Gspace; + o->enable_Merge_ty = IPA_Enable_Merge_ty; + o->max_Jobs = IPA_Max_Jobs; + o->max_Jobs_Set = IPA_Max_Jobs_Set; + o->gspace = IPA_Gspace; o->user_gnum = IPA_user_gnum; - o->Extgot_Factor = IPA_Extgot_Factor; - o->Num_Fortran_Intrinsics = IPA_Num_Fortran_Intrinsics; - o->Has_Fortran = IPA_Has_Fortran; - o->Map_Limit = IPA_Map_Limit; - o->Enable_SP_Partition = IPA_Enable_SP_Partition; - o->Enable_GP_Partition = IPA_Enable_GP_Partition; - o->Space_Access_Mode = IPA_Space_Access_Mode; - o->Group_Names = IPA_Group_Names; - o->Spec_Files = IPA_Spec_Files; - o->Skip = IPA_Skip; - o->Skip_Report = IPA_Skip_Report; - o->Enable_Keeplight = IPA_Enable_Keeplight; - o->Enable_Cord = IPA_Enable_Cord; - o->Enable_Linearization = IPA_Enable_Linearization; - o->Use_Intrinsic = IPA_Use_Intrinsic; - o->Enable_Inline_Nested_PU = IPA_Enable_Inline_Nested_PU; - o->Enable_Inline_Struct = IPA_Enable_Inline_Struct; - o->Enable_Inline_Char_Array = IPA_Enable_Inline_Char_Array; - o->Enable_Inline_Optional_Arg = IPA_Enable_Inline_Optional_Arg; - o->Enable_Inline_Struct_Array_Actual = IPA_Enable_Inline_Struct_Array_Actual; - o->Enable_Inline_Var_Dim_Array = IPA_Enable_Inline_Var_Dim_Array; - o->Enable_Reorder = IPA_Enable_Reorder; - o->Enable_AOT = IPA_Enable_AOT; + o->extgot_Factor = IPA_Extgot_Factor; + o->num_Fortran_Intrinsics = IPA_Num_Fortran_Intrinsics; + o->has_Fortran = IPA_Has_Fortran; + o->map_Limit = IPA_Map_Limit; + o->enable_SP_Partition = IPA_Enable_SP_Partition; + o->enable_GP_Partition = IPA_Enable_GP_Partition; + o->space_Access_Mode = IPA_Space_Access_Mode; + o->group_Names = IPA_Group_Names; + o->spec_Files = IPA_Spec_Files; + o->skip = IPA_Skip; + o->skip_Report = IPA_Skip_Report; + o->enable_Keeplight = IPA_Enable_Keeplight; + o->enable_Cord = IPA_Enable_Cord; + o->enable_Linearization = IPA_Enable_Linearization; + o->use_Intrinsic = IPA_Use_Intrinsic; + o->enable_Inline_Nested_PU = IPA_Enable_Inline_Nested_PU; + o->enable_Inline_Struct = IPA_Enable_Inline_Struct; + o->enable_Inline_Char_Array = IPA_Enable_Inline_Char_Array; + o->enable_Inline_Optional_Arg = IPA_Enable_Inline_Optional_Arg; + o->enable_Inline_Struct_Array_Actual = IPA_Enable_Inline_Struct_Array_Actual; + o->enable_Inline_Var_Dim_Array = IPA_Enable_Inline_Var_Dim_Array; + o->enable_Reorder = IPA_Enable_Reorder; + o->enable_AOT = IPA_Enable_AOT; #ifdef KEY - o->Enable_PU_Reorder = (IPA_OPT_PU_REORDER_SCHEME) IPA_Enable_PU_Reorder; - o->Enable_PU_Reorder_Set = IPA_Enable_PU_Reorder_Set; - o->Enable_Ctype = IPA_Enable_Ctype; - o->Inline_Check_Compatibility = + o->enable_PU_Reorder = (IPA_OPT_PU_REORDER_SCHEME) IPA_Enable_PU_Reorder; + o->enable_PU_Reorder_Set = IPA_Enable_PU_Reorder_Set; + o->enable_Ctype = IPA_Enable_Ctype; + o->inline_Check_Compatibility = (IPA_OPT_CHECK_PARAM_COMPATIBILITY) INLINE_Check_Compatibility; #endif - o->Max_Node_Clones = IPA_Max_Node_Clones; - o->Max_Node_Clones_Set = IPA_Max_Node_Clones_Set; - o->Max_Clone_Bloat = IPA_Max_Clone_Bloat; - o->Max_Output_File_Size = IPA_Max_Output_File_Size; - o->Output_File_Size = IPA_Output_File_Size; - o->Max_Density = IPA_Max_Density; - o->Enable_Old_Type_Merge = IPA_Enable_Old_Type_Merge; + o->max_Node_Clones = IPA_Max_Node_Clones; + o->max_Node_Clones_Set = IPA_Max_Node_Clones_Set; + o->max_Clone_Bloat = IPA_Max_Clone_Bloat; + o->max_Output_File_Size = IPA_Max_Output_File_Size; + o->output_File_Size = IPA_Output_File_Size; + o->max_Density = IPA_Max_Density; + o->enable_Old_Type_Merge = IPA_Enable_Old_Type_Merge; /* --- Devirtualization --- */ - o->Enable_Devirtualization = IPA_Enable_Devirtualization; - o->Enable_Fast_Static_Analysis_VF = IPA_Enable_Fast_Static_Analysis_VF; - o->Enable_Original_VF = IPA_Enable_Original_VF; - o->Enable_New_VF = IPA_Enable_New_VF; - o->Inline_Original_VF = IPA_Inline_Original_VF; - o->Inline_New_VF = IPA_Inline_New_VF; - o->Devirtualization_Input_File = IPA_Devirtualization_Input_File; - o->During_Original_VF = IPA_During_Original_VF; - o->During_New_VF = IPA_During_New_VF; + o->enable_Devirtualization = IPA_Enable_Devirtualization; + o->enable_Fast_Static_Analysis_VF = IPA_Enable_Fast_Static_Analysis_VF; + o->enable_Original_VF = IPA_Enable_Original_VF; + o->enable_New_VF = IPA_Enable_New_VF; + o->inline_Original_VF = IPA_Inline_Original_VF; + o->inline_New_VF = IPA_Inline_New_VF; + o->devirtualization_Input_File = IPA_Devirtualization_Input_File; + o->during_Original_VF = IPA_During_Original_VF; + o->during_New_VF = IPA_During_New_VF; /* --- Whole program / scale --- */ - o->Enable_Whole_Program_Mode = IPA_Enable_Whole_Program_Mode; - o->Enable_Whole_Program_Mode_Set = IPA_Enable_Whole_Program_Mode_Set; - o->Enable_Scale = IPA_Enable_Scale; + o->enable_Whole_Program_Mode = IPA_Enable_Whole_Program_Mode; + o->enable_Whole_Program_Mode_Set = IPA_Enable_Whole_Program_Mode_Set; + o->enable_Scale = IPA_Enable_Scale; /* --- INLINE group options --- */ - o->Inline_Enable = INLINE_Enable; - o->Inline_All = INLINE_All; - o->Inline_Optimize_Alloca = INLINE_Optimize_Alloca; - o->Inline_Enable_Copy_Prop = INLINE_Enable_Copy_Prop; - o->Inline_Enable_Subst_Copy_Prop = INLINE_Enable_Subst_Copy_Prop; - o->Inline_F90 = INLINE_F90; - o->Inline_None = INLINE_None; - o->Inline_Exceptions = INLINE_Exceptions; - o->Inline_Keep_PU_Order = INLINE_Keep_PU_Order; - o->Inline_List_Actions = INLINE_List_Actions; - o->Inline_Max_Pu_Size = INLINE_Max_Pu_Size; - o->Inline_Preemptible = INLINE_Preemptible; - o->Inline_Static = INLINE_Static; - o->Inline_Static_Set = INLINE_Static_Set; - o->Inline_Aggressive = INLINE_Aggressive; - o->Inline_First_Inline_Calls_In_Loops = INLINE_First_Inline_Calls_In_Loops; - o->Inline_Enable_DFE = IPA_Enable_DFE; - o->Inline_Enable_Split_Common = INLINE_Enable_Split_Common; - o->Inline_Enable_Auto_Inlining = INLINE_Enable_Auto_Inlining; - o->Inline_Enable_Restrict_Pointers = INLINE_Enable_Restrict_Pointers; + o->inline_Enable = INLINE_Enable; + o->inline_All = INLINE_All; + o->inline_Optimize_Alloca = INLINE_Optimize_Alloca; + o->inline_Enable_Copy_Prop = INLINE_Enable_Copy_Prop; + o->inline_Enable_Subst_Copy_Prop = INLINE_Enable_Subst_Copy_Prop; + o->inline_F90 = INLINE_F90; + o->inline_None = INLINE_None; + o->inline_Exceptions = INLINE_Exceptions; + o->inline_Keep_PU_Order = INLINE_Keep_PU_Order; + o->inline_List_Actions = INLINE_List_Actions; + o->inline_Max_Pu_Size = INLINE_Max_Pu_Size; + o->inline_Preemptible = INLINE_Preemptible; + o->inline_Static = INLINE_Static; + o->inline_Static_Set = INLINE_Static_Set; + o->inline_Aggressive = INLINE_Aggressive; + o->inline_First_Inline_Calls_In_Loops = INLINE_First_Inline_Calls_In_Loops; + o->inline_Enable_DFE = IPA_Enable_DFE; /* source is IPA_, not INLINE_ */ + o->inline_Enable_Split_Common = INLINE_Enable_Split_Common; + o->inline_Enable_Auto_Inlining = INLINE_Enable_Auto_Inlining; + o->inline_Enable_Restrict_Pointers = INLINE_Enable_Restrict_Pointers; #ifdef KEY - o->Inline_Recursive = INLINE_Recursive; - o->Inline_Param_Mismatch = INLINE_Param_Mismatch; - o->Inline_Type_Mismatch = INLINE_Type_Mismatch; - o->Inline_Ignore_Bloat = INLINE_Ignore_Bloat; - o->Inline_Callee_Limit = INLINE_Callee_Limit; + o->inline_Recursive = INLINE_Recursive; + o->inline_Param_Mismatch = INLINE_Param_Mismatch; + o->inline_Type_Mismatch = INLINE_Type_Mismatch; + o->inline_Ignore_Bloat = INLINE_Ignore_Bloat; + o->inline_Callee_Limit = INLINE_Callee_Limit; #endif - o->Inline_List_Names = INLINE_List_Names; - o->Inline_Spec_Files = INLINE_Spec_Files; - o->Inline_Skip_After = INLINE_Skip_After; - o->Inline_Skip_Before = INLINE_Skip_Before; - o->Inline_Array_Bounds = INLINE_Array_Bounds; - o->Inline_Use_Malloc_Mempool = INLINE_Use_Malloc_Mempool; - o->Inline_Free_Malloc_Mempool = INLINE_Free_Malloc_Mempool; - o->Inline_Inlined_Pu_Call_Graph = INLINE_Inlined_Pu_Call_Graph; - o->Inline_Inlined_Pu_Call_Graph2 = INLINE_Inlined_Pu_Call_Graph2; - o->Inline_Get_Time_Info = INLINE_Get_Time_Info; - o->Inline_Script_Name = INLINE_Script_Name; - o->Inline_Enable_Script = INLINE_Enable_Script; - o->Inline_Enable_Devirtualize = INLINE_Enable_Devirtualize; + o->inline_List_Names = INLINE_List_Names; + o->inline_Spec_Files = INLINE_Spec_Files; + o->inline_Skip_After = INLINE_Skip_After; + o->inline_Skip_Before = INLINE_Skip_Before; + o->inline_Array_Bounds = INLINE_Array_Bounds; + o->inline_Use_Malloc_Mempool = INLINE_Use_Malloc_Mempool; + o->inline_Free_Malloc_Mempool = INLINE_Free_Malloc_Mempool; + o->inline_Inlined_Pu_Call_Graph = INLINE_Inlined_Pu_Call_Graph; + o->inline_Inlined_Pu_Call_Graph2 = INLINE_Inlined_Pu_Call_Graph2; + o->inline_Get_Time_Info = INLINE_Get_Time_Info; + o->inline_Script_Name = INLINE_Script_Name; + o->inline_Enable_Script = INLINE_Enable_Script; + o->inline_Enable_Devirtualize = INLINE_Enable_Devirtualize; g_ipa_options = ipa_options_mutable; } diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h index 20ab8211..c2030d87 100644 --- a/osprey/ipa/common/ipa_context.h +++ b/osprey/ipa/common/ipa_context.h @@ -1,5 +1,4 @@ /* - * * IPA Context — master struct that will eventually replace all IPA * module-level globals. Sub-structs group related state by subsystem. * diff --git a/osprey/ipa/common/ipa_options.h b/osprey/ipa/common/ipa_options.h index 92cd386b..34ccf6f2 100644 --- a/osprey/ipa/common/ipa_options.h +++ b/osprey/ipa/common/ipa_options.h @@ -1,8 +1,6 @@ /* - * * IPA Options context struct — encapsulates the ~140 config_ipa.h globals * into a single struct for eventual threading through IPA passes. - * */ #ifndef cxx_ipa_options_INCLUDED @@ -40,201 +38,201 @@ typedef enum { struct IPA_Options { /* --- Filenames --- */ - char *Feedback_Filename; - char *Annotation_Filename; + char *feedback_Filename; + char *annotation_Filename; /* --- Feature enable flags --- */ - BOOL Enable_DFE; - BOOL Enable_DFE_Set; - BOOL Enable_Inline; - BOOL Enable_Picopt; - BOOL Enable_AutoGnum; - BOOL Enable_BarrierFarg; - BOOL Enable_Opt_Alias; - BOOL Enable_Simple_Alias; - BOOL Enable_Addressing; - BOOL Enable_Readonly_Ref; - BOOL Enable_Cprop; - BOOL Enable_Cprop2; - BOOL Enable_Assert; - BOOL Enable_daVinci; - BOOL Enable_ipacom; - BOOL Enable_final_link; - BOOL Enable_Memtrace; - BOOL Enable_DST; - BOOL Enable_DCE; - BOOL Enable_Exc; - BOOL Enable_Recycle; - BOOL Enable_DVE; - BOOL Enable_CGI; - BOOL Enable_Copy_Prop; - BOOL Enable_Padding; - UINT32 Common_Pad_Size; - BOOL Enable_Split_Common; - BOOL Enable_Cloning; - BOOL Enable_Partial_Inline; - BOOL Echo_Commands; - BOOL Enable_Lang; - BOOL Enable_Preempt; - BOOL Enable_Flow_Analysis; - BOOL Enable_Array_Sections; - BOOL Enable_Array_Summary; - BOOL Enable_Scalar_Euse; - BOOL Enable_Scalar_Kill; - BOOL Enable_Common_Const; - BOOL Enable_Relocatable_Opt; - BOOL Enable_Feedback; - BOOL Enable_Alias_Class; - BOOL Debug_AC_Temp_Files; - BOOL Enable_Reshape; - BOOL Enable_Preopt; - BOOL Enable_Preopt_Set; - BOOL Enable_Siloed_Ref; - BOOL Enable_Siloed_Ref_Set; + BOOL enable_DFE; + BOOL enable_DFE_Set; + BOOL enable_Inline; + BOOL enable_Picopt; + BOOL enable_AutoGnum; + BOOL enable_BarrierFarg; + BOOL enable_Opt_Alias; + BOOL enable_Simple_Alias; + BOOL enable_Addressing; + BOOL enable_Readonly_Ref; + BOOL enable_Cprop; + BOOL enable_Cprop2; + BOOL enable_Assert; + BOOL enable_daVinci; + BOOL enable_ipacom; + BOOL enable_final_link; + BOOL enable_Memtrace; + BOOL enable_DST; + BOOL enable_DCE; + BOOL enable_Exc; + BOOL enable_Recycle; + BOOL enable_DVE; + BOOL enable_CGI; + BOOL enable_Copy_Prop; + BOOL enable_Padding; + UINT32 common_Pad_Size; + BOOL enable_Split_Common; + BOOL enable_Cloning; + BOOL enable_Partial_Inline; + BOOL echo_Commands; + BOOL enable_Lang; + BOOL enable_Preempt; + BOOL enable_Flow_Analysis; + BOOL enable_Array_Sections; + BOOL enable_Array_Summary; + BOOL enable_Scalar_Euse; + BOOL enable_Scalar_Kill; + BOOL enable_Common_Const; + BOOL enable_Relocatable_Opt; + BOOL enable_Feedback; + BOOL enable_Alias_Class; + BOOL debug_AC_Temp_Files; + BOOL enable_Reshape; + BOOL enable_Preopt; + BOOL enable_Preopt_Set; + BOOL enable_Siloed_Ref; + BOOL enable_Siloed_Ref_Set; #ifdef KEY - BOOL Enable_Icall_Opt; - BOOL Enable_EH_Region_Removal; - BOOL Enable_Branch_Heuristic; - float Min_Branch_Prob; - BOOL Check_Options; - BOOL Clone_List_Actions; - BOOL Enable_Pure_Call_Opt; - INT32 Pure_Call_skip_before; - BOOL Consult_Inliner_For_Icall_Opt; - UINT32 Icall_Min_Freq; - BOOL Enable_Source_PU_Order; - UINT32 Enable_Struct_Opt; - UINT32 Enable_Global_As_Local; - UINT32 Update_Struct; + BOOL enable_Icall_Opt; + BOOL enable_EH_Region_Removal; + BOOL enable_Branch_Heuristic; + float min_Branch_Prob; + BOOL check_Options; + BOOL clone_List_Actions; + BOOL enable_Pure_Call_Opt; + INT32 pure_Call_skip_before; + BOOL consult_Inliner_For_Icall_Opt; + UINT32 icall_Min_Freq; + BOOL enable_Source_PU_Order; + UINT32 enable_Struct_Opt; + UINT32 enable_Global_As_Local; + UINT32 update_Struct; #endif /* KEY */ - UINT32 Icall_Target_Min_Rate; + UINT32 icall_Target_Min_Rate; /* --- Inlining heuristics --- */ - UINT32 Bloat_Factor; - BOOL Bloat_Factor_Set; - UINT32 PU_Limit; - BOOL PU_Limit_Set; - UINT32 PU_Hard_Limit; - BOOL PU_Hard_Limit_Set; - UINT32 PU_Minimum_Size; - UINT32 Small_Callee_Limit; - UINT32 Max_Depth; - UINT32 Force_Depth; - BOOL Force_Depth_Set; - UINT32 Min_Freq; - UINT32 Rela_Freq; - UINT32 Min_Hotness; - BOOL Use_Effective_Size; + UINT32 bloat_Factor; + BOOL bloat_Factor_Set; + UINT32 pU_Limit; + BOOL pU_Limit_Set; + UINT32 pU_Hard_Limit; + BOOL pU_Hard_Limit_Set; + UINT32 pU_Minimum_Size; + UINT32 small_Callee_Limit; + UINT32 max_Depth; + UINT32 force_Depth; + BOOL force_Depth_Set; + UINT32 min_Freq; + UINT32 rela_Freq; + UINT32 min_Hotness; + BOOL use_Effective_Size; /* --- Miscellaneous --- */ - BOOL Enable_Merge_ty; - UINT32 Max_Jobs; - BOOL Max_Jobs_Set; - UINT32 Gspace; + BOOL enable_Merge_ty; + UINT32 max_Jobs; + BOOL max_Jobs_Set; + UINT32 gspace; UINT32 user_gnum; - UINT32 Extgot_Factor; - UINT32 Num_Fortran_Intrinsics; - BOOL Has_Fortran; - UINT32 Map_Limit; - BOOL Enable_SP_Partition; - BOOL Enable_GP_Partition; - BOOL Space_Access_Mode; - - struct option_list *Group_Names; - struct option_list *Spec_Files; - struct option_list *Skip; - BOOL Skip_Report; - - BOOL Enable_Keeplight; - BOOL Enable_Cord; - BOOL Enable_Linearization; - BOOL Use_Intrinsic; - BOOL Enable_Inline_Nested_PU; - BOOL Enable_Inline_Struct; - BOOL Enable_Inline_Char_Array; - BOOL Enable_Inline_Optional_Arg; - BOOL Enable_Inline_Struct_Array_Actual; - BOOL Enable_Inline_Var_Dim_Array; - BOOL Enable_Reorder; - BOOL Enable_AOT; + UINT32 extgot_Factor; + UINT32 num_Fortran_Intrinsics; + BOOL has_Fortran; + UINT32 map_Limit; + BOOL enable_SP_Partition; + BOOL enable_GP_Partition; + BOOL space_Access_Mode; + + struct option_list *group_Names; + struct option_list *spec_Files; + struct option_list *skip; + BOOL skip_Report; + + BOOL enable_Keeplight; + BOOL enable_Cord; + BOOL enable_Linearization; + BOOL use_Intrinsic; + BOOL enable_Inline_Nested_PU; + BOOL enable_Inline_Struct; + BOOL enable_Inline_Char_Array; + BOOL enable_Inline_Optional_Arg; + BOOL enable_Inline_Struct_Array_Actual; + BOOL enable_Inline_Var_Dim_Array; + BOOL enable_Reorder; + BOOL enable_AOT; #ifdef KEY - IPA_OPT_PU_REORDER_SCHEME Enable_PU_Reorder; - BOOL Enable_PU_Reorder_Set; - BOOL Enable_Ctype; - IPA_OPT_CHECK_PARAM_COMPATIBILITY Inline_Check_Compatibility; + IPA_OPT_PU_REORDER_SCHEME enable_PU_Reorder; + BOOL enable_PU_Reorder_Set; + BOOL enable_Ctype; + IPA_OPT_CHECK_PARAM_COMPATIBILITY inline_Check_Compatibility; #endif /* KEY */ - UINT32 Max_Node_Clones; - BOOL Max_Node_Clones_Set; - UINT32 Max_Clone_Bloat; - UINT32 Max_Output_File_Size; - INT32 Output_File_Size; - UINT32 Max_Density; + UINT32 max_Node_Clones; + BOOL max_Node_Clones_Set; + UINT32 max_Clone_Bloat; + UINT32 max_Output_File_Size; + INT32 output_File_Size; + UINT32 max_Density; - BOOL Enable_Old_Type_Merge; + BOOL enable_Old_Type_Merge; /* --- Devirtualization --- */ - BOOL Enable_Devirtualization; - BOOL Enable_Fast_Static_Analysis_VF; - BOOL Enable_Original_VF; - BOOL Enable_New_VF; - BOOL Inline_Original_VF; - BOOL Inline_New_VF; - const char *Devirtualization_Input_File; - BOOL During_Original_VF; - BOOL During_New_VF; + BOOL enable_Devirtualization; + BOOL enable_Fast_Static_Analysis_VF; + BOOL enable_Original_VF; + BOOL enable_New_VF; + BOOL inline_Original_VF; + BOOL inline_New_VF; + const char *devirtualization_Input_File; + BOOL during_Original_VF; + BOOL during_New_VF; /* --- Whole program / scale --- */ - BOOL Enable_Whole_Program_Mode; - BOOL Enable_Whole_Program_Mode_Set; - BOOL Enable_Scale; + BOOL enable_Whole_Program_Mode; + BOOL enable_Whole_Program_Mode_Set; + BOOL enable_Scale; /* --- INLINE group options --- */ - BOOL Inline_Enable; - BOOL Inline_All; - BOOL Inline_Optimize_Alloca; - BOOL Inline_Enable_Copy_Prop; - BOOL Inline_Enable_Subst_Copy_Prop; - BOOL Inline_F90; - BOOL Inline_None; - BOOL Inline_Exceptions; - BOOL Inline_Keep_PU_Order; - BOOL Inline_List_Actions; - UINT32 Inline_Max_Pu_Size; - BOOL Inline_Preemptible; - BOOL Inline_Static; - BOOL Inline_Static_Set; - BOOL Inline_Aggressive; - BOOL Inline_First_Inline_Calls_In_Loops; - BOOL Inline_Enable_DFE; - BOOL Inline_Enable_Split_Common; - BOOL Inline_Enable_Auto_Inlining; - BOOL Inline_Enable_Restrict_Pointers; + BOOL inline_Enable; + BOOL inline_All; + BOOL inline_Optimize_Alloca; + BOOL inline_Enable_Copy_Prop; + BOOL inline_Enable_Subst_Copy_Prop; + BOOL inline_F90; + BOOL inline_None; + BOOL inline_Exceptions; + BOOL inline_Keep_PU_Order; + BOOL inline_List_Actions; + UINT32 inline_Max_Pu_Size; + BOOL inline_Preemptible; + BOOL inline_Static; + BOOL inline_Static_Set; + BOOL inline_Aggressive; + BOOL inline_First_Inline_Calls_In_Loops; + BOOL inline_Enable_DFE; + BOOL inline_Enable_Split_Common; + BOOL inline_Enable_Auto_Inlining; + BOOL inline_Enable_Restrict_Pointers; #ifdef KEY - BOOL Inline_Recursive; - BOOL Inline_Param_Mismatch; - BOOL Inline_Type_Mismatch; - BOOL Inline_Ignore_Bloat; - UINT32 Inline_Callee_Limit; + BOOL inline_Recursive; + BOOL inline_Param_Mismatch; + BOOL inline_Type_Mismatch; + BOOL inline_Ignore_Bloat; + UINT32 inline_Callee_Limit; #endif /* KEY */ - struct option_list *Inline_List_Names; - struct option_list *Inline_Spec_Files; - UINT32 Inline_Skip_After; - UINT32 Inline_Skip_Before; - BOOL Inline_Array_Bounds; - BOOL Inline_Use_Malloc_Mempool; - BOOL Inline_Free_Malloc_Mempool; - BOOL Inline_Inlined_Pu_Call_Graph; - BOOL Inline_Inlined_Pu_Call_Graph2; - BOOL Inline_Get_Time_Info; - char *Inline_Script_Name; - BOOL Inline_Enable_Script; - BOOL Inline_Enable_Devirtualize; + struct option_list *inline_List_Names; + struct option_list *inline_Spec_Files; + UINT32 inline_Skip_After; + UINT32 inline_Skip_Before; + BOOL inline_Array_Bounds; + BOOL inline_Use_Malloc_Mempool; + BOOL inline_Free_Malloc_Mempool; + BOOL inline_Inlined_Pu_Call_Graph; + BOOL inline_Inlined_Pu_Call_Graph2; + BOOL inline_Get_Time_Info; + char *inline_Script_Name; + BOOL inline_Enable_Script; + BOOL inline_Enable_Devirtualize; }; /* Transitional global — will be removed once all call-sites are threaded */ From ea4d232e6f059627df426c3681cdbe20199b4209 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Mon, 2 Mar 2026 23:41:17 -0800 Subject: [PATCH 08/10] Migrate merge state globals to IPA_Context Move the five extern globals from ipc_symtab_merge.h into IPA_Merge_State: Aux_St_Tab, Aux_St_Table, Aux_Pu_Table, ST_To_INITO_Map, and Common_Block_Elements_Map. Each is stored as a void* pointer in the context struct with a backward-compatible #define macro. Value-type globals (Aux_St_Tab, Aux_St_Table, Aux_Pu_Table, ST_To_INITO_Map) become file-static in ipc_symtab_merge.cxx with pointers wired up in Initialize_Auxiliary_Tables(). The pointer global Common_Block_Elements_Map uses the same (*(TYPE**)&field) pattern as IPA_Common_Table. The Aux_Pu_Table macro is guarded for _LIGHTWEIGHT_INLINER which defines its own local copy in inline.cxx. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.h | 8 ++++++-- osprey/ipa/common/ipc_symtab_merge.cxx | 18 ++++++++++++------ osprey/ipa/common/ipc_symtab_merge.h | 23 +++++++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h index c2030d87..611c6859 100644 --- a/osprey/ipa/common/ipa_context.h +++ b/osprey/ipa/common/ipa_context.h @@ -130,9 +130,13 @@ struct IPA_Alias_Analysis_State { /* Placeholder — will be populated when we migrate IPAA globals */ }; -/* --- Type/symbol merge state --- */ +/* --- Type/symbol merge state (ipc_symtab_merge.h) --- */ struct IPA_Merge_State { - /* Placeholder — will be populated when we migrate merge globals */ + void *aux_st_tab; /* AUX_ST_TAB* */ + void *aux_st_table; /* AUX_ST_TABLE* */ + void *aux_pu_table; /* AUX_PU_TAB* */ + void *st_to_inito_map; /* ST_TO_INITO_MAP* */ + void *common_block_elements_map; /* COMMON_BLOCK_ELEMENTS_MAP* */ }; /* --- Compile state (ipc_compile.cxx) --- */ diff --git a/osprey/ipa/common/ipc_symtab_merge.cxx b/osprey/ipa/common/ipc_symtab_merge.cxx index 2f6e73b8..2caf4f0c 100644 --- a/osprey/ipa/common/ipc_symtab_merge.cxx +++ b/osprey/ipa/common/ipc_symtab_merge.cxx @@ -90,12 +90,12 @@ #include "ipc_symtab_merge.h" -AUX_ST_TAB Aux_St_Tab; -AUX_ST_TABLE Aux_St_Table; +static AUX_ST_TAB Aux_St_Tab_impl; +static AUX_ST_TABLE Aux_St_Table_impl; static UINT32 num_predefined_st; // number of predefined symbols (pregs) -AUX_PU_TAB Aux_Pu_Table; +static AUX_PU_TAB Aux_Pu_Table_impl; static IP_FILE_HDR* current_file_hdr; @@ -194,10 +194,10 @@ static TCON_IDX_MAP *New_Tcon_Idx; static ST_TO_INITO_MAP *St_To_Inito_Map; // map from ST_IDX to corresponding INITO -- used for constant propagation -ST_TO_INITO_MAP ST_To_INITO_Map; +static ST_TO_INITO_MAP ST_To_INITO_Map_impl; // map from a common block ST_IDX to the array of its elements -COMMON_BLOCK_ELEMENTS_MAP *Common_Block_Elements_Map = NULL; +static COMMON_BLOCK_ELEMENTS_MAP *Common_Block_Elements_Map_impl = NULL; static MEM_POOL Common_map_pool; #if (defined(_STANDALONE_INLINER) || defined(_LIGHTWEIGHT_INLINER)) @@ -234,13 +234,19 @@ get_global_st(char* symname) void Initialize_Auxiliary_Tables () { + /* Wire up context pointers to the file-static objects */ + g_ipa_ctx->merge.aux_st_tab = &Aux_St_Tab_impl; + g_ipa_ctx->merge.aux_st_table = &Aux_St_Table_impl; + g_ipa_ctx->merge.aux_pu_table = &Aux_Pu_Table_impl; + g_ipa_ctx->merge.st_to_inito_map = &ST_To_INITO_Map_impl; + const UINT32 st_size = ST_Table_Size (GLOBAL_SYMTAB); #if (defined(_STANDALONE_INLINER) || defined(_LIGHTWEIGHT_INLINER)) num_predefined_st = count_pregs()+1; #else // _STANDALONE_INLINER num_predefined_st = st_size; #endif // _STANDALONE_INLINER - + Scope_tab[GLOBAL_SYMTAB].st_tab->Register (Aux_St_Tab); const AUX_PU aux_pu; diff --git a/osprey/ipa/common/ipc_symtab_merge.h b/osprey/ipa/common/ipc_symtab_merge.h index 9a418d65..3d71ca05 100644 --- a/osprey/ipa/common/ipc_symtab_merge.h +++ b/osprey/ipa/common/ipc_symtab_merge.h @@ -303,7 +303,13 @@ struct IPC_GLOBAL_IDX_MAP }; // IPC_GLOBAL_IDX_MAP typedef hash_map ST_TO_INITO_MAP; -extern ST_TO_INITO_MAP ST_To_INITO_Map; + +// Merge globals now live in IPA_Context (ipa_context.h). +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define ST_To_INITO_Map \ + (*(ST_TO_INITO_MAP*)(g_ipa_ctx->merge.st_to_inito_map)) // ---------------------------------------------------------------------- // Keep track of all elements of a common block @@ -329,7 +335,8 @@ typedef std::map, std::equal_to, mempool_allocator > COMMON_BLOCK_ELEMENTS_MAP; -extern COMMON_BLOCK_ELEMENTS_MAP *Common_Block_Elements_Map; +#define Common_Block_Elements_Map \ + (*(COMMON_BLOCK_ELEMENTS_MAP**)&(g_ipa_ctx->merge.common_block_elements_map)) //---------------------------------------------------------------------- // Auxiliary tables for STs and PUs @@ -382,7 +389,8 @@ Inc_AUX_ST_modcount (AUX_ST& aux_st, INT32 count) { typedef RELATED_SEGMENTED_ARRAY AUX_ST_TAB; -extern AUX_ST_TAB Aux_St_Tab; +#define Aux_St_Tab \ + (*(AUX_ST_TAB*)(g_ipa_ctx->merge.aux_st_tab)) struct AUX_ST_TABLE { @@ -393,7 +401,8 @@ struct AUX_ST_TABLE }; -extern AUX_ST_TABLE Aux_St_Table; +#define Aux_St_Table \ + (*(AUX_ST_TABLE*)(g_ipa_ctx->merge.aux_st_table)) struct AUX_PU { @@ -433,7 +442,13 @@ AUX_PU_file_hdr (const AUX_PU& pu) typedef SEGMENTED_ARRAY AUX_PU_TAB; +#ifndef _LIGHTWEIGHT_INLINER +#define Aux_Pu_Table \ + (*(AUX_PU_TAB*)(g_ipa_ctx->merge.aux_pu_table)) +#else +/* lw_inline defines its own Aux_Pu_Table in inline.cxx */ extern AUX_PU_TAB Aux_Pu_Table; +#endif extern void Initialize_Auxiliary_Tables (); From 05b85a5e71524fda3b115a4ffd05b65c5b5d7f6e Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Tue, 3 Mar 2026 07:17:27 -0800 Subject: [PATCH 09/10] Migrate call-graph and options-inconsistent globals to IPA_Context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the extern declarations for IPA_Call_Graph, IPA_Call_Graph_Built, and Opt_Options_Inconsistent in ipa_cg.h with #define macros that access the corresponding fields already present in IPA_Context since Step 1. Remove the global definitions from ipa_cg.cxx — the context struct fields (zero-initialized by IPA_Context_Init) provide equivalent storage. IP_File_header migration is deferred: it has a static-constructor initialization pattern in init.cxx that takes its address before g_ipa_ctx is available. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/main/analyze/ipa_cg.cxx | 6 +++--- osprey/ipa/main/analyze/ipa_cg.h | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/osprey/ipa/main/analyze/ipa_cg.cxx b/osprey/ipa/main/analyze/ipa_cg.cxx index 8a21905e..591c90a1 100644 --- a/osprey/ipa/main/analyze/ipa_cg.cxx +++ b/osprey/ipa/main/analyze/ipa_cg.cxx @@ -119,7 +119,7 @@ #include "ipa_nystrom_alias_analyzer.h" #endif -IPA_CALL_GRAPH* IPA_Call_Graph; // "The" call graph of IPA +// IPA_Call_Graph migrated to g_ipa_ctx->call_graph (ipa_context.h). #ifdef KEY // IPA_Graph_Undirected migrated to g_ipa_ctx->graph_undirected (ipa_context.h). // IPA_Call_Graph is a global variable used widely, even in member functions @@ -135,7 +135,7 @@ static IPA_CALL_GRAPH* IPA_Call_Graph_Tmp = NULL; static hash_map node_map; static vector q_order; #endif -BOOL IPA_Call_Graph_Built = FALSE; +// IPA_Call_Graph_Built migrated to g_ipa_ctx->call_graph_built (ipa_context.h). typedef hash_map ALT_ENTRY_MAP; ALT_ENTRY_MAP *alt_entry_map; // map from alt entry to base entry @@ -480,7 +480,7 @@ Mark_PUs_With_File_Id (PU_Info * pu, UINT id) std::vector options; -BOOL Opt_Options_Inconsistent = FALSE; +// Opt_Options_Inconsistent migrated to g_ipa_ctx->opt_options_inconsistent. mINT32 IPA_NODE::next_file_id = -1; // This is a simple scheme to check if there is mismatch in options passed diff --git a/osprey/ipa/main/analyze/ipa_cg.h b/osprey/ipa/main/analyze/ipa_cg.h index da6bd2e8..5c176575 100644 --- a/osprey/ipa/main/analyze/ipa_cg.h +++ b/osprey/ipa/main/analyze/ipa_cg.h @@ -1264,8 +1264,12 @@ class IPA_CALL_GRAPH }; // IPA_CALL_GRAPH -extern IPA_CALL_GRAPH *IPA_Call_Graph; -extern BOOL IPA_Call_Graph_Built; +// IPA_Call_Graph and IPA_Call_Graph_Built now live in IPA_Context. +#ifndef cxx_ipa_context_INCLUDED +#include "ipa_context.h" +#endif +#define IPA_Call_Graph (g_ipa_ctx->call_graph) +#define IPA_Call_Graph_Built (g_ipa_ctx->call_graph_built) extern void IPA_Process_File (IP_FILE_HDR& hdr); extern void Build_Call_Graph (); @@ -1275,9 +1279,6 @@ extern void IPA_Convert_Icalls( IPA_CALL_GRAPH* ); #endif //INLINING_TUNING — these globals now live in IPA_Context (ipa_context.h). -#ifndef cxx_ipa_context_INCLUDED -#include "ipa_context.h" -#endif #define Orig_Prog_WN_Count (g_ipa_ctx->inline_stats.orig_prog_wn_count) #define Prog_WN_Count (g_ipa_ctx->inline_stats.prog_wn_count) #define Total_Dead_Function_WN_Count (g_ipa_ctx->inline_stats.total_dead_function_wn_count) @@ -1597,7 +1598,7 @@ extern char* IPA_Node_Name(IPA_NODE* node); #if defined(KEY) && !defined(_STANDALONE_INLINER) && !defined(_LIGHTWEIGHT_INLINER) extern void Mark_PUs_With_File_Id (PU_Info *, UINT); -extern BOOL Opt_Options_Inconsistent; +#define Opt_Options_Inconsistent (g_ipa_ctx->opt_options_inconsistent) #endif // KEY && !_STANDALONE_INLINER && !_LIGHTWEIGHT_INLINER #ifdef _LIGHTWEIGHT_INLINER From a5ff24d5c88d6d241be521db42199e8b0f149629 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Tue, 3 Mar 2026 00:12:16 -0800 Subject: [PATCH 10/10] Add IPA_Context lifecycle calls at main entry points Add IPA_Context_Alloc/Free as lightweight lifecycle functions available in all IPA-family targets (ipa, inline, lw_inline). Refactor IPA_Context_Init to call IPA_Context_Alloc before snapshotting options. Wire up the calls: - ipa_dot_so_init(): IPA_Context_Alloc() before Initialize_Auxiliary_Tables - ipa_driver(): IPA_Context_Init() after Process_IPA_Options (snapshots config_ipa.h globals with their final command-line values) - Inliner(): IPA_Context_Alloc() before Initialize_Symbol_Tables This makes all previously migrated context-based macros work at runtime. Co-Authored-By: Claude Opus 4.6 --- osprey/ipa/common/ipa_context.cxx | 43 +++++++++++++++++++++---------- osprey/ipa/common/ipa_context.h | 6 +++-- osprey/ipa/common/ipc_main.cxx | 3 +++ osprey/ipa/inline/inline.cxx | 1 + 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/osprey/ipa/common/ipa_context.cxx b/osprey/ipa/common/ipa_context.cxx index 7c209c6a..9201efde 100644 --- a/osprey/ipa/common/ipa_context.cxx +++ b/osprey/ipa/common/ipa_context.cxx @@ -18,10 +18,36 @@ IPA_Context *g_ipa_ctx = NULL; +/* ==================================================================== + * IPA_Context_Alloc / IPA_Context_Free: lightweight context lifecycle. + * Available in ALL IPA-family targets (ipa, inline, lw_inline). + * Allocates and zero-fills the context struct without snapshotting options. + * ==================================================================== + */ +void +IPA_Context_Alloc(void) +{ + if (g_ipa_ctx != NULL) + return; + + g_ipa_ctx = (IPA_Context *) malloc(sizeof(IPA_Context)); + memset(g_ipa_ctx, 0, sizeof(IPA_Context)); +} + +void +IPA_Context_Free(void) +{ + if (g_ipa_ctx != NULL) { + free(g_ipa_ctx); + g_ipa_ctx = NULL; + } +} + + /* * The full init/fini functions are only available in the main IPA target * where config_ipa.h globals are linked in. The inline and lw_inline - * targets just need the g_ipa_ctx symbol for the macro-based accessors. + * targets just need IPA_Context_Alloc/Free. */ #ifdef IPA_CONTEXT_FULL_INIT @@ -249,19 +275,13 @@ IPA_Options_Init(void) /* ==================================================================== - * IPA_Context_Init: allocate and zero-fill the master context. - * Calls IPA_Options_Init to snapshot the option globals. + * IPA_Context_Init: allocate context and snapshot option globals. * ==================================================================== */ void IPA_Context_Init(void) { - if (g_ipa_ctx != NULL) - return; - - g_ipa_ctx = (IPA_Context *) malloc(sizeof(IPA_Context)); - memset(g_ipa_ctx, 0, sizeof(IPA_Context)); - + IPA_Context_Alloc(); IPA_Options_Init(); } @@ -279,10 +299,7 @@ IPA_Context_Fini(void) g_ipa_options = NULL; } - if (g_ipa_ctx != NULL) { - free(g_ipa_ctx); - g_ipa_ctx = NULL; - } + IPA_Context_Free(); } #endif /* IPA_CONTEXT_FULL_INIT */ diff --git a/osprey/ipa/common/ipa_context.h b/osprey/ipa/common/ipa_context.h index 611c6859..53b001d6 100644 --- a/osprey/ipa/common/ipa_context.h +++ b/osprey/ipa/common/ipa_context.h @@ -179,7 +179,9 @@ struct IPA_Context { extern IPA_Context *g_ipa_ctx; /* Lifecycle functions (defined in ipa_context.cxx) */ -extern void IPA_Context_Init(void); -extern void IPA_Context_Fini(void); +extern void IPA_Context_Alloc(void); /* lightweight: alloc+zero, all targets */ +extern void IPA_Context_Free(void); /* free context, all targets */ +extern void IPA_Context_Init(void); /* full: alloc + options snapshot (IPA main) */ +extern void IPA_Context_Fini(void); /* full: free context + options (IPA main) */ #endif /* cxx_ipa_context_INCLUDED */ diff --git a/osprey/ipa/common/ipc_main.cxx b/osprey/ipa/common/ipc_main.cxx index afe1493e..f19e2b52 100644 --- a/osprey/ipa/common/ipc_main.cxx +++ b/osprey/ipa/common/ipc_main.cxx @@ -66,6 +66,7 @@ #include "ld_ipa_interface.h" // for ld_for_all_ST () #include "ipc_weak.h" +#include "ipa_context.h" #include "ipc_link.h" #include "config_ipa.h" @@ -166,6 +167,7 @@ ipa_dot_so_init () Init_Operator_To_Opcode_Table (); Initialize_Symbol_Tables (TRUE); + IPA_Context_Alloc(); Initialize_Auxiliary_Tables (); MEM_POOL_Initialize (&Type_Merge_Pool, "TY Merge Pool", 0); @@ -292,6 +294,7 @@ ipa_driver (INT argc, char **argv) #endif Process_IPA_Options (argc, argv); + IPA_Context_Init(); /* snapshot config_ipa.h options into g_ipa_ctx */ detect_whole_program_mode(); diff --git a/osprey/ipa/inline/inline.cxx b/osprey/ipa/inline/inline.cxx index 73979ec1..aa7a333a 100644 --- a/osprey/ipa/inline/inline.cxx +++ b/osprey/ipa/inline/inline.cxx @@ -1091,6 +1091,7 @@ Inliner(char* input_name, char* output_name, INL_SKIPLST& filter) Initialize_Symbol_Tables(FALSE); + IPA_Context_Alloc(); New_Scope (GLOBAL_SYMTAB, Malloc_Mem_Pool, FALSE);