Polymorphic functions

98 views
Skip to first unread message

daniel.s...@campus.tu-berlin.de

unread,
Nov 13, 2015, 11:21:40 AM11/13/15
to Intel SPMD Program Compiler Developers
As I want to write my bachelor thesis about the ispc compiler, I like the idea to extend it with polymorphic functions.
Polymorphic functions get mentioned in the technical paper as well as in the wiki page as desired feature.

If no one else is already working on this topic, I'd give it a try.

Syntactically I would stick to the C++ function templates, if nothing else gets suggested.
With C++11 the host code can call extern templates. It seems useful to me to implement 
also the possibility to export templates, although a host code parse would be necessary.

How do you like the idea? Any suggestions are welcome.

Regards,
Daniel

Dmitry Babokin

unread,
Nov 16, 2015, 7:06:39 AM11/16/15
to ispc...@googlegroups.com
Hi Daniel,

What do you mean by polymorphic functions? Do you mean function overloads by parameter type? It works, though not for export functions (because export functions are "C" functions and has no mangling).

> cat ov.ispc
void foo(int i, int j);
void foo(float f, float g);

void bar() {
  int i,j;
  float f,g;
  foo(i,j);
  foo(f,g);
}

> ispc ov.ispc --emit-llvm -o -|llvm-dis
Warning: No --target specified on command-line. Using default
        system target "avx2-i32x8".
; ModuleID = '<stdin>'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin14.5.0"

; Function Attrs: nounwind
declare void @foo___vyivyi(<8 x i32>, <8 x i32>, <8 x i32>) #0

; Function Attrs: nounwind
declare void @foo___vyfvyf(<8 x float>, <8 x float>, <8 x i32>) #0

; Function Attrs: nounwind
define void @0(<8 x i32> %__mask) #0 {
allocas:
  tail call void @foo___vyivyi(<8 x i32> undef, <8 x i32> undef, <8 x i32> %__mask)
  tail call void @foo___vyfvyf(<8 x float> undef, <8 x float> undef, <8 x i32> %__mask)
  ret void
}

attributes #0 = { nounwind }

!llvm.ident = !{!0}
!llvm.module.flags = !{!1}

!0 = !{!"clang version 3.8.0 (trunk 252601)"}
!1 = !{i32 1, !"PIC Level", i32 2}

--
You received this message because you are subscribed to the Google Groups "Intel SPMD Program Compiler Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ispc-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Daniel Schürmann

unread,
Nov 16, 2015, 8:05:32 AM11/16/15
to Intel SPMD Program Compiler Developers
Hello Dmitry,

by polymorphism I mean parametric polymorphism or generics or function templates in C++.
Of course the so called instantiations result in overloaded functions.

Now I understand the difficulty in my idea. It would require clang mangling to export overloaded
functions and therefore the compiler doesn't know, if it should export "C" or C++ mangled functions.

Well, I think about, if I implement templates for ispc without the option to export them for now.

Please tell me your ideas or about any other missing parts in the compiler.

Dmitry Babokin

unread,
Nov 16, 2015, 8:36:44 AM11/16/15
to ispc...@googlegroups.com
Daniel,

Adding function templates would be nice, but it's not that easy. And mangling is the easiest problem here. You'll need infrastructure in front-end for template instantiation (postponing semantic checking until the template is instantiated), you'll need to define and implement rules for type deduction as well (see C++ standard and discussions around C++ type deduction).

We've considered all this complications and moving forward decided that we need to switch to front-end, which already supports templates. We work on clang-based ispc front-end. It's not open sourced yet, but we are going to do that, once it's ready.

So, playing around with current ispc front-end may be interesting as a toy project, but could be not that interesting as bachelor thesis, as we are not sure that we'll integrate it into the project.

Daniel Schürmann

unread,
Nov 23, 2015, 12:44:00 PM11/23/15
to Intel SPMD Program Compiler Developers
Hello Dmitry,

I realize why you decided to switch to a new front-end, as it is hardly possible to implement templates in a clean way, if you are contextchecking while parsing,
and I'm not so interested in writing a hack.
Do you already know, when you will release the new front-end? Or is there any possiblity to participate in the developement?

Best regards,
Daniel

Dmitry Babokin

unread,
Nov 24, 2015, 3:12:59 AM11/24/15
to ispc...@googlegroups.com
Daniel,

We don't have particular timeline for releasing new solution, but this should happen some time in the beginning of the next year probably. Though, no promises at this point.

Since we open source it, participation in the development is possible.

I have a pool of students/interns who help me with the project. But if you suggest a topic, which you can develop on your own (with some help from our side), we can discuss it.

Are you mainly interested in front-end features or back-end is also interesting for you?

Dmitry.

Daniel Schürmann

unread,
Nov 25, 2015, 11:06:26 AM11/25/15
to Intel SPMD Program Compiler Developers
Hello Dmitry,

with my more theoretical background, I'm interested in fron-end features, but back-end would also be fine.
If not already done, I'd like to implement templates or a subset of template features.

If this is already done, please tell me open topics.

Best regards,
Daniel

Daniel Schürmann

unread,
Dec 2, 2015, 8:19:06 AM12/2/15
to Intel SPMD Program Compiler Developers
Hello Dmitry,

what do you think about templates and especially exported templates? Is this already implemented in the new front-end?
I would be glad, if I can do this. Thank you very much in advance.

Best regards,
Daniel

Dmitry Babokin

unread,
Dec 5, 2015, 1:20:18 PM12/5/15
to ispc...@googlegroups.com
Daniel,

Templates are not going to be part of our first release, the goal number one is to have the same functionality, but based on the new platform (clang). So the answer - they are not implemented yet. Though adding template support is relatively straight forward in clang, but it brings quite significant implementation burden at the same time.

I would be completely supportive to the idea that you contribute this part, but taking into account that we can't commit to open sourcing new solution by some given date, I think it not suits well for the scope of bachelor thesis.

I though about other things that we'd like to have in the front-end and I have an idea, which I think may be a good as a bachelor thesis. Some time ago I though about implementing it myself or giving it to one of my interns (also as a bachelor thesis), but never got to it.

The idea is front-end mode "ISPC explained" (or C++ explained). ISPC is difficult to newbies, because of it's model, which is different from C++. People don't get what computations are uniform and what are varying. Especially when it comes to pointers and arrays. So the solution, that I have in mind, is compiler mode, when it annotates source code with explicit explanation what's going on in the source code. The same approach could be very useful for C++ as well - for C++ rules, which confuse people - overloading, implicit casts, implicit constructors invocations and so on.

If this sounds interesting to we can discuss it further.

Dmitry.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages