#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)
#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"
#define GET_INSTRINFO_ENUM
#include "Nios2GenInstrInfo.inc"
+#define GET_SUBTARGETINFO_ENUM
+#include "Nios2GenSubtargetInfo.inc"
+
#endif
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
-// 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<string Name, list<SubtargetFeature> Features>
+ : Processor<Name, Nios2GenericItineraries, Features>;
-def Nios2 : Target { let InstructionSet = Nios2InstrInfo; }
+def : Proc<"nios2r1", [FeatureNios2r1]>;
+def : Proc<"nios2r2", [FeatureNios2r2]>;
--- /dev/null
+//===-- 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);
+}
--- /dev/null
+//===-- 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
--- /dev/null
+//===-- 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; }
--- /dev/null
+//===-- 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
--- /dev/null
+//===-- 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;
+}
--- /dev/null
+//===-- 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
--- /dev/null
+//===-- 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<IIAlu , [InstrStage<1, [ALU]>]>,
+ InstrItinData<IILoad , [InstrStage<3, [ALU]>]>,
+ InstrItinData<IIStore , [InstrStage<1, [ALU]>]>,
+ InstrItinData<IIFlush , [InstrStage<1, [ALU]>]>,
+ InstrItinData<IIIdiv , [InstrStage<38, [IMULDIV]>]>,
+ InstrItinData<IIBranch , [InstrStage<1, [ALU]>]>
+]>;
--- /dev/null
+//===-- 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;
+}
--- /dev/null
+//===-- 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<const Nios2InstrInfo> InstrInfo;
+ std::unique_ptr<const Nios2FrameLowering> 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
#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<Nios2TargetMachine> 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<Reloc::Model> RM) {
- if (!RM.hasValue() || CM == CodeModel::JITDefault)
+static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
+ if (!RM.hasValue())
return Reloc::Static;
return *RM;
}
StringRef CPU, StringRef FS,
const TargetOptions &Options,
Optional<Reloc::Model> RM,
- CodeModel::Model CM,
- CodeGenOpt::Level OL)
- : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options), TT, CPU, FS,
- Options, getEffectiveRelocModel(CM, RM), CM, OL) {}
+ Optional<CodeModel::Model> 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<Nios2Subtarget>(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<Nios2TargetMachine>();
+ }
+
+ 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(); }
#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<std::unique_ptr<Nios2Subtarget>> SubtargetMap;
+
public:
Nios2TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
- Optional<Reloc::Model> RM, CodeModel::Model CM,
- CodeGenOpt::Level OL);
+ Optional<Reloc::Model> RM, Optional<CodeModel::Model> 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