Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Unified Diff: runtime/vm/intermediate_language.h

Issue 2937933002: Reduce copying, redundancy & repetition for codegen of comparison instructions (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/intermediate_language.h
diff --git a/runtime/vm/intermediate_language.h b/runtime/vm/intermediate_language.h
index 588d082bc70a03551fc685729f18f6c3db2a823a..11a8a498e87d490994491092e3b8955a41f332f5 100644
--- a/runtime/vm/intermediate_language.h
+++ b/runtime/vm/intermediate_language.h
@@ -536,6 +536,26 @@ FOR_EACH_ABSTRACT_INSTRUCTION(FORWARD_DECLARATION)
DECLARE_INSTRUCTION_NO_BACKEND(type) \
DECLARE_INSTRUCTION_BACKEND()
+#if defined(TARGET_ARCH_DBC)
+#define DECLARE_COMPARISON_METHODS \
+ virtual LocationSummary* MakeLocationSummary(Zone* zone, bool optimizing) \
+ const; \
+ virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler, \
+ BranchLabels labels); \
+ virtual Condition GetPredictedCondition(FlowGraphCompiler* compiler, \
+ BranchLabels labels);
+#else
+#define DECLARE_COMPARISON_METHODS \
+ virtual LocationSummary* MakeLocationSummary(Zone* zone, bool optimizing) \
+ const; \
+ virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler, \
+ BranchLabels labels);
+#endif
+
+#define DECLARE_COMPARISON_INSTRUCTION(type) \
+ DECLARE_INSTRUCTION_NO_BACKEND(type) \
+ DECLARE_COMPARISON_METHODS
+
#ifndef PRODUCT
#define PRINT_TO_SUPPORT virtual void PrintTo(BufferFormatter* f) const;
#else
@@ -966,6 +986,13 @@ class Instruction : public ZoneAllocated {
};
+struct BranchLabels {
+ Label* true_label;
+ Label* false_label;
+ Label* fall_through;
+};
+
+
class PureInstruction : public Instruction {
public:
explicit PureInstruction(intptr_t deopt_id) : Instruction(deopt_id) {}
@@ -1920,13 +1947,6 @@ class TemplateDefinition : public CSETrait<Definition, PureDefinition>::Base {
};
-struct BranchLabels {
- Label* true_label;
- Label* false_label;
- Label* fall_through;
-};
-
-
class InductionVariableInfo;
@@ -2420,6 +2440,22 @@ class TemplateComparison
virtual bool MayThrow() const { return ThrowsTrait::kCanThrow; }
+ virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
Vyacheslav Egorov (Google) 2017/06/15 11:32:46 I think all of these methods should simply go into
Vyacheslav Egorov (Google) 2017/06/15 11:32:46 Also comment what this does.
erikcorry 2017/06/19 07:15:09 I was sure there was some reason that would not wo
erikcorry 2017/06/19 07:15:09 Done.
+
+ // Used by EmitBranchCode and EmitNativeCode depending on whether the boolean
+ // is to be turned into branches or instantiated.
+ // May return a valid condition in which case the caller is expected to emit
+ // a branch based on that condition. May also branch directly to the labels.
Vyacheslav Egorov (Google) 2017/06/15 11:32:46 "emit a branch based on that condition" <- specify
erikcorry 2017/06/19 07:15:09 Done.
+ virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
+ BranchLabels labels) = 0;
+
+#if defined(TARGET_ARCH_DBC)
+ virtual Condition GetPredictedCondition(FlowGraphCompiler* compiler,
Vyacheslav Egorov (Google) 2017/06/15 11:32:46 Comment what this does.
erikcorry 2017/06/19 07:15:09 Done.
+ BranchLabels labels) = 0;
+#endif
+
+ virtual void EmitNativeCode(FlowGraphCompiler* compiler);
+
protected:
EmbeddedArray<Value*, N> inputs_;
@@ -3038,7 +3074,7 @@ class StrictCompareInstr : public TemplateComparison<2, NoThrow, Pure> {
bool needs_number_check,
intptr_t deopt_id);
- DECLARE_INSTRUCTION(StrictCompare)
+ DECLARE_COMPARISON_INSTRUCTION(StrictCompare)
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
@@ -3048,11 +3084,6 @@ class StrictCompareInstr : public TemplateComparison<2, NoThrow, Pure> {
virtual Definition* Canonicalize(FlowGraph* flow_graph);
- virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
-
- virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
- BranchLabels labels);
-
bool needs_number_check() const { return needs_number_check_; }
void set_needs_number_check(bool value) { needs_number_check_ = value; }
@@ -3083,7 +3114,7 @@ class TestSmiInstr : public TemplateComparison<2, NoThrow, Pure> {
SetInputAt(1, right);
}
- DECLARE_INSTRUCTION(TestSmi);
+ DECLARE_COMPARISON_INSTRUCTION(TestSmi);
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
@@ -3095,11 +3126,6 @@ class TestSmiInstr : public TemplateComparison<2, NoThrow, Pure> {
return kTagged;
}
- virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
-
- virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
- BranchLabels labels);
-
private:
DISALLOW_COPY_AND_ASSIGN(TestSmiInstr);
};
@@ -3124,7 +3150,7 @@ class TestCidsInstr : public TemplateComparison<1, NoThrow, Pure> {
return cid_results_;
}
- DECLARE_INSTRUCTION(TestCids);
+ DECLARE_COMPARISON_INSTRUCTION(TestCids);
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
@@ -3142,11 +3168,6 @@ class TestCidsInstr : public TemplateComparison<1, NoThrow, Pure> {
virtual bool AttributesEqual(Instruction* other) const;
- virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
-
- virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
- BranchLabels labels);
-
void set_licm_hoisted(bool value) { licm_hoisted_ = value; }
PRINT_OPERANDS_TO_SUPPORT
@@ -3173,7 +3194,7 @@ class EqualityCompareInstr : public TemplateComparison<2, NoThrow, Pure> {
set_operation_cid(cid);
}
- DECLARE_INSTRUCTION(EqualityCompare)
+ DECLARE_COMPARISON_INSTRUCTION(EqualityCompare)
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
@@ -3181,11 +3202,6 @@ class EqualityCompareInstr : public TemplateComparison<2, NoThrow, Pure> {
virtual bool ComputeCanDeoptimize() const { return false; }
- virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
-
- virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
- BranchLabels labels);
-
virtual Representation RequiredInputRepresentation(intptr_t idx) const {
ASSERT((idx == 0) || (idx == 1));
if (operation_cid() == kDoubleCid) return kUnboxedDouble;
@@ -3215,7 +3231,7 @@ class RelationalOpInstr : public TemplateComparison<2, NoThrow, Pure> {
set_operation_cid(cid);
}
- DECLARE_INSTRUCTION(RelationalOp)
+ DECLARE_COMPARISON_INSTRUCTION(RelationalOp)
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
@@ -3223,11 +3239,6 @@ class RelationalOpInstr : public TemplateComparison<2, NoThrow, Pure> {
virtual bool ComputeCanDeoptimize() const { return false; }
- virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
-
- virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
- BranchLabels labels);
-
virtual Representation RequiredInputRepresentation(intptr_t idx) const {
ASSERT((idx == 0) || (idx == 1));
if (operation_cid() == kDoubleCid) return kUnboxedDouble;
@@ -5348,7 +5359,8 @@ class DoubleTestOpInstr : public TemplateComparison<1, NoThrow, Pure> {
PRINT_OPERANDS_TO_SUPPORT
- DECLARE_INSTRUCTION(DoubleTestOp)
+ DECLARE_COMPARISON_INSTRUCTION(DoubleTestOp)
+
virtual CompileType ComputeType() const;
virtual Definition* Canonicalize(FlowGraph* flow_graph);
@@ -5360,11 +5372,6 @@ class DoubleTestOpInstr : public TemplateComparison<1, NoThrow, Pure> {
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
- virtual void EmitBranchCode(FlowGraphCompiler* compiler, BranchInstr* branch);
-
- virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
- BranchLabels labels);
-
private:
const MethodRecognizer::Kind op_kind_;
@@ -6934,6 +6941,14 @@ class CheckedSmiComparisonInstr : public TemplateComparison<2, Throws> {
virtual Condition EmitComparisonCode(FlowGraphCompiler* compiler,
BranchLabels labels);
+#if defined(TARGET_ARCH_DBC)
+ virtual Condition GetPredictedCondition(FlowGraphCompiler* compiler,
+ BranchLabels labels) {
+ UNREACHABLE();
+ return INVALID_CONDITION;
+ }
+#endif
+
virtual ComparisonInstr* CopyWithNewOperands(Value* left, Value* right);
private:

Powered by Google App Engine
This is Rietveld 408576698