Best ways of adding target specific options

We have been developing a Clang/LLVM derived compiler for our proprietary
processor since v2.7, and this is all working reasonably well, it really is
a great compiler that gets better all the time.

Recently I found myself adding "yet another" target specific option, and I
realise that over the years we have added quite a lot of options that are
very target specific. The majority of these pertain to the code-generation
part of LLVM, some are Clang specific, and some need a bit of both.

It occurred to me that while adding the options "works", that we haven't
really incorporated them into Clang in a way that I would consider properly
aligned with the ethos of the Clang codebase. So I thought that this is a
good time to re-consider all of our additional options and how to better
re-factor them.

Ideally I would have a target specific directory that would allow me to
supplement the standard options in clean regular and object oriented way,
but Clang's driver isn't currently organised this way (I'm still on v3.3,
but I'll move to v3.5 when its cooked). And a way of selective suppressing
some options in a target specific way instead of having to add lots of
conditionally checked exceptions based on the target triple would also be

So I would like to seek advice and recommendations on how to "best" add
target specific options to Clang. What are the best practices for adding

In some cases I have options that effect code-generation which are passed
onto LLVM, but I also need to provide a pre-defined MACRO to the C/C++ code
so that it can be aware of code-generation changes that are important at the
high level language level.

I haven't found any articles that provide guidelines as to how best to add
new options for custom targets. For instance, when should they be added to:


where most of my options have been added - and which group is most
appropriate? Or should they be added to:


or even:


When should they be added to the ".def" files or the ".td" files, and how?

It's not something that is essential, my additional options "work", but
there is a lack of elegance in how we have added them that gnaws at me, and
I know it could be done better. I would like to determine best practice for
adding options, and then maybe derive an abstraction that I could propose to
the Clang developers for future consideration.


  Martin O'Riordan (Movidius Ltd.)