-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][SMT] upstream SMT
dialect
#131480
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
Merged
makslevental
merged 10 commits into
llvm:main
from
makslevental:makslevental/upstream-smt
Apr 11, 2025
Merged
[mlir][SMT] upstream SMT
dialect
#131480
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
632011e
[mlir][smt] upstream SMT dialect
makslevental edf0f55
Update mlir/include/mlir/Dialect/SMT/IR/SMTOps.td
makslevental 8b7ad0e
Update mlir/include/mlir/Dialect/SMT/IR/SMTOps.h
makslevental bf5521d
smt-lib 2.7 standard
makslevental 784540c
bv integer non-negative
makslevental 3f37237
header guard
makslevental 040695c
verify roundtrip
makslevental 14d1b19
Merge branch 'main' into makslevental/upstream-smt
makslevental 644cccc
add unit tests
makslevental dba0979
Merge branch 'main' into makslevental/upstream-smt
makslevental 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(IR) |
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,15 @@ | ||
add_mlir_dialect(SMT smt) | ||
|
||
set(LLVM_TARGET_DEFINITIONS SMT.td) | ||
|
||
mlir_tablegen(SMTAttributes.h.inc -gen-attrdef-decls) | ||
mlir_tablegen(SMTAttributes.cpp.inc -gen-attrdef-defs) | ||
add_public_tablegen_target(MLIRSMTAttrIncGen) | ||
add_dependencies(mlir-headers MLIRSMTAttrIncGen) | ||
|
||
mlir_tablegen(SMTEnums.h.inc -gen-enum-decls) | ||
mlir_tablegen(SMTEnums.cpp.inc -gen-enum-defs) | ||
add_public_tablegen_target(MLIRSMTEnumsIncGen) | ||
add_dependencies(mlir-headers MLIRSMTEnumsIncGen) | ||
|
||
add_mlir_doc(SMT SMT Dialects/ -gen-dialect-doc) |
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,22 @@ | ||
//===- SMT.td - SMT dialect definition ---------------------*- tablegen -*-===// | ||
// | ||
// 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 MLIR_DIALECT_SMT_IR_SMT_TD | ||
#define MLIR_DIALECT_SMT_IR_SMT_TD | ||
|
||
include "mlir/IR/OpBase.td" | ||
|
||
include "mlir/Dialect/SMT/IR/SMTAttributes.td" | ||
include "mlir/Dialect/SMT/IR/SMTDialect.td" | ||
include "mlir/Dialect/SMT/IR/SMTTypes.td" | ||
include "mlir/Dialect/SMT/IR/SMTOps.td" | ||
include "mlir/Dialect/SMT/IR/SMTArrayOps.td" | ||
include "mlir/Dialect/SMT/IR/SMTBitVectorOps.td" | ||
include "mlir/Dialect/SMT/IR/SMTIntOps.td" | ||
|
||
#endif // MLIR_DIALECT_SMT_IR_SMT_TD |
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,99 @@ | ||
//===- SMTArrayOps.td - SMT array operations ---------------*- tablegen -*-===// | ||
// | ||
// 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 MLIR_DIALECT_SMT_IR_SMTARRAYOPS_TD | ||
#define MLIR_DIALECT_SMT_IR_SMTARRAYOPS_TD | ||
|
||
include "mlir/Dialect/SMT/IR/SMTDialect.td" | ||
include "mlir/Dialect/SMT/IR/SMTAttributes.td" | ||
include "mlir/Dialect/SMT/IR/SMTTypes.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
|
||
class SMTArrayOp<string mnemonic, list<Trait> traits = []> : | ||
SMTOp<"array." # mnemonic, traits>; | ||
|
||
def ArrayStoreOp : SMTArrayOp<"store", [ | ||
Pure, | ||
TypesMatchWith<"summary", "array", "index", | ||
"cast<ArrayType>($_self).getDomainType()">, | ||
TypesMatchWith<"summary", "array", "value", | ||
"cast<ArrayType>($_self).getRangeType()">, | ||
AllTypesMatch<["array", "result"]>, | ||
]> { | ||
let summary = "stores a value at a given index and returns the new array"; | ||
let description = [{ | ||
This operation returns a new array which is the same as the 'array' operand | ||
except that the value at the given 'index' is changed to the given 'value'. | ||
The semantics are equivalent to the 'store' operator described in the | ||
[SMT ArrayEx theory](https://smtlib.cs.uiowa.edu/Theories/ArraysEx.smt2) of | ||
the SMT-LIB standard 2.7. | ||
}]; | ||
|
||
let arguments = (ins ArrayType:$array, AnySMTType:$index, AnySMTType:$value); | ||
let results = (outs ArrayType:$result); | ||
|
||
let assemblyFormat = [{ | ||
$array `[` $index `]` `,` $value attr-dict `:` qualified(type($array)) | ||
}]; | ||
} | ||
|
||
def ArraySelectOp : SMTArrayOp<"select", [ | ||
Pure, | ||
TypesMatchWith<"summary", "array", "index", | ||
"cast<ArrayType>($_self).getDomainType()">, | ||
TypesMatchWith<"summary", "array", "result", | ||
"cast<ArrayType>($_self).getRangeType()">, | ||
]> { | ||
let summary = "get the value stored in the array at the given index"; | ||
let description = [{ | ||
This operation is retuns the value stored in the given array at the given | ||
index. The semantics are equivalent to the `select` operator defined in the | ||
[SMT ArrayEx theory](https://smtlib.cs.uiowa.edu/Theories/ArraysEx.smt2) of | ||
the SMT-LIB standard 2.7. | ||
}]; | ||
|
||
let arguments = (ins ArrayType:$array, AnySMTType:$index); | ||
let results = (outs AnySMTType:$result); | ||
|
||
let assemblyFormat = [{ | ||
$array `[` $index `]` attr-dict `:` qualified(type($array)) | ||
}]; | ||
} | ||
|
||
def ArrayBroadcastOp : SMTArrayOp<"broadcast", [ | ||
Pure, | ||
TypesMatchWith<"summary", "result", "value", | ||
"cast<ArrayType>($_self).getRangeType()">, | ||
]> { | ||
let summary = "construct an array with the given value stored at every index"; | ||
let description = [{ | ||
This operation represents a broadcast of the 'value' operand to all indices | ||
of the array. It is equivalent to | ||
``` | ||
%0 = smt.declare "array" : !smt.array<[!smt.int -> !smt.bool]> | ||
%1 = smt.forall ["idx"] { | ||
^bb0(%idx: !smt.int): | ||
%2 = smt.array.select %0[%idx] : !smt.array<[!smt.int -> !smt.bool]> | ||
%3 = smt.eq %value, %2 : !smt.bool | ||
smt.yield %3 : !smt.bool | ||
} | ||
smt.assert %1 | ||
// return %0 | ||
``` | ||
|
||
In SMT-LIB, this is frequently written as | ||
`((as const (Array Int Bool)) value)`. | ||
}]; | ||
|
||
let arguments = (ins AnySMTType:$value); | ||
let results = (outs ArrayType:$result); | ||
|
||
let assemblyFormat = "$value attr-dict `:` qualified(type($result))"; | ||
} | ||
|
||
#endif // MLIR_DIALECT_SMT_IR_SMTARRAYOPS_TD |
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,29 @@ | ||
//===- SMTAttributes.h - Declare SMT dialect attributes ----------*- 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 MLIR_DIALECT_SMT_IR_SMTATTRIBUTES_H | ||
#define MLIR_DIALECT_SMT_IR_SMTATTRIBUTES_H | ||
|
||
#include "mlir/IR/Attributes.h" | ||
#include "mlir/IR/BuiltinAttributeInterfaces.h" | ||
#include "mlir/IR/BuiltinAttributes.h" | ||
|
||
namespace mlir { | ||
namespace smt { | ||
namespace detail { | ||
|
||
struct BitVectorAttrStorage; | ||
|
||
} // namespace detail | ||
} // namespace smt | ||
} // namespace mlir | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "mlir/Dialect/SMT/IR/SMTAttributes.h.inc" | ||
|
||
#endif // MLIR_DIALECT_SMT_IR_SMTATTRIBUTES_H |
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,74 @@ | ||
//===- SMTAttributes.td - Attributes for SMT dialect -------*- tablegen -*-===// | ||
// | ||
// 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 defines SMT dialect specific attributes. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_SMT_IR_SMTATTRIBUTES_TD | ||
#define MLIR_DIALECT_SMT_IR_SMTATTRIBUTES_TD | ||
|
||
include "mlir/Dialect/SMT/IR/SMTDialect.td" | ||
include "mlir/IR/EnumAttr.td" | ||
include "mlir/IR/BuiltinAttributeInterfaces.td" | ||
|
||
def BitVectorAttr : AttrDef<SMTDialect, "BitVector", [ | ||
DeclareAttrInterfaceMethods<TypedAttrInterface> | ||
]> { | ||
let mnemonic = "bv"; | ||
let description = [{ | ||
This attribute represents a constant value of the `(_ BitVec width)` sort as | ||
described in the [SMT bit-vector | ||
theory](https://smtlib.cs.uiowa.edu/theories-FixedSizeBitVectors.shtml). | ||
|
||
The constant is as #bX (binary) or #xX (hexadecimal) in SMT-LIB | ||
where X is the value in the corresponding format without any further | ||
prefixing. Here, the bit-vector constant is given as a regular non-negative | ||
integer literal and the associated bit-vector type indicating the bit-width. | ||
|
||
Examples: | ||
```mlir | ||
#smt.bv<5> : !smt.bv<4> | ||
#smt.bv<92> : !smt.bv<8> | ||
``` | ||
|
||
The explicit type-suffix is mandatory to uniquely represent the attribute, | ||
i.e., this attribute should always be used in the extended form (using the | ||
`quantified` keyword in the operation assembly format string). | ||
|
||
The bit-width must be greater than zero (i.e., at least one digit has to be | ||
present). | ||
}]; | ||
|
||
let parameters = (ins "llvm::APInt":$value); | ||
|
||
let hasCustomAssemblyFormat = true; | ||
let genVerifyDecl = true; | ||
|
||
// We need to manually define the storage class because the generated one is | ||
// buggy (because the APInt asserts matching bitwidth in the `==` operator and | ||
// the generated storage uses that directly. | ||
// Alternatively: add a type parameter to redundantly store the bitwidth of | ||
// of the attribute type, it it's in the order before the 'value' it will be | ||
// checked before the APInt equality (this is the reason it works for the | ||
// builtin integer attribute), but would be more fragile (and we'd store | ||
// duplicate data). | ||
let genStorageClass = false; | ||
|
||
let builders = [ | ||
AttrBuilder<(ins "llvm::StringRef":$value)>, | ||
AttrBuilder<(ins "uint64_t":$value, "unsigned":$width)>, | ||
]; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Return the bit-vector constant as a SMT-LIB formatted string. | ||
std::string getValueAsString(bool prefix = true) const; | ||
}]; | ||
} | ||
|
||
#endif // MLIR_DIALECT_SMT_IR_SMTATTRIBUTES_TD |
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.