[Compiler] Add reset-here option to colored and constrained rlet vars (#169)

* add reset-here to clear coloring at entry to rlet

* update doc
This commit is contained in:
water111
2020-12-27 14:21:48 -05:00
committed by GitHub
parent 25301a8bbc
commit c811778d00
11 changed files with 54 additions and 69 deletions
+8 -8
View File
@@ -857,15 +857,15 @@ void IR_Null::do_codegen(emitter::ObjectGenerator* gen,
}
///////////////////////
// FunctionStart
// ValueReset
///////////////////////
IR_FunctionStart::IR_FunctionStart(std::vector<RegVal*> args) : m_args(std::move(args)) {}
IR_ValueReset::IR_ValueReset(std::vector<RegVal*> args) : m_args(std::move(args)) {}
std::string IR_FunctionStart::print() {
return "function-start";
std::string IR_ValueReset::print() {
return "value-reset";
}
RegAllocInstr IR_FunctionStart::to_rai() {
RegAllocInstr IR_ValueReset::to_rai() {
RegAllocInstr rai;
for (auto& x : m_args) {
rai.write.push_back(x->ireg());
@@ -873,9 +873,9 @@ RegAllocInstr IR_FunctionStart::to_rai() {
return rai;
}
void IR_FunctionStart::do_codegen(emitter::ObjectGenerator* gen,
const AllocationResult& allocs,
emitter::IR_Record irec) {
void IR_ValueReset::do_codegen(emitter::ObjectGenerator* gen,
const AllocationResult& allocs,
emitter::IR_Record irec) {
(void)gen;
(void)allocs;
(void)irec;
+2 -2
View File
@@ -316,9 +316,9 @@ class IR_Null : public IR {
emitter::IR_Record irec) override;
};
class IR_FunctionStart : public IR {
class IR_ValueReset : public IR {
public:
IR_FunctionStart(std::vector<RegVal*> args);
IR_ValueReset(std::vector<RegVal*> args);
std::string print() override;
RegAllocInstr to_rai() override;
void do_codegen(emitter::ObjectGenerator* gen,
+12
View File
@@ -37,6 +37,7 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
auto lenv = fenv->alloc_env<LexicalEnv>(env);
std::vector<IRegConstraint> constraints;
std::vector<RegVal*> reset_regs;
for_each_in_list(defs, [&](const goos::Object& o) {
// (new-place [:reg old-place] [:type type-spec] [:class reg-type] [:bind #f|lexical|lambda])
@@ -44,6 +45,7 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
va_check(o, def_args, {goos::ObjectType::SYMBOL},
{{"reg", {false, goos::ObjectType::SYMBOL}},
{"type", {false, {}}},
{"reset-here", {false, {}}},
{"class", {false, goos::ObjectType::SYMBOL}}});
// get the name of the new place
@@ -71,11 +73,17 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
// alloc a register:
auto new_place_reg = env->make_ireg(ts, register_kind);
new_place_reg->mark_as_settable();
if (def_args.has_named("reg")) {
IRegConstraint constraint;
constraint.ireg = new_place_reg->ireg();
constraint.contrain_everywhere = true;
constraint.desired_register = parse_register(def_args.named.at("reg"));
if (def_args.has_named("reset-here") &&
get_true_or_false(form, def_args.get_named("reset-here"))) {
reset_regs.push_back(new_place_reg);
}
new_place_reg->set_rlet_constraint(constraint.desired_register);
constraints.push_back(constraint);
}
@@ -83,6 +91,10 @@ Val* Compiler::compile_rlet(const goos::Object& form, const goos::Object& rest,
lenv->vars[new_place_name.as_symbol()->name] = new_place_reg;
});
if (!reset_regs.empty()) {
lenv->emit_ir<IR_ValueReset>(reset_regs);
}
Val* result = get_none();
for (u64 i = 1; i < args.unnamed.size(); i++) {
auto& o = args.unnamed.at(i);
+1 -1
View File
@@ -169,7 +169,7 @@ Val* Compiler::compile_lambda(const goos::Object& form, const goos::Object& rest
auto func_block_env = new_func_env->alloc_env<BlockEnv>(new_func_env.get(), "#f");
func_block_env->return_value = return_reg;
func_block_env->end_label = Label(new_func_env.get());
func_block_env->emit(std::make_unique<IR_FunctionStart>(args_for_coloring));
func_block_env->emit(std::make_unique<IR_ValueReset>(args_for_coloring));
// compile the function, iterating through the body.
Val* result = nullptr;
+2 -2
View File
@@ -182,7 +182,7 @@ Val* Compiler::generate_inspector_for_type(const goos::Object& form, Env* env, T
constraint.desired_register = emitter::gRegInfo.get_arg_reg(0); // to the first argument
method_env->constrain(constraint);
// Inform the compiler that `input`'s value will be written to `rdi` (first arg register)
method_env->emit(std::make_unique<IR_FunctionStart>(std::vector<RegVal*>{input}));
method_env->emit(std::make_unique<IR_ValueReset>(std::vector<RegVal*>{input}));
RegVal* type_name = nullptr;
if (dynamic_cast<BasicType*>(structured_type)) {
@@ -342,7 +342,7 @@ Val* Compiler::compile_defmethod(const goos::Object& form, const goos::Object& _
auto func_block_env = new_func_env->alloc_env<BlockEnv>(new_func_env.get(), "#f");
func_block_env->return_value = return_reg;
func_block_env->end_label = Label(new_func_env.get());
func_block_env->emit(std::make_unique<IR_FunctionStart>(args_for_coloring));
func_block_env->emit(std::make_unique<IR_ValueReset>(args_for_coloring));
// compile the function!
Val* result = nullptr;