Add llvm.memset/frameaddress/returnaddress intrinsics.
authorChris Lattner <sabre@nondot.org>
Sat, 14 Feb 2004 02:47:17 +0000 (02:47 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 14 Feb 2004 02:47:17 +0000 (02:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11431 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Intrinsics.h
lib/CodeGen/IntrinsicLowering.cpp
lib/VMCore/Function.cpp
lib/VMCore/IntrinsicLowering.cpp
lib/VMCore/Verifier.cpp

index 125105dd303966651c657d4f6e7b5765eef8888f..cef43aadf8db692a8bc8b6e32f567b896c73ae16 100644 (file)
@@ -31,6 +31,15 @@ namespace Intrinsic {
     va_end,         // Used to implement the va_end macro in C
     va_copy,        // Used to implement the va_copy macro in C
 
+    // Code generator intrinsics...
+    returnaddress,  // Yields the return address of a dynamic call frame
+    frameaddress,   // Yields the frame address of a dynamic call frame
+
+    // Standard libc functions...
+    memcpy,         // Copy non-overlapping memory blocks
+    memmove,        // Copy potentially overlapping memory blocks
+    memset,         // Fill memory with a byte value
+
     // Setjmp/Longjmp intrinsics...
     setjmp,         // Used to represent a setjmp call in C
     longjmp,        // Used to represent a longjmp call in C
@@ -44,10 +53,6 @@ namespace Intrinsic {
     dbg_func_start,   // Start of a function
     dbg_declare,      // Declare a local object
 
-    // Standard libc functions...
-    memcpy,         // Used to copy non-overlapping memory blocks
-    memmove,        // Used to copy overlapping memory blocks
-
 
     // Standard libm functions...
     
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() &&
index 8875661ff04e136118934ee061f6f06a45d0a107..43f3dc46ed38f32c75f790a9145844d7992d1138 100644 (file)
@@ -214,12 +214,19 @@ unsigned Function::getIntrinsicID() const {
     if (getName() == "llvm.dbg.func.start")  return Intrinsic::dbg_func_start;
     if (getName() == "llvm.dbg.declare")     return Intrinsic::dbg_declare;
     break;
+  case 'f':
+    if (getName() == "llvm.frameaddress")  return Intrinsic::frameaddress;
+    break;
   case 'l':
     if (getName() == "llvm.longjmp")  return Intrinsic::longjmp;
     break;
   case 'm':
     if (getName() == "llvm.memcpy")  return Intrinsic::memcpy;
     if (getName() == "llvm.memmove")  return Intrinsic::memmove;
+    if (getName() == "llvm.memset")  return Intrinsic::memset;
+    break;
+  case 'r':
+    if (getName() == "llvm.returnaddress")  return Intrinsic::returnaddress;
     break;
   case 's':
     if (getName() == "llvm.setjmp")     return Intrinsic::setjmp;
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() &&
index e2ccb5b12b99fed706ca20babc9e407821f6ffff..bfd9ae6459d7ea177df0650118d3067a99112e56 100644 (file)
 
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Assembly/Writer.h"
+#include "llvm/Constants.h"
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/iPHINode.h"
-#include "llvm/iTerminators.h"
-#include "llvm/iOther.h"
-#include "llvm/iOperators.h"
-#include "llvm/iMemory.h"
-#include "llvm/SymbolTable.h"
-#include "llvm/PassManager.h"
+#include "llvm/Instructions.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/PassManager.h"
+#include "llvm/SymbolTable.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/InstVisitor.h"
@@ -551,6 +548,16 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
   case Intrinsic::va_end:          NumArgs = 1; break;
   case Intrinsic::va_copy:         NumArgs = 1; break;
 
+  case Intrinsic::returnaddress:
+  case Intrinsic::frameaddress:
+    Assert1(isa<PointerType>(FT->getReturnType()),
+            "llvm.(frame|return)address must return pointers", IF);
+    Assert1(FT->getNumParams() == 1 && isa<ConstantInt>(CI.getOperand(1)),
+       "llvm.(frame|return)address require a single constant integer argument",
+            &CI);
+    NumArgs = 1;
+    break;
+
   case Intrinsic::setjmp:          NumArgs = 1; break;
   case Intrinsic::longjmp:         NumArgs = 2; break;
   case Intrinsic::sigsetjmp:       NumArgs = 2; break;
@@ -564,6 +571,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
 
   case Intrinsic::memcpy:          NumArgs = 4; break;
   case Intrinsic::memmove:         NumArgs = 4; break;
+  case Intrinsic::memset:          NumArgs = 4; break;
  
   case Intrinsic::alpha_ctlz:      NumArgs = 1; break;
   case Intrinsic::alpha_cttz:      NumArgs = 1; break;