Skip to content

Commit

Permalink
[PowerPC] [Clang] Port MMX intrinsics and basic test cases to Power
Browse files Browse the repository at this point in the history
Port mmintrin.h which include x86 MMX intrinsics implementation to PowerPC platform (using Altivec).

To make the include process correct, PowerPC's toolchain class is overrided to insert new headers directory (named ppc_wrappers) into the path. Basic test cases for several intrinsic functions are added.

The header is mainly developed by Steven Munroe, with contributions from Paul Clarke, Bill Schmidt, Jinsong Ji and Zixuan Wu.

Reviewed By: Jinsong Ji

Differential Revision: https://reviews.llvm.org/D59924

llvm-svn: 358949
  • Loading branch information
ecnelises committed Apr 23, 2019
1 parent 9da8142 commit 19828e3
Show file tree
Hide file tree
Showing 8 changed files with 1,606 additions and 1 deletion.
1 change: 1 addition & 0 deletions clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ add_clang_library(clangDriver
ToolChains/TCE.cpp
ToolChains/WebAssembly.cpp
ToolChains/XCore.cpp
ToolChains/PPCLinux.cpp
Types.cpp
XRayArgs.cpp

Expand Down
6 changes: 6 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/NetBSD.h"
#include "ToolChains/OpenBSD.h"
#include "ToolChains/PS4CPU.h"
#include "ToolChains/PPCLinux.h"
#include "ToolChains/RISCVToolchain.h"
#include "ToolChains/Solaris.h"
#include "ToolChains/TCE.h"
Expand Down Expand Up @@ -4576,6 +4577,11 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
!Target.hasEnvironment())
TC = llvm::make_unique<toolchains::MipsLLVMToolChain>(*this, Target,
Args);
else if (Target.getArch() == llvm::Triple::ppc ||
Target.getArch() == llvm::Triple::ppc64 ||
Target.getArch() == llvm::Triple::ppc64le)
TC = llvm::make_unique<toolchains::PPCLinuxToolChain>(*this, Target,
Args);
else
TC = llvm::make_unique<toolchains::Linux>(*this, Target, Args);
break;
Expand Down
31 changes: 31 additions & 0 deletions clang/lib/Driver/ToolChains/PPCLinux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===-- PPCLinux.cpp - PowerPC 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 "PPCLinux.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Options.h"
#include "llvm/Support/Path.h"

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

void PPCLinuxToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// PPC wrapper headers are implementation of x86 intrinsics on PowerPC, which
// is not supported on PPC32 platform.
if (getArch() != llvm::Triple::ppc &&
!DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) &&
!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
const Driver &D = getDriver();
SmallString<128> P(D.ResourceDir);
llvm::sys::path::append(P, "include", "ppc_wrappers");
addSystemInclude(DriverArgs, CC1Args, P);
}

Linux::AddClangSystemIncludeArgs(DriverArgs, CC1Args);
}
33 changes: 33 additions & 0 deletions clang/lib/Driver/ToolChains/PPCLinux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===--- PPCLinux.h - PowerPC 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_PPC_LINUX_H
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PPC_LINUX_H

#include "Linux.h"

namespace clang {
namespace driver {
namespace toolchains {

class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux {
public:
PPCLinuxToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args)
: Linux(D, Triple, Args) {}

void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
};

} // end namespace toolchains
} // end namespace driver
} // end namespace clang

#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_PPC_LINUX_H
6 changes: 5 additions & 1 deletion clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ set(cuda_wrapper_files
cuda_wrappers/new
)

set(ppc_wrapper_files
ppc_wrappers/mmintrin.h
)

set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
set(out_files)

Expand All @@ -147,7 +151,7 @@ endfunction(clang_generate_header)


# Copy header files from the source directory to the build directory
foreach( f ${files} ${cuda_wrapper_files} )
foreach( f ${files} ${cuda_wrapper_files} ${ppc_wrapper_files} )
copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
endforeach( f )

Expand Down
Loading

0 comments on commit 19828e3

Please sign in to comment.