Add Subtarget support to PowerPC. Next up, using it.
authorNate Begeman <natebegeman@mac.com>
Thu, 4 Aug 2005 07:12:09 +0000 (07:12 +0000)
committerNate Begeman <natebegeman@mac.com>
Thu, 4 Aug 2005 07:12:09 +0000 (07:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22644 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCSubtarget.cpp [new file with mode: 0644]
lib/Target/PowerPC/PPCSubtarget.h [new file with mode: 0644]
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/PowerPC/PowerPCTargetMachine.h
lib/Target/X86/X86Subtarget.cpp
lib/Target/X86/X86Subtarget.h

diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp
new file mode 100644 (file)
index 0000000..4fae1a2
--- /dev/null
@@ -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 <mach/mach.h>
+#include <mach/mach_host.h>
+#include <mach/host_info.h>
+#include <mach/machine.h>
+
+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 (file)
index 0000000..c114351
--- /dev/null
@@ -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
index e156f5e744fd97fc1299da62393829e0a67a2740..8393a3b3f49567963584a5d195b0c0edf8b68802 100644 (file)
@@ -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)) {}
 
index da8505104d2ee7d6aefe520404c8f63c0954c713..4a92acf6c018344590bea2c387aae0b043d97e8f 100644 (file)
 #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);
index f2ebdd4abec89504dbcce1f6e3f2474e2868cd25..ed8b8712a7ef6f5ebb418fad3d7f53b5e74996e5 100644 (file)
@@ -1,4 +1,4 @@
-//===- X86Subtarget.cpp - X86 Instruction Information -----------*- C++ -*-===//
+//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
index 1e980f800d068bcfd80c9d21613efac844b4f64e..bf764d3a422fd6a3c098ad2c9b14cedc65d9a5ad 100644 (file)
@@ -1,4 +1,4 @@
-//=====-- X86Subtarget.h - Define TargetMachine for the X86 ---*- C++ -*--====//
+//=====---- X86Subtarget.h - Define Subtarget for the X86 -----*- C++ -*--====//
 //
 //                     The LLVM Compiler Infrastructure
 //