Skip to content

Commit

Permalink
[CIR][CodeGen][NFC] Rename the confusing buildGlobal overload (llvm…
Browse files Browse the repository at this point in the history
…#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)`
  • Loading branch information
seven-mile authored and lanza committed Oct 2, 2024
1 parent f6eb060 commit aee3d23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<mlir::cir::GetGlobalOp>(
getLoc(D->getSourceRange()), ptrTy, g.getSymName(), tlsAccess);
Expand All @@ -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);
}

Expand Down Expand Up @@ -1232,7 +1233,7 @@ void CIRGenModule::buildGlobalVarDefinition(const clang::VarDecl *D,
}
assert(!mlir::isa<mlir::NoneType>(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
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aee3d23

Please sign in to comment.