[PATCH] D99291: [AIX] Support init priority attribute
This revision was automatically updated to reflect the committed changes. Xiangling_L marked an inline comment as done. Closed by commit rGd5085617986e: [AIX] Support init priority attribute (authored by Xiangling_L). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99291/new/ https://reviews.llvm.org/D99291 Files: clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/aix-init-priority-attribute.cpp Index: clang/test/CodeGen/aix-init-priority-attribute.cpp === --- clang/test/CodeGen/aix-init-priority-attribute.cpp +++ clang/test/CodeGen/aix-init-priority-attribute.cpp @@ -1,19 +1,72 @@ -// RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s \ -// RUN: 2>&1 | \ +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s | \ // RUN: FileCheck %s -// RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s \ -// RUN: 2>&1 | \ +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s | \ // RUN: FileCheck %s -class test { - int a; - -public: - test(int c) { a = c; } - ~test() { a = 0; } +struct test { + test() {} + ~test() {} }; -__attribute__((init_priority(2000))) -test t(1); +__attribute__((init_priority(200))) +test t1; +__attribute__((init_priority(200))) +test t2; +__attribute__((init_priority(300))) +test t3; +__attribute__((init_priority(150))) +test t4; +test t5; + +// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__I_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__I_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__I_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }] +// CHECK: @llvm.global_dtors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__a_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__a_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__a_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_a, i8* null }] + +// CHECK: define internal void @_GLOBAL__I_000150() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.3() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__I_000200() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init() +// CHECK: call void @__cxx_global_var_init.1() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__I_000300() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.2() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__sub_I__() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.4() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000150() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t4() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000200() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t2() +// CHECK: call void @__finalize_t1() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000300() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t3() +// CHECK: ret void +// CHECK: } -// CHECK: fatal error: error in backend: 'init_priority' attribute is not yet supported on AIX +// CHECK: define internal void @_GLOBAL__D_a() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t5() +// CHECK: ret void +// CHECK: } Index: clang/lib/Sema/SemaDeclAttr.cpp === --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -7926,10 +7926,6 @@ handleVecTypeHint(S, D, AL); break; case ParsedAttr::AT_InitPriority: -if (S.Context.getTargetInfo().getTriple().isOSAIX()) - llvm::report_fatal_error( - "'init_priority' attribute is not yet supported on AIX"); -else handleInitPriorityAttr(S, D, AL); break; case ParsedAttr::AT_Packed: Index: clang/lib/CodeGen/ItaniumCXXABI.cpp === --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -4728,16 +4728,17 @@ CGF.FinishFunction(); - assert(!D.getAttr() && - "Prioritized sinit and sterm functions are not yet supported."); - - if (isTemplateInstantiation(D.getTemplateSpecializationKind()) || - getContext().GetGVALinkageForVariable() == GVA_DiscardableODR) + if (auto *IPA =
[PATCH] D99291: [AIX] Support init priority attribute
Xiangling_L marked an inline comment as done. Xiangling_L added inline comments. Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:663 + // Create our global prioritized cleanup function. + if (!PrioritizedCXXStermFinalizers.empty()) { jasonliu wrote: > Just noting that this trunk of code have very similar logic counter part in > `EmitCXXGlobalInitFunc`. It seems there is no easy way to common them up > given the current way of implementing it. It may require a non-trivial amount > of refactoring for us to common up the similar logic between init and > cleanup. Yes, I thought about this as well but it looks if we'd like to common it up, we may need to create some template function. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99291/new/ https://reviews.llvm.org/D99291 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D99291: [AIX] Support init priority attribute
jasonliu accepted this revision. jasonliu added a comment. This revision is now accepted and ready to land. LGTM. Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:663 + // Create our global prioritized cleanup function. + if (!PrioritizedCXXStermFinalizers.empty()) { Just noting that this trunk of code have very similar logic counter part in `EmitCXXGlobalInitFunc`. It seems there is no easy way to common them up given the current way of implementing it. It may require a non-trivial amount of refactoring for us to common up the similar logic between init and cleanup. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99291/new/ https://reviews.llvm.org/D99291 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D99291: [AIX] Support init priority attribute
Xiangling_L updated this revision to Diff 58. Xiangling_L marked an inline comment as done. Xiangling_L added a comment. Add assertion to make sure we have correct priority value in range; CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99291/new/ https://reviews.llvm.org/D99291 Files: clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/aix-init-priority-attribute.cpp Index: clang/test/CodeGen/aix-init-priority-attribute.cpp === --- clang/test/CodeGen/aix-init-priority-attribute.cpp +++ clang/test/CodeGen/aix-init-priority-attribute.cpp @@ -1,19 +1,72 @@ -// RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s \ -// RUN: 2>&1 | \ +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s | \ // RUN: FileCheck %s -// RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s \ -// RUN: 2>&1 | \ +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s | \ // RUN: FileCheck %s -class test { - int a; - -public: - test(int c) { a = c; } - ~test() { a = 0; } +struct test { + test() {} + ~test() {} }; -__attribute__((init_priority(2000))) -test t(1); +__attribute__((init_priority(200))) +test t1; +__attribute__((init_priority(200))) +test t2; +__attribute__((init_priority(300))) +test t3; +__attribute__((init_priority(150))) +test t4; +test t5; + +// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__I_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__I_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__I_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }] +// CHECK: @llvm.global_dtors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__a_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__a_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__a_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_a, i8* null }] + +// CHECK: define internal void @_GLOBAL__I_000150() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.3() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__I_000200() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init() +// CHECK: call void @__cxx_global_var_init.1() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__I_000300() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.2() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__sub_I__() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.4() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000150() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t4() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000200() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t2() +// CHECK: call void @__finalize_t1() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000300() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t3() +// CHECK: ret void +// CHECK: } -// CHECK: fatal error: error in backend: 'init_priority' attribute is not yet supported on AIX +// CHECK: define internal void @_GLOBAL__D_a() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t5() +// CHECK: ret void +// CHECK: } Index: clang/lib/Sema/SemaDeclAttr.cpp === --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -8058,10 +8058,6 @@ handleVecTypeHint(S, D, AL); break; case ParsedAttr::AT_InitPriority: -if (S.Context.getTargetInfo().getTriple().isOSAIX()) - llvm::report_fatal_error( - "'init_priority' attribute is not yet supported on AIX"); -else handleInitPriorityAttr(S, D, AL); break; case ParsedAttr::AT_Packed: Index: clang/lib/CodeGen/ItaniumCXXABI.cpp === --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -4728,16 +4728,17 @@ CGF.FinishFunction(); - assert(!D.getAttr() && - "Prioritized sinit and sterm functions are not yet supported."); - - if (isTemplateInstantiation(D.getTemplateSpecializationKind()) || - getContext().GetGVALinkageForVariable() == GVA_DiscardableODR) + if (auto *IPA = D.getAttr()) { +
[PATCH] D99291: [AIX] Support init priority attribute
aaron.ballman added inline comments. Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:574 + std::string PrioritySuffix = llvm::utostr(Priority); + // Priority is always <= 65535 (enforced by sema). + PrioritySuffix = std::string(6 - PrioritySuffix.size(), '0') + PrioritySuffix; This isn't quite true -- it's enforced by sema for user code, but not for code that identifies itself as a system header. I see that this is existing code that's moved around a bit, but we may want to add an assertion here just in case. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99291/new/ https://reviews.llvm.org/D99291 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D99291: [AIX] Support init priority attribute
Xiangling_L created this revision. Xiangling_L added reviewers: jasonliu, hubert.reinterpretcast, ZarkoCA, xingxue. Herald added a reviewer: aaron.ballman. Xiangling_L requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D99291 Files: clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/aix-init-priority-attribute.cpp Index: clang/test/CodeGen/aix-init-priority-attribute.cpp === --- clang/test/CodeGen/aix-init-priority-attribute.cpp +++ clang/test/CodeGen/aix-init-priority-attribute.cpp @@ -1,19 +1,72 @@ -// RUN: not %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s \ -// RUN: 2>&1 | \ +// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -x c++ -emit-llvm < %s | \ // RUN: FileCheck %s -// RUN: not %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s \ -// RUN: 2>&1 | \ +// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -x c++ -emit-llvm < %s | \ // RUN: FileCheck %s -class test { - int a; - -public: - test(int c) { a = c; } - ~test() { a = 0; } +struct test { + test() {} + ~test() {} }; -__attribute__((init_priority(2000))) -test t(1); +__attribute__((init_priority(200))) +test t1; +__attribute__((init_priority(200))) +test t2; +__attribute__((init_priority(300))) +test t3; +__attribute__((init_priority(150))) +test t4; +test t5; + +// CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__I_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__I_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__I_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I__, i8* null }] +// CHECK: @llvm.global_dtors = appending global [4 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 150, void ()* @_GLOBAL__a_000150, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @_GLOBAL__a_000200, i8* null }, { i32, void ()*, i8* } { i32 300, void ()* @_GLOBAL__a_000300, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__D_a, i8* null }] + +// CHECK: define internal void @_GLOBAL__I_000150() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.3() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__I_000200() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init() +// CHECK: call void @__cxx_global_var_init.1() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__I_000300() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.2() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__sub_I__() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__cxx_global_var_init.4() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000150() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t4() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000200() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t2() +// CHECK: call void @__finalize_t1() +// CHECK: ret void +// CHECK: } + +// CHECK: define internal void @_GLOBAL__a_000300() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t3() +// CHECK: ret void +// CHECK: } -// CHECK: fatal error: error in backend: 'init_priority' attribute is not yet supported on AIX +// CHECK: define internal void @_GLOBAL__D_a() [[ATTR:#[0-9]+]] { +// CHECK: entry: +// CHECK: call void @__finalize_t5() +// CHECK: ret void +// CHECK: } Index: clang/lib/Sema/SemaDeclAttr.cpp === --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -8058,10 +8058,6 @@ handleVecTypeHint(S, D, AL); break; case ParsedAttr::AT_InitPriority: -if (S.Context.getTargetInfo().getTriple().isOSAIX()) - llvm::report_fatal_error( - "'init_priority' attribute is not yet supported on AIX"); -else handleInitPriorityAttr(S, D, AL); break; case ParsedAttr::AT_Packed: Index: clang/lib/CodeGen/ItaniumCXXABI.cpp === --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -4728,16 +4728,17 @@ CGF.FinishFunction(); - assert(!D.getAttr() && - "Prioritized sinit and sterm functions are not yet supported."); - - if (isTemplateInstantiation(D.getTemplateSpecializationKind()) || - getContext().GetGVALinkageForVariable() == GVA_DiscardableODR) + if (auto *IPA =