mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
Add llvm.memset/frameaddress/returnaddress intrinsics.
llvm-svn: 11431
This commit is contained in:
parent
a31a767307
commit
cdfcb976c7
@ -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...
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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() &&
|
||||
|
@ -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<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;
|
||||
|
Loading…
Reference in New Issue
Block a user