From 3f47ff4fca9b647c4dd383901695ed9cb6f00af1 Mon Sep 17 00:00:00 2001 From: 7mile Date: Tue, 1 Oct 2024 05:53:14 +0800 Subject: [PATCH] [CIR][CodeGen][NFC] Rename the confusing `buildGlobal` overload (#897) `CIRGenModule::buildGlobal` --[rename]--> `CIRGenModule::getOrCreateCIRGlobal` We already have `CIRGenModule::buildGlobal` that corresponds to `CodeGenModule::EmitGlobal`. But there is an overload of `buildGlobal` used by `getAddrOfGlobalVar`. Since this name is confusing, this PR rename it to `getOrCreateCIRGlobal`. Note that `getOrCreateCIRGlobal` already exists. It is intentional to make the renamed function an overload to it. The reason here is that the renamed function is basically a wrapper of the original `getOrCreateCIRGlobal` with more specific parameters: `getOrCreateCIRGlobal(decl, type, isDef)` --[call]--> `getOrCreateCIRGlobal(getMangledName(decl), type, decl->getType()->getAS(), decl, isDef)` --- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 11 ++++++----- clang/lib/CIR/CodeGen/CIRGenModule.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 2072a332c6b1..76bad240e9c5 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1003,8 +1003,9 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef MangledName, mlir::Type Ty, return GV; } -mlir::cir::GlobalOp CIRGenModule::buildGlobal(const VarDecl *D, mlir::Type Ty, - ForDefinition_t IsForDefinition) { +mlir::cir::GlobalOp +CIRGenModule::getOrCreateCIRGlobal(const VarDecl *D, mlir::Type Ty, + ForDefinition_t IsForDefinition) { assert(D->hasGlobalStorage() && "Not a global variable"); QualType ASTTy = D->getType(); if (!Ty) @@ -1029,7 +1030,7 @@ mlir::Value CIRGenModule::getAddrOfGlobalVar(const VarDecl *D, mlir::Type Ty, Ty = getTypes().convertTypeForMem(ASTTy); bool tlsAccess = D->getTLSKind() != VarDecl::TLS_None; - auto g = buildGlobal(D, Ty, IsForDefinition); + auto g = getOrCreateCIRGlobal(D, Ty, IsForDefinition); auto ptrTy = builder.getPointerTo(g.getSymType(), g.getAddrSpaceAttr()); return builder.create( getLoc(D->getSourceRange()), ptrTy, g.getSymName(), tlsAccess); @@ -1043,7 +1044,7 @@ CIRGenModule::getAddrOfGlobalVarAttr(const VarDecl *D, mlir::Type Ty, if (!Ty) Ty = getTypes().convertTypeForMem(ASTTy); - auto globalOp = buildGlobal(D, Ty, IsForDefinition); + auto globalOp = getOrCreateCIRGlobal(D, Ty, IsForDefinition); return builder.getGlobalViewAttr(builder.getPointerTo(Ty), globalOp); } @@ -1232,7 +1233,7 @@ void CIRGenModule::buildGlobalVarDefinition(const clang::VarDecl *D, } assert(!mlir::isa(InitType) && "Should have a type by now"); - auto Entry = buildGlobal(D, InitType, ForDefinition_t(!IsTentative)); + auto Entry = getOrCreateCIRGlobal(D, InitType, ForDefinition_t(!IsTentative)); // TODO(cir): Strip off pointer casts from Entry if we get them? // TODO(cir): use GlobalValue interface diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index b980ed411c41..b652ec4f9ef7 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -234,7 +234,7 @@ class CIRGenModule : public CIRGenTypeCache { getOrCreateStaticVarDecl(const VarDecl &D, mlir::cir::GlobalLinkageKind Linkage); - mlir::cir::GlobalOp buildGlobal(const VarDecl *D, mlir::Type Ty, + mlir::cir::GlobalOp getOrCreateCIRGlobal(const VarDecl *D, mlir::Type Ty, ForDefinition_t IsForDefinition); /// TODO(cir): once we have cir.module, add this as a convenience method