summaryrefslogtreecommitdiffstats
path: root/compiler/sea_ir
diff options
context:
space:
mode:
authorDragos Sbirlea <dragoss@google.com>2013-07-23 14:31:47 -0700
committerDragos Sbirlea <dragoss@google.com>2013-07-23 22:48:32 +0000
commit81f79a6672a0bd610f05770d8c96e03e276798da (patch)
tree1b9c9c3d60a528293d822b33bb9d3008913c0218 /compiler/sea_ir
parent35275ec4cfe0ebfc247d13c2c96d27c10dc804f9 (diff)
downloadart-81f79a6672a0bd610f05770d8c96e03e276798da.zip
art-81f79a6672a0bd610f05770d8c96e03e276798da.tar.gz
art-81f79a6672a0bd610f05770d8c96e03e276798da.tar.bz2
Refactored string to int conversion.
I was using stringstream for int to std::string, but the StringPrintf utility is shorter and cleaner. Change-Id: I454488602459071abb8b846ff7ac8b9594e9d824
Diffstat (limited to 'compiler/sea_ir')
-rw-r--r--compiler/sea_ir/code_gen.cc15
-rw-r--r--compiler/sea_ir/frontend.cc1
-rw-r--r--compiler/sea_ir/sea.cc18
-rw-r--r--compiler/sea_ir/sea.h8
-rw-r--r--compiler/sea_ir/sea_node.h6
5 files changed, 15 insertions, 33 deletions
diff --git a/compiler/sea_ir/code_gen.cc b/compiler/sea_ir/code_gen.cc
index 0bb3a26..4e15cf6 100644
--- a/compiler/sea_ir/code_gen.cc
+++ b/compiler/sea_ir/code_gen.cc
@@ -66,10 +66,7 @@ void CodeGenPrepassVisitor::Visit(SeaGraph* graph) {
std::vector<llvm::Type*> parameter_types(parameters->size(),
llvm::Type::getInt32Ty(*llvm_data_->context_));
// Build llvm function name.
- std::string function_name = "class=";
- std::stringstream ss;
- ss << graph->class_def_idx_ << "_method=" << graph->method_idx_;
- function_name.append(ss.str());
+ std::string function_name = art::StringPrintf("class=%d_method=%d", graph->class_def_idx_, graph->method_idx_);
// Build llvm function type and parameters.
llvm::FunctionType *function_type = llvm::FunctionType::get(
@@ -82,10 +79,7 @@ void CodeGenPrepassVisitor::Visit(SeaGraph* graph) {
param_id != llvm_data_->function_->arg_size(); ++arg_it, ++param_id) {
DCHECK(parameters->size() > param_id) << "Insufficient parameters for function signature";
// Build parameter register name for LLVM IR clarity.
- std::stringstream ss;
- ss << "r" << parameters->at(param_id);
- std::string arg_name;
- arg_name.append(ss.str());
+ std::string arg_name = art::StringPrintf("r%d", parameters->at(param_id));
arg_it->setName(arg_name);
SignatureNode* parameter = parameters->at(param_id);
llvm_data_->AddValue(parameter, arg_it);
@@ -187,10 +181,7 @@ void CodeGenVisitor::Visit(InvokeStaticInstructionNode* invoke) {
std::string instr = invoke->GetInstruction()->DumpString(NULL);
std::cout << "6.Instruction: " << instr << std::endl;
// TODO: Build callee llvm function name.
- std::string function_name = "class=";
- std::stringstream ss;
- ss << 0 << "_method=" << 1;
- function_name.append(ss.str());
+ std::string function_name = art::StringPrintf("class=%d_method=%d", 0, 1);
llvm::Function *callee = llvm_data_->module_.getFunction(function_name);
// TODO: Add proper checking of the matching between formal and actual signature.
DCHECK(NULL != callee);
diff --git a/compiler/sea_ir/frontend.cc b/compiler/sea_ir/frontend.cc
index 7bfc9ba..bae3cb2 100644
--- a/compiler/sea_ir/frontend.cc
+++ b/compiler/sea_ir/frontend.cc
@@ -47,7 +47,6 @@ static CompiledMethod* CompileMethodWithSeaIr(CompilerDriver& compiler,
return NULL;
}
-
CompiledMethod* SeaIrCompileOneMethod(CompilerDriver& compiler,
const CompilerBackend backend,
const DexFile::CodeItem* code_item,
diff --git a/compiler/sea_ir/sea.cc b/compiler/sea_ir/sea.cc
index 347fcff..ae0cb17 100644
--- a/compiler/sea_ir/sea.cc
+++ b/compiler/sea_ir/sea.cc
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#include "runtime/base/stringprintf.h"
#include "file_output_stream.h"
#include "instruction_tools.h"
#include "sea.h"
@@ -492,9 +492,7 @@ SeaNode* Region::GetLastChild() const {
void Region::ToDot(std::string& result) const {
result += "\n// Region: \n" + StringId() + " [label=\"region " + StringId() + "(rpo=";
- std::stringstream ss;
- ss << rpo_;
- result.append(ss.str());
+ result += art::StringPrintf("%", rpo_number_);
if (NULL != GetIDominator()) {
result += " dom=" + GetIDominator()->StringId();
}
@@ -712,9 +710,7 @@ void InstructionNode::ToDot(std::string& result) const {
def_it != definition_edges_.end(); def_it++) {
if (NULL != def_it->second) {
result += def_it->second->StringId() + " -> " + StringId() +"[color=red,label=\"";
- std::stringstream ss;
- ss << def_it->first;
- result.append(ss.str());
+ result.append(art::StringPrintf("%", def_it->first));
result += "\"] ; // ssa edge\n";
}
}
@@ -763,9 +759,7 @@ std::vector<int> InstructionNode::GetUses() {
void PhiInstructionNode::ToDot(std::string& result) const {
result += "// PhiInstruction: \n" + StringId() +
" [label=\"" + "PHI(";
- std::stringstream phi_reg_stream;
- phi_reg_stream << register_no_;
- result.append(phi_reg_stream.str());
+ result += art::StringPrintf("%d", register_no_);
result += ")\"";
result += "];\n";
@@ -775,9 +769,7 @@ void PhiInstructionNode::ToDot(std::string& result) const {
for (std::vector<InstructionNode* >::const_iterator def_it = defs_from_pred->begin();
def_it != defs_from_pred->end(); def_it++) {
result += (*def_it)->StringId() + " -> " + StringId() +"[color=red,label=\"vR = ";
- std::stringstream ss;
- ss << GetRegisterNumber();
- result.append(ss.str());
+ result += StringPrintf("%d", GetRegisterNumber());
result += "\"] ; // phi-ssa edge\n";
}
}
diff --git a/compiler/sea_ir/sea.h b/compiler/sea_ir/sea.h
index 81a1b88..28d0c17 100644
--- a/compiler/sea_ir/sea.h
+++ b/compiler/sea_ir/sea.h
@@ -137,7 +137,7 @@ class Region : public SeaNode {
public:
explicit Region():
SeaNode(), successors_(), predecessors_(), reaching_defs_size_(0),
- rpo_(NOT_VISITED), idom_(NULL), idominated_set_(), df_(), phi_set_() {}
+ rpo_number_(NOT_VISITED), idom_(NULL), idominated_set_(), df_(), phi_set_() {}
// Adds @instruction as an instruction node child in the current region.
void AddChild(sea_ir::InstructionNode* instruction);
// Returns the last instruction node child of the current region.
@@ -161,11 +161,11 @@ class Region : public SeaNode {
std::map<int, std::set<sea_ir::InstructionNode*>* >* GetReachingDefs();
void SetRPO(int rpo) {
- rpo_ = rpo;
+ rpo_number_ = rpo;
}
int GetRPO() {
- return rpo_;
+ return rpo_number_;
}
void SetIDominator(Region* dom) {
@@ -237,7 +237,7 @@ class Region : public SeaNode {
std::map<int, sea_ir::InstructionNode*> de_defs_;
std::map<int, std::set<sea_ir::InstructionNode*>* > reaching_defs_;
int reaching_defs_size_;
- int rpo_;
+ int rpo_number_; // reverse postorder number of the region
// Immediate dominator node.
Region* idom_;
// The set of nodes immediately dominated by the region.
diff --git a/compiler/sea_ir/sea_node.h b/compiler/sea_ir/sea_node.h
index 7d198b2..88ebe23 100644
--- a/compiler/sea_ir/sea_node.h
+++ b/compiler/sea_ir/sea_node.h
@@ -17,6 +17,8 @@
#ifndef ART_COMPILER_SEA_IR_SEA_NODE_H_
#define ART_COMPILER_SEA_IR_SEA_NODE_H_
+#include "runtime/base/stringprintf.h"
+
namespace sea_ir {
class Region;
class IRVisitor;
@@ -38,9 +40,7 @@ class IVisitable {
class SeaNode: public IVisitable {
public:
explicit SeaNode():id_(GetNewId()), string_id_() {
- std::stringstream ss;
- ss << id_;
- string_id_.append(ss.str());
+ string_id_ = art::StringPrintf("%", id_);
}
// Adds CFG predecessors and successors to each block.
void AddSuccessor(Region* successor);