Constant pointer refs are causing these to fail unnecessarily, which is causing
authorChris Lattner <sabre@nondot.org>
Fri, 31 Oct 2003 17:51:16 +0000 (17:51 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 31 Oct 2003 17:51:16 +0000 (17:51 +0000)
a lot of code to be pessimized.  I hate CPRs.  :(

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9635 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/iOther.h
include/llvm/iTerminators.h
lib/VMCore/iCall.cpp

index e5c3e7d7a317a1546e9549b641813eab6cf3dfec..4e23afdc89879482e9ac5f707334180ff8460113 100644 (file)
@@ -69,12 +69,10 @@ public:
   virtual Instruction *clone() const { return new CallInst(*this); }
   bool mayWriteToMemory() const { return true; }
 
-  const Function *getCalledFunction() const {
-    return dyn_cast<Function>(Operands[0].get());
-  }
-  Function *getCalledFunction() {
-    return dyn_cast<Function>(Operands[0].get());
-  }
+  // FIXME: These methods should be inline once we eliminate
+  // ConstantPointerRefs!
+  const Function *getCalledFunction() const;
+  Function *getCalledFunction();
 
   // getCalledValue - Get a pointer to a method that is invoked by this inst.
   inline const Value *getCalledValue() const { return Operands[0]; }
index 9a40b37e9e63012d314ff82754d57b9a39737eee..5f435a05c6f28b05c9635bdf9938d0623caf40cc 100644 (file)
@@ -214,15 +214,13 @@ public:
 
   bool mayWriteToMemory() const { return true; }
 
-  // getCalledFunction - Return the function called, or null if this is an
-  // indirect function invocation...
-  //
-  inline const Function *getCalledFunction() const {
-    return dyn_cast<Function>(Operands[0].get());
-  }
-  inline Function *getCalledFunction() {
-    return dyn_cast<Function>(Operands[0].get());
-  }
+  /// getCalledFunction - Return the function called, or null if this is an
+  /// indirect function invocation... 
+  ///
+  /// FIXME: These should be inlined once we get rid of ConstantPointerRefs!
+  ///
+  const Function *getCalledFunction() const;
+  Function *getCalledFunction();
 
   // getCalledValue - Get a pointer to a function that is invoked by this inst.
   inline const Value *getCalledValue() const { return Operands[0]; }
index e0f99785a5fed6c943912bdf4493d5e0d0a96993..fcaa1e19300240b5283e2ee50699fcb05b45e37f 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "llvm/iOther.h"
 #include "llvm/iTerminators.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 
@@ -78,6 +79,22 @@ CallInst::CallInst(const CallInst &CI)
     Operands.push_back(Use(CI.Operands[i], this));
 }
 
+const Function *CallInst::getCalledFunction() const {
+  if (const Function *F = dyn_cast<Function>(Operands[0]))
+    return F;
+  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Operands[0]))
+    return cast<Function>(CPR->getValue());
+  return 0;
+}
+Function *CallInst::getCalledFunction() {
+  if (Function *F = dyn_cast<Function>(Operands[0]))
+    return F;
+  if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Operands[0]))
+    return cast<Function>(CPR->getValue());
+  return 0;
+}
+
+
 //===----------------------------------------------------------------------===//
 //                        InvokeInst Implementation
 //===----------------------------------------------------------------------===//
@@ -112,3 +129,17 @@ InvokeInst::InvokeInst(const InvokeInst &CI)
     Operands.push_back(Use(CI.Operands[i], this));
 }
 
+const Function *InvokeInst::getCalledFunction() const {
+  if (const Function *F = dyn_cast<Function>(Operands[0]))
+    return F;
+  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Operands[0]))
+    return cast<Function>(CPR->getValue());
+  return 0;
+}
+Function *InvokeInst::getCalledFunction() {
+  if (Function *F = dyn_cast<Function>(Operands[0]))
+    return F;
+  if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Operands[0]))
+    return cast<Function>(CPR->getValue());
+  return 0;
+}