clang 24.0.0git
CIRGenBuilder.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_LIB_CIR_CODEGEN_CIRGENBUILDER_H
10#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENBUILDER_H
11
12#include "Address.h"
13#include "CIRGenRecordLayout.h"
14#include "CIRGenTypeCache.h"
15#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
16#include "mlir/IR/Attributes.h"
17#include "mlir/IR/Builders.h"
18#include "mlir/IR/BuiltinAttributes.h"
19#include "mlir/Support/LLVM.h"
22
25#include "llvm/ADT/APFloat.h"
26#include "llvm/ADT/STLExtras.h"
27#include "llvm/IR/FPEnv.h"
28
29namespace clang::CIRGen {
30
32 const CIRGenTypeCache &typeCache;
33
34 llvm::StringMap<unsigned> recordNames;
35 llvm::StringMap<unsigned> globalsVersioning;
36
37public:
38 CIRGenBuilderTy(mlir::MLIRContext &mlirContext, const CIRGenTypeCache &tc)
39 : CIRBaseBuilderTy(mlirContext), typeCache(tc) {}
40
41 /// Get a cir::ConstArrayAttr for a string literal.
42 /// Note: This is different from what is returned by
43 /// mlir::Builder::getStringAttr() which is an mlir::StringAttr.
44 mlir::Attribute getString(llvm::StringRef str, mlir::Type eltTy,
45 std::optional<size_t> size,
46 bool ensureNullTerm = true) {
47 size_t finalSize = size.value_or(str.size());
48
49 size_t lastNonZeroPos = str.find_last_not_of('\0');
50 // If the string is full of null bytes, emit a #cir.zero rather than
51 // a #cir.const_array.
52 if (lastNonZeroPos == llvm::StringRef::npos) {
53 auto arrayTy = cir::ArrayType::get(eltTy, finalSize);
54 return cir::ZeroAttr::get(arrayTy);
55 }
56
57 // We emit trailing zeros for all trailing zeros, so the null-terminator in
58 // a constant is always in trailing zeros, and the null-terminator is
59 // skipped in the CIR representation.
60 size_t trailingZerosNum = finalSize - lastNonZeroPos - 1;
61 auto truncatedArrayTy =
62 cir::ArrayType::get(eltTy, finalSize - trailingZerosNum);
63 auto strAttr = mlir::StringAttr::get(str.drop_back(trailingZerosNum),
64 truncatedArrayTy);
65
66 // Most C strings are null terminated, so if we are ensuring there is one,
67 // grow the array size by 1 to add a trailing zero if necessary. The 'auto'
68 // calculation of trailing zeros (the difference between the provided string
69 // and the type) will ensure we get the count correct.
70 finalSize += (ensureNullTerm && trailingZerosNum == 0);
71
72 auto fullArrayTy = cir::ArrayType::get(eltTy, finalSize);
73 return cir::ConstArrayAttr::get(fullArrayTy, strAttr);
74 }
75
76 cir::ConstArrayAttr getConstArray(mlir::Attribute attrs,
77 cir::ArrayType arrayTy) const {
78 return cir::ConstArrayAttr::get(arrayTy, attrs);
79 }
80
81 mlir::Attribute getConstRecordOrZeroAttr(mlir::ArrayAttr arrayAttr,
82 cir::RecordType recordTy);
83
84 cir::ConstRecordAttr getAnonConstRecord(mlir::ArrayAttr arrayAttr) {
86 for (auto &f : arrayAttr) {
87 auto ta = mlir::cast<mlir::TypedAttr>(f);
88 members.push_back(ta.getType());
89 }
90
91 auto sTy = getAnonRecordTy(members, /*packed=*/false,
93 return cir::ConstRecordAttr::get(sTy, arrayAttr);
94 }
95
96 cir::TypeInfoAttr getTypeInfo(mlir::ArrayAttr fieldsAttr) {
97 cir::ConstRecordAttr anonRecord = getAnonConstRecord(fieldsAttr);
98 return cir::TypeInfoAttr::get(anonRecord.getType(), fieldsAttr);
99 }
100
101 std::string getUniqueAnonRecordName() { return getUniqueRecordName("anon"); }
102
103 std::string getUniqueRecordName(const std::string &baseName) {
104 auto it = recordNames.find(baseName);
105 if (it == recordNames.end()) {
106 recordNames[baseName] = 0;
107 return baseName;
108 }
109
110 return baseName + "." + std::to_string(recordNames[baseName]++);
111 }
112
113 cir::LongDoubleType getLongDoubleTy(const llvm::fltSemantics &format) const {
114 if (&format == &llvm::APFloat::IEEEdouble())
115 return cir::LongDoubleType::get(getContext(), typeCache.doubleTy);
116 if (&format == &llvm::APFloat::x87DoubleExtended())
117 return cir::LongDoubleType::get(getContext(), typeCache.fP80Ty);
118 if (&format == &llvm::APFloat::IEEEquad())
119 return cir::LongDoubleType::get(getContext(), typeCache.fP128Ty);
120 if (&format == &llvm::APFloat::PPCDoubleDouble())
121 llvm_unreachable("NYI: PPC double-double format for long double");
122 llvm_unreachable("Unsupported format for long double");
123 }
124
125 mlir::Type getPtrToVPtrType() {
126 return getPointerTo(cir::VPtrType::get(getContext()));
127 }
128
129 cir::FuncType getFuncType(llvm::ArrayRef<mlir::Type> params, mlir::Type retTy,
130 bool isVarArg = false) {
131 return cir::FuncType::get(params, retTy, isVarArg);
132 }
133
134 /// Get a CIR record kind from a AST declaration tag.
135 /// Returns true if the tag kind represents a C++ class (as opposed to a
136 /// plain struct).
139 }
140
141 /// Returns true if the tag kind is a union.
144 }
145
146 /// Get a CIR named record type.
147 ///
148 /// If a record already exists and is complete, but the client tries to fetch
149 /// it with a different set of attributes, this method will crash.
151 llvm::ArrayRef<mlir::Type> members, bool packed, llvm::StringRef name,
153 const auto nameAttr = getStringAttr(name);
155
156 // Always a struct at this call site, never a class or a union.
157 auto type = cir::StructType::get(getContext(), members, nameAttr, packed,
158 /*is_class=*/false, memberKinds);
159
160 // If we found an existing type, verify that either it is incomplete or
161 // it matches the requested attributes.
162 assert(!type.isIncomplete() ||
163 (type.getMembers() == members && type.getPacked() == packed));
164
165 // Complete an incomplete record or ensure the existing complete record
166 // matches the requested attributes.
167 type.complete(members, packed, memberKinds);
168
169 return type;
170 }
171
172 /// Get an incomplete CIR record type. If we have a complete record
173 /// declaration, we may create an incomplete type and then add the
174 /// members, so \p rd here may be complete.
176 const clang::RecordDecl *rd) {
177 const mlir::StringAttr nameAttr = getStringAttr(name);
178 if (rd && tagKindIsUnion(rd->getTagKind()))
179 return cir::UnionType::get(getContext(), nameAttr);
180 bool is_class = rd && tagKindIsClass(rd->getTagKind());
181 return cir::StructType::get(getContext(), nameAttr, is_class);
182 }
183
184 //
185 // Operation creation helpers
186 // --------------------------
187 //
189 cir::CopyOp createCopy(Address dst, Address src, bool isVolatile = false,
190 bool skipTailPadding = false) {
191 cir::CopyOp op = createCopy(dst.getPointer(), src.getPointer(), isVolatile,
192 skipTailPadding);
193 op.setDstAlignment(dst.getAlignment().getQuantity());
194 op.setSrcAlignment(src.getAlignment().getQuantity());
195 return op;
196 }
197
198 cir::MemCpyOp createMemCpy(mlir::Location loc, Address dst, Address src,
199 mlir::Value len) {
200 return cir::MemCpyOp::create(
201 *this, loc, dst.getPointer(), src.getPointer(), len,
202 getI64IntegerAttr(dst.getAlignment().getQuantity()),
203 getI64IntegerAttr(src.getAlignment().getQuantity()));
204 }
205
206 cir::MemMoveOp createMemMove(mlir::Location loc, Address dst, Address src,
207 mlir::Value len) {
208 return cir::MemMoveOp::create(
209 *this, loc, dst.getPointer(), src.getPointer(), len,
210 getI64IntegerAttr(dst.getAlignment().getQuantity()),
211 getI64IntegerAttr(src.getAlignment().getQuantity()));
212 }
213
214 cir::MemSetOp createMemSet(mlir::Location loc, mlir::Value dst,
215 mlir::Value val, mlir::Value len) {
216 assert(val.getType() == getUInt8Ty());
217 return cir::MemSetOp::create(*this, loc, dst, {}, val, len);
218 }
219
220 cir::MemSetOp createMemSet(mlir::Location loc, Address dst, mlir::Value val,
221 mlir::Value len) {
222 mlir::IntegerAttr align = getAlignmentAttr(dst.getAlignment());
223 assert(val.getType() == getUInt8Ty());
224 return cir::MemSetOp::create(*this, loc, dst.getPointer(), align, val, len);
225 }
226 // ---------------------------
227
228 cir::DataMemberAttr getDataMemberAttr(cir::DataMemberType ty,
230 return cir::DataMemberAttr::get(ty, path);
231 }
232
233 cir::DataMemberAttr getNullDataMemberAttr(cir::DataMemberType ty) {
234 return cir::DataMemberAttr::get(ty);
235 }
236
237 // Return true if the value is a null constant such as null pointer, (+0.0)
238 // for floating-point or zero initializer
239 bool isNullValue(mlir::Attribute attr) const {
240 if (mlir::isa<cir::ZeroAttr>(attr))
241 return true;
242
243 if (const auto ptrVal = mlir::dyn_cast<cir::ConstPtrAttr>(attr))
244 return ptrVal.isNullValue();
245
246 if (const auto intVal = mlir::dyn_cast<cir::IntAttr>(attr))
247 return intVal.isNullValue();
248
249 if (const auto boolVal = mlir::dyn_cast<cir::BoolAttr>(attr))
250 return !boolVal.getValue();
251
252 if (auto fpAttr = mlir::dyn_cast<cir::FPAttr>(attr)) {
253 auto fpVal = fpAttr.getValue();
254 bool ignored;
255 llvm::APFloat fv(+0.0);
256 fv.convert(fpVal.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
257 &ignored);
258 return fv.bitwiseIsEqual(fpVal);
259 }
260 if (const auto recordVal = mlir::dyn_cast<cir::ConstRecordAttr>(attr)) {
261 for (const auto elt : recordVal.getMembers()) {
262 // FIXME(cir): the record's ID should not be considered a member.
263 if (mlir::isa<mlir::StringAttr>(elt))
264 continue;
265 if (!isNullValue(elt))
266 return false;
267 }
268 return true;
269 }
270
271 if (const auto arrayVal = mlir::dyn_cast<cir::ConstArrayAttr>(attr)) {
272 if (mlir::isa<mlir::StringAttr>(arrayVal.getElts()))
273 return false;
274
275 return llvm::all_of(
276 mlir::cast<mlir::ArrayAttr>(arrayVal.getElts()),
277 [&](const mlir::Attribute &elt) { return isNullValue(elt); });
278 }
279 return false;
280 }
281
282 //
283 // Type helpers
284 // ------------
285 //
286 cir::IntType getUIntNTy(int n) {
287 switch (n) {
288 case 8:
289 return getUInt8Ty();
290 case 16:
291 return getUInt16Ty();
292 case 32:
293 return getUInt32Ty();
294 case 64:
295 return getUInt64Ty();
296 default:
297 return cir::IntType::get(getContext(), n, false);
298 }
299 }
300
301 cir::IntType getSIntNTy(int n) {
302 switch (n) {
303 case 8:
304 return getSInt8Ty();
305 case 16:
306 return getSInt16Ty();
307 case 32:
308 return getSInt32Ty();
309 case 64:
310 return getSInt64Ty();
311 default:
312 return cir::IntType::get(getContext(), n, true);
313 }
314 }
315
316 cir::VoidType getVoidTy() { return typeCache.voidTy; }
317
318 cir::IntType getBoolMemoryTy() { return getUInt8Ty(); }
319
320 cir::IntType getSInt8Ty() { return typeCache.sInt8Ty; }
321 cir::IntType getSInt16Ty() { return typeCache.sInt16Ty; }
322 cir::IntType getSInt32Ty() { return typeCache.sInt32Ty; }
323 cir::IntType getSInt64Ty() { return typeCache.sInt64Ty; }
324
325 cir::IntType getUInt8Ty() { return typeCache.uInt8Ty; }
326 cir::IntType getUInt16Ty() { return typeCache.uInt16Ty; }
327 cir::IntType getUInt32Ty() { return typeCache.uInt32Ty; }
328 cir::IntType getUInt64Ty() { return typeCache.uInt64Ty; }
329
330 cir::FP16Type getFp16Ty() { return typeCache.fP16Ty; }
331 cir::BF16Type getBfloat16Ty() { return typeCache.bFloat16Ty; }
332 cir::SingleType getSingleTy() { return typeCache.floatTy; }
333 cir::DoubleType getDoubleTy() { return typeCache.doubleTy; }
334 cir::MFloat8Type getMFloat8Ty() { return typeCache.mFloat8Ty; }
335
336 cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal);
337
338 cir::ConstantOp getConstInt(mlir::Location loc, llvm::APInt intVal,
339 bool isUnsigned = true);
340
341 cir::ConstantOp getConstInt(mlir::Location loc, mlir::Type t, uint64_t c);
342
343 cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t,
344 llvm::APFloat fpVal);
345
346 bool isInt8Ty(mlir::Type i) {
347 return i == typeCache.uInt8Ty || i == typeCache.sInt8Ty;
348 }
349 bool isInt16Ty(mlir::Type i) {
350 return i == typeCache.uInt16Ty || i == typeCache.sInt16Ty;
351 }
352 bool isInt32Ty(mlir::Type i) {
353 return i == typeCache.uInt32Ty || i == typeCache.sInt32Ty;
354 }
355 bool isInt64Ty(mlir::Type i) {
356 return i == typeCache.uInt64Ty || i == typeCache.sInt64Ty;
357 }
358 bool isInt(mlir::Type i) { return mlir::isa<cir::IntType>(i); }
359
360 cir::IntType getExtendedIntTy(cir::IntType ty, bool isSigned) {
361 switch (ty.getWidth()) {
362 case 8:
363 return isSigned ? typeCache.sInt16Ty : typeCache.uInt16Ty;
364 case 16:
365 return isSigned ? typeCache.sInt32Ty : typeCache.uInt32Ty;
366 case 32:
367 return isSigned ? typeCache.sInt64Ty : typeCache.uInt64Ty;
368 default:
369 llvm_unreachable("NYI");
370 }
371 }
372
373 cir::IntType getTruncatedIntTy(cir::IntType ty, bool isSigned) {
374 switch (ty.getWidth()) {
375 case 16:
376 return isSigned ? typeCache.sInt8Ty : typeCache.uInt8Ty;
377 case 32:
378 return isSigned ? typeCache.sInt16Ty : typeCache.uInt16Ty;
379 case 64:
380 return isSigned ? typeCache.sInt32Ty : typeCache.uInt32Ty;
381 default:
382 llvm_unreachable("NYI");
383 }
384 }
385
386 cir::VectorType
387 getExtendedOrTruncatedElementVectorType(cir::VectorType vt, bool isExtended,
388 bool isSigned = false) {
389 auto elementTy = mlir::dyn_cast_or_null<cir::IntType>(vt.getElementType());
390 assert(elementTy && "expected int vector");
391 return cir::VectorType::get(isExtended
392 ? getExtendedIntTy(elementTy, isSigned)
393 : getTruncatedIntTy(elementTy, isSigned),
394 vt.getSize(), vt.getKind());
395 }
396
397 // Fetch the type representing a pointer to unsigned int8 values.
398 cir::PointerType getUInt8PtrTy() { return typeCache.uInt8PtrTy; }
399
400 /// Get a CIR anonymous struct type.
401 cir::StructType
405 return cir::StructType::get(getContext(), members, packed,
406 /*is_class=*/false, memberKinds);
407 }
408
409 //===--------------------------------------------------------------------===//
410 // Constant creation helpers
411 //===--------------------------------------------------------------------===//
412 cir::ConstantOp getSInt32(int32_t c, mlir::Location loc) {
413 return getConstantInt(loc, getSInt32Ty(), c);
414 }
415 cir::ConstantOp getUInt32(uint32_t c, mlir::Location loc) {
416 return getConstantInt(loc, getUInt32Ty(), c);
417 }
418 cir::ConstantOp getSInt64(uint64_t c, mlir::Location loc) {
419 return getConstantInt(loc, getSInt64Ty(), c);
420 }
421 cir::ConstantOp getUInt64(uint64_t c, mlir::Location loc) {
422 return getConstantInt(loc, getUInt64Ty(), c);
423 }
424
425 cir::ConstantOp getZero(mlir::Location loc, mlir::Type ty) {
426 // TODO: dispatch creation for primitive types.
427 assert((mlir::isa<cir::RecordType>(ty) || mlir::isa<cir::ArrayType>(ty) ||
428 mlir::isa<cir::VectorType>(ty)) &&
429 "NYI for other types");
430 return cir::ConstantOp::create(*this, loc, cir::ZeroAttr::get(ty));
431 }
432
433 //===--------------------------------------------------------------------===//
434 // UnaryOp creation helpers
435 //===--------------------------------------------------------------------===//
436 mlir::Value createNeg(mlir::Location loc, mlir::Value value,
437 bool nsw = false) {
438
439 if (auto intTy = mlir::dyn_cast<cir::IntType>(value.getType())) {
440 // Source is a unsigned integer: first cast it to signed.
441 if (intTy.isUnsigned())
442 value = createIntCast(value, getSIntNTy(intTy.getWidth()));
443 return createMinus(loc, value, nsw);
444 }
445
446 llvm_unreachable("negation for the given type is NYI");
447 }
448
449 //===--------------------------------------------------------------------===//
450 // CastOp creation helpers
451 //===--------------------------------------------------------------------===//
452
453 // TODO: split this to createFPExt/createFPTrunc when we have dedicated cast
454 // operations.
455 mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType) {
456 return cir::CastOp::create(*this, v.getLoc(), destType,
457 cir::CastKind::floating, v,
459 }
460
461 mlir::Value createDynCast(mlir::Location loc, mlir::Value src,
462 cir::PointerType destType, bool isRefCast,
463 cir::DynamicCastInfoAttr info) {
464 auto castKind =
465 isRefCast ? cir::DynamicCastKind::Ref : cir::DynamicCastKind::Ptr;
466 return cir::DynamicCastOp::create(*this, loc, destType, castKind, src,
467 info);
468 }
469
470 mlir::Value createDynCastToVoid(mlir::Location loc, mlir::Value src) {
471 auto srcPtrTy = mlir::cast<cir::PointerType>(src.getType());
472 cir::PointerType destTy = getVoidPtrTy(srcPtrTy.getAddrSpace());
473 return cir::DynamicCastOp::create(*this, loc, destTy,
474 cir::DynamicCastKind::Ptr, src,
475 cir::DynamicCastInfoAttr{});
476 }
477
478 //===--------------------------------------------------------------------===//
479 // Address creation helpers
480 //===--------------------------------------------------------------------===//
481 Address createBaseClassAddr(mlir::Location loc, Address addr,
482 mlir::Type destType, unsigned offset,
483 bool assumeNotNull) {
484 if (destType == addr.getElementType())
485 return addr;
486
487 auto ptrTy = getPointerTo(destType, addr.getAddressSpace());
488 auto baseAddr =
489 cir::BaseClassAddrOp::create(*this, loc, ptrTy, addr.getPointer(),
490 mlir::APInt(64, offset), assumeNotNull);
491 return Address(baseAddr, destType, addr.getAlignment());
492 }
493
494 Address createDerivedClassAddr(mlir::Location loc, Address addr,
495 mlir::Type destType, unsigned offset,
496 bool assumeNotNull) {
497 if (destType == addr.getElementType())
498 return addr;
499
500 cir::PointerType ptrTy = getPointerTo(destType, addr.getAddressSpace());
501 auto derivedAddr =
502 cir::DerivedClassAddrOp::create(*this, loc, ptrTy, addr.getPointer(),
503 mlir::APInt(64, offset), assumeNotNull);
504 return Address(derivedAddr, destType, addr.getAlignment());
505 }
506
507 //===--------------------------------------------------------------------===//
508 // Virtual Address creation helpers
509 //===--------------------------------------------------------------------===//
510 mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy,
511 mlir::Value addr, uint64_t offset) {
512 return cir::VTTAddrPointOp::create(*this, loc, retTy,
513 mlir::FlatSymbolRefAttr{}, addr, offset);
514 }
515
516 mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy,
517 mlir::FlatSymbolRefAttr sym, uint64_t offset) {
518 return cir::VTTAddrPointOp::create(*this, loc, retTy, sym, mlir::Value{},
519 offset);
520 }
521
522 //===--------------------------------------------------------------------===//
523 // Other creation helpers
524 //===--------------------------------------------------------------------===//
525 cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src,
526 cir::FPClassTest flags) {
527 // FPClassTest occupies bits 0-9 (fcAllFlags). Sema rejects an
528 // out-of-range __builtin_isfpclass mask, so any extra bit here is an
529 // internal error; assert and mask it off so lowering stays well-formed.
530 uint32_t raw = static_cast<uint32_t>(flags);
531 uint32_t all = static_cast<uint32_t>(cir::FPClassTest::All);
532 assert((raw & ~all) == 0 && "FPClassTest mask has bits outside 0-9");
533 flags = static_cast<cir::FPClassTest>(raw & all);
534 return cir::IsFPClassOp::create(*this, loc, src, flags);
535 }
536
537 /// Cast the element type of the given address to a different type,
538 /// preserving information like the alignment.
539 Address createElementBitCast(mlir::Location loc, Address addr,
540 mlir::Type destType) {
541 if (destType == addr.getElementType())
542 return addr;
543
544 auto srcPtrTy = mlir::cast<cir::PointerType>(addr.getPointer().getType());
545 auto ptrTy = getPointerTo(destType, srcPtrTy.getAddrSpace());
546 return Address(createBitcast(loc, addr.getPointer(), ptrTy), destType,
547 addr.getAlignment());
548 }
549
550 cir::LoadOp createLoad(mlir::Location loc, Address addr,
551 bool isVolatile = false, bool isNontemporal = false) {
552 mlir::IntegerAttr align = getAlignmentAttr(addr.getAlignment());
553 return cir::LoadOp::create(*this, loc, addr.getPointer(), /*isDeref=*/false,
554 isVolatile, isNontemporal,
555 /*alignment=*/align,
556 /*sync_scope=*/cir::SyncScopeKindAttr{},
557 /*mem_order=*/cir::MemOrderAttr{},
558 /*invariant=*/false);
559 }
560
561 cir::LoadOp createAlignedLoad(mlir::Location loc, mlir::Type ty,
562 mlir::Value ptr, llvm::MaybeAlign align) {
563 if (ty != mlir::cast<cir::PointerType>(ptr.getType()).getPointee())
564 ptr = createPtrBitcast(ptr, ty);
565 uint64_t alignment = align ? align->value() : 0;
566 mlir::IntegerAttr alignAttr = getAlignmentAttr(alignment);
567 return cir::LoadOp::create(*this, loc, ptr, /*isDeref=*/false,
568 /*isVolatile=*/false, /*isNontemporal=*/false,
569 alignAttr,
570 /*sync_scope=*/cir::SyncScopeKindAttr{},
571 /*mem_order=*/cir::MemOrderAttr{},
572 /*invariant=*/false);
573 }
574
575 cir::LoadOp
576 createAlignedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr,
578 return createAlignedLoad(loc, ty, ptr, align.getAsAlign());
579 }
580
581 cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst,
582 bool isVolatile = false, bool isNontemporal = false,
583 mlir::IntegerAttr align = {},
584 cir::SyncScopeKindAttr scope = {},
585 cir::MemOrderAttr order = {}) {
586 if (!align)
587 align = getAlignmentAttr(dst.getAlignment());
588 return CIRBaseBuilderTy::createStore(loc, val, dst.getPointer(), isVolatile,
589 isNontemporal, align, scope, order);
590 }
591
592 /// Create a cir.complex.real_ptr operation that derives a pointer to the real
593 /// part of the complex value pointed to by the specified pointer value.
594 mlir::Value createComplexRealPtr(mlir::Location loc, mlir::Value value) {
595 auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
596 auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
597 return cir::ComplexRealPtrOp::create(
598 *this, loc, getPointerTo(srcComplexTy.getElementType()), value);
599 }
600
601 Address createComplexRealPtr(mlir::Location loc, Address addr) {
602 return Address{createComplexRealPtr(loc, addr.getPointer()),
603 addr.getAlignment()};
604 }
605
606 /// Create a cir.complex.imag_ptr operation that derives a pointer to the
607 /// imaginary part of the complex value pointed to by the specified pointer
608 /// value.
609 mlir::Value createComplexImagPtr(mlir::Location loc, mlir::Value value) {
610 auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
611 auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
612 return cir::ComplexImagPtrOp::create(
613 *this, loc, getPointerTo(srcComplexTy.getElementType()), value);
614 }
615
616 Address createComplexImagPtr(mlir::Location loc, Address addr) {
617 return Address{createComplexImagPtr(loc, addr.getPointer()),
618 addr.getAlignment()};
619 }
620
622 Address createGetMember(mlir::Location loc, Address base,
623 llvm::StringRef name, unsigned index,
624 const cir::CIRDataLayout &layout) {
625 auto recordTy = mlir::cast<cir::RecordType>(base.getElementType());
626
627 assert(index < recordTy.getMembers().size() &&
628 "member index out of bounds");
629 mlir::Type memberTy = recordTy.getMembers()[index];
630 mlir::Type memberPtrTy = getPointerTo(memberTy, base.getAddressSpace());
631
632 auto memberOffset = CharUnits::fromQuantity(
633 recordTy.getElementOffset(layout.layout, index));
634
635 mlir::Value memberPtr =
636 createGetMember(loc, memberPtrTy, base.getBasePointer(), name, index);
637 return Address(memberPtr, memberTy,
638 base.getAlignment().alignmentAtOffset(memberOffset),
639 base.isKnownNonNull());
640 }
641
642 cir::GetRuntimeMemberOp createGetIndirectMember(mlir::Location loc,
643 mlir::Value objectPtr,
644 mlir::Value memberPtr) {
645 auto memberPtrTy = mlir::cast<cir::DataMemberType>(memberPtr.getType());
646 auto objectPtrTy = mlir::cast<cir::PointerType>(objectPtr.getType());
647
648 // The member lives in the same address space as the object.
649 cir::PointerType resultTy =
650 getPointerTo(memberPtrTy.getMemberTy(), objectPtrTy.getAddrSpace());
651
652 return cir::GetRuntimeMemberOp::create(*this, loc, resultTy, objectPtr,
653 memberPtr);
654 }
655
656 /// Create a cir.get_element or cir.ptr_stride operation to get access to an
657 /// array element. \p idx is the index of the element to access,
658 /// \p shouldDecay is true if the result should decay to a pointer to the
659 /// element type. \p flags are set on the cir.get_element emitted when
660 /// \p shouldDecay is true and \p arrayPtr points to the array type
661 /// \p eltTy, and are dropped when a cir.ptr_stride is emitted.
662 mlir::Value
663 getArrayElement(mlir::Location arrayLocBegin, mlir::Location arrayLocEnd,
664 mlir::Value arrayPtr, mlir::Type eltTy, mlir::Value idx,
665 bool shouldDecay,
667
668 /// Returns a decayed pointer to the first element of the array
669 /// pointed to by \p arrayPtr.
670 mlir::Value maybeBuildArrayDecay(mlir::Location loc, mlir::Value arrayPtr,
671 mlir::Type eltTy);
672
673 // Convert byte offset to sequence of high-level indices suitable for
674 // GlobalViewAttr. Ideally we shouldn't deal with low-level offsets at all
675 // but currently some parts of Clang AST, which we don't want to touch just
676 // yet, return them.
677 //
678 // Returns false if the offset doesn't designate a subelement of \p ty, which
679 // happens when it lands outside of the object or in the middle of a scalar
680 // member. In that case \p indices is left in an unspecified state and the
681 // caller must describe the address with a byte offset, using a
682 // GlobalOffsetAttr, instead.
684 int64_t offset, mlir::Type ty, const cir::CIRDataLayout &layout,
686
687 // Convert high-level indices (e.g. from GlobalViewAttr) to byte offset.
689 mlir::Type ty,
691
692 /// Creates a versioned global variable. If the symbol is already taken, an ID
693 /// will be appended to the symbol. The returned global must always be queried
694 /// for its name so it can be referenced correctly.
695 [[nodiscard]] cir::GlobalOp
696 createVersionedGlobal(mlir::ModuleOp module, mlir::Location loc,
697 mlir::StringRef name, mlir::Type type, bool isConstant,
698 cir::GlobalLinkageKind linkage,
699 mlir::ptr::MemorySpaceAttrInterface addrSpace = {}) {
700 // Create a unique name if the given name is already taken.
701 std::string uniqueName;
702 if (unsigned version = globalsVersioning[name.str()]++)
703 uniqueName = name.str() + "." + std::to_string(version);
704 else
705 uniqueName = name.str();
706
707 return createGlobal(module, loc, uniqueName, type, isConstant, linkage,
708 addrSpace);
709 }
710
711 cir::StackSaveOp createStackSave(mlir::Location loc, mlir::Type ty) {
712 return cir::StackSaveOp::create(*this, loc, ty);
713 }
714
715 cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v) {
716 return cir::StackRestoreOp::create(*this, loc, v);
717 }
718
720 mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
721 const llvm::APSInt &ltRes, const llvm::APSInt &eqRes,
722 const llvm::APSInt &gtRes, cir::CmpOrdering ordering) {
723 assert(ltRes.getBitWidth() == eqRes.getBitWidth() &&
724 ltRes.getBitWidth() == gtRes.getBitWidth() &&
725 "the three comparison results must have the same bit width");
726 assert((ordering == cir::CmpOrdering::Strong ||
727 ordering == cir::CmpOrdering::Weak) &&
728 "total ordering must be strong or weak");
729 cir::IntType cmpResultTy = getSIntNTy(ltRes.getBitWidth());
730 auto infoAttr = cir::CmpThreeWayInfoAttr::get(
731 getContext(), ordering, ltRes.getSExtValue(), eqRes.getSExtValue(),
732 gtRes.getSExtValue());
733 return cir::CmpThreeWayOp::create(*this, loc, cmpResultTy, lhs, rhs,
734 infoAttr);
735 }
736
738 mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
739 const llvm::APSInt &ltRes, const llvm::APSInt &eqRes,
740 const llvm::APSInt &gtRes, const llvm::APSInt &unorderedRes) {
741 assert(ltRes.getBitWidth() == eqRes.getBitWidth() &&
742 ltRes.getBitWidth() == gtRes.getBitWidth() &&
743 ltRes.getBitWidth() == unorderedRes.getBitWidth() &&
744 "the four comparison results must have the same bit width");
745 cir::IntType cmpResultTy = getSIntNTy(ltRes.getBitWidth());
746 auto infoAttr = cir::CmpThreeWayInfoAttr::get(
747 getContext(), ltRes.getSExtValue(), eqRes.getSExtValue(),
748 gtRes.getSExtValue(), unorderedRes.getSExtValue());
749 return cir::CmpThreeWayOp::create(*this, loc, cmpResultTy, lhs, rhs,
750 infoAttr);
751 }
752
753 mlir::Value createSetBitfield(mlir::Location loc, mlir::Type resultType,
754 Address dstAddr, mlir::Type storageType,
755 mlir::Value src, const CIRGenBitFieldInfo &info,
756 bool isLvalueVolatile, bool useVolatile) {
757 unsigned offset = useVolatile ? info.volatileOffset : info.offset;
758
759 // If using AAPCS and the field is volatile, load with the size of the
760 // declared field
761 storageType =
762 useVolatile ? cir::IntType::get(storageType.getContext(),
763 info.volatileStorageSize, info.isSigned)
764 : storageType;
765 return cir::SetBitfieldOp::create(
766 *this, loc, resultType, dstAddr.getPointer(), storageType, src,
767 info.name, info.size, offset, info.isSigned, isLvalueVolatile,
768 dstAddr.getAlignment().getAsAlign().value());
769 }
770
771 mlir::Value createGetBitfield(mlir::Location loc, mlir::Type resultType,
772 Address addr, mlir::Type storageType,
773 const CIRGenBitFieldInfo &info,
774 bool isLvalueVolatile, bool useVolatile) {
775 unsigned offset = useVolatile ? info.volatileOffset : info.offset;
776
777 // If using AAPCS and the field is volatile, load with the size of the
778 // declared field
779 storageType =
780 useVolatile ? cir::IntType::get(storageType.getContext(),
781 info.volatileStorageSize, info.isSigned)
782 : storageType;
783 return cir::GetBitfieldOp::create(*this, loc, resultType, addr.getPointer(),
784 storageType, info.name, info.size, offset,
785 info.isSigned, isLvalueVolatile,
786 addr.getAlignment().getAsAlign().value());
787 }
788
789 mlir::Value createMaskedLoad(mlir::Location loc, mlir::Type ty,
790 mlir::Value ptr, llvm::Align alignment,
791 mlir::Value mask, mlir::Value passThru) {
792 assert(mlir::isa<cir::VectorType>(ty) && "Type should be vector");
793 assert(mask && "Mask should not be all-ones (null)");
794
795 if (!passThru)
796 passThru = this->getConstant(loc, cir::PoisonAttr::get(ty));
797
798 auto alignAttr =
799 this->getI64IntegerAttr(static_cast<int64_t>(alignment.value()));
800
801 return cir::VecMaskedLoadOp::create(*this, loc, ty, ptr, mask, passThru,
802 alignAttr);
803 }
804
805 cir::VecShuffleOp
806 createVecShuffle(mlir::Location loc, mlir::Value vec1, mlir::Value vec2,
808 auto vecType = mlir::cast<cir::VectorType>(vec1.getType());
809 auto resultTy =
810 cir::VectorType::getFixed(vecType.getElementType(), maskAttrs.size());
811 return cir::VecShuffleOp::create(*this, loc, resultTy, vec1, vec2,
812 getArrayAttr(maskAttrs));
813 }
814
815 cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1,
816 mlir::Type resultTy,
818 cir::ConstantOp poison =
819 getConstant(loc, cir::PoisonAttr::get(vec1.getType()));
820 auto maskAttrs = llvm::to_vector_of<mlir::Attribute>(
821 llvm::map_range(mask, [&](int32_t idx) {
822 return cir::IntAttr::get(getSInt32Ty(), idx);
823 }));
824 return cir::VecShuffleOp::create(*this, loc, resultTy, vec1, poison,
825 getArrayAttr(maskAttrs));
826 }
827
828 cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1,
829 mlir::Value vec2,
831 auto maskAttrs = llvm::to_vector_of<mlir::Attribute>(
832 llvm::map_range(mask, [&](int32_t idx) {
833 return cir::IntAttr::get(getSInt32Ty(), idx);
834 }));
835 return createVecShuffle(loc, vec1, vec2, maskAttrs);
836 }
837
838 cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1,
840 /// Create a unary shuffle. The second vector operand of the IR instruction
841 /// is poison.
842 cir::ConstantOp poison =
843 getConstant(loc, cir::PoisonAttr::get(vec1.getType()));
844 return createVecShuffle(loc, vec1, poison, mask);
845 }
846
847 cir::MatrixExtractOp createMatrixExtract(mlir::Location loc,
848 mlir::Value matrix,
849 mlir::Value rowIdx,
850 mlir::Value columnIdx) {
851 return cir::MatrixExtractOp::create(*this, loc, matrix, rowIdx, columnIdx);
852 }
853
854 cir::MatrixExtractRowOp createMatrixExtractRow(mlir::Location loc,
855 mlir::Value matrix,
856 mlir::Value rowIdx) {
857 return cir::MatrixExtractRowOp::create(*this, loc, matrix, rowIdx);
858 }
859
860 cir::MatrixInsertOp createMatrixInsert(mlir::Location loc, mlir::Value value,
861 mlir::Value matrix, mlir::Value rowIdx,
862 mlir::Value columnIdx) {
863 return cir::MatrixInsertOp::create(*this, loc, value, matrix, rowIdx,
864 columnIdx);
865 }
866
867 cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc,
868 mlir::Type resultTy,
869 mlir::Value value,
870 mlir::Value stride,
871 bool isVolatile) {
872 return cir::MatrixColumnMajorLoadOp::create(*this, loc, resultTy, value,
873 stride, isVolatile);
874 }
875
876 /// Multiply an MxK matrix by a KxN matrix, producing an MxN matrix.
877 cir::MatrixMultiplyOp createMatrixMultiply(mlir::Location loc,
878 mlir::Value lhs, mlir::Value rhs) {
879 auto lhsTy = mlir::cast<cir::MatrixType>(lhs.getType());
880 auto rhsTy = mlir::cast<cir::MatrixType>(rhs.getType());
881 auto resultTy = cir::MatrixType::get(
882 lhsTy.getElementType(), lhsTy.getNumRows(), rhsTy.getNumColumns());
883 return cir::MatrixMultiplyOp::create(*this, loc, resultTy, lhs, rhs);
884 }
885
886 cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc,
887 mlir::Value matrix) {
888 auto inputTy = mlir::cast<cir::MatrixType>(matrix.getType());
889 auto resultTy =
890 cir::MatrixType::get(inputTy.getElementType(), inputTy.getNumColumns(),
891 inputTy.getNumRows());
892 return cir::MatrixTransposeOp::create(*this, loc, resultTy, matrix);
893 }
894
895 cir::MatrixColumnMajorStoreOp createMatrixColumnMajorStore(mlir::Location loc,
896 mlir::Value matrix,
897 mlir::Value data,
898 mlir::Value stride,
899 bool isVolatile) {
900 return cir::MatrixColumnMajorStoreOp::create(*this, loc, matrix, data,
901 stride, isVolatile);
902 }
903
904 std::pair<mlir::Value, mlir::Value>
905 splatMatrixOpOperandsIfNecessary(mlir::Location loc, mlir::Value lhs,
906 mlir::Value rhs) {
907 assert(mlir::isa<cir::MatrixType>(lhs.getType()) ||
908 mlir::isa<cir::MatrixType>(rhs.getType()));
909
910 if (!mlir::isa<cir::MatrixType>(lhs.getType()))
911 lhs = cir::VecSplatOp::create(*this, loc, rhs.getType(), lhs);
912 else if (!mlir::isa<cir::MatrixType>(rhs.getType()))
913 rhs = cir::VecSplatOp::create(*this, loc, lhs.getType(), rhs);
914
915 return {lhs, rhs};
916 }
917
918 template <typename... Operands>
919 mlir::Value emitIntrinsicCallOp(mlir::Location loc, const llvm::StringRef str,
920 const mlir::Type &resTy, Operands &&...op) {
921 return cir::LLVMIntrinsicCallOp::create(*this, loc,
922 this->getStringAttr(str), resTy,
923 std::forward<Operands>(op)...)
924 .getResult();
925 }
926
927 template <typename... Operands>
928 mlir::Value emitIntrinsicCallOp(mlir::Location loc, const llvm::StringRef str,
929 const mlir::Type &resTy,
930 cir::FastMathFlagsAttr fastmath,
931 Operands &&...op) {
932 return cir::LLVMIntrinsicCallOp::create(
933 *this, loc, this->getStringAttr(str), resTy,
934 std::forward<Operands>(op)..., fastmath)
935 .getResult();
936 }
937
938 /// Converts \p src to \p dstTy, saturating at its bounds. The signedness of
939 /// \p dstTy selects between fptosi.sat and fptoui.sat.
940 mlir::Value createFPToIntSat(mlir::Location loc, mlir::Value src,
941 cir::IntType dstTy) {
942 return emitIntrinsicCallOp(
943 loc, dstTy.isSigned() ? "fptosi.sat" : "fptoui.sat", dstTy, src);
944 }
945};
946
947} // namespace clang::CIRGen
948
949#endif
static bool isUnsigned(SValBuilder &SVB, NonLoc Value)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
cir::CopyOp createCopy(mlir::Value dst, mlir::Value src, bool isVolatile=false, bool skipTailPadding=false)
Create a copy with inferred length.
cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy, mlir::Value base, llvm::StringRef name, unsigned index)
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::FenvAttr getConstrainedFPAttr()
Build the #cir.fenv attribute describing the constrained floating-point environment currently in effe...
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
cir::PointerType getPointerTo(mlir::Type ty)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
mlir::Value createIntCast(mlir::Value src, mlir::Type newTy)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment)
mlir::Value createMinus(mlir::Location loc, mlir::Value input, bool nsw=false)
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
cir::GlobalOp createGlobal(mlir::ModuleOp mlirModule, mlir::Location loc, mlir::StringRef name, mlir::Type type, bool isConstant, cir::GlobalLinkageKind linkage, mlir::ptr::MemorySpaceAttrInterface addrSpace)
mlir::DataLayout layout
C++ view class that accepts both !cir.struct and !cir.union types.
Definition CIRTypes.h:150
static llvm::SmallVector< RecordMemberKind > getAllDataKinds(llvm::ArrayRef< mlir::Type > members)
One Data kind per member.
Definition CIRTypes.cpp:151
bool isKnownNonNull() const
Whether the pointer is known not to be null.
Definition Address.h:157
mlir::ptr::MemorySpaceAttrInterface getAddressSpace() const
Definition Address.h:133
mlir::Value getPointer() const
Definition Address.h:98
mlir::Type getElementType() const
Definition Address.h:125
clang::CharUnits getAlignment() const
Definition Address.h:138
mlir::Value getBasePointer() const
Definition Address.h:103
cir::StackSaveOp createStackSave(mlir::Location loc, mlir::Type ty)
std::pair< mlir::Value, mlir::Value > splatMatrixOpOperandsIfNecessary(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
bool computeGlobalViewIndicesFromFlatOffset(int64_t offset, mlir::Type ty, const cir::CIRDataLayout &layout, llvm::SmallVectorImpl< int64_t > &indices)
cir::TypeInfoAttr getTypeInfo(mlir::ArrayAttr fieldsAttr)
cir::CmpThreeWayOp createThreeWayCmpTotalOrdering(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, const llvm::APSInt &ltRes, const llvm::APSInt &eqRes, const llvm::APSInt &gtRes, cir::CmpOrdering ordering)
mlir::Value createComplexRealPtr(mlir::Location loc, mlir::Value value)
Create a cir.complex.real_ptr operation that derives a pointer to the real part of the complex value ...
cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, mlir::Value vec2, llvm::ArrayRef< int64_t > mask)
cir::ConstantOp getUInt64(uint64_t c, mlir::Location loc)
mlir::Value emitIntrinsicCallOp(mlir::Location loc, const llvm::StringRef str, const mlir::Type &resTy, Operands &&...op)
cir::IntType getSIntNTy(int n)
cir::DataMemberAttr getDataMemberAttr(cir::DataMemberType ty, llvm::ArrayRef< int32_t > path)
cir::ConstantOp getSInt64(uint64_t c, mlir::Location loc)
cir::IntType getTruncatedIntTy(cir::IntType ty, bool isSigned)
cir::RecordType getIncompleteRecordTy(llvm::StringRef name, const clang::RecordDecl *rd)
Get an incomplete CIR record type.
cir::ConstantOp getUInt32(uint32_t c, mlir::Location loc)
cir::MatrixColumnMajorStoreOp createMatrixColumnMajorStore(mlir::Location loc, mlir::Value matrix, mlir::Value data, mlir::Value stride, bool isVolatile)
cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, mlir::Value vec2, llvm::ArrayRef< mlir::Attribute > maskAttrs)
mlir::Value createNeg(mlir::Location loc, mlir::Value value, bool nsw=false)
cir::MatrixExtractOp createMatrixExtract(mlir::Location loc, mlir::Value matrix, mlir::Value rowIdx, mlir::Value columnIdx)
cir::PointerType getUInt8PtrTy()
mlir::Attribute getConstRecordOrZeroAttr(mlir::ArrayAttr arrayAttr, cir::RecordType recordTy)
cir::RecordType getCompleteNamedRecordType(llvm::ArrayRef< mlir::Type > members, bool packed, llvm::StringRef name, llvm::ArrayRef< cir::RecordMemberKind > memberKinds)
Get a CIR named record type.
std::string getUniqueRecordName(const std::string &baseName)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false, bool isNontemporal=false)
cir::CmpThreeWayOp createThreeWayCmpPartialOrdering(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, const llvm::APSInt &ltRes, const llvm::APSInt &eqRes, const llvm::APSInt &gtRes, const llvm::APSInt &unorderedRes)
mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy, mlir::FlatSymbolRefAttr sym, uint64_t offset)
mlir::Value createMaskedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, llvm::Align alignment, mlir::Value mask, mlir::Value passThru)
Address createBaseClassAddr(mlir::Location loc, Address addr, mlir::Type destType, unsigned offset, bool assumeNotNull)
mlir::Value createComplexImagPtr(mlir::Location loc, mlir::Value value)
Create a cir.complex.imag_ptr operation that derives a pointer to the imaginary part of the complex v...
mlir::Value maybeBuildArrayDecay(mlir::Location loc, mlir::Value arrayPtr, mlir::Type eltTy)
Returns a decayed pointer to the first element of the array pointed to by arrayPtr.
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, bool isNontemporal=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
cir::LoadOp createAlignedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, llvm::MaybeAlign align)
cir::MemMoveOp createMemMove(mlir::Location loc, Address dst, Address src, mlir::Value len)
cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t, llvm::APFloat fpVal)
mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType)
cir::FuncType getFuncType(llvm::ArrayRef< mlir::Type > params, mlir::Type retTy, bool isVarArg=false)
cir::MemSetOp createMemSet(mlir::Location loc, Address dst, mlir::Value val, mlir::Value len)
cir::IntType getExtendedIntTy(cir::IntType ty, bool isSigned)
Address createDerivedClassAddr(mlir::Location loc, Address addr, mlir::Type destType, unsigned offset, bool assumeNotNull)
static bool tagKindIsUnion(const clang::TagTypeKind kind)
Returns true if the tag kind is a union.
uint64_t computeOffsetFromGlobalViewIndices(const cir::CIRDataLayout &layout, mlir::Type ty, llvm::ArrayRef< int64_t > indices)
cir::MatrixTransposeOp createMatrixTranspose(mlir::Location loc, mlir::Value matrix)
cir::GetRuntimeMemberOp createGetIndirectMember(mlir::Location loc, mlir::Value objectPtr, mlir::Value memberPtr)
Address createGetMember(mlir::Location loc, Address base, llvm::StringRef name, unsigned index, const cir::CIRDataLayout &layout)
Address createElementBitCast(mlir::Location loc, Address addr, mlir::Type destType)
Cast the element type of the given address to a different type, preserving information like the align...
cir::MatrixMultiplyOp createMatrixMultiply(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
Multiply an MxK matrix by a KxN matrix, producing an MxN matrix.
cir::ConstRecordAttr getAnonConstRecord(mlir::ArrayAttr arrayAttr)
static bool tagKindIsClass(const clang::TagTypeKind kind)
Get a CIR record kind from a AST declaration tag.
cir::MatrixExtractRowOp createMatrixExtractRow(mlir::Location loc, mlir::Value matrix, mlir::Value rowIdx)
cir::MatrixInsertOp createMatrixInsert(mlir::Location loc, mlir::Value value, mlir::Value matrix, mlir::Value rowIdx, mlir::Value columnIdx)
cir::ConstantOp getZero(mlir::Location loc, mlir::Type ty)
cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, llvm::ArrayRef< int64_t > mask)
cir::MemCpyOp createMemCpy(mlir::Location loc, Address dst, Address src, mlir::Value len)
mlir::Value createDynCast(mlir::Location loc, mlir::Value src, cir::PointerType destType, bool isRefCast, cir::DynamicCastInfoAttr info)
mlir::Value createGetBitfield(mlir::Location loc, mlir::Type resultType, Address addr, mlir::Type storageType, const CIRGenBitFieldInfo &info, bool isLvalueVolatile, bool useVolatile)
bool isNullValue(mlir::Attribute attr) const
cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v)
mlir::Value createSetBitfield(mlir::Location loc, mlir::Type resultType, Address dstAddr, mlir::Type storageType, mlir::Value src, const CIRGenBitFieldInfo &info, bool isLvalueVolatile, bool useVolatile)
Address createComplexRealPtr(mlir::Location loc, Address addr)
cir::GlobalOp createVersionedGlobal(mlir::ModuleOp module, mlir::Location loc, mlir::StringRef name, mlir::Type type, bool isConstant, cir::GlobalLinkageKind linkage, mlir::ptr::MemorySpaceAttrInterface addrSpace={})
Creates a versioned global variable.
cir::MatrixColumnMajorLoadOp createMatrixColumnMajorLoad(mlir::Location loc, mlir::Type resultTy, mlir::Value value, mlir::Value stride, bool isVolatile)
cir::MFloat8Type getMFloat8Ty()
cir::StructType getAnonRecordTy(llvm::ArrayRef< mlir::Type > members, bool packed, llvm::ArrayRef< cir::RecordMemberKind > memberKinds)
Get a CIR anonymous struct type.
mlir::Value emitIntrinsicCallOp(mlir::Location loc, const llvm::StringRef str, const mlir::Type &resTy, cir::FastMathFlagsAttr fastmath, Operands &&...op)
CIRGenBuilderTy(mlir::MLIRContext &mlirContext, const CIRGenTypeCache &tc)
cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src, cir::FPClassTest flags)
mlir::Attribute getString(llvm::StringRef str, mlir::Type eltTy, std::optional< size_t > size, bool ensureNullTerm=true)
Get a cir::ConstArrayAttr for a string literal.
cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, mlir::Type resultTy, llvm::ArrayRef< int64_t > mask)
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
mlir::Value getArrayElement(mlir::Location arrayLocBegin, mlir::Location arrayLocEnd, mlir::Value arrayPtr, mlir::Type eltTy, mlir::Value idx, bool shouldDecay, cir::PtrOffsetFlags flags=cir::PtrOffsetFlags::None)
Create a cir.get_element or cir.ptr_stride operation to get access to an array element.
Address createComplexImagPtr(mlir::Location loc, Address addr)
cir::VectorType getExtendedOrTruncatedElementVectorType(cir::VectorType vt, bool isExtended, bool isSigned=false)
cir::DataMemberAttr getNullDataMemberAttr(cir::DataMemberType ty)
cir::ConstantOp getSInt32(int32_t c, mlir::Location loc)
mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy, mlir::Value addr, uint64_t offset)
cir::MemSetOp createMemSet(mlir::Location loc, mlir::Value dst, mlir::Value val, mlir::Value len)
cir::LongDoubleType getLongDoubleTy(const llvm::fltSemantics &format) const
mlir::Value createDynCastToVoid(mlir::Location loc, mlir::Value src)
cir::CopyOp createCopy(Address dst, Address src, bool isVolatile=false, bool skipTailPadding=false)
cir::ConstArrayAttr getConstArray(mlir::Attribute attrs, cir::ArrayType arrayTy) const
cir::IntType getUIntNTy(int n)
mlir::Value createFPToIntSat(mlir::Location loc, mlir::Value src, cir::IntType dstTy)
Converts src to dstTy, saturating at its bounds.
cir::LoadOp createAlignedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, clang::CharUnits align=clang::CharUnits::One())
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
Definition CharUnits.h:177
llvm::Align getAsAlign() const
Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit bytes.
Definition CharUnits.h:159
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Definition CharUnits.h:155
static CharUnits One()
Construct a CharUnits quantity of one.
Definition CharUnits.h:55
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
Represents a struct/union/class.
Definition Decl.h:4506
TagKind getTagKind() const
Definition Decl.h:4098
PtrOffsetFlags
No-wrap flags of a pointer offset computation: the subset of llvm::GEPNoWrapFlags that cir....
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:6171
@ Class
The "class" keyword.
Definition TypeBase.h:6182
@ Union
The "union" keyword.
Definition TypeBase.h:6179
int __ovld __cnfn all(char)
Returns 1 if the most significant bit in all components of x is set; otherwise returns 0.
__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
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t
static bool astRecordDeclAttr()
Record with information about how a bitfield should be accessed.
This structure provides a set of types that are commonly used during IR emission.