Add support for the llvm.memmove intrinsic
authorChris Lattner <sabre@nondot.org>
Thu, 12 Feb 2004 18:11:20 +0000 (18:11 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 12 Feb 2004 18:11:20 +0000 (18:11 +0000)
Patch graciously contributed by Reid Spencer!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11355 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/IntrinsicLowering.cpp
lib/VMCore/Function.cpp
lib/VMCore/IntrinsicLowering.cpp
lib/VMCore/Verifier.cpp

index 48ae01540bbf6bce994c84320a45e304511995c1..6eaaafa2e26c72cfe86c438371279c390710aed2 100644 (file)
@@ -71,6 +71,19 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
                  CI->getName(), CI);
     break;
   }
                  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() &&
   }
 
   assert(CI->use_empty() &&
index a4bc4eab2a86f8e78d875193b3b3b3af7a4076cc..8875661ff04e136118934ee061f6f06a45d0a107 100644 (file)
@@ -219,6 +219,7 @@ unsigned Function::getIntrinsicID() const {
     break;
   case 'm':
     if (getName() == "llvm.memcpy")  return Intrinsic::memcpy;
     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;
     break;
   case 's':
     if (getName() == "llvm.setjmp")     return Intrinsic::setjmp;
index 48ae01540bbf6bce994c84320a45e304511995c1..6eaaafa2e26c72cfe86c438371279c390710aed2 100644 (file)
@@ -71,6 +71,19 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
                  CI->getName(), CI);
     break;
   }
                  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() &&
   }
 
   assert(CI->use_empty() &&
index 71ea54e58b2d7970c55a4c6b54acd04fc58b2975..e2ccb5b12b99fed706ca20babc9e407821f6ffff 100644 (file)
@@ -563,6 +563,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
   case Intrinsic::dbg_declare:     NumArgs = 1; break;
 
   case Intrinsic::memcpy:          NumArgs = 4; break;
   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;
  
   case Intrinsic::alpha_ctlz:      NumArgs = 1; break;
   case Intrinsic::alpha_cttz:      NumArgs = 1; break;