aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-12-28 08:19:41 +0000
committerChris Lattner <sabre@nondot.org>2003-12-28 08:19:41 +0000
commit3b66ecb05fedbfe0a70b39d73b1ea5998bc8c31b (patch)
treebffc38b3371ccf0eac50f15f177471e7a51d7e25
parent3f52c1561d70575b0003404e2c2210d6286f79a9 (diff)
downloadexternal_llvm-3b66ecb05fedbfe0a70b39d73b1ea5998bc8c31b.zip
external_llvm-3b66ecb05fedbfe0a70b39d73b1ea5998bc8c31b.tar.gz
external_llvm-3b66ecb05fedbfe0a70b39d73b1ea5998bc8c31b.tar.bz2
Implement the default implementation of the intrinsic lowering class
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10621 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp57
-rw-r--r--lib/VMCore/IntrinsicLowering.cpp57
2 files changed, 114 insertions, 0 deletions
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
new file mode 100644
index 0000000..b7b67d2
--- /dev/null
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -0,0 +1,57 @@
+//===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the default intrinsic lowering implementation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/IntrinsicLowering.h"
+#include "llvm/Constant.h"
+#include "llvm/Intrinsics.h"
+#include "llvm/Module.h"
+#include "llvm/Type.h"
+#include "llvm/iOther.h"
+using namespace llvm;
+
+void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
+ Function *Callee = CI->getCalledFunction();
+ assert(Callee && "Cannot lower an indirect call!");
+
+ Module *M = Callee->getParent();
+
+ switch (Callee->getIntrinsicID()) {
+ case Intrinsic::not_intrinsic:
+ std::cerr << "Cannot lower a call to a non-intrinsic function '"
+ << Callee->getName() << "'!\n";
+ abort();
+ default:
+ std::cerr << "Error: Code generator does not support intrinsic function '"
+ << Callee->getName() << "'!\n";
+ abort();
+
+ // The default implementation of setjmp/longjmp transforms setjmp into a
+ // noop that always returns zero and longjmp into a call to abort. This
+ // allows code that never longjmps to work correctly.
+ case Intrinsic::setjmp:
+ case Intrinsic::sigsetjmp:
+ if (CI->getType() != Type::VoidTy)
+ CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+ break;
+
+ case Intrinsic::longjmp:
+ case Intrinsic::siglongjmp:
+ // Insert the call to abort
+ new CallInst(M->getOrInsertFunction("abort", Type::VoidTy, 0), "", CI);
+ break;
+ }
+
+ assert(CI->use_empty() &&
+ "Lowering should have eliminated any uses of the intrinsic call!");
+ CI->getParent()->getInstList().erase(CI);
+}
diff --git a/lib/VMCore/IntrinsicLowering.cpp b/lib/VMCore/IntrinsicLowering.cpp
new file mode 100644
index 0000000..b7b67d2
--- /dev/null
+++ b/lib/VMCore/IntrinsicLowering.cpp
@@ -0,0 +1,57 @@
+//===-- IntrinsicLowering.cpp - Intrinsic Lowering default implementation -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the default intrinsic lowering implementation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/IntrinsicLowering.h"
+#include "llvm/Constant.h"
+#include "llvm/Intrinsics.h"
+#include "llvm/Module.h"
+#include "llvm/Type.h"
+#include "llvm/iOther.h"
+using namespace llvm;
+
+void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
+ Function *Callee = CI->getCalledFunction();
+ assert(Callee && "Cannot lower an indirect call!");
+
+ Module *M = Callee->getParent();
+
+ switch (Callee->getIntrinsicID()) {
+ case Intrinsic::not_intrinsic:
+ std::cerr << "Cannot lower a call to a non-intrinsic function '"
+ << Callee->getName() << "'!\n";
+ abort();
+ default:
+ std::cerr << "Error: Code generator does not support intrinsic function '"
+ << Callee->getName() << "'!\n";
+ abort();
+
+ // The default implementation of setjmp/longjmp transforms setjmp into a
+ // noop that always returns zero and longjmp into a call to abort. This
+ // allows code that never longjmps to work correctly.
+ case Intrinsic::setjmp:
+ case Intrinsic::sigsetjmp:
+ if (CI->getType() != Type::VoidTy)
+ CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+ break;
+
+ case Intrinsic::longjmp:
+ case Intrinsic::siglongjmp:
+ // Insert the call to abort
+ new CallInst(M->getOrInsertFunction("abort", Type::VoidTy, 0), "", CI);
+ break;
+ }
+
+ assert(CI->use_empty() &&
+ "Lowering should have eliminated any uses of the intrinsic call!");
+ CI->getParent()->getInstList().erase(CI);
+}