2013-08-12 21:02:02 +00:00
|
|
|
//===-- SelectionDAGBuilder.h - Selection-DAG building --------*- C++ -*---===//
|
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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_SELECTIONDAG_SELECTIONDAGBUILDER_H
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2008-09-03 16:12:24 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGNodes.h"
|
2014-03-04 11:01:28 +00:00
|
|
|
#include "llvm/IR/CallSite.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2014-10-16 21:26:35 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2008-09-03 16:12:24 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2013-11-15 01:34:59 +00:00
|
|
|
class AddrSpaceCastInst;
|
2008-09-03 16:12:24 +00:00
|
|
|
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;
|
2014-03-12 08:00:24 +00:00
|
|
|
class MVT;
|
2008-09-03 16:12:24 +00:00
|
|
|
class PHINode;
|
|
|
|
class PtrToIntInst;
|
|
|
|
class ReturnInst;
|
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;
|
2012-10-08 16:38:25 +00:00
|
|
|
class DataLayout;
|
2011-12-08 22:15:21 +00:00
|
|
|
class TargetLibraryInfo;
|
2008-09-03 16:12:24 +00:00
|
|
|
class TargetLowering;
|
|
|
|
class TruncInst;
|
|
|
|
class UIToFPInst;
|
|
|
|
class UnreachableInst;
|
|
|
|
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.
|
|
|
|
///
|
2013-09-11 18:05:11 +00:00
|
|
|
class SelectionDAGBuilder {
|
2013-05-25 02:20:36 +00:00
|
|
|
/// CurInst - The current instruction being visited
|
|
|
|
const Instruction *CurInst;
|
2009-01-31 02:22:37 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
DenseMap<const Value*, SDValue> NodeMap;
|
2013-10-31 17:18:07 +00:00
|
|
|
|
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:
|
2014-04-16 04:21:27 +00:00
|
|
|
DanglingDebugInfo() : DI(nullptr), 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 {
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
const Constant *Low;
|
|
|
|
const Constant *High;
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock* BB;
|
2011-07-29 22:25:21 +00:00
|
|
|
uint32_t ExtraWeight;
|
|
|
|
|
2014-04-16 04:21:27 +00:00
|
|
|
Case() : Low(nullptr), High(nullptr), BB(nullptr), ExtraWeight(0) { }
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149481 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-01 07:49:51 +00:00
|
|
|
Case(const Constant *low, const Constant *high, MachineBasicBlock *bb,
|
2011-07-29 22:25:21 +00:00
|
|
|
uint32_t extraweight) : Low(low), High(high), BB(bb),
|
|
|
|
ExtraWeight(extraweight) { }
|
2008-09-03 16:12:24 +00:00
|
|
|
|
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;
|
2012-08-24 18:14:27 +00:00
|
|
|
uint32_t ExtraWeight;
|
2008-09-03 16:12:24 +00:00
|
|
|
|
2012-08-24 18:14:27 +00:00
|
|
|
CaseBits(uint64_t mask, MachineBasicBlock* bb, unsigned bits,
|
|
|
|
uint32_t Weight):
|
|
|
|
Mask(mask), BB(bb), Bits(bits), ExtraWeight(Weight) { }
|
2008-09-03 16:12:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190328 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-09 19:14:35 +00:00
|
|
|
/// The comparison function for sorting the switch case values in the vector.
|
|
|
|
/// WARNING: Case ranges should be disjoint!
|
|
|
|
struct CaseCmp {
|
|
|
|
bool operator()(const Case &C1, const Case &C2) {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-13 19:46:39 +00:00
|
|
|
void 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,
|
2011-07-29 22:25:21 +00:00
|
|
|
MachineBasicBlock *me,
|
|
|
|
uint32_t trueweight = 0, uint32_t falseweight = 0)
|
2008-09-03 16:12:24 +00:00
|
|
|
: CC(cc), CmpLHS(cmplhs), CmpMHS(cmpmiddle), CmpRHS(cmprhs),
|
2011-07-29 22:25:21 +00:00
|
|
|
TrueBB(truebb), FalseBB(falsebb), ThisBB(me),
|
|
|
|
TrueWeight(trueweight), FalseWeight(falseweight) { }
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
// CC - the condition code to use for the case block's setcc node
|
|
|
|
ISD::CondCode CC;
|
2011-07-29 22:25:21 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
// 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;
|
2011-07-29 22:25:21 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
// TrueBB/FalseBB - the block to branch to if the setcc is true/false.
|
|
|
|
MachineBasicBlock *TrueBB, *FalseBB;
|
2011-07-29 22:25:21 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
// ThisBB - the block into which to emit the code for the setcc and branches
|
|
|
|
MachineBasicBlock *ThisBB;
|
2011-07-29 22:25:21 +00:00
|
|
|
|
|
|
|
// TrueWeight/FalseWeight - branch weights.
|
|
|
|
uint32_t TrueWeight, FalseWeight;
|
2008-09-03 16:12:24 +00:00
|
|
|
};
|
2011-07-29 22:25:21 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
struct JumpTable {
|
|
|
|
JumpTable(unsigned R, unsigned J, MachineBasicBlock *M,
|
|
|
|
MachineBasicBlock *D): Reg(R), JTI(J), MBB(M), Default(D) {}
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
/// 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 {
|
2012-08-24 18:14:27 +00:00
|
|
|
BitTestCase(uint64_t M, MachineBasicBlock* T, MachineBasicBlock* Tr,
|
|
|
|
uint32_t Weight):
|
|
|
|
Mask(M), ThisBB(T), TargetBB(Tr), ExtraWeight(Weight) { }
|
2008-09-03 16:12:24 +00:00
|
|
|
uint64_t Mask;
|
2010-01-01 23:37:34 +00:00
|
|
|
MachineBasicBlock *ThisBB;
|
|
|
|
MachineBasicBlock *TargetBB;
|
2012-08-24 18:14:27 +00:00
|
|
|
uint32_t ExtraWeight;
|
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,
|
2012-12-19 12:23:01 +00:00
|
|
|
unsigned Rg, MVT RgVT, bool E,
|
2008-09-03 16:12:24 +00:00
|
|
|
MachineBasicBlock* P, MachineBasicBlock* D,
|
2014-10-04 16:55:56 +00:00
|
|
|
BitTestInfo C):
|
2011-01-06 01:02:44 +00:00
|
|
|
First(F), Range(R), SValue(SV), Reg(Rg), RegVT(RgVT), Emitted(E),
|
2014-10-04 16:55:56 +00:00
|
|
|
Parent(P), Default(D), Cases(std::move(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;
|
2012-12-19 12:23:01 +00:00
|
|
|
MVT RegVT;
|
2008-09-03 16:12:24 +00:00
|
|
|
bool Emitted;
|
|
|
|
MachineBasicBlock *Parent;
|
|
|
|
MachineBasicBlock *Default;
|
|
|
|
BitTestInfo Cases;
|
|
|
|
};
|
|
|
|
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
/// A class which encapsulates all of the information needed to generate a
|
|
|
|
/// stack protector check and signals to isel via its state being initialized
|
|
|
|
/// that a stack protector needs to be generated.
|
|
|
|
///
|
|
|
|
/// *NOTE* The following is a high level documentation of SelectionDAG Stack
|
|
|
|
/// Protector Generation. The reason that it is placed here is for a lack of
|
|
|
|
/// other good places to stick it.
|
|
|
|
///
|
|
|
|
/// High Level Overview of SelectionDAG Stack Protector Generation:
|
|
|
|
///
|
|
|
|
/// Previously, generation of stack protectors was done exclusively in the
|
|
|
|
/// pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
|
|
|
|
/// splitting basic blocks at the IR level to create the success/failure basic
|
|
|
|
/// blocks in the tail of the basic block in question. As a result of this,
|
|
|
|
/// calls that would have qualified for the sibling call optimization were no
|
|
|
|
/// longer eligible for optimization since said calls were no longer right in
|
|
|
|
/// the "tail position" (i.e. the immediate predecessor of a ReturnInst
|
|
|
|
/// instruction).
|
|
|
|
///
|
|
|
|
/// Then it was noticed that since the sibling call optimization causes the
|
|
|
|
/// callee to reuse the caller's stack, if we could delay the generation of
|
|
|
|
/// the stack protector check until later in CodeGen after the sibling call
|
|
|
|
/// decision was made, we get both the tail call optimization and the stack
|
|
|
|
/// protector check!
|
|
|
|
///
|
|
|
|
/// A few goals in solving this problem were:
|
|
|
|
///
|
|
|
|
/// 1. Preserve the architecture independence of stack protector generation.
|
|
|
|
///
|
|
|
|
/// 2. Preserve the normal IR level stack protector check for platforms like
|
2014-06-30 18:57:16 +00:00
|
|
|
/// OpenBSD for which we support platform-specific stack protector
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
/// generation.
|
|
|
|
///
|
|
|
|
/// The main problem that guided the present solution is that one can not
|
|
|
|
/// solve this problem in an architecture independent manner at the IR level
|
|
|
|
/// only. This is because:
|
|
|
|
///
|
|
|
|
/// 1. The decision on whether or not to perform a sibling call on certain
|
|
|
|
/// platforms (for instance i386) requires lower level information
|
|
|
|
/// related to available registers that can not be known at the IR level.
|
|
|
|
///
|
|
|
|
/// 2. Even if the previous point were not true, the decision on whether to
|
|
|
|
/// perform a tail call is done in LowerCallTo in SelectionDAG which
|
|
|
|
/// occurs after the Stack Protector Pass. As a result, one would need to
|
|
|
|
/// put the relevant callinst into the stack protector check success
|
|
|
|
/// basic block (where the return inst is placed) and then move it back
|
|
|
|
/// later at SelectionDAG/MI time before the stack protector check if the
|
|
|
|
/// tail call optimization failed. The MI level option was nixed
|
2014-06-30 18:57:16 +00:00
|
|
|
/// immediately since it would require platform-specific pattern
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
/// matching. The SelectionDAG level option was nixed because
|
|
|
|
/// SelectionDAG only processes one IR level basic block at a time
|
|
|
|
/// implying one could not create a DAG Combine to move the callinst.
|
|
|
|
///
|
|
|
|
/// To get around this problem a few things were realized:
|
|
|
|
///
|
|
|
|
/// 1. While one can not handle multiple IR level basic blocks at the
|
|
|
|
/// SelectionDAG Level, one can generate multiple machine basic blocks
|
|
|
|
/// for one IR level basic block. This is how we handle bit tests and
|
|
|
|
/// switches.
|
|
|
|
///
|
|
|
|
/// 2. At the MI level, tail calls are represented via a special return
|
|
|
|
/// MIInst called "tcreturn". Thus if we know the basic block in which we
|
|
|
|
/// wish to insert the stack protector check, we get the correct behavior
|
|
|
|
/// by always inserting the stack protector check right before the return
|
|
|
|
/// statement. This is a "magical transformation" since no matter where
|
|
|
|
/// the stack protector check intrinsic is, we always insert the stack
|
|
|
|
/// protector check code at the end of the BB.
|
|
|
|
///
|
|
|
|
/// Given the aforementioned constraints, the following solution was devised:
|
|
|
|
///
|
|
|
|
/// 1. On platforms that do not support SelectionDAG stack protector check
|
|
|
|
/// generation, allow for the normal IR level stack protector check
|
|
|
|
/// generation to continue.
|
|
|
|
///
|
|
|
|
/// 2. On platforms that do support SelectionDAG stack protector check
|
|
|
|
/// generation:
|
|
|
|
///
|
|
|
|
/// a. Use the IR level stack protector pass to decide if a stack
|
|
|
|
/// protector is required/which BB we insert the stack protector check
|
|
|
|
/// in by reusing the logic already therein. If we wish to generate a
|
|
|
|
/// stack protector check in a basic block, we place a special IR
|
|
|
|
/// intrinsic called llvm.stackprotectorcheck right before the BB's
|
|
|
|
/// returninst or if there is a callinst that could potentially be
|
|
|
|
/// sibling call optimized, before the call inst.
|
|
|
|
///
|
|
|
|
/// b. Then when a BB with said intrinsic is processed, we codegen the BB
|
|
|
|
/// normally via SelectBasicBlock. In said process, when we visit the
|
|
|
|
/// stack protector check, we do not actually emit anything into the
|
|
|
|
/// BB. Instead, we just initialize the stack protector descriptor
|
|
|
|
/// class (which involves stashing information/creating the success
|
|
|
|
/// mbbb and the failure mbb if we have not created one for this
|
|
|
|
/// function yet) and export the guard variable that we are going to
|
|
|
|
/// compare.
|
|
|
|
///
|
|
|
|
/// c. After we finish selecting the basic block, in FinishBasicBlock if
|
|
|
|
/// the StackProtectorDescriptor attached to the SelectionDAGBuilder is
|
|
|
|
/// initialized, we first find a splice point in the parent basic block
|
|
|
|
/// before the terminator and then splice the terminator of said basic
|
|
|
|
/// block into the success basic block. Then we code-gen a new tail for
|
|
|
|
/// the parent basic block consisting of the two loads, the comparison,
|
|
|
|
/// and finally two branches to the success/failure basic blocks. We
|
|
|
|
/// conclude by code-gening the failure basic block if we have not
|
|
|
|
/// code-gened it already (all stack protector checks we generate in
|
|
|
|
/// the same function, use the same failure basic block).
|
|
|
|
class StackProtectorDescriptor {
|
|
|
|
public:
|
2014-04-16 04:21:27 +00:00
|
|
|
StackProtectorDescriptor() : ParentMBB(nullptr), SuccessMBB(nullptr),
|
2014-07-25 19:31:34 +00:00
|
|
|
FailureMBB(nullptr), Guard(nullptr),
|
|
|
|
GuardReg(0) { }
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
~StackProtectorDescriptor() { }
|
|
|
|
|
|
|
|
/// Returns true if all fields of the stack protector descriptor are
|
|
|
|
/// initialized implying that we should/are ready to emit a stack protector.
|
|
|
|
bool shouldEmitStackProtector() const {
|
|
|
|
return ParentMBB && SuccessMBB && FailureMBB && Guard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Initialize the stack protector descriptor structure for a new basic
|
|
|
|
/// block.
|
|
|
|
void initialize(const BasicBlock *BB,
|
|
|
|
MachineBasicBlock *MBB,
|
|
|
|
const CallInst &StackProtCheckCall) {
|
|
|
|
// Make sure we are not initialized yet.
|
|
|
|
assert(!shouldEmitStackProtector() && "Stack Protector Descriptor is "
|
|
|
|
"already initialized!");
|
|
|
|
ParentMBB = MBB;
|
|
|
|
SuccessMBB = AddSuccessorMBB(BB, MBB);
|
|
|
|
FailureMBB = AddSuccessorMBB(BB, MBB, FailureMBB);
|
|
|
|
if (!Guard)
|
|
|
|
Guard = StackProtCheckCall.getArgOperand(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reset state that changes when we handle different basic blocks.
|
|
|
|
///
|
|
|
|
/// This currently includes:
|
|
|
|
///
|
|
|
|
/// 1. The specific basic block we are generating a
|
|
|
|
/// stack protector for (ParentMBB).
|
|
|
|
///
|
|
|
|
/// 2. The successor machine basic block that will contain the tail of
|
|
|
|
/// parent mbb after we create the stack protector check (SuccessMBB). This
|
|
|
|
/// BB is visited only on stack protector check success.
|
|
|
|
void resetPerBBState() {
|
2014-04-16 04:21:27 +00:00
|
|
|
ParentMBB = nullptr;
|
|
|
|
SuccessMBB = nullptr;
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Reset state that only changes when we switch functions.
|
|
|
|
///
|
|
|
|
/// This currently includes:
|
|
|
|
///
|
|
|
|
/// 1. FailureMBB since we reuse the failure code path for all stack
|
|
|
|
/// protector checks created in an individual function.
|
|
|
|
///
|
|
|
|
/// 2.The guard variable since the guard variable we are checking against is
|
|
|
|
/// always the same.
|
|
|
|
void resetPerFunctionState() {
|
2014-04-16 04:21:27 +00:00
|
|
|
FailureMBB = nullptr;
|
|
|
|
Guard = nullptr;
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MachineBasicBlock *getParentMBB() { return ParentMBB; }
|
|
|
|
MachineBasicBlock *getSuccessMBB() { return SuccessMBB; }
|
|
|
|
MachineBasicBlock *getFailureMBB() { return FailureMBB; }
|
|
|
|
const Value *getGuard() { return Guard; }
|
|
|
|
|
2014-07-25 19:31:34 +00:00
|
|
|
unsigned getGuardReg() const { return GuardReg; }
|
|
|
|
void setGuardReg(unsigned R) { GuardReg = R; }
|
|
|
|
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
private:
|
|
|
|
/// The basic block for which we are generating the stack protector.
|
|
|
|
///
|
|
|
|
/// As a result of stack protector generation, we will splice the
|
|
|
|
/// terminators of this basic block into the successor mbb SuccessMBB and
|
|
|
|
/// replace it with a compare/branch to the successor mbbs
|
|
|
|
/// SuccessMBB/FailureMBB depending on whether or not the stack protector
|
|
|
|
/// was violated.
|
|
|
|
MachineBasicBlock *ParentMBB;
|
|
|
|
|
|
|
|
/// A basic block visited on stack protector check success that contains the
|
|
|
|
/// terminators of ParentMBB.
|
|
|
|
MachineBasicBlock *SuccessMBB;
|
|
|
|
|
|
|
|
/// This basic block visited on stack protector check failure that will
|
|
|
|
/// contain a call to __stack_chk_fail().
|
|
|
|
MachineBasicBlock *FailureMBB;
|
|
|
|
|
|
|
|
/// The guard variable which we will compare against the stored value in the
|
|
|
|
/// stack protector stack slot.
|
|
|
|
const Value *Guard;
|
|
|
|
|
2014-07-25 19:31:34 +00:00
|
|
|
/// The virtual register holding the stack guard value.
|
|
|
|
unsigned GuardReg;
|
|
|
|
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
/// Add a successor machine basic block to ParentMBB. If the successor mbb
|
|
|
|
/// has not been created yet (i.e. if SuccMBB = 0), then the machine basic
|
|
|
|
/// block will be created.
|
|
|
|
MachineBasicBlock *AddSuccessorMBB(const BasicBlock *BB,
|
|
|
|
MachineBasicBlock *ParentMBB,
|
2014-04-16 04:21:27 +00:00
|
|
|
MachineBasicBlock *SuccMBB = nullptr);
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
};
|
|
|
|
|
2013-06-19 21:36:55 +00:00
|
|
|
private:
|
2010-04-19 19:05:59 +00:00
|
|
|
const TargetMachine &TM;
|
2013-06-19 21:36:55 +00:00
|
|
|
public:
|
2014-01-12 14:09:17 +00:00
|
|
|
/// Lowest valid SDNodeOrder. The special case 0 is reserved for scheduling
|
|
|
|
/// nodes without a corresponding SDNode.
|
|
|
|
static const unsigned LowestSDNodeOrder = 1;
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
SelectionDAG &DAG;
|
2014-02-21 18:34:28 +00:00
|
|
|
const DataLayout *DL;
|
2008-09-03 16:12:24 +00:00
|
|
|
AliasAnalysis *AA;
|
2011-12-08 22:15:21 +00:00
|
|
|
const TargetLibraryInfo *LibInfo;
|
2008-09-03 16:12:24 +00:00
|
|
|
|
|
|
|
/// 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;
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
/// A StackProtectorDescriptor structure used to communicate stack protector
|
|
|
|
/// information in between SelectBasicBlock and FinishBasicBlock.
|
|
|
|
StackProtectorDescriptor SPDescriptor;
|
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.
|
2013-10-31 17:18:07 +00:00
|
|
|
///
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel;
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
/// GFI - Garbage collection metadata for the function.
|
|
|
|
GCFunctionInfo *GFI;
|
|
|
|
|
2011-10-05 22:24:35 +00:00
|
|
|
/// LPadToCallSiteMap - Map a landing pad to the call site indexes.
|
|
|
|
DenseMap<MachineBasicBlock*, SmallVector<unsigned, 4> > LPadToCallSiteMap;
|
2011-10-04 22:00:35 +00:00
|
|
|
|
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)
|
2014-04-16 04:21:27 +00:00
|
|
|
: CurInst(nullptr), SDNodeOrder(LowestSDNodeOrder), TM(dag.getTarget()),
|
2010-04-19 19:05:59 +00:00
|
|
|
DAG(dag), FuncInfo(funcinfo), OptLevel(ol),
|
2012-08-22 00:42:39 +00:00
|
|
|
HasTailCall(false) {
|
2008-09-03 16:12:24 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 22:15:21 +00:00
|
|
|
void init(GCFunctionInfo *gfi, AliasAnalysis &aa,
|
|
|
|
const TargetLibraryInfo *li);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
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();
|
|
|
|
|
2011-05-23 17:44:13 +00:00
|
|
|
/// clearDanglingDebugInfo - Clear the dangling debug information
|
2012-06-02 10:20:22 +00:00
|
|
|
/// map. This function is separated from the clear so that debug
|
2011-05-23 17:44:13 +00:00
|
|
|
/// information that is dangling in a basic block can be properly
|
|
|
|
/// resolved in a different basic block. This allows the
|
|
|
|
/// SelectionDAG to resolve dangling debug information attached
|
|
|
|
/// to PHI nodes.
|
|
|
|
void clearDanglingDebugInfo();
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
/// 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();
|
|
|
|
|
2013-05-25 02:20:36 +00:00
|
|
|
SDLoc getCurSDLoc() const {
|
|
|
|
return SDLoc(CurInst, SDNodeOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugLoc getCurDebugLoc() const {
|
|
|
|
return CurInst ? CurInst->getDebugLoc() : DebugLoc();
|
|
|
|
}
|
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-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];
|
2014-04-16 04:21:27 +00:00
|
|
|
assert(!N.getNode() && "Already set a value for this node!");
|
2008-09-03 16:12:24 +00:00
|
|
|
N = NewN;
|
|
|
|
}
|
2013-10-31 17:18:07 +00:00
|
|
|
|
2010-06-01 19:59:01 +00:00
|
|
|
void setUnusedArgValue(const Value *V, SDValue NewN) {
|
|
|
|
SDValue &N = UnusedArgNodeMap[V];
|
2014-04-16 04:21:27 +00:00
|
|
|
assert(!N.getNode() && "Already set a value for this node!");
|
2010-06-01 19:59:01 +00:00
|
|
|
N = NewN;
|
|
|
|
}
|
2008-09-03 16:12:24 +00:00
|
|
|
|
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,
|
2014-01-31 00:42:44 +00:00
|
|
|
MachineBasicBlock *SwitchBB, unsigned Opc,
|
|
|
|
uint32_t TW, uint32_t FW);
|
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,
|
2014-01-31 00:42:44 +00:00
|
|
|
MachineBasicBlock *SwitchBB,
|
|
|
|
uint32_t TW, uint32_t FW);
|
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,
|
2014-04-16 04:21:27 +00:00
|
|
|
MachineBasicBlock *LandingPad = nullptr);
|
2008-09-03 16:12:24 +00:00
|
|
|
|
2014-10-17 17:39:00 +00:00
|
|
|
std::pair<SDValue, SDValue> lowerCallOperands(
|
|
|
|
ImmutableCallSite CS,
|
|
|
|
unsigned ArgIdx,
|
|
|
|
unsigned NumArgs,
|
|
|
|
SDValue Callee,
|
|
|
|
bool UseVoidTy = false,
|
|
|
|
MachineBasicBlock *LandingPad = nullptr);
|
2013-10-31 17:18:24 +00:00
|
|
|
|
2010-09-30 19:44:31 +00:00
|
|
|
/// UpdateSplitBlock - When an MBB was split during scheduling, update the
|
2014-01-11 14:01:43 +00:00
|
|
|
/// references that need to refer to the last resulting block.
|
2010-09-30 19:44:31 +00:00
|
|
|
void UpdateSplitBlock(MachineBasicBlock *First, MachineBasicBlock *Last);
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
private:
|
2014-10-16 21:26:35 +00:00
|
|
|
std::pair<SDValue, SDValue> lowerInvokable(
|
|
|
|
TargetLowering::CallLoweringInfo &CLI,
|
|
|
|
MachineBasicBlock *LandingPad);
|
|
|
|
|
2008-09-03 16:12:24 +00:00
|
|
|
// 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);
|
2014-04-19 13:47:43 +00:00
|
|
|
void visitUnreachable(const UnreachableInst &I);
|
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 *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);
|
2011-06-16 20:22:37 +00:00
|
|
|
|
2011-12-20 20:03:10 +00:00
|
|
|
uint32_t getEdgeWeight(const MachineBasicBlock *Src,
|
|
|
|
const MachineBasicBlock *Dst) const;
|
2011-07-29 22:25:21 +00:00
|
|
|
void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
|
|
|
|
uint32_t Weight = 0);
|
2008-09-03 16:12:24 +00:00
|
|
|
public:
|
2010-04-19 22:41:47 +00:00
|
|
|
void visitSwitchCase(CaseBlock &CB,
|
|
|
|
MachineBasicBlock *SwitchBB);
|
Teach selectiondag how to handle the stackprotectorcheck intrinsic.
Previously, generation of stack protectors was done exclusively in the
pre-SelectionDAG Codegen LLVM IR Pass "Stack Protector". This necessitated
splitting basic blocks at the IR level to create the success/failure basic
blocks in the tail of the basic block in question. As a result of this,
calls that would have qualified for the sibling call optimization were no
longer eligible for optimization since said calls were no longer right in
the "tail position" (i.e. the immediate predecessor of a ReturnInst
instruction).
Then it was noticed that since the sibling call optimization causes the
callee to reuse the caller's stack, if we could delay the generation of
the stack protector check until later in CodeGen after the sibling call
decision was made, we get both the tail call optimization and the stack
protector check!
A few goals in solving this problem were:
1. Preserve the architecture independence of stack protector generation.
2. Preserve the normal IR level stack protector check for platforms like
OpenBSD for which we support platform specific stack protector
generation.
The main problem that guided the present solution is that one can not
solve this problem in an architecture independent manner at the IR level
only. This is because:
1. The decision on whether or not to perform a sibling call on certain
platforms (for instance i386) requires lower level information
related to available registers that can not be known at the IR level.
2. Even if the previous point were not true, the decision on whether to
perform a tail call is done in LowerCallTo in SelectionDAG which
occurs after the Stack Protector Pass. As a result, one would need to
put the relevant callinst into the stack protector check success
basic block (where the return inst is placed) and then move it back
later at SelectionDAG/MI time before the stack protector check if the
tail call optimization failed. The MI level option was nixed
immediately since it would require platform specific pattern
matching. The SelectionDAG level option was nixed because
SelectionDAG only processes one IR level basic block at a time
implying one could not create a DAG Combine to move the callinst.
To get around this problem a few things were realized:
1. While one can not handle multiple IR level basic blocks at the
SelectionDAG Level, one can generate multiple machine basic blocks
for one IR level basic block. This is how we handle bit tests and
switches.
2. At the MI level, tail calls are represented via a special return
MIInst called "tcreturn". Thus if we know the basic block in which we
wish to insert the stack protector check, we get the correct behavior
by always inserting the stack protector check right before the return
statement. This is a "magical transformation" since no matter where
the stack protector check intrinsic is, we always insert the stack
protector check code at the end of the BB.
Given the aforementioned constraints, the following solution was devised:
1. On platforms that do not support SelectionDAG stack protector check
generation, allow for the normal IR level stack protector check
generation to continue.
2. On platforms that do support SelectionDAG stack protector check
generation:
a. Use the IR level stack protector pass to decide if a stack
protector is required/which BB we insert the stack protector check
in by reusing the logic already therein. If we wish to generate a
stack protector check in a basic block, we place a special IR
intrinsic called llvm.stackprotectorcheck right before the BB's
returninst or if there is a callinst that could potentially be
sibling call optimized, before the call inst.
b. Then when a BB with said intrinsic is processed, we codegen the BB
normally via SelectBasicBlock. In said process, when we visit the
stack protector check, we do not actually emit anything into the
BB. Instead, we just initialize the stack protector descriptor
class (which involves stashing information/creating the success
mbbb and the failure mbb if we have not created one for this
function yet) and export the guard variable that we are going to
compare.
c. After we finish selecting the basic block, in FinishBasicBlock if
the StackProtectorDescriptor attached to the SelectionDAGBuilder is
initialized, we first find a splice point in the parent basic block
before the terminator and then splice the terminator of said basic
block into the success basic block. Then we code-gen a new tail for
the parent basic block consisting of the two loads, the comparison,
and finally two branches to the success/failure basic blocks. We
conclude by code-gening the failure basic block if we have not
code-gened it already (all stack protector checks we generate in
the same function, use the same failure basic block).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-08-20 07:00:16 +00:00
|
|
|
void visitSPDescriptorParent(StackProtectorDescriptor &SPD,
|
|
|
|
MachineBasicBlock *ParentBB);
|
|
|
|
void visitSPDescriptorFailure(StackProtectorDescriptor &SPD);
|
2010-04-19 22:41:47 +00:00
|
|
|
void visitBitTestHeader(BitTestBlock &B, MachineBasicBlock *SwitchBB);
|
2011-01-06 01:02:44 +00:00
|
|
|
void visitBitTestCase(BitTestBlock &BB,
|
|
|
|
MachineBasicBlock* NextMBB,
|
2012-08-24 18:14:27 +00:00
|
|
|
uint32_t BranchWeightToNext,
|
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);
|
2013-10-31 17:18:07 +00:00
|
|
|
|
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);
|
2011-07-31 06:30:59 +00:00
|
|
|
void visitResume(const ResumeInst &I);
|
2010-04-15 01:51:59 +00:00
|
|
|
|
|
|
|
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); }
|
Emit a more efficient magic number multiplication for exact sdivs.
We have to do this in DAGBuilder instead of DAGCombiner, because the exact bit is lost after building.
struct foo { char x[24]; };
long bar(struct foo *a, struct foo *b) { return a-b; }
is now compiled into
movl 4(%esp), %eax
subl 8(%esp), %eax
sarl $3, %eax
imull $-1431655765, %eax, %eax
instead of
movl 4(%esp), %eax
subl 8(%esp), %eax
movl $715827883, %ecx
imull %ecx
movl %edx, %eax
shrl $31, %eax
sarl $2, %edx
addl %eax, %edx
movl %edx, %eax
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134695 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-08 10:31:30 +00:00
|
|
|
void visitSDiv(const User &I);
|
2010-04-15 01:51:59 +00:00
|
|
|
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);
|
2013-11-15 01:34:59 +00:00
|
|
|
void visitAddrSpaceCast(const User &I);
|
2010-04-15 01:51:59 +00:00
|
|
|
|
|
|
|
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);
|
2011-08-12 20:24:12 +00:00
|
|
|
void visitLandingPad(const LandingPadInst &I);
|
2010-04-15 01:51:59 +00:00
|
|
|
|
|
|
|
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);
|
2011-07-28 21:48:00 +00:00
|
|
|
void visitAtomicCmpXchg(const AtomicCmpXchgInst &I);
|
|
|
|
void visitAtomicRMW(const AtomicRMWInst &I);
|
2011-07-25 23:16:38 +00:00
|
|
|
void visitFence(const FenceInst &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);
|
2013-08-20 09:38:48 +00:00
|
|
|
bool visitMemChrCall(const CallInst &I);
|
2013-08-16 11:29:37 +00:00
|
|
|
bool visitStrCpyCall(const CallInst &I, bool isStpcpy);
|
2013-08-16 11:21:54 +00:00
|
|
|
bool visitStrCmpCall(const CallInst &I);
|
2013-08-16 11:41:43 +00:00
|
|
|
bool visitStrLenCall(const CallInst &I);
|
|
|
|
bool visitStrNLenCall(const CallInst &I);
|
2012-08-03 23:29:17 +00:00
|
|
|
bool visitUnaryFloatCall(const CallInst &I, unsigned Opcode);
|
2014-10-21 23:01:01 +00:00
|
|
|
bool visitBinaryFloatCall(const CallInst &I, unsigned Opcode);
|
2011-08-24 20:50:09 +00:00
|
|
|
void visitAtomicLoad(const LoadInst &I);
|
|
|
|
void visitAtomicStore(const StoreInst &I);
|
|
|
|
|
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 visitVAStart(const CallInst &I);
|
|
|
|
void visitVAArg(const VAArgInst &I);
|
|
|
|
void visitVAEnd(const CallInst &I);
|
|
|
|
void visitVACopy(const CallInst &I);
|
2013-10-31 17:18:24 +00:00
|
|
|
void visitStackmap(const CallInst &I);
|
2014-10-17 17:39:00 +00:00
|
|
|
void visitPatchpoint(ImmutableCallSite CS,
|
|
|
|
MachineBasicBlock *LandingPad = nullptr);
|
2010-04-15 01:51:59 +00:00
|
|
|
|
|
|
|
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-22 20:55:53 +00:00
|
|
|
|
2013-08-16 10:55:47 +00:00
|
|
|
void processIntegerCallValue(const Instruction &I,
|
|
|
|
SDValue Value, bool IsSigned);
|
|
|
|
|
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
|
2013-10-31 17:18:07 +00:00
|
|
|
/// corresponding DBG_VALUE machine instruction for it now. At the end of
|
2010-08-25 20:41:24 +00:00
|
|
|
/// instruction selection, they will be inserted to the entry BB.
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218787 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-01 18:55:02 +00:00
|
|
|
bool EmitFuncArgumentDbgValue(const Value *V, MDNode *Variable, MDNode *Expr,
|
2014-04-25 20:49:25 +00:00
|
|
|
int64_t Offset, bool IsIndirect,
|
|
|
|
const SDValue &N);
|
2008-09-03 16:12:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|