blob: 454a87e4410e0a4b3f51436db0a86f36850ce925 [file] [log] [blame]
Dan Gohman2048b852009-11-23 18:04:58 +00001//===-- SelectionDAGBuilder.h - Selection-DAG building --------------------===//
Dan Gohmanf0cbcd42008-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
Dan Gohman2048b852009-11-23 18:04:58 +000014#ifndef SELECTIONDAGBUILDER_H
15#define SELECTIONDAGBUILDER_H
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000016
17#include "llvm/Constants.h"
Owen Anderson0a5372e2009-07-13 04:09:18 +000018#include "llvm/CodeGen/SelectionDAG.h"
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000019#include "llvm/ADT/APInt.h"
20#include "llvm/ADT/DenseMap.h"
21#ifndef NDEBUG
22#include "llvm/ADT/SmallSet.h"
23#endif
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000024#include "llvm/CodeGen/SelectionDAGNodes.h"
Bill Wendling0eb96fd2009-02-03 01:32:22 +000025#include "llvm/CodeGen/ValueTypes.h"
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000026#include "llvm/Support/CallSite.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000027#include "llvm/Support/ErrorHandling.h"
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000028#include <vector>
29#include <set>
30
31namespace llvm {
32
33class AliasAnalysis;
34class AllocaInst;
35class BasicBlock;
36class BitCastInst;
37class BranchInst;
38class CallInst;
39class ExtractElementInst;
40class ExtractValueInst;
41class FCmpInst;
42class FPExtInst;
43class FPToSIInst;
44class FPToUIInst;
45class FPTruncInst;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000046class Function;
Dan Gohman6277eb22009-11-23 17:16:22 +000047class FunctionLoweringInfo;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000048class GetElementPtrInst;
49class GCFunctionInfo;
50class ICmpInst;
51class IntToPtrInst;
Chris Lattnerab21db72009-10-28 00:19:10 +000052class IndirectBrInst;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000053class InvokeInst;
54class InsertElementInst;
55class InsertValueInst;
56class Instruction;
57class LoadInst;
58class MachineBasicBlock;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000059class MachineInstr;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000060class MachineRegisterInfo;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000061class PHINode;
62class PtrToIntInst;
63class ReturnInst;
64class SDISelAsmOperandInfo;
65class SExtInst;
66class SelectInst;
67class ShuffleVectorInst;
68class SIToFPInst;
69class StoreInst;
70class SwitchInst;
71class TargetData;
72class TargetLowering;
73class TruncInst;
74class UIToFPInst;
75class UnreachableInst;
76class UnwindInst;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000077class VAArgInst;
78class ZExtInst;
79
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000080//===----------------------------------------------------------------------===//
Dan Gohman2048b852009-11-23 18:04:58 +000081/// SelectionDAGBuilder - This is the common target-independent lowering
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000082/// implementation that is parameterized by a TargetLowering object.
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000083///
Dan Gohman2048b852009-11-23 18:04:58 +000084class SelectionDAGBuilder {
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000085 MachineBasicBlock *CurMBB;
86
Dale Johannesen66978ee2009-01-31 02:22:37 +000087 /// CurDebugLoc - current file + line number. Changes as we build the DAG.
88 DebugLoc CurDebugLoc;
89
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000090 DenseMap<const Value*, SDValue> NodeMap;
91
Chris Lattner8047d9a2009-12-24 00:37:38 +000092public:
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000093 /// PendingLoads - Loads are not emitted to the program immediately. We bunch
94 /// them up and then emit token factor nodes when possible. This allows us to
95 /// get simple disambiguation between loads without worrying about alias
96 /// analysis.
97 SmallVector<SDValue, 8> PendingLoads;
Chris Lattner8047d9a2009-12-24 00:37:38 +000098private:
Dan Gohmanf0cbcd42008-09-03 16:12:24 +000099
100 /// PendingExports - CopyToReg nodes that copy values to virtual registers
101 /// for export to other blocks need to be emitted before any terminator
102 /// instruction, but they have no other ordering requirements. We bunch them
103 /// up and the emit a single tokenfactor for them just before terminator
104 /// instructions.
105 SmallVector<SDValue, 8> PendingExports;
106
Bill Wendlingb4e6a5d2009-12-18 23:32:53 +0000107 /// SDNodeOrder - A unique monotonically increasing number used to order the
108 /// SDNodes we create.
109 unsigned SDNodeOrder;
110
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000111 /// Case - A struct to record the Value for a switch case, and the
112 /// case's target basic block.
113 struct Case {
114 Constant* Low;
115 Constant* High;
116 MachineBasicBlock* BB;
117
118 Case() : Low(0), High(0), BB(0) { }
119 Case(Constant* low, Constant* high, MachineBasicBlock* bb) :
120 Low(low), High(high), BB(bb) { }
Chris Lattnere880efe2009-11-07 07:50:34 +0000121 APInt size() const {
122 const APInt &rHigh = cast<ConstantInt>(High)->getValue();
123 const APInt &rLow = cast<ConstantInt>(Low)->getValue();
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000124 return (rHigh - rLow + 1ULL);
125 }
126 };
127
128 struct CaseBits {
129 uint64_t Mask;
130 MachineBasicBlock* BB;
131 unsigned Bits;
132
133 CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits):
134 Mask(mask), BB(bb), Bits(bits) { }
135 };
136
137 typedef std::vector<Case> CaseVector;
138 typedef std::vector<CaseBits> CaseBitsVector;
139 typedef CaseVector::iterator CaseItr;
140 typedef std::pair<CaseItr, CaseItr> CaseRange;
141
142 /// CaseRec - A struct with ctor used in lowering switches to a binary tree
143 /// of conditional branches.
144 struct CaseRec {
Dan Gohman46510a72010-04-15 01:51:59 +0000145 CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
146 CaseRange r) :
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000147 CaseBB(bb), LT(lt), GE(ge), Range(r) {}
148
149 /// CaseBB - The MBB in which to emit the compare and branch
150 MachineBasicBlock *CaseBB;
151 /// LT, GE - If nonzero, we know the current case value must be less-than or
152 /// greater-than-or-equal-to these Constants.
Dan Gohman46510a72010-04-15 01:51:59 +0000153 const Constant *LT;
154 const Constant *GE;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000155 /// Range - A pair of iterators representing the range of case values to be
156 /// processed at this point in the binary search tree.
157 CaseRange Range;
158 };
159
160 typedef std::vector<CaseRec> CaseRecVector;
161
162 /// The comparison function for sorting the switch case values in the vector.
163 /// WARNING: Case ranges should be disjoint!
164 struct CaseCmp {
Chris Lattner53334ca2010-01-01 23:37:34 +0000165 bool operator()(const Case &C1, const Case &C2) {
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000166 assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High));
167 const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
168 const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
169 return CI1->getValue().slt(CI2->getValue());
170 }
171 };
172
173 struct CaseBitsCmp {
Chris Lattner53334ca2010-01-01 23:37:34 +0000174 bool operator()(const CaseBits &C1, const CaseBits &C2) {
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000175 return C1.Bits > C2.Bits;
176 }
177 };
178
Chris Lattner53334ca2010-01-01 23:37:34 +0000179 size_t Clusterify(CaseVector &Cases, const SwitchInst &SI);
Anton Korobeynikov23218582008-12-23 22:25:27 +0000180
Dan Gohman2048b852009-11-23 18:04:58 +0000181 /// CaseBlock - This structure is used to communicate between
182 /// SelectionDAGBuilder and SDISel for the code generation of additional basic
183 /// blocks needed by multi-case switch statements.
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000184 struct CaseBlock {
Dan Gohman46510a72010-04-15 01:51:59 +0000185 CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
186 const Value *cmpmiddle,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000187 MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
188 MachineBasicBlock *me)
189 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
190 TrueBB(truebb), FalseBB(falsebb), ThisBB(me) {}
191 // CC - the condition code to use for the case block's setcc node
192 ISD::CondCode CC;
193 // CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
194 // Emit by default LHS op RHS. MHS is used for range comparisons:
195 // If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
Dan Gohman46510a72010-04-15 01:51:59 +0000196 const Value *CmpLHS, *CmpMHS, *CmpRHS;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000197 // TrueBB/FalseBB - the block to branch to if the setcc is true/false.
198 MachineBasicBlock *TrueBB, *FalseBB;
199 // ThisBB - the block into which to emit the code for the setcc and branches
200 MachineBasicBlock *ThisBB;
201 };
202 struct JumpTable {
203 JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
204 MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
205
206 /// Reg - the virtual register containing the index of the jump table entry
207 //. to jump to.
208 unsigned Reg;
209 /// JTI - the JumpTableIndex for this jump table in the function.
210 unsigned JTI;
211 /// MBB - the MBB into which to emit the code for the indirect jump.
212 MachineBasicBlock *MBB;
213 /// Default - the MBB of the default bb, which is a successor of the range
214 /// check MBB. This is when updating PHI nodes in successors.
215 MachineBasicBlock *Default;
216 };
217 struct JumpTableHeader {
Dan Gohman46510a72010-04-15 01:51:59 +0000218 JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000219 bool E = false):
220 First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
Anton Korobeynikov23218582008-12-23 22:25:27 +0000221 APInt First;
222 APInt Last;
Dan Gohman46510a72010-04-15 01:51:59 +0000223 const Value *SValue;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000224 MachineBasicBlock *HeaderBB;
225 bool Emitted;
226 };
227 typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock;
228
229 struct BitTestCase {
230 BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr):
231 Mask(M), ThisBB(T), TargetBB(Tr) { }
232 uint64_t Mask;
Chris Lattner53334ca2010-01-01 23:37:34 +0000233 MachineBasicBlock *ThisBB;
234 MachineBasicBlock *TargetBB;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000235 };
236
237 typedef SmallVector<BitTestCase, 3> BitTestInfo;
238
239 struct BitTestBlock {
Dan Gohman46510a72010-04-15 01:51:59 +0000240 BitTestBlock(APInt F, APInt R, const Value* SV,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000241 unsigned Rg, bool E,
242 MachineBasicBlock* P, MachineBasicBlock* D,
243 const BitTestInfo& C):
244 First(F), Range(R), SValue(SV), Reg(Rg), Emitted(E),
245 Parent(P), Default(D), Cases(C) { }
Anton Korobeynikov23218582008-12-23 22:25:27 +0000246 APInt First;
247 APInt Range;
Dan Gohman46510a72010-04-15 01:51:59 +0000248 const Value *SValue;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000249 unsigned Reg;
250 bool Emitted;
251 MachineBasicBlock *Parent;
252 MachineBasicBlock *Default;
253 BitTestInfo Cases;
254 };
255
256public:
257 // TLI - This is information that describes the available target features we
258 // need for lowering. This indicates when operations are unavailable,
259 // implemented with a libcall, etc.
260 TargetLowering &TLI;
261 SelectionDAG &DAG;
262 const TargetData *TD;
263 AliasAnalysis *AA;
264
265 /// SwitchCases - Vector of CaseBlock structures used to communicate
266 /// SwitchInst code generation information.
267 std::vector<CaseBlock> SwitchCases;
268 /// JTCases - Vector of JumpTable structures used to communicate
269 /// SwitchInst code generation information.
270 std::vector<JumpTableBlock> JTCases;
271 /// BitTestCases - Vector of BitTestBlock structures used to communicate
272 /// SwitchInst code generation information.
273 std::vector<BitTestBlock> BitTestCases;
Evan Chengfb2e7522009-09-18 21:02:19 +0000274
275 /// PHINodesToUpdate - A list of phi instructions whose operand list will
276 /// be updated after processing the current basic block.
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000277 std::vector<std::pair<MachineInstr*, unsigned> > PHINodesToUpdate;
278
Evan Chengfb2e7522009-09-18 21:02:19 +0000279 /// EdgeMapping - If an edge from CurMBB to any MBB is changed (e.g. due to
280 /// scheduler custom lowering), track the change here.
281 DenseMap<MachineBasicBlock*, MachineBasicBlock*> EdgeMapping;
282
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000283 // Emit PHI-node-operand constants only once even if used by multiple
284 // PHI nodes.
Dan Gohman46510a72010-04-15 01:51:59 +0000285 DenseMap<const Constant *, unsigned> ConstantsOut;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000286
287 /// FuncInfo - Information about the function as a whole.
288 ///
289 FunctionLoweringInfo &FuncInfo;
Bill Wendlingdfdacee2009-02-19 21:12:54 +0000290
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000291 /// OptLevel - What optimization level we're generating code for.
Bill Wendlingdfdacee2009-02-19 21:12:54 +0000292 ///
Bill Wendling98a366d2009-04-29 23:29:43 +0000293 CodeGenOpt::Level OptLevel;
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000294
295 /// GFI - Garbage collection metadata for the function.
296 GCFunctionInfo *GFI;
297
Dan Gohman98ca4f22009-08-05 01:29:28 +0000298 /// HasTailCall - This is set to true if a call in the current
299 /// block has been translated as a tail call. In this case,
300 /// no subsequent DAG nodes should be created.
301 ///
302 bool HasTailCall;
303
Owen Anderson0a5372e2009-07-13 04:09:18 +0000304 LLVMContext *Context;
305
Dan Gohman2048b852009-11-23 18:04:58 +0000306 SelectionDAGBuilder(SelectionDAG &dag, TargetLowering &tli,
307 FunctionLoweringInfo &funcinfo,
308 CodeGenOpt::Level ol)
Chris Lattnera4f2bb02010-04-02 20:17:23 +0000309 : SDNodeOrder(0), TLI(tli), DAG(dag), FuncInfo(funcinfo), OptLevel(ol),
310 HasTailCall(false), Context(dag.getContext()) {
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000311 }
312
313 void init(GCFunctionInfo *gfi, AliasAnalysis &aa);
314
Dan Gohmanb02b62a2010-04-14 18:24:06 +0000315 /// clear - Clear out the current SelectionDAG and the associated
Dan Gohman2048b852009-11-23 18:04:58 +0000316 /// state and prepare this SelectionDAGBuilder object to be used
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000317 /// for a new block. This doesn't clear out information about
318 /// additional blocks that are needed to complete switch lowering
319 /// or PHI node updating; that information is cleared out as it is
320 /// consumed.
321 void clear();
322
323 /// getRoot - Return the current virtual root of the Selection DAG,
324 /// flushing any PendingLoad items. This must be done before emitting
325 /// a store or any other node that may need to be ordered after any
326 /// prior load instructions.
327 ///
328 SDValue getRoot();
329
330 /// getControlRoot - Similar to getRoot, but instead of flushing all the
331 /// PendingLoad items, flush all the PendingExports items. It is necessary
332 /// to do this before emitting a terminator instruction.
333 ///
334 SDValue getControlRoot();
335
Dale Johannesen66978ee2009-01-31 02:22:37 +0000336 DebugLoc getCurDebugLoc() const { return CurDebugLoc; }
Devang Patel390f3ac2009-04-16 01:33:10 +0000337 void setCurDebugLoc(DebugLoc dl) { CurDebugLoc = dl; }
Dale Johannesen66978ee2009-01-31 02:22:37 +0000338
Bill Wendling3ea3c242009-12-22 02:10:19 +0000339 unsigned getSDNodeOrder() const { return SDNodeOrder; }
340
Dan Gohman46510a72010-04-15 01:51:59 +0000341 void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000342
Bill Wendling4533cac2010-01-28 21:51:40 +0000343 /// AssignOrderingToNode - Assign an ordering to the node. The order is gotten
344 /// from how the code appeared in the source. The ordering is used by the
345 /// scheduler to effectively turn off scheduling.
346 void AssignOrderingToNode(const SDNode *Node);
347
Dan Gohman46510a72010-04-15 01:51:59 +0000348 void visit(const Instruction &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000349
Dan Gohman46510a72010-04-15 01:51:59 +0000350 void visit(unsigned Opcode, const User &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000351
352 void setCurrentBasicBlock(MachineBasicBlock *MBB) { CurMBB = MBB; }
353
354 SDValue getValue(const Value *V);
355
356 void setValue(const Value *V, SDValue NewN) {
357 SDValue &N = NodeMap[V];
358 assert(N.getNode() == 0 && "Already set a value for this node!");
359 N = NewN;
360 }
361
Dale Johannesen8e3455b2008-09-24 23:13:09 +0000362 void GetRegistersForValue(SDISelAsmOperandInfo &OpInfo,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000363 std::set<unsigned> &OutputRegs,
364 std::set<unsigned> &InputRegs);
365
Dan Gohman46510a72010-04-15 01:51:59 +0000366 void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000367 MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
368 unsigned Opc);
Dan Gohman46510a72010-04-15 01:51:59 +0000369 void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
Dan Gohmanc2277342008-10-17 21:16:08 +0000370 MachineBasicBlock *FBB,
371 MachineBasicBlock *CurBB);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000372 bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
Dan Gohman46510a72010-04-15 01:51:59 +0000373 bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
374 void CopyToExportRegsIfNeeded(const Value *V);
375 void ExportFromCurrentBlock(const Value *V);
376 void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000377 MachineBasicBlock *LandingPad = NULL);
378
379private:
380 // Terminator instructions.
Dan Gohman46510a72010-04-15 01:51:59 +0000381 void visitRet(const ReturnInst &I);
382 void visitBr(const BranchInst &I);
383 void visitSwitch(const SwitchInst &I);
384 void visitIndirectBr(const IndirectBrInst &I);
385 void visitUnreachable(const UnreachableInst &I) { /* noop */ }
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000386
387 // Helpers for visitSwitch
388 bool handleSmallSwitchRange(CaseRec& CR,
389 CaseRecVector& WorkList,
Dan Gohman46510a72010-04-15 01:51:59 +0000390 const Value* SV,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000391 MachineBasicBlock* Default);
392 bool handleJTSwitchCase(CaseRec& CR,
393 CaseRecVector& WorkList,
Dan Gohman46510a72010-04-15 01:51:59 +0000394 const Value* SV,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000395 MachineBasicBlock* Default);
396 bool handleBTSplitSwitchCase(CaseRec& CR,
397 CaseRecVector& WorkList,
Dan Gohman46510a72010-04-15 01:51:59 +0000398 const Value* SV,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000399 MachineBasicBlock* Default);
400 bool handleBitTestsSwitchCase(CaseRec& CR,
401 CaseRecVector& WorkList,
Dan Gohman46510a72010-04-15 01:51:59 +0000402 const Value* SV,
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000403 MachineBasicBlock* Default);
404public:
405 void visitSwitchCase(CaseBlock &CB);
406 void visitBitTestHeader(BitTestBlock &B);
407 void visitBitTestCase(MachineBasicBlock* NextMBB,
408 unsigned Reg,
409 BitTestCase &B);
410 void visitJumpTable(JumpTable &JT);
411 void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH);
412
413private:
414 // These all get lowered before this pass.
Dan Gohman46510a72010-04-15 01:51:59 +0000415 void visitInvoke(const InvokeInst &I);
416 void visitUnwind(const UnwindInst &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000417
Dan Gohman46510a72010-04-15 01:51:59 +0000418 void visitBinary(const User &I, unsigned OpCode);
419 void visitShift(const User &I, unsigned Opcode);
420 void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
421 void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
422 void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
423 void visitFSub(const User &I);
424 void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
425 void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
426 void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
427 void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
428 void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
429 void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
430 void visitSDiv(const User &I) { visitBinary(I, ISD::SDIV); }
431 void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
432 void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
433 void visitOr (const User &I) { visitBinary(I, ISD::OR); }
434 void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
435 void visitShl (const User &I) { visitShift(I, ISD::SHL); }
436 void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
437 void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
438 void visitICmp(const User &I);
439 void visitFCmp(const User &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000440 // Visit the conversion instructions
Dan Gohman46510a72010-04-15 01:51:59 +0000441 void visitTrunc(const User &I);
442 void visitZExt(const User &I);
443 void visitSExt(const User &I);
444 void visitFPTrunc(const User &I);
445 void visitFPExt(const User &I);
446 void visitFPToUI(const User &I);
447 void visitFPToSI(const User &I);
448 void visitUIToFP(const User &I);
449 void visitSIToFP(const User &I);
450 void visitPtrToInt(const User &I);
451 void visitIntToPtr(const User &I);
452 void visitBitCast(const User &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000453
Dan Gohman46510a72010-04-15 01:51:59 +0000454 void visitExtractElement(const User &I);
455 void visitInsertElement(const User &I);
456 void visitShuffleVector(const User &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000457
Dan Gohman46510a72010-04-15 01:51:59 +0000458 void visitExtractValue(const ExtractValueInst &I);
459 void visitInsertValue(const InsertValueInst &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000460
Dan Gohman46510a72010-04-15 01:51:59 +0000461 void visitGetElementPtr(const User &I);
462 void visitSelect(const User &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000463
Dan Gohman46510a72010-04-15 01:51:59 +0000464 void visitAlloca(const AllocaInst &I);
465 void visitLoad(const LoadInst &I);
466 void visitStore(const StoreInst &I);
467 void visitPHI(const PHINode &I) { } // PHI nodes are handled specially.
468 void visitCall(const CallInst &I);
469 bool visitMemCmpCall(const CallInst &I);
Chris Lattner8047d9a2009-12-24 00:37:38 +0000470
Dan Gohman46510a72010-04-15 01:51:59 +0000471 void visitInlineAsm(ImmutableCallSite CS);
472 const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
473 void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000474
Dan Gohman46510a72010-04-15 01:51:59 +0000475 void visitPow(const CallInst &I);
476 void visitExp2(const CallInst &I);
477 void visitExp(const CallInst &I);
478 void visitLog(const CallInst &I);
479 void visitLog2(const CallInst &I);
480 void visitLog10(const CallInst &I);
Dale Johannesen601d3c02008-09-05 01:48:15 +0000481
Dan Gohman46510a72010-04-15 01:51:59 +0000482 void visitVAStart(const CallInst &I);
483 void visitVAArg(const VAArgInst &I);
484 void visitVAEnd(const CallInst &I);
485 void visitVACopy(const CallInst &I);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000486
Dan Gohman46510a72010-04-15 01:51:59 +0000487 void visitUserOp1(const Instruction &I) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000488 llvm_unreachable("UserOp1 should not exist at instruction selection time!");
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000489 }
Dan Gohman46510a72010-04-15 01:51:59 +0000490 void visitUserOp2(const Instruction &I) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000491 llvm_unreachable("UserOp2 should not exist at instruction selection time!");
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000492 }
493
Dan Gohman46510a72010-04-15 01:51:59 +0000494 const char *implVisitBinaryAtomic(const CallInst& I, ISD::NodeType Op);
495 const char *implVisitAluOverflow(const CallInst &I, ISD::NodeType Op);
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000496};
497
Dan Gohmanf0cbcd42008-09-03 16:12:24 +0000498} // end namespace llvm
499
500#endif