mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
Propagate changes from my local tree. This patch includes:
1. New parameter attribute called 'inreg'. It has meaning "place this parameter in registers, if possible". This is some generalization of gcc's regparm(n) attribute. It's currently used only in X86-32 backend. 2. Completely rewritten CC handling/lowering code inside X86 backend. Merged stdcall + c CCs and fastcall + fast CC. 3. Dropped CSRET CC. We cannot add struct return variant for each target-specific CC (e.g. stdcall + csretcc and so on). 4. Instead of CSRET CC introduced 'sret' parameter attribute. Setting in on first attribute has meaning 'This is hidden pointer to structure return. Handle it gently'. 5. Fixed small bug in llvm-extract + add new feature to FunctionExtraction pass, which relinks all internal-linkaged callees from deleted function to external linkage. This will allow further linking everything together. NOTEs: 1. Documentation will be updated soon. 2. llvm-upgrade should be improved to translate csret => sret. Before this, there will be some unexpected test fails. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33597 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f0876c7cb7
commit
b10308e440
@ -30,14 +30,6 @@ namespace CallingConv {
|
|||||||
/// certain amounts of prototype mismatch.
|
/// certain amounts of prototype mismatch.
|
||||||
C = 0,
|
C = 0,
|
||||||
|
|
||||||
/// CSRet - C Struct Return calling convention. This convention requires
|
|
||||||
/// that the function return void and take a pointer as the first argument
|
|
||||||
/// of the struct. This is used by targets which need to distinguish
|
|
||||||
/// between C functions returning a structure, and C functions taking a
|
|
||||||
/// structure pointer as the first argument to the function.
|
|
||||||
CSRet = 1,
|
|
||||||
|
|
||||||
|
|
||||||
// Generic LLVM calling conventions. None of these calling conventions
|
// Generic LLVM calling conventions. None of these calling conventions
|
||||||
// support varargs calls, and all assume that the caller and callee
|
// support varargs calls, and all assume that the caller and callee
|
||||||
// prototype exactly match.
|
// prototype exactly match.
|
||||||
|
@ -133,20 +133,25 @@ namespace ISD {
|
|||||||
// UNDEF - An undefined node
|
// UNDEF - An undefined node
|
||||||
UNDEF,
|
UNDEF,
|
||||||
|
|
||||||
/// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG) - This node represents the formal
|
/// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
|
||||||
/// arguments for a function. CC# is a Constant value indicating the
|
/// represents the formal arguments for a function. CC# is a Constant value
|
||||||
/// calling convention of the function, and ISVARARG is a flag that
|
/// indicating the calling convention of the function, and ISVARARG is a
|
||||||
/// indicates whether the function is varargs or not. This node has one
|
/// flag that indicates whether the function is varargs or not. This node
|
||||||
/// result value for each incoming argument, plus one for the output chain.
|
/// has one result value for each incoming argument, plus one for the output
|
||||||
/// It must be custom legalized.
|
/// chain. It must be custom legalized. See description of CALL node for
|
||||||
|
/// FLAG argument contents explanation.
|
||||||
///
|
///
|
||||||
FORMAL_ARGUMENTS,
|
FORMAL_ARGUMENTS,
|
||||||
|
|
||||||
/// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
|
/// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
|
||||||
/// ARG0, SIGN0, ARG1, SIGN1, ... ARGn, SIGNn)
|
/// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
|
||||||
/// This node represents a fully general function call, before the legalizer
|
/// This node represents a fully general function call, before the legalizer
|
||||||
/// runs. This has one result value for each argument / signness pair, plus
|
/// runs. This has one result value for each argument / flag pair, plus
|
||||||
/// a chain result. It must be custom legalized.
|
/// a chain result. It must be custom legalized. Flag argument indicates
|
||||||
|
/// misc. argument attributes. Currently:
|
||||||
|
/// Bit 0 - signness
|
||||||
|
/// Bit 1 - 'inreg' attribute
|
||||||
|
/// Bit 2 - 'sret' attribute
|
||||||
CALL,
|
CALL,
|
||||||
|
|
||||||
// EXTRACT_ELEMENT - This is used to get the first or second (determined by
|
// EXTRACT_ELEMENT - This is used to get the first or second (determined by
|
||||||
|
@ -134,7 +134,9 @@ public:
|
|||||||
NoAttributeSet = 0, ///< No attribute value has been set
|
NoAttributeSet = 0, ///< No attribute value has been set
|
||||||
ZExtAttribute = 1, ///< zero extended before/after call
|
ZExtAttribute = 1, ///< zero extended before/after call
|
||||||
SExtAttribute = 1 << 1, ///< sign extended before/after call
|
SExtAttribute = 1 << 1, ///< sign extended before/after call
|
||||||
NoReturnAttribute = 1 << 2 ///< mark the function as not returning
|
NoReturnAttribute = 1 << 2, ///< mark the function as not returning
|
||||||
|
InRegAttribute = 1 << 3, ///< force argument to be passed in register
|
||||||
|
StructRetAttribute= 1 << 4 ///< hidden pointer to structure to return
|
||||||
};
|
};
|
||||||
typedef std::vector<ParameterAttributes> ParamAttrsList;
|
typedef std::vector<ParameterAttributes> ParamAttrsList;
|
||||||
private:
|
private:
|
||||||
@ -176,6 +178,10 @@ public:
|
|||||||
///
|
///
|
||||||
unsigned getNumParams() const { return unsigned(ContainedTys.size()-1); }
|
unsigned getNumParams() const { return unsigned(ContainedTys.size()-1); }
|
||||||
|
|
||||||
|
bool isStructReturn() const {
|
||||||
|
return (getNumParams() && paramHasAttr(1, StructRetAttribute));
|
||||||
|
}
|
||||||
|
|
||||||
/// The parameter attributes for the \p ith parameter are returned. The 0th
|
/// The parameter attributes for the \p ith parameter are returned. The 0th
|
||||||
/// parameter refers to the return type of the function.
|
/// parameter refers to the return type of the function.
|
||||||
/// @returns The ParameterAttributes for the \p ith parameter.
|
/// @returns The ParameterAttributes for the \p ith parameter.
|
||||||
|
@ -730,6 +730,8 @@ public:
|
|||||||
SDOperand Node;
|
SDOperand Node;
|
||||||
const Type* Ty;
|
const Type* Ty;
|
||||||
bool isSigned;
|
bool isSigned;
|
||||||
|
bool isInReg;
|
||||||
|
bool isSRet;
|
||||||
};
|
};
|
||||||
typedef std::vector<ArgListEntry> ArgListTy;
|
typedef std::vector<ArgListEntry> ArgListTy;
|
||||||
virtual std::pair<SDOperand, SDOperand>
|
virtual std::pair<SDOperand, SDOperand>
|
||||||
|
@ -82,7 +82,8 @@ ModulePass *createGlobalDCEPass();
|
|||||||
/// the specified function. Otherwise, it deletes as much of the module as
|
/// the specified function. Otherwise, it deletes as much of the module as
|
||||||
/// possible, except for the function specified.
|
/// possible, except for the function specified.
|
||||||
///
|
///
|
||||||
ModulePass *createFunctionExtractionPass(Function *F, bool deleteFn = false);
|
ModulePass *createFunctionExtractionPass(Function *F, bool deleteFn = false,
|
||||||
|
bool relinkCallees = false);
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -227,7 +227,6 @@ sideeffect { return SIDEEFFECT; }
|
|||||||
|
|
||||||
cc { return CC_TOK; }
|
cc { return CC_TOK; }
|
||||||
ccc { return CCC_TOK; }
|
ccc { return CCC_TOK; }
|
||||||
csretcc { return CSRETCC_TOK; }
|
|
||||||
fastcc { return FASTCC_TOK; }
|
fastcc { return FASTCC_TOK; }
|
||||||
coldcc { return COLDCC_TOK; }
|
coldcc { return COLDCC_TOK; }
|
||||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||||
@ -287,6 +286,8 @@ call { RET_TOK(OtherOpVal, Call, CALL); }
|
|||||||
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
||||||
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
||||||
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
||||||
|
inreg { return INREG; }
|
||||||
|
sret { return SRET; }
|
||||||
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
||||||
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
||||||
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
||||||
|
@ -227,7 +227,6 @@ sideeffect { return SIDEEFFECT; }
|
|||||||
|
|
||||||
cc { return CC_TOK; }
|
cc { return CC_TOK; }
|
||||||
ccc { return CCC_TOK; }
|
ccc { return CCC_TOK; }
|
||||||
csretcc { return CSRETCC_TOK; }
|
|
||||||
fastcc { return FASTCC_TOK; }
|
fastcc { return FASTCC_TOK; }
|
||||||
coldcc { return COLDCC_TOK; }
|
coldcc { return COLDCC_TOK; }
|
||||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||||
@ -287,6 +286,8 @@ call { RET_TOK(OtherOpVal, Call, CALL); }
|
|||||||
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
||||||
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
||||||
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
||||||
|
inreg { return INREG; }
|
||||||
|
sret { return SRET; }
|
||||||
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
||||||
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
||||||
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
||||||
|
@ -984,8 +984,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
|||||||
%token DLLIMPORT DLLEXPORT EXTERN_WEAK
|
%token DLLIMPORT DLLEXPORT EXTERN_WEAK
|
||||||
%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN
|
%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN
|
||||||
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
|
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
|
||||||
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
|
%token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
|
||||||
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
|
|
||||||
%token DATALAYOUT
|
%token DATALAYOUT
|
||||||
%type <UIntVal> OptCallingConv
|
%type <UIntVal> OptCallingConv
|
||||||
%type <ParamAttrs> OptParamAttrs ParamAttr
|
%type <ParamAttrs> OptParamAttrs ParamAttr
|
||||||
@ -1017,7 +1016,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
|||||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||||
|
|
||||||
// Function Attributes
|
// Function Attributes
|
||||||
%token NORETURN
|
%token NORETURN INREG SRET
|
||||||
|
|
||||||
// Visibility Styles
|
// Visibility Styles
|
||||||
%token DEFAULT HIDDEN
|
%token DEFAULT HIDDEN
|
||||||
@ -1119,7 +1118,6 @@ FunctionDefineLinkage
|
|||||||
|
|
||||||
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
||||||
CCC_TOK { $$ = CallingConv::C; } |
|
CCC_TOK { $$ = CallingConv::C; } |
|
||||||
CSRETCC_TOK { $$ = CallingConv::CSRet; } |
|
|
||||||
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
||||||
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
||||||
X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; } |
|
X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; } |
|
||||||
@ -1131,8 +1129,10 @@ OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
|||||||
CHECK_FOR_ERROR
|
CHECK_FOR_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
ParamAttr : ZEXT { $$ = FunctionType::ZExtAttribute; }
|
ParamAttr : ZEXT { $$ = FunctionType::ZExtAttribute; }
|
||||||
| SEXT { $$ = FunctionType::SExtAttribute; }
|
| SEXT { $$ = FunctionType::SExtAttribute; }
|
||||||
|
| INREG { $$ = FunctionType::InRegAttribute; }
|
||||||
|
| SRET { $$ = FunctionType::StructRetAttribute; }
|
||||||
;
|
;
|
||||||
|
|
||||||
OptParamAttrs : /* empty */ { $$ = FunctionType::NoAttributeSet; }
|
OptParamAttrs : /* empty */ { $$ = FunctionType::NoAttributeSet; }
|
||||||
|
@ -984,8 +984,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
|||||||
%token DLLIMPORT DLLEXPORT EXTERN_WEAK
|
%token DLLIMPORT DLLEXPORT EXTERN_WEAK
|
||||||
%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN
|
%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN
|
||||||
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
|
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
|
||||||
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
|
%token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
|
||||||
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
|
|
||||||
%token DATALAYOUT
|
%token DATALAYOUT
|
||||||
%type <UIntVal> OptCallingConv
|
%type <UIntVal> OptCallingConv
|
||||||
%type <ParamAttrs> OptParamAttrs ParamAttr
|
%type <ParamAttrs> OptParamAttrs ParamAttr
|
||||||
@ -1017,7 +1016,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
|||||||
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
%token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
|
||||||
|
|
||||||
// Function Attributes
|
// Function Attributes
|
||||||
%token NORETURN
|
%token NORETURN INREG SRET
|
||||||
|
|
||||||
// Visibility Styles
|
// Visibility Styles
|
||||||
%token DEFAULT HIDDEN
|
%token DEFAULT HIDDEN
|
||||||
@ -1119,7 +1118,6 @@ FunctionDefineLinkage
|
|||||||
|
|
||||||
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
||||||
CCC_TOK { $$ = CallingConv::C; } |
|
CCC_TOK { $$ = CallingConv::C; } |
|
||||||
CSRETCC_TOK { $$ = CallingConv::CSRet; } |
|
|
||||||
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
FASTCC_TOK { $$ = CallingConv::Fast; } |
|
||||||
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
COLDCC_TOK { $$ = CallingConv::Cold; } |
|
||||||
X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; } |
|
X86_STDCALLCC_TOK { $$ = CallingConv::X86_StdCall; } |
|
||||||
@ -1131,8 +1129,10 @@ OptCallingConv : /*empty*/ { $$ = CallingConv::C; } |
|
|||||||
CHECK_FOR_ERROR
|
CHECK_FOR_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
ParamAttr : ZEXT { $$ = FunctionType::ZExtAttribute; }
|
ParamAttr : ZEXT { $$ = FunctionType::ZExtAttribute; }
|
||||||
| SEXT { $$ = FunctionType::SExtAttribute; }
|
| SEXT { $$ = FunctionType::SExtAttribute; }
|
||||||
|
| INREG { $$ = FunctionType::InRegAttribute; }
|
||||||
|
| SRET { $$ = FunctionType::StructRetAttribute; }
|
||||||
;
|
;
|
||||||
|
|
||||||
OptParamAttrs : /* empty */ { $$ = FunctionType::NoAttributeSet; }
|
OptParamAttrs : /* empty */ { $$ = FunctionType::NoAttributeSet; }
|
||||||
|
@ -2168,6 +2168,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
|
|||||||
const char *FnName = 0;
|
const char *FnName = 0;
|
||||||
if (Node->getOpcode() == ISD::MEMSET) {
|
if (Node->getOpcode() == ISD::MEMSET) {
|
||||||
Entry.Node = Tmp2; Entry.isSigned = false; Entry.Ty = IntPtrTy;
|
Entry.Node = Tmp2; Entry.isSigned = false; Entry.Ty = IntPtrTy;
|
||||||
|
Entry.isInReg = false;
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
// Extend the (previously legalized) ubyte argument to be an int value
|
// Extend the (previously legalized) ubyte argument to be an int value
|
||||||
// for the call.
|
// for the call.
|
||||||
@ -2176,6 +2177,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
|
|||||||
else
|
else
|
||||||
Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3);
|
Tmp3 = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Tmp3);
|
||||||
Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSigned = true;
|
Entry.Node = Tmp3; Entry.Ty = Type::Int32Ty; Entry.isSigned = true;
|
||||||
|
Entry.isInReg = false;
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSigned = false;
|
Entry.Node = Tmp4; Entry.Ty = IntPtrTy; Entry.isSigned = false;
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
@ -2183,7 +2185,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
|
|||||||
FnName = "memset";
|
FnName = "memset";
|
||||||
} else if (Node->getOpcode() == ISD::MEMCPY ||
|
} else if (Node->getOpcode() == ISD::MEMCPY ||
|
||||||
Node->getOpcode() == ISD::MEMMOVE) {
|
Node->getOpcode() == ISD::MEMMOVE) {
|
||||||
Entry.Ty = IntPtrTy; Entry.isSigned = false;
|
Entry.Ty = IntPtrTy; Entry.isSigned = false; Entry.isInReg = false;
|
||||||
Entry.Node = Tmp2; Args.push_back(Entry);
|
Entry.Node = Tmp2; Args.push_back(Entry);
|
||||||
Entry.Node = Tmp3; Args.push_back(Entry);
|
Entry.Node = Tmp3; Args.push_back(Entry);
|
||||||
Entry.Node = Tmp4; Args.push_back(Entry);
|
Entry.Node = Tmp4; Args.push_back(Entry);
|
||||||
@ -4124,7 +4126,7 @@ SDOperand SelectionDAGLegalize::ExpandLibCall(const char *Name, SDNode *Node,
|
|||||||
MVT::ValueType ArgVT = Node->getOperand(i).getValueType();
|
MVT::ValueType ArgVT = Node->getOperand(i).getValueType();
|
||||||
const Type *ArgTy = MVT::getTypeForValueType(ArgVT);
|
const Type *ArgTy = MVT::getTypeForValueType(ArgVT);
|
||||||
Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
|
Entry.Node = Node->getOperand(i); Entry.Ty = ArgTy;
|
||||||
Entry.isSigned = isSigned;
|
Entry.isSigned = isSigned; Entry.isInReg = false;
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
}
|
}
|
||||||
SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy());
|
SDOperand Callee = DAG.getExternalSymbol(Name, TLI.getPointerTy());
|
||||||
|
@ -2167,6 +2167,8 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
|
|||||||
SDOperand ArgNode = getValue(Arg);
|
SDOperand ArgNode = getValue(Arg);
|
||||||
Entry.Node = ArgNode; Entry.Ty = Arg->getType();
|
Entry.Node = ArgNode; Entry.Ty = Arg->getType();
|
||||||
Entry.isSigned = FTy->paramHasAttr(i, FunctionType::SExtAttribute);
|
Entry.isSigned = FTy->paramHasAttr(i, FunctionType::SExtAttribute);
|
||||||
|
Entry.isInReg = FTy->paramHasAttr(i, FunctionType::InRegAttribute);
|
||||||
|
Entry.isSRet = FTy->paramHasAttr(i, FunctionType::StructRetAttribute);
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2761,6 +2763,8 @@ void SelectionDAGLowering::visitMalloc(MallocInst &I) {
|
|||||||
Entry.Node = Src;
|
Entry.Node = Src;
|
||||||
Entry.Ty = TLI.getTargetData()->getIntPtrType();
|
Entry.Ty = TLI.getTargetData()->getIntPtrType();
|
||||||
Entry.isSigned = false;
|
Entry.isSigned = false;
|
||||||
|
Entry.isInReg = false;
|
||||||
|
Entry.isSRet = false;
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
|
|
||||||
std::pair<SDOperand,SDOperand> Result =
|
std::pair<SDOperand,SDOperand> Result =
|
||||||
@ -2777,6 +2781,8 @@ void SelectionDAGLowering::visitFree(FreeInst &I) {
|
|||||||
Entry.Node = getValue(I.getOperand(0));
|
Entry.Node = getValue(I.getOperand(0));
|
||||||
Entry.Ty = TLI.getTargetData()->getIntPtrType();
|
Entry.Ty = TLI.getTargetData()->getIntPtrType();
|
||||||
Entry.isSigned = false;
|
Entry.isSigned = false;
|
||||||
|
Entry.isInReg = false;
|
||||||
|
Entry.isSRet = false;
|
||||||
Args.push_back(Entry);
|
Args.push_back(Entry);
|
||||||
MVT::ValueType IntPtr = TLI.getPointerTy();
|
MVT::ValueType IntPtr = TLI.getPointerTy();
|
||||||
std::pair<SDOperand,SDOperand> Result =
|
std::pair<SDOperand,SDOperand> Result =
|
||||||
@ -2859,6 +2865,7 @@ static SDOperand ExpandScalarFormalArgs(MVT::ValueType VT, SDNode *Arg,
|
|||||||
/// integrated into SDISel.
|
/// integrated into SDISel.
|
||||||
std::vector<SDOperand>
|
std::vector<SDOperand>
|
||||||
TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
||||||
|
const FunctionType *FTy = F.getFunctionType();
|
||||||
// Add CC# and isVararg as operands to the FORMAL_ARGUMENTS node.
|
// Add CC# and isVararg as operands to the FORMAL_ARGUMENTS node.
|
||||||
std::vector<SDOperand> Ops;
|
std::vector<SDOperand> Ops;
|
||||||
Ops.push_back(DAG.getRoot());
|
Ops.push_back(DAG.getRoot());
|
||||||
@ -2867,16 +2874,22 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
|
|
||||||
// Add one result value for each formal argument.
|
// Add one result value for each formal argument.
|
||||||
std::vector<MVT::ValueType> RetVals;
|
std::vector<MVT::ValueType> RetVals;
|
||||||
|
unsigned j = 0;
|
||||||
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
|
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
|
||||||
MVT::ValueType VT = getValueType(I->getType());
|
MVT::ValueType VT = getValueType(I->getType());
|
||||||
|
bool isInReg = FTy->paramHasAttr(++j, FunctionType::InRegAttribute);
|
||||||
|
bool isSRet = FTy->paramHasAttr(j, FunctionType::StructRetAttribute);
|
||||||
|
unsigned Flags = (isInReg << 1) | (isSRet << 2);
|
||||||
|
|
||||||
switch (getTypeAction(VT)) {
|
switch (getTypeAction(VT)) {
|
||||||
default: assert(0 && "Unknown type action!");
|
default: assert(0 && "Unknown type action!");
|
||||||
case Legal:
|
case Legal:
|
||||||
RetVals.push_back(VT);
|
RetVals.push_back(VT);
|
||||||
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
break;
|
break;
|
||||||
case Promote:
|
case Promote:
|
||||||
RetVals.push_back(getTypeToTransformTo(VT));
|
RetVals.push_back(getTypeToTransformTo(VT));
|
||||||
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
break;
|
break;
|
||||||
case Expand:
|
case Expand:
|
||||||
if (VT != MVT::Vector) {
|
if (VT != MVT::Vector) {
|
||||||
@ -2885,8 +2898,10 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
// integers it turns into.
|
// integers it turns into.
|
||||||
MVT::ValueType NVT = getTypeToExpandTo(VT);
|
MVT::ValueType NVT = getTypeToExpandTo(VT);
|
||||||
unsigned NumVals = getNumElements(VT);
|
unsigned NumVals = getNumElements(VT);
|
||||||
for (unsigned i = 0; i != NumVals; ++i)
|
for (unsigned i = 0; i != NumVals; ++i) {
|
||||||
RetVals.push_back(NVT);
|
RetVals.push_back(NVT);
|
||||||
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, this is a vector type. We only support legal vectors
|
// Otherwise, this is a vector type. We only support legal vectors
|
||||||
// right now.
|
// right now.
|
||||||
@ -2898,6 +2913,7 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
MVT::ValueType TVT = MVT::getVectorType(getValueType(EltTy), NumElems);
|
MVT::ValueType TVT = MVT::getVectorType(getValueType(EltTy), NumElems);
|
||||||
if (TVT != MVT::Other && isTypeLegal(TVT)) {
|
if (TVT != MVT::Other && isTypeLegal(TVT)) {
|
||||||
RetVals.push_back(TVT);
|
RetVals.push_back(TVT);
|
||||||
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
} else {
|
} else {
|
||||||
assert(0 && "Don't support illegal by-val vector arguments yet!");
|
assert(0 && "Don't support illegal by-val vector arguments yet!");
|
||||||
}
|
}
|
||||||
@ -2917,7 +2933,6 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
|
|
||||||
// Set up the return result vector.
|
// Set up the return result vector.
|
||||||
Ops.clear();
|
Ops.clear();
|
||||||
const FunctionType *FTy = F.getFunctionType();
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
unsigned Idx = 1;
|
unsigned Idx = 1;
|
||||||
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E;
|
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E;
|
||||||
@ -2984,13 +2999,13 @@ TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
|
|||||||
/// ExpandScalarCallArgs - Recursively expand call argument node by
|
/// ExpandScalarCallArgs - Recursively expand call argument node by
|
||||||
/// bit_converting it or extract a pair of elements from the larger node.
|
/// bit_converting it or extract a pair of elements from the larger node.
|
||||||
static void ExpandScalarCallArgs(MVT::ValueType VT, SDOperand Arg,
|
static void ExpandScalarCallArgs(MVT::ValueType VT, SDOperand Arg,
|
||||||
bool isSigned,
|
unsigned Flags,
|
||||||
SmallVector<SDOperand, 32> &Ops,
|
SmallVector<SDOperand, 32> &Ops,
|
||||||
SelectionDAG &DAG,
|
SelectionDAG &DAG,
|
||||||
TargetLowering &TLI) {
|
TargetLowering &TLI) {
|
||||||
if (TLI.getTypeAction(VT) != TargetLowering::Expand) {
|
if (TLI.getTypeAction(VT) != TargetLowering::Expand) {
|
||||||
Ops.push_back(Arg);
|
Ops.push_back(Arg);
|
||||||
Ops.push_back(DAG.getConstant(isSigned, MVT::i32));
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2998,7 +3013,7 @@ static void ExpandScalarCallArgs(MVT::ValueType VT, SDOperand Arg,
|
|||||||
unsigned NumVals = MVT::getSizeInBits(VT) / MVT::getSizeInBits(EVT);
|
unsigned NumVals = MVT::getSizeInBits(VT) / MVT::getSizeInBits(EVT);
|
||||||
if (NumVals == 1) {
|
if (NumVals == 1) {
|
||||||
Arg = DAG.getNode(ISD::BIT_CONVERT, EVT, Arg);
|
Arg = DAG.getNode(ISD::BIT_CONVERT, EVT, Arg);
|
||||||
ExpandScalarCallArgs(EVT, Arg, isSigned, Ops, DAG, TLI);
|
ExpandScalarCallArgs(EVT, Arg, Flags, Ops, DAG, TLI);
|
||||||
} else if (NumVals == 2) {
|
} else if (NumVals == 2) {
|
||||||
SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, EVT, Arg,
|
SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, EVT, Arg,
|
||||||
DAG.getConstant(0, TLI.getPointerTy()));
|
DAG.getConstant(0, TLI.getPointerTy()));
|
||||||
@ -3006,8 +3021,8 @@ static void ExpandScalarCallArgs(MVT::ValueType VT, SDOperand Arg,
|
|||||||
DAG.getConstant(1, TLI.getPointerTy()));
|
DAG.getConstant(1, TLI.getPointerTy()));
|
||||||
if (!TLI.isLittleEndian())
|
if (!TLI.isLittleEndian())
|
||||||
std::swap(Lo, Hi);
|
std::swap(Lo, Hi);
|
||||||
ExpandScalarCallArgs(EVT, Lo, isSigned, Ops, DAG, TLI);
|
ExpandScalarCallArgs(EVT, Lo, Flags, Ops, DAG, TLI);
|
||||||
ExpandScalarCallArgs(EVT, Hi, isSigned, Ops, DAG, TLI);
|
ExpandScalarCallArgs(EVT, Hi, Flags, Ops, DAG, TLI);
|
||||||
} else {
|
} else {
|
||||||
// Value scalarized into many values. Unimp for now.
|
// Value scalarized into many values. Unimp for now.
|
||||||
assert(0 && "Cannot expand i64 -> i16 yet!");
|
assert(0 && "Cannot expand i64 -> i16 yet!");
|
||||||
@ -3036,11 +3051,14 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
|
|||||||
MVT::ValueType VT = getValueType(Args[i].Ty);
|
MVT::ValueType VT = getValueType(Args[i].Ty);
|
||||||
SDOperand Op = Args[i].Node;
|
SDOperand Op = Args[i].Node;
|
||||||
bool isSigned = Args[i].isSigned;
|
bool isSigned = Args[i].isSigned;
|
||||||
|
bool isInReg = Args[i].isInReg;
|
||||||
|
bool isSRet = Args[i].isSRet;
|
||||||
|
unsigned Flags = (isSRet << 2) | (isInReg << 1) | isSigned;
|
||||||
switch (getTypeAction(VT)) {
|
switch (getTypeAction(VT)) {
|
||||||
default: assert(0 && "Unknown type action!");
|
default: assert(0 && "Unknown type action!");
|
||||||
case Legal:
|
case Legal:
|
||||||
Ops.push_back(Op);
|
Ops.push_back(Op);
|
||||||
Ops.push_back(DAG.getConstant(isSigned, MVT::i32));
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
break;
|
break;
|
||||||
case Promote:
|
case Promote:
|
||||||
if (MVT::isInteger(VT)) {
|
if (MVT::isInteger(VT)) {
|
||||||
@ -3051,14 +3069,14 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
|
|||||||
Op = DAG.getNode(ISD::FP_EXTEND, getTypeToTransformTo(VT), Op);
|
Op = DAG.getNode(ISD::FP_EXTEND, getTypeToTransformTo(VT), Op);
|
||||||
}
|
}
|
||||||
Ops.push_back(Op);
|
Ops.push_back(Op);
|
||||||
Ops.push_back(DAG.getConstant(isSigned, MVT::i32));
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
break;
|
break;
|
||||||
case Expand:
|
case Expand:
|
||||||
if (VT != MVT::Vector) {
|
if (VT != MVT::Vector) {
|
||||||
// If this is a large integer, it needs to be broken down into small
|
// If this is a large integer, it needs to be broken down into small
|
||||||
// integers. Figure out what the source elt type is and how many small
|
// integers. Figure out what the source elt type is and how many small
|
||||||
// integers it is.
|
// integers it is.
|
||||||
ExpandScalarCallArgs(VT, Op, isSigned, Ops, DAG, *this);
|
ExpandScalarCallArgs(VT, Op, Flags, Ops, DAG, *this);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, this is a vector type. We only support legal vectors
|
// Otherwise, this is a vector type. We only support legal vectors
|
||||||
// right now.
|
// right now.
|
||||||
@ -3073,7 +3091,7 @@ TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
|
|||||||
// Insert a VBIT_CONVERT of the MVT::Vector type to the packed type.
|
// Insert a VBIT_CONVERT of the MVT::Vector type to the packed type.
|
||||||
Op = DAG.getNode(ISD::VBIT_CONVERT, TVT, Op);
|
Op = DAG.getNode(ISD::VBIT_CONVERT, TVT, Op);
|
||||||
Ops.push_back(Op);
|
Ops.push_back(Op);
|
||||||
Ops.push_back(DAG.getConstant(isSigned, MVT::i32));
|
Ops.push_back(DAG.getConstant(Flags, MVT::i32));
|
||||||
} else {
|
} else {
|
||||||
assert(0 && "Don't support illegal by-val vector call args yet!");
|
assert(0 && "Don't support illegal by-val vector call args yet!");
|
||||||
abort();
|
abort();
|
||||||
|
@ -352,7 +352,6 @@ SDOperand ARMTargetLowering::LowerCALL(SDOperand Op, SelectionDAG &DAG) {
|
|||||||
SDOperand Chain = Op.getOperand(0);
|
SDOperand Chain = Op.getOperand(0);
|
||||||
unsigned CallConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
|
unsigned CallConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
|
||||||
assert((CallConv == CallingConv::C ||
|
assert((CallConv == CallingConv::C ||
|
||||||
CallConv == CallingConv::CSRet ||
|
|
||||||
CallConv == CallingConv::Fast) && "unknown calling convention");
|
CallConv == CallingConv::Fast) && "unknown calling convention");
|
||||||
SDOperand Callee = Op.getOperand(4);
|
SDOperand Callee = Op.getOperand(4);
|
||||||
unsigned NumOps = (Op.getNumOperands() - 5) / 2;
|
unsigned NumOps = (Op.getNumOperands() - 5) / 2;
|
||||||
|
@ -1748,8 +1748,8 @@ void CWriter::printContainedStructs(const Type *Ty,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
||||||
/// isCStructReturn - Should this function actually return a struct by-value?
|
/// isStructReturn - Should this function actually return a struct by-value?
|
||||||
bool isCStructReturn = F->getCallingConv() == CallingConv::CSRet;
|
bool isStructReturn = F->getFunctionType()->isStructReturn();
|
||||||
|
|
||||||
if (F->hasInternalLinkage()) Out << "static ";
|
if (F->hasInternalLinkage()) Out << "static ";
|
||||||
if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
|
if (F->hasDLLImportLinkage()) Out << "__declspec(dllimport) ";
|
||||||
@ -1778,7 +1778,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
|||||||
|
|
||||||
// If this is a struct-return function, don't print the hidden
|
// If this is a struct-return function, don't print the hidden
|
||||||
// struct-return argument.
|
// struct-return argument.
|
||||||
if (isCStructReturn) {
|
if (isStructReturn) {
|
||||||
assert(I != E && "Invalid struct return function!");
|
assert(I != E && "Invalid struct return function!");
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
@ -1804,7 +1804,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
|||||||
|
|
||||||
// If this is a struct-return function, don't print the hidden
|
// If this is a struct-return function, don't print the hidden
|
||||||
// struct-return argument.
|
// struct-return argument.
|
||||||
if (isCStructReturn) {
|
if (isStructReturn) {
|
||||||
assert(I != E && "Invalid struct return function!");
|
assert(I != E && "Invalid struct return function!");
|
||||||
++I;
|
++I;
|
||||||
}
|
}
|
||||||
@ -1832,7 +1832,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
|
|||||||
|
|
||||||
// Get the return tpe for the function.
|
// Get the return tpe for the function.
|
||||||
const Type *RetTy;
|
const Type *RetTy;
|
||||||
if (!isCStructReturn)
|
if (!isStructReturn)
|
||||||
RetTy = F->getReturnType();
|
RetTy = F->getReturnType();
|
||||||
else {
|
else {
|
||||||
// If this is a struct-return function, print the struct-return type.
|
// If this is a struct-return function, print the struct-return type.
|
||||||
@ -1855,11 +1855,14 @@ static inline bool isFPIntBitCast(const Instruction &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::printFunction(Function &F) {
|
void CWriter::printFunction(Function &F) {
|
||||||
|
/// isStructReturn - Should this function actually return a struct by-value?
|
||||||
|
bool isStructReturn = F.getFunctionType()->isStructReturn();
|
||||||
|
|
||||||
printFunctionSignature(&F, false);
|
printFunctionSignature(&F, false);
|
||||||
Out << " {\n";
|
Out << " {\n";
|
||||||
|
|
||||||
// If this is a struct return function, handle the result with magic.
|
// If this is a struct return function, handle the result with magic.
|
||||||
if (F.getCallingConv() == CallingConv::CSRet) {
|
if (isStructReturn) {
|
||||||
const Type *StructTy =
|
const Type *StructTy =
|
||||||
cast<PointerType>(F.arg_begin()->getType())->getElementType();
|
cast<PointerType>(F.arg_begin()->getType())->getElementType();
|
||||||
Out << " ";
|
Out << " ";
|
||||||
@ -1977,7 +1980,10 @@ void CWriter::printBasicBlock(BasicBlock *BB) {
|
|||||||
//
|
//
|
||||||
void CWriter::visitReturnInst(ReturnInst &I) {
|
void CWriter::visitReturnInst(ReturnInst &I) {
|
||||||
// If this is a struct return function, return the temporary struct.
|
// If this is a struct return function, return the temporary struct.
|
||||||
if (I.getParent()->getParent()->getCallingConv() == CallingConv::CSRet) {
|
bool isStructReturn = I.getParent()->getParent()->
|
||||||
|
getFunctionType()->isStructReturn();
|
||||||
|
|
||||||
|
if (isStructReturn) {
|
||||||
Out << " return StructReturn;\n";
|
Out << " return StructReturn;\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2468,9 +2474,12 @@ void CWriter::visitCallInst(CallInst &I) {
|
|||||||
|
|
||||||
Value *Callee = I.getCalledValue();
|
Value *Callee = I.getCalledValue();
|
||||||
|
|
||||||
|
const PointerType *PTy = cast<PointerType>(Callee->getType());
|
||||||
|
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
|
||||||
|
|
||||||
// If this is a call to a struct-return function, assign to the first
|
// If this is a call to a struct-return function, assign to the first
|
||||||
// parameter instead of passing it to the call.
|
// parameter instead of passing it to the call.
|
||||||
bool isStructRet = I.getCallingConv() == CallingConv::CSRet;
|
bool isStructRet = FTy->isStructReturn();
|
||||||
if (isStructRet) {
|
if (isStructRet) {
|
||||||
Out << "*(";
|
Out << "*(";
|
||||||
writeOperand(I.getOperand(1));
|
writeOperand(I.getOperand(1));
|
||||||
@ -2478,9 +2487,6 @@ void CWriter::visitCallInst(CallInst &I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (I.isTailCall()) Out << " /*tail*/ ";
|
if (I.isTailCall()) Out << " /*tail*/ ";
|
||||||
|
|
||||||
const PointerType *PTy = cast<PointerType>(Callee->getType());
|
|
||||||
const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
|
|
||||||
|
|
||||||
if (!WroteCallee) {
|
if (!WroteCallee) {
|
||||||
// If this is an indirect call to a struct return function, we need to cast
|
// If this is an indirect call to a struct return function, we need to cast
|
||||||
|
@ -1360,9 +1360,9 @@ static SDOperand LowerCALL(SDOperand Op, SelectionDAG &DAG) {
|
|||||||
|
|
||||||
// On PPC64, promote integers to 64-bit values.
|
// On PPC64, promote integers to 64-bit values.
|
||||||
if (isPPC64 && Arg.getValueType() == MVT::i32) {
|
if (isPPC64 && Arg.getValueType() == MVT::i32) {
|
||||||
unsigned ExtOp = ISD::ZERO_EXTEND;
|
unsigned Flags = cast<ConstantSDNode>(Op.getOperand(5+2*i+1))->getValue();
|
||||||
if (cast<ConstantSDNode>(Op.getOperand(5+2*i+1))->getValue())
|
unsigned ExtOp = (Flags & 1) ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
|
||||||
ExtOp = ISD::SIGN_EXTEND;
|
|
||||||
Arg = DAG.getNode(ExtOp, MVT::i64, Arg);
|
Arg = DAG.getNode(ExtOp, MVT::i64, Arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,10 @@ void X86SharedAsmPrinter::decorateName(std::string &Name,
|
|||||||
unsigned CC = F->getCallingConv();
|
unsigned CC = F->getCallingConv();
|
||||||
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Decorate names only when we're targeting Cygwin/Mingw32 targets
|
||||||
|
if (!Subtarget->isTargetCygMing())
|
||||||
|
return;
|
||||||
|
|
||||||
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -364,25 +364,21 @@ namespace llvm {
|
|||||||
/// X86ScalarSSE - Select between SSE2 or x87 floating point ops.
|
/// X86ScalarSSE - Select between SSE2 or x87 floating point ops.
|
||||||
bool X86ScalarSSE;
|
bool X86ScalarSSE;
|
||||||
|
|
||||||
// C Calling Convention implementation.
|
// C and StdCall Calling Convention implementation.
|
||||||
SDOperand LowerCCCArguments(SDOperand Op, SelectionDAG &DAG);
|
SDOperand LowerCCCArguments(SDOperand Op, SelectionDAG &DAG,
|
||||||
SDOperand LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG);
|
bool isStdCall = false);
|
||||||
|
SDOperand LowerCCCCallTo(SDOperand Op, SelectionDAG &DAG,
|
||||||
|
bool isStdCall = false);
|
||||||
|
|
||||||
// X86-64 C Calling Convention implementation.
|
// X86-64 C Calling Convention implementation.
|
||||||
SDOperand LowerX86_64CCCArguments(SDOperand Op, SelectionDAG &DAG);
|
SDOperand LowerX86_64CCCArguments(SDOperand Op, SelectionDAG &DAG);
|
||||||
SDOperand LowerX86_64CCCCallTo(SDOperand Op, SelectionDAG &DAG);
|
SDOperand LowerX86_64CCCCallTo(SDOperand Op, SelectionDAG &DAG);
|
||||||
|
|
||||||
// Fast Calling Convention implementation.
|
// Fast and FastCall Calling Convention implementation.
|
||||||
SDOperand LowerFastCCArguments(SDOperand Op, SelectionDAG &DAG);
|
SDOperand LowerFastCCArguments(SDOperand Op, SelectionDAG &DAG,
|
||||||
|
bool isFastCall = false);
|
||||||
SDOperand LowerFastCCCallTo(SDOperand Op, SelectionDAG &DAG,
|
SDOperand LowerFastCCCallTo(SDOperand Op, SelectionDAG &DAG,
|
||||||
bool isFastCall);
|
bool isFastCall = false);
|
||||||
|
|
||||||
// StdCall Calling Convention implementation.
|
|
||||||
SDOperand LowerStdCallCCArguments(SDOperand Op, SelectionDAG &DAG);
|
|
||||||
SDOperand LowerStdCallCCCallTo(SDOperand Op, SelectionDAG &DAG);
|
|
||||||
|
|
||||||
// FastCall Calling Convention implementation.
|
|
||||||
SDOperand LowerFastCallCCArguments(SDOperand Op, SelectionDAG &DAG);
|
|
||||||
|
|
||||||
SDOperand LowerBUILD_VECTOR(SDOperand Op, SelectionDAG &DAG);
|
SDOperand LowerBUILD_VECTOR(SDOperand Op, SelectionDAG &DAG);
|
||||||
SDOperand LowerVECTOR_SHUFFLE(SDOperand Op, SelectionDAG &DAG);
|
SDOperand LowerVECTOR_SHUFFLE(SDOperand Op, SelectionDAG &DAG);
|
||||||
|
@ -35,6 +35,7 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
|
|||||||
const TargetMachine& TM,
|
const TargetMachine& TM,
|
||||||
bool isDirectCall) const
|
bool isDirectCall) const
|
||||||
{
|
{
|
||||||
|
// FIXME: PIC
|
||||||
if (TM.getRelocationModel() != Reloc::Static)
|
if (TM.getRelocationModel() != Reloc::Static)
|
||||||
if (isTargetDarwin()) {
|
if (isTargetDarwin()) {
|
||||||
return (!isDirectCall &&
|
return (!isDirectCall &&
|
||||||
|
@ -230,9 +230,10 @@ static inline bool CallPassesValueThoughVararg(Instruction *Call,
|
|||||||
// (used in a computation), MaybeLive (only passed as an argument to a call), or
|
// (used in a computation), MaybeLive (only passed as an argument to a call), or
|
||||||
// Dead (not used).
|
// Dead (not used).
|
||||||
DAE::Liveness DAE::getArgumentLiveness(const Argument &A) {
|
DAE::Liveness DAE::getArgumentLiveness(const Argument &A) {
|
||||||
// If this is the return value of a csret function, it's not really dead.
|
const FunctionType *FTy = A.getParent()->getFunctionType();
|
||||||
if (A.getParent()->getCallingConv() == CallingConv::CSRet &&
|
|
||||||
&*A.getParent()->arg_begin() == &A)
|
// If this is the return value of a struct function, it's not really dead.
|
||||||
|
if (FTy->isStructReturn() && &*A.getParent()->arg_begin() == &A)
|
||||||
return Live;
|
return Live;
|
||||||
|
|
||||||
if (A.use_empty()) // First check, directly dead?
|
if (A.use_empty()) // First check, directly dead?
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
@ -20,13 +21,15 @@ namespace {
|
|||||||
class FunctionExtractorPass : public ModulePass {
|
class FunctionExtractorPass : public ModulePass {
|
||||||
Function *Named;
|
Function *Named;
|
||||||
bool deleteFunc;
|
bool deleteFunc;
|
||||||
|
bool reLink;
|
||||||
public:
|
public:
|
||||||
/// FunctionExtractorPass - If deleteFn is true, this pass deletes as the
|
/// FunctionExtractorPass - If deleteFn is true, this pass deletes as the
|
||||||
/// specified function. Otherwise, it deletes as much of the module as
|
/// specified function. Otherwise, it deletes as much of the module as
|
||||||
/// possible, except for the function specified.
|
/// possible, except for the function specified.
|
||||||
///
|
///
|
||||||
FunctionExtractorPass(Function *F = 0, bool deleteFn = true)
|
FunctionExtractorPass(Function *F = 0, bool deleteFn = true,
|
||||||
: Named(F), deleteFunc(deleteFn) {}
|
bool relinkCallees = false)
|
||||||
|
: Named(F), deleteFunc(deleteFn), reLink(relinkCallees) {}
|
||||||
|
|
||||||
bool runOnModule(Module &M) {
|
bool runOnModule(Module &M) {
|
||||||
if (Named == 0) {
|
if (Named == 0) {
|
||||||
@ -41,6 +44,23 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool deleteFunction() {
|
bool deleteFunction() {
|
||||||
|
// If we're in relinking mode, set linkage of all internal callees to
|
||||||
|
// external. This will allow us extract function, and then - link
|
||||||
|
// everything together
|
||||||
|
if (reLink) {
|
||||||
|
for (Function::iterator B = Named->begin(), BE = Named->end();
|
||||||
|
B != BE; ++B) {
|
||||||
|
for (BasicBlock::iterator I = B->begin(), E = B->end();
|
||||||
|
I != E; ++I) {
|
||||||
|
if (CallInst* callInst = dyn_cast<CallInst>(&*I)) {
|
||||||
|
Function* Callee = callInst->getCalledFunction();
|
||||||
|
if (Callee && Callee->hasInternalLinkage())
|
||||||
|
Callee->setLinkage(GlobalValue::ExternalLinkage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Named->setLinkage(GlobalValue::ExternalLinkage);
|
Named->setLinkage(GlobalValue::ExternalLinkage);
|
||||||
Named->deleteBody();
|
Named->deleteBody();
|
||||||
assert(Named->isExternal() && "This didn't make the function external!");
|
assert(Named->isExternal() && "This didn't make the function external!");
|
||||||
@ -113,6 +133,7 @@ namespace {
|
|||||||
RegisterPass<FunctionExtractorPass> X("extract", "Function Extractor");
|
RegisterPass<FunctionExtractorPass> X("extract", "Function Extractor");
|
||||||
}
|
}
|
||||||
|
|
||||||
ModulePass *llvm::createFunctionExtractionPass(Function *F, bool deleteFn) {
|
ModulePass *llvm::createFunctionExtractionPass(Function *F, bool deleteFn,
|
||||||
return new FunctionExtractorPass(F, deleteFn);
|
bool relinkCallees) {
|
||||||
|
return new FunctionExtractorPass(F, deleteFn, relinkCallees);
|
||||||
}
|
}
|
||||||
|
@ -956,7 +956,6 @@ void AssemblyWriter::printFunction(const Function *F) {
|
|||||||
// Print the calling convention.
|
// Print the calling convention.
|
||||||
switch (F->getCallingConv()) {
|
switch (F->getCallingConv()) {
|
||||||
case CallingConv::C: break; // default
|
case CallingConv::C: break; // default
|
||||||
case CallingConv::CSRet: Out << "csretcc "; break;
|
|
||||||
case CallingConv::Fast: Out << "fastcc "; break;
|
case CallingConv::Fast: Out << "fastcc "; break;
|
||||||
case CallingConv::Cold: Out << "coldcc "; break;
|
case CallingConv::Cold: Out << "coldcc "; break;
|
||||||
case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
|
case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
|
||||||
@ -1166,7 +1165,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
|
|||||||
// Print the calling convention being used.
|
// Print the calling convention being used.
|
||||||
switch (CI->getCallingConv()) {
|
switch (CI->getCallingConv()) {
|
||||||
case CallingConv::C: break; // default
|
case CallingConv::C: break; // default
|
||||||
case CallingConv::CSRet: Out << " csretcc"; break;
|
|
||||||
case CallingConv::Fast: Out << " fastcc"; break;
|
case CallingConv::Fast: Out << " fastcc"; break;
|
||||||
case CallingConv::Cold: Out << " coldcc"; break;
|
case CallingConv::Cold: Out << " coldcc"; break;
|
||||||
case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
|
case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
|
||||||
@ -1209,7 +1207,6 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
|
|||||||
// Print the calling convention being used.
|
// Print the calling convention being used.
|
||||||
switch (II->getCallingConv()) {
|
switch (II->getCallingConv()) {
|
||||||
case CallingConv::C: break; // default
|
case CallingConv::C: break; // default
|
||||||
case CallingConv::CSRet: Out << " csretcc"; break;
|
|
||||||
case CallingConv::Fast: Out << " fastcc"; break;
|
case CallingConv::Fast: Out << " fastcc"; break;
|
||||||
case CallingConv::Cold: Out << " coldcc"; break;
|
case CallingConv::Cold: Out << " coldcc"; break;
|
||||||
case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
|
case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break;
|
||||||
|
@ -1089,6 +1089,10 @@ std::string FunctionType::getParamAttrsText(ParameterAttributes Attr) {
|
|||||||
Result += "sext ";
|
Result += "sext ";
|
||||||
if (Attr & NoReturnAttribute)
|
if (Attr & NoReturnAttribute)
|
||||||
Result += "noreturn ";
|
Result += "noreturn ";
|
||||||
|
if (Attr & InRegAttribute)
|
||||||
|
Result += "inreg ";
|
||||||
|
if (Attr & StructRetAttribute)
|
||||||
|
Result += "sret ";
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,17 +338,17 @@ void Verifier::visitFunction(Function &F) {
|
|||||||
F.getReturnType() == Type::VoidTy,
|
F.getReturnType() == Type::VoidTy,
|
||||||
"Functions cannot return aggregate values!", &F);
|
"Functions cannot return aggregate values!", &F);
|
||||||
|
|
||||||
|
Assert1(!FT->isStructReturn() ||
|
||||||
|
(FT->getReturnType() == Type::VoidTy &&
|
||||||
|
FT->getNumParams() > 0 && isa<PointerType>(FT->getParamType(0))),
|
||||||
|
"Invalid struct-return function!", &F);
|
||||||
|
|
||||||
// Check that this function meets the restrictions on this calling convention.
|
// Check that this function meets the restrictions on this calling convention.
|
||||||
switch (F.getCallingConv()) {
|
switch (F.getCallingConv()) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case CallingConv::C:
|
case CallingConv::C:
|
||||||
break;
|
break;
|
||||||
case CallingConv::CSRet:
|
|
||||||
Assert1(FT->getReturnType() == Type::VoidTy &&
|
|
||||||
FT->getNumParams() > 0 && isa<PointerType>(FT->getParamType(0)),
|
|
||||||
"Invalid struct-return function!", &F);
|
|
||||||
break;
|
|
||||||
case CallingConv::Fast:
|
case CallingConv::Fast:
|
||||||
case CallingConv::Cold:
|
case CallingConv::Cold:
|
||||||
case CallingConv::X86_FastCall:
|
case CallingConv::X86_FastCall:
|
||||||
|
@ -42,6 +42,10 @@ Force("f", cl::desc("Overwrite output files"));
|
|||||||
static cl::opt<bool>
|
static cl::opt<bool>
|
||||||
DeleteFn("delete", cl::desc("Delete specified function from Module"));
|
DeleteFn("delete", cl::desc("Delete specified function from Module"));
|
||||||
|
|
||||||
|
static cl::opt<bool>
|
||||||
|
Relink("relink",
|
||||||
|
cl::desc("Turn external linkage for callees of function to delete"));
|
||||||
|
|
||||||
// ExtractFunc - The function to extract from the module... defaults to main.
|
// ExtractFunc - The function to extract from the module... defaults to main.
|
||||||
static cl::opt<std::string>
|
static cl::opt<std::string>
|
||||||
ExtractFunc("func", cl::desc("Specify function to extract"), cl::init("main"),
|
ExtractFunc("func", cl::desc("Specify function to extract"), cl::init("main"),
|
||||||
@ -72,8 +76,9 @@ int main(int argc, char **argv) {
|
|||||||
PassManager Passes;
|
PassManager Passes;
|
||||||
Passes.add(new TargetData(M.get())); // Use correct TargetData
|
Passes.add(new TargetData(M.get())); // Use correct TargetData
|
||||||
// Either isolate the function or delete it from the Module
|
// Either isolate the function or delete it from the Module
|
||||||
Passes.add(createFunctionExtractionPass(F, DeleteFn));
|
Passes.add(createFunctionExtractionPass(F, DeleteFn, Relink));
|
||||||
Passes.add(createGlobalDCEPass()); // Delete unreachable globals
|
if (!DeleteFn)
|
||||||
|
Passes.add(createGlobalDCEPass()); // Delete unreachable globals
|
||||||
Passes.add(createFunctionResolvingPass()); // Delete prototypes
|
Passes.add(createFunctionResolvingPass()); // Delete prototypes
|
||||||
Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
|
Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user