[cfe-commits] [PATCH] Add _M_IX86 for Windows

John Thompson john.thompson.jtsoftware at gmail.com
Thu Aug 20 14:53:30 PDT 2009


Here's another pass at refining Targets.cpp for Windows targets.

Unfortunately, it requires some LLVM enhancements, placed in the
separate visual_studio_targets_llvm.patch file:

I extended the Triple class, supporting more explicitly the optional
environment field, adding an EnvironmentType enum for that with an
item for Visual Studio (-vc), and adding a Win64 OSType.  There are
probably more environments that can be added to the EnvironmentType
enum.

Changed the default triples from cmake to be i686-pc-win32-vc and if
64-bit is enabled, x86_64-pc-win64-vc.

Here's the Targets.cpp changes, placed in visual_studio_targets_clang.patch:

Added separate TargetInfo's for Visual Studio, MinGW, and Cygwin, as
illustrated by the following hierarchy:

TargetInfo
   X86TargetInfo
       X86_32TargetInfo
           DarwinI386TargetInfo
           OpenBSDI386TargetInfo
           CygwinWindowsX86_32TargetInfo  (i686-pc-cygwin) (new)
           WindowsX86_32TargetInfo (i686-pc-win32)
               VisualStudioWindowsX86_32TargetInfo  (i686-pc-win32-vc) (new)
               MinGWX86_32TargetInfo  (i686-pc-mingw32) (new)
        X86_64TargetInfo
           DarwinX86_64TargetInfo
           OpenBSDX86_64TargetInfo
           WindowsX86_64TargetInfo  (x86_64-pc-win64) (new)
               VisualStudioWindowsX86_64TargetInfo  (x86_64-pc-win64-vc) (new)
               MinGWX86_64TargetInfo  (x86_64-pc-mingw64) (new)

Messing with the triple was of some concern to me, so I also tried an
alternate approach without adding -vc to the triple, making the
default -win32 map to Visual Studio, and having MinGW and Cygwin be
separate as above, but then I figured you might want -winXX with no
environment field to be the native Clang target for Windows, mapping
to the generic Windows TargetInfo, assuming at some point Clang has
it's own runtime and headers.  But let me know if this would be the
more desired approach.

Note that though I've tested the Targets;cpp part in the debugger,
I've not yet been able to build, and therefore, run the LLVM tests.  I
don't expect the Triple class changes to change any existing behavior,
but I have a slight worry that the change of the default triple from
cmake might impact something, but being on the apparently less-used
cmake path, perhaps it's less of a concern.  I built and ran the Clang
tests on Linux successfully.

-John

On Wed, Aug 19, 2009 at 2:27 PM, Anton
Korobeynikov<anton at korobeynikov.info> wrote:
> Hello, John
>
> Thanks for working on all this mess with different subtargets &
> flavours!
>
>> It seems the TargetInfo selection is based on the arch-vendor-os
>> "triple" from LLVM.  The implication therefore is that we need to add
>> new Visual Studio-specific triples, even though a triple doesn't seem
>> to really accomodate compiler emulation choice.  (Perhaps we need a
>> arch-vendor-os-tool "quadruple"?)
> This sounds like a sane idea, e.g. x86-pc-win32-vc
>
>> Also, MinGW and Cygwin probably need separate TargetInfo's, rather
>> than being considered the generic Windows.
> Cygwin is not windows... It does not define, e.g. WIN32 define, etc. So,
> this should be completely separate...
>
>> Win64 also needs support.
> Right.
>
>> TargetInfo
>>     X86TargetInfo
>>         X86_32TargetInfo
>>             DarwinI386TargetInfo
>>             OpenBSDI386TargetInfo
>>             WindowsX86_32TargetInfo (x86-pc-win32)
>>                 VisualStudioWindowsX86_32TargetInfo  (x86-pc-win32vc) (new)
>>                 MinGWWindowsX86_32TargetInfo  (x86-pc-mingw32) (new)
> "W" in MingW is already "windows". I don't think we need such prefixes
> here.
>
>>                 CygwinWindowsX86_32TargetInfo  (x86-pc-cygwin) (new)
> See above for cygwin
>
>>         X86_64TargetInfo
>>             DarwinX86_64TargetInfo
>>             OpenBSDX86_64TargetInfo
>>             WindowsX86_64TargetInfo  (x86_64-pc-win64) (new)
>>                 VisualStudioWindowsX86_64TargetInfo
>> (x86_64-pc-win64vc) (new)
>>                 VisualStudioMinGWX86_32TargetInfo  (x86_64-pc-mingw64) (new)
> Why "VisualStudio" here? Also, the correct target triple is
> x86_64-mingw32 :)
>
>> We could carry the VC++ emulation a bit farther, and also encode the
>> VC++ versions, i.e. OS of win32vc80 or win32vc90, which would allow
>> TargetInfo to set _MSC_VER.  And/or the -fms-extensions could be
>> changed to accept a VC++ version number.  But currently the TargetInfo
>> initialization can't see the language options, so this would need to
>> be changed, or the special triple would be needed too.
> I'd prefer to deal with this iteratively, so 'just' vcpp for now...
>
>> At present, Opts.Microsoft gets set to true in
>> WindowsX86_32TargetInfo.  The impression I get from Anton's last
>> message is that setting to true should be moved to the VisualStudio
>> versions only.
> Right
>
>> The current WindowsX86_32TargetInfo class defines __MSVCRT__.  Where
>> does this come from?
> I have no idea about vcpp, but at least mingw defines it as a builtin
>
> PS: It seems you wanted to answer to list, but sent just to me ;)
> --
> With best regards, Anton Korobeynikov.
>
> Faculty of Mathematics & Mechanics, Saint Petersburg State University.
>
>


-- 
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: visual_studio_targets_clang.patch
Type: application/octet-stream
Size: 7379 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090820/a561ce5f/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: visual_studio_targets_llvm.patch
Type: application/octet-stream
Size: 5061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090820/a561ce5f/attachment-0001.obj>


More information about the cfe-commits mailing list