Skip to content

32 registers instead of 16, and apparent fix to some issue I saw last night. #241

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

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
def TargetAArch64 : TargetArch<["aarch64"]>;
def TargetAnyArm : TargetArch<!listconcat(TargetARM.Arches, TargetAArch64.Arches)>;
def TargetAVR : TargetArch<["avr"]>;
def TargetP2 : TargetArch<["p2"]>;
def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
def TargetMips32 : TargetArch<["mips", "mipsel"]>;
def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ add_clang_library(clangBasic
Targets/Mips.cpp
Targets/NVPTX.cpp
Targets/OSTargets.cpp
Targets/P2.cpp
Targets/PNaCl.cpp
Targets/PPC.cpp
Targets/RISCV.cpp
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Targets/Mips.h"
#include "Targets/NVPTX.h"
#include "Targets/OSTargets.h"
#include "Targets/P2.h"
#include "Targets/PNaCl.h"
#include "Targets/PPC.h"
#include "Targets/RISCV.h"
Expand Down Expand Up @@ -234,6 +235,10 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,

case llvm::Triple::avr:
return new AVRTargetInfo(Triple, Opts);

case llvm::Triple::p2:
return new P2TargetInfo(Triple, Opts);

case llvm::Triple::bpfeb:
case llvm::Triple::bpfel:
return new BPFTargetInfo(Triple, Opts);
Expand Down
36 changes: 36 additions & 0 deletions clang/lib/Basic/Targets/P2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===--- P2.cpp - Implement P2 target feature support -------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements P2 TargetInfo objects.
//
//===----------------------------------------------------------------------===//

#include "P2.h"
#include "clang/Basic/MacroBuilder.h"
#include "llvm/ADT/StringSwitch.h"

using namespace clang;
using namespace clang::targets;

namespace clang {
namespace targets {

} // namespace targets
} // namespace clang

// bool P2TargetInfo::isValidCPUName(StringRef Name) const {

// }

// void P2TargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {

// }

void P2TargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
}
105 changes: 105 additions & 0 deletions clang/lib/Basic/Targets/P2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//===--- P2.h - Declare P2 target feature support -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file declares P2 TargetInfo objects.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_P2_H
#define LLVM_CLANG_LIB_BASIC_TARGETS_P2_H

#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/Compiler.h"

namespace clang {
namespace targets {

// P2 Target
class LLVM_LIBRARY_VISIBILITY P2TargetInfo : public TargetInfo {
public:
P2TargetInfo(const llvm::Triple &Triple, const TargetOptions &)
: TargetInfo(Triple) {
// TLSSupported = false;
// PointerWidth = 16;
// PointerAlign = 8;
// IntWidth = 16;
// IntAlign = 8;
// LongWidth = 32;
// LongAlign = 8;
// LongLongWidth = 64;
// LongLongAlign = 8;
// SuitableAlign = 8;
// DefaultAlignForAttributeAligned = 8;
// HalfWidth = 16;
// HalfAlign = 8;
// FloatWidth = 32;
// FloatAlign = 8;
// DoubleWidth = 32;
// DoubleAlign = 8;
// DoubleFormat = &llvm::APFloat::IEEEsingle();
// LongDoubleWidth = 32;
// LongDoubleAlign = 8;
// LongDoubleFormat = &llvm::APFloat::IEEEsingle();
// SizeType = UnsignedInt;
// PtrDiffType = SignedInt;
// IntPtrType = SignedInt;
// Char16Type = UnsignedInt;
// WIntType = SignedInt;
// Char32Type = UnsignedLong;
// SigAtomicType = SignedChar;
resetDataLayout("e-p:32:32-i32:32");
}

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

ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }

BuiltinVaListKind getBuiltinVaListKind() const override {
return TargetInfo::VoidPtrBuiltinVaList;
}

const char *getClobbers() const override { return ""; }

ArrayRef<const char *> getGCCRegNames() const override {
return None;
}

ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
return None;
}

ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override {
return None;
}

bool validateAsmConstraint(const char *&Name,
TargetInfo::ConstraintInfo &Info) const override {
return true;
}

IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
// P2 prefers int for 32-bit integers.
return TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
}

IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
// P2 uses int for int_least32_t and int_fast32_t.
return TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
}

protected:
std::string CPU;
};

} // namespace targets
} // namespace clang

#endif // LLVM_CLANG_LIB_BASIC_TARGETS_P2_H
24 changes: 24 additions & 0 deletions clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8008,6 +8008,27 @@ class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
};
}

//===----------------------------------------------------------------------===//
// P2 ABI Implementation.
//===----------------------------------------------------------------------===//

namespace {
class P2TargetCodeGenInfo : public TargetCodeGenInfo {
public:
P2TargetCodeGenInfo(CodeGenTypes &CGT)
: TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}

void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &CGM) const override {
if (GV->isDeclaration())
return;
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
if (!FD) return;
auto *Fn = cast<llvm::Function>(GV);
}
};
}

//===----------------------------------------------------------------------===//
// TCE ABI Implementation (see http://tce.cs.tut.fi). Uses mostly the defaults.
// Currently subclassed only to implement custom OpenCL C function attribute
Expand Down Expand Up @@ -10818,6 +10839,9 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
case llvm::Triple::avr:
return SetCGInfo(new AVRTargetCodeGenInfo(Types));

case llvm::Triple::p2:
return SetCGInfo(new P2TargetCodeGenInfo(Types));

case llvm::Triple::aarch64:
case llvm::Triple::aarch64_32:
case llvm::Triple::aarch64_be: {
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ add_clang_library(clangDriver
ToolChains/NaCl.cpp
ToolChains/NetBSD.cpp
ToolChains/OpenBSD.cpp
ToolChains/P2.cpp
ToolChains/PS4CPU.cpp
ToolChains/RISCVToolchain.cpp
ToolChains/Solaris.cpp
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "ToolChains/NaCl.h"
#include "ToolChains/NetBSD.h"
#include "ToolChains/OpenBSD.h"
#include "ToolChains/P2.h"
#include "ToolChains/PPCLinux.h"
#include "ToolChains/PS4CPU.h"
#include "ToolChains/RISCVToolchain.h"
Expand Down Expand Up @@ -5037,6 +5038,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
case llvm::Triple::avr:
TC = std::make_unique<toolchains::AVRToolChain>(*this, Target, Args);
break;
case llvm::Triple::p2:
TC = std::make_unique<toolchains::P2ToolChain>(*this, Target, Args);
break;
case llvm::Triple::msp430:
TC =
std::make_unique<toolchains::MSP430ToolChain>(*this, Target, Args);
Expand Down
55 changes: 55 additions & 0 deletions clang/lib/Driver/ToolChains/P2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===--- P2.cpp - P2 ToolChain Implementations ----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "P2.h"
#include "CommonArgs.h"
#include "InputInfo.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/FileSystem.h"

using namespace clang::driver;
using namespace clang::driver::toolchains;
using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;

/// P2 Toolchain
P2ToolChain::P2ToolChain(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
//GCCInstallation.init(Triple, Args);
}

Tool *P2ToolChain::buildLinker() const {
return new tools::P2::Linker(getTriple(), *this);
}

void P2::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {

// std::string Linker = getToolChain().GetProgramPath(getShortName());
// ArgStringList CmdArgs;
// CmdArgs.push_back("-o");
// CmdArgs.push_back(Output.getFilename());

// C.addCommand(std::make_unique<Command>(JA, *this, Args.MakeArgString(Linker), CmdArgs, Inputs));
}

// llvm::Optional<std::string> P2ToolChain::findP2LibcInstallation() const {
// return llvm::None;
// }
71 changes: 71 additions & 0 deletions clang/lib/Driver/ToolChains/P2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//===--- P2.h - P2 Tool and ToolChain Implementations ---------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_P2_H
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_P2_H

#include "Gnu.h"
#include "InputInfo.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Driver/Tool.h"

namespace clang {
namespace driver {
namespace toolchains {

class LLVM_LIBRARY_VISIBILITY P2ToolChain : public Generic_ELF {
public:
P2ToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
bool IsIntegratedAssemblerDefault() const override { return true; }

protected:
Tool *buildLinker() const override;

private:
};

} // end namespace toolchains

namespace tools {
namespace P2 {

// class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {
// public:
// Assembler(const ToolChain &TC)
// : Tool("solaris::Assembler", "assembler", TC) {}

// bool hasIntegratedCPP() const override { return false; }

// void ConstructJob(Compilation &C, const JobAction &JA,
// const InputInfo &Output, const InputInfoList &Inputs,
// const llvm::opt::ArgList &TCArgs,
// const char *LinkingOutput) const override;
// };

class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
public:
Linker(const llvm::Triple &Triple, const ToolChain &TC)
: Tool("P2::Linker", "P2-ld", TC), Triple(Triple) {}

bool hasIntegratedCPP() const override { return false; }
bool isLinkJob() const override { return true; }
void ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output, const InputInfoList &Inputs,
const llvm::opt::ArgList &TCArgs,
const char *LinkingOutput) const override;

protected:
const llvm::Triple &Triple;
};
} // end namespace P2
} // end namespace tools
} // end namespace driver
} // end namespace clang

#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_P2_H
Loading