From cf8990838143fcfa91dd6276af523ac6c23517c2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 14 Feb 2004 02:47:17 +0000 Subject: [PATCH] Add llvm.memset/frameaddress/returnaddress intrinsics. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11431 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Intrinsics.h | 13 +++++++++---- lib/CodeGen/IntrinsicLowering.cpp | 23 +++++++++++++++++++++-- lib/VMCore/Function.cpp | 7 +++++++ lib/VMCore/IntrinsicLowering.cpp | 23 +++++++++++++++++++++-- lib/VMCore/Verifier.cpp | 22 +++++++++++++++------- 5 files changed, 73 insertions(+), 15 deletions(-) diff --git a/include/llvm/Intrinsics.h b/include/llvm/Intrinsics.h index 125105dd303..cef43aadf8d 100644 --- a/include/llvm/Intrinsics.h +++ b/include/llvm/Intrinsics.h @@ -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... diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 6eaaafa2e26..d0030eaea6a 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -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(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(CFT->param_begin(), CFT->param_end()-1), + false); + Function *MemSet = M->getOrInsertFunction("memset", FT); + new CallInst(MemSet, std::vector(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 8875661ff04..43f3dc46ed3 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -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; diff --git a/lib/VMCore/IntrinsicLowering.cpp b/lib/VMCore/IntrinsicLowering.cpp index 6eaaafa2e26..d0030eaea6a 100644 --- a/lib/VMCore/IntrinsicLowering.cpp +++ b/lib/VMCore/IntrinsicLowering.cpp @@ -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(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(CFT->param_begin(), CFT->param_end()-1), + false); + Function *MemSet = M->getOrInsertFunction("memset", FT); + new CallInst(MemSet, std::vector(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 e2ccb5b12b9..bfd9ae6459d 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -41,17 +41,14 @@ #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(FT->getReturnType()), + "llvm.(frame|return)address must return pointers", IF); + Assert1(FT->getNumParams() == 1 && isa(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; -- 2.34.1