Repository navigation
[MLIR] Share TypeTree with MLIR as GenericTypeTree #3484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46266db
Implement MTypeTree and MTypeResult
aokblast caf1d43
fixup! [MLIR] Implement MTypeTree and MTypeResult
aokblast 8841f33
Merge remote-tracking branch 'origin/main' into users/aokblast/mlir/t…
aokblast b4ff4be
fixup! [MLIR] Implement MTypeTree and MTypeResult
aokblast 989847c
fixup! [MLIR] Implement MTypeTree and MTypeResult
aokblast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,12 @@ | |
| #include "mlir/IR/IRMapping.h" | ||
| #include "mlir/Interfaces/FunctionInterfaces.h" | ||
|
|
||
| #include "../../TypeAnalysis/TypeAnalysis.h" | ||
| #include "../../TypeAnalysis/TypeTree.h" | ||
| #include "../../Utils.h" | ||
| #include <functional> | ||
| #include <map> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace mlir { | ||
| namespace enzyme { | ||
|
|
@@ -27,21 +30,65 @@ class MTypeAnalysis { | |
| } | ||
| }; | ||
|
|
||
| } // namespace enzyme | ||
| } // namespace mlir | ||
|
|
||
| template <> struct ConcreteTypeTraits<mlir::Type> { | ||
| static bool isFloatingPoint(mlir::Type T) { return static_cast<bool>(T); } | ||
|
|
||
| static void print(llvm::raw_ostream &OS, mlir::Type T) { OS << T; } | ||
|
|
||
| static std::string floatName(mlir::Type T) { | ||
| std::string S; | ||
| llvm::raw_string_ostream OS(S); | ||
| OS << T; | ||
| return S; | ||
| } | ||
|
|
||
| static bool less(mlir::Type A, mlir::Type B) { | ||
| return A.getAsOpaquePointer() < B.getAsOpaquePointer(); | ||
| } | ||
| }; | ||
|
|
||
| template <> struct TypeTreeTraits<mlir::Type> { | ||
| using Origin = mlir::Operation *; | ||
|
|
||
| // Mirror the defaults of -enzyme-max-type-depth and -enzyme-max-type-offset. | ||
| static unsigned maxDepth() { return 6; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should consider using the same cl::opt here for both to avoid confusion, if feasible |
||
|
|
||
| static int maxOffset() { return 500; } | ||
|
|
||
| template <typename TreeT> | ||
| static void depthLimitExceeded(const TreeT &Tree, Origin Orig, | ||
| const llvm::Twine &Detail) { | ||
| std::string Msg = ("not handling more than " + llvm::Twine(maxDepth()) + | ||
| " pointer lookups deep dt:" + Tree.str() + Detail) | ||
| .str(); | ||
| if (Orig) | ||
| Orig->emitWarning(Msg); | ||
| else | ||
| llvm::errs() << Msg << "\n"; | ||
| } | ||
| }; | ||
|
|
||
| namespace mlir { | ||
| namespace enzyme { | ||
|
|
||
| using MConcreteType = GenericConcreteType<mlir::Type>; | ||
|
|
||
| using MTypeTree = GenericTypeTree<mlir::Type>; | ||
|
|
||
| // The MLIR counterpart of TypeResults. There is no type analysis behind it. | ||
| class MTypeResults { | ||
| public: | ||
| // TODO | ||
| TypeTree getReturnAnalysis() { return TypeTree(); } | ||
| TypeTree query(Value) const { return TypeTree(); } | ||
| ConcreteType intType(size_t num, Value val, bool errIfNotFound = true, | ||
| bool pointerIntSame = false) const { | ||
| if (isa<IntegerType, IndexType>(val.getType())) { | ||
| return BaseType::Integer; | ||
| } | ||
| if (errIfNotFound) { | ||
| llvm_unreachable("something happened"); | ||
| } | ||
| return BaseType::Unknown; | ||
| } | ||
| MTypeTree query(Value val) const; | ||
|
|
||
| /// What the value itself is. | ||
| MConcreteType intType(size_t num, Value val, bool errIfNotFound = true, | ||
| bool pointerIntSame = false) const; | ||
|
|
||
| MConcreteType firstPointer(size_t num, Value val, bool errIfNotFound = true, | ||
| bool pointerIntSame = false) const; | ||
| }; | ||
|
|
||
| class MEnzymeLogic { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //===- MTypeResults.cpp - Type facts for MLIR activity analysis -----------===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // MTypeResults answers the activity analysis's questions about what a value | ||
| // holds. Nothing is inferred: every answer is read off the value's type, which | ||
| // is exact where the type says what a value holds and Unknown elsewhere. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "EnzymeLogic.h" | ||
|
|
||
| using namespace mlir; | ||
| using namespace mlir::enzyme; | ||
|
|
||
| MTypeTree MTypeResults::query(Value val) const { | ||
| // TODO: cache the tree per type in a DenseMap<Type, MTypeTree> once | ||
| // building it is more than a few isa checks. | ||
| MTypeTree tree; | ||
| return tree; | ||
| } | ||
|
|
||
| MConcreteType MTypeResults::intType(size_t num, Value val, bool errIfNotFound, | ||
| bool pointerIntSame) const { | ||
| if (isa<IntegerType, IndexType>(val.getType())) | ||
| return BaseType::Integer; | ||
| if (errIfNotFound) | ||
| llvm_unreachable("MTypeResults::intType: could not deduce the type of the " | ||
| "value from its MLIR type"); | ||
| return BaseType::Unknown; | ||
| } | ||
|
|
||
| MConcreteType MTypeResults::firstPointer(size_t num, Value val, | ||
| bool errIfNotFound, | ||
| bool pointerIntSame) const { | ||
| if (errIfNotFound) | ||
| llvm_unreachable("MTypeResults::firstPointer: could not deduce the pointee " | ||
| "type of the value from its MLIR type"); | ||
| return BaseType::Unknown; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.