OSDN Git Service

Elide single basic block variable materialization
[android-x86/external-swiftshader.git] / src / Reactor / ReactorUnitTests.cpp
index c0abca1..a5de4f9 100644 (file)
@@ -112,6 +112,65 @@ TEST(ReactorUnitTests, Uninitialized)
        delete routine;
 }
 
+TEST(ReactorUnitTests, Unreachable)
+{
+       Routine *routine = nullptr;
+
+       {
+               Function<Int(Int)> function;
+               {
+                       Int a = function.Arg<0>();
+                       Int z = 4;
+
+                       Return(a + z);
+
+                       // Code beyond this point is unreachable but should not cause any
+                       // compilation issues.
+
+                       z += a;
+               }
+
+               routine = function("one");
+
+               if(routine)
+               {
+                       int (*callable)(int) = (int(*)(int))routine->getEntry();
+                       int result = callable(16);
+                       EXPECT_EQ(result, 20);
+               }
+       }
+
+       delete routine;
+}
+
+TEST(ReactorUnitTests, VariableAddress)
+{
+       Routine *routine = nullptr;
+
+       {
+               Function<Int(Int)> function;
+               {
+                       Int a = function.Arg<0>();
+                       Int z = 0;
+                       Pointer<Int> p = &z;
+                       *p = 4;
+
+                       Return(a + z);
+               }
+
+               routine = function("one");
+
+               if(routine)
+               {
+                       int (*callable)(int) = (int(*)(int))routine->getEntry();
+                       int result = callable(16);
+                       EXPECT_EQ(result, 20);
+               }
+       }
+
+       delete routine;
+}
+
 TEST(ReactorUnitTests, SubVectorLoadStore)
 {
        Routine *routine = nullptr;
@@ -1118,7 +1177,60 @@ TEST(ReactorUnitTests, PreserveXMMRegisters)
 }
 
 template <typename T>
-class GEPTest : public ::testing::Test {
+class CToReactorCastTest : public ::testing::Test
+{
+public:
+       using CType = typename std::tuple_element<0, T>::type;
+       using ReactorType = typename std::tuple_element<1, T>::type;
+};
+
+using CToReactorCastTestTypes = ::testing::Types
+       < // Subset of types that can be used as arguments.
+       //      std::pair<bool,         Bool>,    FIXME(capn): Not supported as argument type by Subzero.
+       //      std::pair<uint8_t,      Byte>,    FIXME(capn): Not supported as argument type by Subzero.
+       //      std::pair<int8_t,       SByte>,   FIXME(capn): Not supported as argument type by Subzero.
+       //      std::pair<int16_t,      Short>,   FIXME(capn): Not supported as argument type by Subzero.
+       //      std::pair<uint16_t,     UShort>,  FIXME(capn): Not supported as argument type by Subzero.
+               std::pair<int,          Int>,
+               std::pair<unsigned int, UInt>,
+               std::pair<float,        Float>
+       >;
+
+TYPED_TEST_CASE(CToReactorCastTest, CToReactorCastTestTypes);
+
+TYPED_TEST(CToReactorCastTest, Casts)
+{
+       using CType = typename TestFixture::CType;
+       using ReactorType = typename TestFixture::ReactorType;
+
+       Routine *routine = nullptr;
+
+       {
+               Function< Int(ReactorType) > function;
+               {
+                       ReactorType a = function.template Arg<0>();
+                       ReactorType b = CType{};
+                       RValue<ReactorType> c = RValue<ReactorType>(CType{});
+                       Bool same = (a == b) && (a == c);
+                       Return(IfThenElse(same, Int(1), Int(0))); // TODO: Ability to use Bools as return values.
+               }
+
+               routine = function("one");
+
+               if(routine)
+               {
+                       auto callable = (int(*)(CType))routine->getEntry();
+                       CType in = {};
+                       EXPECT_EQ(callable(in), 1);
+               }
+       }
+
+       delete routine;
+}
+
+template <typename T>
+class GEPTest : public ::testing::Test
+{
 public:
        using CType = typename std::tuple_element<0, T>::type;
        using ReactorType = typename std::tuple_element<1, T>::type;
@@ -1126,7 +1238,7 @@ public:
 
 using GEPTestTypes = ::testing::Types
        <
-               std::pair<int8_t,      Bool>,
+               std::pair<bool,        Bool>,
                std::pair<int8_t,      Byte>,
                std::pair<int8_t,      SByte>,
                std::pair<int8_t[4],   Byte4>,
@@ -1158,7 +1270,8 @@ using GEPTestTypes = ::testing::Types
 
 TYPED_TEST_CASE(GEPTest, GEPTestTypes);
 
-TYPED_TEST(GEPTest, PtrOffsets) {
+TYPED_TEST(GEPTest, PtrOffsets)
+{
        using CType = typename TestFixture::CType;
        using ReactorType = typename TestFixture::ReactorType;