[clang] c0e5e3f - [Ignore Expressions] Fix performance regression by inlining `Ignore*SingleStep`
Eduardo Caldas via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 9 00:32:49 PDT 2020
Author: Eduardo Caldas
Date: 2020-09-09T07:32:40Z
New Revision: c0e5e3fbfa504c3792023d0db9008b08caa6b6d7
URL: https://github.com/llvm/llvm-project/commit/c0e5e3fbfa504c3792023d0db9008b08caa6b6d7
DIFF: https://github.com/llvm/llvm-project/commit/c0e5e3fbfa504c3792023d0db9008b08caa6b6d7.diff
LOG: [Ignore Expressions] Fix performance regression by inlining `Ignore*SingleStep`
We also add a `const` versions of `IgnoreExprNodes`
Differential Revision: https://reviews.llvm.org/D87278
Added:
Modified:
clang/include/clang/AST/IgnoreExpr.h
clang/lib/AST/CMakeLists.txt
Removed:
clang/lib/AST/IgnoreExpr.cpp
################################################################################
diff --git a/clang/include/clang/AST/IgnoreExpr.h b/clang/include/clang/AST/IgnoreExpr.h
index 0aeb547606a2..1c2b538e5b63 100644
--- a/clang/include/clang/AST/IgnoreExpr.h
+++ b/clang/include/clang/AST/IgnoreExpr.h
@@ -14,6 +14,7 @@
#define LLVM_CLANG_AST_IGNOREEXPR_H
#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
namespace clang {
namespace detail {
@@ -38,23 +39,122 @@ template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
return E;
}
-Expr *IgnoreImplicitCastsSingleStep(Expr *E);
+template <typename... FnTys>
+const Expr *IgnoreExprNodes(const Expr *E, FnTys &&...Fns) {
+ return const_cast<Expr *>(IgnoreExprNodes(E, std::forward<FnTys>(Fns)...));
+}
+
+inline Expr *IgnoreImplicitCastsSingleStep(Expr *E) {
+ if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
+ return ICE->getSubExpr();
+
+ if (auto *FE = dyn_cast<FullExpr>(E))
+ return FE->getSubExpr();
+
+ return E;
+}
+
+inline Expr *IgnoreImplicitCastsExtraSingleStep(Expr *E) {
+ // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
+ // addition to what IgnoreImpCasts() skips to account for the current
+ // behaviour of IgnoreParenImpCasts().
+ Expr *SubE = IgnoreImplicitCastsSingleStep(E);
+ if (SubE != E)
+ return SubE;
+
+ if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
+ return MTE->getSubExpr();
+
+ if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
+ return NTTP->getReplacement();
+
+ return E;
+}
+
+inline Expr *IgnoreCastsSingleStep(Expr *E) {
+ if (auto *CE = dyn_cast<CastExpr>(E))
+ return CE->getSubExpr();
+
+ if (auto *FE = dyn_cast<FullExpr>(E))
+ return FE->getSubExpr();
+
+ if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
+ return MTE->getSubExpr();
+
+ if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
+ return NTTP->getReplacement();
+
+ return E;
+}
+
+inline Expr *IgnoreLValueCastsSingleStep(Expr *E) {
+ // Skip what IgnoreCastsSingleStep skips, except that only
+ // lvalue-to-rvalue casts are skipped.
+ if (auto *CE = dyn_cast<CastExpr>(E))
+ if (CE->getCastKind() != CK_LValueToRValue)
+ return E;
-Expr *IgnoreImplicitCastsExtraSingleStep(Expr *E);
+ return IgnoreCastsSingleStep(E);
+}
+
+inline Expr *IgnoreBaseCastsSingleStep(Expr *E) {
+ if (auto *CE = dyn_cast<CastExpr>(E))
+ if (CE->getCastKind() == CK_DerivedToBase ||
+ CE->getCastKind() == CK_UncheckedDerivedToBase ||
+ CE->getCastKind() == CK_NoOp)
+ return CE->getSubExpr();
+
+ return E;
+}
+
+inline Expr *IgnoreImplicitSingleStep(Expr *E) {
+ Expr *SubE = IgnoreImplicitCastsSingleStep(E);
+ if (SubE != E)
+ return SubE;
+
+ if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
+ return MTE->getSubExpr();
+
+ if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
+ return BTE->getSubExpr();
+
+ return E;
+}
+
+inline Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E) {
+ if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
+ return ICE->getSubExprAsWritten();
-Expr *IgnoreCastsSingleStep(Expr *E);
+ return IgnoreImplicitSingleStep(E);
+}
-Expr *IgnoreLValueCastsSingleStep(Expr *E);
+inline Expr *IgnoreParensOnlySingleStep(Expr *E) {
+ if (auto *PE = dyn_cast<ParenExpr>(E))
+ return PE->getSubExpr();
+ return E;
+}
-Expr *IgnoreBaseCastsSingleStep(Expr *E);
+inline Expr *IgnoreParensSingleStep(Expr *E) {
+ if (auto *PE = dyn_cast<ParenExpr>(E))
+ return PE->getSubExpr();
-Expr *IgnoreImplicitSingleStep(Expr *E);
+ if (auto *UO = dyn_cast<UnaryOperator>(E)) {
+ if (UO->getOpcode() == UO_Extension)
+ return UO->getSubExpr();
+ }
-Expr *IgnoreImplicitAsWrittenSingleStep(Expr *E);
+ else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) {
+ if (!GSE->isResultDependent())
+ return GSE->getResultExpr();
+ }
-Expr *IgnoreParensOnlySingleStep(Expr *E);
+ else if (auto *CE = dyn_cast<ChooseExpr>(E)) {
+ if (!CE->isConditionDependent())
+ return CE->getChosenSubExpr();
+ }
-Expr *IgnoreParensSingleStep(Expr *E);
+ return E;
+}
} // namespace clang
diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index dfd26fd97bc6..35099fd0dacf 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -55,7 +55,6 @@ add_clang_library(clangAST
ExternalASTMerger.cpp
ExternalASTSource.cpp
FormatString.cpp
- IgnoreExpr.cpp
InheritViz.cpp
Interp/ByteCodeEmitter.cpp
Interp/ByteCodeExprGen.cpp
diff --git a/clang/lib/AST/IgnoreExpr.cpp b/clang/lib/AST/IgnoreExpr.cpp
deleted file mode 100644
index 65aaaeb6a1ed..000000000000
--- a/clang/lib/AST/IgnoreExpr.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-//===--- IgnoreExpr.cpp - Ignore intermediate Expressions -----------------===//
-//
-// 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 common functions to ignore intermediate expression nodes
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/AST/IgnoreExpr.h"
-#include "clang/AST/Expr.h"
-#include "clang/AST/ExprCXX.h"
-
-using namespace clang;
-
-Expr *clang::IgnoreImplicitCastsSingleStep(Expr *E) {
- if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
- return ICE->getSubExpr();
-
- if (auto *FE = dyn_cast<FullExpr>(E))
- return FE->getSubExpr();
-
- return E;
-}
-
-Expr *clang::IgnoreImplicitCastsExtraSingleStep(Expr *E) {
- // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
- // addition to what IgnoreImpCasts() skips to account for the current
- // behaviour of IgnoreParenImpCasts().
- Expr *SubE = IgnoreImplicitCastsSingleStep(E);
- if (SubE != E)
- return SubE;
-
- if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
- return MTE->getSubExpr();
-
- if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
- return NTTP->getReplacement();
-
- return E;
-}
-
-Expr *clang::IgnoreCastsSingleStep(Expr *E) {
- if (auto *CE = dyn_cast<CastExpr>(E))
- return CE->getSubExpr();
-
- if (auto *FE = dyn_cast<FullExpr>(E))
- return FE->getSubExpr();
-
- if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
- return MTE->getSubExpr();
-
- if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
- return NTTP->getReplacement();
-
- return E;
-}
-
-Expr *clang::IgnoreLValueCastsSingleStep(Expr *E) {
- // Skip what IgnoreCastsSingleStep skips, except that only
- // lvalue-to-rvalue casts are skipped.
- if (auto *CE = dyn_cast<CastExpr>(E))
- if (CE->getCastKind() != CK_LValueToRValue)
- return E;
-
- return IgnoreCastsSingleStep(E);
-}
-
-Expr *clang::IgnoreBaseCastsSingleStep(Expr *E) {
- if (auto *CE = dyn_cast<CastExpr>(E))
- if (CE->getCastKind() == CK_DerivedToBase ||
- CE->getCastKind() == CK_UncheckedDerivedToBase ||
- CE->getCastKind() == CK_NoOp)
- return CE->getSubExpr();
-
- return E;
-}
-
-Expr *clang::IgnoreImplicitSingleStep(Expr *E) {
- Expr *SubE = IgnoreImplicitCastsSingleStep(E);
- if (SubE != E)
- return SubE;
-
- if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
- return MTE->getSubExpr();
-
- if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(E))
- return BTE->getSubExpr();
-
- return E;
-}
-
-Expr *clang::IgnoreImplicitAsWrittenSingleStep(Expr *E) {
- if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
- return ICE->getSubExprAsWritten();
-
- return IgnoreImplicitSingleStep(E);
-}
-
-Expr *clang::IgnoreParensOnlySingleStep(Expr *E) {
- if (auto *PE = dyn_cast<ParenExpr>(E))
- return PE->getSubExpr();
- return E;
-}
-
-Expr *clang::IgnoreParensSingleStep(Expr *E) {
- if (auto *PE = dyn_cast<ParenExpr>(E))
- return PE->getSubExpr();
-
- if (auto *UO = dyn_cast<UnaryOperator>(E)) {
- if (UO->getOpcode() == UO_Extension)
- return UO->getSubExpr();
- }
-
- else if (auto *GSE = dyn_cast<GenericSelectionExpr>(E)) {
- if (!GSE->isResultDependent())
- return GSE->getResultExpr();
- }
-
- else if (auto *CE = dyn_cast<ChooseExpr>(E)) {
- if (!CE->isConditionDependent())
- return CE->getChosenSubExpr();
- }
-
- return E;
-}
More information about the cfe-commits
mailing list