Files
acceptance-tests
data
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
libcxx
libcxxabi
libunwind
lld
lldb
llvm
bindings
cmake
docs
examples
include
lib
Analysis
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
Demangle
ExecutionEngine
FuzzMutate
Fuzzer
IR
IRReader
LTO
LineEditor
Linker
MC
Object
ObjectYAML
Option
Passes
ProfileData
Support
TableGen
Target
AArch64
AMDGPU
ARC
ARM
AVR
BPF
Hexagon
Lanai
MSP430
Mips
AsmParser
Disassembler
InstPrinter
MCTargetDesc
TargetInfo
CMakeLists.txt
LLVMBuild.txt
MSA.txt
MicroMips32r6InstrFormats.td
MicroMips32r6InstrInfo.td
MicroMipsDSPInstrFormats.td
MicroMipsDSPInstrInfo.td
MicroMipsInstrFPU.td
MicroMipsInstrFormats.td
MicroMipsInstrInfo.td
MicroMipsSizeReduction.cpp
Mips.h
Mips.td
Mips16FrameLowering.cpp
Mips16FrameLowering.h
Mips16HardFloat.cpp
Mips16HardFloatInfo.cpp
Mips16HardFloatInfo.h
Mips16ISelDAGToDAG.cpp
Mips16ISelDAGToDAG.h
Mips16ISelLowering.cpp
Mips16ISelLowering.h
Mips16InstrFormats.td
Mips16InstrInfo.cpp
Mips16InstrInfo.h
Mips16InstrInfo.td
Mips16RegisterInfo.cpp
Mips16RegisterInfo.h
Mips32r6InstrFormats.td
Mips32r6InstrInfo.td
Mips64InstrInfo.td
Mips64r6InstrInfo.td
MipsAnalyzeImmediate.cpp
MipsAnalyzeImmediate.h
MipsAsmPrinter.cpp
MipsAsmPrinter.h
MipsCCState.cpp
MipsCCState.h
MipsCallingConv.td
MipsCondMov.td
MipsConstantIslandPass.cpp
MipsDSPInstrFormats.td
MipsDSPInstrInfo.td
MipsDelaySlotFiller.cpp
MipsEVAInstrFormats.td
MipsEVAInstrInfo.td
MipsFastISel.cpp
MipsFrameLowering.cpp
MipsFrameLowering.h
MipsHazardSchedule.cpp
MipsISelDAGToDAG.cpp
MipsISelDAGToDAG.h
MipsISelLowering.cpp.REMOVED.git-id
MipsISelLowering.h
MipsInstrFPU.td
MipsInstrFormats.td
MipsInstrInfo.cpp
MipsInstrInfo.h
MipsInstrInfo.td.REMOVED.git-id
MipsLongBranch.cpp
MipsMCInstLower.cpp
MipsMCInstLower.h
MipsMSAInstrFormats.td
MipsMSAInstrInfo.td.REMOVED.git-id
MipsMTInstrFormats.td
MipsMTInstrInfo.td
MipsMachineFunction.cpp
MipsMachineFunction.h
MipsModuleISelDAGToDAG.cpp
MipsOptimizePICCall.cpp
MipsOptionRecord.h
MipsOs16.cpp
MipsRegisterInfo.cpp
MipsRegisterInfo.h
MipsRegisterInfo.td
MipsSEFrameLowering.cpp
MipsSEFrameLowering.h
MipsSEISelDAGToDAG.cpp
MipsSEISelDAGToDAG.h
MipsSEISelLowering.cpp.REMOVED.git-id
MipsSEISelLowering.h
MipsSEInstrInfo.cpp
MipsSEInstrInfo.h
MipsSERegisterInfo.cpp
MipsSERegisterInfo.h
MipsSchedule.td
MipsScheduleGeneric.td
MipsScheduleP5600.td
MipsSubtarget.cpp
MipsSubtarget.h
MipsTargetMachine.cpp
MipsTargetMachine.h
MipsTargetObjectFile.cpp
MipsTargetObjectFile.h
MipsTargetStreamer.h
Relocation.txt
NVPTX
Nios2
PowerPC
RISCV
Sparc
SystemZ
WebAssembly
X86
XCore
CMakeLists.txt
LLVMBuild.txt
README.txt
Target.cpp
TargetIntrinsicInfo.cpp
TargetLoweringObjectFile.cpp
TargetMachine.cpp
TargetMachineC.cpp
Testing
ToolDrivers
Transforms
WindowsManifest
XRay
CMakeLists.txt
LLVMBuild.txt
projects
resources
runtimes
scripts
test
tools
unittests
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
linux-packaging-mono/external/llvm-project/llvm/lib/Target/Mips/MipsOs16.cpp

159 lines
4.1 KiB
C++
Raw Normal View History

//===---- MipsOs16.cpp for Mips Option -Os16 --------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines an optimization phase for the MIPS target.
//
//===----------------------------------------------------------------------===//
#include "Mips.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
#define DEBUG_TYPE "mips-os16"
static cl::opt<std::string> Mips32FunctionMask(
"mips32-function-mask",
cl::init(""),
cl::desc("Force function to be mips32"),
cl::Hidden);
namespace {
class MipsOs16 : public ModulePass {
public:
static char ID;
MipsOs16() : ModulePass(ID) {}
StringRef getPassName() const override { return "MIPS Os16 Optimization"; }
bool runOnModule(Module &M) override;
};
char MipsOs16::ID = 0;
}
// Figure out if we need float point based on the function signature.
// We need to move variables in and/or out of floating point
// registers because of the ABI
//
static bool needsFPFromSig(Function &F) {
Type* RetType = F.getReturnType();
switch (RetType->getTypeID()) {
case Type::FloatTyID:
case Type::DoubleTyID:
return true;
default:
;
}
if (F.arg_size() >=1) {
Argument &Arg = *F.arg_begin();
switch (Arg.getType()->getTypeID()) {
case Type::FloatTyID:
case Type::DoubleTyID:
return true;
default:
;
}
}
return false;
}
// Figure out if the function will need floating point operations
//
static bool needsFP(Function &F) {
if (needsFPFromSig(F))
return true;
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
I != E; ++I) {
const Instruction &Inst = *I;
switch (Inst.getOpcode()) {
case Instruction::FAdd:
case Instruction::FSub:
case Instruction::FMul:
case Instruction::FDiv:
case Instruction::FRem:
case Instruction::FPToUI:
case Instruction::FPToSI:
case Instruction::UIToFP:
case Instruction::SIToFP:
case Instruction::FPTrunc:
case Instruction::FPExt:
case Instruction::FCmp:
return true;
default:
;
}
if (const CallInst *CI = dyn_cast<CallInst>(I)) {
DEBUG(dbgs() << "Working on call" << "\n");
Function &F_ = *CI->getCalledFunction();
if (needsFPFromSig(F_))
return true;
}
}
return false;
}
bool MipsOs16::runOnModule(Module &M) {
bool usingMask = Mips32FunctionMask.length() > 0;
bool doneUsingMask = false; // this will make it stop repeating
DEBUG(dbgs() << "Run on Module MipsOs16 \n" << Mips32FunctionMask << "\n");
if (usingMask)
DEBUG(dbgs() << "using mask \n" << Mips32FunctionMask << "\n");
unsigned int functionIndex = 0;
bool modified = false;
for (auto &F : M) {
if (F.isDeclaration())
continue;
DEBUG(dbgs() << "Working on " << F.getName() << "\n");
if (usingMask) {
if (!doneUsingMask) {
if (functionIndex == Mips32FunctionMask.length())
functionIndex = 0;
switch (Mips32FunctionMask[functionIndex]) {
case '1':
DEBUG(dbgs() << "mask forced mips32: " << F.getName() << "\n");
F.addFnAttr("nomips16");
break;
case '.':
doneUsingMask = true;
break;
default:
break;
}
functionIndex++;
}
}
else {
if (needsFP(F)) {
DEBUG(dbgs() << "os16 forced mips32: " << F.getName() << "\n");
F.addFnAttr("nomips16");
}
else {
DEBUG(dbgs() << "os16 forced mips16: " << F.getName() << "\n");
F.addFnAttr("mips16");
}
}
}
return modified;
}
ModulePass *llvm::createMipsOs16Pass() { return new MipsOs16(); }