[llvm-commits] Trampoline support (pointers nested funtions)

Evan Cheng evan.cheng at apple.com
Thu Jul 26 18:07:02 PDT 2007


Hi Duncan,

Some nit picks.

1. Please don't use "Chain" for stand for function static chain. It  
confuses backend guys like me. :-) "Chain" stands for control flow  
dependency in the backend.

2. Purely a stylistic thing:

+SDOperand X86TargetLowering::LowerTRAMPOLINE(SDOperand Op,
+                                             SelectionDAG &DAG) {
+  SDOperand Root = Op.getOperand(0);
+  SDOperand Trmp = Op.getOperand(1); // trampoline
+  SDOperand FPtr = Op.getOperand(2); // nested function
+  SDOperand SChn = Op.getOperand(3); // static chain
+
+  SrcValueSDNode *TrmpSV = cast<SrcValueSDNode>(Op.getOperand(4));
+
+  if (Subtarget->is64Bit()) {
+    return SDOperand(); // not yet supported
+  } else {

If you move the check is64Bit() to the beginning of function, there  
is no need to nest the part that actually do the work in the "else"  
clause.

3. In X86TargetLowering::LowerTRAMPOLINE():
+    case CallingConv::X86_StdCall: {
+      Move = 0xb9; // Pass chain in ECX

I assume this is the ModR/M byte? Can you refactor ModRMByte() from  
X86CodeEmitter.cpp (probably also getX86RegNum) and use that to  
calculate this instead? Also, isn't the static chain register  
described in X86CallingConv.td? Magic number is confusing. :-)

Looks great otherwise. Thanks!

Evan

On Jul 26, 2007, at 7:56 AM, Duncan Sands wrote:

> These patches add support for taking pointers to nested
> functions (a gcc extension).  This is done by building
> and executing a small code stub on the stack, known as
> a trampoline.  The LLVM part adds two new intrinsics,
> llvm.init.trampoline and llvm.adjust.trampoline.  The
> adjust intrinsic is implemented for all architectures
> that are supported in gcc, while the init intrinsic is
> only implemented for X86.  Furthermore, trampolines can
> interact badly with stack protection mechanisms which
> don't much like execution of code on the stack.  GCC
> does various tricks to tell the OS that the trampoline
> is kosher.  I didn't implement any of those tricks yet,
> because it works without them on my machine :)
>
> Enjoy!
>
> Duncan.
> <tramp.diff>
> <tramp-gcc.diff>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list