diff options
author | Vladimir Marko <vmarko@google.com> | 2015-03-24 11:58:59 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-24 11:59:00 +0000 |
commit | 94ead7673f90a8199d926fe161d7d021202f0aa7 (patch) | |
tree | 120c8ea6fe55ba3a8e2f9cf6eba041ef98a9b51f | |
parent | 274395fe6649d83d723c4b912a46291b2987efd6 (diff) | |
parent | f6737f7ed741b15cfd60c2530dab69f897540735 (diff) | |
download | android_art-94ead7673f90a8199d926fe161d7d021202f0aa7.tar.gz android_art-94ead7673f90a8199d926fe161d7d021202f0aa7.tar.bz2 android_art-94ead7673f90a8199d926fe161d7d021202f0aa7.zip |
Merge "Quick: Clean up Mir2Lir codegen."
22 files changed, 64 insertions, 78 deletions
diff --git a/compiler/dex/quick/arm/assemble_arm.cc b/compiler/dex/quick/arm/assemble_arm.cc index 8833da324f..3e69878846 100644 --- a/compiler/dex/quick/arm/assemble_arm.cc +++ b/compiler/dex/quick/arm/assemble_arm.cc @@ -848,7 +848,7 @@ const ArmEncodingMap ArmMir2Lir::EncodingMap[kArmLast] = { ENCODING_MAP(kThumb2LdrPcRel12, 0xf8df0000, kFmtBitBlt, 15, 12, kFmtBitBlt, 11, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1, - IS_TERTIARY_OP | REG_DEF0 | REG_USE_PC | IS_LOAD_OFF | NEEDS_FIXUP, + IS_BINARY_OP | REG_DEF0 | REG_USE_PC | IS_LOAD_OFF | NEEDS_FIXUP, "ldr", "!0C, [r15pc, #!1d]", 4, kFixupLoad), ENCODING_MAP(kThumb2BCond, 0xf0008000, kFmtBrOffset, -1, -1, kFmtBitBlt, 25, 22, kFmtUnused, -1, -1, @@ -1502,7 +1502,7 @@ void ArmMir2Lir::AssembleLIR() { break; } case kFixupAdr: { - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[2])); + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[2]); LIR* target = lir->target; int32_t target_disp = (tab_rec != NULL) ? tab_rec->offset + offset_adjustment : target->offset + ((target->flags.generation == lir->flags.generation) ? 0 : @@ -1555,8 +1555,8 @@ void ArmMir2Lir::AssembleLIR() { } case kFixupMovImmLST: { // operands[1] should hold disp, [2] has add, [3] has tab_rec - LIR *addPCInst = reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])); - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + const LIR* addPCInst = UnwrapPointer<LIR>(lir->operands[2]); + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); // If tab_rec is null, this is a literal load. Use target LIR* target = lir->target; int32_t target_disp = tab_rec ? tab_rec->offset : target->offset; @@ -1565,8 +1565,8 @@ void ArmMir2Lir::AssembleLIR() { } case kFixupMovImmHST: { // operands[1] should hold disp, [2] has add, [3] has tab_rec - LIR *addPCInst = reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])); - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + const LIR* addPCInst = UnwrapPointer<LIR>(lir->operands[2]); + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); // If tab_rec is null, this is a literal load. Use target LIR* target = lir->target; int32_t target_disp = tab_rec ? tab_rec->offset : target->offset; diff --git a/compiler/dex/quick/arm/call_arm.cc b/compiler/dex/quick/arm/call_arm.cc index 318292029d..d46c25a8da 100644 --- a/compiler/dex/quick/arm/call_arm.cc +++ b/compiler/dex/quick/arm/call_arm.cc @@ -658,7 +658,7 @@ LIR* ArmMir2Lir::CallWithLinkerFixup(const MethodReference& target_method, Invok // NOTE: Method deduplication takes linker patches into account, so we can just pass 0 // as a placeholder for the offset. LIR* call = RawLIR(current_dalvik_offset_, kThumb2Bl, 0, - target_method_idx, WrapPointer(const_cast<DexFile*>(target_dex_file)), type); + target_method_idx, WrapPointer(target_dex_file), type); AppendLIR(call); call_method_insns_.push_back(call); return call; diff --git a/compiler/dex/quick/arm/codegen_arm.h b/compiler/dex/quick/arm/codegen_arm.h index 67fabbddfe..4141bcfe98 100644 --- a/compiler/dex/quick/arm/codegen_arm.h +++ b/compiler/dex/quick/arm/codegen_arm.h @@ -200,7 +200,7 @@ class ArmMir2Lir FINAL : public Mir2Lir { void UpdateIT(LIR* it, const char* new_guide); void OpEndIT(LIR* it); LIR* OpMem(OpKind op, RegStorage r_base, int disp); - LIR* OpPcRelLoad(RegStorage reg, LIR* target); + void OpPcRelLoad(RegStorage reg, LIR* target); LIR* OpReg(OpKind op, RegStorage r_dest_src); void OpRegCopy(RegStorage r_dest, RegStorage r_src); LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); diff --git a/compiler/dex/quick/arm/int_arm.cc b/compiler/dex/quick/arm/int_arm.cc index ef26323a5a..9193e1b23c 100644 --- a/compiler/dex/quick/arm/int_arm.cc +++ b/compiler/dex/quick/arm/int_arm.cc @@ -1081,9 +1081,10 @@ bool ArmMir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) { return true; } -LIR* ArmMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { +void ArmMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { ScopedMemRefType mem_ref_type(this, ResourceMask::kLiteral); - return RawLIR(current_dalvik_offset_, kThumb2LdrPcRel12, reg.GetReg(), 0, 0, 0, 0, target); + LIR* lir = NewLIR2(kThumb2LdrPcRel12, reg.GetReg(), 0); + lir->target = target; } LIR* ArmMir2Lir::OpVldm(RegStorage r_base, int count) { diff --git a/compiler/dex/quick/arm/target_arm.cc b/compiler/dex/quick/arm/target_arm.cc index 13f9072bbe..9812d9ff99 100644 --- a/compiler/dex/quick/arm/target_arm.cc +++ b/compiler/dex/quick/arm/target_arm.cc @@ -455,7 +455,7 @@ std::string ArmMir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char case 'T': snprintf(tbuf, arraysize(tbuf), "%s", PrettyMethod( static_cast<uint32_t>(lir->operands[1]), - *reinterpret_cast<const DexFile*>(UnwrapPointer(lir->operands[2]))).c_str()); + *UnwrapPointer<DexFile>(lir->operands[2])).c_str()); break; case 'u': { int offset_1 = lir->operands[0]; @@ -906,9 +906,7 @@ void ArmMir2Lir::InstallLiteralPools() { for (LIR* p : call_method_insns_) { DCHECK_EQ(p->opcode, kThumb2Bl); uint32_t target_method_idx = p->operands[1]; - const DexFile* target_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[2])); - + const DexFile* target_dex_file = UnwrapPointer<DexFile>(p->operands[2]); patches_.push_back(LinkerPatch::RelativeCodePatch(p->offset, target_dex_file, target_method_idx)); } diff --git a/compiler/dex/quick/arm64/assemble_arm64.cc b/compiler/dex/quick/arm64/assemble_arm64.cc index aa5e5b4719..329bb1e770 100644 --- a/compiler/dex/quick/arm64/assemble_arm64.cc +++ b/compiler/dex/quick/arm64/assemble_arm64.cc @@ -1003,7 +1003,7 @@ void Arm64Mir2Lir::AssembleLIR() { 0 : offset_adjustment) + target_lir->offset; delta = target_offs - lir->offset; } else if (lir->operands[2] >= 0) { - EmbeddedData* tab = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[2])); + const EmbeddedData* tab = UnwrapPointer<EmbeddedData>(lir->operands[2]); delta = tab->offset + offset_adjustment - lir->offset; } else { // No fixup: this usage allows to retrieve the current PC. diff --git a/compiler/dex/quick/arm64/call_arm64.cc b/compiler/dex/quick/arm64/call_arm64.cc index 1dcbe609b5..823cb60d97 100644 --- a/compiler/dex/quick/arm64/call_arm64.cc +++ b/compiler/dex/quick/arm64/call_arm64.cc @@ -525,7 +525,7 @@ LIR* Arm64Mir2Lir::CallWithLinkerFixup(const MethodReference& target_method, Inv // NOTE: Method deduplication takes linker patches into account, so we can just pass 0 // as a placeholder for the offset. LIR* call = RawLIR(current_dalvik_offset_, kA64Bl1t, 0, - target_method_idx, WrapPointer(const_cast<DexFile*>(target_dex_file)), type); + target_method_idx, WrapPointer(target_dex_file), type); AppendLIR(call); call_method_insns_.push_back(call); return call; diff --git a/compiler/dex/quick/arm64/codegen_arm64.h b/compiler/dex/quick/arm64/codegen_arm64.h index d5f0536691..54fd46de0e 100644 --- a/compiler/dex/quick/arm64/codegen_arm64.h +++ b/compiler/dex/quick/arm64/codegen_arm64.h @@ -203,7 +203,7 @@ class Arm64Mir2Lir FINAL : public Mir2Lir { LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE; void OpEndIT(LIR* it) OVERRIDE; LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE; - LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE; + void OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE; LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE; void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE; LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE; diff --git a/compiler/dex/quick/arm64/int_arm64.cc b/compiler/dex/quick/arm64/int_arm64.cc index 92675f361a..2372ccc527 100644 --- a/compiler/dex/quick/arm64/int_arm64.cc +++ b/compiler/dex/quick/arm64/int_arm64.cc @@ -937,9 +937,10 @@ bool Arm64Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) { return true; } -LIR* Arm64Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { +void Arm64Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { ScopedMemRefType mem_ref_type(this, ResourceMask::kLiteral); - return RawLIR(current_dalvik_offset_, kA64Ldr2rp, As32BitReg(reg).GetReg(), 0, 0, 0, 0, target); + LIR* lir = NewLIR2(kA64Ldr2rp, As32BitReg(reg).GetReg(), 0); + lir->target = target; } LIR* Arm64Mir2Lir::OpVldm(RegStorage r_base, int count) { diff --git a/compiler/dex/quick/arm64/target_arm64.cc b/compiler/dex/quick/arm64/target_arm64.cc index 136be946f3..09a34bf022 100644 --- a/compiler/dex/quick/arm64/target_arm64.cc +++ b/compiler/dex/quick/arm64/target_arm64.cc @@ -851,9 +851,7 @@ void Arm64Mir2Lir::InstallLiteralPools() { for (LIR* p : call_method_insns_) { DCHECK_EQ(p->opcode, kA64Bl1t); uint32_t target_method_idx = p->operands[1]; - const DexFile* target_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[2])); - + const DexFile* target_dex_file = UnwrapPointer<DexFile>(p->operands[2]); patches_.push_back(LinkerPatch::RelativeCodePatch(p->offset, target_dex_file, target_method_idx)); } diff --git a/compiler/dex/quick/codegen_util.cc b/compiler/dex/quick/codegen_util.cc index 3285195b40..4e7919b6d2 100644 --- a/compiler/dex/quick/codegen_util.cc +++ b/compiler/dex/quick/codegen_util.cc @@ -222,7 +222,7 @@ void Mir2Lir::DumpLIRInsn(LIR* lir, unsigned char* base_addr) { } LOG(INFO) << "-------- dalvik offset: 0x" << std::hex << lir->dalvik_offset << " @ " - << reinterpret_cast<char*>(UnwrapPointer(lir->operands[0])); + << UnwrapPointer<char>(lir->operands[0]); break; case kPseudoExitBlock: LOG(INFO) << "-------- exit offset: 0x" << std::hex << dest; @@ -416,7 +416,7 @@ LIR* Mir2Lir::ScanLiteralPoolWide(LIR* data_target, int val_lo, int val_hi) { LIR* Mir2Lir::ScanLiteralPoolMethod(LIR* data_target, const MethodReference& method) { while (data_target) { if (static_cast<uint32_t>(data_target->operands[0]) == method.dex_method_index && - UnwrapPointer(data_target->operands[1]) == method.dex_file) { + UnwrapPointer<DexFile>(data_target->operands[1]) == method.dex_file) { return data_target; } data_target = data_target->next; @@ -428,7 +428,7 @@ LIR* Mir2Lir::ScanLiteralPoolMethod(LIR* data_target, const MethodReference& met LIR* Mir2Lir::ScanLiteralPoolClass(LIR* data_target, const DexFile& dex_file, uint32_t type_idx) { while (data_target) { if (static_cast<uint32_t>(data_target->operands[0]) == type_idx && - UnwrapPointer(data_target->operands[1]) == &dex_file) { + UnwrapPointer<DexFile>(data_target->operands[1]) == &dex_file) { return data_target; } data_target = data_target->next; @@ -491,8 +491,7 @@ void Mir2Lir::InstallLiteralPools() { data_lir = code_literal_list_; while (data_lir != nullptr) { uint32_t target_method_idx = data_lir->operands[0]; - const DexFile* target_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1])); + const DexFile* target_dex_file = UnwrapPointer<DexFile>(data_lir->operands[1]); patches_.push_back(LinkerPatch::CodePatch(code_buffer_.size(), target_dex_file, target_method_idx)); PushUnpatchedReference(&code_buffer_); @@ -501,8 +500,7 @@ void Mir2Lir::InstallLiteralPools() { data_lir = method_literal_list_; while (data_lir != nullptr) { uint32_t target_method_idx = data_lir->operands[0]; - const DexFile* target_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1])); + const DexFile* target_dex_file = UnwrapPointer<DexFile>(data_lir->operands[1]); patches_.push_back(LinkerPatch::MethodPatch(code_buffer_.size(), target_dex_file, target_method_idx)); PushUnpatchedReference(&code_buffer_); @@ -512,8 +510,7 @@ void Mir2Lir::InstallLiteralPools() { data_lir = class_literal_list_; while (data_lir != nullptr) { uint32_t target_type_idx = data_lir->operands[0]; - const DexFile* class_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1])); + const DexFile* class_dex_file = UnwrapPointer<DexFile>(data_lir->operands[1]); patches_.push_back(LinkerPatch::TypePatch(code_buffer_.size(), class_dex_file, target_type_idx)); PushUnpatchedReference(&code_buffer_); @@ -1054,7 +1051,7 @@ Mir2Lir::Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena pointer_storage_.reserve(128); slow_paths_.reserve(32); // Reserve pointer id 0 for nullptr. - size_t null_idx = WrapPointer(nullptr); + size_t null_idx = WrapPointer<void>(nullptr); DCHECK_EQ(null_idx, 0U); } @@ -1263,8 +1260,7 @@ void Mir2Lir::LoadCodeAddress(const MethodReference& target_method, InvokeType t data_target->operands[2] = type; } // Loads a code pointer. Code from oat file can be mapped anywhere. - LIR* load_pc_rel = OpPcRelLoad(TargetPtrReg(symbolic_reg), data_target); - AppendLIR(load_pc_rel); + OpPcRelLoad(TargetPtrReg(symbolic_reg), data_target); DCHECK_NE(cu_->instruction_set, kMips) << reinterpret_cast<void*>(data_target); DCHECK_NE(cu_->instruction_set, kMips64) << reinterpret_cast<void*>(data_target); } @@ -1281,8 +1277,7 @@ void Mir2Lir::LoadMethodAddress(const MethodReference& target_method, InvokeType data_target->operands[2] = type; } // Loads an ArtMethod pointer, which is a reference as it lives in the heap. - LIR* load_pc_rel = OpPcRelLoad(TargetReg(symbolic_reg, kRef), data_target); - AppendLIR(load_pc_rel); + OpPcRelLoad(TargetReg(symbolic_reg, kRef), data_target); DCHECK_NE(cu_->instruction_set, kMips) << reinterpret_cast<void*>(data_target); DCHECK_NE(cu_->instruction_set, kMips64) << reinterpret_cast<void*>(data_target); } @@ -1296,8 +1291,7 @@ void Mir2Lir::LoadClassType(const DexFile& dex_file, uint32_t type_idx, data_target->operands[1] = WrapPointer(const_cast<DexFile*>(&dex_file)); } // Loads a Class pointer, which is a reference as it lives in the heap. - LIR* load_pc_rel = OpPcRelLoad(TargetReg(symbolic_reg, kRef), data_target); - AppendLIR(load_pc_rel); + OpPcRelLoad(TargetReg(symbolic_reg, kRef), data_target); } std::vector<uint8_t>* Mir2Lir::ReturnFrameDescriptionEntry() { diff --git a/compiler/dex/quick/mips/assemble_mips.cc b/compiler/dex/quick/mips/assemble_mips.cc index 0218dcdd24..ed72d676b7 100644 --- a/compiler/dex/quick/mips/assemble_mips.cc +++ b/compiler/dex/quick/mips/assemble_mips.cc @@ -562,8 +562,8 @@ AssemblerStatus MipsMir2Lir::AssembleInstructions(CodeOffset start_addr) { * and is found in lir->target. If operands[3] is non-NULL, * then it is a Switch/Data table. */ - int offset1 = (reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])))->offset; - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + int offset1 = UnwrapPointer<LIR>(lir->operands[2])->offset; + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); int offset2 = tab_rec ? tab_rec->offset : lir->target->offset; int delta = offset2 - offset1; if ((delta & 0xffff) == delta && ((delta & 0x8000) == 0)) { @@ -589,14 +589,14 @@ AssemblerStatus MipsMir2Lir::AssembleInstructions(CodeOffset start_addr) { res = kRetryAll; } } else if (lir->opcode == kMipsDeltaLo) { - int offset1 = (reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])))->offset; - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + int offset1 = UnwrapPointer<LIR>(lir->operands[2])->offset; + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); int offset2 = tab_rec ? tab_rec->offset : lir->target->offset; int delta = offset2 - offset1; lir->operands[1] = delta & 0xffff; } else if (lir->opcode == kMipsDeltaHi) { - int offset1 = (reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])))->offset; - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + int offset1 = UnwrapPointer<LIR>(lir->operands[2])->offset; + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); int offset2 = tab_rec ? tab_rec->offset : lir->target->offset; int delta = offset2 - offset1; lir->operands[1] = (delta >> 16) & 0xffff; diff --git a/compiler/dex/quick/mips/codegen_mips.h b/compiler/dex/quick/mips/codegen_mips.h index 47837a659b..649b6c9417 100644 --- a/compiler/dex/quick/mips/codegen_mips.h +++ b/compiler/dex/quick/mips/codegen_mips.h @@ -172,7 +172,7 @@ class MipsMir2Lir FINAL : public Mir2Lir { LIR* OpIT(ConditionCode cond, const char* guide); void OpEndIT(LIR* it); LIR* OpMem(OpKind op, RegStorage r_base, int disp); - LIR* OpPcRelLoad(RegStorage reg, LIR* target); + void OpPcRelLoad(RegStorage reg, LIR* target); LIR* OpReg(OpKind op, RegStorage r_dest_src); void OpRegCopy(RegStorage r_dest, RegStorage r_src); LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); diff --git a/compiler/dex/quick/mips/int_mips.cc b/compiler/dex/quick/mips/int_mips.cc index 8c9acf60f1..8093c9772c 100644 --- a/compiler/dex/quick/mips/int_mips.cc +++ b/compiler/dex/quick/mips/int_mips.cc @@ -348,7 +348,7 @@ bool MipsMir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) { return true; } -LIR* MipsMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { +void MipsMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { UNUSED(reg, target); LOG(FATAL) << "Unexpected use of OpPcRelLoad for Mips"; UNREACHABLE(); diff --git a/compiler/dex/quick/mips64/assemble_mips64.cc b/compiler/dex/quick/mips64/assemble_mips64.cc index 17a0ef1bb4..d96561bba4 100644 --- a/compiler/dex/quick/mips64/assemble_mips64.cc +++ b/compiler/dex/quick/mips64/assemble_mips64.cc @@ -629,8 +629,8 @@ AssemblerStatus Mips64Mir2Lir::AssembleInstructions(CodeOffset start_addr) { * and is found in lir->target. If operands[3] is non-NULL, * then it is a Switch/Data table. */ - int offset1 = (reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])))->offset; - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + int offset1 = UnwrapPointer<LIR>(lir->operands[2])->offset; + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); int offset2 = tab_rec ? tab_rec->offset : lir->target->offset; int delta = offset2 - offset1; if ((delta & 0xffff) == delta && ((delta & 0x8000) == 0)) { @@ -651,14 +651,14 @@ AssemblerStatus Mips64Mir2Lir::AssembleInstructions(CodeOffset start_addr) { res = kRetryAll; } } else if (lir->opcode == kMips64DeltaLo) { - int offset1 = (reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])))->offset; - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + int offset1 = UnwrapPointer<LIR>(lir->operands[2])->offset; + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); int offset2 = tab_rec ? tab_rec->offset : lir->target->offset; int delta = offset2 - offset1; lir->operands[1] = delta & 0xffff; } else if (lir->opcode == kMips64DeltaHi) { - int offset1 = (reinterpret_cast<LIR*>(UnwrapPointer(lir->operands[2])))->offset; - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(lir->operands[3])); + int offset1 = UnwrapPointer<LIR>(lir->operands[2])->offset; + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(lir->operands[3]); int offset2 = tab_rec ? tab_rec->offset : lir->target->offset; int delta = offset2 - offset1; lir->operands[1] = (delta >> 16) & 0xffff; diff --git a/compiler/dex/quick/mips64/codegen_mips64.h b/compiler/dex/quick/mips64/codegen_mips64.h index 57c30d8b4b..c9fd62f757 100644 --- a/compiler/dex/quick/mips64/codegen_mips64.h +++ b/compiler/dex/quick/mips64/codegen_mips64.h @@ -182,7 +182,7 @@ class Mips64Mir2Lir FINAL : public Mir2Lir { LIR* OpIT(ConditionCode cond, const char* guide); void OpEndIT(LIR* it); LIR* OpMem(OpKind op, RegStorage r_base, int disp); - LIR* OpPcRelLoad(RegStorage reg, LIR* target); + void OpPcRelLoad(RegStorage reg, LIR* target); LIR* OpReg(OpKind op, RegStorage r_dest_src); void OpRegCopy(RegStorage r_dest, RegStorage r_src); LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src); diff --git a/compiler/dex/quick/mips64/int_mips64.cc b/compiler/dex/quick/mips64/int_mips64.cc index 8a57c82575..5c545bb824 100644 --- a/compiler/dex/quick/mips64/int_mips64.cc +++ b/compiler/dex/quick/mips64/int_mips64.cc @@ -283,7 +283,7 @@ bool Mips64Mir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) { return true; } -LIR* Mips64Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { +void Mips64Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { UNUSED(reg, target); LOG(FATAL) << "Unexpected use of OpPcRelLoad for Mips64"; UNREACHABLE(); diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h index 6ee26cc62b..236bad7451 100644 --- a/compiler/dex/quick/mir_to_lir.h +++ b/compiler/dex/quick/mir_to_lir.h @@ -585,14 +585,16 @@ class Mir2Lir { * TUNING: If use of these utilities becomes more common on 32-bit builds, it * may be worth conditionally-compiling a set of identity functions here. */ - uint32_t WrapPointer(void* pointer) { + template <typename T> + uint32_t WrapPointer(const T* pointer) { uint32_t res = pointer_storage_.size(); pointer_storage_.push_back(pointer); return res; } - void* UnwrapPointer(size_t index) { - return pointer_storage_[index]; + template <typename T> + const T* UnwrapPointer(size_t index) { + return reinterpret_cast<const T*>(pointer_storage_[index]); } // strdup(), but allocates from the arena. @@ -1383,7 +1385,7 @@ class Mir2Lir { virtual LIR* OpIT(ConditionCode cond, const char* guide) = 0; virtual void OpEndIT(LIR* it) = 0; virtual LIR* OpMem(OpKind op, RegStorage r_base, int disp) = 0; - virtual LIR* OpPcRelLoad(RegStorage reg, LIR* target) = 0; + virtual void OpPcRelLoad(RegStorage reg, LIR* target) = 0; virtual LIR* OpReg(OpKind op, RegStorage r_dest_src) = 0; virtual void OpRegCopy(RegStorage r_dest, RegStorage r_src) = 0; virtual LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) = 0; @@ -1759,7 +1761,7 @@ class Mir2Lir { ArenaVector<FillArrayData*> fill_array_data_; ArenaVector<RegisterInfo*> tempreg_info_; ArenaVector<RegisterInfo*> reginfo_map_; - ArenaVector<void*> pointer_storage_; + ArenaVector<const void*> pointer_storage_; CodeOffset data_offset_; // starting offset of literal pool. size_t total_size_; // header + code size. LIR* block_label_list_; diff --git a/compiler/dex/quick/x86/assemble_x86.cc b/compiler/dex/quick/x86/assemble_x86.cc index 6f26b78872..118ab1d843 100644 --- a/compiler/dex/quick/x86/assemble_x86.cc +++ b/compiler/dex/quick/x86/assemble_x86.cc @@ -1586,13 +1586,11 @@ void X86Mir2Lir::EmitPcRel(const X86EncodingMap* entry, int32_t raw_reg, int32_t int32_t raw_index, int scale, int32_t table_or_disp) { int disp; if (entry->opcode == kX86PcRelLoadRA) { - Mir2Lir::EmbeddedData *tab_rec = - reinterpret_cast<Mir2Lir::EmbeddedData*>(UnwrapPointer(table_or_disp)); + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(table_or_disp); disp = tab_rec->offset; } else { DCHECK(entry->opcode == kX86PcRelAdr); - Mir2Lir::EmbeddedData *tab_rec = - reinterpret_cast<Mir2Lir::EmbeddedData*>(UnwrapPointer(raw_base_or_table)); + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(raw_base_or_table); disp = tab_rec->offset; } if (entry->opcode == kX86PcRelLoadRA) { @@ -1794,8 +1792,7 @@ AssemblerStatus X86Mir2Lir::AssembleInstructions(CodeOffset start_addr) { DCHECK_EQ(lir->opcode, kX86Lea64RM) << "Unknown instruction: " << X86Mir2Lir::EncodingMap[lir->opcode].name; DCHECK_EQ(lir->operands[1], static_cast<int>(kRIPReg)); // Grab the target offset from the saved data. - Mir2Lir::EmbeddedData* tab_rec = - reinterpret_cast<Mir2Lir::EmbeddedData*>(UnwrapPointer(lir->operands[4])); + const EmbeddedData* tab_rec = UnwrapPointer<Mir2Lir::EmbeddedData>(lir->operands[4]); CodeOffset target = tab_rec->offset; // Handle 64 bit RIP addressing. // Offset is relative to next instruction. diff --git a/compiler/dex/quick/x86/codegen_x86.h b/compiler/dex/quick/x86/codegen_x86.h index 20163b4b76..040a8c4bef 100644 --- a/compiler/dex/quick/x86/codegen_x86.h +++ b/compiler/dex/quick/x86/codegen_x86.h @@ -296,7 +296,7 @@ class X86Mir2Lir : public Mir2Lir { LIR* OpIT(ConditionCode cond, const char* guide) OVERRIDE; void OpEndIT(LIR* it) OVERRIDE; LIR* OpMem(OpKind op, RegStorage r_base, int disp) OVERRIDE; - LIR* OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE; + void OpPcRelLoad(RegStorage reg, LIR* target) OVERRIDE; LIR* OpReg(OpKind op, RegStorage r_dest_src) OVERRIDE; void OpRegCopy(RegStorage r_dest, RegStorage r_src) OVERRIDE; LIR* OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) OVERRIDE; diff --git a/compiler/dex/quick/x86/int_x86.cc b/compiler/dex/quick/x86/int_x86.cc index 25e34e3027..4eb626c14f 100755 --- a/compiler/dex/quick/x86/int_x86.cc +++ b/compiler/dex/quick/x86/int_x86.cc @@ -1324,7 +1324,7 @@ bool X86Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) { return true; } -LIR* X86Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { +void X86Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { if (cu_->target64) { // We can do this directly using RIP addressing. // We don't know the proper offset for the value, so pick one that will force @@ -1334,7 +1334,7 @@ LIR* X86Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { LIR* res = NewLIR3(kX86Mov32RM, reg.GetReg(), kRIPReg, 256); res->target = target; res->flags.fixup = kFixupLoad; - return res; + return; } CHECK(base_of_code_ != nullptr); @@ -1353,11 +1353,9 @@ LIR* X86Mir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { // 4 byte offset. We will fix this up in the assembler later to have the right // value. ScopedMemRefType mem_ref_type(this, ResourceMask::kLiteral); - LIR *res = RawLIR(current_dalvik_offset_, kX86Mov32RM, reg.GetReg(), reg.GetReg(), 256, - 0, 0, target); + LIR* res = NewLIR3(kX86Mov32RM, reg.GetReg(), reg.GetReg(), 256); res->target = target; res->flags.fixup = kFixupLoad; - return res; } LIR* X86Mir2Lir::OpVldm(RegStorage r_base, int count) { diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc index dbe48488a1..f128eb78a3 100755 --- a/compiler/dex/quick/x86/target_x86.cc +++ b/compiler/dex/quick/x86/target_x86.cc @@ -390,7 +390,7 @@ std::string X86Mir2Lir::BuildInsnString(const char *fmt, LIR *lir, unsigned char break; } case 'p': { - EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(operand)); + const EmbeddedData* tab_rec = UnwrapPointer<EmbeddedData>(operand); buf += StringPrintf("0x%08x", tab_rec->offset); break; } @@ -1062,8 +1062,7 @@ void X86Mir2Lir::InstallLiteralPools() { for (LIR* p : method_address_insns_) { DCHECK_EQ(p->opcode, kX86Mov32RI); uint32_t target_method_idx = p->operands[2]; - const DexFile* target_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[3])); + const DexFile* target_dex_file = UnwrapPointer<DexFile>(p->operands[3]); // The offset to patch is the last 4 bytes of the instruction. int patch_offset = p->offset + p->flags.size - 4; @@ -1075,8 +1074,7 @@ void X86Mir2Lir::InstallLiteralPools() { for (LIR* p : class_type_address_insns_) { DCHECK_EQ(p->opcode, kX86Mov32RI); - const DexFile* class_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[3])); + const DexFile* class_dex_file = UnwrapPointer<DexFile>(p->operands[3]); uint32_t target_type_idx = p->operands[2]; // The offset to patch is the last 4 bytes of the instruction. @@ -1090,8 +1088,7 @@ void X86Mir2Lir::InstallLiteralPools() { for (LIR* p : call_method_insns_) { DCHECK_EQ(p->opcode, kX86CallI); uint32_t target_method_idx = p->operands[1]; - const DexFile* target_dex_file = - reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[2])); + const DexFile* target_dex_file = UnwrapPointer<DexFile>(p->operands[2]); // The offset to patch is the last 4 bytes of the instruction. int patch_offset = p->offset + p->flags.size - 4; |