New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang] Add MSC_VER and target arch defines when targeting the MSVC ABI #73250
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -204,6 +204,30 @@ void Flang::AddAArch64TargetArgs(const ArgList &Args, | |||
} | ||||
} | ||||
|
||||
static void addVSDefines(const ToolChain &TC, const ArgList &Args, | ||||
ArgStringList &CmdArgs) { | ||||
|
||||
unsigned ver = 0; | ||||
const VersionTuple vt = TC.computeMSVCVersion(nullptr, Args); | ||||
ver = vt.getMajor() * 10000000 + vt.getMinor().value_or(0) * 100000 + | ||||
vt.getSubminor().value_or(0); | ||||
CmdArgs.push_back(Args.MakeArgString("-D_MSC_VER=" + Twine(ver / 100000))); | ||||
CmdArgs.push_back(Args.MakeArgString("-D_MSC_FULL_VER=" + Twine(ver))); | ||||
CmdArgs.push_back(Args.MakeArgString("-D_WIN32")); | ||||
|
||||
llvm::Triple triple = TC.getTriple(); | ||||
if (triple.isAArch64()) { | ||||
CmdArgs.push_back("-D_M_ARM64=1"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does LLVM/Flang support the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe so. It's not tested at all if it does as far as I can tell! |
||||
} else if (triple.isX86() && triple.isArch32Bit()) { | ||||
CmdArgs.push_back("-D_M_IX86=600"); | ||||
} else if (triple.isX86() && triple.isArch64Bit()) { | ||||
CmdArgs.push_back("-D_M_X64=100"); | ||||
} else { | ||||
llvm_unreachable( | ||||
"Flang on Windows only supports X86_32, X86_64 and AArch64"); | ||||
} | ||||
Comment on lines
+221
to
+228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Flang doesn't support 32bit llvm-project/flang/CMakeLists.txt Line 60 in 659e401
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't support 32 bit hosts but I think we do support 32 bit targets |
||||
} | ||||
|
||||
static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, | ||||
ArgStringList &CmdArgs) { | ||||
assert(TC.getTriple().isKnownWindowsMSVCEnvironment() && | ||||
|
@@ -322,6 +346,7 @@ void Flang::addTargetOptions(const ArgList &Args, | |||
|
||||
if (Triple.isKnownWindowsMSVCEnvironment()) { | ||||
processVSRuntimeLibrary(TC, Args, CmdArgs); | ||||
addVSDefines(TC, Args, CmdArgs); | ||||
} | ||||
|
||||
// TODO: Add target specific flags, ABI, mtune option etc. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OTOH this could be considered out of scope for this PR. |
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
! RUN: %flang -### --target=aarch64-windows-msvc %S/Inputs/hello.f90 -v 2>&1 | FileCheck %s --check-prefixes=MSVC,MSVC-AARCH64 | ||
! RUN: %flang -### --target=i386-windows-msvc %S/Inputs/hello.f90 -v 2>&1 | FileCheck %s --check-prefixes=MSVC,MSVC-X86_32 | ||
! RUN: %flang -### --target=x86_64-windows-msvc %S/Inputs/hello.f90 -v 2>&1 | FileCheck %s --check-prefixes=MSVC,MSVC-X86_64 | ||
|
||
! MSVC: -fc1 | ||
! MSVC-SAME: -D_MSC_VER={{[0-9]*}} | ||
! MSVC-SAME: -D_MSC_FULL_VER={{[0-9]*}} | ||
! MSVC-AARCH64-SAME: -D_M_ARM64=1 | ||
! MSVC-X86_32-SAME: -D_M_IX86=600 | ||
! MSVC-X86_64-SAME: -D_M_X64=100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named it this way to match processVSRuntimeLibs which I stole from clang :)