| 1 | //===-- llvm/CodeGen/GlobalISel/MachineIRBuilder.h - MIBuilder --*- C++ -*-===// |
| 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 | /// \file |
| 9 | /// This file declares the MachineIRBuilder class. |
| 10 | /// This is a helper class to build MachineInstr. |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H |
| 14 | #define LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H |
| 15 | |
| 16 | #include "llvm/CodeGen/GlobalISel/CSEInfo.h" |
| 17 | #include "llvm/CodeGen/LowLevelType.h" |
| 18 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 20 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 21 | #include "llvm/CodeGen/TargetOpcodes.h" |
| 22 | #include "llvm/IR/Constants.h" |
| 23 | #include "llvm/IR/DebugLoc.h" |
| 24 | #include "llvm/IR/Module.h" |
| 25 | |
| 26 | namespace llvm { |
| 27 | |
| 28 | // Forward declarations. |
| 29 | class MachineFunction; |
| 30 | class MachineInstr; |
| 31 | class TargetInstrInfo; |
| 32 | class GISelChangeObserver; |
| 33 | |
| 34 | /// Class which stores all the state required in a MachineIRBuilder. |
| 35 | /// Since MachineIRBuilders will only store state in this object, it allows |
| 36 | /// to transfer BuilderState between different kinds of MachineIRBuilders. |
| 37 | struct MachineIRBuilderState { |
| 38 | /// MachineFunction under construction. |
| 39 | MachineFunction *MF = nullptr; |
| 40 | /// Information used to access the description of the opcodes. |
| 41 | const TargetInstrInfo *TII = nullptr; |
| 42 | /// Information used to verify types are consistent and to create virtual registers. |
| 43 | MachineRegisterInfo *MRI = nullptr; |
| 44 | /// Debug location to be set to any instruction we create. |
| 45 | DebugLoc DL; |
| 46 | |
| 47 | /// \name Fields describing the insertion point. |
| 48 | /// @{ |
| 49 | MachineBasicBlock *MBB = nullptr; |
| 50 | MachineBasicBlock::iterator II; |
| 51 | /// @} |
| 52 | |
| 53 | GISelChangeObserver *Observer = nullptr; |
| 54 | |
| 55 | GISelCSEInfo *CSEInfo = nullptr; |
| 56 | }; |
| 57 | |
| 58 | class DstOp { |
| 59 | union { |
| 60 | LLT LLTTy; |
| 61 | Register Reg; |
| 62 | const TargetRegisterClass *RC; |
| 63 | }; |
| 64 | |
| 65 | public: |
| 66 | enum class DstType { Ty_LLT, Ty_Reg, Ty_RC }; |
| 67 | DstOp(unsigned R) : Reg(R), Ty(DstType::Ty_Reg) {} |
| 68 | DstOp(Register R) : Reg(R), Ty(DstType::Ty_Reg) {} |
| 69 | DstOp(const MachineOperand &Op) : Reg(Op.getReg()), Ty(DstType::Ty_Reg) {} |
| 70 | DstOp(const LLT T) : LLTTy(T), Ty(DstType::Ty_LLT) {} |
| 71 | DstOp(const TargetRegisterClass *TRC) : RC(TRC), Ty(DstType::Ty_RC) {} |
| 72 | |
| 73 | void addDefToMIB(MachineRegisterInfo &MRI, MachineInstrBuilder &MIB) const { |
| 74 | switch (Ty) { |
| 75 | case DstType::Ty_Reg: |
| 76 | MIB.addDef(Reg); |
| 77 | break; |
| 78 | case DstType::Ty_LLT: |
| 79 | MIB.addDef(MRI.createGenericVirtualRegister(LLTTy)); |
| 80 | break; |
| 81 | case DstType::Ty_RC: |
| 82 | MIB.addDef(MRI.createVirtualRegister(RC)); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | LLT getLLTTy(const MachineRegisterInfo &MRI) const { |
| 88 | switch (Ty) { |
| 89 | case DstType::Ty_RC: |
| 90 | return LLT{}; |
| 91 | case DstType::Ty_LLT: |
| 92 | return LLTTy; |
| 93 | case DstType::Ty_Reg: |
| 94 | return MRI.getType(Reg); |
| 95 | } |
| 96 | llvm_unreachable("Unrecognised DstOp::DstType enum"); |
| 97 | } |
| 98 | |
| 99 | Register getReg() const { |
| 100 | assert(Ty == DstType::Ty_Reg && "Not a register"); |
| 101 | return Reg; |
| 102 | } |
| 103 | |
| 104 | const TargetRegisterClass *getRegClass() const { |
| 105 | switch (Ty) { |
| 106 | case DstType::Ty_RC: |
| 107 | return RC; |
| 108 | default: |
| 109 | llvm_unreachable("Not a RC Operand"); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | DstType getDstOpKind() const { return Ty; } |
| 114 | |
| 115 | private: |
| 116 | DstType Ty; |
| 117 | }; |
| 118 | |
| 119 | class SrcOp { |
| 120 | union { |
| 121 | MachineInstrBuilder SrcMIB; |
| 122 | Register Reg; |
| 123 | CmpInst::Predicate Pred; |
| 124 | int64_t Imm; |
| 125 | }; |
| 126 | |
| 127 | public: |
| 128 | enum class SrcType { Ty_Reg, Ty_MIB, Ty_Predicate, Ty_Imm }; |
| 129 | SrcOp(Register R) : Reg(R), Ty(SrcType::Ty_Reg) {} |
| 130 | SrcOp(const MachineOperand &Op) : Reg(Op.getReg()), Ty(SrcType::Ty_Reg) {} |
| 131 | SrcOp(const MachineInstrBuilder &MIB) : SrcMIB(MIB), Ty(SrcType::Ty_MIB) {} |
| 132 | SrcOp(const CmpInst::Predicate P) : Pred(P), Ty(SrcType::Ty_Predicate) {} |
| 133 | /// Use of registers held in unsigned integer variables (or more rarely signed |
| 134 | /// integers) is no longer permitted to avoid ambiguity with upcoming support |
| 135 | /// for immediates. |
| 136 | SrcOp(unsigned) = delete; |
| 137 | SrcOp(int) = delete; |
| 138 | SrcOp(uint64_t V) : Imm(V), Ty(SrcType::Ty_Imm) {} |
| 139 | SrcOp(int64_t V) : Imm(V), Ty(SrcType::Ty_Imm) {} |
| 140 | |
| 141 | void addSrcToMIB(MachineInstrBuilder &MIB) const { |
| 142 | switch (Ty) { |
| 143 | case SrcType::Ty_Predicate: |
| 144 | MIB.addPredicate(Pred); |
| 145 | break; |
| 146 | case SrcType::Ty_Reg: |
| 147 | MIB.addUse(Reg); |
| 148 | break; |
| 149 | case SrcType::Ty_MIB: |
| 150 | MIB.addUse(SrcMIB->getOperand(0).getReg()); |
| 151 | break; |
| 152 | case SrcType::Ty_Imm: |
| 153 | MIB.addImm(Imm); |
| 154 | break; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | LLT getLLTTy(const MachineRegisterInfo &MRI) const { |
| 159 | switch (Ty) { |
| 160 | case SrcType::Ty_Predicate: |
| 161 | case SrcType::Ty_Imm: |
| 162 | llvm_unreachable("Not a register operand"); |
| 163 | case SrcType::Ty_Reg: |
| 164 | return MRI.getType(Reg); |
| 165 | case SrcType::Ty_MIB: |
| 166 | return MRI.getType(SrcMIB->getOperand(0).getReg()); |
| 167 | } |
| 168 | llvm_unreachable("Unrecognised SrcOp::SrcType enum"); |
| 169 | } |
| 170 | |
| 171 | Register getReg() const { |
| 172 | switch (Ty) { |
| 173 | case SrcType::Ty_Predicate: |
| 174 | case SrcType::Ty_Imm: |
| 175 | llvm_unreachable("Not a register operand"); |
| 176 | case SrcType::Ty_Reg: |
| 177 | return Reg; |
| 178 | case SrcType::Ty_MIB: |
| 179 | return SrcMIB->getOperand(0).getReg(); |
| 180 | } |
| 181 | llvm_unreachable("Unrecognised SrcOp::SrcType enum"); |
| 182 | } |
| 183 | |
| 184 | CmpInst::Predicate getPredicate() const { |
| 185 | switch (Ty) { |
| 186 | case SrcType::Ty_Predicate: |
| 187 | return Pred; |
| 188 | default: |
| 189 | llvm_unreachable("Not a register operand"); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | int64_t getImm() const { |
| 194 | switch (Ty) { |
| 195 | case SrcType::Ty_Imm: |
| 196 | return Imm; |
| 197 | default: |
| 198 | llvm_unreachable("Not an immediate"); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | SrcType getSrcOpKind() const { return Ty; } |
| 203 | |
| 204 | private: |
| 205 | SrcType Ty; |
| 206 | }; |
| 207 | |
| 208 | /// Helper class to build MachineInstr. |
| 209 | /// It keeps internally the insertion point and debug location for all |
| 210 | /// the new instructions we want to create. |
| 211 | /// This information can be modify via the related setters. |
| 212 | class MachineIRBuilder { |
| 213 | |
| 214 | MachineIRBuilderState State; |
| 215 | |
| 216 | protected: |
| 217 | void validateTruncExt(const LLT Dst, const LLT Src, bool IsExtend); |
| 218 | |
| 219 | void validateUnaryOp(const LLT Res, const LLT Op0); |
| 220 | void validateBinaryOp(const LLT Res, const LLT Op0, const LLT Op1); |
| 221 | void validateShiftOp(const LLT Res, const LLT Op0, const LLT Op1); |
| 222 | |
| 223 | void validateSelectOp(const LLT ResTy, const LLT TstTy, const LLT Op0Ty, |
| 224 | const LLT Op1Ty); |
| 225 | |
| 226 | void recordInsertion(MachineInstr *InsertedInstr) const { |
| 227 | if (State.Observer) |
| 228 | State.Observer->createdInstr(*InsertedInstr); |
| 229 | } |
| 230 | |
| 231 | public: |
| 232 | /// Some constructors for easy use. |
| 233 | MachineIRBuilder() = default; |
| 234 | MachineIRBuilder(MachineFunction &MF) { setMF(MF); } |
| 235 | |
| 236 | MachineIRBuilder(MachineBasicBlock &MBB, MachineBasicBlock::iterator InsPt) { |
| 237 | setMF(*MBB.getParent()); |
| 238 | setInsertPt(MBB, InsPt); |
| 239 | } |
| 240 | |
| 241 | MachineIRBuilder(MachineInstr &MI) : |
| 242 | MachineIRBuilder(*MI.getParent(), MI.getIterator()) { |
| 243 | setInstr(MI); |
| 244 | setDebugLoc(MI.getDebugLoc()); |
| 245 | } |
| 246 | |
| 247 | MachineIRBuilder(MachineInstr &MI, GISelChangeObserver &Observer) : |
| 248 | MachineIRBuilder(MI) { |
| 249 | setChangeObserver(Observer); |
| 250 | } |
| 251 | |
| 252 | virtual ~MachineIRBuilder() = default; |
| 253 | |
| 254 | MachineIRBuilder(const MachineIRBuilderState &BState) : State(BState) {} |
| 255 | |
| 256 | const TargetInstrInfo &getTII() { |
| 257 | assert(State.TII && "TargetInstrInfo is not set"); |
| 258 | return *State.TII; |
| 259 | } |
| 260 | |
| 261 | /// Getter for the function we currently build. |
| 262 | MachineFunction &getMF() { |
| 263 | assert(State.MF && "MachineFunction is not set"); |
| 264 | return *State.MF; |
| 265 | } |
| 266 | |
| 267 | const MachineFunction &getMF() const { |
| 268 | assert(State.MF && "MachineFunction is not set"); |
| 269 | return *State.MF; |
| 270 | } |
| 271 | |
| 272 | const DataLayout &getDataLayout() const { |
| 273 | return getMF().getFunction().getParent()->getDataLayout(); |
| 274 | } |
| 275 | |
| 276 | /// Getter for DebugLoc |
| 277 | const DebugLoc &getDL() { return State.DL; } |
| 278 | |
| 279 | /// Getter for MRI |
| 280 | MachineRegisterInfo *getMRI() { return State.MRI; } |
| 281 | const MachineRegisterInfo *getMRI() const { return State.MRI; } |
| 282 | |
| 283 | /// Getter for the State |
| 284 | MachineIRBuilderState &getState() { return State; } |
| 285 | |
| 286 | /// Getter for the basic block we currently build. |
| 287 | const MachineBasicBlock &getMBB() const { |
| 288 | assert(State.MBB && "MachineBasicBlock is not set"); |
| 289 | return *State.MBB; |
| 290 | } |
| 291 | |
| 292 | MachineBasicBlock &getMBB() { |
| 293 | return const_cast<MachineBasicBlock &>( |
| 294 | const_cast<const MachineIRBuilder *>(this)->getMBB()); |
| 295 | } |
| 296 | |
| 297 | GISelCSEInfo *getCSEInfo() { return State.CSEInfo; } |
| 298 | const GISelCSEInfo *getCSEInfo() const { return State.CSEInfo; } |
| 299 | |
| 300 | /// Current insertion point for new instructions. |
| 301 | MachineBasicBlock::iterator getInsertPt() { return State.II; } |
| 302 | |
| 303 | /// Set the insertion point before the specified position. |
| 304 | /// \pre MBB must be in getMF(). |
| 305 | /// \pre II must be a valid iterator in MBB. |
| 306 | void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II) { |
| 307 | assert(MBB.getParent() == &getMF() && |
| 308 | "Basic block is in a different function"); |
| 309 | State.MBB = &MBB; |
| 310 | State.II = II; |
| 311 | } |
| 312 | |
| 313 | /// @} |
| 314 | |
| 315 | void setCSEInfo(GISelCSEInfo *Info) { State.CSEInfo = Info; } |
| 316 | |
| 317 | /// \name Setters for the insertion point. |
| 318 | /// @{ |
| 319 | /// Set the MachineFunction where to build instructions. |
| 320 | void setMF(MachineFunction &MF); |
| 321 | |
| 322 | /// Set the insertion point to the end of \p MBB. |
| 323 | /// \pre \p MBB must be contained by getMF(). |
| 324 | void setMBB(MachineBasicBlock &MBB) { |
| 325 | State.MBB = &MBB; |
| 326 | State.II = MBB.end(); |
| 327 | assert(&getMF() == MBB.getParent() && |
| 328 | "Basic block is in a different function"); |
| 329 | } |
| 330 | |
| 331 | /// Set the insertion point to before MI. |
| 332 | /// \pre MI must be in getMF(). |
| 333 | void setInstr(MachineInstr &MI) { |
| 334 | assert(MI.getParent() && "Instruction is not part of a basic block"); |
| 335 | setMBB(*MI.getParent()); |
| 336 | State.II = MI.getIterator(); |
| 337 | } |
| 338 | /// @} |
| 339 | |
| 340 | /// Set the insertion point to before MI, and set the debug loc to MI's loc. |
| 341 | /// \pre MI must be in getMF(). |
| 342 | void setInstrAndDebugLoc(MachineInstr &MI) { |
| 343 | setInstr(MI); |
| 344 | setDebugLoc(MI.getDebugLoc()); |
| 345 | } |
| 346 | |
| 347 | void setChangeObserver(GISelChangeObserver &Observer) { |
| 348 | State.Observer = &Observer; |
| 349 | } |
| 350 | |
| 351 | void stopObservingChanges() { State.Observer = nullptr; } |
| 352 | /// @} |
| 353 | |
| 354 | /// Set the debug location to \p DL for all the next build instructions. |
| 355 | void setDebugLoc(const DebugLoc &DL) { this->State.DL = DL; } |
| 356 | |
| 357 | /// Get the current instruction's debug location. |
| 358 | const DebugLoc &getDebugLoc() { return State.DL; } |
| 359 | |
| 360 | /// Build and insert <empty> = \p Opcode <empty>. |
| 361 | /// The insertion point is the one set by the last call of either |
| 362 | /// setBasicBlock or setMI. |
| 363 | /// |
| 364 | /// \pre setBasicBlock or setMI must have been called. |
| 365 | /// |
| 366 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 367 | MachineInstrBuilder buildInstr(unsigned Opcode) { |
| 368 | return insertInstr(buildInstrNoInsert(Opcode)); |
| 369 | } |
| 370 | |
| 371 | /// Build but don't insert <empty> = \p Opcode <empty>. |
| 372 | /// |
| 373 | /// \pre setMF, setBasicBlock or setMI must have been called. |
| 374 | /// |
| 375 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 376 | MachineInstrBuilder buildInstrNoInsert(unsigned Opcode); |
| 377 | |
| 378 | /// Insert an existing instruction at the insertion point. |
| 379 | MachineInstrBuilder insertInstr(MachineInstrBuilder MIB); |
| 380 | |
| 381 | /// Build and insert a DBG_VALUE instruction expressing the fact that the |
| 382 | /// associated \p Variable lives in \p Reg (suitably modified by \p Expr). |
| 383 | MachineInstrBuilder buildDirectDbgValue(Register Reg, const MDNode *Variable, |
| 384 | const MDNode *Expr); |
| 385 | |
| 386 | /// Build and insert a DBG_VALUE instruction expressing the fact that the |
| 387 | /// associated \p Variable lives in memory at \p Reg (suitably modified by \p |
| 388 | /// Expr). |
| 389 | MachineInstrBuilder buildIndirectDbgValue(Register Reg, |
| 390 | const MDNode *Variable, |
| 391 | const MDNode *Expr); |
| 392 | |
| 393 | /// Build and insert a DBG_VALUE instruction expressing the fact that the |
| 394 | /// associated \p Variable lives in the stack slot specified by \p FI |
| 395 | /// (suitably modified by \p Expr). |
| 396 | MachineInstrBuilder buildFIDbgValue(int FI, const MDNode *Variable, |
| 397 | const MDNode *Expr); |
| 398 | |
| 399 | /// Build and insert a DBG_VALUE instructions specifying that \p Variable is |
| 400 | /// given by \p C (suitably modified by \p Expr). |
| 401 | MachineInstrBuilder buildConstDbgValue(const Constant &C, |
| 402 | const MDNode *Variable, |
| 403 | const MDNode *Expr); |
| 404 | |
| 405 | /// Build and insert a DBG_LABEL instructions specifying that \p Label is |
| 406 | /// given. Convert "llvm.dbg.label Label" to "DBG_LABEL Label". |
| 407 | MachineInstrBuilder buildDbgLabel(const MDNode *Label); |
| 408 | |
| 409 | /// Build and insert \p Res = G_DYN_STACKALLOC \p Size, \p Align |
| 410 | /// |
| 411 | /// G_DYN_STACKALLOC does a dynamic stack allocation and writes the address of |
| 412 | /// the allocated memory into \p Res. |
| 413 | /// \pre setBasicBlock or setMI must have been called. |
| 414 | /// \pre \p Res must be a generic virtual register with pointer type. |
| 415 | /// |
| 416 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 417 | MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size, |
| 418 | Align Alignment); |
| 419 | |
| 420 | /// Build and insert \p Res = G_FRAME_INDEX \p Idx |
| 421 | /// |
| 422 | /// G_FRAME_INDEX materializes the address of an alloca value or other |
| 423 | /// stack-based object. |
| 424 | /// |
| 425 | /// \pre setBasicBlock or setMI must have been called. |
| 426 | /// \pre \p Res must be a generic virtual register with pointer type. |
| 427 | /// |
| 428 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 429 | MachineInstrBuilder buildFrameIndex(const DstOp &Res, int Idx); |
| 430 | |
| 431 | /// Build and insert \p Res = G_GLOBAL_VALUE \p GV |
| 432 | /// |
| 433 | /// G_GLOBAL_VALUE materializes the address of the specified global |
| 434 | /// into \p Res. |
| 435 | /// |
| 436 | /// \pre setBasicBlock or setMI must have been called. |
| 437 | /// \pre \p Res must be a generic virtual register with pointer type |
| 438 | /// in the same address space as \p GV. |
| 439 | /// |
| 440 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 441 | MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV); |
| 442 | |
| 443 | /// Build and insert \p Res = G_PTR_ADD \p Op0, \p Op1 |
| 444 | /// |
| 445 | /// G_PTR_ADD adds \p Op1 addressible units to the pointer specified by \p Op0, |
| 446 | /// storing the resulting pointer in \p Res. Addressible units are typically |
| 447 | /// bytes but this can vary between targets. |
| 448 | /// |
| 449 | /// \pre setBasicBlock or setMI must have been called. |
| 450 | /// \pre \p Res and \p Op0 must be generic virtual registers with pointer |
| 451 | /// type. |
| 452 | /// \pre \p Op1 must be a generic virtual register with scalar type. |
| 453 | /// |
| 454 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 455 | MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0, |
| 456 | const SrcOp &Op1); |
| 457 | |
| 458 | /// Materialize and insert \p Res = G_PTR_ADD \p Op0, (G_CONSTANT \p Value) |
| 459 | /// |
| 460 | /// G_PTR_ADD adds \p Value bytes to the pointer specified by \p Op0, |
| 461 | /// storing the resulting pointer in \p Res. If \p Value is zero then no |
| 462 | /// G_PTR_ADD or G_CONSTANT will be created and \pre Op0 will be assigned to |
| 463 | /// \p Res. |
| 464 | /// |
| 465 | /// \pre setBasicBlock or setMI must have been called. |
| 466 | /// \pre \p Op0 must be a generic virtual register with pointer type. |
| 467 | /// \pre \p ValueTy must be a scalar type. |
| 468 | /// \pre \p Res must be 0. This is to detect confusion between |
| 469 | /// materializePtrAdd() and buildPtrAdd(). |
| 470 | /// \post \p Res will either be a new generic virtual register of the same |
| 471 | /// type as \p Op0 or \p Op0 itself. |
| 472 | /// |
| 473 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 474 | Optional<MachineInstrBuilder> materializePtrAdd(Register &Res, Register Op0, |
| 475 | const LLT ValueTy, |
| 476 | uint64_t Value); |
| 477 | |
| 478 | /// Build and insert \p Res = G_PTRMASK \p Op0, \p Op1 |
| 479 | MachineInstrBuilder buildPtrMask(const DstOp &Res, const SrcOp &Op0, |
| 480 | const SrcOp &Op1) { |
| 481 | return buildInstr(TargetOpcode::G_PTRMASK, {Res}, {Op0, Op1}); |
| 482 | } |
| 483 | |
| 484 | /// Build and insert \p Res = G_PTRMASK \p Op0, \p G_CONSTANT (1 << NumBits) - 1 |
| 485 | /// |
| 486 | /// This clears the low bits of a pointer operand without destroying its |
| 487 | /// pointer properties. This has the effect of rounding the address *down* to |
| 488 | /// a specified alignment in bits. |
| 489 | /// |
| 490 | /// \pre setBasicBlock or setMI must have been called. |
| 491 | /// \pre \p Res and \p Op0 must be generic virtual registers with pointer |
| 492 | /// type. |
| 493 | /// \pre \p NumBits must be an integer representing the number of low bits to |
| 494 | /// be cleared in \p Op0. |
| 495 | /// |
| 496 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 497 | MachineInstrBuilder buildMaskLowPtrBits(const DstOp &Res, const SrcOp &Op0, |
| 498 | uint32_t NumBits); |
| 499 | |
| 500 | /// Build and insert |
| 501 | /// a, b, ..., x = G_UNMERGE_VALUES \p Op0 |
| 502 | /// \p Res = G_BUILD_VECTOR a, b, ..., x, undef, ..., undef |
| 503 | /// |
| 504 | /// Pad \p Op0 with undef elements to match number of elements in \p Res. |
| 505 | /// |
| 506 | /// \pre setBasicBlock or setMI must have been called. |
| 507 | /// \pre \p Res and \p Op0 must be generic virtual registers with vector type, |
| 508 | /// same vector element type and Op0 must have fewer elements then Res. |
| 509 | /// |
| 510 | /// \return a MachineInstrBuilder for the newly created build vector instr. |
| 511 | MachineInstrBuilder buildPadVectorWithUndefElements(const DstOp &Res, |
| 512 | const SrcOp &Op0); |
| 513 | |
| 514 | /// Build and insert |
| 515 | /// a, b, ..., x, y, z = G_UNMERGE_VALUES \p Op0 |
| 516 | /// \p Res = G_BUILD_VECTOR a, b, ..., x |
| 517 | /// |
| 518 | /// Delete trailing elements in \p Op0 to match number of elements in \p Res. |
| 519 | /// |
| 520 | /// \pre setBasicBlock or setMI must have been called. |
| 521 | /// \pre \p Res and \p Op0 must be generic virtual registers with vector type, |
| 522 | /// same vector element type and Op0 must have more elements then Res. |
| 523 | /// |
| 524 | /// \return a MachineInstrBuilder for the newly created build vector instr. |
| 525 | MachineInstrBuilder buildDeleteTrailingVectorElements(const DstOp &Res, |
| 526 | const SrcOp &Op0); |
| 527 | |
| 528 | /// Build and insert \p Res, \p CarryOut = G_UADDO \p Op0, \p Op1 |
| 529 | /// |
| 530 | /// G_UADDO sets \p Res to \p Op0 + \p Op1 (truncated to the bit width) and |
| 531 | /// sets \p CarryOut to 1 if the result overflowed in unsigned arithmetic. |
| 532 | /// |
| 533 | /// \pre setBasicBlock or setMI must have been called. |
| 534 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers with the |
| 535 | /// same scalar type. |
| 536 | ////\pre \p CarryOut must be generic virtual register with scalar type |
| 537 | ///(typically s1) |
| 538 | /// |
| 539 | /// \return The newly created instruction. |
| 540 | MachineInstrBuilder buildUAddo(const DstOp &Res, const DstOp &CarryOut, |
| 541 | const SrcOp &Op0, const SrcOp &Op1) { |
| 542 | return buildInstr(TargetOpcode::G_UADDO, {Res, CarryOut}, {Op0, Op1}); |
| 543 | } |
| 544 | |
| 545 | /// Build and insert \p Res, \p CarryOut = G_USUBO \p Op0, \p Op1 |
| 546 | MachineInstrBuilder buildUSubo(const DstOp &Res, const DstOp &CarryOut, |
| 547 | const SrcOp &Op0, const SrcOp &Op1) { |
| 548 | return buildInstr(TargetOpcode::G_USUBO, {Res, CarryOut}, {Op0, Op1}); |
| 549 | } |
| 550 | |
| 551 | /// Build and insert \p Res, \p CarryOut = G_SADDO \p Op0, \p Op1 |
| 552 | MachineInstrBuilder buildSAddo(const DstOp &Res, const DstOp &CarryOut, |
| 553 | const SrcOp &Op0, const SrcOp &Op1) { |
| 554 | return buildInstr(TargetOpcode::G_SADDO, {Res, CarryOut}, {Op0, Op1}); |
| 555 | } |
| 556 | |
| 557 | /// Build and insert \p Res, \p CarryOut = G_SUBO \p Op0, \p Op1 |
| 558 | MachineInstrBuilder buildSSubo(const DstOp &Res, const DstOp &CarryOut, |
| 559 | const SrcOp &Op0, const SrcOp &Op1) { |
| 560 | return buildInstr(TargetOpcode::G_SSUBO, {Res, CarryOut}, {Op0, Op1}); |
| 561 | } |
| 562 | |
| 563 | /// Build and insert \p Res, \p CarryOut = G_UADDE \p Op0, |
| 564 | /// \p Op1, \p CarryIn |
| 565 | /// |
| 566 | /// G_UADDE sets \p Res to \p Op0 + \p Op1 + \p CarryIn (truncated to the bit |
| 567 | /// width) and sets \p CarryOut to 1 if the result overflowed in unsigned |
| 568 | /// arithmetic. |
| 569 | /// |
| 570 | /// \pre setBasicBlock or setMI must have been called. |
| 571 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 572 | /// with the same scalar type. |
| 573 | /// \pre \p CarryOut and \p CarryIn must be generic virtual |
| 574 | /// registers with the same scalar type (typically s1) |
| 575 | /// |
| 576 | /// \return The newly created instruction. |
| 577 | MachineInstrBuilder buildUAdde(const DstOp &Res, const DstOp &CarryOut, |
| 578 | const SrcOp &Op0, const SrcOp &Op1, |
| 579 | const SrcOp &CarryIn) { |
| 580 | return buildInstr(TargetOpcode::G_UADDE, {Res, CarryOut}, |
| 581 | {Op0, Op1, CarryIn}); |
| 582 | } |
| 583 | |
| 584 | /// Build and insert \p Res, \p CarryOut = G_USUBE \p Op0, \p Op1, \p CarryInp |
| 585 | MachineInstrBuilder buildUSube(const DstOp &Res, const DstOp &CarryOut, |
| 586 | const SrcOp &Op0, const SrcOp &Op1, |
| 587 | const SrcOp &CarryIn) { |
| 588 | return buildInstr(TargetOpcode::G_USUBE, {Res, CarryOut}, |
| 589 | {Op0, Op1, CarryIn}); |
| 590 | } |
| 591 | |
| 592 | /// Build and insert \p Res, \p CarryOut = G_SADDE \p Op0, \p Op1, \p CarryInp |
| 593 | MachineInstrBuilder buildSAdde(const DstOp &Res, const DstOp &CarryOut, |
| 594 | const SrcOp &Op0, const SrcOp &Op1, |
| 595 | const SrcOp &CarryIn) { |
| 596 | return buildInstr(TargetOpcode::G_SADDE, {Res, CarryOut}, |
| 597 | {Op0, Op1, CarryIn}); |
| 598 | } |
| 599 | |
| 600 | /// Build and insert \p Res, \p CarryOut = G_SSUBE \p Op0, \p Op1, \p CarryInp |
| 601 | MachineInstrBuilder buildSSube(const DstOp &Res, const DstOp &CarryOut, |
| 602 | const SrcOp &Op0, const SrcOp &Op1, |
| 603 | const SrcOp &CarryIn) { |
| 604 | return buildInstr(TargetOpcode::G_SSUBE, {Res, CarryOut}, |
| 605 | {Op0, Op1, CarryIn}); |
| 606 | } |
| 607 | |
| 608 | /// Build and insert \p Res = G_ANYEXT \p Op0 |
| 609 | /// |
| 610 | /// G_ANYEXT produces a register of the specified width, with bits 0 to |
| 611 | /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are unspecified |
| 612 | /// (i.e. this is neither zero nor sign-extension). For a vector register, |
| 613 | /// each element is extended individually. |
| 614 | /// |
| 615 | /// \pre setBasicBlock or setMI must have been called. |
| 616 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 617 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 618 | /// \pre \p Op must be smaller than \p Res |
| 619 | /// |
| 620 | /// \return The newly created instruction. |
| 621 | |
| 622 | MachineInstrBuilder buildAnyExt(const DstOp &Res, const SrcOp &Op); |
| 623 | |
| 624 | /// Build and insert \p Res = G_SEXT \p Op |
| 625 | /// |
| 626 | /// G_SEXT produces a register of the specified width, with bits 0 to |
| 627 | /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are duplicated from the |
| 628 | /// high bit of \p Op (i.e. 2s-complement sign extended). |
| 629 | /// |
| 630 | /// \pre setBasicBlock or setMI must have been called. |
| 631 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 632 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 633 | /// \pre \p Op must be smaller than \p Res |
| 634 | /// |
| 635 | /// \return The newly created instruction. |
| 636 | MachineInstrBuilder buildSExt(const DstOp &Res, const SrcOp &Op); |
| 637 | |
| 638 | /// Build and insert \p Res = G_SEXT_INREG \p Op, ImmOp |
| 639 | MachineInstrBuilder buildSExtInReg(const DstOp &Res, const SrcOp &Op, int64_t ImmOp) { |
| 640 | return buildInstr(TargetOpcode::G_SEXT_INREG, {Res}, {Op, SrcOp(ImmOp)}); |
| 641 | } |
| 642 | |
| 643 | /// Build and insert \p Res = G_FPEXT \p Op |
| 644 | MachineInstrBuilder buildFPExt(const DstOp &Res, const SrcOp &Op, |
| 645 | Optional<unsigned> Flags = None) { |
| 646 | return buildInstr(TargetOpcode::G_FPEXT, {Res}, {Op}, Flags); |
| 647 | } |
| 648 | |
| 649 | |
| 650 | /// Build and insert a G_PTRTOINT instruction. |
| 651 | MachineInstrBuilder buildPtrToInt(const DstOp &Dst, const SrcOp &Src) { |
| 652 | return buildInstr(TargetOpcode::G_PTRTOINT, {Dst}, {Src}); |
| 653 | } |
| 654 | |
| 655 | /// Build and insert a G_INTTOPTR instruction. |
| 656 | MachineInstrBuilder buildIntToPtr(const DstOp &Dst, const SrcOp &Src) { |
| 657 | return buildInstr(TargetOpcode::G_INTTOPTR, {Dst}, {Src}); |
| 658 | } |
| 659 | |
| 660 | /// Build and insert \p Dst = G_BITCAST \p Src |
| 661 | MachineInstrBuilder buildBitcast(const DstOp &Dst, const SrcOp &Src) { |
| 662 | return buildInstr(TargetOpcode::G_BITCAST, {Dst}, {Src}); |
| 663 | } |
| 664 | |
| 665 | /// Build and insert \p Dst = G_ADDRSPACE_CAST \p Src |
| 666 | MachineInstrBuilder buildAddrSpaceCast(const DstOp &Dst, const SrcOp &Src) { |
| 667 | return buildInstr(TargetOpcode::G_ADDRSPACE_CAST, {Dst}, {Src}); |
| 668 | } |
| 669 | |
| 670 | /// \return The opcode of the extension the target wants to use for boolean |
| 671 | /// values. |
| 672 | unsigned getBoolExtOp(bool IsVec, bool IsFP) const; |
| 673 | |
| 674 | // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_SEXT \p Op, or \p Res |
| 675 | // = G_ZEXT \p Op depending on how the target wants to extend boolean values. |
| 676 | MachineInstrBuilder buildBoolExt(const DstOp &Res, const SrcOp &Op, |
| 677 | bool IsFP); |
| 678 | |
| 679 | /// Build and insert \p Res = G_ZEXT \p Op |
| 680 | /// |
| 681 | /// G_ZEXT produces a register of the specified width, with bits 0 to |
| 682 | /// sizeof(\p Ty) * 8 set to \p Op. The remaining bits are 0. For a vector |
| 683 | /// register, each element is extended individually. |
| 684 | /// |
| 685 | /// \pre setBasicBlock or setMI must have been called. |
| 686 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 687 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 688 | /// \pre \p Op must be smaller than \p Res |
| 689 | /// |
| 690 | /// \return The newly created instruction. |
| 691 | MachineInstrBuilder buildZExt(const DstOp &Res, const SrcOp &Op); |
| 692 | |
| 693 | /// Build and insert \p Res = G_SEXT \p Op, \p Res = G_TRUNC \p Op, or |
| 694 | /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op. |
| 695 | /// /// |
| 696 | /// \pre setBasicBlock or setMI must have been called. |
| 697 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 698 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 699 | /// |
| 700 | /// \return The newly created instruction. |
| 701 | MachineInstrBuilder buildSExtOrTrunc(const DstOp &Res, const SrcOp &Op); |
| 702 | |
| 703 | /// Build and insert \p Res = G_ZEXT \p Op, \p Res = G_TRUNC \p Op, or |
| 704 | /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op. |
| 705 | /// /// |
| 706 | /// \pre setBasicBlock or setMI must have been called. |
| 707 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 708 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 709 | /// |
| 710 | /// \return The newly created instruction. |
| 711 | MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op); |
| 712 | |
| 713 | // Build and insert \p Res = G_ANYEXT \p Op, \p Res = G_TRUNC \p Op, or |
| 714 | /// \p Res = COPY \p Op depending on the differing sizes of \p Res and \p Op. |
| 715 | /// /// |
| 716 | /// \pre setBasicBlock or setMI must have been called. |
| 717 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 718 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 719 | /// |
| 720 | /// \return The newly created instruction. |
| 721 | MachineInstrBuilder buildAnyExtOrTrunc(const DstOp &Res, const SrcOp &Op); |
| 722 | |
| 723 | /// Build and insert \p Res = \p ExtOpc, \p Res = G_TRUNC \p |
| 724 | /// Op, or \p Res = COPY \p Op depending on the differing sizes of \p Res and |
| 725 | /// \p Op. |
| 726 | /// /// |
| 727 | /// \pre setBasicBlock or setMI must have been called. |
| 728 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 729 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 730 | /// |
| 731 | /// \return The newly created instruction. |
| 732 | MachineInstrBuilder buildExtOrTrunc(unsigned ExtOpc, const DstOp &Res, |
| 733 | const SrcOp &Op); |
| 734 | |
| 735 | /// Build and inserts \p Res = \p G_AND \p Op, \p LowBitsSet(ImmOp) |
| 736 | /// Since there is no G_ZEXT_INREG like G_SEXT_INREG, the instruction is |
| 737 | /// emulated using G_AND. |
| 738 | MachineInstrBuilder buildZExtInReg(const DstOp &Res, const SrcOp &Op, |
| 739 | int64_t ImmOp); |
| 740 | |
| 741 | /// Build and insert an appropriate cast between two registers of equal size. |
| 742 | MachineInstrBuilder buildCast(const DstOp &Dst, const SrcOp &Src); |
| 743 | |
| 744 | /// Build and insert G_BR \p Dest |
| 745 | /// |
| 746 | /// G_BR is an unconditional branch to \p Dest. |
| 747 | /// |
| 748 | /// \pre setBasicBlock or setMI must have been called. |
| 749 | /// |
| 750 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 751 | MachineInstrBuilder buildBr(MachineBasicBlock &Dest); |
| 752 | |
| 753 | /// Build and insert G_BRCOND \p Tst, \p Dest |
| 754 | /// |
| 755 | /// G_BRCOND is a conditional branch to \p Dest. |
| 756 | /// |
| 757 | /// \pre setBasicBlock or setMI must have been called. |
| 758 | /// \pre \p Tst must be a generic virtual register with scalar |
| 759 | /// type. At the beginning of legalization, this will be a single |
| 760 | /// bit (s1). Targets with interesting flags registers may change |
| 761 | /// this. For a wider type, whether the branch is taken must only |
| 762 | /// depend on bit 0 (for now). |
| 763 | /// |
| 764 | /// \return The newly created instruction. |
| 765 | MachineInstrBuilder buildBrCond(const SrcOp &Tst, MachineBasicBlock &Dest); |
| 766 | |
| 767 | /// Build and insert G_BRINDIRECT \p Tgt |
| 768 | /// |
| 769 | /// G_BRINDIRECT is an indirect branch to \p Tgt. |
| 770 | /// |
| 771 | /// \pre setBasicBlock or setMI must have been called. |
| 772 | /// \pre \p Tgt must be a generic virtual register with pointer type. |
| 773 | /// |
| 774 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 775 | MachineInstrBuilder buildBrIndirect(Register Tgt); |
| 776 | |
| 777 | /// Build and insert G_BRJT \p TablePtr, \p JTI, \p IndexReg |
| 778 | /// |
| 779 | /// G_BRJT is a jump table branch using a table base pointer \p TablePtr, |
| 780 | /// jump table index \p JTI and index \p IndexReg |
| 781 | /// |
| 782 | /// \pre setBasicBlock or setMI must have been called. |
| 783 | /// \pre \p TablePtr must be a generic virtual register with pointer type. |
| 784 | /// \pre \p JTI must be be a jump table index. |
| 785 | /// \pre \p IndexReg must be a generic virtual register with pointer type. |
| 786 | /// |
| 787 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 788 | MachineInstrBuilder buildBrJT(Register TablePtr, unsigned JTI, |
| 789 | Register IndexReg); |
| 790 | |
| 791 | /// Build and insert \p Res = G_CONSTANT \p Val |
| 792 | /// |
| 793 | /// G_CONSTANT is an integer constant with the specified size and value. \p |
| 794 | /// Val will be extended or truncated to the size of \p Reg. |
| 795 | /// |
| 796 | /// \pre setBasicBlock or setMI must have been called. |
| 797 | /// \pre \p Res must be a generic virtual register with scalar or pointer |
| 798 | /// type. |
| 799 | /// |
| 800 | /// \return The newly created instruction. |
| 801 | virtual MachineInstrBuilder buildConstant(const DstOp &Res, |
| 802 | const ConstantInt &Val); |
| 803 | |
| 804 | /// Build and insert \p Res = G_CONSTANT \p Val |
| 805 | /// |
| 806 | /// G_CONSTANT is an integer constant with the specified size and value. |
| 807 | /// |
| 808 | /// \pre setBasicBlock or setMI must have been called. |
| 809 | /// \pre \p Res must be a generic virtual register with scalar type. |
| 810 | /// |
| 811 | /// \return The newly created instruction. |
| 812 | MachineInstrBuilder buildConstant(const DstOp &Res, int64_t Val); |
| 813 | MachineInstrBuilder buildConstant(const DstOp &Res, const APInt &Val); |
| 814 | |
| 815 | /// Build and insert \p Res = G_FCONSTANT \p Val |
| 816 | /// |
| 817 | /// G_FCONSTANT is a floating-point constant with the specified size and |
| 818 | /// value. |
| 819 | /// |
| 820 | /// \pre setBasicBlock or setMI must have been called. |
| 821 | /// \pre \p Res must be a generic virtual register with scalar type. |
| 822 | /// |
| 823 | /// \return The newly created instruction. |
| 824 | virtual MachineInstrBuilder buildFConstant(const DstOp &Res, |
| 825 | const ConstantFP &Val); |
| 826 | |
| 827 | MachineInstrBuilder buildFConstant(const DstOp &Res, double Val); |
| 828 | MachineInstrBuilder buildFConstant(const DstOp &Res, const APFloat &Val); |
| 829 | |
| 830 | /// Build and insert \p Res = COPY Op |
| 831 | /// |
| 832 | /// Register-to-register COPY sets \p Res to \p Op. |
| 833 | /// |
| 834 | /// \pre setBasicBlock or setMI must have been called. |
| 835 | /// |
| 836 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 837 | MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op); |
| 838 | |
| 839 | |
| 840 | /// Build and insert G_ASSERT_SEXT, G_ASSERT_ZEXT, or G_ASSERT_ALIGN |
| 841 | /// |
| 842 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 843 | MachineInstrBuilder buildAssertOp(unsigned Opc, const DstOp &Res, const SrcOp &Op, |
| 844 | unsigned Val) { |
| 845 | return buildInstr(Opc, Res, Op).addImm(Val); |
| 846 | } |
| 847 | |
| 848 | /// Build and insert \p Res = G_ASSERT_ZEXT Op, Size |
| 849 | /// |
| 850 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 851 | MachineInstrBuilder buildAssertZExt(const DstOp &Res, const SrcOp &Op, |
| 852 | unsigned Size) { |
| 853 | return buildAssertOp(TargetOpcode::G_ASSERT_ZEXT, Res, Op, Size); |
| 854 | } |
| 855 | |
| 856 | /// Build and insert \p Res = G_ASSERT_SEXT Op, Size |
| 857 | /// |
| 858 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 859 | MachineInstrBuilder buildAssertSExt(const DstOp &Res, const SrcOp &Op, |
| 860 | unsigned Size) { |
| 861 | return buildAssertOp(TargetOpcode::G_ASSERT_SEXT, Res, Op, Size); |
| 862 | } |
| 863 | |
| 864 | /// Build and insert \p Res = G_ASSERT_ALIGN Op, AlignVal |
| 865 | /// |
| 866 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 867 | MachineInstrBuilder buildAssertAlign(const DstOp &Res, const SrcOp &Op, |
| 868 | Align AlignVal) { |
| 869 | return buildAssertOp(TargetOpcode::G_ASSERT_ALIGN, Res, Op, AlignVal.value()); |
| 870 | } |
| 871 | |
| 872 | /// Build and insert `Res = G_LOAD Addr, MMO`. |
| 873 | /// |
| 874 | /// Loads the value stored at \p Addr. Puts the result in \p Res. |
| 875 | /// |
| 876 | /// \pre setBasicBlock or setMI must have been called. |
| 877 | /// \pre \p Res must be a generic virtual register. |
| 878 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 879 | /// |
| 880 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 881 | MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, |
| 882 | MachineMemOperand &MMO) { |
| 883 | return buildLoadInstr(TargetOpcode::G_LOAD, Res, Addr, MMO); |
| 884 | } |
| 885 | |
| 886 | /// Build and insert a G_LOAD instruction, while constructing the |
| 887 | /// MachineMemOperand. |
| 888 | MachineInstrBuilder |
| 889 | buildLoad(const DstOp &Res, const SrcOp &Addr, MachinePointerInfo PtrInfo, |
| 890 | Align Alignment, |
| 891 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
| 892 | const AAMDNodes &AAInfo = AAMDNodes()); |
| 893 | |
| 894 | /// Build and insert `Res = <opcode> Addr, MMO`. |
| 895 | /// |
| 896 | /// Loads the value stored at \p Addr. Puts the result in \p Res. |
| 897 | /// |
| 898 | /// \pre setBasicBlock or setMI must have been called. |
| 899 | /// \pre \p Res must be a generic virtual register. |
| 900 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 901 | /// |
| 902 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 903 | MachineInstrBuilder buildLoadInstr(unsigned Opcode, const DstOp &Res, |
| 904 | const SrcOp &Addr, MachineMemOperand &MMO); |
| 905 | |
| 906 | /// Helper to create a load from a constant offset given a base address. Load |
| 907 | /// the type of \p Dst from \p Offset from the given base address and memory |
| 908 | /// operand. |
| 909 | MachineInstrBuilder buildLoadFromOffset(const DstOp &Dst, |
| 910 | const SrcOp &BasePtr, |
| 911 | MachineMemOperand &BaseMMO, |
| 912 | int64_t Offset); |
| 913 | |
| 914 | /// Build and insert `G_STORE Val, Addr, MMO`. |
| 915 | /// |
| 916 | /// Stores the value \p Val to \p Addr. |
| 917 | /// |
| 918 | /// \pre setBasicBlock or setMI must have been called. |
| 919 | /// \pre \p Val must be a generic virtual register. |
| 920 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 921 | /// |
| 922 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 923 | MachineInstrBuilder buildStore(const SrcOp &Val, const SrcOp &Addr, |
| 924 | MachineMemOperand &MMO); |
| 925 | |
| 926 | /// Build and insert a G_STORE instruction, while constructing the |
| 927 | /// MachineMemOperand. |
| 928 | MachineInstrBuilder |
| 929 | buildStore(const SrcOp &Val, const SrcOp &Addr, MachinePointerInfo PtrInfo, |
| 930 | Align Alignment, |
| 931 | MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone, |
| 932 | const AAMDNodes &AAInfo = AAMDNodes()); |
| 933 | |
| 934 | /// Build and insert `Res0, ... = G_EXTRACT Src, Idx0`. |
| 935 | /// |
| 936 | /// \pre setBasicBlock or setMI must have been called. |
| 937 | /// \pre \p Res and \p Src must be generic virtual registers. |
| 938 | /// |
| 939 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 940 | MachineInstrBuilder buildExtract(const DstOp &Res, const SrcOp &Src, uint64_t Index); |
| 941 | |
| 942 | /// Build and insert \p Res = IMPLICIT_DEF. |
| 943 | MachineInstrBuilder buildUndef(const DstOp &Res); |
| 944 | |
| 945 | /// Build and insert instructions to put \p Ops together at the specified p |
| 946 | /// Indices to form a larger register. |
| 947 | /// |
| 948 | /// If the types of the input registers are uniform and cover the entirity of |
| 949 | /// \p Res then a G_MERGE_VALUES will be produced. Otherwise an IMPLICIT_DEF |
| 950 | /// followed by a sequence of G_INSERT instructions. |
| 951 | /// |
| 952 | /// \pre setBasicBlock or setMI must have been called. |
| 953 | /// \pre The final element of the sequence must not extend past the end of the |
| 954 | /// destination register. |
| 955 | /// \pre The bits defined by each Op (derived from index and scalar size) must |
| 956 | /// not overlap. |
| 957 | /// \pre \p Indices must be in ascending order of bit position. |
| 958 | void buildSequence(Register Res, ArrayRef<Register> Ops, |
| 959 | ArrayRef<uint64_t> Indices); |
| 960 | |
| 961 | /// Build and insert \p Res = G_MERGE_VALUES \p Op0, ... |
| 962 | /// |
| 963 | /// G_MERGE_VALUES combines the input elements contiguously into a larger |
| 964 | /// register. |
| 965 | /// |
| 966 | /// \pre setBasicBlock or setMI must have been called. |
| 967 | /// \pre The entire register \p Res (and no more) must be covered by the input |
| 968 | /// registers. |
| 969 | /// \pre The type of all \p Ops registers must be identical. |
| 970 | /// |
| 971 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 972 | MachineInstrBuilder buildMerge(const DstOp &Res, ArrayRef<Register> Ops); |
| 973 | MachineInstrBuilder buildMerge(const DstOp &Res, |
| 974 | std::initializer_list<SrcOp> Ops); |
| 975 | |
| 976 | /// Build and insert \p Res0, ... = G_UNMERGE_VALUES \p Op |
| 977 | /// |
| 978 | /// G_UNMERGE_VALUES splits contiguous bits of the input into multiple |
| 979 | /// |
| 980 | /// \pre setBasicBlock or setMI must have been called. |
| 981 | /// \pre The entire register \p Res (and no more) must be covered by the input |
| 982 | /// registers. |
| 983 | /// \pre The type of all \p Res registers must be identical. |
| 984 | /// |
| 985 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 986 | MachineInstrBuilder buildUnmerge(ArrayRef<LLT> Res, const SrcOp &Op); |
| 987 | MachineInstrBuilder buildUnmerge(ArrayRef<Register> Res, const SrcOp &Op); |
| 988 | |
| 989 | /// Build and insert an unmerge of \p Res sized pieces to cover \p Op |
| 990 | MachineInstrBuilder buildUnmerge(LLT Res, const SrcOp &Op); |
| 991 | |
| 992 | /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ... |
| 993 | /// |
| 994 | /// G_BUILD_VECTOR creates a vector value from multiple scalar registers. |
| 995 | /// \pre setBasicBlock or setMI must have been called. |
| 996 | /// \pre The entire register \p Res (and no more) must be covered by the |
| 997 | /// input scalar registers. |
| 998 | /// \pre The type of all \p Ops registers must be identical. |
| 999 | /// |
| 1000 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1001 | MachineInstrBuilder buildBuildVector(const DstOp &Res, |
| 1002 | ArrayRef<Register> Ops); |
| 1003 | |
| 1004 | /// Build and insert \p Res = G_BUILD_VECTOR with \p Src replicated to fill |
| 1005 | /// the number of elements |
| 1006 | MachineInstrBuilder buildSplatVector(const DstOp &Res, |
| 1007 | const SrcOp &Src); |
| 1008 | |
| 1009 | /// Build and insert \p Res = G_BUILD_VECTOR_TRUNC \p Op0, ... |
| 1010 | /// |
| 1011 | /// G_BUILD_VECTOR_TRUNC creates a vector value from multiple scalar registers |
| 1012 | /// which have types larger than the destination vector element type, and |
| 1013 | /// truncates the values to fit. |
| 1014 | /// |
| 1015 | /// If the operands given are already the same size as the vector elt type, |
| 1016 | /// then this method will instead create a G_BUILD_VECTOR instruction. |
| 1017 | /// |
| 1018 | /// \pre setBasicBlock or setMI must have been called. |
| 1019 | /// \pre The type of all \p Ops registers must be identical. |
| 1020 | /// |
| 1021 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1022 | MachineInstrBuilder buildBuildVectorTrunc(const DstOp &Res, |
| 1023 | ArrayRef<Register> Ops); |
| 1024 | |
| 1025 | /// Build and insert a vector splat of a scalar \p Src using a |
| 1026 | /// G_INSERT_VECTOR_ELT and G_SHUFFLE_VECTOR idiom. |
| 1027 | /// |
| 1028 | /// \pre setBasicBlock or setMI must have been called. |
| 1029 | /// \pre \p Src must have the same type as the element type of \p Dst |
| 1030 | /// |
| 1031 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1032 | MachineInstrBuilder buildShuffleSplat(const DstOp &Res, const SrcOp &Src); |
| 1033 | |
| 1034 | /// Build and insert \p Res = G_SHUFFLE_VECTOR \p Src1, \p Src2, \p Mask |
| 1035 | /// |
| 1036 | /// \pre setBasicBlock or setMI must have been called. |
| 1037 | /// |
| 1038 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1039 | MachineInstrBuilder buildShuffleVector(const DstOp &Res, const SrcOp &Src1, |
| 1040 | const SrcOp &Src2, ArrayRef<int> Mask); |
| 1041 | |
| 1042 | /// Build and insert \p Res = G_CONCAT_VECTORS \p Op0, ... |
| 1043 | /// |
| 1044 | /// G_CONCAT_VECTORS creates a vector from the concatenation of 2 or more |
| 1045 | /// vectors. |
| 1046 | /// |
| 1047 | /// \pre setBasicBlock or setMI must have been called. |
| 1048 | /// \pre The entire register \p Res (and no more) must be covered by the input |
| 1049 | /// registers. |
| 1050 | /// \pre The type of all source operands must be identical. |
| 1051 | /// |
| 1052 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1053 | MachineInstrBuilder buildConcatVectors(const DstOp &Res, |
| 1054 | ArrayRef<Register> Ops); |
| 1055 | |
| 1056 | MachineInstrBuilder buildInsert(const DstOp &Res, const SrcOp &Src, |
| 1057 | const SrcOp &Op, unsigned Index); |
| 1058 | |
| 1059 | /// Build and insert either a G_INTRINSIC (if \p HasSideEffects is false) or |
| 1060 | /// G_INTRINSIC_W_SIDE_EFFECTS instruction. Its first operand will be the |
| 1061 | /// result register definition unless \p Reg is NoReg (== 0). The second |
| 1062 | /// operand will be the intrinsic's ID. |
| 1063 | /// |
| 1064 | /// Callers are expected to add the required definitions and uses afterwards. |
| 1065 | /// |
| 1066 | /// \pre setBasicBlock or setMI must have been called. |
| 1067 | /// |
| 1068 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1069 | MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<Register> Res, |
| 1070 | bool HasSideEffects); |
| 1071 | MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef<DstOp> Res, |
| 1072 | bool HasSideEffects); |
| 1073 | |
| 1074 | /// Build and insert \p Res = G_FPTRUNC \p Op |
| 1075 | /// |
| 1076 | /// G_FPTRUNC converts a floating-point value into one with a smaller type. |
| 1077 | /// |
| 1078 | /// \pre setBasicBlock or setMI must have been called. |
| 1079 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 1080 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 1081 | /// \pre \p Res must be smaller than \p Op |
| 1082 | /// |
| 1083 | /// \return The newly created instruction. |
| 1084 | MachineInstrBuilder buildFPTrunc(const DstOp &Res, const SrcOp &Op, |
| 1085 | Optional<unsigned> Flags = None); |
| 1086 | |
| 1087 | /// Build and insert \p Res = G_TRUNC \p Op |
| 1088 | /// |
| 1089 | /// G_TRUNC extracts the low bits of a type. For a vector type each element is |
| 1090 | /// truncated independently before being packed into the destination. |
| 1091 | /// |
| 1092 | /// \pre setBasicBlock or setMI must have been called. |
| 1093 | /// \pre \p Res must be a generic virtual register with scalar or vector type. |
| 1094 | /// \pre \p Op must be a generic virtual register with scalar or vector type. |
| 1095 | /// \pre \p Res must be smaller than \p Op |
| 1096 | /// |
| 1097 | /// \return The newly created instruction. |
| 1098 | MachineInstrBuilder buildTrunc(const DstOp &Res, const SrcOp &Op); |
| 1099 | |
| 1100 | /// Build and insert a \p Res = G_ICMP \p Pred, \p Op0, \p Op1 |
| 1101 | /// |
| 1102 | /// \pre setBasicBlock or setMI must have been called. |
| 1103 | |
| 1104 | /// \pre \p Res must be a generic virtual register with scalar or |
| 1105 | /// vector type. Typically this starts as s1 or <N x s1>. |
| 1106 | /// \pre \p Op0 and Op1 must be generic virtual registers with the |
| 1107 | /// same number of elements as \p Res. If \p Res is a scalar, |
| 1108 | /// \p Op0 must be either a scalar or pointer. |
| 1109 | /// \pre \p Pred must be an integer predicate. |
| 1110 | /// |
| 1111 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1112 | MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, |
| 1113 | const SrcOp &Op0, const SrcOp &Op1); |
| 1114 | |
| 1115 | /// Build and insert a \p Res = G_FCMP \p Pred\p Op0, \p Op1 |
| 1116 | /// |
| 1117 | /// \pre setBasicBlock or setMI must have been called. |
| 1118 | |
| 1119 | /// \pre \p Res must be a generic virtual register with scalar or |
| 1120 | /// vector type. Typically this starts as s1 or <N x s1>. |
| 1121 | /// \pre \p Op0 and Op1 must be generic virtual registers with the |
| 1122 | /// same number of elements as \p Res (or scalar, if \p Res is |
| 1123 | /// scalar). |
| 1124 | /// \pre \p Pred must be a floating-point predicate. |
| 1125 | /// |
| 1126 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1127 | MachineInstrBuilder buildFCmp(CmpInst::Predicate Pred, const DstOp &Res, |
| 1128 | const SrcOp &Op0, const SrcOp &Op1, |
| 1129 | Optional<unsigned> Flags = None); |
| 1130 | |
| 1131 | /// Build and insert a \p Res = G_SELECT \p Tst, \p Op0, \p Op1 |
| 1132 | /// |
| 1133 | /// \pre setBasicBlock or setMI must have been called. |
| 1134 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 1135 | /// with the same type. |
| 1136 | /// \pre \p Tst must be a generic virtual register with scalar, pointer or |
| 1137 | /// vector type. If vector then it must have the same number of |
| 1138 | /// elements as the other parameters. |
| 1139 | /// |
| 1140 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1141 | MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst, |
| 1142 | const SrcOp &Op0, const SrcOp &Op1, |
| 1143 | Optional<unsigned> Flags = None); |
| 1144 | |
| 1145 | /// Build and insert \p Res = G_INSERT_VECTOR_ELT \p Val, |
| 1146 | /// \p Elt, \p Idx |
| 1147 | /// |
| 1148 | /// \pre setBasicBlock or setMI must have been called. |
| 1149 | /// \pre \p Res and \p Val must be a generic virtual register |
| 1150 | // with the same vector type. |
| 1151 | /// \pre \p Elt and \p Idx must be a generic virtual register |
| 1152 | /// with scalar type. |
| 1153 | /// |
| 1154 | /// \return The newly created instruction. |
| 1155 | MachineInstrBuilder buildInsertVectorElement(const DstOp &Res, |
| 1156 | const SrcOp &Val, |
| 1157 | const SrcOp &Elt, |
| 1158 | const SrcOp &Idx); |
| 1159 | |
| 1160 | /// Build and insert \p Res = G_EXTRACT_VECTOR_ELT \p Val, \p Idx |
| 1161 | /// |
| 1162 | /// \pre setBasicBlock or setMI must have been called. |
| 1163 | /// \pre \p Res must be a generic virtual register with scalar type. |
| 1164 | /// \pre \p Val must be a generic virtual register with vector type. |
| 1165 | /// \pre \p Idx must be a generic virtual register with scalar type. |
| 1166 | /// |
| 1167 | /// \return The newly created instruction. |
| 1168 | MachineInstrBuilder buildExtractVectorElement(const DstOp &Res, |
| 1169 | const SrcOp &Val, |
| 1170 | const SrcOp &Idx); |
| 1171 | |
| 1172 | /// Build and insert `OldValRes<def>, SuccessRes<def> = |
| 1173 | /// G_ATOMIC_CMPXCHG_WITH_SUCCESS Addr, CmpVal, NewVal, MMO`. |
| 1174 | /// |
| 1175 | /// Atomically replace the value at \p Addr with \p NewVal if it is currently |
| 1176 | /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p |
| 1177 | /// Addr in \p Res, along with an s1 indicating whether it was replaced. |
| 1178 | /// |
| 1179 | /// \pre setBasicBlock or setMI must have been called. |
| 1180 | /// \pre \p OldValRes must be a generic virtual register of scalar type. |
| 1181 | /// \pre \p SuccessRes must be a generic virtual register of scalar type. It |
| 1182 | /// will be assigned 0 on failure and 1 on success. |
| 1183 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1184 | /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual |
| 1185 | /// registers of the same type. |
| 1186 | /// |
| 1187 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1188 | MachineInstrBuilder |
| 1189 | buildAtomicCmpXchgWithSuccess(Register OldValRes, Register SuccessRes, |
| 1190 | Register Addr, Register CmpVal, Register NewVal, |
| 1191 | MachineMemOperand &MMO); |
| 1192 | |
| 1193 | /// Build and insert `OldValRes<def> = G_ATOMIC_CMPXCHG Addr, CmpVal, NewVal, |
| 1194 | /// MMO`. |
| 1195 | /// |
| 1196 | /// Atomically replace the value at \p Addr with \p NewVal if it is currently |
| 1197 | /// \p CmpVal otherwise leaves it unchanged. Puts the original value from \p |
| 1198 | /// Addr in \p Res. |
| 1199 | /// |
| 1200 | /// \pre setBasicBlock or setMI must have been called. |
| 1201 | /// \pre \p OldValRes must be a generic virtual register of scalar type. |
| 1202 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1203 | /// \pre \p OldValRes, \p CmpVal, and \p NewVal must be generic virtual |
| 1204 | /// registers of the same type. |
| 1205 | /// |
| 1206 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1207 | MachineInstrBuilder buildAtomicCmpXchg(Register OldValRes, Register Addr, |
| 1208 | Register CmpVal, Register NewVal, |
| 1209 | MachineMemOperand &MMO); |
| 1210 | |
| 1211 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_<Opcode> Addr, Val, MMO`. |
| 1212 | /// |
| 1213 | /// Atomically read-modify-update the value at \p Addr with \p Val. Puts the |
| 1214 | /// original value from \p Addr in \p OldValRes. The modification is |
| 1215 | /// determined by the opcode. |
| 1216 | /// |
| 1217 | /// \pre setBasicBlock or setMI must have been called. |
| 1218 | /// \pre \p OldValRes must be a generic virtual register. |
| 1219 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1220 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1221 | /// same type. |
| 1222 | /// |
| 1223 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1224 | MachineInstrBuilder buildAtomicRMW(unsigned Opcode, const DstOp &OldValRes, |
| 1225 | const SrcOp &Addr, const SrcOp &Val, |
| 1226 | MachineMemOperand &MMO); |
| 1227 | |
| 1228 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_XCHG Addr, Val, MMO`. |
| 1229 | /// |
| 1230 | /// Atomically replace the value at \p Addr with \p Val. Puts the original |
| 1231 | /// value from \p Addr in \p OldValRes. |
| 1232 | /// |
| 1233 | /// \pre setBasicBlock or setMI must have been called. |
| 1234 | /// \pre \p OldValRes must be a generic virtual register. |
| 1235 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1236 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1237 | /// same type. |
| 1238 | /// |
| 1239 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1240 | MachineInstrBuilder buildAtomicRMWXchg(Register OldValRes, Register Addr, |
| 1241 | Register Val, MachineMemOperand &MMO); |
| 1242 | |
| 1243 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_ADD Addr, Val, MMO`. |
| 1244 | /// |
| 1245 | /// Atomically replace the value at \p Addr with the addition of \p Val and |
| 1246 | /// the original value. Puts the original value from \p Addr in \p OldValRes. |
| 1247 | /// |
| 1248 | /// \pre setBasicBlock or setMI must have been called. |
| 1249 | /// \pre \p OldValRes must be a generic virtual register. |
| 1250 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1251 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1252 | /// same type. |
| 1253 | /// |
| 1254 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1255 | MachineInstrBuilder buildAtomicRMWAdd(Register OldValRes, Register Addr, |
| 1256 | Register Val, MachineMemOperand &MMO); |
| 1257 | |
| 1258 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_SUB Addr, Val, MMO`. |
| 1259 | /// |
| 1260 | /// Atomically replace the value at \p Addr with the subtraction of \p Val and |
| 1261 | /// the original value. Puts the original value from \p Addr in \p OldValRes. |
| 1262 | /// |
| 1263 | /// \pre setBasicBlock or setMI must have been called. |
| 1264 | /// \pre \p OldValRes must be a generic virtual register. |
| 1265 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1266 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1267 | /// same type. |
| 1268 | /// |
| 1269 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1270 | MachineInstrBuilder buildAtomicRMWSub(Register OldValRes, Register Addr, |
| 1271 | Register Val, MachineMemOperand &MMO); |
| 1272 | |
| 1273 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_AND Addr, Val, MMO`. |
| 1274 | /// |
| 1275 | /// Atomically replace the value at \p Addr with the bitwise and of \p Val and |
| 1276 | /// the original value. Puts the original value from \p Addr in \p OldValRes. |
| 1277 | /// |
| 1278 | /// \pre setBasicBlock or setMI must have been called. |
| 1279 | /// \pre \p OldValRes must be a generic virtual register. |
| 1280 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1281 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1282 | /// same type. |
| 1283 | /// |
| 1284 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1285 | MachineInstrBuilder buildAtomicRMWAnd(Register OldValRes, Register Addr, |
| 1286 | Register Val, MachineMemOperand &MMO); |
| 1287 | |
| 1288 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_NAND Addr, Val, MMO`. |
| 1289 | /// |
| 1290 | /// Atomically replace the value at \p Addr with the bitwise nand of \p Val |
| 1291 | /// and the original value. Puts the original value from \p Addr in \p |
| 1292 | /// OldValRes. |
| 1293 | /// |
| 1294 | /// \pre setBasicBlock or setMI must have been called. |
| 1295 | /// \pre \p OldValRes must be a generic virtual register. |
| 1296 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1297 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1298 | /// same type. |
| 1299 | /// |
| 1300 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1301 | MachineInstrBuilder buildAtomicRMWNand(Register OldValRes, Register Addr, |
| 1302 | Register Val, MachineMemOperand &MMO); |
| 1303 | |
| 1304 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_OR Addr, Val, MMO`. |
| 1305 | /// |
| 1306 | /// Atomically replace the value at \p Addr with the bitwise or of \p Val and |
| 1307 | /// the original value. Puts the original value from \p Addr in \p OldValRes. |
| 1308 | /// |
| 1309 | /// \pre setBasicBlock or setMI must have been called. |
| 1310 | /// \pre \p OldValRes must be a generic virtual register. |
| 1311 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1312 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1313 | /// same type. |
| 1314 | /// |
| 1315 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1316 | MachineInstrBuilder buildAtomicRMWOr(Register OldValRes, Register Addr, |
| 1317 | Register Val, MachineMemOperand &MMO); |
| 1318 | |
| 1319 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_XOR Addr, Val, MMO`. |
| 1320 | /// |
| 1321 | /// Atomically replace the value at \p Addr with the bitwise xor of \p Val and |
| 1322 | /// the original value. Puts the original value from \p Addr in \p OldValRes. |
| 1323 | /// |
| 1324 | /// \pre setBasicBlock or setMI must have been called. |
| 1325 | /// \pre \p OldValRes must be a generic virtual register. |
| 1326 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1327 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1328 | /// same type. |
| 1329 | /// |
| 1330 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1331 | MachineInstrBuilder buildAtomicRMWXor(Register OldValRes, Register Addr, |
| 1332 | Register Val, MachineMemOperand &MMO); |
| 1333 | |
| 1334 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_MAX Addr, Val, MMO`. |
| 1335 | /// |
| 1336 | /// Atomically replace the value at \p Addr with the signed maximum of \p |
| 1337 | /// Val and the original value. Puts the original value from \p Addr in \p |
| 1338 | /// OldValRes. |
| 1339 | /// |
| 1340 | /// \pre setBasicBlock or setMI must have been called. |
| 1341 | /// \pre \p OldValRes must be a generic virtual register. |
| 1342 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1343 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1344 | /// same type. |
| 1345 | /// |
| 1346 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1347 | MachineInstrBuilder buildAtomicRMWMax(Register OldValRes, Register Addr, |
| 1348 | Register Val, MachineMemOperand &MMO); |
| 1349 | |
| 1350 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_MIN Addr, Val, MMO`. |
| 1351 | /// |
| 1352 | /// Atomically replace the value at \p Addr with the signed minimum of \p |
| 1353 | /// Val and the original value. Puts the original value from \p Addr in \p |
| 1354 | /// OldValRes. |
| 1355 | /// |
| 1356 | /// \pre setBasicBlock or setMI must have been called. |
| 1357 | /// \pre \p OldValRes must be a generic virtual register. |
| 1358 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1359 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1360 | /// same type. |
| 1361 | /// |
| 1362 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1363 | MachineInstrBuilder buildAtomicRMWMin(Register OldValRes, Register Addr, |
| 1364 | Register Val, MachineMemOperand &MMO); |
| 1365 | |
| 1366 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMAX Addr, Val, MMO`. |
| 1367 | /// |
| 1368 | /// Atomically replace the value at \p Addr with the unsigned maximum of \p |
| 1369 | /// Val and the original value. Puts the original value from \p Addr in \p |
| 1370 | /// OldValRes. |
| 1371 | /// |
| 1372 | /// \pre setBasicBlock or setMI must have been called. |
| 1373 | /// \pre \p OldValRes must be a generic virtual register. |
| 1374 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1375 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1376 | /// same type. |
| 1377 | /// |
| 1378 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1379 | MachineInstrBuilder buildAtomicRMWUmax(Register OldValRes, Register Addr, |
| 1380 | Register Val, MachineMemOperand &MMO); |
| 1381 | |
| 1382 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_UMIN Addr, Val, MMO`. |
| 1383 | /// |
| 1384 | /// Atomically replace the value at \p Addr with the unsigned minimum of \p |
| 1385 | /// Val and the original value. Puts the original value from \p Addr in \p |
| 1386 | /// OldValRes. |
| 1387 | /// |
| 1388 | /// \pre setBasicBlock or setMI must have been called. |
| 1389 | /// \pre \p OldValRes must be a generic virtual register. |
| 1390 | /// \pre \p Addr must be a generic virtual register with pointer type. |
| 1391 | /// \pre \p OldValRes, and \p Val must be generic virtual registers of the |
| 1392 | /// same type. |
| 1393 | /// |
| 1394 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1395 | MachineInstrBuilder buildAtomicRMWUmin(Register OldValRes, Register Addr, |
| 1396 | Register Val, MachineMemOperand &MMO); |
| 1397 | |
| 1398 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_FADD Addr, Val, MMO`. |
| 1399 | MachineInstrBuilder buildAtomicRMWFAdd( |
| 1400 | const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, |
| 1401 | MachineMemOperand &MMO); |
| 1402 | |
| 1403 | /// Build and insert `OldValRes<def> = G_ATOMICRMW_FSUB Addr, Val, MMO`. |
| 1404 | MachineInstrBuilder buildAtomicRMWFSub( |
| 1405 | const DstOp &OldValRes, const SrcOp &Addr, const SrcOp &Val, |
| 1406 | MachineMemOperand &MMO); |
| 1407 | |
| 1408 | /// Build and insert `G_FENCE Ordering, Scope`. |
| 1409 | MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope); |
| 1410 | |
| 1411 | /// Build and insert \p Dst = G_FREEZE \p Src |
| 1412 | MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src) { |
| 1413 | return buildInstr(TargetOpcode::G_FREEZE, {Dst}, {Src}); |
| 1414 | } |
| 1415 | |
| 1416 | /// Build and insert \p Res = G_BLOCK_ADDR \p BA |
| 1417 | /// |
| 1418 | /// G_BLOCK_ADDR computes the address of a basic block. |
| 1419 | /// |
| 1420 | /// \pre setBasicBlock or setMI must have been called. |
| 1421 | /// \pre \p Res must be a generic virtual register of a pointer type. |
| 1422 | /// |
| 1423 | /// \return The newly created instruction. |
| 1424 | MachineInstrBuilder buildBlockAddress(Register Res, const BlockAddress *BA); |
| 1425 | |
| 1426 | /// Build and insert \p Res = G_ADD \p Op0, \p Op1 |
| 1427 | /// |
| 1428 | /// G_ADD sets \p Res to the sum of integer parameters \p Op0 and \p Op1, |
| 1429 | /// truncated to their width. |
| 1430 | /// |
| 1431 | /// \pre setBasicBlock or setMI must have been called. |
| 1432 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 1433 | /// with the same (scalar or vector) type). |
| 1434 | /// |
| 1435 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1436 | |
| 1437 | MachineInstrBuilder buildAdd(const DstOp &Dst, const SrcOp &Src0, |
| 1438 | const SrcOp &Src1, |
| 1439 | Optional<unsigned> Flags = None) { |
| 1440 | return buildInstr(TargetOpcode::G_ADD, {Dst}, {Src0, Src1}, Flags); |
| 1441 | } |
| 1442 | |
| 1443 | /// Build and insert \p Res = G_SUB \p Op0, \p Op1 |
| 1444 | /// |
| 1445 | /// G_SUB sets \p Res to the sum of integer parameters \p Op0 and \p Op1, |
| 1446 | /// truncated to their width. |
| 1447 | /// |
| 1448 | /// \pre setBasicBlock or setMI must have been called. |
| 1449 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 1450 | /// with the same (scalar or vector) type). |
| 1451 | /// |
| 1452 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1453 | |
| 1454 | MachineInstrBuilder buildSub(const DstOp &Dst, const SrcOp &Src0, |
| 1455 | const SrcOp &Src1, |
| 1456 | Optional<unsigned> Flags = None) { |
| 1457 | return buildInstr(TargetOpcode::G_SUB, {Dst}, {Src0, Src1}, Flags); |
| 1458 | } |
| 1459 | |
| 1460 | /// Build and insert \p Res = G_MUL \p Op0, \p Op1 |
| 1461 | /// |
| 1462 | /// G_MUL sets \p Res to the sum of integer parameters \p Op0 and \p Op1, |
| 1463 | /// truncated to their width. |
| 1464 | /// |
| 1465 | /// \pre setBasicBlock or setMI must have been called. |
| 1466 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 1467 | /// with the same (scalar or vector) type). |
| 1468 | /// |
| 1469 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1470 | MachineInstrBuilder buildMul(const DstOp &Dst, const SrcOp &Src0, |
| 1471 | const SrcOp &Src1, |
| 1472 | Optional<unsigned> Flags = None) { |
| 1473 | return buildInstr(TargetOpcode::G_MUL, {Dst}, {Src0, Src1}, Flags); |
| 1474 | } |
| 1475 | |
| 1476 | MachineInstrBuilder buildUMulH(const DstOp &Dst, const SrcOp &Src0, |
| 1477 | const SrcOp &Src1, |
| 1478 | Optional<unsigned> Flags = None) { |
| 1479 | return buildInstr(TargetOpcode::G_UMULH, {Dst}, {Src0, Src1}, Flags); |
| 1480 | } |
| 1481 | |
| 1482 | MachineInstrBuilder buildSMulH(const DstOp &Dst, const SrcOp &Src0, |
| 1483 | const SrcOp &Src1, |
| 1484 | Optional<unsigned> Flags = None) { |
| 1485 | return buildInstr(TargetOpcode::G_SMULH, {Dst}, {Src0, Src1}, Flags); |
| 1486 | } |
| 1487 | |
| 1488 | /// Build and insert \p Res = G_UREM \p Op0, \p Op1 |
| 1489 | MachineInstrBuilder buildURem(const DstOp &Dst, const SrcOp &Src0, |
| 1490 | const SrcOp &Src1, |
| 1491 | Optional<unsigned> Flags = None) { |
| 1492 | return buildInstr(TargetOpcode::G_UREM, {Dst}, {Src0, Src1}, Flags); |
| 1493 | } |
| 1494 | |
| 1495 | MachineInstrBuilder buildFMul(const DstOp &Dst, const SrcOp &Src0, |
| 1496 | const SrcOp &Src1, |
| 1497 | Optional<unsigned> Flags = None) { |
| 1498 | return buildInstr(TargetOpcode::G_FMUL, {Dst}, {Src0, Src1}, Flags); |
| 1499 | } |
| 1500 | |
| 1501 | MachineInstrBuilder buildFMinNum(const DstOp &Dst, const SrcOp &Src0, |
| 1502 | const SrcOp &Src1, |
| 1503 | Optional<unsigned> Flags = None) { |
| 1504 | return buildInstr(TargetOpcode::G_FMINNUM, {Dst}, {Src0, Src1}, Flags); |
| 1505 | } |
| 1506 | |
| 1507 | MachineInstrBuilder buildFMaxNum(const DstOp &Dst, const SrcOp &Src0, |
| 1508 | const SrcOp &Src1, |
| 1509 | Optional<unsigned> Flags = None) { |
| 1510 | return buildInstr(TargetOpcode::G_FMAXNUM, {Dst}, {Src0, Src1}, Flags); |
| 1511 | } |
| 1512 | |
| 1513 | MachineInstrBuilder buildFMinNumIEEE(const DstOp &Dst, const SrcOp &Src0, |
| 1514 | const SrcOp &Src1, |
| 1515 | Optional<unsigned> Flags = None) { |
| 1516 | return buildInstr(TargetOpcode::G_FMINNUM_IEEE, {Dst}, {Src0, Src1}, Flags); |
| 1517 | } |
| 1518 | |
| 1519 | MachineInstrBuilder buildFMaxNumIEEE(const DstOp &Dst, const SrcOp &Src0, |
| 1520 | const SrcOp &Src1, |
| 1521 | Optional<unsigned> Flags = None) { |
| 1522 | return buildInstr(TargetOpcode::G_FMAXNUM_IEEE, {Dst}, {Src0, Src1}, Flags); |
| 1523 | } |
| 1524 | |
| 1525 | MachineInstrBuilder buildShl(const DstOp &Dst, const SrcOp &Src0, |
| 1526 | const SrcOp &Src1, |
| 1527 | Optional<unsigned> Flags = None) { |
| 1528 | return buildInstr(TargetOpcode::G_SHL, {Dst}, {Src0, Src1}, Flags); |
| 1529 | } |
| 1530 | |
| 1531 | MachineInstrBuilder buildLShr(const DstOp &Dst, const SrcOp &Src0, |
| 1532 | const SrcOp &Src1, |
| 1533 | Optional<unsigned> Flags = None) { |
| 1534 | return buildInstr(TargetOpcode::G_LSHR, {Dst}, {Src0, Src1}, Flags); |
| 1535 | } |
| 1536 | |
| 1537 | MachineInstrBuilder buildAShr(const DstOp &Dst, const SrcOp &Src0, |
| 1538 | const SrcOp &Src1, |
| 1539 | Optional<unsigned> Flags = None) { |
| 1540 | return buildInstr(TargetOpcode::G_ASHR, {Dst}, {Src0, Src1}, Flags); |
| 1541 | } |
| 1542 | |
| 1543 | /// Build and insert \p Res = G_AND \p Op0, \p Op1 |
| 1544 | /// |
| 1545 | /// G_AND sets \p Res to the bitwise and of integer parameters \p Op0 and \p |
| 1546 | /// Op1. |
| 1547 | /// |
| 1548 | /// \pre setBasicBlock or setMI must have been called. |
| 1549 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 1550 | /// with the same (scalar or vector) type). |
| 1551 | /// |
| 1552 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1553 | |
| 1554 | MachineInstrBuilder buildAnd(const DstOp &Dst, const SrcOp &Src0, |
| 1555 | const SrcOp &Src1) { |
| 1556 | return buildInstr(TargetOpcode::G_AND, {Dst}, {Src0, Src1}); |
| 1557 | } |
| 1558 | |
| 1559 | /// Build and insert \p Res = G_OR \p Op0, \p Op1 |
| 1560 | /// |
| 1561 | /// G_OR sets \p Res to the bitwise or of integer parameters \p Op0 and \p |
| 1562 | /// Op1. |
| 1563 | /// |
| 1564 | /// \pre setBasicBlock or setMI must have been called. |
| 1565 | /// \pre \p Res, \p Op0 and \p Op1 must be generic virtual registers |
| 1566 | /// with the same (scalar or vector) type). |
| 1567 | /// |
| 1568 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1569 | MachineInstrBuilder buildOr(const DstOp &Dst, const SrcOp &Src0, |
| 1570 | const SrcOp &Src1, |
| 1571 | Optional<unsigned> Flags = None) { |
| 1572 | return buildInstr(TargetOpcode::G_OR, {Dst}, {Src0, Src1}, Flags); |
| 1573 | } |
| 1574 | |
| 1575 | /// Build and insert \p Res = G_XOR \p Op0, \p Op1 |
| 1576 | MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0, |
| 1577 | const SrcOp &Src1) { |
| 1578 | return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, Src1}); |
| 1579 | } |
| 1580 | |
| 1581 | /// Build and insert a bitwise not, |
| 1582 | /// \p NegOne = G_CONSTANT -1 |
| 1583 | /// \p Res = G_OR \p Op0, NegOne |
| 1584 | MachineInstrBuilder buildNot(const DstOp &Dst, const SrcOp &Src0) { |
| 1585 | auto NegOne = buildConstant(Dst.getLLTTy(*getMRI()), -1); |
| 1586 | return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, NegOne}); |
| 1587 | } |
| 1588 | |
| 1589 | /// Build and insert integer negation |
| 1590 | /// \p Zero = G_CONSTANT 0 |
| 1591 | /// \p Res = G_SUB Zero, \p Op0 |
| 1592 | MachineInstrBuilder buildNeg(const DstOp &Dst, const SrcOp &Src0) { |
| 1593 | auto Zero = buildConstant(Dst.getLLTTy(*getMRI()), 0); |
| 1594 | return buildInstr(TargetOpcode::G_SUB, {Dst}, {Zero, Src0}); |
| 1595 | } |
| 1596 | |
| 1597 | /// Build and insert \p Res = G_CTPOP \p Op0, \p Src0 |
| 1598 | MachineInstrBuilder buildCTPOP(const DstOp &Dst, const SrcOp &Src0) { |
| 1599 | return buildInstr(TargetOpcode::G_CTPOP, {Dst}, {Src0}); |
| 1600 | } |
| 1601 | |
| 1602 | /// Build and insert \p Res = G_CTLZ \p Op0, \p Src0 |
| 1603 | MachineInstrBuilder buildCTLZ(const DstOp &Dst, const SrcOp &Src0) { |
| 1604 | return buildInstr(TargetOpcode::G_CTLZ, {Dst}, {Src0}); |
| 1605 | } |
| 1606 | |
| 1607 | /// Build and insert \p Res = G_CTLZ_ZERO_UNDEF \p Op0, \p Src0 |
| 1608 | MachineInstrBuilder buildCTLZ_ZERO_UNDEF(const DstOp &Dst, const SrcOp &Src0) { |
| 1609 | return buildInstr(TargetOpcode::G_CTLZ_ZERO_UNDEF, {Dst}, {Src0}); |
| 1610 | } |
| 1611 | |
| 1612 | /// Build and insert \p Res = G_CTTZ \p Op0, \p Src0 |
| 1613 | MachineInstrBuilder buildCTTZ(const DstOp &Dst, const SrcOp &Src0) { |
| 1614 | return buildInstr(TargetOpcode::G_CTTZ, {Dst}, {Src0}); |
| 1615 | } |
| 1616 | |
| 1617 | /// Build and insert \p Res = G_CTTZ_ZERO_UNDEF \p Op0, \p Src0 |
| 1618 | MachineInstrBuilder buildCTTZ_ZERO_UNDEF(const DstOp &Dst, const SrcOp &Src0) { |
| 1619 | return buildInstr(TargetOpcode::G_CTTZ_ZERO_UNDEF, {Dst}, {Src0}); |
| 1620 | } |
| 1621 | |
| 1622 | /// Build and insert \p Dst = G_BSWAP \p Src0 |
| 1623 | MachineInstrBuilder buildBSwap(const DstOp &Dst, const SrcOp &Src0) { |
| 1624 | return buildInstr(TargetOpcode::G_BSWAP, {Dst}, {Src0}); |
| 1625 | } |
| 1626 | |
| 1627 | /// Build and insert \p Res = G_FADD \p Op0, \p Op1 |
| 1628 | MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0, |
| 1629 | const SrcOp &Src1, |
| 1630 | Optional<unsigned> Flags = None) { |
| 1631 | return buildInstr(TargetOpcode::G_FADD, {Dst}, {Src0, Src1}, Flags); |
| 1632 | } |
| 1633 | |
| 1634 | /// Build and insert \p Res = G_FSUB \p Op0, \p Op1 |
| 1635 | MachineInstrBuilder buildFSub(const DstOp &Dst, const SrcOp &Src0, |
| 1636 | const SrcOp &Src1, |
| 1637 | Optional<unsigned> Flags = None) { |
| 1638 | return buildInstr(TargetOpcode::G_FSUB, {Dst}, {Src0, Src1}, Flags); |
| 1639 | } |
| 1640 | |
| 1641 | /// Build and insert \p Res = G_FDIV \p Op0, \p Op1 |
| 1642 | MachineInstrBuilder buildFDiv(const DstOp &Dst, const SrcOp &Src0, |
| 1643 | const SrcOp &Src1, |
| 1644 | Optional<unsigned> Flags = None) { |
| 1645 | return buildInstr(TargetOpcode::G_FDIV, {Dst}, {Src0, Src1}, Flags); |
| 1646 | } |
| 1647 | |
| 1648 | /// Build and insert \p Res = G_FMA \p Op0, \p Op1, \p Op2 |
| 1649 | MachineInstrBuilder buildFMA(const DstOp &Dst, const SrcOp &Src0, |
| 1650 | const SrcOp &Src1, const SrcOp &Src2, |
| 1651 | Optional<unsigned> Flags = None) { |
| 1652 | return buildInstr(TargetOpcode::G_FMA, {Dst}, {Src0, Src1, Src2}, Flags); |
| 1653 | } |
| 1654 | |
| 1655 | /// Build and insert \p Res = G_FMAD \p Op0, \p Op1, \p Op2 |
| 1656 | MachineInstrBuilder buildFMAD(const DstOp &Dst, const SrcOp &Src0, |
| 1657 | const SrcOp &Src1, const SrcOp &Src2, |
| 1658 | Optional<unsigned> Flags = None) { |
| 1659 | return buildInstr(TargetOpcode::G_FMAD, {Dst}, {Src0, Src1, Src2}, Flags); |
| 1660 | } |
| 1661 | |
| 1662 | /// Build and insert \p Res = G_FNEG \p Op0 |
| 1663 | MachineInstrBuilder buildFNeg(const DstOp &Dst, const SrcOp &Src0, |
| 1664 | Optional<unsigned> Flags = None) { |
| 1665 | return buildInstr(TargetOpcode::G_FNEG, {Dst}, {Src0}, Flags); |
| 1666 | } |
| 1667 | |
| 1668 | /// Build and insert \p Res = G_FABS \p Op0 |
| 1669 | MachineInstrBuilder buildFAbs(const DstOp &Dst, const SrcOp &Src0, |
| 1670 | Optional<unsigned> Flags = None) { |
| 1671 | return buildInstr(TargetOpcode::G_FABS, {Dst}, {Src0}, Flags); |
| 1672 | } |
| 1673 | |
| 1674 | /// Build and insert \p Dst = G_FCANONICALIZE \p Src0 |
| 1675 | MachineInstrBuilder buildFCanonicalize(const DstOp &Dst, const SrcOp &Src0, |
| 1676 | Optional<unsigned> Flags = None) { |
| 1677 | return buildInstr(TargetOpcode::G_FCANONICALIZE, {Dst}, {Src0}, Flags); |
| 1678 | } |
| 1679 | |
| 1680 | /// Build and insert \p Dst = G_INTRINSIC_TRUNC \p Src0 |
| 1681 | MachineInstrBuilder buildIntrinsicTrunc(const DstOp &Dst, const SrcOp &Src0, |
| 1682 | Optional<unsigned> Flags = None) { |
| 1683 | return buildInstr(TargetOpcode::G_INTRINSIC_TRUNC, {Dst}, {Src0}, Flags); |
| 1684 | } |
| 1685 | |
| 1686 | /// Build and insert \p Res = GFFLOOR \p Op0, \p Op1 |
| 1687 | MachineInstrBuilder buildFFloor(const DstOp &Dst, const SrcOp &Src0, |
| 1688 | Optional<unsigned> Flags = None) { |
| 1689 | return buildInstr(TargetOpcode::G_FFLOOR, {Dst}, {Src0}, Flags); |
| 1690 | } |
| 1691 | |
| 1692 | /// Build and insert \p Dst = G_FLOG \p Src |
| 1693 | MachineInstrBuilder buildFLog(const DstOp &Dst, const SrcOp &Src, |
| 1694 | Optional<unsigned> Flags = None) { |
| 1695 | return buildInstr(TargetOpcode::G_FLOG, {Dst}, {Src}, Flags); |
| 1696 | } |
| 1697 | |
| 1698 | /// Build and insert \p Dst = G_FLOG2 \p Src |
| 1699 | MachineInstrBuilder buildFLog2(const DstOp &Dst, const SrcOp &Src, |
| 1700 | Optional<unsigned> Flags = None) { |
| 1701 | return buildInstr(TargetOpcode::G_FLOG2, {Dst}, {Src}, Flags); |
| 1702 | } |
| 1703 | |
| 1704 | /// Build and insert \p Dst = G_FEXP2 \p Src |
| 1705 | MachineInstrBuilder buildFExp2(const DstOp &Dst, const SrcOp &Src, |
| 1706 | Optional<unsigned> Flags = None) { |
| 1707 | return buildInstr(TargetOpcode::G_FEXP2, {Dst}, {Src}, Flags); |
| 1708 | } |
| 1709 | |
| 1710 | /// Build and insert \p Dst = G_FPOW \p Src0, \p Src1 |
| 1711 | MachineInstrBuilder buildFPow(const DstOp &Dst, const SrcOp &Src0, |
| 1712 | const SrcOp &Src1, |
| 1713 | Optional<unsigned> Flags = None) { |
| 1714 | return buildInstr(TargetOpcode::G_FPOW, {Dst}, {Src0, Src1}, Flags); |
| 1715 | } |
| 1716 | |
| 1717 | /// Build and insert \p Res = G_FCOPYSIGN \p Op0, \p Op1 |
| 1718 | MachineInstrBuilder buildFCopysign(const DstOp &Dst, const SrcOp &Src0, |
| 1719 | const SrcOp &Src1) { |
| 1720 | return buildInstr(TargetOpcode::G_FCOPYSIGN, {Dst}, {Src0, Src1}); |
| 1721 | } |
| 1722 | |
| 1723 | /// Build and insert \p Res = G_UITOFP \p Src0 |
| 1724 | MachineInstrBuilder buildUITOFP(const DstOp &Dst, const SrcOp &Src0) { |
| 1725 | return buildInstr(TargetOpcode::G_UITOFP, {Dst}, {Src0}); |
| 1726 | } |
| 1727 | |
| 1728 | /// Build and insert \p Res = G_SITOFP \p Src0 |
| 1729 | MachineInstrBuilder buildSITOFP(const DstOp &Dst, const SrcOp &Src0) { |
| 1730 | return buildInstr(TargetOpcode::G_SITOFP, {Dst}, {Src0}); |
| 1731 | } |
| 1732 | |
| 1733 | /// Build and insert \p Res = G_FPTOUI \p Src0 |
| 1734 | MachineInstrBuilder buildFPTOUI(const DstOp &Dst, const SrcOp &Src0) { |
| 1735 | return buildInstr(TargetOpcode::G_FPTOUI, {Dst}, {Src0}); |
| 1736 | } |
| 1737 | |
| 1738 | /// Build and insert \p Res = G_FPTOSI \p Src0 |
| 1739 | MachineInstrBuilder buildFPTOSI(const DstOp &Dst, const SrcOp &Src0) { |
| 1740 | return buildInstr(TargetOpcode::G_FPTOSI, {Dst}, {Src0}); |
| 1741 | } |
| 1742 | |
| 1743 | /// Build and insert \p Res = G_SMIN \p Op0, \p Op1 |
| 1744 | MachineInstrBuilder buildSMin(const DstOp &Dst, const SrcOp &Src0, |
| 1745 | const SrcOp &Src1) { |
| 1746 | return buildInstr(TargetOpcode::G_SMIN, {Dst}, {Src0, Src1}); |
| 1747 | } |
| 1748 | |
| 1749 | /// Build and insert \p Res = G_SMAX \p Op0, \p Op1 |
| 1750 | MachineInstrBuilder buildSMax(const DstOp &Dst, const SrcOp &Src0, |
| 1751 | const SrcOp &Src1) { |
| 1752 | return buildInstr(TargetOpcode::G_SMAX, {Dst}, {Src0, Src1}); |
| 1753 | } |
| 1754 | |
| 1755 | /// Build and insert \p Res = G_UMIN \p Op0, \p Op1 |
| 1756 | MachineInstrBuilder buildUMin(const DstOp &Dst, const SrcOp &Src0, |
| 1757 | const SrcOp &Src1) { |
| 1758 | return buildInstr(TargetOpcode::G_UMIN, {Dst}, {Src0, Src1}); |
| 1759 | } |
| 1760 | |
| 1761 | /// Build and insert \p Res = G_UMAX \p Op0, \p Op1 |
| 1762 | MachineInstrBuilder buildUMax(const DstOp &Dst, const SrcOp &Src0, |
| 1763 | const SrcOp &Src1) { |
| 1764 | return buildInstr(TargetOpcode::G_UMAX, {Dst}, {Src0, Src1}); |
| 1765 | } |
| 1766 | |
| 1767 | /// Build and insert \p Dst = G_ABS \p Src |
| 1768 | MachineInstrBuilder buildAbs(const DstOp &Dst, const SrcOp &Src) { |
| 1769 | return buildInstr(TargetOpcode::G_ABS, {Dst}, {Src}); |
| 1770 | } |
| 1771 | |
| 1772 | /// Build and insert \p Res = G_JUMP_TABLE \p JTI |
| 1773 | /// |
| 1774 | /// G_JUMP_TABLE sets \p Res to the address of the jump table specified by |
| 1775 | /// the jump table index \p JTI. |
| 1776 | /// |
| 1777 | /// \return a MachineInstrBuilder for the newly created instruction. |
| 1778 | MachineInstrBuilder buildJumpTable(const LLT PtrTy, unsigned JTI); |
| 1779 | |
| 1780 | /// Build and insert \p Res = G_VECREDUCE_SEQ_FADD \p ScalarIn, \p VecIn |
| 1781 | /// |
| 1782 | /// \p ScalarIn is the scalar accumulator input to start the sequential |
| 1783 | /// reduction operation of \p VecIn. |
| 1784 | MachineInstrBuilder buildVecReduceSeqFAdd(const DstOp &Dst, |
| 1785 | const SrcOp &ScalarIn, |
| 1786 | const SrcOp &VecIn) { |
| 1787 | return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FADD, {Dst}, |
| 1788 | {ScalarIn, {VecIn}}); |
| 1789 | } |
| 1790 | |
| 1791 | /// Build and insert \p Res = G_VECREDUCE_SEQ_FMUL \p ScalarIn, \p VecIn |
| 1792 | /// |
| 1793 | /// \p ScalarIn is the scalar accumulator input to start the sequential |
| 1794 | /// reduction operation of \p VecIn. |
| 1795 | MachineInstrBuilder buildVecReduceSeqFMul(const DstOp &Dst, |
| 1796 | const SrcOp &ScalarIn, |
| 1797 | const SrcOp &VecIn) { |
| 1798 | return buildInstr(TargetOpcode::G_VECREDUCE_SEQ_FMUL, {Dst}, |
| 1799 | {ScalarIn, {VecIn}}); |
| 1800 | } |
| 1801 | |
| 1802 | /// Build and insert \p Res = G_VECREDUCE_FADD \p Src |
| 1803 | /// |
| 1804 | /// \p ScalarIn is the scalar accumulator input to the reduction operation of |
| 1805 | /// \p VecIn. |
| 1806 | MachineInstrBuilder buildVecReduceFAdd(const DstOp &Dst, |
| 1807 | const SrcOp &ScalarIn, |
| 1808 | const SrcOp &VecIn) { |
| 1809 | return buildInstr(TargetOpcode::G_VECREDUCE_FADD, {Dst}, {ScalarIn, VecIn}); |
| 1810 | } |
| 1811 | |
| 1812 | /// Build and insert \p Res = G_VECREDUCE_FMUL \p Src |
| 1813 | /// |
| 1814 | /// \p ScalarIn is the scalar accumulator input to the reduction operation of |
| 1815 | /// \p VecIn. |
| 1816 | MachineInstrBuilder buildVecReduceFMul(const DstOp &Dst, |
| 1817 | const SrcOp &ScalarIn, |
| 1818 | const SrcOp &VecIn) { |
| 1819 | return buildInstr(TargetOpcode::G_VECREDUCE_FMUL, {Dst}, {ScalarIn, VecIn}); |
| 1820 | } |
| 1821 | |
| 1822 | /// Build and insert \p Res = G_VECREDUCE_FMAX \p Src |
| 1823 | MachineInstrBuilder buildVecReduceFMax(const DstOp &Dst, const SrcOp &Src) { |
| 1824 | return buildInstr(TargetOpcode::G_VECREDUCE_FMAX, {Dst}, {Src}); |
| 1825 | } |
| 1826 | |
| 1827 | /// Build and insert \p Res = G_VECREDUCE_FMIN \p Src |
| 1828 | MachineInstrBuilder buildVecReduceFMin(const DstOp &Dst, const SrcOp &Src) { |
| 1829 | return buildInstr(TargetOpcode::G_VECREDUCE_FMIN, {Dst}, {Src}); |
| 1830 | } |
| 1831 | /// Build and insert \p Res = G_VECREDUCE_ADD \p Src |
| 1832 | MachineInstrBuilder buildVecReduceAdd(const DstOp &Dst, const SrcOp &Src) { |
| 1833 | return buildInstr(TargetOpcode::G_VECREDUCE_ADD, {Dst}, {Src}); |
| 1834 | } |
| 1835 | |
| 1836 | /// Build and insert \p Res = G_VECREDUCE_MUL \p Src |
| 1837 | MachineInstrBuilder buildVecReduceMul(const DstOp &Dst, const SrcOp &Src) { |
| 1838 | return buildInstr(TargetOpcode::G_VECREDUCE_MUL, {Dst}, {Src}); |
| 1839 | } |
| 1840 | |
| 1841 | /// Build and insert \p Res = G_VECREDUCE_AND \p Src |
| 1842 | MachineInstrBuilder buildVecReduceAnd(const DstOp &Dst, const SrcOp &Src) { |
| 1843 | return buildInstr(TargetOpcode::G_VECREDUCE_AND, {Dst}, {Src}); |
| 1844 | } |
| 1845 | |
| 1846 | /// Build and insert \p Res = G_VECREDUCE_OR \p Src |
| 1847 | MachineInstrBuilder buildVecReduceOr(const DstOp &Dst, const SrcOp &Src) { |
| 1848 | return buildInstr(TargetOpcode::G_VECREDUCE_OR, {Dst}, {Src}); |
| 1849 | } |
| 1850 | |
| 1851 | /// Build and insert \p Res = G_VECREDUCE_XOR \p Src |
| 1852 | MachineInstrBuilder buildVecReduceXor(const DstOp &Dst, const SrcOp &Src) { |
| 1853 | return buildInstr(TargetOpcode::G_VECREDUCE_XOR, {Dst}, {Src}); |
| 1854 | } |
| 1855 | |
| 1856 | /// Build and insert \p Res = G_VECREDUCE_SMAX \p Src |
| 1857 | MachineInstrBuilder buildVecReduceSMax(const DstOp &Dst, const SrcOp &Src) { |
| 1858 | return buildInstr(TargetOpcode::G_VECREDUCE_SMAX, {Dst}, {Src}); |
| 1859 | } |
| 1860 | |
| 1861 | /// Build and insert \p Res = G_VECREDUCE_SMIN \p Src |
| 1862 | MachineInstrBuilder buildVecReduceSMin(const DstOp &Dst, const SrcOp &Src) { |
| 1863 | return buildInstr(TargetOpcode::G_VECREDUCE_SMIN, {Dst}, {Src}); |
| 1864 | } |
| 1865 | |
| 1866 | /// Build and insert \p Res = G_VECREDUCE_UMAX \p Src |
| 1867 | MachineInstrBuilder buildVecReduceUMax(const DstOp &Dst, const SrcOp &Src) { |
| 1868 | return buildInstr(TargetOpcode::G_VECREDUCE_UMAX, {Dst}, {Src}); |
| 1869 | } |
| 1870 | |
| 1871 | /// Build and insert \p Res = G_VECREDUCE_UMIN \p Src |
| 1872 | MachineInstrBuilder buildVecReduceUMin(const DstOp &Dst, const SrcOp &Src) { |
| 1873 | return buildInstr(TargetOpcode::G_VECREDUCE_UMIN, {Dst}, {Src}); |
| 1874 | } |
| 1875 | |
| 1876 | /// Build and insert G_MEMCPY or G_MEMMOVE |
| 1877 | MachineInstrBuilder buildMemTransferInst(unsigned Opcode, const SrcOp &DstPtr, |
| 1878 | const SrcOp &SrcPtr, |
| 1879 | const SrcOp &Size, |
| 1880 | MachineMemOperand &DstMMO, |
| 1881 | MachineMemOperand &SrcMMO) { |
| 1882 | auto MIB = buildInstr( |
| 1883 | Opcode, {}, {DstPtr, SrcPtr, Size, SrcOp(INT64_C(0) /*isTailCall*/)}); |
| 1884 | MIB.addMemOperand(&DstMMO); |
| 1885 | MIB.addMemOperand(&SrcMMO); |
| 1886 | return MIB; |
| 1887 | } |
| 1888 | |
| 1889 | MachineInstrBuilder buildMemCpy(const SrcOp &DstPtr, const SrcOp &SrcPtr, |
| 1890 | const SrcOp &Size, MachineMemOperand &DstMMO, |
| 1891 | MachineMemOperand &SrcMMO) { |
| 1892 | return buildMemTransferInst(TargetOpcode::G_MEMCPY, DstPtr, SrcPtr, Size, |
| 1893 | DstMMO, SrcMMO); |
| 1894 | } |
| 1895 | |
| 1896 | /// Build and insert \p Dst = G_SBFX \p Src, \p LSB, \p Width. |
| 1897 | MachineInstrBuilder buildSbfx(const DstOp &Dst, const SrcOp &Src, |
| 1898 | const SrcOp &LSB, const SrcOp &Width) { |
| 1899 | return buildInstr(TargetOpcode::G_SBFX, {Dst}, {Src, LSB, Width}); |
| 1900 | } |
| 1901 | |
| 1902 | /// Build and insert \p Dst = G_UBFX \p Src, \p LSB, \p Width. |
| 1903 | MachineInstrBuilder buildUbfx(const DstOp &Dst, const SrcOp &Src, |
| 1904 | const SrcOp &LSB, const SrcOp &Width) { |
| 1905 | return buildInstr(TargetOpcode::G_UBFX, {Dst}, {Src, LSB, Width}); |
| 1906 | } |
| 1907 | |
| 1908 | /// Build and insert \p Dst = G_ROTR \p Src, \p Amt |
| 1909 | MachineInstrBuilder buildRotateRight(const DstOp &Dst, const SrcOp &Src, |
| 1910 | const SrcOp &Amt) { |
| 1911 | return buildInstr(TargetOpcode::G_ROTR, {Dst}, {Src, Amt}); |
| 1912 | } |
| 1913 | |
| 1914 | /// Build and insert \p Dst = G_ROTL \p Src, \p Amt |
| 1915 | MachineInstrBuilder buildRotateLeft(const DstOp &Dst, const SrcOp &Src, |
| 1916 | const SrcOp &Amt) { |
| 1917 | return buildInstr(TargetOpcode::G_ROTL, {Dst}, {Src, Amt}); |
| 1918 | } |
| 1919 | |
| 1920 | /// Build and insert \p Dst = G_BITREVERSE \p Src |
| 1921 | MachineInstrBuilder buildBitReverse(const DstOp &Dst, const SrcOp &Src) { |
| 1922 | return buildInstr(TargetOpcode::G_BITREVERSE, {Dst}, {Src}); |
| 1923 | } |
| 1924 | |
| 1925 | virtual MachineInstrBuilder buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps, |
| 1926 | ArrayRef<SrcOp> SrcOps, |
| 1927 | Optional<unsigned> Flags = None); |
| 1928 | }; |
| 1929 | |
| 1930 | } // End namespace llvm. |
| 1931 | #endif // LLVM_CODEGEN_GLOBALISEL_MACHINEIRBUILDER_H |