Author: Erich Keane
Date: 2026-10-15T19:01:48Z
New Revision: 55ce745e2a91ef3003cdab50274674d412bdd94c

URL: 
https://github.com/llvm/llvm-project/commit/55ce745e2a91ef3003cdab50274674d412bdd94c
DIFF: 
https://github.com/llvm/llvm-project/commit/55ce745e2a91ef3003cdab50274674d412bdd94c.diff

LOG: [CIR]  Only load ACC/OMP dialect if they are enabled. (#232434)

This reduces the overall instr count of a ClangIR build without these
languages by ~6%, which seems worth-while.

We DID have to unconditionally load the LLVMDialect, as we previously
were only getting it via the OpenACC dialect transitively.

Added: 
    

Modified: 
    clang/lib/CIR/CodeGen/CIRGenerator.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp 
b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index c853daac8708e..bc0aed0b01ff0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -13,6 +13,7 @@
 #include "CIRGenModule.h"
 
 #include "mlir/Dialect/DLTI/DLTI.h"
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/OpenACC/OpenACC.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/MLIRContext.h"
@@ -50,9 +51,13 @@ void CIRGenerator::Initialize(ASTContext &astContext) {
   // MLIR multithreading stays enabled; the CIRDiagnosticHandler is only ever
   // invoked from a single thread.
   cir::registerAllDialects(*mlirContext);
-  mlirContext->loadDialect<mlir::DLTIDialect, cir::CIRDialect>();
-  mlirContext->getOrLoadDialect<mlir::acc::OpenACCDialect>();
-  mlirContext->getOrLoadDialect<mlir::omp::OpenMPDialect>();
+  mlirContext->loadDialect<mlir::DLTIDialect, mlir::LLVM::LLVMDialect,
+                           cir::CIRDialect>();
+  const LangOptions &langOpts = astContext.getLangOpts();
+  if (langOpts.OpenACC)
+    mlirContext->getOrLoadDialect<mlir::acc::OpenACCDialect>();
+  if (langOpts.OpenMP)
+    mlirContext->getOrLoadDialect<mlir::omp::OpenMPDialect>();
 
   cgm = std::make_unique<clang::CIRGen::CIRGenModule>(
       *mlirContext.get(), astContext, codeGenOpts, diags);


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to