Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir] Prevent SubElementInterface from going into infinite recursion
Since only mutable types and attributes can go into infinite recursion inside SubElementInterface::walkSubElement, and there are only a few of them (mutable types and attributes), we introduce new traits for Type and Attribute: TypeTrait::IsMutable and AttributeTrait::IsMutable, respectively. They indicate whether a type or attribute is mutable. Such traits are required if the ImplType defines a `mutate` function. Then, inside SubElementInterface, we use a set to record visited mutable types and attributes that have been visited before. Differential Revision: https://reviews.llvm.org/D127537
- Loading branch information
1 parent
bc5e7ce
commit d410286
Showing
13 changed files
with
153 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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,7 @@ | ||
add_mlir_unittest(MLIRLLVMIRTests | ||
LLVMTypeTest.cpp | ||
) | ||
target_link_libraries(MLIRLLVMIRTests | ||
PRIVATE | ||
MLIRLLVMDialect | ||
) |
This file contains 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,27 @@ | ||
//===- LLVMTestBase.h - Test fixure for LLVM dialect tests ------*- 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Test fixure for LLVM dialect tests. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_UNITTEST_DIALECT_LLVMIR_LLVMTESTBASE_H | ||
#define MLIR_UNITTEST_DIALECT_LLVMIR_LLVMTESTBASE_H | ||
|
||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/IR/MLIRContext.h" | ||
#include "gtest/gtest.h" | ||
|
||
class LLVMIRTest : public ::testing::Test { | ||
protected: | ||
LLVMIRTest() { context.getOrLoadDialect<mlir::LLVM::LLVMDialect>(); } | ||
|
||
mlir::MLIRContext context; | ||
}; | ||
|
||
#endif |
This file contains 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,20 @@ | ||
//===- LLVMTypeTest.cpp - Tests for LLVM types ----------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "LLVMTestBase.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMTypes.h" | ||
#include "mlir/IR/SubElementInterfaces.h" | ||
|
||
using namespace mlir; | ||
using namespace mlir::LLVM; | ||
|
||
TEST_F(LLVMIRTest, IsStructTypeMutable) { | ||
auto structTy = LLVMStructType::getIdentified(&context, "foo"); | ||
ASSERT_TRUE(bool(structTy)); | ||
ASSERT_TRUE(structTy.hasTrait<TypeTrait::IsMutable>()); | ||
} |