Commit 52cb3d1b by Nicolas Capens Committed by Nicolas Capens

Assume Microsoft ABI on Windows

The SUBZERO_USE_MICROSOFT_ABI macro definition was used to indicate that we want to use the Microsoft x86-64 calling convention, instead of the System V one which PNaCl assumes (even on Windows). Using the standard _WIN64 macro instead makes us not require defining the custom one as part of our build. SUBZERO_USE_MICROSOFT_ABI was also being used to decide whether to emit stack probes. For 32-bit Windows targets, use the _WIN32 macro instead. Note that when _WIN64 is defined, _WIN32 is also defined, but to avoid confusion we use _WIN64 in the X8664 backend. Bug: b/179832693 Change-Id: Ic2e62d3dc26543876673c07b9ccc01e9d92762bf Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/55528 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 97e0693e
......@@ -72,10 +72,6 @@ if (supports_subzero) {
"ICE_THREAD_LOCAL_HACK=0",
]
if (is_win) {
defines += [ "SUBZERO_USE_MICROSOFT_ABI" ]
}
if (current_cpu == "x64") {
defines += [
"SZTARGET=X8664",
......
......@@ -119,8 +119,6 @@ target_compile_definitions(subzero
"ALLOW_MINIMAL_BUILD=0"
"ALLOW_WASM=0"
"ICE_THREAD_LOCAL_HACK=0"
PRIVATE
$<$<BOOL:${WIN32}>:"SUBZERO_USE_MICROSOFT_ABI">
)
target_link_libraries(subzero
......
......@@ -211,7 +211,7 @@
// sboxres, isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8,
// is16To8, isTrunc8Rcvr, isAhRcvr, aliases)
#if defined(SUBZERO_USE_MICROSOFT_ABI) // Microsoft x86-64 ABI
#if defined(_WIN64) // Microsoft x86-64 ABI
#define REGX8664_BYTEREG_TABLE REGX8664_BYTEREG_TABLE2(0, 1)
#define REGX8664_GPR_TABLE REGX8664_GPR_TABLE2(0, 1)
#else // System V AMD64 ABI
......@@ -264,7 +264,7 @@
// sboxres, isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8,
// is16To8, isTrunc8Rcvr, isAhRcvr, aliases)
#if defined(SUBZERO_USE_MICROSOFT_ABI) // Microsoft x86-64 ABI
#if defined(_WIN64) // Microsoft x86-64 ABI
#define REGX8664_XMM_TABLE REGX8664_XMM_TABLE2(0, 1)
#else // System V AMD64 ABI
#define REGX8664_XMM_TABLE REGX8664_XMM_TABLE2(1, 0)
......
......@@ -17,7 +17,7 @@
#include "IceTargetLoweringX8632Traits.h"
#if defined(SUBZERO_USE_MICROSOFT_ABI)
#if defined(_WIN32)
extern "C" void _chkstk();
#endif
......@@ -115,7 +115,7 @@ const TargetX8632Traits::TableTypeX8632AttributesType
const size_t TargetX8632Traits::TableTypeX8632AttributesSize =
llvm::array_lengthof(TableTypeX8632Attributes);
#if defined(SUBZERO_USE_MICROSOFT_ABI)
#if defined(_WIN32)
// Windows 32-bit only guarantees 4 byte stack alignment
const uint32_t TargetX8632Traits::X86_STACK_ALIGNMENT_BYTES = 4;
#else
......@@ -408,7 +408,7 @@ void TargetX8632::emitSandboxedReturn() {
}
void TargetX8632::emitStackProbe(size_t StackSizeBytes) {
#if defined(SUBZERO_USE_MICROSOFT_ABI)
#if defined(_WIN32)
if (StackSizeBytes >= 4096) {
// _chkstk on Win32 is actually __alloca_probe, which adjusts ESP by the
// stack amount specified in EAX, so we save ESP in ECX, and restore them
......
......@@ -17,7 +17,7 @@
#include "IceDefs.h"
#include "IceTargetLoweringX8664Traits.h"
#if defined(SUBZERO_USE_MICROSOFT_ABI)
#if defined(_WIN64)
extern "C" void __chkstk();
#endif
......@@ -716,7 +716,7 @@ Inst *TargetX8664::emitCallToTarget(Operand *CallTarget, Variable *ReturnReg,
// System V: force r11 when calling a variadic function so that rax isn't
// used, since rax stores the number of FP args (see NumVariadicFpArgs
// usage below).
#if !defined(SUBZERO_USE_MICROSOFT_ABI)
#if !defined(_WIN64)
if (NumVariadicFpArgs > 0)
TargetReg = Traits::RegisterSet::Reg_r11;
#endif
......@@ -732,7 +732,7 @@ Inst *TargetX8664::emitCallToTarget(Operand *CallTarget, Variable *ReturnReg,
}
// System V: store number of FP args in RAX for variadic calls
#if !defined(SUBZERO_USE_MICROSOFT_ABI)
#if !defined(_WIN64)
if (NumVariadicFpArgs > 0) {
// Store number of FP args (stored in XMM registers) in RAX for variadic
// calls
......@@ -783,7 +783,7 @@ void TargetX8664::emitSandboxedReturn() {
}
void TargetX8664::emitStackProbe(size_t StackSizeBytes) {
#if defined(SUBZERO_USE_MICROSOFT_ABI)
#if defined(_WIN64)
// Mirroring the behavior of MSVC here, which emits a _chkstk when locals are
// >= 4KB, rather than the 8KB claimed by the docs.
if (StackSizeBytes >= 4096) {
......
......@@ -640,7 +640,7 @@ public:
static RegNumT getRdxOrDie() { return RegisterSet::Reg_rdx; }
#if defined(SUBZERO_USE_MICROSOFT_ABI)
#if defined(_WIN64)
// Microsoft x86-64 calling convention:
//
// * The first four arguments of vector/fp type, regardless of their
......
......@@ -89,14 +89,12 @@ template <> struct PoolTypeConverter<uint8_t> {
namespace X86NAMESPACE {
// The Microsoft x64 ABI requires the caller to allocate a minimum 32 byte
// The Microsoft x64 ABI requires the caller to allocate a 32 byte
// "shadow store" (aka "home space") so that the callee may copy the 4
// register args to it.
template <typename Traits> SizeT getShadowStoreSize() {
#if defined(SUBZERO_USE_MICROSOFT_ABI)
static const SizeT ShadowStoreSize =
Traits::Is64Bit ? 4 * typeWidthInBytes(Traits::WordType) : 0;
return ShadowStoreSize;
constexpr SizeT getShadowStoreSize() {
#if defined(_WIN64)
return 4 * sizeof(int64_t);
#else
return 0;
#endif
......@@ -1049,7 +1047,7 @@ void TargetX86Base<TraitsType>::addProlog(CfgNode *Node) {
// space on the frame for globals (variables with multi-block lifetime), and
// one block to share for locals (single-block lifetime).
const SizeT ShadowStoreSize = getShadowStoreSize<Traits>();
const SizeT ShadowStoreSize = getShadowStoreSize();
// StackPointer: points just past return address of calling function
......@@ -2681,7 +2679,7 @@ void TargetX86Base<TraitsType>::lowerCall(const InstCall *Instr) {
OperandList StackArgs, StackArgLocations;
uint32_t ParameterAreaSizeBytes = 0;
ParameterAreaSizeBytes += getShadowStoreSize<Traits>();
ParameterAreaSizeBytes += getShadowStoreSize();
// Classify each argument operand according to the location where the argument
// is passed.
......@@ -7693,7 +7691,7 @@ uint32_t TargetX86Base<TraitsType>::getCallStackArgumentsSizeBytes(
Variable *Dest = Instr->getDest();
if (Dest != nullptr)
ReturnType = Dest->getType();
return getShadowStoreSize<Traits>() +
return getShadowStoreSize() +
getCallStackArgumentsSizeBytes(ArgTypes, ReturnType);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment