Beispiel #1
0
int
main(int argc, char *argv[])
   {
   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define type dictionaries\n");
   StructTypeDictionary structTypes;
   UnionTypeDictionary unionTypes;

   printf("Step 3: compile getStructFieldAddress builder\n");
   GetStructFieldAddressBuilder getStructFieldAddressBuilder(&structTypes);
   uint8_t *getStructFieldAddressEntry;
   int32_t rc = compileMethodBuilder(&getStructFieldAddressBuilder, &getStructFieldAddressEntry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 4: invoke compiled code for getStructFieldAddress and verify results\n");
   Struct s;
   s.f1 = 1;
   s.f2 = 2;
   auto getStructFieldAddress = (GetStructFieldAddressFunction *) getStructFieldAddressEntry;
   auto structFieldAddress = getStructFieldAddress(&s);
   assert(&(s.f2) == structFieldAddress);

   printf("Step 5: compile getUnionFieldAddress builder\n");
   GetUnionFieldAddressBuilder getUnionFieldAddressBuilder(&unionTypes);
   uint8_t *getUnionFieldAddressEntry;
   rc = compileMethodBuilder(&getUnionFieldAddressBuilder, &getUnionFieldAddressEntry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 6: invoke compiled code for getUnionFieldAddress and verify results\n");
   Union u;
   u.f2 = 2;
   auto getUnionFieldAddress = (GetUnionFieldAddressFunction  *) getUnionFieldAddressEntry;
   auto unionFieldAddress = getUnionFieldAddress(&u);
   assert(&(u.f2) == unionFieldAddress);

   printf ("Step 7: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }
Beispiel #2
0
int
main(int argc, char *argv[])
   {
   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define type dictionary\n");
   TR::TypeDictionary types;

   printf("Step 3: compile method builder\n");
   DotProduct method(&types);
   uint8_t *entry=0;
   int32_t rc = compileMethodBuilder(&method, &entry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 4: define values\n");
   double result[10] = { 0 };
   double values1[10] = { 1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5 };
   double values2[10] = { 10.5,9.5,8.5,7.5,6.5,5.5,4.5,3.5,2.5,1.5 };

   printf("Step 5: invoke compiled code and verify results\n");
   DotProductFunctionType *test = (DotProductFunctionType *)entry;
   test(result, values1, values2, 10);

   printf("result = [\n");
   for (int32_t i=0;i < 10;i++)
      printf("           %lf\n", result[i]);
   printf("         ]\n\n");

   printf ("Step 6: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }
Beispiel #3
0
int
main(int argc, char *argv[])
   {
   int32_t inliningDepth = 1;   // by default, inline one level of calls
   if (argc == 2)
      inliningDepth = atoi(argv[1]);

   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define relevant types\n");
   TR::TypeDictionary types;

   printf("Step 3: compile method builder, inlining one level\n");
   InliningRecursiveFibonacciMethod method(&types, inliningDepth);
   uint8_t *entry=0;
   int32_t rc = compileMethodBuilder(&method, &entry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 4: invoke compiled code\n");
   RecursiveFibFunctionType *fib = (RecursiveFibFunctionType *)entry;
   for (int32_t n=0;n < 20;n++)
      printf("fib(%2d) = %d\n", n, fib(n));

   printf ("Step 5: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }
Beispiel #4
0
static Function assert_compile(TR::MethodBuilder* m)
   {
   uint8_t* entry;
   assert(0 == compileMethodBuilder(m, &entry));
   return (Function)entry;
   }
Beispiel #5
0
int
main(int argc, char *argv[])
   {
   printf("Step 1: initialize JIT\n");
   bool initialized = initializeJit();
   if (!initialized)
      {
      fprintf(stderr, "FAIL: could not initialize JIT\n");
      exit(-1);
      }

   printf("Step 2: define matrices\n");
   const int32_t N=4;
   double A[N*N];
   double B[N*N];
   double C[N*N];
   double D[N*N];
   for (int32_t i=0;i < N;i++)
      {
      for (int32_t j=0;j < N;j++)
         {
         A[i*N+j] = 1.0;
         B[i*N+j] = (double)i+(double)j;
         C[i*N+j] = 0.0;
         D[i*N+j] = 0.0;
         }
      }
   printMatrix(A, N, "A");
   printMatrix(B, N, "B");

   printf("Step 3: define type dictionaries\n");
   OMR::JitBuilder::TypeDictionary types;
   OMR::JitBuilder::TypeDictionary vectypes;

   printf("Step 4: compile MatMult method builder\n");
   MatMult method(&types);
   void *entry=0;
   int32_t rc = compileMethodBuilder(&method, &entry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 5: invoke MatMult compiled code\n");
   MatMultFunctionType *test = (MatMultFunctionType *)entry;
   test(C, A, B, N);
   printMatrix(C, N, "C");

   printf("Step 6: compile VectorMatMult method builder\n");
   VectorMatMult vecmethod(&vectypes);
   void *vecentry=0;
   rc = compileMethodBuilder(&vecmethod, &vecentry);
   if (rc != 0)
      {
      fprintf(stderr,"FAIL: compilation error %d\n", rc);
      exit(-2);
      }

   printf("Step 7: invoke MatMult compiled code\n");
   MatMultFunctionType *vectest = (MatMultFunctionType *)vecentry;
   vectest(D, A, B, N);
   printMatrix(D, N, "D");

   printf ("Step 8: shutdown JIT\n");
   shutdownJit();

   printf("PASS\n");
   }