blob: 30240d8d864458f66f0bc2b3153562c5c3417345 [file] [log] [blame]
Michael Gottesman3923bec2013-08-12 21:02:02 +00001//===-- SelectionDAGBuilder.h - Selection-DAG building --------*- C++ -*---===//
Dan Gohman575fad32008-09-03 16:12:24 +00002//
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 implements routines for translating from LLVM IR into SelectionDAG IR.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H
15#define LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H
Dan Gohman575fad32008-09-03 16:12:24 +000016
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "StatepointLowering.h"
Dan Gohman575fad32008-09-03 16:12:24 +000018#include "llvm/ADT/APInt.h"
19#include "llvm/ADT/DenseMap.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000020#include "llvm/CodeGen/SelectionDAG.h"
Dan Gohman575fad32008-09-03 16:12:24 +000021#include "llvm/CodeGen/SelectionDAGNodes.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000022#include "llvm/IR/CallSite.h"
Igor Laevsky7fc58a42015-02-20 15:28:35 +000023#include "llvm/IR/Statepoint.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/Constants.h"
Torok Edwin56d06592009-07-11 20:10:48 +000025#include "llvm/Support/ErrorHandling.h"
Juergen Ributzkafd4633e2014-10-16 21:26:35 +000026#include "llvm/Target/TargetLowering.h"
Dan Gohman575fad32008-09-03 16:12:24 +000027#include <vector>
Dan Gohman575fad32008-09-03 16:12:24 +000028
29namespace llvm {
30
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +000031class AddrSpaceCastInst;
Dan Gohman575fad32008-09-03 16:12:24 +000032class AliasAnalysis;
33class AllocaInst;
34class BasicBlock;
35class BitCastInst;
36class BranchInst;
37class CallInst;
Devang Patelb12ff592010-08-26 23:35:15 +000038class DbgValueInst;
Dan Gohman575fad32008-09-03 16:12:24 +000039class ExtractElementInst;
40class ExtractValueInst;
41class FCmpInst;
42class FPExtInst;
43class FPToSIInst;
44class FPToUIInst;
45class FPTruncInst;
Dan Gohman575fad32008-09-03 16:12:24 +000046class Function;
Dan Gohmana3624b62009-11-23 17:16:22 +000047class FunctionLoweringInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000048class GetElementPtrInst;
49class GCFunctionInfo;
50class ICmpInst;
51class IntToPtrInst;
Chris Lattnerd04cb6d2009-10-28 00:19:10 +000052class IndirectBrInst;
Dan Gohman575fad32008-09-03 16:12:24 +000053class InvokeInst;
54class InsertElementInst;
55class InsertValueInst;
56class Instruction;
57class LoadInst;
58class MachineBasicBlock;
Dan Gohman575fad32008-09-03 16:12:24 +000059class MachineInstr;
Dan Gohman575fad32008-09-03 16:12:24 +000060class MachineRegisterInfo;
Evan Cheng6e822452010-04-28 23:08:54 +000061class MDNode;
Patrik Hagglund1da35122014-03-12 08:00:24 +000062class MVT;
Dan Gohman575fad32008-09-03 16:12:24 +000063class PHINode;
64class PtrToIntInst;
65class ReturnInst;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000066class SDDbgValue;
Dan Gohman575fad32008-09-03 16:12:24 +000067class SExtInst;
68class SelectInst;
69class ShuffleVectorInst;
70class SIToFPInst;
71class StoreInst;
72class SwitchInst;
Micah Villmowcdfe20b2012-10-08 16:38:25 +000073class DataLayout;
Owen Andersonbb15fec2011-12-08 22:15:21 +000074class TargetLibraryInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000075class TargetLowering;
76class TruncInst;
77class UIToFPInst;
78class UnreachableInst;
Dan Gohman575fad32008-09-03 16:12:24 +000079class VAArgInst;
80class ZExtInst;
81
Dan Gohman575fad32008-09-03 16:12:24 +000082//===----------------------------------------------------------------------===//
Dan Gohman1a6c47f2009-11-23 18:04:58 +000083/// SelectionDAGBuilder - This is the common target-independent lowering
Dan Gohman575fad32008-09-03 16:12:24 +000084/// implementation that is parameterized by a TargetLowering object.
Dan Gohman575fad32008-09-03 16:12:24 +000085///
Benjamin Kramer079b96e2013-09-11 18:05:11 +000086class SelectionDAGBuilder {
Andrew Trick175143b2013-05-25 02:20:36 +000087 /// CurInst - The current instruction being visited
88 const Instruction *CurInst;
Dale Johannesendb7c5f62009-01-31 02:22:37 +000089
Dan Gohman575fad32008-09-03 16:12:24 +000090 DenseMap<const Value*, SDValue> NodeMap;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +000091
Devang Patelb0c76392010-06-01 19:59:01 +000092 /// UnusedArgNodeMap - Maps argument value for unused arguments. This is used
93 /// to preserve debug information for incoming arguments.
94 DenseMap<const Value*, SDValue> UnusedArgNodeMap;
Dan Gohman575fad32008-09-03 16:12:24 +000095
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000096 /// DanglingDebugInfo - Helper type for DanglingDebugInfoMap.
97 class DanglingDebugInfo {
Devang Patelb12ff592010-08-26 23:35:15 +000098 const DbgValueInst* DI;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000099 DebugLoc dl;
100 unsigned SDNodeOrder;
101 public:
Craig Topperada08572014-04-16 04:21:27 +0000102 DanglingDebugInfo() : DI(nullptr), dl(DebugLoc()), SDNodeOrder(0) { }
Devang Patelb12ff592010-08-26 23:35:15 +0000103 DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO) :
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000104 DI(di), dl(DL), SDNodeOrder(SDNO) { }
Devang Patelb12ff592010-08-26 23:35:15 +0000105 const DbgValueInst* getDI() { return DI; }
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000106 DebugLoc getdl() { return dl; }
107 unsigned getSDNodeOrder() { return SDNodeOrder; }
108 };
109
110 /// DanglingDebugInfoMap - Keeps track of dbg_values for which we have not
111 /// yet seen the referent. We defer handling these until we do see it.
112 DenseMap<const Value*, DanglingDebugInfo> DanglingDebugInfoMap;
113
Chris Lattner1a32ede2009-12-24 00:37:38 +0000114public:
Dan Gohman575fad32008-09-03 16:12:24 +0000115 /// PendingLoads - Loads are not emitted to the program immediately. We bunch
116 /// them up and then emit token factor nodes when possible. This allows us to
117 /// get simple disambiguation between loads without worrying about alias
118 /// analysis.
119 SmallVector<SDValue, 8> PendingLoads;
Philip Reames1a1bdb22014-12-02 18:50:36 +0000120
121 /// State used while lowering a statepoint sequence (gc_statepoint,
122 /// gc_relocate, and gc_result). See StatepointLowering.hpp/cpp for details.
123 StatepointLoweringState StatepointLowering;
Chris Lattner1a32ede2009-12-24 00:37:38 +0000124private:
Dan Gohman575fad32008-09-03 16:12:24 +0000125
126 /// PendingExports - CopyToReg nodes that copy values to virtual registers
127 /// for export to other blocks need to be emitted before any terminator
128 /// instruction, but they have no other ordering requirements. We bunch them
129 /// up and the emit a single tokenfactor for them just before terminator
130 /// instructions.
131 SmallVector<SDValue, 8> PendingExports;
132
Bill Wendling022d18f2009-12-18 23:32:53 +0000133 /// SDNodeOrder - A unique monotonically increasing number used to order the
134 /// SDNodes we create.
135 unsigned SDNodeOrder;
136
Dan Gohman575fad32008-09-03 16:12:24 +0000137 /// Case - A struct to record the Value for a switch case, and the
138 /// case's target basic block.
139 struct Case {
Hans Wennborg78325432015-03-19 16:42:21 +0000140 const ConstantInt *Low;
141 const ConstantInt *High;
Dan Gohman575fad32008-09-03 16:12:24 +0000142 MachineBasicBlock* BB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000143 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000144
Craig Topperada08572014-04-16 04:21:27 +0000145 Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { }
Hans Wennborg78325432015-03-19 16:42:21 +0000146 Case(const ConstantInt *low, const ConstantInt *high, MachineBasicBlock *bb,
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000147 uint32_t extraweight) : Low(low), High(high), BB(bb),
148 ExtraWeight(extraweight) { }
149
Chris Lattner8e1d7222009-11-07 07:50:34 +0000150 APInt size() const {
Hans Wennborg78325432015-03-19 16:42:21 +0000151 const APInt &rHigh = High->getValue();
152 const APInt &rLow = Low->getValue();
Dan Gohman575fad32008-09-03 16:12:24 +0000153 return (rHigh - rLow + 1ULL);
154 }
155 };
156
157 struct CaseBits {
158 uint64_t Mask;
159 MachineBasicBlock* BB;
160 unsigned Bits;
Manman Rencf104462012-08-24 18:14:27 +0000161 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000162
Manman Rencf104462012-08-24 18:14:27 +0000163 CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits,
164 uint32_t Weight):
165 Mask(mask), BB(bb), Bits(bits), ExtraWeight(Weight) { }
Dan Gohman575fad32008-09-03 16:12:24 +0000166 };
167
168 typedef std::vector<Case> CaseVector;
169 typedef std::vector<CaseBits> CaseBitsVector;
170 typedef CaseVector::iterator CaseItr;
171 typedef std::pair<CaseItr, CaseItr> CaseRange;
172
173 /// CaseRec - A struct with ctor used in lowering switches to a binary tree
174 /// of conditional branches.
175 struct CaseRec {
Hans Wennborg78325432015-03-19 16:42:21 +0000176 CaseRec(MachineBasicBlock *bb, const ConstantInt *lt, const ConstantInt *ge,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000177 CaseRange r) :
Dan Gohman575fad32008-09-03 16:12:24 +0000178 CaseBB(bb), LT(lt), GE(ge), Range(r) {}
179
180 /// CaseBB - The MBB in which to emit the compare and branch
181 MachineBasicBlock *CaseBB;
182 /// LT, GE - If nonzero, we know the current case value must be less-than or
183 /// greater-than-or-equal-to these Constants.
Hans Wennborg78325432015-03-19 16:42:21 +0000184 const ConstantInt *LT;
185 const ConstantInt *GE;
Dan Gohman575fad32008-09-03 16:12:24 +0000186 /// Range - A pair of iterators representing the range of case values to be
187 /// processed at this point in the binary search tree.
188 CaseRange Range;
189 };
190
191 typedef std::vector<CaseRec> CaseRecVector;
192
Dan Gohman575fad32008-09-03 16:12:24 +0000193 struct CaseBitsCmp {
Chris Lattner24576a52010-01-01 23:37:34 +0000194 bool operator()(const CaseBits &C1, const CaseBits &C2) {
Dan Gohman575fad32008-09-03 16:12:24 +0000195 return C1.Bits > C2.Bits;
196 }
197 };
198
Hans Wennborg077845e2015-03-20 00:41:03 +0000199 /// Populate Cases with the cases in SI, clustering adjacent cases with the
200 /// same destination together.
201 void Clusterify(CaseVector &Cases, const SwitchInst *SI);
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000202
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000203 /// CaseBlock - This structure is used to communicate between
204 /// SelectionDAGBuilder and SDISel for the code generation of additional basic
205 /// blocks needed by multi-case switch statements.
Dan Gohman575fad32008-09-03 16:12:24 +0000206 struct CaseBlock {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000207 CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
208 const Value *cmpmiddle,
Dan Gohman575fad32008-09-03 16:12:24 +0000209 MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000210 MachineBasicBlock *me,
211 uint32_t trueweight = 0, uint32_t falseweight = 0)
Dan Gohman575fad32008-09-03 16:12:24 +0000212 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000213 TrueBB(truebb), FalseBB(falsebb), ThisBB(me),
214 TrueWeight(trueweight), FalseWeight(falseweight) { }
215
Dan Gohman575fad32008-09-03 16:12:24 +0000216 // CC - the condition code to use for the case block's setcc node
217 ISD::CondCode CC;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000218
Dan Gohman575fad32008-09-03 16:12:24 +0000219 // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
220 // Emit by default LHS op RHS. MHS is used for range comparisons:
221 // If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000222 const Value *CmpLHS, *CmpMHS, *CmpRHS;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000223
Dan Gohman575fad32008-09-03 16:12:24 +0000224 // TrueBB/FalseBB - the block to branch to if the setcc is true/false.
225 MachineBasicBlock *TrueBB, *FalseBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000226
Dan Gohman575fad32008-09-03 16:12:24 +0000227 // ThisBB - the block into which to emit the code for the setcc and branches
228 MachineBasicBlock *ThisBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000229
230 // TrueWeight/FalseWeight - branch weights.
231 uint32_t TrueWeight, FalseWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000232 };
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000233
Dan Gohman575fad32008-09-03 16:12:24 +0000234 struct JumpTable {
235 JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
236 MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000237
Dan Gohman575fad32008-09-03 16:12:24 +0000238 /// Reg - the virtual register containing the index of the jump table entry
239 //. to jump to.
240 unsigned Reg;
241 /// JTI - the JumpTableIndex for this jump table in the function.
242 unsigned JTI;
243 /// MBB - the MBB into which to emit the code for the indirect jump.
244 MachineBasicBlock *MBB;
245 /// Default - the MBB of the default bb, which is a successor of the range
246 /// check MBB. This is when updating PHI nodes in successors.
247 MachineBasicBlock *Default;
248 };
249 struct JumpTableHeader {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000250 JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
Dan Gohman575fad32008-09-03 16:12:24 +0000251 bool E = false):
252 First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000253 APInt First;
254 APInt Last;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000255 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000256 MachineBasicBlock *HeaderBB;
257 bool Emitted;
258 };
259 typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock;
260
261 struct BitTestCase {
Manman Rencf104462012-08-24 18:14:27 +0000262 BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr,
263 uint32_t Weight):
264 Mask(M), ThisBB(T), TargetBB(Tr), ExtraWeight(Weight) { }
Dan Gohman575fad32008-09-03 16:12:24 +0000265 uint64_t Mask;
Chris Lattner24576a52010-01-01 23:37:34 +0000266 MachineBasicBlock *ThisBB;
267 MachineBasicBlock *TargetBB;
Manman Rencf104462012-08-24 18:14:27 +0000268 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000269 };
270
271 typedef SmallVector<BitTestCase, 3> BitTestInfo;
272
273 struct BitTestBlock {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000274 BitTestBlock(APInt F, APInt R, const Value* SV,
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000275 unsigned Rg, MVT RgVT, bool E,
Dan Gohman575fad32008-09-03 16:12:24 +0000276 MachineBasicBlock* P, MachineBasicBlock* D,
Benjamin Kramerc6cc58e2014-10-04 16:55:56 +0000277 BitTestInfo C):
Evan Chengac730dd2011-01-06 01:02:44 +0000278 First(F), Range(R), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E),
Benjamin Kramerc6cc58e2014-10-04 16:55:56 +0000279 Parent(P), Default(D), Cases(std::move(C)) { }
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000280 APInt First;
281 APInt Range;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000282 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000283 unsigned Reg;
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000284 MVT RegVT;
Dan Gohman575fad32008-09-03 16:12:24 +0000285 bool Emitted;
286 MachineBasicBlock *Parent;
287 MachineBasicBlock *Default;
288 BitTestInfo Cases;
289 };
290
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000291 /// A class which encapsulates all of the information needed to generate a
292 /// stack protector check and signals to isel via its state being initialized
293 /// that a stack protector needs to be generated.
294 ///
295 /// *NOTE* The following is a high level documentation of SelectionDAG Stack
296 /// Protector Generation. The reason that it is placed here is for a lack of
297 /// other good places to stick it.
298 ///
299 /// High Level Overview of SelectionDAG Stack Protector Generation:
300 ///
301 /// Previously, generation of stack protectors was done exclusively in the
302 /// pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
303 /// splitting basic blocks at the IR level to create the success/failure basic
304 /// blocks in the tail of the basic block in question. As a result of this,
305 /// calls that would have qualified for the sibling call optimization were no
306 /// longer eligible for optimization since said calls were no longer right in
307 /// the "tail position" (i.e. the immediate predecessor of a ReturnInst
308 /// instruction).
309 ///
310 /// Then it was noticed that since the sibling call optimization causes the
311 /// callee to reuse the caller's stack, if we could delay the generation of
312 /// the stack protector check until later in CodeGen after the sibling call
313 /// decision was made, we get both the tail call optimization and the stack
314 /// protector check!
315 ///
316 /// A few goals in solving this problem were:
317 ///
318 /// 1. Preserve the architecture independence of stack protector generation.
319 ///
320 /// 2. Preserve the normal IR level stack protector check for platforms like
Alp Tokercf218752014-06-30 18:57:16 +0000321 /// OpenBSD for which we support platform-specific stack protector
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000322 /// generation.
323 ///
324 /// The main problem that guided the present solution is that one can not
325 /// solve this problem in an architecture independent manner at the IR level
326 /// only. This is because:
327 ///
328 /// 1. The decision on whether or not to perform a sibling call on certain
329 /// platforms (for instance i386) requires lower level information
330 /// related to available registers that can not be known at the IR level.
331 ///
332 /// 2. Even if the previous point were not true, the decision on whether to
333 /// perform a tail call is done in LowerCallTo in SelectionDAG which
334 /// occurs after the Stack Protector Pass. As a result, one would need to
335 /// put the relevant callinst into the stack protector check success
336 /// basic block (where the return inst is placed) and then move it back
337 /// later at SelectionDAG/MI time before the stack protector check if the
338 /// tail call optimization failed. The MI level option was nixed
Alp Tokercf218752014-06-30 18:57:16 +0000339 /// immediately since it would require platform-specific pattern
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000340 /// matching. The SelectionDAG level option was nixed because
341 /// SelectionDAG only processes one IR level basic block at a time
342 /// implying one could not create a DAG Combine to move the callinst.
343 ///
344 /// To get around this problem a few things were realized:
345 ///
346 /// 1. While one can not handle multiple IR level basic blocks at the
347 /// SelectionDAG Level, one can generate multiple machine basic blocks
348 /// for one IR level basic block. This is how we handle bit tests and
349 /// switches.
350 ///
351 /// 2. At the MI level, tail calls are represented via a special return
352 /// MIInst called "tcreturn". Thus if we know the basic block in which we
353 /// wish to insert the stack protector check, we get the correct behavior
354 /// by always inserting the stack protector check right before the return
355 /// statement. This is a "magical transformation" since no matter where
356 /// the stack protector check intrinsic is, we always insert the stack
357 /// protector check code at the end of the BB.
358 ///
359 /// Given the aforementioned constraints, the following solution was devised:
360 ///
361 /// 1. On platforms that do not support SelectionDAG stack protector check
362 /// generation, allow for the normal IR level stack protector check
363 /// generation to continue.
364 ///
365 /// 2. On platforms that do support SelectionDAG stack protector check
366 /// generation:
367 ///
368 /// a. Use the IR level stack protector pass to decide if a stack
369 /// protector is required/which BB we insert the stack protector check
370 /// in by reusing the logic already therein. If we wish to generate a
371 /// stack protector check in a basic block, we place a special IR
372 /// intrinsic called llvm.stackprotectorcheck right before the BB's
373 /// returninst or if there is a callinst that could potentially be
374 /// sibling call optimized, before the call inst.
375 ///
376 /// b. Then when a BB with said intrinsic is processed, we codegen the BB
377 /// normally via SelectBasicBlock. In said process, when we visit the
378 /// stack protector check, we do not actually emit anything into the
379 /// BB. Instead, we just initialize the stack protector descriptor
380 /// class (which involves stashing information/creating the success
381 /// mbbb and the failure mbb if we have not created one for this
382 /// function yet) and export the guard variable that we are going to
383 /// compare.
384 ///
385 /// c. After we finish selecting the basic block, in FinishBasicBlock if
386 /// the StackProtectorDescriptor attached to the SelectionDAGBuilder is
387 /// initialized, we first find a splice point in the parent basic block
388 /// before the terminator and then splice the terminator of said basic
389 /// block into the success basic block. Then we code-gen a new tail for
390 /// the parent basic block consisting of the two loads, the comparison,
391 /// and finally two branches to the success/failure basic blocks. We
392 /// conclude by code-gening the failure basic block if we have not
393 /// code-gened it already (all stack protector checks we generate in
394 /// the same function, use the same failure basic block).
395 class StackProtectorDescriptor {
396 public:
Craig Topperada08572014-04-16 04:21:27 +0000397 StackProtectorDescriptor() : ParentMBB(nullptr), SuccessMBB(nullptr),
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000398 FailureMBB(nullptr), Guard(nullptr),
399 GuardReg(0) { }
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000400 ~StackProtectorDescriptor() { }
401
402 /// Returns true if all fields of the stack protector descriptor are
403 /// initialized implying that we should/are ready to emit a stack protector.
404 bool shouldEmitStackProtector() const {
405 return ParentMBB && SuccessMBB && FailureMBB && Guard;
406 }
407
408 /// Initialize the stack protector descriptor structure for a new basic
409 /// block.
410 void initialize(const BasicBlock *BB,
411 MachineBasicBlock *MBB,
412 const CallInst &StackProtCheckCall) {
413 // Make sure we are not initialized yet.
414 assert(!shouldEmitStackProtector() && "Stack Protector Descriptor is "
415 "already initialized!");
416 ParentMBB = MBB;
Akira Hatanakab9991a22014-12-01 04:27:03 +0000417 SuccessMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ true);
418 FailureMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ false, FailureMBB);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000419 if (!Guard)
420 Guard = StackProtCheckCall.getArgOperand(0);
421 }
422
423 /// Reset state that changes when we handle different basic blocks.
424 ///
425 /// This currently includes:
426 ///
427 /// 1. The specific basic block we are generating a
428 /// stack protector for (ParentMBB).
429 ///
430 /// 2. The successor machine basic block that will contain the tail of
431 /// parent mbb after we create the stack protector check (SuccessMBB). This
432 /// BB is visited only on stack protector check success.
433 void resetPerBBState() {
Craig Topperada08572014-04-16 04:21:27 +0000434 ParentMBB = nullptr;
435 SuccessMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000436 }
437
438 /// Reset state that only changes when we switch functions.
439 ///
440 /// This currently includes:
441 ///
442 /// 1. FailureMBB since we reuse the failure code path for all stack
443 /// protector checks created in an individual function.
444 ///
445 /// 2.The guard variable since the guard variable we are checking against is
446 /// always the same.
447 void resetPerFunctionState() {
Craig Topperada08572014-04-16 04:21:27 +0000448 FailureMBB = nullptr;
449 Guard = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000450 }
451
452 MachineBasicBlock *getParentMBB() { return ParentMBB; }
453 MachineBasicBlock *getSuccessMBB() { return SuccessMBB; }
454 MachineBasicBlock *getFailureMBB() { return FailureMBB; }
455 const Value *getGuard() { return Guard; }
456
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000457 unsigned getGuardReg() const { return GuardReg; }
458 void setGuardReg(unsigned R) { GuardReg = R; }
459
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000460 private:
461 /// The basic block for which we are generating the stack protector.
462 ///
463 /// As a result of stack protector generation, we will splice the
464 /// terminators of this basic block into the successor mbb SuccessMBB and
465 /// replace it with a compare/branch to the successor mbbs
466 /// SuccessMBB/FailureMBB depending on whether or not the stack protector
467 /// was violated.
468 MachineBasicBlock *ParentMBB;
469
470 /// A basic block visited on stack protector check success that contains the
471 /// terminators of ParentMBB.
472 MachineBasicBlock *SuccessMBB;
473
474 /// This basic block visited on stack protector check failure that will
475 /// contain a call to __stack_chk_fail().
476 MachineBasicBlock *FailureMBB;
477
478 /// The guard variable which we will compare against the stored value in the
479 /// stack protector stack slot.
480 const Value *Guard;
481
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000482 /// The virtual register holding the stack guard value.
483 unsigned GuardReg;
484
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000485 /// Add a successor machine basic block to ParentMBB. If the successor mbb
486 /// has not been created yet (i.e. if SuccMBB = 0), then the machine basic
Akira Hatanakab9991a22014-12-01 04:27:03 +0000487 /// block will be created. Assign a large weight if IsLikely is true.
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000488 MachineBasicBlock *AddSuccessorMBB(const BasicBlock *BB,
489 MachineBasicBlock *ParentMBB,
Akira Hatanakab9991a22014-12-01 04:27:03 +0000490 bool IsLikely,
Craig Topperada08572014-04-16 04:21:27 +0000491 MachineBasicBlock *SuccMBB = nullptr);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000492 };
493
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000494private:
Dan Gohmanc3349602010-04-19 19:05:59 +0000495 const TargetMachine &TM;
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000496public:
Nico Rieckb5262d62014-01-12 14:09:17 +0000497 /// Lowest valid SDNodeOrder. The special case 0 is reserved for scheduling
498 /// nodes without a corresponding SDNode.
499 static const unsigned LowestSDNodeOrder = 1;
500
Dan Gohman575fad32008-09-03 16:12:24 +0000501 SelectionDAG &DAG;
Rafael Espindola5f57f462014-02-21 18:34:28 +0000502 const DataLayout *DL;
Dan Gohman575fad32008-09-03 16:12:24 +0000503 AliasAnalysis *AA;
Owen Andersonbb15fec2011-12-08 22:15:21 +0000504 const TargetLibraryInfo *LibInfo;
Dan Gohman575fad32008-09-03 16:12:24 +0000505
506 /// SwitchCases - Vector of CaseBlock structures used to communicate
507 /// SwitchInst code generation information.
508 std::vector<CaseBlock> SwitchCases;
509 /// JTCases - Vector of JumpTable structures used to communicate
510 /// SwitchInst code generation information.
511 std::vector<JumpTableBlock> JTCases;
512 /// BitTestCases - Vector of BitTestBlock structures used to communicate
513 /// SwitchInst code generation information.
514 std::vector<BitTestBlock> BitTestCases;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000515 /// A StackProtectorDescriptor structure used to communicate stack protector
516 /// information in between SelectBasicBlock and FinishBasicBlock.
517 StackProtectorDescriptor SPDescriptor;
Evan Cheng270d0f92009-09-18 21:02:19 +0000518
Dan Gohman575fad32008-09-03 16:12:24 +0000519 // Emit PHI-node-operand constants only once even if used by multiple
520 // PHI nodes.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000521 DenseMap<const Constant *, unsigned> ConstantsOut;
Dan Gohman575fad32008-09-03 16:12:24 +0000522
523 /// FuncInfo - Information about the function as a whole.
524 ///
525 FunctionLoweringInfo &FuncInfo;
Bill Wendling19e0a5b2009-02-19 21:12:54 +0000526
Bill Wendling084669a2009-04-29 00:15:41 +0000527 /// OptLevel - What optimization level we're generating code for.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000528 ///
Bill Wendling026e5d72009-04-29 23:29:43 +0000529 CodeGenOpt::Level OptLevel;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000530
Dan Gohman575fad32008-09-03 16:12:24 +0000531 /// GFI - Garbage collection metadata for the function.
532 GCFunctionInfo *GFI;
533
Bill Wendling267f3232011-10-05 22:24:35 +0000534 /// LPadToCallSiteMap - Map a landing pad to the call site indexes.
535 DenseMap<MachineBasicBlock*, SmallVector<unsigned, 4> > LPadToCallSiteMap;
Bill Wendling3d11aa72011-10-04 22:00:35 +0000536
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000537 /// HasTailCall - This is set to true if a call in the current
538 /// block has been translated as a tail call. In this case,
539 /// no subsequent DAG nodes should be created.
540 ///
541 bool HasTailCall;
542
Owen Anderson53a52212009-07-13 04:09:18 +0000543 LLVMContext *Context;
544
Dan Gohmanc3349602010-04-19 19:05:59 +0000545 SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo,
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000546 CodeGenOpt::Level ol)
Craig Topperada08572014-04-16 04:21:27 +0000547 : CurInst(nullptr), SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()),
Dan Gohmanc3349602010-04-19 19:05:59 +0000548 DAG(dag), FuncInfo(funcinfo), OptLevel(ol),
Richard Smith3fb20472012-08-22 00:42:39 +0000549 HasTailCall(false) {
Dan Gohman575fad32008-09-03 16:12:24 +0000550 }
551
Owen Andersonbb15fec2011-12-08 22:15:21 +0000552 void init(GCFunctionInfo *gfi, AliasAnalysis &aa,
553 const TargetLibraryInfo *li);
Dan Gohman575fad32008-09-03 16:12:24 +0000554
Dan Gohmanf5cca352010-04-14 18:24:06 +0000555 /// clear - Clear out the current SelectionDAG and the associated
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000556 /// state and prepare this SelectionDAGBuilder object to be used
Dan Gohman575fad32008-09-03 16:12:24 +0000557 /// for a new block. This doesn't clear out information about
558 /// additional blocks that are needed to complete switch lowering
559 /// or PHI node updating; that information is cleared out as it is
560 /// consumed.
561 void clear();
562
Devang Patel799288382011-05-23 17:44:13 +0000563 /// clearDanglingDebugInfo - Clear the dangling debug information
Benjamin Kramerbde91762012-06-02 10:20:22 +0000564 /// map. This function is separated from the clear so that debug
Devang Patel799288382011-05-23 17:44:13 +0000565 /// information that is dangling in a basic block can be properly
566 /// resolved in a different basic block. This allows the
567 /// SelectionDAG to resolve dangling debug information attached
568 /// to PHI nodes.
569 void clearDanglingDebugInfo();
570
Dan Gohman575fad32008-09-03 16:12:24 +0000571 /// getRoot - Return the current virtual root of the Selection DAG,
572 /// flushing any PendingLoad items. This must be done before emitting
573 /// a store or any other node that may need to be ordered after any
574 /// prior load instructions.
575 ///
576 SDValue getRoot();
577
578 /// getControlRoot - Similar to getRoot, but instead of flushing all the
579 /// PendingLoad items, flush all the PendingExports items. It is necessary
580 /// to do this before emitting a terminator instruction.
581 ///
582 SDValue getControlRoot();
583
Andrew Trick175143b2013-05-25 02:20:36 +0000584 SDLoc getCurSDLoc() const {
Andrew Trick175143b2013-05-25 02:20:36 +0000585 return SDLoc(CurInst, SDNodeOrder);
586 }
587
588 DebugLoc getCurDebugLoc() const {
589 return CurInst ? CurInst->getDebugLoc() : DebugLoc();
590 }
Devang Patelf3292b22011-02-21 23:21:26 +0000591
Bill Wendling919b7aa2009-12-22 02:10:19 +0000592 unsigned getSDNodeOrder() const { return SDNodeOrder; }
593
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000594 void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
Dan Gohman575fad32008-09-03 16:12:24 +0000595
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000596 void visit(const Instruction &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000597
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000598 void visit(unsigned Opcode, const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000599
Igor Laevsky85f7f722015-03-10 16:26:48 +0000600 /// getCopyFromRegs - If there was virtual register allocated for the value V
601 /// emit CopyFromReg of the specified type Ty. Return empty SDValue() otherwise.
602 SDValue getCopyFromRegs(const Value *V, Type *Ty);
603
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000604 // resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V,
605 // generate the debug data structures now that we've seen its definition.
606 void resolveDanglingDebugInfo(const Value *V, SDValue Val);
Dan Gohman575fad32008-09-03 16:12:24 +0000607 SDValue getValue(const Value *V);
Dan Gohmand4322232010-07-01 01:59:43 +0000608 SDValue getNonRegisterValue(const Value *V);
609 SDValue getValueImpl(const Value *V);
Dan Gohman575fad32008-09-03 16:12:24 +0000610
611 void setValue(const Value *V, SDValue NewN) {
612 SDValue &N = NodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000613 assert(!N.getNode() && "Already set a value for this node!");
Dan Gohman575fad32008-09-03 16:12:24 +0000614 N = NewN;
615 }
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000616
Philip Reames1a1bdb22014-12-02 18:50:36 +0000617 void removeValue(const Value *V) {
618 // This is to support hack in lowerCallFromStatepoint
619 // Should be removed when hack is resolved
Benjamin Kramer4e3b9032015-02-27 21:43:14 +0000620 NodeMap.erase(V);
Philip Reames1a1bdb22014-12-02 18:50:36 +0000621 }
622
Devang Patelb0c76392010-06-01 19:59:01 +0000623 void setUnusedArgValue(const Value *V, SDValue NewN) {
624 SDValue &N = UnusedArgNodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000625 assert(!N.getNode() && "Already set a value for this node!");
Devang Patelb0c76392010-06-01 19:59:01 +0000626 N = NewN;
627 }
Dan Gohman575fad32008-09-03 16:12:24 +0000628
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000629 void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohman575fad32008-09-03 16:12:24 +0000630 MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000631 MachineBasicBlock *SwitchBB, unsigned Opc,
632 uint32_t TW, uint32_t FW);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000633 void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohmand01ddb52008-10-17 21:16:08 +0000634 MachineBasicBlock *FBB,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000635 MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000636 MachineBasicBlock *SwitchBB,
637 uint32_t TW, uint32_t FW);
Dan Gohman575fad32008-09-03 16:12:24 +0000638 bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000639 bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
640 void CopyToExportRegsIfNeeded(const Value *V);
641 void ExportFromCurrentBlock(const Value *V);
642 void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
Craig Topperada08572014-04-16 04:21:27 +0000643 MachineBasicBlock *LandingPad = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000644
Juergen Ributzkaad2363f2014-10-17 17:39:00 +0000645 std::pair<SDValue, SDValue> lowerCallOperands(
646 ImmutableCallSite CS,
647 unsigned ArgIdx,
648 unsigned NumArgs,
649 SDValue Callee,
650 bool UseVoidTy = false,
Hal Finkel0ad96c82015-01-13 17:48:04 +0000651 MachineBasicBlock *LandingPad = nullptr,
652 bool IsPatchPoint = false);
Andrew Trick74f4c742013-10-31 17:18:24 +0000653
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000654 /// UpdateSplitBlock - When an MBB was split during scheduling, update the
Alp Toker798060e2014-01-11 14:01:43 +0000655 /// references that need to refer to the last resulting block.
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000656 void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
657
Igor Laevsky7fc58a42015-02-20 15:28:35 +0000658 // This function is responsible for the whole statepoint lowering process.
Igor Laevsky85f7f722015-03-10 16:26:48 +0000659 // It uniformly handles invoke and call statepoints.
660 void LowerStatepoint(ImmutableStatepoint Statepoint,
661 MachineBasicBlock *LandingPad = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000662private:
Juergen Ributzkafd4633e2014-10-16 21:26:35 +0000663 std::pair<SDValue, SDValue> lowerInvokable(
664 TargetLowering::CallLoweringInfo &CLI,
665 MachineBasicBlock *LandingPad);
666
Dan Gohman575fad32008-09-03 16:12:24 +0000667 // Terminator instructions.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000668 void visitRet(const ReturnInst &I);
669 void visitBr(const BranchInst &I);
670 void visitSwitch(const SwitchInst &I);
671 void visitIndirectBr(const IndirectBrInst &I);
Yaron Kerend7ba46b2014-04-19 13:47:43 +0000672 void visitUnreachable(const UnreachableInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000673
674 // Helpers for visitSwitch
675 bool handleSmallSwitchRange(CaseRec& CR,
676 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000677 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000678 MachineBasicBlock* Default,
679 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000680 bool handleJTSwitchCase(CaseRec& CR,
681 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000682 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000683 MachineBasicBlock* Default,
684 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000685 bool handleBTSplitSwitchCase(CaseRec& CR,
686 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000687 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000688 MachineBasicBlock *SwitchBB);
Daniel Jasperd106b732015-01-20 08:57:44 +0000689 void splitSwitchCase(CaseRec &CR, CaseItr Pivot, CaseRecVector &WorkList,
690 const Value *SV, MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000691 bool handleBitTestsSwitchCase(CaseRec& CR,
692 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000693 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000694 MachineBasicBlock* Default,
695 MachineBasicBlock *SwitchBB);
Jakub Staszak12a43bd2011-06-16 20:22:37 +0000696
Jakub Staszak96f8c552011-12-20 20:03:10 +0000697 uint32_t getEdgeWeight(const MachineBasicBlock *Src,
698 const MachineBasicBlock *Dst) const;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000699 void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
700 uint32_t Weight = 0);
Dan Gohman575fad32008-09-03 16:12:24 +0000701public:
Dan Gohman7c0303a2010-04-19 22:41:47 +0000702 void visitSwitchCase(CaseBlock &CB,
703 MachineBasicBlock *SwitchBB);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000704 void visitSPDescriptorParent(StackProtectorDescriptor &SPD,
705 MachineBasicBlock *ParentBB);
706 void visitSPDescriptorFailure(StackProtectorDescriptor &SPD);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000707 void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB);
Evan Chengac730dd2011-01-06 01:02:44 +0000708 void visitBitTestCase(BitTestBlock &BB,
709 MachineBasicBlock* NextMBB,
Manman Rencf104462012-08-24 18:14:27 +0000710 uint32_t BranchWeightToNext,
Dan Gohman575fad32008-09-03 16:12:24 +0000711 unsigned Reg,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000712 BitTestCase &B,
713 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000714 void visitJumpTable(JumpTable &JT);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000715 void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH,
716 MachineBasicBlock *SwitchBB);
Reid Kleckner0a57f652015-01-14 01:05:27 +0000717 unsigned visitLandingPadClauseBB(GlobalValue *ClauseGV,
718 MachineBasicBlock *LPadMBB);
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000719
Dan Gohman575fad32008-09-03 16:12:24 +0000720private:
721 // These all get lowered before this pass.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000722 void visitInvoke(const InvokeInst &I);
Bill Wendlingf891bf82011-07-31 06:30:59 +0000723 void visitResume(const ResumeInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000724
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000725 void visitBinary(const User &I, unsigned OpCode);
726 void visitShift(const User &I, unsigned Opcode);
727 void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
728 void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
729 void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
730 void visitFSub(const User &I);
731 void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
732 void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
733 void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
734 void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
735 void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
736 void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
Benjamin Kramer9960a252011-07-08 10:31:30 +0000737 void visitSDiv(const User &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000738 void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
739 void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
740 void visitOr (const User &I) { visitBinary(I, ISD::OR); }
741 void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
742 void visitShl (const User &I) { visitShift(I, ISD::SHL); }
743 void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
744 void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
745 void visitICmp(const User &I);
746 void visitFCmp(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000747 // Visit the conversion instructions
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000748 void visitTrunc(const User &I);
749 void visitZExt(const User &I);
750 void visitSExt(const User &I);
751 void visitFPTrunc(const User &I);
752 void visitFPExt(const User &I);
753 void visitFPToUI(const User &I);
754 void visitFPToSI(const User &I);
755 void visitUIToFP(const User &I);
756 void visitSIToFP(const User &I);
757 void visitPtrToInt(const User &I);
758 void visitIntToPtr(const User &I);
759 void visitBitCast(const User &I);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000760 void visitAddrSpaceCast(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000761
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000762 void visitExtractElement(const User &I);
763 void visitInsertElement(const User &I);
764 void visitShuffleVector(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000765
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000766 void visitExtractValue(const ExtractValueInst &I);
767 void visitInsertValue(const InsertValueInst &I);
Bill Wendlingfae14752011-08-12 20:24:12 +0000768 void visitLandingPad(const LandingPadInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000769
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000770 void visitGetElementPtr(const User &I);
771 void visitSelect(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000772
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000773 void visitAlloca(const AllocaInst &I);
774 void visitLoad(const LoadInst &I);
775 void visitStore(const StoreInst &I);
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000776 void visitMaskedLoad(const CallInst &I);
777 void visitMaskedStore(const CallInst &I);
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000778 void visitAtomicCmpXchg(const AtomicCmpXchgInst &I);
779 void visitAtomicRMW(const AtomicRMWInst &I);
Eli Friedmanfee02c62011-07-25 23:16:38 +0000780 void visitFence(const FenceInst &I);
Dan Gohmanf41ad472010-04-20 15:00:41 +0000781 void visitPHI(const PHINode &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000782 void visitCall(const CallInst &I);
783 bool visitMemCmpCall(const CallInst &I);
Richard Sandiford6f6d5512013-08-20 09:38:48 +0000784 bool visitMemChrCall(const CallInst &I);
Richard Sandifordbb83a502013-08-16 11:29:37 +0000785 bool visitStrCpyCall(const CallInst &I, bool isStpcpy);
Richard Sandifordca232712013-08-16 11:21:54 +0000786 bool visitStrCmpCall(const CallInst &I);
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000787 bool visitStrLenCall(const CallInst &I);
788 bool visitStrNLenCall(const CallInst &I);
Bob Wilson874886c2012-08-03 23:29:17 +0000789 bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode);
Matt Arsenault7c936902014-10-21 23:01:01 +0000790 bool visitBinaryFloatCall(const CallInst &I, unsigned Opcode);
Eli Friedman342e8df2011-08-24 20:50:09 +0000791 void visitAtomicLoad(const LoadInst &I);
792 void visitAtomicStore(const StoreInst &I);
793
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000794 void visitInlineAsm(ImmutableCallSite CS);
795 const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
796 void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
Dan Gohman575fad32008-09-03 16:12:24 +0000797
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000798 void visitVAStart(const CallInst &I);
799 void visitVAArg(const VAArgInst &I);
800 void visitVAEnd(const CallInst &I);
801 void visitVACopy(const CallInst &I);
Andrew Trick74f4c742013-10-31 17:18:24 +0000802 void visitStackmap(const CallInst &I);
Juergen Ributzkaad2363f2014-10-17 17:39:00 +0000803 void visitPatchpoint(ImmutableCallSite CS,
804 MachineBasicBlock *LandingPad = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000805
Philip Reames1a1bdb22014-12-02 18:50:36 +0000806 // These three are implemented in StatepointLowering.cpp
807 void visitStatepoint(const CallInst &I);
808 void visitGCRelocate(const CallInst &I);
809 void visitGCResult(const CallInst &I);
810
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000811 void visitUserOp1(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000812 llvm_unreachable("UserOp1 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000813 }
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000814 void visitUserOp2(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000815 llvm_unreachable("UserOp2 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000816 }
Dan Gohman5b43aa02010-04-22 20:55:53 +0000817
Richard Sandiforde3827752013-08-16 10:55:47 +0000818 void processIntegerCallValue(const Instruction &I,
819 SDValue Value, bool IsSigned);
820
Dan Gohman5b43aa02010-04-22 20:55:53 +0000821 void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
Evan Cheng6e822452010-04-28 23:08:54 +0000822
Devang Patel32a72ab2010-08-25 20:41:24 +0000823 /// EmitFuncArgumentDbgValue - If V is an function argument then create
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000824 /// corresponding DBG_VALUE machine instruction for it now. At the end of
Devang Patel32a72ab2010-08-25 20:41:24 +0000825 /// instruction selection, they will be inserted to the entry BB.
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000826 bool EmitFuncArgumentDbgValue(const Value *V, MDNode *Variable, MDNode *Expr,
Adrian Prantl32da8892014-04-25 20:49:25 +0000827 int64_t Offset, bool IsIndirect,
828 const SDValue &N);
Hans Wennborgb4db1422015-03-19 20:41:48 +0000829
830 /// Return the next block after MBB, or nullptr if there is none.
831 MachineBasicBlock *NextBlock(MachineBasicBlock *MBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000832};
833
Dan Gohman575fad32008-09-03 16:12:24 +0000834} // end namespace llvm
835
836#endif