blob: ff9aa2c1f52e5123b0f36ac49a5bcbd271cca19e [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"
Dan Gohman575fad32008-09-03 16:12:24 +000024#include <vector>
Dan Gohman575fad32008-09-03 16:12:24 +000025
26namespace llvm {
27
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +000028class AddrSpaceCastInst;
Dan Gohman575fad32008-09-03 16:12:24 +000029class AliasAnalysis;
30class AllocaInst;
31class BasicBlock;
32class BitCastInst;
33class BranchInst;
34class CallInst;
Devang Patelb12ff592010-08-26 23:35:15 +000035class DbgValueInst;
Dan Gohman575fad32008-09-03 16:12:24 +000036class ExtractElementInst;
37class ExtractValueInst;
38class FCmpInst;
39class FPExtInst;
40class FPToSIInst;
41class FPToUIInst;
42class FPTruncInst;
Dan Gohman575fad32008-09-03 16:12:24 +000043class Function;
Dan Gohmana3624b62009-11-23 17:16:22 +000044class FunctionLoweringInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000045class GetElementPtrInst;
46class GCFunctionInfo;
47class ICmpInst;
48class IntToPtrInst;
Chris Lattnerd04cb6d2009-10-28 00:19:10 +000049class IndirectBrInst;
Dan Gohman575fad32008-09-03 16:12:24 +000050class InvokeInst;
51class InsertElementInst;
52class InsertValueInst;
53class Instruction;
54class LoadInst;
55class MachineBasicBlock;
Dan Gohman575fad32008-09-03 16:12:24 +000056class MachineInstr;
Dan Gohman575fad32008-09-03 16:12:24 +000057class MachineRegisterInfo;
Evan Cheng6e822452010-04-28 23:08:54 +000058class MDNode;
Patrik Hagglund1da35122014-03-12 08:00:24 +000059class MVT;
Dan Gohman575fad32008-09-03 16:12:24 +000060class PHINode;
61class PtrToIntInst;
62class ReturnInst;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000063class SDDbgValue;
Dan Gohman575fad32008-09-03 16:12:24 +000064class SExtInst;
65class SelectInst;
66class ShuffleVectorInst;
67class SIToFPInst;
68class StoreInst;
69class SwitchInst;
Micah Villmowcdfe20b2012-10-08 16:38:25 +000070class DataLayout;
Owen Andersonbb15fec2011-12-08 22:15:21 +000071class TargetLibraryInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000072class TargetLowering;
73class TruncInst;
74class UIToFPInst;
75class UnreachableInst;
Dan Gohman575fad32008-09-03 16:12:24 +000076class VAArgInst;
77class ZExtInst;
78
Dan Gohman575fad32008-09-03 16:12:24 +000079//===----------------------------------------------------------------------===//
Dan Gohman1a6c47f2009-11-23 18:04:58 +000080/// SelectionDAGBuilder - This is the common target-independent lowering
Dan Gohman575fad32008-09-03 16:12:24 +000081/// implementation that is parameterized by a TargetLowering object.
Dan Gohman575fad32008-09-03 16:12:24 +000082///
Benjamin Kramer079b96e2013-09-11 18:05:11 +000083class SelectionDAGBuilder {
Andrew Trick175143b2013-05-25 02:20:36 +000084 /// CurInst - The current instruction being visited
85 const Instruction *CurInst;
Dale Johannesendb7c5f62009-01-31 02:22:37 +000086
Dan Gohman575fad32008-09-03 16:12:24 +000087 DenseMap<const Value*, SDValue> NodeMap;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +000088
Devang Patelb0c76392010-06-01 19:59:01 +000089 /// UnusedArgNodeMap - Maps argument value for unused arguments. This is used
90 /// to preserve debug information for incoming arguments.
91 DenseMap<const Value*, SDValue> UnusedArgNodeMap;
Dan Gohman575fad32008-09-03 16:12:24 +000092
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000093 /// DanglingDebugInfo - Helper type for DanglingDebugInfoMap.
94 class DanglingDebugInfo {
Devang Patelb12ff592010-08-26 23:35:15 +000095 const DbgValueInst* DI;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000096 DebugLoc dl;
97 unsigned SDNodeOrder;
98 public:
Craig Topperada08572014-04-16 04:21:27 +000099 DanglingDebugInfo() : DI(nullptr), dl(DebugLoc()), SDNodeOrder(0) { }
Devang Patelb12ff592010-08-26 23:35:15 +0000100 DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO) :
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000101 DI(di), dl(DL), SDNodeOrder(SDNO) { }
Devang Patelb12ff592010-08-26 23:35:15 +0000102 const DbgValueInst* getDI() { return DI; }
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000103 DebugLoc getdl() { return dl; }
104 unsigned getSDNodeOrder() { return SDNodeOrder; }
105 };
106
107 /// DanglingDebugInfoMap - Keeps track of dbg_values for which we have not
108 /// yet seen the referent. We defer handling these until we do see it.
109 DenseMap<const Value*, DanglingDebugInfo> DanglingDebugInfoMap;
110
Chris Lattner1a32ede2009-12-24 00:37:38 +0000111public:
Dan Gohman575fad32008-09-03 16:12:24 +0000112 /// PendingLoads - Loads are not emitted to the program immediately. We bunch
113 /// them up and then emit token factor nodes when possible. This allows us to
114 /// get simple disambiguation between loads without worrying about alias
115 /// analysis.
116 SmallVector<SDValue, 8> PendingLoads;
Chris Lattner1a32ede2009-12-24 00:37:38 +0000117private:
Dan Gohman575fad32008-09-03 16:12:24 +0000118
119 /// PendingExports - CopyToReg nodes that copy values to virtual registers
120 /// for export to other blocks need to be emitted before any terminator
121 /// instruction, but they have no other ordering requirements. We bunch them
122 /// up and the emit a single tokenfactor for them just before terminator
123 /// instructions.
124 SmallVector<SDValue, 8> PendingExports;
125
Bill Wendling022d18f2009-12-18 23:32:53 +0000126 /// SDNodeOrder - A unique monotonically increasing number used to order the
127 /// SDNodes we create.
128 unsigned SDNodeOrder;
129
Dan Gohman575fad32008-09-03 16:12:24 +0000130 /// Case - A struct to record the Value for a switch case, and the
131 /// case's target basic block.
132 struct Case {
Stepan Dyatkovskiy513aaa52012-02-01 07:49:51 +0000133 const Constant *Low;
134 const Constant *High;
Dan Gohman575fad32008-09-03 16:12:24 +0000135 MachineBasicBlock* BB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000136 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000137
Craig Topperada08572014-04-16 04:21:27 +0000138 Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { }
Stepan Dyatkovskiy513aaa52012-02-01 07:49:51 +0000139 Case(const Constant *low, const Constant *high, MachineBasicBlock *bb,
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000140 uint32_t extraweight) : Low(low), High(high), BB(bb),
141 ExtraWeight(extraweight) { }
142
Chris Lattner8e1d7222009-11-07 07:50:34 +0000143 APInt size() const {
144 const APInt &rHigh = cast<ConstantInt>(High)->getValue();
145 const APInt &rLow = cast<ConstantInt>(Low)->getValue();
Dan Gohman575fad32008-09-03 16:12:24 +0000146 return (rHigh - rLow + 1ULL);
147 }
148 };
149
150 struct CaseBits {
151 uint64_t Mask;
152 MachineBasicBlock* BB;
153 unsigned Bits;
Manman Rencf104462012-08-24 18:14:27 +0000154 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000155
Manman Rencf104462012-08-24 18:14:27 +0000156 CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits,
157 uint32_t Weight):
158 Mask(mask), BB(bb), Bits(bits), ExtraWeight(Weight) { }
Dan Gohman575fad32008-09-03 16:12:24 +0000159 };
160
161 typedef std::vector<Case> CaseVector;
162 typedef std::vector<CaseBits> CaseBitsVector;
163 typedef CaseVector::iterator CaseItr;
164 typedef std::pair<CaseItr, CaseItr> CaseRange;
165
166 /// CaseRec - A struct with ctor used in lowering switches to a binary tree
167 /// of conditional branches.
168 struct CaseRec {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000169 CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
170 CaseRange r) :
Dan Gohman575fad32008-09-03 16:12:24 +0000171 CaseBB(bb), LT(lt), GE(ge), Range(r) {}
172
173 /// CaseBB - The MBB in which to emit the compare and branch
174 MachineBasicBlock *CaseBB;
175 /// LT, GE - If nonzero, we know the current case value must be less-than or
176 /// greater-than-or-equal-to these Constants.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000177 const Constant *LT;
178 const Constant *GE;
Dan Gohman575fad32008-09-03 16:12:24 +0000179 /// Range - A pair of iterators representing the range of case values to be
180 /// processed at this point in the binary search tree.
181 CaseRange Range;
182 };
183
184 typedef std::vector<CaseRec> CaseRecVector;
185
Bob Wilsone4077362013-09-09 19:14:35 +0000186 /// The comparison function for sorting the switch case values in the vector.
187 /// WARNING: Case ranges should be disjoint!
188 struct CaseCmp {
189 bool operator()(const Case &C1, const Case &C2) {
190 assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High));
191 const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
192 const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
193 return CI1->getValue().slt(CI2->getValue());
194 }
195 };
196
Dan Gohman575fad32008-09-03 16:12:24 +0000197 struct CaseBitsCmp {
Chris Lattner24576a52010-01-01 23:37:34 +0000198 bool operator()(const CaseBits &C1, const CaseBits &C2) {
Dan Gohman575fad32008-09-03 16:12:24 +0000199 return C1.Bits > C2.Bits;
200 }
201 };
202
Chad Rosierdf82a332014-10-13 19:46:39 +0000203 void Clusterify(CaseVector &Cases, const SwitchInst &SI);
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000204
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000205 /// CaseBlock - This structure is used to communicate between
206 /// SelectionDAGBuilder and SDISel for the code generation of additional basic
207 /// blocks needed by multi-case switch statements.
Dan Gohman575fad32008-09-03 16:12:24 +0000208 struct CaseBlock {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000209 CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
210 const Value *cmpmiddle,
Dan Gohman575fad32008-09-03 16:12:24 +0000211 MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000212 MachineBasicBlock *me,
213 uint32_t trueweight = 0, uint32_t falseweight = 0)
Dan Gohman575fad32008-09-03 16:12:24 +0000214 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000215 TrueBB(truebb), FalseBB(falsebb), ThisBB(me),
216 TrueWeight(trueweight), FalseWeight(falseweight) { }
217
Dan Gohman575fad32008-09-03 16:12:24 +0000218 // CC - the condition code to use for the case block's setcc node
219 ISD::CondCode CC;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000220
Dan Gohman575fad32008-09-03 16:12:24 +0000221 // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
222 // Emit by default LHS op RHS. MHS is used for range comparisons:
223 // If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000224 const Value *CmpLHS, *CmpMHS, *CmpRHS;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000225
Dan Gohman575fad32008-09-03 16:12:24 +0000226 // TrueBB/FalseBB - the block to branch to if the setcc is true/false.
227 MachineBasicBlock *TrueBB, *FalseBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000228
Dan Gohman575fad32008-09-03 16:12:24 +0000229 // ThisBB - the block into which to emit the code for the setcc and branches
230 MachineBasicBlock *ThisBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000231
232 // TrueWeight/FalseWeight - branch weights.
233 uint32_t TrueWeight, FalseWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000234 };
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000235
Dan Gohman575fad32008-09-03 16:12:24 +0000236 struct JumpTable {
237 JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
238 MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000239
Dan Gohman575fad32008-09-03 16:12:24 +0000240 /// Reg - the virtual register containing the index of the jump table entry
241 //. to jump to.
242 unsigned Reg;
243 /// JTI - the JumpTableIndex for this jump table in the function.
244 unsigned JTI;
245 /// MBB - the MBB into which to emit the code for the indirect jump.
246 MachineBasicBlock *MBB;
247 /// Default - the MBB of the default bb, which is a successor of the range
248 /// check MBB. This is when updating PHI nodes in successors.
249 MachineBasicBlock *Default;
250 };
251 struct JumpTableHeader {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000252 JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
Dan Gohman575fad32008-09-03 16:12:24 +0000253 bool E = false):
254 First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000255 APInt First;
256 APInt Last;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000257 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000258 MachineBasicBlock *HeaderBB;
259 bool Emitted;
260 };
261 typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock;
262
263 struct BitTestCase {
Manman Rencf104462012-08-24 18:14:27 +0000264 BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr,
265 uint32_t Weight):
266 Mask(M), ThisBB(T), TargetBB(Tr), ExtraWeight(Weight) { }
Dan Gohman575fad32008-09-03 16:12:24 +0000267 uint64_t Mask;
Chris Lattner24576a52010-01-01 23:37:34 +0000268 MachineBasicBlock *ThisBB;
269 MachineBasicBlock *TargetBB;
Manman Rencf104462012-08-24 18:14:27 +0000270 uint32_t ExtraWeight;
Dan Gohman575fad32008-09-03 16:12:24 +0000271 };
272
273 typedef SmallVector<BitTestCase, 3> BitTestInfo;
274
275 struct BitTestBlock {
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000276 BitTestBlock(APInt F, APInt R, const Value* SV,
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000277 unsigned Rg, MVT RgVT, bool E,
Dan Gohman575fad32008-09-03 16:12:24 +0000278 MachineBasicBlock* P, MachineBasicBlock* D,
Benjamin Kramerc6cc58e2014-10-04 16:55:56 +0000279 BitTestInfo C):
Evan Chengac730dd2011-01-06 01:02:44 +0000280 First(F), Range(R), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E),
Benjamin Kramerc6cc58e2014-10-04 16:55:56 +0000281 Parent(P), Default(D), Cases(std::move(C)) { }
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000282 APInt First;
283 APInt Range;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000284 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000285 unsigned Reg;
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000286 MVT RegVT;
Dan Gohman575fad32008-09-03 16:12:24 +0000287 bool Emitted;
288 MachineBasicBlock *Parent;
289 MachineBasicBlock *Default;
290 BitTestInfo Cases;
291 };
292
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000293 /// A class which encapsulates all of the information needed to generate a
294 /// stack protector check and signals to isel via its state being initialized
295 /// that a stack protector needs to be generated.
296 ///
297 /// *NOTE* The following is a high level documentation of SelectionDAG Stack
298 /// Protector Generation. The reason that it is placed here is for a lack of
299 /// other good places to stick it.
300 ///
301 /// High Level Overview of SelectionDAG Stack Protector Generation:
302 ///
303 /// Previously, generation of stack protectors was done exclusively in the
304 /// pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
305 /// splitting basic blocks at the IR level to create the success/failure basic
306 /// blocks in the tail of the basic block in question. As a result of this,
307 /// calls that would have qualified for the sibling call optimization were no
308 /// longer eligible for optimization since said calls were no longer right in
309 /// the "tail position" (i.e. the immediate predecessor of a ReturnInst
310 /// instruction).
311 ///
312 /// Then it was noticed that since the sibling call optimization causes the
313 /// callee to reuse the caller's stack, if we could delay the generation of
314 /// the stack protector check until later in CodeGen after the sibling call
315 /// decision was made, we get both the tail call optimization and the stack
316 /// protector check!
317 ///
318 /// A few goals in solving this problem were:
319 ///
320 /// 1. Preserve the architecture independence of stack protector generation.
321 ///
322 /// 2. Preserve the normal IR level stack protector check for platforms like
Alp Tokercf218752014-06-30 18:57:16 +0000323 /// OpenBSD for which we support platform-specific stack protector
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000324 /// generation.
325 ///
326 /// The main problem that guided the present solution is that one can not
327 /// solve this problem in an architecture independent manner at the IR level
328 /// only. This is because:
329 ///
330 /// 1. The decision on whether or not to perform a sibling call on certain
331 /// platforms (for instance i386) requires lower level information
332 /// related to available registers that can not be known at the IR level.
333 ///
334 /// 2. Even if the previous point were not true, the decision on whether to
335 /// perform a tail call is done in LowerCallTo in SelectionDAG which
336 /// occurs after the Stack Protector Pass. As a result, one would need to
337 /// put the relevant callinst into the stack protector check success
338 /// basic block (where the return inst is placed) and then move it back
339 /// later at SelectionDAG/MI time before the stack protector check if the
340 /// tail call optimization failed. The MI level option was nixed
Alp Tokercf218752014-06-30 18:57:16 +0000341 /// immediately since it would require platform-specific pattern
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000342 /// matching. The SelectionDAG level option was nixed because
343 /// SelectionDAG only processes one IR level basic block at a time
344 /// implying one could not create a DAG Combine to move the callinst.
345 ///
346 /// To get around this problem a few things were realized:
347 ///
348 /// 1. While one can not handle multiple IR level basic blocks at the
349 /// SelectionDAG Level, one can generate multiple machine basic blocks
350 /// for one IR level basic block. This is how we handle bit tests and
351 /// switches.
352 ///
353 /// 2. At the MI level, tail calls are represented via a special return
354 /// MIInst called "tcreturn". Thus if we know the basic block in which we
355 /// wish to insert the stack protector check, we get the correct behavior
356 /// by always inserting the stack protector check right before the return
357 /// statement. This is a "magical transformation" since no matter where
358 /// the stack protector check intrinsic is, we always insert the stack
359 /// protector check code at the end of the BB.
360 ///
361 /// Given the aforementioned constraints, the following solution was devised:
362 ///
363 /// 1. On platforms that do not support SelectionDAG stack protector check
364 /// generation, allow for the normal IR level stack protector check
365 /// generation to continue.
366 ///
367 /// 2. On platforms that do support SelectionDAG stack protector check
368 /// generation:
369 ///
370 /// a. Use the IR level stack protector pass to decide if a stack
371 /// protector is required/which BB we insert the stack protector check
372 /// in by reusing the logic already therein. If we wish to generate a
373 /// stack protector check in a basic block, we place a special IR
374 /// intrinsic called llvm.stackprotectorcheck right before the BB's
375 /// returninst or if there is a callinst that could potentially be
376 /// sibling call optimized, before the call inst.
377 ///
378 /// b. Then when a BB with said intrinsic is processed, we codegen the BB
379 /// normally via SelectBasicBlock. In said process, when we visit the
380 /// stack protector check, we do not actually emit anything into the
381 /// BB. Instead, we just initialize the stack protector descriptor
382 /// class (which involves stashing information/creating the success
383 /// mbbb and the failure mbb if we have not created one for this
384 /// function yet) and export the guard variable that we are going to
385 /// compare.
386 ///
387 /// c. After we finish selecting the basic block, in FinishBasicBlock if
388 /// the StackProtectorDescriptor attached to the SelectionDAGBuilder is
389 /// initialized, we first find a splice point in the parent basic block
390 /// before the terminator and then splice the terminator of said basic
391 /// block into the success basic block. Then we code-gen a new tail for
392 /// the parent basic block consisting of the two loads, the comparison,
393 /// and finally two branches to the success/failure basic blocks. We
394 /// conclude by code-gening the failure basic block if we have not
395 /// code-gened it already (all stack protector checks we generate in
396 /// the same function, use the same failure basic block).
397 class StackProtectorDescriptor {
398 public:
Craig Topperada08572014-04-16 04:21:27 +0000399 StackProtectorDescriptor() : ParentMBB(nullptr), SuccessMBB(nullptr),
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000400 FailureMBB(nullptr), Guard(nullptr),
401 GuardReg(0) { }
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000402 ~StackProtectorDescriptor() { }
403
404 /// Returns true if all fields of the stack protector descriptor are
405 /// initialized implying that we should/are ready to emit a stack protector.
406 bool shouldEmitStackProtector() const {
407 return ParentMBB && SuccessMBB && FailureMBB && Guard;
408 }
409
410 /// Initialize the stack protector descriptor structure for a new basic
411 /// block.
412 void initialize(const BasicBlock *BB,
413 MachineBasicBlock *MBB,
414 const CallInst &StackProtCheckCall) {
415 // Make sure we are not initialized yet.
416 assert(!shouldEmitStackProtector() && "Stack Protector Descriptor is "
417 "already initialized!");
418 ParentMBB = MBB;
419 SuccessMBB = AddSuccessorMBB(BB, MBB);
420 FailureMBB = AddSuccessorMBB(BB, MBB, FailureMBB);
421 if (!Guard)
422 Guard = StackProtCheckCall.getArgOperand(0);
423 }
424
425 /// Reset state that changes when we handle different basic blocks.
426 ///
427 /// This currently includes:
428 ///
429 /// 1. The specific basic block we are generating a
430 /// stack protector for (ParentMBB).
431 ///
432 /// 2. The successor machine basic block that will contain the tail of
433 /// parent mbb after we create the stack protector check (SuccessMBB). This
434 /// BB is visited only on stack protector check success.
435 void resetPerBBState() {
Craig Topperada08572014-04-16 04:21:27 +0000436 ParentMBB = nullptr;
437 SuccessMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000438 }
439
440 /// Reset state that only changes when we switch functions.
441 ///
442 /// This currently includes:
443 ///
444 /// 1. FailureMBB since we reuse the failure code path for all stack
445 /// protector checks created in an individual function.
446 ///
447 /// 2.The guard variable since the guard variable we are checking against is
448 /// always the same.
449 void resetPerFunctionState() {
Craig Topperada08572014-04-16 04:21:27 +0000450 FailureMBB = nullptr;
451 Guard = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000452 }
453
454 MachineBasicBlock *getParentMBB() { return ParentMBB; }
455 MachineBasicBlock *getSuccessMBB() { return SuccessMBB; }
456 MachineBasicBlock *getFailureMBB() { return FailureMBB; }
457 const Value *getGuard() { return Guard; }
458
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000459 unsigned getGuardReg() const { return GuardReg; }
460 void setGuardReg(unsigned R) { GuardReg = R; }
461
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000462 private:
463 /// The basic block for which we are generating the stack protector.
464 ///
465 /// As a result of stack protector generation, we will splice the
466 /// terminators of this basic block into the successor mbb SuccessMBB and
467 /// replace it with a compare/branch to the successor mbbs
468 /// SuccessMBB/FailureMBB depending on whether or not the stack protector
469 /// was violated.
470 MachineBasicBlock *ParentMBB;
471
472 /// A basic block visited on stack protector check success that contains the
473 /// terminators of ParentMBB.
474 MachineBasicBlock *SuccessMBB;
475
476 /// This basic block visited on stack protector check failure that will
477 /// contain a call to __stack_chk_fail().
478 MachineBasicBlock *FailureMBB;
479
480 /// The guard variable which we will compare against the stored value in the
481 /// stack protector stack slot.
482 const Value *Guard;
483
Akira Hatanakae5b6e0d2014-07-25 19:31:34 +0000484 /// The virtual register holding the stack guard value.
485 unsigned GuardReg;
486
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000487 /// Add a successor machine basic block to ParentMBB. If the successor mbb
488 /// has not been created yet (i.e. if SuccMBB = 0), then the machine basic
489 /// block will be created.
490 MachineBasicBlock *AddSuccessorMBB(const BasicBlock *BB,
491 MachineBasicBlock *ParentMBB,
Craig Topperada08572014-04-16 04:21:27 +0000492 MachineBasicBlock *SuccMBB = nullptr);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000493 };
494
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000495private:
Dan Gohmanc3349602010-04-19 19:05:59 +0000496 const TargetMachine &TM;
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000497public:
Nico Rieckb5262d62014-01-12 14:09:17 +0000498 /// Lowest valid SDNodeOrder. The special case 0 is reserved for scheduling
499 /// nodes without a corresponding SDNode.
500 static const unsigned LowestSDNodeOrder = 1;
501
Dan Gohman575fad32008-09-03 16:12:24 +0000502 SelectionDAG &DAG;
Rafael Espindola5f57f462014-02-21 18:34:28 +0000503 const DataLayout *DL;
Dan Gohman575fad32008-09-03 16:12:24 +0000504 AliasAnalysis *AA;
Owen Andersonbb15fec2011-12-08 22:15:21 +0000505 const TargetLibraryInfo *LibInfo;
Dan Gohman575fad32008-09-03 16:12:24 +0000506
507 /// SwitchCases - Vector of CaseBlock structures used to communicate
508 /// SwitchInst code generation information.
509 std::vector<CaseBlock> SwitchCases;
510 /// JTCases - Vector of JumpTable structures used to communicate
511 /// SwitchInst code generation information.
512 std::vector<JumpTableBlock> JTCases;
513 /// BitTestCases - Vector of BitTestBlock structures used to communicate
514 /// SwitchInst code generation information.
515 std::vector<BitTestBlock> BitTestCases;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000516 /// A StackProtectorDescriptor structure used to communicate stack protector
517 /// information in between SelectBasicBlock and FinishBasicBlock.
518 StackProtectorDescriptor SPDescriptor;
Evan Cheng270d0f92009-09-18 21:02:19 +0000519
Dan Gohman575fad32008-09-03 16:12:24 +0000520 // Emit PHI-node-operand constants only once even if used by multiple
521 // PHI nodes.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000522 DenseMap<const Constant *, unsigned> ConstantsOut;
Dan Gohman575fad32008-09-03 16:12:24 +0000523
524 /// FuncInfo - Information about the function as a whole.
525 ///
526 FunctionLoweringInfo &FuncInfo;
Bill Wendling19e0a5b2009-02-19 21:12:54 +0000527
Bill Wendling084669a2009-04-29 00:15:41 +0000528 /// OptLevel - What optimization level we're generating code for.
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000529 ///
Bill Wendling026e5d72009-04-29 23:29:43 +0000530 CodeGenOpt::Level OptLevel;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000531
Dan Gohman575fad32008-09-03 16:12:24 +0000532 /// GFI - Garbage collection metadata for the function.
533 GCFunctionInfo *GFI;
534
Bill Wendling267f3232011-10-05 22:24:35 +0000535 /// LPadToCallSiteMap - Map a landing pad to the call site indexes.
536 DenseMap<MachineBasicBlock*, SmallVector<unsigned, 4> > LPadToCallSiteMap;
Bill Wendling3d11aa72011-10-04 22:00:35 +0000537
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000538 /// HasTailCall - This is set to true if a call in the current
539 /// block has been translated as a tail call. In this case,
540 /// no subsequent DAG nodes should be created.
541 ///
542 bool HasTailCall;
543
Owen Anderson53a52212009-07-13 04:09:18 +0000544 LLVMContext *Context;
545
Dan Gohmanc3349602010-04-19 19:05:59 +0000546 SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo,
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000547 CodeGenOpt::Level ol)
Craig Topperada08572014-04-16 04:21:27 +0000548 : CurInst(nullptr), SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()),
Dan Gohmanc3349602010-04-19 19:05:59 +0000549 DAG(dag), FuncInfo(funcinfo), OptLevel(ol),
Richard Smith3fb20472012-08-22 00:42:39 +0000550 HasTailCall(false) {
Dan Gohman575fad32008-09-03 16:12:24 +0000551 }
552
Owen Andersonbb15fec2011-12-08 22:15:21 +0000553 void init(GCFunctionInfo *gfi, AliasAnalysis &aa,
554 const TargetLibraryInfo *li);
Dan Gohman575fad32008-09-03 16:12:24 +0000555
Dan Gohmanf5cca352010-04-14 18:24:06 +0000556 /// clear - Clear out the current SelectionDAG and the associated
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000557 /// state and prepare this SelectionDAGBuilder object to be used
Dan Gohman575fad32008-09-03 16:12:24 +0000558 /// for a new block. This doesn't clear out information about
559 /// additional blocks that are needed to complete switch lowering
560 /// or PHI node updating; that information is cleared out as it is
561 /// consumed.
562 void clear();
563
Devang Patel799288382011-05-23 17:44:13 +0000564 /// clearDanglingDebugInfo - Clear the dangling debug information
Benjamin Kramerbde91762012-06-02 10:20:22 +0000565 /// map. This function is separated from the clear so that debug
Devang Patel799288382011-05-23 17:44:13 +0000566 /// information that is dangling in a basic block can be properly
567 /// resolved in a different basic block. This allows the
568 /// SelectionDAG to resolve dangling debug information attached
569 /// to PHI nodes.
570 void clearDanglingDebugInfo();
571
Dan Gohman575fad32008-09-03 16:12:24 +0000572 /// getRoot - Return the current virtual root of the Selection DAG,
573 /// flushing any PendingLoad items. This must be done before emitting
574 /// a store or any other node that may need to be ordered after any
575 /// prior load instructions.
576 ///
577 SDValue getRoot();
578
579 /// getControlRoot - Similar to getRoot, but instead of flushing all the
580 /// PendingLoad items, flush all the PendingExports items. It is necessary
581 /// to do this before emitting a terminator instruction.
582 ///
583 SDValue getControlRoot();
584
Andrew Trick175143b2013-05-25 02:20:36 +0000585 SDLoc getCurSDLoc() const {
Andrew Trick175143b2013-05-25 02:20:36 +0000586 return SDLoc(CurInst, SDNodeOrder);
587 }
588
589 DebugLoc getCurDebugLoc() const {
590 return CurInst ? CurInst->getDebugLoc() : DebugLoc();
591 }
Devang Patelf3292b22011-02-21 23:21:26 +0000592
Bill Wendling919b7aa2009-12-22 02:10:19 +0000593 unsigned getSDNodeOrder() const { return SDNodeOrder; }
594
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000595 void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
Dan Gohman575fad32008-09-03 16:12:24 +0000596
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000597 void visit(const Instruction &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000598
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000599 void visit(unsigned Opcode, const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000600
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000601 // resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V,
602 // generate the debug data structures now that we've seen its definition.
603 void resolveDanglingDebugInfo(const Value *V, SDValue Val);
Dan Gohman575fad32008-09-03 16:12:24 +0000604 SDValue getValue(const Value *V);
Dan Gohmand4322232010-07-01 01:59:43 +0000605 SDValue getNonRegisterValue(const Value *V);
606 SDValue getValueImpl(const Value *V);
Dan Gohman575fad32008-09-03 16:12:24 +0000607
608 void setValue(const Value *V, SDValue NewN) {
609 SDValue &N = NodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000610 assert(!N.getNode() && "Already set a value for this node!");
Dan Gohman575fad32008-09-03 16:12:24 +0000611 N = NewN;
612 }
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000613
Devang Patelb0c76392010-06-01 19:59:01 +0000614 void setUnusedArgValue(const Value *V, SDValue NewN) {
615 SDValue &N = UnusedArgNodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000616 assert(!N.getNode() && "Already set a value for this node!");
Devang Patelb0c76392010-06-01 19:59:01 +0000617 N = NewN;
618 }
Dan Gohman575fad32008-09-03 16:12:24 +0000619
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000620 void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohman575fad32008-09-03 16:12:24 +0000621 MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000622 MachineBasicBlock *SwitchBB, unsigned Opc,
623 uint32_t TW, uint32_t FW);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000624 void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohmand01ddb52008-10-17 21:16:08 +0000625 MachineBasicBlock *FBB,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000626 MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000627 MachineBasicBlock *SwitchBB,
628 uint32_t TW, uint32_t FW);
Dan Gohman575fad32008-09-03 16:12:24 +0000629 bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000630 bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
631 void CopyToExportRegsIfNeeded(const Value *V);
632 void ExportFromCurrentBlock(const Value *V);
633 void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
Craig Topperada08572014-04-16 04:21:27 +0000634 MachineBasicBlock *LandingPad = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000635
Andrew Trick74f4c742013-10-31 17:18:24 +0000636 std::pair<SDValue, SDValue> LowerCallOperands(const CallInst &CI,
637 unsigned ArgIdx,
638 unsigned NumArgs,
Juergen Ributzka9969d3e2013-11-08 23:28:16 +0000639 SDValue Callee,
640 bool useVoidTy = false);
Andrew Trick74f4c742013-10-31 17:18:24 +0000641
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000642 /// UpdateSplitBlock - When an MBB was split during scheduling, update the
Alp Toker798060e2014-01-11 14:01:43 +0000643 /// references that need to refer to the last resulting block.
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000644 void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
645
Dan Gohman575fad32008-09-03 16:12:24 +0000646private:
647 // Terminator instructions.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000648 void visitRet(const ReturnInst &I);
649 void visitBr(const BranchInst &I);
650 void visitSwitch(const SwitchInst &I);
651 void visitIndirectBr(const IndirectBrInst &I);
Yaron Kerend7ba46b2014-04-19 13:47:43 +0000652 void visitUnreachable(const UnreachableInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000653
654 // Helpers for visitSwitch
655 bool handleSmallSwitchRange(CaseRec& CR,
656 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000657 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000658 MachineBasicBlock* Default,
659 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000660 bool handleJTSwitchCase(CaseRec& CR,
661 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000662 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000663 MachineBasicBlock* Default,
664 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000665 bool handleBTSplitSwitchCase(CaseRec& CR,
666 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000667 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000668 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000669 bool handleBitTestsSwitchCase(CaseRec& CR,
670 CaseRecVector& WorkList,
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000671 const Value* SV,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000672 MachineBasicBlock* Default,
673 MachineBasicBlock *SwitchBB);
Jakub Staszak12a43bd2011-06-16 20:22:37 +0000674
Jakub Staszak96f8c552011-12-20 20:03:10 +0000675 uint32_t getEdgeWeight(const MachineBasicBlock *Src,
676 const MachineBasicBlock *Dst) const;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000677 void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
678 uint32_t Weight = 0);
Dan Gohman575fad32008-09-03 16:12:24 +0000679public:
Dan Gohman7c0303a2010-04-19 22:41:47 +0000680 void visitSwitchCase(CaseBlock &CB,
681 MachineBasicBlock *SwitchBB);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000682 void visitSPDescriptorParent(StackProtectorDescriptor &SPD,
683 MachineBasicBlock *ParentBB);
684 void visitSPDescriptorFailure(StackProtectorDescriptor &SPD);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000685 void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB);
Evan Chengac730dd2011-01-06 01:02:44 +0000686 void visitBitTestCase(BitTestBlock &BB,
687 MachineBasicBlock* NextMBB,
Manman Rencf104462012-08-24 18:14:27 +0000688 uint32_t BranchWeightToNext,
Dan Gohman575fad32008-09-03 16:12:24 +0000689 unsigned Reg,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000690 BitTestCase &B,
691 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000692 void visitJumpTable(JumpTable &JT);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000693 void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH,
694 MachineBasicBlock *SwitchBB);
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000695
Dan Gohman575fad32008-09-03 16:12:24 +0000696private:
697 // These all get lowered before this pass.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000698 void visitInvoke(const InvokeInst &I);
Bill Wendlingf891bf82011-07-31 06:30:59 +0000699 void visitResume(const ResumeInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000700
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000701 void visitBinary(const User &I, unsigned OpCode);
702 void visitShift(const User &I, unsigned Opcode);
703 void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
704 void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
705 void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
706 void visitFSub(const User &I);
707 void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
708 void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
709 void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
710 void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
711 void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
712 void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
Benjamin Kramer9960a252011-07-08 10:31:30 +0000713 void visitSDiv(const User &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000714 void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
715 void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
716 void visitOr (const User &I) { visitBinary(I, ISD::OR); }
717 void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
718 void visitShl (const User &I) { visitShift(I, ISD::SHL); }
719 void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
720 void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
721 void visitICmp(const User &I);
722 void visitFCmp(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000723 // Visit the conversion instructions
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000724 void visitTrunc(const User &I);
725 void visitZExt(const User &I);
726 void visitSExt(const User &I);
727 void visitFPTrunc(const User &I);
728 void visitFPExt(const User &I);
729 void visitFPToUI(const User &I);
730 void visitFPToSI(const User &I);
731 void visitUIToFP(const User &I);
732 void visitSIToFP(const User &I);
733 void visitPtrToInt(const User &I);
734 void visitIntToPtr(const User &I);
735 void visitBitCast(const User &I);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000736 void visitAddrSpaceCast(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000737
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000738 void visitExtractElement(const User &I);
739 void visitInsertElement(const User &I);
740 void visitShuffleVector(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000741
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000742 void visitExtractValue(const ExtractValueInst &I);
743 void visitInsertValue(const InsertValueInst &I);
Bill Wendlingfae14752011-08-12 20:24:12 +0000744 void visitLandingPad(const LandingPadInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000745
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000746 void visitGetElementPtr(const User &I);
747 void visitSelect(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000748
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000749 void visitAlloca(const AllocaInst &I);
750 void visitLoad(const LoadInst &I);
751 void visitStore(const StoreInst &I);
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000752 void visitAtomicCmpXchg(const AtomicCmpXchgInst &I);
753 void visitAtomicRMW(const AtomicRMWInst &I);
Eli Friedmanfee02c62011-07-25 23:16:38 +0000754 void visitFence(const FenceInst &I);
Dan Gohmanf41ad472010-04-20 15:00:41 +0000755 void visitPHI(const PHINode &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000756 void visitCall(const CallInst &I);
757 bool visitMemCmpCall(const CallInst &I);
Richard Sandiford6f6d5512013-08-20 09:38:48 +0000758 bool visitMemChrCall(const CallInst &I);
Richard Sandifordbb83a502013-08-16 11:29:37 +0000759 bool visitStrCpyCall(const CallInst &I, bool isStpcpy);
Richard Sandifordca232712013-08-16 11:21:54 +0000760 bool visitStrCmpCall(const CallInst &I);
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000761 bool visitStrLenCall(const CallInst &I);
762 bool visitStrNLenCall(const CallInst &I);
Bob Wilson874886c2012-08-03 23:29:17 +0000763 bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode);
Eli Friedman342e8df2011-08-24 20:50:09 +0000764 void visitAtomicLoad(const LoadInst &I);
765 void visitAtomicStore(const StoreInst &I);
766
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000767 void visitInlineAsm(ImmutableCallSite CS);
768 const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
769 void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
Dan Gohman575fad32008-09-03 16:12:24 +0000770
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000771 void visitVAStart(const CallInst &I);
772 void visitVAArg(const VAArgInst &I);
773 void visitVAEnd(const CallInst &I);
774 void visitVACopy(const CallInst &I);
Andrew Trick74f4c742013-10-31 17:18:24 +0000775 void visitStackmap(const CallInst &I);
776 void visitPatchpoint(const CallInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000777
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000778 void visitUserOp1(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000779 llvm_unreachable("UserOp1 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000780 }
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000781 void visitUserOp2(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000782 llvm_unreachable("UserOp2 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000783 }
Dan Gohman5b43aa02010-04-22 20:55:53 +0000784
Richard Sandiforde3827752013-08-16 10:55:47 +0000785 void processIntegerCallValue(const Instruction &I,
786 SDValue Value, bool IsSigned);
787
Dan Gohman5b43aa02010-04-22 20:55:53 +0000788 void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
Evan Cheng6e822452010-04-28 23:08:54 +0000789
Devang Patel32a72ab2010-08-25 20:41:24 +0000790 /// EmitFuncArgumentDbgValue - If V is an function argument then create
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000791 /// corresponding DBG_VALUE machine instruction for it now. At the end of
Devang Patel32a72ab2010-08-25 20:41:24 +0000792 /// instruction selection, they will be inserted to the entry BB.
Adrian Prantl87b7eb92014-10-01 18:55:02 +0000793 bool EmitFuncArgumentDbgValue(const Value *V, MDNode *Variable, MDNode *Expr,
Adrian Prantl32da8892014-04-25 20:49:25 +0000794 int64_t Offset, bool IsIndirect,
795 const SDValue &N);
Dan Gohman575fad32008-09-03 16:12:24 +0000796};
797
Dan Gohman575fad32008-09-03 16:12:24 +0000798} // end namespace llvm
799
800#endif