From 41fd3067ae9f1104314a94203863075b98dd4bd0 Mon Sep 17 00:00:00 2001 From: Dmitriy Maksimov Date: Tue, 7 Jan 2020 05:25:42 +1000 Subject: [PATCH] Removed duplicates/unused code from src\jit\jitstd. (#1272) make_signed/make_unsigned moved to clr_std/type_traits. Removed pair.h and type_traits.h Fix #27557 --- src/coreclr/src/inc/clr_std/type_traits | 64 +++++++++ src/coreclr/src/jit/arraystack.h | 2 +- src/coreclr/src/jit/assertionprop.cpp | 6 +- src/coreclr/src/jit/block.cpp | 4 +- src/coreclr/src/jit/compiler.h | 2 +- src/coreclr/src/jit/jithashtable.h | 4 +- src/coreclr/src/jit/jitstd.h | 3 - src/coreclr/src/jit/jitstd/algorithm.h | 45 +----- src/coreclr/src/jit/jitstd/functional.h | 33 ----- src/coreclr/src/jit/jitstd/list.h | 24 ++-- src/coreclr/src/jit/jitstd/pair.h | 57 -------- src/coreclr/src/jit/jitstd/type_traits.h | 230 ------------------------------- src/coreclr/src/jit/jitstd/utility.h | 65 +-------- src/coreclr/src/jit/jitstd/vector.h | 10 +- src/coreclr/src/jit/rangecheck.cpp | 2 +- src/coreclr/src/jit/ssabuilder.h | 2 +- src/coreclr/src/jit/ssarenamestate.h | 2 +- src/coreclr/src/jit/utils.cpp | 4 +- src/coreclr/src/jit/valuenum.cpp | 6 +- 19 files changed, 103 insertions(+), 462 deletions(-) delete mode 100644 src/coreclr/src/jit/jitstd/pair.h delete mode 100644 src/coreclr/src/jit/jitstd/type_traits.h diff --git a/src/coreclr/src/inc/clr_std/type_traits b/src/coreclr/src/inc/clr_std/type_traits index 5001038..334c53b 100644 --- a/src/coreclr/src/inc/clr_std/type_traits +++ b/src/coreclr/src/inc/clr_std/type_traits @@ -187,6 +187,70 @@ namespace std }; //----------------------------------------------------------------------------------------- + // TEMPLATE CLASS make_unsigned + template + struct make_unsigned + { + }; + + template<> + struct make_unsigned + { + typedef unsigned int type; + }; + +#ifndef PLATFORM_UNIX + + template<> + struct make_unsigned + { + typedef unsigned long type; + }; + +#endif // !PLATFORM_UNIX + + template<> + struct make_unsigned<__int64> + { + typedef unsigned __int64 type; + }; + + template<> + struct make_unsigned + { + typedef size_t type; + }; + + //----------------------------------------------------------------------------------------- + // TEMPLATE CLASS make_signed + template + struct make_signed + { + }; + + template<> + struct make_signed + { + typedef signed int type; + }; + +#ifndef PLATFORM_UNIX + + template<> + struct make_signed + { + typedef signed long type; + }; + +#endif // !PLATFORM_UNIX + + template<> + struct make_signed + { + typedef signed __int64 type; + }; + + //----------------------------------------------------------------------------------------- // TEMPLATE CLASS is_lvalue_reference template struct is_lvalue_reference diff --git a/src/coreclr/src/jit/arraystack.h b/src/coreclr/src/jit/arraystack.h index 76268ac..5b62ce6 100644 --- a/src/coreclr/src/jit/arraystack.h +++ b/src/coreclr/src/jit/arraystack.h @@ -46,7 +46,7 @@ public: Realloc(); } - new (&data[tosIndex], jitstd::placement_t()) T(jitstd::forward(args)...); + new (&data[tosIndex], jitstd::placement_t()) T(std::forward(args)...); tosIndex++; } diff --git a/src/coreclr/src/jit/assertionprop.cpp b/src/coreclr/src/jit/assertionprop.cpp index b610048..e50b127 100644 --- a/src/coreclr/src/jit/assertionprop.cpp +++ b/src/coreclr/src/jit/assertionprop.cpp @@ -1938,7 +1938,7 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) // Check for op1 or op2 to be lcl var and if so, keep it in op1. if ((op1->gtOper != GT_LCL_VAR) && (op2->gtOper == GT_LCL_VAR)) { - jitstd::swap(op1, op2); + std::swap(op1, op2); } // If op1 is lcl and op2 is const or lcl, create assertion. if ((op1->gtOper == GT_LCL_VAR) && @@ -1951,7 +1951,7 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) if (((op1->gtOper != GT_IND) || (op1->AsOp()->gtOp1->gtOper != GT_LCL_VAR)) && ((op2->gtOper == GT_IND) && (op2->AsOp()->gtOp1->gtOper == GT_LCL_VAR))) { - jitstd::swap(op1, op2); + std::swap(op1, op2); } // If op1 is ind, then extract op1's oper. if ((op1->gtOper == GT_IND) && (op1->AsOp()->gtOp1->gtOper == GT_LCL_VAR)) @@ -1962,7 +1962,7 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) // Look for a call to an IsInstanceOf helper compared to a nullptr if ((op2->gtOper != GT_CNS_INT) && (op1->gtOper == GT_CNS_INT)) { - jitstd::swap(op1, op2); + std::swap(op1, op2); } // Validate op1 and op2 if ((op1->gtOper != GT_CALL) || (op1->AsCall()->gtCallType != CT_HELPER) || (op1->TypeGet() != TYP_REF) || // op1 diff --git a/src/coreclr/src/jit/block.cpp b/src/coreclr/src/jit/block.cpp index 88f297d..62242d8 100644 --- a/src/coreclr/src/jit/block.cpp +++ b/src/coreclr/src/jit/block.cpp @@ -40,8 +40,8 @@ flowList* ShuffleHelper(unsigned hash, flowList* res) { // Swap res with head. prev->flNext = head; - jitstd::swap(head->flNext, res->flNext); - jitstd::swap(head, res); + std::swap(head->flNext, res->flNext); + std::swap(head, res); } } return head; diff --git a/src/coreclr/src/jit/compiler.h b/src/coreclr/src/jit/compiler.h index 1c8ff9a..3553133 100644 --- a/src/coreclr/src/jit/compiler.h +++ b/src/coreclr/src/jit/compiler.h @@ -327,7 +327,7 @@ public: } unsigned ssaNum = GetMinSsaNum() + m_count; - m_array[m_count++] = T(jitstd::forward(args)...); + m_array[m_count++] = T(std::forward(args)...); // Ensure that the first SSA number we allocate is SsaConfig::FIRST_SSA_NUM assert((ssaNum == SsaConfig::FIRST_SSA_NUM) || (m_count > 1)); diff --git a/src/coreclr/src/jit/jithashtable.h b/src/coreclr/src/jit/jithashtable.h index c186f87..2ae55f8 100644 --- a/src/coreclr/src/jit/jithashtable.h +++ b/src/coreclr/src/jit/jithashtable.h @@ -308,7 +308,7 @@ public: if (n == nullptr) { - n = new (m_alloc) Node(m_table[index], k, jitstd::forward(args)...); + n = new (m_alloc) Node(m_table[index], k, std::forward(args)...); m_table[index] = n; m_tableCount++; @@ -768,7 +768,7 @@ private: Value m_val; template - Node(Node* next, Key k, Args&&... args) : m_next(next), m_key(k), m_val(jitstd::forward(args)...) + Node(Node* next, Key k, Args&&... args) : m_next(next), m_key(k), m_val(std::forward(args)...) { } diff --git a/src/coreclr/src/jit/jitstd.h b/src/coreclr/src/jit/jitstd.h index 5d89694..09095a3 100644 --- a/src/coreclr/src/jit/jitstd.h +++ b/src/coreclr/src/jit/jitstd.h @@ -3,9 +3,6 @@ // See the LICENSE file in the project root for more information. #include "allocator.h" -#include "functional.h" #include "list.h" -#include "pair.h" -#include "type_traits.h" #include "utility.h" #include "vector.h" diff --git a/src/coreclr/src/jit/jitstd/algorithm.h b/src/coreclr/src/jit/jitstd/algorithm.h index ef7204e..460bf08 100644 --- a/src/coreclr/src/jit/jitstd/algorithm.h +++ b/src/coreclr/src/jit/jitstd/algorithm.h @@ -9,43 +9,6 @@ namespace jitstd { -template -InputIterator find(InputIterator first, InputIterator last, - const CompareValue& value) -{ - for (; first != last; ++first) - { - if (*first == value) - { - return first; - } - } - return last; -} - -template -InputIterator find_if(InputIterator first, InputIterator last, const Pred& pred) -{ - for (; first != last; ++first) - { - if (pred(*first)) - { - return first; - } - } - return last; -} - -template -Function for_each(InputIterator first, InputIterator last, Function func) -{ - for (; first != last; ++first) - { - func(*first); - } - return func; -} - namespace { // Sort the elements in range [first, last] using insertion sort, an efficient alternative @@ -109,16 +72,16 @@ void quick_sort(RandomAccessIterator first, RandomAccessIterator last, Less less // The usual median of 3 pivot, we'll have *first <= *pivot <= *last. if (less(*pivot, *first)) { - swap(*pivot, *first); + std::swap(*pivot, *first); } if (less(*last, *pivot)) { - swap(*pivot, *last); + std::swap(*pivot, *last); if (less(*pivot, *first)) { - swap(*pivot, *first); + std::swap(*pivot, *first); } } @@ -167,7 +130,7 @@ void quick_sort(RandomAccessIterator first, RandomAccessIterator last, Less less // We now have *newLast <= *pivot <= *newFirst so we need to swap // *newFirst and *newLast. - swap(*newFirst, *newLast); + std::swap(*newFirst, *newLast); // pivot is an iterator and not the actual value, if the value gets // swapped we need to update the iterator to point to the new place. diff --git a/src/coreclr/src/jit/jitstd/functional.h b/src/coreclr/src/jit/jitstd/functional.h index 31456a8..f9d4592 100644 --- a/src/coreclr/src/jit/jitstd/functional.h +++ b/src/coreclr/src/jit/jitstd/functional.h @@ -9,21 +9,6 @@ namespace jitstd { -template -void swap(T& a, T& b) -{ - T t(a); - a = b; - b = t; -} - -template -struct unary_function -{ - typedef Arg argument_type; - typedef Result result_type; -}; - template struct binary_function { @@ -41,22 +26,4 @@ struct greater : binary_function } }; -template -struct equal_to : binary_function -{ - bool operator()(const T& lhs, const T& rhs) const - { - return lhs == rhs; - } -}; - -template -struct identity : unary_function -{ - const T& operator()(const T& op) const - { - return op; - } -}; - } // end of namespace jitstd. diff --git a/src/coreclr/src/jit/jitstd/list.h b/src/coreclr/src/jit/jitstd/list.h index 1120137..5f28bdf 100644 --- a/src/coreclr/src/jit/jitstd/list.h +++ b/src/coreclr/src/jit/jitstd/list.h @@ -23,7 +23,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #include "iterator.h" #include "functional.h" -#include "utility.h" +#include "clr_std/utility" namespace jitstd { @@ -261,7 +261,7 @@ private: template Node(Args&&... args) - : m_value(jitstd::forward(args)...) + : m_value(std::forward(args)...) { } }; @@ -482,7 +482,7 @@ template typename list::iterator list::emplace(iterator position, Args&&... args) { - Node* pNewNode = new (m_nodeAllocator.allocate(1), placement_t()) Node(jitstd::forward(args)...); + Node* pNewNode = new (m_nodeAllocator.allocate(1), placement_t()) Node(std::forward(args)...); insert_new_node_helper(position.m_pNode, pNewNode); return iterator(pNewNode); } @@ -611,7 +611,7 @@ template template void list::emplace_back(Args&&... args) { - emplace(end(), jitstd::forward(args)...); + emplace(end(), std::forward(args)...); } template @@ -624,7 +624,7 @@ template template void list::emplace_front(Args&&... args) { - emplace(begin(), jitstd::forward(args)...); + emplace(begin(), std::forward(args)...); } template @@ -705,9 +705,9 @@ void list::reverse() { for (Node* p = m_pHead; p != NULL; p = p->m_pNext) { - jitstd::swap(p->m_pPrev, p->m_pNext); + std::swap(p->m_pPrev, p->m_pNext); } - jitstd::swap(m_pHead, m_pTail); + std::swap(m_pHead, m_pTail); } template @@ -757,11 +757,11 @@ void list::splice(iterator position, list& x, iterator first, iter template void list::swap(list& lst) { - jitstd::swap(lst.m_pHead, m_pHead); - jitstd::swap(lst.m_pTail, m_pTail); - jitstd::swap(lst.m_nSize, m_nSize); - jitstd::swap(lst.m_allocator, m_allocator); - jitstd::swap(lst.m_nodeAllocator, m_nodeAllocator); + std::swap(lst.m_pHead, m_pHead); + std::swap(lst.m_pTail, m_pTail); + std::swap(lst.m_nSize, m_nSize); + std::swap(lst.m_allocator, m_allocator); + std::swap(lst.m_nodeAllocator, m_nodeAllocator); } template diff --git a/src/coreclr/src/jit/jitstd/pair.h b/src/coreclr/src/jit/jitstd/pair.h deleted file mode 100644 index f306000..0000000 --- a/src/coreclr/src/jit/jitstd/pair.h +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - - -#pragma once - -namespace jitstd -{ -template -class pair -{ -public: - Type1 first; - Type2 second; - - pair(const Type1& fst, const Type2& sec) - : first(fst) - , second(sec) - { - } - - template - pair(const AltType1& fst, const AltType2& sec) - : first((Type1) fst) - , second((Type2) sec) - { - } - - template - pair(const pair& that) - : first((Type1) that.first) - , second((Type2) that.second) - { - } - - pair(const pair& that) - : first(that.first) - , second(that.second) - { - } - - template - const pair& operator=(const pair& pair) - { - first = pair.first; - second = pair.second; - return *this; - } - - bool operator==(const pair& other) const - { - return (other.first == first && other.second == second); - } -}; -} diff --git a/src/coreclr/src/jit/jitstd/type_traits.h b/src/coreclr/src/jit/jitstd/type_traits.h deleted file mode 100644 index cf690a5..0000000 --- a/src/coreclr/src/jit/jitstd/type_traits.h +++ /dev/null @@ -1,230 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - - -#pragma once - -namespace jitstd -{ -template -struct remove_const -{ - typedef T type; -}; - -template -struct remove_const -{ - typedef T type; -}; - -template -struct remove_volatile -{ - typedef T type; -}; - -template -struct remove_volatile -{ - typedef T type; -}; - -template -struct remove_cv : remove_const::type> -{ -}; - -template -struct remove_reference -{ - typedef T type; -}; - -template -struct remove_reference -{ - typedef T type; -}; - -template -struct remove_reference -{ - typedef T type; -}; - -template -struct is_lvalue_reference -{ - enum { value = false }; -}; - -template -struct is_lvalue_reference -{ - enum { value = true }; -}; - -template -struct is_unqualified_pointer -{ - enum { value = false }; -}; - -template -struct is_unqualified_pointer -{ - enum { value = true }; -}; - -template -struct is_pointer : is_unqualified_pointer::type> -{ -}; - -template -struct is_integral -{ - enum { value = false }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - -template<> -struct is_integral -{ - enum { value = true }; -}; - - -template -struct conditional -{ -}; - -template -struct conditional -{ - typedef Type1 type; -}; - -template -struct conditional -{ - typedef Type2 type; -}; - -template -struct make_unsigned -{ -}; - -template<> -struct make_unsigned -{ - typedef unsigned int type; -}; - -#ifndef _HOST_UNIX_ - -template<> -struct make_unsigned -{ - typedef unsigned long type; -}; - -#endif // !_HOST_UNIX_ - -template<> -struct make_unsigned<__int64> -{ - typedef unsigned __int64 type; -}; - -template<> -struct make_unsigned -{ - typedef size_t type; -}; - -template -struct make_signed -{ -}; - -template<> -struct make_signed -{ - typedef signed int type; -}; - -#ifndef _HOST_UNIX_ - -template<> -struct make_signed -{ - typedef signed long type; -}; - -#endif // !_HOST_UNIX_ - -template<> -struct make_signed -{ - typedef signed __int64 type; -}; - -} // namespace jitstd diff --git a/src/coreclr/src/jit/jitstd/utility.h b/src/coreclr/src/jit/jitstd/utility.h index 3de6f32..119450e 100644 --- a/src/coreclr/src/jit/jitstd/utility.h +++ b/src/coreclr/src/jit/jitstd/utility.h @@ -6,27 +6,11 @@ #pragma once -#include "pair.h" -#include "type_traits.h" +#include "clr_std/type_traits" namespace jitstd { -template -inline -T&& forward(typename jitstd::remove_reference::type& arg) -{ - return static_cast(arg); -} - -template -inline -T&& forward(typename jitstd::remove_reference::type&& arg) -{ - static_assert(!jitstd::is_lvalue_reference::value, "unexpected lvalue reference"); - return static_cast(arg); -} - namespace utility { // Template class for scoped execution of a lambda. @@ -46,53 +30,6 @@ namespace utility scoped_code(const T& l) : l(l) { } ~scoped_code() { l(); } }; - - - // Ensures that "wset" is the union of the initial state of "wset" and "rset". - // Elements from "rset" that were not in "wset" are added to "cset." - template - bool set_union(Set& wset, const Set& rset, Set& cset) - { - bool change = false; - for (typename Set::const_iterator i = rset.begin(); i != rset.end(); ++i) - { - jitstd::pair result = wset.insert(*i); - if (result.second) - { - change = true; - cset.insert(*i); - } - } - return change; - } - - template - bool set_union(Set& wset, const Set& rset) - { - bool change = false; - for (typename Set::const_iterator i = rset.begin(); i != rset.end(); ++i) - { - jitstd::pair result = wset.insert(*i); - change |= result.second; - } - return change; - } - - template - bool set_difference(Set& wset, const Set& rset) - { - bool change = false; - for (typename Set::const_iterator i = rset.begin(); i != rset.end(); ++i) - { - if (wset.find(*i) != wset.end()) - { - wset.erase(*i); - change = true; - } - } - - return change; - } } // end of namespace utility. } // end of namespace jitstd. diff --git a/src/coreclr/src/jit/jitstd/vector.h b/src/coreclr/src/jit/jitstd/vector.h index ff37141..9ffde55 100644 --- a/src/coreclr/src/jit/jitstd/vector.h +++ b/src/coreclr/src/jit/jitstd/vector.h @@ -679,11 +679,11 @@ typename vector::size_type vector::size() const template void vector::swap(vector& vec) { - jitstd::swap(m_pArray, vec.m_pArray); - jitstd::swap(m_nSize, vec.m_nSize); - jitstd::swap(m_nCapacity, vec.m_nCapacity); - jitstd::swap(m_nCapacity, vec.m_nCapacity); - jitstd::swap(m_allocator, vec.m_allocator); + std::swap(m_pArray, vec.m_pArray); + std::swap(m_nSize, vec.m_nSize); + std::swap(m_nCapacity, vec.m_nCapacity); + std::swap(m_nCapacity, vec.m_nCapacity); + std::swap(m_allocator, vec.m_allocator); } // ======================================================================================= diff --git a/src/coreclr/src/jit/rangecheck.cpp b/src/coreclr/src/jit/rangecheck.cpp index ce2b2a6..022df50 100644 --- a/src/coreclr/src/jit/rangecheck.cpp +++ b/src/coreclr/src/jit/rangecheck.cpp @@ -334,7 +334,7 @@ bool RangeCheck::IsBinOpMonotonicallyIncreasing(GenTreeOp* binop) // Check if we have a var + const. if (op2->OperGet() == GT_LCL_VAR) { - jitstd::swap(op1, op2); + std::swap(op1, op2); } if (op1->OperGet() != GT_LCL_VAR) { diff --git a/src/coreclr/src/jit/ssabuilder.h b/src/coreclr/src/jit/ssabuilder.h index b15c5cf..5bdc752 100644 --- a/src/coreclr/src/jit/ssabuilder.h +++ b/src/coreclr/src/jit/ssabuilder.h @@ -11,7 +11,7 @@ typedef int LclVarNum; // Pair of a local var name eg: V01 and Ssa number; eg: V01_01 -typedef jitstd::pair SsaVarName; +typedef std::pair SsaVarName; class SsaBuilder { diff --git a/src/coreclr/src/jit/ssarenamestate.h b/src/coreclr/src/jit/ssarenamestate.h index bf7dac1..5edc200 100644 --- a/src/coreclr/src/jit/ssarenamestate.h +++ b/src/coreclr/src/jit/ssarenamestate.h @@ -107,7 +107,7 @@ private: stack = m_alloc.allocate(1); } - return new (stack, jitstd::placement_t()) StackNode(jitstd::forward(args)...); + return new (stack, jitstd::placement_t()) StackNode(std::forward(args)...); } // Push a SSA number onto a stack diff --git a/src/coreclr/src/jit/utils.cpp b/src/coreclr/src/jit/utils.cpp index 630d996..427544f 100644 --- a/src/coreclr/src/jit/utils.cpp +++ b/src/coreclr/src/jit/utils.cpp @@ -2200,7 +2200,7 @@ T GetUnsignedMagic(T d, bool* add /*out*/, int* shift /*out*/) return magic->magic; } - typedef typename jitstd::make_signed::type ST; + typedef typename std::make_signed::type ST; const unsigned bits = sizeof(T) * 8; const unsigned bitsMinus1 = bits - 1; @@ -2355,7 +2355,7 @@ T GetSignedMagic(T denom, int* shift /*out*/) const int bits = sizeof(T) * 8; const int bits_minus_1 = bits - 1; - typedef typename jitstd::make_unsigned::type UT; + typedef typename std::make_unsigned::type UT; const UT two_nminus1 = UT(1) << bits_minus_1; diff --git a/src/coreclr/src/jit/valuenum.cpp b/src/coreclr/src/jit/valuenum.cpp index e1ea75c..0b72dde 100644 --- a/src/coreclr/src/jit/valuenum.cpp +++ b/src/coreclr/src/jit/valuenum.cpp @@ -634,7 +634,7 @@ float ValueNumStore::EvalOpSpecialized(VNFunc vnf, float v0, float v1) template T ValueNumStore::EvalOpSpecialized(VNFunc vnf, T v0, T v1) { - typedef typename jitstd::make_unsigned::type UT; + typedef typename std::make_unsigned::type UT; assert((sizeof(T) == 4) || (sizeof(T) == 8)); @@ -853,7 +853,7 @@ int ValueNumStore::EvalComparison(VNFunc vnf, float v0, float v1) template int ValueNumStore::EvalComparison(VNFunc vnf, T v0, T v1) { - typedef typename jitstd::make_unsigned::type UT; + typedef typename std::make_unsigned::type UT; // Here we handle the compare ops that are the same for all integer types. if (vnf < VNF_Boundary) @@ -1956,7 +1956,7 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN, V // Order arg0 arg1 by numerical VN value. if (arg0VN > arg1VN) { - jitstd::swap(arg0VN, arg1VN); + std::swap(arg0VN, arg1VN); } } -- 2.7.4