Index: llvm/trunk/lib/Target/Nios2/CMakeLists.txt =================================================================== --- llvm/trunk/lib/Target/Nios2/CMakeLists.txt +++ llvm/trunk/lib/Target/Nios2/CMakeLists.txt @@ -6,12 +6,19 @@ #came from Nios2InstrInfo.td. tablegen(LLVM Nios2GenRegisterInfo.inc -gen-register-info) tablegen(LLVM Nios2GenInstrInfo.inc -gen-instr-info) +tablegen(LLVM Nios2GenSubtargetInfo.inc -gen-subtarget) #Nios2CommonTableGen must be defined add_public_tablegen_target(Nios2CommonTableGen) #Nios2CodeGen should match with LLVMBuild.txt Nios2CodeGen -add_llvm_target(Nios2CodeGen Nios2TargetMachine.cpp) +add_llvm_target(Nios2CodeGen + Nios2InstrInfo.cpp + Nios2FrameLowering.cpp + Nios2RegisterInfo.cpp + Nios2Subtarget.cpp + Nios2TargetMachine.cpp + ) #Should match with "subdirectories = MCTargetDesc TargetInfo" in LLVMBuild.txt add_subdirectory(TargetInfo) Index: llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h =================================================================== --- llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h +++ llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h @@ -31,4 +31,7 @@ #define GET_INSTRINFO_ENUM #include "Nios2GenInstrInfo.inc" +#define GET_SUBTARGETINFO_ENUM +#include "Nios2GenSubtargetInfo.inc" + #endif Index: llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp =================================================================== --- llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp +++ llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp @@ -13,12 +13,16 @@ #include "Nios2MCTargetDesc.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCSubtargetInfo.h" using namespace llvm; #define GET_INSTRINFO_MC_DESC #include "Nios2GenInstrInfo.inc" +#define GET_SUBTARGETINFO_MC_DESC +#include "Nios2GenSubtargetInfo.inc" + #define GET_REGINFO_MC_DESC #include "Nios2GenRegisterInfo.inc" Index: llvm/trunk/lib/Target/Nios2/Nios2.td =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2.td +++ llvm/trunk/lib/Target/Nios2/Nios2.td @@ -8,22 +8,32 @@ //===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===// -// Target-independent interfaces +// Calling Conv, Instruction Descriptions //===----------------------------------------------------------------------===// include "llvm/Target/Target.td" +include "Nios2RegisterInfo.td" +include "Nios2InstrInfo.td" +include "Nios2Schedule.td" + +def Nios2InstrInfo : InstrInfo; + +def Nios2 : Target { let InstructionSet = Nios2InstrInfo; } //===----------------------------------------------------------------------===// -// Target-dependent interfaces +// Nios2 Subtarget features //===----------------------------------------------------------------------===// +def FeatureNios2r1 : SubtargetFeature<"nios2r1", "Nios2ArchVersion", + "Nios2r1", "Nios2 R1 ISA Support">; +def FeatureNios2r2 : SubtargetFeature<"nios2r2", "Nios2ArchVersion", + "Nios2r2", "Nios2 R2 ISA Support">; //===----------------------------------------------------------------------===// -// Calling Conv, Instruction Descriptions +// Nios2 processors supported. //===----------------------------------------------------------------------===// -include "Nios2RegisterInfo.td" -include "Nios2InstrInfo.td" - -def Nios2InstrInfo : InstrInfo; +class Proc Features> + : Processor; -def Nios2 : Target { let InstructionSet = Nios2InstrInfo; } +def : Proc<"nios2r1", [FeatureNios2r1]>; +def : Proc<"nios2r2", [FeatureNios2r2]>; Index: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h +++ llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h @@ -0,0 +1,40 @@ +//===-- Nios2FrameLowering.h - Define frame lowering for Nios2 --*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIB_TARGET_NIOS2_NIOS2FRAMELOWERING_H +#define LLVM_LIB_TARGET_NIOS2_NIOS2FRAMELOWERING_H + +#include "Nios2.h" +#include "llvm/Target/TargetFrameLowering.h" + +namespace llvm { +class Nios2Subtarget; + +class Nios2FrameLowering : public TargetFrameLowering { +protected: + const Nios2Subtarget &STI; + +public: + explicit Nios2FrameLowering(const Nios2Subtarget &sti, unsigned Alignment) + : TargetFrameLowering(StackGrowsDown, Alignment, 0, Alignment), STI(sti) { + } + + static const Nios2FrameLowering *create(const Nios2Subtarget &ST); + bool hasFP(const MachineFunction &MF) const override; + /// emitProlog/emitEpilog - These methods insert prolog and epilog code into + /// the function. + void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; + void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; +}; +} // namespace llvm + +#endif Index: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp +++ llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp @@ -0,0 +1,31 @@ +//===-- Nios2FrameLowering.cpp - Nios2 Frame Information ------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the Nios2 implementation of TargetFrameLowering class. +// +//===----------------------------------------------------------------------===// + +#include "Nios2FrameLowering.h" + +#include "Nios2Subtarget.h" +#include "llvm/CodeGen/MachineFunction.h" + +using namespace llvm; + +bool Nios2FrameLowering::hasFP(const MachineFunction &MF) const { return true; } + +void Nios2FrameLowering::emitPrologue(MachineFunction &MF, + MachineBasicBlock &MBB) const {} + +void Nios2FrameLowering::emitEpilogue(MachineFunction &MF, + MachineBasicBlock &MBB) const {} + +const Nios2FrameLowering *Nios2FrameLowering::create(const Nios2Subtarget &ST) { + return new Nios2FrameLowering(ST, 4); +} Index: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h +++ llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h @@ -0,0 +1,47 @@ +//===-- Nios2InstrInfo.h - Nios2 Instruction 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 contains the Nios2 implementation of the TargetInstrInfo class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NIOS2_NIOS2INSTRINFO_H +#define LLVM_LIB_TARGET_NIOS2_NIOS2INSTRINFO_H + +#include "Nios2.h" +#include "Nios2RegisterInfo.h" + +#include "llvm/CodeGen/MachineInstrBuilder.h" +#include "llvm/Target/TargetInstrInfo.h" + +#define GET_INSTRINFO_HEADER +#include "Nios2GenInstrInfo.inc" + +namespace llvm { + +class Nios2InstrInfo : public Nios2GenInstrInfo { +protected: + const Nios2Subtarget &Subtarget; + const Nios2RegisterInfo RI; + +public: + explicit Nios2InstrInfo(const Nios2Subtarget &STI) + : Nios2GenInstrInfo(), Subtarget(STI), RI(STI) {} + + static const Nios2InstrInfo *create(Nios2Subtarget &STI); + + /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As + /// such, whenever a client has an instance of instruction info, it should + /// always be able to get register info as well (through this method). + /// + const Nios2RegisterInfo &getRegisterInfo() const; +}; +} // namespace llvm + +#endif Index: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp +++ llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp @@ -0,0 +1,26 @@ +//===-- Nios2InstrInfo.cpp - Nios2 Instruction Information ----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the Nios2 implementation of the TargetInstrInfo class. +// +//===----------------------------------------------------------------------===// + +#include "Nios2InstrInfo.h" +#include "Nios2TargetMachine.h" + +using namespace llvm; + +#define GET_INSTRINFO_CTOR_DTOR +#include "Nios2GenInstrInfo.inc" + +const Nios2InstrInfo *Nios2InstrInfo::create(Nios2Subtarget &STI) { + return new Nios2InstrInfo(STI); +} + +const Nios2RegisterInfo &Nios2InstrInfo::getRegisterInfo() const { return RI; } Index: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h +++ llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h @@ -0,0 +1,52 @@ +//===-- Nios2RegisterInfo.h - Nios2 Register Information Impl ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the Nios2 implementation of the TargetRegisterInfo class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NIOS2_NIOS2REGISTERINFO_H +#define LLVM_LIB_TARGET_NIOS2_NIOS2REGISTERINFO_H + +#include "Nios2.h" +#include "llvm/Target/TargetRegisterInfo.h" + +#define GET_REGINFO_HEADER +#include "Nios2GenRegisterInfo.inc" + +namespace llvm { +class Nios2Subtarget; +class TargetInstrInfo; +class Type; + +class Nios2RegisterInfo : public Nios2GenRegisterInfo { +protected: + const Nios2Subtarget &Subtarget; + +public: + Nios2RegisterInfo(const Nios2Subtarget &Subtarget); + + const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override; + + BitVector getReservedRegs(const MachineFunction &MF) const override; + + /// Stack Frame Processing Methods + void eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, + unsigned FIOperandNum, + RegScavenger *RS = nullptr) const override; + + /// Debug information queries. + unsigned getFrameRegister(const MachineFunction &MF) const override; + + /// Return GPR register class. + const TargetRegisterClass *intRegClass(unsigned Size) const; +}; + +} // end namespace llvm +#endif Index: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp +++ llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp @@ -0,0 +1,50 @@ +//===-- Nios2RegisterInfo.cpp - Nios2 Register Information -== ------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file contains the Nios2 implementation of the TargetRegisterInfo class. +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "nios2-reg-info" + +#include "Nios2RegisterInfo.h" + +#include "Nios2.h" +#include "Nios2Subtarget.h" + +#define GET_REGINFO_TARGET_DESC +#include "Nios2GenRegisterInfo.inc" + +using namespace llvm; + +Nios2RegisterInfo::Nios2RegisterInfo(const Nios2Subtarget &ST) + : Nios2GenRegisterInfo(Nios2::RA), Subtarget(ST) {} + +const TargetRegisterClass *Nios2RegisterInfo::intRegClass(unsigned Size) const { + return &Nios2::CPURegsRegClass; +} + +const MCPhysReg * +Nios2RegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { + return nullptr; +} + +BitVector Nios2RegisterInfo::getReservedRegs(const MachineFunction &MF) const { + BitVector Reserved(1); + + return Reserved; +} + +void Nios2RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, + int SPAdj, unsigned FIOperandNum, + RegScavenger *RS) const {} + +unsigned Nios2RegisterInfo::getFrameRegister(const MachineFunction &MF) const { + return 0; +} Index: llvm/trunk/lib/Target/Nios2/Nios2Schedule.td =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2Schedule.td +++ llvm/trunk/lib/Target/Nios2/Nios2Schedule.td @@ -0,0 +1,39 @@ +//===-- Nios2Schedule.td - Nios2 Scheduling Definitions ----*- tablegen -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +//===----------------------------------------------------------------------===// +// Functional units across Nios2 chips sets. Based on GCC/Nios2 backend files. +//===----------------------------------------------------------------------===// +def ALU : FuncUnit; +def IMULDIV : FuncUnit; + +//===----------------------------------------------------------------------===// +// Instruction Itinerary classes used for Nios2 +//===----------------------------------------------------------------------===// +def IIAlu : InstrItinClass; +def IILoad : InstrItinClass; +def IIStore : InstrItinClass; +def IIFlush : InstrItinClass; +def IIIdiv : InstrItinClass; +def IIBranch : InstrItinClass; + +def IIPseudo : InstrItinClass; + +//===----------------------------------------------------------------------===// +// Nios2 Generic instruction itineraries. +//===----------------------------------------------------------------------===// +//@ http://llvm.org/docs/doxygen/html/structllvm_1_1InstrStage.html +def Nios2GenericItineraries : ProcessorItineraries<[ALU, IMULDIV], [], [ + InstrItinData]>, + InstrItinData]>, + InstrItinData]>, + InstrItinData]>, + InstrItinData]>, + InstrItinData]> +]>; Index: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h +++ llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h @@ -0,0 +1,88 @@ +//===-- Nios2Subtarget.h - Define Subtarget for the Nios2 -------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file declares the Nios2 specific subclass of TargetSubtargetInfo. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_NIOS2_NIOS2SUBTARGET_H +#define LLVM_LIB_TARGET_NIOS2_NIOS2SUBTARGET_H + +#include "Nios2FrameLowering.h" +#include "Nios2InstrInfo.h" +#include "llvm/Target/TargetSubtargetInfo.h" + +#define GET_SUBTARGETINFO_HEADER +#include "Nios2GenSubtargetInfo.inc" + +namespace llvm { +class StringRef; + +class Nios2TargetMachine; + +class Nios2Subtarget : public Nios2GenSubtargetInfo { + virtual void anchor(); + +public: + // Nios2 R2 features + // Bit manipulation instructions extension + bool HasBMX; + // Code Density instructions extension + bool HasCDX; + // Multi-Processor instructions extension + bool HasMPX; + // New mandatory instructions + bool HasR2Mandatory; + +protected: + enum Nios2ArchEnum { + // Nios2 R1 ISA + Nios2r1, + // Nios2 R2 ISA + Nios2r2 + }; + + // Nios2 architecture version + Nios2ArchEnum Nios2ArchVersion; + + const Nios2TargetMachine &TM; + + Triple TargetTriple; + + std::unique_ptr InstrInfo; + std::unique_ptr FrameLowering; + +public: + /// This constructor initializes the data members to match that + /// of the specified triple. + Nios2Subtarget(const Triple &TT, const std::string &CPU, + const std::string &FS, const Nios2TargetMachine &_TM); + + /// ParseSubtargetFeatures - Parses features string setting specified + /// subtarget options. Definition of function is auto generated by tblgen. + void ParseSubtargetFeatures(StringRef CPU, StringRef FS); + + bool hasNios2r1() const { return Nios2ArchVersion >= Nios2r1; } + bool isNios2r1() const { return Nios2ArchVersion == Nios2r1; } + bool hasNios2r2() const { return Nios2ArchVersion >= Nios2r2; } + bool isNios2r2() const { return Nios2ArchVersion == Nios2r2; } + + Nios2Subtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS, + const TargetMachine &TM); + + const TargetFrameLowering *getFrameLowering() const override { + return FrameLowering.get(); + } + const Nios2RegisterInfo *getRegisterInfo() const override { + return &InstrInfo->getRegisterInfo(); + } +}; +} // namespace llvm + +#endif Index: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp +++ llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp @@ -0,0 +1,61 @@ +//===-- Nios2Subtarget.cpp - Nios2 Subtarget Information ------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the Nios2 specific subclass of TargetSubtargetInfo. +// +//===----------------------------------------------------------------------===// + +#include "Nios2Subtarget.h" + +#include "Nios2.h" +#include "Nios2RegisterInfo.h" +#include "Nios2TargetMachine.h" + +using namespace llvm; + +#define DEBUG_TYPE "nios2-subtarget" + +#define GET_SUBTARGETINFO_TARGET_DESC +#define GET_SUBTARGETINFO_CTOR +#include "Nios2GenSubtargetInfo.inc" + +void Nios2Subtarget::anchor() {} + +Nios2Subtarget::Nios2Subtarget(const Triple &TT, const std::string &CPU, + const std::string &FS, + const Nios2TargetMachine &_TM) + : + + // Nios2GenSubtargetInfo will display features by llc -march=nios2 + // -mcpu=help + Nios2GenSubtargetInfo(TT, CPU, FS), TM(_TM), TargetTriple(TT), + InstrInfo(Nios2InstrInfo::create( + initializeSubtargetDependencies(CPU, FS, TM))) {} + +Nios2Subtarget & +Nios2Subtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS, + const TargetMachine &TM) { + if (TargetTriple.getArch() == Triple::nios2) { + if (CPU != "nios2r2") { + CPU = "nios2r1"; + Nios2ArchVersion = Nios2r1; + } else { + Nios2ArchVersion = Nios2r2; + } + } else { + errs() << "!!!Error, TargetTriple.getArch() = " << TargetTriple.getArch() + << "CPU = " << CPU << "\n"; + exit(0); + } + + // Parse features string. + ParseSubtargetFeatures(CPU, FS); + + return *this; +} Index: llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h +++ llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h @@ -14,16 +14,28 @@ #ifndef LLVM_LIB_TARGET_NIOS2_NIOS2TARGETMACHINE_H #define LLVM_LIB_TARGET_NIOS2_NIOS2TARGETMACHINE_H +#include "Nios2Subtarget.h" #include "llvm/Target/TargetMachine.h" namespace llvm { class Nios2TargetMachine : public LLVMTargetMachine { + Nios2Subtarget DefaultSubtarget; + + mutable StringMap> SubtargetMap; + public: Nios2TargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, - Optional RM, CodeModel::Model CM, - CodeGenOpt::Level OL); + Optional RM, Optional CM, + CodeGenOpt::Level OL, bool JIT); ~Nios2TargetMachine() override; + + const Nios2Subtarget *getSubtargetImpl() const { return &DefaultSubtarget; } + + const Nios2Subtarget *getSubtargetImpl(const Function &F) const override; + + // Pass Pipeline Configuration + TargetPassConfig *createPassConfig(PassManagerBase &PM) override; }; } // namespace llvm Index: llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp =================================================================== --- llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp +++ llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp @@ -14,22 +14,24 @@ #include "Nios2TargetMachine.h" #include "Nios2.h" +#include "llvm/CodeGen/TargetPassConfig.h" +#include "llvm/Support/TargetRegistry.h" + using namespace llvm; #define DEBUG_TYPE "nios2" extern "C" void LLVMInitializeNios2Target() { // Register the target. + RegisterTargetMachine X(getTheNios2Target()); } -static std::string computeDataLayout(const Triple &TT, StringRef CPU, - const TargetOptions &Options) { +static std::string computeDataLayout() { return "e-p:32:32:32-i8:8:32-i16:16:32-n32"; } -static Reloc::Model getEffectiveRelocModel(CodeModel::Model CM, - Optional RM) { - if (!RM.hasValue() || CM == CodeModel::JITDefault) +static Reloc::Model getEffectiveRelocModel(Optional RM) { + if (!RM.hasValue()) return Reloc::Static; return *RM; } @@ -38,9 +40,62 @@ StringRef CPU, StringRef FS, const TargetOptions &Options, Optional RM, - CodeModel::Model CM, - CodeGenOpt::Level OL) - : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options), TT, CPU, FS, - Options, getEffectiveRelocModel(CM, RM), CM, OL) {} + Optional CM, + CodeGenOpt::Level OL, bool JIT) + : LLVMTargetMachine(T, computeDataLayout(), TT, CPU, FS, Options, + getEffectiveRelocModel(RM), *CM, OL), + DefaultSubtarget(TT, CPU, FS, *this) {} Nios2TargetMachine::~Nios2TargetMachine() {} + +const Nios2Subtarget * +Nios2TargetMachine::getSubtargetImpl(const Function &F) const { + Attribute CPUAttr = F.getFnAttribute("target-cpu"); + Attribute FSAttr = F.getFnAttribute("target-features"); + + std::string CPU = !CPUAttr.hasAttribute(Attribute::None) + ? CPUAttr.getValueAsString().str() + : TargetCPU; + std::string FS = !FSAttr.hasAttribute(Attribute::None) + ? FSAttr.getValueAsString().str() + : TargetFS; + + auto &I = SubtargetMap[CPU + FS]; + if (!I) { + // This needs to be done before we create a new subtarget since any + // creation will depend on the TM and the code generation flags on the + // function that reside in TargetOptions. + resetTargetOptions(F); + I = llvm::make_unique(TargetTriple, CPU, FS, *this); + } + return I.get(); +} + +namespace { +/// Nios2 Code Generator Pass Configuration Options. +class Nios2PassConfig : public TargetPassConfig { +public: + Nios2PassConfig(Nios2TargetMachine &TM, PassManagerBase *PM) + : TargetPassConfig(TM, *PM) {} + + Nios2TargetMachine &getNios2TargetMachine() const { + return getTM(); + } + + const Nios2Subtarget &getNios2Subtarget() const { + return *getNios2TargetMachine().getSubtargetImpl(); + } + void addCodeGenPrepare() override; + void addIRPasses() override; +}; +} // namespace + +TargetPassConfig *Nios2TargetMachine::createPassConfig(PassManagerBase &PM) { + return new Nios2PassConfig(*this, &PM); +} + +void Nios2PassConfig::addCodeGenPrepare() { + TargetPassConfig::addCodeGenPrepare(); +} + +void Nios2PassConfig::addIRPasses() { TargetPassConfig::addIRPasses(); }