From 4ef3e45d7c6ec3c482a1a48f4df470811aa3cf0a Mon Sep 17 00:00:00 2001 From: buzbee Date: Fri, 14 Dec 2012 13:35:28 -0800 Subject: Compiler constant handling rework In preparation for de-optimization, reworked the constant handling mechanism. Also took advantage of knowledge of constant operands (particularly for long operations). Significant performance improvements for Mandelbrot (~60 seconds to ~34 seconds). Minor improvements in other benchmarks. The new constant handling breaks two of the existing optimization passes: "Skip Large Method" and "Load/Store Elimization." I don't intend to update the large method optimization because it will be superceeded by the upcoming interpreter/ fingerprinting mechanism. Leaving the code in place for now in order to compare compile-time improvements with fingerprinting/interpret. All related code will be deleted when that is complete. The load/store elimination pass needs some rework to handle uses of multiple-register loads and stores. It will be updated & restored in a future CL. Change-Id: Ia979abaf51b8ae81bbb0428031cbcea854625fac --- src/compiler/codegen/codegen_util.cc | 45 +++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/compiler/codegen/codegen_util.cc') diff --git a/src/compiler/codegen/codegen_util.cc b/src/compiler/codegen/codegen_util.cc index ad05b93c8d..57d932f6e3 100644 --- a/src/compiler/codegen/codegen_util.cc +++ b/src/compiler/codegen/codegen_util.cc @@ -23,6 +23,27 @@ namespace art { +bool IsInexpensiveConstant(CompilationUnit* cu, RegLocation rl_src) +{ + bool res = false; + if (rl_src.is_const) { + if (rl_src.wide) { + if (rl_src.fp) { + res = cu->cg->InexpensiveConstantDouble(ConstantValueWide(cu, rl_src)); + } else { + res = cu->cg->InexpensiveConstantLong(ConstantValueWide(cu, rl_src)); + } + } else { + if (rl_src.fp) { + res = cu->cg->InexpensiveConstantFloat(ConstantValue(cu, rl_src)); + } else { + res = cu->cg->InexpensiveConstantInt(ConstantValue(cu, rl_src)); + } + } + } + return res; +} + void MarkSafepointPC(CompilationUnit* cu, LIR* inst) { inst->def_mask = ENCODE_ALL; @@ -202,6 +223,9 @@ void DumpLIRInsn(CompilationUnit* cu, LIR* lir, unsigned char* base_addr) LOG(INFO) << "-------- entry offset: 0x" << std::hex << dest; break; case kPseudoDalvikByteCodeBoundary: + if (lir->operands[0] == 0) { + lir->operands[0] = reinterpret_cast("No instruction string"); + } LOG(INFO) << "-------- dalvik offset: 0x" << std::hex << lir->dalvik_offset << " @ " << reinterpret_cast(lir->operands[0]); break; @@ -471,6 +495,8 @@ LIR* ScanLiteralPoolWide(LIR* data_target, int val_lo, int val_hi) LIR* lo_target = NULL; while (data_target) { if (lo_match && (data_target->operands[0] == val_hi)) { + // Record high word in case we need to expand this later. + lo_target->operands[1] = val_hi; return lo_target; } lo_match = false; @@ -488,7 +514,7 @@ LIR* ScanLiteralPoolWide(LIR* data_target, int val_lo, int val_hi) * instruction streams. */ -/* Add a 32-bit constant either in the constant pool */ +/* Add a 32-bit constant to the constant pool */ LIR* AddWordData(CompilationUnit* cu, LIR* *constant_list_p, int value) { /* Add the constant to the literal pool */ @@ -1097,4 +1123,21 @@ bool EvaluateBranch(Instruction::Code opcode, int32_t src1, int32_t src2) return is_taken; } +// Convert relation of src1/src2 to src2/src1 +ConditionCode FlipComparisonOrder(ConditionCode before) { + ConditionCode res; + switch (before) { + case kCondEq: res = kCondEq; break; + case kCondNe: res = kCondNe; break; + case kCondLt: res = kCondGt; break; + case kCondGt: res = kCondLt; break; + case kCondLe: res = kCondGe; break; + case kCondGe: res = kCondLe; break; + default: + res = static_cast(0); + LOG(FATAL) << "Unexpected ccode " << before; + } + return res; +} + } // namespace art -- cgit v1.2.3-59-g8ed1b