Commits
Roman Levenstein committed 2956e5675f7
Update x-macro metaprogramming support in IRGenModule.
Teach IRGen how to handle runtime functions definitions in RuntimeFunctions.def
depending on their calling convention and on their need for global symbols referring
to their internal implementations.
IRGen would now generate wrappers for runtime functions invocations if at least one
of the following conditions is met:
- The runtime function is defined using FUNCTION_WITH_GLOBAL_SYMBOL_AND_IMPL,
which explicitly states that it has a global symbol referring to its implementation. In this case,
the generated wrapper will perform an indirect call using the specified global symbol.
This results in some performance improvements, because doing so removes one level of
indirection during a call of the runtime function.
The invocation sequence before looked like:
Swift code -> dynamic linker stub -> runtime_function -> indirect call of runtime_function's implementation through a global function pointer
And using a wrapper it becomes:
Swift code -> wrapper -> indirect call of runtime_function's implementation through a global function pointer
- The runtime function is defined using the usual FUNCTION x-macro but it uses a calling convention
that requires that wrappers should be used instead of dynamic linker stubs to avoid the situations
where the dynamic linker would clobber some of the callee-saved registers when it performs a lazy
binding of the runtime function, which may lead to an undefined behaviour during the program execution.
In this case, the behaviour is similar to the first case, except that the name of the global symbol for
the runtime function f is assumed to be _f, i.e. it has an underscore as a prefix. This symbol
will be auto-generated and properly initialized by an x-macro based metaprogramming machinery
in the runtime library.