FastISel.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. //===-- FastISel.h - Definition of the FastISel class ---*- C++ -*---------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. ///
  10. /// \file
  11. /// This file defines the FastISel class.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_CODEGEN_FASTISEL_H
  15. #define LLVM_CODEGEN_FASTISEL_H
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/CodeGen/CallingConvLower.h"
  18. #include "llvm/CodeGen/MachineBasicBlock.h"
  19. #include "llvm/IR/CallingConv.h"
  20. #include "llvm/IR/IntrinsicInst.h"
  21. #include "llvm/Target/TargetLowering.h"
  22. namespace llvm {
  23. /// \brief This is a fast-path instruction selection class that generates poor
  24. /// code and doesn't support illegal types or non-trivial lowering, but runs
  25. /// quickly.
  26. class FastISel {
  27. public:
  28. struct ArgListEntry {
  29. Value *Val;
  30. Type *Ty;
  31. bool IsSExt : 1;
  32. bool IsZExt : 1;
  33. bool IsInReg : 1;
  34. bool IsSRet : 1;
  35. bool IsNest : 1;
  36. bool IsByVal : 1;
  37. bool IsInAlloca : 1;
  38. bool IsReturned : 1;
  39. uint16_t Alignment;
  40. ArgListEntry()
  41. : Val(nullptr), Ty(nullptr), IsSExt(false), IsZExt(false),
  42. IsInReg(false), IsSRet(false), IsNest(false), IsByVal(false),
  43. IsInAlloca(false), IsReturned(false), Alignment(0) {}
  44. /// \brief Set CallLoweringInfo attribute flags based on a call instruction
  45. /// and called function attributes.
  46. void setAttributes(ImmutableCallSite *CS, unsigned AttrIdx);
  47. };
  48. typedef std::vector<ArgListEntry> ArgListTy;
  49. struct CallLoweringInfo {
  50. Type *RetTy;
  51. bool RetSExt : 1;
  52. bool RetZExt : 1;
  53. bool IsVarArg : 1;
  54. bool IsInReg : 1;
  55. bool DoesNotReturn : 1;
  56. bool IsReturnValueUsed : 1;
  57. // \brief IsTailCall Should be modified by implementations of FastLowerCall
  58. // that perform tail call conversions.
  59. bool IsTailCall;
  60. unsigned NumFixedArgs;
  61. CallingConv::ID CallConv;
  62. const Value *Callee;
  63. MCSymbol *Symbol;
  64. ArgListTy Args;
  65. ImmutableCallSite *CS;
  66. MachineInstr *Call;
  67. unsigned ResultReg;
  68. unsigned NumResultRegs;
  69. bool IsPatchPoint;
  70. SmallVector<Value *, 16> OutVals;
  71. SmallVector<ISD::ArgFlagsTy, 16> OutFlags;
  72. SmallVector<unsigned, 16> OutRegs;
  73. SmallVector<ISD::InputArg, 4> Ins;
  74. SmallVector<unsigned, 4> InRegs;
  75. CallLoweringInfo()
  76. : RetTy(nullptr), RetSExt(false), RetZExt(false), IsVarArg(false),
  77. IsInReg(false), DoesNotReturn(false), IsReturnValueUsed(true),
  78. IsTailCall(false), NumFixedArgs(-1), CallConv(CallingConv::C),
  79. Callee(nullptr), Symbol(nullptr), CS(nullptr), Call(nullptr),
  80. ResultReg(0), NumResultRegs(0), IsPatchPoint(false) {}
  81. CallLoweringInfo &setCallee(Type *ResultTy, FunctionType *FuncTy,
  82. const Value *Target, ArgListTy &&ArgsList,
  83. ImmutableCallSite &Call) {
  84. RetTy = ResultTy;
  85. Callee = Target;
  86. IsInReg = Call.paramHasAttr(0, Attribute::InReg);
  87. DoesNotReturn = Call.doesNotReturn();
  88. IsVarArg = FuncTy->isVarArg();
  89. IsReturnValueUsed = !Call.getInstruction()->use_empty();
  90. RetSExt = Call.paramHasAttr(0, Attribute::SExt);
  91. RetZExt = Call.paramHasAttr(0, Attribute::ZExt);
  92. CallConv = Call.getCallingConv();
  93. Args = std::move(ArgsList);
  94. NumFixedArgs = FuncTy->getNumParams();
  95. CS = &Call;
  96. return *this;
  97. }
  98. CallLoweringInfo &setCallee(Type *ResultTy, FunctionType *FuncTy,
  99. MCSymbol *Target, ArgListTy &&ArgsList,
  100. ImmutableCallSite &Call,
  101. unsigned FixedArgs = ~0U) {
  102. RetTy = ResultTy;
  103. Callee = Call.getCalledValue();
  104. Symbol = Target;
  105. IsInReg = Call.paramHasAttr(0, Attribute::InReg);
  106. DoesNotReturn = Call.doesNotReturn();
  107. IsVarArg = FuncTy->isVarArg();
  108. IsReturnValueUsed = !Call.getInstruction()->use_empty();
  109. RetSExt = Call.paramHasAttr(0, Attribute::SExt);
  110. RetZExt = Call.paramHasAttr(0, Attribute::ZExt);
  111. CallConv = Call.getCallingConv();
  112. Args = std::move(ArgsList);
  113. NumFixedArgs = (FixedArgs == ~0U) ? FuncTy->getNumParams() : FixedArgs;
  114. CS = &Call;
  115. return *this;
  116. }
  117. CallLoweringInfo &setCallee(CallingConv::ID CC, Type *ResultTy,
  118. const Value *Target, ArgListTy &&ArgsList,
  119. unsigned FixedArgs = ~0U) {
  120. RetTy = ResultTy;
  121. Callee = Target;
  122. CallConv = CC;
  123. Args = std::move(ArgsList);
  124. NumFixedArgs = (FixedArgs == ~0U) ? Args.size() : FixedArgs;
  125. return *this;
  126. }
  127. CallLoweringInfo &setCallee(const DataLayout &DL, MCContext &Ctx,
  128. CallingConv::ID CC, Type *ResultTy,
  129. const char *Target, ArgListTy &&ArgsList,
  130. unsigned FixedArgs = ~0U);
  131. CallLoweringInfo &setCallee(CallingConv::ID CC, Type *ResultTy,
  132. MCSymbol *Target, ArgListTy &&ArgsList,
  133. unsigned FixedArgs = ~0U) {
  134. RetTy = ResultTy;
  135. Symbol = Target;
  136. CallConv = CC;
  137. Args = std::move(ArgsList);
  138. NumFixedArgs = (FixedArgs == ~0U) ? Args.size() : FixedArgs;
  139. return *this;
  140. }
  141. CallLoweringInfo &setTailCall(bool Value = true) {
  142. IsTailCall = Value;
  143. return *this;
  144. }
  145. CallLoweringInfo &setIsPatchPoint(bool Value = true) {
  146. IsPatchPoint = Value;
  147. return *this;
  148. }
  149. ArgListTy &getArgs() { return Args; }
  150. void clearOuts() {
  151. OutVals.clear();
  152. OutFlags.clear();
  153. OutRegs.clear();
  154. }
  155. void clearIns() {
  156. Ins.clear();
  157. InRegs.clear();
  158. }
  159. };
  160. protected:
  161. DenseMap<const Value *, unsigned> LocalValueMap;
  162. FunctionLoweringInfo &FuncInfo;
  163. MachineFunction *MF;
  164. MachineRegisterInfo &MRI;
  165. MachineFrameInfo &MFI;
  166. MachineConstantPool &MCP;
  167. DebugLoc DbgLoc;
  168. const TargetMachine &TM;
  169. const DataLayout &DL;
  170. const TargetInstrInfo &TII;
  171. const TargetLowering &TLI;
  172. const TargetRegisterInfo &TRI;
  173. const TargetLibraryInfo *LibInfo;
  174. bool SkipTargetIndependentISel;
  175. /// \brief The position of the last instruction for materializing constants
  176. /// for use in the current block. It resets to EmitStartPt when it makes sense
  177. /// (for example, it's usually profitable to avoid function calls between the
  178. /// definition and the use)
  179. MachineInstr *LastLocalValue;
  180. /// \brief The top most instruction in the current block that is allowed for
  181. /// emitting local variables. LastLocalValue resets to EmitStartPt when it
  182. /// makes sense (for example, on function calls)
  183. MachineInstr *EmitStartPt;
  184. public:
  185. /// \brief Return the position of the last instruction emitted for
  186. /// materializing constants for use in the current block.
  187. MachineInstr *getLastLocalValue() { return LastLocalValue; }
  188. /// \brief Update the position of the last instruction emitted for
  189. /// materializing constants for use in the current block.
  190. void setLastLocalValue(MachineInstr *I) {
  191. EmitStartPt = I;
  192. LastLocalValue = I;
  193. }
  194. /// \brief Set the current block to which generated machine instructions will
  195. /// be appended, and clear the local CSE map.
  196. void startNewBlock();
  197. /// \brief Return current debug location information.
  198. DebugLoc getCurDebugLoc() const { return DbgLoc; }
  199. /// \brief Do "fast" instruction selection for function arguments and append
  200. /// the machine instructions to the current block. Returns true when
  201. /// successful.
  202. bool lowerArguments();
  203. /// \brief Do "fast" instruction selection for the given LLVM IR instruction
  204. /// and append the generated machine instructions to the current block.
  205. /// Returns true if selection was successful.
  206. bool selectInstruction(const Instruction *I);
  207. /// \brief Do "fast" instruction selection for the given LLVM IR operator
  208. /// (Instruction or ConstantExpr), and append generated machine instructions
  209. /// to the current block. Return true if selection was successful.
  210. bool selectOperator(const User *I, unsigned Opcode);
  211. /// \brief Create a virtual register and arrange for it to be assigned the
  212. /// value for the given LLVM value.
  213. unsigned getRegForValue(const Value *V);
  214. /// \brief Look up the value to see if its value is already cached in a
  215. /// register. It may be defined by instructions across blocks or defined
  216. /// locally.
  217. unsigned lookUpRegForValue(const Value *V);
  218. /// \brief This is a wrapper around getRegForValue that also takes care of
  219. /// truncating or sign-extending the given getelementptr index value.
  220. std::pair<unsigned, bool> getRegForGEPIndex(const Value *V);
  221. /// \brief We're checking to see if we can fold \p LI into \p FoldInst. Note
  222. /// that we could have a sequence where multiple LLVM IR instructions are
  223. /// folded into the same machineinstr. For example we could have:
  224. ///
  225. /// A: x = load i32 *P
  226. /// B: y = icmp A, 42
  227. /// C: br y, ...
  228. ///
  229. /// In this scenario, \p LI is "A", and \p FoldInst is "C". We know about "B"
  230. /// (and any other folded instructions) because it is between A and C.
  231. ///
  232. /// If we succeed folding, return true.
  233. bool tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst);
  234. /// \brief The specified machine instr operand is a vreg, and that vreg is
  235. /// being provided by the specified load instruction. If possible, try to
  236. /// fold the load as an operand to the instruction, returning true if
  237. /// possible.
  238. ///
  239. /// This method should be implemented by targets.
  240. virtual bool tryToFoldLoadIntoMI(MachineInstr * /*MI*/, unsigned /*OpNo*/,
  241. const LoadInst * /*LI*/) {
  242. return false;
  243. }
  244. /// \brief Reset InsertPt to prepare for inserting instructions into the
  245. /// current block.
  246. void recomputeInsertPt();
  247. /// \brief Remove all dead instructions between the I and E.
  248. void removeDeadCode(MachineBasicBlock::iterator I,
  249. MachineBasicBlock::iterator E);
  250. struct SavePoint {
  251. MachineBasicBlock::iterator InsertPt;
  252. DebugLoc DL;
  253. };
  254. /// \brief Prepare InsertPt to begin inserting instructions into the local
  255. /// value area and return the old insert position.
  256. SavePoint enterLocalValueArea();
  257. /// \brief Reset InsertPt to the given old insert position.
  258. void leaveLocalValueArea(SavePoint Old);
  259. virtual ~FastISel();
  260. protected:
  261. explicit FastISel(FunctionLoweringInfo &FuncInfo,
  262. const TargetLibraryInfo *LibInfo,
  263. bool SkipTargetIndependentISel = false);
  264. /// \brief This method is called by target-independent code when the normal
  265. /// FastISel process fails to select an instruction. This gives targets a
  266. /// chance to emit code for anything that doesn't fit into FastISel's
  267. /// framework. It returns true if it was successful.
  268. virtual bool fastSelectInstruction(const Instruction *I) = 0;
  269. /// \brief This method is called by target-independent code to do target-
  270. /// specific argument lowering. It returns true if it was successful.
  271. virtual bool fastLowerArguments();
  272. /// \brief This method is called by target-independent code to do target-
  273. /// specific call lowering. It returns true if it was successful.
  274. virtual bool fastLowerCall(CallLoweringInfo &CLI);
  275. /// \brief This method is called by target-independent code to do target-
  276. /// specific intrinsic lowering. It returns true if it was successful.
  277. virtual bool fastLowerIntrinsicCall(const IntrinsicInst *II);
  278. /// \brief This method is called by target-independent code to request that an
  279. /// instruction with the given type and opcode be emitted.
  280. virtual unsigned fastEmit_(MVT VT, MVT RetVT, unsigned Opcode);
  281. /// \brief This method is called by target-independent code to request that an
  282. /// instruction with the given type, opcode, and register operand be emitted.
  283. virtual unsigned fastEmit_r(MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0,
  284. bool Op0IsKill);
  285. /// \brief This method is called by target-independent code to request that an
  286. /// instruction with the given type, opcode, and register operands be emitted.
  287. virtual unsigned fastEmit_rr(MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0,
  288. bool Op0IsKill, unsigned Op1, bool Op1IsKill);
  289. /// \brief This method is called by target-independent code to request that an
  290. /// instruction with the given type, opcode, and register and immediate
  291. // operands be emitted.
  292. virtual unsigned fastEmit_ri(MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0,
  293. bool Op0IsKill, uint64_t Imm);
  294. /// \brief This method is called by target-independent code to request that an
  295. /// instruction with the given type, opcode, and register and floating-point
  296. /// immediate operands be emitted.
  297. virtual unsigned fastEmit_rf(MVT VT, MVT RetVT, unsigned Opcode, unsigned Op0,
  298. bool Op0IsKill, const ConstantFP *FPImm);
  299. /// \brief This method is called by target-independent code to request that an
  300. /// instruction with the given type, opcode, and register and immediate
  301. /// operands be emitted.
  302. virtual unsigned fastEmit_rri(MVT VT, MVT RetVT, unsigned Opcode,
  303. unsigned Op0, bool Op0IsKill, unsigned Op1,
  304. bool Op1IsKill, uint64_t Imm);
  305. /// \brief This method is a wrapper of fastEmit_ri.
  306. ///
  307. /// It first tries to emit an instruction with an immediate operand using
  308. /// fastEmit_ri. If that fails, it materializes the immediate into a register
  309. /// and try fastEmit_rr instead.
  310. unsigned fastEmit_ri_(MVT VT, unsigned Opcode, unsigned Op0, bool Op0IsKill,
  311. uint64_t Imm, MVT ImmType);
  312. /// \brief This method is called by target-independent code to request that an
  313. /// instruction with the given type, opcode, and immediate operand be emitted.
  314. virtual unsigned fastEmit_i(MVT VT, MVT RetVT, unsigned Opcode, uint64_t Imm);
  315. /// \brief This method is called by target-independent code to request that an
  316. /// instruction with the given type, opcode, and floating-point immediate
  317. /// operand be emitted.
  318. virtual unsigned fastEmit_f(MVT VT, MVT RetVT, unsigned Opcode,
  319. const ConstantFP *FPImm);
  320. /// \brief Emit a MachineInstr with no operands and a result register in the
  321. /// given register class.
  322. unsigned fastEmitInst_(unsigned MachineInstOpcode,
  323. const TargetRegisterClass *RC);
  324. /// \brief Emit a MachineInstr with one register operand and a result register
  325. /// in the given register class.
  326. unsigned fastEmitInst_r(unsigned MachineInstOpcode,
  327. const TargetRegisterClass *RC, unsigned Op0,
  328. bool Op0IsKill);
  329. /// \brief Emit a MachineInstr with two register operands and a result
  330. /// register in the given register class.
  331. unsigned fastEmitInst_rr(unsigned MachineInstOpcode,
  332. const TargetRegisterClass *RC, unsigned Op0,
  333. bool Op0IsKill, unsigned Op1, bool Op1IsKill);
  334. /// \brief Emit a MachineInstr with three register operands and a result
  335. /// register in the given register class.
  336. unsigned fastEmitInst_rrr(unsigned MachineInstOpcode,
  337. const TargetRegisterClass *RC, unsigned Op0,
  338. bool Op0IsKill, unsigned Op1, bool Op1IsKill,
  339. unsigned Op2, bool Op2IsKill);
  340. /// \brief Emit a MachineInstr with a register operand, an immediate, and a
  341. /// result register in the given register class.
  342. unsigned fastEmitInst_ri(unsigned MachineInstOpcode,
  343. const TargetRegisterClass *RC, unsigned Op0,
  344. bool Op0IsKill, uint64_t Imm);
  345. /// \brief Emit a MachineInstr with one register operand and two immediate
  346. /// operands.
  347. unsigned fastEmitInst_rii(unsigned MachineInstOpcode,
  348. const TargetRegisterClass *RC, unsigned Op0,
  349. bool Op0IsKill, uint64_t Imm1, uint64_t Imm2);
  350. /// \brief Emit a MachineInstr with two register operands and a result
  351. /// register in the given register class.
  352. unsigned fastEmitInst_rf(unsigned MachineInstOpcode,
  353. const TargetRegisterClass *RC, unsigned Op0,
  354. bool Op0IsKill, const ConstantFP *FPImm);
  355. /// \brief Emit a MachineInstr with two register operands, an immediate, and a
  356. /// result register in the given register class.
  357. unsigned fastEmitInst_rri(unsigned MachineInstOpcode,
  358. const TargetRegisterClass *RC, unsigned Op0,
  359. bool Op0IsKill, unsigned Op1, bool Op1IsKill,
  360. uint64_t Imm);
  361. /// \brief Emit a MachineInstr with two register operands, two immediates
  362. /// operands, and a result register in the given register class.
  363. unsigned fastEmitInst_rrii(unsigned MachineInstOpcode,
  364. const TargetRegisterClass *RC, unsigned Op0,
  365. bool Op0IsKill, unsigned Op1, bool Op1IsKill,
  366. uint64_t Imm1, uint64_t Imm2);
  367. /// \brief Emit a MachineInstr with a single immediate operand, and a result
  368. /// register in the given register class.
  369. unsigned fastEmitInst_i(unsigned MachineInstrOpcode,
  370. const TargetRegisterClass *RC, uint64_t Imm);
  371. /// \brief Emit a MachineInstr with a two immediate operands.
  372. unsigned fastEmitInst_ii(unsigned MachineInstrOpcode,
  373. const TargetRegisterClass *RC, uint64_t Imm1,
  374. uint64_t Imm2);
  375. /// \brief Emit a MachineInstr for an extract_subreg from a specified index of
  376. /// a superregister to a specified type.
  377. unsigned fastEmitInst_extractsubreg(MVT RetVT, unsigned Op0, bool Op0IsKill,
  378. uint32_t Idx);
  379. /// \brief Emit MachineInstrs to compute the value of Op with all but the
  380. /// least significant bit set to zero.
  381. unsigned fastEmitZExtFromI1(MVT VT, unsigned Op0, bool Op0IsKill);
  382. /// \brief Emit an unconditional branch to the given block, unless it is the
  383. /// immediate (fall-through) successor, and update the CFG.
  384. void fastEmitBranch(MachineBasicBlock *MBB, DebugLoc DL);
  385. /// \brief Update the value map to include the new mapping for this
  386. /// instruction, or insert an extra copy to get the result in a previous
  387. /// determined register.
  388. ///
  389. /// NOTE: This is only necessary because we might select a block that uses a
  390. /// value before we select the block that defines the value. It might be
  391. /// possible to fix this by selecting blocks in reverse postorder.
  392. void updateValueMap(const Value *I, unsigned Reg, unsigned NumRegs = 1);
  393. unsigned createResultReg(const TargetRegisterClass *RC);
  394. /// \brief Try to constrain Op so that it is usable by argument OpNum of the
  395. /// provided MCInstrDesc. If this fails, create a new virtual register in the
  396. /// correct class and COPY the value there.
  397. unsigned constrainOperandRegClass(const MCInstrDesc &II, unsigned Op,
  398. unsigned OpNum);
  399. /// \brief Emit a constant in a register using target-specific logic, such as
  400. /// constant pool loads.
  401. virtual unsigned fastMaterializeConstant(const Constant *C) { return 0; }
  402. /// \brief Emit an alloca address in a register using target-specific logic.
  403. virtual unsigned fastMaterializeAlloca(const AllocaInst *C) { return 0; }
  404. /// \brief Emit the floating-point constant +0.0 in a register using target-
  405. /// specific logic.
  406. virtual unsigned fastMaterializeFloatZero(const ConstantFP *CF) {
  407. return 0;
  408. }
  409. /// \brief Check if \c Add is an add that can be safely folded into \c GEP.
  410. ///
  411. /// \c Add can be folded into \c GEP if:
  412. /// - \c Add is an add,
  413. /// - \c Add's size matches \c GEP's,
  414. /// - \c Add is in the same basic block as \c GEP, and
  415. /// - \c Add has a constant operand.
  416. bool canFoldAddIntoGEP(const User *GEP, const Value *Add);
  417. /// \brief Test whether the given value has exactly one use.
  418. bool hasTrivialKill(const Value *V);
  419. /// \brief Create a machine mem operand from the given instruction.
  420. MachineMemOperand *createMachineMemOperandFor(const Instruction *I) const;
  421. CmpInst::Predicate optimizeCmpPredicate(const CmpInst *CI) const;
  422. bool lowerCallTo(const CallInst *CI, MCSymbol *Symbol, unsigned NumArgs);
  423. bool lowerCallTo(const CallInst *CI, const char *SymbolName,
  424. unsigned NumArgs);
  425. bool lowerCallTo(CallLoweringInfo &CLI);
  426. bool isCommutativeIntrinsic(IntrinsicInst const *II) {
  427. switch (II->getIntrinsicID()) {
  428. case Intrinsic::sadd_with_overflow:
  429. case Intrinsic::uadd_with_overflow:
  430. case Intrinsic::smul_with_overflow:
  431. case Intrinsic::umul_with_overflow:
  432. return true;
  433. default:
  434. return false;
  435. }
  436. }
  437. bool lowerCall(const CallInst *I);
  438. /// \brief Select and emit code for a binary operator instruction, which has
  439. /// an opcode which directly corresponds to the given ISD opcode.
  440. bool selectBinaryOp(const User *I, unsigned ISDOpcode);
  441. bool selectFNeg(const User *I);
  442. bool selectGetElementPtr(const User *I);
  443. bool selectStackmap(const CallInst *I);
  444. bool selectPatchpoint(const CallInst *I);
  445. bool selectCall(const User *Call);
  446. bool selectIntrinsicCall(const IntrinsicInst *II);
  447. bool selectBitCast(const User *I);
  448. bool selectCast(const User *I, unsigned Opcode);
  449. bool selectExtractValue(const User *I);
  450. bool selectInsertValue(const User *I);
  451. private:
  452. /// \brief Handle PHI nodes in successor blocks.
  453. ///
  454. /// Emit code to ensure constants are copied into registers when needed.
  455. /// Remember the virtual registers that need to be added to the Machine PHI
  456. /// nodes as input. We cannot just directly add them, because expansion might
  457. /// result in multiple MBB's for one BB. As such, the start of the BB might
  458. /// correspond to a different MBB than the end.
  459. bool handlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
  460. /// \brief Helper for materializeRegForValue to materialize a constant in a
  461. /// target-independent way.
  462. unsigned materializeConstant(const Value *V, MVT VT);
  463. /// \brief Helper for getRegForVale. This function is called when the value
  464. /// isn't already available in a register and must be materialized with new
  465. /// instructions.
  466. unsigned materializeRegForValue(const Value *V, MVT VT);
  467. /// \brief Clears LocalValueMap and moves the area for the new local variables
  468. /// to the beginning of the block. It helps to avoid spilling cached variables
  469. /// across heavy instructions like calls.
  470. void flushLocalValueMap();
  471. /// \brief Insertion point before trying to select the current instruction.
  472. MachineBasicBlock::iterator SavedInsertPt;
  473. /// \brief Add a stackmap or patchpoint intrinsic call's live variable
  474. /// operands to a stackmap or patchpoint machine instruction.
  475. bool addStackMapLiveVars(SmallVectorImpl<MachineOperand> &Ops,
  476. const CallInst *CI, unsigned StartIdx);
  477. bool lowerCallOperands(const CallInst *CI, unsigned ArgIdx, unsigned NumArgs,
  478. const Value *Callee, bool ForceRetVoidTy,
  479. CallLoweringInfo &CLI);
  480. };
  481. } // end namespace llvm
  482. #endif