From: Chris Lattner
LLVM supports the notion of an "intrinsic function". These -functions have well known names and semantics, and are required to -follow certain restrictions. Overall, these instructions represent an -extension mechanism for the LLVM language that does not require -changing all of the transformations in LLVM to add to the language (or -the bytecode 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 -functions may not be named this. 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. Additionally, -because intrinsic functions are part of the LLVM language, it is -required that they all be documented here if any are added.
-Unless an intrinsic function is target-specific, there must be a -lowering pass to eliminate the intrinsic or all backends must support -the intrinsic function.
+ +LLVM supports the notion of an "intrinsic function". These functions have +well known names and semantics, and are required to follow certain +restrictions. Overall, these instructions represent an extension mechanism for +the LLVM language that does not require changing all of the transformations in +LLVM to add to the language (or the bytecode 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 functions may not be named +this. 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. Additionally, because intrinsic functions are part of the LLVM +language, it is required that they all be documented here if any are added.
+ + ++Adding an intrinsic to LLVM is straight-forward if it is possible to express the +concept in LLVM directly (ie, code generator support is not _required_). To do +this, extend the default implementation of the IntrinsicLowering class to handle +the intrinsic. Code generators use this class to lower intrinsics they do not +understand to raw LLVM instructions that they do. +
+This example shows how the vanext instruction and the variable argument handling intrinsic functions are used.
-int %test(int %X, ...) {+
; Initialize variable argument processing
%ap = call sbyte*()* %llvm.va_start()
; Read a single integer argument
%tmp = vaarg sbyte* %ap, int
; Advance to the next argument
%ap2 = vanext sbyte* %ap, int
; Demonstrate usage of llvm.va_copy and llvm.va_end
%aq = call sbyte* (sbyte*)* %llvm.va_copy(sbyte* %ap2)
call void %llvm.va_end(sbyte* %aq)
; Stop processing of arguments.
call void %llvm.va_end(sbyte* %ap2)
ret int %tmp
}
+int %test(int %X, ...) { + ; Initialize variable argument processing + %ap = call sbyte* %llvm.va_start() + + ; Read a single integer argument + %tmp = vaarg sbyte* %ap, int + + ; Advance to the next argument + %ap2 = vanext sbyte* %ap, int + + ; Demonstrate usage of llvm.va_copy and llvm.va_end + %aq = call sbyte* %llvm.va_copy(sbyte* %ap2) + call void %llvm.va_end(sbyte* %aq) + + ; Stop processing of arguments. + call void %llvm.va_end(sbyte* %ap2) + ret int %tmp +} +@@ -1704,6 +1732,64 @@ element into the returned list. This intrinsic is necessary because the + + + +
+ +
+ ++ call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* <dest>, sbyte* <src>, + uint <len>, uint <align>) ++ +
+The 'llvm.memcpy' intrinsic copies a block of memory from the source +location to the destination location. +
+ ++Note that, unlike the standard libc function, the llvm.memcpy intrinsic +does not return a value, and takes an extra alignment argument. +
+ ++The first argument is a pointer to the destination, the second is a pointer to +the source. The third argument is an (arbitrarily sized) integer argument +specifying the number of bytes to copy, and the fourth argument is the alignment +of the source and destination locations. +
+ ++The 'llvm.memcpy' intrinsic copies a block of memory from the source +location to the destination location, which are not allowed to overlap. It +copies "len" bytes of memory over. If the argument is known to be aligned to +some boundary, this can be specified as the fourth argument, otherwise it should +be set to 0 or 1. +
+