Skip to content

Commit

Permalink
Revert "A new hidden option test-changed=exe that calls exe after eac…
Browse files Browse the repository at this point in the history
…h time IR changes"

This reverts commit f9235e4.

Causes breakages on Windows: http://45.33.8.238/win/50453/step_11.txt.
  • Loading branch information
aeubanks committed Dec 8, 2021
1 parent ca451d3 commit c4ce426
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 249 deletions.
27 changes: 0 additions & 27 deletions llvm/include/llvm/Passes/StandardInstrumentations.h
Expand Up @@ -269,32 +269,6 @@ class IRChangedPrinter : public TextChangeReporter<std::string> {
Any) override;
};

class IRChangedTester : public IRChangedPrinter {
public:
IRChangedTester() : IRChangedPrinter(true) {}
~IRChangedTester() override;
void registerCallbacks(PassInstrumentationCallbacks &PIC);

protected:
void handleIR(const std::string &IR, StringRef PassID);

// Check initial IR
void handleInitialIR(Any IR) override;
// Do nothing.
void omitAfter(StringRef PassID, std::string &Name) override;
// Do nothing.
void handleInvalidated(StringRef PassID) override;
// Do nothing.
void handleFiltered(StringRef PassID, std::string &Name) override;
// Do nothing.
void handleIgnored(StringRef PassID, std::string &Name) override;

// Call test as interesting IR has changed.
void handleAfter(StringRef PassID, std::string &Name,
const std::string &Before, const std::string &After,
Any) override;
};

// Information that needs to be saved for a basic block in order to compare
// before and after the pass to determine if it was changed by a pass.
template <typename T> class BlockDataT {
Expand Down Expand Up @@ -530,7 +504,6 @@ class StandardInstrumentations {
PseudoProbeVerifier PseudoProbeVerification;
InLineChangePrinter PrintChangedDiff;
DotCfgChangeReporter WebsiteChangeReporter;
IRChangedTester ChangeTester;
VerifyInstrumentation Verify;

bool VerifyEach;
Expand Down
145 changes: 30 additions & 115 deletions llvm/lib/Passes/StandardInstrumentations.cpp
Expand Up @@ -164,30 +164,22 @@ static cl::opt<std::string> DotCfgDir(
cl::desc("Generate dot files into specified directory for changed IRs"),
cl::Hidden, cl::init("./"));

// An option for specifying an executable that will be called with the IR
// everytime it changes in the opt pipeline. It will also be called on
// the initial IR as it enters the pipeline. The executable will be passed
// the name of a temporary file containing the IR and the PassID. This may
// be used, for example, to call llc on the IR and run a test to determine
// which pass makes a change that changes the functioning of the IR.
// The usual modifier options work as expected.
static cl::opt<std::string>
TestChanged("test-changed", cl::Hidden, cl::init(""),
cl::desc("exe called with module IR after each pass that "
"changes it"));

namespace {

// Ensure temporary files exist, creating or re-using them. \p FD contains
// file descriptors (-1 indicates that the file should be created) and
// \p SR contains the corresponding initial content. \p FileName will have
// the filenames filled in when creating files. Return any error message
// or "" if none.
std::string prepareTempFiles(SmallVector<int> &FD, ArrayRef<StringRef> SR,
SmallVector<std::string> &FileName) {
assert(FD.size() >= SR.size() && FileName.size() == FD.size() &&
"Unexpected array sizes");
for (unsigned I = 0; I < FD.size(); ++I) {
// Perform a system based diff between \p Before and \p After, using
// \p OldLineFormat, \p NewLineFormat, and \p UnchangedLineFormat
// to control the formatting of the output. Return an error message
// for any failures instead of the diff.
std::string doSystemDiff(StringRef Before, StringRef After,
StringRef OldLineFormat, StringRef NewLineFormat,
StringRef UnchangedLineFormat) {
StringRef SR[2]{Before, After};
// Store the 2 bodies into temporary files and call diff on them
// to get the body of the node.
const unsigned NumFiles = 3;
static std::string FileName[NumFiles];
static int FD[NumFiles]{-1, -1, -1};
for (unsigned I = 0; I < NumFiles; ++I) {
if (FD[I] == -1) {
SmallVector<char, 200> SV;
std::error_code EC =
Expand All @@ -196,44 +188,19 @@ std::string prepareTempFiles(SmallVector<int> &FD, ArrayRef<StringRef> SR,
return "Unable to create temporary file.";
FileName[I] = Twine(SV).str();
}
// Only the first M files have initial content.
if (I < SR.size()) {
std::error_code EC = sys::fs::openFileForWrite(FileName[I], FD[I]);
if (EC)
return "Unable to open temporary file for writing.";
raw_fd_ostream OutStream(FD[I], /*shouldClose=*/true);
if (FD[I] == -1)
return "Error opening file for writing.";
OutStream << SR[I];
}
}
return "";
}
// The third file is used as the result of the diff.
if (I == NumFiles - 1)
break;

std::string cleanUpTempFiles(ArrayRef<std::string> FileName) {
for (unsigned I = 0; I < FileName.size(); ++I) {
std::error_code EC = sys::fs::remove(FileName[I]);
std::error_code EC = sys::fs::openFileForWrite(FileName[I], FD[I]);
if (EC)
return "Unable to remove temporary file.";
}
return "";
}
return "Unable to open temporary file for writing.";

// Perform a system based diff between \p Before and \p After, using
// \p OldLineFormat, \p NewLineFormat, and \p UnchangedLineFormat
// to control the formatting of the output. Return an error message
// for any failures instead of the diff.
std::string doSystemDiff(StringRef Before, StringRef After,
StringRef OldLineFormat, StringRef NewLineFormat,
StringRef UnchangedLineFormat) {
// Store the 2 bodies into temporary files and call diff on them
// to get the body of the node.
static SmallVector<int> FD{-1, -1, -1};
SmallVector<StringRef> SR{Before, After};
static SmallVector<std::string> FileName{"", "", ""};
std::string Err = prepareTempFiles(FD, SR, FileName);
if (Err != "")
return Err;
raw_fd_ostream OutStream(FD[I], /*shouldClose=*/true);
if (FD[I] == -1)
return "Error opening file for writing.";
OutStream << SR[I];
}

static ErrorOr<std::string> DiffExe = sys::findProgramByName(DiffBinary);
if (!DiffExe)
Expand All @@ -257,10 +224,12 @@ std::string doSystemDiff(StringRef Before, StringRef After,
else
return "Unable to read result.";

Err = cleanUpTempFiles(FileName);
if (Err != "")
return Err;

// Clean up.
for (const std::string &I : FileName) {
std::error_code EC = sys::fs::remove(I);
if (EC)
return "Unable to remove temporary file.";
}
return Diff;
}

Expand Down Expand Up @@ -651,59 +620,6 @@ void IRChangedPrinter::handleAfter(StringRef PassID, std::string &Name,
Out << "*** IR Dump After " << PassID << " on " << Name << " ***\n" << After;
}

IRChangedTester::~IRChangedTester() {}

void IRChangedTester::registerCallbacks(PassInstrumentationCallbacks &PIC) {
if (TestChanged != "")
TextChangeReporter<std::string>::registerRequiredCallbacks(PIC);
}

void IRChangedTester::handleIR(const std::string &S, StringRef PassID) {
// Store the body into a temporary file
static SmallVector<int> FD{-1};
SmallVector<StringRef> SR{S};
static SmallVector<std::string> FileName{""};
std::string Err = prepareTempFiles(FD, SR, FileName);
if (Err != "") {
dbgs() << Err;
return;
}
static ErrorOr<std::string> Exe = sys::findProgramByName(TestChanged);
if (!Exe) {
dbgs() << "Unable to find test-changed executable.";
return;
}

StringRef Args[] = {TestChanged, FileName[0], PassID};
int Result = sys::ExecuteAndWait(*Exe, Args);
if (Result < 0) {
dbgs() << "Error executing test-changed executable.";
return;
}

Err = cleanUpTempFiles(FileName);
if (Err != "")
dbgs() << Err;
}

void IRChangedTester::handleInitialIR(Any IR) {
// Always test the initial module.
// Unwrap and print directly to avoid filtering problems in general routines.
std::string S;
generateIRRepresentation(IR, "Initial IR", S);
handleIR(S, "Initial IR");
}

void IRChangedTester::omitAfter(StringRef PassID, std::string &Name) {}
void IRChangedTester::handleInvalidated(StringRef PassID) {}
void IRChangedTester::handleFiltered(StringRef PassID, std::string &Name) {}
void IRChangedTester::handleIgnored(StringRef PassID, std::string &Name) {}
void IRChangedTester::handleAfter(StringRef PassID, std::string &Name,
const std::string &Before,
const std::string &After, Any) {
handleIR(After, PassID);
}

template <typename T>
void OrderedChangedData<T>::report(
const OrderedChangedData &Before, const OrderedChangedData &After,
Expand Down Expand Up @@ -2216,7 +2132,6 @@ void StandardInstrumentations::registerCallbacks(
Verify.registerCallbacks(PIC);
PrintChangedDiff.registerCallbacks(PIC);
WebsiteChangeReporter.registerCallbacks(PIC);
ChangeTester.registerCallbacks(PIC);
}

template class ChangeReporter<std::string>;
Expand Down
4 changes: 0 additions & 4 deletions llvm/test/Other/test-changed-script.sh

This file was deleted.

103 changes: 0 additions & 103 deletions llvm/test/Other/test-changed.ll

This file was deleted.

0 comments on commit c4ce426

Please sign in to comment.