diff mbox

[Cilkplus] Low cost annotations implementation

Message ID 2950715866004049A240A2F9BB410E7315FB28F614@azsmsx502.amr.corp.intel.com
State New
Headers show

Commit Message

Iyer, Balaji V Dec. 2, 2011, 8:24 p.m. UTC
Hello Everyone,
    I found that patch 4 stepped on parts of patch 3. Here is the updated patches (Please notice patch 4, 5 and 6 are replaced).

Thanks,

Balaji V. Iyer.

Comments

H.J. Lu Dec. 2, 2011, 8:43 p.m. UTC | #1
On Fri, Dec 2, 2011 at 12:24 PM, Iyer, Balaji V <balaji.v.iyer@intel.com> wrote:
> Hello Everyone,
>    I found that patch 4 stepped on parts of patch 3. Here is the updated patches (Please notice patch 4, 5 and 6 are replaced).
>
> Thanks,
>
> Balaji V. Iyer.
>
> ________________________________________
> From: Iyer, Balaji V
> Sent: Wednesday, November 30, 2011 3:12 PM
> To: gcc-patches@gcc.gnu.org
> Subject: [PATCH][Cilkplus] Low cost annotations implementation
>
>  Hello Everyone,
>      The attached 7 patches are for the Cilkplus branch affecting both the C and C++ compiler. These patches implement Low-Overhead Tool Annotations. These annotations specifies two intrinsic that enable annotating executables and tools without incurring significant run-time costs when the tools are not in use. These annotations can be read by analyzers to gain insights about the program. For example, Cilk screen and Cilk view use these annotations to detect races and do scalability analysis on parallel programs. Even though the annotations currently specified are Cilk Plus specific, the format is generic and can be used by any tool-vendor to define additional annotations. More information about these annotations can be found in the specification available here: http://software.intel.com/file/39770. Cilk screen and Cilk view are available in the Intel Cilk Plus SDK which can be downloaded for free from the following Intel website: http://software.intel.com/en-us/articles/intel-cilk-plus-software-development-kit/
>
>        The patches are numbered from 1 through 7, and please commit them in order.
>

Please generate a new set of patches against
the current cilkplus branch.  The ChangeLog entries
should be added to the beginning of ChangeLog and
you shouldn't change existing ChangeLog entries. If
there is an error in existing ChangeLog entries, please
send a separate patch.
diff mbox

Patch

diff --git a/gcc/ChangeLog.cilk b/gcc/ChangeLog.cilk
index c021a48..fda0d25 100644
--- a/gcc/ChangeLog.cilk
+++ b/gcc/ChangeLog.cilk
@@ -17,6 +17,13 @@ 
 	(cilk_call_setjmp): Replaced implicit_built_in_decls[] to
 	builtin_decl_implicit ().
 
+2011-10-04  Balaji V. Iyer  <balaji.v.iyer@intel.com>
+
+	* cilk.c (cilk_init_builtins): Added Cilkscreen builtin function
+	declarations.
+	* builtins.def: Added Cilkscreen builtin functions expand tags.
+	* cilk.h: Added Cilkscreen builtin functions in the cilk_trees chain.
+
 2011-09-20  Balaji V. Iyer  <balaji.v.iyer@intel.com>
 
 	* ipa-inline.c(can_inline_edge_p): Added a check for function
diff --git a/gcc/builtins.def b/gcc/builtins.def
index 358e779..4b524bb 100644
--- a/gcc/builtins.def
+++ b/gcc/builtins.def
@@ -799,13 +799,38 @@  DEF_BUILTIN_STUB (BUILT_IN_EH_FILTER, "__builtin_eh_filter")
 DEF_BUILTIN_STUB (BUILT_IN_EH_COPY_VALUES, "__builtin_eh_copy_values")
 
 /* Cilk */
-DEF_BUILTIN_STUB (BUILT_IN_CILK_WORKER_ID, "__cilkrts_current_worker_id")
-DEF_BUILTIN_STUB (BUILT_IN_CILK_WORKER_PTR, "__cilkrts_current_worker")
-DEF_BUILTIN_STUB (BUILT_IN_CILK_DETACH, "__cilkrts_detach")
-DEF_BUILTIN_STUB (BUILT_IN_CILK_SYNCHED, "__cilkrts_synched")
-DEF_BUILTIN_STUB (BUILT_IN_CILK_STOLEN, "__cilkrts_was_stolen")
-DEF_BUILTIN_STUB (BUILT_IN_CILK_ENTER_FRAME, "__cilkrts_enter_frame")
-DEF_BUILTIN_STUB (BUILT_IN_CILK_POP_FRAME, "__cilkrts_pop_frame")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_WORKER_ID, "__cilkrts_current_worker_id")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_WORKER_PTR, "__cilkrts_current_worker")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_DETACH, "__cilkrts_detach")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_SYNCHED, "__cilkrts_synched")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_STOLEN, "__cilkrts_was_stolen")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_ENTER_FRAME, "__cilkrts_enter_frame")
+DEF_BUILTIN_STUB(BUILT_IN_CILK_POP_FRAME, "__cilkrts_pop_frame")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_ENTER_BEGIN, "__cilk_enter_begin")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_ENTER_H_BEGIN, "__cilk_enter_helper_begin")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_ENTER_END, "__cilk_enter_end")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_SPAWN_PREPARE, "__cilk_spawn_prepare")
+DEF_BUILTIN_STUB (BUILT_IN_SPAWN_OR_CONT, "__cilk_spawn_or_continue")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_DETACH_BEGIN, "__cilk_detach_begin")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_DETACH_END, "__cilk_detach_end")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_SYNC_BEGIN, "__cilk_sync_begin")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_SYNC_END, "__cilk_sync_end")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_LEAVE_BEGIN, "__cilk_leave_begin")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_LEAVE_END, "__cilk_leave_end")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_METACALL, "cilkscreen_metacall")
+DEF_BUILTIN_STUB (BUILT_IN_CILK_RESUME, "cilk_resume")
+DEF_BUILTIN_STUB (BUILT_IN_LEAVE_STOLEN, "cilk_leave_stolen")
+DEF_BUILTIN_STUB (BUILT_IN_SYNC_ABANDON, "cilk_sync_abandon")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_DISABLE_INSTR, 
+"cilkscreen_disable_instrumentation")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_EN_INSTR, 
+"cilkscreen_enable_instrumentation")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_DS_INSTR,
+"cilkscreen_disable_instrumentation")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_DS_CHK, "cilkscreen_disable_checking")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_EN_CHK, "cilkscreen_enable_checking")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_AQUIRE_LOCK, "cilkscreen_aquire_lock")
+DEF_BUILTIN_STUB (BUILT_IN_CILKSCREEN_REL_LOCK, "cilkscreen_release_lock")
 
 /* Synchronization Primitives.  */
 #include "sync-builtins.def"
diff --git a/gcc/cilk.c b/gcc/cilk.c
index 369bae0..11726ba 100644
--- a/gcc/cilk.c
+++ b/gcc/cilk.c
@@ -109,6 +109,13 @@  cilk_init_builtins (void)
   tree fptr_fun; /* void(frame *) */
   tree frame_pred;
   tree s_type_node;
+  tree metacall_frame, metacall_fptr_type, metacall_fields, metacall_fptr_fun;
+  tree metacall_fptr_arglist;
+  tree int_list = tree_cons (NULL_TREE, integer_type_node, NULL_TREE);
+  tree int_fun = build_function_type (void_type_node, int_list);
+  tree ptr_list = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
+  tree ptr_fun = build_function_type (void_type_node, ptr_list);
+  tree void_fun = build_function_type (void_type_node, void_list_node);
 
   /* Make the frame and worker tags first because they reference each other. */
   worker = lang_hooks.types.make_type (RECORD_TYPE);
@@ -161,7 +168,34 @@  cilk_init_builtins (void)
 
   cilk_frame_ptr_type_decl = build_qualified_type (fptr_type,
 						   TYPE_QUAL_RESTRICT);
-
+  /*
+    typedef struct __metacall_data_t {
+        unsigned int tool;
+        unsigned int code;
+	void *data;
+    } metacall_data_t;
+  */
+  metacall_frame = lang_hooks.types.make_type (RECORD_TYPE);
+  metacall_fptr_type = build_pointer_type (metacall_frame);
+  metacall_fptr_arglist =
+    tree_cons (NULL_TREE, metacall_fptr_type, void_list_node);
+  metacall_fptr_fun = build_function_type (void_type_node,
+					   metacall_fptr_arglist);
+  metacall_fields = NULL_TREE;
+  metacall_fields = add_field ("tool", unsigned_type_node, metacall_fields);
+  cilk_trees[CILK_TI_METACALL_TOOL_FLAGS] = metacall_fields;
+  metacall_fields = add_field ("code", unsigned_type_node, metacall_fields);
+  cilk_trees[CILK_TI_METACALL_CODE_FLAGS] = metacall_fields;
+  metacall_fields = add_field ("data", fptr_type, metacall_fields);
+  cilk_trees[CILK_TI_METACALL_DATA_FLAGS] = metacall_fields;
+  TYPE_ALIGN (metacall_frame) = PREFERRED_STACK_BOUNDARY;
+  TREE_ADDRESSABLE (metacall_frame) = 1;
+  finish_builtin_struct (metacall_frame, "__metacall_data_s", metacall_fields,
+			 NULL_TREE);
+  cilk_metacall_frame_type_decl = metacall_frame;
+  lang_hooks.types.register_builtin_type (frame, "__metacall_data_t");
+  cilk_mcall_frame_ptr_type_decl = build_qualified_type (metacall_fptr_type,
+							    TYPE_QUAL_RESTRICT);
   /* object could be named __cilk_frame_var for compatibility */
 
   fptr_v_type = build_qualified_type (fptr_type, TYPE_QUAL_VOLATILE);
@@ -303,6 +337,52 @@  cilk_init_builtins (void)
     worker_tail_offset = tree_low_cst (off1, 0) +
       tree_low_cst (off2, 0) / BITS_PER_UNIT;
   }
+
+  cilk_enter_begin_fndecl = install_builtin ("__cilk_enter_begin", fptr_fun,
+					     BUILT_IN_CILK_ENTER_BEGIN, true);
+  cilk_enter_h_begin_fndecl = install_builtin
+    ("cilk_enter_helper_begin", fptr_fun, BUILT_IN_CILK_ENTER_H_BEGIN, true);
+  cilk_enter_end_fndecl = install_builtin ("__cilk_enter_end", fptr_fun,
+					   BUILT_IN_CILK_ENTER_END, true);
+  cilk_spawn_prepare_fndecl = install_builtin
+    ("__cilk_spawn_prepare", fptr_fun, BUILT_IN_CILK_SPAWN_PREPARE, true);
+  cilk_spawn_or_cont_fndecl = install_builtin
+    ("__cilk_spawn_or_continue", int_fun, BUILT_IN_SPAWN_OR_CONT, true);
+  cilk_detach_begin_fndecl = install_builtin ("__cilk_detach_begin", fptr_fun,
+					      BUILT_IN_CILK_DETACH_BEGIN, true);
+  cilk_detach_end_fndecl = install_builtin ("__cilk_detach_end", void_fun,
+					    BUILT_IN_CILK_DETACH_END, true);
+  cilk_sync_begin_fndecl = install_builtin ("__cilk_sync_begin", fptr_fun,
+					  BUILT_IN_CILK_SYNC_BEGIN, true);
+  cilk_sync_end_fndecl = install_builtin ("__cilk_sync_end", fptr_fun,
+					  BUILT_IN_CILK_SYNC_END, true);
+  cilk_leave_begin_fndecl = install_builtin ("__cilk_leave_begin", fptr_fun,
+					     BUILT_IN_CILK_LEAVE_BEGIN, true);
+  cilk_leave_end_fndecl = install_builtin ("__cilk_leave_end", void_fun,
+					   BUILT_IN_CILK_LEAVE_END, true);
+  cilkscreen_metacall_fndecl = install_builtin
+    ("__cilkscreen_metacall", metacall_fptr_fun, BUILT_IN_CILKSCREEN_METACALL,
+     true);
+  cilk_resume_fndecl = install_builtin
+    ("cilk_resume", fptr_fun, BUILT_IN_CILK_RESUME, true);
+  cilk_leave_stolen_fndecl = install_builtin
+    ("cilk_leave_stolen", void_fun, BUILT_IN_LEAVE_STOLEN, true);
+  cilk_sync_abandon_fndecl = install_builtin ("cilk_sync_abandon", void_fun,
+					      BUILT_IN_SYNC_ABANDON, true);
+  cilkscreen_disable_instr_fndecl = install_builtin
+    ("cilkscreen_disable_instrumentation", void_fun,
+     BUILT_IN_CILKSCREEN_DS_INSTR, true);
+  cilkscreen_enable_instr_fndecl = install_builtin
+    ("cilkscreen_enable_instrumentation", void_fun,
+     BUILT_IN_CILKSCREEN_EN_INSTR, true);
+  cilkscreen_disable_check_fndecl = install_builtin
+    ("cilkscreen_disable_checking", void_fun, BUILT_IN_CILKSCREEN_DS_CHK, true);
+  cilkscreen_enable_check_fndecl = install_builtin
+    ("cilkscreen_enable_checking", void_fun, BUILT_IN_CILKSCREEN_EN_CHK, true);
+  cilkscreen_aquire_lock_fndecl = install_builtin
+    ("cilkscreen_aquire_lock", ptr_fun, BUILT_IN_CILKSCREEN_AQUIRE_LOCK, true);
+  cilkscreen_release_lock_fndecl = install_builtin
+    ("cilkscreen_release_lock", ptr_fun, BUILT_IN_CILKSCREEN_REL_LOCK, true);
 }
 
 /* this function will call the value in a structure. eg. x.y */
@@ -665,4 +745,3 @@  gimplify_cilk_sync (tree *expr_p, gimple_seq *pre_p)
 
   gimplify_and_add (sync_expr, pre_p);
 }
-
diff --git a/gcc/cilk.h b/gcc/cilk.h
index 94ce752..cac49f4 100644
--- a/gcc/cilk.h
+++ b/gcc/cilk.h
@@ -58,6 +58,20 @@  enum cilk_tree_index
     CILK_TI_F_LEAVE,         /* __cilkrts_leave_frame() [builtin] */
     CILK_TI_F_DEBUG,         /* __cilkrts_debug_s_frame_flags() */
     CILK_TI_F_POP,           /* __cilkrts_pop_frame() [builtin] */
+    CILK_TI_F_ENTER_BEGIN,  
+    CILK_TI_F_ENTER_H_BEGIN,
+    CILK_TI_F_ENTER_END,
+    CILK_TI_F_SPAWN_PREPARE,
+    CILK_TI_F_SPAWN_OR_CONT,
+    CILK_TI_F_DETACH_BEGIN,
+    CILK_TI_F_DETACH_END,
+    CILK_TI_F_SYNC_BEGIN,
+    CILK_TI_F_SYNC_END,
+    CILK_TI_F_LEAVE_BEGIN,
+    CILK_TI_F_LEAVE_END,
+    CILK_TI_F_RESUME,
+    CILK_TI_F_LEAVE_STOLEN,
+    CILK_TI_F_SYNC_ABANDON,
     CILK_TI_RUN,
     CILK_TI_FREE_DYNAMIC,
     CILK_TI_RUN_SERIAL_VOID,
@@ -75,6 +89,8 @@  enum cilk_tree_index
     CILK_TI_FRAME,         /* __cilkrts_frame_t */
     CILK_TI_FRAME_PTR,     /* __cilkrts_frame_t * restrict */
     CILK_TI_WTYPE,         /* __cilkrts_worker_t */
+    CILK_TI_METACALL_FRAME,
+    CILK_TI_METACALL_FPTR,
 
     
     
@@ -103,6 +119,19 @@  enum cilk_tree_index
     CILK_TI_SAVEDREGS,
     CILK_TI_PENDING_FUNCTIONS,
 
+    /* layout of the fields in metacall struct */
+    CILK_TI_METACALL_TOOL_FLAGS,
+    CILK_TI_METACALL_CODE_FLAGS,
+    CILK_TI_METACALL_DATA_FLAGS,
+
+    /* Cilkscreen functions */
+    CILKSCREEN_TI_F_METACALL,
+    CILKSCREEN_TI_F_DIS_INSTR,
+    CILKSCREEN_TI_F_EN_INSTR,
+    CILKSCREEN_TI_F_DIS_CHECK,
+    CILKSCREEN_TI_F_EN_CHECK,
+    CILKSCREEN_TI_F_AQ_LOCK,
+    CILKSCREEN_TI_F_REL_LOCK,
     CILK_TI_MAX
 };
 
@@ -120,6 +149,8 @@  extern GTY(()) tree cilk_trees[(int) CILK_TI_MAX];
 #define cilk_frame_type_decl		cilk_trees[CILK_TI_FRAME]
 #define cilk_frame_ptr_type_decl	cilk_trees[CILK_TI_FRAME_PTR]
 #define cilk_worker_type_decl		cilk_trees[CILK_TI_WTYPE]
+#define cilk_metacall_frame_type_decl   cilk_trees[CILK_TI_METACALL_FRAME]
+#define cilk_mcall_frame_ptr_type_decl  cilk_trees[CILK_TI_METACALL_FPTR]
 #define cilk_for_32_fndecl		cilk_trees[CILK_TI_F_LOOP_32]
 #define cilk_for_64_fndecl		cilk_trees[CILK_TI_F_LOOP_64]
 #define cilk_enter_fndecl		cilk_trees[CILK_TI_F_ENTER]
@@ -135,6 +166,27 @@  extern GTY(()) tree cilk_trees[(int) CILK_TI_MAX];
 #define cilk_rethrow_fndecl             cilk_trees[CILK_TI_RETHROW]
 #define cilk_throw_fndecl               cilk_trees[CILK_TI_THROW]
 #define cilk_replacement_functions      cilk_trees[CILK_TI_REPLACEMENTS]
+#define cilk_enter_begin_fndecl         cilk_trees[CILK_TI_F_ENTER_BEGIN]
+#define cilk_enter_h_begin_fndecl       cilk_trees[CILK_TI_F_ENTER_H_BEGIN]
+#define cilk_enter_end_fndecl           cilk_trees[CILK_TI_F_ENTER_END]
+#define cilk_spawn_prepare_fndecl       cilk_trees[CILK_TI_F_SPAWN_PREPARE]
+#define cilk_spawn_or_cont_fndecl       cilk_trees[CILK_TI_F_SPAWN_OR_CONT]
+#define cilk_detach_begin_fndecl        cilk_trees[CILK_TI_F_DETACH_BEGIN]
+#define cilk_detach_end_fndecl          cilk_trees[CILK_TI_F_DETACH_END]
+#define cilk_sync_begin_fndecl          cilk_trees[CILK_TI_F_SYNC_BEGIN]
+#define cilk_sync_end_fndecl            cilk_trees[CILK_TI_F_SYNC_END]
+#define cilk_leave_begin_fndecl         cilk_trees[CILK_TI_F_LEAVE_BEGIN]
+#define cilk_leave_end_fndecl           cilk_trees[CILK_TI_F_LEAVE_END]
+#define cilkscreen_metacall_fndecl      cilk_trees[CILKSCREEN_TI_F_METACALL]
+#define cilk_resume_fndecl              cilk_trees[CILK_TI_F_RESUME]
+#define cilk_leave_stolen_fndecl        cilk_trees[CILK_TI_F_LEAVE_STOLEN]
+#define cilk_sync_abandon_fndecl        cilk_trees[CILK_TI_F_SYNC_ABANDON]
+#define cilkscreen_disable_instr_fndecl cilk_trees[CILKSCREEN_TI_F_DIS_INSTR]
+#define cilkscreen_enable_instr_fndecl  cilk_trees[CILKSCREEN_TI_F_EN_INSTR]
+#define cilkscreen_disable_check_fndecl cilk_trees[CILKSCREEN_TI_F_DIS_CHECK]
+#define cilkscreen_enable_check_fndecl  cilk_trees[CILKSCREEN_TI_F_EN_CHECK]
+#define cilkscreen_aquire_lock_fndecl   cilk_trees[CILKSCREEN_TI_F_AQ_LOCK]
+#define cilkscreen_release_lock_fndecl  cilk_trees[CILKSCREEN_TI_F_REL_LOCK]
 
 
 /* Offset of fields in the Cilk frame descriptor.