AMDGPU: Fix off-by-one in SIRegisterInfo::eliminateFrameIndex
[oota-llvm.git] / tools / lli / RemoteTarget.h
index c95fbd1ae9e3b42ad7a113ec27c87fa7fe5d8a22..ee758a2747a4d92044046090004933ad5c2947f6 100644 (file)
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef REMOTEPROCESS_H
-#define REMOTEPROCESS_H
+#ifndef LLVM_TOOLS_LLI_REMOTETARGET_H
+#define LLVM_TOOLS_LLI_REMOTETARGET_H
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 namespace llvm {
 
 class RemoteTarget {
-  std::string ErrorMsg;
   bool IsRunning;
 
-  SmallVector<sys::MemoryBlock, 16> Allocations;
+  typedef SmallVector<sys::MemoryBlock, 16> AllocMapType;
+  AllocMapType Allocations;
+
+protected:
+  std::string ErrorMsg;
 
 public:
   StringRef getErrorMsg() const { return ErrorMsg; }
@@ -39,19 +42,31 @@ public:
   /// @param      Alignment Required minimum alignment for allocated space.
   /// @param[out] Address   Remote address of the allocated memory.
   ///
-  /// @returns False on success. On failure, ErrorMsg is updated with
+  /// @returns True on success. On failure, ErrorMsg is updated with
   ///          descriptive text of the encountered error.
   virtual bool allocateSpace(size_t Size,
                              unsigned Alignment,
                              uint64_t &Address);
 
+  bool isAllocatedMemory(uint64_t Address, uint32_t Size) {
+    uint64_t AddressEnd = Address + Size;
+    for (AllocMapType::const_iterator I = Allocations.begin(),
+                                      E = Allocations.end();
+         I != E; ++I) {
+      if (Address >= (uint64_t)I->base() &&
+          AddressEnd <= (uint64_t)I->base() + I->size())
+        return true;
+    }
+    return false;
+  }
+
   /// Load data into the target address space.
   ///
   /// @param      Address   Destination address in the target process.
   /// @param      Data      Source address in the host process.
   /// @param      Size      Number of bytes to copy.
   ///
-  /// @returns False on success. On failure, ErrorMsg is updated with
+  /// @returns True on success. On failure, ErrorMsg is updated with
   ///          descriptive text of the encountered error.
   virtual bool loadData(uint64_t Address,
                         const void *Data,
@@ -63,7 +78,7 @@ public:
   /// @param      Data      Source address in the host process.
   /// @param      Size      Number of bytes to copy.
   ///
-  /// @returns False on success. On failure, ErrorMsg is updated with
+  /// @returns True on success. On failure, ErrorMsg is updated with
   ///          descriptive text of the encountered error.
   virtual bool loadCode(uint64_t Address,
                         const void *Data,
@@ -76,12 +91,12 @@ public:
   ///                       process.
   /// @param[out] RetVal    The integer return value of the called function.
   ///
-  /// @returns False on success. On failure, ErrorMsg is updated with
+  /// @returns True on success. On failure, ErrorMsg is updated with
   ///          descriptive text of the encountered error.
   virtual bool executeCode(uint64_t Address,
                            int &RetVal);
 
-  /// Minimum alignment for memory permissions. Used to seperate code and
+  /// Minimum alignment for memory permissions. Used to separate code and
   /// data regions to make sure data doesn't get marked as code or vice
   /// versa.
   ///
@@ -89,18 +104,13 @@ public:
   virtual unsigned getPageAlignment() { return 4096; }
 
   /// Start the remote process.
-  virtual void create();
+  virtual bool create();
 
   /// Terminate the remote process.
   virtual void stop();
 
-  RemoteTarget() : ErrorMsg(""), IsRunning(false) {}
+  RemoteTarget() : IsRunning(false), ErrorMsg("") {}
   virtual ~RemoteTarget() { if (IsRunning) stop(); }
-
-  // Create an instance of the system-specific remote target class.
-  static RemoteTarget *createRemoteTarget();
-  static RemoteTarget *createExternalRemoteTarget(std::string &ChildName);
-  static bool hostSupportsExternalRemoteTarget(); 
 private:
   // Main processing function for the remote target process. Command messages
   // are received on file descriptor CmdFD and responses come back on OutFD.