1 //===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
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 implements the default intrinsic lowering implementation.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/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"
22 void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
23 Function *Callee = CI->getCalledFunction();
24 assert(Callee && "Cannot lower an indirect call!");
26 Module *M = Callee->getParent();
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";
34 std::cerr << "Error: Code generator does not support intrinsic function '"
35 << Callee->getName() << "'!\n";
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()));
47 case Intrinsic::longjmp:
48 case Intrinsic::siglongjmp:
49 // Insert the call to abort
50 new CallInst(M->getOrInsertFunction("abort", Type::VoidTy, 0), "", CI);
54 assert(CI->use_empty() &&
55 "Lowering should have eliminated any uses of the intrinsic call!");
56 CI->getParent()->getInstList().erase(CI);