Add Subtarget support to PowerPC. Next up, using it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22644 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nate Begeman 2005-08-04 07:12:09 +00:00
parent 49f72e68cf
commit 8c00f8cdc7
6 changed files with 116 additions and 10 deletions

View File

@ -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
}
}

View File

@ -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

View 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)) {}

View File

@ -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);

View File

@ -1,4 +1,4 @@
//===- X86Subtarget.cpp - X86 Instruction Information -----------*- C++ -*-===//
//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//

View 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
//