[llvm] 500a6c9 - [Analysis] Move SimplifyQuery into separate header (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 02:03:24 PDT 2023
Author: Nikita Popov
Date: 2023-10-10T10:57:49+02:00
New Revision: 500a6c95ff63d0b1d68afe7b64fad4a569748aea
URL: https://github.com/llvm/llvm-project/commit/500a6c95ff63d0b1d68afe7b64fad4a569748aea
DIFF: https://github.com/llvm/llvm-project/commit/500a6c95ff63d0b1d68afe7b64fad4a569748aea.diff
LOG: [Analysis] Move SimplifyQuery into separate header (NFC)
To allow reusing it between InstructionSimplify and ValueTracking.
Added:
llvm/include/llvm/Analysis/SimplifyQuery.h
Modified:
llvm/include/llvm/Analysis/InstructionSimplify.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/InstructionSimplify.h b/llvm/include/llvm/Analysis/InstructionSimplify.h
index 92005da1f4c61e7..c626a6522d01779 100644
--- a/llvm/include/llvm/Analysis/InstructionSimplify.h
+++ b/llvm/include/llvm/Analysis/InstructionSimplify.h
@@ -31,7 +31,7 @@
#ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
#define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
-#include "llvm/IR/PatternMatch.h"
+#include "llvm/Analysis/SimplifyQuery.h"
namespace llvm {
@@ -52,102 +52,6 @@ class TargetLibraryInfo;
class Type;
class Value;
-/// InstrInfoQuery provides an interface to query additional information for
-/// instructions like metadata or keywords like nsw, which provides conservative
-/// results if the users specified it is safe to use.
-struct InstrInfoQuery {
- InstrInfoQuery(bool UMD) : UseInstrInfo(UMD) {}
- InstrInfoQuery() = default;
- bool UseInstrInfo = true;
-
- MDNode *getMetadata(const Instruction *I, unsigned KindID) const {
- if (UseInstrInfo)
- return I->getMetadata(KindID);
- return nullptr;
- }
-
- template <class InstT> bool hasNoUnsignedWrap(const InstT *Op) const {
- if (UseInstrInfo)
- return Op->hasNoUnsignedWrap();
- return false;
- }
-
- template <class InstT> bool hasNoSignedWrap(const InstT *Op) const {
- if (UseInstrInfo)
- return Op->hasNoSignedWrap();
- return false;
- }
-
- bool isExact(const BinaryOperator *Op) const {
- if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
- return cast<PossiblyExactOperator>(Op)->isExact();
- return false;
- }
-
- template <class InstT> bool hasNoSignedZeros(const InstT *Op) const {
- if (UseInstrInfo)
- return Op->hasNoSignedZeros();
- return false;
- }
-};
-
-struct SimplifyQuery {
- const DataLayout &DL;
- const TargetLibraryInfo *TLI = nullptr;
- const DominatorTree *DT = nullptr;
- AssumptionCache *AC = nullptr;
- const Instruction *CxtI = nullptr;
-
- // Wrapper to query additional information for instructions like metadata or
- // keywords like nsw, which provides conservative results if those cannot
- // be safely used.
- const InstrInfoQuery IIQ;
-
- /// Controls whether simplifications are allowed to constrain the range of
- /// possible values for uses of undef. If it is false, simplifications are not
- /// allowed to assume a particular value for a use of undef for example.
- bool CanUseUndef = true;
-
- SimplifyQuery(const DataLayout &DL, const Instruction *CXTI = nullptr)
- : DL(DL), CxtI(CXTI) {}
-
- SimplifyQuery(const DataLayout &DL, const TargetLibraryInfo *TLI,
- const DominatorTree *DT = nullptr,
- AssumptionCache *AC = nullptr,
- const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
- bool CanUseUndef = true)
- : DL(DL), TLI(TLI), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
- CanUseUndef(CanUseUndef) {}
-
- SimplifyQuery(const DataLayout &DL, const DominatorTree *DT,
- AssumptionCache *AC = nullptr,
- const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
- bool CanUseUndef = true)
- : DL(DL), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
- CanUseUndef(CanUseUndef) {}
-
- SimplifyQuery getWithInstruction(const Instruction *I) const {
- SimplifyQuery Copy(*this);
- Copy.CxtI = I;
- return Copy;
- }
- SimplifyQuery getWithoutUndef() const {
- SimplifyQuery Copy(*this);
- Copy.CanUseUndef = false;
- return Copy;
- }
-
- /// If CanUseUndef is true, returns whether \p V is undef.
- /// Otherwise always return false.
- bool isUndefValue(Value *V) const {
- if (!CanUseUndef)
- return false;
-
- using namespace PatternMatch;
- return match(V, m_Undef());
- }
-};
-
// NOTE: the explicit multiple argument versions of these functions are
// deprecated.
// Please use the SimplifyQuery versions in new code.
diff --git a/llvm/include/llvm/Analysis/SimplifyQuery.h b/llvm/include/llvm/Analysis/SimplifyQuery.h
new file mode 100644
index 000000000000000..f9cc3029221d679
--- /dev/null
+++ b/llvm/include/llvm/Analysis/SimplifyQuery.h
@@ -0,0 +1,118 @@
+//===-- SimplifyQuery.h - Context for simplifications -----------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_SIMPLIFYQUERY_H
+#define LLVM_ANALYSIS_SIMPLIFYQUERY_H
+
+#include "llvm/IR/PatternMatch.h"
+
+namespace llvm {
+
+class AssumptionCache;
+class DominatorTree;
+class TargetLibraryInfo;
+
+/// InstrInfoQuery provides an interface to query additional information for
+/// instructions like metadata or keywords like nsw, which provides conservative
+/// results if the users specified it is safe to use.
+struct InstrInfoQuery {
+ InstrInfoQuery(bool UMD) : UseInstrInfo(UMD) {}
+ InstrInfoQuery() = default;
+ bool UseInstrInfo = true;
+
+ MDNode *getMetadata(const Instruction *I, unsigned KindID) const {
+ if (UseInstrInfo)
+ return I->getMetadata(KindID);
+ return nullptr;
+ }
+
+ template <class InstT> bool hasNoUnsignedWrap(const InstT *Op) const {
+ if (UseInstrInfo)
+ return Op->hasNoUnsignedWrap();
+ return false;
+ }
+
+ template <class InstT> bool hasNoSignedWrap(const InstT *Op) const {
+ if (UseInstrInfo)
+ return Op->hasNoSignedWrap();
+ return false;
+ }
+
+ bool isExact(const BinaryOperator *Op) const {
+ if (UseInstrInfo && isa<PossiblyExactOperator>(Op))
+ return cast<PossiblyExactOperator>(Op)->isExact();
+ return false;
+ }
+
+ template <class InstT> bool hasNoSignedZeros(const InstT *Op) const {
+ if (UseInstrInfo)
+ return Op->hasNoSignedZeros();
+ return false;
+ }
+};
+
+struct SimplifyQuery {
+ const DataLayout &DL;
+ const TargetLibraryInfo *TLI = nullptr;
+ const DominatorTree *DT = nullptr;
+ AssumptionCache *AC = nullptr;
+ const Instruction *CxtI = nullptr;
+
+ // Wrapper to query additional information for instructions like metadata or
+ // keywords like nsw, which provides conservative results if those cannot
+ // be safely used.
+ const InstrInfoQuery IIQ;
+
+ /// Controls whether simplifications are allowed to constrain the range of
+ /// possible values for uses of undef. If it is false, simplifications are not
+ /// allowed to assume a particular value for a use of undef for example.
+ bool CanUseUndef = true;
+
+ SimplifyQuery(const DataLayout &DL, const Instruction *CXTI = nullptr)
+ : DL(DL), CxtI(CXTI) {}
+
+ SimplifyQuery(const DataLayout &DL, const TargetLibraryInfo *TLI,
+ const DominatorTree *DT = nullptr,
+ AssumptionCache *AC = nullptr,
+ const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
+ bool CanUseUndef = true)
+ : DL(DL), TLI(TLI), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
+ CanUseUndef(CanUseUndef) {}
+
+ SimplifyQuery(const DataLayout &DL, const DominatorTree *DT,
+ AssumptionCache *AC = nullptr,
+ const Instruction *CXTI = nullptr, bool UseInstrInfo = true,
+ bool CanUseUndef = true)
+ : DL(DL), DT(DT), AC(AC), CxtI(CXTI), IIQ(UseInstrInfo),
+ CanUseUndef(CanUseUndef) {}
+
+ SimplifyQuery getWithInstruction(const Instruction *I) const {
+ SimplifyQuery Copy(*this);
+ Copy.CxtI = I;
+ return Copy;
+ }
+ SimplifyQuery getWithoutUndef() const {
+ SimplifyQuery Copy(*this);
+ Copy.CanUseUndef = false;
+ return Copy;
+ }
+
+ /// If CanUseUndef is true, returns whether \p V is undef.
+ /// Otherwise always return false.
+ bool isUndefValue(Value *V) const {
+ if (!CanUseUndef)
+ return false;
+
+ using namespace PatternMatch;
+ return match(V, m_Undef());
+ }
+};
+
+} // end namespace llvm
+
+#endif
More information about the llvm-commits
mailing list