Passing Arguments to Back-End

Using Clang, is there any way to specify -mcpu and -mattr options for the back-end? I am using -ccc-host-triple to force the triple to ptx32–. I have tried -mcpu and -mtarget with Clang, but I just get the “argument unused during compilation” warning.

For context, my back-end supports -mattr=+double. I can pass this argument to llc. Is there a command-line option in Clang to pass this along to the back-end? I know I can use -emit-llvm and then invoke llc manually, but I would like to let Clang handle this, if possible.

Hi Justin

You can try the clang's hidden '-llvm' switch like this : '-llvm -mcpu=mycpu' to pass options to the backend. I do not know for top of tree, but this works fine with llvm-2.9.

Cheers,

Hi Justin

You can try the clang’s hidden ‘-llvm’ switch like this : ‘-llvm –mcpu=mycpu’ to pass options to the backend. I do not know for top of tree, but this works fine with llvm-2.9.

Unfortunately, that does not work, at least not with ToT:

$ clang -ccc-host-triple ptx32 test1.c -S -O1 -mllvm -mattr=double
clang (LLVM option parsing): Unknown command line argument ‘-mattr=double’. Try: ‘clang (LLVM option parsing) -help’
clang (LLVM option parsing): Did you mean ‘-stats=double’?

For reference, what I want to replace is:

$ clang -ccc-host-triple ptx32 test1.c -S -O1 -emit-llvm && llc -mattr=double test1.s -o test1.ptx

Try "-Xclang -target-feature -Xclang +double".

-Eli

Hi Justin

You can try the clang’s hidden ‘-llvm’ switch like this : ‘-llvm
–mcpu=mycpu’ to pass options to the backend. I do not know for top of tree,
but this works fine with llvm-2.9.

Unfortunately, that does not work, at least not with ToT:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -mllvm -mattr=double
clang (LLVM option parsing): Unknown command line argument ‘-mattr=double’.
Try: ‘clang (LLVM option parsing) -help’
clang (LLVM option parsing): Did you mean ‘-stats=double’?
For reference, what I want to replace is:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -emit-llvm && llc
-mattr=double test1.s -o test1.ptx

Try “-Xclang -target-feature -Xclang +double”.

This seems to be on the right track, but now I’m getting another error:

$ clang -ccc-host-triple ptx32 test1.c -S -O1 -Xclang -target-feature -Xclang sm20
error: invalid target feature ‘double’

Does this just not work yet for non-native targets?

Hi Justin

You can try the clang’s hidden ‘-llvm’ switch like this : ‘-llvm
–mcpu=mycpu’ to pass options to the backend. I do not know for top of tree,
but this works fine with llvm-2.9.

Unfortunately, that does not work, at least not with ToT:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -mllvm -mattr=double
clang (LLVM option parsing): Unknown command line argument ‘-mattr=double’.
Try: ‘clang (LLVM option parsing) -help’
clang (LLVM option parsing): Did you mean ‘-stats=double’?
For reference, what I want to replace is:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -emit-llvm && llc
-mattr=double test1.s -o test1.ptx

Try “-Xclang -target-feature -Xclang +double”.

This seems to be on the right track, but now I’m getting another error:

$ clang -ccc-host-triple ptx32 test1.c -S -O1 -Xclang -target-feature -Xclang sm20
error: invalid target feature ‘double’

Sorry, bad copy-paste job. Replace sm20 with double. sm20 should also be a valid option for the back-end.

Oh, right, you also need to implement PTXTargetInfo::setFeatureEnabled
(in lib/Basic/Targets.cpp).

-Eli

Hi Justin

You can try the clang’s hidden ‘-llvm’ switch like this : ‘-llvm
–mcpu=mycpu’ to pass options to the backend. I do not know for top of
tree,
but this works fine with llvm-2.9.

Unfortunately, that does not work, at least not with ToT:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -mllvm -mattr=double
clang (LLVM option parsing): Unknown command line argument
‘-mattr=double’.
Try: ‘clang (LLVM option parsing) -help’
clang (LLVM option parsing): Did you mean ‘-stats=double’?
For reference, what I want to replace is:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -emit-llvm && llc
-mattr=double test1.s -o test1.ptx

Try “-Xclang -target-feature -Xclang +double”.

This seems to be on the right track, but now I’m getting another error:
$ clang -ccc-host-triple ptx32 test1.c -S -O1 -Xclang -target-feature
-Xclang sm20
error: invalid target feature ‘double’

Sorry, bad copy-paste job. Replace sm20 with double. sm20 should also be a
valid option for the back-end.

Oh, right, you also need to implement PTXTargetInfo::setFeatureEnabled
(in lib/Basic/Targets.cpp).

Works like a charm now! Thanks!