llvm.org GIT mirror llvm / f7331b3
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 Duncan Sands 13 years ago
14 changed file(s) with 53 addition(s) and 119 deletion(s). Raw diff Collapse all Expand all
199199
  • 'llvm.memory.barrier' Intrinsic
  • 200200
    201201
    202
  • Trampoline Intrinsics
  • 202
  • Trampoline Intrinsic
  • 203203
    204204
  • 'llvm.init.trampoline' Intrinsic
  • 205
  • 'llvm.adjust.trampoline' Intrinsic
  • 206205
    207206
    208207
  • General intrinsics
  • 51485147
    51495148
    51505149
    5151 Trampoline Intrinsics
    5152
    5153
    5154
    5155

    5156 These intrinsics make it possible to excise one parameter, marked with
    5150 Trampoline Intrinsic
    5151
    5152
    5153
    5154

    5155 This intrinsic makes it possible to excise one parameter, marked with
    51575156 the nest attribute, from a function. The result is a callable
    51585157 function pointer lacking the nest parameter - the caller does not need
    51595158 to provide a value for it. Instead, the value to use is stored in
    51675166 i32 f(i8* nest %c, i32 %x, i32 %y) then the resulting function
    51685167 pointer has signature i32 (i32, i32)*. It can be created as follows:
    51695168
    
                      
                    
    5170 %tramp1 = alloca [10 x i8], align 4 ; size and alignment only correct for X86
    5171 %tramp = getelementptr [10 x i8]* %tramp1, i32 0, i32 0
    5172 call void @llvm.init.trampoline( i8* %tramp, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
    5173 %adj = call i8* @llvm.adjust.trampoline( i8* %tramp )
    5174 %fp = bitcast i8* %adj to i32 (i32, i32)*
    5169 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
    5170 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
    5171 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
    5172 %fp = bitcast i8* %p to i32 (i32, i32)*
    51755173
    51765174 The call %val = call i32 %fp( i32 %x, i32 %y ) is then equivalent to
    51775175 %val = call i32 %f( i8* %nval, i32 %x, i32 %y ).
    51855183
    51865184
    Syntax:
    51875185
    
                      
                    
    5188 declare void @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
    5189
    5190
    Overview:
    5191

    5192 This initializes the memory pointed to by tramp as a trampoline.
    5186 declare i8* @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>)
    5187
    5188
    Overview:
    5189

    5190 This fills the memory pointed to by tramp with code
    5191 and returns a function pointer suitable for executing it.
    51935192

    51945193
    Arguments:
    51955194

    52045203
    Semantics:
    52055204

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

    5215
    5216
    5217
    5218
    5219 'llvm.adjust.trampoline' Intrinsic
    5220
    5221
    5222
    Syntax:
    5223
    
                      
                    
    5224 declare i8* @llvm.adjust.trampoline(i8* <tramp>)
    5225
    5226
    Overview:
    5227

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

    5231
    Arguments:
    5232

    5233 The llvm.adjust.trampoline takes one argument, a pointer to a
    5234 trampoline initialized by the
    5235 'llvm.init.trampoline' intrinsic.
    5236

    5237
    Semantics:
    5238

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

    52445219
    52455220
    539539 // produces a token chain as output.
    540540 DEBUG_LOC,
    541541
    542 // ADJUST_TRAMP - This corresponds to the adjust_trampoline intrinsic.
    543 // It takes a value as input and returns a value as output.
    544 ADJUST_TRAMP,
    545
    546542 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
    547543 // It takes as input a token chain, the pointer to the trampoline,
    548544 // the pointer to the nested function, the pointer to pass for the
    549545 // 'nest' parameter, a SRCVALUE for the trampoline and another for
    550546 // the nested function (allowing targets to access the original
    551 // Function*). It produces a token chain as output.
    547 // Function*). It produces the result of the intrinsic and a token
    548 // chain as output.
    552549 TRAMPOLINE,
    553550
    554551 // BUILTIN_OP_END - This must be the last enum value in this list.
    242242
    243243 //===------------------------ Trampoline Intrinsics -----------------------===//
    244244 //
    245 def int_init_trampoline : Intrinsic<[llvm_void_ty, llvm_ptr_ty, llvm_ptr_ty,
    246 llvm_ptr_ty], []>,
    247 GCCBuiltin<"__builtin_init_trampoline">;
    248 def int_adjust_trampoline : Intrinsic<[llvm_ptr_ty, llvm_ptr_ty], [IntrNoMem]>,
    249 GCCBuiltin<"__builtin_adjust_trampoline">;
    245 def int_init_trampoline : Intrinsic<[llvm_ptr_ty, llvm_ptr_ty, llvm_ptr_ty,
    246 llvm_ptr_ty], []>,
    247 GCCBuiltin<"__builtin_init_trampoline">;
    250248
    251249 //===----------------------------------------------------------------------===//
    252250 // Target-specific intrinsics
    33833383 }
    33843384 break;
    33853385 }
    3386 case ISD::ADJUST_TRAMP: {
    3387 Tmp1 = LegalizeOp(Node->getOperand(0));
    3388 switch (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0))) {
    3389 default: assert(0 && "This action is not supported yet!");
    3390 case TargetLowering::Custom:
    3391 Result = DAG.UpdateNodeOperands(Result, Tmp1);
    3392 Result = TLI.LowerOperation(Result, DAG);
    3393 if (Result.Val) break;
    3394 // FALL THROUGH
    3395 case TargetLowering::Expand:
    3396 Result = Tmp1;
    3397 break;
    3398 }
    3399 break;
    3400 }
    34013386 case ISD::TRAMPOLINE: {
    34023387 SDOperand Ops[6];
    34033388 for (unsigned i = 0; i != 6; ++i)
    34063391 // The only option for this node is to custom lower it.
    34073392 Result = TLI.LowerOperation(Result, DAG);
    34083393 assert(Result.Val && "Should always custom lower!");
    3409 break;
    3394
    3395 // Since trampoline produces two values, make sure to remember that we
    3396 // legalized both of them.
    3397 Tmp1 = LegalizeOp(Result.getValue(1));
    3398 Result = LegalizeOp(Result);
    3399 AddLegalizedOperand(SDOperand(Node, 0), Result);
    3400 AddLegalizedOperand(SDOperand(Node, 1), Tmp1);
    3401 return Op.ResNo ? Tmp1 : Result;
    34103402 }
    34113403 }
    34123404
    36423642 case ISD::DEBUG_LOC: return "debug_loc";
    36433643
    36443644 // Trampolines
    3645 case ISD::ADJUST_TRAMP: return "adjust_tramp";
    3646 case ISD::TRAMPOLINE: return "trampoline";
    3645 case ISD::TRAMPOLINE: return "trampoline";
    36473646
    36483647 case ISD::CONDCODE:
    36493648 switch (cast(this)->get()) {
    28802880 // Discard annotate attributes
    28812881 return 0;
    28822882
    2883 case Intrinsic::adjust_trampoline: {
    2884 SDOperand Arg = getValue(I.getOperand(1));
    2885 setValue(&I, DAG.getNode(ISD::ADJUST_TRAMP, TLI.getPointerTy(), Arg));
    2886 return 0;
    2887 }
    2888
    28892883 case Intrinsic::init_trampoline: {
    28902884 const Function *F =
    28912885 cast(IntrinsicInst::StripPointerCasts(I.getOperand(2)));
    28982892 Ops[4] = DAG.getSrcValue(I.getOperand(1));
    28992893 Ops[5] = DAG.getSrcValue(F);
    29002894
    2901 DAG.setRoot(DAG.getNode(ISD::TRAMPOLINE, MVT::Other, Ops, 6));
    2895 SDOperand Tmp = DAG.getNode(ISD::TRAMPOLINE,
    2896 DAG.getNodeValueTypes(TLI.getPointerTy(),
    2897 MVT::Other), 2,
    2898 Ops, 6);
    2899
    2900 setValue(&I, Tmp);
    2901 DAG.setRoot(Tmp.getValue(1));
    29022902 return 0;
    29032903 }
    29042904 }
    189189 setOperationAction(ISD::MEMSET , MVT::Other, Expand);
    190190 setOperationAction(ISD::MEMCPY , MVT::Other, Custom);
    191191 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
    192
    193 if (Subtarget->isThumb())
    194 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Custom);
    195 else
    196 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
    197192
    198193 // Use the default implementation.
    199194 setOperationAction(ISD::VASTART , MVT::Other, Expand);
    14171412 return Chain;
    14181413 }
    14191414
    1420 SDOperand ARMTargetLowering::LowerADJUST_TRAMP(SDOperand Op,
    1421 SelectionDAG &DAG) {
    1422 // Thumb trampolines should be entered in thumb mode, so set the bottom bit
    1423 // of the address.
    1424 return DAG.getNode(ISD::OR, MVT::i32, Op.getOperand(0),
    1425 DAG.getConstant(1, MVT::i32));
    1426 }
    1427
    14281415 SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
    14291416 switch (Op.getOpcode()) {
    14301417 default: assert(0 && "Don't know how to custom lower this!"); abort();
    14561443 case ISD::FRAMEADDR: break;
    14571444 case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG);
    14581445 case ISD::MEMCPY: return LowerMEMCPY(Op, DAG);
    1459 case ISD::ADJUST_TRAMP: return LowerADJUST_TRAMP(Op, DAG);
    14601446 }
    14611447 return SDOperand();
    14621448 }
    137137 SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG);
    138138 SDOperand LowerBR_JT(SDOperand Op, SelectionDAG &DAG);
    139139 SDOperand LowerMEMCPY(SDOperand Op, SelectionDAG &DAG);
    140 SDOperand LowerADJUST_TRAMP(SDOperand Op, SelectionDAG &DAG);
    141140 };
    142141 }
    143142
    122122 setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
    123123 setOperationAction(ISD::ExternalSymbol, MVT::i64, Custom);
    124124 setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
    125
    126 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
    127 setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand);
    128125
    129126 setOperationAction(ISD::VASTART, MVT::Other, Custom);
    130127 setOperationAction(ISD::VAEND, MVT::Other, Expand);
    9595 setOperationAction(ISD::ROTL , MVT::i64 , Expand);
    9696 setOperationAction(ISD::ROTR , MVT::i64 , Expand);
    9797 setOperationAction(ISD::BSWAP, MVT::i64 , Expand); // mux @rev
    98
    99 setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand);
    10098
    10199 // VASTART needs to be custom lowered to use the VarArgsFrameIndex
    102100 setOperationAction(ISD::VAARG , MVT::Other, Custom);
    103103 // Use the default for now
    104104 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
    105105 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
    106
    107 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
    108106
    109107 setStackPointerRegisterToSaveRestore(Mips::SP);
    110108 computeRegisterProperties();
    169169
    170170 // RET must be custom lowered, to meet ABI requirements
    171171 setOperationAction(ISD::RET , MVT::Other, Custom);
    172
    173 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
    174 setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand);
    175172
    176173 // VASTART needs to be custom lowered to use the VarArgsFrameIndex
    177174 setOperationAction(ISD::VASTART , MVT::Other, Custom);
    214214
    215215 // RET must be custom lowered, to meet ABI requirements
    216216 setOperationAction(ISD::RET , MVT::Other, Custom);
    217
    218 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
    219217
    220218 // VASTART needs to be custom lowered to use the VarArgsFrameIndex.
    221219 setOperationAction(ISD::VASTART , MVT::Other, Custom);
    245245 }
    246246 setOperationAction(ISD::FRAME_TO_ARGS_OFFSET, MVT::i32, Custom);
    247247
    248 setOperationAction(ISD::ADJUST_TRAMP, MVT::i32, Expand);
    249 setOperationAction(ISD::ADJUST_TRAMP, MVT::i64, Expand);
    250 setOperationAction(ISD::TRAMPOLINE, MVT::Other, Custom);
    248 setOperationAction(ISD::TRAMPOLINE, MVT::Other, Custom);
    251249
    252250 // VASTART needs to be custom lowered to use the VarArgsFrameIndex
    253251 setOperationAction(ISD::VASTART , MVT::Other, Custom);
    44054403 OutChains[3] = DAG.getStore(Root, Disp, Addr, TrmpSV->getValue(),
    44064404 TrmpSV->getOffset() + 6, false, 1);
    44074405
    4408 return DAG.getNode(ISD::TokenFactor, MVT::Other, OutChains, 4);
    4406 SDOperand Ops[] =
    4407 { Trmp, DAG.getNode(ISD::TokenFactor, MVT::Other, OutChains, 4) };
    4408 return DAG.getNode(ISD::MERGE_VALUES, Op.Val->getVTList(), Ops, 2);
    44094409 }
    44104410 }
    44114411