source: icGREP/icgrep-devel/icgrep/grep_engine.cpp @ 5828

Last change on this file since 5828 was 5824, checked in by cameron, 16 months ago

Test case for compileCCfromCodeUnitStream using DirectLineFeedBuilder?

File size: 20.3 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "grep_engine.h"
8#include "grep_interface.h"
9#include <llvm/IR/Module.h>
10#include <boost/filesystem.hpp>
11#include <UCD/resolve_properties.h>
12#include <kernels/charclasses.h>
13#include <kernels/cc_kernel.h>
14#include <kernels/grep_kernel.h>
15#include <kernels/linebreak_kernel.h>
16#include <kernels/streams_merge.h>
17#include <kernels/source_kernel.h>
18#include <kernels/s2p_kernel.h>
19#include <kernels/scanmatchgen.h>
20#include <kernels/streamset.h>
21#include <kernels/until_n.h>
22#include <kernels/kernel_builder.h>
23#include <pablo/pablo_kernel.h>
24#include <re/re_cc.h>
25#include <re/casing.h>
26#include <re/exclude_CC.h>
27#include <re/re_toolchain.h>
28#include <toolchain/toolchain.h>
29#include <re/re_name_resolve.h>
30#include <re/re_collect_unicodesets.h>
31#include <re/re_multiplex.h>
32#include <re/grapheme_clusters.h>
33#include <re/printer_re.h>
34#include <toolchain/toolchain.h>
35#include <toolchain/cpudriver.h>
36#include <iostream>
37#include <cc/multiplex_CCs.h>
38#include <llvm/Support/raw_ostream.h>
39#include <util/aligned_allocator.h>
40#include <sys/stat.h>
41#include <fcntl.h>
42#include <errno.h>
43#include <llvm/ADT/STLExtras.h> // for make_unique
44#include <llvm/Support/CommandLine.h>
45#include <llvm/Support/Debug.h>
46#include <sched.h>
47
48using namespace parabix;
49using namespace llvm;
50using namespace cc;
51
52static cl::opt<int> Threads("t", cl::desc("Total number of threads."), cl::init(2));
53
54namespace grep {
55
56// Grep Engine construction and initialization.
57
58GrepEngine::GrepEngine() :
59    mGrepDriver(nullptr),
60    mNextFileToGrep(0),
61    mNextFileToPrint(0),
62    grepMatchFound(false),
63    mMoveMatchesToEOL(true),
64    mEngineThread(pthread_self()) {}
65
66GrepEngine::~GrepEngine() {
67    delete mGrepDriver;
68}
69
70QuietModeEngine::QuietModeEngine() : GrepEngine() {
71    mMoveMatchesToEOL = false;
72}
73
74MatchOnlyEngine::MatchOnlyEngine(bool showFilesWithoutMatch) :
75    GrepEngine(), mRequiredCount(showFilesWithoutMatch) {
76    mFileSuffix = NullFlag ? std::string("\0", 1) : "\n";
77    mMoveMatchesToEOL = false;
78}
79
80CountOnlyEngine::CountOnlyEngine() : GrepEngine() {
81    mFileSuffix = ":";
82}
83
84EmitMatchesEngine::EmitMatchesEngine() : GrepEngine() {
85    mFileSuffix = InitialTabFlag ? "\t:" : ":";
86    if (LineRegexpFlag) mMoveMatchesToEOL = false;
87}
88
89void GrepEngine::initFileResult(std::vector<std::string> & filenames) {
90    const unsigned n = filenames.size();
91    mResultStrs.resize(n);
92    mFileStatus.resize(n, FileStatus::Pending);
93    inputFiles = filenames;
94}
95
96// Code Generation
97//
98// All engines share a common pipeline to compute a stream of Matches from a given input Bytestream.
99//#define USE_DIRECT_LF_BUILDER 1
100
101std::pair<StreamSetBuffer *, StreamSetBuffer *> GrepEngine::grepPipeline(std::vector<re::RE *> & REs, StreamSetBuffer * ByteStream) {
102    auto & idb = mGrepDriver->getBuilder();
103    const unsigned segmentSize = codegen::SegmentSize;
104    const unsigned bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
105    const unsigned encodingBits = 8;
106
107    StreamSetBuffer * BasisBits = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(encodingBits, 1), segmentSize * bufferSegments);
108    kernel::Kernel * s2pk = mGrepDriver->addKernelInstance<kernel::S2PKernel>(idb);
109    mGrepDriver->makeKernelCall(s2pk, {ByteStream}, {BasisBits});
110
111    StreamSetBuffer * LineFeedStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
112#ifdef USE_DIRECT_LF_BUILDER
113    kernel::Kernel * linefeedK = mGrepDriver->addKernelInstance<kernel::DirectLineFeedBuilder>(idb);
114    mGrepDriver->makeKernelCall(linefeedK, {ByteStream}, {LineFeedStream});
115#else
116    kernel::Kernel * linefeedK = mGrepDriver->addKernelInstance<kernel::LineFeedKernelBuilder>(idb, encodingBits);
117    mGrepDriver->makeKernelCall(linefeedK, {BasisBits}, {LineFeedStream});
118#endif
119
120    StreamSetBuffer * LineBreakStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
121    StreamSetBuffer * CRLFStream = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
122    kernel::Kernel * linebreakK = mGrepDriver->addKernelInstance<kernel::LineBreakKernelBuilder>(idb, encodingBits);
123    mGrepDriver->makeKernelCall(linebreakK, {BasisBits, LineFeedStream}, {LineBreakStream, CRLFStream});
124
125    kernel::Kernel * requiredStreamsK = mGrepDriver->addKernelInstance<kernel::RequiredStreams_UTF8>(idb);
126    StreamSetBuffer * RequiredStreams = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(3, 1), segmentSize * bufferSegments);
127    mGrepDriver->makeKernelCall(requiredStreamsK, {BasisBits}, {RequiredStreams});
128
129    const auto n = REs.size();
130    std::vector<StreamSetBuffer *> MatchResultsBufs(n);
131
132    for(unsigned i = 0; i < n; ++i) {
133        REs[i] = resolveModesAndExternalSymbols(REs[i]);
134        REs[i] = excludeUnicodeLineBreak(REs[i]);
135        REs[i] = regular_expression_passes(REs[i]);
136#define USE_MULTIPLEX_CC
137#ifdef USE_MULTIPLEX_CC
138        const std::vector<const re::CC *> UnicodeSets = re::collectUnicodeSets(REs[i]);
139        if (UnicodeSets.size() <= 1) {
140            StreamSetBuffer * MatchResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
141            kernel::Kernel * icgrepK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, REs[i]);
142            mGrepDriver->makeKernelCall(icgrepK, {BasisBits, LineBreakStream, CRLFStream, RequiredStreams}, {MatchResults});
143            MatchResultsBufs[i] = MatchResults;
144        }
145        else {
146            mpx = make_unique<MultiplexedAlphabet>("mpx", UnicodeSets);
147            REs[i] = transformCCs(mpx.get(), REs[i]);
148            std::vector<re::CC *> mpx_basis = mpx->getMultiplexedCCs();
149            auto numOfCharacterClasses = mpx_basis.size();
150            StreamSetBuffer * CharClasses = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(numOfCharacterClasses), segmentSize * bufferSegments);
151            kernel::Kernel * ccK = mGrepDriver->addKernelInstance<kernel::CharClassesKernel>(idb, std::move(mpx_basis));
152            mGrepDriver->makeKernelCall(ccK, {BasisBits}, {CharClasses});
153            StreamSetBuffer * MatchResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
154            kernel::Kernel * icgrepK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, REs[i], std::vector<cc::Alphabet *>{mpx.get()});
155            mGrepDriver->makeKernelCall(icgrepK, {BasisBits, LineBreakStream, CRLFStream, RequiredStreams, CharClasses}, {MatchResults});
156            MatchResultsBufs[i] = MatchResults;
157        }
158#else
159        StreamSetBuffer * MatchResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
160        kernel::Kernel * icgrepK = mGrepDriver->addKernelInstance<kernel::ICGrepKernel>(idb, REs[i]);
161        mGrepDriver->makeKernelCall(icgrepK, {BasisBits, LineBreakStream, CRLFStream, RequiredStreams}, {MatchResults});
162        MatchResultsBufs[i] = MatchResults;
163#endif
164    }
165    StreamSetBuffer * MergedResults = MatchResultsBufs[0];
166    if (REs.size() > 1) {
167        MergedResults = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
168        kernel::Kernel * streamsMergeK = mGrepDriver->addKernelInstance<kernel::StreamsMerge>(idb, 1, REs.size());
169        mGrepDriver->makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
170    }
171    StreamSetBuffer * Matches = MergedResults;
172
173    if (mMoveMatchesToEOL) {
174        StreamSetBuffer * OriginalMatches = Matches;
175        kernel::Kernel * matchedLinesK = mGrepDriver->addKernelInstance<kernel::MatchedLinesKernel>(idb);
176        Matches = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
177        mGrepDriver->makeKernelCall(matchedLinesK, {OriginalMatches, LineBreakStream}, {Matches});
178    }
179
180    if (InvertMatchFlag) {
181        kernel::Kernel * invertK = mGrepDriver->addKernelInstance<kernel::InvertMatchesKernel>(idb);
182        StreamSetBuffer * OriginalMatches = Matches;
183        Matches = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
184        mGrepDriver->makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {Matches});
185    }
186    if (MaxCountFlag > 0) {
187        kernel::Kernel * untilK = mGrepDriver->addKernelInstance<kernel::UntilNkernel>(idb);
188        untilK->setInitialArguments({idb->getSize(MaxCountFlag)});
189        StreamSetBuffer * AllMatches = Matches;
190        Matches = mGrepDriver->addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments);
191        mGrepDriver->makeKernelCall(untilK, {AllMatches}, {Matches});
192    }
193    return std::pair<StreamSetBuffer *, StreamSetBuffer *>(LineBreakStream, Matches);
194}
195
196// The QuietMode, MatchOnly and CountOnly engines share a common code generation main function,
197// which returns a count of the matches found (possibly subject to a MaxCount).
198//
199
200void GrepEngine::grepCodeGen(std::vector<re::RE *> REs) {
201
202    assert (mGrepDriver == nullptr);
203    mGrepDriver = new ParabixDriver("engine");
204    auto & idb = mGrepDriver->getBuilder();
205    Module * M = idb->getModule();
206
207    const auto segmentSize = codegen::SegmentSize;
208    const auto bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
209
210    const unsigned encodingBits = 8;
211
212    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), nullptr));
213    mainFunc->setCallingConv(CallingConv::C);
214    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
215    auto args = mainFunc->arg_begin();
216
217    Value * const fileDescriptor = &*(args++);
218    fileDescriptor->setName("fileDescriptor");
219
220    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits));
221    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::FDSourceKernel>(idb, segmentSize * bufferSegments);
222    sourceK->setInitialArguments({fileDescriptor});
223    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
224
225    StreamSetBuffer * LineBreakStream;
226    StreamSetBuffer * Matches;
227    std::tie(LineBreakStream, Matches) = grepPipeline(REs, ByteStream);
228
229    kernel::Kernel * matchCountK = mGrepDriver->addKernelInstance<kernel::PopcountKernel>(idb);
230    mGrepDriver->makeKernelCall(matchCountK, {Matches}, {});
231    mGrepDriver->generatePipelineIR();
232    idb->setKernel(matchCountK);
233    Value * matchedLineCount = idb->getAccumulator("countResult");
234    matchedLineCount = idb->CreateZExt(matchedLineCount, idb->getInt64Ty());
235    mGrepDriver->deallocateBuffers();
236    idb->CreateRet(matchedLineCount);
237    mGrepDriver->finalizeObject();
238}
239
240//
241// The EmitMatches engine uses an EmitMatchesAccumulator object to concatenate together
242// matched lines.
243
244class EmitMatch : public MatchAccumulator {
245    friend class EmitMatchesEngine;
246public:
247    EmitMatch(std::string linePrefix, std::ostringstream & strm) : mLinePrefix(linePrefix), mLineCount(0), mTerminated(true), mResultStr(strm) {}
248    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
249    void finalize_match(char * buffer_end) override;
250protected:
251    std::string mLinePrefix;
252    size_t mLineCount;
253    bool mTerminated;
254    std::ostringstream & mResultStr;
255};
256
257//
258//  Default Report Match:  lines are emitted with whatever line terminators are found in the
259//  input.  However, if the final line is not terminated, a new line is appended.
260//
261void EmitMatch::accumulate_match (const size_t lineNum, char * line_start, char * line_end) {
262    if (WithFilenameFlag) {
263        mResultStr << mLinePrefix;
264    }
265    if (LineNumberFlag) {
266        // Internally line numbers are counted from 0.  For display, adjust
267        // the line number so that lines are numbered from 1.
268        if (InitialTabFlag) {
269            mResultStr << lineNum+1 << "\t:";
270        }
271        else {
272            mResultStr << lineNum+1 << ":";
273        }
274    }
275    size_t bytes = line_end - line_start + 1;
276    mResultStr.write(line_start, bytes);
277    mLineCount++;
278    unsigned last_byte = *line_end;
279    mTerminated = (last_byte >= 0x0A) && (last_byte <= 0x0D);
280    if (LLVM_UNLIKELY(!mTerminated)) {
281        if (last_byte == 0x85) {  //  Possible NEL terminator.
282            mTerminated = (bytes >= 2) && (static_cast<unsigned>(line_end[-1]) == 0xC2);
283        }
284        else {
285            // Possible LS or PS terminators.
286            mTerminated = (bytes >= 3) && (static_cast<unsigned>(line_end[-2]) == 0xE2)
287                                       && (static_cast<unsigned>(line_end[-1]) == 0x80)
288                                       && ((last_byte == 0xA8) || (last_byte == 0xA9));
289        }
290    }
291}
292
293void EmitMatch::finalize_match(char * buffer_end) {
294    if (!mTerminated) mResultStr << "\n";
295}
296
297void EmitMatchesEngine::grepCodeGen(std::vector<re::RE *> REs) {
298    assert (mGrepDriver == nullptr);
299    mGrepDriver = new ParabixDriver("engine");
300    auto & idb = mGrepDriver->getBuilder();
301    Module * M = idb->getModule();
302
303    const auto segmentSize = codegen::SegmentSize;
304    const auto bufferSegments = codegen::BufferSegments * codegen::ThreadNum;
305    const unsigned encodingBits = 8;
306
307    Function * mainFunc = cast<Function>(M->getOrInsertFunction("Main", idb->getInt64Ty(), idb->getInt32Ty(), idb->getIntAddrTy(), nullptr));
308    mainFunc->setCallingConv(CallingConv::C);
309    idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
310    auto args = mainFunc->arg_begin();
311
312    Value * const fileDescriptor = &*(args++);
313    fileDescriptor->setName("fileDescriptor");
314    Value * match_accumulator = &*(args++);
315    match_accumulator->setName("match_accumulator");
316
317    StreamSetBuffer * ByteStream = mGrepDriver->addBuffer<SourceBuffer>(idb, idb->getStreamSetTy(1, encodingBits));
318    kernel::Kernel * sourceK = mGrepDriver->addKernelInstance<kernel::FDSourceKernel>(idb, segmentSize * bufferSegments);
319    sourceK->setInitialArguments({fileDescriptor});
320    mGrepDriver->makeKernelCall(sourceK, {}, {ByteStream});
321
322    StreamSetBuffer * LineBreakStream;
323    StreamSetBuffer * Matches;
324    std::tie(LineBreakStream, Matches) = grepPipeline(REs, ByteStream);
325
326    kernel::Kernel * scanMatchK = mGrepDriver->addKernelInstance<kernel::ScanMatchKernel>(idb);
327    scanMatchK->setInitialArguments({match_accumulator});
328    mGrepDriver->makeKernelCall(scanMatchK, {Matches, LineBreakStream, ByteStream}, {});
329    mGrepDriver->LinkFunction(*scanMatchK, "accumulate_match_wrapper", &accumulate_match_wrapper);
330    mGrepDriver->LinkFunction(*scanMatchK, "finalize_match_wrapper", &finalize_match_wrapper);
331
332    mGrepDriver->generatePipelineIR();
333    mGrepDriver->deallocateBuffers();
334    idb->CreateRet(idb->getInt64(0));
335    mGrepDriver->finalizeObject();
336}
337
338
339//
340//  The doGrep methods apply a GrepEngine to a single file, processing the results
341//  differently based on the engine type.
342
343uint64_t GrepEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
344    typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor);
345    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
346
347    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx]);
348    if (fileDescriptor == -1) return 0;
349
350    uint64_t grepResult = f(fileDescriptor);
351    close(fileDescriptor);
352    return grepResult;
353}
354
355uint64_t CountOnlyEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
356    uint64_t grepResult = GrepEngine::doGrep(fileName, fileIdx);
357    if (WithFilenameFlag) mResultStrs[fileIdx] << linePrefix(fileName);
358    mResultStrs[fileIdx] << grepResult << "\n";
359    return grepResult;
360}
361
362std::string GrepEngine::linePrefix(std::string fileName) {
363    if (fileName == "-") {
364        return LabelFlag + mFileSuffix;
365    }
366    else {
367        return fileName + mFileSuffix;
368    }
369}
370
371uint64_t MatchOnlyEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
372    uint64_t grepResult = GrepEngine::doGrep(fileName, fileIdx);
373    if (grepResult == mRequiredCount) {
374       mResultStrs[fileIdx] << linePrefix(fileName);
375    }
376    return grepResult;
377}
378
379uint64_t EmitMatchesEngine::doGrep(const std::string & fileName, const uint32_t fileIdx) {
380    typedef uint64_t (*GrepFunctionType)(int32_t fileDescriptor, intptr_t accum_addr);
381    auto f = reinterpret_cast<GrepFunctionType>(mGrepDriver->getMain());
382
383    int32_t fileDescriptor = openFile(fileName, mResultStrs[fileIdx]);
384    if (fileDescriptor == -1) return 0;
385    EmitMatch accum(linePrefix(fileName), mResultStrs[fileIdx]);
386    f(fileDescriptor, reinterpret_cast<intptr_t>(&accum));
387    close(fileDescriptor);
388    if (accum.mLineCount > 0) grepMatchFound = true;
389    return accum.mLineCount;
390}
391
392// Open a file and return its file desciptor.
393int32_t GrepEngine::openFile(const std::string & fileName, std::ostringstream & msgstrm) {
394    if (fileName == "-") {
395        return STDIN_FILENO;
396    }
397    else {
398        struct stat sb;
399        int32_t fileDescriptor = open(fileName.c_str(), O_RDONLY);
400        if (LLVM_UNLIKELY(fileDescriptor == -1)) {
401            if (!NoMessagesFlag) {
402                if (errno == EACCES) {
403                    msgstrm << "icgrep: " << fileName << ": Permission denied.\n";
404                }
405                else if (errno == ENOENT) {
406                    msgstrm << "icgrep: " << fileName << ": No such file.\n";
407                }
408                else {
409                    msgstrm << "icgrep: " << fileName << ": Failed.\n";
410                }
411            }
412            return fileDescriptor;
413        }
414        if (stat(fileName.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
415            if (!NoMessagesFlag) {
416                msgstrm << "icgrep: " << fileName << ": Is a directory.\n";
417            }
418            close(fileDescriptor);
419            return -1;
420        }
421        return fileDescriptor;
422    }
423}
424
425// The process of searching a group of files may use a sequential or a task
426// parallel approach.
427
428void * DoGrepThreadFunction(void *args) {
429    return reinterpret_cast<GrepEngine *>(args)->DoGrepThreadMethod();
430}
431
432bool GrepEngine::searchAllFiles() {
433    const unsigned numOfThreads = std::min(static_cast<unsigned>(Threads), static_cast<unsigned>(inputFiles.size())); 
434    std::vector<pthread_t> threads(numOfThreads);
435
436    for(unsigned long i = 1; i < numOfThreads; ++i) {
437        const int rc = pthread_create(&threads[i], nullptr, DoGrepThreadFunction, (void *)this);
438        if (rc) {
439            llvm::report_fatal_error("Failed to create thread: code " + std::to_string(rc));
440        }
441    }
442    // Main thread also does the work;
443
444    DoGrepThreadMethod();
445    for(unsigned i = 1; i < numOfThreads; ++i) {
446        void * status = nullptr;
447        const int rc = pthread_join(threads[i], &status);
448        if (rc) {
449            llvm::report_fatal_error("Failed to join thread: code " + std::to_string(rc));
450        }
451    }
452    return grepMatchFound;
453}
454
455
456// DoGrep thread function.
457void * GrepEngine::DoGrepThreadMethod() {
458
459    unsigned fileIdx = mNextFileToGrep++;
460    while (fileIdx < inputFiles.size()) {
461        const auto grepResult = doGrep(inputFiles[fileIdx], fileIdx);
462        mFileStatus[fileIdx] = FileStatus::GrepComplete;
463        if (grepResult > 0) {
464            grepMatchFound = true;
465        }
466        if (QuietMode && grepMatchFound) {
467            if (pthread_self() != mEngineThread) {
468                pthread_exit(nullptr);
469            }
470            return nullptr;
471        }
472        fileIdx = mNextFileToGrep++;
473    }
474
475    unsigned printIdx = mNextFileToPrint++;
476    while (printIdx < inputFiles.size()) {
477        const bool readyToPrint = ((printIdx == 0) || (mFileStatus[printIdx - 1] == FileStatus::PrintComplete)) && (mFileStatus[printIdx] == FileStatus::GrepComplete);
478        if (readyToPrint) {
479            const auto output = mResultStrs[printIdx].str();
480            if (!output.empty()) {
481                llvm::outs() << output;
482            }
483            mFileStatus[printIdx] = FileStatus::PrintComplete;
484            printIdx = mNextFileToPrint++;
485        } else {
486            mGrepDriver->performIncrementalCacheCleanupStep();
487        }
488        sched_yield();
489    }
490
491    if (pthread_self() != mEngineThread) {
492        pthread_exit(nullptr);
493    } else {
494        // Always perform one final cache cleanup step.
495        mGrepDriver->performIncrementalCacheCleanupStep();
496    }
497    return nullptr;
498}
499
500}
Note: See TracBrowser for help on using the repository browser.