FS_OPT_RTS_SYMMETRIC, /**< RTS optimization: call to symmetric function f(-x) replaced by f(x) */
FS_OPT_RTS_STRCMP, /**< RTS optimization: call to strcmp() replaced */
FS_OPT_RTS_STRNCMP, /**< RTS optimization: call to strncmp() replaced */
+ FS_OPT_RTS_STRCPY, /**< RTS optimization: call to strcpy() replaced */
+ FS_OPT_RTS_STRLEN, /**< RTS optimization: call to strlen() replaced */
FS_OPT_RTS_MEMCPY, /**< RTS optimization: call to memcpy() replaced */
+ FS_OPT_RTS_MEMPCPY, /**< RTS optimization: call to mempcpy() replaced */
+ FS_OPT_RTS_MEMMOVE, /**< RTS optimization: call to memmove() replaced */
FS_OPT_RTS_MEMSET, /**< RTS optimization: call to memset() replaced */
- FS_OPT_RTS_STRLEN, /**< RTS optimization: call to strlen() replaced */
+ FS_OPT_RTS_MEMCMP, /**< RTS optimization: call to memcmp() replaced */
FS_BE_IA32_LEA, /**< Lea was created */
FS_BE_IA32_LOAD_LEA, /**< Load merged with a Lea */
FS_BE_IA32_STORE_LEA, /**< Store merged with a Lea */
*/
int i_mapper_strncmp(ir_node *call, void *ctx);
+/**
+ * A mapper for the strcpy-Function: char pointer strcpy(char pointer a, char pointer b);
+ *
+ * @return 0 if the strcpy call was removed, 0 else.
+ */
+int i_mapper_strcpy(ir_node *call, void *ctx);
+
/**
* A mapper for the strlen-Function: inttype strlen(char pointer a);
*
*/
int i_mapper_memcpy(ir_node *call, void *ctx);
+/**
+ * A mapper for the mempcpy-Function: void pointer mempcpy(void pointer d, void pointer s, inttype c);
+ *
+ * @return 0 if the mempcpy call was removed, 0 else.
+ */
+int i_mapper_mempcpy(ir_node *call, void *ctx);
+
+/**
+ * A mapper for the memmove-Function: void pointer memmove(void pointer d, void pointer s, inttype c);
+ *
+ * @return 0 if the memmove call was removed, 0 else.
+ */
+int i_mapper_memmove(ir_node *call, void *ctx);
+
/**
* A mapper for the memset-Function: void pointer memset(void pointer d, inttype C, inttype len);
*
*/
int i_mapper_memset(ir_node *call, void *ctx);
+/**
+ * A mapper for the strncmp-Function: inttype memcmp(void pointer a, void pointer b, inttype len);
+ *
+ * @return 0 if the strncmp call was removed, 0 else.
+ */
+int i_mapper_memcmp(ir_node *call, void *ctx);
+
/**
* A mapper for the alloca() function: pointer alloca(inttype size)
* Replaces the call by a Alloca(stack_alloc) node.
return 0;
} /* i_mapper_strncmp */
+/* A mapper for strcpy */
+int i_mapper_strcpy(ir_node *call, void *ctx) {
+ ir_node *dst = get_Call_param(call, 0);
+ ir_node *src = get_Call_param(call, 1);
+ (void) ctx;
+
+ if (dst == src) {
+ /* a strcpy(d, s) ==> d */
+ ir_node *mem = get_Call_mem(call);
+ ir_node *dst = get_Call_param(call, 0);
+
+ DBG_OPT_ALGSIM0(call, dst, FS_OPT_RTS_STRCPY);
+ replace_call(dst, call, mem, NULL, NULL);
+ return 1;
+ }
+ return 0;
+} /* i_mapper_strcpy */
+
/* A mapper for memcpy */
int i_mapper_memcpy(ir_node *call, void *ctx) {
+ ir_node *dst = get_Call_param(call, 0);
+ ir_node *src = get_Call_param(call, 1);
ir_node *len = get_Call_param(call, 2);
(void) ctx;
- if (is_Const(len) && is_Const_null(len)) {
+ if (dst == src || (is_Const(len) && is_Const_null(len))) {
+ /* a memcpy(d, d, len) ==> d OR
/* a memcpy(d, s, 0) ==> d */
ir_node *mem = get_Call_mem(call);
- ir_node *dst = get_Call_param(call, 0);
DBG_OPT_ALGSIM0(call, dst, FS_OPT_RTS_MEMCPY);
replace_call(dst, call, mem, NULL, NULL);
return 0;
} /* i_mapper_memcpy */
+/* A mapper for mempcpy */
+int i_mapper_mempcpy(ir_node *call, void *ctx) {
+ ir_node *dst = get_Call_param(call, 0);
+ ir_node *src = get_Call_param(call, 1);
+ ir_node *len = get_Call_param(call, 2);
+ (void) ctx;
+
+ if (dst == src || (is_Const(len) && is_Const_null(len))) {
+ /* a memcpy(d, d, len) ==> d + len OR
+ /* a memcpy(d, s, 0) ==> d + 0 */
+ dbg_info *dbg = get_irn_dbg_info(call);
+ ir_node *mem = get_Call_mem(call);
+ ir_node *blk = get_nodes_block(call);
+ ir_mode *mode = get_irn_mode(dst);
+ ir_node *res = new_rd_Add(dbg, get_irn_irg(blk), blk, dst, len, mode);
+
+ DBG_OPT_ALGSIM0(call, res, FS_OPT_RTS_MEMPCPY);
+ replace_call(res, call, mem, NULL, NULL);
+ return 1;
+ }
+ return 0;
+} /* i_mapper_mempcpy */
+
+/* A mapper for memmove */
+int i_mapper_memmove(ir_node *call, void *ctx) {
+ ir_node *dst = get_Call_param(call, 0);
+ ir_node *src = get_Call_param(call, 1);
+ ir_node *len = get_Call_param(call, 2);
+ (void) ctx;
+
+ if (dst == src || (is_Const(len) && is_Const_null(len))) {
+ /* a memmove(d, d, len) ==> d OR
+ /* a memmove(d, s, 0) ==> d */
+ ir_node *mem = get_Call_mem(call);
+
+ DBG_OPT_ALGSIM0(call, dst, FS_OPT_RTS_MEMMOVE);
+ replace_call(dst, call, mem, NULL, NULL);
+ return 1;
+ }
+ return 0;
+} /* i_mapper_memmove */
+
/* A mapper for memset */
int i_mapper_memset(ir_node *call, void *ctx) {
ir_node *len = get_Call_param(call, 2);
return 0;
} /* i_mapper_memset */
+/* A mapper for memcmp */
+int i_mapper_memcmp(ir_node *call, void *ctx) {
+ ir_node *left = get_Call_param(call, 0);
+ ir_node *right = get_Call_param(call, 1);
+ ir_node *len = get_Call_param(call, 2);
+ ir_node *irn;
+ (void) ctx;
+
+ if (left == right || (is_Const(len) && is_Const_null(len))) {
+ /* a memcmp(s, s, len) ==> 0 OR
+ a memcmp(a, b, 0) ==> 0 */
+ ir_node *mem = get_Call_mem(call);
+ ir_node *adr = get_Call_ptr(call);
+ ir_entity *ent = get_SymConst_entity(adr);
+ ir_type *call_tp = get_entity_type(ent);
+ ir_type *res_tp = get_method_res_type(call_tp, 0);
+ ir_mode *mode = get_type_mode(res_tp);
+
+ irn = new_Const(get_mode_null(mode));
+ DBG_OPT_ALGSIM0(call, irn, FS_OPT_RTS_STRNCMP);
+ replace_call(irn, call, mem, NULL, NULL);
+ return 1;
+ }
+ return 0;
+} /* i_mapper_memcmp */
+
/**
* Returns the result mode of a node.
*/
{ FS_OPT_RTS_SYMMETRIC, "RTS optimization: call to symmetric function f(-x) replaced by f(x)" },
{ FS_OPT_RTS_STRCMP, "RTS optimization: call to strcmp() replaced" },
{ FS_OPT_RTS_STRNCMP, "RTS optimization: call to strncmp() replaced" },
+ { FS_OPT_RTS_STRCPY, "RTS optimization: call to strcpy() replaced" },
+ { FS_OPT_RTS_STRLEN, "RTS optimization: call to strlen() replaced" },
{ FS_OPT_RTS_MEMCPY, "RTS optimization: call to memcpy() replaced" },
+ { FS_OPT_RTS_MEMPCPY, "RTS optimization: call to mempcpy() replaced" },
+ { FS_OPT_RTS_MEMMOVE, "RTS optimization: call to memmove() replaced" },
{ FS_OPT_RTS_MEMSET, "RTS optimization: call to memset() replaced" },
- { FS_OPT_RTS_STRLEN, "RTS optimization: call to strlen() replaced" },
+ { FS_OPT_RTS_MEMCMP, "RTS optimization: call to memcmp() replaced" },
{ FS_BE_IA32_LEA, "ia32 Backend transformation: Lea was created" },
{ FS_BE_IA32_LOAD_LEA, "ia32 Backend transformation: Load merged with a Lea" },
{ FS_BE_IA32_STORE_LEA, "ia32 Backend transformation: Store merged with a Lea" },