Use intrinsic codegen for compiling intrinsic methods.
When compiling an intrinsic method, generate a graph that
invokes the same method and try to compile it. If the call
is actually intrinsified (or simplified to other HIR) and
yields a leaf method, use the result of this compilation
attempt, otherwise compile the actual code or JNI stub.
Note that CodeGenerator::CreateThrowingSlowPathLocations()
actually marks the locations as kNoCall if the throw is not
in a catch block, thus considering some throwing methods
(for example, String.charAt()) as leaf methods.
We would ideally want to use the intrinsic codegen for all
intrinsics that do not generate a slow-path call to the
default implementation. Relying on the leaf method is
suboptimal as we're missing out on methods that do other
types of calls, for example runtime calls. This shall be
fixed in a subsequent CL.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 67717501
Change-Id: I640fda7c22d4ff494b5ff77ebec3b7f5f75af652
diff --git a/compiler/optimizing/block_builder.h b/compiler/optimizing/block_builder.h
index 79f7a7b..7d0f56d 100644
--- a/compiler/optimizing/block_builder.h
+++ b/compiler/optimizing/block_builder.h
@@ -28,14 +28,15 @@
public:
HBasicBlockBuilder(HGraph* graph,
const DexFile* const dex_file,
- const DexFile::CodeItem& code_item,
+ const DexFile::CodeItem* code_item,
ScopedArenaAllocator* local_allocator)
: allocator_(graph->GetAllocator()),
graph_(graph),
dex_file_(dex_file),
code_item_(code_item),
local_allocator_(local_allocator),
- branch_targets_(code_item.insns_size_in_code_units_,
+ branch_targets_(code_item != nullptr ? code_item->insns_size_in_code_units_
+ : /* fake dex_pc=0 for intrinsic graph */ 1u,
nullptr,
local_allocator->Adapter(kArenaAllocGraphBuilder)),
throwing_blocks_(kDefaultNumberOfThrowingBlocks,
@@ -50,6 +51,9 @@
// exits a try block.
bool Build();
+ // Creates basic blocks in `graph_` for compiling an intrinsic.
+ void BuildIntrinsic();
+
size_t GetNumberOfBranches() const { return number_of_branches_; }
HBasicBlock* GetBlockAt(uint32_t dex_pc) const { return branch_targets_[dex_pc]; }
@@ -79,7 +83,7 @@
HGraph* const graph_;
const DexFile* const dex_file_;
- const DexFile::CodeItem& code_item_;
+ const DexFile::CodeItem* const code_item_; // null for intrinsic graph.
ScopedArenaAllocator* const local_allocator_;
ScopedArenaVector<HBasicBlock*> branch_targets_;