Grammer correction.
[oota-llvm.git] / include / llvm / CodeGen / IntrinsicLowering.h
1 //===-- IntrinsicLowering.h - Intrinsic Function Lowering -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
15 //
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
22 // implemented yet.
23 //
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.
30 //
31 //===----------------------------------------------------------------------===//
32
33 #ifndef LLVM_CODEGEN_INTRINSICLOWERING_H
34 #define LLVM_CODEGEN_INTRINSICLOWERING_H
35
36 #include "llvm/Intrinsics.h"
37
38 namespace llvm {
39   class CallInst;
40   class Module;
41
42   class IntrinsicLowering {
43   protected:
44     bool ShouldEmitDebugFunctions;
45   public:
46     IntrinsicLowering() : ShouldEmitDebugFunctions(false) {}
47     virtual ~IntrinsicLowering() {}
48
49     bool EmitDebugFunctions() const { return ShouldEmitDebugFunctions; }
50     
51     /// AddPrototypes - This method, if called, causes all of the prototypes
52     /// that might be needed by an intrinsic lowering implementation to be
53     /// inserted into the module specified.
54     virtual void AddPrototypes(Module &M) = 0;
55
56     /// LowerIntrinsicCall - This method returns the LLVM function which should
57     /// be used to implement the specified intrinsic function call.  If an
58     /// intrinsic function must be implemented by the code generator (such as
59     /// va_start), this function should print a message and abort.
60     ///
61     /// Otherwise, if an intrinsic function call can be lowered, the code to
62     /// implement it (often a call to a non-intrinsic function) is inserted
63     /// _after_ the call instruction and the call is deleted.  The caller must
64     /// be capable of handling this kind of change.
65     ///
66     virtual void LowerIntrinsicCall(CallInst *CI) = 0;
67   };
68
69   /// DefaultIntrinsicLower - This is the default intrinsic lowering pass which
70   /// is used if no other one is specified.  Custom intrinsic lowering
71   /// implementations should pass any unhandled intrinsics to this
72   /// implementation to allow for future extensibility.
73   struct DefaultIntrinsicLowering : public IntrinsicLowering {
74     virtual void AddPrototypes(Module &M);
75     virtual void LowerIntrinsicCall(CallInst *CI);
76   };
77 }
78
79 #endif