Skip to content

Commit

Permalink
[dfmc] Propagate not-inline to generated code.
Browse files Browse the repository at this point in the history
When a function is flagged as not-inline in Dylan, it is useful for
that information to be passed along to C and LLVM to prevent it from
being inlined during code generation.

This is particularly useful in tests where you want to prevent the
compiler from optimizing away the thing that you're testing.

* sources/dfmc/llvm-back-end/llvm-emit-code.dylan
  (llvm-function-attributes): New.
  (emit-code): Get function attributes and pass them along to the
   <llvm-function>.

* sources/dfmc/c-back-end/c-emit-object.dylan
  (emit-lambda-interface-using-function): Pass not-inline along to
   the generated C function.

* sources/lib/run-time/run-time.h
  (OPEN_DYLAN_NO_INLINE): New portability macro.
  • Loading branch information
waywardmonkeys committed Apr 12, 2015
1 parent 4d5402c commit 823ee0e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions documentation/release-notes/source/2015.1.rst
Expand Up @@ -66,6 +66,9 @@ Compiler
* Previously, ``define domain`` was accepted without warning. This is
not valid Dylan syntax as it should be ``define sealed domain``.

* Dylan functions that are marked as ``not-inline`` now take that into
account when generating code in the LLVM and C back-ends.

Documentation
=============

Expand Down
4 changes: 4 additions & 0 deletions sources/dfmc/c-back-end/c-emit-object.dylan
Expand Up @@ -657,6 +657,10 @@ define method emit-lambda-interface-using-function
unless (external-lambda?(fun))
write(stream, "static ");
end;
let form = fn.model-definition;
if (form & form.form-inline-policy == #"not-inline")
write(stream, "OPEN_DYLAN_NO_INLINE ");
end if;
emit-return-types(back-end, stream, o);
format-emit*(back-end, stream, " ^ ", o);
let sig = ^function-signature(fn);
Expand Down
20 changes: 20 additions & 0 deletions sources/dfmc/llvm-back-end/llvm-emit-code.dylan
Expand Up @@ -138,6 +138,7 @@ define method emit-code
arguments: concatenate(arguments,
extra,
calling-convention-parameters),
attribute-list: llvm-function-attributes(back-end, o),
linkage: linkage,
section: llvm-section-name(back-end, section),
calling-convention:
Expand Down Expand Up @@ -237,3 +238,22 @@ define method llvm-calling-convention
$llvm-calling-convention-c
end method;

define method llvm-function-attributes
(back-end :: <llvm-back-end>, o :: <&iep>)
=> (attributes :: <llvm-attribute-list>)
let function-attributes = $llvm-attribute-none;
let parameter-attributes = #[];
let return-attributes = $llvm-attribute-none;
let form = o.function.model-definition;
if (form)
select (form.form-inline-policy)
#"not-inline" =>
function-attributes := llvm-attribute-merge(function-attributes, $llvm-attribute-noinline);
otherwise =>
end select;
end if;
make(<llvm-attribute-list>,
return-attributes: return-attributes,
function-attributes: function-attributes,
parameter-attributes: parameter-attributes)
end method;
7 changes: 7 additions & 0 deletions sources/lib/run-time/run-time.h
Expand Up @@ -92,6 +92,13 @@ typedef void* D;

/* COMPILER-SPECIFIC INTRINSICS */


#ifdef OPEN_DYLAN_COMPILER_GCC_LIKE
# define OPEN_DYLAN_NO_INLINE __attribute__((noinline))
#else
# define OPEN_DYLAN_NO_INLINE
#endif

#ifdef OPEN_DYLAN_COMPILER_GCC_LIKE
# define NORETURN_FUNCTION __attribute__((noreturn))
#else
Expand Down

0 comments on commit 823ee0e

Please sign in to comment.