serene/libserene.v0/lib/slir/ops.cpp

58 lines
1.8 KiB
C++
Raw Normal View History

2021-06-23 20:34:57 +01:00
/*
2021-10-12 20:51:03 +01:00
* Serene Programming Language
2021-06-23 20:34:57 +01:00
*
2022-01-27 11:44:44 +00:00
* Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
2021-06-23 20:34:57 +01:00
*
2021-10-12 20:51:03 +01:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
2021-06-23 20:34:57 +01:00
*
2021-10-12 20:51:03 +01:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2021-06-23 20:34:57 +01:00
*
2021-10-12 20:51:03 +01:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2021-06-23 20:34:57 +01:00
*/
#include "serene/slir/ops.h"
2021-06-23 20:34:57 +01:00
#include "serene/slir/dialect.h"
#include "serene/slir/types.h"
2022-06-02 15:24:27 +01:00
#include "serene/utils.h"
2021-06-23 20:34:57 +01:00
#include <llvm/Support/FormatVariadic.h>
#include <mlir/IR/Attributes.h>
2021-06-23 20:34:57 +01:00
#include <mlir/IR/Builders.h>
#include <mlir/IR/BuiltinAttributes.h>
2021-06-23 20:34:57 +01:00
#include <mlir/IR/OperationSupport.h>
#define GET_OP_CLASSES
#include "serene/slir/ops.cpp.inc"
2022-04-27 21:49:57 +01:00
namespace serene::slir {
mlir::DataLayoutSpecInterface NsOp::getDataLayoutSpec() {
// Take the first and only (if present) attribute that implements the
// interface. This needs a linear search, but is called only once per data
// layout object construction that is used for repeated queries.
2022-06-02 15:24:27 +01:00
for (mlir::NamedAttribute attr : getOperation()->getAttrs()) {
if (auto spec = attr.getValue().dyn_cast<mlir::DataLayoutSpecInterface>()) {
2022-04-27 21:49:57 +01:00
return spec;
2022-06-02 15:24:27 +01:00
}
}
2022-04-27 21:49:57 +01:00
return {};
}
mlir::OpFoldResult SymbolOp::fold(llvm::ArrayRef<mlir::Attribute> operands) {
UNUSED(operands);
return value();
};
2022-06-02 15:24:27 +01:00
mlir::OpFoldResult ValueOp::fold(llvm::ArrayRef<mlir::Attribute> operands) {
UNUSED(operands);
return value();
};
2022-04-27 21:49:57 +01:00
} // namespace serene::slir