LLVM API Documentation

IntrinsicLowering.h

Go to the documentation of this file.
00001 //===-- IntrinsicLowering.h - Intrinsic Function Lowering -------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the IntrinsicLowering interface.  This interface allows
00011 // addition of domain-specific or front-end specific intrinsics to LLVM without
00012 // having to modify all of the code generators to support the new intrinsic.
00013 // Later, as desired, targets can incrementally add support for particular
00014 // intrinsic functions, as desired, to generate better code.
00015 //
00016 // If a code generator cannot handle or does not know about an intrinsic
00017 // function, it will use the intrinsic lowering interface to change an intrinsic
00018 // function name into a concrete function name which can be used to implement
00019 // the functionality of the intrinsic.  For example, llvm.memcpy can be
00020 // implemented as a call to the math library 'memcpy' function if the target
00021 // doesn't have hardware support for the intrinsic, or if it has not yet been
00022 // implemented yet.
00023 //
00024 // Another use for this interface is the addition of domain-specific intrinsics.
00025 // The default implementation of this interface would then lower the intrinsics
00026 // to noop calls, allowing the direct execution of programs with instrumentation
00027 // or other hooks placed in them.  When a specific tool or flag is used, a
00028 // different implementation of these interfaces may be used, which activates the
00029 // intrinsics in some way.
00030 //
00031 //===----------------------------------------------------------------------===//
00032 
00033 #ifndef LLVM_CODEGEN_INTRINSICLOWERING_H
00034 #define LLVM_CODEGEN_INTRINSICLOWERING_H
00035 
00036 #include "llvm/Intrinsics.h"
00037 
00038 namespace llvm {
00039   class CallInst;
00040   class Module;
00041 
00042   class IntrinsicLowering {
00043   public:
00044     IntrinsicLowering() {}
00045     virtual ~IntrinsicLowering() {}
00046 
00047     /// AddPrototypes - This method, if called, causes all of the prototypes
00048     /// that might be needed by an intrinsic lowering implementation to be
00049     /// inserted into the module specified.
00050     virtual void AddPrototypes(Module &M) = 0;
00051 
00052     /// LowerIntrinsicCall - This method returns the LLVM function which should
00053     /// be used to implement the specified intrinsic function call.  If an
00054     /// intrinsic function must be implemented by the code generator (such as
00055     /// va_start), this function should print a message and abort.
00056     ///
00057     /// Otherwise, if an intrinsic function call can be lowered, the code to
00058     /// implement it (often a call to a non-intrinsic function) is inserted
00059     /// _after_ the call instruction and the call is deleted.  The caller must
00060     /// be capable of handling this kind of change.
00061     ///
00062     virtual void LowerIntrinsicCall(CallInst *CI) = 0;
00063   };
00064 
00065   /// DefaultIntrinsicLower - This is the default intrinsic lowering pass which
00066   /// is used if no other one is specified.  Custom intrinsic lowering
00067   /// implementations should pass any unhandled intrinsics to this
00068   /// implementation to allow for future extensibility.
00069   struct DefaultIntrinsicLowering : public IntrinsicLowering {
00070     virtual void AddPrototypes(Module &M);
00071     virtual void LowerIntrinsicCall(CallInst *CI);
00072   };
00073 }
00074 
00075 #endif