diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp new file mode 100644 index 00000000000..4fae1a2d1de --- /dev/null +++ b/lib/Target/PowerPC/PPCSubtarget.cpp @@ -0,0 +1,54 @@ +//===- PowerPCSubtarget.cpp - PPC Subtarget Information ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Nate Begeman and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the PPC specific subclass of TargetSubtarget. +// +//===----------------------------------------------------------------------===// + +#include "PowerPCSubtarget.h" +#include "llvm/Module.h" + +#if defined(__APPLE__) +#include +#include +#include +#include + +static boolean_t IsGP() { + host_basic_info_data_t hostInfo; + mach_msg_type_number_t infoCount; + + infoCount = HOST_BASIC_INFO_COUNT; + host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, + &infoCount); + + return ((hostInfo.cpu_type == CPU_TYPE_POWERPC) && + (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970)); +} +#endif + +using namespace llvm; + +PPCSubtarget::PPCSubtarget(const Module &M) + : TargetSubtarget(), stackAlignment(16), isGigaProcessor(false), isAIX(false), + isDarwin(false) { + // Set the boolean corresponding to the current target triple, or the default + // if one cannot be determined, to true. + const std::string& TT = M.getTargetTriple(); + if (TT.length() > 5) { + isDarwin = TT.find("darwin") != std::string::npos; + } else if (TT.empty()) { +#if defined(_POWER) + isAIX = true; +#elif defined(__APPLE__) + isDarwin = true; + isGigaProcessor = IsGP(); +#endif + } +} diff --git a/lib/Target/PowerPC/PPCSubtarget.h b/lib/Target/PowerPC/PPCSubtarget.h new file mode 100644 index 00000000000..c1143518009 --- /dev/null +++ b/lib/Target/PowerPC/PPCSubtarget.h @@ -0,0 +1,48 @@ +//=====-- PowerPCSubtarget.h - Define Subtarget for the PPC ---*- C++ -*--====// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Nate Begeman and is distributed under the +// University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares the X86 specific subclass of TargetSubtarget. +// +//===----------------------------------------------------------------------===// + +#ifndef POWERPCSUBTARGET_H +#define POWERPCSUBTARGET_H + +#include "llvm/Target/TargetSubtarget.h" + +namespace llvm { +class Module; + +class PPCSubtarget : public TargetSubtarget { +protected: + /// stackAlignment - The minimum alignment known to hold of the stack frame on + /// entry to the function and which must be maintained by every function. + unsigned stackAlignment; + + /// Used by the ISel to turn in optimizations for POWER4-derived architectures + bool isGigaProcessor; + bool isAIX; + bool isDarwin; +public: + /// This constructor initializes the data members to match that + /// of the specified module. + /// + PPCSubtarget(const Module &M); + + /// getStackAlignment - Returns the minimum alignment known to hold of the + /// stack frame on entry to the function and which must be maintained by every + /// function for this subtarget. + unsigned getStackAlignment() const { return stackAlignment; } + + bool IsAIX() const { return isAIX; } + bool IsDarwin() const { return isDarwin; } +}; +} // End llvm namespace + +#endif diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp index e156f5e744f..8393a3b3f49 100644 --- a/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -59,10 +59,10 @@ namespace { PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name, IntrinsicLowering *IL, + const Module &M, const TargetData &TD, const PowerPCFrameInfo &TFI) - : TargetMachine(name, IL, TD), FrameInfo(TFI) -{} +: TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) {} unsigned PPC32TargetMachine::getJITMatchQuality() { #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) @@ -177,14 +177,14 @@ void PowerPCJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { /// PowerPCTargetMachine ctor - Create an ILP32 architecture model /// PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL) - : PowerPCTargetMachine(PPC32ID, IL, + : PowerPCTargetMachine(PPC32ID, IL, M, TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,1), PowerPCFrameInfo(*this, false)), JITInfo(*this) {} /// PPC64TargetMachine ctor - Create a LP64 architecture model /// PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL) - : PowerPCTargetMachine(PPC64ID, IL, + : PowerPCTargetMachine(PPC64ID, IL, M, TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,1), PowerPCFrameInfo(*this, true)) {} diff --git a/lib/Target/PowerPC/PowerPCTargetMachine.h b/lib/Target/PowerPC/PowerPCTargetMachine.h index da8505104d2..4a92acf6c01 100644 --- a/lib/Target/PowerPC/PowerPCTargetMachine.h +++ b/lib/Target/PowerPC/PowerPCTargetMachine.h @@ -14,9 +14,11 @@ #ifndef POWERPC_TARGETMACHINE_H #define POWERPC_TARGETMACHINE_H -#include "PowerPCFrameInfo.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetFrameInfo.h" #include "llvm/PassManager.h" +#include "PowerPCFrameInfo.h" +#include "PowerPCSubtarget.h" namespace llvm { @@ -24,13 +26,15 @@ class GlobalValue; class IntrinsicLowering; class PowerPCTargetMachine : public TargetMachine { - PowerPCFrameInfo FrameInfo; - + PowerPCFrameInfo FrameInfo; + PPCSubtarget Subtarget; protected: PowerPCTargetMachine(const std::string &name, IntrinsicLowering *IL, - const TargetData &TD, const PowerPCFrameInfo &TFI); + const Module &M, const TargetData &TD, + const PowerPCFrameInfo &TFI); public: virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; } + virtual const TargetSubtarget *getSubtargetImpl() const{ return &Subtarget; } virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, CodeGenFileType FileType); diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index f2ebdd4abec..ed8b8712a7e 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -1,4 +1,4 @@ -//===- X86Subtarget.cpp - X86 Instruction Information -----------*- C++ -*-===// +//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // diff --git a/lib/Target/X86/X86Subtarget.h b/lib/Target/X86/X86Subtarget.h index 1e980f800d0..bf764d3a422 100644 --- a/lib/Target/X86/X86Subtarget.h +++ b/lib/Target/X86/X86Subtarget.h @@ -1,4 +1,4 @@ -//=====-- X86Subtarget.h - Define TargetMachine for the X86 ---*- C++ -*--====// +//=====---- X86Subtarget.h - Define Subtarget for the X86 -----*- C++ -*--====// // // The LLVM Compiler Infrastructure //