blob: b2215f22ab1c56b1525465409798d7591bdbf9fa [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
Dan Gohman575fad32008-09-03 16:12:24 +000017#include "llvm/ADT/APInt.h"
18#include "llvm/ADT/DenseMap.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000019#include "llvm/CodeGen/SelectionDAG.h"
Dan Gohman575fad32008-09-03 16:12:24 +000020#include "llvm/CodeGen/SelectionDAGNodes.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000021#include "llvm/IR/CallSite.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000022#include "llvm/IR/Constants.h"
Torok Edwin56d06592009-07-11 20:10:48 +000023#include "llvm/Support/ErrorHandling.h"
Juergen Ributzkafd4633e2014-10-16 21:26:35 +000024#include "llvm/Target/TargetLowering.h"
Dan Gohman575fad32008-09-03 16:12:24 +000025#include <vector>
Dan Gohman575fad32008-09-03 16:12:24 +000026
27namespace llvm {
28
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +000029class AddrSpaceCastInst;
Dan Gohman575fad32008-09-03 16:12:24 +000030class AliasAnalysis;
31class AllocaInst;
32class BasicBlock;
33class BitCastInst;
34class BranchInst;
35class CallInst;
Devang Patelb12ff592010-08-26 23:35:15 +000036class DbgValueInst;
Dan Gohman575fad32008-09-03 16:12:24 +000037class ExtractElementInst;
38class ExtractValueInst;
39class FCmpInst;
40class FPExtInst;
41class FPToSIInst;
42class FPToUIInst;
43class FPTruncInst;
Dan Gohman575fad32008-09-03 16:12:24 +000044class Function;
Dan Gohmana3624b62009-11-23 17:16:22 +000045class FunctionLoweringInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000046class GetElementPtrInst;
47class GCFunctionInfo;
48class ICmpInst;
49class IntToPtrInst;
Chris Lattnerd04cb6d2009-10-28 00:19:10 +000050class IndirectBrInst;
Dan Gohman575fad32008-09-03 16:12:24 +000051class InvokeInst;
52class InsertElementInst;
53class InsertValueInst;
54class Instruction;
55class LoadInst;
56class MachineBasicBlock;
Dan Gohman575fad32008-09-03 16:12:24 +000057class MachineInstr;
Dan Gohman575fad32008-09-03 16:12:24 +000058class MachineRegisterInfo;
Evan Cheng6e822452010-04-28 23:08:54 +000059class MDNode;
Patrik Hagglund1da35122014-03-12 08:00:24 +000060class MVT;
Dan Gohman575fad32008-09-03 16:12:24 +000061class PHINode;
62class PtrToIntInst;
63class ReturnInst;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000064class SDDbgValue;
Dan Gohman575fad32008-09-03 16:12:24 +000065class SExtInst;
66class SelectInst;
67class ShuffleVectorInst;
68class SIToFPInst;
69class StoreInst;
70class SwitchInst;
Micah Villmowcdfe20b2012-10-08 16:38:25 +000071class DataLayout;
Owen Andersonbb15fec2011-12-08 22:15:21 +000072class TargetLibraryInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000073class TargetLowering;
74class TruncInst;
75class UIToFPInst;
76class UnreachableInst;
Dan Gohman575fad32008-09-03 16:12:24 +000077class VAArgInst;
78class ZExtInst;
79
Dan Gohman575fad32008-09-03 16:12:24 +000080//===----------------------------------------------------------------------===//
Dan Gohman1a6c47f2009-11-23 18:04:58 +000081/// SelectionDAGBuilder - This is the common target-independent lowering
Dan Gohman575fad32008-09-03 16:12:24 +000082/// implementation that is parameterized by a TargetLowering object.
Dan Gohman575fad32008-09-03 16:12:24 +000083///
Benjamin Kramer079b96e2013-09-11 18:05:11 +000084class SelectionDAGBuilder {
Andrew Trick175143b2013-05-25 02:20:36 +000085 /// CurInst - The current instruction being visited
86 const Instruction *CurInst;
Dale Johannesendb7c5f62009-01-31 02:22:37 +000087
Dan Gohman575fad32008-09-03 16:12:24 +000088 DenseMap<const Value*, SDValue> NodeMap;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +000089
Devang Patelb0c76392010-06-01 19:59:01 +000090 /// UnusedArgNodeMap - Maps argument value for unused arguments. This is used
91 /// to preserve debug information for incoming arguments.
92 DenseMap<const Value*, SDValue> UnusedArgNodeMap;
Dan Gohman575fad32008-09-03 16:12:24 +000093
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000094 /// DanglingDebugInfo - Helper type for DanglingDebugInfoMap.
95 class DanglingDebugInfo {
Devang Patelb12ff592010-08-26 23:35:15 +000096 const DbgValueInst* DI;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000097 DebugLoc dl;
98 unsigned SDNodeOrder;
99 public:
Craig Topperada08572014-04-16 04:21:27 +0000100 DanglingDebugInfo() : DI(nullptr), dl(DebugLoc()), SDNodeOrder(0) { }
Devang Patelb12ff592010-08-26 23:35:15 +0000101 DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO) :
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000102 DI(di), dl(DL), SDNodeOrder(SDNO) { }
Devang Patelb12ff592010-08-26 23:35:15 +0000103 const DbgValueInst* getDI() { return DI; }
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000104 DebugLoc getdl() { return dl; }
105 unsigned getSDNodeOrder() { return SDNodeOrder; }
106 };
107
108 /// DanglingDebugInfoMap - Keeps track of dbg_values for which we have not
109 /// yet seen the referent. We defer handling these until we do see it.
110 DenseMap<const Value*, DanglingDebugInfo> DanglingDebugInfoMap;
111
Chris Lattner1a32ede2009-12-24 00:37:38 +0000112public:
Dan Gohman575fad32008-09-03 16:12:24 +0000113 /// PendingLoads - Loads are not emitted to the program immediately. We bunch
114 /// them up and then emit token factor nodes when possible. This allows us to
115 /// get simple disambiguation between loads without worrying about alias
116 /// analysis.
117 SmallVector<SDValue, 8> PendingLoads;
Chris Lattner1a32ede2009-12-24 00:37:38 +0000118private:
Dan Gohman575fad32008-09-03 16:12:24 +0000119
120 /// PendingExports - CopyToReg nodes that copy values to virtual registers
121 /// for export to other blocks need to be emitted before any terminator
122 /// instruction, but they have no other ordering requirements. We bunch them
123 /// up and the emit a single tokenfactor for them just before terminator
124 /// instructions.
125 SmallVector<SDValue, 8> PendingExports;
126
Bill Wendling022d18f2009-12-18 23:32:53 +0000127 /// SDNodeOrder - A unique monotonically increasing number used to order the
128 /// SDNodes we create.
129 unsigned SDNodeOrder;
130
Dan Gohman575fad32008-09-03 16:12:24 +0000131 /// Case - A struct to record the Value for a switch case, and the
132 /// case's target basic block.
133 struct Case {
Stepan Dyatkovskiy513aaa52012-02-01 07:49:51 +0000134 const Constant *Low;
135 const Constant *High;
Dan Gohman575fad32008-09-03 16:12:24 +0000136 MachineBasicBlock* BB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000137 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000138
Craig Topperada08572014-04-16 04:21:27 +0000139 Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { }
Stepan Dyatkovskiy513aaa52012-02-01 07:49:51 +0000140 Case(const Constant *low, const Constant *high, MachineBasicBlock *bb,
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000141 uint32_t extraweight) : Low(low), High(high), BB(bb),
142 ExtraWeight(extraweight) { }
143
Chris Lattner8e1d7222009-11-07 07:50:34 +0000144 APInt size() const {
145 const APInt &rHigh = cast<ConstantInt>(High)->getValue();
146 const APInt &rLow = cast<ConstantInt>(Low)->getValue();
Dan Gohman575fad32008-09-03 16:12:24 +0000147 return (rHigh - rLow + 1ULL);
148 }
149 };
150
151 struct CaseBits {
152 uint64_t Mask;
153 MachineBasicBlock* BB;
154 unsigned Bits;
Manman Rencf104462012-08-24 18:14:27 +0000155 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000156
Manman Rencf104462012-08-24 18:14:27 +0000157 CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits,
158 uint32_t Weight):
159 Mask(mask), BB(bb), Bits(bits), ExtraWeight(Weight) { }
Dan Gohman575fad32008-09-03 16:12:24 +0000160 };
161
162 typedef std::vector<Case> CaseVector;
163 typedef std::vector<CaseBits> CaseBitsVector;
164 typedef CaseVector::iterator CaseItr;
165 typedef std::pair<CaseItr, CaseItr> CaseRange;
166
167 /// CaseRec - A struct with ctor used in lowering switches to a binary tree
168 /// of conditional branches.
169 struct CaseRec {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000170 CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
171 CaseRange r) :
Dan Gohman575fad32008-09-03 16:12:24 +0000172 CaseBB(bb), LT(lt), GE(ge), Range(r) {}
173
174 /// CaseBB - The MBB in which to emit the compare and branch
175 MachineBasicBlock *CaseBB;
176 /// LT, GE - If nonzero, we know the current case value must be less-than or
177 /// greater-than-or-equal-to these Constants.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000178 const Constant *LT;
179 const Constant *GE;
Dan Gohman575fad32008-09-03 16:12:24 +0000180 /// Range - A pair of iterators representing the range of case values to be
181 /// processed at this point in the binary search tree.
182 CaseRange Range;
183 };
184
185 typedef std::vector<CaseRec> CaseRecVector;
186
Bob Wilsone4077362013-09-09 19:14:35 +0000187 /// The comparison function for sorting the switch case values in the vector.
188 /// WARNING: Case ranges should be disjoint!
189 struct CaseCmp {
190 bool operator()(const Case &C1, const Case &C2) {
191 assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High));
192 const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
193 const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
194 return CI1->getValue().slt(CI2->getValue());
195 }
196 };
197
Dan Gohman575fad32008-09-03 16:12:24 +0000198 struct CaseBitsCmp {
Chris Lattner24576a52010-01-01 23:37:34 +0000199 bool operator()(const CaseBits &C1, const CaseBits &C2) {
Dan Gohman575fad32008-09-03 16:12:24 +0000200 return C1.Bits > C2.Bits;
201 }
202 };
203
Chad Rosierdf82a332014-10-13 19:46:39 +0000204 void Clusterify(CaseVector &Cases, const SwitchInst &SI);
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000205
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000206 /// CaseBlock - This structure is used to communicate between
207 /// SelectionDAGBuilder and SDISel for the code generation of additional basic
208 /// blocks needed by multi-case switch statements.
Dan Gohman575fad32008-09-03 16:12:24 +0000209 struct CaseBlock {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000210 CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
211 const Value *cmpmiddle,
Dan Gohman575fad32008-09-03 16:12:24 +0000212 MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000213 MachineBasicBlock *me,
214 uint32_t trueweight = 0, uint32_t falseweight = 0)
Dan Gohman575fad32008-09-03 16:12:24 +0000215 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000216 TrueBB(truebb), FalseBB(falsebb), ThisBB(me),
217 TrueWeight(trueweight), FalseWeight(falseweight) { }
218
Dan Gohman575fad32008-09-03 16:12:24 +0000219 // CC - the condition code to use for the case block's setcc node
220 ISD::CondCode CC;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000221
Dan Gohman575fad32008-09-03 16:12:24 +0000222 // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
223 // Emit by default LHS op RHS. MHS is used for range comparisons:
224 // If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000225 const Value *CmpLHS, *CmpMHS, *CmpRHS;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000226
Dan Gohman575fad32008-09-03 16:12:24 +0000227 // TrueBB/FalseBB - the block to branch to if the setcc is true/false.
228 MachineBasicBlock *TrueBB, *FalseBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000229
Dan Gohman575fad32008-09-03 16:12:24 +0000230 // ThisBB - the block into which to emit the code for the setcc and branches
231 MachineBasicBlock *ThisBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000232
233 // TrueWeight/FalseWeight - branch weights.
234 uint32_t TrueWeight, FalseWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000235 };
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000236
Dan Gohman575fad32008-09-03 16:12:24 +0000237 struct JumpTable {
238 JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
239 MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000240
Dan Gohman575fad32008-09-03 16:12:24 +0000241 /// Reg - the virtual register containing the index of the jump table entry
242 //. to jump to.
243 unsigned Reg;
244 /// JTI - the JumpTableIndex for this jump table in the function.
245 unsigned JTI;
246 /// MBB - the MBB into which to emit the code for the indirect jump.
247 MachineBasicBlock *MBB;
248 /// Default - the MBB of the default bb, which is a successor of the range
249 /// check MBB. This is when updating PHI nodes in successors.
250 MachineBasicBlock *Default;
251 };
252 struct JumpTableHeader {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000253 JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
Dan Gohman575fad32008-09-03 16:12:24 +0000254 bool E = false):
255 First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000256 APInt First;
257 APInt Last;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000258 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000259 MachineBasicBlock *HeaderBB;
260 bool Emitted;
261 };
262 typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock;
263
264 struct BitTestCase {
Manman Rencf104462012-08-24 18:14:27 +0000265 BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr,
266 uint32_t Weight):
267 Mask(M), ThisBB(T), TargetBB(Tr), ExtraWeight(Weight) { }
Dan Gohman575fad32008-09-03 16:12:24 +0000268 uint64_t Mask;
Chris Lattner24576a52010-01-01 23:37:34 +0000269 MachineBasicBlock *ThisBB;
270 MachineBasicBlock *TargetBB;
Manman Rencf104462012-08-24 18:14:27 +0000271 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000272 };
273
274 typedef SmallVector<BitTestCase, 3> BitTestInfo;
275
276 struct BitTestBlock {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000277 BitTestBlock(APInt F, APInt R, const Value* SV,
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000278 unsigned Rg, MVT RgVT, bool E,
Dan Gohman575fad32008-09-03 16:12:24 +0000279 MachineBasicBlock* P, MachineBasicBlock* D,
Benjamin Kramerc6cc58e2014-10-04 16:55:56 +0000280 BitTestInfo C):
Evan Chengac730dd2011-01-06 01:02:44 +0000281 First(F), Range(R), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E),
Benjamin Kramerc6cc58e2014-10-04 16:55:56 +0000282 Parent(P), Default(D), Cases(std::move(C)) { }
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000283 APInt First;
284 APInt Range;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000285 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000286 unsigned Reg;
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000287 MVT RegVT;
Dan Gohman575fad32008-09-03 16:12:24 +0000288 bool Emitted;
289 MachineBasicBlock *Parent;
290 MachineBasicBlock *Default;
291 BitTestInfo Cases;
292 };
293
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000294 /// A class which encapsulates all of the information needed to generate a
295 /// stack protector check and signals to isel via its state being initialized
296 /// that a stack protector needs to be generated.
297 ///
298 /// *NOTE* The following is a high level documentation of SelectionDAG Stack
299 /// Protector Generation. The reason that it is placed here is for a lack of
300 /// other good places to stick it.
301 ///
302 /// High Level Overview of SelectionDAG Stack Protector Generation:
303 ///
304 /// Previously, generation of stack protectors was done exclusively in the
305 /// pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
306 /// splitting basic blocks at the IR level to create the success/failure basic
307 /// blocks in the tail of the basic block in question. As a result of this,
308 /// calls that would have qualified for the sibling call optimization were no
309 /// longer eligible for optimization since said calls were no longer right in
310 /// the "tail position" (i.e. the immediate predecessor of a ReturnInst
311 /// instruction).
312 ///
313 /// Then it was noticed that since the sibling call optimization causes the
314 /// callee to reuse the caller's stack, if we could delay the generation of
315 /// the stack protector check until later in CodeGen after the sibling call
316 /// decision was made, we get both the tail call optimization and the stack
317 /// protector check!
318 ///
319 /// A few goals in solving this problem were:
320 ///
321 /// 1. Preserve the architecture independence of stack protector generation.
322 ///
323 /// 2. Preserve the normal IR level stack protector check for platforms like
Alp Tokercf218752014-06-30 18:57:16 +0000324 /// OpenBSD for which we support platform-specific stack protector
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000325 /// generation.
326 ///
327 /// The main problem that guided the present solution is that one can not
328 /// solve this problem in an architecture independent manner at the IR level
329 /// only. This is because:
330 ///
331 /// 1. The decision on whether or not to perform a sibling call on certain
332 /// platforms (for instance i386) requires lower level information
333 /// related to available registers that can not be known at the IR level.
334 ///
335 /// 2. Even if the previous point were not true, the decision on whether to
336 /// perform a tail call is done in LowerCallTo in SelectionDAG which
337 /// occurs after the Stack Protector Pass. As a result, one would need to
338 /// put the relevant callinst into the stack protector check success
339 /// basic block (where the return inst is placed) and then move it back
340 /// later at SelectionDAG/MI time before the stack protector check if the
341 /// tail call optimization failed. The MI level option was nixed
Alp Tokercf218752014-06-30 18:57:16 +0000342 /// immediately since it would require platform-specific pattern
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000343 /// matching. The SelectionDAG level option was nixed because
344 /// SelectionDAG only processes one IR level basic block at a time
345 /// implying one could not create a DAG Combine to move the callinst.
346 ///
347 /// To get around this problem a few things were realized:
348 ///
349 /// 1. While one can not handle multiple IR level basic blocks at the
350 /// SelectionDAG Level, one can generate multiple machine basic blocks
351 /// for one IR level basic block. This is how we handle bit tests and
352 /// switches.
353 ///
354 /// 2. At the MI level, tail calls are represented via a special return
355 /// MIInst called "tcreturn". Thus if we know the basic block in which we
356 /// wish to insert the stack protector check, we get the correct behavior
357 /// by always inserting the stack protector check right before the return
358 /// statement. This is a "magical transformation" since no matter where
359 /// the stack protector check intrinsic is, we always insert the stack
360 /// protector check code at the end of the BB.
361 ///
362 /// Given the aforementioned constraints, the following solution was devised:
363 ///
364 /// 1. On platforms that do not support SelectionDAG stack protector check
365 /// generation, allow for the normal IR level stack protector check
366 /// generation to continue.
367 ///
368 /// 2. On platforms that do support SelectionDAG stack protector check
369 /// generation:
370 ///
371 /// a. Use the IR level stack protector pass to decide if a stack
372 /// protector is required/which BB we insert the stack protector check
373 /// in by reusing the logic already therein. If we wish to generate a
374 /// stack protector check in a basic block, we place a special IR
375 /// intrinsic called llvm.stackprotectorcheck right before the BB's
376 /// returninst or if there is a callinst that could potentially be
377 /// sibling call optimized, before the call inst.
378 ///
379 /// b. Then when a BB with said intrinsic is processed, we codegen the BB
380 /// normally via SelectBasicBlock. In said process, when we visit the
381 /// stack protector check, we do not actually emit anything into the
382 /// BB. Instead, we just initialize the stack protector descriptor
383 /// class (which involves stashing information/creating the success
384 /// mbbb and the failure mbb if we have not created one for this
385 /// function yet) and export the guard variable that we are going to
386 /// compare.
387 ///
388 /// c. After we finish selecting the basic block, in FinishBasicBlock if
389 /// the StackProtectorDescriptor attached to the SelectionDAGBuilder is
390 /// initialized, we first find a splice point in the parent basic block
391 /// before the terminator and then splice the terminator of said basic
392 /// block into the success basic block. Then we code-gen a new tail for
393 /// the parent basic block consisting of the two loads, the comparison,
394 /// and finally two branches to the success/failure basic blocks. We
395 /// conclude by code-gening the failure basic block if we have not
396 /// code-gened it already (all stack protector checks we generate in
397 /// the same function, use the same failure basic block).
398 class StackProtectorDescriptor {
399 public:
Craig Topperada08572014-04-16 04:21:27 +0000400 StackProtectorDescriptor() : ParentMBB(nullptr), SuccessMBB(nullptr),
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000401 FailureMBB(nullptr), Guard(nullptr),
402 GuardReg(0) { }
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000403 ~StackProtectorDescriptor() { }
404
405 /// Returns true if all fields of the stack protector descriptor are
406 /// initialized implying that we should/are ready to emit a stack protector.
407 bool shouldEmitStackProtector() const {
408 return ParentMBB && SuccessMBB && FailureMBB && Guard;
409 }
410
411 /// Initialize the stack protector descriptor structure for a new basic
412 /// block.
413 void initialize(const BasicBlock *BB,
414 MachineBasicBlock *MBB,
415 const CallInst &StackProtCheckCall) {
416 // Make sure we are not initialized yet.
417 assert(!shouldEmitStackProtector() && "Stack Protector Descriptor is "
418 "already initialized!");
419 ParentMBB = MBB;
Akira Hatanakab9991a22014-12-01 04:27:03 +0000420 SuccessMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ true);
421 FailureMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ false, FailureMBB);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000422 if (!Guard)
423 Guard = StackProtCheckCall.getArgOperand(0);
424 }
425
426 /// Reset state that changes when we handle different basic blocks.
427 ///
428 /// This currently includes:
429 ///
430 /// 1. The specific basic block we are generating a
431 /// stack protector for (ParentMBB).
432 ///
433 /// 2. The successor machine basic block that will contain the tail of
434 /// parent mbb after we create the stack protector check (SuccessMBB). This
435 /// BB is visited only on stack protector check success.
436 void resetPerBBState() {
Craig Topperada08572014-04-16 04:21:27 +0000437 ParentMBB = nullptr;
438 SuccessMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000439 }
440
441 /// Reset state that only changes when we switch functions.
442 ///
443 /// This currently includes:
444 ///
445 /// 1. FailureMBB since we reuse the failure code path for all stack
446 /// protector checks created in an individual function.
447 ///
448 /// 2.The guard variable since the guard variable we are checking against is
449 /// always the same.
450 void resetPerFunctionState() {
Craig Topperada08572014-04-16 04:21:27 +0000451 FailureMBB = nullptr;
452 Guard = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000453 }
454
455 MachineBasicBlock *getParentMBB() { return ParentMBB; }
456 MachineBasicBlock *getSuccessMBB() { return SuccessMBB; }
457 MachineBasicBlock *getFailureMBB() { return FailureMBB; }
458 const Value *getGuard() { return Guard; }
459
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000460 unsigned getGuardReg() const { return GuardReg; }
461 void setGuardReg(unsigned R) { GuardReg = R; }
462
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000463 private:
464 /// The basic block for which we are generating the stack protector.
465 ///
466 /// As a result of stack protector generation, we will splice the
467 /// terminators of this basic block into the successor mbb SuccessMBB and
468 /// replace it with a compare/branch to the successor mbbs
469 /// SuccessMBB/FailureMBB depending on whether or not the stack protector
470 /// was violated.
471 MachineBasicBlock *ParentMBB;
472
473 /// A basic block visited on stack protector check success that contains the
474 /// terminators of ParentMBB.
475 MachineBasicBlock *SuccessMBB;
476
477 /// This basic block visited on stack protector check failure that will
478 /// contain a call to __stack_chk_fail().
479 MachineBasicBlock *FailureMBB;
480
481 /// The guard variable which we will compare against the stored value in the
482 /// stack protector stack slot.
483 const Value *Guard;
484
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000485 /// The virtual register holding the stack guard value.
486 unsigned GuardReg;
487
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000488 /// Add a successor machine basic block to ParentMBB. If the successor mbb
489 /// has not been created yet (i.e. if SuccMBB = 0), then the machine basic
Akira Hatanakab9991a22014-12-01 04:27:03 +0000490 /// block will be created. Assign a large weight if IsLikely is true.
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000491 MachineBasicBlock *AddSuccessorMBB(const BasicBlock *BB,
492 MachineBasicBlock *ParentMBB,
Akira Hatanakab9991a22014-12-01 04:27:03 +0000493 bool IsLikely,
Craig Topperada08572014-04-16 04:21:27 +0000494 MachineBasicBlock *SuccMBB = nullptr);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000495 };
496
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000497private:
Dan Gohmanc3349602010-04-19 19:05:59 +0000498 const TargetMachine &TM;
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000499public:
Nico Rieckb5262d62014-01-12 14:09:17 +0000500 /// Lowest valid SDNodeOrder. The special case 0 is reserved for scheduling
501 /// nodes without a corresponding SDNode.
502 static const unsigned LowestSDNodeOrder = 1;
503
Dan Gohman575fad32008-09-03 16:12:24 +0000504 SelectionDAG &DAG;
Rafael Espindola5f57f462014-02-21 18:34:28 +0000505 const DataLayout *DL;
Dan Gohman575fad32008-09-03 16:12:24 +0000506 AliasAnalysis *AA;
Owen Andersonbb15fec2011-12-08 22:15:21 +0000507 const TargetLibraryInfo *LibInfo;
Dan Gohman575fad32008-09-03 16:12:24 +0000508
509 /// SwitchCases - Vector of CaseBlock structures used to communicate
510 /// SwitchInst code generation information.
511 std::vector<CaseBlock> SwitchCases;
512 /// JTCases - Vector of JumpTable structures used to communicate
513 /// SwitchInst code generation information.
514 std::vector<JumpTableBlock> JTCases;
515 /// BitTestCases - Vector of BitTestBlock structures used to communicate
516 /// SwitchInst code generation information.
517 std::vector<BitTestBlock> BitTestCases;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000518 /// A StackProtectorDescriptor structure used to communicate stack protector
519 /// information in between SelectBasicBlock and FinishBasicBlock.
520 StackProtectorDescriptor SPDescriptor;
Evan Cheng270d0f92009-09-18 21:02:19 +0000521
Dan Gohman575fad32008-09-03 16:12:24 +0000522 // Emit PHI-node-operand constants only once even if used by multiple
523 // PHI nodes.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000524 DenseMap<const Constant *, unsigned> ConstantsOut;
Dan Gohman575fad32008-09-03 16:12:24 +0000525
526 /// FuncInfo - Information about the function as a whole.
527 ///
528 FunctionLoweringInfo &FuncInfo;
Bill Wendling19e0a5b2009-02-19 21:12:54 +0000529
Bill Wendling084669a2009-04-29 00:15:41 +0000530 /// OptLevel - What optimization level we're generating code for.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000531 ///
Bill Wendling026e5d72009-04-29 23:29:43 +0000532 CodeGenOpt::Level OptLevel;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000533
Dan Gohman575fad32008-09-03 16:12:24 +0000534 /// GFI - Garbage collection metadata for the function.
535 GCFunctionInfo *GFI;
536
Bill Wendling267f3232011-10-05 22:24:35 +0000537 /// LPadToCallSiteMap - Map a landing pad to the call site indexes.
538 DenseMap<MachineBasicBlock*, SmallVector<unsigned, 4> > LPadToCallSiteMap;
Bill Wendling3d11aa72011-10-04 22:00:35 +0000539
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000540 /// HasTailCall - This is set to true if a call in the current
541 /// block has been translated as a tail call. In this case,
542 /// no subsequent DAG nodes should be created.
543 ///
544 bool HasTailCall;
545
Owen Anderson53a52212009-07-13 04:09:18 +0000546 LLVMContext *Context;
547
Dan Gohmanc3349602010-04-19 19:05:59 +0000548 SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo,
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000549 CodeGenOpt::Level ol)
Craig Topperada08572014-04-16 04:21:27 +0000550 : CurInst(nullptr), SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()),
Dan Gohmanc3349602010-04-19 19:05:59 +0000551 DAG(dag), FuncInfo(funcinfo), OptLevel(ol),
Richard Smith3fb20472012-08-22 00:42:39 +0000552 HasTailCall(false) {
Dan Gohman575fad32008-09-03 16:12:24 +0000553 }
554
Owen Andersonbb15fec2011-12-08 22:15:21 +0000555 void init(GCFunctionInfo *gfi, AliasAnalysis &aa,
556 const TargetLibraryInfo *li);
Dan Gohman575fad32008-09-03 16:12:24 +0000557
Dan Gohmanf5cca352010-04-14 18:24:06 +0000558 /// clear - Clear out the current SelectionDAG and the associated
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000559 /// state and prepare this SelectionDAGBuilder object to be used
Dan Gohman575fad32008-09-03 16:12:24 +0000560 /// for a new block. This doesn't clear out information about
561 /// additional blocks that are needed to complete switch lowering
562 /// or PHI node updating; that information is cleared out as it is
563 /// consumed.
564 void clear();
565
Devang Patel799288382011-05-23 17:44:13 +0000566 /// clearDanglingDebugInfo - Clear the dangling debug information
Benjamin Kramerbde91762012-06-02 10:20:22 +0000567 /// map. This function is separated from the clear so that debug
Devang Patel799288382011-05-23 17:44:13 +0000568 /// information that is dangling in a basic block can be properly
569 /// resolved in a different basic block. This allows the
570 /// SelectionDAG to resolve dangling debug information attached
571 /// to PHI nodes.
572 void clearDanglingDebugInfo();
573
Dan Gohman575fad32008-09-03 16:12:24 +0000574 /// getRoot - Return the current virtual root of the Selection DAG,
575 /// flushing any PendingLoad items. This must be done before emitting
576 /// a store or any other node that may need to be ordered after any
577 /// prior load instructions.
578 ///
579 SDValue getRoot();
580
581 /// getControlRoot - Similar to getRoot, but instead of flushing all the
582 /// PendingLoad items, flush all the PendingExports items. It is necessary
583 /// to do this before emitting a terminator instruction.
584 ///
585 SDValue getControlRoot();
586
Andrew Trick175143b2013-05-25 02:20:36 +0000587 SDLoc getCurSDLoc() const {
Andrew Trick175143b2013-05-25 02:20:36 +0000588 return SDLoc(CurInst, SDNodeOrder);
589 }
590
591 DebugLoc getCurDebugLoc() const {
592 return CurInst ? CurInst->getDebugLoc() : DebugLoc();
593 }
Devang Patelf3292b22011-02-21 23:21:26 +0000594
Bill Wendling919b7aa2009-12-22 02:10:19 +0000595 unsigned getSDNodeOrder() const { return SDNodeOrder; }
596
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000597 void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
Dan Gohman575fad32008-09-03 16:12:24 +0000598
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000599 void visit(const Instruction &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000600
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000601 void visit(unsigned Opcode, const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000602
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000603 // resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V,
604 // generate the debug data structures now that we've seen its definition.
605 void resolveDanglingDebugInfo(const Value *V, SDValue Val);
Dan Gohman575fad32008-09-03 16:12:24 +0000606 SDValue getValue(const Value *V);
Dan Gohmand4322232010-07-01 01:59:43 +0000607 SDValue getNonRegisterValue(const Value *V);
608 SDValue getValueImpl(const Value *V);
Dan Gohman575fad32008-09-03 16:12:24 +0000609
610 void setValue(const Value *V, SDValue NewN) {
611 SDValue &N = NodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000612 assert(!N.getNode() && "Already set a value for this node!");
Dan Gohman575fad32008-09-03 16:12:24 +0000613 N = NewN;
614 }
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000615
Devang Patelb0c76392010-06-01 19:59:01 +0000616 void setUnusedArgValue(const Value *V, SDValue NewN) {
617 SDValue &N = UnusedArgNodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000618 assert(!N.getNode() && "Already set a value for this node!");
Devang Patelb0c76392010-06-01 19:59:01 +0000619 N = NewN;
620 }
Dan Gohman575fad32008-09-03 16:12:24 +0000621
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000622 void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohman575fad32008-09-03 16:12:24 +0000623 MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000624 MachineBasicBlock *SwitchBB, unsigned Opc,
625 uint32_t TW, uint32_t FW);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000626 void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohmand01ddb52008-10-17 21:16:08 +0000627 MachineBasicBlock *FBB,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000628 MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000629 MachineBasicBlock *SwitchBB,
630 uint32_t TW, uint32_t FW);
Dan Gohman575fad32008-09-03 16:12:24 +0000631 bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000632 bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
633 void CopyToExportRegsIfNeeded(const Value *V);
634 void ExportFromCurrentBlock(const Value *V);
635 void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
Craig Topperada08572014-04-16 04:21:27 +0000636 MachineBasicBlock *LandingPad = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000637
Juergen Ributzkaad2363f2014-10-17 17:39:00 +0000638 std::pair<SDValue, SDValue> lowerCallOperands(
639 ImmutableCallSite CS,
640 unsigned ArgIdx,
641 unsigned NumArgs,
642 SDValue Callee,
643 bool UseVoidTy = false,
644 MachineBasicBlock *LandingPad = nullptr);
Andrew Trick74f4c742013-10-31 17:18:24 +0000645
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000646 /// UpdateSplitBlock - When an MBB was split during scheduling, update the
Alp Toker798060e2014-01-11 14:01:43 +0000647 /// references that need to refer to the last resulting block.
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000648 void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
649
Dan Gohman575fad32008-09-03 16:12:24 +0000650private:
Juergen Ributzkafd4633e2014-10-16 21:26:35 +0000651 std::pair<SDValue, SDValue> lowerInvokable(
652 TargetLowering::CallLoweringInfo &CLI,
653 MachineBasicBlock *LandingPad);
654
Dan Gohman575fad32008-09-03 16:12:24 +0000655 // Terminator instructions.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000656 void visitRet(const ReturnInst &I);
657 void visitBr(const BranchInst &I);
658 void visitSwitch(const SwitchInst &I);
659 void visitIndirectBr(const IndirectBrInst &I);
Yaron Kerend7ba46b2014-04-19 13:47:43 +0000660 void visitUnreachable(const UnreachableInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000661
662 // Helpers for visitSwitch
663 bool handleSmallSwitchRange(CaseRec& CR,
664 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000665 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000666 MachineBasicBlock* Default,
667 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000668 bool handleJTSwitchCase(CaseRec& CR,
669 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000670 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000671 MachineBasicBlock* Default,
672 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000673 bool handleBTSplitSwitchCase(CaseRec& CR,
674 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000675 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000676 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000677 bool handleBitTestsSwitchCase(CaseRec& CR,
678 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000679 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000680 MachineBasicBlock* Default,
681 MachineBasicBlock *SwitchBB);
Jakub Staszak12a43bd2011-06-16 20:22:37 +0000682
Jakub Staszak96f8c552011-12-20 20:03:10 +0000683 uint32_t getEdgeWeight(const MachineBasicBlock *Src,
684 const MachineBasicBlock *Dst) const;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000685 void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
686 uint32_t Weight = 0);
Dan Gohman575fad32008-09-03 16:12:24 +0000687public:
Dan Gohman7c0303a2010-04-19 22:41:47 +0000688 void visitSwitchCase(CaseBlock &CB,
689 MachineBasicBlock *SwitchBB);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000690 void visitSPDescriptorParent(StackProtectorDescriptor &SPD,
691 MachineBasicBlock *ParentBB);
692 void visitSPDescriptorFailure(StackProtectorDescriptor &SPD);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000693 void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB);
Evan Chengac730dd2011-01-06 01:02:44 +0000694 void visitBitTestCase(BitTestBlock &BB,
695 MachineBasicBlock* NextMBB,
Manman Rencf104462012-08-24 18:14:27 +0000696 uint32_t BranchWeightToNext,
Dan Gohman575fad32008-09-03 16:12:24 +0000697 unsigned Reg,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000698 BitTestCase &B,
699 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000700 void visitJumpTable(JumpTable &JT);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000701 void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH,
702 MachineBasicBlock *SwitchBB);
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000703
Dan Gohman575fad32008-09-03 16:12:24 +0000704private:
705 // These all get lowered before this pass.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000706 void visitInvoke(const InvokeInst &I);
Bill Wendlingf891bf82011-07-31 06:30:59 +0000707 void visitResume(const ResumeInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000708
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000709 void visitBinary(const User &I, unsigned OpCode);
710 void visitShift(const User &I, unsigned Opcode);
711 void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
712 void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
713 void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
714 void visitFSub(const User &I);
715 void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
716 void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
717 void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
718 void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
719 void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
720 void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
Benjamin Kramer9960a252011-07-08 10:31:30 +0000721 void visitSDiv(const User &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000722 void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
723 void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
724 void visitOr (const User &I) { visitBinary(I, ISD::OR); }
725 void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
726 void visitShl (const User &I) { visitShift(I, ISD::SHL); }
727 void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
728 void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
729 void visitICmp(const User &I);
730 void visitFCmp(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000731 // Visit the conversion instructions
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000732 void visitTrunc(const User &I);
733 void visitZExt(const User &I);
734 void visitSExt(const User &I);
735 void visitFPTrunc(const User &I);
736 void visitFPExt(const User &I);
737 void visitFPToUI(const User &I);
738 void visitFPToSI(const User &I);
739 void visitUIToFP(const User &I);
740 void visitSIToFP(const User &I);
741 void visitPtrToInt(const User &I);
742 void visitIntToPtr(const User &I);
743 void visitBitCast(const User &I);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000744 void visitAddrSpaceCast(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000745
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000746 void visitExtractElement(const User &I);
747 void visitInsertElement(const User &I);
748 void visitShuffleVector(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000749
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000750 void visitExtractValue(const ExtractValueInst &I);
751 void visitInsertValue(const InsertValueInst &I);
Bill Wendlingfae14752011-08-12 20:24:12 +0000752 void visitLandingPad(const LandingPadInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000753
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000754 void visitGetElementPtr(const User &I);
755 void visitSelect(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000756
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000757 void visitAlloca(const AllocaInst &I);
758 void visitLoad(const LoadInst &I);
759 void visitStore(const StoreInst &I);
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000760 void visitAtomicCmpXchg(const AtomicCmpXchgInst &I);
761 void visitAtomicRMW(const AtomicRMWInst &I);
Eli Friedmanfee02c62011-07-25 23:16:38 +0000762 void visitFence(const FenceInst &I);
Dan Gohmanf41ad472010-04-20 15:00:41 +0000763 void visitPHI(const PHINode &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000764 void visitCall(const CallInst &I);
765 bool visitMemCmpCall(const CallInst &I);
Richard Sandiford6f6d5512013-08-20 09:38:48 +0000766 bool visitMemChrCall(const CallInst &I);
Richard Sandifordbb83a502013-08-16 11:29:37 +0000767 bool visitStrCpyCall(const CallInst &I, bool isStpcpy);
Richard Sandifordca232712013-08-16 11:21:54 +0000768 bool visitStrCmpCall(const CallInst &I);
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000769 bool visitStrLenCall(const CallInst &I);
770 bool visitStrNLenCall(const CallInst &I);
Bob Wilson874886c2012-08-03 23:29:17 +0000771 bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode);
Matt Arsenault7c936902014-10-21 23:01:01 +0000772 bool visitBinaryFloatCall(const CallInst &I, unsigned Opcode);
Eli Friedman342e8df2011-08-24 20:50:09 +0000773 void visitAtomicLoad(const LoadInst &I);
774 void visitAtomicStore(const StoreInst &I);
775
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000776 void visitInlineAsm(ImmutableCallSite CS);
777 const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
778 void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
Dan Gohman575fad32008-09-03 16:12:24 +0000779
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000780 void visitVAStart(const CallInst &I);
781 void visitVAArg(const VAArgInst &I);
782 void visitVAEnd(const CallInst &I);
783 void visitVACopy(const CallInst &I);
Andrew Trick74f4c742013-10-31 17:18:24 +0000784 void visitStackmap(const CallInst &I);
Juergen Ributzkaad2363f2014-10-17 17:39:00 +0000785 void visitPatchpoint(ImmutableCallSite CS,
786 MachineBasicBlock *LandingPad = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000787
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000788 void visitUserOp1(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000789 llvm_unreachable("UserOp1 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000790 }
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000791 void visitUserOp2(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000792 llvm_unreachable("UserOp2 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000793 }
Dan Gohman5b43aa02010-04-22 20:55:53 +0000794
Richard Sandiforde3827752013-08-16 10:55:47 +0000795 void processIntegerCallValue(const Instruction &I,
796 SDValue Value, bool IsSigned);
797
Dan Gohman5b43aa02010-04-22 20:55:53 +0000798 void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
Evan Cheng6e822452010-04-28 23:08:54 +0000799
Devang Patel32a72ab2010-08-25 20:41:24 +0000800 /// EmitFuncArgumentDbgValue - If V is an function argument then create
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000801 /// corresponding DBG_VALUE machine instruction for it now. At the end of
Devang Patel32a72ab2010-08-25 20:41:24 +0000802 /// instruction selection, they will be inserted to the entry BB.
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000803 bool EmitFuncArgumentDbgValue(const Value *V, MDNode *Variable, MDNode *Expr,
Adrian Prantl32da8892014-04-25 20:49:25 +0000804 int64_t Offset, bool IsIndirect,
805 const SDValue &N);
Dan Gohman575fad32008-09-03 16:12:24 +0000806};
807
Dan Gohman575fad32008-09-03 16:12:24 +0000808} // end namespace llvm
809
810#endif