[llvm] r334294 - Clean up some code in Program.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 8 08:16:26 PDT 2018
Author: zturner
Date: Fri Jun 8 08:16:25 2018
New Revision: 334294
URL: http://llvm.org/viewvc/llvm-project?rev=334294&view=rev
Log:
Clean up some code in Program.
NFC here, this just raises some platform specific ifdef hackery
out of a class and creates proper platform-independent typedefs
for the relevant things. This allows these typedefs to be
reused in other places without having to reinvent this preprocessor
logic.
Modified:
llvm/trunk/include/llvm/Support/Program.h
llvm/trunk/lib/Support/Unix/Program.inc
llvm/trunk/lib/Support/Windows/Program.inc
llvm/trunk/tools/llvm-xray/xray-account.h
llvm/trunk/tools/llvm-xray/xray-graph.h
Modified: llvm/trunk/include/llvm/Support/Program.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Program.h?rev=334294&r1=334293&r2=334294&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Program.h (original)
+++ llvm/trunk/include/llvm/Support/Program.h Fri Jun 8 08:16:25 2018
@@ -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.
///
Modified: llvm/trunk/lib/Support/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=334294&r1=334293&r2=334294&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Program.inc (original)
+++ llvm/trunk/lib/Support/Unix/Program.inc Fri Jun 8 08:16:25 2018
@@ -237,6 +237,7 @@ static bool Execute(ProcessInfo &PI, Str
return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err);
PI.Pid = PID;
+ PI.Process = PID;
return true;
}
@@ -300,6 +301,7 @@ static bool Execute(ProcessInfo &PI, Str
}
PI.Pid = child;
+ PI.Process = child;
return true;
}
Modified: llvm/trunk/lib/Support/Windows/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Program.inc?rev=334294&r1=334293&r2=334294&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Program.inc (original)
+++ llvm/trunk/lib/Support/Windows/Program.inc Fri Jun 8 08:16:25 2018
@@ -31,7 +31,7 @@
namespace llvm {
-ProcessInfo::ProcessInfo() : ProcessHandle(0), Pid(0), ReturnCode(0) {}
+ProcessInfo::ProcessInfo() : Process(0), Pid(0), ReturnCode(0) {}
ErrorOr<std::string> sys::findProgramByName(StringRef Name,
ArrayRef<StringRef> Paths) {
@@ -381,7 +381,7 @@ static bool Execute(ProcessInfo &PI, Str
}
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
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
// 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);
Modified: llvm/trunk/tools/llvm-xray/xray-account.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-account.h?rev=334294&r1=334293&r2=334294&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-account.h (original)
+++ llvm/trunk/tools/llvm-xray/xray-account.h Fri Jun 8 08:16:25 2018
@@ -29,12 +29,11 @@ namespace xray {
class LatencyAccountant {
public:
typedef std::map<int32_t, std::vector<uint64_t>> FunctionLatencyMap;
- typedef std::map<llvm::sys::ProcessInfo::ProcessId,
- std::pair<uint64_t, uint64_t>>
+ typedef std::map<llvm::sys::procid_t, std::pair<uint64_t, uint64_t>>
PerThreadMinMaxTSCMap;
typedef std::map<uint8_t, std::pair<uint64_t, uint64_t>> PerCPUMinMaxTSCMap;
typedef std::vector<std::pair<int32_t, uint64_t>> FunctionStack;
- typedef std::map<llvm::sys::ProcessInfo::ProcessId, FunctionStack>
+ typedef std::map<llvm::sys::procid_t, FunctionStack>
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;
Modified: llvm/trunk/tools/llvm-xray/xray-graph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-xray/xray-graph.h?rev=334294&r1=334293&r2=334294&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-xray/xray-graph.h (original)
+++ llvm/trunk/tools/llvm-xray/xray-graph.h Fri Jun 8 08:16:25 2018
@@ -80,7 +80,7 @@ public:
using FunctionStack = SmallVector<FunctionAttr, 4>;
using PerThreadFunctionStackMap =
- DenseMap<llvm::sys::ProcessInfo::ProcessId, FunctionStack>;
+ DenseMap<llvm::sys::procid_t, FunctionStack>;
class GraphT : public Graph<FunctionStats, CallStats, int32_t> {
public:
More information about the llvm-commits
mailing list