diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2012-02-21 00:26:58 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2012-02-21 00:26:58 +0000 |
commit | 45062046405c649c9b493f0f2abb04c6bdcba368 (patch) | |
tree | d6794333922f0959954c41b0e5cd58e93a302d4a /clang/lib/CodeGen/CGDeclCXX.cpp | |
parent | 1ac04c308832f7a9b2e07e360f07c82f7cb2a02c (diff) | |
download | bcm5719-llvm-45062046405c649c9b493f0f2abb04c6bdcba368.tar.gz bcm5719-llvm-45062046405c649c9b493f0f2abb04c6bdcba368.zip |
Emit the exact size for the invariant intrinsics.
llvm-svn: 151010
Diffstat (limited to 'clang/lib/CodeGen/CGDeclCXX.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDeclCXX.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index d8ece58d6e5..fac38a32427 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -103,7 +103,8 @@ static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D, /// Emit code to cause the variable at the given address to be considered as /// constant from this point onwards. -static void EmitDeclInvariant(CodeGenFunction &CGF, llvm::Constant *Addr) { +static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D, + llvm::Constant *Addr) { // Don't emit the intrinsic if we're not optimizing. if (!CGF.CGM.getCodeGenOpts().OptimizationLevel) return; @@ -112,8 +113,10 @@ static void EmitDeclInvariant(CodeGenFunction &CGF, llvm::Constant *Addr) { llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start; llvm::Constant *InvariantStart = CGF.CGM.getIntrinsic(InvStartID); - // Emit a call, with size -1 signifying the whole object. - llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(CGF.Int64Ty, -1), + // Emit a call with the size in bytes of the object. + CharUnits WidthChars = CGF.getContext().getTypeSizeInChars(D.getType()); + uint64_t Width = WidthChars.getQuantity(); + llvm::Value *Args[2] = { llvm::ConstantInt::getSigned(CGF.Int64Ty, Width), llvm::ConstantExpr::getBitCast(Addr, CGF.Int8PtrTy)}; CGF.Builder.CreateCall(InvariantStart, Args); } @@ -129,7 +132,7 @@ void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D, if (PerformInit) EmitDeclInit(*this, D, DeclPtr); if (CGM.isTypeConstant(D.getType(), true)) - EmitDeclInvariant(*this, DeclPtr); + EmitDeclInvariant(*this, D, DeclPtr); else EmitDeclDestroy(*this, D, DeclPtr); return; |