# HG changeset patch # User Julien Bect # Date 1507363156 -7200 # Node ID e622b58d78a2ac8bb45c76e764285930bb936acb # Parent 8d8e4d8e6fdc59670d61195fec1cc58e2af6113b jit: Get rid of residual calls to OCT_MAKE_DECL_LIST and OCT_ITERATE_MACRO * libinterp/parse-tree/jit-ir.h: Get rid of residual calls to OCT_MAKE_DECL_LIST and OCT_ITERATE_MACRO. * libinterp/parse-tree/jit-typeinfo.h: Idem. * libinterp/parse-tree/jit-util.h: Idem. * libinterp/parse-tree/pt-jit.h: Idem. diff -r 8d8e4d8e6fdc -r e622b58d78a2 libinterp/parse-tree/jit-ir.h --- a/libinterp/parse-tree/jit-ir.h Tue Oct 17 07:13:28 2017 +0200 +++ b/libinterp/parse-tree/jit-ir.h Sat Oct 07 09:59:16 2017 +0200 @@ -109,33 +109,14 @@ const value_list& constants (void) const { return mconstants; } - template - T * create (void) + template + T * create (const Args&... args) { - T *ret = new T (); + T *ret = new T (args...); track_value (ret); return ret; } -#define DECL_ARG(n) const ARG ## n& arg ## n - -#define JIT_CREATE(N) \ - template \ - T * create (OCT_MAKE_LIST (DECL_ARG, N)) \ - { \ - T *ret = new T (OCT_MAKE_ARG_LIST (arg, N)); \ - track_value (ret); \ - return ret; \ - } - - JIT_CREATE (1) - JIT_CREATE (2) - JIT_CREATE (3) - JIT_CREATE (4) - -#undef JIT_CREATE -#undef DECL_ARG - private: void track_value (jit_value *v); @@ -344,23 +325,15 @@ marguments.reserve (nargs); } -#define STASH_ARG(i) stash_argument (i, arg ## i); - -#define JIT_INSTRUCTION_CTOR(N) \ - jit_instruction (OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ - : already_infered (N), marguments (N), mid (next_id ()), mparent (0) \ - { \ - OCT_ITERATE_MACRO (STASH_ARG, N); \ + template + jit_instruction (jit_value * arg1, Args... other_args) + : already_infered (1 + sizeof... (other_args)), + marguments (1 + sizeof... (other_args)), + mid (next_id ()), mparent (nullptr) + { + stash_argument (0, arg1, other_args...); } - JIT_INSTRUCTION_CTOR(1) - JIT_INSTRUCTION_CTOR(2) - JIT_INSTRUCTION_CTOR(3) - JIT_INSTRUCTION_CTOR(4) - -#undef STASH_ARG -#undef JIT_INSTRUCTION_CTOR - jit_instruction (const std::vector& aarguments) : already_infered (aarguments.size ()), marguments (aarguments.size ()), mid (next_id ()), mparent (0) @@ -404,11 +377,18 @@ return os << "NULL"; } - void stash_argument (size_t i, jit_value *arg) + void stash_argument (size_t i, jit_value * arg) { marguments[i].stash_value (arg, this, i); } + template + void stash_argument (size_t i, jit_value * arg1, Args... aargs) + { + marguments[i].stash_value (arg1, this, i); + stash_argument (++i, aargs...); + } + void push_argument (jit_value *arg) { marguments.push_back (jit_use ()); @@ -1029,18 +1009,11 @@ { public: -#define JIT_TERMINATOR_CONST(N) \ - jit_terminator (size_t asuccessor_count, \ - OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ - : jit_instruction (OCT_MAKE_ARG_LIST (arg, N)), \ + template + jit_terminator (size_t asuccessor_count, Args... args) + : jit_instruction (args...), malive (asuccessor_count, false) { } - JIT_TERMINATOR_CONST (1) - JIT_TERMINATOR_CONST (2) - JIT_TERMINATOR_CONST (3) - -#undef JIT_TERMINATOR_CONST - jit_block * successor (size_t idx = 0) const { return static_cast (argument (idx)); @@ -1152,22 +1125,17 @@ stash_type (ol.result ()); } -#define JIT_CALL_CONST(N) \ - jit_call (const jit_operation& aoperation, \ - OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ - : jit_instruction (OCT_MAKE_ARG_LIST (arg, N)), moperation (aoperation) { } \ - \ - jit_call (const jit_operation& (*aoperation) (void), \ - OCT_MAKE_DECL_LIST (jit_value *, arg, N)) \ - : jit_instruction (OCT_MAKE_ARG_LIST (arg, N)), moperation (aoperation ()) \ + template + jit_call (const jit_operation& aoperation, + jit_value * arg1, Args... other_args) + : jit_instruction (arg1, other_args...), moperation (aoperation) { } - JIT_CALL_CONST (1) - JIT_CALL_CONST (2) - JIT_CALL_CONST (3) - JIT_CALL_CONST (4) - -#undef JIT_CALL_CONST + template + jit_call (const jit_operation& (*aoperation) (void), + jit_value * arg1, Args... other_args) + : jit_instruction (arg1, other_args...), moperation (aoperation ()) + { } jit_call (const jit_operation& aoperation, const std::vector& args) diff -r 8d8e4d8e6fdc -r e622b58d78a2 libinterp/parse-tree/jit-typeinfo.h --- a/libinterp/parse-tree/jit-typeinfo.h Tue Oct 17 07:13:28 2017 +0200 +++ b/libinterp/parse-tree/jit-typeinfo.h Sat Oct 07 09:59:16 2017 +0200 @@ -255,34 +255,49 @@ llvm::BasicBlock * new_block (const std::string& aname = "body", llvm::BasicBlock *insert_before = nullptr); + typedef std::vector arg_vec; + + llvm::Value * call (llvm::IRBuilderD& builder, + const arg_vec& in_args = arg_vec ()) const; + llvm::Value * call (llvm::IRBuilderD& builder, const std::vector& in_args) const; - llvm::Value * call (llvm::IRBuilderD& builder, - const std::vector& in_args - = std::vector ()) const; + template + llvm::Value * call (llvm::IRBuilderD& builder, arg_vec& in_args, + llvm::Value * arg1, Args... other_args) const + { + in_args.push_back (arg1); + return call (builder, in_args, other_args...); + } -#define JIT_PARAM_ARGS llvm::IRBuilderD& builder, -#define JIT_PARAMS builder, -#define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, llvm::Value *, const, N) + template + llvm::Value * call (llvm::IRBuilderD& builder, arg_vec& in_args, + T * arg1, Args... other_args) const + { + in_args.push_back (arg1->to_llvm ()); + return call (builder, in_args, other_args...); + } - JIT_CALL (1) - JIT_CALL (2) - JIT_CALL (3) - JIT_CALL (4) - JIT_CALL (5) - -#undef JIT_CALL + template + llvm::Value * call (llvm::IRBuilderD& builder, llvm::Value * arg1, + Args... other_args) const + { + arg_vec in_args; + in_args.reserve (1 + sizeof... (other_args)); + in_args.push_back (arg1); + return call (builder, in_args, other_args...); + } -#define JIT_CALL(N) JIT_EXPAND (llvm::Value *, call, jit_value *, const, N) - - JIT_CALL (1); - JIT_CALL (2); - JIT_CALL (3); - -#undef JIT_CALL -#undef JIT_PARAMS -#undef JIT_PARAM_ARGS + template + llvm::Value * call (llvm::IRBuilderD& builder, T * arg1, + Args... other_args) const + { + arg_vec in_args; + in_args.reserve (1 + sizeof... (other_args)); + in_args.push_back (arg1->to_llvm ()); + return call (builder, in_args, other_args...); + } llvm::Value * argument (llvm::IRBuilderD& builder, size_t idx) const; @@ -341,24 +356,45 @@ const jit_function& overload (const signature_vec& types) const; + template + const jit_function& overload (signature_vec& args, jit_type * arg1, + Args... other_args) const + { + args.push_back (arg1); + return overload (args, other_args...); + } + + template + const jit_function& overload (jit_type * arg1, Args... other_args) const + { + signature_vec args; + args.reserve (1 + sizeof... (other_args)); + args.push_back (arg1); + return overload (args, other_args...); + } + jit_type * result (const signature_vec& types) const { const jit_function& temp = overload (types); return temp.result (); } -#define JIT_PARAMS -#define JIT_PARAM_ARGS -#define JIT_OVERLOAD(N) \ - JIT_EXPAND (const jit_function&, overload, jit_type *, const, N) \ - JIT_EXPAND (jit_type *, result, jit_type *, const, N) + template + jit_type * result (signature_vec& args, jit_type * arg1, + Args... other_args) const + { + args.push_back (arg1); + return overload (args, other_args...); + } - JIT_OVERLOAD (1); - JIT_OVERLOAD (2); - JIT_OVERLOAD (3); - -#undef JIT_PARAMS -#undef JIT_PARAM_ARGS + template + jit_type * result (jit_type * arg1, Args... other_args) const + { + signature_vec args; + args.reserve (1 + sizeof... (other_args)); + args.push_back (arg1); + return overload (args, other_args...); + } const std::string& name (void) const { return mname; } @@ -679,13 +715,16 @@ void add_binary_fcmp (jit_type *ty, int op, int llvm_op); + // type signature vector + typedef std::vector signature_vec; + // create a function with an external calling convention // forces the function pointer to be specified template jit_function create_external (llvm::ExecutionEngine *ee, T fn, const llvm::Twine& name, jit_type *ret, - const std::vector& args - = std::vector ()) + const signature_vec& args + = signature_vec ()) { jit_function retval = create_function (jit_convention::external, name, ret, args); @@ -693,21 +732,26 @@ return retval; } -#define JIT_PARAM_ARGS llvm::ExecutionEngine *ee, T fn, \ - const llvm::Twine& name, jit_type *ret, -#define JIT_PARAMS ee, fn, name, ret, -#define CREATE_FUNCTION(N) JIT_EXPAND(template jit_function, \ - create_external, \ - jit_type *, /* empty */, N) + template + jit_function create_external (llvm::ExecutionEngine *ee, T fn, + const llvm::Twine& name, jit_type *ret, + signature_vec& args, jit_type * arg1, + Args... other_args) + { + args.push_back (arg1); + return create_external (ee, fn, name, ret, args, other_args...); + } - CREATE_FUNCTION(1); - CREATE_FUNCTION(2); - CREATE_FUNCTION(3); - CREATE_FUNCTION(4); - -#undef JIT_PARAM_ARGS -#undef JIT_PARAMS -#undef CREATE_FUNCTION + template + jit_function create_external (llvm::ExecutionEngine *ee, T fn, + const llvm::Twine& name, jit_type *ret, + jit_type * arg1, Args... other_args) + { + signature_vec args; + args.reserve (1 + sizeof... (other_args)); + args.push_back (arg1); + return create_external (ee, fn, name, ret, args, other_args...); + } // use create_external or create_internal directly jit_function create_function (jit_convention::type cc, @@ -717,25 +761,30 @@ // create an internal calling convention (a function defined in llvm) jit_function create_internal (const llvm::Twine& name, jit_type *ret, - const std::vector& args - = std::vector ()) + const signature_vec& args + = signature_vec ()) { return create_function (jit_convention::internal, name, ret, args); } -#define JIT_PARAM_ARGS const llvm::Twine& name, jit_type *ret, -#define JIT_PARAMS name, ret, -#define CREATE_FUNCTION(N) JIT_EXPAND(jit_function, create_internal, \ - jit_type *, /* empty */, N) + template + jit_function create_internal (const llvm::Twine& name, jit_type *ret, + signature_vec& args, + jit_type * arg1, Args... other_args) + { + args.push_back (arg1); + return create_internal (name, ret, args, other_args...); + } - CREATE_FUNCTION(1); - CREATE_FUNCTION(2); - CREATE_FUNCTION(3); - CREATE_FUNCTION(4); - -#undef JIT_PARAM_ARGS -#undef JIT_PARAMS -#undef CREATE_FUNCTION + template + jit_function create_internal (const llvm::Twine& name, jit_type *ret, + jit_type * arg1, Args... other_args) + { + signature_vec args; + args.reserve (1 + sizeof... (other_args)); + args.push_back (arg1); + return create_internal (name, ret, args, other_args...); + } jit_function create_identity (jit_type *type); diff -r 8d8e4d8e6fdc -r e622b58d78a2 libinterp/parse-tree/jit-util.h --- a/libinterp/parse-tree/jit-util.h Tue Oct 17 07:13:28 2017 +0200 +++ b/libinterp/parse-tree/jit-util.h Sat Oct 07 09:59:16 2017 +0200 @@ -206,14 +206,5 @@ return dynamic_cast (value); } -#define JIT_ASSIGN_ARG(i) the_args[i] = arg ## i; -#define JIT_EXPAND(ret, fname, type, isconst, N) \ - ret fname (JIT_PARAM_ARGS OCT_MAKE_DECL_LIST (type, arg, N)) isconst \ - { \ - std::vector the_args (N); \ - OCT_ITERATE_MACRO (JIT_ASSIGN_ARG, N); \ - return fname (JIT_PARAMS the_args); \ - } - #endif #endif diff -r 8d8e4d8e6fdc -r e622b58d78a2 libinterp/parse-tree/pt-jit.h --- a/libinterp/parse-tree/pt-jit.h Tue Oct 17 07:13:28 2017 +0200 +++ b/libinterp/parse-tree/pt-jit.h Sat Oct 07 09:59:16 2017 +0200 @@ -48,23 +48,13 @@ jit_convert (octave_user_function& fcn, const std::vector& args); -#define DECL_ARG(n) const ARG ## n& arg ## n -#define JIT_CREATE_CHECKED(N) \ - template \ - jit_call * create_checked (OCT_MAKE_LIST (DECL_ARG, N)) \ - { \ - jit_call *ret = factory.create (OCT_MAKE_ARG_LIST (arg, N)); \ - return create_checked_impl (ret); \ + template + jit_call * create_checked (const Args&... args) + { + jit_call *ret = factory.create (args...); + return create_checked_impl (ret); } - JIT_CREATE_CHECKED (1) - JIT_CREATE_CHECKED (2) - JIT_CREATE_CHECKED (3) - JIT_CREATE_CHECKED (4) - -#undef JIT_CREATE_CHECKED -#undef DECL_ARG - jit_block_list& get_blocks (void) { return blocks; } const type_bound_vector& get_bounds (void) const { return bounds; }