Skip to content

Commit

Permalink
Compiled reduce without disabling profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexp-sssup committed Mar 24, 2011
1 parent 1b5e452 commit 14b6788
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
9 changes: 6 additions & 3 deletions scripting/abc.h
Expand Up @@ -309,10 +309,12 @@ friend struct block_info;
const llvm::Type* int_type);
static void compileCallProperty(int t, int t2, std::vector<stack_entry>& static_stack, llvm::Value* dynamic_stack,
llvm::Value* dynamic_stack_index, llvm::Value* callContext,
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex, const llvm::Type* int_type);
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex,
const llvm::Type* int_type, const llvm::Type* voidptr_type);
static void compileCallPropVoid(int t, int t2, std::vector<stack_entry>& static_stack, llvm::Value* dynamic_stack,
llvm::Value* dynamic_stack_index, llvm::Value* callContext,
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex, const llvm::Type* int_type);
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex,
const llvm::Type* int_type, const llvm::Type* voidptr_type);
static void compileConvert_i(std::vector<stack_entry>& static_stack, llvm::Value* dynamic_stack,
llvm::Value* dynamic_stack_index, llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex,
const llvm::Type* int_type);
Expand Down Expand Up @@ -533,7 +535,8 @@ struct opcode_handler
};

enum ARGS_TYPE { ARGS_OBJ_OBJ=0, ARGS_OBJ_INT, ARGS_OBJ, ARGS_INT, ARGS_OBJ_OBJ_INT, ARGS_NUMBER, ARGS_OBJ_NUMBER,
ARGS_BOOL, ARGS_INT_OBJ, ARGS_NONE, ARGS_NUMBER_OBJ, ARGS_INT_INT, ARGS_CONTEXT, ARGS_CONTEXT_INT, ARGS_CONTEXT_INT_INT};
ARGS_BOOL, ARGS_INT_OBJ, ARGS_NONE, ARGS_NUMBER_OBJ, ARGS_INT_INT, ARGS_CONTEXT, ARGS_CONTEXT_INT, ARGS_CONTEXT_INT_INT,
ARGS_CONTEXT_INT_INT_OBJ};

struct typed_opcode_handler
{
Expand Down
35 changes: 25 additions & 10 deletions scripting/abc_codesynt.cpp
Expand Up @@ -130,8 +130,8 @@ typed_opcode_handler ABCVm::opcode_table_void[]={
{"initProperty",(void*)&ABCVm::initProperty,ARGS_CONTEXT_INT},
{"kill",(void*)&ABCVm::kill,ARGS_INT},
{"jump",(void*)&ABCVm::jump,ARGS_INT},
{"callProperty",(void*)&ABCVm::callProperty,ARGS_CONTEXT_INT_INT},
{"callPropVoid",(void*)&ABCVm::callPropVoid,ARGS_CONTEXT_INT_INT},
{"callProperty",(void*)&ABCVm::callProperty,ARGS_CONTEXT_INT_INT_OBJ},
{"callPropVoid",(void*)&ABCVm::callPropVoid,ARGS_CONTEXT_INT_INT_OBJ},
{"constructProp",(void*)&ABCVm::constructProp,ARGS_CONTEXT_INT_INT},
{"callSuper",(void*)&ABCVm::callSuper,ARGS_CONTEXT_INT_INT},
{"callSuperVoid",(void*)&ABCVm::callSuperVoid,ARGS_CONTEXT_INT_INT},
Expand Down Expand Up @@ -348,6 +348,11 @@ void ABCVm::register_table(const llvm::Type* ret_type,typed_opcode_handler* tabl
sig_context_int_int.push_back(int_type);
sig_context_int_int.push_back(int_type);

vector<const llvm::Type*> sig_context_int_int_obj;
sig_context_int_int.push_back(context_type);
sig_context_int_int.push_back(int_type);
sig_context_int_int.push_back(int_type);
sig_context_int_int.push_back(voidptr_type);
llvm::FunctionType* FT=NULL;
for(int i=0;i<table_len;i++)
{
Expand Down Expand Up @@ -398,6 +403,9 @@ void ABCVm::register_table(const llvm::Type* ret_type,typed_opcode_handler* tabl
case ARGS_CONTEXT_INT_INT:
FT=llvm::FunctionType::get(ret_type, sig_context_int_int, false);
break;
case ARGS_CONTEXT_INT_INT_OBJ:
FT=llvm::FunctionType::get(ret_type, sig_context_int_int_obj, false);
break;
}

llvm::Function* F=llvm::Function::Create(FT,llvm::Function::ExternalLinkage,table[i].name,module);
Expand Down Expand Up @@ -1586,26 +1594,32 @@ void method_info::compileBitAnd(vector<stack_entry>& static_stack, llvm::Value*

void method_info::compileCallProperty(int t, int t2, vector<stack_entry>& static_stack, llvm::Value* dynamic_stack,
llvm::Value* dynamic_stack_index, llvm::Value* callContext,
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex, const llvm::Type* int_type)
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex,
const llvm::Type* int_type, const llvm::Type* voidptr_type)
{
LOG(LOG_TRACE, "synt callproperty");
llvm::Constant* constant = llvm::ConstantInt::get(int_type, t);
llvm::Constant* constant2 = llvm::ConstantInt::get(int_type, t2);
syncStacks(ex,Builder,static_stack,dynamic_stack,dynamic_stack_index);

Builder.CreateCall3(ex->FindFunctionNamed("callProperty"), callContext, constant, constant2);
//callProperty returns also the method_info of the called function by reference
llvm::Value* called_mi=Builder.CreateAlloca(voidptr_type);
Builder.CreateCall4(ex->FindFunctionNamed("callProperty"), callContext, constant, constant2, called_mi);
}

void method_info::compileCallPropVoid(int t, int t2, vector<stack_entry>& static_stack, llvm::Value* dynamic_stack,
llvm::Value* dynamic_stack_index, llvm::Value* callContext,
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex, const llvm::Type* int_type)
llvm::IRBuilder<>& Builder, llvm::ExecutionEngine* ex,
const llvm::Type* int_type, const llvm::Type* voidptr_type)
{
LOG(LOG_TRACE, "synt callpropvoid");
llvm::Constant* constant = llvm::ConstantInt::get(int_type, t);
llvm::Constant* constant2 = llvm::ConstantInt::get(int_type, t2);
syncStacks(ex,Builder,static_stack,dynamic_stack,dynamic_stack_index);

Builder.CreateCall3(ex->FindFunctionNamed("callPropVoid"), callContext, constant, constant2);
//callProperty returns also the method_info of the called function by reference
llvm::Value* called_mi=Builder.CreateAlloca(voidptr_type);
Builder.CreateCall4(ex->FindFunctionNamed("callPropVoid"), callContext, constant, constant2, called_mi);
}

void method_info::compileConvert_i(vector<stack_entry>& static_stack, llvm::Value* dynamic_stack,
Expand Down Expand Up @@ -2523,7 +2537,7 @@ BlockStudy::synt_block method_info::compileBlock(uint32_t start, uint32_t end)
code >> t;
code >> t2;
compileCallProperty(t, t2, static_stack, dynamic_stack, dynamic_stack_index, callContext,
Builder, ex, int_type);
Builder, ex, int_type, voidptr_type);
break;
}
case 0x4f:
Expand All @@ -2533,7 +2547,7 @@ BlockStudy::synt_block method_info::compileBlock(uint32_t start, uint32_t end)
code >> t;
code >> t2;
compileCallPropVoid(t, t2, static_stack, dynamic_stack, dynamic_stack_index, callContext,
Builder, ex, int_type);
Builder, ex, int_type, voidptr_type);
break;
}
case 0x60:
Expand Down Expand Up @@ -2674,7 +2688,7 @@ BlockStudy::synt_block method_info::compileBlock(uint32_t start, uint32_t end)
LOG(LOG_ERROR,_("Not implemented instruction @") << code.tellg());
LOG(LOG_ERROR,_("Opcode ") << hex << (unsigned int)opcode << dec);
llvmf->eraseFromParent();
cout << "Failed to compile " << profName << endl;
//cout << "Failed to compile " << profName << endl;
return NULL;
/*constant = llvm::ConstantInt::get(int_type, opcode);
Builder.CreateCall(ex->FindFunctionNamed("not_impl"), constant);
Expand Down Expand Up @@ -2757,9 +2771,10 @@ BlockStudy::synt_block method_info::compileBlock(uint32_t start, uint32_t end)
}

//cout << profName << " start: " << start << " end: " << end << endl;
//llvmf->dump();
getVm()->FPM->run(*llvmf);
BlockStudy::synt_block ret=(BlockStudy::synt_block)getVm()->ex->getPointerToFunction(llvmf);
if(profName=="MontgomeryReduction::::reduce")
llvmf->dump();
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions scripting/abc_opcodes.cpp
Expand Up @@ -331,7 +331,7 @@ void ABCVm::callProperty(call_context* th, int n, int m, method_info*& called_mi
f->incRef();
ASObject* ret=f->call(obj,args,m);
//call getMethodInfo only after the call, so it's updated
//called_mi=f->getMethodInfo();
called_mi=f->getMethodInfo();
f->decRef();
if(ret==NULL)
ret=new Undefined;
Expand Down Expand Up @@ -907,7 +907,7 @@ void ABCVm::callPropVoid(call_context* th, int n, int m, method_info*& called_mi
f->incRef();
ASObject* ret=f->call(obj,args,m);
//call getMethodInfo only after the call, so it's updated
//called_mi=f->getMethodInfo();
called_mi=f->getMethodInfo();
f->decRef();
if(ret)
ret->decRef();
Expand Down

0 comments on commit 14b6788

Please sign in to comment.