[llvm] [DomTreeUpdater] Split implementations (PR #97027)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 02:49:56 PDT 2024
================
@@ -0,0 +1,477 @@
+//===- GenericDomTreeUpdaterImpl.h ------------------------------*- 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 implements the GenericDomTreeUpdater class. This file should only
+// be included by files that implement a specialization of the relevant
+// templates. Currently these are:
+// - llvm/lib/Analysis/DomTreeUpdater.cpp
+// - llvm/lib/CodeGen/MachineDomTreeUpdater.cpp
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_ANALYSIS_GENERICDOMTREEUPDATERIMPL_H
+#define LLVM_ANALYSIS_GENERICDOMTREEUPDATERIMPL_H
+
+#include "llvm/Analysis/GenericDomTreeUpdater.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+DerivedT &GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::derived() {
+ return *static_cast<DerivedT *>(this);
+}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+const DerivedT &
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::derived() const {
+ return *static_cast<const DerivedT *>(this);
+}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ UpdateStrategy Strategy_)
+ : Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ DomTreeT &DT_, UpdateStrategy Strategy_)
+ : DT(&DT_), Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ DomTreeT *DT_, UpdateStrategy Strategy_)
+ : DT(DT_), Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ PostDomTreeT &PDT_, UpdateStrategy Strategy_)
+ : PDT(&PDT_), Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ PostDomTreeT *PDT_, UpdateStrategy Strategy_)
+ : PDT(PDT_), Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ DomTreeT &DT_, PostDomTreeT &PDT_, UpdateStrategy Strategy_)
+ : DT(&DT_), PDT(&PDT_), Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::GenericDomTreeUpdater(
+ DomTreeT *DT_, PostDomTreeT *PDT_, UpdateStrategy Strategy_)
+ : DT(DT_), PDT(PDT_), Strategy(Strategy_) {}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+GenericDomTreeUpdater<DerivedT, DomTreeT,
+ PostDomTreeT>::~GenericDomTreeUpdater() {
+ flush();
+}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+bool GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::isLazy() const {
+ return Strategy == UpdateStrategy::Lazy;
+}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+bool GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::isEager() const {
+ return Strategy == UpdateStrategy::Eager;
+}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+bool GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::hasDomTree()
+ const {
+ return DT != nullptr;
+}
+
+template <typename DerivedT, typename DomTreeT, typename PostDomTreeT>
+bool GenericDomTreeUpdater<DerivedT, DomTreeT, PostDomTreeT>::hasPostDomTree()
+ const {
+ return DT != nullptr;
+}
----------------
nikic wrote:
It's fine (and preferable) to keep the definitions for all these tiny single-line methods in the header, assuming they work fine with forward-declarations, which I think they do. Basically the ones that were in the header prior to https://github.com/llvm/llvm-project/pull/96851 can also stay in the header now.
https://github.com/llvm/llvm-project/pull/97027
More information about the llvm-commits
mailing list