1 //===-- MipsastISel.cpp - Mips FastISel implementation
2 //---------------------===//
4 #include "MipsCCState.h"
5 #include "MipsInstrInfo.h"
6 #include "MipsISelLowering.h"
7 #include "MipsMachineFunction.h"
8 #include "MipsRegisterInfo.h"
9 #include "MipsSubtarget.h"
10 #include "MipsTargetMachine.h"
11 #include "llvm/Analysis/TargetLibraryInfo.h"
12 #include "llvm/CodeGen/FastISel.h"
13 #include "llvm/CodeGen/FunctionLoweringInfo.h"
14 #include "llvm/CodeGen/MachineInstrBuilder.h"
15 #include "llvm/CodeGen/MachineRegisterInfo.h"
16 #include "llvm/IR/GlobalAlias.h"
17 #include "llvm/IR/GlobalVariable.h"
18 #include "llvm/Target/TargetInstrInfo.h"
24 class MipsFastISel final : public FastISel {
26 // All possible address modes.
29 typedef enum { RegBase, FrameIndexBase } BaseKind;
40 const GlobalValue *GV;
43 // Innocuous defaults for our address.
44 Address() : Kind(RegBase), Offset(0), GV(0) { Base.Reg = 0; }
45 void setKind(BaseKind K) { Kind = K; }
46 BaseKind getKind() const { return Kind; }
47 bool isRegBase() const { return Kind == RegBase; }
48 bool isFIBase() const { return Kind == FrameIndexBase; }
49 void setReg(unsigned Reg) {
50 assert(isRegBase() && "Invalid base register access!");
53 unsigned getReg() const {
54 assert(isRegBase() && "Invalid base register access!");
57 void setFI(unsigned FI) {
58 assert(isFIBase() && "Invalid base frame index access!");
61 unsigned getFI() const {
62 assert(isFIBase() && "Invalid base frame index access!");
66 void setOffset(int64_t Offset_) { Offset = Offset_; }
67 int64_t getOffset() const { return Offset; }
68 void setGlobalValue(const GlobalValue *G) { GV = G; }
69 const GlobalValue *getGlobalValue() { return GV; }
72 /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
73 /// make the right decision when generating code for different targets.
74 const TargetMachine &TM;
75 const MipsSubtarget *Subtarget;
76 const TargetInstrInfo &TII;
77 const TargetLowering &TLI;
78 MipsFunctionInfo *MFI;
80 // Convenience variables to avoid some queries.
83 bool fastLowerCall(CallLoweringInfo &CLI) override;
86 bool UnsupportedFPMode; // To allow fast-isel to proceed and just not handle
87 // floating point but not reject doing fast-isel in other
91 // Selection routines.
92 bool selectLogicalOp(const Instruction *I);
93 bool selectLoad(const Instruction *I);
94 bool selectStore(const Instruction *I);
95 bool selectBranch(const Instruction *I);
96 bool selectCmp(const Instruction *I);
97 bool selectFPExt(const Instruction *I);
98 bool selectFPTrunc(const Instruction *I);
99 bool selectFPToInt(const Instruction *I, bool IsSigned);
100 bool selectRet(const Instruction *I);
101 bool selectTrunc(const Instruction *I);
102 bool selectIntExt(const Instruction *I);
103 bool selectShift(const Instruction *I);
105 // Utility helper routines.
106 bool isTypeLegal(Type *Ty, MVT &VT);
107 bool isTypeSupported(Type *Ty, MVT &VT);
108 bool isLoadTypeLegal(Type *Ty, MVT &VT);
109 bool computeAddress(const Value *Obj, Address &Addr);
110 bool computeCallAddress(const Value *V, Address &Addr);
111 void simplifyAddress(Address &Addr);
113 // Emit helper routines.
114 bool emitCmp(unsigned DestReg, const CmpInst *CI);
115 bool emitLoad(MVT VT, unsigned &ResultReg, Address &Addr,
116 unsigned Alignment = 0);
117 bool emitStore(MVT VT, unsigned SrcReg, Address Addr,
118 MachineMemOperand *MMO = nullptr);
119 bool emitStore(MVT VT, unsigned SrcReg, Address &Addr,
120 unsigned Alignment = 0);
121 unsigned emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, bool isZExt);
122 bool emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, unsigned DestReg,
125 bool emitIntZExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, unsigned DestReg);
127 bool emitIntSExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, unsigned DestReg);
128 bool emitIntSExt32r1(MVT SrcVT, unsigned SrcReg, MVT DestVT,
130 bool emitIntSExt32r2(MVT SrcVT, unsigned SrcReg, MVT DestVT,
133 unsigned getRegEnsuringSimpleIntegerWidening(const Value *, bool IsUnsigned);
135 unsigned emitLogicalOp(unsigned ISDOpc, MVT RetVT, const Value *LHS,
138 unsigned materializeFP(const ConstantFP *CFP, MVT VT);
139 unsigned materializeGV(const GlobalValue *GV, MVT VT);
140 unsigned materializeInt(const Constant *C, MVT VT);
141 unsigned materialize32BitInt(int64_t Imm, const TargetRegisterClass *RC);
143 MachineInstrBuilder emitInst(unsigned Opc) {
144 return BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc));
146 MachineInstrBuilder emitInst(unsigned Opc, unsigned DstReg) {
147 return BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc),
150 MachineInstrBuilder emitInstStore(unsigned Opc, unsigned SrcReg,
151 unsigned MemReg, int64_t MemOffset) {
152 return emitInst(Opc).addReg(SrcReg).addReg(MemReg).addImm(MemOffset);
154 MachineInstrBuilder emitInstLoad(unsigned Opc, unsigned DstReg,
155 unsigned MemReg, int64_t MemOffset) {
156 return emitInst(Opc, DstReg).addReg(MemReg).addImm(MemOffset);
158 // for some reason, this default is not generated by tablegen
159 // so we explicitly generate it here.
161 unsigned fastEmitInst_riir(uint64_t inst, const TargetRegisterClass *RC,
162 unsigned Op0, bool Op0IsKill, uint64_t imm1,
163 uint64_t imm2, unsigned Op3, bool Op3IsKill) {
167 // Call handling routines.
169 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC) const;
170 bool processCallArgs(CallLoweringInfo &CLI, SmallVectorImpl<MVT> &ArgVTs,
172 bool finishCall(CallLoweringInfo &CLI, MVT RetVT, unsigned NumBytes);
175 // Backend specific FastISel code.
176 explicit MipsFastISel(FunctionLoweringInfo &funcInfo,
177 const TargetLibraryInfo *libInfo)
178 : FastISel(funcInfo, libInfo), TM(funcInfo.MF->getTarget()),
179 Subtarget(&funcInfo.MF->getSubtarget<MipsSubtarget>()),
180 TII(*Subtarget->getInstrInfo()), TLI(*Subtarget->getTargetLowering()) {
181 MFI = funcInfo.MF->getInfo<MipsFunctionInfo>();
182 Context = &funcInfo.Fn->getContext();
184 ((TM.getRelocationModel() == Reloc::PIC_) &&
185 ((Subtarget->hasMips32r2() || Subtarget->hasMips32()) &&
186 (static_cast<const MipsTargetMachine &>(TM).getABI().IsO32())));
187 UnsupportedFPMode = Subtarget->isFP64bit();
190 unsigned fastMaterializeConstant(const Constant *C) override;
191 bool fastSelectInstruction(const Instruction *I) override;
193 #include "MipsGenFastISel.inc"
195 } // end anonymous namespace.
197 static bool CC_Mips(unsigned ValNo, MVT ValVT, MVT LocVT,
198 CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
199 CCState &State) LLVM_ATTRIBUTE_UNUSED;
201 static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, MVT LocVT,
202 CCValAssign::LocInfo LocInfo,
203 ISD::ArgFlagsTy ArgFlags, CCState &State) {
204 llvm_unreachable("should not be called");
207 static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, MVT LocVT,
208 CCValAssign::LocInfo LocInfo,
209 ISD::ArgFlagsTy ArgFlags, CCState &State) {
210 llvm_unreachable("should not be called");
213 #include "MipsGenCallingConv.inc"
215 CCAssignFn *MipsFastISel::CCAssignFnForCall(CallingConv::ID CC) const {
219 unsigned MipsFastISel::emitLogicalOp(unsigned ISDOpc, MVT RetVT,
220 const Value *LHS, const Value *RHS) {
221 // Canonicalize immediates to the RHS first.
222 if (isa<ConstantInt>(LHS) && !isa<ConstantInt>(RHS))
226 if (ISDOpc == ISD::AND) {
228 } else if (ISDOpc == ISD::OR) {
230 } else if (ISDOpc == ISD::XOR) {
233 llvm_unreachable("unexpected opcode");
235 unsigned LHSReg = getRegForValue(LHS);
236 unsigned ResultReg = createResultReg(&Mips::GPR32RegClass);
244 if (const auto *C = dyn_cast<ConstantInt>(RHS))
245 RHSReg = materializeInt(C, MVT::i32);
247 RHSReg = getRegForValue(RHS);
252 emitInst(Opc, ResultReg).addReg(LHSReg).addReg(RHSReg);
256 unsigned MipsFastISel::materializeInt(const Constant *C, MVT VT) {
257 if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1)
259 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
260 const ConstantInt *CI = cast<ConstantInt>(C);
262 if ((VT != MVT::i1) && CI->isNegative())
263 Imm = CI->getSExtValue();
265 Imm = CI->getZExtValue();
266 return materialize32BitInt(Imm, RC);
269 unsigned MipsFastISel::materialize32BitInt(int64_t Imm,
270 const TargetRegisterClass *RC) {
271 unsigned ResultReg = createResultReg(RC);
273 if (isInt<16>(Imm)) {
274 unsigned Opc = Mips::ADDiu;
275 emitInst(Opc, ResultReg).addReg(Mips::ZERO).addImm(Imm);
277 } else if (isUInt<16>(Imm)) {
278 emitInst(Mips::ORi, ResultReg).addReg(Mips::ZERO).addImm(Imm);
281 unsigned Lo = Imm & 0xFFFF;
282 unsigned Hi = (Imm >> 16) & 0xFFFF;
284 // Both Lo and Hi have nonzero bits.
285 unsigned TmpReg = createResultReg(RC);
286 emitInst(Mips::LUi, TmpReg).addImm(Hi);
287 emitInst(Mips::ORi, ResultReg).addReg(TmpReg).addImm(Lo);
289 emitInst(Mips::LUi, ResultReg).addImm(Hi);
294 unsigned MipsFastISel::materializeFP(const ConstantFP *CFP, MVT VT) {
295 if (UnsupportedFPMode)
297 int64_t Imm = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
298 if (VT == MVT::f32) {
299 const TargetRegisterClass *RC = &Mips::FGR32RegClass;
300 unsigned DestReg = createResultReg(RC);
301 unsigned TempReg = materialize32BitInt(Imm, &Mips::GPR32RegClass);
302 emitInst(Mips::MTC1, DestReg).addReg(TempReg);
304 } else if (VT == MVT::f64) {
305 const TargetRegisterClass *RC = &Mips::AFGR64RegClass;
306 unsigned DestReg = createResultReg(RC);
307 unsigned TempReg1 = materialize32BitInt(Imm >> 32, &Mips::GPR32RegClass);
309 materialize32BitInt(Imm & 0xFFFFFFFF, &Mips::GPR32RegClass);
310 emitInst(Mips::BuildPairF64, DestReg).addReg(TempReg2).addReg(TempReg1);
316 unsigned MipsFastISel::materializeGV(const GlobalValue *GV, MVT VT) {
317 // For now 32-bit only.
320 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
321 unsigned DestReg = createResultReg(RC);
322 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
323 bool IsThreadLocal = GVar && GVar->isThreadLocal();
324 // TLS not supported at this time.
327 emitInst(Mips::LW, DestReg)
328 .addReg(MFI->getGlobalBaseReg())
329 .addGlobalAddress(GV, 0, MipsII::MO_GOT);
330 if ((GV->hasInternalLinkage() ||
331 (GV->hasLocalLinkage() && !isa<Function>(GV)))) {
332 unsigned TempReg = createResultReg(RC);
333 emitInst(Mips::ADDiu, TempReg)
335 .addGlobalAddress(GV, 0, MipsII::MO_ABS_LO);
341 // Materialize a constant into a register, and return the register
342 // number (or zero if we failed to handle it).
343 unsigned MipsFastISel::fastMaterializeConstant(const Constant *C) {
344 EVT CEVT = TLI.getValueType(C->getType(), true);
346 // Only handle simple types.
347 if (!CEVT.isSimple())
349 MVT VT = CEVT.getSimpleVT();
351 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
352 return (UnsupportedFPMode) ? 0 : materializeFP(CFP, VT);
353 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
354 return materializeGV(GV, VT);
355 else if (isa<ConstantInt>(C))
356 return materializeInt(C, VT);
361 bool MipsFastISel::computeAddress(const Value *Obj, Address &Addr) {
363 const User *U = nullptr;
364 unsigned Opcode = Instruction::UserOp1;
365 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
366 // Don't walk into other basic blocks unless the object is an alloca from
367 // another block, otherwise it may not have a virtual register assigned.
368 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
369 FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) {
370 Opcode = I->getOpcode();
373 } else if (isa<ConstantExpr>(Obj))
378 case Instruction::BitCast: {
379 // Look through bitcasts.
380 return computeAddress(U->getOperand(0), Addr);
382 case Instruction::GetElementPtr: {
383 Address SavedAddr = Addr;
384 uint64_t TmpOffset = Addr.getOffset();
385 // Iterate through the GEP folding the constants into offsets where
387 gep_type_iterator GTI = gep_type_begin(U);
388 for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end(); i != e;
390 const Value *Op = *i;
391 if (StructType *STy = dyn_cast<StructType>(*GTI)) {
392 const StructLayout *SL = DL.getStructLayout(STy);
393 unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
394 TmpOffset += SL->getElementOffset(Idx);
396 uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType());
398 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
399 // Constant-offset addressing.
400 TmpOffset += CI->getSExtValue() * S;
403 if (canFoldAddIntoGEP(U, Op)) {
404 // A compatible add with a constant operand. Fold the constant.
406 cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
407 TmpOffset += CI->getSExtValue() * S;
408 // Iterate on the other operand.
409 Op = cast<AddOperator>(Op)->getOperand(0);
413 goto unsupported_gep;
417 // Try to grab the base operand now.
418 Addr.setOffset(TmpOffset);
419 if (computeAddress(U->getOperand(0), Addr))
421 // We failed, restore everything and try the other options.
426 case Instruction::Alloca: {
427 const AllocaInst *AI = cast<AllocaInst>(Obj);
428 DenseMap<const AllocaInst *, int>::iterator SI =
429 FuncInfo.StaticAllocaMap.find(AI);
430 if (SI != FuncInfo.StaticAllocaMap.end()) {
431 Addr.setKind(Address::FrameIndexBase);
432 Addr.setFI(SI->second);
438 Addr.setReg(getRegForValue(Obj));
439 return Addr.getReg() != 0;
442 bool MipsFastISel::computeCallAddress(const Value *V, Address &Addr) {
443 const GlobalValue *GV = dyn_cast<GlobalValue>(V);
444 if (GV && isa<Function>(GV) && cast<Function>(GV)->isIntrinsic())
448 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
449 Addr.setGlobalValue(GV);
455 bool MipsFastISel::isTypeLegal(Type *Ty, MVT &VT) {
456 EVT evt = TLI.getValueType(Ty, true);
457 // Only handle simple types.
458 if (evt == MVT::Other || !evt.isSimple())
460 VT = evt.getSimpleVT();
462 // Handle all legal types, i.e. a register that will directly hold this
464 return TLI.isTypeLegal(VT);
467 bool MipsFastISel::isTypeSupported(Type *Ty, MVT &VT) {
468 if (Ty->isVectorTy())
471 if (isTypeLegal(Ty, VT))
474 // If this is a type than can be sign or zero-extended to a basic operation
475 // go ahead and accept it now.
476 if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16)
482 bool MipsFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) {
483 if (isTypeLegal(Ty, VT))
485 // We will extend this in a later patch:
486 // If this is a type than can be sign or zero-extended to a basic operation
487 // go ahead and accept it now.
488 if (VT == MVT::i8 || VT == MVT::i16)
492 // Because of how EmitCmp is called with fast-isel, you can
493 // end up with redundant "andi" instructions after the sequences emitted below.
494 // We should try and solve this issue in the future.
496 bool MipsFastISel::emitCmp(unsigned ResultReg, const CmpInst *CI) {
497 const Value *Left = CI->getOperand(0), *Right = CI->getOperand(1);
498 bool IsUnsigned = CI->isUnsigned();
499 unsigned LeftReg = getRegEnsuringSimpleIntegerWidening(Left, IsUnsigned);
502 unsigned RightReg = getRegEnsuringSimpleIntegerWidening(Right, IsUnsigned);
505 CmpInst::Predicate P = CI->getPredicate();
510 case CmpInst::ICMP_EQ: {
511 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
512 emitInst(Mips::XOR, TempReg).addReg(LeftReg).addReg(RightReg);
513 emitInst(Mips::SLTiu, ResultReg).addReg(TempReg).addImm(1);
516 case CmpInst::ICMP_NE: {
517 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
518 emitInst(Mips::XOR, TempReg).addReg(LeftReg).addReg(RightReg);
519 emitInst(Mips::SLTu, ResultReg).addReg(Mips::ZERO).addReg(TempReg);
522 case CmpInst::ICMP_UGT: {
523 emitInst(Mips::SLTu, ResultReg).addReg(RightReg).addReg(LeftReg);
526 case CmpInst::ICMP_ULT: {
527 emitInst(Mips::SLTu, ResultReg).addReg(LeftReg).addReg(RightReg);
530 case CmpInst::ICMP_UGE: {
531 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
532 emitInst(Mips::SLTu, TempReg).addReg(LeftReg).addReg(RightReg);
533 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
536 case CmpInst::ICMP_ULE: {
537 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
538 emitInst(Mips::SLTu, TempReg).addReg(RightReg).addReg(LeftReg);
539 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
542 case CmpInst::ICMP_SGT: {
543 emitInst(Mips::SLT, ResultReg).addReg(RightReg).addReg(LeftReg);
546 case CmpInst::ICMP_SLT: {
547 emitInst(Mips::SLT, ResultReg).addReg(LeftReg).addReg(RightReg);
550 case CmpInst::ICMP_SGE: {
551 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
552 emitInst(Mips::SLT, TempReg).addReg(LeftReg).addReg(RightReg);
553 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
556 case CmpInst::ICMP_SLE: {
557 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
558 emitInst(Mips::SLT, TempReg).addReg(RightReg).addReg(LeftReg);
559 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
562 case CmpInst::FCMP_OEQ:
563 case CmpInst::FCMP_UNE:
564 case CmpInst::FCMP_OLT:
565 case CmpInst::FCMP_OLE:
566 case CmpInst::FCMP_OGT:
567 case CmpInst::FCMP_OGE: {
568 if (UnsupportedFPMode)
570 bool IsFloat = Left->getType()->isFloatTy();
571 bool IsDouble = Left->getType()->isDoubleTy();
572 if (!IsFloat && !IsDouble)
574 unsigned Opc, CondMovOpc;
576 case CmpInst::FCMP_OEQ:
577 Opc = IsFloat ? Mips::C_EQ_S : Mips::C_EQ_D32;
578 CondMovOpc = Mips::MOVT_I;
580 case CmpInst::FCMP_UNE:
581 Opc = IsFloat ? Mips::C_EQ_S : Mips::C_EQ_D32;
582 CondMovOpc = Mips::MOVF_I;
584 case CmpInst::FCMP_OLT:
585 Opc = IsFloat ? Mips::C_OLT_S : Mips::C_OLT_D32;
586 CondMovOpc = Mips::MOVT_I;
588 case CmpInst::FCMP_OLE:
589 Opc = IsFloat ? Mips::C_OLE_S : Mips::C_OLE_D32;
590 CondMovOpc = Mips::MOVT_I;
592 case CmpInst::FCMP_OGT:
593 Opc = IsFloat ? Mips::C_ULE_S : Mips::C_ULE_D32;
594 CondMovOpc = Mips::MOVF_I;
596 case CmpInst::FCMP_OGE:
597 Opc = IsFloat ? Mips::C_ULT_S : Mips::C_ULT_D32;
598 CondMovOpc = Mips::MOVF_I;
601 llvm_unreachable("Only switching of a subset of CCs.");
603 unsigned RegWithZero = createResultReg(&Mips::GPR32RegClass);
604 unsigned RegWithOne = createResultReg(&Mips::GPR32RegClass);
605 emitInst(Mips::ADDiu, RegWithZero).addReg(Mips::ZERO).addImm(0);
606 emitInst(Mips::ADDiu, RegWithOne).addReg(Mips::ZERO).addImm(1);
607 emitInst(Opc).addReg(LeftReg).addReg(RightReg).addReg(
608 Mips::FCC0, RegState::ImplicitDefine);
609 MachineInstrBuilder MI = emitInst(CondMovOpc, ResultReg)
612 .addReg(RegWithZero, RegState::Implicit);
613 MI->tieOperands(0, 3);
619 bool MipsFastISel::emitLoad(MVT VT, unsigned &ResultReg, Address &Addr,
620 unsigned Alignment) {
622 // more cases will be handled here in following patches.
625 switch (VT.SimpleTy) {
627 ResultReg = createResultReg(&Mips::GPR32RegClass);
632 ResultReg = createResultReg(&Mips::GPR32RegClass);
637 ResultReg = createResultReg(&Mips::GPR32RegClass);
642 if (UnsupportedFPMode)
644 ResultReg = createResultReg(&Mips::FGR32RegClass);
649 if (UnsupportedFPMode)
651 ResultReg = createResultReg(&Mips::AFGR64RegClass);
658 if (Addr.isRegBase()) {
659 simplifyAddress(Addr);
660 emitInstLoad(Opc, ResultReg, Addr.getReg(), Addr.getOffset());
663 if (Addr.isFIBase()) {
664 unsigned FI = Addr.getFI();
666 unsigned Offset = Addr.getOffset();
667 MachineFrameInfo &MFI = *MF->getFrameInfo();
668 MachineMemOperand *MMO = MF->getMachineMemOperand(
669 MachinePointerInfo::getFixedStack(FI), MachineMemOperand::MOLoad,
670 MFI.getObjectSize(FI), Align);
671 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg)
680 bool MipsFastISel::emitStore(MVT VT, unsigned SrcReg, Address &Addr,
681 unsigned Alignment) {
683 // more cases will be handled here in following patches.
686 switch (VT.SimpleTy) {
697 if (UnsupportedFPMode)
702 if (UnsupportedFPMode)
709 if (Addr.isRegBase()) {
710 simplifyAddress(Addr);
711 emitInstStore(Opc, SrcReg, Addr.getReg(), Addr.getOffset());
714 if (Addr.isFIBase()) {
715 unsigned FI = Addr.getFI();
717 unsigned Offset = Addr.getOffset();
718 MachineFrameInfo &MFI = *MF->getFrameInfo();
719 MachineMemOperand *MMO = MF->getMachineMemOperand(
720 MachinePointerInfo::getFixedStack(FI), MachineMemOperand::MOLoad,
721 MFI.getObjectSize(FI), Align);
722 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc))
732 bool MipsFastISel::selectLogicalOp(const Instruction *I) {
734 if (!isTypeSupported(I->getType(), VT))
738 switch (I->getOpcode()) {
740 llvm_unreachable("Unexpected instruction.");
741 case Instruction::And:
742 ResultReg = emitLogicalOp(ISD::AND, VT, I->getOperand(0), I->getOperand(1));
744 case Instruction::Or:
745 ResultReg = emitLogicalOp(ISD::OR, VT, I->getOperand(0), I->getOperand(1));
747 case Instruction::Xor:
748 ResultReg = emitLogicalOp(ISD::XOR, VT, I->getOperand(0), I->getOperand(1));
755 updateValueMap(I, ResultReg);
759 bool MipsFastISel::selectLoad(const Instruction *I) {
760 // Atomic loads need special handling.
761 if (cast<LoadInst>(I)->isAtomic())
764 // Verify we have a legal type before going any further.
766 if (!isLoadTypeLegal(I->getType(), VT))
769 // See if we can handle this address.
771 if (!computeAddress(I->getOperand(0), Addr))
775 if (!emitLoad(VT, ResultReg, Addr, cast<LoadInst>(I)->getAlignment()))
777 updateValueMap(I, ResultReg);
781 bool MipsFastISel::selectStore(const Instruction *I) {
782 Value *Op0 = I->getOperand(0);
785 // Atomic stores need special handling.
786 if (cast<StoreInst>(I)->isAtomic())
789 // Verify we have a legal type before going any further.
791 if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
794 // Get the value to be stored into a register.
795 SrcReg = getRegForValue(Op0);
799 // See if we can handle this address.
801 if (!computeAddress(I->getOperand(1), Addr))
804 if (!emitStore(VT, SrcReg, Addr, cast<StoreInst>(I)->getAlignment()))
810 // This can cause a redundant sltiu to be generated.
811 // FIXME: try and eliminate this in a future patch.
813 bool MipsFastISel::selectBranch(const Instruction *I) {
814 const BranchInst *BI = cast<BranchInst>(I);
815 MachineBasicBlock *BrBB = FuncInfo.MBB;
817 // TBB is the basic block for the case where the comparison is true.
818 // FBB is the basic block for the case where the comparison is false.
819 // if (cond) goto TBB
823 MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
824 MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
826 // For now, just try the simplest case where it's fed by a compare.
827 if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
828 unsigned CondReg = createResultReg(&Mips::GPR32RegClass);
829 if (!emitCmp(CondReg, CI))
831 BuildMI(*BrBB, FuncInfo.InsertPt, DbgLoc, TII.get(Mips::BGTZ))
834 fastEmitBranch(FBB, DbgLoc);
835 FuncInfo.MBB->addSuccessor(TBB);
841 bool MipsFastISel::selectCmp(const Instruction *I) {
842 const CmpInst *CI = cast<CmpInst>(I);
843 unsigned ResultReg = createResultReg(&Mips::GPR32RegClass);
844 if (!emitCmp(ResultReg, CI))
846 updateValueMap(I, ResultReg);
850 // Attempt to fast-select a floating-point extend instruction.
851 bool MipsFastISel::selectFPExt(const Instruction *I) {
852 if (UnsupportedFPMode)
854 Value *Src = I->getOperand(0);
855 EVT SrcVT = TLI.getValueType(Src->getType(), true);
856 EVT DestVT = TLI.getValueType(I->getType(), true);
858 if (SrcVT != MVT::f32 || DestVT != MVT::f64)
862 getRegForValue(Src); // his must be a 32 bit floating point register class
863 // maybe we should handle this differently
867 unsigned DestReg = createResultReg(&Mips::AFGR64RegClass);
868 emitInst(Mips::CVT_D32_S, DestReg).addReg(SrcReg);
869 updateValueMap(I, DestReg);
873 // Attempt to fast-select a floating-point truncate instruction.
874 bool MipsFastISel::selectFPTrunc(const Instruction *I) {
875 if (UnsupportedFPMode)
877 Value *Src = I->getOperand(0);
878 EVT SrcVT = TLI.getValueType(Src->getType(), true);
879 EVT DestVT = TLI.getValueType(I->getType(), true);
881 if (SrcVT != MVT::f64 || DestVT != MVT::f32)
884 unsigned SrcReg = getRegForValue(Src);
888 unsigned DestReg = createResultReg(&Mips::FGR32RegClass);
892 emitInst(Mips::CVT_S_D32, DestReg).addReg(SrcReg);
893 updateValueMap(I, DestReg);
897 // Attempt to fast-select a floating-point-to-integer conversion.
898 bool MipsFastISel::selectFPToInt(const Instruction *I, bool IsSigned) {
899 if (UnsupportedFPMode)
903 return false; // We don't handle this case yet. There is no native
904 // instruction for this but it can be synthesized.
905 Type *DstTy = I->getType();
906 if (!isTypeLegal(DstTy, DstVT))
909 if (DstVT != MVT::i32)
912 Value *Src = I->getOperand(0);
913 Type *SrcTy = Src->getType();
914 if (!isTypeLegal(SrcTy, SrcVT))
917 if (SrcVT != MVT::f32 && SrcVT != MVT::f64)
920 unsigned SrcReg = getRegForValue(Src);
924 // Determine the opcode for the conversion, which takes place
925 // entirely within FPRs.
926 unsigned DestReg = createResultReg(&Mips::GPR32RegClass);
927 unsigned TempReg = createResultReg(&Mips::FGR32RegClass);
930 if (SrcVT == MVT::f32)
931 Opc = Mips::TRUNC_W_S;
933 Opc = Mips::TRUNC_W_D32;
935 // Generate the convert.
936 emitInst(Opc, TempReg).addReg(SrcReg);
938 emitInst(Mips::MFC1, DestReg).addReg(TempReg);
940 updateValueMap(I, DestReg);
944 bool MipsFastISel::processCallArgs(CallLoweringInfo &CLI,
945 SmallVectorImpl<MVT> &OutVTs,
946 unsigned &NumBytes) {
947 CallingConv::ID CC = CLI.CallConv;
948 SmallVector<CCValAssign, 16> ArgLocs;
949 CCState CCInfo(CC, false, *FuncInfo.MF, ArgLocs, *Context);
950 CCInfo.AnalyzeCallOperands(OutVTs, CLI.OutFlags, CCAssignFnForCall(CC));
951 // Get a count of how many bytes are to be pushed on the stack.
952 NumBytes = CCInfo.getNextStackOffset();
953 // This is the minimum argument area used for A0-A3.
957 emitInst(Mips::ADJCALLSTACKDOWN).addImm(16);
960 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
961 CCValAssign &VA = ArgLocs[i];
962 const Value *ArgVal = CLI.OutVals[VA.getValNo()];
963 MVT ArgVT = OutVTs[VA.getValNo()];
967 if (ArgVT == MVT::f32) {
968 VA.convertToReg(Mips::F12);
969 } else if (ArgVT == MVT::f64) {
970 VA.convertToReg(Mips::D6);
973 if ((firstMVT == MVT::f32) || (firstMVT == MVT::f64)) {
974 if (ArgVT == MVT::f32) {
975 VA.convertToReg(Mips::F14);
976 } else if (ArgVT == MVT::f64) {
977 VA.convertToReg(Mips::D7);
981 if (((ArgVT == MVT::i32) || (ArgVT == MVT::f32)) && VA.isMemLoc()) {
982 switch (VA.getLocMemOffset()) {
984 VA.convertToReg(Mips::A0);
987 VA.convertToReg(Mips::A1);
990 VA.convertToReg(Mips::A2);
993 VA.convertToReg(Mips::A3);
999 unsigned ArgReg = getRegForValue(ArgVal);
1003 // Handle arg promotion: SExt, ZExt, AExt.
1004 switch (VA.getLocInfo()) {
1005 case CCValAssign::Full:
1007 case CCValAssign::AExt:
1008 case CCValAssign::SExt: {
1009 MVT DestVT = VA.getLocVT();
1011 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT, /*isZExt=*/false);
1016 case CCValAssign::ZExt: {
1017 MVT DestVT = VA.getLocVT();
1019 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT, /*isZExt=*/true);
1025 llvm_unreachable("Unknown arg promotion!");
1028 // Now copy/store arg to correct locations.
1029 if (VA.isRegLoc() && !VA.needsCustom()) {
1030 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1031 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(ArgReg);
1032 CLI.OutRegs.push_back(VA.getLocReg());
1033 } else if (VA.needsCustom()) {
1034 llvm_unreachable("Mips does not use custom args.");
1038 // FIXME: This path will currently return false. It was copied
1039 // from the AArch64 port and should be essentially fine for Mips too.
1040 // The work to finish up this path will be done in a follow-on patch.
1042 assert(VA.isMemLoc() && "Assuming store on stack.");
1043 // Don't emit stores for undef values.
1044 if (isa<UndefValue>(ArgVal))
1047 // Need to store on the stack.
1048 // FIXME: This alignment is incorrect but this path is disabled
1049 // for now (will return false). We need to determine the right alignment
1050 // based on the normal alignment for the underlying machine type.
1052 unsigned ArgSize = RoundUpToAlignment(ArgVT.getSizeInBits(), 4);
1054 unsigned BEAlign = 0;
1055 if (ArgSize < 8 && !Subtarget->isLittle())
1056 BEAlign = 8 - ArgSize;
1059 Addr.setKind(Address::RegBase);
1060 Addr.setReg(Mips::SP);
1061 Addr.setOffset(VA.getLocMemOffset() + BEAlign);
1063 unsigned Alignment = DL.getABITypeAlignment(ArgVal->getType());
1064 MachineMemOperand *MMO = FuncInfo.MF->getMachineMemOperand(
1065 MachinePointerInfo::getStack(Addr.getOffset()),
1066 MachineMemOperand::MOStore, ArgVT.getStoreSize(), Alignment);
1068 // if (!emitStore(ArgVT, ArgReg, Addr, MMO))
1069 return false; // can't store on the stack yet.
1076 bool MipsFastISel::finishCall(CallLoweringInfo &CLI, MVT RetVT,
1077 unsigned NumBytes) {
1078 CallingConv::ID CC = CLI.CallConv;
1079 emitInst(Mips::ADJCALLSTACKUP).addImm(16);
1080 if (RetVT != MVT::isVoid) {
1081 SmallVector<CCValAssign, 16> RVLocs;
1082 CCState CCInfo(CC, false, *FuncInfo.MF, RVLocs, *Context);
1083 CCInfo.AnalyzeCallResult(RetVT, RetCC_Mips);
1085 // Only handle a single return value.
1086 if (RVLocs.size() != 1)
1088 // Copy all of the result registers out of their specified physreg.
1089 MVT CopyVT = RVLocs[0].getValVT();
1090 // Special handling for extended integers.
1091 if (RetVT == MVT::i1 || RetVT == MVT::i8 || RetVT == MVT::i16)
1094 unsigned ResultReg = createResultReg(TLI.getRegClassFor(CopyVT));
1095 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1096 TII.get(TargetOpcode::COPY),
1097 ResultReg).addReg(RVLocs[0].getLocReg());
1098 CLI.InRegs.push_back(RVLocs[0].getLocReg());
1100 CLI.ResultReg = ResultReg;
1101 CLI.NumResultRegs = 1;
1106 bool MipsFastISel::fastLowerCall(CallLoweringInfo &CLI) {
1107 CallingConv::ID CC = CLI.CallConv;
1108 bool IsTailCall = CLI.IsTailCall;
1109 bool IsVarArg = CLI.IsVarArg;
1110 const Value *Callee = CLI.Callee;
1111 // const char *SymName = CLI.SymName;
1113 // Allow SelectionDAG isel to handle tail calls.
1117 // Let SDISel handle vararg functions.
1121 // FIXME: Only handle *simple* calls for now.
1123 if (CLI.RetTy->isVoidTy())
1124 RetVT = MVT::isVoid;
1125 else if (!isTypeLegal(CLI.RetTy, RetVT))
1128 for (auto Flag : CLI.OutFlags)
1129 if (Flag.isInReg() || Flag.isSRet() || Flag.isNest() || Flag.isByVal())
1132 // Set up the argument vectors.
1133 SmallVector<MVT, 16> OutVTs;
1134 OutVTs.reserve(CLI.OutVals.size());
1136 for (auto *Val : CLI.OutVals) {
1138 if (!isTypeLegal(Val->getType(), VT) &&
1139 !(VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16))
1142 // We don't handle vector parameters yet.
1143 if (VT.isVector() || VT.getSizeInBits() > 64)
1146 OutVTs.push_back(VT);
1150 if (!computeCallAddress(Callee, Addr))
1153 // Handle the arguments now that we've gotten them.
1155 if (!processCallArgs(CLI, OutVTs, NumBytes))
1159 unsigned DestAddress = materializeGV(Addr.getGlobalValue(), MVT::i32);
1160 emitInst(TargetOpcode::COPY, Mips::T9).addReg(DestAddress);
1161 MachineInstrBuilder MIB =
1162 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Mips::JALR),
1163 Mips::RA).addReg(Mips::T9);
1165 // Add implicit physical register uses to the call.
1166 for (auto Reg : CLI.OutRegs)
1167 MIB.addReg(Reg, RegState::Implicit);
1169 // Add a register mask with the call-preserved registers.
1170 // Proper defs for return values will be added by setPhysRegsDeadExcept().
1171 MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
1175 // Finish off the call including any return values.
1176 return finishCall(CLI, RetVT, NumBytes);
1179 bool MipsFastISel::selectRet(const Instruction *I) {
1180 const Function &F = *I->getParent()->getParent();
1181 const ReturnInst *Ret = cast<ReturnInst>(I);
1183 if (!FuncInfo.CanLowerReturn)
1186 // Build a list of return value registers.
1187 SmallVector<unsigned, 4> RetRegs;
1189 if (Ret->getNumOperands() > 0) {
1190 CallingConv::ID CC = F.getCallingConv();
1191 SmallVector<ISD::OutputArg, 4> Outs;
1192 GetReturnInfo(F.getReturnType(), F.getAttributes(), Outs, TLI);
1193 // Analyze operands of the call, assigning locations to each operand.
1194 SmallVector<CCValAssign, 16> ValLocs;
1195 MipsCCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, ValLocs,
1197 CCAssignFn *RetCC = RetCC_Mips;
1198 CCInfo.AnalyzeReturn(Outs, RetCC);
1200 // Only handle a single return value for now.
1201 if (ValLocs.size() != 1)
1204 CCValAssign &VA = ValLocs[0];
1205 const Value *RV = Ret->getOperand(0);
1207 // Don't bother handling odd stuff for now.
1208 if ((VA.getLocInfo() != CCValAssign::Full) &&
1209 (VA.getLocInfo() != CCValAssign::BCvt))
1212 // Only handle register returns for now.
1216 unsigned Reg = getRegForValue(RV);
1220 unsigned SrcReg = Reg + VA.getValNo();
1221 unsigned DestReg = VA.getLocReg();
1222 // Avoid a cross-class copy. This is very unlikely.
1223 if (!MRI.getRegClass(SrcReg)->contains(DestReg))
1226 EVT RVEVT = TLI.getValueType(RV->getType());
1227 if (!RVEVT.isSimple())
1230 if (RVEVT.isVector())
1233 MVT RVVT = RVEVT.getSimpleVT();
1234 if (RVVT == MVT::f128)
1237 MVT DestVT = VA.getValVT();
1238 // Special handling for extended integers.
1239 if (RVVT != DestVT) {
1240 if (RVVT != MVT::i1 && RVVT != MVT::i8 && RVVT != MVT::i16)
1243 if (!Outs[0].Flags.isZExt() && !Outs[0].Flags.isSExt())
1246 bool IsZExt = Outs[0].Flags.isZExt();
1247 SrcReg = emitIntExt(RVVT, SrcReg, DestVT, IsZExt);
1253 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
1254 TII.get(TargetOpcode::COPY), DestReg).addReg(SrcReg);
1256 // Add register to return instruction.
1257 RetRegs.push_back(VA.getLocReg());
1259 MachineInstrBuilder MIB = emitInst(Mips::RetRA);
1260 for (unsigned i = 0, e = RetRegs.size(); i != e; ++i)
1261 MIB.addReg(RetRegs[i], RegState::Implicit);
1265 bool MipsFastISel::selectTrunc(const Instruction *I) {
1266 // The high bits for a type smaller than the register size are assumed to be
1268 Value *Op = I->getOperand(0);
1271 SrcVT = TLI.getValueType(Op->getType(), true);
1272 DestVT = TLI.getValueType(I->getType(), true);
1274 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
1276 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
1279 unsigned SrcReg = getRegForValue(Op);
1283 // Because the high bits are undefined, a truncate doesn't generate
1285 updateValueMap(I, SrcReg);
1288 bool MipsFastISel::selectIntExt(const Instruction *I) {
1289 Type *DestTy = I->getType();
1290 Value *Src = I->getOperand(0);
1291 Type *SrcTy = Src->getType();
1293 bool isZExt = isa<ZExtInst>(I);
1294 unsigned SrcReg = getRegForValue(Src);
1298 EVT SrcEVT, DestEVT;
1299 SrcEVT = TLI.getValueType(SrcTy, true);
1300 DestEVT = TLI.getValueType(DestTy, true);
1301 if (!SrcEVT.isSimple())
1303 if (!DestEVT.isSimple())
1306 MVT SrcVT = SrcEVT.getSimpleVT();
1307 MVT DestVT = DestEVT.getSimpleVT();
1308 unsigned ResultReg = createResultReg(&Mips::GPR32RegClass);
1310 if (!emitIntExt(SrcVT, SrcReg, DestVT, ResultReg, isZExt))
1312 updateValueMap(I, ResultReg);
1315 bool MipsFastISel::emitIntSExt32r1(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1318 switch (SrcVT.SimpleTy) {
1328 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
1329 emitInst(Mips::SLL, TempReg).addReg(SrcReg).addImm(ShiftAmt);
1330 emitInst(Mips::SRA, DestReg).addReg(TempReg).addImm(ShiftAmt);
1334 bool MipsFastISel::emitIntSExt32r2(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1336 switch (SrcVT.SimpleTy) {
1340 emitInst(Mips::SEB, DestReg).addReg(SrcReg);
1343 emitInst(Mips::SEH, DestReg).addReg(SrcReg);
1349 bool MipsFastISel::emitIntSExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1351 if ((DestVT != MVT::i32) && (DestVT != MVT::i16))
1353 if (Subtarget->hasMips32r2())
1354 return emitIntSExt32r2(SrcVT, SrcReg, DestVT, DestReg);
1355 return emitIntSExt32r1(SrcVT, SrcReg, DestVT, DestReg);
1358 bool MipsFastISel::emitIntZExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1360 switch (SrcVT.SimpleTy) {
1364 emitInst(Mips::ANDi, DestReg).addReg(SrcReg).addImm(1);
1367 emitInst(Mips::ANDi, DestReg).addReg(SrcReg).addImm(0xff);
1370 emitInst(Mips::ANDi, DestReg).addReg(SrcReg).addImm(0xffff);
1376 bool MipsFastISel::emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1377 unsigned DestReg, bool IsZExt) {
1379 return emitIntZExt(SrcVT, SrcReg, DestVT, DestReg);
1380 return emitIntSExt(SrcVT, SrcReg, DestVT, DestReg);
1383 unsigned MipsFastISel::emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1385 unsigned DestReg = createResultReg(&Mips::GPR32RegClass);
1386 bool Success = emitIntExt(SrcVT, SrcReg, DestVT, DestReg, isZExt);
1387 return Success ? DestReg : 0;
1390 bool MipsFastISel::selectShift(const Instruction *I) {
1393 if (!isTypeSupported(I->getType(), RetVT))
1396 unsigned ResultReg = createResultReg(&Mips::GPR32RegClass);
1400 unsigned Opcode = I->getOpcode();
1401 const Value *Op0 = I->getOperand(0);
1402 unsigned Op0Reg = getRegForValue(Op0);
1406 // If AShr or LShr, then we need to make sure the operand0 is sign extended.
1407 if (Opcode == Instruction::AShr || Opcode == Instruction::LShr) {
1408 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
1412 MVT Op0MVT = TLI.getValueType(Op0->getType(), true).getSimpleVT();
1413 bool IsZExt = Opcode == Instruction::LShr;
1414 if (!emitIntExt(Op0MVT, Op0Reg, MVT::i32, TempReg, IsZExt))
1420 if (const auto *C = dyn_cast<ConstantInt>(I->getOperand(1))) {
1421 uint64_t ShiftVal = C->getZExtValue();
1425 llvm_unreachable("Unexpected instruction.");
1426 case Instruction::Shl:
1429 case Instruction::AShr:
1432 case Instruction::LShr:
1437 emitInst(Opcode, ResultReg).addReg(Op0Reg).addImm(ShiftVal);
1438 updateValueMap(I, ResultReg);
1442 unsigned Op1Reg = getRegForValue(I->getOperand(1));
1448 llvm_unreachable("Unexpected instruction.");
1449 case Instruction::Shl:
1450 Opcode = Mips::SLLV;
1452 case Instruction::AShr:
1453 Opcode = Mips::SRAV;
1455 case Instruction::LShr:
1456 Opcode = Mips::SRLV;
1460 emitInst(Opcode, ResultReg).addReg(Op0Reg).addReg(Op1Reg);
1461 updateValueMap(I, ResultReg);
1465 bool MipsFastISel::fastSelectInstruction(const Instruction *I) {
1466 if (!TargetSupported)
1468 switch (I->getOpcode()) {
1471 case Instruction::Load:
1472 return selectLoad(I);
1473 case Instruction::Store:
1474 return selectStore(I);
1475 case Instruction::Shl:
1476 case Instruction::LShr:
1477 case Instruction::AShr:
1478 return selectShift(I);
1479 case Instruction::And:
1480 case Instruction::Or:
1481 case Instruction::Xor:
1482 return selectLogicalOp(I);
1483 case Instruction::Br:
1484 return selectBranch(I);
1485 case Instruction::Ret:
1486 return selectRet(I);
1487 case Instruction::Trunc:
1488 return selectTrunc(I);
1489 case Instruction::ZExt:
1490 case Instruction::SExt:
1491 return selectIntExt(I);
1492 case Instruction::FPTrunc:
1493 return selectFPTrunc(I);
1494 case Instruction::FPExt:
1495 return selectFPExt(I);
1496 case Instruction::FPToSI:
1497 return selectFPToInt(I, /*isSigned*/ true);
1498 case Instruction::FPToUI:
1499 return selectFPToInt(I, /*isSigned*/ false);
1500 case Instruction::ICmp:
1501 case Instruction::FCmp:
1502 return selectCmp(I);
1507 unsigned MipsFastISel::getRegEnsuringSimpleIntegerWidening(const Value *V,
1509 unsigned VReg = getRegForValue(V);
1512 MVT VMVT = TLI.getValueType(V->getType(), true).getSimpleVT();
1513 if ((VMVT == MVT::i8) || (VMVT == MVT::i16)) {
1514 unsigned TempReg = createResultReg(&Mips::GPR32RegClass);
1515 if (!emitIntExt(VMVT, VReg, MVT::i32, TempReg, IsUnsigned))
1522 void MipsFastISel::simplifyAddress(Address &Addr) {
1523 if (!isInt<16>(Addr.getOffset())) {
1525 materialize32BitInt(Addr.getOffset(), &Mips::GPR32RegClass);
1526 unsigned DestReg = createResultReg(&Mips::GPR32RegClass);
1527 emitInst(Mips::ADDu, DestReg).addReg(TempReg).addReg(Addr.getReg());
1528 Addr.setReg(DestReg);
1534 FastISel *Mips::createFastISel(FunctionLoweringInfo &funcInfo,
1535 const TargetLibraryInfo *libInfo) {
1536 return new MipsFastISel(funcInfo, libInfo);