blob: 3d58a040e2ac97a2f5411cef32abd97c18c7dc23 [file] [log] [blame]
Eugene Zelenkofa57bd02017-09-27 23:26:01 +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"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000019#include "llvm/ADT/ArrayRef.h"
Dan Gohman575fad32008-09-03 16:12:24 +000020#include "llvm/ADT/DenseMap.h"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000021#include "llvm/ADT/SmallVector.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000022#include "llvm/Analysis/AliasAnalysis.h"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000023#include "llvm/CodeGen/ISDOpcodes.h"
24#include "llvm/CodeGen/MachineValueType.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000025#include "llvm/CodeGen/SelectionDAG.h"
Dan Gohman575fad32008-09-03 16:12:24 +000026#include "llvm/CodeGen/SelectionDAGNodes.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000027#include "llvm/CodeGen/TargetLowering.h"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000028#include "llvm/CodeGen/ValueTypes.h"
Chandler Carruth219b89b2014-03-04 11:01:28 +000029#include "llvm/IR/CallSite.h"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000030#include "llvm/IR/DebugLoc.h"
31#include "llvm/IR/Instruction.h"
Benjamin Kramer82de7d32016-05-27 14:27:24 +000032#include "llvm/IR/Statepoint.h"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000033#include "llvm/Support/BranchProbability.h"
34#include "llvm/Support/CodeGen.h"
Torok Edwin56d06592009-07-11 20:10:48 +000035#include "llvm/Support/ErrorHandling.h"
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000036#include <algorithm>
37#include <cassert>
38#include <cstdint>
Benjamin Kramer82de7d32016-05-27 14:27:24 +000039#include <utility>
Dan Gohman575fad32008-09-03 16:12:24 +000040#include <vector>
Dan Gohman575fad32008-09-03 16:12:24 +000041
42namespace llvm {
43
Dan Gohman575fad32008-09-03 16:12:24 +000044class AllocaInst;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000045class AtomicCmpXchgInst;
46class AtomicRMWInst;
Dan Gohman575fad32008-09-03 16:12:24 +000047class BasicBlock;
Dan Gohman575fad32008-09-03 16:12:24 +000048class BranchInst;
49class CallInst;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000050class CatchPadInst;
51class CatchReturnInst;
52class CatchSwitchInst;
53class CleanupPadInst;
54class CleanupReturnInst;
55class Constant;
56class ConstantInt;
57class ConstrainedFPIntrinsic;
Devang Patelb12ff592010-08-26 23:35:15 +000058class DbgValueInst;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000059class DataLayout;
60class DIExpression;
61class DILocalVariable;
62class DILocation;
63class FenceInst;
Dan Gohmana3624b62009-11-23 17:16:22 +000064class FunctionLoweringInfo;
Dan Gohman575fad32008-09-03 16:12:24 +000065class GCFunctionInfo;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000066class GCRelocateInst;
67class GCResultInst;
Chris Lattnerd04cb6d2009-10-28 00:19:10 +000068class IndirectBrInst;
Dan Gohman575fad32008-09-03 16:12:24 +000069class InvokeInst;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000070class LandingPadInst;
71class LLVMContext;
Dan Gohman575fad32008-09-03 16:12:24 +000072class LoadInst;
73class MachineBasicBlock;
Dan Gohman575fad32008-09-03 16:12:24 +000074class PHINode;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000075class ResumeInst;
Dan Gohman575fad32008-09-03 16:12:24 +000076class ReturnInst;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +000077class SDDbgValue;
Dan Gohman575fad32008-09-03 16:12:24 +000078class StoreInst;
79class SwitchInst;
Owen Andersonbb15fec2011-12-08 22:15:21 +000080class TargetLibraryInfo;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000081class TargetMachine;
82class Type;
Dan Gohman575fad32008-09-03 16:12:24 +000083class VAArgInst;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000084class UnreachableInst;
85class Use;
86class User;
87class Value;
Dan Gohman575fad32008-09-03 16:12:24 +000088
Dan Gohman575fad32008-09-03 16:12:24 +000089//===----------------------------------------------------------------------===//
Dan Gohman1a6c47f2009-11-23 18:04:58 +000090/// SelectionDAGBuilder - This is the common target-independent lowering
Dan Gohman575fad32008-09-03 16:12:24 +000091/// implementation that is parameterized by a TargetLowering object.
Dan Gohman575fad32008-09-03 16:12:24 +000092///
Benjamin Kramer079b96e2013-09-11 18:05:11 +000093class SelectionDAGBuilder {
Andrew Trick175143b2013-05-25 02:20:36 +000094 /// CurInst - The current instruction being visited
Eugene Zelenkofa57bd02017-09-27 23:26:01 +000095 const Instruction *CurInst = nullptr;
Dale Johannesendb7c5f62009-01-31 02:22:37 +000096
Dan Gohman575fad32008-09-03 16:12:24 +000097 DenseMap<const Value*, SDValue> NodeMap;
Andrew Trickd4d1d9c2013-10-31 17:18:07 +000098
Devang Patelb0c76392010-06-01 19:59:01 +000099 /// UnusedArgNodeMap - Maps argument value for unused arguments. This is used
100 /// to preserve debug information for incoming arguments.
101 DenseMap<const Value*, SDValue> UnusedArgNodeMap;
Dan Gohman575fad32008-09-03 16:12:24 +0000102
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000103 /// DanglingDebugInfo - Helper type for DanglingDebugInfoMap.
104 class DanglingDebugInfo {
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000105 const DbgValueInst* DI = nullptr;
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000106 DebugLoc dl;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000107 unsigned SDNodeOrder = 0;
108
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000109 public:
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000110 DanglingDebugInfo() = default;
Benjamin Kramer82de7d32016-05-27 14:27:24 +0000111 DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO)
112 : DI(di), dl(std::move(DL)), SDNodeOrder(SDNO) {}
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000113
Devang Patelb12ff592010-08-26 23:35:15 +0000114 const DbgValueInst* getDI() { return DI; }
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000115 DebugLoc getdl() { return dl; }
116 unsigned getSDNodeOrder() { return SDNodeOrder; }
117 };
118
119 /// DanglingDebugInfoMap - Keeps track of dbg_values for which we have not
120 /// yet seen the referent. We defer handling these until we do see it.
121 DenseMap<const Value*, DanglingDebugInfo> DanglingDebugInfoMap;
122
Chris Lattner1a32ede2009-12-24 00:37:38 +0000123public:
Dan Gohman575fad32008-09-03 16:12:24 +0000124 /// PendingLoads - Loads are not emitted to the program immediately. We bunch
125 /// them up and then emit token factor nodes when possible. This allows us to
126 /// get simple disambiguation between loads without worrying about alias
127 /// analysis.
128 SmallVector<SDValue, 8> PendingLoads;
Philip Reames1a1bdb22014-12-02 18:50:36 +0000129
130 /// State used while lowering a statepoint sequence (gc_statepoint,
131 /// gc_relocate, and gc_result). See StatepointLowering.hpp/cpp for details.
132 StatepointLoweringState StatepointLowering;
Dan Gohman575fad32008-09-03 16:12:24 +0000133
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000134private:
Dan Gohman575fad32008-09-03 16:12:24 +0000135 /// PendingExports - CopyToReg nodes that copy values to virtual registers
136 /// for export to other blocks need to be emitted before any terminator
137 /// instruction, but they have no other ordering requirements. We bunch them
138 /// up and the emit a single tokenfactor for them just before terminator
139 /// instructions.
140 SmallVector<SDValue, 8> PendingExports;
141
Bill Wendling022d18f2009-12-18 23:32:53 +0000142 /// SDNodeOrder - A unique monotonically increasing number used to order the
143 /// SDNodes we create.
144 unsigned SDNodeOrder;
145
Hans Wennborg0867b152015-04-23 16:45:24 +0000146 enum CaseClusterKind {
147 /// A cluster of adjacent case labels with the same destination, or just one
148 /// case.
149 CC_Range,
150 /// A cluster of cases suitable for jump table lowering.
151 CC_JumpTable,
152 /// A cluster of cases suitable for bit test lowering.
153 CC_BitTests
154 };
Dan Gohman575fad32008-09-03 16:12:24 +0000155
Hans Wennborg0867b152015-04-23 16:45:24 +0000156 /// A cluster of case labels.
157 struct CaseCluster {
158 CaseClusterKind Kind;
159 const ConstantInt *Low, *High;
160 union {
161 MachineBasicBlock *MBB;
162 unsigned JTCasesIndex;
163 unsigned BTCasesIndex;
164 };
Cong Hou1938f2e2015-11-24 08:51:23 +0000165 BranchProbability Prob;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000166
Hans Wennborg0867b152015-04-23 16:45:24 +0000167 static CaseCluster range(const ConstantInt *Low, const ConstantInt *High,
Cong Hou1938f2e2015-11-24 08:51:23 +0000168 MachineBasicBlock *MBB, BranchProbability Prob) {
Hans Wennborg0867b152015-04-23 16:45:24 +0000169 CaseCluster C;
170 C.Kind = CC_Range;
171 C.Low = Low;
172 C.High = High;
173 C.MBB = MBB;
Cong Hou1938f2e2015-11-24 08:51:23 +0000174 C.Prob = Prob;
Hans Wennborg0867b152015-04-23 16:45:24 +0000175 return C;
176 }
177
178 static CaseCluster jumpTable(const ConstantInt *Low,
179 const ConstantInt *High, unsigned JTCasesIndex,
Cong Hou1938f2e2015-11-24 08:51:23 +0000180 BranchProbability Prob) {
Hans Wennborg0867b152015-04-23 16:45:24 +0000181 CaseCluster C;
182 C.Kind = CC_JumpTable;
183 C.Low = Low;
184 C.High = High;
185 C.JTCasesIndex = JTCasesIndex;
Cong Hou1938f2e2015-11-24 08:51:23 +0000186 C.Prob = Prob;
Hans Wennborg0867b152015-04-23 16:45:24 +0000187 return C;
188 }
189
190 static CaseCluster bitTests(const ConstantInt *Low, const ConstantInt *High,
Cong Hou1938f2e2015-11-24 08:51:23 +0000191 unsigned BTCasesIndex, BranchProbability Prob) {
Hans Wennborg0867b152015-04-23 16:45:24 +0000192 CaseCluster C;
193 C.Kind = CC_BitTests;
194 C.Low = Low;
195 C.High = High;
196 C.BTCasesIndex = BTCasesIndex;
Cong Hou1938f2e2015-11-24 08:51:23 +0000197 C.Prob = Prob;
Hans Wennborg0867b152015-04-23 16:45:24 +0000198 return C;
Dan Gohman575fad32008-09-03 16:12:24 +0000199 }
200 };
201
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000202 using CaseClusterVector = std::vector<CaseCluster>;
203 using CaseClusterIt = CaseClusterVector::iterator;
Hans Wennborg0867b152015-04-23 16:45:24 +0000204
Dan Gohman575fad32008-09-03 16:12:24 +0000205 struct CaseBits {
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000206 uint64_t Mask = 0;
207 MachineBasicBlock* BB = nullptr;
208 unsigned Bits = 0;
Cong Hou1938f2e2015-11-24 08:51:23 +0000209 BranchProbability ExtraProb;
Dan Gohman575fad32008-09-03 16:12:24 +0000210
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000211 CaseBits() = default;
Manman Rencf104462012-08-24 18:14:27 +0000212 CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits,
Cong Hou1938f2e2015-11-24 08:51:23 +0000213 BranchProbability Prob):
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000214 Mask(mask), BB(bb), Bits(bits), ExtraProb(Prob) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000215 };
216
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000217 using CaseBitsVector = std::vector<CaseBits>;
Dan Gohman575fad32008-09-03 16:12:24 +0000218
Hans Wennborg0867b152015-04-23 16:45:24 +0000219 /// Sort Clusters and merge adjacent cases.
220 void sortAndRangeify(CaseClusterVector &Clusters);
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000221
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000222 /// CaseBlock - This structure is used to communicate between
223 /// SelectionDAGBuilder and SDISel for the code generation of additional basic
224 /// blocks needed by multi-case switch statements.
Dan Gohman575fad32008-09-03 16:12:24 +0000225 struct CaseBlock {
Dan Gohman575fad32008-09-03 16:12:24 +0000226 // CC - the condition code to use for the case block's setcc node
227 ISD::CondCode CC;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000228
Dan Gohman575fad32008-09-03 16:12:24 +0000229 // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
230 // Emit by default LHS op RHS. MHS is used for range comparisons:
231 // If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000232 const Value *CmpLHS, *CmpMHS, *CmpRHS;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000233
Dan Gohman575fad32008-09-03 16:12:24 +0000234 // TrueBB/FalseBB - the block to branch to if the setcc is true/false.
235 MachineBasicBlock *TrueBB, *FalseBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000236
Dan Gohman575fad32008-09-03 16:12:24 +0000237 // ThisBB - the block into which to emit the code for the setcc and branches
238 MachineBasicBlock *ThisBB;
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000239
Adrian Prantl6a57daa2017-08-17 16:57:13 +0000240 /// The debug location of the instruction this CaseBlock was
241 /// produced from.
242 SDLoc DL;
243
Cong Hou1938f2e2015-11-24 08:51:23 +0000244 // TrueProb/FalseProb - branch weights.
245 BranchProbability TrueProb, FalseProb;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000246
247 CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
248 const Value *cmpmiddle, MachineBasicBlock *truebb,
249 MachineBasicBlock *falsebb, MachineBasicBlock *me,
250 SDLoc dl,
251 BranchProbability trueprob = BranchProbability::getUnknown(),
252 BranchProbability falseprob = BranchProbability::getUnknown())
253 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
254 TrueBB(truebb), FalseBB(falsebb), ThisBB(me), DL(dl),
255 TrueProb(trueprob), FalseProb(falseprob) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000256 };
Jakub Staszak0480a8f2011-07-29 22:25:21 +0000257
Dan Gohman575fad32008-09-03 16:12:24 +0000258 struct JumpTable {
Dan Gohman575fad32008-09-03 16:12:24 +0000259 /// Reg - the virtual register containing the index of the jump table entry
260 //. to jump to.
261 unsigned Reg;
262 /// JTI - the JumpTableIndex for this jump table in the function.
263 unsigned JTI;
264 /// MBB - the MBB into which to emit the code for the indirect jump.
265 MachineBasicBlock *MBB;
266 /// Default - the MBB of the default bb, which is a successor of the range
267 /// check MBB. This is when updating PHI nodes in successors.
268 MachineBasicBlock *Default;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000269
270 JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
271 MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000272 };
273 struct JumpTableHeader {
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000274 APInt First;
275 APInt Last;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000276 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000277 MachineBasicBlock *HeaderBB;
278 bool Emitted;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000279
280 JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
281 bool E = false)
282 : First(std::move(F)), Last(std::move(L)), SValue(SV), HeaderBB(H),
283 Emitted(E) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000284 };
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000285 using JumpTableBlock = std::pair<JumpTableHeader, JumpTable>;
Dan Gohman575fad32008-09-03 16:12:24 +0000286
287 struct BitTestCase {
Dan Gohman575fad32008-09-03 16:12:24 +0000288 uint64_t Mask;
Chris Lattner24576a52010-01-01 23:37:34 +0000289 MachineBasicBlock *ThisBB;
290 MachineBasicBlock *TargetBB;
Cong Hou1938f2e2015-11-24 08:51:23 +0000291 BranchProbability ExtraProb;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000292
293 BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr,
294 BranchProbability Prob):
295 Mask(M), ThisBB(T), TargetBB(Tr), ExtraProb(Prob) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000296 };
297
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000298 using BitTestInfo = SmallVector<BitTestCase, 3>;
Dan Gohman575fad32008-09-03 16:12:24 +0000299
300 struct BitTestBlock {
Anton Korobeynikov6f219132008-12-23 22:25:27 +0000301 APInt First;
302 APInt Range;
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000303 const Value *SValue;
Dan Gohman575fad32008-09-03 16:12:24 +0000304 unsigned Reg;
Patrik Hagglund4e0f8282012-12-19 12:23:01 +0000305 MVT RegVT;
Dan Gohman575fad32008-09-03 16:12:24 +0000306 bool Emitted;
Cong Houcd595912015-08-25 21:34:38 +0000307 bool ContiguousRange;
Dan Gohman575fad32008-09-03 16:12:24 +0000308 MachineBasicBlock *Parent;
309 MachineBasicBlock *Default;
310 BitTestInfo Cases;
Cong Hou1938f2e2015-11-24 08:51:23 +0000311 BranchProbability Prob;
312 BranchProbability DefaultProb;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000313
314 BitTestBlock(APInt F, APInt R, const Value *SV, unsigned Rg, MVT RgVT,
315 bool E, bool CR, MachineBasicBlock *P, MachineBasicBlock *D,
316 BitTestInfo C, BranchProbability Pr)
317 : First(std::move(F)), Range(std::move(R)), SValue(SV), Reg(Rg),
318 RegVT(RgVT), Emitted(E), ContiguousRange(CR), Parent(P), Default(D),
319 Cases(std::move(C)), Prob(Pr) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000320 };
321
Jun Bum Lim919f9e82017-04-28 16:04:03 +0000322 /// Return the range of value in [First..Last].
323 uint64_t getJumpTableRange(const CaseClusterVector &Clusters, unsigned First,
324 unsigned Last) const;
325
326 /// Return the number of cases in [First..Last].
327 uint64_t getJumpTableNumCases(const SmallVectorImpl<unsigned> &TotalCases,
328 unsigned First, unsigned Last) const;
Hans Wennborg0867b152015-04-23 16:45:24 +0000329
330 /// Build a jump table cluster from Clusters[First..Last]. Returns false if it
331 /// decides it's not a good idea.
Aditya Kumar356f79d2016-09-01 23:35:26 +0000332 bool buildJumpTable(const CaseClusterVector &Clusters, unsigned First,
Hans Wennborg0867b152015-04-23 16:45:24 +0000333 unsigned Last, const SwitchInst *SI,
334 MachineBasicBlock *DefaultMBB, CaseCluster &JTCluster);
335
336 /// Find clusters of cases suitable for jump table lowering.
337 void findJumpTables(CaseClusterVector &Clusters, const SwitchInst *SI,
338 MachineBasicBlock *DefaultMBB);
339
Hans Wennborg0867b152015-04-23 16:45:24 +0000340 /// Build a bit test cluster from Clusters[First..Last]. Returns false if it
341 /// decides it's not a good idea.
342 bool buildBitTests(CaseClusterVector &Clusters, unsigned First, unsigned Last,
343 const SwitchInst *SI, CaseCluster &BTCluster);
344
345 /// Find clusters of cases suitable for bit test lowering.
346 void findBitTestClusters(CaseClusterVector &Clusters, const SwitchInst *SI);
347
348 struct SwitchWorkListItem {
349 MachineBasicBlock *MBB;
350 CaseClusterIt FirstCluster;
351 CaseClusterIt LastCluster;
352 const ConstantInt *GE;
353 const ConstantInt *LT;
Cong Hou1938f2e2015-11-24 08:51:23 +0000354 BranchProbability DefaultProb;
Hans Wennborg0867b152015-04-23 16:45:24 +0000355 };
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000356 using SwitchWorkList = SmallVector<SwitchWorkListItem, 4>;
Hans Wennborg0867b152015-04-23 16:45:24 +0000357
Hans Wennborg6ed81cb2015-06-20 17:14:07 +0000358 /// Determine the rank by weight of CC in [First,Last]. If CC has more weight
359 /// than each cluster in the range, its rank is 0.
360 static unsigned caseClusterRank(const CaseCluster &CC, CaseClusterIt First,
361 CaseClusterIt Last);
362
Hans Wennborg0867b152015-04-23 16:45:24 +0000363 /// Emit comparison and split W into two subtrees.
364 void splitWorkItem(SwitchWorkList &WorkList, const SwitchWorkListItem &W,
365 Value *Cond, MachineBasicBlock *SwitchMBB);
366
367 /// Lower W.
368 void lowerWorkItem(SwitchWorkListItem W, Value *Cond,
369 MachineBasicBlock *SwitchMBB,
370 MachineBasicBlock *DefaultMBB);
371
Rong Xu3573d8d2017-11-14 21:44:09 +0000372 /// Peel the top probability case if it exceeds the threshold
373 MachineBasicBlock *peelDominantCaseCluster(const SwitchInst &SI,
374 CaseClusterVector &Clusters,
375 BranchProbability &PeeledCaseProb);
Hans Wennborg0867b152015-04-23 16:45:24 +0000376
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000377 /// A class which encapsulates all of the information needed to generate a
378 /// stack protector check and signals to isel via its state being initialized
379 /// that a stack protector needs to be generated.
380 ///
381 /// *NOTE* The following is a high level documentation of SelectionDAG Stack
382 /// Protector Generation. The reason that it is placed here is for a lack of
383 /// other good places to stick it.
384 ///
385 /// High Level Overview of SelectionDAG Stack Protector Generation:
386 ///
387 /// Previously, generation of stack protectors was done exclusively in the
388 /// pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
389 /// splitting basic blocks at the IR level to create the success/failure basic
390 /// blocks in the tail of the basic block in question. As a result of this,
391 /// calls that would have qualified for the sibling call optimization were no
392 /// longer eligible for optimization since said calls were no longer right in
393 /// the "tail position" (i.e. the immediate predecessor of a ReturnInst
394 /// instruction).
395 ///
396 /// Then it was noticed that since the sibling call optimization causes the
397 /// callee to reuse the caller's stack, if we could delay the generation of
398 /// the stack protector check until later in CodeGen after the sibling call
399 /// decision was made, we get both the tail call optimization and the stack
400 /// protector check!
401 ///
402 /// A few goals in solving this problem were:
403 ///
404 /// 1. Preserve the architecture independence of stack protector generation.
405 ///
406 /// 2. Preserve the normal IR level stack protector check for platforms like
Alp Tokercf218752014-06-30 18:57:16 +0000407 /// OpenBSD for which we support platform-specific stack protector
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000408 /// generation.
409 ///
410 /// The main problem that guided the present solution is that one can not
411 /// solve this problem in an architecture independent manner at the IR level
412 /// only. This is because:
413 ///
414 /// 1. The decision on whether or not to perform a sibling call on certain
415 /// platforms (for instance i386) requires lower level information
416 /// related to available registers that can not be known at the IR level.
417 ///
418 /// 2. Even if the previous point were not true, the decision on whether to
419 /// perform a tail call is done in LowerCallTo in SelectionDAG which
420 /// occurs after the Stack Protector Pass. As a result, one would need to
421 /// put the relevant callinst into the stack protector check success
422 /// basic block (where the return inst is placed) and then move it back
423 /// later at SelectionDAG/MI time before the stack protector check if the
424 /// tail call optimization failed. The MI level option was nixed
Alp Tokercf218752014-06-30 18:57:16 +0000425 /// immediately since it would require platform-specific pattern
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000426 /// matching. The SelectionDAG level option was nixed because
427 /// SelectionDAG only processes one IR level basic block at a time
428 /// implying one could not create a DAG Combine to move the callinst.
429 ///
430 /// To get around this problem a few things were realized:
431 ///
432 /// 1. While one can not handle multiple IR level basic blocks at the
433 /// SelectionDAG Level, one can generate multiple machine basic blocks
434 /// for one IR level basic block. This is how we handle bit tests and
435 /// switches.
436 ///
437 /// 2. At the MI level, tail calls are represented via a special return
438 /// MIInst called "tcreturn". Thus if we know the basic block in which we
439 /// wish to insert the stack protector check, we get the correct behavior
440 /// by always inserting the stack protector check right before the return
441 /// statement. This is a "magical transformation" since no matter where
442 /// the stack protector check intrinsic is, we always insert the stack
443 /// protector check code at the end of the BB.
444 ///
445 /// Given the aforementioned constraints, the following solution was devised:
446 ///
447 /// 1. On platforms that do not support SelectionDAG stack protector check
448 /// generation, allow for the normal IR level stack protector check
449 /// generation to continue.
450 ///
451 /// 2. On platforms that do support SelectionDAG stack protector check
452 /// generation:
453 ///
454 /// a. Use the IR level stack protector pass to decide if a stack
455 /// protector is required/which BB we insert the stack protector check
456 /// in by reusing the logic already therein. If we wish to generate a
457 /// stack protector check in a basic block, we place a special IR
458 /// intrinsic called llvm.stackprotectorcheck right before the BB's
459 /// returninst or if there is a callinst that could potentially be
460 /// sibling call optimized, before the call inst.
461 ///
462 /// b. Then when a BB with said intrinsic is processed, we codegen the BB
463 /// normally via SelectBasicBlock. In said process, when we visit the
464 /// stack protector check, we do not actually emit anything into the
465 /// BB. Instead, we just initialize the stack protector descriptor
466 /// class (which involves stashing information/creating the success
467 /// mbbb and the failure mbb if we have not created one for this
468 /// function yet) and export the guard variable that we are going to
469 /// compare.
470 ///
471 /// c. After we finish selecting the basic block, in FinishBasicBlock if
472 /// the StackProtectorDescriptor attached to the SelectionDAGBuilder is
Etienne Bergeron22bfa832016-06-07 20:15:35 +0000473 /// initialized, we produce the validation code with one of these
474 /// techniques:
475 /// 1) with a call to a guard check function
476 /// 2) with inlined instrumentation
477 ///
478 /// 1) We insert a call to the check function before the terminator.
479 ///
480 /// 2) We first find a splice point in the parent basic block
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000481 /// before the terminator and then splice the terminator of said basic
482 /// block into the success basic block. Then we code-gen a new tail for
483 /// the parent basic block consisting of the two loads, the comparison,
484 /// and finally two branches to the success/failure basic blocks. We
485 /// conclude by code-gening the failure basic block if we have not
486 /// code-gened it already (all stack protector checks we generate in
487 /// the same function, use the same failure basic block).
488 class StackProtectorDescriptor {
489 public:
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000490 StackProtectorDescriptor() = default;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000491
492 /// Returns true if all fields of the stack protector descriptor are
493 /// initialized implying that we should/are ready to emit a stack protector.
494 bool shouldEmitStackProtector() const {
Tim Shen00127562016-04-08 21:26:31 +0000495 return ParentMBB && SuccessMBB && FailureMBB;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000496 }
497
Etienne Bergeron22bfa832016-06-07 20:15:35 +0000498 bool shouldEmitFunctionBasedCheckStackProtector() const {
499 return ParentMBB && !SuccessMBB && !FailureMBB;
500 }
501
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000502 /// Initialize the stack protector descriptor structure for a new basic
503 /// block.
Etienne Bergeron22bfa832016-06-07 20:15:35 +0000504 void initialize(const BasicBlock *BB, MachineBasicBlock *MBB,
505 bool FunctionBasedInstrumentation) {
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000506 // Make sure we are not initialized yet.
507 assert(!shouldEmitStackProtector() && "Stack Protector Descriptor is "
508 "already initialized!");
509 ParentMBB = MBB;
Etienne Bergeron22bfa832016-06-07 20:15:35 +0000510 if (!FunctionBasedInstrumentation) {
511 SuccessMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ true);
512 FailureMBB = AddSuccessorMBB(BB, MBB, /* IsLikely */ false, FailureMBB);
513 }
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000514 }
515
516 /// Reset state that changes when we handle different basic blocks.
517 ///
518 /// This currently includes:
519 ///
520 /// 1. The specific basic block we are generating a
521 /// stack protector for (ParentMBB).
522 ///
523 /// 2. The successor machine basic block that will contain the tail of
524 /// parent mbb after we create the stack protector check (SuccessMBB). This
525 /// BB is visited only on stack protector check success.
526 void resetPerBBState() {
Craig Topperada08572014-04-16 04:21:27 +0000527 ParentMBB = nullptr;
528 SuccessMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000529 }
530
531 /// Reset state that only changes when we switch functions.
532 ///
533 /// This currently includes:
534 ///
535 /// 1. FailureMBB since we reuse the failure code path for all stack
536 /// protector checks created in an individual function.
537 ///
538 /// 2.The guard variable since the guard variable we are checking against is
539 /// always the same.
540 void resetPerFunctionState() {
Craig Topperada08572014-04-16 04:21:27 +0000541 FailureMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000542 }
543
544 MachineBasicBlock *getParentMBB() { return ParentMBB; }
545 MachineBasicBlock *getSuccessMBB() { return SuccessMBB; }
546 MachineBasicBlock *getFailureMBB() { return FailureMBB; }
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000547
548 private:
549 /// The basic block for which we are generating the stack protector.
550 ///
551 /// As a result of stack protector generation, we will splice the
552 /// terminators of this basic block into the successor mbb SuccessMBB and
553 /// replace it with a compare/branch to the successor mbbs
554 /// SuccessMBB/FailureMBB depending on whether or not the stack protector
555 /// was violated.
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000556 MachineBasicBlock *ParentMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000557
558 /// A basic block visited on stack protector check success that contains the
559 /// terminators of ParentMBB.
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000560 MachineBasicBlock *SuccessMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000561
562 /// This basic block visited on stack protector check failure that will
563 /// contain a call to __stack_chk_fail().
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000564 MachineBasicBlock *FailureMBB = nullptr;
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000565
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000566 /// Add a successor machine basic block to ParentMBB. If the successor mbb
567 /// has not been created yet (i.e. if SuccMBB = 0), then the machine basic
Akira Hatanakab9991a22014-12-01 04:27:03 +0000568 /// block will be created. Assign a large weight if IsLikely is true.
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000569 MachineBasicBlock *AddSuccessorMBB(const BasicBlock *BB,
570 MachineBasicBlock *ParentMBB,
Akira Hatanakab9991a22014-12-01 04:27:03 +0000571 bool IsLikely,
Craig Topperada08572014-04-16 04:21:27 +0000572 MachineBasicBlock *SuccMBB = nullptr);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000573 };
574
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000575private:
Dan Gohmanc3349602010-04-19 19:05:59 +0000576 const TargetMachine &TM;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000577
Bill Wendlinga3cd3502013-06-19 21:36:55 +0000578public:
Nico Rieckb5262d62014-01-12 14:09:17 +0000579 /// Lowest valid SDNodeOrder. The special case 0 is reserved for scheduling
580 /// nodes without a corresponding SDNode.
581 static const unsigned LowestSDNodeOrder = 1;
582
Dan Gohman575fad32008-09-03 16:12:24 +0000583 SelectionDAG &DAG;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000584 const DataLayout *DL = nullptr;
585 AliasAnalysis *AA = nullptr;
Owen Andersonbb15fec2011-12-08 22:15:21 +0000586 const TargetLibraryInfo *LibInfo;
Dan Gohman575fad32008-09-03 16:12:24 +0000587
588 /// SwitchCases - Vector of CaseBlock structures used to communicate
589 /// SwitchInst code generation information.
590 std::vector<CaseBlock> SwitchCases;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000591
Dan Gohman575fad32008-09-03 16:12:24 +0000592 /// JTCases - Vector of JumpTable structures used to communicate
593 /// SwitchInst code generation information.
594 std::vector<JumpTableBlock> JTCases;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000595
Dan Gohman575fad32008-09-03 16:12:24 +0000596 /// BitTestCases - Vector of BitTestBlock structures used to communicate
597 /// SwitchInst code generation information.
598 std::vector<BitTestBlock> BitTestCases;
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000599
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000600 /// A StackProtectorDescriptor structure used to communicate stack protector
601 /// information in between SelectBasicBlock and FinishBasicBlock.
602 StackProtectorDescriptor SPDescriptor;
Evan Cheng270d0f92009-09-18 21:02:19 +0000603
Dan Gohman575fad32008-09-03 16:12:24 +0000604 // Emit PHI-node-operand constants only once even if used by multiple
605 // PHI nodes.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000606 DenseMap<const Constant *, unsigned> ConstantsOut;
Dan Gohman575fad32008-09-03 16:12:24 +0000607
608 /// FuncInfo - Information about the function as a whole.
609 ///
610 FunctionLoweringInfo &FuncInfo;
Bill Wendling19e0a5b2009-02-19 21:12:54 +0000611
Dan Gohman575fad32008-09-03 16:12:24 +0000612 /// GFI - Garbage collection metadata for the function.
613 GCFunctionInfo *GFI;
614
Bill Wendling267f3232011-10-05 22:24:35 +0000615 /// LPadToCallSiteMap - Map a landing pad to the call site indexes.
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000616 DenseMap<MachineBasicBlock *, SmallVector<unsigned, 4>> LPadToCallSiteMap;
Bill Wendling3d11aa72011-10-04 22:00:35 +0000617
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000618 /// HasTailCall - This is set to true if a call in the current
619 /// block has been translated as a tail call. In this case,
620 /// no subsequent DAG nodes should be created.
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000621 bool HasTailCall = false;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000622
Owen Anderson53a52212009-07-13 04:09:18 +0000623 LLVMContext *Context;
624
Dan Gohmanc3349602010-04-19 19:05:59 +0000625 SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo,
Dan Gohman1a6c47f2009-11-23 18:04:58 +0000626 CodeGenOpt::Level ol)
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000627 : SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()), DAG(dag),
628 FuncInfo(funcinfo) {}
Dan Gohman575fad32008-09-03 16:12:24 +0000629
Ahmed Bougacha604526f2017-05-10 00:39:30 +0000630 void init(GCFunctionInfo *gfi, AliasAnalysis *AA,
Owen Andersonbb15fec2011-12-08 22:15:21 +0000631 const TargetLibraryInfo *li);
Dan Gohman575fad32008-09-03 16:12:24 +0000632
Sanjay Patel209b0f92017-03-02 20:48:08 +0000633 /// Clear out the current SelectionDAG and the associated state and prepare
634 /// this SelectionDAGBuilder object to be used for a new block. This doesn't
635 /// clear out information about additional blocks that are needed to complete
636 /// switch lowering or PHI node updating; that information is cleared out as
637 /// it is consumed.
Dan Gohman575fad32008-09-03 16:12:24 +0000638 void clear();
639
Sanjay Patel209b0f92017-03-02 20:48:08 +0000640 /// Clear the dangling debug information map. This function is separated from
641 /// the clear so that debug information that is dangling in a basic block can
642 /// be properly resolved in a different basic block. This allows the
643 /// SelectionDAG to resolve dangling debug information attached to PHI nodes.
Devang Patel799288382011-05-23 17:44:13 +0000644 void clearDanglingDebugInfo();
645
Sanjay Patel209b0f92017-03-02 20:48:08 +0000646 /// Return the current virtual root of the Selection DAG, flushing any
647 /// PendingLoad items. This must be done before emitting a store or any other
648 /// node that may need to be ordered after any prior load instructions.
Dan Gohman575fad32008-09-03 16:12:24 +0000649 SDValue getRoot();
650
Sanjay Patel209b0f92017-03-02 20:48:08 +0000651 /// Similar to getRoot, but instead of flushing all the PendingLoad items,
652 /// flush all the PendingExports items. It is necessary to do this before
653 /// emitting a terminator instruction.
Dan Gohman575fad32008-09-03 16:12:24 +0000654 SDValue getControlRoot();
655
Andrew Trick175143b2013-05-25 02:20:36 +0000656 SDLoc getCurSDLoc() const {
Andrew Trick175143b2013-05-25 02:20:36 +0000657 return SDLoc(CurInst, SDNodeOrder);
658 }
659
660 DebugLoc getCurDebugLoc() const {
661 return CurInst ? CurInst->getDebugLoc() : DebugLoc();
662 }
Devang Patelf3292b22011-02-21 23:21:26 +0000663
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000664 void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
Dan Gohman575fad32008-09-03 16:12:24 +0000665
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000666 void visit(const Instruction &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000667
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000668 void visit(unsigned Opcode, const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000669
Igor Laevsky85f7f722015-03-10 16:26:48 +0000670 /// getCopyFromRegs - If there was virtual register allocated for the value V
671 /// emit CopyFromReg of the specified type Ty. Return empty SDValue() otherwise.
672 SDValue getCopyFromRegs(const Value *V, Type *Ty);
673
Bjorn Petterssona223f8152018-03-12 18:02:39 +0000674 /// If we have dangling debug info that describes \p Variable, or an
675 /// overlapping part of variable considering the \p Expr, then this method
676 /// weill drop that debug info as it isn't valid any longer.
677 void dropDanglingDebugInfo(const DILocalVariable *Variable,
678 const DIExpression *Expr);
679
Dale Johannesenbfd4fd72010-07-16 00:02:08 +0000680 // resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V,
681 // generate the debug data structures now that we've seen its definition.
682 void resolveDanglingDebugInfo(const Value *V, SDValue Val);
Eugene Zelenkofa57bd02017-09-27 23:26:01 +0000683
Dan Gohman575fad32008-09-03 16:12:24 +0000684 SDValue getValue(const Value *V);
Elena Demikhovsky584ce372015-04-28 07:57:37 +0000685 bool findValue(const Value *V) const;
686
Dan Gohmand4322232010-07-01 01:59:43 +0000687 SDValue getNonRegisterValue(const Value *V);
688 SDValue getValueImpl(const Value *V);
Dan Gohman575fad32008-09-03 16:12:24 +0000689
690 void setValue(const Value *V, SDValue NewN) {
691 SDValue &N = NodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000692 assert(!N.getNode() && "Already set a value for this node!");
Dan Gohman575fad32008-09-03 16:12:24 +0000693 N = NewN;
694 }
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000695
Devang Patelb0c76392010-06-01 19:59:01 +0000696 void setUnusedArgValue(const Value *V, SDValue NewN) {
697 SDValue &N = UnusedArgNodeMap[V];
Craig Topperada08572014-04-16 04:21:27 +0000698 assert(!N.getNode() && "Already set a value for this node!");
Devang Patelb0c76392010-06-01 19:59:01 +0000699 N = NewN;
700 }
Dan Gohman575fad32008-09-03 16:12:24 +0000701
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000702 void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohman575fad32008-09-03 16:12:24 +0000703 MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
Pete Cooper69234612015-07-15 01:31:26 +0000704 MachineBasicBlock *SwitchBB,
Cong Hou1938f2e2015-11-24 08:51:23 +0000705 Instruction::BinaryOps Opc, BranchProbability TW,
Geoff Berry92a286a2017-01-24 16:36:07 +0000706 BranchProbability FW, bool InvertCond);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000707 void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohmand01ddb52008-10-17 21:16:08 +0000708 MachineBasicBlock *FBB,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000709 MachineBasicBlock *CurBB,
Manman Ren4ece7452014-01-31 00:42:44 +0000710 MachineBasicBlock *SwitchBB,
Geoff Berry92a286a2017-01-24 16:36:07 +0000711 BranchProbability TW, BranchProbability FW,
712 bool InvertCond);
Dan Gohman575fad32008-09-03 16:12:24 +0000713 bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000714 bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
715 void CopyToExportRegsIfNeeded(const Value *V);
716 void ExportFromCurrentBlock(const Value *V);
717 void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
Reid Kleckner51189f0a2015-09-08 23:28:38 +0000718 const BasicBlock *EHPadBB = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000719
Matt Arsenault2bba7792016-02-08 16:28:19 +0000720 // Lower range metadata from 0 to N to assert zext to an integer of nearest
721 // floor power of two.
722 SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I,
723 SDValue Op);
724
Sanjoy Das19c61592016-03-16 20:49:31 +0000725 void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI,
726 ImmutableCallSite CS, unsigned ArgIdx,
727 unsigned NumArgs, SDValue Callee,
728 Type *ReturnTy, bool IsPatchPoint);
729
730 std::pair<SDValue, SDValue>
731 lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
732 const BasicBlock *EHPadBB = nullptr);
Andrew Trick74f4c742013-10-31 17:18:24 +0000733
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000734 /// UpdateSplitBlock - When an MBB was split during scheduling, update the
Alp Toker798060e2014-01-11 14:01:43 +0000735 /// references that need to refer to the last resulting block.
Jakob Stoklund Olesen665aa6e2010-09-30 19:44:31 +0000736 void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
737
Sanjoy Das70697ff2016-03-16 23:08:00 +0000738 /// Describes a gc.statepoint or a gc.statepoint like thing for the purposes
Sanjoy Dasa5b29722016-03-23 02:28:35 +0000739 /// of lowering into a STATEPOINT node.
Sanjoy Das70697ff2016-03-16 23:08:00 +0000740 struct StatepointLoweringInfo {
741 /// Bases[i] is the base pointer for Ptrs[i]. Together they denote the set
742 /// of gc pointers this STATEPOINT has to relocate.
Sanjoy Dase58ca592016-03-23 02:24:07 +0000743 SmallVector<const Value *, 16> Bases;
744 SmallVector<const Value *, 16> Ptrs;
Sanjoy Das70697ff2016-03-16 23:08:00 +0000745
746 /// The set of gc.relocate calls associated with this gc.statepoint.
Sanjoy Dase58ca592016-03-23 02:24:07 +0000747 SmallVector<const GCRelocateInst *, 16> GCRelocates;
Sanjoy Das70697ff2016-03-16 23:08:00 +0000748
749 /// The full list of gc arguments to the gc.statepoint being lowered.
750 ArrayRef<const Use> GCArgs;
751
752 /// The gc.statepoint instruction.
753 const Instruction *StatepointInstr = nullptr;
754
755 /// The list of gc transition arguments present in the gc.statepoint being
756 /// lowered.
757 ArrayRef<const Use> GCTransitionArgs;
758
759 /// The ID that the resulting STATEPOINT instruction has to report.
760 unsigned ID = -1;
761
762 /// Information regarding the underlying call instruction.
763 TargetLowering::CallLoweringInfo CLI;
764
765 /// The deoptimization state associated with this gc.statepoint call, if
766 /// any.
767 ArrayRef<const Use> DeoptState;
768
769 /// Flags associated with the meta arguments being lowered.
770 uint64_t StatepointFlags = -1;
771
772 /// The number of patchable bytes the call needs to get lowered into.
773 unsigned NumPatchBytes = -1;
774
775 /// The exception handling unwind destination, in case this represents an
776 /// invoke of gc.statepoint.
777 const BasicBlock *EHPadBB = nullptr;
778
779 explicit StatepointLoweringInfo(SelectionDAG &DAG) : CLI(DAG) {}
780 };
781
782 /// Lower \p SLI into a STATEPOINT instruction.
Sanjoy Das38bfc222016-03-22 00:59:13 +0000783 SDValue LowerAsSTATEPOINT(StatepointLoweringInfo &SLI);
Sanjoy Das70697ff2016-03-16 23:08:00 +0000784
Igor Laevsky7fc58a42015-02-20 15:28:35 +0000785 // This function is responsible for the whole statepoint lowering process.
Igor Laevsky85f7f722015-03-10 16:26:48 +0000786 // It uniformly handles invoke and call statepoints.
787 void LowerStatepoint(ImmutableStatepoint Statepoint,
Reid Kleckner51189f0a2015-09-08 23:28:38 +0000788 const BasicBlock *EHPadBB = nullptr);
Sanjoy Das38bfc222016-03-22 00:59:13 +0000789
790 void LowerCallSiteWithDeoptBundle(ImmutableCallSite CS, SDValue Callee,
791 const BasicBlock *EHPadBB);
792
Sanjoy Dasdf9ae702016-03-24 20:23:29 +0000793 void LowerDeoptimizeCall(const CallInst *CI);
Sanjoy Das65a60672016-04-06 01:33:49 +0000794 void LowerDeoptimizingReturn();
Sanjoy Dasdf9ae702016-03-24 20:23:29 +0000795
Sanjoy Dasfd3eaa82016-03-24 22:51:49 +0000796 void LowerCallSiteWithDeoptBundleImpl(ImmutableCallSite CS, SDValue Callee,
797 const BasicBlock *EHPadBB,
Sanjoy Das65a60672016-04-06 01:33:49 +0000798 bool VarArgDisallowed,
799 bool ForceVoidReturnTy);
Sanjoy Dasfd3eaa82016-03-24 22:51:49 +0000800
Sanjoy Das40c32dd2017-04-27 17:17:16 +0000801 /// Returns the type of FrameIndex and TargetFrameIndex nodes.
802 MVT getFrameIndexTy() {
803 return DAG.getTargetLoweringInfo().getFrameIndexTy(DAG.getDataLayout());
804 }
805
Dan Gohman575fad32008-09-03 16:12:24 +0000806private:
807 // Terminator instructions.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000808 void visitRet(const ReturnInst &I);
809 void visitBr(const BranchInst &I);
810 void visitSwitch(const SwitchInst &I);
811 void visitIndirectBr(const IndirectBrInst &I);
Yaron Kerend7ba46b2014-04-19 13:47:43 +0000812 void visitUnreachable(const UnreachableInst &I);
David Majnemer654e1302015-07-31 17:58:14 +0000813 void visitCleanupRet(const CleanupReturnInst &I);
David Majnemer8a1c45d2015-12-12 05:38:55 +0000814 void visitCatchSwitch(const CatchSwitchInst &I);
David Majnemer654e1302015-07-31 17:58:14 +0000815 void visitCatchRet(const CatchReturnInst &I);
816 void visitCatchPad(const CatchPadInst &I);
David Majnemer654e1302015-07-31 17:58:14 +0000817 void visitCleanupPad(const CleanupPadInst &CPI);
Dan Gohman575fad32008-09-03 16:12:24 +0000818
Cong Hou1938f2e2015-11-24 08:51:23 +0000819 BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
820 const MachineBasicBlock *Dst) const;
821 void addSuccessorWithProb(
822 MachineBasicBlock *Src, MachineBasicBlock *Dst,
823 BranchProbability Prob = BranchProbability::getUnknown());
824
Dan Gohman575fad32008-09-03 16:12:24 +0000825public:
Dan Gohman7c0303a2010-04-19 22:41:47 +0000826 void visitSwitchCase(CaseBlock &CB,
827 MachineBasicBlock *SwitchBB);
Michael Gottesmanb27f0f12013-08-20 07:00:16 +0000828 void visitSPDescriptorParent(StackProtectorDescriptor &SPD,
829 MachineBasicBlock *ParentBB);
830 void visitSPDescriptorFailure(StackProtectorDescriptor &SPD);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000831 void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB);
Evan Chengac730dd2011-01-06 01:02:44 +0000832 void visitBitTestCase(BitTestBlock &BB,
833 MachineBasicBlock* NextMBB,
Cong Hou1938f2e2015-11-24 08:51:23 +0000834 BranchProbability BranchProbToNext,
Dan Gohman575fad32008-09-03 16:12:24 +0000835 unsigned Reg,
Dan Gohman7c0303a2010-04-19 22:41:47 +0000836 BitTestCase &B,
837 MachineBasicBlock *SwitchBB);
Dan Gohman575fad32008-09-03 16:12:24 +0000838 void visitJumpTable(JumpTable &JT);
Dan Gohman7c0303a2010-04-19 22:41:47 +0000839 void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH,
840 MachineBasicBlock *SwitchBB);
Andrew Trickd4d1d9c2013-10-31 17:18:07 +0000841
Dan Gohman575fad32008-09-03 16:12:24 +0000842private:
843 // These all get lowered before this pass.
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000844 void visitInvoke(const InvokeInst &I);
Bill Wendlingf891bf82011-07-31 06:30:59 +0000845 void visitResume(const ResumeInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000846
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000847 void visitBinary(const User &I, unsigned OpCode);
848 void visitShift(const User &I, unsigned Opcode);
849 void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
850 void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
851 void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
852 void visitFSub(const User &I);
853 void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
854 void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
855 void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
856 void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
857 void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
858 void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
Benjamin Kramer9960a252011-07-08 10:31:30 +0000859 void visitSDiv(const User &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000860 void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
861 void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
862 void visitOr (const User &I) { visitBinary(I, ISD::OR); }
863 void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
864 void visitShl (const User &I) { visitShift(I, ISD::SHL); }
865 void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
866 void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
867 void visitICmp(const User &I);
868 void visitFCmp(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000869 // Visit the conversion instructions
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000870 void visitTrunc(const User &I);
871 void visitZExt(const User &I);
872 void visitSExt(const User &I);
873 void visitFPTrunc(const User &I);
874 void visitFPExt(const User &I);
875 void visitFPToUI(const User &I);
876 void visitFPToSI(const User &I);
877 void visitUIToFP(const User &I);
878 void visitSIToFP(const User &I);
879 void visitPtrToInt(const User &I);
880 void visitIntToPtr(const User &I);
881 void visitBitCast(const User &I);
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000882 void visitAddrSpaceCast(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000883
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000884 void visitExtractElement(const User &I);
885 void visitInsertElement(const User &I);
886 void visitShuffleVector(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000887
Simon Pilgrim55a4b672017-07-09 16:01:04 +0000888 void visitExtractValue(const User &I);
889 void visitInsertValue(const User &I);
Bill Wendlingfae14752011-08-12 20:24:12 +0000890 void visitLandingPad(const LandingPadInst &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000891
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000892 void visitGetElementPtr(const User &I);
893 void visitSelect(const User &I);
Dan Gohman575fad32008-09-03 16:12:24 +0000894
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000895 void visitAlloca(const AllocaInst &I);
896 void visitLoad(const LoadInst &I);
897 void visitStore(const StoreInst &I);
Elena Demikhovskycaaceef2016-11-03 03:23:55 +0000898 void visitMaskedLoad(const CallInst &I, bool IsExpanding = false);
899 void visitMaskedStore(const CallInst &I, bool IsCompressing = false);
Elena Demikhovsky584ce372015-04-28 07:57:37 +0000900 void visitMaskedGather(const CallInst &I);
901 void visitMaskedScatter(const CallInst &I);
Eli Friedmanc9a551e2011-07-28 21:48:00 +0000902 void visitAtomicCmpXchg(const AtomicCmpXchgInst &I);
903 void visitAtomicRMW(const AtomicRMWInst &I);
Eli Friedmanfee02c62011-07-25 23:16:38 +0000904 void visitFence(const FenceInst &I);
Dan Gohmanf41ad472010-04-20 15:00:41 +0000905 void visitPHI(const PHINode &I);
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000906 void visitCall(const CallInst &I);
907 bool visitMemCmpCall(const CallInst &I);
Andrew Kaylorb99d1cc2016-07-29 18:23:18 +0000908 bool visitMemPCpyCall(const CallInst &I);
Richard Sandiford6f6d5512013-08-20 09:38:48 +0000909 bool visitMemChrCall(const CallInst &I);
Richard Sandifordbb83a502013-08-16 11:29:37 +0000910 bool visitStrCpyCall(const CallInst &I, bool isStpcpy);
Richard Sandifordca232712013-08-16 11:21:54 +0000911 bool visitStrCmpCall(const CallInst &I);
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000912 bool visitStrLenCall(const CallInst &I);
913 bool visitStrNLenCall(const CallInst &I);
Bob Wilson874886c2012-08-03 23:29:17 +0000914 bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode);
Matt Arsenault7c936902014-10-21 23:01:01 +0000915 bool visitBinaryFloatCall(const CallInst &I, unsigned Opcode);
Eli Friedman342e8df2011-08-24 20:50:09 +0000916 void visitAtomicLoad(const LoadInst &I);
917 void visitAtomicStore(const StoreInst &I);
Manman Rene221a872016-04-05 18:13:16 +0000918 void visitLoadFromSwiftError(const LoadInst &I);
919 void visitStoreToSwiftError(const StoreInst &I);
Eli Friedman342e8df2011-08-24 20:50:09 +0000920
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000921 void visitInlineAsm(ImmutableCallSite CS);
922 const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
923 void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
Andrew Kaylorf4660012017-05-25 21:31:00 +0000924 void visitConstrainedFPIntrinsic(const ConstrainedFPIntrinsic &FPI);
Dan Gohman575fad32008-09-03 16:12:24 +0000925
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000926 void visitVAStart(const CallInst &I);
927 void visitVAArg(const VAArgInst &I);
928 void visitVAEnd(const CallInst &I);
929 void visitVACopy(const CallInst &I);
Andrew Trick74f4c742013-10-31 17:18:24 +0000930 void visitStackmap(const CallInst &I);
Juergen Ributzkaad2363f2014-10-17 17:39:00 +0000931 void visitPatchpoint(ImmutableCallSite CS,
Reid Kleckner51189f0a2015-09-08 23:28:38 +0000932 const BasicBlock *EHPadBB = nullptr);
Dan Gohman575fad32008-09-03 16:12:24 +0000933
Sanjoy Das3a020192016-03-17 00:47:14 +0000934 // These two are implemented in StatepointLowering.cpp
Manuel Jacob83eefa62016-01-05 04:03:00 +0000935 void visitGCRelocate(const GCRelocateInst &I);
Philip Reames92d1f0c2016-04-12 18:05:10 +0000936 void visitGCResult(const GCResultInst &I);
Philip Reames1a1bdb22014-12-02 18:50:36 +0000937
Amara Emersoncf9daa32017-05-09 10:43:25 +0000938 void visitVectorReduce(const CallInst &I, unsigned Intrinsic);
939
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000940 void visitUserOp1(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000941 llvm_unreachable("UserOp1 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000942 }
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000943 void visitUserOp2(const Instruction &I) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000944 llvm_unreachable("UserOp2 should not exist at instruction selection time!");
Dan Gohman575fad32008-09-03 16:12:24 +0000945 }
Dan Gohman5b43aa02010-04-22 20:55:53 +0000946
Richard Sandiforde3827752013-08-16 10:55:47 +0000947 void processIntegerCallValue(const Instruction &I,
948 SDValue Value, bool IsSigned);
949
Dan Gohman5b43aa02010-04-22 20:55:53 +0000950 void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
Evan Cheng6e822452010-04-28 23:08:54 +0000951
Renato Golin38ed8022016-05-17 19:52:01 +0000952 void emitInlineAsmError(ImmutableCallSite CS, const Twine &Message);
953
Adrian Prantla6175762017-07-28 21:27:35 +0000954 /// If V is an function argument then create corresponding DBG_VALUE machine
955 /// instruction for it now. At the end of instruction selection, they will be
956 /// inserted to the entry BB.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000957 bool EmitFuncArgumentDbgValue(const Value *V, DILocalVariable *Variable,
958 DIExpression *Expr, DILocation *DL,
Adrian Prantla6175762017-07-28 21:27:35 +0000959 bool IsDbgDeclare, const SDValue &N);
Hans Wennborgb4db1422015-03-19 20:41:48 +0000960
961 /// Return the next block after MBB, or nullptr if there is none.
962 MachineBasicBlock *NextBlock(MachineBasicBlock *MBB);
Krzysztof Parzyszeka46c36b2015-04-13 17:16:45 +0000963
964 /// Update the DAG and DAG builder with the relevant information after
965 /// a new root node has been created which could be a tail call.
966 void updateDAGForMaybeTailCall(SDValue MaybeTC);
Wolfgang Piebdfad9b22016-08-15 18:18:26 +0000967
968 /// Return the appropriate SDDbgValue based on N.
969 SDDbgValue *getDbgValue(SDValue N, DILocalVariable *Variable,
Adrian Prantla6175762017-07-28 21:27:35 +0000970 DIExpression *Expr, const DebugLoc &dl,
971 unsigned DbgSDNodeOrder);
Dan Gohman575fad32008-09-03 16:12:24 +0000972};
973
Sanjoy Das3936a972015-05-05 23:06:54 +0000974/// RegsForValue - This struct represents the registers (physical or virtual)
975/// that a particular set of values is assigned, and the type information about
976/// the value. The most common situation is to represent one value at a time,
977/// but struct or array values are handled element-wise as multiple values. The
978/// splitting of aggregates is performed recursively, so that we never have
979/// aggregate-typed registers. The values at this point do not necessarily have
980/// legal types, so each value may require one or more registers of some legal
981/// type.
982///
983struct RegsForValue {
Sanjay Patel209b0f92017-03-02 20:48:08 +0000984 /// The value types of the values, which may not be legal, and
Sanjoy Das3936a972015-05-05 23:06:54 +0000985 /// may need be promoted or synthesized from one or more registers.
Sanjoy Das3936a972015-05-05 23:06:54 +0000986 SmallVector<EVT, 4> ValueVTs;
987
Sanjay Patel209b0f92017-03-02 20:48:08 +0000988 /// The value types of the registers. This is the same size as ValueVTs and it
989 /// records, for each value, what the type of the assigned register or
990 /// registers are. (Individual values are never synthesized from more than one
991 /// type of register.)
Sanjoy Das3936a972015-05-05 23:06:54 +0000992 ///
993 /// With virtual registers, the contents of RegVTs is redundant with TLI's
994 /// getRegisterType member function, however when with physical registers
995 /// it is necessary to have a separate record of the types.
Sanjoy Das3936a972015-05-05 23:06:54 +0000996 SmallVector<MVT, 4> RegVTs;
997
Sanjay Patel209b0f92017-03-02 20:48:08 +0000998 /// This list holds the registers assigned to the values.
Sanjoy Das3936a972015-05-05 23:06:54 +0000999 /// Each legal or promoted value requires one register, and each
1000 /// expanded value requires multiple registers.
Sanjoy Das3936a972015-05-05 23:06:54 +00001001 SmallVector<unsigned, 4> Regs;
1002
Simon Dardis212cccb2017-06-09 14:37:08 +00001003 /// This list holds the number of registers for each value.
1004 SmallVector<unsigned, 4> RegCount;
1005
1006 /// Records if this value needs to be treated in an ABI dependant manner,
1007 /// different to normal type legalization.
Eugene Zelenkofa57bd02017-09-27 23:26:01 +00001008 bool IsABIMangled = false;
Simon Dardis212cccb2017-06-09 14:37:08 +00001009
Eugene Zelenkofa57bd02017-09-27 23:26:01 +00001010 RegsForValue() = default;
Simon Dardis212cccb2017-06-09 14:37:08 +00001011 RegsForValue(const SmallVector<unsigned, 4> &regs, MVT regvt, EVT valuevt,
1012 bool IsABIMangledValue = false);
Mehdi Amini56228da2015-07-09 01:57:34 +00001013 RegsForValue(LLVMContext &Context, const TargetLowering &TLI,
Simon Dardis212cccb2017-06-09 14:37:08 +00001014 const DataLayout &DL, unsigned Reg, Type *Ty,
1015 bool IsABIMangledValue = false);
Sanjoy Das3936a972015-05-05 23:06:54 +00001016
Sanjay Patel209b0f92017-03-02 20:48:08 +00001017 /// Add the specified values to this one.
Sanjoy Das3936a972015-05-05 23:06:54 +00001018 void append(const RegsForValue &RHS) {
1019 ValueVTs.append(RHS.ValueVTs.begin(), RHS.ValueVTs.end());
1020 RegVTs.append(RHS.RegVTs.begin(), RHS.RegVTs.end());
1021 Regs.append(RHS.Regs.begin(), RHS.Regs.end());
Simon Dardis212cccb2017-06-09 14:37:08 +00001022 RegCount.push_back(RHS.Regs.size());
Sanjoy Das3936a972015-05-05 23:06:54 +00001023 }
1024
Sanjay Patel209b0f92017-03-02 20:48:08 +00001025 /// Emit a series of CopyFromReg nodes that copies from this value and returns
1026 /// the result as a ValueVTs value. This uses Chain/Flag as the input and
1027 /// updates them for the output Chain/Flag. If the Flag pointer is NULL, no
1028 /// flag is used.
Sanjoy Das3936a972015-05-05 23:06:54 +00001029 SDValue getCopyFromRegs(SelectionDAG &DAG, FunctionLoweringInfo &FuncInfo,
Benjamin Kramerbdc49562016-06-12 15:39:02 +00001030 const SDLoc &dl, SDValue &Chain, SDValue *Flag,
Sanjoy Das3936a972015-05-05 23:06:54 +00001031 const Value *V = nullptr) const;
1032
Sanjay Patel209b0f92017-03-02 20:48:08 +00001033 /// Emit a series of CopyToReg nodes that copies the specified value into the
1034 /// registers specified by this object. This uses Chain/Flag as the input and
1035 /// updates them for the output Chain/Flag. If the Flag pointer is nullptr, no
1036 /// flag is used. If V is not nullptr, then it is used in printing better
1037 /// diagnostic messages on error.
Benjamin Kramerbdc49562016-06-12 15:39:02 +00001038 void getCopyToRegs(SDValue Val, SelectionDAG &DAG, const SDLoc &dl,
1039 SDValue &Chain, SDValue *Flag, const Value *V = nullptr,
1040 ISD::NodeType PreferredExtendType = ISD::ANY_EXTEND) const;
Sanjoy Das3936a972015-05-05 23:06:54 +00001041
Sanjay Patel209b0f92017-03-02 20:48:08 +00001042 /// Add this value to the specified inlineasm node operand list. This adds the
1043 /// code marker, matching input operand index (if applicable), and includes
1044 /// the number of values added into it.
Benjamin Kramerbdc49562016-06-12 15:39:02 +00001045 void AddInlineAsmOperands(unsigned Kind, bool HasMatching,
1046 unsigned MatchingIdx, const SDLoc &dl,
1047 SelectionDAG &DAG, std::vector<SDValue> &Ops) const;
Sanjoy Das3936a972015-05-05 23:06:54 +00001048};
1049
Dan Gohman575fad32008-09-03 16:12:24 +00001050} // end namespace llvm
1051
Eugene Zelenkofa57bd02017-09-27 23:26:01 +00001052#endif // LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H