[llvm-branch-commits] [clang] [CIR] Add InlineAsmOp lowering to LLVM (PR #153387)
Morris Hafner via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Aug 14 07:22:44 PDT 2025
================
@@ -2896,6 +2898,68 @@ mlir::LogicalResult CIRToLLVMGetBitfieldOpLowering::matchAndRewrite(
return mlir::success();
}
+mlir::LogicalResult CIRToLLVMInlineAsmOpLowering::matchAndRewrite(
+ cir::InlineAsmOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ mlir::Type llResTy;
+ if (op.getNumResults())
+ llResTy = getTypeConverter()->convertType(op.getType(0));
+
+ cir::AsmFlavor dialect = op.getAsmFlavor();
+ mlir::LLVM::AsmDialect llDialect = dialect == cir::AsmFlavor::x86_att
+ ? mlir::LLVM::AsmDialect::AD_ATT
+ : mlir::LLVM::AsmDialect::AD_Intel;
+
+ SmallVector<mlir::Attribute> opAttrs;
+ StringRef llvmAttrName = mlir::LLVM::InlineAsmOp::getElementTypeAttrName();
+
+ // this is for the lowering to LLVM from LLVM dialect. Otherwise, if we
+ // don't have the result (i.e. void type as a result of operation), the
+ // element type attribute will be attached to the whole instruction, but not
+ // to the operand
+ if (!op.getNumResults())
+ opAttrs.push_back(mlir::Attribute());
+
+ SmallVector<mlir::Value> llvmOperands;
+ SmallVector<mlir::Value> cirOperands;
+ for (auto [llvmOp, cirOp] :
+ llvm::zip(adaptor.getAsmOperands(), op.getAsmOperands())) {
+ llvmOperands.append(llvmOp.begin(), llvmOp.end());
+ cirOperands.append(cirOp.begin(), cirOp.end());
----------------
mmha wrote:
```suggestion
append_range(llvmOperands, llvmOp);
append_range(cirOperands, cirOp);
```
https://github.com/llvm/llvm-project/pull/153387
More information about the llvm-branch-commits
mailing list