Home  |  Linux  | Mysql  | PHP  | XML
From:Nuno Lopes Date:Thu Oct 23 14:12:09 2008
Subject:cvs: pecl /llvm phpllvm.cpp phpllvm_compile.cpp phpllvm_execute.cpp phpllvm_execute.h
nlopess Thu Oct 23 14:12:09 2008 UTC

Modified files:
/pecl/llvm phpllvm.cpp phpllvm_compile.cpp phpllvm_execute.cpp
phpllvm_execute.h
Log:
fix execute data padding
fix some typos in the execute data struct dumping, it isnt fully working, though
use the new raw_ostream API instead of std::ostream
remove some useless TSRMLS_D/C

http://cvs.php.net/viewvc.cgi/pecl/llvm/phpllvm.cpp?r1=1.7&r2=1.8&diff_format=u
Index: pecl/llvm/phpllvm.cpp
diff -u pecl/llvm/phpllvm.cpp:1.7 pecl/llvm/phpllvm.cpp:1.8
--- pecl/llvm/phpllvm.cpp:1.7 Tue Jul 29 00:54:51 2008
+++ pecl/llvm/phpllvm.cpp Thu Oct 23 14:12:09 2008
@@ -62,10 +62,10 @@

REGISTER_INI_ENTRIES();

- init_jit_engine(NULL TSRMLS_CC);
+ init_jit_engine(NULL);

if (INI_BOOL("phpllvm.active"))
- override_executor(TSRMLS_C);
+ override_executor();

return SUCCESS;
}
@@ -74,12 +74,12 @@
static PHP_MSHUTDOWN_FUNCTION(phpllvm)
{
if (INI_BOOL("phpllvm.active"))
- restore_executor(TSRMLS_C);
+ restore_executor();

UNREGISTER_INI_ENTRIES();

save_module(TEMP_FILE);
- destroy_jit_engine(TSRMLS_C);
+ destroy_jit_engine();

return SUCCESS;
}
@@ -96,7 +96,7 @@
static PHP_MINFO_FUNCTION(phpllvm)
{
php_info_print_table_start();
- php_info_print_table_row(2, "Revision", "$Revision: 1.7 $");
+ php_info_print_table_row(2, "Revision", "$Revision: 1.8 $");
php_info_print_table_row(2, "LLVM version", getLLVMString());
php_info_print_table_end();

http://cvs.php.net/viewvc.cgi/pecl/llvm/phpllvm_compile.cpp?r1=1.18&r2=1.19&diff_format=u
Index: pecl/llvm/phpllvm_compile.cpp
diff -u pecl/llvm/phpllvm_compile.cpp:1.18 pecl/llvm/phpllvm_compile.cpp:1.19
--- pecl/llvm/phpllvm_compile.cpp:1.18 Sat Aug 9 15:17:00 2008
+++ pecl/llvm/phpllvm_compile.cpp Thu Oct 23 14:12:09 2008
@@ -305,6 +305,14 @@
return process_oparray;
}

+
+static void add_padding(std::vector<Constant*> &v, unsigned bytes)
+{
+ for (unsigned i = 0; i < bytes; ++i) {
+ v.push_back(ConstantInt::get(Type::Int8Ty, 0));
+ }
+}
+
static GlobalVariable* dump_class_entry(zend_class_entry* class_entry, Module* mod) {
const Type* class_entry_type = mod->getTypeByName(STRUCT("zend_class_entry"));

@@ -498,10 +506,7 @@
op_members.push_back(ConstantInt::get(Type::Int8Ty, opcodes[i].opcode));

#ifdef COMPILED_WITH_CLANG
- // clang adds some padding
- for (uint i = 0; i < 3; ++i) {
- op_members.push_back(ConstantInt::get(Type::Int8Ty, 0));
- }
+ add_padding(op_members, 3);
#endif

ops.push_back(ConstantStruct::get(op_type, op_members));
@@ -581,11 +586,12 @@
}

static GlobalVariable* dump_try_catch_array(zend_try_catch_element* elements, int count, Module* mod) {
- const StructType* try_catch_element_type = cast<const StructType>(mod->getTypeByName(STRUCT("zend_try_catch_element")));
+ const StructType* try_catch_element_type = cast<const StructType>(mod->getTypeByName(STRUCT("zend_label")));
+ const Type* uint_type = Type::Int32Ty; // TODO: adjust this automatically

std::vector<Constant*> members;

- for(int i = 0; i < count; i++) {
+ for (int i = 0; i < count; ++i) {
// typedef struct _zend_try_catch_element {
// zend_uint try_op;
// zend_uint catch_op; /* ketchup! */
@@ -594,8 +600,8 @@

std::vector<Constant*> element_members;

- element_members.push_back(ConstantInt::get(Type::Int32Ty, elements[i].try_op));
- element_members.push_back(ConstantInt::get(Type::Int32Ty, elements[i].catch_op));
+ element_members.push_back(ConstantInt::get(uint_type, elements[i].try_op));
+ element_members.push_back(ConstantInt::get(uint_type, elements[i].catch_op));

members.push_back(ConstantStruct::get(try_catch_element_type, element_members));
}
@@ -618,14 +624,15 @@

static GlobalVariable* dump_op_array(zend_op_array* op_array, Module* mod, ExecutionEngine* engine) {
const StructType* op_array_type = cast<const StructType>(mod->getTypeByName(STRUCT("zend_op_array")));
- const Type* class_entry_type = mod->getTypeByName(STRUCT("zend_class_entry"));
- const Type* function_type = mod->getTypeByName(UNION("zend_function"));
const Type* arg_info_type = mod->getTypeByName(STRUCT("zend_arg_info"));
- const Type* compiled_variable_type = mod->getTypeByName(STRUCT("zend_compiled_variable"));
const Type* brk_cont_element_type = mod->getTypeByName(STRUCT("zend_brk_cont_element"));
- const Type* try_catch_element_type = mod->getTypeByName(STRUCT("zend_try_catch_element"));
- const Type* hashtable_type = mod->getTypeByName(STRUCT("HashTable"));
+ const Type* class_entry_type = mod->getTypeByName(STRUCT("zend_class_entry"));
+ const Type* compiled_variable_type = mod->getTypeByName(STRUCT("zend_compiled_variable"));
+ const Type* function_type = mod->getTypeByName(UNION("zend_function"));
+ const Type* hashtable_type = mod->getTypeByName(STRUCT("hashtable"));
+ const Type* label_type = mod->getTypeByName(STRUCT("zend_label"));
const Type* op_type = mod->getTypeByName(STRUCT("zend_op"));
+ const Type* uint_type = Type::Int32Ty; // TODO: adjust this automatically

std::vector<Constant*> members;

@@ -633,42 +640,47 @@

// zend_uchar type;
members.push_back(ConstantInt::get(Type::Int8Ty, op_array->type));
+ add_padding(members, 3);

// char *function_name;
if (op_array->function_name) {
Constant* string = ConstantArray::get(op_array->function_name);
GlobalVariable* var = new GlobalVariable(string->getType(), true, GlobalValue::InternalLinkage, string, "function_name", mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(Type::Int8Ty)));
+ }

// zend_class_entry *scope;
- if (op_array->scope)
+ if (op_array->scope) {
members.push_back(dump_class_entry(op_array->scope, mod));
- else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(class_entry_type)));
+ }

// zend_uint fn_flags;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->fn_flags));
+ members.push_back(ConstantInt::get(uint_type, op_array->fn_flags));

// union _zend_function *prototype;
- if (op_array->prototype)
+ if (op_array->prototype) {
members.push_back(dump_function(op_array->prototype, mod));
- else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(function_type)));
+ }

// zend_uint num_args;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->num_args));
+ members.push_back(ConstantInt::get(uint_type, op_array->num_args));

// zend_uint required_num_args;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->num_args));
+ members.push_back(ConstantInt::get(uint_type, op_array->num_args));

// zend_arg_info *arg_info;
- if (op_array->prototype) {
+ if (op_array->arg_info) {
GlobalVariable* var = dump_arg_info_array(op_array->arg_info, op_array->num_args, mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(arg_info_type)));
+ }

// zend_bool pass_rest_by_reference;
members.push_back(ConstantInt::get(Type::Int8Ty, op_array->pass_rest_by_reference));
@@ -679,41 +691,46 @@
// zend_bool done_pass_two;
members.push_back(ConstantInt::get(Type::Int8Ty, op_array->done_pass_two));

+ add_padding(members, 1);
+
// zend_uint *refcount;
- if (op_array->function_name) {
- GlobalVariable* var = new GlobalVariable(Type::Int32Ty, true, GlobalValue::InternalLinkage, ConstantInt::get(Type::Int32Ty, *op_array->refcount), "refcount", mod);
+ if (op_array->refcount) {
+ GlobalVariable* var = new GlobalVariable(uint_type, true, GlobalValue::InternalLinkage, ConstantInt::get(uint_type, *op_array->refcount), "refcount", mod);
members.push_back(var);
- } else
- members.push_back(ConstantPointerNull::get(PointerType::getUnqual(Type::Int32Ty)));
+ } else {
+ members.push_back(ConstantPointerNull::get(PointerType::getUnqual(uint_type)));
+ }

// zend_op *opcodes;
GlobalVariable* opcodes = dump_opcodes(op_array->opcodes, op_array->last, mod, engine);
members.push_back(opcodes);

// zend_uint last, size;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->last));
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->last)); // not "size" intentionally
+ members.push_back(ConstantInt::get(uint_type, op_array->last));
+ members.push_back(ConstantInt::get(uint_type, op_array->last)); // not "size" intentionally

// zend_compiled_variable *vars;
if (op_array->vars) {
GlobalVariable* var = dump_compiled_vars(op_array->vars, op_array->last_var, mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(compiled_variable_type)));
+ }

// int last_var, size_var;
members.push_back(ConstantInt::get(Type::Int32Ty, op_array->last_var));
members.push_back(ConstantInt::get(Type::Int32Ty, op_array->size_var));

// zend_uint T;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->T));
+ members.push_back(ConstantInt::get(uint_type, op_array->T));

// zend_brk_cont_element *brk_cont_array;
if (op_array->brk_cont_array) {
GlobalVariable* var = dump_brk_cont_array(op_array->brk_cont_array, op_array->last_brk_cont, mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(brk_cont_element_type)));
+ }

// int last_brk_cont;
members.push_back(ConstantInt::get(Type::Int32Ty, op_array->last_brk_cont));
@@ -721,11 +738,13 @@
// int current_brk_cont;
members.push_back(ConstantInt::get(Type::Int32Ty, op_array->current_brk_cont));

+ // zend_try_catch_element *try_catch_array;
if (op_array->try_catch_array) {
GlobalVariable* var = dump_try_catch_array(op_array->try_catch_array, op_array->last_try_catch, mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
- members.push_back(ConstantPointerNull::get(PointerType::getUnqual(try_catch_element_type)));
+ } else {
+ members.push_back(ConstantPointerNull::get(PointerType::getUnqual(label_type)));
+ }

// int last_try_catch;
members.push_back(ConstantInt::get(Type::Int32Ty, op_array->last_try_catch));
@@ -741,47 +760,50 @@
indices.push_back(ConstantInt::get(Type::Int32Ty, 0));
indices.push_back(ConstantInt::get(Type::Int32Ty, start));
members.push_back(ConstantExpr::getGetElementPtr(opcodes, &indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(op_type)));
+ }

// int backpatch_count;
members.push_back(ConstantInt::get(Type::Int32Ty, op_array->backpatch_count));

// zend_uint this_var;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->this_var));
+ members.push_back(ConstantInt::get(uint_type, op_array->this_var));

// char *filename;
if (op_array->filename) {
Constant* string = ConstantArray::get(op_array->filename);
GlobalVariable* var = new GlobalVariable(string->getType(), true, GlobalValue::InternalLinkage, string, "filename", mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(Type::Int8Ty)));
+ }

// zend_uint line_start;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->line_start));
+ members.push_back(ConstantInt::get(uint_type, op_array->line_start));

// zend_uint line_end;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->line_end));
+ members.push_back(ConstantInt::get(uint_type, op_array->line_end));

// char *doc_comment;
if (op_array->doc_comment) {
Constant* string = ConstantArray::get(op_array->doc_comment);
GlobalVariable* var = new GlobalVariable(string->getType(), true, GlobalValue::InternalLinkage, string, "doc_comment", mod);
members.push_back(ConstantExpr::getGetElementPtr(var, &zero_indices[0], 2));
- } else
+ } else {
members.push_back(ConstantPointerNull::get(PointerType::getUnqual(Type::Int8Ty)));
+ }

// zend_uint doc_comment_len;
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->doc_comment_len));
+ members.push_back(ConstantInt::get(uint_type, op_array->doc_comment_len));

// zend_uint early_binding; /* the linked list of delayed declarations */
- members.push_back(ConstantInt::get(Type::Int32Ty, op_array->early_binding));
+ members.push_back(ConstantInt::get(uint_type, op_array->early_binding));

// void *reserved[ZEND_MAX_RESERVED_RESOURCES];
const ArrayType *ptr_array_type = ArrayType::get(PointerType::getUnqual(Type::Int8Ty), ZEND_MAX_RESERVED_RESOURCES);
std::vector<Constant*> vals;
- for(int i = 0; op_array->reserved[i] && i < ZEND_MAX_RESERVED_RESOURCES; i++) {
+ for(unsigned i = 0; op_array->reserved[i] && i < ZEND_MAX_RESERVED_RESOURCES; i++) {
// TODO: Do these need to be deep copied?
GlobalVariable* var = new GlobalVariable(Type::Int8Ty, true, GlobalValue::InternalLinkage, ConstantInt::get(Type::Int8Ty, (uint64_t) op_array->reserved[i]), "reserved_ptr", mod);
vals.push_back(var);
http://cvs.php.net/viewvc.cgi/pecl/llvm/phpllvm_execute.cpp?r1=1.12&r2=1.13&diff_format=u
Index: pecl/llvm/phpllvm_execute.cpp
diff -u pecl/llvm/phpllvm_execute.cpp:1.12 pecl/llvm/phpllvm_execute.cpp:1.13
--- pecl/llvm/phpllvm_execute.cpp:1.12 Tue Aug 12 15:14:11 2008
+++ pecl/llvm/phpllvm_execute.cpp Thu Oct 23 14:12:09 2008
@@ -21,29 +21,24 @@
#include "phpllvm_compile.h"

#include <llvm/PassManager.h>
-#include <llvm/CallingConv.h>
-#include <llvm/Support/IRBuilder.h>
-
-#include "llvm/ModuleProvider.h"
+#include <llvm/ModuleProvider.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Assembly/PrintModulePass.h>
-
-#include "llvm/Target/TargetData.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/IPO.h"
-
-#include <fstream>
+#include <llvm/Target/TargetData.h>
+#include <llvm/Transforms/Scalar.h>
+#include <llvm/Transforms/IPO.h>
+#include <llvm/Support/raw_ostream.h>

using namespace llvm;
using namespace phpllvm;

-/* pointer to the original Zend engine execute function */
+// pointer to the original Zend engine execute function
typedef void (zend_execute_t)(zend_op_array *op_array TSRMLS_DC);
-static zend_execute_t *old_execute;
+static zend_execute_t *old_execute = NULL;

static ExecutionEngine* engine;
static Module* module;
@@ -65,31 +60,36 @@
verifyModule(*module, AbortProcessAction);
#endif

- std::ofstream bc_os(filename, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
- if (!bc_os.fail()) {
- WriteBitcodeToFile(module, bc_os);
+ std::string ErrorInfo;
+ raw_fd_ostream os(filename, ErrorInfo);
+
+ if (ErrorInfo.empty()) {
+ WriteBitcodeToFile(module, os);
}
}

-void phpllvm::init_jit_engine(const char* filename TSRMLS_DC) {
+void phpllvm::init_jit_engine(const char* filename) {

- if (!filename)
+ if (!filename) {
filename = "module_template.bc";
+ }

- /* read in the template that includes the handlers */
+ // read in the template that includes the handlers
MemoryBuffer* buf;
std::string err;

- if (!(buf = MemoryBuffer::getFile(filename, &err)))
+ if (!(buf = MemoryBuffer::getFile(filename, &err))) {
fprintf(stderr, "Couldn't read handlers file: %s", err.c_str());
+ }

- if (!(module = ParseBitcodeFile(buf, &err)))
+ if (!(module = ParseBitcodeFile(buf, &err))) {
fprintf(stderr, "Couldn't parse handlers file: %s", err.c_str());
+ }

provider = new ExistingModuleProvider(module);
engine = ExecutionEngine::create(provider);

- /* Force codegen of handlers. */
+ // Force codegen of handlers. this is a workaround for an LLVM bug in the JIT engine
for (Module::iterator I = module->begin(), E = module->end(); I != E; ++I) {
Function *Fn = &*I;
if (!Fn->isDeclaration() && Fn->getName().compare(0, 5, "ZEND_") == 0) {
@@ -98,44 +98,36 @@
}
}

- /* Set up the optimization passes */
+ // Set up the optimization passes
opt_fpass_manager = new FunctionPassManager(provider);

opt_fpass_manager->add(new TargetData(*engine->getTargetData()));
pass_manager.add(new TargetData(*engine->getTargetData()));

// IPO optimizations
- // Inline function calls.
pass_manager.add(createFunctionInliningPass());

// local optimizations
- // Do simple "peephole" optimizations and bit-twiddling optzns.
opt_fpass_manager->add(createInstructionCombiningPass());
- // Reassociate expressions.
opt_fpass_manager->add(createReassociatePass());
- // Eliminate Common SubExpressions.
opt_fpass_manager->add(createGVNPass());
- // Simplify the control flow graph (deleting unreachable blocks, etc).
opt_fpass_manager->add(createCFGSimplificationPass());
}

-void phpllvm::destroy_jit_engine(TSRMLS_D) {
+void phpllvm::destroy_jit_engine() {
delete engine;
- engine = NULL;
- provider = NULL;
-
delete opt_fpass_manager;
- opt_fpass_manager = NULL;
}

-void phpllvm::override_executor(TSRMLS_D) {
+void phpllvm::override_executor() {
old_execute = zend_execute;
zend_execute = phpllvm::execute;
}

-void phpllvm::restore_executor(TSRMLS_D) {
- if (old_execute)
+void phpllvm::restore_executor() {
+ if (old_execute) {
zend_execute = old_execute;
+ }
}

void phpllvm::execute(zend_op_array *op_array TSRMLS_DC) {
http://cvs.php.net/viewvc.cgi/pecl/llvm/phpllvm_execute.h?r1=1.5&r2=1.6&diff_format=u
Index: pecl/llvm/phpllvm_execute.h
diff -u pecl/llvm/phpllvm_execute.h:1.5 pecl/llvm/phpllvm_execute.h:1.6
--- pecl/llvm/phpllvm_execute.h:1.5 Tue Jul 29 00:54:51 2008
+++ pecl/llvm/phpllvm_execute.h Thu Oct 23 14:12:09 2008
@@ -26,13 +26,13 @@

namespace phpllvm {

- void init_jit_engine(const char* filename TSRMLS_DC);
+ void init_jit_engine(const char* filename);

- void destroy_jit_engine(TSRMLS_D);
+ void destroy_jit_engine();

- void override_executor(TSRMLS_D);
+ void override_executor();

- void restore_executor(TSRMLS_D);
+ void restore_executor();

void execute(zend_op_array *op_array TSRMLS_DC);


Navigate in group php.pecl.cvs at sever news.php.net
Previous Next


Your recent visits
Re: [PHP] php selecting multiple stylesheets
Re: [PHP] php selecting multiple stylesheets
Re: [PHP] removing an array from a compound array
LMPX.COM :: Linux, Mysql, Php, Xml
generally, where in cPanel can one set the default page to load?



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants