29 #define DEBUG_TYPE "x86-pseudo"
58 return "X86 pseudo instruction expansion pass";
80 case X86::TCRETURNdicc:
83 case X86::TCRETURNdi64:
84 case X86::TCRETURNdi64cc:
85 case X86::TCRETURNri64:
86 case X86::TCRETURNmi64: {
87 bool isMem = Opcode == X86::TCRETURNmi || Opcode == X86::TCRETURNmi64;
90 assert(StackAdjust.
isImm() &&
"Expecting immediate value.");
93 int StackAdj = StackAdjust.
getImm();
94 int MaxTCDelta = X86FI->getTCReturnAddrDelta();
96 assert(MaxTCDelta <= 0 &&
"MaxTCDelta should never be positive");
99 Offset = StackAdj - MaxTCDelta;
100 assert(Offset >= 0 &&
"Offset should never be negative");
102 if (Opcode == X86::TCRETURNdicc || Opcode == X86::TCRETURNdi64cc) {
103 assert(Offset == 0 &&
"Conditional tail call cannot adjust the stack.");
108 Offset += X86FL->mergeSPUpdates(MBB, MBBI,
true);
109 X86FL->emitSPUpdate(MBB, MBBI, Offset,
true);
113 bool IsWin64 = STI->isTargetWin64();
114 if (Opcode == X86::TCRETURNdi || Opcode == X86::TCRETURNdicc ||
115 Opcode == X86::TCRETURNdi64 || Opcode == X86::TCRETURNdi64cc) {
118 case X86::TCRETURNdi:
121 case X86::TCRETURNdicc:
122 Op = X86::TAILJMPd_CC;
124 case X86::TCRETURNdi64cc:
126 "Conditional tail calls confuse "
127 "the Win64 unwinder.");
128 Op = X86::TAILJMPd64_CC;
133 Op = X86::TAILJMPd64;
145 if (Op == X86::TAILJMPd_CC || Op == X86::TAILJMPd64_CC) {
146 MIB.
addImm(MBBI->getOperand(2).getImm());
149 }
else if (Opcode == X86::TCRETURNmi || Opcode == X86::TCRETURNmi64) {
150 unsigned Op = (Opcode == X86::TCRETURNmi)
152 : (IsWin64 ? X86::TAILJMPm64_REX : X86::TAILJMPm64);
154 for (
unsigned i = 0; i != 5; ++i)
155 MIB.
add(MBBI->getOperand(i));
156 }
else if (Opcode == X86::TCRETURNri64) {
158 TII->get(IsWin64 ? X86::TAILJMPr64_REX : X86::TAILJMPr64))
161 BuildMI(MBB, MBBI, DL,
TII->get(X86::TAILJMPr))
174 case X86::EH_RETURN64: {
176 assert(DestAddr.
isReg() &&
"Offset should be in register!");
177 const bool Uses64BitFramePtr =
178 STI->isTarget64BitLP64() || STI->isTargetNaCl64();
179 unsigned StackPtr = TRI->getStackRegister();
181 TII->get(Uses64BitFramePtr ? X86::MOV64rr : X86::MOV32rr), StackPtr)
182 .addReg(DestAddr.
getReg());
188 int64_t StackAdj = MBBI->getOperand(0).getImm();
189 X86FL->emitSPUpdate(MBB, MBBI, StackAdj,
true);
192 TII->get(STI->is64Bit() ? X86::IRET64 : X86::IRET32));
198 int64_t StackAdj = MBBI->getOperand(0).getImm();
202 TII->get(STI->is64Bit() ? X86::RETQ : X86::RETL));
205 TII->get(STI->is64Bit() ? X86::RETIQ : X86::RETIL))
209 "shouldn't need to do this for x86_64 targets!");
213 X86FL->emitSPUpdate(MBB, MBBI, StackAdj,
true);
214 BuildMI(MBB, MBBI, DL,
TII->get(X86::PUSH32r)).addReg(X86::ECX);
215 MIB =
BuildMI(MBB, MBBI, DL,
TII->get(X86::RETL));
217 for (
unsigned I = 1,
E = MBBI->getNumOperands();
I !=
E; ++
I)
218 MIB.
add(MBBI->getOperand(
I));
222 case X86::EH_RESTORE: {
226 X86FL->restoreWin32EHStackPointers(MBB, MBBI, DL, IsSEH);
227 MBBI->eraseFromParent();
230 case X86::LCMPXCHG8B_SAVE_EBX:
231 case X86::LCMPXCHG16B_SAVE_RBX: {
239 unsigned SaveRbx = MBBI->getOperand(7).getReg();
241 unsigned ActualInArg =
242 Opcode == X86::LCMPXCHG8B_SAVE_EBX ? X86::EBX : X86::RBX;
249 Opcode == X86::LCMPXCHG8B_SAVE_EBX ? X86::LCMPXCHG8B : X86::LCMPXCHG16B;
252 for (
unsigned Idx = 1; Idx < 6; ++Idx)
259 MBBI->eraseFromParent();
269 bool Modified =
false;
275 Modified |= ExpandMI(MBB, MBBI);
284 TII = STI->getInstrInfo();
287 X86FL = STI->getFrameLowering();
289 bool Modified =
false;
291 Modified |= ExpandMBB(MBB);
297 return new X86ExpandPseudo();
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const GlobalValue * getGlobal() const
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const char * getSymbolName() const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
static bool isMem(const MachineInstr &MI, unsigned Op)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
const HexagonRegisterInfo & getRegisterInfo() const
HexagonInstrInfo specifics.
void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
Return from interrupt. Operand 0 is the number of bytes to pop.
AnalysisUsage & addPreservedID(const void *ID)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getTargetFlags() const
FunctionPass * createX86ExpandPseudoPass()
Return a Machine IR pass that expands X86-specific pseudo instructions into a sequence of actual inst...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Represent the analysis usage information of a pass.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
FunctionPass class - This class is used to implement most global optimizations.
int64_t getOffset() const
Return the offset from the symbol in this operand.
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
MachineOperand class - Representation of each machine instruction operand.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
llvm_unreachable("Unknown RegBank!")
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, bool KillSrc) const override
Emit instructions to copy a pair of physical registers.
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
constexpr bool isUInt< 16 >(uint64_t x)
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin...
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
StringRef - Represent a constant reference to a string, i.e.
Properties which a MachineFunction may have at a given point in time.