[flang] add FIROps.h

Original-commit: flang-compiler/f18@e53fefb66c
Reviewed-on: https://github.com/flang-compiler/f18/pull/696
Tree-same-pre-rewrite: false
This commit is contained in:
Eric Schweitz 2019-09-10 08:25:34 -07:00
parent d6bfd9135c
commit 6bff59ec6b
1 changed files with 114 additions and 0 deletions

114
flang/include/fir/FIROps.h Normal file
View File

@ -0,0 +1,114 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIR_FIROPS_H
#define FIR_FIROPS_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/FunctionSupport.h"
#include "mlir/IR/OpDefinition.h"
using namespace mlir;
using llvm::ArrayRef;
using llvm::StringRef;
namespace fir {
class FirEndOp;
/// `fir.global` is a typed symbol with an optional list of initializers.
class GlobalOp
: public mlir::Op<GlobalOp, mlir::OpTrait::ZeroOperands,
mlir::OpTrait::ZeroResult, mlir::OpTrait::IsIsolatedFromAbove,
mlir::OpTrait::SingleBlockImplicitTerminator<FirEndOp>::Impl> {
public:
using Op::Op;
using Op::print;
static llvm::StringRef getOperationName() { return "fir.global"; }
static llvm::StringRef getTypeAttrName() { return "type"; }
static void build(mlir::Builder *builder, mlir::OperationState *result,
llvm::StringRef name, mlir::Type type,
llvm::ArrayRef<mlir::NamedAttribute> attrs);
/// Operation hooks.
static mlir::ParseResult parse(
mlir::OpAsmParser *parser, mlir::OperationState *result);
void print(mlir::OpAsmPrinter *p);
mlir::LogicalResult verify();
mlir::Type getType() {
return getAttrOfType<TypeAttr>(getTypeAttrName()).getValue();
}
void appendInitialValue(mlir::Operation *op);
private:
mlir::Region &front();
};
/// `fir.dispatch_table` is an untyped symbol that is a list of associations
/// between method identifiers and a FuncOp symbol.
class DispatchTableOp
: public mlir::Op<DispatchTableOp, mlir::OpTrait::ZeroOperands,
mlir::OpTrait::ZeroResult, mlir::OpTrait::IsIsolatedFromAbove,
mlir::OpTrait::SingleBlockImplicitTerminator<FirEndOp>::Impl> {
public:
using Op::Op;
static llvm::StringRef getOperationName() { return "fir.dispatch_table"; }
static void build(mlir::Builder *builder, mlir::OperationState *result,
llvm::StringRef name, mlir::Type type,
llvm::ArrayRef<mlir::NamedAttribute> attrs);
/// Operation hooks.
static mlir::ParseResult parse(
mlir::OpAsmParser *parser, mlir::OperationState *result);
void print(mlir::OpAsmPrinter *p);
mlir::LogicalResult verify();
void appendTableEntry(mlir::Operation *op);
private:
mlir::Region &front();
};
mlir::ParseResult isValidCaseAttr(mlir::Attribute attr);
unsigned getCaseArgumentOffset(
llvm::ArrayRef<mlir::Attribute> cases, unsigned dest);
#define GET_OP_CLASSES
#include "fir/FIROps.h.inc"
mlir::ParseResult parseCallOp(
mlir::OpAsmParser *parser, mlir::OperationState *result);
void printCallOp(mlir::OpAsmPrinter *p, fir::CallOp call);
mlir::ParseResult parseDispatchOp(
mlir::OpAsmParser *parser, mlir::OperationState *result);
mlir::ParseResult parseDTEntryOp(
mlir::OpAsmParser *parser, mlir::OperationState *result);
LoopOp getForInductionVarOwner(mlir::Value *val);
} // namespace fir
#endif // FIR_FIROPS_H