summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReed Kotler <rkotler@mips.com>2014-04-29 17:57:50 +0000
committerReed Kotler <rkotler@mips.com>2014-04-29 17:57:50 +0000
commit52c03fbb3b4841f5ca407bffdc5c0f472402efcb (patch)
treeb850289d898ecae5233e2ce7163af16237f5e9b3
parentb58db2293dff0eb47d9e16a8482b32e2008b68e4 (diff)
downloadllvm-52c03fbb3b4841f5ca407bffdc5c0f472402efcb.tar.gz
llvm-52c03fbb3b4841f5ca407bffdc5c0f472402efcb.tar.bz2
llvm-52c03fbb3b4841f5ca407bffdc5c0f472402efcb.tar.xz
Add Simple return instruction to Mips fast-isel
Reviewers: dsanders Reviewed by: dsanders Differential Revision: http://reviews.llvm.org/D3430 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207565 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/Mips/MipsFastISel.cpp60
-rw-r--r--test/CodeGen/Mips/Fast-ISel/nullvoid.ll9
2 files changed, 67 insertions, 2 deletions
diff --git a/lib/Target/Mips/MipsFastISel.cpp b/lib/Target/Mips/MipsFastISel.cpp
index 70579bd270..c85be1e553 100644
--- a/lib/Target/Mips/MipsFastISel.cpp
+++ b/lib/Target/Mips/MipsFastISel.cpp
@@ -3,8 +3,13 @@
#include "llvm/CodeGen/FunctionLoweringInfo.h"
#include "llvm/CodeGen/FastISel.h"
+
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetLibraryInfo.h"
#include "MipsISelLowering.h"
+#include "MipsMachineFunction.h"
+#include "MipsSubtarget.h"
using namespace llvm;
@@ -12,12 +17,63 @@ namespace {
class MipsFastISel final : public FastISel {
+ /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
+ /// make the right decision when generating code for different targets.
+ const MipsSubtarget *Subtarget;
+ Module &M;
+ const TargetMachine &TM;
+ const TargetInstrInfo &TII;
+ const TargetLowering &TLI;
+ MipsFunctionInfo *MFI;
+
+ // Convenience variables to avoid some queries.
+ LLVMContext *Context;
+
+ bool TargetSupported;
+
public:
explicit MipsFastISel(FunctionLoweringInfo &funcInfo,
const TargetLibraryInfo *libInfo)
- : FastISel(funcInfo, libInfo) {}
- bool TargetSelectInstruction(const Instruction *I) override { return false; }
+ : FastISel(funcInfo, libInfo),
+ M(const_cast<Module &>(*funcInfo.Fn->getParent())),
+ TM(funcInfo.MF->getTarget()), TII(*TM.getInstrInfo()),
+ TLI(*TM.getTargetLowering()) {
+ Subtarget = &TM.getSubtarget<MipsSubtarget>();
+ MFI = funcInfo.MF->getInfo<MipsFunctionInfo>();
+ Context = &funcInfo.Fn->getContext();
+ TargetSupported = ((Subtarget->getRelocationModel() == Reloc::PIC_) &&
+ (Subtarget->hasMips32r2() && (Subtarget->isABI_O32())));
+ }
+
+ bool TargetSelectInstruction(const Instruction *I) override;
+
+ bool SelectRet(const Instruction *I);
};
+
+bool MipsFastISel::SelectRet(const Instruction *I) {
+ const ReturnInst *Ret = cast<ReturnInst>(I);
+
+ if (!FuncInfo.CanLowerReturn)
+ return false;
+ if (Ret->getNumOperands() > 0) {
+ return false;
+ }
+ unsigned RetOpc = Mips::RetRA;
+ BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(RetOpc));
+ return true;
+}
+
+bool MipsFastISel::TargetSelectInstruction(const Instruction *I) {
+ if (!TargetSupported)
+ return false;
+ switch (I->getOpcode()) {
+ default:
+ break;
+ case Instruction::Ret:
+ return SelectRet(I);
+ }
+ return false;
+}
}
namespace llvm {
diff --git a/test/CodeGen/Mips/Fast-ISel/nullvoid.ll b/test/CodeGen/Mips/Fast-ISel/nullvoid.ll
new file mode 100644
index 0000000000..eeaff878bf
--- /dev/null
+++ b/test/CodeGen/Mips/Fast-ISel/nullvoid.ll
@@ -0,0 +1,9 @@
+; RUN: llc -march=mipsel -relocation-model=pic -O0 -mips-fast-isel -fast-isel-abort -mcpu=mips32r2 \
+; RUN: < %s | FileCheck %s
+
+; Function Attrs: nounwind
+define void @foo() {
+entry:
+ ret void
+; CHECK: jr $ra
+}