[llvm-commits] CVS: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp ExternalFunctions.cpp Interpreter.cpp Interpreter.h

Chris Lattner lattner at cs.uiuc.edu
Sun Dec 28 03:45:03 PST 2003


Changes in directory llvm/lib/ExecutionEngine/Interpreter:

Execution.cpp updated: 1.118 -> 1.119
ExternalFunctions.cpp updated: 1.71 -> 1.72
Interpreter.cpp updated: 1.19 -> 1.20
Interpreter.h updated: 1.58 -> 1.59

---
Log message:

Pass around IntrinsicLowering instances as appropriate.
Reimplement the Interpreters implementation of va_* to be more direct.


---
Diffs of the changes:  (+58 -41)

Index: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
diff -u llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.118 llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.119
--- llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.118	Thu Dec 11 23:13:05 2003
+++ llvm/lib/ExecutionEngine/Interpreter/Execution.cpp	Sun Dec 28 03:44:36 2003
@@ -12,11 +12,12 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "interpreter"
-
 #include "Interpreter.h"
-#include "llvm/Instructions.h"
-#include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Instructions.h"
+#include "llvm/IntrinsicLowering.h"
+#include "llvm/Intrinsics.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "Support/Statistic.h"
 #include "Support/Debug.h"
@@ -25,15 +26,15 @@
 
 namespace {
   Statistic<> NumDynamicInsts("lli", "Number of dynamic instructions executed");
-}
 
-namespace llvm {
   Interpreter *TheEE = 0;
 }
 
+
 //===----------------------------------------------------------------------===//
 //                     Value Manipulation code
 //===----------------------------------------------------------------------===//
+
 static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2, 
 				   const Type *Ty);
 static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2, 
@@ -764,6 +765,36 @@
 
 void Interpreter::visitCallSite(CallSite CS) {
   ExecutionContext &SF = ECStack.back();
+
+  // Check to see if this is an intrinsic function call...
+  if (Function *F = CS.getCalledFunction())
+    switch (F->getIntrinsicID()) {
+    case Intrinsic::va_start:  // va_start: implemented by getFirstVarArg()
+      SetValue(CS.getInstruction(), getFirstVarArg(), SF);
+      return;
+    case Intrinsic::va_end:    // va_end is a noop for the interpreter
+      return;
+    case Intrinsic::va_copy:   // va_copy: dest = src
+      SetValue(CS.getInstruction(), getOperandValue(*CS.arg_begin(), SF), SF);
+      return;
+    default:
+      // If it is an unknown intrinsic function, using the intrinsic lowering
+      // class to transform it into hopefully tasty LLVM code.
+      //
+      Instruction *Prev = CS.getInstruction()->getPrev();
+      BasicBlock *Parent = CS.getInstruction()->getParent();
+      IL->LowerIntrinsicCall(cast<CallInst>(CS.getInstruction()));
+
+      // Restore the CurInst pointer to the first instruction newly inserted, if
+      // any.
+      if (!Prev) {
+        SF.CurInst = Parent->begin();
+      } else {
+        SF.CurInst = Prev;
+        ++SF.CurInst;
+      }
+    }
+
   SF.Caller = CS;
   std::vector<GenericValue> ArgVals;
   const unsigned NumArgs = SF.Caller.arg_size();


Index: llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
diff -u llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.71 llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.72
--- llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp:1.71	Sun Dec 14 17:25:48 2003
+++ llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp	Sun Dec 28 03:44:37 2003
@@ -676,28 +676,6 @@
   return GV;
 }
 
-//===----------------------------------------------------------------------===//
-// LLVM Intrinsic Functions...
-//===----------------------------------------------------------------------===//
-
-// <va_list> llvm.va_start() - Implement the va_start operation...
-GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
-  assert(Args.size() == 0);
-  return TheInterpreter->getFirstVarArg();
-}
-
-// void llvm.va_end(<va_list> *) - Implement the va_end operation...
-GenericValue llvm_va_end(FunctionType *F, const vector<GenericValue> &Args) {
-  assert(Args.size() == 1);
-  return GenericValue();    // Noop!
-}
-
-// <va_list> llvm.va_copy(<va_list>) - Implement the va_copy operation...
-GenericValue llvm_va_copy(FunctionType *F, const vector<GenericValue> &Args) {
-  assert(Args.size() == 1);
-  return Args[0];
-}
-
 } // End extern "C"
 
 
@@ -749,9 +727,5 @@
   FuncNames["lle_X_ungetc"]       = lle_X_ungetc;
   FuncNames["lle_X_fprintf"]      = lle_X_fprintf;
   FuncNames["lle_X_freopen"]      = lle_X_freopen;
-
-  FuncNames["lle_X_llvm.va_start"]= llvm_va_start;
-  FuncNames["lle_X_llvm.va_end"]  = llvm_va_end;
-  FuncNames["lle_X_llvm.va_copy"] = llvm_va_copy;
 }
 


Index: llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
diff -u llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp:1.19 llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp:1.20
--- llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp:1.19	Fri Dec 26 00:13:05 2003
+++ llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp	Sun Dec 28 03:44:37 2003
@@ -14,13 +14,14 @@
 //===----------------------------------------------------------------------===//
 
 #include "Interpreter.h"
-#include "llvm/Module.h"
+#include "llvm/IntrinsicLowering.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
 using namespace llvm;
 
 /// create - Create a new interpreter object.  This can never fail.
 ///
-ExecutionEngine *Interpreter::create(Module *M){
+ExecutionEngine *Interpreter::create(Module *M, IntrinsicLowering *IL) {
   bool isLittleEndian = false;
   switch (M->getEndianness()) {
   case Module::LittleEndian: isLittleEndian = true; break;
@@ -41,22 +42,29 @@
     break;
   }
 
-  return new Interpreter(M, isLittleEndian, isLongPointer);
+  return new Interpreter(M, isLittleEndian, isLongPointer, IL);
 }
 
 //===----------------------------------------------------------------------===//
 // Interpreter ctor - Initialize stuff
 //
-Interpreter::Interpreter(Module *M, bool isLittleEndian, bool isLongPointer)
-  : ExecutionEngine(M), ExitCode(0),
+Interpreter::Interpreter(Module *M, bool isLittleEndian, bool isLongPointer,
+                         IntrinsicLowering *il)
+  : ExecutionEngine(M), ExitCode(0), 
     TD("lli", isLittleEndian, isLongPointer ? 8 : 4, isLongPointer ? 8 : 4,
-       isLongPointer ? 8 : 4) {
+       isLongPointer ? 8 : 4), IL(il) {
 
   setTargetData(TD);
   // Initialize the "backend"
   initializeExecutionEngine();
   initializeExternalFunctions();
   emitGlobals();
+
+  if (IL == 0) IL = new DefaultIntrinsicLowering();
+}
+
+Interpreter::~Interpreter() {
+  delete IL;
 }
 
 void Interpreter::runAtExitHandlers () {


Index: llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
diff -u llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.58 llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.59
--- llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.58	Fri Dec 26 00:13:05 2003
+++ llvm/lib/ExecutionEngine/Interpreter/Interpreter.h	Sun Dec 28 03:44:37 2003
@@ -79,6 +79,7 @@
 class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
   int ExitCode;                // The exit code to be returned by the lli util
   TargetData TD;
+  IntrinsicLowering *IL;
 
   // The runtime stack of executing code.  The top of the stack is the current
   // function record.
@@ -89,17 +90,20 @@
   std::vector<Function*> AtExitHandlers;
 
 public:
-  Interpreter(Module *M, bool isLittleEndian, bool isLongPointer);
-  inline ~Interpreter() { }
+  Interpreter(Module *M, bool isLittleEndian, bool isLongPointer,
+              IntrinsicLowering *IL);
+  ~Interpreter();
 
   /// runAtExitHandlers - Run any functions registered by the program's calls to
   /// atexit(3), which we intercept and store in AtExitHandlers.
   ///
   void runAtExitHandlers();
 
-  /// create - Create an interpreter ExecutionEngine. This can never fail.
+  /// create - Create an interpreter ExecutionEngine. This can never fail.  The
+  /// specified IntrinsicLowering implementation will be deleted when the
+  /// Interpreter execution engine is destroyed.
   ///
-  static ExecutionEngine *create(Module *M);
+  static ExecutionEngine *create(Module *M, IntrinsicLowering *IL);
 
   /// run - Start execution with the specified function and arguments.
   ///





More information about the llvm-commits mailing list