Skip to content

Commit

Permalink
i#1569 AArch64: Create clean_call_opt_shared.c and refactor.
Browse files Browse the repository at this point in the history
About half of x86/clean_call_opt.c is moved to clean_call_opt_shared.c
with minor changes. Prototypes for a new internal API are in
clean_call_opt.h and {aarch64,arm}/clean_call_opt.c are rewritten
accordingly with ASSERT_NOT_IMPLEMENTED in function bodies.

This is based on work done by Kevin Zhou in July.

Review-URL: https://codereview.appspot.com/311330043
  • Loading branch information
egrimley-arm committed Dec 8, 2016
1 parent e2e27e0 commit 7ff49b0
Show file tree
Hide file tree
Showing 7 changed files with 1,078 additions and 881 deletions.
1 change: 1 addition & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ set(ARCH_SRCS
arch/${ARCH_NAME}/proc.c
arch/mangle_shared.c
arch/${ARCH_NAME_SHARED}/mangle.c
arch/clean_call_opt_shared.c
arch/${ARCH_NAME}/clean_call_opt.c
arch/steal_reg.c
arch/x86_code.c
Expand Down
68 changes: 43 additions & 25 deletions core/arch/aarch64/clean_call_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,72 @@
* DAMAGE.
*/

/* file "clean_call_opt.c" */

#include "../globals.h"
#include "arch.h"

#ifdef CLIENT_INTERFACE

static void
callee_info_init(callee_info_t *ci)
void
analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
{
memset(ci, 0, sizeof(*ci));
ci->bailout = true;
/* to be conservative */
ci->has_locals = true;
ci->write_flags = true;
ci->read_flags = true;
ci->tls_used = true;
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

void
clean_call_opt_init(void)
analyze_callee_save_reg(dcontext_t *dcontext, callee_info_t *ci)
{
/* FIXME i#1569: NYI on AArch64 */
ASSERT_NOT_IMPLEMENTED(INTERNAL_OPTION(opt_cleancall) == 0);
callee_info_init(&default_callee_info);
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

void
clean_call_opt_exit(void)
analyze_callee_tls(dcontext_t *dcontext, callee_info_t *ci)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

app_pc
check_callee_instr_level2(dcontext_t *dcontext, callee_info_t *ci, app_pc next_pc,
app_pc cur_pc, app_pc tgt_pc)
{
/* FIXME i#1569: NYI on AArch64 */
ASSERT_NOT_IMPLEMENTED(INTERNAL_OPTION(opt_cleancall) == 0);
/* FIXME i#1569: For opt level greater than 1, we abort. */
return NULL;
}

bool
analyze_clean_call(dcontext_t *dcontext, clean_call_info_t *cci, instr_t *where,
void *callee, bool save_fpstate, bool always_out_of_line,
uint num_args, opnd_t *args)
check_callee_ilist_inline(dcontext_t *dcontext, callee_info_t *ci)
{
/* FIXME i#1569: NYI on AArch64 */
ASSERT_NOT_IMPLEMENTED(INTERNAL_OPTION(opt_cleancall) == 0);
clean_call_info_init(cci, callee, save_fpstate, num_args);
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
return false;
}

void
insert_inline_clean_call(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args)
analyze_clean_call_aflags(dcontext_t *dcontext,
clean_call_info_t *cci, instr_t *where)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

void
insert_inline_reg_save(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

void
insert_inline_reg_restore(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

void
insert_inline_arg_setup(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569 */
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#1569: NYI on AArch64 */
}

#endif /* CLIENT_INTERFACE */
2 changes: 1 addition & 1 deletion core/arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ typedef struct _callee_info_t {
extern callee_info_t default_callee_info;
extern clean_call_info_t default_clean_call_info;

/* in clean_call_opt.c */
/* in clean_call_opt_shared.c */
#ifdef CLIENT_INTERFACE
void
clean_call_opt_init(void);
Expand Down
74 changes: 43 additions & 31 deletions core/arch/arm/clean_call_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,60 +30,72 @@
* DAMAGE.
*/

/* file "cleancallopt.c" */
/* file "clean_call_opt.c" */

#include "../globals.h"
#include "arch.h"
#include "instrument.h"
#include "../hashtable.h"
#include "disassemble.h"
#include "instr_create.h"

#ifdef CLIENT_INTERFACE

static void
callee_info_init(callee_info_t *ci)
void
analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
{
memset(ci, 0, sizeof(*ci));
ci->bailout = true;
/* to be conservative */
ci->has_locals = true;
ci->write_flags = true;
ci->read_flags = true;
ci->tls_used = true;
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

void
clean_call_opt_init(void)
analyze_callee_save_reg(dcontext_t *dcontext, callee_info_t *ci)
{
/* FIXME i#1551: NYI on ARM */
ASSERT_NOT_IMPLEMENTED(INTERNAL_OPTION(opt_cleancall) == 0);
callee_info_init(&default_callee_info);
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

void
clean_call_opt_exit(void)
analyze_callee_tls(dcontext_t *dcontext, callee_info_t *ci)
{
/* FIXME i#1551: NYI on ARM */
ASSERT_NOT_IMPLEMENTED(INTERNAL_OPTION(opt_cleancall) == 0);
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

app_pc
check_callee_instr_level2(dcontext_t *dcontext, callee_info_t *ci, app_pc next_pc,
app_pc cur_pc, app_pc tgt_pc)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
return NULL;
}

bool
analyze_clean_call(dcontext_t *dcontext, clean_call_info_t *cci, instr_t *where,
void *callee, bool save_fpstate, bool always_out_of_line,
uint num_args, opnd_t *args)
check_callee_ilist_inline(dcontext_t *dcontext, callee_info_t *ci)
{
/* FIXME i#1551: NYI on ARM */
ASSERT_NOT_IMPLEMENTED(INTERNAL_OPTION(opt_cleancall) == 0);
clean_call_info_init(cci, callee, save_fpstate, num_args);
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
return false;
}

void
insert_inline_clean_call(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args)
analyze_clean_call_aflags(dcontext_t *dcontext,
clean_call_info_t *cci, instr_t *where)
{
/* FIXME i#1551: NYI on ARM */
ASSERT_NOT_REACHED();
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

void
insert_inline_reg_save(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

void
insert_inline_reg_restore(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

void
insert_inline_arg_setup(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args)
{
ASSERT_NOT_IMPLEMENTED(false); /* FIXME i#2094: NYI on ARM */
}

#endif /* CLIENT_INTERFACE */
84 changes: 84 additions & 0 deletions core/arch/clean_call_opt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* **********************************************************
* Copyright (c) 2016 ARM Limited. All rights reserved.
* **********************************************************/

/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of ARM Limited nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL ARM LIMITED OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

/* file "clean_call_opt.h" - arch-specific clean call optimisation */

#ifndef _CLEAN_CALL_OPT_
#define _CLEAN_CALL_OPT_ 1

/****************************************************************************
* Functions provided by clean_call_opt_shared.c.
*/

void
callee_info_reserve_slot(callee_info_t *ci, slot_kind_t kind, reg_id_t value);

opnd_t
callee_info_slot_opnd(callee_info_t *ci, slot_kind_t kind, reg_id_t value);

/****************************************************************************
* Functions implemented in arch-specific clean_call_opt.c.
*/

void
analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci);

void
analyze_callee_save_reg(dcontext_t *dcontext, callee_info_t *ci);

void
analyze_callee_tls(dcontext_t *dcontext, callee_info_t *ci);

app_pc
check_callee_instr_level2(dcontext_t *dcontext, callee_info_t *ci, app_pc next_pc,
app_pc cur_pc, app_pc tgt_pc);

bool
check_callee_ilist_inline(dcontext_t *dcontext, callee_info_t *ci);

void
analyze_clean_call_aflags(dcontext_t *dcontext,
clean_call_info_t *cci, instr_t *where);

void
insert_inline_reg_save(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args);

void
insert_inline_reg_restore(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where);

void
insert_inline_arg_setup(dcontext_t *dcontext, clean_call_info_t *cci,
instrlist_t *ilist, instr_t *where, opnd_t *args);

#endif /* _CLEAN_CALL_OPT_ */
Loading

0 comments on commit 7ff49b0

Please sign in to comment.