1 //===-- IntrinsicLowering.h - Intrinsic Function Lowering -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the IntrinsicLowering interface. This interface allows
11 // addition of domain-specific or front-end specific intrinsics to LLVM without
12 // having to modify all of the code generators to support the new intrinsic.
13 // Later, as desired, targets can incrementally add support for particular
14 // intrinsic functions, as desired, to generate better code.
16 // If a code generator cannot handle or does not know about an intrinsic
17 // function, it will use the intrinsic lowering interface to change an intrinsic
18 // function name into a concrete function name which can be used to implement
19 // the functionality of the intrinsic. For example, llvm.memcpy can be
20 // implemented as a call to the math library 'memcpy' function if the target
21 // doesn't have hardware support for the intrinsic, or if it has not yet been
24 // Another use for this interface is the addition of domain-specific intrinsics.
25 // The default implementation of this interface would then lower the intrinsics
26 // to noop calls, allowing the direct execution of programs with instrumentation
27 // or other hooks placed in them. When a specific tool or flag is used, a
28 // different implementation of these interfaces may be used, which activates the
29 // intrinsics in some way.
31 //===----------------------------------------------------------------------===//
33 #ifndef LLVM_CODEGEN_INTRINSICLOWERING_H
34 #define LLVM_CODEGEN_INTRINSICLOWERING_H
36 #include "llvm/Intrinsics.h"
42 class IntrinsicLowering {
44 virtual ~IntrinsicLowering() {}
46 /// AddPrototypes - This method, if called, causes all of the prototypes
47 /// that might be needed by an intrinsic lowering implementation to be
48 /// inserted into the module specified.
49 virtual void AddPrototypes(Module &M) = 0;
51 /// LowerIntrinsicCall - This method returns the LLVM function which should
52 /// be used to implement the specified intrinsic function call. If an
53 /// intrinsic function must be implemented by the code generator (such as
54 /// va_start), this function should print a message and abort.
56 /// Otherwise, if an intrinsic function call can be lowered, the code to
57 /// implement it (often a call to a non-intrinsic function) is inserted
58 /// _after_ the call instruction and the call is deleted. The caller must
59 /// be capable of handling this kind of change.
61 virtual void LowerIntrinsicCall(CallInst *CI) = 0;
64 /// DefaultIntrinsicLower - This is the default intrinsic lowering pass which
65 /// is used if no other one is specified. Custom intrinsic lowering
66 /// implementations should pass any unhandled intrinsics to this
67 /// implementation to allow for future extensibility.
68 struct DefaultIntrinsicLowering : public IntrinsicLowering {
69 virtual void AddPrototypes(Module &M);
70 virtual void LowerIntrinsicCall(CallInst *CI);