Fold the adjust_trampoline intrinsic into
authorDuncan Sands <baldrick@free.fr>
Tue, 11 Sep 2007 14:10:23 +0000 (14:10 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 11 Sep 2007 14:10:23 +0000 (14:10 +0000)
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

14 files changed:
docs/LangRef.html
include/llvm/CodeGen/SelectionDAGNodes.h
include/llvm/Intrinsics.td
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Target/ARM/ARMISelLowering.cpp
lib/Target/ARM/ARMISelLowering.h
lib/Target/Alpha/AlphaISelLowering.cpp
lib/Target/IA64/IA64ISelLowering.cpp
lib/Target/Mips/MipsISelLowering.cpp
lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/Sparc/SparcISelDAGToDAG.cpp
lib/Target/X86/X86ISelLowering.cpp

index 7a97ff5d1d4159a6606cba055b93fee9ec050b50..76e7feed4bd3da593d58a1e99e1f0b7d08395696 100644 (file)
           <li><a href="#int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a></li>
         </ol>
       </li>
-      <li><a href="#int_trampoline">Trampoline Intrinsics</a>
+      <li><a href="#int_trampoline">Trampoline Intrinsic</a>
         <ol>
           <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
-          <li><a href="#int_at">'<tt>llvm.adjust.trampoline</tt>' Intrinsic</a></li>
         </ol>
       </li>
       <li><a href="#int_general">General intrinsics</a>
@@ -5149,12 +5148,12 @@ declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;,
 
 <!-- ======================================================================= -->
 <div class="doc_subsection">
-  <a name="int_trampoline">Trampoline Intrinsics</a>
+  <a name="int_trampoline">Trampoline Intrinsic</a>
 </div>
 
 <div class="doc_text">
 <p>
-  These intrinsics make it possible to excise one parameter, marked with
+  This intrinsic makes it possible to excise one parameter, marked with
   the <tt>nest</tt> 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 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;,
   <tt>i32 f(i8* nest  %c, i32 %x, i32 %y)</tt> then the resulting function
   pointer has signature <tt>i32 (i32, i32)*</tt>.  It can be created as follows:
 <pre>
-  %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)*
 </pre>
   The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent to
   <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.
@@ -5186,11 +5184,12 @@ declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;,
 <div class="doc_text">
 <h5>Syntax:</h5>
 <pre>
-declare void @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
+declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
 </pre>
 <h5>Overview:</h5>
 <p>
-  This initializes the memory pointed to by <tt>tramp</tt> as a trampoline.
+  This fills the memory pointed to by <tt>tramp</tt> with code
+  and returns a function pointer suitable for executing it.
 </p>
 <h5>Arguments:</h5>
 <p>
@@ -5205,42 +5204,18 @@ declare void @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;
 <h5>Semantics:</h5>
 <p>
   The block of memory pointed to by <tt>tramp</tt> is filled with target
-  dependent code, turning it into a function.
-  The new function's signature is the same as that of <tt>func</tt> with
-  any arguments marked with the <tt>nest</tt> attribute removed.  At most
-  one such <tt>nest</tt> argument is allowed, and it must be of pointer
-  type.  Calling the new function is equivalent to calling <tt>func</tt>
-  with the same argument list, but with <tt>nval</tt> used for the missing
-  <tt>nest</tt> argument.
-</p>
-</div>
-
-<!-- _______________________________________________________________________ -->
-<div class="doc_subsubsection">
-  <a name="int_at">'<tt>llvm.adjust.trampoline</tt>' Intrinsic</a>
-</div>
-<div class="doc_text">
-<h5>Syntax:</h5>
-<pre>
-declare i8* @llvm.adjust.trampoline(i8* &lt;tramp&gt;)
-</pre>
-<h5>Overview:</h5>
-<p>
-  This intrinsic returns a function pointer suitable for executing
-  the trampoline code pointed to by <tt>tramp</tt>.
-</p>
-<h5>Arguments:</h5>
-<p>
-  The <tt>llvm.adjust.trampoline</tt> takes one argument, a pointer to a
-  trampoline initialized by the
-  <a href="#int_it">'<tt>llvm.init.trampoline</tt>' intrinsic</a>.
-</p>
-<h5>Semantics:</h5>
-<p>
-  A function pointer that can be used to execute the trampoline code in
-  <tt>tramp</tt> 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
   <a href="#int_trampoline">appropriate function pointer type</a>
-  before being called.
+  before being called.  The new function's signature is the same as that of
+  <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute
+  removed.  At most one such <tt>nest</tt> argument is allowed, and it must be
+  of pointer type.  Calling the new function is equivalent to calling
+  <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the
+  missing <tt>nest</tt> argument.  If, after calling
+  <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is
+  modified, then the effect of any later call to the returned function pointer is
+  undefined.
 </p>
 </div>
 
index d70e3cdb478002e9909289d5d628dcdab2a8c059..4f44c4f8423af29d9c4c59371bf42b3577269b8b 100644 (file)
@@ -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.
index bb9e9c7a461ae20895a34ee07749ecdd1d238385..f7b46b2e6c15de6dc21c49f0ad1735a596880f8f 100644 (file)
@@ -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
index 2c5b9dad42868b46b98eb2a7bcb849675a6e1252..31e29470e803b00ebc945558683c115477634b15 100644 (file)
@@ -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;
   }
   }
   
index 05d5ec0ec20417d940ad91ad5f1ad7bb5dd06b51..01ec5c968aa04956508ecd45f90805a912f6cde2 100644 (file)
@@ -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<CondCodeSDNode>(this)->get()) {
index 60b5290607a5ef5971c9a10aed8819e3d188839f..561b303f7086d0f8503d0e9080f42cb186c57883 100644 (file)
@@ -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<Function>(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;
   }
   }
index d6ca1481395352fd91bdd45bfd67bb41e3a528ee..c41bb2ee4632acfa252e438ce8900b22e1a835ae 100644 (file)
@@ -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();
 }
index aba6ab3475a0be39a65459ddab43749ecc975d57..ea2ab74375ae203726cd9df39fa5a598d73adee3 100644 (file)
@@ -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);
   };
 }
 
index faeb7918248f1c77e185c0b57d4fa6e174f525dc..a3654af114f6d46ab574d4f0d01da56557db3413 100644 (file)
@@ -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);
index 8f62c1f41917c16669126059d8dadd29cf483572..f1bd5ba86f42f5f687419e6ec0431815d420e742 100644 (file)
@@ -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);
index 9f5f7f99f70fe365bfc9d2823a7a35b8de83b3ef..a63da4c1d1bf923027adfef4e2e4779b5707d232 100644 (file)
@@ -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();
 }
index 8c7677651ac878eb0df9f08c98daf264d97a927b..cfebef1edd661c85a4816a75a9178e115ef113ea 100644 (file)
@@ -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);
   
index 536abc11cb7c487a30664870191168dc63ba4bfe..e1628b995dffc99d8210d0a57321d64470d4dfb6 100644 (file)
@@ -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.
index 22b282bd5f7ac539a8fc472974b7da9d0836882e..6d3bcf7bb51c19b7eb5ca979499cb3e2f7ef3a2b 100644 (file)
@@ -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);
   }
 }