Add llvm.memset/frameaddress/returnaddress intrinsics.
[oota-llvm.git] / lib / VMCore / IntrinsicLowering.cpp
index 6eaaafa2e26c72cfe86c438371279c390710aed2..d0030eaea6a8f80bf39ae8e9902217b43fc34835 100644 (file)
@@ -12,7 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IntrinsicLowering.h"
-#include "llvm/Constant.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/iOther.h"
@@ -49,6 +49,12 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
     new CallInst(M->getOrInsertFunction("abort", Type::VoidTy, 0), "", CI);
     break;
 
+  case Intrinsic::returnaddress:
+  case Intrinsic::frameaddress:
+    CI->replaceAllUsesWith(ConstantPointerNull::get(
+                                            cast<PointerType>(CI->getType())));
+    break;
+
   case Intrinsic::dbg_stoppoint:
   case Intrinsic::dbg_region_start:
   case Intrinsic::dbg_region_end:
@@ -72,7 +78,7 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
     break;
   }
   case Intrinsic::memmove: {
-    // The memmove intrinsic take an extra alignment argument that the memcpy
+    // The memmove intrinsic take an extra alignment argument that the memmove
     // libc function does not.
     const FunctionType *CFT = Callee->getFunctionType();
     FunctionType *FT =
@@ -84,6 +90,19 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
                  CI->getName(), CI);
     break;
   }
+  case Intrinsic::memset: {
+    // The memset intrinsic take an extra alignment argument that the memset
+    // libc function does not.
+    const FunctionType *CFT = Callee->getFunctionType();
+    FunctionType *FT =
+      FunctionType::get(*CFT->param_begin(), 
+           std::vector<const Type*>(CFT->param_begin(), CFT->param_end()-1),
+                        false);
+    Function *MemSet = M->getOrInsertFunction("memset", FT);
+    new CallInst(MemSet, std::vector<Value*>(CI->op_begin()+1, CI->op_end()-1),
+                 CI->getName(), CI);
+    break;
+  }
   }
 
   assert(CI->use_empty() &&