Emit the exact size for the invariant intrinsics.

llvm-svn: 151010
This commit is contained in:
Nick Lewycky
2012-02-21 00:26:58 +00:00
parent 1ac04c3088
commit 4506204640
2 changed files with 12 additions and 9 deletions

View File

@@ -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;

View File

@@ -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