Author: abataev Date: Wed May 9 07:15:18 2018 New Revision: 331879 URL: http://llvm.org/viewvc/llvm-project?rev=331879&view=rev Log: [OPENMP] Mark global tors/dtors as used.
If the global variables are marked as declare target and they need ctors/dtors, these ctors/dtors are emitted and then invoked by the offloading runtime library. They are not explicitly used in the emitted code and thus can be optimized out. Patch marks these functions as used, so the optimizer cannot remove these function during the optimization phase. Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp cfe/trunk/test/OpenMP/declare_target_codegen.cpp Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=331879&r1=331878&r2=331879&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original) +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed May 9 07:15:18 2018 @@ -2686,6 +2686,7 @@ bool CGOpenMPRuntime::emitDeclareTargetV CtorCGF.FinishFunction(); Ctor = Fn; ID = llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy); + CGM.addUsedGlobal(cast<llvm::GlobalValue>(Ctor)); } else { Ctor = new llvm::GlobalVariable( CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true, @@ -2724,6 +2725,7 @@ bool CGOpenMPRuntime::emitDeclareTargetV DtorCGF.FinishFunction(); Dtor = Fn; ID = llvm::ConstantExpr::getBitCast(Fn, CGM.Int8PtrTy); + CGM.addUsedGlobal(cast<llvm::GlobalValue>(Dtor)); } else { Dtor = new llvm::GlobalVariable( CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true, Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=331879&r1=331878&r2=331879&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original) +++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Wed May 9 07:15:18 2018 @@ -17,10 +17,13 @@ // CHECK-DAG: @b = global i32 15, // CHECK-DAG: @d = global i32 0, // CHECK-DAG: @c = external global i32, +// CHECK-DAG: @globals = global %struct.S zeroinitializer, +// CHECK-DAG: @llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @__omp_offloading__{{.+}}_globals_l[[@LINE+41]]_ctor to i8*)], section "llvm.metadata" // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}() // CHECK-DAG: define {{.*}}void @{{.*}}TemplateClass{{.*}}(%class.TemplateClass* %{{.*}}) // CHECK-DAG: define {{.*}}i32 @{{.*}}TemplateClass{{.*}}f_method{{.*}}(%class.TemplateClass* %{{.*}}) +// CHECK-DAG: define {{.*}}void @__omp_offloading__{{.*}}_globals_l[[@LINE+36]]_ctor() #ifndef HEADER #define HEADER @@ -56,6 +59,7 @@ struct S { int foo() { return 0; } int b = 15; int d; +S globals(d); #pragma omp end declare target int c; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits