[llvm] [AArch64] Add AArch64PassRegistry.def (PR #85215)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 20 18:31:31 PDT 2024
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/85215
>From 53b2f72a17e72fef9c0c1893e3179886c7d14355 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Thu, 14 Mar 2024 20:38:04 +0800
Subject: [PATCH 1/2] [AArch64] Add AArch64PassRegistry.def
---
.../llvm/Passes/TargetPassRegistry.inc | 334 ++++++++++++++++++
.../Target/AArch64/AArch64PassRegistry.def | 20 ++
.../Target/AArch64/AArch64TargetMachine.cpp | 4 +
.../LoopIdiom/AArch64/byte-compare-index.ll | 31 +-
4 files changed, 380 insertions(+), 9 deletions(-)
create mode 100644 llvm/include/llvm/Passes/TargetPassRegistry.inc
create mode 100644 llvm/lib/Target/AArch64/AArch64PassRegistry.def
diff --git a/llvm/include/llvm/Passes/TargetPassRegistry.inc b/llvm/include/llvm/Passes/TargetPassRegistry.inc
new file mode 100644
index 00000000000000..a71d88ad0b7098
--- /dev/null
+++ b/llvm/include/llvm/Passes/TargetPassRegistry.inc
@@ -0,0 +1,334 @@
+//===- TargetPassRegistry.inc - Registry of passes --------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is used as the registry of passes in registerPassBuilderCallbacks
+//
+//===----------------------------------------------------------------------===//
+
+// NOTE: NO INCLUDE GUARD DESIRED!
+
+#ifdef GET_PASS_REGISTRY
+
+#if !__has_include(GET_PASS_REGISTRY)
+#error "must provide <Target>PassRegistry.def"
+#endif
+
+{
+
+ // FIXME: use std::size when MSVC_MIN >= 19.30
+
+ static constexpr bool HAVE_MODULE_ANALYSIS_ =
+ std::array{
+ "",
+#define MODULE_ANALYSIS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef MODULE_ANALYSIS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_MODULE_PASS_ =
+ std::array{
+ "",
+#define MODULE_PASS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef MODULE_PASS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_MODULE_PASS_WITH_PARAMS_ =
+ std::array{
+ "",
+#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) NAME,
+#include GET_PASS_REGISTRY
+#undef MODULE_PASS_WITH_PARAMS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_FUNCTION_ANALYSIS_ =
+ std::array{
+ "",
+#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef FUNCTION_ANALYSIS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_FUNCTION_ALIAS_ANALYSIS_ =
+ std::array{
+ "",
+#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef FUNCTION_ALIAS_ANALYSIS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_FUNCTION_PASS_ =
+ std::array{
+ "",
+#define FUNCTION_PASS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef FUNCTION_PASS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_FUNCTION_PASS_WITH_PARAMS_ =
+ std::array{
+ "",
+#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
+ NAME,
+#include GET_PASS_REGISTRY
+#undef FUNCTION_PASS_WITH_PARAMS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_LOOP_ANALYSIS_ =
+ std::array{
+ "",
+#define LOOP_ANALYSIS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef LOOP_ANALYSIS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_LOOP_PASS_ =
+ std::array{
+ "",
+#define LOOP_PASS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef LOOP_PASS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_MACHINE_FUNCTION_ANALYSIS_ =
+ std::array{
+ "",
+#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef MACHINE_FUNCTION_ANALYSIS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_MACHINE_FUNCTION_PASS_ =
+ std::array{
+ "",
+#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) NAME,
+#include GET_PASS_REGISTRY
+#undef MACHINE_FUNCTION_PASS
+ }
+ .size() > 1;
+
+ static constexpr bool HAVE_MACHINE_FUNCTION_PASS_WITH_PARAMS_ =
+ std::array{
+ "",
+#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
+ PARAMS) \
+ NAME,
+#include GET_PASS_REGISTRY
+#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
+ }
+ .size() > 1;
+
+ if (PopulateClassToPassNames) {
+ auto *PIC = PB.getPassInstrumentationCallbacks();
+
+#define ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS) \
+ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
+#define ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS) \
+ PIC->addClassToPassName(CLASS, NAME);
+
+#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define MODULE_PASS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
+ ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
+#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define FUNCTION_PASS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
+ ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
+#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define LOOP_PASS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
+ ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
+#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
+ PARAMS) \
+ ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CREATE_PASS)
+#include GET_PASS_REGISTRY
+#undef MODULE_ANALYSIS
+#undef MODULE_PASS
+#undef MODULE_PASS_WITH_PARAMS
+#undef FUNCTION_ANALYSIS
+#undef FUNCTION_PASS
+#undef FUNCTION_PASS_WITH_PARAMS
+#undef LOOP_ANALYSIS
+#undef LOOP_PASS
+#undef MACHINE_FUNCTION_ANALYSIS
+#undef MACHINE_FUNCTION_PASS
+#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
+#undef ADD_CLASS_PASS_TO_PASS_NAME
+#undef ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS
+ }
+
+#define ADD_PASS(NAME, CREATE_PASS) \
+ if (Name == NAME) { \
+ PM.addPass(CREATE_PASS); \
+ return true; \
+ }
+
+#define ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
+ if (PassBuilder::checkParametrizedPassName(Name, NAME)) { \
+ auto Params = PassBuilder::parsePassParameters(PARSER, Name, NAME); \
+ if (!Params) \
+ return false; \
+ PM.addPass(CREATE_PASS(Params.get())); \
+ return true; \
+ }
+
+ if constexpr (HAVE_MODULE_PASS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, ModulePassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define MODULE_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
+#include GET_PASS_REGISTRY
+#undef MODULE_PASS
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_MODULE_PASS_WITH_PARAMS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, ModulePassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
+ ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
+#include GET_PASS_REGISTRY
+#undef MODULE_PASS_WITH_PARAMS
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_FUNCTION_PASS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, FunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
+#include GET_PASS_REGISTRY
+#undef FUNCTION_PASS
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_FUNCTION_PASS_WITH_PARAMS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, FunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
+ ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
+#include GET_PASS_REGISTRY
+#undef FUNCTION_PASS_WITH_PARAMS
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_LOOP_PASS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, LoopPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define LOOP_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
+#include GET_PASS_REGISTRY
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_MACHINE_FUNCTION_PASS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, MachineFunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
+#include GET_PASS_REGISTRY
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_MACHINE_FUNCTION_PASS_WITH_PARAMS_) {
+ PB.registerPipelineParsingCallback(
+ [=](StringRef Name, FunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
+#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
+ PARAMS) \
+ ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
+#include GET_PASS_REGISTRY
+#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
+ return false;
+ });
+ }
+#undef ADD_PASS
+#undef ADD_PASS_WITH_PARAMS
+
+ if constexpr (HAVE_MODULE_ANALYSIS_) {
+ PB.registerAnalysisRegistrationCallback([](ModuleAnalysisManager &AM) {
+#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
+ AM.registerPass([&] { return CREATE_PASS; });
+#include GET_PASS_REGISTRY
+#undef MODULE_ANALYSIS
+ });
+ }
+
+ if constexpr (HAVE_FUNCTION_ANALYSIS_) {
+ PB.registerAnalysisRegistrationCallback([](FunctionAnalysisManager &AM) {
+#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
+ AM.registerPass([&] { return CREATE_PASS; });
+#include GET_PASS_REGISTRY
+#undef FUNCTION_ANALYSIS
+ });
+ }
+
+ if constexpr (HAVE_FUNCTION_ALIAS_ANALYSIS_) {
+ PB.registerParseAACallback([](StringRef Name, AAManager &AM) {
+#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
+ if (Name == NAME) { \
+ AM.registerFunctionAnalysis< \
+ std::remove_reference_t<decltype(CREATE_PASS)>>(); \
+ return true; \
+ }
+#include GET_PASS_REGISTRY
+#undef FUNCTION_ANALYSIS
+ return false;
+ });
+ }
+
+ if constexpr (HAVE_LOOP_ANALYSIS_) {
+ PB.registerAnalysisRegistrationCallback([](LoopAnalysisManager &AM) {
+#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
+ AM.registerPass([&] { return CREATE_PASS; });
+#include GET_PASS_REGISTRY
+#undef LOOP_ANALYSIS
+ });
+ }
+
+ if constexpr (HAVE_MACHINE_FUNCTION_ANALYSIS_) {
+ PB.registerAnalysisRegistrationCallback(
+ [](MachineFunctionAnalysisManager &AM) {
+#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
+ AM.registerPass([&] { return CREATE_PASS; });
+#include GET_PASS_REGISTRY
+#undef MACHINE_FUNCTION_ANALYSIS
+ });
+ }
+}
+
+#undef GET_PASS_REGISTRY
+#endif // GET_PASS_REGISTRY
diff --git a/llvm/lib/Target/AArch64/AArch64PassRegistry.def b/llvm/lib/Target/AArch64/AArch64PassRegistry.def
new file mode 100644
index 00000000000000..ca944579f93a93
--- /dev/null
+++ b/llvm/lib/Target/AArch64/AArch64PassRegistry.def
@@ -0,0 +1,20 @@
+//===- AArch64PassRegistry.def - Registry of AArch64 passes -----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is used as the registry of passes that are part of the
+// AArch64 backend.
+//
+//===----------------------------------------------------------------------===//
+
+// NOTE: NO INCLUDE GUARD DESIRED!
+
+#ifndef LOOP_PASS
+#define LOOP_PASS(NAME, CREATE_PASS)
+#endif
+LOOP_PASS("aarch64-lit", AArch64LoopIdiomTransformPass())
+#undef LOOP_PASS
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index e5e60459e8148a..08238fdf167bf2 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -547,6 +547,10 @@ class AArch64PassConfig : public TargetPassConfig {
void AArch64TargetMachine::registerPassBuilderCallbacks(
PassBuilder &PB, bool PopulateClassToPassNames) {
+
+#define GET_PASS_REGISTRY "AArch64PassRegistry.def"
+#include "llvm/Passes/TargetPassRegistry.inc"
+
PB.registerLateLoopOptimizationsEPCallback(
[=](LoopPassManager &LPM, OptimizationLevel Level) {
LPM.addPass(AArch64LoopIdiomTransformPass());
diff --git a/llvm/test/Transforms/LoopIdiom/AArch64/byte-compare-index.ll b/llvm/test/Transforms/LoopIdiom/AArch64/byte-compare-index.ll
index e6a0c5f45375fd..daa64f2e2ea7c0 100644
--- a/llvm/test/Transforms/LoopIdiom/AArch64/byte-compare-index.ll
+++ b/llvm/test/Transforms/LoopIdiom/AArch64/byte-compare-index.ll
@@ -2,6 +2,9 @@
; RUN: opt -aarch64-lit -aarch64-lit-verify -verify-dom-info -mtriple aarch64-unknown-linux-gnu -mattr=+sve -S < %s | FileCheck %s
; RUN: opt -aarch64-lit -simplifycfg -mtriple aarch64-unknown-linux-gnu -mattr=+sve -S < %s | FileCheck %s --check-prefix=LOOP-DEL
; RUN: opt -aarch64-lit -mtriple aarch64-unknown-linux-gnu -S < %s | FileCheck %s --check-prefix=NO-TRANSFORM
+; RUN: opt -p aarch64-lit -aarch64-lit-verify -verify-dom-info -mtriple aarch64-unknown-linux-gnu -mattr=+sve -S < %s | FileCheck %s
+; RUN: opt -passes='function(loop(aarch64-lit)),simplifycfg' -mtriple aarch64-unknown-linux-gnu -mattr=+sve -S < %s | FileCheck %s --check-prefix=LOOP-DEL
+; RUN: opt -p aarch64-lit -mtriple aarch64-unknown-linux-gnu -S < %s | FileCheck %s --check-prefix=NO-TRANSFORM
define i32 @compare_bytes_simple(ptr %a, ptr %b, i32 %len, i32 %extra, i32 %n) {
; CHECK-LABEL: define i32 @compare_bytes_simple(
@@ -780,7 +783,7 @@ define i32 @compare_bytes_extra_cmp(ptr %a, ptr %b, i32 %len, i32 %n, i32 %x) {
; CHECK-NEXT: [[LEN_ADDR:%.*]] = phi i32 [ [[LEN]], [[MISMATCH_END]] ], [ [[MISMATCH_RESULT]], [[WHILE_BODY:%.*]] ]
; CHECK-NEXT: [[INC:%.*]] = add i32 [[LEN_ADDR]], 1
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[MISMATCH_RESULT]], [[N]]
-; CHECK-NEXT: br i1 [[CMP_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; CHECK-NEXT: br i1 [[CMP_NOT]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
; CHECK: while.body:
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[MISMATCH_RESULT]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[IDXPROM]]
@@ -788,11 +791,14 @@ define i32 @compare_bytes_extra_cmp(ptr %a, ptr %b, i32 %len, i32 %n, i32 %x) {
; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i8, ptr [[B]], i64 [[IDXPROM]]
; CHECK-NEXT: [[TMP46:%.*]] = load i8, ptr [[ARRAYIDX2]], align 1
; CHECK-NEXT: [[CMP_NOT2:%.*]] = icmp eq i8 [[TMP45]], [[TMP46]]
-; CHECK-NEXT: br i1 [[CMP_NOT2]], label [[WHILE_COND]], label [[WHILE_END]]
+; CHECK-NEXT: br i1 [[CMP_NOT2]], label [[WHILE_COND]], label [[WHILE_END_LOOPEXIT]]
; CHECK: byte.compare:
+; CHECK-NEXT: br label [[WHILE_END_LOOPEXIT]]
+; CHECK: while.end.loopexit:
+; CHECK-NEXT: [[INC_LCSSA1:%.*]] = phi i32 [ [[MISMATCH_RESULT]], [[WHILE_COND]] ], [ [[MISMATCH_RESULT]], [[WHILE_BODY]] ], [ [[MISMATCH_RESULT]], [[BYTE_COMPARE]] ]
; CHECK-NEXT: br label [[WHILE_END]]
; CHECK: while.end:
-; CHECK-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[MISMATCH_RESULT]], [[WHILE_BODY]] ], [ [[MISMATCH_RESULT]], [[WHILE_COND]] ], [ [[X]], [[ENTRY:%.*]] ], [ [[MISMATCH_RESULT]], [[BYTE_COMPARE]] ]
+; CHECK-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[X]], [[ENTRY:%.*]] ], [ [[INC_LCSSA1]], [[WHILE_END_LOOPEXIT]] ]
; CHECK-NEXT: ret i32 [[INC_LCSSA]]
;
; LOOP-DEL-LABEL: define i32 @compare_bytes_extra_cmp(
@@ -884,7 +890,7 @@ define i32 @compare_bytes_extra_cmp(ptr %a, ptr %b, i32 %len, i32 %n, i32 %x) {
; NO-TRANSFORM-NEXT: [[LEN_ADDR:%.*]] = phi i32 [ [[LEN]], [[PH]] ], [ [[INC:%.*]], [[WHILE_BODY:%.*]] ]
; NO-TRANSFORM-NEXT: [[INC]] = add i32 [[LEN_ADDR]], 1
; NO-TRANSFORM-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[INC]], [[N]]
-; NO-TRANSFORM-NEXT: br i1 [[CMP_NOT]], label [[WHILE_END]], label [[WHILE_BODY]]
+; NO-TRANSFORM-NEXT: br i1 [[CMP_NOT]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
; NO-TRANSFORM: while.body:
; NO-TRANSFORM-NEXT: [[IDXPROM:%.*]] = zext i32 [[INC]] to i64
; NO-TRANSFORM-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 [[IDXPROM]]
@@ -892,9 +898,12 @@ define i32 @compare_bytes_extra_cmp(ptr %a, ptr %b, i32 %len, i32 %n, i32 %x) {
; NO-TRANSFORM-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i8, ptr [[B]], i64 [[IDXPROM]]
; NO-TRANSFORM-NEXT: [[TMP1:%.*]] = load i8, ptr [[ARRAYIDX2]], align 1
; NO-TRANSFORM-NEXT: [[CMP_NOT2:%.*]] = icmp eq i8 [[TMP0]], [[TMP1]]
-; NO-TRANSFORM-NEXT: br i1 [[CMP_NOT2]], label [[WHILE_COND]], label [[WHILE_END]]
+; NO-TRANSFORM-NEXT: br i1 [[CMP_NOT2]], label [[WHILE_COND]], label [[WHILE_END_LOOPEXIT]]
+; NO-TRANSFORM: while.end.loopexit:
+; NO-TRANSFORM-NEXT: [[INC_LCSSA1:%.*]] = phi i32 [ [[INC]], [[WHILE_COND]] ], [ [[INC]], [[WHILE_BODY]] ]
+; NO-TRANSFORM-NEXT: br label [[WHILE_END]]
; NO-TRANSFORM: while.end:
-; NO-TRANSFORM-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[INC]], [[WHILE_BODY]] ], [ [[INC]], [[WHILE_COND]] ], [ [[X]], [[ENTRY:%.*]] ]
+; NO-TRANSFORM-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[X]], [[ENTRY:%.*]] ], [ [[INC_LCSSA1]], [[WHILE_END_LOOPEXIT]] ]
; NO-TRANSFORM-NEXT: ret i32 [[INC_LCSSA]]
;
entry:
@@ -908,7 +917,7 @@ while.cond:
%len.addr = phi i32 [ %len, %ph ], [ %inc, %while.body ]
%inc = add i32 %len.addr, 1
%cmp.not = icmp eq i32 %inc, %n
- br i1 %cmp.not, label %while.end, label %while.body
+ br i1 %cmp.not, label %while.end.loopexit, label %while.body
while.body:
%idxprom = zext i32 %inc to i64
@@ -917,10 +926,14 @@ while.body:
%arrayidx2 = getelementptr inbounds i8, ptr %b, i64 %idxprom
%1 = load i8, ptr %arrayidx2
%cmp.not2 = icmp eq i8 %0, %1
- br i1 %cmp.not2, label %while.cond, label %while.end
+ br i1 %cmp.not2, label %while.cond, label %while.end.loopexit
+
+while.end.loopexit:
+ %inc.lcssa1 = phi i32 [ %inc, %while.cond ], [ %inc, %while.body ]
+ br label %while.end
while.end:
- %inc.lcssa = phi i32 [ %inc, %while.body ], [ %inc, %while.cond ], [ %x, %entry ]
+ %inc.lcssa = phi i32 [ %x, %entry ], [ %inc.lcssa1, %while.end.loopexit ]
ret i32 %inc.lcssa
}
>From 7bfe5b2f7cbe0dffad778ee391eeaea0788d3193 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Wed, 20 Mar 2024 15:22:57 +0800
Subject: [PATCH 2/2] always add callbacks
---
.../llvm/Passes/TargetPassRegistry.inc | 244 ++++--------------
1 file changed, 51 insertions(+), 193 deletions(-)
diff --git a/llvm/include/llvm/Passes/TargetPassRegistry.inc b/llvm/include/llvm/Passes/TargetPassRegistry.inc
index a71d88ad0b7098..50766a99f6a72f 100644
--- a/llvm/include/llvm/Passes/TargetPassRegistry.inc
+++ b/llvm/include/llvm/Passes/TargetPassRegistry.inc
@@ -7,6 +7,9 @@
//===----------------------------------------------------------------------===//
//
// This file is used as the registry of passes in registerPassBuilderCallbacks
+// Just put the following lines in the body of registerPassBuilderCallbacks:
+// #define GET_PASS_REGISTRY "<Target>PassRegistry.def"
+// #include "llvm/Passes/TargetPassRegistry.inc"
//
//===----------------------------------------------------------------------===//
@@ -18,123 +21,8 @@
#error "must provide <Target>PassRegistry.def"
#endif
-{
-
- // FIXME: use std::size when MSVC_MIN >= 19.30
-
- static constexpr bool HAVE_MODULE_ANALYSIS_ =
- std::array{
- "",
-#define MODULE_ANALYSIS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef MODULE_ANALYSIS
- }
- .size() > 1;
-
- static constexpr bool HAVE_MODULE_PASS_ =
- std::array{
- "",
-#define MODULE_PASS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef MODULE_PASS
- }
- .size() > 1;
-
- static constexpr bool HAVE_MODULE_PASS_WITH_PARAMS_ =
- std::array{
- "",
-#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) NAME,
-#include GET_PASS_REGISTRY
-#undef MODULE_PASS_WITH_PARAMS
- }
- .size() > 1;
-
- static constexpr bool HAVE_FUNCTION_ANALYSIS_ =
- std::array{
- "",
-#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef FUNCTION_ANALYSIS
- }
- .size() > 1;
-
- static constexpr bool HAVE_FUNCTION_ALIAS_ANALYSIS_ =
- std::array{
- "",
-#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef FUNCTION_ALIAS_ANALYSIS
- }
- .size() > 1;
-
- static constexpr bool HAVE_FUNCTION_PASS_ =
- std::array{
- "",
-#define FUNCTION_PASS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef FUNCTION_PASS
- }
- .size() > 1;
-
- static constexpr bool HAVE_FUNCTION_PASS_WITH_PARAMS_ =
- std::array{
- "",
-#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- NAME,
-#include GET_PASS_REGISTRY
-#undef FUNCTION_PASS_WITH_PARAMS
- }
- .size() > 1;
-
- static constexpr bool HAVE_LOOP_ANALYSIS_ =
- std::array{
- "",
-#define LOOP_ANALYSIS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef LOOP_ANALYSIS
- }
- .size() > 1;
-
- static constexpr bool HAVE_LOOP_PASS_ =
- std::array{
- "",
-#define LOOP_PASS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef LOOP_PASS
- }
- .size() > 1;
-
- static constexpr bool HAVE_MACHINE_FUNCTION_ANALYSIS_ =
- std::array{
- "",
-#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef MACHINE_FUNCTION_ANALYSIS
- }
- .size() > 1;
-
- static constexpr bool HAVE_MACHINE_FUNCTION_PASS_ =
- std::array{
- "",
-#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) NAME,
-#include GET_PASS_REGISTRY
-#undef MACHINE_FUNCTION_PASS
- }
- .size() > 1;
-
- static constexpr bool HAVE_MACHINE_FUNCTION_PASS_WITH_PARAMS_ =
- std::array{
- "",
-#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
- PARAMS) \
- NAME,
-#include GET_PASS_REGISTRY
-#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
- }
- .size() > 1;
-
- if (PopulateClassToPassNames) {
- auto *PIC = PB.getPassInstrumentationCallbacks();
+if (PopulateClassToPassNames) {
+ auto *PIC = PB.getPassInstrumentationCallbacks();
#define ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS) \
PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
@@ -165,12 +53,13 @@
ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
PARAMS) \
- ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CREATE_PASS)
+ ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
#include GET_PASS_REGISTRY
#undef MODULE_ANALYSIS
#undef MODULE_PASS
#undef MODULE_PASS_WITH_PARAMS
#undef FUNCTION_ANALYSIS
+#undef FUNCTION_ALIAS_ANALYSIS
#undef FUNCTION_PASS
#undef FUNCTION_PASS_WITH_PARAMS
#undef LOOP_ANALYSIS
@@ -180,7 +69,7 @@
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
#undef ADD_CLASS_PASS_TO_PASS_NAME
#undef ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS
- }
+}
#define ADD_PASS(NAME, CREATE_PASS) \
if (Name == NAME) { \
@@ -197,138 +86,107 @@
return true; \
}
- if constexpr (HAVE_MODULE_PASS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, ModulePassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define MODULE_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
#include GET_PASS_REGISTRY
#undef MODULE_PASS
- return false;
- });
- }
+ return false;
+});
- if constexpr (HAVE_MODULE_PASS_WITH_PARAMS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, ModulePassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
#include GET_PASS_REGISTRY
#undef MODULE_PASS_WITH_PARAMS
- return false;
- });
- }
+ return false;
+});
- if constexpr (HAVE_FUNCTION_PASS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, FunctionPassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
#include GET_PASS_REGISTRY
#undef FUNCTION_PASS
- return false;
- });
- }
+ return false;
+});
- if constexpr (HAVE_FUNCTION_PASS_WITH_PARAMS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, FunctionPassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
#include GET_PASS_REGISTRY
#undef FUNCTION_PASS_WITH_PARAMS
- return false;
- });
- }
+ return false;
+});
- if constexpr (HAVE_LOOP_PASS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, LoopPassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name, LoopPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define LOOP_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
#include GET_PASS_REGISTRY
- return false;
- });
- }
+ return false;
+});
- if constexpr (HAVE_MACHINE_FUNCTION_PASS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, MachineFunctionPassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name,
+ MachineFunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
#include GET_PASS_REGISTRY
- return false;
- });
- }
+ return false;
+});
- if constexpr (HAVE_MACHINE_FUNCTION_PASS_WITH_PARAMS_) {
- PB.registerPipelineParsingCallback(
- [=](StringRef Name, FunctionPassManager &PM,
- ArrayRef<PassBuilder::PipelineElement>) {
+PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
+ ArrayRef<PassBuilder::PipelineElement>) {
#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
PARAMS) \
ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
#include GET_PASS_REGISTRY
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
- return false;
- });
- }
+ return false;
+});
+
#undef ADD_PASS
#undef ADD_PASS_WITH_PARAMS
- if constexpr (HAVE_MODULE_ANALYSIS_) {
- PB.registerAnalysisRegistrationCallback([](ModuleAnalysisManager &AM) {
+PB.registerAnalysisRegistrationCallback([](ModuleAnalysisManager &AM) {
#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
AM.registerPass([&] { return CREATE_PASS; });
#include GET_PASS_REGISTRY
#undef MODULE_ANALYSIS
- });
- }
+});
- if constexpr (HAVE_FUNCTION_ANALYSIS_) {
- PB.registerAnalysisRegistrationCallback([](FunctionAnalysisManager &AM) {
+PB.registerAnalysisRegistrationCallback([](FunctionAnalysisManager &AM) {
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
AM.registerPass([&] { return CREATE_PASS; });
#include GET_PASS_REGISTRY
#undef FUNCTION_ANALYSIS
- });
- }
+});
- if constexpr (HAVE_FUNCTION_ALIAS_ANALYSIS_) {
- PB.registerParseAACallback([](StringRef Name, AAManager &AM) {
-#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
+PB.registerParseAACallback([](StringRef Name, AAManager &AM) {
+#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
if (Name == NAME) { \
AM.registerFunctionAnalysis< \
std::remove_reference_t<decltype(CREATE_PASS)>>(); \
return true; \
}
#include GET_PASS_REGISTRY
-#undef FUNCTION_ANALYSIS
- return false;
- });
- }
+#undef FUNCTION_ALIAS_ANALYSIS
+ return false;
+});
- if constexpr (HAVE_LOOP_ANALYSIS_) {
- PB.registerAnalysisRegistrationCallback([](LoopAnalysisManager &AM) {
+PB.registerAnalysisRegistrationCallback([](LoopAnalysisManager &AM) {
#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
AM.registerPass([&] { return CREATE_PASS; });
#include GET_PASS_REGISTRY
#undef LOOP_ANALYSIS
- });
- }
+});
- if constexpr (HAVE_MACHINE_FUNCTION_ANALYSIS_) {
- PB.registerAnalysisRegistrationCallback(
- [](MachineFunctionAnalysisManager &AM) {
+PB.registerAnalysisRegistrationCallback([](MachineFunctionAnalysisManager &AM) {
#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
AM.registerPass([&] { return CREATE_PASS; });
#include GET_PASS_REGISTRY
#undef MACHINE_FUNCTION_ANALYSIS
- });
- }
-}
+});
#undef GET_PASS_REGISTRY
#endif // GET_PASS_REGISTRY
More information about the llvm-commits
mailing list