clang 24.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"
19#include "llvm/ADT/BitmaskEnum.h"
20#include "llvm/IR/FPEnv.h"
21#include "llvm/Support/ErrorHandling.h"
22
23#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
24#include "mlir/IR/Builders.h"
25#include "mlir/IR/BuiltinAttributes.h"
26#include "mlir/IR/Location.h"
27#include "mlir/IR/OperationSupport.h"
28#include "mlir/IR/Types.h"
29
30namespace cir {
31
33
34/// No-wrap flags of a pointer offset computation: the subset of
35/// llvm::GEPNoWrapFlags that `cir.get_element` carries as its `in_bounds` and
36/// `no_unsigned_wrap` properties.
37enum class PtrOffsetFlags {
38 None = 0,
39 InBounds = 1 << 0,
41 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/NoUnsignedWrap)
42};
43
44class CIRBaseBuilderTy : public mlir::OpBuilder {
45
46public:
47 CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
48 : mlir::OpBuilder(&mlirContext) {}
49 CIRBaseBuilderTy(mlir::OpBuilder &builder) : mlir::OpBuilder(builder) {}
50
51 // mlir::Builder's float getters return builtin types, which CIR types don't
52 // accept as elements. Use CIR float types, such as cir::SingleType.
53 mlir::FloatType getBF16Type() = delete;
54 mlir::FloatType getF16Type() = delete;
55 mlir::FloatType getTF32Type() = delete;
56 mlir::FloatType getF32Type() = delete;
57 mlir::FloatType getF64Type() = delete;
58 mlir::FloatType getF80Type() = delete;
59 mlir::FloatType getF128Type() = delete;
60
61 bool isFPConstrained = false;
64 llvm::RoundingMode defaultConstrainedRounding =
65 llvm::RoundingMode::NearestTiesToEven;
66 cir::FastMathFlags fastMathFlags = cir::FastMathFlags::none;
67
68 mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
69 const llvm::APInt &val) {
70 return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(typ, val));
71 }
72
73 cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
74 return cir::ConstantOp::create(*this, loc, attr);
75 }
76
77 cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
78 int64_t value) {
79 return getConstant(loc, cir::IntAttr::get(ty, value));
80 }
81
82 mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits) {
83 auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/true);
84 return getConstAPInt(loc, type,
85 llvm::APInt(numBits, val, /*isSigned=*/true));
86 }
87
88 mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val,
89 unsigned numBits) {
90 auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/false);
91 return getConstAPInt(loc, type, llvm::APInt(numBits, val));
92 }
93
94 // Creates constant null value for integral type ty.
95 cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc) {
96 return getConstant(loc, getZeroInitAttr(ty));
97 }
98
99 mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) {
100 assert(mlir::isa<cir::PointerType>(t) && "expected cir.ptr");
101 return getConstPtrAttr(t, 0);
102 }
103
104 mlir::TypedAttr getNullDataMemberAttr(cir::DataMemberType ty) {
105 return cir::DataMemberAttr::get(ty);
106 }
107
108 mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
109 if (auto bitFieldTy = mlir::dyn_cast<cir::BitFieldType>(ty)) {
110 assert(bitFieldTy.ownsBytes() &&
111 "a zero-width bit-field takes no initializer");
112 return getZeroInitAttr(bitFieldTy.getStorageType());
113 }
114 if (mlir::isa<cir::IntType>(ty))
115 return cir::IntAttr::get(ty, 0);
116 if (cir::isAnyFloatingPointType(ty))
117 return cir::FPAttr::getZero(ty);
118 if (cir::isAnyOpaqueFloatingPointType(ty))
119 return cir::ZeroAttr::get(ty);
120 if (auto complexType = mlir::dyn_cast<cir::ComplexType>(ty))
121 return cir::ZeroAttr::get(complexType);
122 if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
123 return cir::ZeroAttr::get(arrTy);
124 if (auto vecTy = mlir::dyn_cast<cir::VectorType>(ty))
125 return cir::ZeroAttr::get(vecTy);
126 if (auto matrixTy = mlir::dyn_cast<cir::MatrixType>(ty))
127 return cir::ZeroAttr::get(matrixTy);
128 if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
129 return getConstNullPtrAttr(ptrTy);
130 if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
131 return cir::ZeroAttr::get(recordTy);
132 if (auto dataMemberTy = mlir::dyn_cast<cir::DataMemberType>(ty))
133 return getNullDataMemberAttr(dataMemberTy);
134 if (auto methodTy = mlir::dyn_cast<cir::MethodType>(ty))
135 return getNullMethodAttr(methodTy);
136 if (auto vptrTy = mlir::dyn_cast<cir::VPtrType>(ty))
137 return cir::ZeroAttr::get(vptrTy);
138 if (mlir::isa<cir::BoolType>(ty)) {
139 return getFalseAttr();
140 }
141
142 llvm_unreachable("Zero initializer for given type is NYI");
143 }
144
145 cir::ConstantOp getBool(bool state, mlir::Location loc) {
146 return cir::ConstantOp::create(*this, loc, getCIRBoolAttr(state));
147 }
148 cir::ConstantOp getFalse(mlir::Location loc) { return getBool(false, loc); }
149 cir::ConstantOp getTrue(mlir::Location loc) { return getBool(true, loc); }
150
151 cir::BoolType getBoolTy() { return cir::BoolType::get(getContext()); }
152 cir::VoidType getVoidTy() { return cir::VoidType::get(getContext()); }
153
154 cir::IntType getUIntNTy(int n) {
155 return cir::IntType::get(getContext(), n, false);
156 }
157
158 static unsigned getCIRIntOrFloatBitWidth(mlir::Type eltTy) {
159 if (auto intType = mlir::dyn_cast<cir::IntTypeInterface>(eltTy))
160 return intType.getWidth();
161 if (auto floatType = mlir::dyn_cast<cir::FPTypeInterface>(eltTy))
162 return floatType.getWidth();
163
164 llvm_unreachable("Unsupported type in getCIRIntOrFloatBitWidth");
165 }
166 cir::IntType getSIntNTy(int n) {
167 return cir::IntType::get(getContext(), n, true);
168 }
169
170 cir::PointerType getPointerTo(mlir::Type ty) {
171 return cir::PointerType::get(ty);
172 }
173
174 cir::PointerType getPointerTo(mlir::Type ty,
175 mlir::ptr::MemorySpaceAttrInterface as) {
176 return cir::PointerType::get(ty, as);
177 }
178
179 cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS) {
180 if (langAS == clang::LangAS::Default)
181 return getPointerTo(ty);
182
183 mlir::ptr::MemorySpaceAttrInterface addrSpaceAttr =
184 cir::toCIRAddressSpaceAttr(*getContext(), langAS);
185 return getPointerTo(ty, addrSpaceAttr);
186 }
187
189 return getPointerTo(cir::VoidType::get(getContext()), langAS);
190 }
191
192 cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as) {
193 return getPointerTo(cir::VoidType::get(getContext()), as);
194 }
195
196 cir::MethodAttr getMethodAttr(cir::MethodType ty, cir::FuncOp methodFuncOp) {
197 auto methodFuncSymbolRef = mlir::FlatSymbolRefAttr::get(methodFuncOp);
198 return cir::MethodAttr::get(ty, methodFuncSymbolRef);
199 }
200
201 cir::MethodAttr getNullMethodAttr(cir::MethodType ty) {
202 return cir::MethodAttr::get(ty);
203 }
204
205 cir::BoolAttr getCIRBoolAttr(bool state) {
206 return cir::BoolAttr::get(getContext(), state);
207 }
208
209 cir::BoolAttr getTrueAttr() { return getCIRBoolAttr(true); }
210 cir::BoolAttr getFalseAttr() { return getCIRBoolAttr(false); }
211
212 //
213 // Floating point specific helpers
214 // -------------------------------
215 //
216
217 /// Enable/Disable use of constrained floating point math. When enabled the
218 /// CreateF<op>() calls instead create constrained floating point intrinsic
219 /// calls. Fast math flags are unaffected by this setting.
220 void setIsFPConstrained(bool isCon) { isFPConstrained = isCon; }
221
222 /// Query for the use of constrained floating point math
223 bool getIsFPConstrained() const { return isFPConstrained; }
224
225 /// Set the exception handling to be used with constrained floating point
230
231 /// Get the exception handling used with constrained floating point
235
236 /// Set the rounding mode handling to be used with constrained floating point
237 void setDefaultConstrainedRounding(llvm::RoundingMode newRounding) {
238 defaultConstrainedRounding = newRounding;
239 }
240
241 /// Get the rounding mode handling used with constrained floating point
242 llvm::RoundingMode getDefaultConstrainedRounding() const {
244 }
245
246 /// Set the fast-math flags attached to floating-point operations.
247 void setFastMathFlags(cir::FastMathFlags flags) { fastMathFlags = flags; }
248
249 /// Get the fast-math flags attached to floating-point operations.
250 cir::FastMathFlags getFastMathFlags() const { return fastMathFlags; }
251
252 /// Returns a null attribute when no fast-math flags are set.
253 cir::FastMathFlagsAttr getFastMathFlagsAttr() {
254 if (fastMathFlags == cir::FastMathFlags::none)
255 return {};
256 return cir::FastMathFlagsAttr::get(getContext(), fastMathFlags);
257 }
258
259 /// Build the `#cir.fenv` attribute describing the constrained floating-point
260 /// environment currently in effect. This is attached to floating-point
261 /// operations that support it to capture the rounding and exception
262 /// behavior. Returns a null attribute when constrained floating-point is not
263 /// enabled, in which case no attribute should be attached.
264 cir::FenvAttr getConstrainedFPAttr() {
265 if (!isFPConstrained)
266 return {};
267
268 cir::FPDynamicRoundingMode roundingMode;
270 case llvm::RoundingMode::NearestTiesToEven:
271 roundingMode = cir::FPDynamicRoundingMode::ToNearest;
272 break;
273 case llvm::RoundingMode::TowardNegative:
274 roundingMode = cir::FPDynamicRoundingMode::Downward;
275 break;
276 case llvm::RoundingMode::TowardPositive:
277 roundingMode = cir::FPDynamicRoundingMode::Upward;
278 break;
279 case llvm::RoundingMode::TowardZero:
280 roundingMode = cir::FPDynamicRoundingMode::UpwardZero;
281 break;
282 case llvm::RoundingMode::NearestTiesToAway:
283 roundingMode = cir::FPDynamicRoundingMode::ToNearestAway;
284 break;
285 case llvm::RoundingMode::Dynamic:
286 roundingMode = cir::FPDynamicRoundingMode::Unknown;
287 break;
288 default:
289 llvm_unreachable("unexpected constrained rounding mode");
290 }
291
292 cir::FPExceptionMode exceptMode;
293 bool strictExcept;
294 switch (defaultConstrainedExcept) {
296 exceptMode = cir::FPExceptionMode::Masked;
297 strictExcept = false;
298 break;
300 exceptMode = cir::FPExceptionMode::Unknown;
301 strictExcept = false;
302 break;
304 exceptMode = cir::FPExceptionMode::Unknown;
305 strictExcept = true;
306 break;
307 default:
308 llvm_unreachable("unexpected constrained exception mode");
309 }
310
311 return cir::FenvAttr::get(getContext(), roundingMode, exceptMode,
312 mlir::BoolAttr::get(getContext(), strictExcept));
313 }
314
315 mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real,
316 mlir::Value imag) {
317 auto resultComplexTy = cir::ComplexType::get(real.getType());
318 return cir::ComplexCreateOp::create(*this, loc, resultComplexTy, real,
319 imag);
320 }
321
322 mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
323 auto resultType = operand.getType();
324 if (auto complexResultType = mlir::dyn_cast<cir::ComplexType>(resultType))
325 resultType = complexResultType.getElementType();
326 return cir::ComplexRealOp::create(*this, loc, resultType, operand);
327 }
328
329 mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {
330 auto resultType = operand.getType();
331 if (auto complexResultType = mlir::dyn_cast<cir::ComplexType>(resultType))
332 resultType = complexResultType.getElementType();
333 return cir::ComplexImagOp::create(*this, loc, resultType, operand);
334 }
335
336 mlir::Value createComplexAdd(mlir::Location loc, mlir::Value lhs,
337 mlir::Value rhs) {
338 auto complexTy = mlir::cast<cir::ComplexType>(lhs.getType());
339 if (cir::isAnyFloatingPointType(complexTy.getElementType())) {
340 cir::FenvAttr fenv = getConstrainedFPAttr();
341 return cir::ComplexFAddOp::create(*this, loc, lhs, rhs, fenv);
342 }
343 return cir::ComplexAddOp::create(*this, loc, lhs, rhs);
344 }
345
346 mlir::Value createComplexSub(mlir::Location loc, mlir::Value lhs,
347 mlir::Value rhs) {
348 auto complexTy = mlir::cast<cir::ComplexType>(lhs.getType());
349 if (cir::isAnyFloatingPointType(complexTy.getElementType())) {
350 cir::FenvAttr fenv = getConstrainedFPAttr();
351 return cir::ComplexFSubOp::create(*this, loc, lhs, rhs, fenv);
352 }
353 return cir::ComplexSubOp::create(*this, loc, lhs, rhs);
354 }
355
356 mlir::Value createComplexMul(mlir::Location loc, mlir::Value lhs,
357 mlir::Value rhs,
358 cir::ComplexRangeKind rangeKind) {
359 auto complexTy = mlir::cast<cir::ComplexType>(lhs.getType());
360 if (cir::isAnyFloatingPointType(complexTy.getElementType()))
361 return cir::ComplexFMulOp::create(*this, loc, lhs, rhs, rangeKind);
362 return cir::ComplexMulOp::create(*this, loc, lhs, rhs);
363 }
364
365 mlir::Value createComplexDiv(mlir::Location loc, mlir::Value lhs,
366 mlir::Value rhs,
367 cir::ComplexRangeKind rangeKind) {
368 auto complexTy = mlir::cast<cir::ComplexType>(lhs.getType());
369 if (cir::isAnyFloatingPointType(complexTy.getElementType()))
370 return cir::ComplexFDivOp::create(*this, loc, lhs, rhs, rangeKind);
371 return cir::ComplexDivOp::create(*this, loc, lhs, rhs);
372 }
373
374 mlir::Value createComplexConj(mlir::Location loc, mlir::Value operand) {
375 return cir::ComplexConjOp::create(*this, loc, operand.getType(), operand);
376 }
377
378 cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr,
379 bool isVolatile = false, uint64_t alignment = 0,
380 bool isNontemporal = false) {
381 mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment);
382 return cir::LoadOp::create(*this, loc, ptr, /*isDeref=*/false, isVolatile,
383 isNontemporal, alignmentAttr,
384 cir::SyncScopeKindAttr{}, cir::MemOrderAttr{},
385 /*invariant=*/false, /*tbaa=*/{});
386 }
387
388 mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr,
389 uint64_t alignment) {
390 return createLoad(loc, ptr, /*isVolatile=*/false, alignment);
391 }
392
393 mlir::Value createNot(mlir::Location loc, mlir::Value value) {
394 return cir::NotOp::create(*this, loc, value);
395 }
396
397 mlir::Value createNot(mlir::Value value) {
398 return createNot(value.getLoc(), value);
399 }
400
401 /// Create a do-while operation.
402 cir::DoWhileOp createDoWhile(
403 mlir::Location loc,
404 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
405 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
406 return cir::DoWhileOp::create(*this, loc, condBuilder, bodyBuilder);
407 }
408
409 /// Create a while operation.
410 cir::WhileOp createWhile(
411 mlir::Location loc,
412 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
413 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
414 return cir::WhileOp::create(*this, loc, condBuilder, bodyBuilder);
415 }
416
417 /// Create a while operation with a per-iteration cleanup region.
418 cir::WhileOp createWhile(
419 mlir::Location loc,
420 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
421 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
422 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>
423 cleanupBuilder,
424 cir::CleanupKind cleanupKind) {
425 return cir::WhileOp::create(*this, loc, condBuilder, bodyBuilder,
426 cleanupBuilder, cleanupKind);
427 }
428
429 /// Create a for operation.
430 cir::ForOp createFor(
431 mlir::Location loc,
432 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
433 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
434 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> stepBuilder) {
435 return cir::ForOp::create(*this, loc, condBuilder, bodyBuilder,
436 stepBuilder);
437 }
438
439 /// Create a for operation with a per-iteration cleanup region.
440 cir::ForOp createFor(
441 mlir::Location loc,
442 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
443 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
444 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> stepBuilder,
445 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>
446 cleanupBuilder,
447 cir::CleanupKind cleanupKind) {
448 return cir::ForOp::create(*this, loc, condBuilder, bodyBuilder, stepBuilder,
449 cleanupBuilder, cleanupKind);
450 }
451
452 /// Create a break operation.
453 cir::BreakOp createBreak(mlir::Location loc) {
454 return cir::BreakOp::create(*this, loc);
455 }
456
457 /// Create a continue operation.
458 cir::ContinueOp createContinue(mlir::Location loc) {
459 return cir::ContinueOp::create(*this, loc);
460 }
461
462 mlir::Value createInc(mlir::Location loc, mlir::Value input,
463 bool nsw = false) {
464 return cir::IncOp::create(*this, loc, input, nsw);
465 }
466
467 mlir::Value createDec(mlir::Location loc, mlir::Value input,
468 bool nsw = false) {
469 return cir::DecOp::create(*this, loc, input, nsw);
470 }
471
472 mlir::Value createMinus(mlir::Location loc, mlir::Value input,
473 bool nsw = false) {
474 return cir::MinusOp::create(*this, loc, input, nsw);
475 }
476
477 mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
478 return cir::ConstPtrAttr::get(type, getI64IntegerAttr(value));
479 }
480
481 mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
482 llvm::StringRef name, mlir::IntegerAttr alignment,
483 mlir::Value dynAllocSize) {
484 return cir::AllocaOp::create(*this, loc, addrType, name, alignment,
485 dynAllocSize);
486 }
487
488 mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
489 mlir::Type type, llvm::StringRef name,
490 clang::CharUnits alignment,
491 mlir::Value dynAllocSize) {
492 mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment);
493 return createAlloca(loc, addrType, name, alignmentAttr, dynAllocSize);
494 }
495
496 mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
497 llvm::StringRef name, mlir::IntegerAttr alignment) {
498 return cir::AllocaOp::create(*this, loc, addrType, name, alignment);
499 }
500
501 mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
502 llvm::StringRef name, clang::CharUnits alignment) {
503 mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment);
504 return createAlloca(loc, addrType, name, alignmentAttr);
505 }
506
507 /// Get constant address of a global variable as an MLIR attribute.
508 /// This wrapper infers the attribute type through the global op.
509 cir::GlobalViewAttr getGlobalViewAttr(cir::GlobalOp globalOp,
510 mlir::ArrayAttr indices = {}) {
511 cir::PointerType type = getPointerTo(globalOp.getSymType());
512 return getGlobalViewAttr(type, globalOp, indices);
513 }
514
515 /// Get constant address of a global variable as an MLIR attribute.
516 cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type,
517 cir::GlobalOp globalOp,
518 mlir::ArrayAttr indices = {},
519 bool addressPoint = false) {
520 auto symbol = mlir::FlatSymbolRefAttr::get(globalOp.getSymNameAttr());
521 return cir::GlobalViewAttr::get(type, symbol, indices, addressPoint);
522 }
523
524 /// Get constant address of a global variable as an MLIR attribute.
525 /// This overload converts raw int64_t indices to an ArrayAttr.
526 cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type,
527 cir::GlobalOp globalOp,
529 bool addressPoint = false) {
531 for (int64_t ind : indices)
532 attrs.push_back(getI64IntegerAttr(ind));
533 mlir::ArrayAttr arAttr = mlir::ArrayAttr::get(getContext(), attrs);
534 return getGlobalViewAttr(type, globalOp, arAttr, addressPoint);
535 }
536
537 cir::GetGlobalOp createGetGlobal(mlir::Location loc, cir::GlobalOp global,
538 bool threadLocal = false) {
539 return cir::GetGlobalOp::create(
540 *this, loc,
541 getPointerTo(global.getSymType(), global.getAddrSpaceAttr()),
542 global.getSymNameAttr(), threadLocal);
543 }
544
545 cir::GetGlobalOp createGetGlobal(cir::GlobalOp global,
546 bool threadLocal = false) {
547 return createGetGlobal(global.getLoc(), global, threadLocal);
548 }
549
550 /// Create a copy with inferred length.
551 cir::CopyOp createCopy(mlir::Value dst, mlir::Value src,
552 bool isVolatile = false,
553 bool skipTailPadding = false) {
554 return cir::CopyOp::create(*this, dst.getLoc(), dst, src,
555 /*dst_alignment=*/{}, /*src_alignment=*/{},
556 isVolatile, skipTailPadding);
557 }
558
559 cir::StoreOp createStore(mlir::Location loc, mlir::Value val, mlir::Value dst,
560 bool isVolatile = false, bool isNontemporal = false,
561 mlir::IntegerAttr align = {},
562 cir::SyncScopeKindAttr scope = {},
563 cir::MemOrderAttr order = {},
564 cir::TBAATagAttr tbaa = {}) {
565 if (mlir::cast<cir::PointerType>(dst.getType()).getPointee() !=
566 val.getType())
567 dst = createPtrBitcast(dst, val.getType());
568 return cir::StoreOp::create(*this, loc, val, dst, isVolatile, isNontemporal,
569 align, scope, order, tbaa);
570 }
571
572 /// Emit a load from an boolean flag variable.
573 cir::LoadOp createFlagLoad(mlir::Location loc, mlir::Value addr) {
574 mlir::Type boolTy = getBoolTy();
575 if (boolTy != mlir::cast<cir::PointerType>(addr.getType()).getPointee())
576 addr = createPtrBitcast(addr, boolTy);
577 return createLoad(loc, addr, /*isVolatile=*/false, /*alignment=*/1);
578 }
579
580 cir::StoreOp createFlagStore(mlir::Location loc, bool val, mlir::Value dst) {
581 mlir::Value flag = getBool(val, loc);
582 return CIRBaseBuilderTy::createStore(loc, flag, dst);
583 }
584
585 [[nodiscard]] cir::GlobalOp
586 createGlobal(mlir::ModuleOp mlirModule, mlir::Location loc,
587 mlir::StringRef name, mlir::Type type, bool isConstant,
588 cir::GlobalLinkageKind linkage,
589 mlir::ptr::MemorySpaceAttrInterface addrSpace) {
590 mlir::OpBuilder::InsertionGuard guard(*this);
591 setInsertionPointToStart(mlirModule.getBody());
592 return cir::GlobalOp::create(*this, loc, name, type, isConstant, addrSpace,
593 linkage);
594 }
595
596 cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy,
597 mlir::Value base, llvm::StringRef name,
598 unsigned index) {
599 return cir::GetMemberOp::create(*this, loc, resultTy, base, name, index);
600 }
601
602 mlir::Value createDummyValue(mlir::Location loc, mlir::Type type,
603 clang::CharUnits alignment) {
604 mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment);
605 auto addr = createAlloca(loc, getPointerTo(type), {}, alignmentAttr);
606 return cir::LoadOp::create(*this, loc, addr, /*isDeref=*/false,
607 /*isVolatile=*/false, /*nontemporal=*/false,
608 alignmentAttr,
609 /*sync_scope=*/{}, /*mem_order=*/{},
610 /*invariant=*/false, /*tbaa=*/{});
611 }
612
613 cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base,
614 mlir::Value stride) {
615 return cir::PtrStrideOp::create(*this, loc, base.getType(), base, stride);
616 }
617
618 //===--------------------------------------------------------------------===//
619 // Call operators
620 //===--------------------------------------------------------------------===//
621
622 cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
623 mlir::Type returnType, mlir::ValueRange operands,
627 cir::CallingConv callingConv = cir::CallingConv::C) {
628 auto op = cir::CallOp::create(*this, loc, callee, returnType, operands);
629 op->setAttrs(attrs);
630 if (callingConv != cir::CallingConv::C)
631 op.setCallingConv(callingConv);
632
633 if (!argAttrs.empty()) {
634 llvm::SmallVector<mlir::Attribute> argDictAttrs;
635 argDictAttrs.reserve(argAttrs.size());
636
637 llvm::transform(
638 argAttrs, std::back_inserter(argDictAttrs),
639 [this](llvm::ArrayRef<mlir::NamedAttribute> singleArgAttrs) {
640 return mlir::DictionaryAttr::get(getContext(), singleArgAttrs);
641 });
642
643 op.setArgAttrsAttr(mlir::ArrayAttr::get(getContext(), argDictAttrs));
644 }
645
646 if (!resAttrs.empty()) {
647 auto resultDictAttr = mlir::DictionaryAttr::get(getContext(), resAttrs);
648 op.setResAttrsAttr(mlir::ArrayAttr::get(getContext(), resultDictAttr));
649 }
650 return op;
651 }
652
653 cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee,
654 mlir::ValueRange operands,
658 cir::CallingConv callingConv = cir::CallingConv::C) {
659 return createCallOp(loc, mlir::SymbolRefAttr::get(callee),
660 callee.getFunctionType().getReturnType(), operands,
661 attrs, argAttrs, resAttrs, callingConv);
662 }
663
664 cir::CallOp
665 createIndirectCallOp(mlir::Location loc, mlir::Value indirectTarget,
666 cir::FuncType funcType, mlir::ValueRange operands,
670 cir::CallingConv callingConv = cir::CallingConv::C) {
671 llvm::SmallVector<mlir::Value> resOperands{indirectTarget};
672 resOperands.append(operands.begin(), operands.end());
673
674 return createCallOp(loc, mlir::SymbolRefAttr(), funcType.getReturnType(),
675 resOperands, attrs, argAttrs, resAttrs, callingConv);
676 }
677
678 cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
679 mlir::ValueRange operands = mlir::ValueRange(),
683 return createCallOp(loc, callee, cir::VoidType(), operands, attrs, argAttrs,
684 resAttrs);
685 }
686
687 //===--------------------------------------------------------------------===//
688 // Cast/Conversion Operators
689 //===--------------------------------------------------------------------===//
690
691 mlir::Value createCast(mlir::Location loc, cir::CastKind kind,
692 mlir::Value src, mlir::Type newTy) {
693 if (newTy == src.getType())
694 return src;
695 return cir::CastOp::create(*this, loc, newTy, kind, src);
696 }
697
698 mlir::Value createCast(cir::CastKind kind, mlir::Value src,
699 mlir::Type newTy) {
700 if (newTy == src.getType())
701 return src;
702 return createCast(src.getLoc(), kind, src, newTy);
703 }
704
705 // Creates a cast from bool or int to an integer type.
706 mlir::Value createBoolIntToIntCast(mlir::Value src, mlir::Type newTy) {
707 if (newTy == src.getType())
708 return src;
709 if (src.getType() == getBoolTy())
710 return createBoolToInt(src, newTy);
711 return createIntCast(src, newTy);
712 }
713
714 mlir::Value createIntCast(mlir::Value src, mlir::Type newTy) {
715 return createCast(cir::CastKind::integral, src, newTy);
716 }
717
718 mlir::Value createBuiltinIntCast(mlir::Location loc, mlir::Value src,
719 mlir::Type newTy) {
720 return cir::BuiltinIntCastOp::create(*this, loc, newTy, src);
721 }
722
723 mlir::Value createBuiltinIntCast(mlir::Value src, mlir::Type newTy) {
724 return createBuiltinIntCast(src.getLoc(), src, newTy);
725 }
726
727 /// Casts \p src to the builtin MLIR integer type with the same width as
728 /// its own CIR integer type.
729 mlir::Value createBuiltinIntCast(mlir::Location loc, mlir::Value src) {
730 auto cirIntTy = mlir::cast<cir::IntType>(src.getType());
731 return createBuiltinIntCast(loc, src, getIntegerType(cirIntTy.getWidth()));
732 }
733
734 mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy) {
735 return createCast(cir::CastKind::int_to_ptr, src, newTy);
736 }
737
738 mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {
739 return createCast(cir::CastKind::ptr_to_int, src, newTy);
740 }
741
742 mlir::Value createPtrToBoolCast(mlir::Value v) {
743 return createCast(cir::CastKind::ptr_to_bool, v, getBoolTy());
744 }
745
746 mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy) {
747 return createCast(cir::CastKind::bool_to_int, src, newTy);
748 }
749
750 mlir::Value createBitcast(mlir::Value src, mlir::Type newTy) {
751 return createCast(cir::CastKind::bitcast, src, newTy);
752 }
753
754 mlir::Value createBitcast(mlir::Location loc, mlir::Value src,
755 mlir::Type newTy) {
756 return createCast(loc, cir::CastKind::bitcast, src, newTy);
757 }
758
759 mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy) {
760 assert(mlir::isa<cir::PointerType>(src.getType()) && "expected ptr src");
761 cir::PointerType srcPtrTy = mlir::cast<cir::PointerType>(src.getType());
762 return createBitcast(src,
763 getPointerTo(newPointeeTy, srcPtrTy.getAddrSpace()));
764 }
765
766 mlir::Value createPtrIsNull(mlir::Value ptr) {
767 mlir::Value nullPtr = getNullPtr(ptr.getType(), ptr.getLoc());
768 return createCompare(ptr.getLoc(), cir::CmpOpKind::eq, ptr, nullPtr);
769 }
770
771 mlir::Value createPtrIsNotNull(mlir::Value ptr) {
772 mlir::Value nullPtr = getNullPtr(ptr.getType(), ptr.getLoc());
773 return createCompare(ptr.getLoc(), cir::CmpOpKind::ne, ptr, nullPtr);
774 }
775
776 mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src,
777 mlir::Type newTy) {
778 return createCast(loc, cir::CastKind::address_space, src, newTy);
779 }
780
781 mlir::Value createAddrSpaceCast(mlir::Value src, mlir::Type newTy) {
782 return createAddrSpaceCast(src.getLoc(), src, newTy);
783 }
784
785 //===--------------------------------------------------------------------===//
786 // Other Instructions
787 //===--------------------------------------------------------------------===//
788
789 mlir::Value createExtractElement(mlir::Location loc, mlir::Value vec,
790 cir::IntType idxTy, uint64_t idx) {
791 assert(idxTy.isFundamental() &&
792 "vector index must have a fundamental integer type");
793 mlir::Value idxVal =
794 getConstAPInt(loc, idxTy, llvm::APInt(idxTy.getWidth(), idx));
795 return cir::VecExtractOp::create(*this, loc, vec, idxVal);
796 }
797
798 mlir::Value createExtractElement(mlir::Location loc, mlir::Value vec,
799 mlir::Value idx) {
800 return cir::VecExtractOp::create(*this, loc, vec, idx);
801 }
802
803 mlir::Value createInsertElement(mlir::Location loc, mlir::Value vec,
804 mlir::Value newElt, cir::IntType idxTy,
805 uint64_t idx) {
806 assert(idxTy.isFundamental() &&
807 "vector index must have a fundamental integer type");
808 mlir::Value idxVal =
809 getConstAPInt(loc, idxTy, llvm::APInt(idxTy.getWidth(), idx));
810 return cir::VecInsertOp::create(*this, loc, vec, newElt, idxVal);
811 }
812
813 mlir::Value createInsertElement(mlir::Location loc, mlir::Value vec,
814 mlir::Value newElt, mlir::Value idx) {
815 return cir::VecInsertOp::create(*this, loc, vec, newElt, idx);
816 }
817
818 cir::SignBitOp createSignBit(mlir::Location loc, mlir::Value val) {
819 auto resTy = cir::BoolType::get(getContext());
820 return cir::SignBitOp::create(*this, loc, resTy, val);
821 }
822
823 //===--------------------------------------------------------------------===//
824 // Binary Operators
825 //===--------------------------------------------------------------------===//
826
827 mlir::Value createLowBitsSet(mlir::Location loc, unsigned size,
828 unsigned bits) {
829 llvm::APInt val = llvm::APInt::getLowBitsSet(size, bits);
830 auto type = cir::IntType::get(getContext(), size, /*isSigned=*/false);
831 return getConstAPInt(loc, type, val);
832 }
833
834 mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
835 return cir::AndOp::create(*this, loc, lhs, rhs);
836 }
837
838 mlir::Value createOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
839 return cir::OrOp::create(*this, loc, lhs, rhs);
840 }
841
842 mlir::Value createSelect(mlir::Location loc, mlir::Value condition,
843 mlir::Value trueValue, mlir::Value falseValue) {
844 assert(trueValue.getType() == falseValue.getType() &&
845 "trueValue and falseValue should have the same type");
846 return cir::SelectOp::create(*this, loc, trueValue.getType(), condition,
847 trueValue, falseValue);
848 }
849
850 mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs,
851 mlir::Value rhs) {
852 return createSelect(loc, lhs, rhs, getBool(false, loc));
853 }
854
855 mlir::Value createLogicalOr(mlir::Location loc, mlir::Value lhs,
856 mlir::Value rhs) {
857 return createSelect(loc, lhs, getBool(true, loc), rhs);
858 }
859
860 mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
861 OverflowFlags flags = OverflowFlags::None) {
862 return cir::MulOp::create(*this, loc, lhs, rhs, flags);
863 }
864 mlir::Value createNSWMul(mlir::Location loc, mlir::Value lhs,
865 mlir::Value rhs) {
866 return createMul(loc, lhs, rhs, OverflowFlags::NoSignedWrap);
867 }
868 mlir::Value createNUWAMul(mlir::Location loc, mlir::Value lhs,
869 mlir::Value rhs) {
870 return createMul(loc, lhs, rhs, OverflowFlags::NoUnsignedWrap);
871 }
872
873 mlir::Value createAddSat(mlir::Location loc, mlir::Value lhs,
874 mlir::Value rhs) {
875 return cir::AddSatOp::create(*this, loc, lhs, rhs);
876 }
877
878 mlir::Value createSubSat(mlir::Location loc, mlir::Value lhs,
879 mlir::Value rhs) {
880 return cir::SubSatOp::create(*this, loc, lhs, rhs);
881 }
882
883 mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
884 OverflowFlags flags = OverflowFlags::None) {
885 return cir::SubOp::create(*this, loc, lhs, rhs, flags);
886 }
887
888 mlir::Value createNSWSub(mlir::Location loc, mlir::Value lhs,
889 mlir::Value rhs) {
890 return createSub(loc, lhs, rhs, OverflowFlags::NoSignedWrap);
891 }
892
893 mlir::Value createNUWSub(mlir::Location loc, mlir::Value lhs,
894 mlir::Value rhs) {
895 return createSub(loc, lhs, rhs, OverflowFlags::NoUnsignedWrap);
896 }
897
898 mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
899 OverflowFlags flags = OverflowFlags::None) {
900 return cir::AddOp::create(*this, loc, lhs, rhs, flags);
901 }
902
903 mlir::Value createNSWAdd(mlir::Location loc, mlir::Value lhs,
904 mlir::Value rhs) {
905 return createAdd(loc, lhs, rhs, OverflowFlags::NoSignedWrap);
906 }
907
908 mlir::Value createNUWAdd(mlir::Location loc, mlir::Value lhs,
909 mlir::Value rhs) {
910 return createAdd(loc, lhs, rhs, OverflowFlags::NoUnsignedWrap);
911 }
912
913 mlir::Value createDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
914 return cir::DivOp::create(*this, loc, lhs, rhs);
915 }
916
917 mlir::Value createRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
918 return cir::RemOp::create(*this, loc, lhs, rhs);
919 }
920
921 template <typename OpTy>
922 mlir::Value createFPBinOp(mlir::Location loc, mlir::Value lhs,
923 mlir::Value rhs) {
925 return OpTy::create(*this, loc, lhs, rhs, getConstrainedFPAttr(),
927 }
928
929 mlir::Value createFAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
930 return createFPBinOp<cir::FAddOp>(loc, lhs, rhs);
931 }
932
933 mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
934 return createFPBinOp<cir::FSubOp>(loc, lhs, rhs);
935 }
936
937 mlir::Value createFMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
938 return createFPBinOp<cir::FMulOp>(loc, lhs, rhs);
939 }
940
941 mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
942 return createFPBinOp<cir::FDivOp>(loc, lhs, rhs);
943 }
944
945 mlir::Value createFRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
946 return createFPBinOp<cir::FRemOp>(loc, lhs, rhs);
947 }
948
949 mlir::Value createFNeg(mlir::Location loc, mlir::Value operand) {
950 assert(cir::isFPOrVectorOfFPType(operand.getType()) &&
951 "expected floating-point or vector-of-float type");
953 // fneg does not raise FP exceptions or depend on the rounding mode, so it
954 // never carries an fenv attribute.
955 return cir::FNegOp::create(*this, loc, operand, getFastMathFlagsAttr());
956 }
957
958 mlir::Value createXor(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
959 return cir::XorOp::create(*this, loc, lhs, rhs);
960 }
961
962 mlir::Value createMax(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
963 return cir::MaxOp::create(*this, loc, lhs, rhs);
964 }
965
966 mlir::Value createMin(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
967 return cir::MinOp::create(*this, loc, lhs, rhs);
968 }
969
970 cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind,
971 mlir::Value lhs, mlir::Value rhs) {
972 cir::FenvAttr fenv;
973 if (cir::isAnyFloatingPointType(lhs.getType()))
974 fenv = getConstrainedFPAttr();
975 return cir::CmpOp::create(*this, loc, kind, lhs, rhs, fenv);
976 }
977
978 cir::FCmpOp createFCompare(mlir::Location loc, cir::FCmpOpKind kind,
979 mlir::Value lhs, mlir::Value rhs,
980 bool signaling = false) {
981 cir::FenvAttr fenv;
982 fenv = getConstrainedFPAttr();
983 return cir::FCmpOp::create(*this, loc, kind, lhs, rhs, signaling, fenv);
984 }
985
986 /// Compares \p lhs and \p rhs element-wise. Each result element is a
987 /// signed integer of the operand element's bit width.
988 cir::VecCmpOp createVecCompare(mlir::Location loc, cir::CmpOpKind kind,
989 mlir::Value lhs, mlir::Value rhs) {
990 VectorType vecCast = mlir::cast<VectorType>(lhs.getType());
991 mlir::Type elemTy = vecCast.getElementType();
992 IntType integralTy = getSIntNTy(getCIRIntOrFloatBitWidth(elemTy));
993 return createVecCompare(
994 loc,
995 cir::VectorType::get(integralTy, vecCast.getSize(), vecCast.getKind()),
996 kind, lhs, rhs);
997 }
998
999 /// Compares \p lhs and \p rhs element-wise, producing \p resultTy, which
1000 /// must be a vector of integers or bools with as many elements as \p lhs.
1001 /// The result element width can then differ from the operand element's
1002 /// bit width.
1003 cir::VecCmpOp createVecCompare(mlir::Location loc, VectorType resultTy,
1004 cir::CmpOpKind kind, mlir::Value lhs,
1005 mlir::Value rhs) {
1006 assert(mlir::cast<VectorType>(lhs.getType()).getSize() ==
1007 resultTy.getSize() &&
1008 cir::isIntOrBoolType(resultTy.getElementType()) &&
1009 "vector compare result must be an int or bool vector of the "
1010 "operand length");
1011 return cir::VecCmpOp::create(*this, loc, resultTy, kind, lhs, rhs);
1012 }
1013
1014 /// Compares \p lhs and \p rhs element-wise. Each result element is a
1015 /// signed integer of the operand element's bit width. That is not the
1016 /// result an FP80 element needs, so an FP80 compare names its result type
1017 /// with the overload below.
1018 cir::VecFCmpOp createVecFCompare(mlir::Location loc, cir::FCmpOpKind kind,
1019 mlir::Value lhs, mlir::Value rhs,
1020 bool signaling = false) {
1021 VectorType vecCast = mlir::cast<VectorType>(lhs.getType());
1022 mlir::Type elemTy = vecCast.getElementType();
1023 assert(!(mlir::isa<cir::FPTypeInterface>(elemTy) &&
1024 &mlir::cast<cir::FPTypeInterface>(elemTy).getFloatSemantics() ==
1025 &llvm::APFloat::x87DoubleExtended()) &&
1026 "an FP80 vector compare must name its result type");
1027 IntType integralTy = getSIntNTy(getCIRIntOrFloatBitWidth(elemTy));
1028 auto resTy =
1029 cir::VectorType::get(integralTy, vecCast.getSize(), vecCast.getKind());
1030 return cir::VecFCmpOp::create(*this, loc, resTy, kind, lhs, rhs, signaling,
1032 }
1033
1034 /// Compares \p lhs and \p rhs element-wise, producing \p resultTy, which
1035 /// must be a vector of integers or bools with as many elements as \p lhs.
1036 /// The result element width can then differ from the operand element's
1037 /// bit width, as for FP80, whose result elements are 128 bits.
1038 cir::VecFCmpOp createVecFCompare(mlir::Location loc, VectorType resultTy,
1039 cir::FCmpOpKind kind, mlir::Value lhs,
1040 mlir::Value rhs, bool signaling = false) {
1041 assert(mlir::cast<VectorType>(lhs.getType()).getSize() ==
1042 resultTy.getSize() &&
1043 cir::isIntOrBoolType(resultTy.getElementType()) &&
1044 "vector compare result must be an int or bool vector of the "
1045 "operand length");
1046 return cir::VecFCmpOp::create(*this, loc, resultTy, kind, lhs, rhs,
1047 signaling, getConstrainedFPAttr());
1048 }
1049
1050 mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand) {
1051 return createFCompare(loc, cir::FCmpOpKind::uno, operand, operand);
1052 }
1053
1054 mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
1055 bool isShiftLeft) {
1056 return cir::ShiftOp::create(*this, loc, lhs.getType(), lhs, rhs,
1057 isShiftLeft);
1058 }
1059
1060 mlir::Value createShift(mlir::Location loc, mlir::Value lhs,
1061 const llvm::APInt &rhs, bool isShiftLeft) {
1062 return createShift(loc, lhs, getConstAPInt(loc, lhs.getType(), rhs),
1063 isShiftLeft);
1064 }
1065
1066 mlir::Value createShift(mlir::Location loc, mlir::Value lhs, unsigned bits,
1067 bool isShiftLeft) {
1068 auto width = mlir::dyn_cast<cir::IntType>(lhs.getType()).getWidth();
1069 auto shift = llvm::APInt(width, bits);
1070 return createShift(loc, lhs, shift, isShiftLeft);
1071 }
1072
1073 mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs,
1074 unsigned bits) {
1075 return createShift(loc, lhs, bits, true);
1076 }
1077
1078 mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs,
1079 unsigned bits) {
1080 return createShift(loc, lhs, bits, false);
1081 }
1082
1083 mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs,
1084 mlir::Value rhs) {
1085 return createShift(loc, lhs, rhs, true);
1086 }
1087
1088 mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs,
1089 mlir::Value rhs) {
1090 return createShift(loc, lhs, rhs, false);
1091 }
1092
1093 /// Returns `void (T...)` as a cir::FuncType.
1094 cir::FuncType getVoidFnTy(mlir::TypeRange argTypes = {}) {
1095 return cir::FuncType::get(llvm::to_vector(argTypes), getVoidTy());
1096 }
1097
1098 /// Returns `void (*)(T...)` as a cir::PointerType.
1099 cir::PointerType getVoidFnPtrTy(mlir::TypeRange argTypes = {}) {
1100 return getPointerTo(getVoidFnTy(argTypes));
1101 }
1102
1103 //
1104 // Block handling helpers
1105 // ----------------------
1106 //
1107 static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block) {
1108 auto last =
1109 std::find_if(block->rbegin(), block->rend(), [](mlir::Operation &op) {
1110 return mlir::isa<cir::AllocaOp, cir::LabelOp>(&op);
1111 });
1112
1113 if (last != block->rend())
1114 return OpBuilder::InsertPoint(block, ++mlir::Block::iterator(&*last));
1115 return OpBuilder::InsertPoint(block, block->begin());
1116 };
1117
1118 //
1119 // Alignment and size helpers
1120 //
1121
1122 // Note that mlir::IntegerType is used instead of cir::IntType here because we
1123 // don't need sign information for these to be useful, so keep it simple.
1124
1125 // For 0 alignment, any overload of `getAlignmentAttr` returns an empty
1126 // attribute.
1127 mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment) {
1128 return getAlignmentAttr(alignment.getQuantity());
1129 }
1130
1131 mlir::IntegerAttr getAlignmentAttr(llvm::Align alignment) {
1132 return getAlignmentAttr(alignment.value());
1133 }
1134
1135 mlir::IntegerAttr getAlignmentAttr(int64_t alignment) {
1136 return alignment ? getI64IntegerAttr(alignment) : mlir::IntegerAttr();
1137 }
1138
1139 // Materialize an alignment value as a CIR integer constant of the given
1140 // integer type.
1141 cir::ConstantOp getAlignment(mlir::Location loc, mlir::Type t,
1142 clang::CharUnits alignment) {
1143 return getConstantInt(loc, t, alignment.getQuantity());
1144 }
1145
1146 mlir::IntegerAttr getSizeFromCharUnits(clang::CharUnits size) {
1147 return getI64IntegerAttr(size.getQuantity());
1148 }
1149
1150 // Creates constant nullptr for pointer type ty.
1151 cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
1153 return cir::ConstantOp::create(*this, loc, getConstPtrAttr(ty, 0));
1154 }
1155
1156 /// Create a loop condition.
1157 cir::ConditionOp createCondition(mlir::Value condition) {
1158 return cir::ConditionOp::create(*this, condition.getLoc(), condition);
1159 }
1160
1161 /// Create a yield operation.
1162 cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value = {}) {
1163 return cir::YieldOp::create(*this, loc, value);
1164 }
1165
1167 mlir::Value callee;
1168 mlir::Value adjustedThis;
1169 };
1170
1171 GetMethodResults createGetMethod(mlir::Location loc, mlir::Value method,
1172 mlir::Value objectPtr) {
1173 // Build the callee function type.
1174 auto methodFuncTy =
1175 mlir::cast<cir::MethodType>(method.getType()).getMemberFuncTy();
1176 auto methodFuncInputTypes = methodFuncTy.getInputs();
1177
1178 auto objectPtrTy = mlir::cast<cir::PointerType>(objectPtr.getType());
1179 mlir::Type adjustedThisTy = getVoidPtrTy(objectPtrTy.getAddrSpace());
1180
1181 llvm::SmallVector<mlir::Type> calleeFuncInputTypes{adjustedThisTy};
1182 // The member function type's first parameter is the implicit 'this'
1183 // pointer. The callee takes an adjusted void* receiver instead.
1184 if (methodFuncInputTypes.size() > 1)
1185 calleeFuncInputTypes.insert(calleeFuncInputTypes.end(),
1186 methodFuncInputTypes.begin() + 1,
1187 methodFuncInputTypes.end());
1188 cir::FuncType calleeFuncTy =
1189 methodFuncTy.clone(calleeFuncInputTypes, methodFuncTy.getReturnType());
1190 // TODO(cir): consider the address space of the callee.
1192 cir::PointerType calleeTy = getPointerTo(calleeFuncTy);
1193
1194 auto op = cir::GetMethodOp::create(*this, loc, calleeTy, adjustedThisTy,
1195 method, objectPtr,
1196 /*tbaa=*/cir::TBAATagAttr());
1197 return {op.getCallee(), op.getAdjustedThis()};
1198 }
1199};
1200
1201} // namespace cir
1202
1203#endif
Provides definitions for the various language-specific address spaces.
Defines the clang::LangOptions interface.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a an optional score condition
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
mlir::FloatType getTF32Type()=delete
cir::VecFCmpOp createVecFCompare(mlir::Location loc, VectorType resultTy, cir::FCmpOpKind kind, mlir::Value lhs, mlir::Value rhs, bool signaling=false)
Compares lhs and rhs element-wise, producing resultTy, which must be a vector of integers or bools wi...
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::StoreOp createFlagStore(mlir::Location loc, bool val, mlir::Value dst)
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.
mlir::Value createDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowFlags flags=OverflowFlags::None)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, llvm::StringRef name, mlir::IntegerAttr alignment)
mlir::Value createComplexMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, cir::ComplexRangeKind rangeKind)
cir::VecCmpOp createVecCompare(mlir::Location loc, VectorType resultTy, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
Compares lhs and rhs element-wise, producing resultTy, which must be a vector of integers or bools wi...
cir::BreakOp createBreak(mlir::Location loc)
Create a break operation.
mlir::TypedAttr getConstNullPtrAttr(mlir::Type t)
cir::FenvAttr getConstrainedFPAttr()
Build the #cir.fenv attribute describing the constrained floating-point environment currently in effe...
cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as)
mlir::IntegerAttr getAlignmentAttr(int64_t alignment)
mlir::Value createDec(mlir::Location loc, mlir::Value input, bool nsw=false)
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)
mlir::Value createBuiltinIntCast(mlir::Value src, mlir::Type newTy)
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)
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowFlags flags=OverflowFlags::None)
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
clang::LangOptions::FPExceptionModeKind getDefaultConstrainedExcept() const
Get the exception handling used with constrained floating point.
mlir::Value createLowBitsSet(mlir::Location loc, unsigned size, unsigned bits)
mlir::Value createInc(mlir::Location loc, mlir::Value input, bool nsw=false)
cir::CopyOp createCopy(mlir::Value dst, mlir::Value src, bool isVolatile=false, bool skipTailPadding=false)
Create a copy with inferred length.
mlir::Value createNSWAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::GlobalViewAttr getGlobalViewAttr(cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
cir::FCmpOp createFCompare(mlir::Location loc, cir::FCmpOpKind kind, mlir::Value lhs, mlir::Value rhs, bool signaling=false)
cir::MethodAttr getMethodAttr(cir::MethodType ty, cir::FuncOp methodFuncOp)
cir::FastMathFlags getFastMathFlags() const
Get the fast-math flags attached to floating-point operations.
cir::VoidType getVoidTy()
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)
cir::MethodAttr getNullMethodAttr(cir::MethodType ty)
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::FloatType getF80Type()=delete
mlir::Value createPtrIsNull(mlir::Value ptr)
mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createBuiltinIntCast(mlir::Location loc, mlir::Value src)
Casts src to the builtin MLIR integer type with the same width as its own CIR integer type.
mlir::Value createFPBinOp(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::SignBitOp createSignBit(mlir::Location loc, mlir::Value val)
mlir::Value createInsertElement(mlir::Location loc, mlir::Value vec, mlir::Value newElt, cir::IntType idxTy, uint64_t idx)
mlir::Value createCast(mlir::Location loc, cir::CastKind kind, mlir::Value src, mlir::Type newTy)
mlir::IntegerAttr getSizeFromCharUnits(clang::CharUnits size)
cir::PointerType getVoidFnPtrTy(mlir::TypeRange argTypes={})
Returns void (*)(T...) as a cir::PointerType.
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, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> cleanupBuilder, cir::CleanupKind cleanupKind)
Create a for operation with a per-iteration cleanup region.
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy)
mlir::Value createRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
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.
cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type, cir::GlobalOp globalOp, mlir::ArrayAttr indices={}, bool addressPoint=false)
Get constant address of a global variable as an MLIR attribute.
mlir::FloatType getF64Type()=delete
static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block)
mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy)
mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createNUWSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getFalse(mlir::Location loc)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::ValueRange operands=mlir::ValueRange(), llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={})
cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy, mlir::Value base, llvm::StringRef name, unsigned index)
cir::PointerType getPointerTo(mlir::Type ty)
cir::VecFCmpOp createVecFCompare(mlir::Location loc, cir::FCmpOpKind kind, mlir::Value lhs, mlir::Value rhs, bool signaling=false)
Compares lhs and rhs element-wise.
mlir::Value createFNeg(mlir::Location loc, mlir::Value operand)
mlir::Value createComplexSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, llvm::StringRef name, clang::CharUnits alignment)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, mlir::Value dst, bool isVolatile=false, bool isNontemporal=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={}, cir::TBAATagAttr tbaa={})
mlir::Value createNot(mlir::Value value)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::Type returnType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={}, cir::CallingConv callingConv=cir::CallingConv::C)
mlir::Value createAddSat(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowFlags flags=OverflowFlags::None)
mlir::Value createFAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createExtractElement(mlir::Location loc, mlir::Value vec, cir::IntType idxTy, uint64_t idx)
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)
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={}, cir::CallingConv callingConv=cir::CallingConv::C)
cir::GetGlobalOp createGetGlobal(cir::GlobalOp global, bool threadLocal=false)
cir::IntType getUIntNTy(int n)
mlir::Value createComplexDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, cir::ComplexRangeKind rangeKind)
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)
mlir::Value createInsertElement(mlir::Location loc, mlir::Value vec, mlir::Value newElt, mlir::Value idx)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
cir::GetGlobalOp createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)
mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs, unsigned bits)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, llvm::StringRef name, mlir::IntegerAttr alignment, mlir::Value dynAllocSize)
cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr, bool isVolatile=false, uint64_t alignment=0, bool isNontemporal=false)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, clang::CharUnits alignment, mlir::Value dynAllocSize)
mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits)
cir::WhileOp createWhile(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)> cleanupBuilder, cir::CleanupKind cleanupKind)
Create a while operation with a per-iteration cleanup region.
mlir::Value createMax(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::FloatType getF16Type()=delete
cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS)
cir::VecCmpOp createVecCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
Compares lhs and rhs element-wise.
mlir::Value createIntCast(mlir::Value src, mlir::Type newTy)
cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type, cir::GlobalOp globalOp, llvm::ArrayRef< int64_t > indices, bool addressPoint=false)
Get constant address of a global variable as an MLIR attribute.
llvm::RoundingMode defaultConstrainedRounding
cir::FastMathFlagsAttr getFastMathFlagsAttr()
Returns a null attribute when no fast-math flags are set.
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
mlir::Value createFMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
mlir::Value createBitcast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
cir::FuncType getVoidFnTy(mlir::TypeRange argTypes={})
Returns void (T...) as a cir::FuncType.
mlir::Value createSubSat(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::TypedAttr getNullDataMemberAttr(cir::DataMemberType ty)
mlir::Value createBuiltinIntCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
clang::LangOptions::FPExceptionModeKind defaultConstrainedExcept
cir::CallOp createIndirectCallOp(mlir::Location loc, mlir::Value indirectTarget, cir::FuncType funcType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={}, cir::CallingConv callingConv=cir::CallingConv::C)
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment)
mlir::Value createNot(mlir::Location loc, mlir::Value value)
mlir::Value createExtractElement(mlir::Location loc, mlir::Value vec, mlir::Value idx)
void setIsFPConstrained(bool isCon)
Enable/Disable use of constrained floating point math.
mlir::Value createMin(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
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.
llvm::RoundingMode getDefaultConstrainedRounding() const
Get the rounding mode handling used with constrained floating point.
cir::PointerType getPointerTo(mlir::Type ty, mlir::ptr::MemorySpaceAttrInterface as)
mlir::FloatType getF32Type()=delete
mlir::TypedAttr getZeroInitAttr(mlir::Type ty)
mlir::Value createMinus(mlir::Location loc, mlir::Value input, bool nsw=false)
CIRBaseBuilderTy(mlir::OpBuilder &builder)
mlir::Value createPtrIsNotNull(mlir::Value ptr)
static unsigned getCIRIntOrFloatBitWidth(mlir::Type eltTy)
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 createBoolIntToIntCast(mlir::Value src, mlir::Type newTy)
mlir::Value createAddrSpaceCast(mlir::Value src, mlir::Type newTy)
mlir::Value createComplexConj(mlir::Location loc, mlir::Value operand)
mlir::Value createPtrToBoolCast(mlir::Value v)
cir::BoolAttr getTrueAttr()
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
mlir::Value createFRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs, unsigned bits)
mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand)
cir::IntType getSIntNTy(int n)
void setDefaultConstrainedExcept(clang::LangOptions::FPExceptionModeKind newExcept)
Set the exception handling to be used with constrained floating point.
mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr, uint64_t alignment)
bool getIsFPConstrained() const
Query for the use of constrained floating point math.
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value)
mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
cir::FastMathFlags fastMathFlags
mlir::Value createDummyValue(mlir::Location loc, mlir::Type type, clang::CharUnits alignment)
cir::BoolAttr getFalseAttr()
void setDefaultConstrainedRounding(llvm::RoundingMode newRounding)
Set the rounding mode handling to be used with constrained floating point.
mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::FloatType getBF16Type()=delete
mlir::Value createXor(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::FloatType getF128Type()=delete
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
cir::ConstantOp getAlignment(mlir::Location loc, mlir::Type t, clang::CharUnits alignment)
mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::GlobalOp createGlobal(mlir::ModuleOp mlirModule, mlir::Location loc, mlir::StringRef name, mlir::Type type, bool isConstant, cir::GlobalLinkageKind linkage, mlir::ptr::MemorySpaceAttrInterface addrSpace)
void setFastMathFlags(cir::FastMathFlags flags)
Set the fast-math flags attached to floating-point operations.
mlir::IntegerAttr getAlignmentAttr(llvm::Align alignment)
mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::LoadOp createFlagLoad(mlir::Location loc, mlir::Value addr)
Emit a load from an boolean flag variable.
cir::BoolType getBoolTy()
mlir::Value createComplexAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val, unsigned numBits)
GetMethodResults createGetMethod(mlir::Location loc, mlir::Value method, mlir::Value objectPtr)
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand)
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Definition CharUnits.h:155
FPExceptionModeKind
Possible floating point exception behavior.
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
PtrOffsetFlags
No-wrap flags of a pointer offset computation: the subset of llvm::GEPNoWrapFlags that cir....
LangAS
Defines the address space values used by the address space qualifier of QualType.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t int64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
static bool metaDataNode()
static bool addressSpace()
static bool targetCodeGenInfoGetNullPointer()