+++ /dev/null
-// 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 FIRST_TERM_STMT
-#define FIRST_TERM_STMT(num)
-#endif
-#ifndef HANDLE_TERM_STMT
-#ifndef HANDLE_STMT
-#define HANDLE_TERM_STMT(num, opcode, Class)
-#else
-#define HANDLE_TERM_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
-#endif
-#endif
-#ifndef LAST_TERM_STMT
-#define LAST_TERM_STMT(num)
-#endif
-
-#ifndef FIRST_COMPUTE_STMT
-#define FIRST_COMPUTE_STMT(num)
-#endif
-#ifndef HANDLE_COMPUTE_STMT
-#ifndef HANDLE_STMT
-#define HANDLE_COMPUTE_STMT(num, opcode, instclass)
-#else
-#define HANDLE_COMPUTE_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
-#endif
-#endif
-#ifndef LAST_COMPUTE_STMT
-#define LAST_COMPUTE_STMT(num)
-#endif
-
-#ifndef FIRST_MEMORY_STMT
-#define FIRST_MEMORY_STMT(num)
-#endif
-#ifndef HANDLE_MEMORY_STMT
-#ifndef HANDLE_STMT
-#define HANDLE_MEMORY_STMT(num, opcode, Class)
-#else
-#define HANDLE_MEMORY_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
-#endif
-#endif
-#ifndef LAST_MEMORY_STMT
-#define LAST_MEMORY_STMT(num)
-#endif
-
-#ifndef FIRST_CAST_STMT
-#define FIRST_CAST_STMT(num)
-#endif
-#ifndef HANDLE_CAST_STMT
-#ifndef HANDLE_STMT
-#define HANDLE_CAST_STMT(num, opcode, Class)
-#else
-#define HANDLE_CAST_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
-#endif
-#endif
-#ifndef LAST_CAST_STMT
-#define LAST_CAST_STMT(num)
-#endif
-
-#ifndef FIRST_OTHER_STMT
-#define FIRST_OTHER_STMT(num)
-#endif
-#ifndef HANDLE_LAST_OTHER_STMT
-#ifndef HANDLE_LAST_STMT
-#ifndef HANDLE_OTHER_STMT
-#ifndef HANDLE_STMT
-#define HANDLE_LAST_OTHER_STMT(num, opcode, Class)
-#else
-#define HANDLE_LAST_OTHER_STMT(num, opcode, Class) \
- HANDLE_STMT(num, opcode, Class)
-#endif
-#else
-#define HANDLE_LAST_OTHER_STMT(num, opcode, Class) \
- HANDLE_OTHER_STMT(num, opcode, Class)
-#endif
-#else
-#define HANDLE_LAST_OTHER_STMT(num, opcode, Class) \
- HANDLE_LAST_STMT(num, opcode, Class)
-#endif
-#endif
-#ifndef HANDLE_OTHER_STMT
-#ifndef HANDLE_STMT
-#define HANDLE_OTHER_STMT(num, opcode, Class)
-#else
-#define HANDLE_OTHER_STMT(num, opcode, Class) HANDLE_STMT(num, opcode, Class)
-#endif
-#endif
-#ifndef LAST_OTHER_STMT
-#define LAST_OTHER_STMT(num)
-#endif
-
-// Terminator Instructions - These instructions are used to terminate a basic
-// block of the program. Every basic block must end with one of these
-// instructions for it to be a well formed basic block.
-FIRST_TERM_STMT(1)
-HANDLE_TERM_STMT( 1, Return, ReturnStmt)
-HANDLE_TERM_STMT( 2, Branch, BranchStmt)
-HANDLE_TERM_STMT( 3, Switch, SwitchStmt)
-HANDLE_TERM_STMT( 4, SwitchCase, SwitchCaseStmt)
-HANDLE_TERM_STMT( 5, SwitchType, SwitchTypeStmt)
-HANDLE_TERM_STMT( 6, SwitchRank, SwitchRankStmt)
-HANDLE_TERM_STMT( 7, IndirectBranch, IndirectBranchStmt)
-HANDLE_TERM_STMT( 8, Unreachable, UnreachableStmt)
-LAST_TERM_STMT(8)
-
-// Standard actions - These instructions capture computations as
-// evaluate::expressions
-FIRST_COMPUTE_STMT(9)
-HANDLE_COMPUTE_STMT( 9, Assign, AssignmentStmt)
-HANDLE_COMPUTE_STMT(10, PointerAssign, PointerAssignStmt)
-HANDLE_COMPUTE_STMT(11, LabelAssign, LabelAssignStmt)
-HANDLE_COMPUTE_STMT(12, ApplyExpr, ApplyExprStmt)
-HANDLE_COMPUTE_STMT(13, LocateExpr, LocateExprStmt)
-LAST_COMPUTE_STMT(13)
-
-// Memory operators - These instructions capture ALLOCATE and DEALLOCATE
-// Fortran statements
-FIRST_MEMORY_STMT(14)
-HANDLE_MEMORY_STMT(14, Allocate, AllocateInsn)
-HANDLE_MEMORY_STMT(15, Deallocate, DeallocateInsn)
-HANDLE_MEMORY_STMT(16, AllocLocal, AllocateLocalInsn)
-HANDLE_MEMORY_STMT(17, Load, LoadInsn)
-HANDLE_MEMORY_STMT(18, Store, StoreInsn)
-HANDLE_MEMORY_STMT(19, Disassociate, DisassociateInsn)
-LAST_MEMORY_STMT(19)
-
-// Other operators - These are operations that don't fit the above categories
-FIRST_OTHER_STMT(20)
-HANDLE_OTHER_STMT(20, Call, CallStmt)
-HANDLE_OTHER_STMT(21, RuntimeCall, RuntimeStmt)
-HANDLE_OTHER_STMT(22, IORuntimeCall, IORuntimeStmt)
-HANDLE_OTHER_STMT(23, ScopeEnter, ScopeEnterStmt)
-HANDLE_OTHER_STMT(24, ScopeExit, ScopeExitStmt)
-HANDLE_LAST_OTHER_STMT(25, Phi, PHIStmt)
-LAST_OTHER_STMT(25)
-
-#undef FIRST_TERM_STMT
-#undef HANDLE_TERM_STMT
-#undef LAST_TERM_STMT
-
-#undef FIRST_COMPUTE_STMT
-#undef HANDLE_COMPUTE_STMT
-#undef LAST_COMPUTE_STMT
-
-#undef FIRST_MEMORY_STMT
-#undef HANDLE_MEMORY_STMT
-#undef LAST_MEMORY_STMT
-
-#undef FIRST_CAST_STMT
-#undef HANDLE_CAST_STMT
-#undef LAST_CAST_STMT
-
-#undef FIRST_OTHER_STMT
-#undef HANDLE_OTHER_STMT
-#undef HANDLE_LAST_OTHER_STMT
-#undef HANDLE_LAST_STMT
-#undef LAST_OTHER_STMT
-
-#ifdef HANDLE_STMT
-#undef HANDLE_STMT
-#endif
class Stmt_impl {
public:
using StatementTrait = std::true_type;
+ virtual ~Stmt_impl() {}
};
// Every basic block must end in a terminator
return IndirectBranchStmt{variable, potentialTargets};
}
+ Variable *variable() const { return variable_; }
+
private:
explicit IndirectBranchStmt(
Variable *variable, const TargetListType &potentialTargets)
return AllocateInsn{type, alignment};
}
+ Type type() const { return type_; }
+ int alignment() const { return alignment_; }
+
private:
explicit AllocateInsn(Type type, int alignment)
: type_{type}, alignment_{alignment} {}
// Deallocate storage (per DEALLOCATE)
class DeallocateInsn : public MemoryStmt_impl {
public:
- static DeallocateInsn Create(const AllocateInsn *alloc) {
+ static DeallocateInsn Create(AllocateInsn *alloc) {
return DeallocateInsn{alloc};
}
+ AllocateInsn *alloc() { return alloc_; }
+
private:
- explicit DeallocateInsn(const AllocateInsn *alloc) : alloc_{alloc} {}
- const AllocateInsn *alloc_;
+ explicit DeallocateInsn(AllocateInsn *alloc) : alloc_{alloc} {}
+ AllocateInsn *alloc_;
};
// Allocate space for a temporary by its Type. The lifetime of the temporary
return AllocateLocalInsn{type, alignment};
}
+ Type type() const { return type_; }
+ int alignment() const { return alignment_; }
+
private:
explicit AllocateLocalInsn(Type type, int alignment, const Expression &expr)
: Addressable_impl{expr}, type_{type}, alignment_{alignment} {}
return DisassociateInsn{n};
}
+ // FIXME - remove parse tree reference
+ const parser::NullifyStmt *disassociate() { return disassociate_; }
+
private:
DisassociateInsn(const parser::NullifyStmt *n) : disassociate_{n} {}
const parser::NullifyStmt *disassociate_;
return RuntimeStmt{call, std::move(argument)};
}
+ RuntimeCallType call() const { return call_; }
+
private:
explicit RuntimeStmt(RuntimeCallType call, RuntimeCallArguments &&arguments)
: CallStmt_impl{nullptr, nullptr, std::move(arguments)}, call_{call} {}
return IORuntimeStmt{call, std::move(arguments)};
}
+ InputOutputCallType call() const { return call_; }
+
private:
explicit IORuntimeStmt(InputOutputCallType call, IOCallArguments &&arguments)
: CallStmt_impl{nullptr, nullptr, std::move(arguments)}, call_{call} {}
+++ /dev/null
-// 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 FORTRAN_FIR_STMT_H_
-#define FORTRAN_FIR_STMT_H_
-
-#include "basicblock.h"
-#include "mixin.h"
-#include "statements.h"
-
-namespace Fortran::FIR {
-
-/// Sum type over all statement classes
-class Statement : public SumTypeMixin<std::variant<
-#define HANDLE_STMT(num, opcode, name) name,
-#define HANDLE_LAST_STMT(num, opcode, name) name
-#include "statement.def"
- >>,
- public ChildMixin<Statement, BasicBlock>,
- public llvm::ilist_node<Statement> {
-public:
- template<typename A>
- Statement(BasicBlock *p, A &&t) : SumTypeMixin{t}, ChildMixin{p} {
- parent->insertBefore(this);
- }
- std::string dump() const;
-};
-
-inline std::list<BasicBlock *> succ_list(BasicBlock &block) {
- if (auto *terminator{block.terminator()}) {
- return reinterpret_cast<const TerminatorStmt_impl *>(&terminator->u)
- ->succ_blocks();
- }
- // CHECK(false && "block does not have terminator");
- return {};
-}
-}
-
-#endif