LLVM 22.0.0git
X86ExpandPseudo.cpp
Go to the documentation of this file.
1//===------- X86ExpandPseudo.cpp - Expand pseudo instructions -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a pass that expands pseudo instructions into target
10// instructions to allow proper scheduling, if-conversion, other late
11// optimizations, or simply the encoding of the instructions.
12//
13//===----------------------------------------------------------------------===//
14
15#include "X86.h"
16#include "X86FrameLowering.h"
17#include "X86InstrInfo.h"
19#include "X86Subtarget.h"
23#include "llvm/CodeGen/Passes.h" // For IDs of passes that are preserved.
25#include "llvm/IR/GlobalValue.h"
27using namespace llvm;
28
29#define DEBUG_TYPE "x86-pseudo"
30#define X86_EXPAND_PSEUDO_NAME "X86 pseudo instruction expansion pass"
31
32namespace {
33class X86ExpandPseudo : public MachineFunctionPass {
34public:
35 static char ID;
36 X86ExpandPseudo() : MachineFunctionPass(ID) {}
37
38 void getAnalysisUsage(AnalysisUsage &AU) const override {
39 AU.setPreservesCFG();
43 }
44
45 const X86Subtarget *STI = nullptr;
46 const X86InstrInfo *TII = nullptr;
47 const X86RegisterInfo *TRI = nullptr;
48 const X86MachineFunctionInfo *X86FI = nullptr;
49 const X86FrameLowering *X86FL = nullptr;
50
51 bool runOnMachineFunction(MachineFunction &MF) override;
52
53 MachineFunctionProperties getRequiredProperties() const override {
54 return MachineFunctionProperties().setNoVRegs();
55 }
56
57 StringRef getPassName() const override {
58 return "X86 pseudo instruction expansion pass";
59 }
60
61private:
62 void expandICallBranchFunnel(MachineBasicBlock *MBB,
64 void expandCALL_RVMARKER(MachineBasicBlock &MBB,
67 bool expandMBB(MachineBasicBlock &MBB);
68
69 /// This function expands pseudos which affects control flow.
70 /// It is done in separate pass to simplify blocks navigation in main
71 /// pass(calling expandMBB).
72 bool expandPseudosWhichAffectControlFlow(MachineFunction &MF);
73
74 /// Expand X86::VASTART_SAVE_XMM_REGS into set of xmm copying instructions,
75 /// placed into separate block guarded by check for al register(for SystemV
76 /// abi).
77 void expandVastartSaveXmmRegs(
78 MachineBasicBlock *EntryBlk,
79 MachineBasicBlock::iterator VAStartPseudoInstr) const;
80};
81char X86ExpandPseudo::ID = 0;
82
83} // End anonymous namespace.
84
86 false)
87
88void X86ExpandPseudo::expandICallBranchFunnel(
90 MachineBasicBlock *JTMBB = MBB;
91 MachineInstr *JTInst = &*MBBI;
92 MachineFunction *MF = MBB->getParent();
93 const BasicBlock *BB = MBB->getBasicBlock();
94 auto InsPt = MachineFunction::iterator(MBB);
95 ++InsPt;
96
97 std::vector<std::pair<MachineBasicBlock *, unsigned>> TargetMBBs;
98 const DebugLoc &DL = JTInst->getDebugLoc();
99 MachineOperand Selector = JTInst->getOperand(0);
100 const GlobalValue *CombinedGlobal = JTInst->getOperand(1).getGlobal();
101
102 auto CmpTarget = [&](unsigned Target) {
103 if (Selector.isReg())
104 MBB->addLiveIn(Selector.getReg());
105 BuildMI(*MBB, MBBI, DL, TII->get(X86::LEA64r), X86::R11)
106 .addReg(X86::RIP)
107 .addImm(1)
108 .addReg(0)
109 .addGlobalAddress(CombinedGlobal,
110 JTInst->getOperand(2 + 2 * Target).getImm())
111 .addReg(0);
112 BuildMI(*MBB, MBBI, DL, TII->get(X86::CMP64rr))
113 .add(Selector)
114 .addReg(X86::R11);
115 };
116
117 auto CreateMBB = [&]() {
118 auto *NewMBB = MF->CreateMachineBasicBlock(BB);
119 MBB->addSuccessor(NewMBB);
120 if (!MBB->isLiveIn(X86::EFLAGS))
121 MBB->addLiveIn(X86::EFLAGS);
122 return NewMBB;
123 };
124
125 auto EmitCondJump = [&](unsigned CC, MachineBasicBlock *ThenMBB) {
126 BuildMI(*MBB, MBBI, DL, TII->get(X86::JCC_1)).addMBB(ThenMBB).addImm(CC);
127
128 auto *ElseMBB = CreateMBB();
129 MF->insert(InsPt, ElseMBB);
130 MBB = ElseMBB;
131 MBBI = MBB->end();
132 };
133
134 auto EmitCondJumpTarget = [&](unsigned CC, unsigned Target) {
135 auto *ThenMBB = CreateMBB();
136 TargetMBBs.push_back({ThenMBB, Target});
137 EmitCondJump(CC, ThenMBB);
138 };
139
140 auto EmitTailCall = [&](unsigned Target) {
141 BuildMI(*MBB, MBBI, DL, TII->get(X86::TAILJMPd64))
142 .add(JTInst->getOperand(3 + 2 * Target));
143 };
144
145 std::function<void(unsigned, unsigned)> EmitBranchFunnel =
146 [&](unsigned FirstTarget, unsigned NumTargets) {
147 if (NumTargets == 1) {
148 EmitTailCall(FirstTarget);
149 return;
150 }
151
152 if (NumTargets == 2) {
153 CmpTarget(FirstTarget + 1);
154 EmitCondJumpTarget(X86::COND_B, FirstTarget);
155 EmitTailCall(FirstTarget + 1);
156 return;
157 }
158
159 if (NumTargets < 6) {
160 CmpTarget(FirstTarget + 1);
161 EmitCondJumpTarget(X86::COND_B, FirstTarget);
162 EmitCondJumpTarget(X86::COND_E, FirstTarget + 1);
163 EmitBranchFunnel(FirstTarget + 2, NumTargets - 2);
164 return;
165 }
166
167 auto *ThenMBB = CreateMBB();
168 CmpTarget(FirstTarget + (NumTargets / 2));
169 EmitCondJump(X86::COND_B, ThenMBB);
170 EmitCondJumpTarget(X86::COND_E, FirstTarget + (NumTargets / 2));
171 EmitBranchFunnel(FirstTarget + (NumTargets / 2) + 1,
172 NumTargets - (NumTargets / 2) - 1);
173
174 MF->insert(InsPt, ThenMBB);
175 MBB = ThenMBB;
176 MBBI = MBB->end();
177 EmitBranchFunnel(FirstTarget, NumTargets / 2);
178 };
179
180 EmitBranchFunnel(0, (JTInst->getNumOperands() - 2) / 2);
181 for (auto P : TargetMBBs) {
182 MF->insert(InsPt, P.first);
183 BuildMI(P.first, DL, TII->get(X86::TAILJMPd64))
184 .add(JTInst->getOperand(3 + 2 * P.second));
185 }
186 JTMBB->erase(JTInst);
187}
188
189void X86ExpandPseudo::expandCALL_RVMARKER(MachineBasicBlock &MBB,
191 // Expand CALL_RVMARKER pseudo to call instruction, followed by the special
192 //"movq %rax, %rdi" marker.
193 MachineInstr &MI = *MBBI;
194
195 MachineInstr *OriginalCall;
196 assert((MI.getOperand(1).isGlobal() || MI.getOperand(1).isReg()) &&
197 "invalid operand for regular call");
198 unsigned Opc = -1;
199 if (MI.getOpcode() == X86::CALL64m_RVMARKER)
200 Opc = X86::CALL64m;
201 else if (MI.getOpcode() == X86::CALL64r_RVMARKER)
202 Opc = X86::CALL64r;
203 else if (MI.getOpcode() == X86::CALL64pcrel32_RVMARKER)
204 Opc = X86::CALL64pcrel32;
205 else
206 llvm_unreachable("unexpected opcode");
207
208 OriginalCall = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc)).getInstr();
209 bool RAXImplicitDead = false;
210 for (MachineOperand &Op : llvm::drop_begin(MI.operands())) {
211 // RAX may be 'implicit dead', if there are no other users of the return
212 // value. We introduce a new use, so change it to 'implicit def'.
213 if (Op.isReg() && Op.isImplicit() && Op.isDead() &&
214 TRI->regsOverlap(Op.getReg(), X86::RAX)) {
215 Op.setIsDead(false);
216 Op.setIsDef(true);
217 RAXImplicitDead = true;
218 }
219 OriginalCall->addOperand(Op);
220 }
221
222 // Emit marker "movq %rax, %rdi". %rdi is not callee-saved, so it cannot be
223 // live across the earlier call. The call to the ObjC runtime function returns
224 // the first argument, so the value of %rax is unchanged after the ObjC
225 // runtime call. On Windows targets, the runtime call follows the regular
226 // x64 calling convention and expects the first argument in %rcx.
227 auto TargetReg = STI->getTargetTriple().isOSWindows() ? X86::RCX : X86::RDI;
228 auto *Marker = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(X86::MOV64rr))
229 .addReg(TargetReg, RegState::Define)
230 .addReg(X86::RAX)
231 .getInstr();
232 if (MI.shouldUpdateAdditionalCallInfo())
234
235 // Emit call to ObjC runtime.
236 const uint32_t *RegMask =
237 TRI->getCallPreservedMask(*MBB.getParent(), CallingConv::C);
238 MachineInstr *RtCall =
239 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(X86::CALL64pcrel32))
240 .addGlobalAddress(MI.getOperand(0).getGlobal(), 0, 0)
241 .addRegMask(RegMask)
242 .addReg(X86::RAX,
244 (RAXImplicitDead ? (RegState::Dead | RegState::Define)
246 .getInstr();
247 MI.eraseFromParent();
248
249 auto &TM = MBB.getParent()->getTarget();
250 // On Darwin platforms, wrap the expanded sequence in a bundle to prevent
251 // later optimizations from breaking up the sequence.
252 if (TM.getTargetTriple().isOSDarwin())
253 finalizeBundle(MBB, OriginalCall->getIterator(),
254 std::next(RtCall->getIterator()));
255}
256
257/// If \p MBBI is a pseudo instruction, this method expands
258/// it to the corresponding (sequence of) actual instruction(s).
259/// \returns true if \p MBBI has been expanded.
260bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
262 MachineInstr &MI = *MBBI;
263 unsigned Opcode = MI.getOpcode();
264 const DebugLoc &DL = MBBI->getDebugLoc();
265#define GET_EGPR_IF_ENABLED(OPC) (STI->hasEGPR() ? OPC##_EVEX : OPC)
266 switch (Opcode) {
267 default:
268 return false;
269 case X86::TCRETURNdi:
270 case X86::TCRETURNdicc:
271 case X86::TCRETURNri:
272 case X86::TCRETURN_WIN64ri:
273 case X86::TCRETURN_HIPE32ri:
274 case X86::TCRETURNmi:
275 case X86::TCRETURNdi64:
276 case X86::TCRETURNdi64cc:
277 case X86::TCRETURNri64:
278 case X86::TCRETURNri64_ImpCall:
279 case X86::TCRETURNmi64:
280 case X86::TCRETURN_WINmi64: {
281 bool isMem = Opcode == X86::TCRETURNmi || Opcode == X86::TCRETURNmi64 ||
282 Opcode == X86::TCRETURN_WINmi64;
283 MachineOperand &JumpTarget = MBBI->getOperand(0);
284 MachineOperand &StackAdjust = MBBI->getOperand(isMem ? X86::AddrNumOperands
285 : 1);
286 assert(StackAdjust.isImm() && "Expecting immediate value.");
287
288 // Adjust stack pointer.
289 int StackAdj = StackAdjust.getImm();
290 int MaxTCDelta = X86FI->getTCReturnAddrDelta();
291 int64_t Offset = 0;
292 assert(MaxTCDelta <= 0 && "MaxTCDelta should never be positive");
293
294 // Incoporate the retaddr area.
295 Offset = StackAdj - MaxTCDelta;
296 assert(Offset >= 0 && "Offset should never be negative");
297
298 if (Opcode == X86::TCRETURNdicc || Opcode == X86::TCRETURNdi64cc) {
299 assert(Offset == 0 && "Conditional tail call cannot adjust the stack.");
300 }
301
302 if (Offset) {
303 // Check for possible merge with preceding ADD instruction.
304 Offset = X86FL->mergeSPAdd(MBB, MBBI, Offset, true);
305 X86FL->emitSPUpdate(MBB, MBBI, DL, Offset, /*InEpilogue=*/true);
306 }
307
308 // Use this predicate to set REX prefix for X86_64 targets.
309 bool IsX64 = STI->isTargetWin64() || STI->isTargetUEFI64();
310 // Jump to label or value in register.
311 if (Opcode == X86::TCRETURNdi || Opcode == X86::TCRETURNdicc ||
312 Opcode == X86::TCRETURNdi64 || Opcode == X86::TCRETURNdi64cc) {
313 unsigned Op;
314 switch (Opcode) {
315 case X86::TCRETURNdi:
316 Op = X86::TAILJMPd;
317 break;
318 case X86::TCRETURNdicc:
319 Op = X86::TAILJMPd_CC;
320 break;
321 case X86::TCRETURNdi64cc:
323 "Conditional tail calls confuse "
324 "the Win64 unwinder.");
325 Op = X86::TAILJMPd64_CC;
326 break;
327 default:
328 // Note: Win64 uses REX prefixes indirect jumps out of functions, but
329 // not direct ones.
330 Op = X86::TAILJMPd64;
331 break;
332 }
333 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(Op));
334 if (JumpTarget.isGlobal()) {
335 MIB.addGlobalAddress(JumpTarget.getGlobal(), JumpTarget.getOffset(),
336 JumpTarget.getTargetFlags());
337 } else {
338 assert(JumpTarget.isSymbol());
339 MIB.addExternalSymbol(JumpTarget.getSymbolName(),
340 JumpTarget.getTargetFlags());
341 }
342 if (Op == X86::TAILJMPd_CC || Op == X86::TAILJMPd64_CC) {
343 MIB.addImm(MBBI->getOperand(2).getImm());
344 }
345
346 } else if (Opcode == X86::TCRETURNmi || Opcode == X86::TCRETURNmi64 ||
347 Opcode == X86::TCRETURN_WINmi64) {
348 unsigned Op = (Opcode == X86::TCRETURNmi)
349 ? X86::TAILJMPm
350 : (IsX64 ? X86::TAILJMPm64_REX : X86::TAILJMPm64);
351 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, DL, TII->get(Op));
352 for (unsigned i = 0; i != X86::AddrNumOperands; ++i)
353 MIB.add(MBBI->getOperand(i));
354 } else if (Opcode == X86::TCRETURNri64 ||
355 Opcode == X86::TCRETURNri64_ImpCall ||
356 Opcode == X86::TCRETURN_WIN64ri) {
357 JumpTarget.setIsKill();
358 BuildMI(MBB, MBBI, DL,
359 TII->get(IsX64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
360 .add(JumpTarget);
361 } else {
362 assert(!IsX64 && "Win64 and UEFI64 require REX for indirect jumps.");
363 JumpTarget.setIsKill();
364 BuildMI(MBB, MBBI, DL, TII->get(X86::TAILJMPr))
365 .add(JumpTarget);
366 }
367
368 MachineInstr &NewMI = *std::prev(MBBI);
369 NewMI.copyImplicitOps(*MBBI->getParent()->getParent(), *MBBI);
370 NewMI.setCFIType(*MBB.getParent(), MI.getCFIType());
371
372 // Update the call info.
373 if (MBBI->isCandidateForAdditionalCallInfo())
375
376 // Delete the pseudo instruction TCRETURN.
377 MBB.erase(MBBI);
378
379 return true;
380 }
381 case X86::EH_RETURN:
382 case X86::EH_RETURN64: {
383 MachineOperand &DestAddr = MBBI->getOperand(0);
384 assert(DestAddr.isReg() && "Offset should be in register!");
385 const bool Uses64BitFramePtr = STI->isTarget64BitLP64();
386 Register StackPtr = TRI->getStackRegister();
387 BuildMI(MBB, MBBI, DL,
388 TII->get(Uses64BitFramePtr ? X86::MOV64rr : X86::MOV32rr), StackPtr)
389 .addReg(DestAddr.getReg());
390 // The EH_RETURN pseudo is really removed during the MC Lowering.
391 return true;
392 }
393 case X86::IRET: {
394 // Adjust stack to erase error code
395 int64_t StackAdj = MBBI->getOperand(0).getImm();
396 X86FL->emitSPUpdate(MBB, MBBI, DL, StackAdj, true);
397 // Replace pseudo with machine iret
398 unsigned RetOp = STI->is64Bit() ? X86::IRET64 : X86::IRET32;
399 // Use UIRET if UINTR is present (except for building kernel)
400 if (STI->is64Bit() && STI->hasUINTR() &&
402 RetOp = X86::UIRET;
403 BuildMI(MBB, MBBI, DL, TII->get(RetOp));
404 MBB.erase(MBBI);
405 return true;
406 }
407 case X86::RET: {
408 // Adjust stack to erase error code
409 int64_t StackAdj = MBBI->getOperand(0).getImm();
410 MachineInstrBuilder MIB;
411 if (StackAdj == 0) {
412 MIB = BuildMI(MBB, MBBI, DL,
413 TII->get(STI->is64Bit() ? X86::RET64 : X86::RET32));
414 } else if (isUInt<16>(StackAdj)) {
415 MIB = BuildMI(MBB, MBBI, DL,
416 TII->get(STI->is64Bit() ? X86::RETI64 : X86::RETI32))
417 .addImm(StackAdj);
418 } else {
419 assert(!STI->is64Bit() &&
420 "shouldn't need to do this for x86_64 targets!");
421 // A ret can only handle immediates as big as 2**16-1. If we need to pop
422 // off bytes before the return address, we must do it manually.
423 BuildMI(MBB, MBBI, DL, TII->get(X86::POP32r)).addReg(X86::ECX, RegState::Define);
424 X86FL->emitSPUpdate(MBB, MBBI, DL, StackAdj, /*InEpilogue=*/true);
425 BuildMI(MBB, MBBI, DL, TII->get(X86::PUSH32r)).addReg(X86::ECX);
426 MIB = BuildMI(MBB, MBBI, DL, TII->get(X86::RET32));
427 }
428 for (unsigned I = 1, E = MBBI->getNumOperands(); I != E; ++I)
429 MIB.add(MBBI->getOperand(I));
430 MBB.erase(MBBI);
431 return true;
432 }
433 case X86::LCMPXCHG16B_SAVE_RBX: {
434 // Perform the following transformation.
435 // SaveRbx = pseudocmpxchg Addr, <4 opds for the address>, InArg, SaveRbx
436 // =>
437 // RBX = InArg
438 // actualcmpxchg Addr
439 // RBX = SaveRbx
440 const MachineOperand &InArg = MBBI->getOperand(6);
441 Register SaveRbx = MBBI->getOperand(7).getReg();
442
443 // Copy the input argument of the pseudo into the argument of the
444 // actual instruction.
445 // NOTE: We don't copy the kill flag since the input might be the same reg
446 // as one of the other operands of LCMPXCHG16B.
447 TII->copyPhysReg(MBB, MBBI, DL, X86::RBX, InArg.getReg(), false);
448 // Create the actual instruction.
449 MachineInstr *NewInstr = BuildMI(MBB, MBBI, DL, TII->get(X86::LCMPXCHG16B));
450 // Copy the operands related to the address. If we access a frame variable,
451 // we need to replace the RBX base with SaveRbx, as RBX has another value.
452 const MachineOperand &Base = MBBI->getOperand(1);
453 if (Base.getReg() == X86::RBX || Base.getReg() == X86::EBX)
455 Base.getReg() == X86::RBX
456 ? SaveRbx
457 : Register(TRI->getSubReg(SaveRbx, X86::sub_32bit)),
458 /*IsDef=*/false));
459 else
460 NewInstr->addOperand(Base);
461 for (unsigned Idx = 1 + 1; Idx < 1 + X86::AddrNumOperands; ++Idx)
462 NewInstr->addOperand(MBBI->getOperand(Idx));
463 // Finally, restore the value of RBX.
464 TII->copyPhysReg(MBB, MBBI, DL, X86::RBX, SaveRbx,
465 /*SrcIsKill*/ true);
466
467 // Delete the pseudo.
469 return true;
470 }
471 // Loading/storing mask pairs requires two kmov operations. The second one of
472 // these needs a 2 byte displacement relative to the specified address (with
473 // 32 bit spill size). The pairs of 1bit masks up to 16 bit masks all use the
474 // same spill size, they all are stored using MASKPAIR16STORE, loaded using
475 // MASKPAIR16LOAD.
476 //
477 // The displacement value might wrap around in theory, thus the asserts in
478 // both cases.
479 case X86::MASKPAIR16LOAD: {
480 int64_t Disp = MBBI->getOperand(1 + X86::AddrDisp).getImm();
481 assert(Disp >= 0 && Disp <= INT32_MAX - 2 && "Unexpected displacement");
482 Register Reg = MBBI->getOperand(0).getReg();
483 bool DstIsDead = MBBI->getOperand(0).isDead();
484 Register Reg0 = TRI->getSubReg(Reg, X86::sub_mask_0);
485 Register Reg1 = TRI->getSubReg(Reg, X86::sub_mask_1);
486
487 auto MIBLo =
488 BuildMI(MBB, MBBI, DL, TII->get(GET_EGPR_IF_ENABLED(X86::KMOVWkm)))
489 .addReg(Reg0, RegState::Define | getDeadRegState(DstIsDead));
490 auto MIBHi =
491 BuildMI(MBB, MBBI, DL, TII->get(GET_EGPR_IF_ENABLED(X86::KMOVWkm)))
492 .addReg(Reg1, RegState::Define | getDeadRegState(DstIsDead));
493
494 for (int i = 0; i < X86::AddrNumOperands; ++i) {
495 MIBLo.add(MBBI->getOperand(1 + i));
496 if (i == X86::AddrDisp)
497 MIBHi.addImm(Disp + 2);
498 else
499 MIBHi.add(MBBI->getOperand(1 + i));
500 }
501
502 // Split the memory operand, adjusting the offset and size for the halves.
503 MachineMemOperand *OldMMO = MBBI->memoperands().front();
504 MachineFunction *MF = MBB.getParent();
505 MachineMemOperand *MMOLo = MF->getMachineMemOperand(OldMMO, 0, 2);
506 MachineMemOperand *MMOHi = MF->getMachineMemOperand(OldMMO, 2, 2);
507
508 MIBLo.setMemRefs(MMOLo);
509 MIBHi.setMemRefs(MMOHi);
510
511 // Delete the pseudo.
512 MBB.erase(MBBI);
513 return true;
514 }
515 case X86::MASKPAIR16STORE: {
516 int64_t Disp = MBBI->getOperand(X86::AddrDisp).getImm();
517 assert(Disp >= 0 && Disp <= INT32_MAX - 2 && "Unexpected displacement");
518 Register Reg = MBBI->getOperand(X86::AddrNumOperands).getReg();
519 bool SrcIsKill = MBBI->getOperand(X86::AddrNumOperands).isKill();
520 Register Reg0 = TRI->getSubReg(Reg, X86::sub_mask_0);
521 Register Reg1 = TRI->getSubReg(Reg, X86::sub_mask_1);
522
523 auto MIBLo =
524 BuildMI(MBB, MBBI, DL, TII->get(GET_EGPR_IF_ENABLED(X86::KMOVWmk)));
525 auto MIBHi =
526 BuildMI(MBB, MBBI, DL, TII->get(GET_EGPR_IF_ENABLED(X86::KMOVWmk)));
527
528 for (int i = 0; i < X86::AddrNumOperands; ++i) {
529 MIBLo.add(MBBI->getOperand(i));
530 if (i == X86::AddrDisp)
531 MIBHi.addImm(Disp + 2);
532 else
533 MIBHi.add(MBBI->getOperand(i));
534 }
535 MIBLo.addReg(Reg0, getKillRegState(SrcIsKill));
536 MIBHi.addReg(Reg1, getKillRegState(SrcIsKill));
537
538 // Split the memory operand, adjusting the offset and size for the halves.
539 MachineMemOperand *OldMMO = MBBI->memoperands().front();
540 MachineFunction *MF = MBB.getParent();
541 MachineMemOperand *MMOLo = MF->getMachineMemOperand(OldMMO, 0, 2);
542 MachineMemOperand *MMOHi = MF->getMachineMemOperand(OldMMO, 2, 2);
543
544 MIBLo.setMemRefs(MMOLo);
545 MIBHi.setMemRefs(MMOHi);
546
547 // Delete the pseudo.
548 MBB.erase(MBBI);
549 return true;
550 }
551 case X86::MWAITX_SAVE_RBX: {
552 // Perform the following transformation.
553 // SaveRbx = pseudomwaitx InArg, SaveRbx
554 // =>
555 // [E|R]BX = InArg
556 // actualmwaitx
557 // [E|R]BX = SaveRbx
558 const MachineOperand &InArg = MBBI->getOperand(1);
559 // Copy the input argument of the pseudo into the argument of the
560 // actual instruction.
561 TII->copyPhysReg(MBB, MBBI, DL, X86::EBX, InArg.getReg(), InArg.isKill());
562 // Create the actual instruction.
563 BuildMI(MBB, MBBI, DL, TII->get(X86::MWAITXrrr));
564 // Finally, restore the value of RBX.
565 Register SaveRbx = MBBI->getOperand(2).getReg();
566 TII->copyPhysReg(MBB, MBBI, DL, X86::RBX, SaveRbx, /*SrcIsKill*/ true);
567 // Delete the pseudo.
569 return true;
570 }
571 case TargetOpcode::ICALL_BRANCH_FUNNEL:
572 expandICallBranchFunnel(&MBB, MBBI);
573 return true;
574 case X86::PLDTILECFGV: {
575 MI.setDesc(TII->get(GET_EGPR_IF_ENABLED(X86::LDTILECFG)));
576 return true;
577 }
578 case X86::PTILELOADDV:
579 case X86::PTILELOADDT1V:
580 case X86::PTILELOADDRSV:
581 case X86::PTILELOADDRST1V:
582 case X86::PTCVTROWD2PSrreV:
583 case X86::PTCVTROWD2PSrriV:
584 case X86::PTCVTROWPS2BF16HrreV:
585 case X86::PTCVTROWPS2BF16HrriV:
586 case X86::PTCVTROWPS2BF16LrreV:
587 case X86::PTCVTROWPS2BF16LrriV:
588 case X86::PTCVTROWPS2PHHrreV:
589 case X86::PTCVTROWPS2PHHrriV:
590 case X86::PTCVTROWPS2PHLrreV:
591 case X86::PTCVTROWPS2PHLrriV:
592 case X86::PTILEMOVROWrreV:
593 case X86::PTILEMOVROWrriV: {
594 for (unsigned i = 2; i > 0; --i)
595 MI.removeOperand(i);
596 unsigned Opc;
597 switch (Opcode) {
598 case X86::PTILELOADDRSV:
599 Opc = GET_EGPR_IF_ENABLED(X86::TILELOADDRS);
600 break;
601 case X86::PTILELOADDRST1V:
602 Opc = GET_EGPR_IF_ENABLED(X86::TILELOADDRST1);
603 break;
604 case X86::PTILELOADDV:
605 Opc = GET_EGPR_IF_ENABLED(X86::TILELOADD);
606 break;
607 case X86::PTILELOADDT1V:
608 Opc = GET_EGPR_IF_ENABLED(X86::TILELOADDT1);
609 break;
610 case X86::PTCVTROWD2PSrreV:
611 Opc = X86::TCVTROWD2PSrre;
612 break;
613 case X86::PTCVTROWD2PSrriV:
614 Opc = X86::TCVTROWD2PSrri;
615 break;
616 case X86::PTCVTROWPS2BF16HrreV:
617 Opc = X86::TCVTROWPS2BF16Hrre;
618 break;
619 case X86::PTCVTROWPS2BF16HrriV:
620 Opc = X86::TCVTROWPS2BF16Hrri;
621 break;
622 case X86::PTCVTROWPS2BF16LrreV:
623 Opc = X86::TCVTROWPS2BF16Lrre;
624 break;
625 case X86::PTCVTROWPS2BF16LrriV:
626 Opc = X86::TCVTROWPS2BF16Lrri;
627 break;
628 case X86::PTCVTROWPS2PHHrreV:
629 Opc = X86::TCVTROWPS2PHHrre;
630 break;
631 case X86::PTCVTROWPS2PHHrriV:
632 Opc = X86::TCVTROWPS2PHHrri;
633 break;
634 case X86::PTCVTROWPS2PHLrreV:
635 Opc = X86::TCVTROWPS2PHLrre;
636 break;
637 case X86::PTCVTROWPS2PHLrriV:
638 Opc = X86::TCVTROWPS2PHLrri;
639 break;
640 case X86::PTILEMOVROWrreV:
641 Opc = X86::TILEMOVROWrre;
642 break;
643 case X86::PTILEMOVROWrriV:
644 Opc = X86::TILEMOVROWrri;
645 break;
646 default:
647 llvm_unreachable("Unexpected Opcode");
648 }
649 MI.setDesc(TII->get(Opc));
650 return true;
651 }
652 case X86::PTCMMIMFP16PSV:
653 case X86::PTCMMRLFP16PSV:
654 case X86::PTDPBSSDV:
655 case X86::PTDPBSUDV:
656 case X86::PTDPBUSDV:
657 case X86::PTDPBUUDV:
658 case X86::PTDPBF16PSV:
659 case X86::PTDPFP16PSV:
660 case X86::PTMMULTF32PSV:
661 case X86::PTDPBF8PSV:
662 case X86::PTDPBHF8PSV:
663 case X86::PTDPHBF8PSV:
664 case X86::PTDPHF8PSV: {
665 MI.untieRegOperand(4);
666 for (unsigned i = 3; i > 0; --i)
667 MI.removeOperand(i);
668 unsigned Opc;
669 switch (Opcode) {
670 // clang-format off
671 case X86::PTCMMIMFP16PSV: Opc = X86::TCMMIMFP16PS; break;
672 case X86::PTCMMRLFP16PSV: Opc = X86::TCMMRLFP16PS; break;
673 case X86::PTDPBSSDV: Opc = X86::TDPBSSD; break;
674 case X86::PTDPBSUDV: Opc = X86::TDPBSUD; break;
675 case X86::PTDPBUSDV: Opc = X86::TDPBUSD; break;
676 case X86::PTDPBUUDV: Opc = X86::TDPBUUD; break;
677 case X86::PTDPBF16PSV: Opc = X86::TDPBF16PS; break;
678 case X86::PTDPFP16PSV: Opc = X86::TDPFP16PS; break;
679 case X86::PTMMULTF32PSV: Opc = X86::TMMULTF32PS; break;
680 case X86::PTDPBF8PSV: Opc = X86::TDPBF8PS; break;
681 case X86::PTDPBHF8PSV: Opc = X86::TDPBHF8PS; break;
682 case X86::PTDPHBF8PSV: Opc = X86::TDPHBF8PS; break;
683 case X86::PTDPHF8PSV: Opc = X86::TDPHF8PS; break;
684 // clang-format on
685 default:
686 llvm_unreachable("Unexpected Opcode");
687 }
688 MI.setDesc(TII->get(Opc));
689 MI.tieOperands(0, 1);
690 return true;
691 }
692 case X86::PTILESTOREDV: {
693 for (int i = 1; i >= 0; --i)
694 MI.removeOperand(i);
695 MI.setDesc(TII->get(GET_EGPR_IF_ENABLED(X86::TILESTORED)));
696 return true;
697 }
698#undef GET_EGPR_IF_ENABLED
699 case X86::PTILEZEROV: {
700 for (int i = 2; i > 0; --i) // Remove row, col
701 MI.removeOperand(i);
702 MI.setDesc(TII->get(X86::TILEZERO));
703 return true;
704 }
705 case X86::CALL64pcrel32_RVMARKER:
706 case X86::CALL64r_RVMARKER:
707 case X86::CALL64m_RVMARKER:
708 expandCALL_RVMARKER(MBB, MBBI);
709 return true;
710 case X86::CALL64r_ImpCall:
711 MI.setDesc(TII->get(X86::CALL64r));
712 return true;
713 case X86::ADD32mi_ND:
714 case X86::ADD64mi32_ND:
715 case X86::SUB32mi_ND:
716 case X86::SUB64mi32_ND:
717 case X86::AND32mi_ND:
718 case X86::AND64mi32_ND:
719 case X86::OR32mi_ND:
720 case X86::OR64mi32_ND:
721 case X86::XOR32mi_ND:
722 case X86::XOR64mi32_ND:
723 case X86::ADC32mi_ND:
724 case X86::ADC64mi32_ND:
725 case X86::SBB32mi_ND:
726 case X86::SBB64mi32_ND: {
727 // It's possible for an EVEX-encoded legacy instruction to reach the 15-byte
728 // instruction length limit: 4 bytes of EVEX prefix + 1 byte of opcode + 1
729 // byte of ModRM + 1 byte of SIB + 4 bytes of displacement + 4 bytes of
730 // immediate = 15 bytes in total, e.g.
731 //
732 // subq $184, %fs:257(%rbx, %rcx), %rax
733 //
734 // In such a case, no additional (ADSIZE or segment override) prefix can be
735 // used. To resolve the issue, we split the “long” instruction into 2
736 // instructions:
737 //
738 // movq %fs:257(%rbx, %rcx),%rax
739 // subq $184, %rax
740 //
741 // Therefore we consider the OPmi_ND to be a pseudo instruction to some
742 // extent.
743 const MachineOperand &ImmOp =
744 MI.getOperand(MI.getNumExplicitOperands() - 1);
745 // If the immediate is a expr, conservatively estimate 4 bytes.
746 if (ImmOp.isImm() && isInt<8>(ImmOp.getImm()))
747 return false;
748 int MemOpNo = X86::getFirstAddrOperandIdx(MI);
749 const MachineOperand &DispOp = MI.getOperand(MemOpNo + X86::AddrDisp);
750 Register Base = MI.getOperand(MemOpNo + X86::AddrBaseReg).getReg();
751 // If the displacement is a expr, conservatively estimate 4 bytes.
752 if (Base && DispOp.isImm() && isInt<8>(DispOp.getImm()))
753 return false;
754 // There can only be one of three: SIB, segment override register, ADSIZE
755 Register Index = MI.getOperand(MemOpNo + X86::AddrIndexReg).getReg();
756 unsigned Count = !!MI.getOperand(MemOpNo + X86::AddrSegmentReg).getReg();
757 if (X86II::needSIB(Base, Index, /*In64BitMode=*/true))
758 ++Count;
759 if (X86MCRegisterClasses[X86::GR32RegClassID].contains(Base) ||
760 X86MCRegisterClasses[X86::GR32RegClassID].contains(Index))
761 ++Count;
762 if (Count < 2)
763 return false;
764 unsigned Opc, LoadOpc;
765 switch (Opcode) {
766#define MI_TO_RI(OP) \
767 case X86::OP##32mi_ND: \
768 Opc = X86::OP##32ri; \
769 LoadOpc = X86::MOV32rm; \
770 break; \
771 case X86::OP##64mi32_ND: \
772 Opc = X86::OP##64ri32; \
773 LoadOpc = X86::MOV64rm; \
774 break;
775
776 default:
777 llvm_unreachable("Unexpected Opcode");
778 MI_TO_RI(ADD);
779 MI_TO_RI(SUB);
780 MI_TO_RI(AND);
781 MI_TO_RI(OR);
782 MI_TO_RI(XOR);
783 MI_TO_RI(ADC);
784 MI_TO_RI(SBB);
785#undef MI_TO_RI
786 }
787 // Insert OPri.
788 Register DestReg = MI.getOperand(0).getReg();
789 BuildMI(MBB, std::next(MBBI), DL, TII->get(Opc), DestReg)
790 .addReg(DestReg)
791 .add(ImmOp);
792 // Change OPmi_ND to MOVrm.
793 for (unsigned I = MI.getNumImplicitOperands() + 1; I != 0; --I)
794 MI.removeOperand(MI.getNumOperands() - 1);
795 MI.setDesc(TII->get(LoadOpc));
796 return true;
797 }
798 }
799 llvm_unreachable("Previous switch has a fallthrough?");
800}
801
802// This function creates additional block for storing varargs guarded
803// registers. It adds check for %al into entry block, to skip
804// GuardedRegsBlk if xmm registers should not be stored.
805//
806// EntryBlk[VAStartPseudoInstr] EntryBlk
807// | | .
808// | | .
809// | | GuardedRegsBlk
810// | => | .
811// | | .
812// | TailBlk
813// | |
814// | |
815//
816void X86ExpandPseudo::expandVastartSaveXmmRegs(
817 MachineBasicBlock *EntryBlk,
818 MachineBasicBlock::iterator VAStartPseudoInstr) const {
819 assert(VAStartPseudoInstr->getOpcode() == X86::VASTART_SAVE_XMM_REGS);
820
821 MachineFunction *Func = EntryBlk->getParent();
822 const TargetInstrInfo *TII = STI->getInstrInfo();
823 const DebugLoc &DL = VAStartPseudoInstr->getDebugLoc();
824 Register CountReg = VAStartPseudoInstr->getOperand(0).getReg();
825
826 // Calculate liveins for newly created blocks.
827 LivePhysRegs LiveRegs(*STI->getRegisterInfo());
829
830 LiveRegs.addLiveIns(*EntryBlk);
831 for (MachineInstr &MI : EntryBlk->instrs()) {
832 if (MI.getOpcode() == VAStartPseudoInstr->getOpcode())
833 break;
834
835 LiveRegs.stepForward(MI, Clobbers);
836 }
837
838 // Create the new basic blocks. One block contains all the XMM stores,
839 // and another block is the final destination regardless of whether any
840 // stores were performed.
841 const BasicBlock *LLVMBlk = EntryBlk->getBasicBlock();
842 MachineFunction::iterator EntryBlkIter = ++EntryBlk->getIterator();
843 MachineBasicBlock *GuardedRegsBlk = Func->CreateMachineBasicBlock(LLVMBlk);
844 MachineBasicBlock *TailBlk = Func->CreateMachineBasicBlock(LLVMBlk);
845 Func->insert(EntryBlkIter, GuardedRegsBlk);
846 Func->insert(EntryBlkIter, TailBlk);
847
848 // Transfer the remainder of EntryBlk and its successor edges to TailBlk.
849 TailBlk->splice(TailBlk->begin(), EntryBlk,
850 std::next(MachineBasicBlock::iterator(VAStartPseudoInstr)),
851 EntryBlk->end());
852 TailBlk->transferSuccessorsAndUpdatePHIs(EntryBlk);
853
854 uint64_t FrameOffset = VAStartPseudoInstr->getOperand(4).getImm();
855 uint64_t VarArgsRegsOffset = VAStartPseudoInstr->getOperand(6).getImm();
856
857 // TODO: add support for YMM and ZMM here.
858 unsigned MOVOpc = STI->hasAVX() ? X86::VMOVAPSmr : X86::MOVAPSmr;
859
860 // In the XMM save block, save all the XMM argument registers.
861 for (int64_t OpndIdx = 7, RegIdx = 0;
862 OpndIdx < VAStartPseudoInstr->getNumOperands() - 1;
863 OpndIdx++, RegIdx++) {
864 auto NewMI = BuildMI(GuardedRegsBlk, DL, TII->get(MOVOpc));
865 for (int i = 0; i < X86::AddrNumOperands; ++i) {
866 if (i == X86::AddrDisp)
867 NewMI.addImm(FrameOffset + VarArgsRegsOffset + RegIdx * 16);
868 else
869 NewMI.add(VAStartPseudoInstr->getOperand(i + 1));
870 }
871 NewMI.addReg(VAStartPseudoInstr->getOperand(OpndIdx).getReg());
872 assert(VAStartPseudoInstr->getOperand(OpndIdx).getReg().isPhysical());
873 }
874
875 // The original block will now fall through to the GuardedRegsBlk.
876 EntryBlk->addSuccessor(GuardedRegsBlk);
877 // The GuardedRegsBlk will fall through to the TailBlk.
878 GuardedRegsBlk->addSuccessor(TailBlk);
879
880 if (!STI->isCallingConvWin64(Func->getFunction().getCallingConv())) {
881 // If %al is 0, branch around the XMM save block.
882 BuildMI(EntryBlk, DL, TII->get(X86::TEST8rr))
883 .addReg(CountReg)
884 .addReg(CountReg);
885 BuildMI(EntryBlk, DL, TII->get(X86::JCC_1))
886 .addMBB(TailBlk)
888 EntryBlk->addSuccessor(TailBlk);
889 }
890
891 // Add liveins to the created block.
892 addLiveIns(*GuardedRegsBlk, LiveRegs);
893 addLiveIns(*TailBlk, LiveRegs);
894
895 // Delete the pseudo.
896 VAStartPseudoInstr->eraseFromParent();
897}
898
899/// Expand all pseudo instructions contained in \p MBB.
900/// \returns true if any expansion occurred for \p MBB.
901bool X86ExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
902 bool Modified = false;
903
904 // MBBI may be invalidated by the expansion.
906 while (MBBI != E) {
907 MachineBasicBlock::iterator NMBBI = std::next(MBBI);
908 Modified |= expandMI(MBB, MBBI);
909 MBBI = NMBBI;
910 }
911
912 return Modified;
913}
914
915bool X86ExpandPseudo::expandPseudosWhichAffectControlFlow(MachineFunction &MF) {
916 // Currently pseudo which affects control flow is only
917 // X86::VASTART_SAVE_XMM_REGS which is located in Entry block.
918 // So we do not need to evaluate other blocks.
919 for (MachineInstr &Instr : MF.front().instrs()) {
920 if (Instr.getOpcode() == X86::VASTART_SAVE_XMM_REGS) {
921 expandVastartSaveXmmRegs(&(MF.front()), Instr);
922 return true;
923 }
924 }
925
926 return false;
927}
928
929bool X86ExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
930 STI = &MF.getSubtarget<X86Subtarget>();
931 TII = STI->getInstrInfo();
932 TRI = STI->getRegisterInfo();
933 X86FI = MF.getInfo<X86MachineFunctionInfo>();
934 X86FL = STI->getFrameLowering();
935
936 bool Modified = expandPseudosWhichAffectControlFlow(MF);
937
938 for (MachineBasicBlock &MBB : MF)
939 Modified |= expandMBB(MBB);
940 return Modified;
941}
942
943/// Returns an instance of the pseudo instruction expansion pass.
945 return new X86ExpandPseudo();
946}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define DEBUG_TYPE
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define I(x, y, z)
Definition MD5.cpp:58
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define P(N)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:472
static Target * FirstTarget
#define GET_EGPR_IF_ENABLED(OPC)
#define MI_TO_RI(OP)
#define X86_EXPAND_PSEUDO_NAME
Represent the analysis usage information of a pass.
AnalysisUsage & addPreservedID(const void *ID)
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:270
LLVM Basic Block Representation.
Definition BasicBlock.h:62
A debug info location.
Definition DebugLoc.h:124
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
Emit instructions to copy a pair of physical registers.
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Properties which a MachineFunction may have at a given point in time.
void moveAdditionalCallInfo(const MachineInstr *Old, const MachineInstr *New)
Move the call site info from Old to \New call site info.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
LLVM_ABI void setCFIType(MachineFunction &MF, uint32_t Type)
Set the CFI type for the instruction.
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
LLVM_ABI void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
void setIsKill(bool Val=true)
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
int64_t getOffset() const
Return the offset from the symbol in this operand.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
CodeModel::Model getCodeModel() const
Returns the code model.
Target - Wrapper for Target specific information.
bool isOSWindows() const
Tests whether the OS is Windows.
Definition Triple.h:681
int64_t mergeSPAdd(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t AddOffset, bool doMergeWithPrevious) const
Equivalent to: mergeSPUpdates(MBB, MBBI, [AddOffset](int64_t Offset) { return AddOffset + Offset; }...
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &DL, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
bool isTargetWin64() const
bool isTarget64BitLP64() const
Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
const Triple & getTargetTriple() const
const X86InstrInfo * getInstrInfo() const override
bool isCallingConvWin64(CallingConv::ID CC) const
bool isTargetUEFI64() const
const X86RegisterInfo * getRegisterInfo() const override
bool hasAVX() const
const X86FrameLowering * getFrameLowering() const override
self_iterator getIterator()
Definition ilist_node.h:123
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Dead
Unused definition.
@ Define
Register definition.
@ X86
Windows x64, Windows Itanium (IA-64)
Definition MCAsmInfo.h:50
bool needSIB(MCRegister BaseReg, MCRegister IndexReg, bool In64BitMode)
int getFirstAddrOperandIdx(const MachineInstr &MI)
Return the index of the instruction's first address operand, if it has a memory reference,...
@ AddrNumOperands
Definition X86BaseInfo.h:36
NodeAddr< InstrNode * > Instr
Definition RDFGraph.h:389
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
@ Offset
Definition DWP.cpp:477
LLVM_ABI void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
finalizeBundle - Finalize a machine instruction bundle which includes a sequence of instructions star...
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:165
static bool isMem(const MachineInstr &MI, unsigned Op)
LLVM_ABI char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
unsigned getDeadRegState(bool B)
LLVM_ABI char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
FunctionPass * createX86ExpandPseudoPass()
Return a Machine IR pass that expands X86-specific pseudo instructions into a sequence of actual inst...
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
unsigned getKillRegState(bool B)
DWARFExpression::Operation Op
void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs)
Adds registers contained in LiveRegs to the block live-in list of MBB.