LLvm LiveVariables Pass

文章讲述了LLVM中的LiveVariablesPass功能,该功能用于标记虚拟寄存器的使用情况。在给定的机器IR示例中,展示了如何识别死定义和使用。经过Phi节点消除后,某些变量和指令被标记为已杀(killed),但路径依赖性使得某些变量无法被标记为死定义。
摘要由CSDN通过智能技术生成

LLvm LiveVariables Pass

Functionality

For virtual register:
If there is not any usage after a definition, then the def will be marked as dead.
If there is not any usage after a usage, then the usage will be marked as killed.

Consider the following machine irs before phi-node-elimination

Function Live Ins: $edi in %4

bb.0.entry:
  successors: %bb.2(0x30000000), %bb.1(0x50000000); %bb.2(37.50%), %bb.1(62.50%)
  liveins: $edi
  %4:gr32 = COPY $edi
  %7:gr32 = ADD32ri8 %4:gr32(tied-def 0), 2, implicit-def $eflags
  %6:gr32 = MOV32ri 2
  CMP32ri8 %6:gr32, 0, implicit-def $eflags
  JCC_1 %bb.2, 14, implicit $eflags

bb.1.if.then:
; predecessors: %bb.0
  successors: %bb.3(0x80000000); %bb.3(100.00%)

  %9:gr32 = MOV32ri 1
  %10:gr32 = ADD32ri8 %9:gr32(tied-def 0), 1, implicit-def $eflags
  JMP_1 %bb.3

bb.2.if.else:
; predecessors: %bb.0
  successors: %bb.3(0x80000000); %bb.3(100.00%)

  %8:gr32 = ADD32ri8 %4:gr32(tied-def 0), 2, implicit-def $eflags

bb.3.if.end:
; predecessors: %bb.2, %bb.1

  %3:gr32 = PHI %8:gr32, %bb.2, %10:gr32, %bb.1
  %16:gr32 = ADD32ri8 %3:gr32(tied-def 0), 1, implicit-def $eflags
  %15:gr32 = ADD32rr %16:gr32(tied-def 0), %7:gr32, implicit-def $eflags
  %13:gr32 = ADD32ri8 %15:gr32(tied-def 0), 1, implicit-def $eflags
  $eax = COPY %13:gr32
  RET64 implicit $eax

After phi-node-elimination, the sequence will be

Function Live Ins: $edi in %4

bb.0.entry:
  successors: %bb.2(0x30000000), %bb.1(0x50000000); %bb.2(37.50%), %bb.1(62.50%)
  liveins: $edi
  %4:gr32 = COPY killed $edi
  %7:gr32 = ADD32ri8 %4:gr32(tied-def 0), 2, implicit-def dead $eflags
  %6:gr32 = MOV32ri 2
  CMP32ri8 killed %6:gr32, 0, implicit-def $eflags
  JCC_1 %bb.2, 14, implicit killed $eflags

bb.1.if.then:
; predecessors: %bb.0
  successors: %bb.3(0x80000000); %bb.3(100.00%)

  %9:gr32 = MOV32ri 1
  %10:gr32 = ADD32ri8 killed %9:gr32(tied-def 0), 1, implicit-def dead $eflags
  JMP_1 %bb.3

bb.2.if.else:
; predecessors: %bb.0
  successors: %bb.3(0x80000000); %bb.3(100.00%)

  %8:gr32 = ADD32ri8 killed %4:gr32(tied-def 0), 2, implicit-def dead $eflags

bb.3.if.end:
; predecessors: %bb.2, %bb.1

  %3:gr32 = PHI %8:gr32, %bb.2, %10:gr32, %bb.1
  %16:gr32 = ADD32ri8 killed %3:gr32(tied-def 0), 1, implicit-def dead $eflags
  %15:gr32 = ADD32rr killed %16:gr32(tied-def 0), killed %7:gr32, implicit-def dead $eflags
  %13:gr32 = ADD32ri8 killed %15:gr32(tied-def 0), 1, implicit-def dead $eflags
  $eax = COPY killed %13:gr32
  RET64 implicit killed $eax

Consider the control flow path1: bb.0->bb.1->bb.3 and the virtual register %4. Although the source %4 of %7:gr32 = ADD32ri8 %4:gr32(tied-def 0), 2, implicit-def dead $eflags is the last usage when path1 is taken. But it will not be the last usage when path2: bb.0->bb.2->bb.3 is taken, so the %4 at %7:gr32 = ADD32ri8 %4:gr32(tied-def 0), 2, implicit-def dead $eflags will not be marked as killed.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值