[llvm-dev] IR with no optimization

Kai Wang via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 9 08:09:00 PST 2016


Hi all,

I'm compiling linux kernel with clang. I want to generate IR with no
optimization. However, kernel can only be compile with -O2 instead of -O0.

Here is the source code snippet:

struct zone *next_zone(struct zone *zone)

 {   pg_data_t **pgdat* = zone->zone_pgdat;

}

I want to know there is an assignment from "zone" to "pgdat". I'm trying to
iterate "store" instructions in IR.

When I compile with -O2, I have the following IR:

define %struct.zone* @next_zone(%struct.zone* readonly %zone) #0 !dbg !214 {

        call void @llvm.dbg.value(metadata %struct.zone* %zone, i64 0,
metadata !218, metadata !305), !dbg !326

        %1 = getelementptr inbounds %struct.zone, %struct.zone* %zone, i64 0,
i32 5, !dbg !327

        %2 = load %struct.pglist_data*, %struct.pglist_data** %1, align 8,
!dbg !327

        call void @llvm.dbg.value(metadata %struct.pglist_data* %2, i64 0,
metadata !219, metadata !305), !dbg !328 }

*Store instruction has been optimized, and no variable name in IR.*

When I comile with -O0, I have the following IR:

define %struct.zone* @next_zone(%struct.zone* %zone) #0 !dbg !211 {

         %1 = alloca %struct.zone*, align 8

         %pgdat = alloca %struct.pglist_data*, align 8

         store %struct.zone* %zone, %struct.zone** %1, align 8

         call void @llvm.dbg.declare(metadata %struct.zone** %1, metadata !
297, metadata !265), !dbg !298

         call void @llvm.dbg.declare(metadata %struct.pglist_data** %pgdat,
metadata !299, metadata !265), !dbg !302

         %2 = load %struct.zone*, %struct.zone** %1, align 8, !dbg !303

         %3 = getelementptr inbounds %struct.zone, %struct.zone* %2, i32 0,
i32 5, !dbg !304

         %4 = load %struct.pglist_data*, %struct.pglist_data** %3, align 8,
!dbg !304

         *store %struct.pglist_data* %4, %struct.pglist_data** %**pgdat,
align 8, !dbg !302*
There is store instruction. I know there is an assignment. From this store,
I backward traverse until I find variable.
For example, I go through %4->%3->%2->%1->struct.zone. I have variable name
pgdat in IR as well.

Since kernel can only be compiled with -O2, IR has been optimized a lot.
Is there any way I can know the variable name and there is an assignment
from "zone" to "pgdat"?

Thank you!
-- 
Regards,
Kai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160209/f1629bde/attachment.html>


More information about the llvm-dev mailing list