Skip to content

[Clang][MIPS] Create specific targets for MIPS PE/COFF #121040

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

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::NaCl:
return std::make_unique<NaClTargetInfo<NaClMips32TargetInfo>>(Triple,
Opts);
case llvm::Triple::Win32:
switch (Triple.getEnvironment()) {
case llvm::Triple::GNU:
return std::make_unique<MinGWMipsTargetInfo>(Triple, Opts);
case llvm::Triple::MSVC:
default: // Assume MSVC for unknown environments
return std::make_unique<MicrosoftMipsTargetInfo>(Triple, Opts);
}
default:
return std::make_unique<MipsTargetInfo>(Triple, Opts);
}
Expand Down
59 changes: 59 additions & 0 deletions clang/lib/Basic/Targets/Mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,62 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine &Diags) const {

return true;
}

WindowsMipsTargetInfo::WindowsMipsTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsTargetInfo<MipsTargetInfo>(Triple, Opts), Triple(Triple) {}

void WindowsMipsTargetInfo::getVisualStudioDefines(
const LangOptions &Opts, MacroBuilder &Builder) const {
Builder.defineMacro("_M_MRX000", "4000");
}

TargetInfo::BuiltinVaListKind
WindowsMipsTargetInfo::getBuiltinVaListKind() const {
return TargetInfo::CharPtrBuiltinVaList;
}

TargetInfo::CallingConvCheckResult
WindowsMipsTargetInfo::checkCallingConvention(CallingConv CC) const {
switch (CC) {
case CC_X86StdCall:
case CC_X86ThisCall:
case CC_X86FastCall:
case CC_X86VectorCall:
return CCCR_Ignore;
case CC_C:
case CC_OpenCLKernel:
case CC_PreserveMost:
case CC_PreserveAll:
case CC_Swift:
case CC_SwiftAsync:
return CCCR_OK;
default:
return CCCR_Warning;
}
}

// Windows MIPS, MS (C++) ABI
MicrosoftMipsTargetInfo::MicrosoftMipsTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsMipsTargetInfo(Triple, Opts) {
TheCXXABI.set(TargetCXXABI::Microsoft);
}

void MicrosoftMipsTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
WindowsMipsTargetInfo::getTargetDefines(Opts, Builder);
WindowsMipsTargetInfo::getVisualStudioDefines(Opts, Builder);
}

MinGWMipsTargetInfo::MinGWMipsTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts)
: WindowsMipsTargetInfo(Triple, Opts) {
TheCXXABI.set(TargetCXXABI::GenericMIPS);
}

void MinGWMipsTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
WindowsMipsTargetInfo::getTargetDefines(Opts, Builder);
Builder.defineMacro("_MIPS_");
}
37 changes: 37 additions & 0 deletions clang/lib/Basic/Targets/Mips.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H
#define LLVM_CLANG_LIB_BASIC_TARGETS_MIPS_H

#include "OSTargets.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -450,6 +451,42 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public TargetInfo {
return std::make_pair(32, 32);
}
};

class LLVM_LIBRARY_VISIBILITY WindowsMipsTargetInfo
: public WindowsTargetInfo<MipsTargetInfo> {
const llvm::Triple Triple;

public:
WindowsMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);

void getVisualStudioDefines(const LangOptions &Opts,
MacroBuilder &Builder) const;

BuiltinVaListKind getBuiltinVaListKind() const override;

CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
};

// Windows MIPS, MS (C++) ABI
class LLVM_LIBRARY_VISIBILITY MicrosoftMipsTargetInfo
: public WindowsMipsTargetInfo {
public:
MicrosoftMipsTargetInfo(const llvm::Triple &Triple,
const TargetOptions &Opts);

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
};

// MIPS MinGW target
class LLVM_LIBRARY_VISIBILITY MinGWMipsTargetInfo
: public WindowsMipsTargetInfo {
public:
MinGWMipsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);

void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
};
} // namespace targets
} // namespace clang

Expand Down
16 changes: 16 additions & 0 deletions clang/test/Preprocessor/predefined-win-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@
// CHECK-ARM64EC-WIN: #define _WIN32 1
// CHECK-ARM64EC-WIN: #define _WIN64 1

// RUN: %clang_cc1 -triple mipsel-windows %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-MIPSEL-WIN

// CHECK-MIPSEL-WIN: #define _M_MRX000 4000
// CHECK-MIPSEL-WIN: #define _WIN32 1
// CHECK-MIPSEL-WIN-NOT: #define _MIPS_ 1

// RUN: %clang_cc1 -triple i686-windows-gnu %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-X86-MINGW

Expand Down Expand Up @@ -173,3 +180,12 @@
// CHECK-ARM64EC-MINGW: #define __arm64ec__ 1
// CHECK-ARM64EC-MINGW: #define __x86_64 1
// CHECK-ARM64EC-MINGW: #define __x86_64__ 1

// RUN: %clang_cc1 -triple mipsel-windows-gnu %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-MIPSEL-MINGW

// CHECK-MIPSEL-MINGW-NOT: #define _M_MRX000 4000
// CHECK-MIPSEL-MINGW: #define _MIPS_ 1
// CHECK-MIPSEL-MINGW: #define _WIN32 1
// CHECK-MIPSEL-MINGW: #define __mips 32
// CHECK-MIPSEL-MINGW: #define __mips__ 1
Loading