Skip to content
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
20 changes: 14 additions & 6 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,10 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
}
}
}
// std::vector is used here to accomodate large number of elements that
// exceed SmallVector capacity.
std::vector<llvm::Constant *> constants(numElements, child);
return llvm::ConstantArray::get(arrayType, constants);
// std::vector is used here to accomodate large number of elements that
// exceed SmallVector capacity.
std::vector<llvm::Constant *> constants(numElements, child);
return llvm::ConstantArray::get(arrayType, constants);
}
}

Expand Down Expand Up @@ -2131,8 +2131,16 @@ LogicalResult ModuleTranslation::createTBAAMetadata() {
// LLVM metadata instances.
AttrTypeWalker walker;
walker.addWalk([&](TBAARootAttr root) {
tbaaMetadataMapping.insert(
{root, llvm::MDNode::get(ctx, llvm::MDString::get(ctx, root.getId()))});
llvm::MDNode *node;
if (StringAttr id = root.getId()) {
node = llvm::MDNode::get(ctx, llvm::MDString::get(ctx, id));
} else {
// Anonymous root nodes are self-referencing.
auto selfRef = llvm::MDNode::getTemporary(ctx, {});
node = llvm::MDNode::get(ctx, {selfRef.get()});
node->replaceOperandWith(0, node);
}
tbaaMetadataMapping.insert({root, node});
});

walker.addWalk([&](TBAATypeDescriptorAttr descriptor) {
Expand Down
21 changes: 21 additions & 0 deletions mlir/test/Target/LLVMIR/anonymous-tbaa.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s

#tbaa_root_0 = #llvm.tbaa_root<>
#tbaa_type_desc_1 = #llvm.tbaa_type_desc<id = "omnipotent char", members = {<#tbaa_root_0, 0>}>
#tbaa_type_desc_2 = #llvm.tbaa_type_desc<id = "long long", members = {<#tbaa_type_desc_1, 0>}>
#tbaa_tag_3 = #llvm.tbaa_tag<access_type = #tbaa_type_desc_2, base_type = #tbaa_type_desc_2, offset = 0>

// CHECK: define void @tbaa_anonymous_root(ptr %{{.*}}) {
// CHECK: %{{.*}} = load i64, ptr %{{.*}}, align 4, !tbaa ![[TAG:[0-9]+]]
// CHECK: ret void
// CHECK: }
// CHECK: !llvm.module.flags = !{![[FLAGS:[0-9]+]]}
// CHECK: ![[FLAGS]] = !{i32 2, !"Debug Info Version", i32 3}
// CHECK: ![[TAG]] = !{![[TYPE:[0-9]+]], ![[TYPE]], i64 0}
// CHECK: ![[TYPE]] = !{!"long long", ![[BASE:[0-9]+]], i64 0}
// CHECK: ![[BASE]] = !{!"omnipotent char", ![[ROOT:[0-9]+]], i64 0}
// CHECK: ![[ROOT]] = distinct !{![[ROOT]]}
llvm.func @tbaa_anonymous_root(%arg0: !llvm.ptr) {
%0 = llvm.load %arg0 {tbaa = [#tbaa_tag_3]} : !llvm.ptr -> i64
llvm.return
}