Permalink
Browse files

const pointers should be real constants

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@2662 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 2b72912 commit f61f2c7df13147f73281d2c514745d909d458591 @vincentisambart vincentisambart committed Sep 28, 2009
Showing with 67 additions and 49 deletions.
  1. +40 −22 compiler.cpp
  2. +27 −27 compiler.h
View
@@ -622,7 +622,7 @@ RoxorAOTCompiler::compile_ccache(ID name)
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 @@ RoxorCompiler::compile_binding(void)
"", 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,16 +1086,16 @@ RoxorAOTCompiler::gen_slot_cache(ID id)
return new LoadInst(gvar, "");
}
-Instruction *
+Value *
RoxorCompiler::compile_slot_cache(ID id)
{
if (inside_eval || current_block || !current_instance_method
|| current_module) {
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 @@ RoxorCompiler::compile_slot_cache(ID id)
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 @@ RoxorCompiler::compile_ivar_slots(Value *klass,
"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 @@ RoxorCompiler::compile_ivar_slots(Value *klass,
}
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 @@ RoxorCompiler::compile_node(NODE *node)
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 @@ RoxorAOTCompiler::compile_main_function(NODE *node)
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 @@ RoxorAOTCompiler::compile_main_function(NODE *node)
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 @@ RoxorAOTCompiler::compile_main_function(NODE *node)
{
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 @@ RoxorAOTCompiler::compile_main_function(NODE *node)
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;
View
@@ -85,7 +85,7 @@ class RoxorCompiler {
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 @@ class RoxorCompiler {
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 @@ class RoxorCompiler {
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 @@ class RoxorCompiler {
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 @@ class RoxorAOTCompiler : public RoxorCompiler {
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 @@ class RoxorAOTCompiler : public RoxorCompiler {
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");

0 comments on commit f61f2c7

Please sign in to comment.