HGraphBuilder方法分析一

本文详细分析了Android编译器优化过程中,HGraphBuilder类如何解析Dalvik指令,特别是针对CONST_4指令的处理过程。通过对`BuildGraphForInstruction`方法的解读,揭示了如何将指令转换为HInstruction并添加到图中,包括检查当前块、根据Opcode处理指令、获取并设置常量到寄存器的过程。
摘要由CSDN通过智能技术生成

在~/android-6.0.1_r62/art/compiler/optimizing/builder.cc中为类HGraphBuilder的具体信息:
1/首要分析的方法为:
bool AnalyzeDexInstruction(const Instruction& instruction, uint32_t dex_pc);
该方法的主要功能是分析dex instruction,将HInstruction添加到graph中以可以执行该dex instruction。返回值意为,该dex instruction是否能被处理。
具体实现:
A.
1317 if (current_block_ == nullptr) {
1318 return true; // Dead code
1319 }

先检查current_block_ == nullptr,若相等,则直接返回真。
B. switch (instruction.Opcode())
根据Opcode的不同进行不同的处理,类instruction中定义了dex instruction,Opcode()方法返回的是instruction的opcode field,也就是instruction的前16位。
下面以CONST_4为例,总共只有三行代码。

1322     case Instruction::CONST_4: {
1323       int32_t register_index = instruction.VRegA();
1324       HIntConstant* constant = graph_->GetIntConstant(instruction.VRegB_11n());//HIntConstant类包含的是int类型的常量。
1325       UpdateLocal(register_index, constant);
1326       break;
1327     }

其中CONST_4为dalvik指令const/4:
const/4 vA,#+B 将数值符号扩展为32位后赋值给寄存器vA。
关于dalvik指令更详细的介绍在~/android-6.0.1_r62/art/runtime/dex_instruction_list.h中,例如对于CONST_4:

#define DEX_INSTRUCTION_LIST(V) \
V(0x12, CONST_4, "const/4", k11n, true, kNone, kContinue | kRegBFieldOrConstant, kVerifyRegA)

①int32_t register_index = instruction.VRegA();

 57 inline int32_t Instruction::VRegA() const {
 58   switch (FormatOf(Opcode())) {
 59     case k10t: return VRegA_10t();
 60     case k10x: return VRegA_10x();
 61     case k11n: return VRegA_11n();
 62     case k11x: return VRegA_11x();
 63     case<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值