Justin Holewinski
2012-Dec-30 13:39 UTC
[LLVMdev] Cannot interchange "literal" and "identified" structs
With primitive types, I can interchange literal usage and type aliases in IR: %mytype = type i32 define void @foo(%mytype* %ptr) { %t1 = load *%mytype** %ptr store i32 *%t1*, *i32** %ptr ret void } But for structs, I cannot: %mytype = type { i32, i32 } define void @foo(%mytype* %ptr) { %t1 = load *%mytype** %ptr store* { i32, i32 }* %t1, *{ i32, i32 }** %ptr ret void } bin/llvm-as: alias2.ll:6:22: error: '%t1' defined with type '%mytype = type { i32, i32 }' store { i32, i32 } %t1, { i32, i32 }* %ptr I don't see anything in the language reference manual that disallows such usage, as the literal struct type and %mytype are equivalent. Am I missing something here, or is this just a bug in the assembly parser? -- Thanks, Justin Holewinski -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121230/f5b42f91/attachment.html>
NAKAMURA Takumi
2012-Dec-30 23:19 UTC
[LLVMdev] Cannot interchange "literal" and "identified" structs
Justin, http://llvm.org/docs/LangRef.html#structure-type "Identified types can be recursive, can be opaqued, and are never uniqued." Do you think it would be less descriptive? "Identified type, aka named llvm::StructType, is never uniqued against other identified types nor literal types, aka unnamed StructType(s)." ? See also; http://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.html ...Takumi 2012/12/30 Justin Holewinski <justin.holewinski at gmail.com>:> With primitive types, I can interchange literal usage and type aliases in > IR: > > %mytype = type i32 > > define void @foo(%mytype* %ptr) { > %t1 = load %mytype* %ptr > store i32 %t1, i32* %ptr > ret void > } > > But for structs, I cannot: > > %mytype = type { i32, i32 } > > define void @foo(%mytype* %ptr) { > %t1 = load %mytype* %ptr > store { i32, i32 } %t1, { i32, i32 }* %ptr > ret void > } > > bin/llvm-as: alias2.ll:6:22: error: '%t1' defined with type '%mytype = type > { i32, i32 }' > store { i32, i32 } %t1, { i32, i32 }* %ptr > > I don't see anything in the language reference manual that disallows such > usage, as the literal struct type and %mytype are equivalent. Am I missing > something here, or is this just a bug in the assembly parser? > > -- > > Thanks, > > Justin Holewinski > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Justin Holewinski
2012-Dec-31 12:38 UTC
[LLVMdev] Cannot interchange "literal" and "identified" structs
Alright, I misunderstood that statement then. This does seem to be inconsistent with llvm-link, though. If I have two identified structs in the same module, I cannot interchange them. But if they are in different modules, llvm-link will merge them: $ cat struct1.ll %mystruct = type { i32, i32 } define i32 @foo(i32 %a) { %val = tail call %mystruct @llvm.my.intrinsic(i32 %a) %ret = extractvalue %mystruct %val, 0 ret i32 %ret } declare %mystruct @llvm.my.intrinsic(i32) $ cat struct2.ll %mytype = type { i32, i32 } define i32 @bar(i32 %a) { %val = tail call %mytype @llvm.my.intrinsic(i32 %a) %ret = extractvalue %mytype %val, 1 ret i32 %ret } declare %mytype @llvm.my.intrinsic(i32) $ bin/llvm-link struct1.ll struct2.ll -S ; ModuleID = 'struct1.ll' %mystruct = type { i32, i32 } define i32 @foo(i32 %a) { %val = tail call %mystruct @llvm.my.intrinsic(i32 %a) %ret = extractvalue %mystruct %val, 0 ret i32 %ret } declare %mystruct @llvm.my.intrinsic(i32) define i32 @bar(i32 %a) { %val = tail call %mystruct @llvm.my.intrinsic(i32 %a) %ret = extractvalue %mystruct %val, 1 ret i32 %ret } Shouldn't llvm-link throw an error saying %mystruct and %mytype are different structs and @llvm.my.intrinsic cannot be double-defined with both return types? On Sun, Dec 30, 2012 at 6:19 PM, NAKAMURA Takumi <geek4civic at gmail.com>wrote:> Justin, > > http://llvm.org/docs/LangRef.html#structure-type > "Identified types can be recursive, can be opaqued, and are never uniqued." > Do you think it would be less descriptive? > > "Identified type, aka named llvm::StructType, is never uniqued against > other identified types nor literal types, aka unnamed StructType(s)." > ? > > See also; http://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.html > > ...Takumi > > 2012/12/30 Justin Holewinski <justin.holewinski at gmail.com>: > > With primitive types, I can interchange literal usage and type aliases in > > IR: > > > > %mytype = type i32 > > > > define void @foo(%mytype* %ptr) { > > %t1 = load %mytype* %ptr > > store i32 %t1, i32* %ptr > > ret void > > } > > > > But for structs, I cannot: > > > > %mytype = type { i32, i32 } > > > > define void @foo(%mytype* %ptr) { > > %t1 = load %mytype* %ptr > > store { i32, i32 } %t1, { i32, i32 }* %ptr > > ret void > > } > > > > bin/llvm-as: alias2.ll:6:22: error: '%t1' defined with type '%mytype > type > > { i32, i32 }' > > store { i32, i32 } %t1, { i32, i32 }* %ptr > > > > I don't see anything in the language reference manual that disallows such > > usage, as the literal struct type and %mytype are equivalent. Am I > missing > > something here, or is this just a bug in the assembly parser? > > > > -- > > > > Thanks, > > > > Justin Holewinski > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > >-- Thanks, Justin Holewinski -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121231/314b955f/attachment.html>
Seemingly Similar Threads
- [LLVMdev] Cannot interchange "literal" and "identified" structs
- [LLVMdev] RFC: Indexing of structs vs arrays in getelementpointer
- [LLVMdev] RFC: Indexing of structs vs arrays in getelementpointer
- [LLVMdev] Structs passed by value
- [LLVMdev] Structs passed by value