1 //===----------------------------------------------------------------------===//
2 // Instruction Selector Subtarget Control
3 //===----------------------------------------------------------------------===//
4 
5 //===----------------------------------------------------------------------===//
6 // This file defines a pass used to change the subtarget for the
7 // Mips Instruction selector.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #include "Mips.h"
12 #include "MipsTargetMachine.h"
13 #include "llvm/CodeGen/TargetPassConfig.h"
14 #include "llvm/CodeGen/StackProtector.h"
15 #include "llvm/Support/Debug.h"
16 #include "llvm/Support/raw_ostream.h"
17 
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "mips-isel"
21 
22 namespace {
23   class MipsModuleDAGToDAGISel : public MachineFunctionPass {
24   public:
25     static char ID;
26 
MipsModuleDAGToDAGISel()27     MipsModuleDAGToDAGISel() : MachineFunctionPass(ID) {}
28 
29     // Pass Name
getPassName() const30     StringRef getPassName() const override {
31       return "MIPS DAG->DAG Pattern Instruction Selection";
32     }
33 
getAnalysisUsage(AnalysisUsage & AU) const34     void getAnalysisUsage(AnalysisUsage &AU) const override {
35       AU.addRequired<TargetPassConfig>();
36       AU.addPreserved<StackProtector>();
37       MachineFunctionPass::getAnalysisUsage(AU);
38     }
39 
40     bool runOnMachineFunction(MachineFunction &MF) override;
41   };
42 
43   char MipsModuleDAGToDAGISel::ID = 0;
44 }
45 
runOnMachineFunction(MachineFunction & MF)46 bool MipsModuleDAGToDAGISel::runOnMachineFunction(MachineFunction &MF) {
47   LLVM_DEBUG(errs() << "In MipsModuleDAGToDAGISel::runMachineFunction\n");
48   auto &TPC = getAnalysis<TargetPassConfig>();
49   auto &TM = TPC.getTM<MipsTargetMachine>();
50   TM.resetSubtarget(&MF);
51   return false;
52 }
53 
createMipsModuleISelDagPass()54 llvm::FunctionPass *llvm::createMipsModuleISelDagPass() {
55   return new MipsModuleDAGToDAGISel();
56 }
57