[cfe-commits] r97638 - in /cfe/trunk/lib/CodeGen: CGBuiltin.cpp CodeGenFunction.h TargetInfo.h

John McCall rjmccall at apple.com
Tue Mar 2 20:15:11 PST 2010


Author: rjmccall
Date: Tue Mar  2 22:15:11 2010
New Revision: 97638

URL: http://llvm.org/viewvc/llvm-project?rev=97638&view=rev
Log:
Add proper target hooks for __builtin_extract_return_address and
__builtin_frob_return_address.  The implementations for both are
still trivial in the default case.


Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/TargetInfo.h

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=97638&r1=97637&r2=97638&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Mar  2 22:15:11 2010
@@ -360,8 +360,14 @@
     return RValue::get(Builder.CreateCall(F, Depth));
   }
   case Builtin::BI__builtin_extract_return_addr: {
-    // FIXME: There should be a target hook for this
-    return RValue::get(EmitScalarExpr(E->getArg(0)));
+    Value *Address = EmitScalarExpr(E->getArg(0));
+    Value *Result = getTargetHooks().decodeReturnAddress(*this, Address);
+    return RValue::get(Result);
+  }
+  case Builtin::BI__builtin_frob_return_addr: {
+    Value *Address = EmitScalarExpr(E->getArg(0));
+    Value *Result = getTargetHooks().encodeReturnAddress(*this, Address);
+    return RValue::get(Result);
   }
   case Builtin::BI__builtin_unwind_init: {
     Value *F = CGM.getIntrinsic(Intrinsic::eh_unwind_init, 0, 0);
@@ -391,7 +397,7 @@
 
     // Otherwise, ask the codegen data what to do.
     const llvm::IntegerType *Int64Ty = llvm::IntegerType::get(C, 64);
-    if (CGM.getTargetCodeGenInfo().extendPointerWithSExt())
+    if (getTargetHooks().extendPointerWithSExt())
       return RValue::get(Builder.CreateSExt(Result, Int64Ty, "extend.sext"));
     else
       return RValue::get(Builder.CreateZExt(Result, Int64Ty, "extend.zext"));

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=97638&r1=97637&r2=97638&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Mar  2 22:15:11 2010
@@ -55,6 +55,7 @@
   class ObjCImplementationDecl;
   class ObjCPropertyImplDecl;
   class TargetInfo;
+  class TargetCodeGenInfo;
   class VarDecl;
   class ObjCForCollectionStmt;
   class ObjCAtTryStmt;
@@ -62,7 +63,6 @@
   class ObjCAtSynchronizedStmt;
 
 namespace CodeGen {
-  class CodeGenModule;
   class CodeGenTypes;
   class CGDebugInfo;
   class CGFunctionInfo;
@@ -1338,6 +1338,10 @@
                                     ArgType));
     }
   }
+
+  const TargetCodeGenInfo &getTargetHooks() const {
+    return CGM.getTargetCodeGenInfo();
+  }
 };
 
 

Modified: cfe/trunk/lib/CodeGen/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.h?rev=97638&r1=97637&r2=97638&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.h (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.h Tue Mar  2 22:15:11 2010
@@ -17,6 +17,7 @@
 
 namespace llvm {
   class GlobalValue;
+  class Value;
 }
 
 namespace clang {
@@ -25,6 +26,7 @@
 
   namespace CodeGen {
     class CodeGenModule;
+    class CodeGenFunction;
   }
 
   /// TargetCodeGenInfo - This class organizes various target-specific
@@ -53,6 +55,26 @@
     ///   - that implicitly ignore/truncate the top bits when addressing
     ///     through such registers.
     virtual bool extendPointerWithSExt() const { return false; }
+
+    /// Performs the code-generation required to convert a return
+    /// address as stored by the system into the actual address of the
+    /// next instruction that will be executed.
+    ///
+    /// Used by __builtin_extract_return_addr().
+    virtual llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+                                             llvm::Value *Address) const {
+      return Address;
+    }
+
+    /// Performs the code-generation required to convert the address
+    /// of an instruction into a return address suitable for storage
+    /// by the system in a return slot.
+    ///
+    /// Used by __builtin_frob_return_addr().
+    virtual llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+                                             llvm::Value *Address) const {
+      return Address;
+    }
   };
 }
 





More information about the cfe-commits mailing list