Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][Codegen] Fixes global variables that point to another globals #1277

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
handle const arrays
  • Loading branch information
gitoleg committed Jan 29, 2025
commit 089364d1ecc4c8ecdd9916fa96360e9fa22e27e5
14 changes: 13 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,22 @@ void CIRGenModule::replaceGlobal(cir::GlobalOp Old, cir::GlobalOp New) {
changeType(GGO);
} else if (auto glob = dyn_cast<cir::GlobalOp>(UserOp)) {
if (auto init = glob.getInitialValue()) {
if (auto attr = mlir::dyn_cast<cir::GlobalViewAttr>(init.value())) {
if (auto attr = mlir::dyn_cast<cir::GlobalViewAttr>(init.value())) {

auto view = createNewGlobalView(*this, attr, OldTy, New);
glob.setInitialValueAttr(view);
} else if (auto attr = mlir::dyn_cast<ConstArrayAttr>(init.value())) {

llvm::SmallVector<mlir::Attribute> newArray;
auto eltsAttr = dyn_cast<mlir::ArrayAttr>(attr.getElts());
for (auto elt : eltsAttr) {
if (auto view = dyn_cast<GlobalViewAttr>(elt)) {
newArray.push_back(createNewGlobalView(*this, view, OldTy, New));
}
}
mlir::Attribute ar = mlir::ArrayAttr::get(builder.getContext(), newArray);
auto newAr = builder.getConstArray(ar, cast<cir::ArrayType>(attr.getType()));
glob.setInitialValueAttr(newAr);
}
}
}
Expand Down