aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-02-21 00:26:58 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-02-21 00:26:58 +0000
commitef7844666b36226521e459d18f2834dacaa039e3 (patch)
tree92aa83c61ffcb5d6f27d673104cbf9cae2b24224 /lib/CodeGen
parent362054766d3dacb8a87c0ee3f503d096709adf08 (diff)
Emit the exact size for the invariant intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151010 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGDeclCXX.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp
index d8ece58d6e..fac38a3242 100644
--- a/lib/CodeGen/CGDeclCXX.cpp
+++ b/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;