llvm.org GIT mirror llvm / b71fd78
Simplify IntrinsicLowering and clarify that it is only for use by the CBE and interpreter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31755 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
5 changed file(s) with 9 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
88 //
99 // This file defines the IntrinsicLowering interface. This interface allows
1010 // addition of domain-specific or front-end specific intrinsics to LLVM without
11 // having to modify all of the code generators to support the new intrinsic.
12 // Later, as desired, targets can incrementally add support for particular
13 // intrinsic functions, as desired, to generate better code.
14 //
15 // If a code generator cannot handle or does not know about an intrinsic
16 // function, it will use the intrinsic lowering interface to change an intrinsic
17 // function name into a concrete function name which can be used to implement
18 // the functionality of the intrinsic. For example, llvm.memcpy can be
19 // implemented as a call to the math library 'memcpy' function if the target
20 // doesn't have hardware support for the intrinsic, or if it has not yet been
21 // implemented yet.
22 //
23 // Another use for this interface is the addition of domain-specific intrinsics.
24 // The default implementation of this interface would then lower the intrinsics
25 // to noop calls, allowing the direct execution of programs with instrumentation
26 // or other hooks placed in them. When a specific tool or flag is used, a
27 // different implementation of these interfaces may be used, which activates the
28 // intrinsics in some way.
11 // having to modify all of the C backend or interpreter.
2912 //
3013 //===----------------------------------------------------------------------===//
3114
4124 class IntrinsicLowering {
4225 public:
4326 IntrinsicLowering() {}
44 virtual ~IntrinsicLowering() {}
4527
4628 /// AddPrototypes - This method, if called, causes all of the prototypes
4729 /// that might be needed by an intrinsic lowering implementation to be
4830 /// inserted into the module specified.
49 virtual void AddPrototypes(Module &M) = 0;
31 void AddPrototypes(Module &M);
5032
5133 /// LowerIntrinsicCall - This method returns the LLVM function which should
5234 /// be used to implement the specified intrinsic function call. If an
5840 /// _after_ the call instruction and the call is deleted. The caller must
5941 /// be capable of handling this kind of change.
6042 ///
61 virtual void LowerIntrinsicCall(CallInst *CI) = 0;
62 };
63
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);
43 void LowerIntrinsicCall(CallInst *CI);
7144 };
7245 }
7346
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This file implements the default intrinsic lowering implementation.
9 // This file implements the IntrinsicLowering class.
1010 //
1111 //===----------------------------------------------------------------------===//
1212
8181 return NewCI;
8282 }
8383
84 void DefaultIntrinsicLowering::AddPrototypes(Module &M) {
84 void IntrinsicLowering::AddPrototypes(Module &M) {
8585 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
8686 if (I->isExternal() && !I->use_empty())
8787 switch (I->getIntrinsicID()) {
262262
263263
264264
265 void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
265 void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
266266 Function *Callee = CI->getCalledFunction();
267267 assert(Callee && "Cannot lower an indirect call!");
268268
6666 initializeExternalFunctions();
6767 emitGlobals();
6868
69 IL = new DefaultIntrinsicLowering();
69 IL = new IntrinsicLowering();
7070 }
7171
7272 Interpreter::~Interpreter() {
6868 /// module to a C translation unit.
6969 class CWriter : public FunctionPass, public InstVisitor {
7070 std::ostream &Out;
71 DefaultIntrinsicLowering IL;
71 IntrinsicLowering IL;
7272 Mangler *Mang;
7373 LoopInfo *LI;
7474 const Module *TheModule;
6868 /// module to a C translation unit.
6969 class CWriter : public FunctionPass, public InstVisitor {
7070 std::ostream &Out;
71 DefaultIntrinsicLowering IL;
71 IntrinsicLowering IL;
7272 Mangler *Mang;
7373 LoopInfo *LI;
7474 const Module *TheModule;