2009-11-23 18:04:58 +00:00
|
|
|
//===-- SelectionDAGBuilder.h - Selection-DAG building --------------------===//
|
2008-09-03 16:12:24 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements routines for translating from LLVM IR into SelectionDAG IR.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-23 18:04:58 +00:00
|
|
|
#ifndef SELECTIONDAGBUILDER_H
|
|
|
|
#define SELECTIONDAGBUILDER_H
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
#include "llvm/Constants.h"
|
2009-07-13 04:09:18 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2008-09-03 16:12:24 +00:00
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
2009-02-03 01:32:22 +00:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
2008-09-03 16:12:24 +00:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2008-09-03 16:12:24 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class AliasAnalysis;
|
|
|
|
class AllocaInst;
|
|
|
|
class BasicBlock;
|
|
|
|
class BitCastInst;
|
|
|
|
class BranchInst;
|
|
|
|
class CallInst;
|
2010-08-26 23:35:15 +00:00
|
|
|
class DbgValueInst;
|
2008-09-03 16:12:24 +00:00
|
|
|
class ExtractElementInst;
|
|
|
|
class ExtractValueInst;
|
|
|
|
class FCmpInst;
|
|
|
|
class FPExtInst;
|
|
|
|
class FPToSIInst;
|
|
|
|
class FPToUIInst;
|
|
|
|
class FPTruncInst;
|
|
|
|
class Function;
|
2009-11-23 17:16:22 +00:00
|
|
|
class FunctionLoweringInfo;
|
2008-09-03 16:12:24 +00:00
|
|
|
class GetElementPtrInst;
|
|
|
|
class GCFunctionInfo;
|
|
|
|
class ICmpInst;
|
|
|
|
class IntToPtrInst;
|
2009-10-28 00:19:10 +00:00
|
|
|
class IndirectBrInst;
|
2008-09-03 16:12:24 +00:00
|
|
|
class InvokeInst;
|
|
|
|
class InsertElementInst;
|
|
|
|
class InsertValueInst;
|
|
|
|
class Instruction;
|
|
|
|
class LoadInst;
|
|
|
|
class MachineBasicBlock;
|
|
|
|
class MachineInstr;
|
|
|
|
class MachineRegisterInfo;
|
2010-04-28 23:08:54 +00:00
|
|
|
class MDNode;
|
2008-09-03 16:12:24 +00:00
|
|
|
class PHINode;
|
|
|
|
class PtrToIntInst;
|
|
|
|
class ReturnInst;
|
|
|
|
class SDISelAsmOperandInfo;
|
2010-07-16 00:02:08 +00:00
|
|
|
class SDDbgValue;
|
2008-09-03 16:12:24 +00:00
|
|
|
class SExtInst;
|
|
|
|
class SelectInst;
|
|
|
|
class ShuffleVectorInst;
|
|
|
|
class SIToFPInst;
|
|
|
|
class StoreInst;
|
|
|
|
class SwitchInst;
|
|
|
|
class TargetData;
|
|
|
|
class TargetLowering;
|
|
|
|
class TruncInst;
|
|
|
|
class UIToFPInst;
|
|
|
|
class UnreachableInst;
|
|
|
|
class UnwindInst;
|
|
|
|
class VAArgInst;
|
|
|
|
class ZExtInst;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-11-23 18:04:58 +00:00
|
|
|
/// SelectionDAGBuilder - This is the common target-independent lowering
|
2008-09-03 16:12:24 +00:00
|
|
|
/// implementation that is parameterized by a TargetLowering object.
|
|
|
|
///
|
2009-11-23 18:04:58 +00:00
|
|
|
class SelectionDAGBuilder {
|
2009-01-31 02:22:37 +00:00
|
|
|
/// CurDebugLoc - current file + line number. Changes as we build the DAG.
|
|
|
|
DebugLoc CurDebugLoc;
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
DenseMap<const Value*, SDValue> NodeMap;
|
2010-06-01 19:59:01 +00:00
|
|
|
|
|
|
|
/// UnusedArgNodeMap - Maps argument value for unused arguments. This is used
|
|
|
|
/// to preserve debug information for incoming arguments.
|
|
|
|
DenseMap<const Value*, SDValue> UnusedArgNodeMap;
|
2008-09-03 16:12:24 +00:00
|
|
|
|
2010-07-16 00:02:08 +00:00
|
|
|
/// DanglingDebugInfo - Helper type for DanglingDebugInfoMap.
|
|
|
|
class DanglingDebugInfo {
|
2010-08-26 23:35:15 +00:00
|
|
|
const DbgValueInst* DI;
|
2010-07-16 00:02:08 +00:00
|
|
|
DebugLoc dl;
|
|
|
|
unsigned SDNodeOrder;
|
|
|
|
public:
|
|
|
|
DanglingDebugInfo() : DI(0), dl(DebugLoc()), SDNodeOrder(0) { }
|
2010-08-26 23:35:15 +00:00
|
|
|
DanglingDebugInfo(const DbgValueInst *di, DebugLoc DL, unsigned SDNO) :
|
2010-07-16 00:02:08 +00:00
|
|
|
DI(di), dl(DL), SDNodeOrder(SDNO) { }
|
2010-08-26 23:35:15 +00:00
|
|
|
const DbgValueInst* getDI() { return DI; }
|
2010-07-16 00:02:08 +00:00
|
|
|
DebugLoc getdl() { return dl; }
|
|
|
|
unsigned getSDNodeOrder() { return SDNodeOrder; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// DanglingDebugInfoMap - Keeps track of dbg_values for which we have not
|
|
|
|
/// yet seen the referent. We defer handling these until we do see it.
|
|
|
|
DenseMap<const Value*, DanglingDebugInfo> DanglingDebugInfoMap;
|
|
|
|
|
2009-12-24 00:37:38 +00:00
|
|
|
public:
|
2008-09-03 16:12:24 +00:00
|
|
|
/// PendingLoads - Loads are not emitted to the program immediately. We bunch
|
|
|
|
/// them up and then emit token factor nodes when possible. This allows us to
|
|
|
|
/// get simple disambiguation between loads without worrying about alias
|
|
|
|
/// analysis.
|
|
|
|
SmallVector<SDValue, 8> PendingLoads;
|
2009-12-24 00:37:38 +00:00
|
|
|
private:
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
/// PendingExports - CopyToReg nodes that copy values to virtual registers
|
|
|
|
/// for export to other blocks need to be emitted before any terminator
|
|
|
|
/// instruction, but they have no other ordering requirements. We bunch them
|
|
|
|
/// up and the emit a single tokenfactor for them just before terminator
|
|
|
|
/// instructions.
|
|
|
|
SmallVector<SDValue, 8> PendingExports;
|
|
|
|
|
2009-12-18 23:32:53 +00:00
|
|
|
/// SDNodeOrder - A unique monotonically increasing number used to order the
|
|
|
|
/// SDNodes we create.
|
|
|
|
unsigned SDNodeOrder;
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
/// Case - A struct to record the Value for a switch case, and the
|
|
|
|
/// case's target basic block.
|
|
|
|
struct Case {
|
|
|
|
Constant* Low;
|
|
|
|
Constant* High;
|
|
|
|
MachineBasicBlock* BB;
|
|
|
|
|
|
|
|
Case() : Low(0), High(0), BB(0) { }
|
|
|
|
Case(Constant* low, Constant* high, MachineBasicBlock* bb) :
|
|
|
|
Low(low), High(high), BB(bb) { }
|
2009-11-07 07:50:34 +00:00
|
|
|
APInt size() const {
|
|
|
|
const APInt &rHigh = cast<ConstantInt>(High)->getValue();
|
|
|
|
const APInt &rLow = cast<ConstantInt>(Low)->getValue();
|
2008-09-03 16:12:24 +00:00
|
|
|
return (rHigh - rLow + 1ULL);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CaseBits {
|
|
|
|
uint64_t Mask;
|
|
|
|
MachineBasicBlock* BB;
|
|
|
|
unsigned Bits;
|
|
|
|
|
|
|
|
CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits):
|
|
|
|
Mask(mask), BB(bb), Bits(bits) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Case> CaseVector;
|
|
|
|
typedef std::vector<CaseBits> CaseBitsVector;
|
|
|
|
typedef CaseVector::iterator CaseItr;
|
|
|
|
typedef std::pair<CaseItr, CaseItr> CaseRange;
|
|
|
|
|
|
|
|
/// CaseRec - A struct with ctor used in lowering switches to a binary tree
|
|
|
|
/// of conditional branches.
|
|
|
|
struct CaseRec {
|
2010-04-15 01:51:59 +00:00
|
|
|
CaseRec(MachineBasicBlock *bb, const Constant *lt, const Constant *ge,
|
|
|
|
CaseRange r) :
|
2008-09-03 16:12:24 +00:00
|
|
|
CaseBB(bb), LT(lt), GE(ge), Range(r) {}
|
|
|
|
|
|
|
|
/// CaseBB - The MBB in which to emit the compare and branch
|
|
|
|
MachineBasicBlock *CaseBB;
|
|
|
|
/// LT, GE - If nonzero, we know the current case value must be less-than or
|
|
|
|
/// greater-than-or-equal-to these Constants.
|
2010-04-15 01:51:59 +00:00
|
|
|
const Constant *LT;
|
|
|
|
const Constant *GE;
|
2008-09-03 16:12:24 +00:00
|
|
|
/// Range - A pair of iterators representing the range of case values to be
|
|
|
|
/// processed at this point in the binary search tree.
|
|
|
|
CaseRange Range;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<CaseRec> CaseRecVector;
|
|
|
|
|
|
|
|
/// The comparison function for sorting the switch case values in the vector.
|
|
|
|
/// WARNING: Case ranges should be disjoint!
|
|
|
|
struct CaseCmp {
|
2010-01-01 23:37:34 +00:00
|
|
|
bool operator()(const Case &C1, const Case &C2) {
|
2008-09-03 16:12:24 +00:00
|
|
|
assert(isa<ConstantInt>(C1.Low) && isa<ConstantInt>(C2.High));
|
|
|
|
const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
|
|
|
|
const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
|
|
|
|
return CI1->getValue().slt(CI2->getValue());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CaseBitsCmp {
|
2010-01-01 23:37:34 +00:00
|
|
|
bool operator()(const CaseBits &C1, const CaseBits &C2) {
|
2008-09-03 16:12:24 +00:00
|
|
|
return C1.Bits > C2.Bits;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-01-01 23:37:34 +00:00
|
|
|
size_t Clusterify(CaseVector &Cases, const SwitchInst &SI);
|
2008-12-23 22:25:27 +00:00
|
|
|
|
2009-11-23 18:04:58 +00:00
|
|
|
/// CaseBlock - This structure is used to communicate between
|
|
|
|
/// SelectionDAGBuilder and SDISel for the code generation of additional basic
|
|
|
|
/// blocks needed by multi-case switch statements.
|
2008-09-03 16:12:24 +00:00
|
|
|
struct CaseBlock {
|
2010-04-15 01:51:59 +00:00
|
|
|
CaseBlock(ISD::CondCode cc, const Value *cmplhs, const Value *cmprhs,
|
|
|
|
const Value *cmpmiddle,
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock *truebb, MachineBasicBlock *falsebb,
|
|
|
|
MachineBasicBlock *me)
|
|
|
|
: CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
|
|
|
|
TrueBB(truebb), FalseBB(falsebb), ThisBB(me) {}
|
|
|
|
// CC - the condition code to use for the case block's setcc node
|
|
|
|
ISD::CondCode CC;
|
|
|
|
// CmpLHS/CmpRHS/CmpMHS - The LHS/MHS/RHS of the comparison to emit.
|
|
|
|
// Emit by default LHS op RHS. MHS is used for range comparisons:
|
|
|
|
// If MHS is not null: (LHS <= MHS) and (MHS <= RHS).
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value *CmpLHS, *CmpMHS, *CmpRHS;
|
2008-09-03 16:12:24 +00:00
|
|
|
// TrueBB/FalseBB - the block to branch to if the setcc is true/false.
|
|
|
|
MachineBasicBlock *TrueBB, *FalseBB;
|
|
|
|
// ThisBB - the block into which to emit the code for the setcc and branches
|
|
|
|
MachineBasicBlock *ThisBB;
|
|
|
|
};
|
|
|
|
struct JumpTable {
|
|
|
|
JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
|
|
|
|
MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
|
|
|
|
|
|
|
|
/// Reg - the virtual register containing the index of the jump table entry
|
|
|
|
//. to jump to.
|
|
|
|
unsigned Reg;
|
|
|
|
/// JTI - the JumpTableIndex for this jump table in the function.
|
|
|
|
unsigned JTI;
|
|
|
|
/// MBB - the MBB into which to emit the code for the indirect jump.
|
|
|
|
MachineBasicBlock *MBB;
|
|
|
|
/// Default - the MBB of the default bb, which is a successor of the range
|
|
|
|
/// check MBB. This is when updating PHI nodes in successors.
|
|
|
|
MachineBasicBlock *Default;
|
|
|
|
};
|
|
|
|
struct JumpTableHeader {
|
2010-04-15 01:51:59 +00:00
|
|
|
JumpTableHeader(APInt F, APInt L, const Value *SV, MachineBasicBlock *H,
|
2008-09-03 16:12:24 +00:00
|
|
|
bool E = false):
|
|
|
|
First(F), Last(L), SValue(SV), HeaderBB(H), Emitted(E) {}
|
2008-12-23 22:25:27 +00:00
|
|
|
APInt First;
|
|
|
|
APInt Last;
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value *SValue;
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock *HeaderBB;
|
|
|
|
bool Emitted;
|
|
|
|
};
|
|
|
|
typedef std::pair<JumpTableHeader, JumpTable> JumpTableBlock;
|
|
|
|
|
|
|
|
struct BitTestCase {
|
|
|
|
BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr):
|
|
|
|
Mask(M), ThisBB(T), TargetBB(Tr) { }
|
|
|
|
uint64_t Mask;
|
2010-01-01 23:37:34 +00:00
|
|
|
MachineBasicBlock *ThisBB;
|
|
|
|
MachineBasicBlock *TargetBB;
|
2008-09-03 16:12:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SmallVector<BitTestCase, 3> BitTestInfo;
|
|
|
|
|
|
|
|
struct BitTestBlock {
|
2010-04-15 01:51:59 +00:00
|
|
|
BitTestBlock(APInt F, APInt R, const Value* SV,
|
2011-01-06 01:02:44 +00:00
|
|
|
unsigned Rg, EVT RgVT, bool E,
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock* P, MachineBasicBlock* D,
|
|
|
|
const BitTestInfo& C):
|
2011-01-06 01:02:44 +00:00
|
|
|
First(F), Range(R), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E),
|
2008-09-03 16:12:24 +00:00
|
|
|
Parent(P), Default(D), Cases(C) { }
|
2008-12-23 22:25:27 +00:00
|
|
|
APInt First;
|
|
|
|
APInt Range;
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value *SValue;
|
2008-09-03 16:12:24 +00:00
|
|
|
unsigned Reg;
|
2011-01-06 01:02:44 +00:00
|
|
|
EVT RegVT;
|
2008-09-03 16:12:24 +00:00
|
|
|
bool Emitted;
|
|
|
|
MachineBasicBlock *Parent;
|
|
|
|
MachineBasicBlock *Default;
|
|
|
|
BitTestInfo Cases;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
// TLI - This is information that describes the available target features we
|
|
|
|
// need for lowering. This indicates when operations are unavailable,
|
|
|
|
// implemented with a libcall, etc.
|
2010-04-19 19:05:59 +00:00
|
|
|
const TargetMachine &TM;
|
2010-04-17 15:26:15 +00:00
|
|
|
const TargetLowering &TLI;
|
2008-09-03 16:12:24 +00:00
|
|
|
SelectionDAG &DAG;
|
|
|
|
const TargetData *TD;
|
|
|
|
AliasAnalysis *AA;
|
|
|
|
|
|
|
|
/// SwitchCases - Vector of CaseBlock structures used to communicate
|
|
|
|
/// SwitchInst code generation information.
|
|
|
|
std::vector<CaseBlock> SwitchCases;
|
|
|
|
/// JTCases - Vector of JumpTable structures used to communicate
|
|
|
|
/// SwitchInst code generation information.
|
|
|
|
std::vector<JumpTableBlock> JTCases;
|
|
|
|
/// BitTestCases - Vector of BitTestBlock structures used to communicate
|
|
|
|
/// SwitchInst code generation information.
|
|
|
|
std::vector<BitTestBlock> BitTestCases;
|
2009-09-18 21:02:19 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
// Emit PHI-node-operand constants only once even if used by multiple
|
|
|
|
// PHI nodes.
|
2010-04-15 01:51:59 +00:00
|
|
|
DenseMap<const Constant *, unsigned> ConstantsOut;
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
/// FuncInfo - Information about the function as a whole.
|
|
|
|
///
|
|
|
|
FunctionLoweringInfo &FuncInfo;
|
2009-02-19 21:12:54 +00:00
|
|
|
|
2009-04-29 00:15:41 +00:00
|
|
|
/// OptLevel - What optimization level we're generating code for.
|
2009-02-19 21:12:54 +00:00
|
|
|
///
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel;
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
/// GFI - Garbage collection metadata for the function.
|
|
|
|
GCFunctionInfo *GFI;
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
/// HasTailCall - This is set to true if a call in the current
|
|
|
|
/// block has been translated as a tail call. In this case,
|
|
|
|
/// no subsequent DAG nodes should be created.
|
|
|
|
///
|
|
|
|
bool HasTailCall;
|
|
|
|
|
2009-07-13 04:09:18 +00:00
|
|
|
LLVMContext *Context;
|
|
|
|
|
2010-04-19 19:05:59 +00:00
|
|
|
SelectionDAGBuilder(SelectionDAG &dag, FunctionLoweringInfo &funcinfo,
|
2009-11-23 18:04:58 +00:00
|
|
|
CodeGenOpt::Level ol)
|
2010-04-19 19:05:59 +00:00
|
|
|
: SDNodeOrder(0), TM(dag.getTarget()), TLI(dag.getTargetLoweringInfo()),
|
|
|
|
DAG(dag), FuncInfo(funcinfo), OptLevel(ol),
|
2010-04-02 20:17:23 +00:00
|
|
|
HasTailCall(false), Context(dag.getContext()) {
|
2008-09-03 16:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init(GCFunctionInfo *gfi, AliasAnalysis &aa);
|
|
|
|
|
2010-04-14 18:24:06 +00:00
|
|
|
/// clear - Clear out the current SelectionDAG and the associated
|
2009-11-23 18:04:58 +00:00
|
|
|
/// state and prepare this SelectionDAGBuilder object to be used
|
2008-09-03 16:12:24 +00:00
|
|
|
/// for a new block. This doesn't clear out information about
|
|
|
|
/// additional blocks that are needed to complete switch lowering
|
|
|
|
/// or PHI node updating; that information is cleared out as it is
|
|
|
|
/// consumed.
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/// getRoot - Return the current virtual root of the Selection DAG,
|
|
|
|
/// flushing any PendingLoad items. This must be done before emitting
|
|
|
|
/// a store or any other node that may need to be ordered after any
|
|
|
|
/// prior load instructions.
|
|
|
|
///
|
|
|
|
SDValue getRoot();
|
|
|
|
|
|
|
|
/// getControlRoot - Similar to getRoot, but instead of flushing all the
|
|
|
|
/// PendingLoad items, flush all the PendingExports items. It is necessary
|
|
|
|
/// to do this before emitting a terminator instruction.
|
|
|
|
///
|
|
|
|
SDValue getControlRoot();
|
|
|
|
|
2009-01-31 02:22:37 +00:00
|
|
|
DebugLoc getCurDebugLoc() const { return CurDebugLoc; }
|
2011-02-21 23:21:26 +00:00
|
|
|
|
2009-12-22 02:10:19 +00:00
|
|
|
unsigned getSDNodeOrder() const { return SDNodeOrder; }
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
void CopyValueToVirtualRegister(const Value *V, unsigned Reg);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
2010-01-28 21:51:40 +00:00
|
|
|
/// AssignOrderingToNode - Assign an ordering to the node. The order is gotten
|
|
|
|
/// from how the code appeared in the source. The ordering is used by the
|
|
|
|
/// scheduler to effectively turn off scheduling.
|
|
|
|
void AssignOrderingToNode(const SDNode *Node);
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
void visit(const Instruction &I);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
void visit(unsigned Opcode, const User &I);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
2010-07-16 00:02:08 +00:00
|
|
|
// resolveDanglingDebugInfo - if we saw an earlier dbg_value referring to V,
|
|
|
|
// generate the debug data structures now that we've seen its definition.
|
|
|
|
void resolveDanglingDebugInfo(const Value *V, SDValue Val);
|
2008-09-03 16:12:24 +00:00
|
|
|
SDValue getValue(const Value *V);
|
2010-07-01 01:59:43 +00:00
|
|
|
SDValue getNonRegisterValue(const Value *V);
|
|
|
|
SDValue getValueImpl(const Value *V);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
void setValue(const Value *V, SDValue NewN) {
|
|
|
|
SDValue &N = NodeMap[V];
|
|
|
|
assert(N.getNode() == 0 && "Already set a value for this node!");
|
|
|
|
N = NewN;
|
|
|
|
}
|
|
|
|
|
2010-06-01 19:59:01 +00:00
|
|
|
void setUnusedArgValue(const Value *V, SDValue NewN) {
|
|
|
|
SDValue &N = UnusedArgNodeMap[V];
|
|
|
|
assert(N.getNode() == 0 && "Already set a value for this node!");
|
|
|
|
N = NewN;
|
|
|
|
}
|
|
|
|
|
2008-09-24 23:13:09 +00:00
|
|
|
void GetRegistersForValue(SDISelAsmOperandInfo &OpInfo,
|
2008-09-03 16:12:24 +00:00
|
|
|
std::set<unsigned> &OutputRegs,
|
|
|
|
std::set<unsigned> &InputRegs);
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
void FindMergedConditions(const Value *Cond, MachineBasicBlock *TBB,
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock *FBB, MachineBasicBlock *CurBB,
|
2010-04-19 22:41:47 +00:00
|
|
|
MachineBasicBlock *SwitchBB, unsigned Opc);
|
2010-04-15 01:51:59 +00:00
|
|
|
void EmitBranchForMergedCondition(const Value *Cond, MachineBasicBlock *TBB,
|
2008-10-17 21:16:08 +00:00
|
|
|
MachineBasicBlock *FBB,
|
2010-04-19 22:41:47 +00:00
|
|
|
MachineBasicBlock *CurBB,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
bool ShouldEmitAsBranches(const std::vector<CaseBlock> &Cases);
|
2010-04-15 01:51:59 +00:00
|
|
|
bool isExportableFromCurrentBlock(const Value *V, const BasicBlock *FromBB);
|
|
|
|
void CopyToExportRegsIfNeeded(const Value *V);
|
|
|
|
void ExportFromCurrentBlock(const Value *V);
|
|
|
|
void LowerCallTo(ImmutableCallSite CS, SDValue Callee, bool IsTailCall,
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock *LandingPad = NULL);
|
|
|
|
|
2010-09-30 19:44:31 +00:00
|
|
|
/// UpdateSplitBlock - When an MBB was split during scheduling, update the
|
|
|
|
/// references that ned to refer to the last resulting block.
|
|
|
|
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
private:
|
|
|
|
// Terminator instructions.
|
2010-04-15 01:51:59 +00:00
|
|
|
void visitRet(const ReturnInst &I);
|
|
|
|
void visitBr(const BranchInst &I);
|
|
|
|
void visitSwitch(const SwitchInst &I);
|
|
|
|
void visitIndirectBr(const IndirectBrInst &I);
|
2010-07-15 23:42:21 +00:00
|
|
|
void visitUnreachable(const UnreachableInst &I) { /* noop */ }
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
// Helpers for visitSwitch
|
|
|
|
bool handleSmallSwitchRange(CaseRec& CR,
|
|
|
|
CaseRecVector& WorkList,
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value* SV,
|
2010-04-19 22:41:47 +00:00
|
|
|
MachineBasicBlock* Default,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
bool handleJTSwitchCase(CaseRec& CR,
|
|
|
|
CaseRecVector& WorkList,
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value* SV,
|
2010-04-19 22:41:47 +00:00
|
|
|
MachineBasicBlock* Default,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
bool handleBTSplitSwitchCase(CaseRec& CR,
|
|
|
|
CaseRecVector& WorkList,
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value* SV,
|
2010-04-19 22:41:47 +00:00
|
|
|
MachineBasicBlock* Default,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
bool handleBitTestsSwitchCase(CaseRec& CR,
|
|
|
|
CaseRecVector& WorkList,
|
2010-04-15 01:51:59 +00:00
|
|
|
const Value* SV,
|
2010-04-19 22:41:47 +00:00
|
|
|
MachineBasicBlock* Default,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
public:
|
2010-04-19 22:41:47 +00:00
|
|
|
void visitSwitchCase(CaseBlock &CB,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
|
|
|
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB);
|
2011-01-06 01:02:44 +00:00
|
|
|
void visitBitTestCase(BitTestBlock &BB,
|
|
|
|
MachineBasicBlock* NextMBB,
|
2008-09-03 16:12:24 +00:00
|
|
|
unsigned Reg,
|
2010-04-19 22:41:47 +00:00
|
|
|
BitTestCase &B,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
void visitJumpTable(JumpTable &JT);
|
2010-04-19 22:41:47 +00:00
|
|
|
void visitJumpTableHeader(JumpTable &JT, JumpTableHeader &JTH,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// These all get lowered before this pass.
|
2010-04-15 01:51:59 +00:00
|
|
|
void visitInvoke(const InvokeInst &I);
|
|
|
|
void visitUnwind(const UnwindInst &I);
|
|
|
|
|
|
|
|
void visitBinary(const User &I, unsigned OpCode);
|
|
|
|
void visitShift(const User &I, unsigned Opcode);
|
|
|
|
void visitAdd(const User &I) { visitBinary(I, ISD::ADD); }
|
|
|
|
void visitFAdd(const User &I) { visitBinary(I, ISD::FADD); }
|
|
|
|
void visitSub(const User &I) { visitBinary(I, ISD::SUB); }
|
|
|
|
void visitFSub(const User &I);
|
|
|
|
void visitMul(const User &I) { visitBinary(I, ISD::MUL); }
|
|
|
|
void visitFMul(const User &I) { visitBinary(I, ISD::FMUL); }
|
|
|
|
void visitURem(const User &I) { visitBinary(I, ISD::UREM); }
|
|
|
|
void visitSRem(const User &I) { visitBinary(I, ISD::SREM); }
|
|
|
|
void visitFRem(const User &I) { visitBinary(I, ISD::FREM); }
|
|
|
|
void visitUDiv(const User &I) { visitBinary(I, ISD::UDIV); }
|
|
|
|
void visitSDiv(const User &I) { visitBinary(I, ISD::SDIV); }
|
|
|
|
void visitFDiv(const User &I) { visitBinary(I, ISD::FDIV); }
|
|
|
|
void visitAnd (const User &I) { visitBinary(I, ISD::AND); }
|
|
|
|
void visitOr (const User &I) { visitBinary(I, ISD::OR); }
|
|
|
|
void visitXor (const User &I) { visitBinary(I, ISD::XOR); }
|
|
|
|
void visitShl (const User &I) { visitShift(I, ISD::SHL); }
|
|
|
|
void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
|
|
|
|
void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
|
|
|
|
void visitICmp(const User &I);
|
|
|
|
void visitFCmp(const User &I);
|
2008-09-03 16:12:24 +00:00
|
|
|
// Visit the conversion instructions
|
2010-04-15 01:51:59 +00:00
|
|
|
void visitTrunc(const User &I);
|
|
|
|
void visitZExt(const User &I);
|
|
|
|
void visitSExt(const User &I);
|
|
|
|
void visitFPTrunc(const User &I);
|
|
|
|
void visitFPExt(const User &I);
|
|
|
|
void visitFPToUI(const User &I);
|
|
|
|
void visitFPToSI(const User &I);
|
|
|
|
void visitUIToFP(const User &I);
|
|
|
|
void visitSIToFP(const User &I);
|
|
|
|
void visitPtrToInt(const User &I);
|
|
|
|
void visitIntToPtr(const User &I);
|
|
|
|
void visitBitCast(const User &I);
|
|
|
|
|
|
|
|
void visitExtractElement(const User &I);
|
|
|
|
void visitInsertElement(const User &I);
|
|
|
|
void visitShuffleVector(const User &I);
|
|
|
|
|
|
|
|
void visitExtractValue(const ExtractValueInst &I);
|
|
|
|
void visitInsertValue(const InsertValueInst &I);
|
|
|
|
|
|
|
|
void visitGetElementPtr(const User &I);
|
|
|
|
void visitSelect(const User &I);
|
|
|
|
|
|
|
|
void visitAlloca(const AllocaInst &I);
|
|
|
|
void visitLoad(const LoadInst &I);
|
|
|
|
void visitStore(const StoreInst &I);
|
2010-04-20 15:00:41 +00:00
|
|
|
void visitPHI(const PHINode &I);
|
2010-04-15 01:51:59 +00:00
|
|
|
void visitCall(const CallInst &I);
|
|
|
|
bool visitMemCmpCall(const CallInst &I);
|
2009-12-24 00:37:38 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
void visitInlineAsm(ImmutableCallSite CS);
|
|
|
|
const char *visitIntrinsicCall(const CallInst &I, unsigned Intrinsic);
|
|
|
|
void visitTargetIntrinsic(const CallInst &I, unsigned Intrinsic);
|
|
|
|
|
|
|
|
void visitPow(const CallInst &I);
|
|
|
|
void visitExp2(const CallInst &I);
|
|
|
|
void visitExp(const CallInst &I);
|
|
|
|
void visitLog(const CallInst &I);
|
|
|
|
void visitLog2(const CallInst &I);
|
|
|
|
void visitLog10(const CallInst &I);
|
|
|
|
|
|
|
|
void visitVAStart(const CallInst &I);
|
|
|
|
void visitVAArg(const VAArgInst &I);
|
|
|
|
void visitVAEnd(const CallInst &I);
|
|
|
|
void visitVACopy(const CallInst &I);
|
|
|
|
|
|
|
|
void visitUserOp1(const Instruction &I) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("UserOp1 should not exist at instruction selection time!");
|
2008-09-03 16:12:24 +00:00
|
|
|
}
|
2010-04-15 01:51:59 +00:00
|
|
|
void visitUserOp2(const Instruction &I) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("UserOp2 should not exist at instruction selection time!");
|
2008-09-03 16:12:24 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const char *implVisitBinaryAtomic(const CallInst& I, ISD::NodeType Op);
|
|
|
|
const char *implVisitAluOverflow(const CallInst &I, ISD::NodeType Op);
|
2010-04-22 20:55:53 +00:00
|
|
|
|
|
|
|
void HandlePHINodesInSuccessorBlocks(const BasicBlock *LLVMBB);
|
2010-04-28 23:08:54 +00:00
|
|
|
|
2010-08-25 20:41:24 +00:00
|
|
|
/// EmitFuncArgumentDbgValue - If V is an function argument then create
|
|
|
|
/// corresponding DBG_VALUE machine instruction for it now. At the end of
|
|
|
|
/// instruction selection, they will be inserted to the entry BB.
|
2010-08-25 20:39:26 +00:00
|
|
|
bool EmitFuncArgumentDbgValue(const Value *V, MDNode *Variable,
|
2010-08-31 06:12:08 +00:00
|
|
|
int64_t Offset, const SDValue &N);
|
2008-09-03 16:12:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|