clang 23.0.0git
CXXABILowering.cpp
Go to the documentation of this file.
1//==- CXXABILowering.cpp - lower C++ operations to target-specific ABI form -=//
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#include <deque>
10
11#include "PassDetail.h"
13
14#include "mlir/Dialect/OpenACC/OpenACCOpsDialect.h.inc"
15#include "mlir/Dialect/OpenMP/OpenMPOpsDialect.h.inc"
16#include "mlir/IR/PatternMatch.h"
17#include "mlir/Interfaces/DataLayoutInterfaces.h"
18#include "mlir/Pass/Pass.h"
19#include "mlir/Transforms/DialectConversion.h"
27
28#include "llvm/ADT/ScopeExit.h"
29#include "llvm/ADT/TypeSwitch.h"
30
31using namespace mlir;
32using namespace cir;
33
34namespace mlir {
35#define GEN_PASS_DEF_CXXABILOWERING
36#include "clang/CIR/Dialect/Passes.h.inc"
37} // namespace mlir
38
39namespace {
40// Check an attribute for legality. An attribute is only currently potentially
41// illegal if it contains a type, member pointers are our source of illegality
42// in regards to attributes.
43bool isCXXABIAttributeLegal(const mlir::TypeConverter &tc,
44 mlir::Attribute attr) {
45 // If we don't have an attribute, it can't have a type!
46 if (!attr)
47 return true;
48
49 // None of the OpenACC/OMP attributes contain a type of concern, so we can
50 // just treat them as legal.
51 if (isa<mlir::acc::OpenACCDialect, mlir::omp::OpenMPDialect>(
52 attr.getDialect()))
53 return true;
54
55 // These attributes either don't contain a type, or don't contain a type that
56 // can have a data member/method.
57 if (isa<mlir::DenseArrayAttr, mlir::FloatAttr, mlir::UnitAttr,
58 mlir::StringAttr, mlir::IntegerAttr, mlir::SymbolRefAttr>(attr))
59 return true;
60
61 // Tablegen'ed always-legal attributes:
62 if (isa<
64#include "clang/CIR/Dialect/IR/CIRLowering.inc"
66 >(attr))
67 return true;
68
69 // Data Member and method are ALWAYS illegal.
70 if (isa<cir::DataMemberAttr, cir::MethodAttr>(attr))
71 return false;
72
73 return llvm::TypeSwitch<mlir::Attribute, bool>(attr)
74 // These attributes just have a type, so they are legal if their type is.
75 .Case<cir::ZeroAttr>(
76 [&tc](cir::ZeroAttr za) { return tc.isLegal(za.getType()); })
77 .Case<cir::PoisonAttr>(
78 [&tc](cir::PoisonAttr pa) { return tc.isLegal(pa.getType()); })
79 .Case<cir::UndefAttr>(
80 [&tc](cir::UndefAttr uda) { return tc.isLegal(uda.getType()); })
81 .Case<mlir::TypeAttr>(
82 [&tc](mlir::TypeAttr ta) { return tc.isLegal(ta.getValue()); })
83 .Case<cir::ConstPtrAttr>(
84 [&tc](cir::ConstPtrAttr cpa) { return tc.isLegal(cpa.getType()); })
85 .Case<cir::CXXCtorAttr>(
86 [&tc](cir::CXXCtorAttr ca) { return tc.isLegal(ca.getType()); })
87 .Case<cir::CXXDtorAttr>(
88 [&tc](cir::CXXDtorAttr da) { return tc.isLegal(da.getType()); })
89 .Case<cir::CXXAssignAttr>(
90 [&tc](cir::CXXAssignAttr aa) { return tc.isLegal(aa.getType()); })
91
92 // Collection attributes are legal if ALL of the attributes in them are
93 // also legal.
94 .Case<mlir::ArrayAttr>([&tc](mlir::ArrayAttr array) {
95 return llvm::all_of(array.getValue(), [&tc](mlir::Attribute attr) {
96 return isCXXABIAttributeLegal(tc, attr);
97 });
98 })
99 .Case<mlir::DictionaryAttr>([&tc](mlir::DictionaryAttr dict) {
100 return llvm::all_of(dict.getValue(), [&tc](mlir::NamedAttribute na) {
101 return isCXXABIAttributeLegal(tc, na.getValue());
102 });
103 })
104 // These attributes have sub-attributes that we should check for legality.
105 .Case<cir::ConstArrayAttr>([&tc](cir::ConstArrayAttr array) {
106 return tc.isLegal(array.getType()) &&
107 isCXXABIAttributeLegal(tc, array.getElts());
108 })
109 .Case<cir::GlobalViewAttr>([&tc](cir::GlobalViewAttr gva) {
110 return tc.isLegal(gva.getType()) &&
111 isCXXABIAttributeLegal(tc, gva.getIndices());
112 })
113 .Case<cir::VTableAttr>([&tc](cir::VTableAttr vta) {
114 return tc.isLegal(vta.getType()) &&
115 isCXXABIAttributeLegal(tc, vta.getData());
116 })
117 .Case<cir::TypeInfoAttr>([&tc](cir::TypeInfoAttr tia) {
118 return tc.isLegal(tia.getType()) &&
119 isCXXABIAttributeLegal(tc, tia.getData());
120 })
121 .Case<cir::DynamicCastInfoAttr>([&tc](cir::DynamicCastInfoAttr dcia) {
122 return isCXXABIAttributeLegal(tc, dcia.getSrcRtti()) &&
123 isCXXABIAttributeLegal(tc, dcia.getDestRtti()) &&
124 isCXXABIAttributeLegal(tc, dcia.getRuntimeFunc()) &&
125 isCXXABIAttributeLegal(tc, dcia.getBadCastFunc());
126 })
127 .Case<cir::ConstRecordAttr>([&tc](cir::ConstRecordAttr cra) {
128 return tc.isLegal(cra.getType()) &&
129 isCXXABIAttributeLegal(tc, cra.getMembers());
130 })
131 // We did an audit of all of our attributes (both in OpenACC and CIR), so
132 // it shouldn't be dangerous to consider everything we haven't considered
133 // 'illegal'. Any 'new' attributes will end up asserting in
134 // 'rewriteAttribute' to make sure we consider them here. Otherwise, we
135 // wouldn't discover a problematic new attribute until it contains a
136 // member/method.
137 .Default(false);
138}
139
140mlir::Attribute rewriteAttribute(const mlir::TypeConverter &tc,
141 mlir::MLIRContext *ctx, mlir::Attribute attr) {
142 // If the attribute is legal, there is no reason to rewrite it. This also
143 // filters out 'null' attributes.
144 if (isCXXABIAttributeLegal(tc, attr))
145 return attr;
146
147 // This switch needs to be kept in sync with the potentially-legal type switch
148 // from isCXXABIAttributeLegal. IF we miss any, this will end up causing
149 // verification/transformation issues later, often in the form of
150 // unrealized-conversion-casts.
151
152 return llvm::TypeSwitch<mlir::Attribute, mlir::Attribute>(attr)
153 // These attributes just have a type, so convert just the type.
154 .Case<cir::ZeroAttr>([&tc](cir::ZeroAttr za) {
155 return cir::ZeroAttr::get(tc.convertType(za.getType()));
156 })
157 .Case<cir::PoisonAttr>([&tc](cir::PoisonAttr pa) {
158 return cir::PoisonAttr::get(tc.convertType(pa.getType()));
159 })
160 .Case<cir::UndefAttr>([&tc](cir::UndefAttr uda) {
161 return cir::UndefAttr::get(tc.convertType(uda.getType()));
162 })
163 .Case<mlir::TypeAttr>([&tc](mlir::TypeAttr ta) {
164 return mlir::TypeAttr::get(tc.convertType(ta.getValue()));
165 })
166 .Case<cir::ConstPtrAttr>([&tc](cir::ConstPtrAttr cpa) {
167 return cir::ConstPtrAttr::get(tc.convertType(cpa.getType()),
168 cpa.getValue());
169 })
170 .Case<cir::CXXCtorAttr>([&tc](cir::CXXCtorAttr ca) {
171 return cir::CXXCtorAttr::get(tc.convertType(ca.getType()),
172 ca.getCtorKind(), ca.getIsTrivial());
173 })
174 .Case<cir::CXXDtorAttr>([&tc](cir::CXXDtorAttr da) {
175 return cir::CXXDtorAttr::get(tc.convertType(da.getType()),
176 da.getIsTrivial());
177 })
178 .Case<cir::CXXAssignAttr>([&tc](cir::CXXAssignAttr aa) {
179 return cir::CXXAssignAttr::get(tc.convertType(aa.getType()),
180 aa.getAssignKind(), aa.getIsTrivial());
181 })
182 // Collection attributes need to transform all of the attributes inside of
183 // them.
184 .Case<mlir::ArrayAttr>([&tc, ctx](mlir::ArrayAttr array) {
186 for (mlir::Attribute a : array.getValue())
187 elts.push_back(rewriteAttribute(tc, ctx, a));
188 return mlir::ArrayAttr::get(ctx, elts);
189 })
190 .Case<mlir::DictionaryAttr>([&tc, ctx](mlir::DictionaryAttr dict) {
192 for (mlir::NamedAttribute na : dict.getValue())
193 elts.emplace_back(na.getName(),
194 rewriteAttribute(tc, ctx, na.getValue()));
195
196 return mlir::DictionaryAttr::get(ctx, elts);
197 })
198 // These attributes have sub-attributes that need converting too.
199 .Case<cir::ConstArrayAttr>([&tc, ctx](cir::ConstArrayAttr array) {
200 return cir::ConstArrayAttr::get(
201 ctx, tc.convertType(array.getType()),
202 rewriteAttribute(tc, ctx, array.getElts()),
203 array.getTrailingZerosNum());
204 })
205 .Case<cir::GlobalViewAttr>([&tc, ctx](cir::GlobalViewAttr gva) {
206 return cir::GlobalViewAttr::get(
207 tc.convertType(gva.getType()), gva.getSymbol(),
208 mlir::cast<mlir::ArrayAttr>(
209 rewriteAttribute(tc, ctx, gva.getIndices())));
210 })
211 .Case<cir::VTableAttr>([&tc, ctx](cir::VTableAttr vta) {
212 return cir::VTableAttr::get(
213 tc.convertType(vta.getType()),
214 mlir::cast<mlir::ArrayAttr>(
215 rewriteAttribute(tc, ctx, vta.getData())));
216 })
217 .Case<cir::TypeInfoAttr>([&tc, ctx](cir::TypeInfoAttr tia) {
218 return cir::TypeInfoAttr::get(
219 tc.convertType(tia.getType()),
220 mlir::cast<mlir::ArrayAttr>(
221 rewriteAttribute(tc, ctx, tia.getData())));
222 })
223 .Case<cir::DynamicCastInfoAttr>([&tc,
224 ctx](cir::DynamicCastInfoAttr dcia) {
225 return cir::DynamicCastInfoAttr::get(
226 mlir::cast<cir::GlobalViewAttr>(
227 rewriteAttribute(tc, ctx, dcia.getSrcRtti())),
228 mlir::cast<cir::GlobalViewAttr>(
229 rewriteAttribute(tc, ctx, dcia.getDestRtti())),
230 dcia.getRuntimeFunc(), dcia.getBadCastFunc(), dcia.getOffsetHint());
231 })
232 .Case<cir::ConstRecordAttr>([&tc, ctx](cir::ConstRecordAttr cra) {
233 return cir::ConstRecordAttr::get(
234 ctx, tc.convertType(cra.getType()),
235 mlir::cast<mlir::ArrayAttr>(
236 rewriteAttribute(tc, ctx, cra.getMembers())));
237 })
238 .DefaultUnreachable("unrewritten illegal attribute kind");
239}
240
241#define GET_ABI_LOWERING_PATTERNS
242#include "clang/CIR/Dialect/IR/CIRLowering.inc"
243#undef GET_ABI_LOWERING_PATTERNS
244
245struct CXXABILoweringPass
246 : public impl::CXXABILoweringBase<CXXABILoweringPass> {
247 CXXABILoweringPass() = default;
248 void runOnOperation() override;
249};
250
251/// A generic ABI lowering rewrite pattern. This conversion pattern matches any
252/// CIR dialect operations with at least one operand or result of an
253/// ABI-dependent type. This conversion pattern rewrites the matched operation
254/// by replacing all its ABI-dependent operands and results with their
255/// lowered counterparts.
256class CIRGenericCXXABILoweringPattern : public mlir::ConversionPattern {
257public:
258 CIRGenericCXXABILoweringPattern(mlir::MLIRContext *context,
259 const mlir::TypeConverter &typeConverter)
260 : mlir::ConversionPattern(typeConverter, MatchAnyOpTypeTag(),
261 /*benefit=*/1, context) {}
262
263 mlir::LogicalResult
264 matchAndRewrite(mlir::Operation *op, llvm::ArrayRef<mlir::Value> operands,
265 mlir::ConversionPatternRewriter &rewriter) const override {
266 // Do not match on operations that have dedicated ABI lowering rewrite rules
267 if (llvm::isa<cir::AllocaOp, cir::BaseDataMemberOp, cir::BaseMethodOp,
268 cir::CastOp, cir::CmpOp, cir::ConstantOp, cir::DeleteArrayOp,
269 cir::DerivedDataMemberOp, cir::DerivedMethodOp, cir::FuncOp,
270 cir::GetMethodOp, cir::GetRuntimeMemberOp, cir::GlobalOp>(op))
271 return mlir::failure();
272
273 const mlir::TypeConverter *typeConverter = getTypeConverter();
274 assert(typeConverter &&
275 "CIRGenericCXXABILoweringPattern requires a type converter");
276 bool operandsAndResultsLegal = typeConverter->isLegal(op);
277 bool regionsLegal =
278 std::all_of(op->getRegions().begin(), op->getRegions().end(),
279 [typeConverter](mlir::Region &region) {
280 return typeConverter->isLegal(&region);
281 });
282 bool attrsLegal =
283 llvm::all_of(op->getAttrs(), [typeConverter](mlir::NamedAttribute na) {
284 return isCXXABIAttributeLegal(*typeConverter, na.getValue());
285 });
286
287 if (operandsAndResultsLegal && regionsLegal && attrsLegal) {
288 // The operation does not have any CXXABI-dependent operands or results,
289 // the match fails.
290 return mlir::failure();
291 }
292
293 mlir::OperationState loweredOpState(op->getLoc(), op->getName());
294 loweredOpState.addOperands(operands);
295 loweredOpState.addSuccessors(op->getSuccessors());
296
297 // Lower all attributes.
298 llvm::SmallVector<mlir::NamedAttribute> attrs;
299 for (const mlir::NamedAttribute &na : op->getAttrs())
300 attrs.push_back(
301 {na.getName(),
302 rewriteAttribute(*typeConverter, op->getContext(), na.getValue())});
303 loweredOpState.addAttributes(attrs);
304
305 // Lower all result types
306 llvm::SmallVector<mlir::Type> loweredResultTypes;
307 loweredResultTypes.reserve(op->getNumResults());
308 for (mlir::Type result : op->getResultTypes())
309 loweredResultTypes.push_back(typeConverter->convertType(result));
310 loweredOpState.addTypes(loweredResultTypes);
311
312 // Lower all regions
313 for (mlir::Region &region : op->getRegions()) {
314 mlir::Region *loweredRegion = loweredOpState.addRegion();
315 rewriter.inlineRegionBefore(region, *loweredRegion, loweredRegion->end());
316 if (mlir::failed(
317 rewriter.convertRegionTypes(loweredRegion, *getTypeConverter())))
318 return mlir::failure();
319 }
320
321 // Clone the operation with lowered operand types and result types
322 mlir::Operation *loweredOp = rewriter.create(loweredOpState);
323
324 rewriter.replaceOp(op, loweredOp);
325 return mlir::success();
326 }
327};
328
329} // namespace
330
331mlir::LogicalResult CIRAllocaOpABILowering::matchAndRewrite(
332 cir::AllocaOp op, OpAdaptor adaptor,
333 mlir::ConversionPatternRewriter &rewriter) const {
334 mlir::Type allocaPtrTy = op.getType();
335 mlir::Type allocaTy = op.getAllocaType();
336 mlir::Type loweredAllocaPtrTy = getTypeConverter()->convertType(allocaPtrTy);
337 mlir::Type loweredAllocaTy = getTypeConverter()->convertType(allocaTy);
338
339 cir::AllocaOp loweredOp = cir::AllocaOp::create(
340 rewriter, op.getLoc(), loweredAllocaPtrTy, loweredAllocaTy, op.getName(),
341 op.getAlignmentAttr(), /*dynAllocSize=*/adaptor.getDynAllocSize());
342 loweredOp.setInit(op.getInit());
343 loweredOp.setConstant(op.getConstant());
344 loweredOp.setAnnotationsAttr(op.getAnnotationsAttr());
345
346 rewriter.replaceOp(op, loweredOp);
347 return mlir::success();
348}
349
350mlir::LogicalResult CIRCastOpABILowering::matchAndRewrite(
351 cir::CastOp op, OpAdaptor adaptor,
352 mlir::ConversionPatternRewriter &rewriter) const {
353 mlir::Type srcTy = op.getSrc().getType();
354
355 if (mlir::isa<cir::DataMemberType, cir::MethodType>(srcTy)) {
356 switch (op.getKind()) {
357 case cir::CastKind::bitcast: {
358 mlir::Type destTy = getTypeConverter()->convertType(op.getType());
359 mlir::Value loweredResult;
360 if (mlir::isa<cir::DataMemberType>(srcTy))
361 loweredResult = lowerModule->getCXXABI().lowerDataMemberBitcast(
362 op, destTy, adaptor.getSrc(), rewriter);
363 else
364 loweredResult = lowerModule->getCXXABI().lowerMethodBitcast(
365 op, destTy, adaptor.getSrc(), rewriter);
366 rewriter.replaceOp(op, loweredResult);
367 return mlir::success();
368 }
369 case cir::CastKind::member_ptr_to_bool: {
370 mlir::Value loweredResult;
371 if (mlir::isa<cir::DataMemberType>(srcTy))
372 loweredResult = lowerModule->getCXXABI().lowerDataMemberToBoolCast(
373 op, adaptor.getSrc(), rewriter);
374 else
375 loweredResult = lowerModule->getCXXABI().lowerMethodToBoolCast(
376 op, adaptor.getSrc(), rewriter);
377 rewriter.replaceOp(op, loweredResult);
378 return mlir::success();
379 }
380 default:
381 break;
382 }
383 }
384
385 mlir::Value loweredResult = cir::CastOp::create(
386 rewriter, op.getLoc(), getTypeConverter()->convertType(op.getType()),
387 adaptor.getKind(), adaptor.getSrc());
388 rewriter.replaceOp(op, loweredResult);
389 return mlir::success();
390}
391
392// Helper function to lower a value for things like an initializer.
393static mlir::TypedAttr lowerInitialValue(const LowerModule *lowerModule,
394 const mlir::DataLayout &layout,
395 const mlir::TypeConverter &tc,
396 mlir::Type ty,
397 mlir::Attribute initVal) {
398 if (mlir::isa<cir::DataMemberType>(ty)) {
399 auto dataMemberVal = mlir::cast_if_present<cir::DataMemberAttr>(initVal);
400 return lowerModule->getCXXABI().lowerDataMemberConstant(dataMemberVal,
401 layout, tc);
402 }
403 if (mlir::isa<cir::MethodType>(ty)) {
404 auto methodVal = mlir::cast_if_present<cir::MethodAttr>(initVal);
405 return lowerModule->getCXXABI().lowerMethodConstant(methodVal, layout, tc);
406 }
407
408 if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty)) {
409 auto loweredArrTy = mlir::cast<cir::ArrayType>(tc.convertType(arrTy));
410
411 if (!initVal)
412 return {};
413
414 if (auto zeroVal = mlir::dyn_cast_if_present<cir::ZeroAttr>(initVal))
415 return cir::ZeroAttr::get(loweredArrTy);
416
417 auto arrayVal = mlir::cast<cir::ConstArrayAttr>(initVal);
418 auto arrayElts = mlir::cast<ArrayAttr>(arrayVal.getElts());
419 SmallVector<mlir::Attribute> loweredElements;
420 loweredElements.reserve(arrTy.getSize());
421 for (const mlir::Attribute &attr : arrayElts) {
422 auto typedAttr = cast<mlir::TypedAttr>(attr);
423 loweredElements.push_back(lowerInitialValue(
424 lowerModule, layout, tc, typedAttr.getType(), typedAttr));
425 }
426
427 return cir::ConstArrayAttr::get(
428 loweredArrTy, mlir::ArrayAttr::get(ty.getContext(), loweredElements),
429 arrayVal.getTrailingZerosNum());
430 }
431
432 if (auto recordTy = mlir::dyn_cast<cir::RecordType>(ty)) {
433 auto convertedTy = mlir::cast<cir::RecordType>(tc.convertType(recordTy));
434
435 if (auto recVal = mlir::dyn_cast_if_present<cir::ZeroAttr>(initVal))
436 return cir::ZeroAttr::get(convertedTy);
437
438 if (auto undefVal = mlir::dyn_cast_if_present<cir::UndefAttr>(initVal))
439 return cir::UndefAttr::get(convertedTy);
440
441 // This might not be possible from Clang directly, but we can get here with
442 // hand-written IR.
443 if (auto poisonVal = mlir::dyn_cast_if_present<cir::PoisonAttr>(initVal))
444 return cir::PoisonAttr::get(convertedTy);
445
446 if (auto recVal =
447 mlir::dyn_cast_if_present<cir::ConstRecordAttr>(initVal)) {
448 auto recordMembers = mlir::cast<ArrayAttr>(recVal.getMembers());
449
450 SmallVector<mlir::Attribute> loweredMembers;
451 loweredMembers.reserve(recordMembers.size());
452
453 for (const mlir::Attribute &attr : recordMembers) {
454 auto typedAttr = cast<mlir::TypedAttr>(attr);
455 loweredMembers.push_back(lowerInitialValue(
456 lowerModule, layout, tc, typedAttr.getType(), typedAttr));
457 }
458
459 return cir::ConstRecordAttr::get(
460 convertedTy, mlir::ArrayAttr::get(ty.getContext(), loweredMembers));
461 }
462
463 assert(!initVal && "Record init val type not handled");
464 return {};
465 }
466
467 // Pointers can contain record types, which can change.
468 if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty)) {
469 auto convertedTy = mlir::cast<cir::PointerType>(tc.convertType(ptrTy));
470 // pointers don't change other than their types.
471
472 if (auto gva = mlir::dyn_cast_if_present<cir::GlobalViewAttr>(initVal))
473 return cir::GlobalViewAttr::get(convertedTy, gva.getSymbol(),
474 gva.getIndices());
475
476 auto constPtr = mlir::cast_if_present<cir::ConstPtrAttr>(initVal);
477 if (!constPtr)
478 return {};
479 return cir::ConstPtrAttr::get(convertedTy, constPtr.getValue());
480 }
481
482 assert(ty == tc.convertType(ty) &&
483 "cir.global or constant operand is not an CXXABI-dependent type");
484
485 // Every other type can be left alone.
486 return cast<mlir::TypedAttr>(initVal);
487}
488
489mlir::LogicalResult CIRConstantOpABILowering::matchAndRewrite(
490 cir::ConstantOp op, OpAdaptor adaptor,
491 mlir::ConversionPatternRewriter &rewriter) const {
492
493 mlir::DataLayout layout(op->getParentOfType<mlir::ModuleOp>());
494 mlir::TypedAttr newValue = lowerInitialValue(
495 lowerModule, layout, *getTypeConverter(), op.getType(), op.getValue());
496 rewriter.replaceOpWithNewOp<ConstantOp>(op, newValue);
497 return mlir::success();
498}
499
500mlir::LogicalResult CIRCmpOpABILowering::matchAndRewrite(
501 cir::CmpOp op, OpAdaptor adaptor,
502 mlir::ConversionPatternRewriter &rewriter) const {
503 mlir::Type type = op.getLhs().getType();
504
505 mlir::Value loweredResult;
506 if (mlir::isa<cir::DataMemberType>(type))
507 loweredResult = lowerModule->getCXXABI().lowerDataMemberCmp(
508 op, adaptor.getLhs(), adaptor.getRhs(), rewriter);
509 else if (mlir::isa<cir::MethodType>(type))
510 loweredResult = lowerModule->getCXXABI().lowerMethodCmp(
511 op, adaptor.getLhs(), adaptor.getRhs(), rewriter);
512 else
513 loweredResult = cir::CmpOp::create(
514 rewriter, op.getLoc(), getTypeConverter()->convertType(op.getType()),
515 adaptor.getKind(), adaptor.getLhs(), adaptor.getRhs());
516
517 rewriter.replaceOp(op, loweredResult);
518 return mlir::success();
519}
520
521mlir::LogicalResult CIRFuncOpABILowering::matchAndRewrite(
522 cir::FuncOp op, OpAdaptor adaptor,
523 mlir::ConversionPatternRewriter &rewriter) const {
524 cir::FuncType opFuncType = op.getFunctionType();
525 mlir::TypeConverter::SignatureConversion signatureConversion(
526 opFuncType.getNumInputs());
527
528 for (const auto &[i, argType] : llvm::enumerate(opFuncType.getInputs())) {
529 mlir::Type loweredArgType = getTypeConverter()->convertType(argType);
530 if (!loweredArgType)
531 return mlir::failure();
532 signatureConversion.addInputs(i, loweredArgType);
533 }
534
535 mlir::Type loweredResultType =
536 getTypeConverter()->convertType(opFuncType.getReturnType());
537 if (!loweredResultType)
538 return mlir::failure();
539
540 auto loweredFuncType =
541 cir::FuncType::get(signatureConversion.getConvertedTypes(),
542 loweredResultType, /*isVarArg=*/opFuncType.isVarArg());
543
544 // Create a new cir.func operation for the CXXABI-lowered function.
545 cir::FuncOp loweredFuncOp = rewriter.cloneWithoutRegions(op);
546 loweredFuncOp.setFunctionType(loweredFuncType);
547
549 for (const mlir::NamedAttribute &na : op->getAttrs())
550 attrs.push_back(
551 {na.getName(), rewriteAttribute(*getTypeConverter(), op->getContext(),
552 na.getValue())});
553
554 loweredFuncOp->setAttrs(attrs);
555
556 rewriter.inlineRegionBefore(op.getBody(), loweredFuncOp.getBody(),
557 loweredFuncOp.end());
558 if (mlir::failed(rewriter.convertRegionTypes(
559 &loweredFuncOp.getBody(), *getTypeConverter(), &signatureConversion)))
560 return mlir::failure();
561
562 rewriter.eraseOp(op);
563 return mlir::success();
564}
565
566mlir::LogicalResult CIRGlobalOpABILowering::matchAndRewrite(
567 cir::GlobalOp op, OpAdaptor adaptor,
568 mlir::ConversionPatternRewriter &rewriter) const {
569 mlir::Type ty = op.getSymType();
570 mlir::Type loweredTy = getTypeConverter()->convertType(ty);
571 if (!loweredTy)
572 return mlir::failure();
573
574 mlir::DataLayout layout(op->getParentOfType<mlir::ModuleOp>());
575
576 mlir::Attribute loweredInit = lowerInitialValue(
577 lowerModule, layout, *getTypeConverter(), ty, op.getInitialValueAttr());
578
579 auto newOp = mlir::cast<cir::GlobalOp>(rewriter.clone(*op.getOperation()));
580 newOp.setInitialValueAttr(loweredInit);
581 newOp.setSymType(loweredTy);
582 rewriter.replaceOp(op, newOp);
583 return mlir::success();
584}
585
586mlir::LogicalResult CIRBaseDataMemberOpABILowering::matchAndRewrite(
587 cir::BaseDataMemberOp op, OpAdaptor adaptor,
588 mlir::ConversionPatternRewriter &rewriter) const {
589 mlir::Value loweredResult = lowerModule->getCXXABI().lowerBaseDataMember(
590 op, adaptor.getSrc(), rewriter);
591 rewriter.replaceOp(op, loweredResult);
592 return mlir::success();
593}
594
595mlir::LogicalResult CIRBaseMethodOpABILowering::matchAndRewrite(
596 cir::BaseMethodOp op, OpAdaptor adaptor,
597 mlir::ConversionPatternRewriter &rewriter) const {
598 mlir::Value loweredResult =
599 lowerModule->getCXXABI().lowerBaseMethod(op, adaptor.getSrc(), rewriter);
600 rewriter.replaceOp(op, loweredResult);
601 return mlir::success();
602}
603
604mlir::LogicalResult CIRDeleteArrayOpABILowering::matchAndRewrite(
605 cir::DeleteArrayOp op, OpAdaptor adaptor,
606 mlir::ConversionPatternRewriter &rewriter) const {
607 mlir::FlatSymbolRefAttr deleteFn = op.getDeleteFnAttr();
608 mlir::Location loc = op->getLoc();
609 mlir::Value loweredAddress = adaptor.getAddress();
610
611 cir::UsualDeleteParamsAttr deleteParams = op.getDeleteParams();
612 bool cookieRequired = deleteParams.getSize();
613 assert((deleteParams.getSize() || !op.getElementDtorAttr()) &&
614 "Expected size parameter when dtor fn is provided!");
615
616 if (deleteParams.getTypeAwareDelete() || deleteParams.getDestroyingDelete() ||
617 deleteParams.getAlignment())
618 return rewriter.notifyMatchFailure(
619 op, "type-aware, destroying, or aligned delete not yet supported");
620
621 const CIRCXXABI &cxxABI = lowerModule->getCXXABI();
622 CIRBaseBuilderTy cirBuilder(rewriter);
623 mlir::Value deletePtr;
625
626 if (cookieRequired) {
627 mlir::Value numElements;
628 clang::CharUnits cookieSize;
629 auto ptrTy = mlir::cast<cir::PointerType>(loweredAddress.getType());
630 mlir::DataLayout dl(op->getParentOfType<mlir::ModuleOp>());
631
632 cxxABI.readArrayCookie(loc, loweredAddress, dl, cirBuilder, numElements,
633 deletePtr, cookieSize);
634
635 // If a dtor function is provided, create an array dtor operation.
636 // This will get expanded during LoweringPrepare.
637 mlir::FlatSymbolRefAttr dtorFn = op.getElementDtorAttr();
638 if (dtorFn) {
639 auto eltPtrTy = cir::PointerType::get(ptrTy.getPointee());
640 cir::ArrayDtor::create(
641 rewriter, loc, loweredAddress, numElements,
642 [&](mlir::OpBuilder &b, mlir::Location l) {
643 auto arg = b.getInsertionBlock()->addArgument(eltPtrTy, l);
644 cir::CallOp::create(b, l, dtorFn, cir::VoidType(),
645 mlir::ValueRange{arg});
646 cir::YieldOp::create(b, l);
647 });
648 }
649
650 // Compute the total allocation size and add it to the call arguments.
651 callArgs.push_back(deletePtr);
652 uint64_t eltSizeBytes = dl.getTypeSizeInBits(ptrTy.getPointee()) / 8;
653 unsigned ptrWidth =
654 lowerModule->getTarget().getPointerWidth(clang::LangAS::Default);
655 cir::IntType sizeTy = cirBuilder.getUIntNTy(ptrWidth);
656
657 mlir::Value eltSizeVal = cir::ConstantOp::create(
658 rewriter, loc, cir::IntAttr::get(sizeTy, eltSizeBytes));
659 mlir::Value allocSize =
660 cir::MulOp::create(rewriter, loc, sizeTy, eltSizeVal, numElements);
661 mlir::Value cookieSizeVal = cir::ConstantOp::create(
662 rewriter, loc, cir::IntAttr::get(sizeTy, cookieSize.getQuantity()));
663 allocSize =
664 cir::AddOp::create(rewriter, loc, sizeTy, allocSize, cookieSizeVal);
665 callArgs.push_back(allocSize);
666 } else {
667 deletePtr = cir::CastOp::create(rewriter, loc, cirBuilder.getVoidPtrTy(),
668 cir::CastKind::bitcast, loweredAddress);
669 callArgs.push_back(deletePtr);
670 }
671
672 cir::CallOp::create(rewriter, loc, deleteFn, cir::VoidType(), callArgs);
673 rewriter.eraseOp(op);
674 return mlir::success();
675}
676
677mlir::LogicalResult CIRDerivedDataMemberOpABILowering::matchAndRewrite(
678 cir::DerivedDataMemberOp op, OpAdaptor adaptor,
679 mlir::ConversionPatternRewriter &rewriter) const {
680 mlir::Value loweredResult = lowerModule->getCXXABI().lowerDerivedDataMember(
681 op, adaptor.getSrc(), rewriter);
682 rewriter.replaceOp(op, loweredResult);
683 return mlir::success();
684}
685
686mlir::LogicalResult CIRDerivedMethodOpABILowering::matchAndRewrite(
687 cir::DerivedMethodOp op, OpAdaptor adaptor,
688 mlir::ConversionPatternRewriter &rewriter) const {
689 mlir::Value loweredResult = lowerModule->getCXXABI().lowerDerivedMethod(
690 op, adaptor.getSrc(), rewriter);
691 rewriter.replaceOp(op, loweredResult);
692 return mlir::success();
693}
694
695mlir::LogicalResult CIRDynamicCastOpABILowering::matchAndRewrite(
696 cir::DynamicCastOp op, OpAdaptor adaptor,
697 mlir::ConversionPatternRewriter &rewriter) const {
698 mlir::Value loweredResult =
699 lowerModule->getCXXABI().lowerDynamicCast(op, rewriter);
700 rewriter.replaceOp(op, loweredResult);
701 return mlir::success();
702}
703
704mlir::LogicalResult CIRGetMethodOpABILowering::matchAndRewrite(
705 cir::GetMethodOp op, OpAdaptor adaptor,
706 mlir::ConversionPatternRewriter &rewriter) const {
707 mlir::Value callee;
708 mlir::Value thisArg;
709 lowerModule->getCXXABI().lowerGetMethod(
710 op, callee, thisArg, adaptor.getMethod(), adaptor.getObject(), rewriter);
711 rewriter.replaceOp(op, {callee, thisArg});
712 return mlir::success();
713}
714
715mlir::LogicalResult CIRGetRuntimeMemberOpABILowering::matchAndRewrite(
716 cir::GetRuntimeMemberOp op, OpAdaptor adaptor,
717 mlir::ConversionPatternRewriter &rewriter) const {
718 mlir::Type resTy = getTypeConverter()->convertType(op.getType());
719 mlir::Operation *newOp = lowerModule->getCXXABI().lowerGetRuntimeMember(
720 op, resTy, adaptor.getAddr(), adaptor.getMember(), rewriter);
721 rewriter.replaceOp(op, newOp);
722 return mlir::success();
723}
724
725mlir::LogicalResult CIRVTableGetTypeInfoOpABILowering::matchAndRewrite(
726 cir::VTableGetTypeInfoOp op, OpAdaptor adaptor,
727 mlir::ConversionPatternRewriter &rewriter) const {
728 mlir::Value loweredResult =
729 lowerModule->getCXXABI().lowerVTableGetTypeInfo(op, rewriter);
730 rewriter.replaceOp(op, loweredResult);
731 return mlir::success();
732}
733
734namespace {
735// A small type to handle type conversion for the the CXXABILoweringPass.
736// Even though this is a CIR-to-CIR pass, we are eliminating some CIR types.
737// Most importantly, this pass solves recursive type conversion problems by
738// keeping a call stack.
739class CIRABITypeConverter : public mlir::TypeConverter {
740
741 mlir::MLIRContext &context;
742
743 // Recursive structure detection.
744 // We store one entry per thread here, and rely on locking. This works the
745 // same way as the LLVM-IR lowering does it, which has a similar problem.
746 DenseMap<uint64_t, std::unique_ptr<SmallVector<cir::RecordType>>>
747 conversionCallStack;
748 llvm::sys::SmartRWMutex<true> callStackMutex;
749
750 // In order to let us 'change the names' back after the fact, we collect them
751 // along the way. They should only be added/accessed via the thread-safe
752 // functions below.
753 llvm::SmallVector<cir::RecordType> convertedRecordTypes;
754 llvm::sys::SmartRWMutex<true> recordTypeMutex;
755
756 // This provides a stack for the RecordTypes being processed on the current
757 // thread, which lets us solve recursive conversions. This implementation is
758 // cribbed from the LLVMTypeConverter which solves a similar but not identical
759 // problem.
760 SmallVector<cir::RecordType> &getCurrentThreadRecursiveStack() {
761 {
762 // Most of the time, the entry already exists in the map.
763 std::shared_lock<decltype(callStackMutex)> lock(callStackMutex,
764 std::defer_lock);
765 if (context.isMultithreadingEnabled())
766 lock.lock();
767 auto recursiveStack = conversionCallStack.find(llvm::get_threadid());
768 if (recursiveStack != conversionCallStack.end())
769 return *recursiveStack->second;
770 }
771
772 // First time this thread gets here, we have to get an exclusive access to
773 // insert in the map
774 std::unique_lock<decltype(callStackMutex)> lock(callStackMutex);
775 auto recursiveStackInserted = conversionCallStack.insert(
776 std::make_pair(llvm::get_threadid(),
777 std::make_unique<SmallVector<cir::RecordType>>()));
778 return *recursiveStackInserted.first->second;
779 }
780
781 void addConvertedRecordType(cir::RecordType rt) {
782 std::unique_lock<decltype(recordTypeMutex)> lock(recordTypeMutex);
783 convertedRecordTypes.push_back(rt);
784 }
785
786 llvm::SmallVector<mlir::Type> convertRecordMemberTypes(cir::RecordType type) {
787 llvm::SmallVector<mlir::Type> loweredMemberTypes;
788 loweredMemberTypes.reserve(type.getNumElements());
789
790 if (mlir::failed(convertTypes(type.getMembers(), loweredMemberTypes)))
791 return {};
792
793 return loweredMemberTypes;
794 }
795
796 cir::RecordType convertRecordType(cir::RecordType type) {
797 // Unnamed record types can't be referred to recursively, so we can just
798 // convert this one. It also doesn't have uniqueness problems, so we can
799 // just do a conversion on it.
800 if (!type.getName())
801 return cir::RecordType::get(
802 type.getContext(), convertRecordMemberTypes(type), type.getPacked(),
803 type.getPadded(), type.getKind());
804
805 assert(!type.isIncomplete() || type.getMembers().empty());
806
807 // If the type has already been converted, we can just return, since there
808 // is nothing to do. Also, if it is incomplete, it can't have invalid
809 // members! So we can skip transforming it.
810 if (type.isIncomplete() || type.isABIConvertedRecord())
811 return type;
812
813 SmallVectorImpl<cir::RecordType> &recursiveStack =
814 getCurrentThreadRecursiveStack();
815
816 auto convertedType = cir::RecordType::get(
817 type.getContext(), type.getABIConvertedName(), type.getKind());
818
819 // This type has already been converted, just return it.
820 if (convertedType.isComplete())
821 return convertedType;
822
823 // We put the existing 'type' into the vector if we're in the process of
824 // converting it (and pop it when we're done). To prevent recursion,
825 // just return the 'incomplete' version, and the 'top level' version of this
826 // call will call 'complete' on it.
827 if (llvm::is_contained(recursiveStack, type))
828 return convertedType;
829
830 recursiveStack.push_back(type);
831 llvm::scope_exit popConvertingType(
832 [&recursiveStack]() { recursiveStack.pop_back(); });
833
834 SmallVector<mlir::Type> convertedMembers = convertRecordMemberTypes(type);
835
836 convertedType.complete(convertedMembers, type.getPacked(),
837 type.getPadded());
838 addConvertedRecordType(convertedType);
839 return convertedType;
840 }
841
842public:
843 CIRABITypeConverter(mlir::MLIRContext &ctx, mlir::DataLayout &dataLayout,
844 cir::LowerModule &lowerModule)
845 : context(ctx) {
846 addConversion([&](mlir::Type type) -> mlir::Type { return type; });
847 // This is necessary in order to convert CIR pointer types that are
848 // pointing to CIR types that we are lowering in this pass.
849 addConversion([&](cir::PointerType type) -> mlir::Type {
850 mlir::Type loweredPointeeType = convertType(type.getPointee());
851 if (!loweredPointeeType)
852 return {};
853 return cir::PointerType::get(type.getContext(), loweredPointeeType,
854 type.getAddrSpace());
855 });
856 addConversion([&](cir::ArrayType type) -> mlir::Type {
857 mlir::Type loweredElementType = convertType(type.getElementType());
858 if (!loweredElementType)
859 return {};
860 return cir::ArrayType::get(loweredElementType, type.getSize());
861 });
862
863 addConversion([&](cir::DataMemberType type) -> mlir::Type {
864 mlir::Type abiType =
865 lowerModule.getCXXABI().lowerDataMemberType(type, *this);
866 return convertType(abiType);
867 });
868 addConversion([&](cir::MethodType type) -> mlir::Type {
869 mlir::Type abiType = lowerModule.getCXXABI().lowerMethodType(type, *this);
870 return convertType(abiType);
871 });
872 // This is necessary in order to convert CIR function types that have
873 // argument or return types that use CIR types that we are lowering in
874 // this pass.
875 addConversion([&](cir::FuncType type) -> mlir::Type {
876 llvm::SmallVector<mlir::Type> loweredInputTypes;
877 loweredInputTypes.reserve(type.getNumInputs());
878 if (mlir::failed(convertTypes(type.getInputs(), loweredInputTypes)))
879 return {};
880
881 mlir::Type loweredReturnType = convertType(type.getReturnType());
882 if (!loweredReturnType)
883 return {};
884
885 return cir::FuncType::get(loweredInputTypes, loweredReturnType,
886 /*isVarArg=*/type.getVarArg());
887 });
888 addConversion([&](cir::RecordType type) -> mlir::Type {
889 return convertRecordType(type);
890 });
891 }
892
893 void restoreRecordTypeNames() {
894 std::unique_lock<decltype(recordTypeMutex)> lock(recordTypeMutex);
895
896 for (auto rt : convertedRecordTypes)
897 rt.removeABIConversionNamePrefix();
898 }
899};
900} // namespace
901
902static void
903populateCXXABIConversionTarget(mlir::ConversionTarget &target,
904 const mlir::TypeConverter &typeConverter) {
905 target.addLegalOp<mlir::ModuleOp>();
906
907 // The ABI lowering pass is interested in CIR operations with operands or
908 // results of CXXABI-dependent types, or CIR operations with regions whose
909 // block arguments are of CXXABI-dependent types.
910 target.addDynamicallyLegalDialect<cir::CIRDialect>(
911 [&typeConverter](mlir::Operation *op) {
912 if (!typeConverter.isLegal(op))
913 return false;
914
915 bool attrs = llvm::all_of(
916 op->getAttrs(), [&typeConverter](const mlir::NamedAttribute &a) {
917 return isCXXABIAttributeLegal(typeConverter, a.getValue());
918 });
919
920 return attrs &&
921 std::all_of(op->getRegions().begin(), op->getRegions().end(),
922 [&typeConverter](mlir::Region &region) {
923 return typeConverter.isLegal(&region);
924 });
925 });
926
927 target.addDynamicallyLegalDialect<mlir::acc::OpenACCDialect>(
928 [&typeConverter](mlir::Operation *op) {
929 if (!typeConverter.isLegal(op))
930 return false;
931
932 bool attrs = llvm::all_of(
933 op->getAttrs(), [&typeConverter](const mlir::NamedAttribute &a) {
934 return isCXXABIAttributeLegal(typeConverter, a.getValue());
935 });
936
937 return attrs &&
938 std::all_of(op->getRegions().begin(), op->getRegions().end(),
939 [&typeConverter](mlir::Region &region) {
940 return typeConverter.isLegal(&region);
941 });
942 });
943
944 // Some CIR ops needs special checking for legality
945 target.addDynamicallyLegalOp<cir::FuncOp>([&typeConverter](cir::FuncOp op) {
946 bool attrs = llvm::all_of(
947 op->getAttrs(), [&typeConverter](const mlir::NamedAttribute &a) {
948 return isCXXABIAttributeLegal(typeConverter, a.getValue());
949 });
950
951 return attrs && typeConverter.isLegal(op.getFunctionType());
952 });
953 target.addDynamicallyLegalOp<cir::GlobalOp>(
954 [&typeConverter](cir::GlobalOp op) {
955 return typeConverter.isLegal(op.getSymType());
956 });
957 // Operations that do not use any special types must be explicitly marked as
958 // illegal to trigger processing here.
959 target.addIllegalOp<cir::DeleteArrayOp>();
960 target.addIllegalOp<cir::DynamicCastOp>();
961 target.addIllegalOp<cir::VTableGetTypeInfoOp>();
962}
963
964//===----------------------------------------------------------------------===//
965// The Pass
966//===----------------------------------------------------------------------===//
967
968// The applyPartialConversion function traverses blocks in the dominance order,
969// so it does not lower and operations that are not reachachable from the
970// operations passed in as arguments. Since we do need to lower such code in
971// order to avoid verification errors occur, we cannot just pass the module op
972// to applyPartialConversion. We must build a set of unreachable ops and
973// explicitly add them, along with the module, to the vector we pass to
974// applyPartialConversion.
975//
976// For instance, this CIR code:
977//
978// cir.func @foo(%arg0: !s32i) -> !s32i {
979// %4 = cir.cast int_to_bool %arg0 : !s32i -> !cir.bool
980// cir.if %4 {
981// %5 = cir.const #cir.int<1> : !s32i
982// cir.return %5 : !s32i
983// } else {
984// %5 = cir.const #cir.int<0> : !s32i
985// cir.return %5 : !s32i
986// }
987// cir.return %arg0 : !s32i
988// }
989//
990// contains an unreachable return operation (the last one). After the CXXABI
991// pass it will be placed into the unreachable block. This will error because
992// it will have not converted the types in the block, making the legalizer fail.
993//
994// In the future we may want to get rid of this function and use a DCE pass or
995// something similar. But for now we need to guarantee the absence of the
996// dialect verification errors. Note: We do the same in LowerToLLVM as well,
997// this is a striaght copy/paste including most of the comment. We might wi sh
998// to combine these if we don't want to do a DCE pass/etc.
999static void collectUnreachable(mlir::Operation *parent,
1001
1002 llvm::SmallVector<mlir::Block *> unreachableBlocks;
1003 parent->walk([&](mlir::Block *blk) { // check
1004 if (blk->hasNoPredecessors() && !blk->isEntryBlock())
1005 unreachableBlocks.push_back(blk);
1006 });
1007
1008 std::set<mlir::Block *> visited;
1009 for (mlir::Block *root : unreachableBlocks) {
1010 // We create a work list for each unreachable block.
1011 // Thus we traverse operations in some order.
1012 std::deque<mlir::Block *> workList;
1013 workList.push_back(root);
1014
1015 while (!workList.empty()) {
1016 mlir::Block *blk = workList.back();
1017 workList.pop_back();
1018 if (visited.count(blk))
1019 continue;
1020 visited.emplace(blk);
1021
1022 for (mlir::Operation &op : *blk)
1023 ops.push_back(&op);
1024
1025 for (mlir::Block *succ : blk->getSuccessors())
1026 workList.push_back(succ);
1027 }
1028 }
1029}
1030
1031void CXXABILoweringPass::runOnOperation() {
1032 auto mod = mlir::cast<mlir::ModuleOp>(getOperation());
1033 mlir::MLIRContext *ctx = mod.getContext();
1034
1035 std::unique_ptr<cir::LowerModule> lowerModule = cir::createLowerModule(mod);
1036 // If lower module is not available, skip the ABI lowering pass.
1037 if (!lowerModule) {
1038 mod.emitWarning("Cannot create a CIR lower module, skipping the ")
1039 << getName() << " pass";
1040 return;
1041 }
1042
1043 mlir::DataLayout dataLayout(mod);
1044 CIRABITypeConverter typeConverter(*ctx, dataLayout, *lowerModule);
1045
1046 mlir::RewritePatternSet patterns(ctx);
1047 patterns.add<CIRGenericCXXABILoweringPattern>(patterns.getContext(),
1048 typeConverter);
1049 patterns.add<
1050#define GET_ABI_LOWERING_PATTERNS_LIST
1051#include "clang/CIR/Dialect/IR/CIRLowering.inc"
1052#undef GET_ABI_LOWERING_PATTERNS_LIST
1053 >(patterns.getContext(), typeConverter, dataLayout, *lowerModule);
1054
1055 mlir::ConversionTarget target(*ctx);
1056 populateCXXABIConversionTarget(target, typeConverter);
1057
1058 llvm::SmallVector<mlir::Operation *> ops;
1059 ops.push_back(mod);
1060 collectUnreachable(mod, ops);
1061
1062 if (failed(mlir::applyPartialConversion(ops, target, std::move(patterns))))
1063 signalPassFailure();
1064
1065 typeConverter.restoreRecordTypeNames();
1066}
1067
1068std::unique_ptr<Pass> mlir::createCXXABILoweringPass() {
1069 return std::make_unique<CXXABILoweringPass>();
1070}
#define CXX_ABI_ALWAYS_LEGAL_ATTRS
static void collectUnreachable(mlir::Operation *parent, llvm::SmallVector< mlir::Operation * > &ops)
static void populateCXXABIConversionTarget(mlir::ConversionTarget &target, const mlir::TypeConverter &typeConverter)
static mlir::TypedAttr lowerInitialValue(const LowerModule *lowerModule, const mlir::DataLayout &layout, const mlir::TypeConverter &tc, mlir::Type ty, mlir::Attribute initVal)
__device__ __2f16 b
virtual mlir::Type lowerMethodType(cir::MethodType type, const mlir::TypeConverter &typeConverter) const =0
Lower the given member function pointer type to its ABI type.
void readArrayCookie(mlir::Location loc, mlir::Value elementPtr, const mlir::DataLayout &dataLayout, CIRBaseBuilderTy &builder, mlir::Value &numElements, mlir::Value &allocPtr, clang::CharUnits &cookieSize) const
Read the array cookie for a dynamically-allocated array whose first element is at elementPtr.
Definition CIRCXXABI.cpp:25
virtual mlir::TypedAttr lowerDataMemberConstant(cir::DataMemberAttr attr, const mlir::DataLayout &layout, const mlir::TypeConverter &typeConverter) const =0
Lower the given data member pointer constant to a constant of the ABI type.
virtual mlir::TypedAttr lowerMethodConstant(cir::MethodAttr attr, const mlir::DataLayout &layout, const mlir::TypeConverter &typeConverter) const =0
Lower the given member function pointer constant to a constant of the ABI type.
virtual mlir::Type lowerDataMemberType(cir::DataMemberType type, const mlir::TypeConverter &typeConverter) const =0
Lower the given data member pointer type to its ABI type.
CIRCXXABI & getCXXABI() const
Definition LowerModule.h:46
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition CharUnits.h:185
std::unique_ptr< LowerModule > createLowerModule(mlir::ModuleOp module)
const internal::VariadicAllOfMatcher< Attr > attr
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
StringRef getName(const HeaderType T)
Definition HeaderFile.h:38
RangeSelector callArgs(std::string ID)
bool isa(CodeGen::Address addr)
Definition Address.h:330
std::unique_ptr< Pass > createCXXABILoweringPass()
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)