-
Notifications
You must be signed in to change notification settings - Fork 133
Init commit for sql dialect #319
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
Open
carlguo866
wants to merge
23
commits into
main
Choose a base branch
from
sql
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
813db3f
init commit for sql dialect
carlguo866 764a5a0
reformat
carlguo866 575584f
reformat names; remove unimportant dependencies; add include guards
carlguo866 2e7bb44
fix build issue
carlguo866 a324331
fix build issue & cleanup names
carlguo866 7dae0f7
SQLLower
carlguo866 32bc7d3
sql lowering workings with pragma
carlguo866 6634ed0
mlir gen works; lowering still buggy
carlguo866 548d94a
lowering still buggy
carlguo866 5bed072
select op
carlguo866 b0f6226
parser works
carlguo866 2b568ce
progress
carlguo866 5249dbe
basic select
carlguo866 0a26185
merge this before using new parser
carlguo866 0b85724
now with sql
carlguo866 1faa6e5
push new parser
wsmoses f9da02e
fix build
cliarie a16a4ce
fix build
cliarie 6d0b215
simple sql lowering test
cliarie c57a376
register sql
cliarie 59f91bc
tests with checks
cliarie c776b3a
fix tests
cliarie 21086d3
wip
cliarie 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
add_subdirectory(polygeist) | ||
if (ENABLE_SQL) | ||
add_subdirectory(sql) | ||
endif() |
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,4 @@ | ||
add_mlir_dialect(SQLOps sql) | ||
# add_mlir_doc(SQLDialect -gen-dialect-doc SQLDialect SQL/) | ||
# add_mlir_doc(SQLOps -gen-op-doc SQLOps SQL/) | ||
add_subdirectory(Passes) |
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,28 @@ | ||
//===- Parser.h - SQL dialect -----------------*- C++ -*-===// | ||
// | ||
// This file is licensed 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 SQLPARSER_H | ||
#define SQLPARSER_H | ||
|
||
#include "mlir/IR/Dialect.h" | ||
|
||
#include "mlir/IR/Value.h" | ||
#include "mlir/IR/Builders.h" | ||
#include "mlir/IR/Location.h" | ||
#include "mlir/IR/Attributes.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "mlir/IR/BuiltinTypes.h" | ||
|
||
#include "sql/SQLDialect.h" | ||
#include "sql/SQLOps.h" | ||
#include "sql/SQLTypes.h" | ||
|
||
mlir::Value parseSQL(mlir::Location loc, mlir::OpBuilder& builder, std::string str); | ||
|
||
#endif // SQLPARSER_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,5 @@ | ||
set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
mlir_tablegen(Passes.h.inc -gen-pass-decls -name sql) | ||
add_public_tablegen_target(MLIRSQLPassIncGen) | ||
|
||
add_mlir_doc(Passes SQLPasses ./ -gen-pass-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,52 @@ | ||
#ifndef SQL_DIALECT_SQL_PASSES_H | ||
#define SQL_DIALECT_SQL_PASSES_H | ||
|
||
#include "mlir/Conversion/LLVMCommon/LoweringOptions.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include <memory> | ||
namespace mlir { | ||
class PatternRewriter; | ||
class RewritePatternSet; | ||
class DominanceInfo; | ||
namespace sql { | ||
|
||
std::unique_ptr<Pass> createSQLLowerPass(); | ||
std::unique_ptr<Pass> createSQLRaisingPass(); | ||
void registersqlPasses(); | ||
} // namespace sql | ||
} // namespace mlir | ||
|
||
|
||
|
||
namespace mlir { | ||
// Forward declaration from Dialect.h | ||
template <typename ConcreteDialect> | ||
void registerDialect(DialectRegistry ®istry); | ||
|
||
namespace arith { | ||
class ArithDialect; | ||
} // end namespace arith | ||
|
||
namespace scf { | ||
class SCFDialect; | ||
} // end namespace scf | ||
|
||
namespace memref { | ||
class MemRefDialect; | ||
} // end namespace memref | ||
|
||
namespace func { | ||
class FuncDialect; | ||
} | ||
|
||
class AffineDialect; | ||
namespace LLVM { | ||
class LLVMDialect; | ||
} | ||
|
||
#define GEN_PASS_REGISTRATION | ||
#include "sql/Passes/Passes.h.inc" | ||
|
||
} // end namespace mlir | ||
|
||
#endif // SQL_DIALECT_SQL_PASSES_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,22 @@ | ||
#ifndef SQL_PASSES | ||
#define SQL_PASSES | ||
|
||
include "mlir/Pass/PassBase.td" | ||
|
||
|
||
def SQLLower : Pass<"sql-lower", "mlir::ModuleOp"> { | ||
let summary = "Lower sql op to mlir"; | ||
let dependentDialects = | ||
["arith::ArithDialect", "func::FuncDialect", "LLVM::LLVMDialect"]; | ||
let constructor = "mlir::sql::createSQLLowerPass()"; | ||
} | ||
|
||
|
||
def SQLRaising : Pass<"sql-raising", "mlir::ModuleOp"> { | ||
let summary = "Raise sql op to mlir"; | ||
let dependentDialects = | ||
["arith::ArithDialect", "func::FuncDialect", "LLVM::LLVMDialect"]; | ||
let constructor = "mlir::sql::createSQLRaisingPass()"; | ||
} | ||
|
||
#endif // SQL_PASSES |
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,139 @@ | ||
#pragma once | ||
|
||
#include "mlir/Dialect/Affine/IR/AffineOps.h" | ||
#include "mlir/Dialect/SCF/IR/SCF.h" | ||
#include "mlir/IR/BlockAndValueMapping.h" | ||
#include "mlir/IR/IntegerSet.h" | ||
|
||
static inline mlir::scf::IfOp | ||
cloneWithResults(mlir::scf::IfOp op, mlir::OpBuilder &rewriter, | ||
mlir::BlockAndValueMapping mapping = {}) { | ||
using namespace mlir; | ||
return rewriter.create<scf::IfOp>(op.getLoc(), op.getResultTypes(), | ||
mapping.lookupOrDefault(op.getCondition()), | ||
true); | ||
} | ||
static inline mlir::AffineIfOp | ||
cloneWithResults(mlir::AffineIfOp op, mlir::OpBuilder &rewriter, | ||
mlir::BlockAndValueMapping mapping = {}) { | ||
using namespace mlir; | ||
SmallVector<mlir::Value> lower; | ||
for (auto o : op.getOperands()) | ||
lower.push_back(mapping.lookupOrDefault(o)); | ||
return rewriter.create<AffineIfOp>(op.getLoc(), op.getResultTypes(), | ||
op.getIntegerSet(), lower, true); | ||
} | ||
|
||
static inline mlir::scf::IfOp | ||
cloneWithoutResults(mlir::scf::IfOp op, mlir::OpBuilder &rewriter, | ||
mlir::BlockAndValueMapping mapping = {}, | ||
mlir::TypeRange types = {}) { | ||
using namespace mlir; | ||
return rewriter.create<scf::IfOp>( | ||
op.getLoc(), types, mapping.lookupOrDefault(op.getCondition()), true); | ||
} | ||
static inline mlir::AffineIfOp | ||
cloneWithoutResults(mlir::AffineIfOp op, mlir::OpBuilder &rewriter, | ||
mlir::BlockAndValueMapping mapping = {}, | ||
mlir::TypeRange types = {}) { | ||
using namespace mlir; | ||
SmallVector<mlir::Value> lower; | ||
for (auto o : op.getOperands()) | ||
lower.push_back(mapping.lookupOrDefault(o)); | ||
return rewriter.create<AffineIfOp>(op.getLoc(), types, op.getIntegerSet(), | ||
lower, true); | ||
} | ||
|
||
static inline mlir::scf::ForOp | ||
cloneWithoutResults(mlir::scf::ForOp op, mlir::PatternRewriter &rewriter, | ||
mlir::BlockAndValueMapping mapping = {}) { | ||
using namespace mlir; | ||
return rewriter.create<scf::ForOp>( | ||
op.getLoc(), mapping.lookupOrDefault(op.getLowerBound()), | ||
mapping.lookupOrDefault(op.getUpperBound()), | ||
mapping.lookupOrDefault(op.getStep())); | ||
} | ||
static inline mlir::AffineForOp | ||
cloneWithoutResults(mlir::AffineForOp op, mlir::PatternRewriter &rewriter, | ||
mlir::BlockAndValueMapping mapping = {}) { | ||
using namespace mlir; | ||
SmallVector<Value> lower; | ||
for (auto o : op.getLowerBoundOperands()) | ||
lower.push_back(mapping.lookupOrDefault(o)); | ||
SmallVector<Value> upper; | ||
for (auto o : op.getUpperBoundOperands()) | ||
upper.push_back(mapping.lookupOrDefault(o)); | ||
return rewriter.create<AffineForOp>(op.getLoc(), lower, op.getLowerBoundMap(), | ||
upper, op.getUpperBoundMap(), | ||
op.getStep()); | ||
} | ||
|
||
static inline void clearBlock(mlir::Block *block, | ||
mlir::PatternRewriter &rewriter) { | ||
for (auto &op : llvm::make_early_inc_range(llvm::reverse(*block))) { | ||
assert(op.use_empty() && "expected 'op' to have no uses"); | ||
rewriter.eraseOp(&op); | ||
} | ||
} | ||
|
||
static inline mlir::Block *getThenBlock(mlir::scf::IfOp op) { | ||
return op.thenBlock(); | ||
} | ||
static inline mlir::Block *getThenBlock(mlir::AffineIfOp op) { | ||
return op.getThenBlock(); | ||
} | ||
static inline mlir::Block *getElseBlock(mlir::scf::IfOp op) { | ||
return op.elseBlock(); | ||
} | ||
static inline mlir::Block *getElseBlock(mlir::AffineIfOp op) { | ||
if (op.hasElse()) | ||
return op.getElseBlock(); | ||
else | ||
return nullptr; | ||
} | ||
|
||
static inline mlir::Region &getThenRegion(mlir::scf::IfOp op) { | ||
return op.getThenRegion(); | ||
} | ||
static inline mlir::Region &getThenRegion(mlir::AffineIfOp op) { | ||
return op.getThenRegion(); | ||
} | ||
static inline mlir::Region &getElseRegion(mlir::scf::IfOp op) { | ||
return op.getElseRegion(); | ||
} | ||
static inline mlir::Region &getElseRegion(mlir::AffineIfOp op) { | ||
return op.getElseRegion(); | ||
} | ||
|
||
static inline mlir::scf::YieldOp getThenYield(mlir::scf::IfOp op) { | ||
return op.thenYield(); | ||
} | ||
static inline mlir::AffineYieldOp getThenYield(mlir::AffineIfOp op) { | ||
return llvm::cast<mlir::AffineYieldOp>(op.getThenBlock()->getTerminator()); | ||
} | ||
static inline mlir::scf::YieldOp getElseYield(mlir::scf::IfOp op) { | ||
return op.elseYield(); | ||
} | ||
static inline mlir::AffineYieldOp getElseYield(mlir::AffineIfOp op) { | ||
return llvm::cast<mlir::AffineYieldOp>(op.getElseBlock()->getTerminator()); | ||
} | ||
|
||
static inline bool inBound(mlir::scf::IfOp op, mlir::Value v) { | ||
return op.getCondition() == v; | ||
} | ||
static inline bool inBound(mlir::AffineIfOp op, mlir::Value v) { | ||
return llvm::any_of(op.getOperands(), [&](mlir::Value e) { return e == v; }); | ||
} | ||
static inline bool inBound(mlir::scf::ForOp op, mlir::Value v) { | ||
return op.getUpperBound() == v; | ||
} | ||
static inline bool inBound(mlir::AffineForOp op, mlir::Value v) { | ||
return llvm::any_of(op.getUpperBoundOperands(), | ||
[&](mlir::Value e) { return e == v; }); | ||
} | ||
static inline bool hasElse(mlir::scf::IfOp op) { | ||
return op.getElseRegion().getBlocks().size() > 0; | ||
} | ||
static inline bool hasElse(mlir::AffineIfOp op) { | ||
return op.getElseRegion().getBlocks().size() > 0; | ||
} |
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,16 @@ | ||
//===- SQLDialect.h - SQL dialect -----------------*- C++ -*-===// | ||
// | ||
// This file is licensed 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 SQL_DIALECT_H | ||
#define SQL_DIALECT_H | ||
|
||
#include "mlir/IR/Dialect.h" | ||
|
||
#include "sql/SQLOpsDialect.h.inc" | ||
|
||
#endif |
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,40 @@ | ||
//===- SQLDialect.td - SQL dialect -----------*- tablegen -*-===// | ||
// | ||
carlguo866 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This file is licensed 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 SQL_DIALECT | ||
#define SQL_DIALECT | ||
|
||
|
||
|
||
include "mlir/IR/SymbolInterfaces.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
include "mlir/Interfaces/CallInterfaces.td" | ||
include "mlir/Interfaces/CastInterfaces.td" | ||
|
||
|
||
def SQL_Dialect : Dialect { | ||
let summary = "A dialect for SQL languages in MLIR."; | ||
let description = [{ | ||
TBD | ||
}]; | ||
let name = "sql"; | ||
let cppNamespace = "::mlir::sql"; | ||
|
||
let useDefaultTypePrinterParser = 1; | ||
let extraClassDeclaration = [{ | ||
void registerTypes(); | ||
}]; | ||
} | ||
|
||
|
||
#endif // SQL_DIALECT | ||
|
||
|
||
|
||
|
||
|
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.