Tingyuan LIANG via llvm-dev
2019-Jun-30 05:36 UTC
[llvm-dev] Information Loss of Array Type in Function Interface in IR Generated by Clang
Dear all, Hi! Recently, I notice a situation where I cannot infer the size of the outermost dimension of array in the function interface. To concretely depict the problem, I show the C source code and the generated IR code at the end. The array size of A[] is 51 but this information is lost in the generated IR. How can I maintain such information in IR? Should I set some argument for Clang so it can do so? The Clang command I used is : clang -O1 -emit-llvm -S -g tmp.cc -o tmp.bc Thanks in advance for your time and suggestion! ^_^ C source code: int f ( int A[51], int x) { return A[x]; } ==========================generated IR: ; Function Attrs: norecurse nounwind readonly uwtable define dso_local i32 @_Z1fPii(i32* nocapture readonly %A, i32 %x) local_unnamed_addr #0 !dbg !7 { entry: call void @llvm.dbg.value(metadata i32* %A, metadata !13, metadata !DIExpression()), !dbg !15 call void @llvm.dbg.value(metadata i32 %x, metadata !14, metadata !DIExpression()), !dbg !16 %idxprom = sext i32 %x to i64, !dbg !17 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom, !dbg !17 %0 = load i32, i32* %arrayidx, align 4, !dbg !17, !tbaa !18 ret i32 %0, !dbg !22 } Best regards, ------------------------------------------ Tingyuan LIANG MPhil Student Department of Electronic and Computer Engineering The Hong Kong University of Science and Technology -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190630/c228ad67/attachment.html>
David Blaikie via llvm-dev
2019-Jun-30 05:40 UTC
[llvm-dev] Information Loss of Array Type in Function Interface in IR Generated by Clang
LLVM IR doesn't maintain a lot of information present in the source. What were you hoping to do with that information? Perhaps you'd be best off doing something up in clang/using the AST uinstead of LLVM IR? On Sat, Jun 29, 2019 at 10:36 PM Tingyuan LIANG via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Dear all, > > Hi! Recently, I notice a situation where I cannot infer the size of > the outermost dimension of array in the function interface. > To concretely depict the problem, I show the C source code and the > generated IR code at the end. The array size of A[] is 51 but this > information is lost in the generated IR. > How can I maintain such information in IR? Should I set some argument > for Clang so it can do so? > The Clang command I used is : > > clang -O1 -emit-llvm -S -g tmp.cc -o tmp.bc > > Thanks in advance for your time and suggestion! ^_^ > > C source code: > int f ( int A[51], int x) > { > return A[x]; > } > > ==========================> generated IR: > ; Function Attrs: norecurse nounwind readonly uwtable > define dso_local i32 @_Z1fPii(i32* nocapture readonly %A, i32 %x) > local_unnamed_addr #0 !dbg !7 { > entry: > call void @llvm.dbg.value(metadata i32* %A, metadata !13, metadata > !DIExpression()), !dbg !15 > call void @llvm.dbg.value(metadata i32 %x, metadata !14, metadata > !DIExpression()), !dbg !16 > %idxprom = sext i32 %x to i64, !dbg !17 > %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom, !dbg !17 > %0 = load i32, i32* %arrayidx, align 4, !dbg !17, !tbaa !18 > ret i32 %0, !dbg !22 > } > > > Best regards, > ------------------------------------------ > Tingyuan LIANG > MPhil Student > Department of Electronic and Computer Engineering > The Hong Kong University of Science and Technology > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190629/056c7d78/attachment.html>
Tingyuan LIANG via llvm-dev
2019-Jun-30 05:48 UTC
[llvm-dev] Information Loss of Array Type in Function Interface in IR Generated by Clang
Dear David, Thanks for your prompt reply! Sure, I can implement a AST visitor to go through the AST to get the information but I just wonder whether there is any other way to let Clang do so. What I am considering is how to let the generated IR looks like below, which some tools realize: define dso_local i32 @_Z1fPii([51 x i32]* %A, i32 %x) local_unnamed_addr #0 !dbg !7 { entry: ... } Best regards, ------------------------------------------ Tingyuan LIANG MPhil Student Department of Electronic and Computer Engineering The Hong Kong University of Science and Technology ________________________________ From: David Blaikie <dblaikie at gmail.com> Sent: Sunday, June 30, 2019 1:40 PM To: Tingyuan LIANG Cc: llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] Information Loss of Array Type in Function Interface in IR Generated by Clang LLVM IR doesn't maintain a lot of information present in the source. What were you hoping to do with that information? Perhaps you'd be best off doing something up in clang/using the AST uinstead of LLVM IR? On Sat, Jun 29, 2019 at 10:36 PM Tingyuan LIANG via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote: Dear all, Hi! Recently, I notice a situation where I cannot infer the size of the outermost dimension of array in the function interface. To concretely depict the problem, I show the C source code and the generated IR code at the end. The array size of A[] is 51 but this information is lost in the generated IR. How can I maintain such information in IR? Should I set some argument for Clang so it can do so? The Clang command I used is : clang -O1 -emit-llvm -S -g tmp.cc -o tmp.bc Thanks in advance for your time and suggestion! ^_^ C source code: int f ( int A[51], int x) { return A[x]; } ==========================generated IR: ; Function Attrs: norecurse nounwind readonly uwtable define dso_local i32 @_Z1fPii(i32* nocapture readonly %A, i32 %x) local_unnamed_addr #0 !dbg !7 { entry: call void @llvm.dbg.value(metadata i32* %A, metadata !13, metadata !DIExpression()), !dbg !15 call void @llvm.dbg.value(metadata i32 %x, metadata !14, metadata !DIExpression()), !dbg !16 %idxprom = sext i32 %x to i64, !dbg !17 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom, !dbg !17 %0 = load i32, i32* %arrayidx, align 4, !dbg !17, !tbaa !18 ret i32 %0, !dbg !22 } Best regards, ------------------------------------------ Tingyuan LIANG MPhil Student Department of Electronic and Computer Engineering The Hong Kong University of Science and Technology _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190630/18f9794d/attachment.html>
Possibly Parallel Threads
- Information Loss of Array Type in Function Interface in IR Generated by Clang
- Confusing ERROR with LoopAccessLegacyAnalysis: Pass 'Unnamed pass: implement Pass::getPassName()' is not initialized.
- Wrong Range of SCEV for URem
- Unable to find requested analysis info (Interesting Assertion Failture for Specific Target Source Code)
- Loop Strength Reduction Pass Does Not Work for Some Varialbles Related to Induction Variables