https://github.com/bviyer created https://github.com/llvm/llvm-project/pull/238117
Set a `cir.sycl_device` module attribute in CIRGenModule when `LangOpts.SYCLIsDevice` and lower it to an LLVM `sycl-device` module flag. This lets consumer of hte emitted IR distinguish SYCL device modules from host modules. >From c3dadb2efec7858b3d95057ac3ec44424eb82c10 Mon Sep 17 00:00:00 2001 From: "Balaji V. Iyer" <[email protected]> Date: Mon, 2 Nov 2026 13:43:10 -0800 Subject: [PATCH] Init commit --- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 3 +++ clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 11904c58f82350..3a3a80935f0404 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -164,6 +164,9 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext, spirMajor > 1 ? 0 : 2)); } } + if (langOpts.SYCLIsDevice) + getModule()->setAttr("cir.sycl_device", builder.getI32IntegerAttr(1)); + getModule()->setAttr(cir::CIRDialect::getTripleAttrName(), builder.getStringAttr(getTriple().str())); getModule()->setAttr(cir::CIRDialect::getTargetABIAttrName(), diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp index 2b80606fea6138..78e1fc86d9079b 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVMIR.cpp @@ -219,6 +219,14 @@ class CIRDialectLLVMIRTranslationInterface } } + if (attribute.getName() == "cir.sycl_device") { + if (auto intAttr = + mlir::dyn_cast<mlir::IntegerAttr>(attribute.getValue())) { + llvmModule->addModuleFlag(llvm::Module::Error, "sycl-device", + static_cast<uint32_t>(intAttr.getInt())); + } + } + return mlir::success(); } }; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
