[clang] [clang][CIR] Change buildX functions to emitX (PR #115568)

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 8 15:53:59 PST 2024


https://github.com/smeenai created https://github.com/llvm/llvm-project/pull/115568

The buildX naming convention originated when the CIRGen implementation
was planned to be substantially different from original CodeGen. CIRGen
is now a much closer adaption of CodeGen, and the emitX to buildX
renaming just makes things more confusing, since CodeGen also has some
helper functions whose names start with build or Build, so it's not
immediately clear which CodeGen function corresponds to a CIRGen buildX
function. Rename the buildX functions back to emitX to fix this.

>From b15d7eb3d800284f2adce45d99cf2ee01e77d7a2 Mon Sep 17 00:00:00 2001
From: Shoaib Meenai <smeenai at fb.com>
Date: Fri, 8 Nov 2024 15:51:29 -0800
Subject: [PATCH] [clang][CIR] Change buildX functions to emitX

The buildX naming convention originated when the CIRGen implementation
was planned to be substantially different from original CodeGen. CIRGen
is now a much closer adaption of CodeGen, and the emitX to buildX
renaming just makes things more confusing, since CodeGen also has some
helper functions whose names start with build or Build, so it's not
immediately clear which CodeGen function corresponds to a CIRGen buildX
function. Rename the buildX functions back to emitX to fix this.
---
 clang/lib/CIR/CodeGen/CIRGenModule.cpp | 20 ++++++++++----------
 clang/lib/CIR/CodeGen/CIRGenModule.h   | 10 +++++-----
 clang/lib/CIR/CodeGen/CIRGenerator.cpp |  2 +-
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 4e8a8cc3f4c524..5963d43bb9672f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -50,7 +50,7 @@ mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
   return mlir::FusedLoc::get({begin, end}, metadata, builder.getContext());
 }
 
-void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
+void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
   const auto *global = cast<ValueDecl>(gd.getDecl());
 
   if (const auto *fd = dyn_cast<FunctionDecl>(global)) {
@@ -71,19 +71,19 @@ void CIRGenModule::buildGlobal(clang::GlobalDecl gd) {
   }
 
   // TODO(CIR): Defer emitting some global definitions until later
-  buildGlobalDefinition(gd);
+  emitGlobalDefinition(gd);
 }
 
-void CIRGenModule::buildGlobalFunctionDefinition(clang::GlobalDecl gd,
-                                                 mlir::Operation *op) {
+void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd,
+                                                mlir::Operation *op) {
   auto const *funcDecl = cast<FunctionDecl>(gd.getDecl());
   auto funcOp = builder.create<cir::FuncOp>(
       getLoc(funcDecl->getSourceRange()), funcDecl->getIdentifier()->getName());
   theModule.push_back(funcOp);
 }
 
-void CIRGenModule::buildGlobalDefinition(clang::GlobalDecl gd,
-                                         mlir::Operation *op) {
+void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl gd,
+                                        mlir::Operation *op) {
   const auto *decl = cast<ValueDecl>(gd.getDecl());
   if (const auto *fd = dyn_cast<FunctionDecl>(decl)) {
     // TODO(CIR): Skip generation of CIR for functions with available_externally
@@ -99,15 +99,15 @@ void CIRGenModule::buildGlobalDefinition(clang::GlobalDecl gd,
 
     if (fd->isMultiVersion())
       errorNYI(fd->getSourceRange(), "multiversion functions");
-    buildGlobalFunctionDefinition(gd, op);
+    emitGlobalFunctionDefinition(gd, op);
     return;
   }
 
-  llvm_unreachable("Invalid argument to CIRGenModule::buildGlobalDefinition");
+  llvm_unreachable("Invalid argument to CIRGenModule::emitGlobalDefinition");
 }
 
 // Emit code for a single top level declaration.
-void CIRGenModule::buildTopLevelDecl(Decl *decl) {
+void CIRGenModule::emitTopLevelDecl(Decl *decl) {
 
   // Ignore dependent declarations.
   if (decl->isTemplated())
@@ -123,7 +123,7 @@ void CIRGenModule::buildTopLevelDecl(Decl *decl) {
     auto *fd = cast<FunctionDecl>(decl);
     // Consteval functions shouldn't be emitted.
     if (!fd->isConsteval())
-      buildGlobal(fd);
+      emitGlobal(fd);
     break;
   }
   }
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h
index 9e5950ff71c528..aaded92e6a633e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.h
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.h
@@ -72,15 +72,15 @@ class CIRGenModule : public CIRGenTypeCache {
   mlir::Location getLoc(clang::SourceLocation cLoc);
   mlir::Location getLoc(clang::SourceRange cRange);
 
-  void buildTopLevelDecl(clang::Decl *decl);
+  void emitTopLevelDecl(clang::Decl *decl);
 
   /// Emit code for a single global function or variable declaration. Forward
   /// declarations are emitted lazily.
-  void buildGlobal(clang::GlobalDecl gd);
+  void emitGlobal(clang::GlobalDecl gd);
 
-  void buildGlobalDefinition(clang::GlobalDecl gd,
-                             mlir::Operation *op = nullptr);
-  void buildGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
+  void emitGlobalDefinition(clang::GlobalDecl gd,
+                            mlir::Operation *op = nullptr);
+  void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
 
   /// Helpers to emit "not yet implemented" error diagnostics
   DiagnosticBuilder errorNYI(llvm::StringRef);
diff --git a/clang/lib/CIR/CodeGen/CIRGenerator.cpp b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
index 85367a916ef783..8f3370c0041afe 100644
--- a/clang/lib/CIR/CodeGen/CIRGenerator.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenerator.cpp
@@ -45,7 +45,7 @@ mlir::ModuleOp CIRGenerator::getModule() const { return cgm->getModule(); }
 bool CIRGenerator::HandleTopLevelDecl(DeclGroupRef group) {
 
   for (Decl *decl : group)
-    cgm->buildTopLevelDecl(decl);
+    cgm->emitTopLevelDecl(decl);
 
   return true;
 }



More information about the cfe-commits mailing list