Skip to content

[CIR][Lowering][TBAA] distinct C and C++ #1406

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 9 additions & 3 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace direct {

class CIRToLLVMTBAAAttrLowering {
public:
CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext)
: mlirContext(mlirContext) {}
CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext, bool isCPlusPlus)
: mlirContext(mlirContext), isCPlusPlus(isCPlusPlus) {}

mlir::LLVM::TBAATypeDescriptorAttr
lowerCIRTBAAAttrToLLVMTBAAAttr(mlir::Attribute tbaa) {
Expand Down Expand Up @@ -44,6 +44,9 @@ class CIRToLLVMTBAAAttrLowering {

private:
mlir::LLVM::TBAARootAttr getRoot() {
if (isCPlusPlus)
return createTBAARoot("Simple C++ TBAA");

return createTBAARoot("Simple C/C++ TBAA");
}

Expand All @@ -67,13 +70,16 @@ class CIRToLLVMTBAAAttrLowering {
}

mlir::MLIRContext *mlirContext;
bool isCPlusPlus;
};

mlir::ArrayAttr lowerCIRTBAAAttr(mlir::Attribute tbaa,
mlir::ConversionPatternRewriter &rewriter,
cir::LowerModule *lowerMod) {
auto *ctx = rewriter.getContext();
CIRToLLVMTBAAAttrLowering lower(ctx);
auto langAttr = mlir::cast<cir::LangAttr>(
lowerMod->getModule()->getAttr(cir::CIRDialect::getLangAttrName()));
CIRToLLVMTBAAAttrLowering lower(ctx, langAttr.isCXX());
if (auto tbaaTag = mlir::dyn_cast<cir::TBAATagAttr>(tbaa)) {
mlir::LLVM::TBAATypeDescriptorAttr accessType =
lower.lowerCIRTBAAAttrToLLVMTBAAAttr(tbaaTag.getAccess());
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4739,8 +4739,6 @@ void ConvertCIRToLLVMPass::runOnOperation() {
// Allow operations that will be lowered directly to LLVM IR.
target.addLegalOp<mlir::LLVM::ZeroOp>();

processCIRAttrs(module);

llvm::SmallVector<mlir::Operation *> ops;
ops.push_back(module);
collect_unreachable(module, ops);
Expand All @@ -4767,6 +4765,8 @@ void ConvertCIRToLLVMPass::runOnOperation() {
dtorAttr.getPriority());
});
buildGlobalAnnotationsVar(stringGlobalsMap, argStringGlobalsMap, argsVarMap);

processCIRAttrs(module);
}

std::unique_ptr<mlir::Pass> createConvertCIRToLLVMPass() {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/tbaa-struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) {
// OLD-PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
// OLD-PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0}
// OLD-PATH: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
// OLD-PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
// OLD-PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
// OLD-PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]
Expand Down
Loading