[llvm-uc] [PATCH] Add CSR list and UniCoreFrameLowering

  • From: 陳韋任 (Wei-Ren Chen) <chenwj@xxxxxxxxxxxxxxxxx>
  • To: llvm-uc@xxxxxxxxxxxxx
  • Date: Mon, 3 Dec 2012 15:56:23 +0800

  This patch modifies UniCoreRegisterInfo to return CSR (callee saved register)
list defined in UniCoreRegisterInfo.td so that LLVM register allocator does not
complain anymore. Also add UniCoreFrameLowering stub, for prologue/epilogue
insertion. 

Signed-off-by: Chen Wei-Ren <chenwj@xxxxxxxxxxxxxxxxx>
---
 lib/Target/UniCore/UniCoreFrameLowering.cpp       |   42 ++++++++++++++++++++
 lib/Target/UniCore/UniCoreFrameLowering.h         |   43 +++++++++++++++++++++
 lib/Target/UniCore/UniCoreMachineFunctionInfo.cpp |   14 +++++++
 lib/Target/UniCore/UniCoreMachineFunctionInfo.h   |   33 ++++++++++++++++
 lib/Target/UniCore/UniCoreRegisterInfo.cpp        |   18 +++++++-
 lib/Target/UniCore/UniCoreTargetMachine.cpp       |    4 +-
 lib/Target/UniCore/UniCoreTargetMachine.h         |   12 ++++++
 7 files changed, 161 insertions(+), 5 deletions(-)
 create mode 100644 lib/Target/UniCore/UniCoreFrameLowering.cpp
 create mode 100644 lib/Target/UniCore/UniCoreFrameLowering.h
 create mode 100644 lib/Target/UniCore/UniCoreMachineFunctionInfo.cpp
 create mode 100644 lib/Target/UniCore/UniCoreMachineFunctionInfo.h

diff --git a/lib/Target/UniCore/UniCoreFrameLowering.cpp 
b/lib/Target/UniCore/UniCoreFrameLowering.cpp
new file mode 100644
index 0000000..54910ac
--- /dev/null
+++ b/lib/Target/UniCore/UniCoreFrameLowering.cpp
@@ -0,0 +1,42 @@
+//===-- UniCoreFrameLowering.cpp - UniCore 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 UniCore implementation of TargetFrameLowering class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "UniCoreFrameLowering.h"
+#include "UniCoreInstrInfo.h"
+#include "UniCoreMachineFunctionInfo.h"
+#include "llvm/DataLayout.h"
+#include "llvm/Function.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/Target/TargetOptions.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+
+bool UniCoreFrameLowering::hasFP(const MachineFunction &MF) const {
+  const MachineFrameInfo *MFI = MF.getFrameInfo();
+
+  return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
+          MF.getFrameInfo()->hasVarSizedObjects() ||
+          MFI->isFrameAddressTaken());
+}
+
+void UniCoreFrameLowering::emitPrologue(MachineFunction &MF) const {
+}
+
+void UniCoreFrameLowering::emitEpilogue(MachineFunction &MF,
+                                        MachineBasicBlock &MBB) const {
+}
diff --git a/lib/Target/UniCore/UniCoreFrameLowering.h 
b/lib/Target/UniCore/UniCoreFrameLowering.h
new file mode 100644
index 0000000..e889c78
--- /dev/null
+++ b/lib/Target/UniCore/UniCoreFrameLowering.h
@@ -0,0 +1,43 @@
+//- UniCoreFrameLowering.h - Define frame lowering for UniCore --*- C++ -*--//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This class implements UniCore-specific bits of TargetFrameLowering class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef UNICORE_FRAMEINFO_H
+#define UNICORE_FRAMEINFO_H
+
+#include "UniCore.h"
+#include "UniCoreSubtarget.h"
+#include "llvm/Target/TargetFrameLowering.h"
+
+namespace llvm {
+  class UniCoreSubtarget;
+
+class UniCoreFrameLowering : public TargetFrameLowering {
+protected:
+  const UniCoreSubtarget &STI;
+
+public:
+  explicit UniCoreFrameLowering(const UniCoreSubtarget &sti)
+    : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 8, 0), STI(sti) 
{
+  }
+
+  /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
+  /// the function.
+  void emitPrologue(MachineFunction &MF) const;
+  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
+
+  bool hasFP(const MachineFunction &MF) const;
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/lib/Target/UniCore/UniCoreMachineFunctionInfo.cpp 
b/lib/Target/UniCore/UniCoreMachineFunctionInfo.cpp
new file mode 100644
index 0000000..7ddd4a8
--- /dev/null
+++ b/lib/Target/UniCore/UniCoreMachineFunctionInfo.cpp
@@ -0,0 +1,14 @@
+//===-- UniCoreMachineFuctionInfo.cpp - UniCore machine function info ---===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "UniCoreMachineFunctionInfo.h"
+
+using namespace llvm;
+
+void UniCoreMachineFunctionInfo::anchor() { }
diff --git a/lib/Target/UniCore/UniCoreMachineFunctionInfo.h 
b/lib/Target/UniCore/UniCoreMachineFunctionInfo.h
new file mode 100644
index 0000000..c08a822
--- /dev/null
+++ b/lib/Target/UniCore/UniCoreMachineFunctionInfo.h
@@ -0,0 +1,33 @@
+//===- UniCoreMachineFuctionInfo.h - UniCore machine func info -*- 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 UniCore-specific per-machine-function information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef UNICOREMACHINEFUNCTIONINFO_H
+#define UNICOREMACHINEFUNCTIONINFO_H
+
+#include "llvm/CodeGen/MachineFunction.h"
+
+namespace llvm {
+
+/// UniCoreMachineFunctionInfo - This class is derived from MachineFunction and
+/// contains private UniCore target-specific information for each 
MachineFunction.
+class UniCoreMachineFunctionInfo : public MachineFunctionInfo {
+  virtual void anchor();
+public:
+  UniCoreMachineFunctionInfo() {}
+
+  explicit UniCoreMachineFunctionInfo(MachineFunction &MF) {}
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/lib/Target/UniCore/UniCoreRegisterInfo.cpp 
b/lib/Target/UniCore/UniCoreRegisterInfo.cpp
index a246a3d..d50c6a9 100644
--- a/lib/Target/UniCore/UniCoreRegisterInfo.cpp
+++ b/lib/Target/UniCore/UniCoreRegisterInfo.cpp
@@ -37,14 +37,26 @@ 
UniCoreRegisterInfo::UniCoreRegisterInfo(UniCoreTargetMachine &tm,
 }
 
 const uint16_t *
-UniCoreRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {}
+UniCoreRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
+  return CSR_SaveList;
+}
 
 BitVector
-UniCoreRegisterInfo::getReservedRegs(const MachineFunction &MF) const {}
+UniCoreRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
+  BitVector Reserved(getNumRegs());
+
+  Reserved.set(UniCore::R16);
+  Reserved.set(UniCore::SP);
+  Reserved.set(UniCore::PC);
+
+  return Reserved;
+}
 
 void
 UniCoreRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
                                          int SPAdj, RegScavenger *RS) const {}
 
 unsigned
-UniCoreRegisterInfo::getFrameRegister(const MachineFunction &MF) const {}
+UniCoreRegisterInfo::getFrameRegister(const MachineFunction &MF) const {
+  return UniCore::SP;
+}
diff --git a/lib/Target/UniCore/UniCoreTargetMachine.cpp 
b/lib/Target/UniCore/UniCoreTargetMachine.cpp
index 325a726..88822aa 100644
--- a/lib/Target/UniCore/UniCoreTargetMachine.cpp
+++ b/lib/Target/UniCore/UniCoreTargetMachine.cpp
@@ -33,8 +33,8 @@ UniCoreTargetMachine(const Target &T, StringRef TT,
   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
     Subtarget(TT, CPU, FS),
     DL("e-p:32:32:32-i8:8:8-i16:16:16-i32:32:32-n32"),
-    InstrInfo(*this),
-    TLInfo(*this)
+    InstrInfo(*this), TLInfo(*this), TSInfo(*this),
+    FrameLowering(Subtarget)
 {
 }
 
diff --git a/lib/Target/UniCore/UniCoreTargetMachine.h 
b/lib/Target/UniCore/UniCoreTargetMachine.h
index 8fff21a..ac4db78 100644
--- a/lib/Target/UniCore/UniCoreTargetMachine.h
+++ b/lib/Target/UniCore/UniCoreTargetMachine.h
@@ -18,6 +18,8 @@
 #include "UniCoreSubtarget.h"
 #include "UniCoreInstrInfo.h"
 #include "UniCoreISelLowering.h"
+#include "UniCoreFrameLowering.h"
+#include "UniCoreSelectionDAGInfo.h"
 #include "UniCoreSelectionDAGInfo.h"
 #include "llvm/DataLayout.h"
 #include "llvm/Target/TargetMachine.h"
@@ -30,6 +32,8 @@ namespace llvm {
   const DataLayout          DL;        // Calculates type size & alignment
   UniCoreInstrInfo          InstrInfo;
   UniCoreTargetLowering     TLInfo;
+  UniCoreSelectionDAGInfo   TSInfo;
+  UniCoreFrameLowering      FrameLowering;
 
   public:
     UniCoreTargetMachine(const Target &T, StringRef TT,
@@ -52,6 +56,14 @@ namespace llvm {
       return &TLInfo;
     }
 
+    virtual const UniCoreSelectionDAGInfo* getSelectionDAGInfo() const {
+      return &TSInfo;
+    }
+
+    virtual const TargetFrameLowering *getFrameLowering() const {
+      return &FrameLowering;
+    }
+
     virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
   };
 } // End llvm namespace
-- 
1.7.3.4


-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj

Other related posts:

  • » [llvm-uc] [PATCH] Add CSR list and UniCoreFrameLowering - Wei-Ren Chen