Add support for the llvm.memmove intrinsic

Patch graciously contributed by Reid Spencer!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11355 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index 48ae015..6eaaafa 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -71,6 +71,19 @@
                  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() &&
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index a4bc4ea..8875661 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -219,6 +219,7 @@
     break;
   case 'm':
     if (getName() == "llvm.memcpy")  return Intrinsic::memcpy;
+    if (getName() == "llvm.memmove")  return Intrinsic::memmove;
     break;
   case 's':
     if (getName() == "llvm.setjmp")     return Intrinsic::setjmp;
diff --git a/lib/VMCore/IntrinsicLowering.cpp b/lib/VMCore/IntrinsicLowering.cpp
index 48ae015..6eaaafa 100644
--- a/lib/VMCore/IntrinsicLowering.cpp
+++ b/lib/VMCore/IntrinsicLowering.cpp
@@ -71,6 +71,19 @@
                  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() &&
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 71ea54e..e2ccb5b 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -563,6 +563,7 @@
   case Intrinsic::dbg_declare:     NumArgs = 1; break;
 
   case Intrinsic::memcpy:          NumArgs = 4; break;
+  case Intrinsic::memmove:         NumArgs = 4; break;
  
   case Intrinsic::alpha_ctlz:      NumArgs = 1; break;
   case Intrinsic::alpha_cttz:      NumArgs = 1; break;