Unfortunately using Terra's saveobj() function with a user defined target object didn't work.
However, it set me on the right path to find a solution.
Adding the following lines to Terra programs allowed me to execute them:
terralib.nativetarget = terralib.newtarget {
Triple = "x86_64-pc-linux-gnu"; -- LLVM target triple
CPU = "x86-64"; -- LLVM CPU name,
}
Though adding the " import "regent" "-statement brought the error back again.
Eventually I was able to pinpoint the problem to the cpu name and discard the target triple as a problem.
It seems that llvm just uses the name "unknown" if it is unable to recognize the host's cpu.
hunner@ubuntu-desktop:~$ llc --version
LLVM (http://llvm.org/):
LLVM version 3.8.1
Optimized build.
Built Jun 5 2018 (14:58:11).
Default target: x86_64-pc-linux-gnu
Host CPU: (unknown) A
list of cpu names recognized by llvm can be found by calling "llc
-mattr=help". To further add to the confusion, this command even lists a
available cpu target called "generic" for my system.
I found the following discussion in the Issue tracker of the Portable Computing Language project:
User franz:
There
was a commit to pocl's CMake to add a fallback to "generic" cpu and
print a warning but it seems "generic" doesn't work at all (although llc
does list it in the recognized cpu list).
So I guess something similar happens somewhere in the Terra codebase at
the moment: Substituting "unknown" with the target "generic" in hopes of enabling code generation for unsupported cpus.
Here is a fix to this from the Portable Computing Language project:
Before
the fix, they set the cpu target to "generic" when llc reported a cpu
name of "unknown", causing a similar issue to the one I encountered.
As
you can see, the way they choose to fix the problem was to emit an
error during the building process if an unknown cpu was encountered and
ask the user to provide a fitting substitution value. Maybe this could
also be a easy solution for the Legion Project.
But now to my dirty quick fix:
I cloned Terra from github and added the following two lines to
terra/src/tcompiler.cpp before
line 309 to overwrite the assignment in
line 271:
TT->external = new Module("external",*TT->ctx);
TT->external->setTargetTriple(TT->Triple);
lua_pushlightuserdata(L, TT);
// inserted code begins here
if(TT->CPU == "generic")
TT->CPU = "x86-64";
// inserted code ends here
return 1; // line 309 in the unmodified tcompiler.cpp
After this step I just built Terra with make and executed legion/language/install.py using the --with-terra flag.
As far as I can tell this allows the Terra compiler to use "valid" target information to generate generic x86_64 code.
I am now able to execute the regent example programs, as well as my own code.
Hopefully this hack can be helpful to other users facing problems with llvm not recognizing their CPU.
Markus Hunner