[llvm] r313626 - [Nios2] Subtarget, basic infrastructure for frame, instructions and registers
Nikolai Bozhenov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 04:54:29 PDT 2017
Author: n.bozhenov
Date: Tue Sep 19 04:54:29 2017
New Revision: 313626
URL: http://llvm.org/viewvc/llvm-project?rev=313626&view=rev
Log:
[Nios2] Subtarget, basic infrastructure for frame, instructions and registers
This is the second minimal patch keeping Nios2 target buildable.
I'm adding subtarget here and other stuff for frame lowering, instruction,
register information methods. I do not add any test cases, as still there
are missing parts like DAG selector and assembly printing. I plan to include
them into the next patch.
Patch by Andrei Grischenko <andrei.l.grischenko at intel.com>
Differential Revision: https://reviews.llvm.org/D37256
Added:
llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp (with props)
llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h (with props)
llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp (with props)
llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h (with props)
llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp (with props)
llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h (with props)
llvm/trunk/lib/Target/Nios2/Nios2Schedule.td
llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp (with props)
llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h (with props)
Modified:
llvm/trunk/lib/Target/Nios2/CMakeLists.txt
llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp
llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h
llvm/trunk/lib/Target/Nios2/Nios2.td
llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp
llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h
Modified: llvm/trunk/lib/Target/Nios2/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/CMakeLists.txt?rev=313626&r1=313625&r2=313626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Nios2/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/Nios2/CMakeLists.txt Tue Sep 19 04:54:29 2017
@@ -6,12 +6,19 @@ set(LLVM_TARGET_DEFINITIONS Nios2.td)
#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)
Modified: llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp?rev=313626&r1=313625&r2=313626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp (original)
+++ llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.cpp Tue Sep 19 04:54:29 2017
@@ -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"
Modified: llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h?rev=313626&r1=313625&r2=313626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h (original)
+++ llvm/trunk/lib/Target/Nios2/MCTargetDesc/Nios2MCTargetDesc.h Tue Sep 19 04:54:29 2017
@@ -31,4 +31,7 @@ Target &getTheNios2Target();
#define GET_INSTRINFO_ENUM
#include "Nios2GenInstrInfo.inc"
+#define GET_SUBTARGETINFO_ENUM
+#include "Nios2GenSubtargetInfo.inc"
+
#endif
Modified: llvm/trunk/lib/Target/Nios2/Nios2.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2.td?rev=313626&r1=313625&r2=313626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2.td (original)
+++ llvm/trunk/lib/Target/Nios2/Nios2.td Tue Sep 19 04:54:29 2017
@@ -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<string Name, list<SubtargetFeature> Features>
+ : Processor<Name, Nios2GenericItineraries, Features>;
-def Nios2 : Target { let InstructionSet = Nios2InstrInfo; }
+def : Proc<"nios2r1", [FeatureNios2r1]>;
+def : Proc<"nios2r2", [FeatureNios2r2]>;
Added: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp Tue Sep 19 04:54:29 2017
@@ -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);
+}
Propchange: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h Tue Sep 19 04:54:29 2017
@@ -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
Propchange: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2FrameLowering.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp Tue Sep 19 04:54:29 2017
@@ -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; }
Propchange: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h Tue Sep 19 04:54:29 2017
@@ -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
Propchange: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2InstrInfo.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp Tue Sep 19 04:54:29 2017
@@ -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;
+}
Propchange: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h Tue Sep 19 04:54:29 2017
@@ -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
Propchange: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2RegisterInfo.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2Schedule.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2Schedule.td?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2Schedule.td (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2Schedule.td Tue Sep 19 04:54:29 2017
@@ -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<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]>]>
+]>;
Added: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp Tue Sep 19 04:54:29 2017
@@ -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;
+}
Propchange: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h?rev=313626&view=auto
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h (added)
+++ llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h Tue Sep 19 04:54:29 2017
@@ -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<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
Propchange: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: llvm/trunk/lib/Target/Nios2/Nios2Subtarget.h
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp?rev=313626&r1=313625&r2=313626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.cpp Tue Sep 19 04:54:29 2017
@@ -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<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;
}
@@ -38,9 +40,62 @@ Nios2TargetMachine::Nios2TargetMachine(c
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(); }
Modified: llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h?rev=313626&r1=313625&r2=313626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h (original)
+++ llvm/trunk/lib/Target/Nios2/Nios2TargetMachine.h Tue Sep 19 04:54:29 2017
@@ -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<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
More information about the llvm-commits
mailing list