- Added MCSubtargetInfo to capture subtarget features and scheduling

itineraries.
- Refactor TargetSubtarget to be based on MCSubtargetInfo.
- Change tablegen generated subtarget info to initialize MCSubtargetInfo
  and hide more details from targets.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134257 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2011-07-01 20:45:01 +00:00
parent eb03c3b228
commit 94214703d9
33 changed files with 402 additions and 102 deletions

View File

@ -0,0 +1,61 @@
//==-- llvm/MC/MCSubtargetInfo.h - Subtarget Information ---------*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file describes the subtarget options of a Target machine.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCSUBTARGET_H
#define LLVM_MC_MCSUBTARGET_H
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/MC/MCInstrItineraries.h"
namespace llvm {
class StringRef;
//===----------------------------------------------------------------------===//
///
/// MCSubtargetInfo - Generic base class for all target subtargets.
///
class MCSubtargetInfo {
const SubtargetFeatureKV *ProcFeatures; // Processor feature list
const SubtargetFeatureKV *ProcDesc; // Processor descriptions
const SubtargetInfoKV *ProcItins; // Scheduling itineraries
const InstrStage *Stages; // Instruction stages
const unsigned *OperandCycles; // Operand cycles
const unsigned *ForwardingPathes; // Forwarding pathes
unsigned NumFeatures; // Number of processor features
unsigned NumProcs; // Number of processors
public:
void InitMCSubtargetInfo(const SubtargetFeatureKV *PF,
const SubtargetFeatureKV *PD,
const SubtargetInfoKV *PI, const InstrStage *IS,
const unsigned *OC, const unsigned *FP,
unsigned NF, unsigned NP) {
ProcFeatures = PF;
ProcDesc = PD;
ProcItins = PI;
Stages = IS;
OperandCycles = OC;
ForwardingPathes = FP;
NumFeatures = NF;
NumProcs = NP;
}
/// getInstrItineraryForCPU - Get scheduling itinerary of a CPU.
///
InstrItineraryData getInstrItineraryForCPU(StringRef CPU) const;
};
} // End llvm namespace
#endif

View File

@ -14,6 +14,7 @@
#ifndef LLVM_TARGET_TARGETSUBTARGET_H #ifndef LLVM_TARGET_TARGETSUBTARGET_H
#define LLVM_TARGET_TARGETSUBTARGET_H #define LLVM_TARGET_TARGETSUBTARGET_H
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
namespace llvm { namespace llvm {
@ -29,7 +30,7 @@ template <typename T> class SmallVectorImpl;
/// Target-specific options that control code generation and printing should /// Target-specific options that control code generation and printing should
/// be exposed through a TargetSubtarget-derived class. /// be exposed through a TargetSubtarget-derived class.
/// ///
class TargetSubtarget { class TargetSubtarget : public MCSubtargetInfo {
TargetSubtarget(const TargetSubtarget&); // DO NOT IMPLEMENT TargetSubtarget(const TargetSubtarget&); // DO NOT IMPLEMENT
void operator=(const TargetSubtarget&); // DO NOT IMPLEMENT void operator=(const TargetSubtarget&); // DO NOT IMPLEMENT
protected: // Can only create subclasses... protected: // Can only create subclasses...

View File

@ -28,6 +28,7 @@ add_llvm_library(LLVMMC
MCSectionELF.cpp MCSectionELF.cpp
MCSectionMachO.cpp MCSectionMachO.cpp
MCStreamer.cpp MCStreamer.cpp
MCSubtargetInfo.cpp
MCSymbol.cpp MCSymbol.cpp
MCValue.cpp MCValue.cpp
MCWin64EH.cpp MCWin64EH.cpp

View File

@ -0,0 +1,44 @@
//===-- MCSubtargetInfo.cpp - Subtarget Information -----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCInstrItineraries.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
InstrItineraryData
MCSubtargetInfo::getInstrItineraryForCPU(StringRef CPU) const {
assert(ProcItins && "Instruction itineraries information not available!");
#ifndef NDEBUG
for (size_t i = 1; i < NumProcs; i++) {
assert(strcmp(ProcItins[i - 1].Key, ProcItins[i].Key) < 0 &&
"Itineraries table is not sorted");
}
#endif
// Find entry
SubtargetInfoKV KV;
KV.Key = CPU.data();
const SubtargetInfoKV *Found =
std::lower_bound(ProcItins, ProcItins+NumProcs, KV);
if (Found == ProcItins+NumProcs || StringRef(Found->Key) != CPU) {
errs() << "'" << CPU
<< "' is not a recognized processor for this target"
<< " (ignoring processor)\n";
return InstrItineraryData();
}
return InstrItineraryData(Stages, OperandCycles, ForwardingPathes,
(InstrItinerary *)Found->Value);
}

View File

@ -12,11 +12,17 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "ARMSubtarget.h" #include "ARMSubtarget.h"
#include "ARMGenSubtarget.inc"
#include "ARMBaseRegisterInfo.h" #include "ARMBaseRegisterInfo.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Target/TargetSubtarget.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "ARMGenSubtarget.inc"
using namespace llvm; using namespace llvm;
static cl::opt<bool> static cl::opt<bool>
@ -32,7 +38,8 @@ StrictAlign("arm-strict-align", cl::Hidden,
ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU, ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS, bool isT) const std::string &FS, bool isT)
: ARMArchVersion(V4) : ARMGenSubtargetInfo()
, ARMArchVersion(V4)
, ARMProcFamily(Others) , ARMProcFamily(Others)
, ARMFPUType(None) , ARMFPUType(None)
, UseNEONForSinglePrecisionFP(false) , UseNEONForSinglePrecisionFP(false)
@ -130,6 +137,9 @@ ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &CPU,
FSWithArch = FSWithArch + "," + FS; FSWithArch = FSWithArch + "," + FS;
ParseSubtargetFeatures(FSWithArch, CPUString); ParseSubtargetFeatures(FSWithArch, CPUString);
// Initialize scheduling itinerary for the specified CPU.
InstrItins = getInstrItineraryForCPU(CPUString);
// After parsing Itineraries, set ItinData.IssueWidth. // After parsing Itineraries, set ItinData.IssueWidth.
computeIssueWidth(); computeIssueWidth();

View File

@ -19,10 +19,13 @@
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "ARMGenSubtarget.inc"
namespace llvm { namespace llvm {
class GlobalValue; class GlobalValue;
class ARMSubtarget : public TargetSubtarget { class ARMSubtarget : public ARMGenSubtargetInfo {
protected: protected:
enum ARMArchEnum { enum ARMArchEnum {
V4, V4T, V5T, V5TE, V6, V6M, V6T2, V7A, V7M V4, V4T, V5T, V5TE, V6, V6M, V6T2, V7A, V7M

View File

@ -14,15 +14,24 @@
#include "AlphaSubtarget.h" #include "AlphaSubtarget.h"
#include "Alpha.h" #include "Alpha.h"
#include "AlphaGenSubtarget.inc" #include "AlphaGenSubtarget.inc"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "AlphaGenSubtarget.inc"
using namespace llvm; using namespace llvm;
AlphaSubtarget::AlphaSubtarget(const std::string &TT, const std::string &CPU, AlphaSubtarget::AlphaSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS) const std::string &FS)
: HasCT(false) { : AlphaGenSubtargetInfo(), HasCT(false) {
std::string CPUName = CPU; std::string CPUName = CPU;
if (CPUName.empty()) if (CPUName.empty())
CPUName = "generic"; CPUName = "generic";
// Parse features string. // Parse features string.
ParseSubtargetFeatures(FS, CPUName); ParseSubtargetFeatures(FS, CPUName);
// Initialize scheduling itinerary for the specified CPU.
InstrItins = getInstrItineraryForCPU(CPUName);
} }

View File

@ -18,9 +18,12 @@
#include "llvm/MC/MCInstrItineraries.h" #include "llvm/MC/MCInstrItineraries.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "AlphaGenSubtarget.inc"
namespace llvm { namespace llvm {
class AlphaSubtarget : public TargetSubtarget { class AlphaSubtarget : public AlphaGenSubtargetInfo {
protected: protected:
bool HasCT; bool HasCT;

View File

@ -12,6 +12,10 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "BlackfinSubtarget.h" #include "BlackfinSubtarget.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "BlackfinGenSubtarget.inc" #include "BlackfinGenSubtarget.inc"
using namespace llvm; using namespace llvm;
@ -19,7 +23,7 @@ using namespace llvm;
BlackfinSubtarget::BlackfinSubtarget(const std::string &TT, BlackfinSubtarget::BlackfinSubtarget(const std::string &TT,
const std::string &CPU, const std::string &CPU,
const std::string &FS) const std::string &FS)
: sdram(false), : BlackfinGenSubtargetInfo(), sdram(false),
icplb(false), icplb(false),
wa_mi_shift(false), wa_mi_shift(false),
wa_csync(false), wa_csync(false),

View File

@ -17,9 +17,12 @@
#include "llvm/Target/TargetSubtarget.h" #include "llvm/Target/TargetSubtarget.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "BlackfinGenSubtarget.inc"
namespace llvm { namespace llvm {
class BlackfinSubtarget : public TargetSubtarget { class BlackfinSubtarget : public BlackfinGenSubtargetInfo {
bool sdram; bool sdram;
bool icplb; bool icplb;
bool wa_mi_shift; bool wa_mi_shift;

View File

@ -13,14 +13,19 @@
#include "SPUSubtarget.h" #include "SPUSubtarget.h"
#include "SPU.h" #include "SPU.h"
#include "SPUGenSubtarget.inc"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "SPURegisterInfo.h" #include "SPURegisterInfo.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "SPUGenSubtarget.inc"
using namespace llvm; using namespace llvm;
SPUSubtarget::SPUSubtarget(const std::string &TT, const std::string &CPU, SPUSubtarget::SPUSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS) : const std::string &FS) :
SPUGenSubtargetInfo(),
StackAlignment(16), StackAlignment(16),
ProcDirective(SPU::DEFAULT_PROC), ProcDirective(SPU::DEFAULT_PROC),
UseLargeMem(false) UseLargeMem(false)
@ -31,6 +36,9 @@ SPUSubtarget::SPUSubtarget(const std::string &TT, const std::string &CPU,
// Parse features string. // Parse features string.
ParseSubtargetFeatures(FS, default_cpu); ParseSubtargetFeatures(FS, default_cpu);
// Initialize scheduling itinerary for the specified CPU.
InstrItins = getInstrItineraryForCPU(default_cpu);
} }
/// SetJITMode - This is called to inform the subtarget info that we are /// SetJITMode - This is called to inform the subtarget info that we are

View File

@ -18,6 +18,9 @@
#include "llvm/MC/MCInstrItineraries.h" #include "llvm/MC/MCInstrItineraries.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "SPUGenSubtarget.inc"
namespace llvm { namespace llvm {
class GlobalValue; class GlobalValue;
@ -28,7 +31,7 @@ namespace llvm {
}; };
} }
class SPUSubtarget : public TargetSubtarget { class SPUSubtarget : public SPUGenSubtargetInfo {
protected: protected:
/// stackAlignment - The minimum alignment known to hold of the stack frame /// stackAlignment - The minimum alignment known to hold of the stack frame
/// on entry to the function and which must be maintained by every function. /// on entry to the function and which must be maintained by every function.

View File

@ -14,13 +14,19 @@
#include "MBlazeSubtarget.h" #include "MBlazeSubtarget.h"
#include "MBlaze.h" #include "MBlaze.h"
#include "MBlazeRegisterInfo.h" #include "MBlazeRegisterInfo.h"
#include "MBlazeGenSubtarget.inc"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "MBlazeGenSubtarget.inc"
using namespace llvm; using namespace llvm;
MBlazeSubtarget::MBlazeSubtarget(const std::string &TT, MBlazeSubtarget::MBlazeSubtarget(const std::string &TT,
const std::string &CPU, const std::string &CPU,
const std::string &FS): const std::string &FS):
MBlazeGenSubtargetInfo(),
HasBarrel(false), HasDiv(false), HasMul(false), HasPatCmp(false), HasBarrel(false), HasDiv(false), HasMul(false), HasPatCmp(false),
HasFPU(false), HasMul64(false), HasSqrt(false) HasFPU(false), HasMul64(false), HasSqrt(false)
{ {
@ -35,6 +41,9 @@ MBlazeSubtarget::MBlazeSubtarget(const std::string &TT,
HasItin = CPUName != "mblaze"; HasItin = CPUName != "mblaze";
DEBUG(dbgs() << "CPU " << CPUName << "(" << HasItin << ")\n"); DEBUG(dbgs() << "CPU " << CPUName << "(" << HasItin << ")\n");
// Initialize scheduling itinerary for the specified CPU.
InstrItins = getInstrItineraryForCPU(CPUName);
// Compute the issue width of the MBlaze itineraries // Compute the issue width of the MBlaze itineraries
computeIssueWidth(); computeIssueWidth();
} }

View File

@ -18,9 +18,12 @@
#include "llvm/MC/MCInstrItineraries.h" #include "llvm/MC/MCInstrItineraries.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "MBlazeGenSubtarget.inc"
namespace llvm { namespace llvm {
class MBlazeSubtarget : public TargetSubtarget { class MBlazeSubtarget : public MBlazeGenSubtargetInfo {
protected: protected:
bool HasBarrel; bool HasBarrel;

View File

@ -13,6 +13,10 @@
#include "MSP430Subtarget.h" #include "MSP430Subtarget.h"
#include "MSP430.h" #include "MSP430.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "MSP430GenSubtarget.inc" #include "MSP430GenSubtarget.inc"
using namespace llvm; using namespace llvm;

View File

@ -16,11 +16,14 @@
#include "llvm/Target/TargetSubtarget.h" #include "llvm/Target/TargetSubtarget.h"
#define GET_SUBTARGETINFO_HEADER
#include "MSP430GenSubtarget.inc"
#include <string> #include <string>
namespace llvm { namespace llvm {
class MSP430Subtarget : public TargetSubtarget { class MSP430Subtarget : public MSP430GenSubtargetInfo {
bool ExtendedInsts; bool ExtendedInsts;
public: public:
/// This constructor initializes the data members to match that /// This constructor initializes the data members to match that

View File

@ -13,11 +13,17 @@
#include "MipsSubtarget.h" #include "MipsSubtarget.h"
#include "Mips.h" #include "Mips.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "MipsGenSubtarget.inc" #include "MipsGenSubtarget.inc"
using namespace llvm; using namespace llvm;
MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU, MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS, bool little) : const std::string &FS, bool little) :
MipsGenSubtargetInfo(),
MipsArchVersion(Mips1), MipsABI(O32), IsLittle(little), IsSingleFloat(false), MipsArchVersion(Mips1), MipsABI(O32), IsLittle(little), IsSingleFloat(false),
IsFP64bit(false), IsGP64bit(false), HasVFPU(false), IsLinux(true), IsFP64bit(false), IsGP64bit(false), HasVFPU(false), IsLinux(true),
HasSEInReg(false), HasCondMov(false), HasMulDivAdd(false), HasMinMax(false), HasSEInReg(false), HasCondMov(false), HasMulDivAdd(false), HasMinMax(false),
@ -31,6 +37,9 @@ MipsSubtarget::MipsSubtarget(const std::string &TT, const std::string &CPU,
// Parse features string. // Parse features string.
ParseSubtargetFeatures(FS, CPUName); ParseSubtargetFeatures(FS, CPUName);
// Initialize scheduling itinerary for the specified CPU.
InstrItins = getInstrItineraryForCPU(CPUName);
// Is the target system Linux ? // Is the target system Linux ?
if (TT.find("linux") == std::string::npos) if (TT.find("linux") == std::string::npos)
IsLinux = false; IsLinux = false;

View File

@ -18,9 +18,12 @@
#include "llvm/MC/MCInstrItineraries.h" #include "llvm/MC/MCInstrItineraries.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "MipsGenSubtarget.inc"
namespace llvm { namespace llvm {
class MipsSubtarget : public TargetSubtarget { class MipsSubtarget : public MipsGenSubtargetInfo {
public: public:
enum MipsABIEnum { enum MipsABIEnum {

View File

@ -14,11 +14,17 @@
#include "PTXSubtarget.h" #include "PTXSubtarget.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "PTXGenSubtarget.inc"
using namespace llvm; using namespace llvm;
PTXSubtarget::PTXSubtarget(const std::string &TT, const std::string &CPU, PTXSubtarget::PTXSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS, bool is64Bit) const std::string &FS, bool is64Bit)
: PTXTarget(PTX_COMPUTE_1_0), : PTXGenSubtargetInfo(),
PTXTarget(PTX_COMPUTE_1_0),
PTXVersion(PTX_VERSION_2_0), PTXVersion(PTX_VERSION_2_0),
SupportsDouble(false), SupportsDouble(false),
SupportsFMA(true), SupportsFMA(true),

View File

@ -16,8 +16,11 @@
#include "llvm/Target/TargetSubtarget.h" #include "llvm/Target/TargetSubtarget.h"
#define GET_SUBTARGETINFO_HEADER
#include "PTXGenSubtarget.inc"
namespace llvm { namespace llvm {
class PTXSubtarget : public TargetSubtarget { class PTXSubtarget : public PTXGenSubtargetInfo {
public: public:
/** /**

View File

@ -15,8 +15,13 @@
#include "PPC.h" #include "PPC.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "PPCGenSubtarget.inc"
#include <cstdlib> #include <cstdlib>
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "PPCGenSubtarget.inc"
using namespace llvm; using namespace llvm;
#if defined(__APPLE__) #if defined(__APPLE__)
@ -59,7 +64,8 @@ static const char *GetCurrentPowerPCCPU() {
PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU, PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS, bool is64Bit) const std::string &FS, bool is64Bit)
: StackAlignment(16) : PPCGenSubtargetInfo()
, StackAlignment(16)
, DarwinDirective(PPC::DIR_NONE) , DarwinDirective(PPC::DIR_NONE)
, IsGigaProcessor(false) , IsGigaProcessor(false)
, Has64BitSupport(false) , Has64BitSupport(false)
@ -84,6 +90,9 @@ PPCSubtarget::PPCSubtarget(const std::string &TT, const std::string &CPU,
// Parse features string. // Parse features string.
ParseSubtargetFeatures(FS, CPUName); ParseSubtargetFeatures(FS, CPUName);
// Initialize scheduling itinerary for the specified CPU.
InstrItins = getInstrItineraryForCPU(CPUName);
// If we are generating code for ppc64, verify that options make sense. // If we are generating code for ppc64, verify that options make sense.
if (is64Bit) { if (is64Bit) {
Has64BitSupport = true; Has64BitSupport = true;

View File

@ -19,6 +19,9 @@
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "PPCGenSubtarget.inc"
// GCC #defines PPC on Linux but we use it as our namespace name // GCC #defines PPC on Linux but we use it as our namespace name
#undef PPC #undef PPC
@ -42,7 +45,7 @@ namespace PPC {
class GlobalValue; class GlobalValue;
class TargetMachine; class TargetMachine;
class PPCSubtarget : public TargetSubtarget { class PPCSubtarget : public PPCGenSubtargetInfo {
protected: protected:
/// stackAlignment - The minimum alignment known to hold of the stack frame on /// stackAlignment - The minimum alignment known to hold of the stack frame on
/// entry to the function and which must be maintained by every function. /// entry to the function and which must be maintained by every function.

View File

@ -12,11 +12,17 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "SparcSubtarget.h" #include "SparcSubtarget.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "SparcGenSubtarget.inc" #include "SparcGenSubtarget.inc"
using namespace llvm; using namespace llvm;
SparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU, SparcSubtarget::SparcSubtarget(const std::string &TT, const std::string &CPU,
const std::string &FS, bool is64Bit) : const std::string &FS, bool is64Bit) :
SparcGenSubtargetInfo(),
IsV9(false), IsV9(false),
V8DeprecatedInsts(false), V8DeprecatedInsts(false),
IsVIS(false), IsVIS(false),

View File

@ -17,9 +17,12 @@
#include "llvm/Target/TargetSubtarget.h" #include "llvm/Target/TargetSubtarget.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "SparcGenSubtarget.inc"
namespace llvm { namespace llvm {
class SparcSubtarget : public TargetSubtarget { class SparcSubtarget : public SparcGenSubtargetInfo {
bool IsV9; bool IsV9;
bool V8DeprecatedInsts; bool V8DeprecatedInsts;
bool IsVIS; bool IsVIS;

View File

@ -13,16 +13,20 @@
#include "SystemZSubtarget.h" #include "SystemZSubtarget.h"
#include "SystemZ.h" #include "SystemZ.h"
#include "SystemZGenSubtarget.inc"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "SystemZGenSubtarget.inc"
using namespace llvm; using namespace llvm;
SystemZSubtarget::SystemZSubtarget(const std::string &TT, SystemZSubtarget::SystemZSubtarget(const std::string &TT,
const std::string &CPU, const std::string &CPU,
const std::string &FS): const std::string &FS):
HasZ10Insts(false) { SystemZGenSubtargetInfo(), HasZ10Insts(false) {
std::string CPUName = CPU; std::string CPUName = CPU;
if (CPUName.empty()) if (CPUName.empty())
CPUName = "z9"; CPUName = "z9";

View File

@ -15,14 +15,16 @@
#define LLVM_TARGET_SystemZ_SUBTARGET_H #define LLVM_TARGET_SystemZ_SUBTARGET_H
#include "llvm/Target/TargetSubtarget.h" #include "llvm/Target/TargetSubtarget.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "SystemZGenSubtarget.inc"
namespace llvm { namespace llvm {
class GlobalValue; class GlobalValue;
class TargetMachine; class TargetMachine;
class SystemZSubtarget : public TargetSubtarget { class SystemZSubtarget : public SystemZGenSubtargetInfo {
bool HasZ10Insts; bool HasZ10Insts;
public: public:
/// This constructor initializes the data members to match that /// This constructor initializes the data members to match that

View File

@ -14,13 +14,18 @@
#define DEBUG_TYPE "subtarget" #define DEBUG_TYPE "subtarget"
#include "X86Subtarget.h" #include "X86Subtarget.h"
#include "X86InstrInfo.h" #include "X86InstrInfo.h"
#include "X86GenSubtarget.inc"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Host.h" #include "llvm/Support/Host.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "X86GenSubtarget.inc"
using namespace llvm; using namespace llvm;
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -287,7 +292,8 @@ void X86Subtarget::AutoDetectSubtargetFeatures() {
X86Subtarget::X86Subtarget(const std::string &TT, const std::string &CPU, X86Subtarget::X86Subtarget(const std::string &TT, const std::string &CPU,
const std::string &FS, const std::string &FS,
bool is64Bit, unsigned StackAlignOverride) bool is64Bit, unsigned StackAlignOverride)
: PICStyle(PICStyles::None) : X86GenSubtargetInfo()
, PICStyle(PICStyles::None)
, X86SSELevel(NoMMXSSE) , X86SSELevel(NoMMXSSE)
, X863DNowLevel(NoThreeDNow) , X863DNowLevel(NoThreeDNow)
, HasCMov(false) , HasCMov(false)

View File

@ -19,6 +19,9 @@
#include "llvm/CallingConv.h" #include "llvm/CallingConv.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "X86GenSubtarget.inc"
namespace llvm { namespace llvm {
class GlobalValue; class GlobalValue;
class TargetMachine; class TargetMachine;
@ -35,7 +38,7 @@ enum Style {
}; };
} }
class X86Subtarget : public TargetSubtarget { class X86Subtarget : public X86GenSubtargetInfo {
protected: protected:
enum X86SSEEnum { enum X86SSEEnum {
NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42

View File

@ -13,9 +13,16 @@
#include "XCoreSubtarget.h" #include "XCoreSubtarget.h"
#include "XCore.h" #include "XCore.h"
#define GET_SUBTARGETINFO_CTOR
#define GET_SUBTARGETINFO_MC_DESC
#define GET_SUBTARGETINFO_TARGET_DESC
#include "XCoreGenSubtarget.inc"
using namespace llvm; using namespace llvm;
XCoreSubtarget::XCoreSubtarget(const std::string &TT, XCoreSubtarget::XCoreSubtarget(const std::string &TT,
const std::string &CPU, const std::string &FS) const std::string &CPU, const std::string &FS)
: XCoreGenSubtargetInfo()
{ {
} }

View File

@ -16,12 +16,14 @@
#include "llvm/Target/TargetSubtarget.h" #include "llvm/Target/TargetSubtarget.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
#include <string> #include <string>
#define GET_SUBTARGETINFO_HEADER
#include "XCoreGenSubtarget.inc"
namespace llvm { namespace llvm {
class XCoreSubtarget : public TargetSubtarget { class XCoreSubtarget : public XCoreGenSubtargetInfo {
public: public:
/// This constructor initializes the data members to match that /// This constructor initializes the data members to match that

View File

@ -223,7 +223,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OS << "#undef GET_INSTRINFO_HEADER\n"; OS << "#undef GET_INSTRINFO_HEADER\n";
std::string ClassName = TargetName + "GenInstrInfo"; std::string ClassName = TargetName + "GenInstrInfo";
OS << "namespace llvm {\n\n"; OS << "namespace llvm {\n";
OS << "struct " << ClassName << " : public TargetInstrInfoImpl {\n" OS << "struct " << ClassName << " : public TargetInstrInfoImpl {\n"
<< " explicit " << ClassName << "(int SO = -1, int DO = -1);\n" << " explicit " << ClassName << "(int SO = -1, int DO = -1);\n"
<< "};\n"; << "};\n";
@ -234,7 +234,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OS << "\n#ifdef GET_INSTRINFO_CTOR\n"; OS << "\n#ifdef GET_INSTRINFO_CTOR\n";
OS << "#undef GET_INSTRINFO_CTOR\n"; OS << "#undef GET_INSTRINFO_CTOR\n";
OS << "namespace llvm {\n\n"; OS << "namespace llvm {\n";
OS << ClassName << "::" << ClassName << "(int SO, int DO)\n" OS << ClassName << "::" << ClassName << "(int SO, int DO)\n"
<< " : TargetInstrInfoImpl(SO, DO) {\n" << " : TargetInstrInfoImpl(SO, DO) {\n"
<< " InitMCInstrInfo(" << TargetName << "Insts, " << " InitMCInstrInfo(" << TargetName << "Insts, "

View File

@ -29,16 +29,20 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS,
std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName); std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName);
std::sort(DefList.begin(), DefList.end(), LessRecord()); std::sort(DefList.begin(), DefList.end(), LessRecord());
// Open enumeration
OS << "enum {\n";
// For each record
unsigned N = DefList.size(); unsigned N = DefList.size();
if (N == 0)
return;
if (N > 64) { if (N > 64) {
errs() << "Too many (> 64) subtarget features!\n"; errs() << "Too many (> 64) subtarget features!\n";
exit(1); exit(1);
} }
OS << "namespace " << Target << " {\n";
// Open enumeration
OS << "enum {\n";
// For each record
for (unsigned i = 0; i < N;) { for (unsigned i = 0; i < N;) {
// Next record // Next record
Record *Def = DefList[i]; Record *Def = DefList[i];
@ -57,23 +61,31 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS,
// Close enumeration // Close enumeration
OS << "};\n"; OS << "};\n";
OS << "}\n";
} }
// //
// FeatureKeyValues - Emit data of all the subtarget features. Used by the // FeatureKeyValues - Emit data of all the subtarget features. Used by the
// command line. // command line.
// //
void SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) { unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
// Gather and sort all the features // Gather and sort all the features
std::vector<Record*> FeatureList = std::vector<Record*> FeatureList =
Records.getAllDerivedDefinitions("SubtargetFeature"); Records.getAllDerivedDefinitions("SubtargetFeature");
if (FeatureList.empty())
return 0;
std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName()); std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
// Begin feature table // Begin feature table
OS << "// Sorted (by key) array of values for CPU features.\n" OS << "// Sorted (by key) array of values for CPU features.\n"
<< "static const llvm::SubtargetFeatureKV FeatureKV[] = {\n"; << "static const llvm::SubtargetFeatureKV "
<< Target << "FeatureKV[] = {\n";
// For each feature // For each feature
unsigned NumFeatures = 0;
for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) { for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
// Next feature // Next feature
Record *Feature = FeatureList[i]; Record *Feature = FeatureList[i];
@ -88,7 +100,7 @@ void SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
OS << " { " OS << " { "
<< "\"" << CommandLineName << "\", " << "\"" << CommandLineName << "\", "
<< "\"" << Desc << "\", " << "\"" << Desc << "\", "
<< Name << ", "; << Target << "::" << Name << ", ";
const std::vector<Record*> &ImpliesList = const std::vector<Record*> &ImpliesList =
Feature->getValueAsListOfDefs("Implies"); Feature->getValueAsListOfDefs("Implies");
@ -97,12 +109,13 @@ void SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
OS << "0ULL"; OS << "0ULL";
} else { } else {
for (unsigned j = 0, M = ImpliesList.size(); j < M;) { for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
OS << ImpliesList[j]->getName(); OS << Target << "::" << ImpliesList[j]->getName();
if (++j < M) OS << " | "; if (++j < M) OS << " | ";
} }
} }
OS << " }"; OS << " }";
++NumFeatures;
// Depending on 'if more in the list' emit comma // Depending on 'if more in the list' emit comma
if ((i + 1) < N) OS << ","; if ((i + 1) < N) OS << ",";
@ -113,17 +126,14 @@ void SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
// End feature table // End feature table
OS << "};\n"; OS << "};\n";
// Emit size of table return NumFeatures;
OS<<"\nenum {\n";
OS<<" FeatureKVSize = sizeof(FeatureKV)/sizeof(llvm::SubtargetFeatureKV)\n";
OS<<"};\n";
} }
// //
// CPUKeyValues - Emit data of all the subtarget processors. Used by command // CPUKeyValues - Emit data of all the subtarget processors. Used by command
// line. // line.
// //
void SubtargetEmitter::CPUKeyValues(raw_ostream &OS) { unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
// Gather and sort processor information // Gather and sort processor information
std::vector<Record*> ProcessorList = std::vector<Record*> ProcessorList =
Records.getAllDerivedDefinitions("Processor"); Records.getAllDerivedDefinitions("Processor");
@ -131,7 +141,8 @@ void SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
// Begin processor table // Begin processor table
OS << "// Sorted (by key) array of values for CPU subtype.\n" OS << "// Sorted (by key) array of values for CPU subtype.\n"
<< "static const llvm::SubtargetFeatureKV SubTypeKV[] = {\n"; << "static const llvm::SubtargetFeatureKV "
<< Target << "SubTypeKV[] = {\n";
// For each processor // For each processor
for (unsigned i = 0, N = ProcessorList.size(); i < N;) { for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
@ -151,7 +162,7 @@ void SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
OS << "0ULL"; OS << "0ULL";
} else { } else {
for (unsigned j = 0, M = FeatureList.size(); j < M;) { for (unsigned j = 0, M = FeatureList.size(); j < M;) {
OS << FeatureList[j]->getName(); OS << Target << "::" << FeatureList[j]->getName();
if (++j < M) OS << " | "; if (++j < M) OS << " | ";
} }
} }
@ -168,10 +179,7 @@ void SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
// End processor table // End processor table
OS << "};\n"; OS << "};\n";
// Emit size of table return ProcessorList.size();
OS<<"\nenum {\n";
OS<<" SubTypeKVSize = sizeof(SubTypeKV)/sizeof(llvm::SubtargetFeatureKV)\n";
OS<<"};\n";
} }
// //
@ -192,11 +200,6 @@ CollectAllItinClasses(raw_ostream &OS,
ItinClassesMap[ItinClass->getName()] = i; ItinClassesMap[ItinClass->getName()] = i;
} }
// Emit size of table
OS<<"\nenum {\n";
OS<<" ItinClassesSize = " << N << "\n";
OS<<"};\n";
// Return itinerary class count // Return itinerary class count
return N; return N;
} }
@ -336,15 +339,18 @@ void SubtargetEmitter::EmitStageAndOperandCycleData(raw_ostream &OS,
} }
// Begin stages table // Begin stages table
std::string StageTable = "\nstatic const llvm::InstrStage Stages[] = {\n"; std::string StageTable = "\nstatic const llvm::InstrStage " + Target +
"Stages[] = {\n";
StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n"; StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n";
// Begin operand cycle table // Begin operand cycle table
std::string OperandCycleTable = "static const unsigned OperandCycles[] = {\n"; std::string OperandCycleTable = "static const unsigned " + Target +
"OperandCycles[] = {\n";
OperandCycleTable += " 0, // No itinerary\n"; OperandCycleTable += " 0, // No itinerary\n";
// Begin pipeline bypass table // Begin pipeline bypass table
std::string BypassTable = "static const unsigned ForwardingPathes[] = {\n"; std::string BypassTable = "static const unsigned " + Target +
"ForwardingPathes[] = {\n";
BypassTable += " 0, // No itinerary\n"; BypassTable += " 0, // No itinerary\n";
unsigned StageCount = 1, OperandCycleCount = 1; unsigned StageCount = 1, OperandCycleCount = 1;
@ -457,12 +463,6 @@ void SubtargetEmitter::EmitStageAndOperandCycleData(raw_ostream &OS,
OS << StageTable; OS << StageTable;
OS << OperandCycleTable; OS << OperandCycleTable;
OS << BypassTable; OS << BypassTable;
// Emit size of tables
OS<<"\nenum {\n";
OS<<" StagesSize = sizeof(Stages)/sizeof(llvm::InstrStage),\n";
OS<<" OperandCyclesSize = sizeof(OperandCycles)/sizeof(unsigned)\n";
OS<<"};\n";
} }
// //
@ -533,7 +533,8 @@ void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
// Begin processor table // Begin processor table
OS << "\n"; OS << "\n";
OS << "// Sorted (by key) array of itineraries for CPU subtype.\n" OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
<< "static const llvm::SubtargetInfoKV ProcItinKV[] = {\n"; << "static const llvm::SubtargetInfoKV "
<< Target << "ProcItinKV[] = {\n";
// For each processor // For each processor
for (unsigned i = 0, N = ProcessorList.size(); i < N;) { for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
@ -559,12 +560,6 @@ void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
// End processor table // End processor table
OS << "};\n"; OS << "};\n";
// Emit size of table
OS<<"\nenum {\n";
OS<<" ProcItinKVSize = sizeof(ProcItinKV)/"
"sizeof(llvm::SubtargetInfoKV)\n";
OS<<"};\n";
} }
// //
@ -599,7 +594,9 @@ void SubtargetEmitter::EmitData(raw_ostream &OS) {
// ParseFeaturesFunction - Produces a subtarget specific function for parsing // ParseFeaturesFunction - Produces a subtarget specific function for parsing
// the subtarget features string. // the subtarget features string.
// //
void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS) { void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS,
unsigned NumFeatures,
unsigned NumProcs) {
std::vector<Record*> Features = std::vector<Record*> Features =
Records.getAllDerivedDefinitions("SubtargetFeature"); Records.getAllDerivedDefinitions("SubtargetFeature");
std::sort(Features.begin(), Features.end(), LessRecord()); std::sort(Features.begin(), Features.end(), LessRecord());
@ -611,11 +608,18 @@ void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS) {
OS << "Subtarget::ParseSubtargetFeatures(const std::string &FS,\n" OS << "Subtarget::ParseSubtargetFeatures(const std::string &FS,\n"
<< " const std::string &CPU) {\n" << " const std::string &CPU) {\n"
<< " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n" << " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n"
<< " DEBUG(dbgs() << \"\\nCPU:\" << CPU);\n" << " DEBUG(dbgs() << \"\\nCPU:\" << CPU);\n";
<< " SubtargetFeatures Features(FS);\n"
if (Features.empty()) {
OS << "}\n";
return;
}
OS << " SubtargetFeatures Features(FS);\n"
<< " uint64_t Bits = Features.getFeatureBits(CPU, " << " uint64_t Bits = Features.getFeatureBits(CPU, "
<< "SubTypeKV, SubTypeKVSize,\n" << Target << "SubTypeKV, " << NumProcs << ",\n"
<< " FeatureKV, FeatureKVSize);\n"; << " " << Target << "FeatureKV, "
<< NumFeatures << ");\n";
for (unsigned i = 0; i < Features.size(); i++) { for (unsigned i = 0; i < Features.size(); i++) {
// Next record // Next record
@ -625,20 +629,12 @@ void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS) {
const std::string &Attribute = R->getValueAsString("Attribute"); const std::string &Attribute = R->getValueAsString("Attribute");
if (Value=="true" || Value=="false") if (Value=="true" || Value=="false")
OS << " if ((Bits & " << Instance << ") != 0) " OS << " if ((Bits & " << Target << "::" << Instance << ") != 0) "
<< Attribute << " = " << Value << ";\n"; << Attribute << " = " << Value << ";\n";
else else
OS << " if ((Bits & " << Instance << ") != 0 && " << Attribute << OS << " if ((Bits & " << Target << "::" << Instance << ") != 0 && "
" < " << Value << ") " << Attribute << " = " << Value << ";\n"; << Attribute << " < " << Value << ") "
} << Attribute << " = " << Value << ";\n";
if (HasItineraries) {
OS << "\n"
<< " InstrItinerary *Itinerary = (InstrItinerary *)"
<< "Features.getItinerary(CPU, "
<< "ProcItinKV, ProcItinKVSize);\n"
<< " InstrItins = InstrItineraryData(Stages, OperandCycles, "
<< "ForwardingPathes, Itinerary);\n";
} }
OS << "}\n"; OS << "}\n";
@ -652,22 +648,90 @@ void SubtargetEmitter::run(raw_ostream &OS) {
EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS); EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
OS << "#include \"llvm/Support/Debug.h\"\n"; OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n";
OS << "#include \"llvm/Support/raw_ostream.h\"\n"; OS << "#undef GET_SUBTARGETINFO_MC_DESC\n";
OS << "#include \"llvm/MC/SubtargetFeature.h\"\n";
OS << "#include \"llvm/MC/MCInstrItineraries.h\"\n\n";
// Enumeration(OS, "FuncUnit", true); OS << "namespace llvm {\n";
// OS<<"\n";
// Enumeration(OS, "InstrItinClass", false);
// OS<<"\n";
Enumeration(OS, "SubtargetFeature", true); Enumeration(OS, "SubtargetFeature", true);
OS<<"\n"; OS<<"\n";
FeatureKeyValues(OS); unsigned NumFeatures = FeatureKeyValues(OS);
OS<<"\n"; OS<<"\n";
CPUKeyValues(OS); unsigned NumProcs = CPUKeyValues(OS);
OS<<"\n"; OS<<"\n";
EmitData(OS); EmitData(OS);
OS<<"\n"; OS<<"\n";
ParseFeaturesFunction(OS);
// MCInstrInfo initialization routine.
OS << "static inline void Init" << Target
<< "MCSubtargetInfo(MCSubtargetInfo *II) {\n";
OS << " II->InitMCSubtargetInfo(";
if (NumFeatures)
OS << Target << "FeatureKV, ";
else
OS << "0, ";
if (NumProcs)
OS << Target << "SubTypeKV, ";
else
OS << "0, ";
if (HasItineraries) {
OS << Target << "ProcItinKV, "
<< Target << "Stages, "
<< Target << "OperandCycles, "
<< Target << "ForwardingPathes, ";
} else
OS << "0, 0, 0, 0, ";
OS << NumFeatures << ", " << NumProcs << ");\n}\n\n";
OS << "} // End llvm namespace \n";
OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n";
OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n";
OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n";
OS << "#include \"llvm/Support/Debug.h\"\n";
OS << "#include \"llvm/Support/raw_ostream.h\"\n";
ParseFeaturesFunction(OS, NumFeatures, NumProcs);
OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n";
// Create a TargetSubtarget subclass to hide the MC layer initialization.
OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n";
OS << "#undef GET_SUBTARGETINFO_HEADER\n";
std::string ClassName = Target + "GenSubtargetInfo";
OS << "namespace llvm {\n";
OS << "struct " << ClassName << " : public TargetSubtarget {\n"
<< " explicit " << ClassName << "();\n"
<< "};\n";
OS << "} // End llvm namespace \n";
OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n";
OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n";
OS << "#undef GET_SUBTARGETINFO_CTOR\n";
OS << "namespace llvm {\n";
OS << ClassName << "::" << ClassName << "()\n"
<< " : TargetSubtarget() {\n"
<< " InitMCSubtargetInfo(";
if (NumFeatures)
OS << Target << "FeatureKV, ";
else
OS << "0, ";
if (NumProcs)
OS << Target << "SubTypeKV, ";
else
OS << "0, ";
if (HasItineraries) {
OS << Target << "ProcItinKV, "
<< Target << "Stages, "
<< Target << "OperandCycles, "
<< Target << "ForwardingPathes, ";
} else
OS << "0, 0, 0, 0, ";
OS << NumFeatures << ", " << NumProcs << ");\n}\n\n";
OS << "} // End llvm namespace \n";
OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n";
} }

View File

@ -30,8 +30,8 @@ class SubtargetEmitter : public TableGenBackend {
bool HasItineraries; bool HasItineraries;
void Enumeration(raw_ostream &OS, const char *ClassName, bool isBits); void Enumeration(raw_ostream &OS, const char *ClassName, bool isBits);
void FeatureKeyValues(raw_ostream &OS); unsigned FeatureKeyValues(raw_ostream &OS);
void CPUKeyValues(raw_ostream &OS); unsigned CPUKeyValues(raw_ostream &OS);
unsigned CollectAllItinClasses(raw_ostream &OS, unsigned CollectAllItinClasses(raw_ostream &OS,
std::map<std::string,unsigned> &ItinClassesMap, std::map<std::string,unsigned> &ItinClassesMap,
std::vector<Record*> &ItinClassList); std::vector<Record*> &ItinClassList);
@ -52,7 +52,8 @@ class SubtargetEmitter : public TableGenBackend {
std::vector<std::vector<InstrItinerary> > &ProcList); std::vector<std::vector<InstrItinerary> > &ProcList);
void EmitProcessorLookup(raw_ostream &OS); void EmitProcessorLookup(raw_ostream &OS);
void EmitData(raw_ostream &OS); void EmitData(raw_ostream &OS);
void ParseFeaturesFunction(raw_ostream &OS); void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures,
unsigned NumProcs);
public: public:
SubtargetEmitter(RecordKeeper &R) : Records(R), HasItineraries(false) {} SubtargetEmitter(RecordKeeper &R) : Records(R), HasItineraries(false) {}