LLVM  10.0.0
VEInstrInfo.cpp
Go to the documentation of this file.
1 //===-- VEInstrInfo.cpp - VE Instruction Information ----------------------===//
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 the VE implementation of the TargetInstrInfo class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "VEInstrInfo.h"
14 #include "VE.h"
15 #include "VESubtarget.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Support/Debug.h"
26 
27 #define DEBUG_TYPE "ve"
28 
29 using namespace llvm;
30 
31 #define GET_INSTRINFO_CTOR_DTOR
32 #include "VEGenInstrInfo.inc"
33 
34 // Pin the vtable to this file.
35 void VEInstrInfo::anchor() {}
36 
38  : VEGenInstrInfo(VE::ADJCALLSTACKDOWN, VE::ADJCALLSTACKUP), RI(),
39  Subtarget(ST) {}
40 
42  switch (MI.getOpcode()) {
43  case VE::EXTEND_STACK: {
44  return expandExtendStackPseudo(MI);
45  }
46  case VE::EXTEND_STACK_GUARD: {
47  MI.eraseFromParent(); // The pseudo instruction is gone now.
48  return true;
49  }
50  }
51  return false;
52 }
53 
55  MachineBasicBlock &MBB = *MI.getParent();
56  MachineFunction &MF = *MBB.getParent();
57  const VEInstrInfo &TII =
58  *static_cast<const VEInstrInfo *>(MF.getSubtarget().getInstrInfo());
59  DebugLoc dl = MBB.findDebugLoc(MI);
60 
61  // Create following instructions and multiple basic blocks.
62  //
63  // thisBB:
64  // brge.l.t %sp, %sl, sinkBB
65  // syscallBB:
66  // ld %s61, 0x18(, %tp) // load param area
67  // or %s62, 0, %s0 // spill the value of %s0
68  // lea %s63, 0x13b // syscall # of grow
69  // shm.l %s63, 0x0(%s61) // store syscall # at addr:0
70  // shm.l %sl, 0x8(%s61) // store old limit at addr:8
71  // shm.l %sp, 0x10(%s61) // store new limit at addr:16
72  // monc // call monitor
73  // or %s0, 0, %s62 // restore the value of %s0
74  // sinkBB:
75 
76  // Create new MBB
77  MachineBasicBlock *BB = &MBB;
78  const BasicBlock *LLVM_BB = BB->getBasicBlock();
79  MachineBasicBlock *syscallMBB = MF.CreateMachineBasicBlock(LLVM_BB);
80  MachineBasicBlock *sinkMBB = MF.CreateMachineBasicBlock(LLVM_BB);
82  MF.insert(It, syscallMBB);
83  MF.insert(It, sinkMBB);
84 
85  // Transfer the remainder of BB and its successor edges to sinkMBB.
86  sinkMBB->splice(sinkMBB->begin(), BB,
87  std::next(std::next(MachineBasicBlock::iterator(MI))),
88  BB->end());
90 
91  // Next, add the true and fallthrough blocks as its successors.
92  BB->addSuccessor(syscallMBB);
93  BB->addSuccessor(sinkMBB);
94  BuildMI(BB, dl, TII.get(VE::BCRLrr))
95  .addImm(VECC::CC_IGE)
96  .addReg(VE::SX11) // %sp
97  .addReg(VE::SX8) // %sl
98  .addMBB(sinkMBB);
99 
100  BB = syscallMBB;
101 
102  // Update machine-CFG edges
103  BB->addSuccessor(sinkMBB);
104 
105  BuildMI(BB, dl, TII.get(VE::LDSri), VE::SX61)
106  .addReg(VE::SX14)
107  .addImm(0x18);
108  BuildMI(BB, dl, TII.get(VE::ORri), VE::SX62)
109  .addReg(VE::SX0)
110  .addImm(0);
111  BuildMI(BB, dl, TII.get(VE::LEAzzi), VE::SX63)
112  .addImm(0x13b);
113  BuildMI(BB, dl, TII.get(VE::SHMri))
114  .addReg(VE::SX61)
115  .addImm(0)
116  .addReg(VE::SX63);
117  BuildMI(BB, dl, TII.get(VE::SHMri))
118  .addReg(VE::SX61)
119  .addImm(8)
120  .addReg(VE::SX8);
121  BuildMI(BB, dl, TII.get(VE::SHMri))
122  .addReg(VE::SX61)
123  .addImm(16)
124  .addReg(VE::SX11);
125  BuildMI(BB, dl, TII.get(VE::MONC));
126 
127  BuildMI(BB, dl, TII.get(VE::ORri), VE::SX0)
128  .addReg(VE::SX62)
129  .addImm(0);
130 
131  MI.eraseFromParent(); // The pseudo instruction is gone now.
132  return true;
133 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
A debug info location.
Definition: DebugLoc.h:33
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const HexagonInstrInfo * TII
void eraseFromParent()
Unlink &#39;this&#39; from the containing basic block and delete it.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
virtual const TargetInstrInfo * getInstrInfo() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
self_iterator getIterator()
Definition: ilist_node.h:81
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:271
bool expandExtendStackPseudo(MachineInstr &MI) const
Definition: VEInstrInfo.cpp:54
Representation of each machine instruction.
Definition: MachineInstr.h:63
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB &#39;Other&#39; at the position From, and insert it into this MBB right before &#39;...
VEInstrInfo(VESubtarget &ST)
Definition: VEInstrInfo.cpp:37
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
void insert(iterator MBBI, MachineBasicBlock *MBB)
bool expandPostRAPseudo(MachineInstr &MI) const override
Definition: VEInstrInfo.cpp:41
IRTranslator LLVM IR MI
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.