25 #define DEBUG_TYPE "mips16-hard-float"
34 StringRef getPassName()
const override {
return "MIPS16 Hard Float Pass"; }
41 bool runOnModule(
Module &M)
override;
45 std::vector<llvm::Type *> AsmArgTypes;
46 std::vector<llvm::Value *> AsmArgs;
127 switch (ArgTypeID1) {
137 switch (ArgTypeID1) {
192 std::string
MI = ToFP ?
"mtc1 ":
"mfc1 ";
197 AsmText += MI +
"$$4, $$f12\n";
201 AsmText += MI +
"$$4, $$f12\n";
202 AsmText += MI +
"$$5, $$f14\n";
206 AsmText += MI +
"$$4, $$f12\n";
208 AsmText += MI +
"$$6, $$f14\n";
209 AsmText += MI +
"$$7, $$f15\n";
211 AsmText += MI +
"$$7, $$f14\n";
212 AsmText += MI +
"$$6, $$f15\n";
218 AsmText += MI +
"$$4, $$f12\n";
219 AsmText += MI +
"$$5, $$f13\n";
221 AsmText += MI +
"$$5, $$f12\n";
222 AsmText += MI +
"$$4, $$f13\n";
228 AsmText += MI +
"$$4, $$f12\n";
229 AsmText += MI +
"$$5, $$f13\n";
230 AsmText += MI +
"$$6, $$f14\n";
231 AsmText += MI +
"$$7, $$f15\n";
233 AsmText += MI +
"$$5, $$f12\n";
234 AsmText += MI +
"$$4, $$f13\n";
235 AsmText += MI +
"$$7, $$f14\n";
236 AsmText += MI +
"$$6, $$f15\n";
242 AsmText += MI +
"$$4, $$f12\n";
243 AsmText += MI +
"$$5, $$f13\n";
245 AsmText += MI +
"$$5, $$f12\n";
246 AsmText += MI +
"$$4, $$f13\n";
248 AsmText += MI +
"$$6, $$f14\n";
271 std::string StubName =
"__call_stub_fp_" +
Name;
280 FStub->
addFnAttr(llvm::Attribute::Naked);
281 FStub->
addFnAttr(llvm::Attribute::NoInline);
282 FStub->
addFnAttr(llvm::Attribute::NoUnwind);
290 AsmText +=
".set reorder\n";
293 AsmText +=
"move $$18, $$31\n";
294 AsmText +=
"jal " + Name +
"\n";
296 AsmText +=
"lui $$25, %hi(" + Name +
")\n";
297 AsmText +=
"addiu $$25, $$25, %lo(" + Name +
")\n";
302 AsmText +=
"mfc1 $$2, $$f0\n";
307 AsmText +=
"mfc1 $$2, $$f0\n";
308 AsmText +=
"mfc1 $$3, $$f1\n";
310 AsmText +=
"mfc1 $$3, $$f0\n";
311 AsmText +=
"mfc1 $$2, $$f1\n";
317 AsmText +=
"mfc1 $$2, $$f0\n";
318 AsmText +=
"mfc1 $$3, $$f2\n";
320 AsmText +=
"mfc1 $$3, $$f0\n";
321 AsmText +=
"mfc1 $$3, $$f2\n";
327 AsmText +=
"mfc1 $$4, $$f2\n";
328 AsmText +=
"mfc1 $$5, $$f3\n";
329 AsmText +=
"mfc1 $$2, $$f0\n";
330 AsmText +=
"mfc1 $$3, $$f1\n";
333 AsmText +=
"mfc1 $$5, $$f2\n";
334 AsmText +=
"mfc1 $$4, $$f3\n";
335 AsmText +=
"mfc1 $$3, $$f0\n";
336 AsmText +=
"mfc1 $$2, $$f1\n";
345 AsmText +=
"jr $$18\n";
347 AsmText +=
"jr $$25\n";
348 EmitInlineAsm(Context, BB, AsmText);
358 "llvm.ceil.f32",
"llvm.ceil.f64",
359 "llvm.copysign.f32",
"llvm.copysign.f64",
360 "llvm.cos.f32",
"llvm.cos.f64",
361 "llvm.exp.f32",
"llvm.exp.f64",
362 "llvm.exp2.f32",
"llvm.exp2.f64",
363 "llvm.fabs.f32",
"llvm.fabs.f64",
364 "llvm.floor.f32",
"llvm.floor.f64",
365 "llvm.fma.f32",
"llvm.fma.f64",
366 "llvm.log.f32",
"llvm.log.f64",
367 "llvm.log10.f32",
"llvm.log10.f64",
368 "llvm.nearbyint.f32",
"llvm.nearbyint.f64",
369 "llvm.pow.f32",
"llvm.pow.f64",
370 "llvm.powi.f32",
"llvm.powi.f64",
371 "llvm.rint.f32",
"llvm.rint.f64",
372 "llvm.round.f32",
"llvm.round.f64",
373 "llvm.sin.f32",
"llvm.sin.f64",
374 "llvm.sqrt.f32",
"llvm.sqrt.f64",
375 "llvm.trunc.f32",
"llvm.trunc.f64",
388 bool Modified =
false;
393 if (
const ReturnInst *RI = dyn_cast<ReturnInst>(&
I)) {
394 Value *RVal = RI->getReturnValue();
406 static const char *
const Helper[
NoFPRet] = {
407 "__mips16_ret_sf",
"__mips16_ret_df",
"__mips16_ret_sc",
410 const char *
Name = Helper[RV];
412 Value *Params[] = {RVal};
421 "__Mips16RetHelper");
423 Attribute::ReadNone);
425 Attribute::NoInline);
428 }
else if (
const CallInst *CI = dyn_cast<CallInst>(&
I)) {
430 Function *F_ = CI->getCalledFunction();
434 F.addFnAttr(
"saveS2");
441 F.addFnAttr(
"saveS2");
462 std::string StubName =
"__fn_stub_" +
Name;
463 std::string LocalName =
"$$__fn_local_" +
Name;
468 FStub->
addFnAttr(llvm::Attribute::Naked);
469 FStub->
addFnAttr(llvm::Attribute::NoUnwind);
470 FStub->
addFnAttr(llvm::Attribute::NoInline);
477 AsmText +=
".set noreorder\n";
478 AsmText +=
".cpload $$25\n";
479 AsmText +=
".set reorder\n";
480 AsmText +=
".reloc 0, R_MIPS_NONE, " + Name +
"\n";
481 AsmText +=
"la $$25, " + LocalName +
"\n";
483 AsmText +=
"la $$25, " + Name +
"\n";
485 AsmText +=
"jr $$25\n";
486 AsmText += LocalName +
" = " + Name +
"\n";
487 EmitInlineAsm(Context, BB, AsmText);
497 DEBUG(
errs() <<
"removing -use-soft-float\n");
501 DEBUG(
errs() <<
"still has -use-soft-float\n");
525 bool Mips16HardFloat::runOnModule(
Module &M) {
527 getAnalysis<TargetPassConfig>().getTM<TargetMachine>());
528 DEBUG(
errs() <<
"Run on Module Mips16HardFloat\n");
529 bool Modified =
false;
531 if (
F->hasFnAttribute(
"nomips16") &&
532 F->hasFnAttribute(
"use-soft-float")) {
536 if (
F->isDeclaration() ||
F->hasFnAttribute(
"mips16_fp_stub") ||
537 F->hasFnAttribute(
"nomips16"))
continue;
Return a value (possibly void), from a function.
const_iterator end(StringRef path)
Get end iterator over path.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
static bool needsFPReturnHelper(Function &F)
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
unsigned getStructNumElements() const
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
static void removeUseSoftFloat(Function &F)
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
This class represents a function call, abstracting a target machine's calling convention.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
StringRef getName() const
Return a constant reference to the value's name.
AnalysisUsage & addRequired()
static bool needsFPHelperFromSig(Function &F)
TypeID
Definitions of all of the base types for the Type system.
Target-Independent Code Generator Pass Configuration Options.
static bool needsFPStubFromParams(Function &F)
static FPReturnVariant whichFPReturnVariant(Type *T)
Class to represent function types.
const Type::TypeID FloatTyID
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
TypeID getTypeID() const
Return the type id for the type.
AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
static bool isIntrinsicInline(Function *F)
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
static void assureFPCallStub(Function &F, Module *M, const MipsTargetMachine &TM)
Type * getReturnType() const
Returns the type of the ret val.
Type * getParamType(unsigned i) const
Parameter type accessors.
LLVM Basic Block Representation.
static bool fixupFPReturnAndCall(Function &F, Module *M, const MipsTargetMachine &TM)
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
This function has undefined behavior.
static void createFPFnStub(Function *F, Module *M, FPParamVariant PV, const MipsTargetMachine &TM)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
bool isPositionIndependent() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
ModulePass * createMips16HardFloatPass()
Iterator for intrusive lists based on ilist_node.
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
bool isLittleEndian() const
llvm_unreachable("Unknown RegBank!")
void removeAttributes(unsigned i, const AttrBuilder &Attrs)
removes the attributes from the list of attributes.
static FPParamVariant whichFPParamVariantNeeded(Function &F)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static const char *const IntrinsicInline[]
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Rename collisions when linking (static functions).
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
3: 64-bit floating point type
void addAttributes(unsigned i, const AttrBuilder &Attrs)
adds the attributes to the list of attributes.
Type * getReturnType() const
const Type::TypeID DoubleTyID
LLVM Value Representation.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
static cl::opt< bool > Mips16HardFloat("mips16-hard-float", cl::NotHidden, cl::desc("Enable mips16 hard float."), cl::init(false))
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
void setSection(StringRef S)
Change the section for this global.
static std::string swapFPIntParams(FPParamVariant PV, Module *M, bool LE, bool ToFP)
LLVMContext & getContext() const
Get the global data context.