[macruby-changes] [2662] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Sep 27 21:24:47 PDT 2009


Revision: 2662
          http://trac.macosforge.org/projects/ruby/changeset/2662
Author:   vincent.isambart at gmail.com
Date:     2009-09-27 21:24:43 -0700 (Sun, 27 Sep 2009)
Log Message:
-----------
const pointers should be real constants

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/compiler.h

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2009-09-28 03:40:10 UTC (rev 2661)
+++ MacRuby/trunk/compiler.cpp	2009-09-28 04:24:43 UTC (rev 2662)
@@ -622,7 +622,7 @@
     return new LoadInst(gvar, "", bb);
 }
 
-Instruction *
+Value *
 RoxorAOTCompiler::compile_sel(SEL sel, bool add_to_bb)
 {
     std::map<SEL, GlobalVariable *>::iterator iter = sels.find(sel);
@@ -1068,15 +1068,15 @@
 	    "", bb);
 }
 
-Instruction *
+Value *
 RoxorCompiler::gen_slot_cache(ID id)
 {
     int *slot = (int *)malloc(sizeof(int));
     *slot = -1;
-    return compile_const_pointer(slot, Int32PtrTy, false);
+    return compile_const_pointer(slot, Int32PtrTy);
 }
 
-Instruction *
+Value *
 RoxorAOTCompiler::gen_slot_cache(ID id)
 {
     GlobalVariable *gvar = new GlobalVariable(*RoxorCompiler::module,
@@ -1086,7 +1086,7 @@
     return new LoadInst(gvar, "");
 }
 
-Instruction *
+Value *
 RoxorCompiler::compile_slot_cache(ID id)
 {
     if (inside_eval || current_block || !current_instance_method
@@ -1094,8 +1094,8 @@
 	return compile_const_pointer(NULL, Int32PtrTy);
     }
 
-    std::map<ID, Instruction *>::iterator iter = ivar_slots_cache.find(id);
-    Instruction *slot;
+    std::map<ID, Value *>::iterator iter = ivar_slots_cache.find(id);
+    Value *slot;
     if (iter == ivar_slots_cache.end()) {
 #if ROXOR_COMPILER_DEBUG
 	printf("allocating a new slot for ivar %s\n", rb_id2name(id));
@@ -1107,10 +1107,16 @@
 	slot = iter->second;
     }
 
-    Instruction *insn = slot->clone(context);
-    BasicBlock::InstListType &list = bb->getInstList();
-    list.insert(list.end(), insn);
-    return insn;
+    Instruction *slot_insn = dyn_cast<Instruction>(slot);
+    if (slot_insn != NULL) {
+	Instruction *insn = slot_insn->clone(context);
+	BasicBlock::InstListType &list = bb->getInstList();
+	list.insert(list.end(), insn);
+	return insn;
+    }
+    else {
+	return slot;
+    }
 }
 
 Value *
@@ -2857,13 +2863,13 @@
 			"rb_vm_prepare_class_ivar_slot", 
 			VoidTy, RubyObjTy, IntTy, Int32PtrTy, NULL));
 	}
-	for (std::map<ID, Instruction *>::iterator iter
+	for (std::map<ID, Value *>::iterator iter
 		= ivar_slots_cache.begin();
 	     iter != ivar_slots_cache.end();
 	     ++iter) {
 
 	    ID ivar_name = iter->first;
-	    Instruction *ivar_slot = iter->second;
+	    Value *ivar_slot = iter->second;
 	    std::vector<Value *> params;
 
 	    params.push_back(klass);
@@ -2876,9 +2882,15 @@
 	    }
 	    params.push_back(id_val);
 
-	    Instruction *insn = ivar_slot->clone(context);
-	    list.insert(list_iter, insn);
-	    params.push_back(insn);
+	    Instruction *slot_insn = dyn_cast<Instruction>(ivar_slot);
+	    if (slot_insn != NULL) {
+		Instruction *insn = slot_insn->clone(context);
+		list.insert(list_iter, insn);
+		params.push_back(insn);
+	    }
+	    else {
+		params.push_back(ivar_slot);
+	    }
 
 	    CallInst *call = CallInst::Create(prepareIvarSlotFunc, 
 		    params.begin(), params.end(), "");
@@ -3866,7 +3878,7 @@
 
 			bool old_current_module = current_module;
 
-			std::map<ID, Instruction *> old_ivar_slots_cache
+			std::map<ID, Value *> old_ivar_slots_cache
 			    = ivar_slots_cache;
 			ivar_slots_cache.clear();
 
@@ -5184,7 +5196,7 @@
 	GlobalVariable *gvar = i->second;
 
 	std::vector<Value *> params;
-	Instruction *load = compile_sel(sel, false);
+	Value *load = compile_sel(sel, false);
 	params.push_back(load);
 
 	Instruction *call = CallInst::Create(getMethodCacheFunc,
@@ -5194,7 +5206,10 @@
 
 	list.insert(list.begin(), assign);
 	list.insert(list.begin(), call);
-	list.insert(list.begin(), load);
+	Instruction *load_insn = dyn_cast<Instruction>(load);
+	if (load_insn != NULL) {
+	    list.insert(list.begin(), load_insn);
+	}
     }
 
     // Compile constant caches.
@@ -5320,9 +5335,9 @@
 		{
 		    struct RRegexp *re = (struct RRegexp *)val;
 
-		    Instruction *re_str;
+		    Value *re_str;
 		    if (re->len == 0) {
-			re_str = compile_const_pointer(NULL, NULL, false);	
+			re_str = compile_const_pointer(NULL, NULL);
 		    }
 		    else {
 			GlobalVariable *rename_gvar =
@@ -5348,7 +5363,10 @@
 
 		    list.insert(list.begin(), assign);
 		    list.insert(list.begin(), call);
-		    list.insert(list.begin(), re_str);
+		    Instruction *re_str_insn = dyn_cast<Instruction>(re_str);
+		    if (re_str_insn != NULL) {
+			list.insert(list.begin(), re_str_insn);
+		    }
 		}
 		break;
 

Modified: MacRuby/trunk/compiler.h
===================================================================
--- MacRuby/trunk/compiler.h	2009-09-28 03:40:10 UTC (rev 2661)
+++ MacRuby/trunk/compiler.h	2009-09-28 04:24:43 UTC (rev 2662)
@@ -85,7 +85,7 @@
 
 	std::map<ID, Value *> lvars;
 	std::vector<ID> dvars;
-	std::map<ID, Instruction *> ivar_slots_cache;
+	std::map<ID, Value *> ivar_slots_cache;
 	std::map<std::string, GlobalVariable *> static_strings;
 	std::map<CFHashCode, GlobalVariable *> static_ustrings;
 	std::map<Function *, RoxorScope *> scopes;
@@ -225,30 +225,32 @@
 	const Type *FloatTy;
 	const Type *DoubleTy;
 	const Type *RubyObjTy; 
-	const Type *RubyObjPtrTy;
-	const Type *RubyObjPtrPtrTy;
-	const Type *PtrTy;
-	const Type *PtrPtrTy;
+	const PointerType *RubyObjPtrTy;
+	const PointerType *RubyObjPtrPtrTy;
+	const PointerType *PtrTy;
+	const PointerType *PtrPtrTy;
 	const Type *IntTy;
-	const Type *Int32PtrTy;
+	const PointerType *Int32PtrTy;
 
 	void compile_node_error(const char *msg, NODE *node);
 
-	virtual Instruction *
-	compile_const_pointer(void *ptr, const Type *type=NULL,
-		bool insert_to_bb=true) {
-	    Value *ptrint = ConstantInt::get(IntTy, (long)ptr);
+	virtual Constant *
+	compile_const_pointer(void *ptr, const PointerType *type=NULL) {
 	    if (type == NULL) {
 		type = PtrTy;
 	    }
-	    return insert_to_bb
-		? new IntToPtrInst(ptrint, type, "", bb)
-		: new IntToPtrInst(ptrint, type, "");
+	    if (ptr == NULL) {
+		return ConstantPointerNull::get(type);
+	    }
+	    else {
+		Constant *ptrint = ConstantInt::get(IntTy, (long)ptr);
+		return ConstantExpr::getIntToPtr(ptrint, type);
+	    }
 	}
 
-	Instruction *
-        compile_const_pointer_to_pointer(void *ptr, bool insert_to_bb=true) {
-	    return compile_const_pointer(ptr, PtrPtrTy, insert_to_bb);
+	Constant *
+	compile_const_pointer_to_pointer(void *ptr) {
+	    return compile_const_pointer(ptr, PtrPtrTy);
 	}
 
 	Instruction *compile_protected_call(Function *func,
@@ -300,8 +302,8 @@
 	virtual Value *compile_mcache(SEL sel, bool super);
 	Value *compile_get_mcache(Value *sel, bool super);
 	virtual Value *compile_ccache(ID id);
-	virtual Instruction *compile_sel(SEL sel, bool add_to_bb=true) {
-	    return compile_const_pointer(sel, PtrTy, add_to_bb);
+	virtual Value *compile_sel(SEL sel, bool add_to_bb=true) {
+	    return compile_const_pointer(sel, PtrTy);
 	}
 	virtual Value *compile_id(ID id);
 	GlobalVariable *compile_const_global_string(const char *str,
@@ -345,8 +347,8 @@
 	Value *compile_conversion_to_ruby(const char *type,
 					  const Type *llvm_type, Value *val);
 
-	Instruction *compile_slot_cache(ID id);
-	virtual Instruction *gen_slot_cache(ID id);
+	Value *compile_slot_cache(ID id);
+	virtual Value *gen_slot_cache(ID id);
 	ICmpInst *is_value_a_fixnum(Value *val);
 	void compile_ivar_slots(Value *klass, BasicBlock::InstListType &list, 
 				BasicBlock::InstListType::iterator iter);
@@ -383,7 +385,7 @@
 
 	Value *compile_mcache(SEL sel, bool super);
 	Value *compile_ccache(ID id);
-	Instruction *compile_sel(SEL sel, bool add_to_bb=true);
+	Value *compile_sel(SEL sel, bool add_to_bb=true);
 	void compile_prepare_method(Value *classVal, Value *sel,
 		bool singleton, Function *new_function, rb_vm_arity_t &arity,
 		NODE *body);
@@ -394,14 +396,12 @@
 	Value *compile_immutable_literal(VALUE val);
 	Value *compile_global_entry(NODE *node);
 
-	Instruction *gen_slot_cache(ID id);
+	Value *gen_slot_cache(ID id);
 
-	Instruction *
-        compile_const_pointer(void *ptr, const Type *type=NULL,
-		bool insert_to_bb=true) {
+	Constant *
+	compile_const_pointer(void *ptr, const PointerType *type=NULL) {
 	    if (ptr == NULL) {
-		return RoxorCompiler::compile_const_pointer(ptr, type,
-			insert_to_bb);
+		return RoxorCompiler::compile_const_pointer(ptr, type);
 	    }
 	    printf("compile_const_pointer() called with a non-NULL pointer " \
 		   "on the AOT compiler - leaving the ship!\n");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090927/7e25ae96/attachment-0001.html>


More information about the macruby-changes mailing list