diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index 8f8a6a6f29b..381b0d4902d 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -32,29 +32,26 @@ namespace sys { const char EnvPathSeparator = ';'; #endif -/// This struct encapsulates information about a process. -struct ProcessInfo { -#if defined(LLVM_ON_UNIX) - typedef pid_t ProcessId; -#elif defined(_WIN32) - typedef unsigned long ProcessId; // Must match the type of DWORD on Windows. - typedef void * HANDLE; // Must match the type of HANDLE on Windows. - /// The handle to the process (available on Windows only). - HANDLE ProcessHandle; +#if defined(_WIN32) + typedef unsigned long procid_t; // Must match the type of DWORD on Windows. + typedef void *process_t; // Must match the type of HANDLE on Windows. #else -#error "ProcessInfo is not defined for this platform!" + typedef pid_t procid_t; + typedef procid_t process_t; #endif - enum : ProcessId { InvalidPid = 0 }; + /// This struct encapsulates information about a process. + struct ProcessInfo { + enum : procid_t { InvalidPid = 0 }; - /// The process identifier. - ProcessId Pid; + procid_t Pid; /// The process identifier. + process_t Process; /// Platform-dependent process object. - /// The return code, set after execution. - int ReturnCode; + /// The return code, set after execution. + int ReturnCode; - ProcessInfo(); -}; + ProcessInfo(); + }; /// Find the first executable file \p Name in \p Paths. /// diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc index 03599c44b69..5344adf9c3f 100644 --- a/lib/Support/Unix/Program.inc +++ b/lib/Support/Unix/Program.inc @@ -237,6 +237,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err); PI.Pid = PID; + PI.Process = PID; return true; } @@ -300,6 +301,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, } PI.Pid = child; + PI.Process = child; return true; } diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc index 0dcd305d1eb..183b66ce2c0 100644 --- a/lib/Support/Windows/Program.inc +++ b/lib/Support/Windows/Program.inc @@ -31,7 +31,7 @@ namespace llvm { -ProcessInfo::ProcessInfo() : ProcessHandle(0), Pid(0), ReturnCode(0) {} +ProcessInfo::ProcessInfo() : Process(0), Pid(0), ReturnCode(0) {} ErrorOr sys::findProgramByName(StringRef Name, ArrayRef Paths) { @@ -381,7 +381,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, } PI.Pid = pi.dwProcessId; - PI.ProcessHandle = pi.hProcess; + PI.Process = pi.hProcess; // Make sure these get closed no matter what. ScopedCommonHandle hThread(pi.hThread); @@ -418,7 +418,7 @@ namespace llvm { ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, bool WaitUntilChildTerminates, std::string *ErrMsg) { assert(PI.Pid && "invalid pid to wait on, process not started?"); - assert(PI.ProcessHandle && + assert((PI.Process && PI.Process != INVALID_HANDLE_VALUE) && "invalid process handle to wait on, process not started?"); DWORD milliSecondsToWait = 0; if (WaitUntilChildTerminates) @@ -427,20 +427,20 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, milliSecondsToWait = SecondsToWait * 1000; ProcessInfo WaitResult = PI; - DWORD WaitStatus = WaitForSingleObject(PI.ProcessHandle, milliSecondsToWait); + DWORD WaitStatus = WaitForSingleObject(PI.Process, milliSecondsToWait); if (WaitStatus == WAIT_TIMEOUT) { if (SecondsToWait) { - if (!TerminateProcess(PI.ProcessHandle, 1)) { + if (!TerminateProcess(PI.Process, 1)) { if (ErrMsg) MakeErrMsg(ErrMsg, "Failed to terminate timed-out program"); // -2 indicates a crash or timeout as opposed to failure to execute. WaitResult.ReturnCode = -2; - CloseHandle(PI.ProcessHandle); + CloseHandle(PI.Process); return WaitResult; } - WaitForSingleObject(PI.ProcessHandle, INFINITE); - CloseHandle(PI.ProcessHandle); + WaitForSingleObject(PI.Process, INFINITE); + CloseHandle(PI.Process); } else { // Non-blocking wait. return ProcessInfo(); @@ -449,10 +449,10 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, // Get its exit status. DWORD status; - BOOL rc = GetExitCodeProcess(PI.ProcessHandle, &status); + BOOL rc = GetExitCodeProcess(PI.Process, &status); DWORD err = GetLastError(); if (err != ERROR_INVALID_HANDLE) - CloseHandle(PI.ProcessHandle); + CloseHandle(PI.Process); if (!rc) { SetLastError(err); diff --git a/tools/llvm-xray/xray-account.h b/tools/llvm-xray/xray-account.h index cc9ba897e53..5c457f17816 100644 --- a/tools/llvm-xray/xray-account.h +++ b/tools/llvm-xray/xray-account.h @@ -29,12 +29,11 @@ namespace xray { class LatencyAccountant { public: typedef std::map> FunctionLatencyMap; - typedef std::map> + typedef std::map> PerThreadMinMaxTSCMap; typedef std::map> PerCPUMinMaxTSCMap; typedef std::vector> FunctionStack; - typedef std::map + typedef std::map PerThreadFunctionStackMap; private: @@ -79,8 +78,7 @@ public: /// bool accountRecord(const XRayRecord &Record); - const FunctionStack * - getThreadFunctionStack(llvm::sys::ProcessInfo::ProcessId TId) const { + const FunctionStack *getThreadFunctionStack(llvm::sys::procid_t TId) const { auto I = PerThreadFunctionStack.find(TId); if (I == PerThreadFunctionStack.end()) return nullptr; diff --git a/tools/llvm-xray/xray-graph.h b/tools/llvm-xray/xray-graph.h index a43df265d0e..fc7f8bb470f 100644 --- a/tools/llvm-xray/xray-graph.h +++ b/tools/llvm-xray/xray-graph.h @@ -80,7 +80,7 @@ public: using FunctionStack = SmallVector; using PerThreadFunctionStackMap = - DenseMap; + DenseMap; class GraphT : public Graph { public: