From f7331b3dd72409e644833ecaf62a0f6db03c97ee Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Tue, 11 Sep 2007 14:10:23 +0000 Subject: [PATCH] Fold the adjust_trampoline intrinsic into init_trampoline. There is now only one trampoline intrinsic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41841 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LangRef.html | 67 ++++++------------- include/llvm/CodeGen/SelectionDAGNodes.h | 7 +- include/llvm/Intrinsics.td | 8 +-- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 24 +++---- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 3 +- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 14 ++-- lib/Target/ARM/ARMISelLowering.cpp | 14 ---- lib/Target/ARM/ARMISelLowering.h | 1 - lib/Target/Alpha/AlphaISelLowering.cpp | 3 - lib/Target/IA64/IA64ISelLowering.cpp | 2 - lib/Target/Mips/MipsISelLowering.cpp | 2 - lib/Target/PowerPC/PPCISelLowering.cpp | 3 - lib/Target/Sparc/SparcISelDAGToDAG.cpp | 2 - lib/Target/X86/X86ISelLowering.cpp | 8 +-- 14 files changed, 46 insertions(+), 112 deletions(-) diff --git a/docs/LangRef.html b/docs/LangRef.html index 7a97ff5d1d4..76e7feed4bd 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -200,10 +200,9 @@
  • 'llvm.memory.barrier' Intrinsic
  • -
  • Trampoline Intrinsics +
  • Trampoline Intrinsic
    1. 'llvm.init.trampoline' Intrinsic
    2. -
    3. 'llvm.adjust.trampoline' Intrinsic
  • General intrinsics @@ -5149,12 +5148,12 @@ declare void @llvm.memory.barrier( i1 <ll>, i1 <ls>, i1 <sl>,

    - These intrinsics make it possible to excise one parameter, marked with + This intrinsic makes it possible to excise one parameter, marked with the nest attribute, from a function. The result is a callable function pointer lacking the nest parameter - the caller does not need to provide a value for it. Instead, the value to use is stored in @@ -5168,11 +5167,10 @@ declare void @llvm.memory.barrier( i1 <ll>, i1 <ls>, i1 <sl>, i32 f(i8* nest %c, i32 %x, i32 %y) then the resulting function pointer has signature i32 (i32, i32)*. It can be created as follows:

    -  %tramp1 = alloca [10 x i8], align 4 ; size and alignment only correct for X86
    -  %tramp = getelementptr [10 x i8]* %tramp1, i32 0, i32 0
    -  call void @llvm.init.trampoline( i8* %tramp, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
    -  %adj = call i8* @llvm.adjust.trampoline( i8* %tramp )
    -  %fp = bitcast i8* %adj to i32 (i32, i32)*
    +  %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
    +  %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
    +  %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
    +  %fp = bitcast i8* %p to i32 (i32, i32)*
     
    The call %val = call i32 %fp( i32 %x, i32 %y ) is then equivalent to %val = call i32 %f( i8* %nval, i32 %x, i32 %y ). @@ -5186,11 +5184,12 @@ declare void @llvm.memory.barrier( i1 <ll>, i1 <ls>, i1 <sl>,
    Syntax:
    -declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
    +declare i8* @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
     
    Overview:

    - This initializes the memory pointed to by tramp as a trampoline. + This fills the memory pointed to by tramp with code + and returns a function pointer suitable for executing it.

    Arguments:

    @@ -5205,42 +5204,18 @@ declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <

    Semantics:

    The block of memory pointed to by tramp is filled with target - dependent code, turning it into a function. - The new function's signature is the same as that of func with - any arguments marked with the nest attribute removed. At most - one such nest argument is allowed, and it must be of pointer - type. Calling the new function is equivalent to calling func - with the same argument list, but with nval used for the missing - nest argument. -

    -
    - - - -
    -
    Syntax:
    -
    -declare i8* @llvm.adjust.trampoline(i8* <tramp>)
    -
    -
    Overview:
    -

    - This intrinsic returns a function pointer suitable for executing - the trampoline code pointed to by tramp. -

    -
    Arguments:
    -

    - The llvm.adjust.trampoline takes one argument, a pointer to a - trampoline initialized by the - 'llvm.init.trampoline' intrinsic. -

    -
    Semantics:
    -

    - A function pointer that can be used to execute the trampoline code in - tramp is returned. The returned value should be bitcast to an + dependent code, turning it into a function. A pointer to this function is + returned, but needs to be bitcast to an appropriate function pointer type - before being called. + before being called. The new function's signature is the same as that of + func with any arguments marked with the nest attribute + removed. At most one such nest argument is allowed, and it must be + of pointer type. Calling the new function is equivalent to calling + func with the same argument list, but with nval used for the + missing nest argument. If, after calling + llvm.init.trampoline, the memory pointed to by tramp is + modified, then the effect of any later call to the returned function pointer is + undefined.

    diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index d70e3cdb478..4f44c4f8423 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -540,16 +540,13 @@ namespace ISD { // produces a token chain as output. DEBUG_LOC, - // ADJUST_TRAMP - This corresponds to the adjust_trampoline intrinsic. - // It takes a value as input and returns a value as output. - ADJUST_TRAMP, - // TRAMPOLINE - This corresponds to the init_trampoline intrinsic. // It takes as input a token chain, the pointer to the trampoline, // the pointer to the nested function, the pointer to pass for the // 'nest' parameter, a SRCVALUE for the trampoline and another for // the nested function (allowing targets to access the original - // Function*). It produces a token chain as output. + // Function*). It produces the result of the intrinsic and a token + // chain as output. TRAMPOLINE, // BUILTIN_OP_END - This must be the last enum value in this list. diff --git a/include/llvm/Intrinsics.td b/include/llvm/Intrinsics.td index bb9e9c7a461..f7b46b2e6c1 100644 --- a/include/llvm/Intrinsics.td +++ b/include/llvm/Intrinsics.td @@ -243,11 +243,9 @@ def int_var_annotation : Intrinsic<[llvm_void_ty, llvm_ptr_ty, llvm_ptr_ty, //===------------------------ Trampoline Intrinsics -----------------------===// // -def int_init_trampoline : Intrinsic<[llvm_void_ty, llvm_ptr_ty, llvm_ptr_ty, - llvm_ptr_ty], []>, - GCCBuiltin<"__builtin_init_trampoline">; -def int_adjust_trampoline : Intrinsic<[llvm_ptr_ty, llvm_ptr_ty], [IntrNoMem]>, - GCCBuiltin<"__builtin_adjust_trampoline">; +def int_init_trampoline : Intrinsic<[llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty, + llvm_ptr_ty], []>, + GCCBuiltin<"__builtin_init_trampoline">; //===----------------------------------------------------------------------===// // Target-specific intrinsics diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 2c5b9dad428..31e29470e80 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -3384,21 +3384,6 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { } break; } - case ISD::ADJUST_TRAMP: { - Tmp1 = LegalizeOp(Node->getOperand(0)); - switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) { - default: assert(0 && "This action is not supported yet!"); - case TargetLowering::Custom: - Result = DAG.UpdateNodeOperands(Result, Tmp1); - Result = TLI.LowerOperation(Result, DAG); - if (Result.Val) break; - // FALL THROUGH - case TargetLowering::Expand: - Result = Tmp1; - break; - } - break; - } case ISD::TRAMPOLINE: { SDOperand Ops[6]; for (unsigned i = 0; i != 6; ++i) @@ -3407,7 +3392,14 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { // The only option for this node is to custom lower it. Result = TLI.LowerOperation(Result, DAG); assert(Result.Val && "Should always custom lower!"); - break; + + // Since trampoline produces two values, make sure to remember that we + // legalized both of them. + Tmp1 = LegalizeOp(Result.getValue(1)); + Result = LegalizeOp(Result); + AddLegalizedOperand(SDOperand(Node, 0), Result); + AddLegalizedOperand(SDOperand(Node, 1), Tmp1); + return Op.ResNo ? Tmp1 : Result; } } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 05d5ec0ec20..01ec5c968aa 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -3643,8 +3643,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const { case ISD::DEBUG_LOC: return "debug_loc"; // Trampolines - case ISD::ADJUST_TRAMP: return "adjust_tramp"; - case ISD::TRAMPOLINE: return "trampoline"; + case ISD::TRAMPOLINE: return "trampoline"; case ISD::CONDCODE: switch (cast(this)->get()) { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 60b5290607a..561b303f708 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -2881,12 +2881,6 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { // Discard annotate attributes return 0; - case Intrinsic::adjust_trampoline: { - SDOperand Arg = getValue(I.getOperand(1)); - setValue(&I, DAG.getNode(ISD::ADJUST_TRAMP, TLI.getPointerTy(), Arg)); - return 0; - } - case Intrinsic::init_trampoline: { const Function *F = cast(IntrinsicInst::StripPointerCasts(I.getOperand(2))); @@ -2899,7 +2893,13 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { Ops[4] = DAG.getSrcValue(I.getOperand(1)); Ops[5] = DAG.getSrcValue(F); - DAG.setRoot(DAG.getNode(ISD::TRAMPOLINE, MVT::Other, Ops, 6)); + SDOperand Tmp = DAG.getNode(ISD::TRAMPOLINE, + DAG.getNodeValueTypes(TLI.getPointerTy(), + MVT::Other), 2, + Ops, 6); + + setValue(&I, Tmp); + DAG.setRoot(Tmp.getValue(1)); return 0; } } diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index d6ca1481395..c41bb2ee463 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -191,11 +191,6 @@ ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) setOperationAction(ISD::MEMCPY , MVT::Other, Custom); setOperationAction(ISD::MEMMOVE , MVT::Other, Expand); - if (Subtarget->isThumb()) - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Custom); - else - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand); - // Use the default implementation. setOperationAction(ISD::VASTART , MVT::Other, Expand); setOperationAction(ISD::VAARG , MVT::Other, Expand); @@ -1418,14 +1413,6 @@ SDOperand ARMTargetLowering::LowerMEMCPY(SDOperand Op, SelectionDAG &DAG) { return Chain; } -SDOperand ARMTargetLowering::LowerADJUST_TRAMP(SDOperand Op, - SelectionDAG &DAG) { - // Thumb trampolines should be entered in thumb mode, so set the bottom bit - // of the address. - return DAG.getNode(ISD::OR, MVT::i32, Op.getOperand(0), - DAG.getConstant(1, MVT::i32)); -} - SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { switch (Op.getOpcode()) { default: assert(0 && "Don't know how to custom lower this!"); abort(); @@ -1457,7 +1444,6 @@ SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { case ISD::FRAMEADDR: break; case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); case ISD::MEMCPY: return LowerMEMCPY(Op, DAG); - case ISD::ADJUST_TRAMP: return LowerADJUST_TRAMP(Op, DAG); } return SDOperand(); } diff --git a/lib/Target/ARM/ARMISelLowering.h b/lib/Target/ARM/ARMISelLowering.h index aba6ab3475a..ea2ab74375a 100644 --- a/lib/Target/ARM/ARMISelLowering.h +++ b/lib/Target/ARM/ARMISelLowering.h @@ -138,7 +138,6 @@ namespace llvm { SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG); SDOperand LowerBR_JT(SDOperand Op, SelectionDAG &DAG); SDOperand LowerMEMCPY(SDOperand Op, SelectionDAG &DAG); - SDOperand LowerADJUST_TRAMP(SDOperand Op, SelectionDAG &DAG); }; } diff --git a/lib/Target/Alpha/AlphaISelLowering.cpp b/lib/Target/Alpha/AlphaISelLowering.cpp index faeb7918248..a3654af114f 100644 --- a/lib/Target/Alpha/AlphaISelLowering.cpp +++ b/lib/Target/Alpha/AlphaISelLowering.cpp @@ -124,9 +124,6 @@ AlphaTargetLowering::AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom); setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand); - setOperationAction(ISD::VASTART, MVT::Other, Custom); setOperationAction(ISD::VAEND, MVT::Other, Expand); setOperationAction(ISD::VACOPY, MVT::Other, Custom); diff --git a/lib/Target/IA64/IA64ISelLowering.cpp b/lib/Target/IA64/IA64ISelLowering.cpp index 8f62c1f4191..f1bd5ba86f4 100644 --- a/lib/Target/IA64/IA64ISelLowering.cpp +++ b/lib/Target/IA64/IA64ISelLowering.cpp @@ -97,8 +97,6 @@ IA64TargetLowering::IA64TargetLowering(TargetMachine &TM) setOperationAction(ISD::ROTR , MVT::i64 , Expand); setOperationAction(ISD::BSWAP, MVT::i64 , Expand); // mux @rev - setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand); - // VASTART needs to be custom lowered to use the VarArgsFrameIndex setOperationAction(ISD::VAARG , MVT::Other, Custom); setOperationAction(ISD::VASTART , MVT::Other, Custom); diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp index 9f5f7f99f70..a63da4c1d1b 100644 --- a/lib/Target/Mips/MipsISelLowering.cpp +++ b/lib/Target/Mips/MipsISelLowering.cpp @@ -105,8 +105,6 @@ MipsTargetLowering(MipsTargetMachine &TM): TargetLowering(TM) setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand); - setStackPointerRegisterToSaveRestore(Mips::SP); computeRegisterProperties(); } diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp index 8c7677651ac..cfebef1edd6 100644 --- a/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/lib/Target/PowerPC/PPCISelLowering.cpp @@ -171,9 +171,6 @@ PPCTargetLowering::PPCTargetLowering(PPCTargetMachine &TM) // RET must be custom lowered, to meet ABI requirements setOperationAction(ISD::RET , MVT::Other, Custom); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand); - // VASTART needs to be custom lowered to use the VarArgsFrameIndex setOperationAction(ISD::VASTART , MVT::Other, Custom); diff --git a/lib/Target/Sparc/SparcISelDAGToDAG.cpp b/lib/Target/Sparc/SparcISelDAGToDAG.cpp index 536abc11cb7..e1628b995df 100644 --- a/lib/Target/Sparc/SparcISelDAGToDAG.cpp +++ b/lib/Target/Sparc/SparcISelDAGToDAG.cpp @@ -216,8 +216,6 @@ SparcTargetLowering::SparcTargetLowering(TargetMachine &TM) // RET must be custom lowered, to meet ABI requirements setOperationAction(ISD::RET , MVT::Other, Custom); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand); - // VASTART needs to be custom lowered to use the VarArgsFrameIndex. setOperationAction(ISD::VASTART , MVT::Other, Custom); // VAARG needs to be lowered to not do unaligned accesses for doubles. diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 22b282bd5f7..6d3bcf7bb51 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -246,9 +246,7 @@ X86TargetLowering::X86TargetLowering(TargetMachine &TM) } setOperationAction(ISD::FRAME_TO_ARGS_OFFSET, MVT::i32, Custom); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand); - setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand); - setOperationAction(ISD::TRAMPOLINE, MVT::Other, Custom); + setOperationAction(ISD::TRAMPOLINE, MVT::Other, Custom); // VASTART needs to be custom lowered to use the VarArgsFrameIndex setOperationAction(ISD::VASTART , MVT::Other, Custom); @@ -4406,7 +4404,9 @@ SDOperand X86TargetLowering::LowerTRAMPOLINE(SDOperand Op, OutChains[3] = DAG.getStore(Root, Disp, Addr, TrmpSV->getValue(), TrmpSV->getOffset() + 6, false, 1); - return DAG.getNode(ISD::TokenFactor, MVT::Other, OutChains, 4); + SDOperand Ops[] = + { Trmp, DAG.getNode(ISD::TokenFactor, MVT::Other, OutChains, 4) }; + return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(), Ops, 2); } }