+ }
+
+ if (mode)
+ set_irg_additional_property(irg, mode);
+ current_ir_graph = rem;
+ return mode;
+} /* is_pure_function */
+
+/**
+ * Handle calls to const functions.
+ */
+static void handle_const_Calls(env_t *ctx)
+{
+ int i;
+
+ ctx->n_calls_removed_SymConst = 0;
+ ctx->n_calls_removed_Sel = 0;
+
+ /* all calls of const functions can be transformed */
+ for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
+ ir_graph *irg = get_irp_irg(i);
+
+ ctx->const_call_list = NULL;
+ ctx->pure_call_list = NULL;
+ ctx->proj_list = NULL;
+ irg_walk_graph(irg, NULL, collect_calls, ctx);
+
+ if (ctx->const_call_list)
+ fix_const_call_list(irg, ctx->const_call_list, ctx->proj_list);
+ }
+} /* handle_const_Calls */
+
+/*
+ * optimize function calls by handling const functions
+ */
+void optimize_funccalls(int force_run)
+{
+ int i, n;
+ unsigned num_const = 0;
+ unsigned num_pure = 0;
+
+ if (! get_opt_function_call())
+ return;
+
+ /* prepare: mark all graphs as not analyzed */
+ n = get_irp_n_irgs();
+ for (i = n - 1; i >= 0; --i)
+ MARK_IRG(get_irp_irg(i));
+
+ /* first step: detect, which functions are const, i.e. do NOT touch any memory */
+ for (i = n - 1; i >= 0; --i) {
+ ir_graph *irg = get_irp_irg(i);
+ unsigned mode = is_pure_function(irg);
+
+ if (mode & mtp_property_const)
+ ++num_const;
+ else if (mode & mtp_property_pure)
+ ++num_pure;
+ }
+
+ if (force_run || num_const > 0) {
+ env_t ctx;