浏览代码

Clang changes for overloading invariant.start and end intrinsics

This change depends on the corresponding LLVM change at:
https://reviews.llvm.org/D22519

The llvm.invariant.start and llvm.invariant.end intrinsics currently
support specifying invariant memory objects only in the default address
space.

With this LLVM change, these intrinsics are overloaded for any adddress space
for memory objects and we can use these llvm invariant intrinsics in
non-default address spaces.

Example: llvm.invariant.start.p1i8(i64 4, i8 addrspace(1)* %ptr)

This overloaded intrinsic is needed for representing final or invariant
memory in managed languages.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276448 91177308-0d34-0410-b5e6-96231b3b80d8
Anna Thomas 9 年之前
父节点
当前提交
f9fef1ef2e
共有 2 个文件被更改,包括 10 次插入8 次删除
  1. 3 1
      lib/CodeGen/CGDeclCXX.cpp
  2. 7 7
      test/CodeGenCXX/init-invariant.cpp

+ 3 - 1
lib/CodeGen/CGDeclCXX.cpp

@@ -127,7 +127,9 @@ static void EmitDeclInvariant(CodeGenFunction &CGF, const VarDecl &D,
 
 
   // Grab the llvm.invariant.start intrinsic.
   // Grab the llvm.invariant.start intrinsic.
   llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
   llvm::Intrinsic::ID InvStartID = llvm::Intrinsic::invariant_start;
-  llvm::Constant *InvariantStart = CGF.CGM.getIntrinsic(InvStartID);
+  // Overloaded address space type.
+  llvm::Type *ObjectPtr[1] = {CGF.Int8PtrTy};
+  llvm::Constant *InvariantStart = CGF.CGM.getIntrinsic(InvStartID, ObjectPtr);
 
 
   // Emit a call with the size in bytes of the object.
   // Emit a call with the size in bytes of the object.
   CharUnits WidthChars = CGF.getContext().getTypeSizeInChars(D.getType());
   CharUnits WidthChars = CGF.getContext().getTypeSizeInChars(D.getType());

+ 7 - 7
test/CodeGenCXX/init-invariant.cpp

@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O0
 // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O0
 // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -o - | FileCheck %s
 // RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -o - | FileCheck %s
 
 
-// Check that we add an llvm.invariant.start to mark when a global becomes
+// Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes
 // read-only. If globalopt can fold the initializer, it will then mark the
 // read-only. If globalopt can fold the initializer, it will then mark the
 // variable as constant.
 // variable as constant.
 
 
 // Do not produce markers at -O0.
 // Do not produce markers at -O0.
-// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.start.p0i8
 
 
 struct A {
 struct A {
   A();
   A();
@@ -42,19 +42,19 @@ void e() {
 }
 }
 
 
 // CHECK: call void @_ZN1AC1Ev({{.*}}* nonnull @a)
 // CHECK: call void @_ZN1AC1Ev({{.*}}* nonnull @a)
-// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @b to i8*))
 
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK-NOT: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @c to i8*))
 
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
 // CHECK: store {{.*}}, i32* @d
-// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @d to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* bitcast ({{.*}} @d to i8*))
 
 
 // CHECK-LABEL: define void @_Z1ev(
 // CHECK-LABEL: define void @_Z1ev(
 // CHECK: call void @_ZN1AC1Ev(%struct.A* nonnull @_ZZ1evE1a)
 // CHECK: call void @_ZN1AC1Ev(%struct.A* nonnull @_ZZ1evE1a)
-// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* {{.*}}bitcast ({{.*}} @_ZZ1evE1a to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start.p0i8(i64 4, i8* {{.*}}bitcast ({{.*}} @_ZZ1evE1a to i8*))
 // CHECK-NOT: llvm.invariant.end
 // CHECK-NOT: llvm.invariant.end