================ @@ -1394,13 +1501,84 @@ mlir::Value CIRGenFunction::createDummyValue(mlir::Location loc, return builder.createDummyValue(loc, t, alignment); } -/// This creates an alloca and inserts it into the entry block if -/// \p insertIntoFnEntryBlock is true, otherwise it inserts it at the current -/// insertion point of the builder. +//===----------------------------------------------------------------------===// +// CIR builder helpers +//===----------------------------------------------------------------------===// + +Address CIRGenFunction::createMemTemp(QualType ty, mlir::Location loc, + const Twine &name, Address *alloca, + mlir::OpBuilder::InsertPoint ip) { + // FIXME: Should we prefer the preferred type alignment here? + return createMemTemp(ty, getContext().getTypeAlignInChars(ty), loc, name, + alloca, ip); +} + +Address CIRGenFunction::createMemTemp(QualType ty, CharUnits align, + mlir::Location loc, const Twine &name, + Address *alloca, + mlir::OpBuilder::InsertPoint ip) { + Address result = createTempAlloca(convertTypeForMem(ty), align, loc, name, + /*ArraySize=*/nullptr, alloca, ip); + if (ty->isConstantMatrixType()) { + assert(!cir::MissingFeatures::matrixType()); + cgm.errorNYI(loc, "temporary matrix value"); + } + return result; +} + +/// This creates a alloca and inserts it into the entry block of the +/// current region. +Address CIRGenFunction::createTempAllocaWithoutCast( + mlir::Type ty, CharUnits align, mlir::Location loc, const Twine &name, + mlir::Value arraySize, mlir::OpBuilder::InsertPoint ip) { + cir::AllocaOp alloca = ip.isSet() + ? createTempAlloca(ty, loc, name, ip, arraySize) + : createTempAlloca(ty, loc, name, arraySize); + alloca.setAlignmentAttr(cgm.getSize(align)); + return Address(alloca, ty, align); +} + +/// This creates a alloca and inserts it into the entry block. The alloca is +/// casted to default address space if necessary. Address CIRGenFunction::createTempAlloca(mlir::Type ty, CharUnits align, mlir::Location loc, const Twine &name, - bool insertIntoFnEntryBlock) { - mlir::Value alloca = - emitAlloca(name.str(), ty, loc, align, insertIntoFnEntryBlock); - return Address(alloca, ty, align); + mlir::Value arraySize, + Address *allocaAddr, + mlir::OpBuilder::InsertPoint ip) { + Address alloca = + createTempAllocaWithoutCast(ty, align, loc, name, arraySize, ip); + if (allocaAddr) + *allocaAddr = alloca; + mlir::Value v = alloca.getPointer(); + // Alloca always returns a pointer in alloca address space, which may + // be different from the type defined by the language. For example, + // in C++ the auto variables are in the default address space. Therefore + // cast alloca to the default address space when necessary. + assert(!cir::MissingFeatures::addressSpace()); + return Address(v, ty, align); +} + +/// This creates an alloca and inserts it into the entry block if \p ArraySize +/// is nullptr, otherwise inserts it at the current insertion point of the +/// builder. +cir::AllocaOp CIRGenFunction::createTempAlloca(mlir::Type ty, + mlir::Location loc, + const Twine &name, + mlir::Value arraySize, + bool insertIntoFnEntryBlock) { + return cast<cir::AllocaOp>(emitAlloca(name.str(), ty, loc, CharUnits(), ---------------- andykaylor wrote:
It seems like this should be doing something to get the alignment based on the type. Looking at the equivalent classic codegen, if `CreateTempAlloca` is called without explicit alignment, it calls `IRBuilder::CreateAlloca`, which uses `DataLayout::getPrefTypeAlign()` to set the alignment. https://github.com/llvm/llvm-project/pull/138156 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits