ART: Make ManagedRegister ValueObject
Make ManagedRegister a value class, and ensure it is trivially
copyable.
Bug: 32619234
Test: m
Change-Id: Ie39b7f59a01ed293891e97110db3f5262f25fb4e
diff --git a/compiler/utils/managed_register.h b/compiler/utils/managed_register.h
index bb30f46..184cdf5 100644
--- a/compiler/utils/managed_register.h
+++ b/compiler/utils/managed_register.h
@@ -17,8 +17,11 @@
#ifndef ART_COMPILER_UTILS_MANAGED_REGISTER_H_
#define ART_COMPILER_UTILS_MANAGED_REGISTER_H_
+#include <type_traits>
#include <vector>
+#include "base/value_object.h"
+
namespace art {
namespace arm {
@@ -42,17 +45,14 @@
class X86_64ManagedRegister;
}
-class ManagedRegister {
+class ManagedRegister : public ValueObject {
public:
// ManagedRegister is a value class. There exists no method to change the
// internal state. We therefore allow a copy constructor and an
// assignment-operator.
- constexpr ManagedRegister(const ManagedRegister& other) : id_(other.id_) { }
+ constexpr ManagedRegister(const ManagedRegister& other) = default;
- ManagedRegister& operator=(const ManagedRegister& other) {
- id_ = other.id_;
- return *this;
- }
+ ManagedRegister& operator=(const ManagedRegister& other) = default;
constexpr arm::ArmManagedRegister AsArm() const;
constexpr arm64::Arm64ManagedRegister AsArm64() const;
@@ -85,6 +85,9 @@
int id_;
};
+static_assert(std::is_trivially_copyable<ManagedRegister>::value,
+ "ManagedRegister should be trivially copyable");
+
class ManagedRegisterSpill : public ManagedRegister {
public:
// ManagedRegisterSpill contains information about data type size and location in caller frame