/* { dg-do compile } */ /* { dg-options "-O2 -fdump-tree-optimized" } */ extern void __assert_fail(const char*, const char*, int, const char*); namespace Eigen { enum { AutoAlign }; template struct conditional; template struct conditional { typedef Else type; }; template struct remove_reference { typedef T type; }; struct is_arithmetic { enum { value }; }; template struct traits; template struct traits : traits {}; template struct evaluator; template struct EigenBase; template class PlainObjectBase; template class Matrix; template class MatrixBase; template class CwiseNullaryOp; template class CwiseBinaryOp; template struct scalar_constant_op; template struct size_at_compile_time { enum { ret = _Rows }; }; struct ref_selector { typedef const Matrix& type; }; template struct dense_xpr_base { typedef MatrixBase type; }; template ::XprKind> struct generic_xpr_base { typedef typename dense_xpr_base::type type; }; template struct plain_constant_type { ; typedef CwiseNullaryOp, Matrix::ColsAtCompileTime, traits::MaxRowsAtCompileTime, traits::MaxColsAtCompileTime>> type; }; struct scalar_product_op { float operator()(float a, float b) { return a * b; } }; template struct scalar_constant_op { scalar_constant_op(float other) : m_other(other) {} float operator()() { return m_other; } float m_other; }; struct assign_op { void assignCoeff(float& a, float b) { a = b; } }; template class DenseCoeffsBase : public EigenBase { public: typedef typename traits::Scalar Scalar; typedef typename conditional::type CoeffReturnType; }; template class DenseBase : public DenseCoeffsBase { public: enum { RowsAtCompileTime = traits::RowsAtCompileTime, SizeAtCompileTime = size_at_compile_time::ret, MaxSizeAtCompileTime }; }; template class MatrixBase : public DenseBase { public: using DenseBase::derived; template CwiseBinaryOp::type> operator*(T& scalar) { return CwiseBinaryOp::type>( derived(), typename plain_constant_type::type(derived().rows(), 0, scalar)); } }; template struct EigenBase { const Derived& derived() const { return *static_cast(this); } Derived& const_cast_derived() const { return *static_cast(const_cast(this)); } }; template struct binary_evaluator; template struct evaluator : evaluator { evaluator(const T& xpr) : evaluator(xpr) {} }; template struct evaluator { typedef Derived PlainObjectType; typedef typename PlainObjectType::Scalar Scalar; evaluator(const PlainObjectType& m) : m_data(m.data()) {} typename PlainObjectType::CoeffReturnType coeff(long row, long) { return m_data[row]; } Scalar& coeffRef(long row, long) { return const_cast(m_data)[row]; } const Scalar* m_data; }; template struct evaluator> : evaluator>> { typedef Matrix XprType; evaluator(const XprType& m) : evaluator>(m) {} }; struct nullary_wrapper { template float operator()(scalar_constant_op op, IndexType, IndexType) const { return op(); } }; template struct evaluator> { typedef CwiseNullaryOp XprType; evaluator(XprType n) : m_functor(n.functor()) {} template typename XprType::CoeffReturnType coeff(IndexType row, IndexType col) { return m_wrapper(m_functor, row, col); } NullaryOp m_functor; nullary_wrapper m_wrapper; }; template struct evaluator> : binary_evaluator> { evaluator(CwiseBinaryOp xpr) : binary_evaluator>(xpr) {} }; template struct binary_evaluator> { typedef CwiseBinaryOp XprType; binary_evaluator(XprType xpr) : m_lhsImpl(xpr.lhs()), m_rhsImpl(xpr.rhs()) {} typename XprType::CoeffReturnType coeff(long row, long col) { return m_functor(m_lhsImpl.coeff(row, col), m_rhsImpl.coeff(row, col)); } BinaryOp m_functor; evaluator m_lhsImpl; evaluator m_rhsImpl; }; template struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling { enum { outer, inner = Index }; static void run(Kernel kernel) { kernel.assignCoeffByOuterInner(outer, inner); copy_using_evaluator_DefaultTraversal_CompleteUnrolling::run(kernel); } }; template struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling { static void run(Kernel) {} }; template struct dense_assignment_loop { static void run(Kernel kernel) { typedef typename Kernel::DstEvaluatorType::XprType DstXprType; enum { size = DstXprType::SizeAtCompileTime, alignedSize = 0 }; copy_using_evaluator_DefaultTraversal_CompleteUnrolling::run(kernel); } }; template class generic_dense_assignment_kernel { typedef typename DstEvaluatorTypeT::XprType DstXprType; public: typedef DstEvaluatorTypeT DstEvaluatorType; typedef SrcEvaluatorTypeT SrcEvaluatorType; generic_dense_assignment_kernel(DstEvaluatorType dst, SrcEvaluatorType src, Functor, DstXprType& dstExpr) : m_dst(dst), m_src(src), m_dstExpr(dstExpr) {} long assignCoeff_col; void assignCoeffByOuterInner(long, long inner) { long __trans_tmp_1 = inner; m_functor.assignCoeff(m_dst.coeffRef(__trans_tmp_1, assignCoeff_col), m_src.coeff(__trans_tmp_1, assignCoeff_col)); } DstEvaluatorType m_dst; SrcEvaluatorType m_src; Functor m_functor; DstXprType& m_dstExpr; }; template void call_dense_assignment_loop(DstXprType& dst, SrcXprType src, Functor func) { typedef evaluator DstEvaluatorType; typedef evaluator SrcEvaluatorType; SrcEvaluatorType srcEvaluator(src); DstEvaluatorType dstEvaluator(dst); typedef generic_dense_assignment_kernel Kernel; Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived()); dense_assignment_loop::run(kernel); } template void call_assignment_no_alias(Dst& dst, Src src, Func func) { enum { NeedToTranspose }; typename conditional::type actualDst(dst); CwiseBinaryOp, const CwiseNullaryOp, const Matrix>> __trans_tmp_4 = src; call_dense_assignment_loop(actualDst, __trans_tmp_4, func); } template struct plain_array { float array[Size]; }; template class DenseStorage { plain_array m_data; public: DenseStorage() {} DenseStorage(const DenseStorage&); static long rows() { return _Rows; } const float* data() const { return m_data.array; } float* data() { return m_data.array; } }; template class PlainObjectBase : public dense_xpr_base::type { public: typedef typename dense_xpr_base::type Base; typedef typename traits::Scalar Scalar; DenseStorage m_storage; long rows() const { return m_storage.rows(); } const Scalar* data() const { return m_storage.data(); } PlainObjectBase() {} template PlainObjectBase(const DenseBase& other) { _set_noalias(other); } template void _set_noalias(const DenseBase& other) { call_assignment_no_alias(this->derived(), other.derived(), assign_op()); } }; template struct traits> { typedef _Scalar Scalar; typedef int XprKind; enum { RowsAtCompileTime = _Rows, ColsAtCompileTime, MaxRowsAtCompileTime, MaxColsAtCompileTime, }; }; template class Matrix : public PlainObjectBase< Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> { public: typedef PlainObjectBase Base; typedef typename traits::Scalar Scalar; Matrix(Scalar& x, Scalar& y, Scalar& z) { m_storage.data()[0] = x; m_storage.data()[1] = y; m_storage.data()[2] = z; } template Matrix(const EigenBase& other) : Base(other.derived()) {} using Base::m_storage; }; template struct traits> { typedef typename traits::XprKind XprKind; enum { RowsAtCompileTime }; typedef float Scalar; }; template class CwiseBinaryOpImpl; template class CwiseBinaryOp : public CwiseBinaryOpImpl { public: typedef ref_selector::type LhsNested; typedef RhsType RhsNested; CwiseBinaryOp(const Matrix& aLhs, RhsType& aRhs) : m_lhs(aLhs), m_rhs(aRhs) {} remove_reference::type& lhs() { return m_lhs; } typename remove_reference::type& rhs() { return m_rhs; } LhsNested m_lhs; RhsNested m_rhs; }; template class CwiseBinaryOpImpl : public generic_xpr_base, const CwiseNullaryOp, const Matrix>>>::type {}; template struct traits> : traits {}; template class CwiseNullaryOp : public dense_xpr_base>::type { public: CwiseNullaryOp(long rows, long, scalar_constant_op func) : m_functor(func) { rows ? void() : __assert_fail("", "", 1, __PRETTY_FUNCTION__); } scalar_constant_op functor() { return m_functor; } scalar_constant_op m_functor; }; } // namespace Eigen Eigen::Matrix should_inline(float x, float y, float z, float scale) { return Eigen::Matrix(x, y, z) * scale; } // We should inline everything to should_inline /* { dg-final { scan-tree-dump-times "Function" "optimized" } } */