Intrinsic
public class Intrinsic : Function
An Intrinsic
represents an intrinsic known to LLVM.
Intrinsic functions have well known names and semantics and are required to follow certain restrictions. Overall, these intrinsics represent an extension mechanism for the LLVM language that does not require changing all of the transformations in LLVM when adding to the language (or the bitcode reader/writer, the parser, etc…).
Intrinsic function names must all start with an llvm.
prefix. This prefix
is reserved in LLVM for intrinsic names; thus, function names may not begin
with this prefix. Intrinsic functions must always be external functions: you
cannot define the body of intrinsic functions. Intrinsic functions may only
be used in call or invoke instructions: it is illegal to take the address of
an intrinsic function.
Some intrinsic functions can be overloaded, i.e., the intrinsic represents a family of functions that perform the same operation but on different data types. Because LLVM can represent over 8 million different integer types, overloading is used commonly to allow an intrinsic function to operate on any integer type. One or more of the argument types or the result type can be overloaded to accept any integer type. Argument types may also be defined as exactly matching a previous argument’s type or the result type. This allows an intrinsic function which accepts multiple arguments, but needs all of them to be of the same type, to only be overloaded with respect to a single argument or the result.
Overloaded intrinsics will have the names of its overloaded argument types
encoded into its function name, each preceded by a period. Only those types
which are overloaded result in a name suffix. Arguments whose type is
matched against another type do not. For example, the llvm.ctpop function
can take an integer of any width and returns an integer of exactly the same
integer width. This leads to a family of functions such as
i8 @llvm.ctpop.i8(i8 %val)
and i29 @llvm.ctpop.i29(i29 %val)
. Only one
type, the return type, is overloaded, and only one type suffix is required.
Because the argument’s type is matched against the return type, it does not
require its own name suffix.
Dynamic Member Lookup For Intrinsics
This library provides a dynamic member lookup facility for retrieving
intrinsic selectors. For any LLVM intrinsic selector of the form
llvm.foo.bar.baz
, the name of the corresponding dynamic member is that
name with any dots replaced by underscores.
For example:
llvm.foo.bar.baz -> Intrinsic.ID.llvm_foo_bar_baz
llvm.stacksave -> Intrinsic.ID.llvm_stacksave
llvm.x86.xsave64 -> Intrinsic.ID.llvm_x86_xsave64
Any existing underscores do not need to be replaced, e.g.
llvm.va_copy
becomes Intrinsic.ID.llvm_va_copy
.
For overloaded intrinsics, the non-overloaded prefix excluding the explicit type parameters is used and normalized according to the convention above.
For example:
llvm.sinf64 -> Intrinsic.ID.llvm_sin
llvm.memcpy.p0i8.p0i8.i32 -> Intrinsic.ID.llvm_memcpy
llvm.bswap.v4i32 -> Intrinsic.ID.llvm_bswap
-
A wrapper type for an intrinsic selector.
Declaration
Swift
public struct Selector
-
This type provides a dynamic member lookup facility for LLVM intrinsics.
It is not possible to create a
See moreDynamicIntrinsicResolver
in user code. One is provided byIntrinsic.ID
.Declaration
Swift
@dynamicMemberLookup public struct DynamicIntrinsicResolver
-
The default dynamic intrinsic resolver.
Declaration
Swift
public static let ID: Intrinsic.DynamicIntrinsicResolver
-
Retrieves the name of this intrinsic if it is not overloaded.
Declaration
Swift
public var name: String { get }
-
Retrieves the name of this intrinsic if it is overloaded, resolving it with the given parameter types.
Declaration
Swift
public func overloadedName(for parameterTypes: [IRType]) -> String
-
Retrieves the type of this intrinsic if it is not overloaded.
Declaration
Swift
public var type: IRType { get }
-
Resolves the type of an overloaded intrinsic using the given parameter types.
Declaration
Parameters
context
The context in which to create the type.
parameterTypes
The type of the parameters to the intrinsic.
Return Value
The type of the intrinsic function with its overloaded parameter types resolved.
-
Retrieves if this intrinsic is overloaded.
Declaration
Swift
public var isOverloaded: Bool { get }
-
Retrieves the ID number of this intrinsic function.
Declaration
Swift
public var identifier: UInt32 { get }