diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-26 12:59:39 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-26 12:59:39 +0000 |
commit | 0c99509927a0c7a48490486b9fec287b63e5c09c (patch) | |
tree | 62ff858a189b69f2f239fbd5eca722a525ebd0b7 /lib/CodeGen/CodeGenModule.cpp | |
parent | 1849128c7d88247d914f05efe4c03907f0932174 (diff) |
Emit memmove, not memcpy, for structure copies; this is unfortunately
required for correctness in cases of copying a struct to itself or to
an overlapping struct (itself for cases like *a = *a, and overlapping
is possible with unions).
Hopefully, this won't end up being a perf issue; LLVM *should* be able
to optimize memmove to memcpy in a lot of cases, and for small copies
the generated code *should* be mostly comparable. (In reality, LLVM
is currently horrible at optimizing memmove, but that's a bug, not a
fundamental issue.)
gcc currently generates wrong code; that's
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51566 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ec61d667ee..329599c116 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -35,7 +35,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO, llvm::Module &M, const llvm::TargetData &TD, Diagnostic &diags, bool GenerateDebugInfo) : Context(C), Features(LO), TheModule(M), TheTargetData(TD), Diags(diags), - Types(C, M, TD), MemCpyFn(0), MemSetFn(0), CFConstantStringClassRef(0) { + Types(C, M, TD), MemCpyFn(0), MemMoveFn(0), MemSetFn(0), + CFConstantStringClassRef(0) { //TODO: Make this selectable at runtime Runtime = CreateObjCRuntime(M, getTypes().ConvertType(getContext().IntTy), @@ -589,6 +590,17 @@ llvm::Function *CodeGenModule::getMemCpyFn() { return MemCpyFn = getIntrinsic(IID); } +llvm::Function *CodeGenModule::getMemMoveFn() { + if (MemMoveFn) return MemMoveFn; + llvm::Intrinsic::ID IID; + switch (Context.Target.getPointerWidth(0)) { + default: assert(0 && "Unknown ptr width"); + case 32: IID = llvm::Intrinsic::memmove_i32; break; + case 64: IID = llvm::Intrinsic::memmove_i64; break; + } + return MemMoveFn = getIntrinsic(IID); +} + llvm::Function *CodeGenModule::getMemSetFn() { if (MemSetFn) return MemSetFn; llvm::Intrinsic::ID IID; |