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
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...
//===----------------------------------------------------------------------===//
#include "llvm/IntrinsicLowering.h"
-#include "llvm/Constant.h"
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/iOther.h"
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:
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 =
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() &&
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;
//===----------------------------------------------------------------------===//
#include "llvm/IntrinsicLowering.h"
-#include "llvm/Constant.h"
+#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/iOther.h"
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:
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 =
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() &&
#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"
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;
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;