Move into the VMCore library
[oota-llvm.git] / lib / CodeGen / IntrinsicLowering.cpp
1 //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
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 implements the default intrinsic lowering implementation.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/IntrinsicLowering.h"
15 #include "llvm/Constant.h"
16 #include "llvm/Intrinsics.h"
17 #include "llvm/Module.h"
18 #include "llvm/Type.h"
19 #include "llvm/iOther.h"
20 using namespace llvm;
21
22 void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
23   Function *Callee = CI->getCalledFunction();
24   assert(Callee && "Cannot lower an indirect call!");
25   
26   Module *M = Callee->getParent();
27
28   switch (Callee->getIntrinsicID()) {
29   case Intrinsic::not_intrinsic:
30     std::cerr << "Cannot lower a call to a non-intrinsic function '"
31               << Callee->getName() << "'!\n";
32     abort();
33   default:
34     std::cerr << "Error: Code generator does not support intrinsic function '"
35               << Callee->getName() << "'!\n";
36     abort();
37
38     // The default implementation of setjmp/longjmp transforms setjmp into a
39     // noop that always returns zero and longjmp into a call to abort.  This
40     // allows code that never longjmps to work correctly.
41   case Intrinsic::setjmp:
42   case Intrinsic::sigsetjmp:
43     if (CI->getType() != Type::VoidTy)
44       CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
45     break;
46
47   case Intrinsic::longjmp:
48   case Intrinsic::siglongjmp:
49     // Insert the call to abort
50     new CallInst(M->getOrInsertFunction("abort", Type::VoidTy, 0), "", CI);
51     break;
52   }
53
54   assert(CI->use_empty() &&
55          "Lowering should have eliminated any uses of the intrinsic call!");
56   CI->getParent()->getInstList().erase(CI);
57 }