@@ -1023,6 +1023,32 @@ void mapped_file_region::unmapImpl() {
10231023
10241024void mapped_file_region::dontNeedImpl () {}
10251025
1026+ void mapped_file_region::willNeedImpl () {
1027+ #if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
1028+ typedef struct _WIN32_MEMORY_RANGE_ENTRY {
1029+ PVOID VirtualAddress;
1030+ SIZE_T NumberOfBytes;
1031+ } WIN32_MEMORY_RANGE_ENTRY, *PWIN32_MEMORY_RANGE_ENTRY;
1032+ #endif
1033+
1034+ HMODULE kernelM = llvm::sys::windows::loadSystemModuleSecure (L" kernel32.dll" );
1035+ if (kernelM) {
1036+ // PrefetchVirtualMemory is only available on Windows 8 and later. Since we
1037+ // still support compilation on Windows 7, we load the function dynamically.
1038+ typedef BOOL (WINAPI * PrefetchVirtualMemory_t)(
1039+ HANDLE hProcess, ULONG_PTR NumberOfEntries,
1040+ _In_reads_ (NumberOfEntries) PWIN32_MEMORY_RANGE_ENTRY VirtualAddresses,
1041+ ULONG Flags);
1042+ static const auto pfnPrefetchVirtualMemory =
1043+ (PrefetchVirtualMemory_t)::GetProcAddress (kernelM,
1044+ " PrefetchVirtualMemory" );
1045+ if (pfnPrefetchVirtualMemory) {
1046+ WIN32_MEMORY_RANGE_ENTRY Range{Mapping, Size};
1047+ pfnPrefetchVirtualMemory (::GetCurrentProcess (), 1 , &Range, 0 );
1048+ }
1049+ }
1050+ }
1051+
10261052std::error_code mapped_file_region::sync () const {
10271053 if (!::FlushViewOfFile (Mapping, Size))
10281054 return mapWindowsError (GetLastError ());
0 commit comments