From c81e749084775342c8f48cc842173de8cf83f44d Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Apr 2025 00:27:49 -0700 Subject: [PATCH] [PassSupport] Simplify callDefaultCtor (NFC) We can use "constexpr if" to combine the two variants of functions. --- llvm/include/llvm/PassSupport.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/PassSupport.h b/llvm/include/llvm/PassSupport.h index 2806d9b52b0b9..b0897a6be37d1 100644 --- a/llvm/include/llvm/PassSupport.h +++ b/llvm/include/llvm/PassSupport.h @@ -64,20 +64,13 @@ class Pass; INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis) \ INITIALIZE_PASS_END(PassName, Arg, Name, Cfg, Analysis) -template < - class PassName, - std::enable_if_t{}, bool> = true> -Pass *callDefaultCtor() { - return new PassName(); -} - -template < - class PassName, - std::enable_if_t{}, bool> = true> -Pass *callDefaultCtor() { - // Some codegen passes should only be testable via - // `llc -{start|stop}-{before|after}=`, not via `opt -`. - report_fatal_error("target-specific codegen-only pass"); +template Pass *callDefaultCtor() { + if constexpr (std::is_default_constructible_v) + return new PassName(); + else + // Some codegen passes should only be testable via + // `llc -{start|stop}-{before|after}=`, not via `opt -`. + report_fatal_error("target-specific codegen-only pass"); } //===---------------------------------------------------------------------------