Add support for the llvm.memmove intrinsic
[oota-llvm.git] / lib / CodeGen / IntrinsicLowering.cpp
index 31a904351d2f71baef1b75ff7def649abcb9fc98..6eaaafa2e26c72cfe86c438371279c390710aed2 100644 (file)
@@ -13,9 +13,8 @@
 
 #include "llvm/IntrinsicLowering.h"
 #include "llvm/Constant.h"
-#include "llvm/Intrinsics.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
-#include "llvm/Type.h"
 #include "llvm/iOther.h"
 using namespace llvm;
 
@@ -49,6 +48,42 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
     // Insert the call to abort
     new CallInst(M->getOrInsertFunction("abort", Type::VoidTy, 0), "", CI);
     break;
+
+  case Intrinsic::dbg_stoppoint:
+  case Intrinsic::dbg_region_start:
+  case Intrinsic::dbg_region_end:
+  case Intrinsic::dbg_declare:
+  case Intrinsic::dbg_func_start:
+    if (CI->getType() != Type::VoidTy)
+      CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+    break;    // Simply strip out debugging intrinsics
+
+  case Intrinsic::memcpy: {
+    // The memcpy intrinsic take an extra alignment argument that the memcpy
+    // 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 *MemCpy = M->getOrInsertFunction("memcpy", FT);
+    new CallInst(MemCpy, std::vector<Value*>(CI->op_begin()+1, CI->op_end()-1),
+                 CI->getName(), CI);
+    break;
+  }
+  case Intrinsic::memmove: {
+    // The memmove intrinsic take an extra alignment argument that the memcpy
+    // 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 *MemMove = M->getOrInsertFunction("memmove", FT);
+    new CallInst(MemMove, std::vector<Value*>(CI->op_begin()+1, CI->op_end()-1),
+                 CI->getName(), CI);
+    break;
+  }
   }
 
   assert(CI->use_empty() &&