Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed calls to import_args_19_style()
Browse files Browse the repository at this point in the history
sshao committed Oct 30, 2014
1 parent 295842c commit d61e782
Showing 4 changed files with 0 additions and 475 deletions.
274 changes: 0 additions & 274 deletions vm/llvm/jit_block.cpp
Original file line number Diff line number Diff line change
@@ -61,8 +61,6 @@ namespace jit {

setup_block_scope();

import_args_19_style();

if(ctx_->llvm_state()->include_profiling()) {
Value* test = b().CreateLoad(ctx_->profiling(), "profiling");

@@ -204,278 +202,6 @@ namespace jit {

}

void BlockBuilder::import_args_19_style() {
if(machine_code_->required_args > 1) {
Value* lambda_check =
b().CreateICmpEQ(
b().CreateAnd(
inv_flags_,
ConstantInt::get(inv_flags_->getType(), CallFrame::cIsLambda)),
ConstantInt::get(inv_flags_->getType(), 0));

BasicBlock* destruct = BasicBlock::Create(ctx_->llvm_context(), "destructure", info_.function());
BasicBlock* cont = BasicBlock::Create(ctx_->llvm_context(), "arg_loop_body", info_.function());

b().CreateCondBr(lambda_check, destruct, cont);

b().SetInsertPoint(destruct);

Signature sig(ctx_, "Object");
sig << "State";
sig << "CallFrame";
sig << "Arguments";

Value* call_args[] = { info_.state(), info_.call_frame(), info_.args() };

Value* val = sig.call("rbx_destructure_args", call_args, 3, "", b());

Value* null = Constant::getNullValue(val->getType());
Value* is_null = b().CreateICmpEQ(val, null);

info_.add_return_value(null, b().GetInsertBlock());
b().CreateCondBr(is_null, info_.return_pad(), cont);

b().SetInsertPoint(cont);
}

Value* local_i = counter2_;

Value* loop_i = info_.counter();
Value* arg_ary = b().CreateLoad(
b().CreateConstGEP2_32(info_.args(), 0, offset::Arguments::arguments),
"arg_ary");

// The variables used in the 4 phases.
int P = machine_code_->post_args;
Value* Pv = cint(P);

int R = machine_code_->required_args;

int M = R - P;
Value* Mv = cint(M);

Value* T = b().CreateLoad(
b().CreateConstGEP2_32(info_.args(), 0, offset::Arguments::total),
"args.total");

int DT = machine_code_->total_args;
Value* DTv = cint(DT);

int O = DT - R;
Value* Ov = cint(O);

int HS = machine_code_->splat_position > 0 ? 1 : 0;

Value* CT = HS ? T
: b().CreateSelect(b().CreateICmpSLT(T, DTv), T, DTv);

Value* Z = b().CreateSub(CT, cint(M));
Value* U = b().CreateSub(Z, cint(P));



// Phase 1, the mandatories
// 0 ... min(M,T)

{
BasicBlock* top = info_.new_block("mand_loop_top");
BasicBlock* body = info_.new_block("mand_loop_body");
BasicBlock* after = info_.new_block("mand_loop_cont");

// limit = min(M,T)
Value* limit = b().CreateSelect(b().CreateICmpSLT(Mv, T), Mv, T);

// *loop_i = T-P
b().CreateStore(cint(0), loop_i);

b().CreateBr(top);

b().SetInsertPoint(top);

// loop_val = *loop_i
Value* loop_val = b().CreateLoad(loop_i, "loop_val");

// if(loop_val < T) { goto body } else { goto after }
b().CreateCondBr(
b().CreateICmpSLT(loop_val, limit, "loop_test"),
body, after);

// Now, the body
b().SetInsertPoint(body);

Value* idx2[] = {
cint(0),
cint(offset::StackVariables::locals),
loop_val
};

// locals[loop_val] = args[loop_val]
b().CreateStore(
b().CreateLoad(
b().CreateGEP(arg_ary, loop_val)),
b().CreateGEP(vars, idx2));

// *loop_i = loop_val + 1
b().CreateStore(
b().CreateAdd(loop_val, cint(1)),
loop_i);

b().CreateBr(top);

b().SetInsertPoint(after);
}

// Phase 2, the post args
// CT - min(Z,P) ... CT
{
BasicBlock* top = info_.new_block("post_loop_top");
BasicBlock* body = info_.new_block("post_loop_body");
BasicBlock* after = info_.new_block("post_loop_cont");

// *loop_i = CT - min(Z,P)
b().CreateStore(
b().CreateSub(
CT,
b().CreateSelect(b().CreateICmpSLT(Z, Pv), Z, Pv)),
loop_i);

// *local_i = M+O+HS
b().CreateStore(
cint(M+O+HS),
local_i);

b().CreateBr(top);

b().SetInsertPoint(top);

// loop_val = *loop_i
Value* loop_val = b().CreateLoad(loop_i, "loop_val");

// if(loop_val < T) { goto body } else { goto after }
b().CreateCondBr(
b().CreateICmpSLT(loop_val, CT, "loop_test"),
body, after);

// Now, the body
b().SetInsertPoint(body);

// local_val = *local_i
Value* local_val = b().CreateLoad(local_i, "local_val");

Value* idx2[] = {
cint(0),
cint(offset::StackVariables::locals),
local_val
};

// locals[local_idx] = args[loop_val]
b().CreateStore(
b().CreateLoad(
b().CreateGEP(arg_ary, loop_val)),
b().CreateGEP(vars, idx2));

// *loop_i = loop_val + 1
b().CreateStore(
b().CreateAdd(loop_val, cint(1)),
loop_i);

// *local_i = local_val + 1;
b().CreateStore(
b().CreateAdd(local_val, cint(1)),
local_i);

b().CreateBr(top);

b().SetInsertPoint(after);
}

// Phase 3 - optionals
// M ... M + min(O, U)

{
BasicBlock* top = info_.new_block("opt_arg_loop_top");
BasicBlock* body = info_.new_block("opt_arg_loop_body");
BasicBlock* after = info_.new_block("opt_arg_loop_cont");

Value* limit =
b().CreateAdd(
Mv,
b().CreateSelect(b().CreateICmpSLT(Ov, U), Ov, U));

// *loop_i = M
b().CreateStore(Mv, loop_i);
b().CreateBr(top);

b().SetInsertPoint(top);

// loop_val = *loop_i;
Value* loop_val = b().CreateLoad(loop_i, "loop_val");

// if(loop_val < limit) { goto body; } else { goto after; }
b().CreateCondBr(
b().CreateICmpSLT(loop_val, limit, "loop_test"),
body, after);

// Now, the body
b().SetInsertPoint(body);

Value* idx2[] = {
cint(0),
cint(offset::StackVariables::locals),
loop_val
};

// locals[loop_val] = args[loop_val]
b().CreateStore(
b().CreateLoad(
b().CreateGEP(arg_ary, loop_val)),
b().CreateGEP(vars, idx2));

// *loop_i = loop_val + 1
b().CreateStore(
b().CreateAdd(loop_val, cint(1)),
loop_i);

b().CreateBr(top);

b().SetInsertPoint(after);
}

// Phase 4 - splat
if(machine_code_->splat_position >= 0) {
Signature sig(ctx_, "Object");
sig << "State";
sig << "Arguments";
sig << ctx_->Int32Ty;
sig << ctx_->Int32Ty;

Value* call_args[] = {
info_.state(),
info_.args(),
cint(M + O),
cint(DT)
};

Function* func = sig.function("rbx_construct_splat");
func->setOnlyReadsMemory();
func->setDoesNotThrow();

CallInst* splat_val = sig.call("rbx_construct_splat", call_args, 4, "splat_val", b());

splat_val->setOnlyReadsMemory();
splat_val->setDoesNotThrow();

Value* idx3[] = {
cint(0),
cint(offset::StackVariables::locals),
cint(machine_code_->splat_position)
};

Value* pos = b().CreateGEP(vars, idx3, "splat_pos");
b().CreateStore(splat_val, pos);
}
}

}
}

1 change: 0 additions & 1 deletion vm/llvm/jit_block.hpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ namespace jit {
void initialize_frame(int stack_size);
void setup_block_scope();
void setup();
void import_args_19_style();

protected:
llvm::Value* inv_flags_;
199 changes: 0 additions & 199 deletions vm/llvm/jit_method.cpp
Original file line number Diff line number Diff line change
@@ -72,208 +72,9 @@ namespace jit {
b().SetInsertPoint(body_);
}

void MethodBuilder::import_args_19_style() {
Value* local_i = counter2_;

Value* loop_i = info_.counter();
Value* arg_ary = b().CreateLoad(
b().CreateConstGEP2_32(info_.args(), 0, offset::Arguments::arguments,
"arg_ary_pos"),
"arg_ary");

// The variables used in the 4 phases.
int P = machine_code_->post_args;
int M = machine_code_->required_args - P;
Value* T = arg_total;
int DT = machine_code_->total_args;
int R = machine_code_->required_args;
int O = machine_code_->total_args - R;
int HS = machine_code_->splat_position > 0 ? 1 : 0;


// Phase 1, the manditories
// 0 ... M

for(int i = 0; i < M; i++) {
Value* int_pos = cint(i);

Value* arg_val_offset = b().CreateConstGEP1_32(arg_ary, i, "arg_val_offset");

Value* arg_val = b().CreateLoad(arg_val_offset, "arg_val");

Value* idx2[] = {
cint(0),
cint(offset::StackVariables::locals),
int_pos
};

Value* pos = b().CreateGEP(vars, idx2, "var_pos");

b().CreateStore(arg_val, pos);
}

// Phase 2, the post args
// T-P ... T
{
BasicBlock* top = info_.new_block("arg_loop_top");
BasicBlock* body = info_.new_block("arg_loop_body");
BasicBlock* after = info_.new_block("arg_loop_cont");

// *loop_i = T-P
b().CreateStore(
b().CreateSub(T, ConstantInt::get(T->getType(), P)),
loop_i);

// *local_i = M+O+HS
b().CreateStore(
cint(M+O+HS),
local_i);

b().CreateBr(top);

b().SetInsertPoint(top);

// loop_val = *loop_i
Value* loop_val = b().CreateLoad(loop_i, "loop_val");

// if(loop_val < T) { goto body } else { goto after }
b().CreateCondBr(
b().CreateICmpSLT(loop_val, T, "loop_test"),
body, after);

// Now, the body
b().SetInsertPoint(body);

// local_val = *local_i
Value* local_val = b().CreateLoad(local_i, "local_val");

Value* idx2[] = {
cint(0),
cint(offset::StackVariables::locals),
local_val
};

// locals[local_idx] = args[loop_val]
b().CreateStore(
b().CreateLoad(
b().CreateGEP(arg_ary, loop_val)),
b().CreateGEP(vars, idx2));

// *loop_i = loop_val + 1
b().CreateStore(
b().CreateAdd(loop_val, cint(1)),
loop_i);

// *local_i = local_val + 1;
b().CreateStore(
b().CreateAdd(local_val, cint(1)),
local_i);

b().CreateBr(top);

b().SetInsertPoint(after);
}

// Phase 3 - optionals
// M ... M + min(O, T-R)

Value* Oval = cint(O);
Value* left = b().CreateSub(T, ConstantInt::get(ctx_->Int32Ty, R));

Value* limit =
b().CreateAdd(
cint(M),
b().CreateSelect(
b().CreateICmpSLT(Oval, left),
Oval, left));

{
BasicBlock* top = info_.new_block("opt_arg_loop_top");
BasicBlock* body = info_.new_block("opt_arg_loop_body");
BasicBlock* after = info_.new_block("opt_arg_loop_cont");

// *loop_i = M
b().CreateStore(cint(M), loop_i);
b().CreateBr(top);

b().SetInsertPoint(top);

// loop_val = *loop_i;
Value* loop_val = b().CreateLoad(loop_i, "loop_val");

// if(loop_val < limit) { goto body; } else { goto after; }
b().CreateCondBr(
b().CreateICmpSLT(loop_val, limit, "loop_test"),
body, after);

// Now, the body
b().SetInsertPoint(body);

Value* idx2[] = {
cint(0),
cint(offset::StackVariables::locals),
loop_val
};

// locals[loop_val] = args[loop_val]
b().CreateStore(
b().CreateLoad(
b().CreateGEP(arg_ary, loop_val)),
b().CreateGEP(vars, idx2));

// *loop_i = loop_val + 1
b().CreateStore(
b().CreateAdd(loop_val, cint(1)),
loop_i);

b().CreateBr(top);

b().SetInsertPoint(after);
}

// Phase 4 - splat
if(machine_code_->splat_position >= 0) {
Signature sig(ctx_, "Object");
sig << "State";
sig << "Arguments";
sig << ctx_->Int32Ty;
sig << ctx_->Int32Ty;

Value* call_args[] = {
info_.state(),
info_.args(),
cint(M + O),
cint(DT)
};

Function* func = sig.function("rbx_construct_splat");
func->setOnlyReadsMemory();
func->setDoesNotThrow();

CallInst* splat_val = sig.call("rbx_construct_splat", call_args, 4, "splat_val", b());

splat_val->setOnlyReadsMemory();
splat_val->setDoesNotThrow();

Value* idx3[] = {
cint(0),
cint(offset::StackVariables::locals),
cint(machine_code_->splat_position)
};

Value* pos = b().CreateGEP(vars, idx3, "splat_pos");
b().CreateStore(splat_val, pos);
}
}

void MethodBuilder::import_args() {
setup_scope();

if(machine_code_->post_args > 0) {
import_args_19_style();
return;
}

// Import the arguments
Value* offset = b().CreateConstGEP2_32(info_.args(), 0, offset::Arguments::arguments, "arg_ary_pos");

1 change: 0 additions & 1 deletion vm/llvm/jit_method.hpp
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ namespace jit {

void check_arity();
void import_args();
void import_args_19_style();
void setup_scope();
void initialize_frame(int);
void return_value(llvm::Value* ret, llvm::BasicBlock* cont = 0);

0 comments on commit d61e782

Please sign in to comment.