MLIR: include/mlir/Interfaces/ControlFlowInterfaces.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14 #ifndef MLIR_INTERFACES_CONTROLFLOWINTERFACES_H

15 #define MLIR_INTERFACES_CONTROLFLOWINTERFACES_H

16

18

19 namespace mlir {

20 class BranchOpInterface;

21 class RegionBranchOpInterface;

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

44 public:

45

46

48

49

50

53

54

55

56 unsigned size() const {

57 return producedOperandCount + forwardedOperands.size();

58 }

59

60

61 bool empty() const { return size() == 0; }

62

63

64

66

67

68

70 return index < producedOperandCount;

71 }

72

73

74

75

79 return forwardedOperands[index - producedOperandCount].get();

80 }

81

82

84

85

87 return forwardedOperands;

88 }

89

90

91

94 "can't slice operands produced by the operation");

95 return forwardedOperands.slice(subStart - producedOperandCount, subLen);

96 }

97

98

99

100 void erase(unsigned subStart, unsigned subLen = 1) {

102 "can't erase operands produced by the operation");

103 forwardedOperands.erase(subStart - producedOperandCount, subLen);

104 }

105

106

108

109

110

111

114 "can't map operand produced by the operation");

117 (blockArgumentIndex - producedOperandCount);

118 }

119

120 private:

121

122

123 unsigned producedOperandCount;

124

126 };

127

128

129

130

131

132 namespace detail {

133

134

135

136 std::optional

138 unsigned operandIndex, Block *successor);

139

140

142 const SuccessorOperands &operands);

143 }

144

145

146

147

148

149 namespace detail {

150

151

153 }

154

155

156

157

158

159 namespace detail {

160

161

163 }

164

165

166

167

168

169 namespace detail {

170

172 }

173

174

175

176

177

178

179

180

181

182

183

184

186 public:

187

188

190 : region(region), inputs(regionInputs) {}

191

194

196

197

198

200

201

202 bool isParent() const { return region == nullptr; }

203

204

205

207

208 private:

209 Region *region{nullptr};

210 ValueRange inputs;

211 };

212

213

214

215

216

217

219 public:

220

221

223

224

225

227 assert(region && "Region must not be null");

228 }

229

231

232

234

235

236

239 maybeRegion = nullptr;

240 else

242 }

243

244

246 maybeRegion = ®ion;

247 return *this;

248 }

249

250

251 bool isParent() const { return maybeRegion == nullptr; }

252

253

254

256

257

259 return lhs.maybeRegion == rhs.maybeRegion;

260 }

261

262 private:

263

265

266

267

268 Region *maybeRegion;

269 };

270

272 return !(lhs == rhs);

273 }

274

275

276

277

279 public:

280

281

283 : lower(lb), upper(ub) {

284 assert((!ub || ub >= lb) && "upper bound cannot be less than lower bound");

285 }

286

287

289

290

291 std::optional getUpperBound() const { return upper; }

292

293

294

296

297 private:

298

299 unsigned lower;

300

301

302 std::optional upper;

303 };

304

305

306

308

309

310

311

313

314

315

316

318

319

320

321

322

323 namespace OpTrait {

324

325

326

327

328 template

331 static_assert(ConcreteType::template hasTrait(),

332 "expected operation to be a terminator");

333 static_assert(ConcreteType::template hasTrait(),

334 "expected operation to have zero results");

335 static_assert(ConcreteType::template hasTrait(),

336 "expected operation to have zero successors");

337 return success();

338 }

339 };

340 }

341

342 }

343

344

345

346

347

348

349 #include "mlir/Interfaces/ControlFlowInterfaces.h.inc"

350

351 #endif

MutableArrayRef< BlockArgument > BlockArgListType

This class represents upper and lower bounds on the number of times a region of a RegionBranchOpInter...

static InvocationBounds getUnknown()

Returns the unknown invocation bounds, i.e., there is no information on how many times a region may b...

std::optional< unsigned > getUpperBound() const

Return the upper bound.

InvocationBounds(unsigned lb, std::optional< unsigned > ub)

Create invocation bounds.

unsigned getLowerBound() const

Return the lower bound.

This class provides a mutable adaptor for a range of operands.

unsigned size() const

Returns the current size of the range.

MutableOperandRange slice(unsigned subStart, unsigned subLen, std::optional< OperandSegment > segment=std::nullopt) const

Slice this range into a sub range, with the additional operand segment.

void erase(unsigned subStart, unsigned subLen=1)

Erase the operands within the given sub-range.

void append(ValueRange values)

Append the given values to the range.

Helper class for implementing traits.

This class implements the operand iterators for the Operation class.

unsigned getBeginOperandIndex() const

Return the operand index of the first element of this range.

Operation is the basic unit of execution within MLIR.

This class represents a point being branched from in the methods of the RegionBranchOpInterface.

RegionBranchPoint(std::nullptr_t)=delete

Explicitly stops users from constructing with nullptr.

RegionBranchPoint(RegionSuccessor successor)

Constructs a RegionBranchPoint from the the target of a RegionSuccessor instance.

bool isParent() const

Returns true if branching from the parent op.

RegionBranchPoint & operator=(Region &region)

Assigns a region being branched from.

static constexpr RegionBranchPoint parent()

Returns an instance of RegionBranchPoint representing the parent operation.

RegionBranchPoint(Region *region)

Creates a RegionBranchPoint that branches from the given region.

friend bool operator==(RegionBranchPoint lhs, RegionBranchPoint rhs)

Returns true if the two branch points are equal.

RegionBranchPoint(Region &region)

Region * getRegionOrNull() const

Returns the region if branching from a region.

This class represents a successor of a region.

RegionSuccessor(Region *region, Block::BlockArgListType regionInputs={})

Initialize a successor that branches to another region of the parent operation.

ValueRange getSuccessorInputs() const

Return the inputs to the successor that are remapped by the exit values of the current region.

RegionSuccessor()

Constructor with no arguments.

bool isParent() const

Return true if the successor is the parent operation.

Region * getSuccessor() const

Return the given region successor.

RegionSuccessor(Operation::result_range results)

Initialize a successor that branches back to/out of the parent operation.

This class contains a list of basic blocks and a link to the parent operation it is attached to.

This class implements the result iterators for the Operation class.

This class models how operands are forwarded to block arguments in control flow.

SuccessorOperands(unsigned producedOperandCount, MutableOperandRange forwardedOperands)

Constructs a SuccessorOperands with the given amount of produced operands and forwarded operands.

MutableOperandRange slice(unsigned subStart, unsigned subLen) const

Get a slice of the operands forwarded to the successor.

void erase(unsigned subStart, unsigned subLen=1)

Erase operands forwarded to the successor.

MutableOperandRange getMutableForwardedOperands() const

Get the range of operands that are simply forwarded to the successor.

SuccessorOperands(MutableOperandRange forwardedOperands)

Constructs a SuccessorOperands with no produced operands that simply forwards operands to the success...

Value operator[](unsigned index) const

Returns the Value that is passed to the successors block argument denoted by index.

unsigned getOperandIndex(unsigned blockArgumentIndex) const

Gets the index of the forwarded operand within the operation which maps to the block argument denoted...

bool isOperandProduced(unsigned index) const

Returns true if the successor operand denoted by index is produced by the operation.

unsigned getProducedOperandCount() const

Returns the amount of operands that are produced internally by the operation.

bool empty() const

Returns true if there are no successor operands.

void append(ValueRange valueRange)

Add new operands that are forwarded to the successor.

unsigned size() const

Returns the amount of operands passed to the successor.

OperandRange getForwardedOperands() const

Get the range of operands that are simply forwarded to the successor.

This class provides an abstraction over the different types of ranges over Values.

This class represents an instance of an SSA value in the MLIR system, representing a computable value...

std::optional< BlockArgument > getBranchSuccessorArgument(const SuccessorOperands &operands, unsigned operandIndex, Block *successor)

Return the BlockArgument corresponding to operand operandIndex in some successor if operandIndex is w...

LogicalResult verifyRegionBranchWeights(Operation *op)

Verify that the region weights attached to an operation implementing WeightedRegiobBranchOpInterface ...

LogicalResult verifyBranchSuccessorOperands(Operation *op, unsigned succNo, const SuccessorOperands &operands)

Verify that the given operands match those of the given successor block.

LogicalResult verifyTypesAlongControlFlowEdges(Operation *op)

Verify that types match along control flow edges described the given op.

LogicalResult verifyBranchWeights(Operation *op)

Verify that the branch weights attached to an operation implementing WeightedBranchOpInterface are co...

Include the generated interface declarations.

bool insideMutuallyExclusiveRegions(Operation *a, Operation *b)

Return true if a and b are in mutually exclusive regions as per RegionBranchOpInterface.

Region * getEnclosingRepetitiveRegion(Operation *op)

Return the first enclosing region of the given op that may be executed repetitively as per RegionBran...

bool operator!=(RegionBranchPoint lhs, RegionBranchPoint rhs)

This trait indicates that a terminator operation is "return-like".

static LogicalResult verifyTrait(Operation *op)