14 #ifndef SELECTIONDAGBUILDER_H
15 #define SELECTIONDAGBUILDER_H
29 class AddrSpaceCastInst;
37 class ExtractElementInst;
38 class ExtractValueInst;
45 class FunctionLoweringInfo;
46 class GetElementPtrInst;
52 class InsertElementInst;
53 class InsertValueInst;
56 class MachineBasicBlock;
58 class MachineRegisterInfo;
66 class ShuffleVectorInst;
71 class TargetLibraryInfo;
75 class UnreachableInst;
94 class DanglingDebugInfo {
99 DanglingDebugInfo() : DI(0), dl(
DebugLoc()), SDNodeOrder(0) { }
101 DI(di), dl(DL), SDNodeOrder(SDNO) { }
128 unsigned SDNodeOrder;
136 uint32_t ExtraWeight;
138 Case() : Low(0), High(0), BB(0), ExtraWeight(0) { }
140 uint32_t extraweight) : Low(low), High(high), BB(bb),
141 ExtraWeight(extraweight) { }
146 return (rHigh - rLow + 1ULL);
154 uint32_t ExtraWeight;
158 Mask(mask), BB(bb),
Bits(bits), ExtraWeight(Weight) { }
161 typedef std::vector<Case> CaseVector;
162 typedef std::vector<CaseBits> CaseBitsVector;
163 typedef CaseVector::iterator CaseItr;
164 typedef std::pair<CaseItr, CaseItr> CaseRange;
171 CaseBB(bb),
LT(lt),
GE(ge), Range(r) {}
174 MachineBasicBlock *CaseBB;
184 typedef std::vector<CaseRec> CaseRecVector;
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());
198 bool operator()(
const CaseBits &C1,
const CaseBits &C2) {
199 return C1.Bits > C2.Bits;
203 size_t Clusterify(CaseVector &Cases,
const SwitchInst &SI);
209 CaseBlock(
ISD::CondCode cc,
const Value *cmplhs,
const Value *cmprhs,
210 const Value *cmpmiddle,
211 MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
212 MachineBasicBlock *me,
213 uint32_t trueweight = 0, uint32_t falseweight = 0)
214 : CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
215 TrueBB(truebb), FalseBB(falsebb), ThisBB(me),
216 TrueWeight(trueweight), FalseWeight(falseweight) { }
224 const Value *CmpLHS, *CmpMHS, *CmpRHS;
227 MachineBasicBlock *TrueBB, *FalseBB;
230 MachineBasicBlock *ThisBB;
233 uint32_t TrueWeight, FalseWeight;
237 JumpTable(
unsigned R,
unsigned J, MachineBasicBlock *M,
238 MachineBasicBlock *D):
Reg(R), JTI(J), MBB(M),
Default(D) {}
246 MachineBasicBlock *MBB;
251 struct JumpTableHeader {
252 JumpTableHeader(APInt
F, APInt L,
const Value *SV, MachineBasicBlock *
H,
254 First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
258 MachineBasicBlock *HeaderBB;
261 typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock;
264 BitTestCase(uint64_t M, MachineBasicBlock*
T, MachineBasicBlock* Tr,
266 Mask(M), ThisBB(T), TargetBB(Tr), ExtraWeight(Weight) { }
268 MachineBasicBlock *ThisBB;
269 MachineBasicBlock *TargetBB;
270 uint32_t ExtraWeight;
273 typedef SmallVector<BitTestCase, 3> BitTestInfo;
275 struct BitTestBlock {
276 BitTestBlock(APInt
F, APInt R,
const Value* SV,
277 unsigned Rg, MVT RgVT,
bool E,
278 MachineBasicBlock*
P, MachineBasicBlock* D,
279 const BitTestInfo&
C):
280 First(F), Range(R), SValue(SV),
Reg(Rg), RegVT(RgVT), Emitted(E),
281 Parent(P),
Default(D), Cases(C) { }
288 MachineBasicBlock *Parent;
397 class StackProtectorDescriptor {
399 StackProtectorDescriptor() : ParentMBB(0), SuccessMBB(0), FailureMBB(0),
401 ~StackProtectorDescriptor() { }
405 bool shouldEmitStackProtector()
const {
406 return ParentMBB && SuccessMBB && FailureMBB && Guard;
412 MachineBasicBlock *MBB,
413 const CallInst &StackProtCheckCall) {
415 assert(!shouldEmitStackProtector() &&
"Stack Protector Descriptor is "
416 "already initialized!");
418 SuccessMBB = AddSuccessorMBB(BB, MBB);
419 FailureMBB = AddSuccessorMBB(BB, MBB, FailureMBB);
421 Guard = StackProtCheckCall.getArgOperand(0);
434 void resetPerBBState() {
448 void resetPerFunctionState() {
453 MachineBasicBlock *getParentMBB() {
return ParentMBB; }
454 MachineBasicBlock *getSuccessMBB() {
return SuccessMBB; }
455 MachineBasicBlock *getFailureMBB() {
return FailureMBB; }
456 const Value *getGuard() {
return Guard; }
466 MachineBasicBlock *ParentMBB;
470 MachineBasicBlock *SuccessMBB;
474 MachineBasicBlock *FailureMBB;
483 MachineBasicBlock *AddSuccessorMBB(
const BasicBlock *BB,
484 MachineBasicBlock *ParentMBB,
485 MachineBasicBlock *SuccMBB = 0);
489 const TargetMachine &TM;
537 : CurInst(NULL), SDNodeOrder(0), TM(dag.getTarget()),
575 return SDLoc(CurInst, SDNodeOrder);
599 assert(N.
getNode() == 0 &&
"Already set a value for this node!");
605 assert(N.
getNode() == 0 &&
"Already set a value for this node!");
627 bool useVoidTy =
false);
642 bool handleSmallSwitchRange(CaseRec& CR,
643 CaseRecVector& WorkList,
646 MachineBasicBlock *SwitchBB);
647 bool handleJTSwitchCase(CaseRec& CR,
648 CaseRecVector& WorkList,
651 MachineBasicBlock *SwitchBB);
652 bool handleBTSplitSwitchCase(CaseRec& CR,
653 CaseRecVector& WorkList,
656 MachineBasicBlock *SwitchBB);
657 bool handleBitTestsSwitchCase(CaseRec& CR,
658 CaseRecVector& WorkList,
661 MachineBasicBlock *SwitchBB);
663 uint32_t getEdgeWeight(
const MachineBasicBlock *Src,
664 const MachineBasicBlock *Dst)
const;
665 void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
666 uint32_t Weight = 0);
669 MachineBasicBlock *SwitchBB);
671 MachineBasicBlock *ParentBB);
675 MachineBasicBlock* NextMBB,
676 uint32_t BranchWeightToNext,
679 MachineBasicBlock *SwitchBB);
682 MachineBasicBlock *SwitchBB);
686 void visitInvoke(
const InvokeInst &
I);
687 void visitResume(
const ResumeInst &
I);
689 void visitBinary(
const User &
I,
unsigned OpCode);
690 void visitShift(
const User &
I,
unsigned Opcode);
691 void visitAdd(
const User &
I) { visitBinary(I,
ISD::ADD); }
692 void visitFAdd(
const User &
I) { visitBinary(I,
ISD::FADD); }
693 void visitSub(
const User &
I) { visitBinary(I,
ISD::SUB); }
694 void visitFSub(
const User &
I);
695 void visitMul(
const User &
I) { visitBinary(I,
ISD::MUL); }
696 void visitFMul(
const User &
I) { visitBinary(I,
ISD::FMUL); }
697 void visitURem(
const User &
I) { visitBinary(I,
ISD::UREM); }
698 void visitSRem(
const User &
I) { visitBinary(I,
ISD::SREM); }
699 void visitFRem(
const User &
I) { visitBinary(I,
ISD::FREM); }
700 void visitUDiv(
const User &
I) { visitBinary(I,
ISD::UDIV); }
701 void visitSDiv(
const User &
I);
702 void visitFDiv(
const User &
I) { visitBinary(I,
ISD::FDIV); }
703 void visitAnd (
const User &
I) { visitBinary(I,
ISD::AND); }
704 void visitOr (
const User &
I) { visitBinary(I,
ISD::OR); }
705 void visitXor (
const User &
I) { visitBinary(I,
ISD::XOR); }
706 void visitShl (
const User &
I) { visitShift(I,
ISD::SHL); }
707 void visitLShr(
const User &
I) { visitShift(I,
ISD::SRL); }
708 void visitAShr(
const User &
I) { visitShift(I,
ISD::SRA); }
709 void visitICmp(
const User &
I);
710 void visitFCmp(
const User &
I);
712 void visitTrunc(
const User &
I);
713 void visitZExt(
const User &
I);
714 void visitSExt(
const User &
I);
715 void visitFPTrunc(
const User &
I);
716 void visitFPExt(
const User &
I);
717 void visitFPToUI(
const User &
I);
718 void visitFPToSI(
const User &
I);
719 void visitUIToFP(
const User &
I);
720 void visitSIToFP(
const User &
I);
721 void visitPtrToInt(
const User &
I);
722 void visitIntToPtr(
const User &
I);
723 void visitBitCast(
const User &
I);
724 void visitAddrSpaceCast(
const User &
I);
726 void visitExtractElement(
const User &
I);
727 void visitInsertElement(
const User &
I);
728 void visitShuffleVector(
const User &
I);
730 void visitExtractValue(
const ExtractValueInst &
I);
731 void visitInsertValue(
const InsertValueInst &
I);
732 void visitLandingPad(
const LandingPadInst &
I);
734 void visitGetElementPtr(
const User &
I);
735 void visitSelect(
const User &
I);
737 void visitAlloca(
const AllocaInst &
I);
738 void visitLoad(
const LoadInst &
I);
739 void visitStore(
const StoreInst &
I);
740 void visitAtomicCmpXchg(
const AtomicCmpXchgInst &
I);
741 void visitAtomicRMW(
const AtomicRMWInst &
I);
742 void visitFence(
const FenceInst &
I);
743 void visitPHI(
const PHINode &
I);
744 void visitCall(
const CallInst &
I);
745 bool visitMemCmpCall(
const CallInst &
I);
746 bool visitMemChrCall(
const CallInst &
I);
747 bool visitStrCpyCall(
const CallInst &
I,
bool isStpcpy);
748 bool visitStrCmpCall(
const CallInst &
I);
749 bool visitStrLenCall(
const CallInst &
I);
750 bool visitStrNLenCall(
const CallInst &
I);
751 bool visitUnaryFloatCall(
const CallInst &
I,
unsigned Opcode);
752 void visitAtomicLoad(
const LoadInst &
I);
753 void visitAtomicStore(
const StoreInst &
I);
755 void visitInlineAsm(ImmutableCallSite CS);
756 const char *visitIntrinsicCall(
const CallInst &
I,
unsigned Intrinsic);
757 void visitTargetIntrinsic(
const CallInst &
I,
unsigned Intrinsic);
759 void visitVAStart(
const CallInst &
I);
760 void visitVAArg(
const VAArgInst &
I);
761 void visitVAEnd(
const CallInst &
I);
762 void visitVACopy(
const CallInst &
I);
763 void visitStackmap(
const CallInst &
I);
764 void visitPatchpoint(
const CallInst &
I);
766 void visitUserOp1(
const Instruction &
I) {
767 llvm_unreachable(
"UserOp1 should not exist at instruction selection time!");
769 void visitUserOp2(
const Instruction &
I) {
770 llvm_unreachable(
"UserOp2 should not exist at instruction selection time!");
773 void processIntegerCallValue(
const Instruction &
I,
774 SDValue Value,
bool IsSigned);
776 void HandlePHINodesInSuccessorBlocks(
const BasicBlock *LLVMBB);
781 bool EmitFuncArgumentDbgValue(
const Value *V, MDNode *Variable,
782 int64_t Offset,
const SDValue &
N);
std::vector< BitTestBlock > BitTestCases
void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall, MachineBasicBlock *LandingPad=NULL)
void ExportFromCurrentBlock(const Value *V)
const TargetLibraryInfo * LibInfo
void CopyValueToVirtualRegister(const Value *V, unsigned Reg)
SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo, CodeGenOpt::Level ol)
void setValue(const Value *V, SDValue NewN)
void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH, MachineBasicBlock *SwitchBB)
SDValue getValueImpl(const Value *V)
DebugLoc getCurDebugLoc() const
SDValue getValue(const Value *V)
getValue - Return an SDValue for the given Value.
StackProtectorDescriptor SPDescriptor
void visitSPDescriptorParent(StackProtectorDescriptor &SPD, MachineBasicBlock *ParentBB)
unsigned getSDNodeOrder() const
void visitSwitchCase(CaseBlock &CB, MachineBasicBlock *SwitchBB)
#define llvm_unreachable(msg)
void visitJumpTable(JumpTable &JT)
visitJumpTable - Emit JumpTable node in the current MBB
std::pair< SDValue, SDValue > LowerCallOperands(const CallInst &CI, unsigned ArgIdx, unsigned NumArgs, SDValue Callee, bool useVoidTy=false)
Lower an argument list according to the target calling convention.
This file implements a class to represent arbitrary precision integral constant values and operations...
Simple integer binary arithmetic operators.
SDValue getNonRegisterValue(const Value *V)
bool ShouldEmitAsBranches(const std::vector< CaseBlock > &Cases)
SDNode * getNode() const
get the SDNode which holds the desired result
LLVM Basic Block Representation.
void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB, MachineBasicBlock *FBB, MachineBasicBlock *CurBB, MachineBasicBlock *SwitchBB)
Simple binary floating point operators.
static void initialize(TargetLibraryInfo &TLI, const Triple &T, const char **StandardNames)
LLVM Constant Representation.
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
void visitBitTestCase(BitTestBlock &BB, MachineBasicBlock *NextMBB, uint32_t BranchWeightToNext, unsigned Reg, BitTestCase &B, MachineBasicBlock *SwitchBB)
visitBitTestCase - this function produces one "bit test"
SDLoc getCurSDLoc() const
CodeGenOpt::Level OptLevel
void CopyToExportRegsIfNeeded(const Value *V)
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD)
void visit(const Instruction &I)
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last)
GCFunctionInfo * GFI
GFI - Garbage collection metadata for the function.
Class for arbitrary precision integers.
std::vector< JumpTableBlock > JTCases
SmallVector< SDValue, 8 > PendingLoads
Bitwise operators - logical and, logical or, logical xor.
ImmutableCallSite - establish a view to a call site for examination.
void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB, MachineBasicBlock *FBB, MachineBasicBlock *CurBB, MachineBasicBlock *SwitchBB, unsigned Opc)
FindMergedConditions - If Cond is an expression like.
FunctionLoweringInfo & FuncInfo
void setUnusedArgValue(const Value *V, SDValue NewN)
LLVM Value Representation.
void init(GCFunctionInfo *gfi, AliasAnalysis &aa, const TargetLibraryInfo *li)
std::vector< CaseBlock > SwitchCases
void clearDanglingDebugInfo()
DenseMap< MachineBasicBlock *, SmallVector< unsigned, 4 > > LPadToCallSiteMap
LPadToCallSiteMap - Map a landing pad to the call site indexes.
DenseMap< const Constant *, unsigned > ConstantsOut
bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB)
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB)
void resolveDanglingDebugInfo(const Value *V, SDValue Val)