summaryrefslogtreecommitdiffstats
path: root/clang
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
commit45062046405c649c9b493f0f2abb04c6bdcba368 (patch)
treed6794333922f0959954c41b0e5cd58e93a302d4a /clang
parent1ac04c308832f7a9b2e07e360f07c82f7cb2a02c (diff)
downloadbcm5719-llvm-45062046405c649c9b493f0f2abb04c6bdcba368.tar.gz
bcm5719-llvm-45062046405c649c9b493f0f2abb04c6bdcba368.zip
Emit the exact size for the invariant intrinsics.
llvm-svn: 151010
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGDeclCXX.cpp11
-rw-r--r--clang/test/CodeGenCXX/init-invariant.cpp10
2 files changed, 12 insertions, 9 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;
diff --git a/clang/test/CodeGenCXX/init-invariant.cpp b/clang/test/CodeGenCXX/init-invariant.cpp
index 5d0ff8b0db0..9eb19896b6b 100644
--- a/clang/test/CodeGenCXX/init-invariant.cpp
+++ b/clang/test/CodeGenCXX/init-invariant.cpp
@@ -42,19 +42,19 @@ void e() {
}
// CHECK: call void @_ZN1AC1Ev({{.*}}* @a)
-// CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @a to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
// CHECK: call void @_ZN1BC1Ev({{.*}}* @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @b to i8*))
+// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
// CHECK: call void @_ZN1CC1Ev({{.*}}* @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @c to i8*))
+// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
// CHECK: call i32 @_Z1fv(
// CHECK: store {{.*}}, i32* @d
-// CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @d to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @d to i8*))
// CHECK: define void @_Z1ev(
// CHECK: call void @_ZN1AC1Ev(%struct.A* @_ZZ1evE1a)
-// CHECK: call {{.*}}@llvm.invariant.start(i64 -1, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @_ZZ1evE1a to i8*))
// CHECK-NOT: llvm.invariant.end
OpenPOWER on IntegriCloud