1 //===---- MipsOs16.cpp for Mips Option -Os16 --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an optimization phase for the MIPS target.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "mips-os16"
16 #include "llvm/IR/Module.h"
17 #include "llvm/Support/Debug.h"
18 #include "llvm/Support/raw_ostream.h"
22 // Figure out if we need float point based on the function signature.
23 // We need to move variables in and/or out of floating point
24 // registers because of the ABI
26 bool needsFPFromSig(Function &F) {
27 Type* RetType = F.getReturnType();
28 switch (RetType->getTypeID()) {
30 case Type::DoubleTyID:
35 if (F.arg_size() >=1) {
36 Argument &Arg = F.getArgumentList().front();
37 switch (Arg.getType()->getTypeID()) {
39 case Type::DoubleTyID:
48 // Figure out if the function will need floating point operations
50 bool needsFP(Function &F) {
51 if (needsFPFromSig(F))
53 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
54 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
56 const Instruction &Inst = *I;
57 switch (Inst.getOpcode()) {
58 case Instruction::FAdd:
59 case Instruction::FSub:
60 case Instruction::FMul:
61 case Instruction::FDiv:
62 case Instruction::FRem:
63 case Instruction::FPToUI:
64 case Instruction::FPToSI:
65 case Instruction::UIToFP:
66 case Instruction::SIToFP:
67 case Instruction::FPTrunc:
68 case Instruction::FPExt:
69 case Instruction::FCmp:
74 if (const CallInst *CI = dyn_cast<CallInst>(I)) {
75 DEBUG(dbgs() << "Working on call" << "\n");
76 Function &F_ = *CI->getCalledFunction();
77 if (needsFPFromSig(F_))
87 bool MipsOs16::runOnModule(Module &M) {
88 DEBUG(errs() << "Run on Module MipsOs16\n");
89 bool modified = false;
90 for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
91 if (F->isDeclaration()) continue;
92 DEBUG(dbgs() << "Working on " << F->getName() << "\n");
94 DEBUG(dbgs() << " need to compile as nomips16 \n");
95 F->addFnAttr("nomips16");
98 F->addFnAttr("mips16");
99 DEBUG(dbgs() << " no need to compile as nomips16 \n");
105 char MipsOs16::ID = 0;
109 ModulePass *llvm::createMipsOs16(MipsTargetMachine &TM) {