!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr);
+ // We can't really figure out if the environment is needed or not.
+ instr->environment()->set_has_been_used();
}
return instr;
LOperand* temp2 = FixedTemp(d11);
LInstruction* result =
DefineSameAsFirst(new(zone()) LTaggedToI(value, temp1, temp2));
- if (!val->representation().IsSmi()) {
- // Note: Only deopts in deferred code.
- result = AssignEnvironment(result);
- }
+ if (!val->representation().IsSmi()) result = AssignEnvironment(result);
return result;
}
}
value = UseRegisterAtStart(instr->value());
if (instr->has_migration_target()) info()->MarkAsDeferredCalling();
}
- LCheckMaps* result = new(zone()) LCheckMaps(value);
+ LInstruction* result = new(zone()) LCheckMaps(value);
if (!instr->CanOmitMapChecks()) {
- // Note: Only deopts in deferred code.
- AssignEnvironment(result);
- if (instr->has_migration_target()) return AssignPointerMap(result);
+ result = AssignEnvironment(result);
+ if (instr->has_migration_target()) result = AssignPointerMap(result);
}
return result;
}
void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
Safepoint::DeoptMode mode) {
+ environment->set_has_been_used();
if (!environment->HasBeenRegistered()) {
// Physical stack frame layout:
// -x ............. -4 0 ..................................... y
!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr);
+ // We can't really figure out if the environment is needed or not.
+ instr->environment()->set_has_been_used();
}
return instr;
LOperand* temp2 = instr->CanTruncateToInt32() ? NULL : FixedTemp(d24);
LInstruction* result =
DefineAsRegister(new(zone()) LTaggedToI(value, temp1, temp2));
- if (!val->representation().IsSmi()) {
- // Note: Only deopts in deferred code.
- result = AssignEnvironment(result);
- }
+ if (!val->representation().IsSmi()) result = AssignEnvironment(result);
return result;
}
}
}
LInstruction* result = new(zone()) LCheckMaps(value, temp);
if (!instr->CanOmitMapChecks()) {
- // Note: Only deopts in deferred code.
result = AssignEnvironment(result);
- if (instr->has_migration_target()) return AssignPointerMap(result);
+ if (instr->has_migration_target()) result = AssignPointerMap(result);
}
return result;
}
LOperand* temp3 = TempRegister();
LInstruction* result = DefineAsRegister(
new(zone()) LMathAbsTagged(context, input, temp1, temp2, temp3));
- // Note: Only deopts in deferred code.
return AssignEnvironment(AssignPointerMap(result));
} else {
LOperand* input = UseRegisterAtStart(instr->value());
void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
Safepoint::DeoptMode mode) {
+ environment->set_has_been_used();
if (!environment->HasBeenRegistered()) {
int frame_count = 0;
int jsframe_count = 0;
void LCodeGen::RegisterEnvironmentForDeoptimization(
LEnvironment* environment, Safepoint::DeoptMode mode) {
+ environment->set_has_been_used();
if (!environment->HasBeenRegistered()) {
// Physical stack frame layout:
// -x ............. -4 0 ..................................... y
!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr);
+ // We can't really figure out if the environment is needed or not.
+ instr->environment()->set_has_been_used();
}
return instr;
? FixedTemp(xmm1) : NULL;
LInstruction* result =
DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
- if (!val->representation().IsSmi()) {
- // Note: Only deopts in deferred code.
- result = AssignEnvironment(result);
- }
+ if (!val->representation().IsSmi()) result = AssignEnvironment(result);
return result;
}
}
value = UseRegisterAtStart(instr->value());
if (instr->has_migration_target()) info()->MarkAsDeferredCalling();
}
- LCheckMaps* result = new(zone()) LCheckMaps(value);
+ LInstruction* result = new(zone()) LCheckMaps(value);
if (!instr->CanOmitMapChecks()) {
- // Note: Only deopts in deferred code.
- AssignEnvironment(result);
- if (instr->has_migration_target()) return AssignPointerMap(result);
+ result = AssignEnvironment(result);
+ if (instr->has_migration_target()) result = AssignPointerMap(result);
}
return result;
}
}
+void LCodeGenBase::CheckEnvironmentUsage() {
+#ifdef DEBUG
+ bool live_block = true;
+ for (int i = 0; i < instructions_->length(); i++) {
+ LInstruction* instr = instructions_->at(i);
+ if (instr->IsLabel()) live_block = !LLabel::cast(instr)->HasReplacement();
+ if (live_block &&
+ instr->hydrogen_value()->block()->IsReachable() &&
+ instr->HasEnvironment() &&
+ !instr->environment()->has_been_used()) {
+ FunctionLiteral* lit = info_->function();
+ V8_Fatal(__FILE__, __LINE__, "unused environment in %s <@%d,#%d> %s\n",
+ lit == NULL ? "<UNKNOWN>" : lit->name()->ToCString().get(),
+ i, instr->hydrogen_value()->id(), instr->Mnemonic());
+ }
+ }
+#endif
+}
+
+
void LCodeGenBase::Comment(const char* format, ...) {
if (!FLAG_code_comments) return;
char buffer[4 * KB];
void RegisterWeakObjectsInOptimizedCode(Handle<Code> code);
+ // Check that an environment assigned via AssignEnvironment is actually being
+ // used. Redundant assignments keep things alive longer than necessary, and
+ // consequently lead to worse code, so it's important to minimize this.
+ void CheckEnvironmentUsage();
+
protected:
enum Status {
UNUSED,
MarkEmptyBlocks();
if (generator.GenerateCode()) {
+ generator.CheckEnvironmentUsage();
CodeGenerator::MakeCodePrologue(info(), "optimized");
Code::Flags flags = info()->flags();
Handle<Code> code =
object_mapping_(0, zone),
outer_(outer),
entry_(entry),
- zone_(zone) { }
+ zone_(zone),
+ has_been_used_(false) { }
Handle<JSFunction> closure() const { return closure_; }
FrameType frame_type() const { return frame_type_; }
HEnterInlined* entry() { return entry_; }
Zone* zone() const { return zone_; }
+ bool has_been_used() const { return has_been_used_; }
+ void set_has_been_used() { has_been_used_ = true; }
+
void AddValue(LOperand* operand,
Representation representation,
bool is_uint32) {
LEnvironment* outer_;
HEnterInlined* entry_;
Zone* zone_;
+ bool has_been_used_;
};
void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment,
Safepoint::DeoptMode mode) {
+ environment->set_has_been_used();
if (!environment->HasBeenRegistered()) {
// Physical stack frame layout:
// -x ............. -4 0 ..................................... y
!hinstr->HasObservableSideEffects();
if (needs_environment && !instr->HasEnvironment()) {
instr = AssignEnvironment(instr);
+ // We can't really figure out if the environment is needed or not.
+ instr->environment()->set_has_been_used();
}
return instr;
LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1);
LInstruction* result =
DefineSameAsFirst(new(zone()) LTaggedToI(value, xmm_temp));
- if (!val->representation().IsSmi()) {
- // Note: Only deopts in deferred code.
- result = AssignEnvironment(result);
- }
+ if (!val->representation().IsSmi()) result = AssignEnvironment(result);
return result;
}
}
value = UseRegisterAtStart(instr->value());
if (instr->has_migration_target()) info()->MarkAsDeferredCalling();
}
- LCheckMaps* result = new(zone()) LCheckMaps(value);
+ LInstruction* result = new(zone()) LCheckMaps(value);
if (!instr->CanOmitMapChecks()) {
- // Note: Only deopts in deferred code.
- AssignEnvironment(result);
- if (instr->has_migration_target()) return AssignPointerMap(result);
+ result = AssignEnvironment(result);
+ if (instr->has_migration_target()) result = AssignPointerMap(result);
}
return result;
}