[clang] [llvm] [CIR] Add TBAA support for scalar loads and stores (PR #246079)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 06:52:26 PST 2026
================
@@ -1234,3 +1234,69 @@ RecordLayoutAttr cir::getRecordLayout(mlir::ModuleOp mod,
assert(attr && "record layout entry missing for named record");
return attr;
}
+
+//===----------------------------------------------------------------------===//
+// TBAA attributes
+//===----------------------------------------------------------------------===//
+
+bool cir::isTBAATypeDescriptor(mlir::Attribute attr) {
+ return mlir::isa<TBAAOmnipotentCharAttr, TBAAScalarAttr, TBAAStructAttr>(
+ attr);
+}
+
+LogicalResult
+TBAAMemberAttr::verify(function_ref<InFlightDiagnostic()> emitError,
+ mlir::Attribute typeDesc, uint64_t offset) {
+ if (!isTBAATypeDescriptor(typeDesc))
+ return emitError() << "expected a TBAA type descriptor";
+ return success();
+}
+
+void TBAAStructAttr::print(AsmPrinter &printer) const {
+ printer << "<\"";
+ llvm::printEscapedString(getId(), printer.getStream());
+ printer << "\", [";
+ llvm::interleaveComma(getMembers(), printer, [&](TBAAMemberAttr member) {
+ printer.printStrippedAttrOrType(member);
+ });
+ printer << "]>";
+}
+
+Attribute TBAAStructAttr::parse(AsmParser &parser, Type odsType) {
+ std::string id;
+ if (parser.parseLess() || parser.parseString(&id) || parser.parseComma() ||
+ parser.parseLSquare())
+ return {};
+
+ llvm::SmallVector<TBAAMemberAttr> members;
+ if (failed(parser.parseOptionalRSquare())) {
+ if (parser.parseCommaSeparatedList([&]() -> ParseResult {
+ auto member = mlir::dyn_cast_if_present<TBAAMemberAttr>(
+ TBAAMemberAttr::parse(parser, Type()));
+ if (!member)
+ return failure();
+ members.push_back(member);
+ return success();
+ }) ||
+ parser.parseRSquare())
+ return {};
+ }
+
+ if (parser.parseGreater())
+ return {};
+ return TBAAStructAttr::get(parser.getContext(), id, members);
+}
+
+LogicalResult TBAATagAttr::verify(function_ref<InFlightDiagnostic()> emitError,
----------------
xlauko wrote:
This doesn't check that the access type is reachable at the offset, or that struct member offsets increase. Such tags pass cir-opt but fail LLVM translation.
https://github.com/llvm/llvm-project/pull/246079
More information about the cfe-commits
mailing list