Replace a few std::vector with ArenaVector in Mir2Lir.
Change-Id: I7867d60afc60f57cdbbfd312f02883854d65c805
diff --git a/compiler/dex/quick/codegen_util.cc b/compiler/dex/quick/codegen_util.cc
index 055c39f..0be9fd4 100644
--- a/compiler/dex/quick/codegen_util.cc
+++ b/compiler/dex/quick/codegen_util.cc
@@ -456,37 +456,29 @@
return AddWordData(constant_list_p, val_lo);
}
-static void Push32(std::vector<uint8_t>&buf, int data) {
- buf.push_back(data & 0xff);
- buf.push_back((data >> 8) & 0xff);
- buf.push_back((data >> 16) & 0xff);
- buf.push_back((data >> 24) & 0xff);
-}
-
/**
* @brief Push a compressed reference which needs patching at link/patchoat-time.
* @details This needs to be kept consistent with the code which actually does the patching in
* oat_writer.cc and in the patchoat tool.
*/
-static void PushUnpatchedReference(std::vector<uint8_t>&buf) {
+static void PushUnpatchedReference(CodeBuffer* buf) {
// Note that we can safely initialize the patches to zero. The code deduplication mechanism takes
// the patches into account when determining whether two pieces of codes are functionally
// equivalent.
Push32(buf, UINT32_C(0));
}
-static void AlignBuffer(std::vector<uint8_t>&buf, size_t offset) {
- while (buf.size() < offset) {
- buf.push_back(0);
- }
+static void AlignBuffer(CodeBuffer* buf, size_t offset) {
+ DCHECK_LE(buf->size(), offset);
+ buf->insert(buf->end(), offset - buf->size(), 0u);
}
/* Write the literal pool to the output stream */
void Mir2Lir::InstallLiteralPools() {
- AlignBuffer(code_buffer_, data_offset_);
+ AlignBuffer(&code_buffer_, data_offset_);
LIR* data_lir = literal_list_;
while (data_lir != nullptr) {
- Push32(code_buffer_, data_lir->operands[0]);
+ Push32(&code_buffer_, data_lir->operands[0]);
data_lir = NEXT_LIR(data_lir);
}
// TODO: patches_.reserve() as needed.
@@ -498,7 +490,7 @@
reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1]));
patches_.push_back(LinkerPatch::CodePatch(code_buffer_.size(),
target_dex_file, target_method_idx));
- PushUnpatchedReference(code_buffer_);
+ PushUnpatchedReference(&code_buffer_);
data_lir = NEXT_LIR(data_lir);
}
data_lir = method_literal_list_;
@@ -508,7 +500,7 @@
reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1]));
patches_.push_back(LinkerPatch::MethodPatch(code_buffer_.size(),
target_dex_file, target_method_idx));
- PushUnpatchedReference(code_buffer_);
+ PushUnpatchedReference(&code_buffer_);
data_lir = NEXT_LIR(data_lir);
}
// Push class literals.
@@ -519,7 +511,7 @@
reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1]));
patches_.push_back(LinkerPatch::TypePatch(code_buffer_.size(),
class_dex_file, target_type_idx));
- PushUnpatchedReference(code_buffer_);
+ PushUnpatchedReference(&code_buffer_);
data_lir = NEXT_LIR(data_lir);
}
}
@@ -527,7 +519,7 @@
/* Write the switch tables to the output stream */
void Mir2Lir::InstallSwitchTables() {
for (Mir2Lir::SwitchTable* tab_rec : switch_tables_) {
- AlignBuffer(code_buffer_, tab_rec->offset);
+ AlignBuffer(&code_buffer_, tab_rec->offset);
/*
* For Arm, our reference point is the address of the bx
* instruction that does the launch, so we have to subtract
@@ -567,8 +559,8 @@
LIR* boundary_lir = InsertCaseLabel(target, key);
DCHECK(boundary_lir != nullptr);
int disp = boundary_lir->offset - bx_offset;
- Push32(code_buffer_, key);
- Push32(code_buffer_, disp);
+ Push32(&code_buffer_, key);
+ Push32(&code_buffer_, disp);
if (cu_->verbose) {
LOG(INFO) << " Case[" << elems << "] key: 0x"
<< std::hex << key << ", disp: 0x"
@@ -592,7 +584,7 @@
LIR* boundary_lir = InsertCaseLabel(target, key);
DCHECK(boundary_lir != nullptr);
int disp = boundary_lir->offset - bx_offset;
- Push32(code_buffer_, disp);
+ Push32(&code_buffer_, disp);
if (cu_->verbose) {
LOG(INFO) << " Case[" << elems << "] disp: 0x"
<< std::hex << disp;
@@ -607,7 +599,7 @@
/* Write the fill array dta to the output stream */
void Mir2Lir::InstallFillArrayData() {
for (Mir2Lir::FillArrayData* tab_rec : fill_array_data_) {
- AlignBuffer(code_buffer_, tab_rec->offset);
+ AlignBuffer(&code_buffer_, tab_rec->offset);
for (int i = 0; i < (tab_rec->size + 1) / 2; i++) {
code_buffer_.push_back(tab_rec->table[i] & 0xFF);
code_buffer_.push_back((tab_rec->table[i] >> 8) & 0xFF);
@@ -975,8 +967,11 @@
estimated_native_code_size_(0),
reg_pool_(nullptr),
live_sreg_(0),
+ code_buffer_(mir_graph->GetArena()->Adapter()),
+ encoded_mapping_table_(mir_graph->GetArena()->Adapter()),
core_vmap_table_(mir_graph->GetArena()->Adapter()),
fp_vmap_table_(mir_graph->GetArena()->Adapter()),
+ native_gc_map_(mir_graph->GetArena()->Adapter()),
patches_(mir_graph->GetArena()->Adapter()),
num_core_spills_(0),
num_fp_spills_(0),
diff --git a/compiler/dex/quick/mir_to_lir.h b/compiler/dex/quick/mir_to_lir.h
index 88ca911..6fdd764 100644
--- a/compiler/dex/quick/mir_to_lir.h
+++ b/compiler/dex/quick/mir_to_lir.h
@@ -146,7 +146,7 @@
uint32_t method_idx, uintptr_t direct_code,
uintptr_t direct_method, InvokeType type);
-typedef std::vector<uint8_t> CodeBuffer;
+typedef ArenaVector<uint8_t> CodeBuffer;
typedef uint32_t CodeOffset; // Native code offset in bytes.
struct UseDefMasks {
@@ -1742,10 +1742,10 @@
// The source mapping table data (pc -> dex). More entries than in encoded_mapping_table_
DefaultSrcMap src_mapping_table_;
// The encoding mapping table data (dex -> pc offset and pc offset -> dex) with a size prefix.
- std::vector<uint8_t> encoded_mapping_table_;
+ ArenaVector<uint8_t> encoded_mapping_table_;
ArenaVector<uint32_t> core_vmap_table_;
ArenaVector<uint32_t> fp_vmap_table_;
- std::vector<uint8_t> native_gc_map_;
+ ArenaVector<uint8_t> native_gc_map_;
ArenaVector<LinkerPatch> patches_;
int num_core_spills_;
int num_fp_spills_;
diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc
index c4adb09..8f97d1e 100755
--- a/compiler/dex/quick/x86/target_x86.cc
+++ b/compiler/dex/quick/x86/target_x86.cc
@@ -1051,10 +1051,10 @@
}
for (LIR *p = const_vectors_; p != nullptr; p = p->next) {
- PushWord(&code_buffer_, p->operands[0]);
- PushWord(&code_buffer_, p->operands[1]);
- PushWord(&code_buffer_, p->operands[2]);
- PushWord(&code_buffer_, p->operands[3]);
+ Push32(&code_buffer_, p->operands[0]);
+ Push32(&code_buffer_, p->operands[1]);
+ Push32(&code_buffer_, p->operands[2]);
+ Push32(&code_buffer_, p->operands[3]);
}
}