Skip to content

Commit cfeeb8d

Browse files
committed
[CIR][Lowering][TBAA] distinct C and C++
1 parent 2ab0704 commit cfeeb8d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "mlir/IR/Attributes.h"
2424
#include "mlir/IR/BuiltinAttributes.h"
2525
#include "mlir/IR/PatternMatch.h"
26+
#include "mlir/Support/LLVM.h"
2627
#include "mlir/Support/LogicalResult.h"
2728
#include "clang/CIR/Target/AArch64.h"
2829
#include "llvm/Support/ErrorHandling.h"
@@ -242,6 +243,12 @@ createLowerModule(mlir::ModuleOp module, mlir::PatternRewriter &rewriter) {
242243
// Create context.
243244
cir_cconv_assert(!cir::MissingFeatures::langOpts());
244245
clang::LangOptions langOpts;
246+
if (auto langAttr = mlir::cast_if_present<cir::LangAttr>(
247+
module->getAttr(cir::CIRDialect::getLangAttrName()))) {
248+
if (langAttr.isCXX()) {
249+
langOpts.CPlusPlus = true;
250+
}
251+
}
245252

246253
// FIXME(cir): This just uses the default code generation options. We need to
247254
// account for custom options.

clang/lib/CIR/Lowering/DirectToLLVM/LowerTBAAToLLVM.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace direct {
1414

1515
class CIRToLLVMTBAAAttrLowering {
1616
public:
17-
CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext)
18-
: mlirContext(mlirContext) {}
17+
CIRToLLVMTBAAAttrLowering(mlir::MLIRContext *mlirContext, bool isCPlusPlus)
18+
: mlirContext(mlirContext), isCPlusPlus(isCPlusPlus) {}
1919

2020
mlir::LLVM::TBAATypeDescriptorAttr
2121
lowerCIRTBAAAttrToLLVMTBAAAttr(mlir::Attribute tbaa) {
@@ -44,7 +44,11 @@ class CIRToLLVMTBAAAttrLowering {
4444

4545
private:
4646
mlir::LLVM::TBAARootAttr getRoot() {
47-
return createTBAARoot("Simple C/C++ TBAA");
47+
if (isCPlusPlus) {
48+
return createTBAARoot("Simple C++ TBAA");
49+
} else {
50+
return createTBAARoot("Simple C/C++ TBAA");
51+
}
4852
}
4953

5054
mlir::LLVM::TBAATypeDescriptorAttr getChar() {
@@ -67,13 +71,15 @@ class CIRToLLVMTBAAAttrLowering {
6771
}
6872

6973
mlir::MLIRContext *mlirContext;
74+
bool isCPlusPlus;
7075
};
7176

7277
mlir::ArrayAttr lowerCIRTBAAAttr(mlir::Attribute tbaa,
7378
mlir::ConversionPatternRewriter &rewriter,
7479
cir::LowerModule *lowerMod) {
7580
auto *ctx = rewriter.getContext();
76-
CIRToLLVMTBAAAttrLowering lower(ctx);
81+
CIRToLLVMTBAAAttrLowering lower(
82+
ctx, lowerMod->getContext().getLangOpts().CPlusPlus);
7783
if (auto tbaaTag = mlir::dyn_cast<cir::TBAATagAttr>(tbaa)) {
7884
mlir::LLVM::TBAATypeDescriptorAttr accessType =
7985
lower.lowerCIRTBAAAttrToLLVMTBAAAttr(tbaaTag.getAccess());

clang/test/CIR/CodeGen/tbaa-struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ uint32_t g15(StructS *S, StructS3 *S3, uint64_t count) {
380380
// OLD-PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
381381
// OLD-PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR:!.*]], i64 0}
382382
// OLD-PATH: [[TYPE_CHAR]] = !{!"omnipotent char", [[TAG_cxx_tbaa:!.*]],
383-
// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C/C++ TBAA"}
383+
// OLD-PATH: [[TAG_cxx_tbaa]] = !{!"Simple C++ TBAA"}
384384
// OLD-PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
385385
// OLD-PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
386386
// OLD-PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]

0 commit comments

Comments
 (0)