Fix the compatiblity issues with llvm version aff028f7d8322c625422febd3d8b9794746cdc5b

This commit is contained in:
Sameer Rahmani 2021-12-15 17:26:08 +00:00
parent 76a9106559
commit 3e82b71903
7 changed files with 34 additions and 23 deletions

View File

@ -1,5 +1,5 @@
--- ---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,cert-*,-cert-err58-cpp,concurrency-*,llvm-*,performance-*,readability-*' Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,cert-*,-cert-err58-cpp,concurrency-*,llvm-*,performance-*,-readability-identifier-length*,readability-*'
WarningsAsErrors: 'clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,cert-*,-cert-err58-cpp,concurrency-*,llvm-*,performance-*,readability-*' WarningsAsErrors: 'clang-diagnostic-*,clang-analyzer-*,-*,clang-analyzer-*,cert-*,-cert-err58-cpp,concurrency-*,llvm-*,performance-*,readability-*'
HeaderFilterRegex: '' HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false

View File

@ -18,6 +18,11 @@ Setup the githook and install dependencies using the following commands:
- CCache (If you want faster builds specially with the LLVM) - CCache (If you want faster builds specially with the LLVM)
** LLVM Installation ** LLVM Installation
*Important Note*: We're trying to keep Serene up to date with the LLVM release cycle till we get
to our first release. So we use the development version of the LLVM. Currently we are using
=aff028f7d8322c625422febd3d8b9794746cdc5b= commit as our reference.
MLIR is a part of the [[https://llvm.org][LLVM]] project and in order to build it we need to build the LLVM itself as well. MLIR is a part of the [[https://llvm.org][LLVM]] project and in order to build it we need to build the LLVM itself as well.
Here is a quick guide to build the latest version of the LLVM and MLIR. Here is a quick guide to build the latest version of the LLVM and MLIR.

View File

@ -95,8 +95,8 @@ public:
baseLayer.emit(std::move(mr), compileAst(ns, e)); baseLayer.emit(std::move(mr), compileAst(ns, e));
} }
orc::MaterializationUnit::Interface getInterface(Namespace &ns,
orc::SymbolFlagsMap getInterface(Namespace &ns, exprs::Ast &e); exprs::Ast &e);
}; };
/// NS Layer ================================================================== /// NS Layer ==================================================================
@ -157,7 +157,7 @@ public:
baseLayer.emit(std::move(mr), compileNS(ns)); baseLayer.emit(std::move(mr), compileNS(ns));
} }
orc::SymbolFlagsMap getInterface(serene::Namespace &ns); orc::MaterializationUnit::Interface getInterface(serene::Namespace &ns);
}; };
} // namespace jit } // namespace jit
} // namespace serene } // namespace serene

View File

@ -20,6 +20,7 @@
#define LLVM_PATCHES_H #define LLVM_PATCHES_H
#include <llvm/ADT/DenseMap.h> #include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/Hashing.h>
namespace llvm { namespace llvm {

View File

@ -48,15 +48,16 @@ llvm::orc::ThreadSafeModule compileAst(Namespace &ns, exprs::Ast &ast) {
AstMaterializationUnit::AstMaterializationUnit(Namespace &ns, AstLayer &l, AstMaterializationUnit::AstMaterializationUnit(Namespace &ns, AstLayer &l,
exprs::Ast &ast) exprs::Ast &ast)
: MaterializationUnit(l.getInterface(ns, ast), nullptr), ns(ns), : orc::MaterializationUnit(l.getInterface(ns, ast)), ns(ns), astLayer(l),
astLayer(l), ast(ast){}; ast(ast){};
void AstMaterializationUnit::materialize( void AstMaterializationUnit::materialize(
std::unique_ptr<orc::MaterializationResponsibility> r) { std::unique_ptr<orc::MaterializationResponsibility> r) {
astLayer.emit(std::move(r), ns, ast); astLayer.emit(std::move(r), ns, ast);
} }
orc::SymbolFlagsMap AstLayer::getInterface(Namespace &ns, exprs::Ast &e) { orc::MaterializationUnit::Interface AstLayer::getInterface(Namespace &ns,
exprs::Ast &e) {
orc::SymbolFlagsMap Symbols; orc::SymbolFlagsMap Symbols;
auto symList = ns.getSymList(); auto symList = ns.getSymList();
unsigned index = symList.size(); unsigned index = symList.size();
@ -67,7 +68,7 @@ orc::SymbolFlagsMap AstLayer::getInterface(Namespace &ns, exprs::Ast &e) {
if (err) { if (err) {
// TODO: Fix this by a call to diag engine or return the err // TODO: Fix this by a call to diag engine or return the err
llvm::outs() << "Fixme: semantic err\n"; llvm::outs() << "Fixme: semantic err\n";
return Symbols; return orc::MaterializationUnit::Interface(std::move(Symbols), nullptr);
} }
auto &env = ns.getRootEnv(); auto &env = ns.getRootEnv();
@ -92,7 +93,7 @@ orc::SymbolFlagsMap AstLayer::getInterface(Namespace &ns, exprs::Ast &e) {
}; };
std::for_each(symList.begin() + index, symList.end(), populateTableFn); std::for_each(symList.begin() + index, symList.end(), populateTableFn);
return Symbols; return orc::MaterializationUnit::Interface(std::move(Symbols), nullptr);
} }
/// NS Layer ================================================================== /// NS Layer ==================================================================
@ -111,7 +112,7 @@ llvm::orc::ThreadSafeModule compileNS(Namespace &ns) {
}; };
NSMaterializationUnit::NSMaterializationUnit(NSLayer &l, Namespace &ns) NSMaterializationUnit::NSMaterializationUnit(NSLayer &l, Namespace &ns)
: MaterializationUnit(l.getInterface(ns), nullptr), nsLayer(l), ns(ns){}; : MaterializationUnit(l.getInterface(ns)), nsLayer(l), ns(ns){};
void NSMaterializationUnit::materialize( void NSMaterializationUnit::materialize(
std::unique_ptr<orc::MaterializationResponsibility> r) { std::unique_ptr<orc::MaterializationResponsibility> r) {
@ -139,7 +140,8 @@ llvm::Error NSLayer::add(orc::ResourceTrackerSP &rt, llvm::StringRef nsname,
std::make_unique<NSMaterializationUnit>(*this, *ns), rt); std::make_unique<NSMaterializationUnit>(*this, *ns), rt);
} }
orc::SymbolFlagsMap NSLayer::getInterface(serene::Namespace &ns) { orc::MaterializationUnit::Interface
NSLayer::getInterface(serene::Namespace &ns) {
orc::SymbolFlagsMap Symbols; orc::SymbolFlagsMap Symbols;
for (auto &k : ns.getRootEnv()) { for (auto &k : ns.getRootEnv()) {
@ -156,7 +158,7 @@ orc::SymbolFlagsMap NSLayer::getInterface(serene::Namespace &ns) {
Symbols[mangledSym] = llvm::JITSymbolFlags(flags); Symbols[mangledSym] = llvm::JITSymbolFlags(flags);
} }
return Symbols; return orc::MaterializationUnit::Interface(std::move(Symbols), nullptr);
} }
} // namespace serene::jit } // namespace serene::jit

View File

@ -56,11 +56,13 @@ ValueOpLowering::matchAndRewrite(serene::slir::ValueOp op,
auto *entryBlock = fn.addEntryBlock(); auto *entryBlock = fn.addEntryBlock();
rewriter.setInsertionPointToStart(entryBlock); rewriter.setInsertionPointToStart(entryBlock);
// Since we only support i64 at the moment we use ConstantIntOp // Since we only support i64 at the moment we use ConstantOp
auto retVal = rewriter auto retVal =
.create<mlir::ConstantIntOp>(loc, (int64_t)value, rewriter
rewriter.getI64Type()) .create<mlir::ConstantOp>(
.getResult(); loc, mlir::IntegerAttr::get(rewriter.getI64Type(), value),
rewriter.getI64Type())
.getResult();
UNUSED(rewriter.create<mlir::ReturnOp>(loc, retVal)); UNUSED(rewriter.create<mlir::ReturnOp>(loc, retVal));
@ -92,7 +94,7 @@ FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
llvm::SmallVector<mlir::Type, 4> arg_types; llvm::SmallVector<mlir::Type, 4> arg_types;
for (const auto &arg : args) { for (const auto &arg : args) {
auto attr = std::get<1>(arg).dyn_cast<mlir::TypeAttr>(); auto attr = arg.getValue().dyn_cast<mlir::TypeAttr>();
if (!attr) { if (!attr) {
op.emitError("It's not a type attr"); op.emitError("It's not a type attr");
@ -108,10 +110,11 @@ FnOpLowering::matchAndRewrite(serene::slir::FnOp op,
rewriter.setInsertionPointToStart(entryBlock); rewriter.setInsertionPointToStart(entryBlock);
auto retVal = auto retVal = rewriter
rewriter .create<mlir::ConstantOp>(
.create<mlir::ConstantIntOp>(loc, (int64_t)3, rewriter.getI64Type()) loc, mlir::IntegerAttr::get(rewriter.getI64Type(), 3),
.getResult(); rewriter.getI64Type())
.getResult();
rewriter.create<mlir::ReturnOp>(loc, retVal); rewriter.create<mlir::ReturnOp>(loc, retVal);

View File

@ -35,12 +35,12 @@
#include <llvm/ADT/SmallString.h> #include <llvm/ADT/SmallString.h>
#include <llvm/ADT/StringRef.h> #include <llvm/ADT/StringRef.h>
#include <llvm/IR/LegacyPassManager.h> #include <llvm/IR/LegacyPassManager.h>
//#include <llvm/MC/TargetRegistry.h>
#include <llvm/Support/CommandLine.h> #include <llvm/Support/CommandLine.h>
#include <llvm/Support/FileSystem.h> #include <llvm/Support/FileSystem.h>
#include <llvm/Support/FormatVariadic.h> #include <llvm/Support/FormatVariadic.h>
#include <llvm/Support/Host.h> #include <llvm/Support/Host.h>
#include <llvm/Support/Path.h> #include <llvm/Support/Path.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/raw_ostream.h> #include <llvm/Support/raw_ostream.h>
#include <llvm/Target/TargetMachine.h> #include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h> #include <llvm/Target/TargetOptions.h>