LLVM 23.0.0git
MipsFastISel.cpp
Go to the documentation of this file.
1//===- MipsFastISel.cpp - Mips FastISel implementation --------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the MIPS-specific support for the FastISel class.
11/// Some of the target-specific code is generated by tablegen in the file
12/// MipsGenFastISel.inc, which is #included here.
13///
14//===----------------------------------------------------------------------===//
15
18#include "MipsCCState.h"
19#include "MipsISelLowering.h"
20#include "MipsInstrInfo.h"
21#include "MipsMachineFunction.h"
22#include "MipsSubtarget.h"
23#include "MipsTargetMachine.h"
24#include "llvm/ADT/APInt.h"
25#include "llvm/ADT/DenseMap.h"
41#include "llvm/IR/Attributes.h"
42#include "llvm/IR/CallingConv.h"
43#include "llvm/IR/Constant.h"
44#include "llvm/IR/Constants.h"
45#include "llvm/IR/DataLayout.h"
46#include "llvm/IR/Function.h"
48#include "llvm/IR/GlobalValue.h"
50#include "llvm/IR/InstrTypes.h"
51#include "llvm/IR/Instruction.h"
54#include "llvm/IR/Operator.h"
55#include "llvm/IR/Type.h"
56#include "llvm/IR/User.h"
57#include "llvm/IR/Value.h"
58#include "llvm/MC/MCContext.h"
59#include "llvm/MC/MCInstrDesc.h"
60#include "llvm/MC/MCSymbol.h"
63#include "llvm/Support/Debug.h"
67#include <algorithm>
68#include <array>
69#include <cassert>
70#include <cstdint>
71
72#define DEBUG_TYPE "mips-fastisel"
73
74using namespace llvm;
75
77
78namespace {
79
80class MipsFastISel final : public FastISel {
81
82 // All possible address modes.
83 class Address {
84 public:
85 enum BaseKind { RegBase, FrameIndexBase };
86
87 private:
88 BaseKind Kind = RegBase;
89 union {
90 unsigned Reg;
91 int FI;
92 } Base;
93
94 int64_t Offset = 0;
95
96 const GlobalValue *GV = nullptr;
97
98 public:
99 // Innocuous defaults for our address.
100 Address() { Base.Reg = 0; }
101
102 void setKind(BaseKind K) { Kind = K; }
103 BaseKind getKind() const { return Kind; }
104 bool isRegBase() const { return Kind == RegBase; }
105 bool isFIBase() const { return Kind == FrameIndexBase; }
106
107 void setReg(unsigned Reg) {
108 assert(isRegBase() && "Invalid base register access!");
109 Base.Reg = Reg;
110 }
111
112 unsigned getReg() const {
113 assert(isRegBase() && "Invalid base register access!");
114 return Base.Reg;
115 }
116
117 void setFI(unsigned FI) {
118 assert(isFIBase() && "Invalid base frame index access!");
119 Base.FI = FI;
120 }
121
122 unsigned getFI() const {
123 assert(isFIBase() && "Invalid base frame index access!");
124 return Base.FI;
125 }
126
127 void setOffset(int64_t Offset_) { Offset = Offset_; }
128 int64_t getOffset() const { return Offset; }
129 void setGlobalValue(const GlobalValue *G) { GV = G; }
130 const GlobalValue *getGlobalValue() { return GV; }
131 };
132
133 /// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
134 /// make the right decision when generating code for different targets.
135 const TargetMachine &TM;
136 const MipsSubtarget *Subtarget;
137 const TargetInstrInfo &TII;
138 const TargetLowering &TLI;
139 MipsFunctionInfo *MFI;
140
141 // Convenience variables to avoid some queries.
142 LLVMContext *Context;
143
144 bool fastLowerArguments() override;
145 bool fastLowerCall(CallLoweringInfo &CLI) override;
146 bool fastLowerIntrinsicCall(const IntrinsicInst *II) override;
147
148 bool UnsupportedFPMode; // To allow fast-isel to proceed and just not handle
149 // floating point but not reject doing fast-isel in other
150 // situations
151
152private:
153 // Selection routines.
154 bool selectLogicalOp(const Instruction *I);
155 bool selectLoad(const Instruction *I);
156 bool selectStore(const Instruction *I);
157 bool selectBranch(const Instruction *I);
158 bool selectSelect(const Instruction *I);
159 bool selectCmp(const Instruction *I);
160 bool selectFPExt(const Instruction *I);
161 bool selectFPTrunc(const Instruction *I);
162 bool selectFPToInt(const Instruction *I, bool IsSigned);
163 bool selectRet(const Instruction *I);
164 bool selectTrunc(const Instruction *I);
165 bool selectIntExt(const Instruction *I);
166 bool selectShift(const Instruction *I);
167 bool selectDivRem(const Instruction *I, unsigned ISDOpcode);
168
169 // Utility helper routines.
170 bool isTypeLegal(Type *Ty, MVT &VT);
171 bool isTypeSupported(Type *Ty, MVT &VT);
172 bool isLoadTypeLegal(Type *Ty, MVT &VT);
173 bool computeAddress(const Value *Obj, Address &Addr);
174 bool computeCallAddress(const Value *V, Address &Addr);
175 void simplifyAddress(Address &Addr);
176
177 // Emit helper routines.
178 bool emitCmp(unsigned DestReg, const CmpInst *CI);
179 bool emitLoad(MVT VT, unsigned &ResultReg, Address &Addr);
180 bool emitStore(MVT VT, unsigned SrcReg, Address &Addr);
181 unsigned emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, bool isZExt);
182 bool emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, unsigned DestReg,
183
184 bool IsZExt);
185 bool emitIntZExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, unsigned DestReg);
186
187 bool emitIntSExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, unsigned DestReg);
188 bool emitIntSExt32r1(MVT SrcVT, unsigned SrcReg, MVT DestVT,
189 unsigned DestReg);
190 bool emitIntSExt32r2(MVT SrcVT, unsigned SrcReg, MVT DestVT,
191 unsigned DestReg);
192
193 unsigned getRegEnsuringSimpleIntegerWidening(const Value *, bool IsUnsigned);
194
195 unsigned emitLogicalOp(unsigned ISDOpc, MVT RetVT, const Value *LHS,
196 const Value *RHS);
197
198 unsigned materializeFP(const ConstantFP *CFP, MVT VT);
199 unsigned materializeGV(const GlobalValue *GV, MVT VT);
200 unsigned materializeInt(const Constant *C, MVT VT);
201 unsigned materialize32BitInt(int64_t Imm, const TargetRegisterClass *RC);
202 unsigned materializeExternalCallSym(MCSymbol *Syn);
203
204 MachineInstrBuilder emitInst(unsigned Opc) {
205 return BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Opc));
206 }
207
208 MachineInstrBuilder emitInst(unsigned Opc, unsigned DstReg) {
209 return BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Opc),
210 DstReg);
211 }
212
213 MachineInstrBuilder emitInstStore(unsigned Opc, unsigned SrcReg,
214 unsigned MemReg, int64_t MemOffset) {
215 return emitInst(Opc).addReg(SrcReg).addReg(MemReg).addImm(MemOffset);
216 }
217
218 MachineInstrBuilder emitInstLoad(unsigned Opc, unsigned DstReg,
219 unsigned MemReg, int64_t MemOffset) {
220 return emitInst(Opc, DstReg).addReg(MemReg).addImm(MemOffset);
221 }
222
223 unsigned fastEmitInst_rr(unsigned MachineInstOpcode,
224 const TargetRegisterClass *RC,
225 unsigned Op0, unsigned Op1);
226
227 // for some reason, this default is not generated by tablegen
228 // so we explicitly generate it here.
229 unsigned fastEmitInst_riir(uint64_t inst, const TargetRegisterClass *RC,
230 unsigned Op0, uint64_t imm1, uint64_t imm2,
231 unsigned Op3) {
232 return 0;
233 }
234
235 // Call handling routines.
236private:
237 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC) const;
238 bool processCallArgs(CallLoweringInfo &CLI, SmallVectorImpl<MVT> &ArgVTs,
239 unsigned &NumBytes);
240 bool finishCall(CallLoweringInfo &CLI, MVT RetVT, unsigned NumBytes);
241
242 const MipsABIInfo &getABI() const {
243 return static_cast<const MipsTargetMachine &>(TM).getABI();
244 }
245
246public:
247 // Backend specific FastISel code.
248 explicit MipsFastISel(FunctionLoweringInfo &funcInfo,
249 const TargetLibraryInfo *libInfo,
250 const LibcallLoweringInfo *libcallLowering)
251 : FastISel(funcInfo, libInfo, libcallLowering),
252 TM(funcInfo.MF->getTarget()),
253 Subtarget(&funcInfo.MF->getSubtarget<MipsSubtarget>()),
254 TII(*Subtarget->getInstrInfo()), TLI(*Subtarget->getTargetLowering()) {
255 MFI = funcInfo.MF->getInfo<MipsFunctionInfo>();
256 Context = &funcInfo.Fn->getContext();
257 UnsupportedFPMode = Subtarget->isFP64bit() || Subtarget->useSoftFloat();
258 }
259
260 Register fastMaterializeAlloca(const AllocaInst *AI) override;
261 Register fastMaterializeConstant(const Constant *C) override;
262 bool fastSelectInstruction(const Instruction *I) override;
263
264#include "MipsGenFastISel.inc"
265};
266
267} // end anonymous namespace
268
269[[maybe_unused]] static bool CC_Mips(unsigned ValNo, MVT ValVT, MVT LocVT,
270 CCValAssign::LocInfo LocInfo,
271 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
272 CCState &State);
273
274static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, MVT LocVT,
275 CCValAssign::LocInfo LocInfo,
276 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
277 CCState &State) {
278 llvm_unreachable("should not be called");
279}
280
281static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, MVT LocVT,
282 CCValAssign::LocInfo LocInfo,
283 ISD::ArgFlagsTy ArgFlags, Type *OrigTy,
284 CCState &State) {
285 llvm_unreachable("should not be called");
286}
287
288#define GET_CALLING_CONV_IMPL
289#include "MipsGenCallingConv.inc"
290
291CCAssignFn *MipsFastISel::CCAssignFnForCall(CallingConv::ID CC) const {
292 return CC_MipsO32;
293}
294
295unsigned MipsFastISel::emitLogicalOp(unsigned ISDOpc, MVT RetVT,
296 const Value *LHS, const Value *RHS) {
297 // Canonicalize immediates to the RHS first.
299 std::swap(LHS, RHS);
300
301 unsigned Opc;
302 switch (ISDOpc) {
303 case ISD::AND:
304 Opc = Mips::AND;
305 break;
306 case ISD::OR:
307 Opc = Mips::OR;
308 break;
309 case ISD::XOR:
310 Opc = Mips::XOR;
311 break;
312 default:
313 llvm_unreachable("unexpected opcode");
314 }
315
316 Register LHSReg = getRegForValue(LHS);
317 if (!LHSReg)
318 return 0;
319
320 unsigned RHSReg;
321 if (const auto *C = dyn_cast<ConstantInt>(RHS))
322 RHSReg = materializeInt(C, MVT::i32);
323 else
324 RHSReg = getRegForValue(RHS);
325 if (!RHSReg)
326 return 0;
327
328 Register ResultReg = createResultReg(&Mips::GPR32RegClass);
329 if (!ResultReg)
330 return 0;
331
332 emitInst(Opc, ResultReg).addReg(LHSReg).addReg(RHSReg);
333 return ResultReg;
334}
335
336Register MipsFastISel::fastMaterializeAlloca(const AllocaInst *AI) {
337 assert(TLI.getValueType(DL, AI->getType(), true) == MVT::i32 &&
338 "Alloca should always return a pointer.");
339
340 auto SI = FuncInfo.StaticAllocaMap.find(AI);
341
342 if (SI != FuncInfo.StaticAllocaMap.end()) {
343 Register ResultReg = createResultReg(&Mips::GPR32RegClass);
344 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Mips::LEA_ADDiu),
345 ResultReg)
346 .addFrameIndex(SI->second)
347 .addImm(0);
348 return ResultReg;
349 }
350
351 return Register();
352}
353
354unsigned MipsFastISel::materializeInt(const Constant *C, MVT VT) {
355 if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1)
356 return 0;
357 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
358 const ConstantInt *CI = cast<ConstantInt>(C);
359 return materialize32BitInt(CI->getZExtValue(), RC);
360}
361
362unsigned MipsFastISel::materialize32BitInt(int64_t Imm,
363 const TargetRegisterClass *RC) {
364 Register ResultReg = createResultReg(RC);
365
366 if (isInt<16>(Imm)) {
367 unsigned Opc = Mips::ADDiu;
368 emitInst(Opc, ResultReg).addReg(Mips::ZERO).addImm(Imm);
369 return ResultReg;
370 } else if (isUInt<16>(Imm)) {
371 emitInst(Mips::ORi, ResultReg).addReg(Mips::ZERO).addImm(Imm);
372 return ResultReg;
373 }
374 unsigned Lo = Imm & 0xFFFF;
375 unsigned Hi = (Imm >> 16) & 0xFFFF;
376 if (Lo) {
377 // Both Lo and Hi have nonzero bits.
378 Register TmpReg = createResultReg(RC);
379 emitInst(Mips::LUi, TmpReg).addImm(Hi);
380 emitInst(Mips::ORi, ResultReg).addReg(TmpReg).addImm(Lo);
381 } else {
382 emitInst(Mips::LUi, ResultReg).addImm(Hi);
383 }
384 return ResultReg;
385}
386
387unsigned MipsFastISel::materializeFP(const ConstantFP *CFP, MVT VT) {
388 if (UnsupportedFPMode)
389 return 0;
390 int64_t Imm = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
391 if (VT == MVT::f32) {
392 const TargetRegisterClass *RC = &Mips::FGR32RegClass;
393 Register DestReg = createResultReg(RC);
394 unsigned TempReg = materialize32BitInt(Imm, &Mips::GPR32RegClass);
395 emitInst(Mips::MTC1, DestReg).addReg(TempReg);
396 return DestReg;
397 } else if (VT == MVT::f64) {
398 const TargetRegisterClass *RC = &Mips::AFGR64RegClass;
399 Register DestReg = createResultReg(RC);
400 unsigned TempReg1 = materialize32BitInt(Imm >> 32, &Mips::GPR32RegClass);
401 unsigned TempReg2 =
402 materialize32BitInt(Imm & 0xFFFFFFFF, &Mips::GPR32RegClass);
403 emitInst(Mips::BuildPairF64, DestReg).addReg(TempReg2).addReg(TempReg1);
404 return DestReg;
405 }
406 return 0;
407}
408
409unsigned MipsFastISel::materializeGV(const GlobalValue *GV, MVT VT) {
410 // For now 32-bit only.
411 if (VT != MVT::i32)
412 return 0;
413 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
414 Register DestReg = createResultReg(RC);
415 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
416 bool IsThreadLocal = GVar && GVar->isThreadLocal();
417 // TLS not supported at this time.
418 if (IsThreadLocal)
419 return 0;
420 emitInst(Mips::LW, DestReg)
421 .addReg(MFI->getGlobalBaseReg(*MF))
422 .addGlobalAddress(GV, 0, MipsII::MO_GOT);
423 if ((GV->hasInternalLinkage() ||
424 (GV->hasLocalLinkage() && !isa<Function>(GV)))) {
425 Register TempReg = createResultReg(RC);
426 emitInst(Mips::ADDiu, TempReg)
427 .addReg(DestReg)
428 .addGlobalAddress(GV, 0, MipsII::MO_ABS_LO);
429 DestReg = TempReg;
430 }
431 return DestReg;
432}
433
434unsigned MipsFastISel::materializeExternalCallSym(MCSymbol *Sym) {
435 const TargetRegisterClass *RC = &Mips::GPR32RegClass;
436 Register DestReg = createResultReg(RC);
437 emitInst(Mips::LW, DestReg)
438 .addReg(MFI->getGlobalBaseReg(*MF))
439 .addSym(Sym, MipsII::MO_GOT);
440 return DestReg;
441}
442
443// Materialize a constant into a register, and return the register
444// number (or zero if we failed to handle it).
445Register MipsFastISel::fastMaterializeConstant(const Constant *C) {
446 EVT CEVT = TLI.getValueType(DL, C->getType(), true);
447
448 // Only handle simple types.
449 if (!CEVT.isSimple())
450 return Register();
451 MVT VT = CEVT.getSimpleVT();
452
453 if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
454 return (UnsupportedFPMode) ? 0 : materializeFP(CFP, VT);
455 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
456 return materializeGV(GV, VT);
457 else if (isa<ConstantInt>(C))
458 return materializeInt(C, VT);
459
460 return Register();
461}
462
463bool MipsFastISel::computeAddress(const Value *Obj, Address &Addr) {
464 const User *U = nullptr;
465 unsigned Opcode = Instruction::UserOp1;
466 if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
467 // Don't walk into other basic blocks unless the object is an alloca from
468 // another block, otherwise it may not have a virtual register assigned.
469 if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
470 FuncInfo.getMBB(I->getParent()) == FuncInfo.MBB) {
471 Opcode = I->getOpcode();
472 U = I;
473 }
474 } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
475 Opcode = C->getOpcode();
476 U = C;
477 }
478 switch (Opcode) {
479 default:
480 break;
481 case Instruction::BitCast:
482 // Look through bitcasts.
483 return computeAddress(U->getOperand(0), Addr);
484 case Instruction::GetElementPtr: {
485 Address SavedAddr = Addr;
486 int64_t TmpOffset = Addr.getOffset();
487 // Iterate through the GEP folding the constants into offsets where
488 // we can.
490 for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end(); i != e;
491 ++i, ++GTI) {
492 const Value *Op = *i;
493 if (StructType *STy = GTI.getStructTypeOrNull()) {
494 const StructLayout *SL = DL.getStructLayout(STy);
495 unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
496 TmpOffset += SL->getElementOffset(Idx);
497 } else {
498 uint64_t S = GTI.getSequentialElementStride(DL);
499 while (true) {
500 if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
501 // Constant-offset addressing.
502 TmpOffset += CI->getSExtValue() * S;
503 break;
504 }
505 if (canFoldAddIntoGEP(U, Op)) {
506 // A compatible add with a constant operand. Fold the constant.
507 ConstantInt *CI =
508 cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
509 TmpOffset += CI->getSExtValue() * S;
510 // Iterate on the other operand.
511 Op = cast<AddOperator>(Op)->getOperand(0);
512 continue;
513 }
514 // Unsupported
515 goto unsupported_gep;
516 }
517 }
518 }
519 // Try to grab the base operand now.
520 Addr.setOffset(TmpOffset);
521 if (computeAddress(U->getOperand(0), Addr))
522 return true;
523 // We failed, restore everything and try the other options.
524 Addr = SavedAddr;
525 unsupported_gep:
526 break;
527 }
528 case Instruction::Alloca: {
529 const AllocaInst *AI = cast<AllocaInst>(Obj);
530 auto SI = FuncInfo.StaticAllocaMap.find(AI);
531 if (SI != FuncInfo.StaticAllocaMap.end()) {
532 Addr.setKind(Address::FrameIndexBase);
533 Addr.setFI(SI->second);
534 return true;
535 }
536 break;
537 }
538 }
539 Addr.setReg(getRegForValue(Obj));
540 return Addr.getReg() != 0;
541}
542
543bool MipsFastISel::computeCallAddress(const Value *V, Address &Addr) {
544 const User *U = nullptr;
545 unsigned Opcode = Instruction::UserOp1;
546
547 if (const auto *I = dyn_cast<Instruction>(V)) {
548 // Check if the value is defined in the same basic block. This information
549 // is crucial to know whether or not folding an operand is valid.
550 if (I->getParent() == FuncInfo.MBB->getBasicBlock()) {
551 Opcode = I->getOpcode();
552 U = I;
553 }
554 } else if (const auto *C = dyn_cast<ConstantExpr>(V)) {
555 Opcode = C->getOpcode();
556 U = C;
557 }
558
559 switch (Opcode) {
560 default:
561 break;
562 case Instruction::BitCast:
563 // Look past bitcasts if its operand is in the same BB.
564 return computeCallAddress(U->getOperand(0), Addr);
565 break;
566 case Instruction::IntToPtr:
567 // Look past no-op inttoptrs if its operand is in the same BB.
568 if (TLI.getValueType(DL, U->getOperand(0)->getType()) ==
569 TLI.getPointerTy(DL))
570 return computeCallAddress(U->getOperand(0), Addr);
571 break;
572 case Instruction::PtrToInt:
573 // Look past no-op ptrtoints if its operand is in the same BB.
574 if (TLI.getValueType(DL, U->getType()) == TLI.getPointerTy(DL))
575 return computeCallAddress(U->getOperand(0), Addr);
576 break;
577 }
578
579 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
580 Addr.setGlobalValue(GV);
581 return true;
582 }
583
584 // If all else fails, try to materialize the value in a register.
585 if (!Addr.getGlobalValue()) {
586 Addr.setReg(getRegForValue(V));
587 return Addr.getReg() != 0;
588 }
589
590 return false;
591}
592
593bool MipsFastISel::isTypeLegal(Type *Ty, MVT &VT) {
594 EVT evt = TLI.getValueType(DL, Ty, true);
595 // Only handle simple types.
596 if (evt == MVT::Other || !evt.isSimple())
597 return false;
598 VT = evt.getSimpleVT();
599
600 // Handle all legal types, i.e. a register that will directly hold this
601 // value.
602 return TLI.isTypeLegal(VT);
603}
604
605bool MipsFastISel::isTypeSupported(Type *Ty, MVT &VT) {
606 if (Ty->isVectorTy())
607 return false;
608
609 if (isTypeLegal(Ty, VT))
610 return true;
611
612 // If this is a type than can be sign or zero-extended to a basic operation
613 // go ahead and accept it now.
614 if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16)
615 return true;
616
617 return false;
618}
619
620bool MipsFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) {
621 if (isTypeLegal(Ty, VT))
622 return true;
623 // We will extend this in a later patch:
624 // If this is a type than can be sign or zero-extended to a basic operation
625 // go ahead and accept it now.
626 if (VT == MVT::i8 || VT == MVT::i16)
627 return true;
628 return false;
629}
630
631// Because of how EmitCmp is called with fast-isel, you can
632// end up with redundant "andi" instructions after the sequences emitted below.
633// We should try and solve this issue in the future.
634//
635bool MipsFastISel::emitCmp(unsigned ResultReg, const CmpInst *CI) {
636 const Value *Left = CI->getOperand(0), *Right = CI->getOperand(1);
637 bool IsUnsigned = CI->isUnsigned();
638 unsigned LeftReg = getRegEnsuringSimpleIntegerWidening(Left, IsUnsigned);
639 if (LeftReg == 0)
640 return false;
641 unsigned RightReg = getRegEnsuringSimpleIntegerWidening(Right, IsUnsigned);
642 if (RightReg == 0)
643 return false;
645
646 switch (P) {
647 default:
648 return false;
649 case CmpInst::ICMP_EQ: {
650 Register TempReg = createResultReg(&Mips::GPR32RegClass);
651 emitInst(Mips::XOR, TempReg).addReg(LeftReg).addReg(RightReg);
652 emitInst(Mips::SLTiu, ResultReg).addReg(TempReg).addImm(1);
653 break;
654 }
655 case CmpInst::ICMP_NE: {
656 Register TempReg = createResultReg(&Mips::GPR32RegClass);
657 emitInst(Mips::XOR, TempReg).addReg(LeftReg).addReg(RightReg);
658 emitInst(Mips::SLTu, ResultReg).addReg(Mips::ZERO).addReg(TempReg);
659 break;
660 }
662 emitInst(Mips::SLTu, ResultReg).addReg(RightReg).addReg(LeftReg);
663 break;
665 emitInst(Mips::SLTu, ResultReg).addReg(LeftReg).addReg(RightReg);
666 break;
667 case CmpInst::ICMP_UGE: {
668 Register TempReg = createResultReg(&Mips::GPR32RegClass);
669 emitInst(Mips::SLTu, TempReg).addReg(LeftReg).addReg(RightReg);
670 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
671 break;
672 }
673 case CmpInst::ICMP_ULE: {
674 Register TempReg = createResultReg(&Mips::GPR32RegClass);
675 emitInst(Mips::SLTu, TempReg).addReg(RightReg).addReg(LeftReg);
676 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
677 break;
678 }
680 emitInst(Mips::SLT, ResultReg).addReg(RightReg).addReg(LeftReg);
681 break;
683 emitInst(Mips::SLT, ResultReg).addReg(LeftReg).addReg(RightReg);
684 break;
685 case CmpInst::ICMP_SGE: {
686 Register TempReg = createResultReg(&Mips::GPR32RegClass);
687 emitInst(Mips::SLT, TempReg).addReg(LeftReg).addReg(RightReg);
688 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
689 break;
690 }
691 case CmpInst::ICMP_SLE: {
692 Register TempReg = createResultReg(&Mips::GPR32RegClass);
693 emitInst(Mips::SLT, TempReg).addReg(RightReg).addReg(LeftReg);
694 emitInst(Mips::XORi, ResultReg).addReg(TempReg).addImm(1);
695 break;
696 }
702 case CmpInst::FCMP_OGE: {
703 if (UnsupportedFPMode)
704 return false;
705 bool IsFloat = Left->getType()->isFloatTy();
706 bool IsDouble = Left->getType()->isDoubleTy();
707 if (!IsFloat && !IsDouble)
708 return false;
709 unsigned Opc, CondMovOpc;
710 switch (P) {
712 Opc = IsFloat ? Mips::C_EQ_S : Mips::C_EQ_D32;
713 CondMovOpc = Mips::MOVT_I;
714 break;
716 Opc = IsFloat ? Mips::C_EQ_S : Mips::C_EQ_D32;
717 CondMovOpc = Mips::MOVF_I;
718 break;
720 Opc = IsFloat ? Mips::C_OLT_S : Mips::C_OLT_D32;
721 CondMovOpc = Mips::MOVT_I;
722 break;
724 Opc = IsFloat ? Mips::C_OLE_S : Mips::C_OLE_D32;
725 CondMovOpc = Mips::MOVT_I;
726 break;
728 Opc = IsFloat ? Mips::C_ULE_S : Mips::C_ULE_D32;
729 CondMovOpc = Mips::MOVF_I;
730 break;
732 Opc = IsFloat ? Mips::C_ULT_S : Mips::C_ULT_D32;
733 CondMovOpc = Mips::MOVF_I;
734 break;
735 default:
736 llvm_unreachable("Only switching of a subset of CCs.");
737 }
738 Register RegWithZero = createResultReg(&Mips::GPR32RegClass);
739 Register RegWithOne = createResultReg(&Mips::GPR32RegClass);
740 emitInst(Mips::ADDiu, RegWithZero).addReg(Mips::ZERO).addImm(0);
741 emitInst(Mips::ADDiu, RegWithOne).addReg(Mips::ZERO).addImm(1);
742 emitInst(Opc).addReg(Mips::FCC0, RegState::Define).addReg(LeftReg)
743 .addReg(RightReg);
744 emitInst(CondMovOpc, ResultReg)
745 .addReg(RegWithOne)
746 .addReg(Mips::FCC0)
747 .addReg(RegWithZero);
748 break;
749 }
750 }
751 return true;
752}
753
754bool MipsFastISel::emitLoad(MVT VT, unsigned &ResultReg, Address &Addr) {
755 //
756 // more cases will be handled here in following patches.
757 //
758 unsigned Opc;
759 switch (VT.SimpleTy) {
760 case MVT::i32:
761 ResultReg = createResultReg(&Mips::GPR32RegClass);
762 Opc = Mips::LW;
763 break;
764 case MVT::i16:
765 ResultReg = createResultReg(&Mips::GPR32RegClass);
766 Opc = Mips::LHu;
767 break;
768 case MVT::i8:
769 ResultReg = createResultReg(&Mips::GPR32RegClass);
770 Opc = Mips::LBu;
771 break;
772 case MVT::f32:
773 if (UnsupportedFPMode)
774 return false;
775 ResultReg = createResultReg(&Mips::FGR32RegClass);
776 Opc = Mips::LWC1;
777 break;
778 case MVT::f64:
779 if (UnsupportedFPMode)
780 return false;
781 ResultReg = createResultReg(&Mips::AFGR64RegClass);
782 Opc = Mips::LDC1;
783 break;
784 default:
785 return false;
786 }
787 if (Addr.isRegBase()) {
788 simplifyAddress(Addr);
789 emitInstLoad(Opc, ResultReg, Addr.getReg(), Addr.getOffset());
790 return true;
791 }
792 if (Addr.isFIBase()) {
793 unsigned FI = Addr.getFI();
794 int64_t Offset = Addr.getOffset();
795 MachineFrameInfo &MFI = MF->getFrameInfo();
796 MachineMemOperand *MMO = MF->getMachineMemOperand(
798 MFI.getObjectSize(FI), Align(4));
799 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Opc), ResultReg)
800 .addFrameIndex(FI)
801 .addImm(Offset)
802 .addMemOperand(MMO);
803 return true;
804 }
805 return false;
806}
807
808bool MipsFastISel::emitStore(MVT VT, unsigned SrcReg, Address &Addr) {
809 //
810 // more cases will be handled here in following patches.
811 //
812 unsigned Opc;
813 switch (VT.SimpleTy) {
814 case MVT::i8:
815 Opc = Mips::SB;
816 break;
817 case MVT::i16:
818 Opc = Mips::SH;
819 break;
820 case MVT::i32:
821 Opc = Mips::SW;
822 break;
823 case MVT::f32:
824 if (UnsupportedFPMode)
825 return false;
826 Opc = Mips::SWC1;
827 break;
828 case MVT::f64:
829 if (UnsupportedFPMode)
830 return false;
831 Opc = Mips::SDC1;
832 break;
833 default:
834 return false;
835 }
836 if (Addr.isRegBase()) {
837 simplifyAddress(Addr);
838 emitInstStore(Opc, SrcReg, Addr.getReg(), Addr.getOffset());
839 return true;
840 }
841 if (Addr.isFIBase()) {
842 unsigned FI = Addr.getFI();
843 int64_t Offset = Addr.getOffset();
844 MachineFrameInfo &MFI = MF->getFrameInfo();
845 MachineMemOperand *MMO = MF->getMachineMemOperand(
847 MFI.getObjectSize(FI), Align(4));
848 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Opc))
849 .addReg(SrcReg)
850 .addFrameIndex(FI)
851 .addImm(Offset)
852 .addMemOperand(MMO);
853 return true;
854 }
855 return false;
856}
857
858bool MipsFastISel::selectLogicalOp(const Instruction *I) {
859 MVT VT;
860 if (!isTypeSupported(I->getType(), VT))
861 return false;
862
863 unsigned ResultReg;
864 switch (I->getOpcode()) {
865 default:
866 llvm_unreachable("Unexpected instruction.");
867 case Instruction::And:
868 ResultReg = emitLogicalOp(ISD::AND, VT, I->getOperand(0), I->getOperand(1));
869 break;
870 case Instruction::Or:
871 ResultReg = emitLogicalOp(ISD::OR, VT, I->getOperand(0), I->getOperand(1));
872 break;
873 case Instruction::Xor:
874 ResultReg = emitLogicalOp(ISD::XOR, VT, I->getOperand(0), I->getOperand(1));
875 break;
876 }
877
878 if (!ResultReg)
879 return false;
880
881 updateValueMap(I, ResultReg);
882 return true;
883}
884
885bool MipsFastISel::selectLoad(const Instruction *I) {
886 const LoadInst *LI = cast<LoadInst>(I);
887
888 // Atomic loads need special handling.
889 if (LI->isAtomic())
890 return false;
891
892 // Verify we have a legal type before going any further.
893 MVT VT;
894 if (!isLoadTypeLegal(LI->getType(), VT))
895 return false;
896
897 // Underaligned loads need special handling.
898 if (LI->getAlign() < VT.getFixedSizeInBits() / 8 &&
899 !Subtarget->systemSupportsUnalignedAccess())
900 return false;
901
902 // See if we can handle this address.
903 Address Addr;
904 if (!computeAddress(LI->getOperand(0), Addr))
905 return false;
906
907 unsigned ResultReg;
908 if (!emitLoad(VT, ResultReg, Addr))
909 return false;
910 updateValueMap(LI, ResultReg);
911 return true;
912}
913
914bool MipsFastISel::selectStore(const Instruction *I) {
915 const StoreInst *SI = cast<StoreInst>(I);
916
917 Value *Op0 = SI->getOperand(0);
918 unsigned SrcReg = 0;
919
920 // Atomic stores need special handling.
921 if (SI->isAtomic())
922 return false;
923
924 // Verify we have a legal type before going any further.
925 MVT VT;
926 if (!isLoadTypeLegal(SI->getOperand(0)->getType(), VT))
927 return false;
928
929 // Underaligned stores need special handling.
930 if (SI->getAlign() < VT.getFixedSizeInBits() / 8 &&
931 !Subtarget->systemSupportsUnalignedAccess())
932 return false;
933
934 // Get the value to be stored into a register.
935 SrcReg = getRegForValue(Op0);
936 if (SrcReg == 0)
937 return false;
938
939 // See if we can handle this address.
940 Address Addr;
941 if (!computeAddress(SI->getOperand(1), Addr))
942 return false;
943
944 if (!emitStore(VT, SrcReg, Addr))
945 return false;
946 return true;
947}
948
949// This can cause a redundant sltiu to be generated.
950// FIXME: try and eliminate this in a future patch.
951bool MipsFastISel::selectBranch(const Instruction *I) {
952 const CondBrInst *BI = cast<CondBrInst>(I);
953 MachineBasicBlock *BrBB = FuncInfo.MBB;
954 //
955 // TBB is the basic block for the case where the comparison is true.
956 // FBB is the basic block for the case where the comparison is false.
957 // if (cond) goto TBB
958 // goto FBB
959 // TBB:
960 //
961 MachineBasicBlock *TBB = FuncInfo.getMBB(BI->getSuccessor(0));
962 MachineBasicBlock *FBB = FuncInfo.getMBB(BI->getSuccessor(1));
963
964 // Fold the common case of a conditional branch with a comparison
965 // in the same block.
966 unsigned ZExtCondReg = 0;
967 if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
968 if (CI->hasOneUse() && CI->getParent() == I->getParent()) {
969 ZExtCondReg = createResultReg(&Mips::GPR32RegClass);
970 if (!emitCmp(ZExtCondReg, CI))
971 return false;
972 }
973 }
974
975 // For the general case, we need to mask with 1.
976 if (ZExtCondReg == 0) {
977 Register CondReg = getRegForValue(BI->getCondition());
978 if (CondReg == 0)
979 return false;
980
981 ZExtCondReg = emitIntExt(MVT::i1, CondReg, MVT::i32, true);
982 if (ZExtCondReg == 0)
983 return false;
984 }
985
986 BuildMI(*BrBB, FuncInfo.InsertPt, MIMD, TII.get(Mips::BGTZ))
987 .addReg(ZExtCondReg)
988 .addMBB(TBB);
989 finishCondBranch(BI->getParent(), TBB, FBB);
990 return true;
991}
992
993bool MipsFastISel::selectCmp(const Instruction *I) {
994 const CmpInst *CI = cast<CmpInst>(I);
995 Register ResultReg = createResultReg(&Mips::GPR32RegClass);
996 if (!emitCmp(ResultReg, CI))
997 return false;
998 updateValueMap(I, ResultReg);
999 return true;
1000}
1001
1002// Attempt to fast-select a floating-point extend instruction.
1003bool MipsFastISel::selectFPExt(const Instruction *I) {
1004 if (UnsupportedFPMode)
1005 return false;
1006 Value *Src = I->getOperand(0);
1007 EVT SrcVT = TLI.getValueType(DL, Src->getType(), true);
1008 EVT DestVT = TLI.getValueType(DL, I->getType(), true);
1009
1010 if (SrcVT != MVT::f32 || DestVT != MVT::f64)
1011 return false;
1012
1013 Register SrcReg =
1014 getRegForValue(Src); // this must be a 32bit floating point register class
1015 // maybe we should handle this differently
1016 if (!SrcReg)
1017 return false;
1018
1019 Register DestReg = createResultReg(&Mips::AFGR64RegClass);
1020 emitInst(Mips::CVT_D32_S, DestReg).addReg(SrcReg);
1021 updateValueMap(I, DestReg);
1022 return true;
1023}
1024
1025bool MipsFastISel::selectSelect(const Instruction *I) {
1026 assert(isa<SelectInst>(I) && "Expected a select instruction.");
1027
1028 LLVM_DEBUG(dbgs() << "selectSelect\n");
1029
1030 MVT VT;
1031 if (!isTypeSupported(I->getType(), VT) || UnsupportedFPMode) {
1032 LLVM_DEBUG(
1033 dbgs() << ".. .. gave up (!isTypeSupported || UnsupportedFPMode)\n");
1034 return false;
1035 }
1036
1037 unsigned CondMovOpc;
1038 const TargetRegisterClass *RC;
1039
1040 if (VT.isInteger() && !VT.isVector() && VT.getSizeInBits() <= 32) {
1041 CondMovOpc = Mips::MOVN_I_I;
1042 RC = &Mips::GPR32RegClass;
1043 } else if (VT == MVT::f32) {
1044 CondMovOpc = Mips::MOVN_I_S;
1045 RC = &Mips::FGR32RegClass;
1046 } else if (VT == MVT::f64) {
1047 CondMovOpc = Mips::MOVN_I_D32;
1048 RC = &Mips::AFGR64RegClass;
1049 } else
1050 return false;
1051
1052 const SelectInst *SI = cast<SelectInst>(I);
1053 const Value *Cond = SI->getCondition();
1054 Register Src1Reg = getRegForValue(SI->getTrueValue());
1055 Register Src2Reg = getRegForValue(SI->getFalseValue());
1056 Register CondReg = getRegForValue(Cond);
1057
1058 if (!Src1Reg || !Src2Reg || !CondReg)
1059 return false;
1060
1061 Register ZExtCondReg = createResultReg(&Mips::GPR32RegClass);
1062 if (!ZExtCondReg)
1063 return false;
1064
1065 if (!emitIntExt(MVT::i1, CondReg, MVT::i32, ZExtCondReg, true))
1066 return false;
1067
1068 Register ResultReg = createResultReg(RC);
1069 Register TempReg = createResultReg(RC);
1070
1071 if (!ResultReg || !TempReg)
1072 return false;
1073
1074 emitInst(TargetOpcode::COPY, TempReg).addReg(Src2Reg);
1075 emitInst(CondMovOpc, ResultReg)
1076 .addReg(Src1Reg).addReg(ZExtCondReg).addReg(TempReg);
1077 updateValueMap(I, ResultReg);
1078 return true;
1079}
1080
1081// Attempt to fast-select a floating-point truncate instruction.
1082bool MipsFastISel::selectFPTrunc(const Instruction *I) {
1083 if (UnsupportedFPMode)
1084 return false;
1085 Value *Src = I->getOperand(0);
1086 EVT SrcVT = TLI.getValueType(DL, Src->getType(), true);
1087 EVT DestVT = TLI.getValueType(DL, I->getType(), true);
1088
1089 if (SrcVT != MVT::f64 || DestVT != MVT::f32)
1090 return false;
1091
1092 Register SrcReg = getRegForValue(Src);
1093 if (!SrcReg)
1094 return false;
1095
1096 Register DestReg = createResultReg(&Mips::FGR32RegClass);
1097 if (!DestReg)
1098 return false;
1099
1100 emitInst(Mips::CVT_S_D32, DestReg).addReg(SrcReg);
1101 updateValueMap(I, DestReg);
1102 return true;
1103}
1104
1105// Attempt to fast-select a floating-point-to-integer conversion.
1106bool MipsFastISel::selectFPToInt(const Instruction *I, bool IsSigned) {
1107 if (UnsupportedFPMode)
1108 return false;
1109 MVT DstVT, SrcVT;
1110 if (!IsSigned)
1111 return false; // We don't handle this case yet. There is no native
1112 // instruction for this but it can be synthesized.
1113 Type *DstTy = I->getType();
1114 if (!isTypeLegal(DstTy, DstVT))
1115 return false;
1116
1117 if (DstVT != MVT::i32)
1118 return false;
1119
1120 Value *Src = I->getOperand(0);
1121 Type *SrcTy = Src->getType();
1122 if (!isTypeLegal(SrcTy, SrcVT))
1123 return false;
1124
1125 if (SrcVT != MVT::f32 && SrcVT != MVT::f64)
1126 return false;
1127
1128 Register SrcReg = getRegForValue(Src);
1129 if (SrcReg == 0)
1130 return false;
1131
1132 // Determine the opcode for the conversion, which takes place
1133 // entirely within FPRs.
1134 Register DestReg = createResultReg(&Mips::GPR32RegClass);
1135 Register TempReg = createResultReg(&Mips::FGR32RegClass);
1136 unsigned Opc = (SrcVT == MVT::f32) ? Mips::TRUNC_W_S : Mips::TRUNC_W_D32;
1137
1138 // Generate the convert.
1139 emitInst(Opc, TempReg).addReg(SrcReg);
1140 emitInst(Mips::MFC1, DestReg).addReg(TempReg);
1141
1142 updateValueMap(I, DestReg);
1143 return true;
1144}
1145
1146bool MipsFastISel::processCallArgs(CallLoweringInfo &CLI,
1147 SmallVectorImpl<MVT> &OutVTs,
1148 unsigned &NumBytes) {
1149 CallingConv::ID CC = CLI.CallConv;
1152 for (const ArgListEntry &Arg : CLI.Args)
1153 ArgTys.push_back(Arg.Val->getType());
1154 CCState CCInfo(CC, false, *FuncInfo.MF, ArgLocs, *Context);
1155 CCInfo.AnalyzeCallOperands(OutVTs, CLI.OutFlags, ArgTys,
1156 CCAssignFnForCall(CC));
1157 // Get a count of how many bytes are to be pushed on the stack.
1158 NumBytes = CCInfo.getStackSize();
1159 // This is the minimum argument area used for A0-A3.
1160 if (NumBytes < 16)
1161 NumBytes = 16;
1162
1163 emitInst(Mips::ADJCALLSTACKDOWN).addImm(16).addImm(0);
1164 // Process the args.
1165 MVT firstMVT;
1166 for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
1167 CCValAssign &VA = ArgLocs[i];
1168 const Value *ArgVal = CLI.OutVals[VA.getValNo()];
1169 MVT ArgVT = OutVTs[VA.getValNo()];
1170
1171 if (i == 0) {
1172 firstMVT = ArgVT;
1173 if (ArgVT == MVT::f32) {
1174 VA.convertToReg(Mips::F12);
1175 } else if (ArgVT == MVT::f64) {
1176 if (Subtarget->isFP64bit())
1177 VA.convertToReg(Mips::D6_64);
1178 else
1179 VA.convertToReg(Mips::D6);
1180 }
1181 } else if (i == 1) {
1182 if ((firstMVT == MVT::f32) || (firstMVT == MVT::f64)) {
1183 if (ArgVT == MVT::f32) {
1184 VA.convertToReg(Mips::F14);
1185 } else if (ArgVT == MVT::f64) {
1186 if (Subtarget->isFP64bit())
1187 VA.convertToReg(Mips::D7_64);
1188 else
1189 VA.convertToReg(Mips::D7);
1190 }
1191 }
1192 }
1193 if (((ArgVT == MVT::i32) || (ArgVT == MVT::f32) || (ArgVT == MVT::i16) ||
1194 (ArgVT == MVT::i8)) &&
1195 VA.isMemLoc()) {
1196 switch (VA.getLocMemOffset()) {
1197 case 0:
1198 VA.convertToReg(Mips::A0);
1199 break;
1200 case 4:
1201 VA.convertToReg(Mips::A1);
1202 break;
1203 case 8:
1204 VA.convertToReg(Mips::A2);
1205 break;
1206 case 12:
1207 VA.convertToReg(Mips::A3);
1208 break;
1209 default:
1210 break;
1211 }
1212 }
1213 Register ArgReg = getRegForValue(ArgVal);
1214 if (!ArgReg)
1215 return false;
1216
1217 // Handle arg promotion: SExt, ZExt, AExt.
1218 switch (VA.getLocInfo()) {
1219 case CCValAssign::Full:
1220 break;
1221 case CCValAssign::AExt:
1222 case CCValAssign::SExt: {
1223 MVT DestVT = VA.getLocVT();
1224 MVT SrcVT = ArgVT;
1225 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT, /*isZExt=*/false);
1226 if (!ArgReg)
1227 return false;
1228 break;
1229 }
1230 case CCValAssign::ZExt: {
1231 MVT DestVT = VA.getLocVT();
1232 MVT SrcVT = ArgVT;
1233 ArgReg = emitIntExt(SrcVT, ArgReg, DestVT, /*isZExt=*/true);
1234 if (!ArgReg)
1235 return false;
1236 break;
1237 }
1238 default:
1239 llvm_unreachable("Unknown arg promotion!");
1240 }
1241
1242 // Now copy/store arg to correct locations.
1243 if (VA.isRegLoc() && !VA.needsCustom()) {
1244 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1245 TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(ArgReg);
1246 CLI.OutRegs.push_back(VA.getLocReg());
1247 } else if (VA.needsCustom()) {
1248 llvm_unreachable("Mips does not use custom args.");
1249 return false;
1250 } else {
1251 //
1252 // FIXME: This path will currently return false. It was copied
1253 // from the AArch64 port and should be essentially fine for Mips too.
1254 // The work to finish up this path will be done in a follow-on patch.
1255 //
1256 assert(VA.isMemLoc() && "Assuming store on stack.");
1257 // Don't emit stores for undef values.
1258 if (isa<UndefValue>(ArgVal))
1259 continue;
1260
1261 // Need to store on the stack.
1262 // FIXME: This alignment is incorrect but this path is disabled
1263 // for now (will return false). We need to determine the right alignment
1264 // based on the normal alignment for the underlying machine type.
1265 //
1266 unsigned ArgSize = alignTo(ArgVT.getSizeInBits(), 4);
1267
1268 unsigned BEAlign = 0;
1269 if (ArgSize < 8 && !Subtarget->isLittle())
1270 BEAlign = 8 - ArgSize;
1271
1272 Address Addr;
1273 Addr.setKind(Address::RegBase);
1274 Addr.setReg(Mips::SP);
1275 Addr.setOffset(VA.getLocMemOffset() + BEAlign);
1276
1277 Align Alignment = DL.getABITypeAlign(ArgVal->getType());
1278 MachineMemOperand *MMO = FuncInfo.MF->getMachineMemOperand(
1279 MachinePointerInfo::getStack(*FuncInfo.MF, Addr.getOffset()),
1280 MachineMemOperand::MOStore, ArgVT.getStoreSize(), Alignment);
1281 (void)(MMO);
1282 // if (!emitStore(ArgVT, ArgReg, Addr, MMO))
1283 return false; // can't store on the stack yet.
1284 }
1285 }
1286
1287 return true;
1288}
1289
1290bool MipsFastISel::finishCall(CallLoweringInfo &CLI, MVT RetVT,
1291 unsigned NumBytes) {
1292 CallingConv::ID CC = CLI.CallConv;
1293 emitInst(Mips::ADJCALLSTACKUP).addImm(16).addImm(0);
1294 if (RetVT != MVT::isVoid) {
1296 MipsCCState CCInfo(CC, false, *FuncInfo.MF, RVLocs, *Context);
1297
1298 CCInfo.AnalyzeCallResult(CLI.Ins, RetCC_Mips);
1299
1300 // Only handle a single return value.
1301 if (RVLocs.size() != 1)
1302 return false;
1303 // Copy all of the result registers out of their specified physreg.
1304 MVT CopyVT = RVLocs[0].getValVT();
1305 // Special handling for extended integers.
1306 if (RetVT == MVT::i1 || RetVT == MVT::i8 || RetVT == MVT::i16)
1307 CopyVT = MVT::i32;
1308
1309 Register ResultReg = createResultReg(TLI.getRegClassFor(CopyVT));
1310 if (!ResultReg)
1311 return false;
1312 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1313 TII.get(TargetOpcode::COPY),
1314 ResultReg).addReg(RVLocs[0].getLocReg());
1315 CLI.InRegs.push_back(RVLocs[0].getLocReg());
1316
1317 CLI.ResultReg = ResultReg;
1318 CLI.NumResultRegs = 1;
1319 }
1320 return true;
1321}
1322
1323bool MipsFastISel::fastLowerArguments() {
1324 LLVM_DEBUG(dbgs() << "fastLowerArguments\n");
1325
1326 if (!FuncInfo.CanLowerReturn) {
1327 LLVM_DEBUG(dbgs() << ".. gave up (!CanLowerReturn)\n");
1328 return false;
1329 }
1330
1331 const Function *F = FuncInfo.Fn;
1332 if (F->isVarArg()) {
1333 LLVM_DEBUG(dbgs() << ".. gave up (varargs)\n");
1334 return false;
1335 }
1336
1337 CallingConv::ID CC = F->getCallingConv();
1338 if (CC != CallingConv::C) {
1339 LLVM_DEBUG(dbgs() << ".. gave up (calling convention is not C)\n");
1340 return false;
1341 }
1342
1343 std::array<MCPhysReg, 4> GPR32ArgRegs = {{Mips::A0, Mips::A1, Mips::A2,
1344 Mips::A3}};
1345 std::array<MCPhysReg, 2> FGR32ArgRegs = {{Mips::F12, Mips::F14}};
1346 std::array<MCPhysReg, 2> AFGR64ArgRegs = {{Mips::D6, Mips::D7}};
1347 auto NextGPR32 = GPR32ArgRegs.begin();
1348 auto NextFGR32 = FGR32ArgRegs.begin();
1349 auto NextAFGR64 = AFGR64ArgRegs.begin();
1350
1351 struct AllocatedReg {
1352 const TargetRegisterClass *RC;
1353 unsigned Reg;
1354 AllocatedReg(const TargetRegisterClass *RC, unsigned Reg)
1355 : RC(RC), Reg(Reg) {}
1356 };
1357
1358 // Only handle simple cases. i.e. All arguments are directly mapped to
1359 // registers of the appropriate type.
1361 for (const auto &FormalArg : F->args()) {
1362 if (FormalArg.hasAttribute(Attribute::InReg) ||
1363 FormalArg.hasAttribute(Attribute::StructRet) ||
1364 FormalArg.hasAttribute(Attribute::ByVal)) {
1365 LLVM_DEBUG(dbgs() << ".. gave up (inreg, structret, byval)\n");
1366 return false;
1367 }
1368
1369 Type *ArgTy = FormalArg.getType();
1370 if (ArgTy->isStructTy() || ArgTy->isArrayTy() || ArgTy->isVectorTy()) {
1371 LLVM_DEBUG(dbgs() << ".. gave up (struct, array, or vector)\n");
1372 return false;
1373 }
1374
1375 EVT ArgVT = TLI.getValueType(DL, ArgTy);
1376 LLVM_DEBUG(dbgs() << ".. " << FormalArg.getArgNo() << ": "
1377 << ArgVT << "\n");
1378 if (!ArgVT.isSimple()) {
1379 LLVM_DEBUG(dbgs() << ".. .. gave up (not a simple type)\n");
1380 return false;
1381 }
1382
1383 switch (ArgVT.getSimpleVT().SimpleTy) {
1384 case MVT::i1:
1385 case MVT::i8:
1386 case MVT::i16:
1387 if (!FormalArg.hasAttribute(Attribute::SExt) &&
1388 !FormalArg.hasAttribute(Attribute::ZExt)) {
1389 // It must be any extend, this shouldn't happen for clang-generated IR
1390 // so just fall back on SelectionDAG.
1391 LLVM_DEBUG(dbgs() << ".. .. gave up (i8/i16 arg is not extended)\n");
1392 return false;
1393 }
1394
1395 if (NextGPR32 == GPR32ArgRegs.end()) {
1396 LLVM_DEBUG(dbgs() << ".. .. gave up (ran out of GPR32 arguments)\n");
1397 return false;
1398 }
1399
1400 LLVM_DEBUG(dbgs() << ".. .. GPR32(" << *NextGPR32 << ")\n");
1401 Allocation.emplace_back(&Mips::GPR32RegClass, *NextGPR32++);
1402
1403 // Allocating any GPR32 prohibits further use of floating point arguments.
1404 NextFGR32 = FGR32ArgRegs.end();
1405 NextAFGR64 = AFGR64ArgRegs.end();
1406 break;
1407
1408 case MVT::i32:
1409 if (FormalArg.hasAttribute(Attribute::ZExt)) {
1410 // The O32 ABI does not permit a zero-extended i32.
1411 LLVM_DEBUG(dbgs() << ".. .. gave up (i32 arg is zero extended)\n");
1412 return false;
1413 }
1414
1415 if (NextGPR32 == GPR32ArgRegs.end()) {
1416 LLVM_DEBUG(dbgs() << ".. .. gave up (ran out of GPR32 arguments)\n");
1417 return false;
1418 }
1419
1420 LLVM_DEBUG(dbgs() << ".. .. GPR32(" << *NextGPR32 << ")\n");
1421 Allocation.emplace_back(&Mips::GPR32RegClass, *NextGPR32++);
1422
1423 // Allocating any GPR32 prohibits further use of floating point arguments.
1424 NextFGR32 = FGR32ArgRegs.end();
1425 NextAFGR64 = AFGR64ArgRegs.end();
1426 break;
1427
1428 case MVT::f32:
1429 if (UnsupportedFPMode) {
1430 LLVM_DEBUG(dbgs() << ".. .. gave up (UnsupportedFPMode)\n");
1431 return false;
1432 }
1433 if (NextFGR32 == FGR32ArgRegs.end()) {
1434 LLVM_DEBUG(dbgs() << ".. .. gave up (ran out of FGR32 arguments)\n");
1435 return false;
1436 }
1437 LLVM_DEBUG(dbgs() << ".. .. FGR32(" << *NextFGR32 << ")\n");
1438 Allocation.emplace_back(&Mips::FGR32RegClass, *NextFGR32++);
1439 // Allocating an FGR32 also allocates the super-register AFGR64, and
1440 // ABI rules require us to skip the corresponding GPR32.
1441 if (NextGPR32 != GPR32ArgRegs.end())
1442 NextGPR32++;
1443 if (NextAFGR64 != AFGR64ArgRegs.end())
1444 NextAFGR64++;
1445 break;
1446
1447 case MVT::f64:
1448 if (UnsupportedFPMode) {
1449 LLVM_DEBUG(dbgs() << ".. .. gave up (UnsupportedFPMode)\n");
1450 return false;
1451 }
1452 if (NextAFGR64 == AFGR64ArgRegs.end()) {
1453 LLVM_DEBUG(dbgs() << ".. .. gave up (ran out of AFGR64 arguments)\n");
1454 return false;
1455 }
1456 LLVM_DEBUG(dbgs() << ".. .. AFGR64(" << *NextAFGR64 << ")\n");
1457 Allocation.emplace_back(&Mips::AFGR64RegClass, *NextAFGR64++);
1458 // Allocating an FGR32 also allocates the super-register AFGR64, and
1459 // ABI rules require us to skip the corresponding GPR32 pair.
1460 if (NextGPR32 != GPR32ArgRegs.end())
1461 NextGPR32++;
1462 if (NextGPR32 != GPR32ArgRegs.end())
1463 NextGPR32++;
1464 if (NextFGR32 != FGR32ArgRegs.end())
1465 NextFGR32++;
1466 break;
1467
1468 default:
1469 LLVM_DEBUG(dbgs() << ".. .. gave up (unknown type)\n");
1470 return false;
1471 }
1472 }
1473
1474 for (const auto &FormalArg : F->args()) {
1475 unsigned ArgNo = FormalArg.getArgNo();
1476 unsigned SrcReg = Allocation[ArgNo].Reg;
1477 Register DstReg = FuncInfo.MF->addLiveIn(SrcReg, Allocation[ArgNo].RC);
1478 // FIXME: Unfortunately it's necessary to emit a copy from the livein copy.
1479 // Without this, EmitLiveInCopies may eliminate the livein if its only
1480 // use is a bitcast (which isn't turned into an instruction).
1481 Register ResultReg = createResultReg(Allocation[ArgNo].RC);
1482 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1483 TII.get(TargetOpcode::COPY), ResultReg)
1484 .addReg(DstReg, getKillRegState(true));
1485 updateValueMap(&FormalArg, ResultReg);
1486 }
1487
1488 // Calculate the size of the incoming arguments area.
1489 // We currently reject all the cases where this would be non-zero.
1490 unsigned IncomingArgSizeInBytes = 0;
1491
1492 // Account for the reserved argument area on ABI's that have one (O32).
1493 // It seems strange to do this on the caller side but it's necessary in
1494 // SelectionDAG's implementation.
1495 IncomingArgSizeInBytes = std::max(getABI().GetCalleeAllocdArgSizeInBytes(CC),
1496 IncomingArgSizeInBytes);
1497
1498 MF->getInfo<MipsFunctionInfo>()->setFormalArgInfo(IncomingArgSizeInBytes,
1499 false);
1500
1501 return true;
1502}
1503
1504bool MipsFastISel::fastLowerCall(CallLoweringInfo &CLI) {
1505 CallingConv::ID CC = CLI.CallConv;
1506 bool IsTailCall = CLI.IsTailCall;
1507 bool IsVarArg = CLI.IsVarArg;
1508 const Value *Callee = CLI.Callee;
1509 MCSymbol *Symbol = CLI.Symbol;
1510
1511 // Do not handle FastCC.
1512 if (CC == CallingConv::Fast)
1513 return false;
1514
1515 // Allow SelectionDAG isel to handle tail calls.
1516 if (IsTailCall)
1517 return false;
1518
1519 // Let SDISel handle vararg functions.
1520 if (IsVarArg)
1521 return false;
1522
1523 // FIXME: Only handle *simple* calls for now.
1524 MVT RetVT;
1525 if (CLI.RetTy->isVoidTy())
1526 RetVT = MVT::isVoid;
1527 else if (!isTypeSupported(CLI.RetTy, RetVT))
1528 return false;
1529
1530 for (auto Flag : CLI.OutFlags)
1531 if (Flag.isInReg() || Flag.isSRet() || Flag.isNest() || Flag.isByVal())
1532 return false;
1533
1534 // Set up the argument vectors.
1535 SmallVector<MVT, 16> OutVTs;
1536 OutVTs.reserve(CLI.OutVals.size());
1537
1538 for (auto *Val : CLI.OutVals) {
1539 MVT VT;
1540 if (!isTypeLegal(Val->getType(), VT) &&
1541 !(VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16))
1542 return false;
1543
1544 // We don't handle vector parameters yet.
1545 if (VT.isVector() || VT.getSizeInBits() > 64)
1546 return false;
1547
1548 OutVTs.push_back(VT);
1549 }
1550
1551 Address Addr;
1552 if (!computeCallAddress(Callee, Addr))
1553 return false;
1554
1555 // Handle the arguments now that we've gotten them.
1556 unsigned NumBytes;
1557 if (!processCallArgs(CLI, OutVTs, NumBytes))
1558 return false;
1559
1560 if (!Addr.getGlobalValue())
1561 return false;
1562
1563 // Issue the call.
1564 unsigned DestAddress;
1565 if (Symbol)
1566 DestAddress = materializeExternalCallSym(Symbol);
1567 else
1568 DestAddress = materializeGV(Addr.getGlobalValue(), MVT::i32);
1569 emitInst(TargetOpcode::COPY, Mips::T9).addReg(DestAddress);
1570 MachineInstrBuilder MIB =
1571 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Mips::JALR),
1572 Mips::RA).addReg(Mips::T9);
1573
1574 // Add implicit physical register uses to the call.
1575 for (auto Reg : CLI.OutRegs)
1576 MIB.addReg(Reg, RegState::Implicit);
1577
1578 // Add a register mask with the call-preserved registers.
1579 // Proper defs for return values will be added by setPhysRegsDeadExcept().
1580 MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC));
1581
1582 CLI.Call = MIB;
1583
1584 if (EmitJalrReloc && !Subtarget->inMips16Mode()) {
1585 // Attach callee address to the instruction, let asm printer emit
1586 // .reloc R_MIPS_JALR.
1587 if (Symbol)
1588 MIB.addSym(Symbol, MipsII::MO_JALR);
1589 else
1590 MIB.addSym(FuncInfo.MF->getContext().getOrCreateSymbol(
1591 Addr.getGlobalValue()->getName()), MipsII::MO_JALR);
1592 }
1593
1594 // Finish off the call including any return values.
1595 return finishCall(CLI, RetVT, NumBytes);
1596}
1597
1598bool MipsFastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
1599 switch (II->getIntrinsicID()) {
1600 default:
1601 return false;
1602 case Intrinsic::bswap: {
1603 Type *RetTy = II->getCalledFunction()->getReturnType();
1604
1605 MVT VT;
1606 if (!isTypeSupported(RetTy, VT))
1607 return false;
1608
1609 Register SrcReg = getRegForValue(II->getOperand(0));
1610 if (SrcReg == 0)
1611 return false;
1612 Register DestReg = createResultReg(&Mips::GPR32RegClass);
1613 if (DestReg == 0)
1614 return false;
1615 if (VT == MVT::i16) {
1616 if (Subtarget->hasMips32r2()) {
1617 emitInst(Mips::WSBH, DestReg).addReg(SrcReg);
1618 updateValueMap(II, DestReg);
1619 return true;
1620 } else {
1621 unsigned TempReg[3];
1622 for (unsigned &R : TempReg) {
1623 R = createResultReg(&Mips::GPR32RegClass);
1624 if (R == 0)
1625 return false;
1626 }
1627 emitInst(Mips::SLL, TempReg[0]).addReg(SrcReg).addImm(8);
1628 emitInst(Mips::SRL, TempReg[1]).addReg(SrcReg).addImm(8);
1629 emitInst(Mips::ANDi, TempReg[2]).addReg(TempReg[1]).addImm(0xFF);
1630 emitInst(Mips::OR, DestReg).addReg(TempReg[0]).addReg(TempReg[2]);
1631 updateValueMap(II, DestReg);
1632 return true;
1633 }
1634 } else if (VT == MVT::i32) {
1635 if (Subtarget->hasMips32r2()) {
1636 Register TempReg = createResultReg(&Mips::GPR32RegClass);
1637 emitInst(Mips::WSBH, TempReg).addReg(SrcReg);
1638 emitInst(Mips::ROTR, DestReg).addReg(TempReg).addImm(16);
1639 updateValueMap(II, DestReg);
1640 return true;
1641 } else {
1642 unsigned TempReg[8];
1643 for (unsigned &R : TempReg) {
1644 R = createResultReg(&Mips::GPR32RegClass);
1645 if (R == 0)
1646 return false;
1647 }
1648
1649 emitInst(Mips::SRL, TempReg[0]).addReg(SrcReg).addImm(8);
1650 emitInst(Mips::SRL, TempReg[1]).addReg(SrcReg).addImm(24);
1651 emitInst(Mips::ANDi, TempReg[2]).addReg(TempReg[0]).addImm(0xFF00);
1652 emitInst(Mips::OR, TempReg[3]).addReg(TempReg[1]).addReg(TempReg[2]);
1653
1654 emitInst(Mips::ANDi, TempReg[4]).addReg(SrcReg).addImm(0xFF00);
1655 emitInst(Mips::SLL, TempReg[5]).addReg(TempReg[4]).addImm(8);
1656
1657 emitInst(Mips::SLL, TempReg[6]).addReg(SrcReg).addImm(24);
1658 emitInst(Mips::OR, TempReg[7]).addReg(TempReg[3]).addReg(TempReg[5]);
1659 emitInst(Mips::OR, DestReg).addReg(TempReg[6]).addReg(TempReg[7]);
1660 updateValueMap(II, DestReg);
1661 return true;
1662 }
1663 }
1664 return false;
1665 }
1666 case Intrinsic::memcpy:
1667 case Intrinsic::memmove: {
1668 const auto *MTI = cast<MemTransferInst>(II);
1669 // Don't handle volatile.
1670 if (MTI->isVolatile())
1671 return false;
1672 if (!MTI->getLength()->getType()->isIntegerTy(32))
1673 return false;
1674 const char *IntrMemName = isa<MemCpyInst>(II) ? "memcpy" : "memmove";
1675 return lowerCallTo(II, IntrMemName, II->arg_size() - 1);
1676 }
1677 case Intrinsic::memset: {
1678 const MemSetInst *MSI = cast<MemSetInst>(II);
1679 // Don't handle volatile.
1680 if (MSI->isVolatile())
1681 return false;
1682 if (!MSI->getLength()->getType()->isIntegerTy(32))
1683 return false;
1684 return lowerCallTo(II, "memset", II->arg_size() - 1);
1685 }
1686 }
1687 return false;
1688}
1689
1690bool MipsFastISel::selectRet(const Instruction *I) {
1691 const Function &F = *I->getParent()->getParent();
1692 const ReturnInst *Ret = cast<ReturnInst>(I);
1693
1694 LLVM_DEBUG(dbgs() << "selectRet\n");
1695
1696 if (!FuncInfo.CanLowerReturn)
1697 return false;
1698
1699 // Build a list of return value registers.
1700 SmallVector<unsigned, 4> RetRegs;
1701
1702 if (Ret->getNumOperands() > 0) {
1703 CallingConv::ID CC = F.getCallingConv();
1704
1705 // Do not handle FastCC.
1706 if (CC == CallingConv::Fast)
1707 return false;
1708
1710 GetReturnInfo(CC, F.getReturnType(), F.getAttributes(), Outs, TLI, DL);
1711
1712 // Analyze operands of the call, assigning locations to each operand.
1714 MipsCCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, ValLocs,
1715 I->getContext());
1716 CCAssignFn *RetCC = RetCC_Mips;
1717 CCInfo.AnalyzeReturn(Outs, RetCC);
1718
1719 // Only handle a single return value for now.
1720 if (ValLocs.size() != 1)
1721 return false;
1722
1723 CCValAssign &VA = ValLocs[0];
1724 const Value *RV = Ret->getOperand(0);
1725
1726 // Don't bother handling odd stuff for now.
1727 if ((VA.getLocInfo() != CCValAssign::Full) &&
1728 (VA.getLocInfo() != CCValAssign::BCvt))
1729 return false;
1730
1731 // Only handle register returns for now.
1732 if (!VA.isRegLoc())
1733 return false;
1734
1735 Register Reg = getRegForValue(RV);
1736 if (Reg == 0)
1737 return false;
1738
1739 unsigned SrcReg = Reg + VA.getValNo();
1740 Register DestReg = VA.getLocReg();
1741 // Avoid a cross-class copy. This is very unlikely.
1742 if (!MRI.getRegClass(SrcReg)->contains(DestReg))
1743 return false;
1744
1745 EVT RVEVT = TLI.getValueType(DL, RV->getType());
1746 if (!RVEVT.isSimple())
1747 return false;
1748
1749 if (RVEVT.isVector())
1750 return false;
1751
1752 MVT RVVT = RVEVT.getSimpleVT();
1753 if (RVVT == MVT::f128)
1754 return false;
1755
1756 // Do not handle FGR64 returns for now.
1757 if (RVVT == MVT::f64 && UnsupportedFPMode) {
1758 LLVM_DEBUG(dbgs() << ".. .. gave up (UnsupportedFPMode\n");
1759 return false;
1760 }
1761
1762 MVT DestVT = VA.getValVT();
1763 // Special handling for extended integers.
1764 if (RVVT != DestVT) {
1765 if (RVVT != MVT::i1 && RVVT != MVT::i8 && RVVT != MVT::i16)
1766 return false;
1767
1768 if (Outs[0].Flags.isZExt() || Outs[0].Flags.isSExt()) {
1769 bool IsZExt = Outs[0].Flags.isZExt();
1770 SrcReg = emitIntExt(RVVT, SrcReg, DestVT, IsZExt);
1771 if (SrcReg == 0)
1772 return false;
1773 }
1774 }
1775
1776 // Make the copy.
1777 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
1778 TII.get(TargetOpcode::COPY), DestReg).addReg(SrcReg);
1779
1780 // Add register to return instruction.
1781 RetRegs.push_back(VA.getLocReg());
1782 }
1783 MachineInstrBuilder MIB = emitInst(Mips::RetRA);
1784 for (unsigned Reg : RetRegs)
1785 MIB.addReg(Reg, RegState::Implicit);
1786 return true;
1787}
1788
1789bool MipsFastISel::selectTrunc(const Instruction *I) {
1790 // The high bits for a type smaller than the register size are assumed to be
1791 // undefined.
1792 Value *Op = I->getOperand(0);
1793
1794 EVT SrcVT, DestVT;
1795 SrcVT = TLI.getValueType(DL, Op->getType(), true);
1796 DestVT = TLI.getValueType(DL, I->getType(), true);
1797
1798 if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
1799 return false;
1800 if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
1801 return false;
1802
1803 Register SrcReg = getRegForValue(Op);
1804 if (!SrcReg)
1805 return false;
1806
1807 // Because the high bits are undefined, a truncate doesn't generate
1808 // any code.
1809 updateValueMap(I, SrcReg);
1810 return true;
1811}
1812
1813bool MipsFastISel::selectIntExt(const Instruction *I) {
1814 Type *DestTy = I->getType();
1815 Value *Src = I->getOperand(0);
1816 Type *SrcTy = Src->getType();
1817
1818 bool isZExt = isa<ZExtInst>(I);
1819 Register SrcReg = getRegForValue(Src);
1820 if (!SrcReg)
1821 return false;
1822
1823 EVT SrcEVT, DestEVT;
1824 SrcEVT = TLI.getValueType(DL, SrcTy, true);
1825 DestEVT = TLI.getValueType(DL, DestTy, true);
1826 if (!SrcEVT.isSimple())
1827 return false;
1828 if (!DestEVT.isSimple())
1829 return false;
1830
1831 MVT SrcVT = SrcEVT.getSimpleVT();
1832 MVT DestVT = DestEVT.getSimpleVT();
1833 Register ResultReg = createResultReg(&Mips::GPR32RegClass);
1834
1835 if (!emitIntExt(SrcVT, SrcReg, DestVT, ResultReg, isZExt))
1836 return false;
1837 updateValueMap(I, ResultReg);
1838 return true;
1839}
1840
1841bool MipsFastISel::emitIntSExt32r1(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1842 unsigned DestReg) {
1843 unsigned ShiftAmt;
1844 switch (SrcVT.SimpleTy) {
1845 default:
1846 return false;
1847 case MVT::i8:
1848 ShiftAmt = 24;
1849 break;
1850 case MVT::i16:
1851 ShiftAmt = 16;
1852 break;
1853 }
1854 Register TempReg = createResultReg(&Mips::GPR32RegClass);
1855 emitInst(Mips::SLL, TempReg).addReg(SrcReg).addImm(ShiftAmt);
1856 emitInst(Mips::SRA, DestReg).addReg(TempReg).addImm(ShiftAmt);
1857 return true;
1858}
1859
1860bool MipsFastISel::emitIntSExt32r2(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1861 unsigned DestReg) {
1862 switch (SrcVT.SimpleTy) {
1863 default:
1864 return false;
1865 case MVT::i8:
1866 emitInst(Mips::SEB, DestReg).addReg(SrcReg);
1867 break;
1868 case MVT::i16:
1869 emitInst(Mips::SEH, DestReg).addReg(SrcReg);
1870 break;
1871 }
1872 return true;
1873}
1874
1875bool MipsFastISel::emitIntSExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1876 unsigned DestReg) {
1877 if ((DestVT != MVT::i32) && (DestVT != MVT::i16))
1878 return false;
1879 if (Subtarget->hasMips32r2())
1880 return emitIntSExt32r2(SrcVT, SrcReg, DestVT, DestReg);
1881 return emitIntSExt32r1(SrcVT, SrcReg, DestVT, DestReg);
1882}
1883
1884bool MipsFastISel::emitIntZExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1885 unsigned DestReg) {
1886 int64_t Imm;
1887
1888 switch (SrcVT.SimpleTy) {
1889 default:
1890 return false;
1891 case MVT::i1:
1892 Imm = 1;
1893 break;
1894 case MVT::i8:
1895 Imm = 0xff;
1896 break;
1897 case MVT::i16:
1898 Imm = 0xffff;
1899 break;
1900 }
1901
1902 emitInst(Mips::ANDi, DestReg).addReg(SrcReg).addImm(Imm);
1903 return true;
1904}
1905
1906bool MipsFastISel::emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1907 unsigned DestReg, bool IsZExt) {
1908 // FastISel does not have plumbing to deal with extensions where the SrcVT or
1909 // DestVT are odd things, so test to make sure that they are both types we can
1910 // handle (i1/i8/i16/i32 for SrcVT and i8/i16/i32/i64 for DestVT), otherwise
1911 // bail out to SelectionDAG.
1912 if (((DestVT != MVT::i8) && (DestVT != MVT::i16) && (DestVT != MVT::i32)) ||
1913 ((SrcVT != MVT::i1) && (SrcVT != MVT::i8) && (SrcVT != MVT::i16)))
1914 return false;
1915 if (IsZExt)
1916 return emitIntZExt(SrcVT, SrcReg, DestVT, DestReg);
1917 return emitIntSExt(SrcVT, SrcReg, DestVT, DestReg);
1918}
1919
1920unsigned MipsFastISel::emitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT,
1921 bool isZExt) {
1922 unsigned DestReg = createResultReg(&Mips::GPR32RegClass);
1923 bool Success = emitIntExt(SrcVT, SrcReg, DestVT, DestReg, isZExt);
1924 return Success ? DestReg : 0;
1925}
1926
1927bool MipsFastISel::selectDivRem(const Instruction *I, unsigned ISDOpcode) {
1928 EVT DestEVT = TLI.getValueType(DL, I->getType(), true);
1929 if (!DestEVT.isSimple())
1930 return false;
1931
1932 MVT DestVT = DestEVT.getSimpleVT();
1933 if (DestVT != MVT::i32)
1934 return false;
1935
1936 unsigned DivOpc;
1937 switch (ISDOpcode) {
1938 default:
1939 return false;
1940 case ISD::SDIV:
1941 case ISD::SREM:
1942 DivOpc = Mips::SDIV;
1943 break;
1944 case ISD::UDIV:
1945 case ISD::UREM:
1946 DivOpc = Mips::UDIV;
1947 break;
1948 }
1949
1950 Register Src0Reg = getRegForValue(I->getOperand(0));
1951 Register Src1Reg = getRegForValue(I->getOperand(1));
1952 if (!Src0Reg || !Src1Reg)
1953 return false;
1954
1955 emitInst(DivOpc).addReg(Src0Reg).addReg(Src1Reg);
1956 if (!isa<ConstantInt>(I->getOperand(1)) ||
1957 dyn_cast<ConstantInt>(I->getOperand(1))->isZero()) {
1958 emitInst(Mips::TEQ).addReg(Src1Reg).addReg(Mips::ZERO).addImm(7);
1959 }
1960
1961 Register ResultReg = createResultReg(&Mips::GPR32RegClass);
1962 if (!ResultReg)
1963 return false;
1964
1965 unsigned MFOpc = (ISDOpcode == ISD::SREM || ISDOpcode == ISD::UREM)
1966 ? Mips::MFHI
1967 : Mips::MFLO;
1968 emitInst(MFOpc, ResultReg);
1969
1970 updateValueMap(I, ResultReg);
1971 return true;
1972}
1973
1974bool MipsFastISel::selectShift(const Instruction *I) {
1975 MVT RetVT;
1976
1977 if (!isTypeSupported(I->getType(), RetVT))
1978 return false;
1979
1980 Register ResultReg = createResultReg(&Mips::GPR32RegClass);
1981 if (!ResultReg)
1982 return false;
1983
1984 unsigned Opcode = I->getOpcode();
1985 const Value *Op0 = I->getOperand(0);
1986 Register Op0Reg = getRegForValue(Op0);
1987 if (!Op0Reg)
1988 return false;
1989
1990 // If AShr or LShr, then we need to make sure the operand0 is sign extended.
1991 if (Opcode == Instruction::AShr || Opcode == Instruction::LShr) {
1992 Register TempReg = createResultReg(&Mips::GPR32RegClass);
1993 if (!TempReg)
1994 return false;
1995
1996 MVT Op0MVT = TLI.getValueType(DL, Op0->getType(), true).getSimpleVT();
1997 bool IsZExt = Opcode == Instruction::LShr;
1998 if (!emitIntExt(Op0MVT, Op0Reg, MVT::i32, TempReg, IsZExt))
1999 return false;
2000
2001 Op0Reg = TempReg;
2002 }
2003
2004 if (const auto *C = dyn_cast<ConstantInt>(I->getOperand(1))) {
2005 uint64_t ShiftVal = C->getZExtValue();
2006
2007 switch (Opcode) {
2008 default:
2009 llvm_unreachable("Unexpected instruction.");
2010 case Instruction::Shl:
2011 Opcode = Mips::SLL;
2012 break;
2013 case Instruction::AShr:
2014 Opcode = Mips::SRA;
2015 break;
2016 case Instruction::LShr:
2017 Opcode = Mips::SRL;
2018 break;
2019 }
2020
2021 emitInst(Opcode, ResultReg).addReg(Op0Reg).addImm(ShiftVal);
2022 updateValueMap(I, ResultReg);
2023 return true;
2024 }
2025
2026 Register Op1Reg = getRegForValue(I->getOperand(1));
2027 if (!Op1Reg)
2028 return false;
2029
2030 switch (Opcode) {
2031 default:
2032 llvm_unreachable("Unexpected instruction.");
2033 case Instruction::Shl:
2034 Opcode = Mips::SLLV;
2035 break;
2036 case Instruction::AShr:
2037 Opcode = Mips::SRAV;
2038 break;
2039 case Instruction::LShr:
2040 Opcode = Mips::SRLV;
2041 break;
2042 }
2043
2044 emitInst(Opcode, ResultReg).addReg(Op0Reg).addReg(Op1Reg);
2045 updateValueMap(I, ResultReg);
2046 return true;
2047}
2048
2049bool MipsFastISel::fastSelectInstruction(const Instruction *I) {
2050 switch (I->getOpcode()) {
2051 default:
2052 break;
2053 case Instruction::Load:
2054 return selectLoad(I);
2055 case Instruction::Store:
2056 return selectStore(I);
2057 case Instruction::SDiv:
2058 if (!selectBinaryOp(I, ISD::SDIV))
2059 return selectDivRem(I, ISD::SDIV);
2060 return true;
2061 case Instruction::UDiv:
2062 if (!selectBinaryOp(I, ISD::UDIV))
2063 return selectDivRem(I, ISD::UDIV);
2064 return true;
2065 case Instruction::SRem:
2066 if (!selectBinaryOp(I, ISD::SREM))
2067 return selectDivRem(I, ISD::SREM);
2068 return true;
2069 case Instruction::URem:
2070 if (!selectBinaryOp(I, ISD::UREM))
2071 return selectDivRem(I, ISD::UREM);
2072 return true;
2073 case Instruction::Shl:
2074 case Instruction::LShr:
2075 case Instruction::AShr:
2076 return selectShift(I);
2077 case Instruction::And:
2078 case Instruction::Or:
2079 case Instruction::Xor:
2080 return selectLogicalOp(I);
2081 case Instruction::CondBr:
2082 return selectBranch(I);
2083 case Instruction::Ret:
2084 return selectRet(I);
2085 case Instruction::Trunc:
2086 return selectTrunc(I);
2087 case Instruction::ZExt:
2088 case Instruction::SExt:
2089 return selectIntExt(I);
2090 case Instruction::FPTrunc:
2091 return selectFPTrunc(I);
2092 case Instruction::FPExt:
2093 return selectFPExt(I);
2094 case Instruction::FPToSI:
2095 return selectFPToInt(I, /*isSigned*/ true);
2096 case Instruction::FPToUI:
2097 return selectFPToInt(I, /*isSigned*/ false);
2098 case Instruction::ICmp:
2099 case Instruction::FCmp:
2100 return selectCmp(I);
2101 case Instruction::Select:
2102 return selectSelect(I);
2103 }
2104 return false;
2105}
2106
2107unsigned MipsFastISel::getRegEnsuringSimpleIntegerWidening(const Value *V,
2108 bool IsUnsigned) {
2109 Register VReg = getRegForValue(V);
2110 if (VReg == 0)
2111 return 0;
2112 MVT VMVT = TLI.getValueType(DL, V->getType(), true).getSimpleVT();
2113
2114 if (VMVT == MVT::i1)
2115 return 0;
2116
2117 if ((VMVT == MVT::i8) || (VMVT == MVT::i16)) {
2118 Register TempReg = createResultReg(&Mips::GPR32RegClass);
2119 if (!emitIntExt(VMVT, VReg, MVT::i32, TempReg, IsUnsigned))
2120 return 0;
2121 VReg = TempReg;
2122 }
2123 return VReg;
2124}
2125
2126void MipsFastISel::simplifyAddress(Address &Addr) {
2127 if (!isInt<16>(Addr.getOffset())) {
2128 unsigned TempReg =
2129 materialize32BitInt(Addr.getOffset(), &Mips::GPR32RegClass);
2130 Register DestReg = createResultReg(&Mips::GPR32RegClass);
2131 emitInst(Mips::ADDu, DestReg).addReg(TempReg).addReg(Addr.getReg());
2132 Addr.setReg(DestReg);
2133 Addr.setOffset(0);
2134 }
2135}
2136
2137unsigned MipsFastISel::fastEmitInst_rr(unsigned MachineInstOpcode,
2138 const TargetRegisterClass *RC,
2139 unsigned Op0, unsigned Op1) {
2140 // We treat the MUL instruction in a special way because it clobbers
2141 // the HI0 & LO0 registers. The TableGen definition of this instruction can
2142 // mark these registers only as implicitly defined. As a result, the
2143 // register allocator runs out of registers when this instruction is
2144 // followed by another instruction that defines the same registers too.
2145 // We can fix this by explicitly marking those registers as dead.
2146 if (MachineInstOpcode == Mips::MUL) {
2147 Register ResultReg = createResultReg(RC);
2148 const MCInstrDesc &II = TII.get(MachineInstOpcode);
2149 Op0 = constrainOperandRegClass(II, Op0, II.getNumDefs());
2150 Op1 = constrainOperandRegClass(II, Op1, II.getNumDefs() + 1);
2151 BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, II, ResultReg)
2152 .addReg(Op0)
2153 .addReg(Op1)
2154 .addReg(Mips::HI0, RegState::ImplicitDefine | RegState::Dead)
2155 .addReg(Mips::LO0, RegState::ImplicitDefine | RegState::Dead);
2156 return ResultReg;
2157 }
2158
2159 return FastISel::fastEmitInst_rr(MachineInstOpcode, RC, Op0, Op1);
2160}
2161
2162namespace llvm {
2163
2165 const TargetLibraryInfo *libInfo,
2166 const LibcallLoweringInfo *libcallLowering) {
2167 return new MipsFastISel(funcInfo, libInfo, libcallLowering);
2168}
2169
2170} // end namespace llvm
#define Success
static unsigned selectBinaryOp(unsigned GenericOpc, unsigned RegBankID, unsigned OpSize)
Select the AArch64 opcode for the basic binary operation GenericOpc (such as G_OR or G_SDIV),...
static void emitLoad(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator Pos, const TargetInstrInfo &TII, unsigned Reg1, unsigned Reg2, int Offset, bool IsPostDec)
Emit a load-pair instruction for frame-destroy.
static void emitStore(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator Pos, const TargetInstrInfo &TII, unsigned Reg1, unsigned Reg2, int Offset, bool IsPreDec)
Emit a store-pair instruction for frame-setup.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the FastISel class.
const HexagonInstrInfo * TII
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
cl::opt< bool > EmitJalrReloc
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool CC_Mips(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
static bool CC_MipsO32_FP64(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
static bool CC_MipsO32_FP32(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State, ArrayRef< MCPhysReg > F64Regs)
uint64_t IntrinsicInst * II
#define P(N)
if(PassOpts->AAPipeline)
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
static SDValue emitCmp(SelectionDAG &DAG, const SDLoc &DL, Comparison &C)
This file describes how to lower LLVM code to machine code.
Value * RHS
Value * LHS
APInt bitcastToAPInt() const
Definition APFloat.h:1457
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1565
an instruction to allocate memory on the stack
PointerType * getType() const
Overload to return most specific pointer type.
CCState - This class holds information needed while lowering arguments and return values.
void convertToReg(MCRegister Reg)
Register getLocReg() const
LocInfo getLocInfo() const
bool needsCustom() const
int64_t getLocMemOffset() const
unsigned getValNo() const
This class is the base class for the comparison instructions.
Definition InstrTypes.h:728
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:756
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
Predicate getPredicate() const
Return the predicate for this instruction.
Definition InstrTypes.h:828
bool isUnsigned() const
Definition InstrTypes.h:999
Value * getCondition() const
BasicBlock * getSuccessor(unsigned i) const
ConstantFP - Floating Point Values [float, double].
Definition Constants.h:420
const APFloat & getValueAPF() const
Definition Constants.h:463
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition Constants.h:174
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition Constants.h:168
This is an important base class in LLVM.
Definition Constant.h:43
This is a fast-path instruction selection class that generates poor code and doesn't support illegal ...
Definition FastISel.h:67
Register fastEmitInst_rr(unsigned MachineInstOpcode, const TargetRegisterClass *RC, Register Op0, Register Op1)
Emit a MachineInstr with two register operands and a result register in the given register class.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:353
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
bool hasLocalLinkage() const
bool hasInternalLinkage() const
LLVM_ABI bool isAtomic() const LLVM_READONLY
Return true if this instruction has an AtomicOrdering of unordered or higher.
A wrapper class for inspecting calls to intrinsic functions.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Tracks which library functions to use for a particular subtarget.
Align getAlign() const
Return the alignment of the access that is being performed.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Machine Value Type.
SimpleValueType SimpleTy
bool isVector() const
Return true if this is a vector value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
Value * getLength() const
bool isVolatile() const
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
Register getGlobalBaseReg(MachineFunction &MF)
bool isFP64bit() const
bool useSoftFloat() const
const MipsInstrInfo * getInstrInfo() const override
bool inMips16Mode() const
bool systemSupportsUnalignedAccess() const
Does the system support unaligned memory access.
bool hasMips32r2() const
const MipsTargetLowering * getTargetLowering() const override
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void push_back(const T &Elt)
TypeSize getElementOffset(unsigned Idx) const
Definition DataLayout.h:774
TargetInstrInfo - Interface to description of machine instruction set.
Provides information about what library functions are available for the current target.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:288
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:257
const Use * const_op_iterator
Definition User.h:255
Value * getOperand(unsigned i) const
Definition User.h:207
unsigned getNumOperands() const
Definition User.h:229
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
bool hasOneUse() const
Return true if there is exactly one use of this value.
Definition Value.h:439
TypeSize getSequentialElementStride(const DataLayout &DL) const
const ParentTy * getParent() const
Definition ilist_node.h:34
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ AND
Bitwise operators - logical and, logical or, logical xor.
Definition ISDOpcodes.h:741
Flag
These should be considered private to the implementation of the MCInstrDesc class.
FastISel * createFastISel(FunctionLoweringInfo &funcInfo, const TargetLibraryInfo *libInfo, const LibcallLoweringInfo *libcallLowering)
@ User
could "use" a pointer
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:573
LLVM_ABI Register constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const TargetRegisterClass &RegClass, MachineOperand &RegMO)
Constrain the Register operand OpIdx, so that it is now constrained to the TargetRegisterClass passed...
Definition Utils.cpp:60
LLVM_ABI void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags,...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
generic_gep_type_iterator<> gep_type_iterator
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
gep_type_iterator gep_type_begin(const User *GEP)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:862
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:145
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:339
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:176
static LLVM_ABI MachinePointerInfo getStack(MachineFunction &MF, int64_t Offset, uint8_t ID=0)
Stack pointer relative access.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.