clang 22.0.0git
CIRBaseBuilder.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
10#define LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
11
12#include "clang/AST/CharUnits.h"
17#include "llvm/ADT/STLForwardCompat.h"
18#include "llvm/Support/ErrorHandling.h"
19
20#include "mlir/IR/Builders.h"
21#include "mlir/IR/BuiltinAttributes.h"
22#include "mlir/IR/Location.h"
23#include "mlir/IR/Types.h"
24
25namespace cir {
26
27enum class OverflowBehavior {
28 None = 0,
29 NoSignedWrap = 1 << 0,
30 NoUnsignedWrap = 1 << 1,
31 Saturated = 1 << 2,
32};
33
35 return static_cast<OverflowBehavior>(llvm::to_underlying(a) |
36 llvm::to_underlying(b));
37}
38
40 return static_cast<OverflowBehavior>(llvm::to_underlying(a) &
41 llvm::to_underlying(b));
42}
43
46 a = a | b;
47 return a;
48}
49
52 a = a & b;
53 return a;
54}
55
56class CIRBaseBuilderTy : public mlir::OpBuilder {
57
58public:
59 CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
60 : mlir::OpBuilder(&mlirContext) {}
61 CIRBaseBuilderTy(mlir::OpBuilder &builder) : mlir::OpBuilder(builder) {}
62
63 mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
64 const llvm::APInt &val) {
65 return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(typ, val));
66 }
67
68 cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
69 return cir::ConstantOp::create(*this, loc, attr);
70 }
71
72 cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
73 int64_t value) {
74 return getConstant(loc, cir::IntAttr::get(ty, value));
75 }
76
77 mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits) {
78 auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/true);
79 return getConstAPInt(loc, type,
80 llvm::APInt(numBits, val, /*isSigned=*/true));
81 }
82
83 mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val,
84 unsigned numBits) {
85 auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/false);
86 return getConstAPInt(loc, type, llvm::APInt(numBits, val));
87 }
88
89 // Creates constant null value for integral type ty.
90 cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc) {
91 return getConstant(loc, getZeroInitAttr(ty));
92 }
93
94 mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) {
95 assert(mlir::isa<cir::PointerType>(t) && "expected cir.ptr");
96 return getConstPtrAttr(t, 0);
97 }
98
99 mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
100 if (mlir::isa<cir::IntType>(ty))
101 return cir::IntAttr::get(ty, 0);
102 if (cir::isAnyFloatingPointType(ty))
103 return cir::FPAttr::getZero(ty);
104 if (auto complexType = mlir::dyn_cast<cir::ComplexType>(ty))
105 return cir::ZeroAttr::get(complexType);
106 if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
107 return cir::ZeroAttr::get(arrTy);
108 if (auto vecTy = mlir::dyn_cast<cir::VectorType>(ty))
109 return cir::ZeroAttr::get(vecTy);
110 if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
111 return getConstNullPtrAttr(ptrTy);
112 if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
113 return cir::ZeroAttr::get(recordTy);
114 if (mlir::isa<cir::BoolType>(ty)) {
115 return getFalseAttr();
116 }
117 llvm_unreachable("Zero initializer for given type is NYI");
118 }
119
120 cir::ConstantOp getBool(bool state, mlir::Location loc) {
121 return cir::ConstantOp::create(*this, loc, getCIRBoolAttr(state));
122 }
123 cir::ConstantOp getFalse(mlir::Location loc) { return getBool(false, loc); }
124 cir::ConstantOp getTrue(mlir::Location loc) { return getBool(true, loc); }
125
126 cir::BoolType getBoolTy() { return cir::BoolType::get(getContext()); }
127
128 cir::PointerType getPointerTo(mlir::Type ty) {
129 return cir::PointerType::get(ty);
130 }
131
132 cir::PointerType getVoidPtrTy() {
133 return getPointerTo(cir::VoidType::get(getContext()));
134 }
135
136 cir::BoolAttr getCIRBoolAttr(bool state) {
137 return cir::BoolAttr::get(getContext(), state);
138 }
139
140 cir::BoolAttr getTrueAttr() { return getCIRBoolAttr(true); }
141 cir::BoolAttr getFalseAttr() { return getCIRBoolAttr(false); }
142
143 mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real,
144 mlir::Value imag) {
145 auto resultComplexTy = cir::ComplexType::get(real.getType());
146 return cir::ComplexCreateOp::create(*this, loc, resultComplexTy, real,
147 imag);
148 }
149
150 mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
151 auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
152 return cir::ComplexRealOp::create(*this, loc, operandTy.getElementType(),
153 operand);
154 }
155
156 mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {
157 auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
158 return cir::ComplexImagOp::create(*this, loc, operandTy.getElementType(),
159 operand);
160 }
161
162 cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr,
163 bool isVolatile = false, uint64_t alignment = 0) {
164 mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment);
165 return cir::LoadOp::create(*this, loc, ptr, /*isDeref=*/false, isVolatile,
166 alignmentAttr, cir::MemOrderAttr{});
167 }
168
169 mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr,
170 uint64_t alignment) {
171 return createLoad(loc, ptr, /*isVolatile=*/false, alignment);
172 }
173
174 mlir::Value createNot(mlir::Value value) {
175 return cir::UnaryOp::create(*this, value.getLoc(), value.getType(),
176 cir::UnaryOpKind::Not, value);
177 }
178
179 /// Create a do-while operation.
180 cir::DoWhileOp createDoWhile(
181 mlir::Location loc,
182 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
183 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
184 return cir::DoWhileOp::create(*this, loc, condBuilder, bodyBuilder);
185 }
186
187 /// Create a while operation.
188 cir::WhileOp createWhile(
189 mlir::Location loc,
190 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
191 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
192 return cir::WhileOp::create(*this, loc, condBuilder, bodyBuilder);
193 }
194
195 /// Create a for operation.
196 cir::ForOp createFor(
197 mlir::Location loc,
198 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
199 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
200 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> stepBuilder) {
201 return cir::ForOp::create(*this, loc, condBuilder, bodyBuilder,
202 stepBuilder);
203 }
204
205 /// Create a break operation.
206 cir::BreakOp createBreak(mlir::Location loc) {
207 return cir::BreakOp::create(*this, loc);
208 }
209
210 /// Create a continue operation.
211 cir::ContinueOp createContinue(mlir::Location loc) {
212 return cir::ContinueOp::create(*this, loc);
213 }
214
215 mlir::Value createUnaryOp(mlir::Location loc, cir::UnaryOpKind kind,
216 mlir::Value operand) {
217 return cir::UnaryOp::create(*this, loc, kind, operand);
218 }
219
220 mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
221 return cir::ConstPtrAttr::get(type, getI64IntegerAttr(value));
222 }
223
224 mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
225 mlir::Type type, llvm::StringRef name,
226 mlir::IntegerAttr alignment) {
227 return cir::AllocaOp::create(*this, loc, addrType, type, name, alignment);
228 }
229
230 /// Get constant address of a global variable as an MLIR attribute.
231 cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type,
232 cir::GlobalOp globalOp,
233 mlir::ArrayAttr indices = {}) {
234 auto symbol = mlir::FlatSymbolRefAttr::get(globalOp.getSymNameAttr());
235 return cir::GlobalViewAttr::get(type, symbol, indices);
236 }
237
238 mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global) {
240 return cir::GetGlobalOp::create(
241 *this, loc, getPointerTo(global.getSymType()), global.getSymName());
242 }
243
244 mlir::Value createGetGlobal(cir::GlobalOp global) {
245 return createGetGlobal(global.getLoc(), global);
246 }
247
248 cir::StoreOp createStore(mlir::Location loc, mlir::Value val, mlir::Value dst,
249 bool isVolatile = false,
250 mlir::IntegerAttr align = {},
251 cir::MemOrderAttr order = {}) {
252 return cir::StoreOp::create(*this, loc, val, dst, isVolatile, align, order);
253 }
254
255 [[nodiscard]] cir::GlobalOp createGlobal(mlir::ModuleOp mlirModule,
256 mlir::Location loc,
257 mlir::StringRef name,
258 mlir::Type type, bool isConstant,
259 cir::GlobalLinkageKind linkage) {
260 mlir::OpBuilder::InsertionGuard guard(*this);
261 setInsertionPointToStart(mlirModule.getBody());
262 return cir::GlobalOp::create(*this, loc, name, type, isConstant, linkage);
263 }
264
265 cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy,
266 mlir::Value base, llvm::StringRef name,
267 unsigned index) {
268 return cir::GetMemberOp::create(*this, loc, resultTy, base, name, index);
269 }
270
271 mlir::Value createDummyValue(mlir::Location loc, mlir::Type type,
272 clang::CharUnits alignment) {
273 mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment);
274 auto addr = createAlloca(loc, getPointerTo(type), type, {}, alignmentAttr);
275 return cir::LoadOp::create(*this, loc, addr, /*isDeref=*/false,
276 /*isVolatile=*/false, alignmentAttr,
277 /*mem_order=*/{});
278 }
279
280 cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base,
281 mlir::Value stride) {
282 return cir::PtrStrideOp::create(*this, loc, base.getType(), base, stride);
283 }
284
285 //===--------------------------------------------------------------------===//
286 // Call operators
287 //===--------------------------------------------------------------------===//
288
289 cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
290 mlir::Type returnType, mlir::ValueRange operands,
292 auto op = cir::CallOp::create(*this, loc, callee, returnType, operands);
293 op->setAttrs(attrs);
294 return op;
295 }
296
297 cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee,
298 mlir::ValueRange operands,
300 return createCallOp(loc, mlir::SymbolRefAttr::get(callee),
301 callee.getFunctionType().getReturnType(), operands,
302 attrs);
303 }
304
305 cir::CallOp
306 createIndirectCallOp(mlir::Location loc, mlir::Value indirectTarget,
307 cir::FuncType funcType, mlir::ValueRange operands,
309 llvm::SmallVector<mlir::Value> resOperands{indirectTarget};
310 resOperands.append(operands.begin(), operands.end());
311 return createCallOp(loc, mlir::SymbolRefAttr(), funcType.getReturnType(),
312 resOperands, attrs);
313 }
314
315 cir::CallOp createTryCallOp(
316 mlir::Location loc, mlir::SymbolRefAttr callee = mlir::SymbolRefAttr(),
317 mlir::Type returnType = cir::VoidType(),
318 mlir::ValueRange operands = mlir::ValueRange(),
319 [[maybe_unused]] cir::SideEffect sideEffect = cir::SideEffect::All) {
322 return createCallOp(loc, callee, returnType, operands);
323 }
324
325 cir::CallOp createTryCallOp(
326 mlir::Location loc, cir::FuncOp callee, mlir::ValueRange operands,
327 [[maybe_unused]] cir::SideEffect sideEffect = cir::SideEffect::All) {
330 return createTryCallOp(loc, mlir::SymbolRefAttr::get(callee),
331 callee.getFunctionType().getReturnType(), operands);
332 }
333
334 //===--------------------------------------------------------------------===//
335 // Cast/Conversion Operators
336 //===--------------------------------------------------------------------===//
337
338 mlir::Value createCast(mlir::Location loc, cir::CastKind kind,
339 mlir::Value src, mlir::Type newTy) {
340 if (newTy == src.getType())
341 return src;
342 return cir::CastOp::create(*this, loc, newTy, kind, src);
343 }
344
345 mlir::Value createCast(cir::CastKind kind, mlir::Value src,
346 mlir::Type newTy) {
347 if (newTy == src.getType())
348 return src;
349 return createCast(src.getLoc(), kind, src, newTy);
350 }
351
352 mlir::Value createIntCast(mlir::Value src, mlir::Type newTy) {
353 return createCast(cir::CastKind::integral, src, newTy);
354 }
355
356 mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy) {
357 return createCast(cir::CastKind::int_to_ptr, src, newTy);
358 }
359
360 mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {
361 return createCast(cir::CastKind::ptr_to_int, src, newTy);
362 }
363
364 mlir::Value createPtrToBoolCast(mlir::Value v) {
365 return createCast(cir::CastKind::ptr_to_bool, v, getBoolTy());
366 }
367
368 mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy) {
369 return createCast(cir::CastKind::bool_to_int, src, newTy);
370 }
371
372 mlir::Value createBitcast(mlir::Value src, mlir::Type newTy) {
373 return createCast(cir::CastKind::bitcast, src, newTy);
374 }
375
376 mlir::Value createBitcast(mlir::Location loc, mlir::Value src,
377 mlir::Type newTy) {
378 return createCast(loc, cir::CastKind::bitcast, src, newTy);
379 }
380
381 mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy) {
382 assert(mlir::isa<cir::PointerType>(src.getType()) && "expected ptr src");
383 return createBitcast(src, getPointerTo(newPointeeTy));
384 }
385
386 //===--------------------------------------------------------------------===//
387 // Binary Operators
388 //===--------------------------------------------------------------------===//
389
390 mlir::Value createBinop(mlir::Location loc, mlir::Value lhs,
391 cir::BinOpKind kind, mlir::Value rhs) {
392 return cir::BinOp::create(*this, loc, lhs.getType(), kind, lhs, rhs);
393 }
394
395 mlir::Value createLowBitsSet(mlir::Location loc, unsigned size,
396 unsigned bits) {
397 llvm::APInt val = llvm::APInt::getLowBitsSet(size, bits);
398 auto type = cir::IntType::get(getContext(), size, /*isSigned=*/false);
399 return getConstAPInt(loc, type, val);
400 }
401
402 mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
403 return createBinop(loc, lhs, cir::BinOpKind::And, rhs);
404 }
405
406 mlir::Value createOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
407 return createBinop(loc, lhs, cir::BinOpKind::Or, rhs);
408 }
409
410 mlir::Value createSelect(mlir::Location loc, mlir::Value condition,
411 mlir::Value trueValue, mlir::Value falseValue) {
412 assert(trueValue.getType() == falseValue.getType() &&
413 "trueValue and falseValue should have the same type");
414 return cir::SelectOp::create(*this, loc, trueValue.getType(), condition,
415 trueValue, falseValue);
416 }
417
418 mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs,
419 mlir::Value rhs) {
420 return createSelect(loc, lhs, rhs, getBool(false, loc));
421 }
422
423 mlir::Value createLogicalOr(mlir::Location loc, mlir::Value lhs,
424 mlir::Value rhs) {
425 return createSelect(loc, lhs, getBool(true, loc), rhs);
426 }
427
428 mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
430 auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Mul,
431 lhs, rhs);
432 op.setNoUnsignedWrap(
433 llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
434 op.setNoSignedWrap(
435 llvm::to_underlying(ob & OverflowBehavior::NoSignedWrap));
436 return op;
437 }
438 mlir::Value createNSWMul(mlir::Location loc, mlir::Value lhs,
439 mlir::Value rhs) {
440 return createMul(loc, lhs, rhs, OverflowBehavior::NoSignedWrap);
441 }
442 mlir::Value createNUWAMul(mlir::Location loc, mlir::Value lhs,
443 mlir::Value rhs) {
444 return createMul(loc, lhs, rhs, OverflowBehavior::NoUnsignedWrap);
445 }
446
447 mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
449 auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Sub,
450 lhs, rhs);
451 op.setNoUnsignedWrap(
452 llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
453 op.setNoSignedWrap(
454 llvm::to_underlying(ob & OverflowBehavior::NoSignedWrap));
455 op.setSaturated(llvm::to_underlying(ob & OverflowBehavior::Saturated));
456 return op;
457 }
458
459 mlir::Value createNSWSub(mlir::Location loc, mlir::Value lhs,
460 mlir::Value rhs) {
461 return createSub(loc, lhs, rhs, OverflowBehavior::NoSignedWrap);
462 }
463
464 mlir::Value createNUWSub(mlir::Location loc, mlir::Value lhs,
465 mlir::Value rhs) {
466 return createSub(loc, lhs, rhs, OverflowBehavior::NoUnsignedWrap);
467 }
468
469 mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
471 auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Add,
472 lhs, rhs);
473 op.setNoUnsignedWrap(
474 llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
475 op.setNoSignedWrap(
476 llvm::to_underlying(ob & OverflowBehavior::NoSignedWrap));
477 op.setSaturated(llvm::to_underlying(ob & OverflowBehavior::Saturated));
478 return op;
479 }
480
481 mlir::Value createNSWAdd(mlir::Location loc, mlir::Value lhs,
482 mlir::Value rhs) {
483 return createAdd(loc, lhs, rhs, OverflowBehavior::NoSignedWrap);
484 }
485
486 mlir::Value createNUWAdd(mlir::Location loc, mlir::Value lhs,
487 mlir::Value rhs) {
488 return createAdd(loc, lhs, rhs, OverflowBehavior::NoUnsignedWrap);
489 }
490
491 cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind,
492 mlir::Value lhs, mlir::Value rhs) {
493 return cir::CmpOp::create(*this, loc, getBoolTy(), kind, lhs, rhs);
494 }
495
496 mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand) {
497 return createCompare(loc, cir::CmpOpKind::ne, operand, operand);
498 }
499
500 mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
501 bool isShiftLeft) {
502 return cir::ShiftOp::create(*this, loc, lhs.getType(), lhs, rhs,
503 isShiftLeft);
504 }
505
506 mlir::Value createShift(mlir::Location loc, mlir::Value lhs,
507 const llvm::APInt &rhs, bool isShiftLeft) {
508 return createShift(loc, lhs, getConstAPInt(loc, lhs.getType(), rhs),
509 isShiftLeft);
510 }
511
512 mlir::Value createShift(mlir::Location loc, mlir::Value lhs, unsigned bits,
513 bool isShiftLeft) {
514 auto width = mlir::dyn_cast<cir::IntType>(lhs.getType()).getWidth();
515 auto shift = llvm::APInt(width, bits);
516 return createShift(loc, lhs, shift, isShiftLeft);
517 }
518
519 mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs,
520 unsigned bits) {
521 return createShift(loc, lhs, bits, true);
522 }
523
524 mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs,
525 unsigned bits) {
526 return createShift(loc, lhs, bits, false);
527 }
528
529 mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs,
530 mlir::Value rhs) {
531 return createShift(loc, lhs, rhs, true);
532 }
533
534 mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs,
535 mlir::Value rhs) {
536 return createShift(loc, lhs, rhs, false);
537 }
538
539 //
540 // Block handling helpers
541 // ----------------------
542 //
543 static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block) {
544 auto last =
545 std::find_if(block->rbegin(), block->rend(), [](mlir::Operation &op) {
546 return mlir::isa<cir::AllocaOp, cir::LabelOp>(&op);
547 });
548
549 if (last != block->rend())
550 return OpBuilder::InsertPoint(block, ++mlir::Block::iterator(&*last));
551 return OpBuilder::InsertPoint(block, block->begin());
552 };
553
554 //
555 // Alignment and size helpers
556 //
557
558 // Note that mlir::IntegerType is used instead of cir::IntType here because we
559 // don't need sign information for these to be useful, so keep it simple.
560
561 // For 0 alignment, any overload of `getAlignmentAttr` returns an empty
562 // attribute.
563 mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment) {
564 return getAlignmentAttr(alignment.getQuantity());
565 }
566
567 mlir::IntegerAttr getAlignmentAttr(llvm::Align alignment) {
568 return getAlignmentAttr(alignment.value());
569 }
570
571 mlir::IntegerAttr getAlignmentAttr(int64_t alignment) {
572 return alignment ? getI64IntegerAttr(alignment) : mlir::IntegerAttr();
573 }
574
575 mlir::IntegerAttr getSizeFromCharUnits(clang::CharUnits size) {
576 return getI64IntegerAttr(size.getQuantity());
577 }
578
579 /// Create a loop condition.
580 cir::ConditionOp createCondition(mlir::Value condition) {
581 return cir::ConditionOp::create(*this, condition.getLoc(), condition);
582 }
583
584 /// Create a yield operation.
585 cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value = {}) {
586 return cir::YieldOp::create(*this, loc, value);
587 }
588};
589
590} // namespace cir
591
592#endif
__device__ __2f16 b
mlir::Value createNSWSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getBool(bool state, mlir::Location loc)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, unsigned bits, bool isShiftLeft)
cir::WhileOp createWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a while operation.
cir::BreakOp createBreak(mlir::Location loc)
Create a break operation.
mlir::TypedAttr getConstNullPtrAttr(mlir::Type t)
mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global)
mlir::IntegerAttr getAlignmentAttr(int64_t alignment)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, const llvm::APInt &rhs, bool isShiftLeft)
mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ, const llvm::APInt &val)
cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type, cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
mlir::Value createCast(cir::CastKind kind, mlir::Value src, mlir::Type newTy)
mlir::Value createLogicalOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, bool isShiftLeft)
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
mlir::Value createLowBitsSet(mlir::Location loc, unsigned size, unsigned bits)
mlir::Value createNSWAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc)
cir::BoolAttr getCIRBoolAttr(bool state)
mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy)
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
mlir::Value createNUWAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createCast(mlir::Location loc, cir::CastKind kind, mlir::Value src, mlir::Type newTy)
mlir::IntegerAttr getSizeFromCharUnits(clang::CharUnits size)
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy)
cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={})
cir::ForOp createFor(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> stepBuilder)
Create a for operation.
static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block)
mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy)
mlir::Value createNUWSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getFalse(mlir::Location loc)
mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy, mlir::Value base, llvm::StringRef name, unsigned index)
cir::PointerType getPointerTo(mlir::Type ty)
mlir::Value createNot(mlir::Value value)
mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand)
cir::ConstantOp getTrue(mlir::Location loc)
mlir::Value createNSWMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createGetGlobal(cir::GlobalOp global)
cir::DoWhileOp createDoWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a do-while operation.
mlir::Value createNUWAMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::Type returnType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={})
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
cir::CallOp createTryCallOp(mlir::Location loc, mlir::SymbolRefAttr callee=mlir::SymbolRefAttr(), mlir::Type returnType=cir::VoidType(), mlir::ValueRange operands=mlir::ValueRange(), cir::SideEffect sideEffect=cir::SideEffect::All)
mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs, unsigned bits)
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::Saturated)
mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits)
mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createIntCast(mlir::Value src, mlir::Type newTy)
cir::CallOp createTryCallOp(mlir::Location loc, cir::FuncOp callee, mlir::ValueRange operands, cir::SideEffect sideEffect=cir::SideEffect::All)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
mlir::Value createBitcast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
cir::GlobalOp createGlobal(mlir::ModuleOp mlirModule, mlir::Location loc, mlir::StringRef name, mlir::Type type, bool isConstant, cir::GlobalLinkageKind linkage)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, mlir::Value dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::MemOrderAttr order={})
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment)
mlir::Value createBinop(mlir::Location loc, mlir::Value lhs, cir::BinOpKind kind, mlir::Value rhs)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, mlir::IntegerAttr alignment)
mlir::Value createSelect(mlir::Location loc, mlir::Value condition, mlir::Value trueValue, mlir::Value falseValue)
cir::ContinueOp createContinue(mlir::Location loc)
Create a continue operation.
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
mlir::TypedAttr getZeroInitAttr(mlir::Type ty)
cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr, bool isVolatile=false, uint64_t alignment=0)
cir::CallOp createIndirectCallOp(mlir::Location loc, mlir::Value indirectTarget, cir::FuncType funcType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={})
CIRBaseBuilderTy(mlir::OpBuilder &builder)
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, mlir::Value imag)
mlir::Value createPtrToBoolCast(mlir::Value v)
cir::BoolAttr getTrueAttr()
mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs, unsigned bits)
mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand)
mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr, uint64_t alignment)
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value)
mlir::Value createDummyValue(mlir::Location loc, mlir::Type type, clang::CharUnits alignment)
cir::BoolAttr getFalseAttr()
cir::PointerType getVoidPtrTy()
mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createUnaryOp(mlir::Location loc, cir::UnaryOpKind kind, mlir::Value operand)
mlir::IntegerAttr getAlignmentAttr(llvm::Align alignment)
cir::BoolType getBoolTy()
mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val, unsigned numBits)
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand)
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
Definition: ABIArgInfo.h:22
constexpr OverflowBehavior operator|(OverflowBehavior a, OverflowBehavior b)
constexpr OverflowBehavior operator&(OverflowBehavior a, OverflowBehavior b)
constexpr OverflowBehavior & operator|=(OverflowBehavior &a, OverflowBehavior b)
constexpr OverflowBehavior & operator&=(OverflowBehavior &a, OverflowBehavior b)
OverflowBehavior
static bool addressSpace()
static bool opCallSideEffect()
static bool opCallCallConv()