11
11
//
12
12
// ===----------------------------------------------------------------------===//
13
13
14
- #include " MipsOs16.h"
15
14
#include " llvm/IR/Instructions.h"
16
15
#include " llvm/IR/Module.h"
17
16
#include " llvm/Support/CommandLine.h"
18
17
#include " llvm/Support/Debug.h"
19
- #include " llvm/Support/raw_ostream.h"
18
+ #include " Mips.h"
19
+
20
20
using namespace llvm ;
21
21
22
22
#define DEBUG_TYPE " mips-os16"
@@ -28,82 +28,84 @@ static cl::opt<std::string> Mips32FunctionMask(
28
28
cl::Hidden);
29
29
30
30
namespace {
31
+ class MipsOs16 : public ModulePass {
32
+ public:
33
+ static char ID;
34
+
35
+ MipsOs16 () : ModulePass(ID) {}
36
+
37
+ const char *getPassName () const override {
38
+ return " MIPS Os16 Optimization" ;
39
+ }
40
+
41
+ bool runOnModule (Module &M) override ;
42
+ };
43
+
44
+ char MipsOs16::ID = 0 ;
45
+ }
31
46
32
- // Figure out if we need float point based on the function signature.
33
- // We need to move variables in and/or out of floating point
34
- // registers because of the ABI
35
- //
36
- bool needsFPFromSig (Function &F) {
37
- Type* RetType = F.getReturnType ();
38
- switch (RetType->getTypeID ()) {
47
+ // Figure out if we need float point based on the function signature.
48
+ // We need to move variables in and/or out of floating point
49
+ // registers because of the ABI
50
+ //
51
+ static bool needsFPFromSig (Function &F) {
52
+ Type* RetType = F.getReturnType ();
53
+ switch (RetType->getTypeID ()) {
54
+ case Type::FloatTyID:
55
+ case Type::DoubleTyID:
56
+ return true ;
57
+ default :
58
+ ;
59
+ }
60
+ if (F.arg_size () >=1 ) {
61
+ Argument &Arg = F.getArgumentList ().front ();
62
+ switch (Arg.getType ()->getTypeID ()) {
39
63
case Type::FloatTyID:
40
64
case Type::DoubleTyID:
41
65
return true ;
42
66
default :
43
67
;
44
68
}
45
- if (F.arg_size () >=1 ) {
46
- Argument &Arg = F.getArgumentList ().front ();
47
- switch (Arg.getType ()->getTypeID ()) {
48
- case Type::FloatTyID:
49
- case Type::DoubleTyID:
50
- return true ;
51
- default :
52
- ;
53
- }
54
- }
55
- return false ;
56
69
}
70
+ return false ;
71
+ }
57
72
58
- // Figure out if the function will need floating point operations
59
- //
60
- bool needsFP (Function &F) {
61
- if (needsFPFromSig (F))
62
- return true ;
63
- for (Function::const_iterator BB = F.begin (), E = F.end (); BB != E; ++BB)
64
- for (BasicBlock::const_iterator I = BB->begin (), E = BB->end ();
73
+ // Figure out if the function will need floating point operations
74
+ //
75
+ static bool needsFP (Function &F) {
76
+ if (needsFPFromSig (F))
77
+ return true ;
78
+ for (Function::const_iterator BB = F.begin (), E = F.end (); BB != E; ++BB)
79
+ for (BasicBlock::const_iterator I = BB->begin (), E = BB->end ();
65
80
I != E; ++I) {
66
- const Instruction &Inst = *I;
67
- switch (Inst.getOpcode ()) {
68
- case Instruction::FAdd:
69
- case Instruction::FSub:
70
- case Instruction::FMul:
71
- case Instruction::FDiv:
72
- case Instruction::FRem:
73
- case Instruction::FPToUI:
74
- case Instruction::FPToSI:
75
- case Instruction::UIToFP:
76
- case Instruction::SIToFP:
77
- case Instruction::FPTrunc:
78
- case Instruction::FPExt:
79
- case Instruction::FCmp:
81
+ const Instruction &Inst = *I;
82
+ switch (Inst.getOpcode ()) {
83
+ case Instruction::FAdd:
84
+ case Instruction::FSub:
85
+ case Instruction::FMul:
86
+ case Instruction::FDiv:
87
+ case Instruction::FRem:
88
+ case Instruction::FPToUI:
89
+ case Instruction::FPToSI:
90
+ case Instruction::UIToFP:
91
+ case Instruction::SIToFP:
92
+ case Instruction::FPTrunc:
93
+ case Instruction::FPExt:
94
+ case Instruction::FCmp:
95
+ return true ;
96
+ default :
97
+ ;
98
+ }
99
+ if (const CallInst *CI = dyn_cast<CallInst>(I)) {
100
+ DEBUG (dbgs () << " Working on call" << " \n " );
101
+ Function &F_ = *CI->getCalledFunction ();
102
+ if (needsFPFromSig (F_))
80
103
return true ;
81
- default :
82
- ;
83
- }
84
- if (const CallInst *CI = dyn_cast<CallInst>(I)) {
85
- DEBUG (dbgs () << " Working on call" << " \n " );
86
- Function &F_ = *CI->getCalledFunction ();
87
- if (needsFPFromSig (F_))
88
- return true ;
89
- }
90
104
}
91
- return false ;
92
- }
105
+ }
106
+ return false ;
93
107
}
94
108
95
- namespace {
96
-
97
- class MipsOs16 : public ModulePass {
98
- public:
99
- static char ID;
100
-
101
- MipsOs16 () : ModulePass(ID) {}
102
-
103
- const char *getPassName () const override { return " MIPS Os16 Optimization" ; }
104
- bool runOnModule (Module &M) override ;
105
- };
106
- } // namespace
107
109
108
110
bool MipsOs16::runOnModule (Module &M) {
109
111
bool usingMask = Mips32FunctionMask.length () > 0 ;
@@ -148,8 +150,6 @@ bool MipsOs16::runOnModule(Module &M) {
148
150
return modified;
149
151
}
150
152
151
- char MipsOs16::ID = 0 ;
152
-
153
- ModulePass *llvm::createMipsOs16 (MipsTargetMachine &TM) {
153
+ ModulePass *llvm::createMipsOs16Pass (MipsTargetMachine &TM) {
154
154
return new MipsOs16;
155
155
}
0 commit comments