[macruby-changes] [2295] MacRuby/trunk/compiler.cpp
source_changes at macosforge.org
source_changes at macosforge.org
Wed Aug 12 05:35:53 PDT 2009
Revision: 2295
http://trac.macosforge.org/projects/ruby/changeset/2295
Author: vincent.isambart at gmail.com
Date: 2009-08-12 05:35:53 -0700 (Wed, 12 Aug 2009)
Log Message:
-----------
fixed the TODO for keeping variables (we only call the method to save
the variables if really needed) - still needs a bit of refactoring
though
Modified Paths:
--------------
MacRuby/trunk/compiler.cpp
Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp 2009-08-12 05:55:36 UTC (rev 2294)
+++ MacRuby/trunk/compiler.cpp 2009-08-12 12:35:53 UTC (rev 2295)
@@ -2945,41 +2945,61 @@
// searches all ReturnInst in the function we just created and add before
// a call to the function to save the local variables if necessary
// (we can't do this before finishing compiling the whole function
- // because we can't be sure if a block is there or not before)
+ // because we can't be sure if the function contains a block or not before)
+ std::vector<ReturnInst *> to_fix;
for (Function::iterator block_it = f->begin();
block_it != f->end();
++block_it) {
for (BasicBlock::iterator inst_it = block_it->begin();
inst_it != block_it->end();
++inst_it) {
- if (dyn_cast<ReturnInst>(inst_it)) {
- // params must be filled each time because in AOT mode it contains instructions
- std::vector<Value *> params;
+ ReturnInst *inst = dyn_cast<ReturnInst>(inst_it);
+ if (inst != NULL) {
+ to_fix.push_back(inst);
+ }
+ }
+ }
+ for (std::vector<ReturnInst *>::iterator inst_it = to_fix.begin();
+ inst_it != to_fix.end();
+ ++inst_it) {
- params.push_back(new LoadInst(current_var_uses, "", inst_it));
- params.push_back(NULL);
- int vars_count = 0;
- for (std::map<ID, Value *>::iterator iter = lvars.begin();
- iter != lvars.end(); ++iter) {
- ID name = iter->first;
- Value *slot = iter->second;
- if (std::find(dvars.begin(), dvars.end(), name) == dvars.end()) {
- Value *id_val = compile_id(name);
- if (Instruction::classof(id_val)) {
- cast<Instruction>(id_val)->moveBefore(inst_it);
- }
- params.push_back(id_val);
- params.push_back(slot);
- vars_count++;
- }
- }
- params[1] = ConstantInt::get(Type::Int32Ty, vars_count);
+ ReturnInst *inst = *inst_it;
- // TODO: only call the function if current_use is not NULL
- CallInst::Create(keepVarsFunc, params.begin(), params.end(), "",
- inst_it);
+ BasicBlock *startBB = inst->getParent();
+ BasicBlock *mergeBB = startBB->splitBasicBlock(inst, "merge");
+ // we do not want the BranchInst added by splitBasicBlock
+ startBB->getInstList().pop_back();
+ BasicBlock *notNullBB = BasicBlock::Create("not_null", f);
+
+ bb = startBB;
+ Value *usesVal = new LoadInst(current_var_uses, "", bb);
+ Value *notNullCond = new ICmpInst(ICmpInst::ICMP_NE, usesVal, compile_const_pointer(NULL), "", bb);
+ // we only need to call keepVarsFunc if current_var_uses is not NULL
+ BranchInst::Create(notNullBB, mergeBB, notNullCond, bb);
+
+ bb = notNullBB;
+
+ // params must be filled each time because in AOT mode it contains instructions
+ std::vector<Value *> params;
+ params.push_back(new LoadInst(current_var_uses, "", bb));
+ params.push_back(NULL);
+ int vars_count = 0;
+ for (std::map<ID, Value *>::iterator iter = lvars.begin();
+ iter != lvars.end(); ++iter) {
+ ID name = iter->first;
+ Value *slot = iter->second;
+ if (std::find(dvars.begin(), dvars.end(), name) == dvars.end()) {
+ Value *id_val = compile_id(name);
+ params.push_back(id_val);
+ params.push_back(slot);
+ vars_count++;
}
}
+ params[1] = ConstantInt::get(Type::Int32Ty, vars_count);
+
+ CallInst::Create(keepVarsFunc, params.begin(), params.end(), "", bb);
+
+ BranchInst::Create(mergeBB, bb);
}
if (new_rescue_bb->use_empty()) {
@@ -3016,6 +3036,7 @@
params[1] = ConstantInt::get(Type::Int32Ty, vars_count);
CallInst::Create(keepVarsFunc, params.begin(), params.end(), "", bb);
+
BranchInst::Create(mergeBB, bb);
bb = mergeBB;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090812/d3361ac9/attachment.html>
More information about the macruby-changes
mailing list