LLVM  5.0.0
AArch64ExpandPseudoInsts.cpp
Go to the documentation of this file.
1 //==-- AArch64ExpandPseudoInsts.cpp - Expand pseudo instructions --*- C++ -*-=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains a pass that expands pseudo instructions into target
11 // instructions to allow proper scheduling and other late optimizations. This
12 // pass should be run after register allocation but before the post-regalloc
13 // scheduling pass.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #include "AArch64InstrInfo.h"
18 #include "AArch64Subtarget.h"
20 #include "Utils/AArch64BaseInfo.h"
25 using namespace llvm;
26 
27 #define AARCH64_EXPAND_PSEUDO_NAME "AArch64 pseudo instruction expansion pass"
28 
29 namespace {
30 class AArch64ExpandPseudo : public MachineFunctionPass {
31 public:
32  static char ID;
33  AArch64ExpandPseudo() : MachineFunctionPass(ID) {
35  }
36 
37  const AArch64InstrInfo *TII;
38 
39  bool runOnMachineFunction(MachineFunction &Fn) override;
40 
41  StringRef getPassName() const override { return AARCH64_EXPAND_PSEUDO_NAME; }
42 
43 private:
44  bool expandMBB(MachineBasicBlock &MBB);
45  bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
46  MachineBasicBlock::iterator &NextMBBI);
47  bool expandMOVImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
48  unsigned BitSize);
49 
50  bool expandCMP_SWAP(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
51  unsigned LdarOp, unsigned StlrOp, unsigned CmpOp,
52  unsigned ExtendImm, unsigned ZeroReg,
53  MachineBasicBlock::iterator &NextMBBI);
54  bool expandCMP_SWAP_128(MachineBasicBlock &MBB,
56  MachineBasicBlock::iterator &NextMBBI);
57 };
59 }
60 
61 INITIALIZE_PASS(AArch64ExpandPseudo, "aarch64-expand-pseudo",
62  AARCH64_EXPAND_PSEUDO_NAME, false, false)
63 
64 /// \brief Transfer implicit operands on the pseudo instruction to the
65 /// instructions created from the expansion.
66 static void transferImpOps(MachineInstr &OldMI, MachineInstrBuilder &UseMI,
67  MachineInstrBuilder &DefMI) {
68  const MCInstrDesc &Desc = OldMI.getDesc();
69  for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands(); i != e;
70  ++i) {
71  const MachineOperand &MO = OldMI.getOperand(i);
72  assert(MO.isReg() && MO.getReg());
73  if (MO.isUse())
74  UseMI.add(MO);
75  else
76  DefMI.add(MO);
77  }
78 }
79 
80 /// \brief Helper function which extracts the specified 16-bit chunk from a
81 /// 64-bit value.
82 static uint64_t getChunk(uint64_t Imm, unsigned ChunkIdx) {
83  assert(ChunkIdx < 4 && "Out of range chunk index specified!");
84 
85  return (Imm >> (ChunkIdx * 16)) & 0xFFFF;
86 }
87 
88 /// \brief Helper function which replicates a 16-bit chunk within a 64-bit
89 /// value. Indices correspond to element numbers in a v4i16.
90 static uint64_t replicateChunk(uint64_t Imm, unsigned FromIdx, unsigned ToIdx) {
91  assert((FromIdx < 4) && (ToIdx < 4) && "Out of range chunk index specified!");
92  const unsigned ShiftAmt = ToIdx * 16;
93 
94  // Replicate the source chunk to the destination position.
95  const uint64_t Chunk = getChunk(Imm, FromIdx) << ShiftAmt;
96  // Clear the destination chunk.
97  Imm &= ~(0xFFFFLL << ShiftAmt);
98  // Insert the replicated chunk.
99  return Imm | Chunk;
100 }
101 
102 /// \brief Helper function which tries to materialize a 64-bit value with an
103 /// ORR + MOVK instruction sequence.
104 static bool tryOrrMovk(uint64_t UImm, uint64_t OrrImm, MachineInstr &MI,
105  MachineBasicBlock &MBB,
107  const AArch64InstrInfo *TII, unsigned ChunkIdx) {
108  assert(ChunkIdx < 4 && "Out of range chunk index specified!");
109  const unsigned ShiftAmt = ChunkIdx * 16;
110 
111  uint64_t Encoding;
112  if (AArch64_AM::processLogicalImmediate(OrrImm, 64, Encoding)) {
113  // Create the ORR-immediate instruction.
114  MachineInstrBuilder MIB =
115  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORRXri))
116  .add(MI.getOperand(0))
117  .addReg(AArch64::XZR)
118  .addImm(Encoding);
119 
120  // Create the MOVK instruction.
121  const unsigned Imm16 = getChunk(UImm, ChunkIdx);
122  const unsigned DstReg = MI.getOperand(0).getReg();
123  const bool DstIsDead = MI.getOperand(0).isDead();
124  MachineInstrBuilder MIB1 =
125  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi))
126  .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
127  .addReg(DstReg)
128  .addImm(Imm16)
130 
131  transferImpOps(MI, MIB, MIB1);
132  MI.eraseFromParent();
133  return true;
134  }
135 
136  return false;
137 }
138 
139 /// \brief Check whether the given 16-bit chunk replicated to full 64-bit width
140 /// can be materialized with an ORR instruction.
141 static bool canUseOrr(uint64_t Chunk, uint64_t &Encoding) {
142  Chunk = (Chunk << 48) | (Chunk << 32) | (Chunk << 16) | Chunk;
143 
144  return AArch64_AM::processLogicalImmediate(Chunk, 64, Encoding);
145 }
146 
147 /// \brief Check for identical 16-bit chunks within the constant and if so
148 /// materialize them with a single ORR instruction. The remaining one or two
149 /// 16-bit chunks will be materialized with MOVK instructions.
150 ///
151 /// This allows us to materialize constants like |A|B|A|A| or |A|B|C|A| (order
152 /// of the chunks doesn't matter), assuming |A|A|A|A| can be materialized with
153 /// an ORR instruction.
154 ///
155 static bool tryToreplicateChunks(uint64_t UImm, MachineInstr &MI,
156  MachineBasicBlock &MBB,
158  const AArch64InstrInfo *TII) {
159  typedef DenseMap<uint64_t, unsigned> CountMap;
160  CountMap Counts;
161 
162  // Scan the constant and count how often every chunk occurs.
163  for (unsigned Idx = 0; Idx < 4; ++Idx)
164  ++Counts[getChunk(UImm, Idx)];
165 
166  // Traverse the chunks to find one which occurs more than once.
167  for (CountMap::const_iterator Chunk = Counts.begin(), End = Counts.end();
168  Chunk != End; ++Chunk) {
169  const uint64_t ChunkVal = Chunk->first;
170  const unsigned Count = Chunk->second;
171 
172  uint64_t Encoding = 0;
173 
174  // We are looking for chunks which have two or three instances and can be
175  // materialized with an ORR instruction.
176  if ((Count != 2 && Count != 3) || !canUseOrr(ChunkVal, Encoding))
177  continue;
178 
179  const bool CountThree = Count == 3;
180  // Create the ORR-immediate instruction.
181  MachineInstrBuilder MIB =
182  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORRXri))
183  .add(MI.getOperand(0))
184  .addReg(AArch64::XZR)
185  .addImm(Encoding);
186 
187  const unsigned DstReg = MI.getOperand(0).getReg();
188  const bool DstIsDead = MI.getOperand(0).isDead();
189 
190  unsigned ShiftAmt = 0;
191  uint64_t Imm16 = 0;
192  // Find the first chunk not materialized with the ORR instruction.
193  for (; ShiftAmt < 64; ShiftAmt += 16) {
194  Imm16 = (UImm >> ShiftAmt) & 0xFFFF;
195 
196  if (Imm16 != ChunkVal)
197  break;
198  }
199 
200  // Create the first MOVK instruction.
201  MachineInstrBuilder MIB1 =
202  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi))
203  .addReg(DstReg,
204  RegState::Define | getDeadRegState(DstIsDead && CountThree))
205  .addReg(DstReg)
206  .addImm(Imm16)
208 
209  // In case we have three instances the whole constant is now materialized
210  // and we can exit.
211  if (CountThree) {
212  transferImpOps(MI, MIB, MIB1);
213  MI.eraseFromParent();
214  return true;
215  }
216 
217  // Find the remaining chunk which needs to be materialized.
218  for (ShiftAmt += 16; ShiftAmt < 64; ShiftAmt += 16) {
219  Imm16 = (UImm >> ShiftAmt) & 0xFFFF;
220 
221  if (Imm16 != ChunkVal)
222  break;
223  }
224 
225  // Create the second MOVK instruction.
226  MachineInstrBuilder MIB2 =
227  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi))
228  .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
229  .addReg(DstReg)
230  .addImm(Imm16)
232 
233  transferImpOps(MI, MIB, MIB2);
234  MI.eraseFromParent();
235  return true;
236  }
237 
238  return false;
239 }
240 
241 /// \brief Check whether this chunk matches the pattern '1...0...'. This pattern
242 /// starts a contiguous sequence of ones if we look at the bits from the LSB
243 /// towards the MSB.
244 static bool isStartChunk(uint64_t Chunk) {
245  if (Chunk == 0 || Chunk == UINT64_MAX)
246  return false;
247 
248  return isMask_64(~Chunk);
249 }
250 
251 /// \brief Check whether this chunk matches the pattern '0...1...' This pattern
252 /// ends a contiguous sequence of ones if we look at the bits from the LSB
253 /// towards the MSB.
254 static bool isEndChunk(uint64_t Chunk) {
255  if (Chunk == 0 || Chunk == UINT64_MAX)
256  return false;
257 
258  return isMask_64(Chunk);
259 }
260 
261 /// \brief Clear or set all bits in the chunk at the given index.
262 static uint64_t updateImm(uint64_t Imm, unsigned Idx, bool Clear) {
263  const uint64_t Mask = 0xFFFF;
264 
265  if (Clear)
266  // Clear chunk in the immediate.
267  Imm &= ~(Mask << (Idx * 16));
268  else
269  // Set all bits in the immediate for the particular chunk.
270  Imm |= Mask << (Idx * 16);
271 
272  return Imm;
273 }
274 
275 /// \brief Check whether the constant contains a sequence of contiguous ones,
276 /// which might be interrupted by one or two chunks. If so, materialize the
277 /// sequence of contiguous ones with an ORR instruction.
278 /// Materialize the chunks which are either interrupting the sequence or outside
279 /// of the sequence with a MOVK instruction.
280 ///
281 /// Assuming S is a chunk which starts the sequence (1...0...), E is a chunk
282 /// which ends the sequence (0...1...). Then we are looking for constants which
283 /// contain at least one S and E chunk.
284 /// E.g. |E|A|B|S|, |A|E|B|S| or |A|B|E|S|.
285 ///
286 /// We are also looking for constants like |S|A|B|E| where the contiguous
287 /// sequence of ones wraps around the MSB into the LSB.
288 ///
289 static bool trySequenceOfOnes(uint64_t UImm, MachineInstr &MI,
290  MachineBasicBlock &MBB,
292  const AArch64InstrInfo *TII) {
293  const int NotSet = -1;
294  const uint64_t Mask = 0xFFFF;
295 
296  int StartIdx = NotSet;
297  int EndIdx = NotSet;
298  // Try to find the chunks which start/end a contiguous sequence of ones.
299  for (int Idx = 0; Idx < 4; ++Idx) {
300  int64_t Chunk = getChunk(UImm, Idx);
301  // Sign extend the 16-bit chunk to 64-bit.
302  Chunk = (Chunk << 48) >> 48;
303 
304  if (isStartChunk(Chunk))
305  StartIdx = Idx;
306  else if (isEndChunk(Chunk))
307  EndIdx = Idx;
308  }
309 
310  // Early exit in case we can't find a start/end chunk.
311  if (StartIdx == NotSet || EndIdx == NotSet)
312  return false;
313 
314  // Outside of the contiguous sequence of ones everything needs to be zero.
315  uint64_t Outside = 0;
316  // Chunks between the start and end chunk need to have all their bits set.
317  uint64_t Inside = Mask;
318 
319  // If our contiguous sequence of ones wraps around from the MSB into the LSB,
320  // just swap indices and pretend we are materializing a contiguous sequence
321  // of zeros surrounded by a contiguous sequence of ones.
322  if (StartIdx > EndIdx) {
323  std::swap(StartIdx, EndIdx);
324  std::swap(Outside, Inside);
325  }
326 
327  uint64_t OrrImm = UImm;
328  int FirstMovkIdx = NotSet;
329  int SecondMovkIdx = NotSet;
330 
331  // Find out which chunks we need to patch up to obtain a contiguous sequence
332  // of ones.
333  for (int Idx = 0; Idx < 4; ++Idx) {
334  const uint64_t Chunk = getChunk(UImm, Idx);
335 
336  // Check whether we are looking at a chunk which is not part of the
337  // contiguous sequence of ones.
338  if ((Idx < StartIdx || EndIdx < Idx) && Chunk != Outside) {
339  OrrImm = updateImm(OrrImm, Idx, Outside == 0);
340 
341  // Remember the index we need to patch.
342  if (FirstMovkIdx == NotSet)
343  FirstMovkIdx = Idx;
344  else
345  SecondMovkIdx = Idx;
346 
347  // Check whether we are looking a chunk which is part of the contiguous
348  // sequence of ones.
349  } else if (Idx > StartIdx && Idx < EndIdx && Chunk != Inside) {
350  OrrImm = updateImm(OrrImm, Idx, Inside != Mask);
351 
352  // Remember the index we need to patch.
353  if (FirstMovkIdx == NotSet)
354  FirstMovkIdx = Idx;
355  else
356  SecondMovkIdx = Idx;
357  }
358  }
359  assert(FirstMovkIdx != NotSet && "Constant materializable with single ORR!");
360 
361  // Create the ORR-immediate instruction.
362  uint64_t Encoding = 0;
363  AArch64_AM::processLogicalImmediate(OrrImm, 64, Encoding);
364  MachineInstrBuilder MIB =
365  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ORRXri))
366  .add(MI.getOperand(0))
367  .addReg(AArch64::XZR)
368  .addImm(Encoding);
369 
370  const unsigned DstReg = MI.getOperand(0).getReg();
371  const bool DstIsDead = MI.getOperand(0).isDead();
372 
373  const bool SingleMovk = SecondMovkIdx == NotSet;
374  // Create the first MOVK instruction.
375  MachineInstrBuilder MIB1 =
376  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi))
377  .addReg(DstReg,
378  RegState::Define | getDeadRegState(DstIsDead && SingleMovk))
379  .addReg(DstReg)
380  .addImm(getChunk(UImm, FirstMovkIdx))
381  .addImm(
382  AArch64_AM::getShifterImm(AArch64_AM::LSL, FirstMovkIdx * 16));
383 
384  // Early exit in case we only need to emit a single MOVK instruction.
385  if (SingleMovk) {
386  transferImpOps(MI, MIB, MIB1);
387  MI.eraseFromParent();
388  return true;
389  }
390 
391  // Create the second MOVK instruction.
392  MachineInstrBuilder MIB2 =
393  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MOVKXi))
394  .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
395  .addReg(DstReg)
396  .addImm(getChunk(UImm, SecondMovkIdx))
397  .addImm(
398  AArch64_AM::getShifterImm(AArch64_AM::LSL, SecondMovkIdx * 16));
399 
400  transferImpOps(MI, MIB, MIB2);
401  MI.eraseFromParent();
402  return true;
403 }
404 
405 /// \brief Expand a MOVi32imm or MOVi64imm pseudo instruction to one or more
406 /// real move-immediate instructions to synthesize the immediate.
407 bool AArch64ExpandPseudo::expandMOVImm(MachineBasicBlock &MBB,
409  unsigned BitSize) {
410  MachineInstr &MI = *MBBI;
411  unsigned DstReg = MI.getOperand(0).getReg();
412  uint64_t Imm = MI.getOperand(1).getImm();
413  const unsigned Mask = 0xFFFF;
414 
415  if (DstReg == AArch64::XZR || DstReg == AArch64::WZR) {
416  // Useless def, and we don't want to risk creating an invalid ORR (which
417  // would really write to sp).
418  MI.eraseFromParent();
419  return true;
420  }
421 
422  // Try a MOVI instruction (aka ORR-immediate with the zero register).
423  uint64_t UImm = Imm << (64 - BitSize) >> (64 - BitSize);
424  uint64_t Encoding;
425  if (AArch64_AM::processLogicalImmediate(UImm, BitSize, Encoding)) {
426  unsigned Opc = (BitSize == 32 ? AArch64::ORRWri : AArch64::ORRXri);
427  MachineInstrBuilder MIB =
428  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc))
429  .add(MI.getOperand(0))
430  .addReg(BitSize == 32 ? AArch64::WZR : AArch64::XZR)
431  .addImm(Encoding);
432  transferImpOps(MI, MIB, MIB);
433  MI.eraseFromParent();
434  return true;
435  }
436 
437  // Scan the immediate and count the number of 16-bit chunks which are either
438  // all ones or all zeros.
439  unsigned OneChunks = 0;
440  unsigned ZeroChunks = 0;
441  for (unsigned Shift = 0; Shift < BitSize; Shift += 16) {
442  const unsigned Chunk = (Imm >> Shift) & Mask;
443  if (Chunk == Mask)
444  OneChunks++;
445  else if (Chunk == 0)
446  ZeroChunks++;
447  }
448 
449  // Since we can't materialize the constant with a single ORR instruction,
450  // let's see whether we can materialize 3/4 of the constant with an ORR
451  // instruction and use an additional MOVK instruction to materialize the
452  // remaining 1/4.
453  //
454  // We are looking for constants with a pattern like: |A|X|B|X| or |X|A|X|B|.
455  //
456  // E.g. assuming |A|X|A|X| is a pattern which can be materialized with ORR,
457  // we would create the following instruction sequence:
458  //
459  // ORR x0, xzr, |A|X|A|X|
460  // MOVK x0, |B|, LSL #16
461  //
462  // Only look at 64-bit constants which can't be materialized with a single
463  // instruction e.g. which have less than either three all zero or all one
464  // chunks.
465  //
466  // Ignore 32-bit constants here, they always can be materialized with a
467  // MOVZ/MOVN + MOVK pair. Since the 32-bit constant can't be materialized
468  // with a single ORR, the best sequence we can achieve is a ORR + MOVK pair.
469  // Thus we fall back to the default code below which in the best case creates
470  // a single MOVZ/MOVN instruction (in case one chunk is all zero or all one).
471  //
472  if (BitSize == 64 && OneChunks < 3 && ZeroChunks < 3) {
473  // If we interpret the 64-bit constant as a v4i16, are elements 0 and 2
474  // identical?
475  if (getChunk(UImm, 0) == getChunk(UImm, 2)) {
476  // See if we can come up with a constant which can be materialized with
477  // ORR-immediate by replicating element 3 into element 1.
478  uint64_t OrrImm = replicateChunk(UImm, 3, 1);
479  if (tryOrrMovk(UImm, OrrImm, MI, MBB, MBBI, TII, 1))
480  return true;
481 
482  // See if we can come up with a constant which can be materialized with
483  // ORR-immediate by replicating element 1 into element 3.
484  OrrImm = replicateChunk(UImm, 1, 3);
485  if (tryOrrMovk(UImm, OrrImm, MI, MBB, MBBI, TII, 3))
486  return true;
487 
488  // If we interpret the 64-bit constant as a v4i16, are elements 1 and 3
489  // identical?
490  } else if (getChunk(UImm, 1) == getChunk(UImm, 3)) {
491  // See if we can come up with a constant which can be materialized with
492  // ORR-immediate by replicating element 2 into element 0.
493  uint64_t OrrImm = replicateChunk(UImm, 2, 0);
494  if (tryOrrMovk(UImm, OrrImm, MI, MBB, MBBI, TII, 0))
495  return true;
496 
497  // See if we can come up with a constant which can be materialized with
498  // ORR-immediate by replicating element 1 into element 3.
499  OrrImm = replicateChunk(UImm, 0, 2);
500  if (tryOrrMovk(UImm, OrrImm, MI, MBB, MBBI, TII, 2))
501  return true;
502  }
503  }
504 
505  // Check for identical 16-bit chunks within the constant and if so materialize
506  // them with a single ORR instruction. The remaining one or two 16-bit chunks
507  // will be materialized with MOVK instructions.
508  if (BitSize == 64 && tryToreplicateChunks(UImm, MI, MBB, MBBI, TII))
509  return true;
510 
511  // Check whether the constant contains a sequence of contiguous ones, which
512  // might be interrupted by one or two chunks. If so, materialize the sequence
513  // of contiguous ones with an ORR instruction. Materialize the chunks which
514  // are either interrupting the sequence or outside of the sequence with a
515  // MOVK instruction.
516  if (BitSize == 64 && trySequenceOfOnes(UImm, MI, MBB, MBBI, TII))
517  return true;
518 
519  // Use a MOVZ or MOVN instruction to set the high bits, followed by one or
520  // more MOVK instructions to insert additional 16-bit portions into the
521  // lower bits.
522  bool isNeg = false;
523 
524  // Use MOVN to materialize the high bits if we have more all one chunks
525  // than all zero chunks.
526  if (OneChunks > ZeroChunks) {
527  isNeg = true;
528  Imm = ~Imm;
529  }
530 
531  unsigned FirstOpc;
532  if (BitSize == 32) {
533  Imm &= (1LL << 32) - 1;
534  FirstOpc = (isNeg ? AArch64::MOVNWi : AArch64::MOVZWi);
535  } else {
536  FirstOpc = (isNeg ? AArch64::MOVNXi : AArch64::MOVZXi);
537  }
538  unsigned Shift = 0; // LSL amount for high bits with MOVZ/MOVN
539  unsigned LastShift = 0; // LSL amount for last MOVK
540  if (Imm != 0) {
541  unsigned LZ = countLeadingZeros(Imm);
542  unsigned TZ = countTrailingZeros(Imm);
543  Shift = (TZ / 16) * 16;
544  LastShift = ((63 - LZ) / 16) * 16;
545  }
546  unsigned Imm16 = (Imm >> Shift) & Mask;
547  bool DstIsDead = MI.getOperand(0).isDead();
548  MachineInstrBuilder MIB1 =
549  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(FirstOpc))
550  .addReg(DstReg, RegState::Define |
551  getDeadRegState(DstIsDead && Shift == LastShift))
552  .addImm(Imm16)
554 
555  // If a MOVN was used for the high bits of a negative value, flip the rest
556  // of the bits back for use with MOVK.
557  if (isNeg)
558  Imm = ~Imm;
559 
560  if (Shift == LastShift) {
561  transferImpOps(MI, MIB1, MIB1);
562  MI.eraseFromParent();
563  return true;
564  }
565 
566  MachineInstrBuilder MIB2;
567  unsigned Opc = (BitSize == 32 ? AArch64::MOVKWi : AArch64::MOVKXi);
568  while (Shift < LastShift) {
569  Shift += 16;
570  Imm16 = (Imm >> Shift) & Mask;
571  if (Imm16 == (isNeg ? Mask : 0))
572  continue; // This 16-bit portion is already set correctly.
573  MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc))
574  .addReg(DstReg,
576  getDeadRegState(DstIsDead && Shift == LastShift))
577  .addReg(DstReg)
578  .addImm(Imm16)
580  }
581 
582  transferImpOps(MI, MIB1, MIB2);
583  MI.eraseFromParent();
584  return true;
585 }
586 
587 bool AArch64ExpandPseudo::expandCMP_SWAP(
588  MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned LdarOp,
589  unsigned StlrOp, unsigned CmpOp, unsigned ExtendImm, unsigned ZeroReg,
590  MachineBasicBlock::iterator &NextMBBI) {
591  MachineInstr &MI = *MBBI;
592  DebugLoc DL = MI.getDebugLoc();
593  const MachineOperand &Dest = MI.getOperand(0);
594  unsigned StatusReg = MI.getOperand(1).getReg();
595  bool StatusDead = MI.getOperand(1).isDead();
596  // Duplicating undef operands into 2 instructions does not guarantee the same
597  // value on both; However undef should be replaced by xzr anyway.
598  assert(!MI.getOperand(2).isUndef() && "cannot handle undef");
599  unsigned AddrReg = MI.getOperand(2).getReg();
600  unsigned DesiredReg = MI.getOperand(3).getReg();
601  unsigned NewReg = MI.getOperand(4).getReg();
602 
603  MachineFunction *MF = MBB.getParent();
604  auto LoadCmpBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
605  auto StoreBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
606  auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
607 
608  MF->insert(++MBB.getIterator(), LoadCmpBB);
609  MF->insert(++LoadCmpBB->getIterator(), StoreBB);
610  MF->insert(++StoreBB->getIterator(), DoneBB);
611 
612  // .Lloadcmp:
613  // mov wStatus, 0
614  // ldaxr xDest, [xAddr]
615  // cmp xDest, xDesired
616  // b.ne .Ldone
617  if (!StatusDead)
618  BuildMI(LoadCmpBB, DL, TII->get(AArch64::MOVZWi), StatusReg)
619  .addImm(0).addImm(0);
620  BuildMI(LoadCmpBB, DL, TII->get(LdarOp), Dest.getReg())
621  .addReg(AddrReg);
622  BuildMI(LoadCmpBB, DL, TII->get(CmpOp), ZeroReg)
623  .addReg(Dest.getReg(), getKillRegState(Dest.isDead()))
624  .addReg(DesiredReg)
625  .addImm(ExtendImm);
626  BuildMI(LoadCmpBB, DL, TII->get(AArch64::Bcc))
627  .addImm(AArch64CC::NE)
628  .addMBB(DoneBB)
629  .addReg(AArch64::NZCV, RegState::Implicit | RegState::Kill);
630  LoadCmpBB->addSuccessor(DoneBB);
631  LoadCmpBB->addSuccessor(StoreBB);
632 
633  // .Lstore:
634  // stlxr wStatus, xNew, [xAddr]
635  // cbnz wStatus, .Lloadcmp
636  BuildMI(StoreBB, DL, TII->get(StlrOp), StatusReg)
637  .addReg(NewReg)
638  .addReg(AddrReg);
639  BuildMI(StoreBB, DL, TII->get(AArch64::CBNZW))
640  .addReg(StatusReg, getKillRegState(StatusDead))
641  .addMBB(LoadCmpBB);
642  StoreBB->addSuccessor(LoadCmpBB);
643  StoreBB->addSuccessor(DoneBB);
644 
645  DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
646  DoneBB->transferSuccessors(&MBB);
647 
648  MBB.addSuccessor(LoadCmpBB);
649 
650  NextMBBI = MBB.end();
651  MI.eraseFromParent();
652 
653  // Recompute livein lists.
654  const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
655  LivePhysRegs LiveRegs;
656  computeLiveIns(LiveRegs, MRI, *DoneBB);
657  computeLiveIns(LiveRegs, MRI, *StoreBB);
658  computeLiveIns(LiveRegs, MRI, *LoadCmpBB);
659  // Do an extra pass around the loop to get loop carried registers right.
660  StoreBB->clearLiveIns();
661  computeLiveIns(LiveRegs, MRI, *StoreBB);
662  LoadCmpBB->clearLiveIns();
663  computeLiveIns(LiveRegs, MRI, *LoadCmpBB);
664 
665  return true;
666 }
667 
668 bool AArch64ExpandPseudo::expandCMP_SWAP_128(
670  MachineBasicBlock::iterator &NextMBBI) {
671 
672  MachineInstr &MI = *MBBI;
673  DebugLoc DL = MI.getDebugLoc();
674  MachineOperand &DestLo = MI.getOperand(0);
675  MachineOperand &DestHi = MI.getOperand(1);
676  unsigned StatusReg = MI.getOperand(2).getReg();
677  bool StatusDead = MI.getOperand(2).isDead();
678  // Duplicating undef operands into 2 instructions does not guarantee the same
679  // value on both; However undef should be replaced by xzr anyway.
680  assert(!MI.getOperand(3).isUndef() && "cannot handle undef");
681  unsigned AddrReg = MI.getOperand(3).getReg();
682  unsigned DesiredLoReg = MI.getOperand(4).getReg();
683  unsigned DesiredHiReg = MI.getOperand(5).getReg();
684  unsigned NewLoReg = MI.getOperand(6).getReg();
685  unsigned NewHiReg = MI.getOperand(7).getReg();
686 
687  MachineFunction *MF = MBB.getParent();
688  auto LoadCmpBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
689  auto StoreBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
690  auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
691 
692  MF->insert(++MBB.getIterator(), LoadCmpBB);
693  MF->insert(++LoadCmpBB->getIterator(), StoreBB);
694  MF->insert(++StoreBB->getIterator(), DoneBB);
695 
696  // .Lloadcmp:
697  // ldaxp xDestLo, xDestHi, [xAddr]
698  // cmp xDestLo, xDesiredLo
699  // sbcs xDestHi, xDesiredHi
700  // b.ne .Ldone
701  BuildMI(LoadCmpBB, DL, TII->get(AArch64::LDAXPX))
702  .addReg(DestLo.getReg(), RegState::Define)
703  .addReg(DestHi.getReg(), RegState::Define)
704  .addReg(AddrReg);
705  BuildMI(LoadCmpBB, DL, TII->get(AArch64::SUBSXrs), AArch64::XZR)
706  .addReg(DestLo.getReg(), getKillRegState(DestLo.isDead()))
707  .addReg(DesiredLoReg)
708  .addImm(0);
709  BuildMI(LoadCmpBB, DL, TII->get(AArch64::CSINCWr), StatusReg)
710  .addUse(AArch64::WZR)
711  .addUse(AArch64::WZR)
713  BuildMI(LoadCmpBB, DL, TII->get(AArch64::SUBSXrs), AArch64::XZR)
714  .addReg(DestHi.getReg(), getKillRegState(DestHi.isDead()))
715  .addReg(DesiredHiReg)
716  .addImm(0);
717  BuildMI(LoadCmpBB, DL, TII->get(AArch64::CSINCWr), StatusReg)
718  .addUse(StatusReg, RegState::Kill)
719  .addUse(StatusReg, RegState::Kill)
721  BuildMI(LoadCmpBB, DL, TII->get(AArch64::CBNZW))
722  .addUse(StatusReg, getKillRegState(StatusDead))
723  .addMBB(DoneBB);
724  LoadCmpBB->addSuccessor(DoneBB);
725  LoadCmpBB->addSuccessor(StoreBB);
726 
727  // .Lstore:
728  // stlxp wStatus, xNewLo, xNewHi, [xAddr]
729  // cbnz wStatus, .Lloadcmp
730  BuildMI(StoreBB, DL, TII->get(AArch64::STLXPX), StatusReg)
731  .addReg(NewLoReg)
732  .addReg(NewHiReg)
733  .addReg(AddrReg);
734  BuildMI(StoreBB, DL, TII->get(AArch64::CBNZW))
735  .addReg(StatusReg, getKillRegState(StatusDead))
736  .addMBB(LoadCmpBB);
737  StoreBB->addSuccessor(LoadCmpBB);
738  StoreBB->addSuccessor(DoneBB);
739 
740  DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
741  DoneBB->transferSuccessors(&MBB);
742 
743  MBB.addSuccessor(LoadCmpBB);
744 
745  NextMBBI = MBB.end();
746  MI.eraseFromParent();
747 
748  // Recompute liveness bottom up.
749  const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
750  LivePhysRegs LiveRegs;
751  computeLiveIns(LiveRegs, MRI, *DoneBB);
752  computeLiveIns(LiveRegs, MRI, *StoreBB);
753  computeLiveIns(LiveRegs, MRI, *LoadCmpBB);
754  // Do an extra pass in the loop to get the loop carried dependencies right.
755  StoreBB->clearLiveIns();
756  computeLiveIns(LiveRegs, MRI, *StoreBB);
757  LoadCmpBB->clearLiveIns();
758  computeLiveIns(LiveRegs, MRI, *LoadCmpBB);
759 
760  return true;
761 }
762 
763 /// \brief If MBBI references a pseudo instruction that should be expanded here,
764 /// do the expansion and return true. Otherwise return false.
765 bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
767  MachineBasicBlock::iterator &NextMBBI) {
768  MachineInstr &MI = *MBBI;
769  unsigned Opcode = MI.getOpcode();
770  switch (Opcode) {
771  default:
772  break;
773 
774  case AArch64::ADDWrr:
775  case AArch64::SUBWrr:
776  case AArch64::ADDXrr:
777  case AArch64::SUBXrr:
778  case AArch64::ADDSWrr:
779  case AArch64::SUBSWrr:
780  case AArch64::ADDSXrr:
781  case AArch64::SUBSXrr:
782  case AArch64::ANDWrr:
783  case AArch64::ANDXrr:
784  case AArch64::BICWrr:
785  case AArch64::BICXrr:
786  case AArch64::ANDSWrr:
787  case AArch64::ANDSXrr:
788  case AArch64::BICSWrr:
789  case AArch64::BICSXrr:
790  case AArch64::EONWrr:
791  case AArch64::EONXrr:
792  case AArch64::EORWrr:
793  case AArch64::EORXrr:
794  case AArch64::ORNWrr:
795  case AArch64::ORNXrr:
796  case AArch64::ORRWrr:
797  case AArch64::ORRXrr: {
798  unsigned Opcode;
799  switch (MI.getOpcode()) {
800  default:
801  return false;
802  case AArch64::ADDWrr: Opcode = AArch64::ADDWrs; break;
803  case AArch64::SUBWrr: Opcode = AArch64::SUBWrs; break;
804  case AArch64::ADDXrr: Opcode = AArch64::ADDXrs; break;
805  case AArch64::SUBXrr: Opcode = AArch64::SUBXrs; break;
806  case AArch64::ADDSWrr: Opcode = AArch64::ADDSWrs; break;
807  case AArch64::SUBSWrr: Opcode = AArch64::SUBSWrs; break;
808  case AArch64::ADDSXrr: Opcode = AArch64::ADDSXrs; break;
809  case AArch64::SUBSXrr: Opcode = AArch64::SUBSXrs; break;
810  case AArch64::ANDWrr: Opcode = AArch64::ANDWrs; break;
811  case AArch64::ANDXrr: Opcode = AArch64::ANDXrs; break;
812  case AArch64::BICWrr: Opcode = AArch64::BICWrs; break;
813  case AArch64::BICXrr: Opcode = AArch64::BICXrs; break;
814  case AArch64::ANDSWrr: Opcode = AArch64::ANDSWrs; break;
815  case AArch64::ANDSXrr: Opcode = AArch64::ANDSXrs; break;
816  case AArch64::BICSWrr: Opcode = AArch64::BICSWrs; break;
817  case AArch64::BICSXrr: Opcode = AArch64::BICSXrs; break;
818  case AArch64::EONWrr: Opcode = AArch64::EONWrs; break;
819  case AArch64::EONXrr: Opcode = AArch64::EONXrs; break;
820  case AArch64::EORWrr: Opcode = AArch64::EORWrs; break;
821  case AArch64::EORXrr: Opcode = AArch64::EORXrs; break;
822  case AArch64::ORNWrr: Opcode = AArch64::ORNWrs; break;
823  case AArch64::ORNXrr: Opcode = AArch64::ORNXrs; break;
824  case AArch64::ORRWrr: Opcode = AArch64::ORRWrs; break;
825  case AArch64::ORRXrr: Opcode = AArch64::ORRXrs; break;
826  }
827  MachineInstrBuilder MIB1 =
828  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opcode),
829  MI.getOperand(0).getReg())
830  .add(MI.getOperand(1))
831  .add(MI.getOperand(2))
833  transferImpOps(MI, MIB1, MIB1);
834  MI.eraseFromParent();
835  return true;
836  }
837 
838  case AArch64::LOADgot: {
839  // Expand into ADRP + LDR.
840  unsigned DstReg = MI.getOperand(0).getReg();
841  const MachineOperand &MO1 = MI.getOperand(1);
842  unsigned Flags = MO1.getTargetFlags();
843  MachineInstrBuilder MIB1 =
844  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg);
845  MachineInstrBuilder MIB2 =
846  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::LDRXui))
847  .add(MI.getOperand(0))
848  .addReg(DstReg);
849 
850  if (MO1.isGlobal()) {
851  MIB1.addGlobalAddress(MO1.getGlobal(), 0, Flags | AArch64II::MO_PAGE);
852  MIB2.addGlobalAddress(MO1.getGlobal(), 0,
854  } else if (MO1.isSymbol()) {
856  MIB2.addExternalSymbol(MO1.getSymbolName(),
858  } else {
859  assert(MO1.isCPI() &&
860  "Only expect globals, externalsymbols, or constant pools");
861  MIB1.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(),
862  Flags | AArch64II::MO_PAGE);
863  MIB2.addConstantPoolIndex(MO1.getIndex(), MO1.getOffset(),
864  Flags | AArch64II::MO_PAGEOFF |
866  }
867 
868  transferImpOps(MI, MIB1, MIB2);
869  MI.eraseFromParent();
870  return true;
871  }
872 
873  case AArch64::MOVaddr:
874  case AArch64::MOVaddrJT:
875  case AArch64::MOVaddrCP:
876  case AArch64::MOVaddrBA:
877  case AArch64::MOVaddrTLS:
878  case AArch64::MOVaddrEXT: {
879  // Expand into ADRP + ADD.
880  unsigned DstReg = MI.getOperand(0).getReg();
881  MachineInstrBuilder MIB1 =
882  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADRP), DstReg)
883  .add(MI.getOperand(1));
884 
885  MachineInstrBuilder MIB2 =
886  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADDXri))
887  .add(MI.getOperand(0))
888  .addReg(DstReg)
889  .add(MI.getOperand(2))
890  .addImm(0);
891 
892  transferImpOps(MI, MIB1, MIB2);
893  MI.eraseFromParent();
894  return true;
895  }
896  case AArch64::MOVbaseTLS: {
897  unsigned DstReg = MI.getOperand(0).getReg();
898  auto SysReg = AArch64SysReg::TPIDR_EL0;
899  MachineFunction *MF = MBB.getParent();
900  if (MF->getTarget().getTargetTriple().isOSFuchsia() &&
902  SysReg = AArch64SysReg::TPIDR_EL1;
903  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::MRS), DstReg)
904  .addImm(SysReg);
905  MI.eraseFromParent();
906  return true;
907  }
908 
909  case AArch64::MOVi32imm:
910  return expandMOVImm(MBB, MBBI, 32);
911  case AArch64::MOVi64imm:
912  return expandMOVImm(MBB, MBBI, 64);
913  case AArch64::RET_ReallyLR: {
914  // Hiding the LR use with RET_ReallyLR may lead to extra kills in the
915  // function and missing live-ins. We are fine in practice because callee
916  // saved register handling ensures the register value is restored before
917  // RET, but we need the undef flag here to appease the MachineVerifier
918  // liveness checks.
919  MachineInstrBuilder MIB =
920  BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::RET))
921  .addReg(AArch64::LR, RegState::Undef);
922  transferImpOps(MI, MIB, MIB);
923  MI.eraseFromParent();
924  return true;
925  }
926  case AArch64::CMP_SWAP_8:
927  return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRB, AArch64::STLXRB,
928  AArch64::SUBSWrx,
930  AArch64::WZR, NextMBBI);
931  case AArch64::CMP_SWAP_16:
932  return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRH, AArch64::STLXRH,
933  AArch64::SUBSWrx,
935  AArch64::WZR, NextMBBI);
936  case AArch64::CMP_SWAP_32:
937  return expandCMP_SWAP(MBB, MBBI, AArch64::LDAXRW, AArch64::STLXRW,
938  AArch64::SUBSWrs,
940  AArch64::WZR, NextMBBI);
941  case AArch64::CMP_SWAP_64:
942  return expandCMP_SWAP(MBB, MBBI,
943  AArch64::LDAXRX, AArch64::STLXRX, AArch64::SUBSXrs,
945  AArch64::XZR, NextMBBI);
946  case AArch64::CMP_SWAP_128:
947  return expandCMP_SWAP_128(MBB, MBBI, NextMBBI);
948 
949  case AArch64::AESMCrrTied:
950  case AArch64::AESIMCrrTied: {
951  MachineInstrBuilder MIB =
952  BuildMI(MBB, MBBI, MI.getDebugLoc(),
953  TII->get(Opcode == AArch64::AESMCrrTied ? AArch64::AESMCrr :
954  AArch64::AESIMCrr))
955  .add(MI.getOperand(0))
956  .add(MI.getOperand(1));
957  transferImpOps(MI, MIB, MIB);
958  MI.eraseFromParent();
959  return true;
960  }
961  }
962  return false;
963 }
964 
965 /// \brief Iterate over the instructions in basic block MBB and expand any
966 /// pseudo instructions. Return true if anything was modified.
967 bool AArch64ExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
968  bool Modified = false;
969 
970  MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
971  while (MBBI != E) {
972  MachineBasicBlock::iterator NMBBI = std::next(MBBI);
973  Modified |= expandMI(MBB, MBBI, NMBBI);
974  MBBI = NMBBI;
975  }
976 
977  return Modified;
978 }
979 
980 bool AArch64ExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
981  TII = static_cast<const AArch64InstrInfo *>(MF.getSubtarget().getInstrInfo());
982 
983  bool Modified = false;
984  for (auto &MBB : MF)
985  Modified |= expandMBB(MBB);
986  return Modified;
987 }
988 
989 /// \brief Returns an instance of the pseudo instruction expansion pass.
991  return new AArch64ExpandPseudo();
992 }
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const GlobalValue * getGlobal() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
MO_PAGE - A symbol operand with this flag represents the pc-relative offset of the 4K page containing...
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
DataLayout DL
bool isDead() const
static bool processLogicalImmediate(uint64_t Imm, unsigned RegSize, uint64_t &Encoding)
processLogicalImmediate - Determine if an immediate value can be encoded as the immediate operand of ...
const char * getSymbolName() const
A debug info location.
Definition: DebugLoc.h:34
static bool tryToreplicateChunks(uint64_t UImm, MachineInstr &MI, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const AArch64InstrInfo *TII)
Check for identical 16-bit chunks within the constant and if so materialize them with a single ORR in...
static bool canUseOrr(uint64_t Chunk, uint64_t &Encoding)
Check whether the given 16-bit chunk replicated to full 64-bit width can be materialized with an ORR ...
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
Definition: MathExtras.h:181
const Triple & getTargetTriple() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isUndef() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Definition: MathExtras.h:403
static uint64_t replicateChunk(uint64_t Imm, unsigned FromIdx, unsigned ToIdx)
Helper function which replicates a 16-bit chunk within a 64-bit value.
int64_t getImm() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
unsigned getKillRegState(bool B)
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
static uint64_t updateImm(uint64_t Imm, unsigned Idx, bool Clear)
Clear or set all bits in the chunk at the given index.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:279
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
unsigned getDeadRegState(bool B)
static bool isStartChunk(uint64_t Chunk)
Check whether this chunk matches the pattern '1...0...'.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getTargetFlags() const
void computeLiveIns(LivePhysRegs &LiveRegs, const MachineRegisterInfo &MRI, MachineBasicBlock &MBB)
Computes the live-in list for MBB assuming all of its successors live-in lists are up-to-date...
unsigned const MachineRegisterInfo * MRI
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
Definition: MathExtras.h:112
CodeModel::Model getCodeModel() const
Returns the code model.
void initializeAArch64ExpandPseudoPass(PassRegistry &)
MachineInstrBuilder & UseMI
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isOSFuchsia() const
Definition: Triple.h:482
static const unsigned End
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
INITIALIZE_PASS(AArch64ExpandPseudo,"aarch64-expand-pseudo", AARCH64_EXPAND_PSEUDO_NAME, false, false) static void transferImpOps(MachineInstr &OldMI
Transfer implicit operands on the pseudo instruction to the instructions created from the expansion...
int64_t getOffset() const
Return the offset from the symbol in this operand.
self_iterator getIterator()
Definition: ilist_node.h:82
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define E
Definition: LargeTest.cpp:27
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
static uint64_t getChunk(uint64_t Imm, unsigned ChunkIdx)
Helper function which extracts the specified 16-bit chunk from a 64-bit value.
MachineOperand class - Representation of each machine instruction operand.
FunctionPass * createAArch64ExpandPseudoPass()
Returns an instance of the pseudo instruction expansion pass.
static bool isEndChunk(uint64_t Chunk)
Check whether this chunk matches the pattern '0...1...' This pattern ends a contiguous sequence of on...
static bool trySequenceOfOnes(uint64_t UImm, MachineInstr &MI, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const AArch64InstrInfo *TII)
Check whether the constant contains a sequence of contiguous ones, which might be interrupted by one ...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:923
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:257
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
Representation of each machine instruction.
Definition: MachineInstr.h:59
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
Definition: LivePhysRegs.h:49
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned char TargetFlags=0) const
MO_PAGEOFF - A symbol operand with this flag represents the offset of that symbol within a 4K page...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
#define AARCH64_EXPAND_PSEUDO_NAME
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addUse(unsigned RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
virtual const TargetInstrInfo * getInstrInfo() const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Definition: MCInstrDesc.h:210
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
static bool tryOrrMovk(uint64_t UImm, uint64_t OrrImm, MachineInstr &MI, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const AArch64InstrInfo *TII, unsigned ChunkIdx)
Helper function which tries to materialize a 64-bit value with an ORR + MOVK instruction sequence...
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MO_NC - Indicates whether the linker is expected to check the symbol reference for overflow...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.