Get SEA fibonacci running in interpreter mode.
Android.mk: Added new file to build.
compile_driver.cc: Moved SE_IR usage test in the block
protected by bool compile, which is enabled by
adding a sepatate test in IsCnadidateForCompilation.
class_linker.cc: Added check in NeedsInterpreter to enable SEA_IR.
art_method-inl.h: DIsabled check in SEA_IR mode.
method_verifier.cc: Added check for SEA_IR mode.
method_verifier.h: Chenged IsCandidateForCompilation signature to
allow testing the function name (for SEA_IR selective
compilation).
dot_gen.h: Updated ART file API usage to altest version.
sea_ir/frontend.cc: Passing function symbol name to CompileMethod.
instruction_Nodes.h: Added accessor for method index for
InvokeStatic IR node.
sea.cc: Added additional IR SignatureNode for function calls (extra
Method parameter). Fixed UnnamedConstant constant value.
sea.h: Passing function_name to GenerateLLVM.
type_inference_visitor.cc: Aded type for first (placeholder) method
parameter.
Change-Id: I295858ea0761a3dffb36f35748d8b93d4919d6a9
diff --git a/compiler/sea_ir/ir/instruction_nodes.h b/compiler/sea_ir/ir/instruction_nodes.h
index 906a10f..63e89e7 100644
--- a/compiler/sea_ir/ir/instruction_nodes.h
+++ b/compiler/sea_ir/ir/instruction_nodes.h
@@ -56,6 +56,8 @@
// essentially creating SSA form.
void RenameToSSA(int reg_no, InstructionNode* definition) {
definition_edges_.insert(std::pair<int, InstructionNode*>(reg_no, definition));
+ DCHECK(NULL != definition) << "SSA definition for register " << reg_no
+ << " used in instruction " << Id() << " not found.";
definition->AddSSAUse(this);
}
// Returns the ordered set of Instructions that define the input operands of this instruction.
@@ -179,14 +181,22 @@
class InvokeStaticInstructionNode: public InstructionNode {
public:
- explicit InvokeStaticInstructionNode(const art::Instruction* inst): InstructionNode(inst) { }
+ explicit InvokeStaticInstructionNode(const art::Instruction* inst): InstructionNode(inst),
+ method_index_(inst->VRegB_35c()) { }
int GetResultRegister() const {
return RETURN_REGISTER;
}
+
+ int GetCalledMethodIndex() const {
+ return method_index_;
+ }
void Accept(IRVisitor* v) {
v->Visit(this);
v->Traverse(this);
}
+
+ private:
+ const uint32_t method_index_;
};
class AddIntInstructionNode: public InstructionNode {
diff --git a/compiler/sea_ir/ir/sea.cc b/compiler/sea_ir/ir/sea.cc
index 902839d..5ccaba6 100644
--- a/compiler/sea_ir/ir/sea.cc
+++ b/compiler/sea_ir/ir/sea.cc
@@ -174,6 +174,21 @@
DCHECK(!changed) << "Reaching definitions computation did not reach a fixed point.";
}
+void SeaGraph::InsertSignatureNodes(const art::DexFile::CodeItem* code_item, Region* r) {
+ // Insert a fake SignatureNode for the first parameter.
+ // TODO: Provide a register enum value for the fake parameter.
+ SignatureNode* parameter_def_node = new sea_ir::SignatureNode(0, 0);
+ AddParameterNode(parameter_def_node);
+ r->AddChild(parameter_def_node);
+ // Insert SignatureNodes for each Dalvik register parameter.
+ for (unsigned int crt_offset = 0; crt_offset < code_item->ins_size_; crt_offset++) {
+ int register_no = code_item->registers_size_ - crt_offset - 1;
+ int position = crt_offset + 1;
+ SignatureNode* parameter_def_node = new sea_ir::SignatureNode(register_no, position);
+ AddParameterNode(parameter_def_node);
+ r->AddChild(parameter_def_node);
+ }
+}
void SeaGraph::BuildMethodSeaGraph(const art::DexFile::CodeItem* code_item,
const art::DexFile& dex_file, uint32_t class_def_idx,
@@ -209,15 +224,8 @@
Region* r = GetNewRegion();
- // Insert one SignatureNode per function argument,
- // to serve as placeholder definitions in dataflow analysis.
- for (unsigned int crt_offset = 0; crt_offset < code_item->ins_size_; crt_offset++) {
- int position = crt_offset; // TODO: Is this the correct offset in the signature?
- SignatureNode* parameter_def_node =
- new sea_ir::SignatureNode(code_item->registers_size_ - 1 - crt_offset, position);
- AddParameterNode(parameter_def_node);
- r->AddChild(parameter_def_node);
- }
+
+ InsertSignatureNodes(code_item, r);
// Pass: Assign instructions to region nodes and
// assign branches their control flow successors.
i = 0;
@@ -386,23 +394,21 @@
scoped_table->CloseScope();
}
-CodeGenData* SeaGraph::GenerateLLVM() {
+CodeGenData* SeaGraph::GenerateLLVM(const std::string& function_name,
+ const art::DexFile& dex_file) {
// Pass: Generate LLVM IR.
- CodeGenPrepassVisitor code_gen_prepass_visitor;
+ CodeGenPrepassVisitor code_gen_prepass_visitor(function_name);
std::cout << "Generating code..." << std::endl;
- std::cout << "=== PRE VISITING ===" << std::endl;
Accept(&code_gen_prepass_visitor);
- CodeGenVisitor code_gen_visitor(code_gen_prepass_visitor.GetData());
- std::cout << "=== VISITING ===" << std::endl;
+ CodeGenVisitor code_gen_visitor(code_gen_prepass_visitor.GetData(), dex_file);
Accept(&code_gen_visitor);
- std::cout << "=== POST VISITING ===" << std::endl;
CodeGenPostpassVisitor code_gen_postpass_visitor(code_gen_visitor.GetData());
Accept(&code_gen_postpass_visitor);
- code_gen_postpass_visitor.Write(std::string("my_file.llvm"));
return code_gen_postpass_visitor.GetData();
}
CodeGenData* SeaGraph::CompileMethod(
+ const std::string& function_name,
const art::DexFile::CodeItem* code_item, uint32_t class_def_idx,
uint32_t method_idx, uint32_t method_access_flags, const art::DexFile& dex_file) {
// Two passes: Builds the intermediate structure (non-SSA) of the sea-ir for the function.
@@ -422,7 +428,7 @@
// Pass: type inference
ti_->ComputeTypes(this);
// Pass: Generate LLVM IR.
- CodeGenData* cgd = GenerateLLVM();
+ CodeGenData* cgd = GenerateLLVM(function_name, dex_file);
return cgd;
}
@@ -607,7 +613,7 @@
sea_instructions.push_back(new IfNeInstructionNode(in));
break;
case art::Instruction::ADD_INT_LIT8:
- sea_instructions.push_back(new UnnamedConstInstructionNode(in, in->VRegB_22b()));
+ sea_instructions.push_back(new UnnamedConstInstructionNode(in, in->VRegC_22b()));
sea_instructions.push_back(new AddIntLitInstructionNode(in));
break;
case art::Instruction::MOVE_RESULT:
diff --git a/compiler/sea_ir/ir/sea.h b/compiler/sea_ir/ir/sea.h
index df420ed..92c2043 100644
--- a/compiler/sea_ir/ir/sea.h
+++ b/compiler/sea_ir/ir/sea.h
@@ -50,12 +50,12 @@
class SignatureNode: public InstructionNode {
public:
// Creates a new signature node representing the initial definition of the
- // register @parameter_register which is the @position-th argument to the method.
- explicit SignatureNode(unsigned int parameter_register, unsigned int position):
- InstructionNode(NULL), parameter_register_(parameter_register), position_(position) { }
+ // register @register_no which is the @signature_position-th argument to the method.
+ explicit SignatureNode(unsigned int register_no, unsigned int signature_position):
+ InstructionNode(NULL), register_no_(register_no), position_(signature_position) { }
int GetResultRegister() const {
- return parameter_register_;
+ return register_no_;
}
unsigned int GetPositionInSignature() const {
@@ -72,7 +72,7 @@
}
private:
- const unsigned int parameter_register_;
+ const unsigned int register_no_;
const unsigned int position_; // The position of this parameter node is
// in the function parameter list.
};
@@ -261,7 +261,8 @@
public:
static SeaGraph* GetGraph(const art::DexFile&);
- CodeGenData* CompileMethod(const art::DexFile::CodeItem* code_item, uint32_t class_def_idx,
+ CodeGenData* CompileMethod(const std::string& function_name,
+ const art::DexFile::CodeItem* code_item, uint32_t class_def_idx,
uint32_t method_idx, uint32_t method_access_flags, const art::DexFile& dex_file);
// Returns all regions corresponding to this SeaGraph.
std::vector<Region*>* GetRegions() {
@@ -338,7 +339,9 @@
void RenameAsSSA(Region* node, utils::ScopedHashtable<int, InstructionNode*>* scoped_table);
// Generate LLVM IR for the method.
// Precondition: ConvertToSSA().
- CodeGenData* GenerateLLVM();
+ CodeGenData* GenerateLLVM(const std::string& function_name, const art::DexFile& dex_file);
+ // Inserts one SignatureNode for each argument of the function in
+ void InsertSignatureNodes(const art::DexFile::CodeItem* code_item, Region* r);
static SeaGraph graph_;
std::vector<Region*> regions_;