Commit 1582f37c authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Fix CFI failures with Operator1 class.

This ensures the class in question specifies the correct equality and
hashing function when instantiated. Note that this introduces two new
structs (i.e. OpEqualTo and OpHash) which can be used for defaults
within OpParameter as well.

R=titzer@chromium.org,bmeurer@chromium.org
TEST=cctest/test-operator

Review URL: https://codereview.chromium.org/1455913003

Cr-Commit-Position: refs/heads/master@{#32080}
parent 279f2aad
......@@ -573,22 +573,20 @@ const Operator* CommonOperatorBuilder::Int64Constant(int64_t value) {
const Operator* CommonOperatorBuilder::Float32Constant(volatile float value) {
return new (zone())
Operator1<float, base::bit_equal_to<float>, base::bit_hash<float>>( // --
IrOpcode::kFloat32Constant, Operator::kPure, // opcode
"Float32Constant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
return new (zone()) Operator1<float>( // --
IrOpcode::kFloat32Constant, Operator::kPure, // opcode
"Float32Constant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
}
const Operator* CommonOperatorBuilder::Float64Constant(volatile double value) {
return new (zone()) Operator1<double, base::bit_equal_to<double>,
base::bit_hash<double>>( // --
IrOpcode::kFloat64Constant, Operator::kPure, // opcode
"Float64Constant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
return new (zone()) Operator1<double>( // --
IrOpcode::kFloat64Constant, Operator::kPure, // opcode
"Float64Constant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
}
......@@ -603,24 +601,21 @@ const Operator* CommonOperatorBuilder::ExternalConstant(
const Operator* CommonOperatorBuilder::NumberConstant(volatile double value) {
return new (zone()) Operator1<double, base::bit_equal_to<double>,
base::bit_hash<double>>( // --
IrOpcode::kNumberConstant, Operator::kPure, // opcode
"NumberConstant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
return new (zone()) Operator1<double>( // --
IrOpcode::kNumberConstant, Operator::kPure, // opcode
"NumberConstant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
}
const Operator* CommonOperatorBuilder::HeapConstant(
const Handle<HeapObject>& value) {
return new (zone())
Operator1<Handle<HeapObject>, Handle<HeapObject>::equal_to,
Handle<HeapObject>::hash>( // --
IrOpcode::kHeapConstant, Operator::kPure, // opcode
"HeapConstant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
return new (zone()) Operator1<Handle<HeapObject>>( // --
IrOpcode::kHeapConstant, Operator::kPure, // opcode
"HeapConstant", // name
0, 0, 0, 1, 0, 0, // counts
value); // parameter
}
......
......@@ -677,8 +677,7 @@ const Operator* JSOperatorBuilder::CreateFunctionContext(int slot_count) {
const Operator* JSOperatorBuilder::CreateCatchContext(
const Handle<String>& name) {
return new (zone()) Operator1<Handle<String>, Handle<String>::equal_to,
Handle<String>::hash>( // --
return new (zone()) Operator1<Handle<String>>( // --
IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode
"JSCreateCatchContext", // name
2, 1, 1, 1, 1, 2, // counts
......@@ -688,8 +687,7 @@ const Operator* JSOperatorBuilder::CreateCatchContext(
const Operator* JSOperatorBuilder::CreateBlockContext(
const Handle<ScopeInfo>& scpope_info) {
return new (zone()) Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to,
Handle<ScopeInfo>::hash>( // --
return new (zone()) Operator1<Handle<ScopeInfo>>( // --
IrOpcode::kJSCreateBlockContext, Operator::kNoProperties, // opcode
"JSCreateBlockContext", // name
1, 1, 1, 1, 1, 2, // counts
......@@ -699,8 +697,7 @@ const Operator* JSOperatorBuilder::CreateBlockContext(
const Operator* JSOperatorBuilder::CreateScriptContext(
const Handle<ScopeInfo>& scpope_info) {
return new (zone()) Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to,
Handle<ScopeInfo>::hash>( // --
return new (zone()) Operator1<Handle<ScopeInfo>>( // --
IrOpcode::kJSCreateScriptContext, Operator::kNoProperties, // opcode
"JSCreateScriptContext", // name
1, 1, 1, 1, 1, 2, // counts
......
......@@ -136,10 +136,19 @@ DEFINE_OPERATORS_FOR_FLAGS(Operator::Properties)
std::ostream& operator<<(std::ostream& os, const Operator& op);
// Default equality function for below Operator1<*> class.
template <typename T>
struct OpEqualTo : public std::equal_to<T> {};
// Default hashing function for below Operator1<*> class.
template <typename T>
struct OpHash : public base::hash<T> {};
// A templatized implementation of Operator that has one static parameter of
// type {T}.
template <typename T, typename Pred = std::equal_to<T>,
typename Hash = base::hash<T>>
// type {T} with the proper default equality and hashing functions.
template <typename T, typename Pred = OpEqualTo<T>, typename Hash = OpHash<T>>
class Operator1 : public Operator {
public:
Operator1(Opcode opcode, Properties properties, const char* mnemonic,
......@@ -183,46 +192,38 @@ class Operator1 : public Operator {
// Helper to extract parameters from Operator1<*> operator.
template <typename T>
inline T const& OpParameter(const Operator* op) {
return reinterpret_cast<const Operator1<T>*>(op)->parameter();
return reinterpret_cast<const Operator1<T, OpEqualTo<T>, OpHash<T>>*>(op)
->parameter();
}
// NOTE: We have to be careful to use the right equal/hash functions below, for
// float/double we always use the ones operating on the bit level, for Handle<>
// we always use the ones operating on the location level.
template <>
inline float const& OpParameter(const Operator* op) {
return reinterpret_cast<const Operator1<float, base::bit_equal_to<float>,
base::bit_hash<float>>*>(op)
->parameter();
}
struct OpEqualTo<float> : public base::bit_equal_to<float> {};
template <>
struct OpHash<float> : public base::bit_hash<float> {};
template <>
inline double const& OpParameter(const Operator* op) {
return reinterpret_cast<const Operator1<double, base::bit_equal_to<double>,
base::bit_hash<double>>*>(op)
->parameter();
}
struct OpEqualTo<double> : public base::bit_equal_to<double> {};
template <>
struct OpHash<double> : public base::bit_hash<double> {};
template <>
inline Handle<HeapObject> const& OpParameter(const Operator* op) {
return reinterpret_cast<
const Operator1<Handle<HeapObject>, Handle<HeapObject>::equal_to,
Handle<HeapObject>::hash>*>(op)->parameter();
}
struct OpEqualTo<Handle<HeapObject>> : public Handle<HeapObject>::equal_to {};
template <>
struct OpHash<Handle<HeapObject>> : public Handle<HeapObject>::hash {};
template <>
inline Handle<String> const& OpParameter(const Operator* op) {
return reinterpret_cast<const Operator1<
Handle<String>, Handle<String>::equal_to, Handle<String>::hash>*>(op)
->parameter();
}
struct OpEqualTo<Handle<String>> : public Handle<String>::equal_to {};
template <>
struct OpHash<Handle<String>> : public Handle<String>::hash {};
template <>
inline Handle<ScopeInfo> const& OpParameter(const Operator* op) {
return reinterpret_cast<
const Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to,
Handle<ScopeInfo>::hash>*>(op)->parameter();
}
struct OpEqualTo<Handle<ScopeInfo>> : public Handle<ScopeInfo>::equal_to {};
template <>
struct OpHash<Handle<ScopeInfo>> : public Handle<ScopeInfo>::hash {};
} // namespace compiler
} // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment