blob: 2222a12c5d1295d15567288229f988e2075c29b8 [file] [log] [blame]
Chris Lattner4c95a502018-06-23 16:03:42 -07001//===- Instructions.cpp - MLIR CFGFunction Instruction Classes ------------===//
2//
3// Copyright 2019 The MLIR Authors.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// =============================================================================
17
18#include "mlir/IR/Instructions.h"
19#include "mlir/IR/BasicBlock.h"
20using namespace mlir;
21
Chris Lattnered65a732018-06-28 20:45:33 -070022//===----------------------------------------------------------------------===//
23// Instruction
24//===----------------------------------------------------------------------===//
25
26CFGFunction *Instruction::getFunction() const {
Chris Lattner4c95a502018-06-23 16:03:42 -070027 return getBlock()->getFunction();
28}
29
Chris Lattnered65a732018-06-28 20:45:33 -070030//===----------------------------------------------------------------------===//
31// OperationInst
32//===----------------------------------------------------------------------===//
33
34OperationInst::OperationInst(Identifier name, BasicBlock *block) :
35 Instruction(Kind::Operation, block), name(name) {
36 getBlock()->instList.push_back(this);
37}
38
39//===----------------------------------------------------------------------===//
40// Terminators
41//===----------------------------------------------------------------------===//
42
Chris Lattnerf6d80a02018-06-24 11:18:29 -070043ReturnInst::ReturnInst(BasicBlock *parent)
44 : TerminatorInst(Kind::Return, parent) {
Chris Lattnered65a732018-06-28 20:45:33 -070045 getBlock()->setTerminator(this);
Chris Lattner4c95a502018-06-23 16:03:42 -070046}
47
Chris Lattnerf6d80a02018-06-24 11:18:29 -070048BranchInst::BranchInst(BasicBlock *dest, BasicBlock *parent)
49 : TerminatorInst(Kind::Branch, parent), dest(dest) {
Chris Lattnered65a732018-06-28 20:45:33 -070050 getBlock()->setTerminator(this);
Chris Lattnerf6d80a02018-06-24 11:18:29 -070051}