diff options
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/bugpoint/BugDriver.cpp | 18 | ||||
-rw-r--r-- | llvm/tools/bugpoint/BugDriver.h | 37 | ||||
-rw-r--r-- | llvm/tools/bugpoint/CrashDebugger.cpp | 124 | ||||
-rw-r--r-- | llvm/tools/bugpoint/ExecutionDriver.cpp | 57 | ||||
-rw-r--r-- | llvm/tools/bugpoint/ExtractFunction.cpp | 64 | ||||
-rw-r--r-- | llvm/tools/bugpoint/Miscompilation.cpp | 40 | ||||
-rw-r--r-- | llvm/tools/bugpoint/OptimizerDriver.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/bugpoint/ToolRunner.cpp | 32 | ||||
-rw-r--r-- | llvm/tools/bugpoint/bugpoint.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 5 |
10 files changed, 180 insertions, 201 deletions
diff --git a/llvm/tools/bugpoint/BugDriver.cpp b/llvm/tools/bugpoint/BugDriver.cpp index 2bdfebe..a7e93f6 100644 --- a/llvm/tools/bugpoint/BugDriver.cpp +++ b/llvm/tools/bugpoint/BugDriver.cpp @@ -27,9 +27,7 @@ #include <memory> using namespace llvm; -namespace llvm { -Triple TargetTriple; -} +Triple llvm::TargetTriple; DiscardTemp::~DiscardTemp() { if (SaveTemps) { @@ -41,18 +39,14 @@ DiscardTemp::~DiscardTemp() { errs() << "Failed to delete temp file " << toString(std::move(E)) << '\n'; } -// Anonymous namespace to define command line options for debugging. -// -namespace { // Output - The user can specify a file containing the expected output of the // program. If this filename is set, it is used as the reference diff source, // otherwise the raw input run through an interpreter is used as the reference // source. // -cl::opt<std::string> OutputFile("output", - cl::desc("Specify a reference program output " - "(for miscompilation detection)")); -} +static cl::opt<std::string> + OutputFile("output", cl::desc("Specify a reference program output " + "(for miscompilation detection)")); /// If we reduce or update the program somehow, call this method to update /// bugdriver with it. This deletes the old module and sets the specified one @@ -238,7 +232,7 @@ Error BugDriver::run() { return Error::success(); } -void llvm::PrintFunctionList(const std::vector<Function *> &Funcs) { +void llvm::printFunctionList(const std::vector<Function *> &Funcs) { unsigned NumPrint = Funcs.size(); if (NumPrint > 10) NumPrint = 10; @@ -249,7 +243,7 @@ void llvm::PrintFunctionList(const std::vector<Function *> &Funcs) { outs().flush(); } -void llvm::PrintGlobalVariableList(const std::vector<GlobalVariable *> &GVs) { +void llvm::printGlobalVariableList(const std::vector<GlobalVariable *> &GVs) { unsigned NumPrint = GVs.size(); if (NumPrint > 10) NumPrint = 10; diff --git a/llvm/tools/bugpoint/BugDriver.h b/llvm/tools/bugpoint/BugDriver.h index e3117ec..ca57405 100644 --- a/llvm/tools/bugpoint/BugDriver.h +++ b/llvm/tools/bugpoint/BugDriver.h @@ -57,7 +57,6 @@ class BugDriver { // FIXME: sort out public/private distinctions... friend class ReducePassList; - friend class ReduceMisCodegenFunctions; public: BugDriver(const char *toolname, bool find_bugs, unsigned timeout, @@ -76,7 +75,7 @@ public: void setPassesToRun(const std::vector<std::string> &PTR) { PassesToRun = PTR; } - const std::vector<std::string> &getPassesToRun() const { return PassesToRun; } + ArrayRef<std::string> getPassesToRun() const { return PassesToRun; } /// run - The top level method that is invoked after all of the instance /// variables are set up from command line arguments. The \p as_child argument @@ -111,7 +110,6 @@ public: Error debugCodeGenerator(); /// isExecutingJIT - Returns true if bugpoint is currently testing the JIT - /// bool isExecutingJIT(); Module &getProgram() const { return *Program; } @@ -167,7 +165,7 @@ public: bool RemoveBitcode = false) const; /// This function is used to output M to a file named "bugpoint-ID.bc". - void EmitProgressBitcode(const Module &M, const std::string &ID, + void emitProgressBitcode(const Module &M, const std::string &ID, bool NoFlyer = false) const; /// This method clones the current Program and deletes the specified @@ -214,7 +212,6 @@ public: /// outs() a single line message indicating whether compilation was successful /// or failed, unless Quiet is set. ExtraArgs specifies additional arguments /// to pass to the child bugpoint instance. - /// bool runPasses(Module &Program, const std::vector<std::string> &PassesToRun, std::string &OutputFilename, bool DeleteOutput = false, bool Quiet = false, @@ -223,7 +220,6 @@ public: /// runPasses - Just like the method above, but this just returns true or /// false indicating whether or not the optimizer crashed on the specified /// input (true = crashed). Does not produce any output. - /// bool runPasses(Module &M, const std::vector<std::string> &PassesToRun) const { std::string Filename; return runPasses(M, PassesToRun, Filename, true); @@ -247,7 +243,6 @@ public: private: /// initializeExecutionEnvironment - This method is used to set up the /// environment for executing LLVM programs. - /// Error initializeExecutionEnvironment(); }; @@ -258,37 +253,31 @@ struct DiscardTemp { /// Given a bitcode or assembly input filename, parse and return it, or return /// null if not possible. -/// std::unique_ptr<Module> parseInputFile(StringRef InputFilename, LLVMContext &ctxt); /// getPassesString - Turn a list of passes into a string which indicates the /// command line options that must be passed to add the passes. -/// std::string getPassesString(const std::vector<std::string> &Passes); -/// PrintFunctionList - prints out list of problematic functions -/// -void PrintFunctionList(const std::vector<Function *> &Funcs); +/// Prints out list of problematic functions +void printFunctionList(const std::vector<Function *> &Funcs); -/// PrintGlobalVariableList - prints out list of problematic global variables -/// -void PrintGlobalVariableList(const std::vector<GlobalVariable *> &GVs); +/// Prints out list of problematic global variables +void printGlobalVariableList(const std::vector<GlobalVariable *> &GVs); -// DeleteGlobalInitializer - "Remove" the global variable by deleting its -// initializer, making it external. -// -void DeleteGlobalInitializer(GlobalVariable *GV); +/// "Remove" the global variable by deleting its initializer, making it +/// external. +void deleteGlobalInitializer(GlobalVariable *GV); -// DeleteFunctionBody - "Remove" the function by deleting all of it's basic -// blocks, making it external. -// -void DeleteFunctionBody(Function *F); +/// "Remove" the function by deleting all of it's basic blocks, making it +/// external. +void deleteFunctionBody(Function *F); /// Given a module and a list of functions in the module, split the functions /// OUT of the specified module, and place them in the new module. std::unique_ptr<Module> -SplitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, +splitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, ValueToValueMapTy &VMap); } // End llvm namespace diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp index fcac014..240300b 100644 --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -36,39 +36,44 @@ #include <set> using namespace llvm; -namespace { -cl::opt<bool> KeepMain("keep-main", - cl::desc("Force function reduction to keep main"), - cl::init(false)); -cl::opt<bool> NoGlobalRM("disable-global-remove", - cl::desc("Do not remove global variables"), - cl::init(false)); - -cl::opt<bool> NoAttributeRM("disable-attribute-remove", - cl::desc("Do not remove function attributes"), - cl::init(false)); - -cl::opt<bool> ReplaceFuncsWithNull( +static cl::opt<bool> KeepMain("keep-main", + cl::desc("Force function reduction to keep main"), + cl::init(false)); +static cl::opt<bool> NoGlobalRM("disable-global-remove", + cl::desc("Do not remove global variables"), + cl::init(false)); + +static cl::opt<bool> + NoAttributeRM("disable-attribute-remove", + cl::desc("Do not remove function attributes"), + cl::init(false)); + +static cl::opt<bool> ReplaceFuncsWithNull( "replace-funcs-with-null", cl::desc("When stubbing functions, replace all uses will null"), cl::init(false)); -cl::opt<bool> DontReducePassList("disable-pass-list-reduction", - cl::desc("Skip pass list reduction steps"), - cl::init(false)); - -cl::opt<bool> NoNamedMDRM("disable-namedmd-remove", - cl::desc("Do not remove global named metadata"), - cl::init(false)); -cl::opt<bool> NoStripDebugInfo("disable-strip-debuginfo", - cl::desc("Do not strip debug info metadata"), - cl::init(false)); -cl::opt<bool> NoStripDebugTypeInfo("disable-strip-debug-types", - cl::desc("Do not strip debug type info metadata"), - cl::init(false)); -cl::opt<bool> VerboseErrors("verbose-errors", - cl::desc("Print the output of crashing program"), - cl::init(false)); -} + +static cl::opt<bool> + DontReducePassList("disable-pass-list-reduction", + cl::desc("Skip pass list reduction steps"), + cl::init(false)); + +static cl::opt<bool> + NoNamedMDRM("disable-namedmd-remove", + cl::desc("Do not remove global named metadata"), + cl::init(false)); +static cl::opt<bool> + NoStripDebugInfo("disable-strip-debuginfo", + cl::desc("Do not strip debug info metadata"), + cl::init(false)); +static cl::opt<bool> + NoStripDebugTypeInfo("disable-strip-debug-types", + cl::desc("Do not strip debug type info metadata"), + cl::init(false)); +static cl::opt<bool> + VerboseErrors("verbose-errors", + cl::desc("Print the output of crashing program"), + cl::init(false)); static bool isValidModule(std::unique_ptr<Module> &M, bool ExitOnFailure = true) { @@ -83,6 +88,8 @@ static bool isValidModule(std::unique_ptr<Module> &M, } namespace llvm { +// Note this class needs to be in llvm namespace since its declared as a friend +// of BugDriver. class ReducePassList : public ListReducer<std::string> { BugDriver &BD; @@ -95,7 +102,7 @@ public: Expected<TestResult> doTest(std::vector<std::string> &Removed, std::vector<std::string> &Kept) override; }; -} +} // namespace llvm Expected<ReducePassList::TestResult> ReducePassList::doTest(std::vector<std::string> &Prefix, @@ -156,7 +163,7 @@ public: bool TestGlobalVariables(std::vector<GlobalVariable *> &GVs); }; -} +} // namespace bool ReduceCrashingGlobalInitializers::TestGlobalVariables( std::vector<GlobalVariable *> &GVs) { @@ -174,14 +181,14 @@ bool ReduceCrashingGlobalInitializers::TestGlobalVariables( } outs() << "Checking for crash with only these global variables: "; - PrintGlobalVariableList(GVs); + printGlobalVariableList(GVs); outs() << ": "; // Loop over and delete any global variables which we aren't supposed to be // playing with... for (GlobalVariable &I : M->globals()) if (I.hasInitializer() && !GVSet.count(&I)) { - DeleteGlobalInitializer(&I); + deleteGlobalInitializer(&I); I.setLinkage(GlobalValue::ExternalLinkage); I.setComdat(nullptr); } @@ -223,7 +230,7 @@ public: bool TestFuncs(std::vector<Function *> &Prefix); }; -} +} // namespace static void RemoveFunctionReferences(Module *M, const char *Name) { auto *UsedVar = M->getGlobalVariable(Name, true); @@ -269,14 +276,14 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector<Function *> &Funcs) { } outs() << "Checking for crash with only these functions: "; - PrintFunctionList(Funcs); + printFunctionList(Funcs); outs() << ": "; if (!ReplaceFuncsWithNull) { // Loop over and delete any functions which we aren't supposed to be playing // with... for (Function &I : *M) if (!I.isDeclaration() && !Functions.count(&I)) - DeleteFunctionBody(&I); + deleteFunctionBody(&I); } else { std::vector<GlobalValue *> ToRemove; // First, remove aliases to functions we're about to purge. @@ -356,7 +363,7 @@ public: bool TestFuncAttrs(std::vector<Attribute> &Attrs); }; -} +} // namespace bool ReduceCrashingFunctionAttributes::TestFuncAttrs( std::vector<Attribute> &Attrs) { @@ -396,12 +403,11 @@ bool ReduceCrashingFunctionAttributes::TestFuncAttrs( return false; } -namespace { /// Simplify the CFG without completely destroying it. /// This is not well defined, but basically comes down to "try to eliminate /// unreachable blocks and constant fold terminators without deciding that /// certain undefined behavior cuts off the program at the legs". -void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { +static void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { if (F.empty()) return; @@ -435,6 +441,8 @@ void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { for (auto *BB : Unreachable) BB->eraseFromParent(); } + +namespace { /// ReduceCrashingBlocks reducer - This works by setting the terminators of /// all terminators except the specified basic blocks to a 'ret' instruction, /// then running the simplifycfg pass. This has the effect of chopping up @@ -459,7 +467,7 @@ public: bool TestBlocks(std::vector<const BasicBlock *> &Prefix); }; -} +} // namespace bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... @@ -571,7 +579,7 @@ public: bool TestBlocks(std::vector<const BasicBlock *> &Prefix); }; -} +} // namespace bool ReduceCrashingConditionals::TestBlocks( std::vector<const BasicBlock *> &BBs) { @@ -670,7 +678,7 @@ public: bool TestBlocks(std::vector<const BasicBlock *> &Prefix); }; -} +} // namespace bool ReduceSimplifyCFG::TestBlocks(std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... @@ -755,7 +763,7 @@ public: bool TestInsts(std::vector<const Instruction *> &Prefix); }; -} +} // namespace bool ReduceCrashingInstructions::TestInsts( std::vector<const Instruction *> &Insts) { @@ -896,7 +904,7 @@ public: bool TestNamedMDs(std::vector<std::string> &NamedMDs); }; -} +} // namespace bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) { @@ -959,7 +967,7 @@ public: bool TestNamedMDOps(std::vector<const MDNode *> &NamedMDOps); }; -} +} // namespace bool ReduceCrashingNamedMDOps::TestNamedMDOps( std::vector<const MDNode *> &NamedMDOps) { @@ -1018,7 +1026,7 @@ static Error ReduceGlobalInitializers(BugDriver &BD, BugTester TestFn) { for (GlobalVariable &GV : M->globals()) { if (GV.hasInitializer()) { - DeleteGlobalInitializer(&GV); + deleteGlobalInitializer(&GV); GV.setLinkage(GlobalValue::ExternalLinkage); GV.setComdat(nullptr); DeletedInit = true; @@ -1056,7 +1064,7 @@ static Error ReduceGlobalInitializers(BugDriver &BD, BugTester TestFn) { return E; if (GVs.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-global-variables"); } return Error::success(); } @@ -1155,7 +1163,7 @@ static Error ReduceInsts(BugDriver &BD, BugTester TestFn) { return E; } - BD.EmitProgressBitcode(BD.getProgram(), "reduced-instructions"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-instructions"); return Error::success(); } @@ -1186,7 +1194,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { return E; if (Functions.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-function"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-function"); } if (!NoAttributeRM) { @@ -1218,7 +1226,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { } if (OldSize < NewSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-function-attributes"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-function-attributes"); } } @@ -1238,7 +1246,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; if (Blocks.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-conditionals"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-conditionals"); } // Attempt to delete entire basic blocks at a time to speed up @@ -1256,7 +1264,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; if (Blocks.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-blocks"); } if (!DisableSimplifyCFG && !BugpointIsInterrupted) { @@ -1269,7 +1277,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; if (Blocks.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplifycfg"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-simplifycfg"); } // Attempt to delete instructions using bisection. This should help out nasty @@ -1319,7 +1327,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; } - BD.EmitProgressBitcode(BD.getProgram(), "reduced-named-md"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-named-md"); } // Try to clean up the testcase by running funcresolve and globaldce... @@ -1334,7 +1342,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { std::move(M)); // Yup, it does, keep the reduced version... } - BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplified"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-simplified"); return Error::success(); } @@ -1361,7 +1369,7 @@ Error BugDriver::debugOptimizerCrash(const std::string &ID) { << (PassesToRun.size() == 1 ? ": " : "es: ") << getPassesString(PassesToRun) << '\n'; - EmitProgressBitcode(*Program, ID); + emitProgressBitcode(*Program, ID); auto Res = DebugACrash(*this, TestForOptimizerCrash); if (Res || DontReducePassList) @@ -1376,7 +1384,7 @@ Error BugDriver::debugOptimizerCrash(const std::string &ID) { << (PassesToRun.size() == 1 ? ": " : "es: ") << getPassesString(PassesToRun) << '\n'; - EmitProgressBitcode(getProgram(), "reduced-simplified"); + emitProgressBitcode(getProgram(), "reduced-simplified"); return Res; } diff --git a/llvm/tools/bugpoint/ExecutionDriver.cpp b/llvm/tools/bugpoint/ExecutionDriver.cpp index 165b55f..8c6b7fb 100644 --- a/llvm/tools/bugpoint/ExecutionDriver.cpp +++ b/llvm/tools/bugpoint/ExecutionDriver.cpp @@ -36,15 +36,16 @@ enum OutputType { CompileCustom, Custom }; +} // namespace -cl::opt<double> AbsTolerance("abs-tolerance", - cl::desc("Absolute error tolerated"), - cl::init(0.0)); -cl::opt<double> RelTolerance("rel-tolerance", - cl::desc("Relative error tolerated"), - cl::init(0.0)); +static cl::opt<double> AbsTolerance("abs-tolerance", + cl::desc("Absolute error tolerated"), + cl::init(0.0)); +static cl::opt<double> RelTolerance("rel-tolerance", + cl::desc("Relative error tolerated"), + cl::init(0.0)); -cl::opt<OutputType> InterpreterSel( +static cl::opt<OutputType> InterpreterSel( cl::desc("Specify the \"test\" i.e. suspect back-end:"), cl::values(clEnumValN(AutoPick, "auto", "Use best guess"), clEnumValN(RunLLI, "run-int", "Execute with the interpreter"), @@ -60,7 +61,7 @@ cl::opt<OutputType> InterpreterSel( "the bitcode. Useful for cross-compilation.")), cl::init(AutoPick)); -cl::opt<OutputType> SafeInterpreterSel( +static cl::opt<OutputType> SafeInterpreterSel( cl::desc("Specify \"safe\" i.e. known-good backend:"), cl::values(clEnumValN(AutoPick, "safe-auto", "Use best guess"), clEnumValN(RunLLC, "safe-run-llc", "Compile with LLC"), @@ -69,16 +70,16 @@ cl::opt<OutputType> SafeInterpreterSel( "the bitcode. Useful for cross-compilation.")), cl::init(AutoPick)); -cl::opt<std::string> SafeInterpreterPath( +static cl::opt<std::string> SafeInterpreterPath( "safe-path", cl::desc("Specify the path to the \"safe\" backend program"), cl::init("")); -cl::opt<bool> AppendProgramExitCode( +static cl::opt<bool> AppendProgramExitCode( "append-exit-code", cl::desc("Append the exit code to the output so it gets diff'd too"), cl::init(false)); -cl::opt<std::string> +static cl::opt<std::string> InputFile("input", cl::init("/dev/null"), cl::desc("Filename to pipe in as stdin (default: /dev/null)")); @@ -89,20 +90,19 @@ static cl::list<std::string> static cl::list<std::string> AdditionalLinkerArgs( "Xlinker", cl::desc("Additional arguments to pass to the linker")); -cl::opt<std::string> CustomCompileCommand( +static cl::opt<std::string> CustomCompileCommand( "compile-command", cl::init("llc"), cl::desc("Command to compile the bitcode (use with -compile-custom) " "(default: llc)")); -cl::opt<std::string> CustomExecCommand( +static cl::opt<std::string> CustomExecCommand( "exec-command", cl::init("simulate"), cl::desc("Command to execute the bitcode (use with -run-custom) " "(default: simulate)")); -} -namespace llvm { // Anything specified after the --args option are taken as arguments to the // program being debugged. +namespace llvm { cl::list<std::string> InputArgv("args", cl::Positional, cl::desc("<program arguments>..."), cl::PositionalEatsArgs); @@ -110,25 +110,22 @@ cl::list<std::string> InputArgv("args", cl::Positional, cl::opt<std::string> OutputPrefix("output-prefix", cl::init("bugpoint"), cl::desc("Prefix to use for outputs (default: 'bugpoint')")); -} - -namespace { -cl::list<std::string> ToolArgv("tool-args", cl::Positional, - cl::desc("<tool arguments>..."), - cl::PositionalEatsArgs); +} // namespace llvm -cl::list<std::string> SafeToolArgv("safe-tool-args", cl::Positional, - cl::desc("<safe-tool arguments>..."), - cl::PositionalEatsArgs); +static cl::list<std::string> ToolArgv("tool-args", cl::Positional, + cl::desc("<tool arguments>..."), + cl::PositionalEatsArgs); -cl::opt<std::string> CCBinary("gcc", cl::init(""), - cl::desc("The gcc binary to use.")); +static cl::list<std::string> SafeToolArgv("safe-tool-args", cl::Positional, + cl::desc("<safe-tool arguments>..."), + cl::PositionalEatsArgs); -cl::list<std::string> CCToolArgv("gcc-tool-args", cl::Positional, - cl::desc("<gcc-tool arguments>..."), - cl::PositionalEatsArgs); -} +static cl::opt<std::string> CCBinary("gcc", cl::init(""), + cl::desc("The gcc binary to use.")); +static cl::list<std::string> CCToolArgv("gcc-tool-args", cl::Positional, + cl::desc("<gcc-tool arguments>..."), + cl::PositionalEatsArgs); //===----------------------------------------------------------------------===// // BugDriver method implementation // diff --git a/llvm/tools/bugpoint/ExtractFunction.cpp b/llvm/tools/bugpoint/ExtractFunction.cpp index dd9a82c..3206589 100644 --- a/llvm/tools/bugpoint/ExtractFunction.cpp +++ b/llvm/tools/bugpoint/ExtractFunction.cpp @@ -35,19 +35,19 @@ using namespace llvm; #define DEBUG_TYPE "bugpoint" +bool llvm::DisableSimplifyCFG = false; namespace llvm { -bool DisableSimplifyCFG = false; extern cl::opt<std::string> OutputPrefix; -} // End llvm namespace +} // namespace llvm -namespace { -cl::opt<bool> NoDCE("disable-dce", - cl::desc("Do not use the -dce pass to reduce testcases")); -cl::opt<bool, true> +static cl::opt<bool> + NoDCE("disable-dce", + cl::desc("Do not use the -dce pass to reduce testcases")); +static cl::opt<bool, true> NoSCFG("disable-simplifycfg", cl::location(DisableSimplifyCFG), cl::desc("Do not use the -simplifycfg pass to reduce testcases")); -Function *globalInitUsesExternalBA(GlobalVariable *GV) { +static Function *globalInitUsesExternalBA(GlobalVariable *GV) { if (!GV->hasInitializer()) return nullptr; @@ -78,7 +78,6 @@ Function *globalInitUsesExternalBA(GlobalVariable *GV) { } return nullptr; } -} // end anonymous namespace std::unique_ptr<Module> BugDriver::deleteInstructionFromProgram(const Instruction *I, @@ -154,7 +153,7 @@ std::unique_ptr<Module> BugDriver::extractLoop(Module *M) { std::unique_ptr<Module> NewM = runPassesOn(M, LoopExtractPasses); if (!NewM) { outs() << "*** Loop extraction failed: "; - EmitProgressBitcode(*M, "loopextraction", true); + emitProgressBitcode(*M, "loopextraction", true); outs() << "*** Sorry. :( Please report a bug!\n"; return nullptr; } @@ -198,21 +197,16 @@ static void eliminateAliases(GlobalValue *GV) { } } -// -// DeleteGlobalInitializer - "Remove" the global variable by deleting its -// initializer, -// making it external. -// -void llvm::DeleteGlobalInitializer(GlobalVariable *GV) { +// "Remove" the global variable by deleting its initializer, making it external. +void llvm::deleteGlobalInitializer(GlobalVariable *GV) { eliminateAliases(GV); GV->setInitializer(nullptr); GV->setComdat(nullptr); } -// DeleteFunctionBody - "Remove" the function by deleting all of its basic -// blocks, making it external. -// -void llvm::DeleteFunctionBody(Function *F) { +// "Remove" the function by deleting all of its basic blocks, making it +// external. +void llvm::deleteFunctionBody(Function *F) { eliminateAliases(F); // Function declarations can't have comdats. F->setComdat(nullptr); @@ -222,9 +216,9 @@ void llvm::DeleteFunctionBody(Function *F) { assert(F->isDeclaration() && "This didn't make the function external!"); } -/// GetTorInit - Given a list of entries for static ctors/dtors, return them +/// getTorInit - Given a list of entries for static ctors/dtors, return them /// as a constant array. -static Constant *GetTorInit(std::vector<std::pair<Function *, int>> &TorList) { +static Constant *getTorInit(std::vector<std::pair<Function *, int>> &TorList) { assert(!TorList.empty() && "Don't create empty tor list!"); std::vector<Constant *> ArrayElts; Type *Int32Ty = Type::getInt32Ty(TorList[0].first->getContext()); @@ -239,11 +233,11 @@ static Constant *GetTorInit(std::vector<std::pair<Function *, int>> &TorList) { ArrayType::get(ArrayElts[0]->getType(), ArrayElts.size()), ArrayElts); } -/// SplitStaticCtorDtor - A module was recently split into two parts, M1/M2, and +/// splitStaticCtorDtor - A module was recently split into two parts, M1/M2, and /// M1 has all of the global variables. If M2 contains any functions that are /// static ctors/dtors, we need to add an llvm.global_[cd]tors global to M2, and /// prune appropriate entries out of M1s list. -static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, +static void splitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, ValueToValueMapTy &VMap) { GlobalVariable *GV = M1->getNamedGlobal(GlobalName); if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() || !GV->use_empty()) @@ -284,7 +278,7 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, GV->eraseFromParent(); if (!M1Tors.empty()) { - Constant *M1Init = GetTorInit(M1Tors); + Constant *M1Init = getTorInit(M1Tors); new GlobalVariable(*M1, M1Init->getType(), false, GlobalValue::AppendingLinkage, M1Init, GlobalName); } @@ -295,14 +289,14 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, GV->eraseFromParent(); if (!M2Tors.empty()) { - Constant *M2Init = GetTorInit(M2Tors); + Constant *M2Init = getTorInit(M2Tors); new GlobalVariable(*M2, M2Init->getType(), false, GlobalValue::AppendingLinkage, M2Init, GlobalName); } } std::unique_ptr<Module> -llvm::SplitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, +llvm::splitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, ValueToValueMapTy &VMap) { // Make sure functions & globals are all external so that linkage // between the two modules will work. @@ -326,13 +320,13 @@ llvm::SplitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, LLVM_DEBUG(TNOF->printAsOperand(errs(), false)); LLVM_DEBUG(errs() << "\n"); TestFunctions.insert(cast<Function>(NewVMap[TNOF])); - DeleteFunctionBody(TNOF); // Function is now external in this module! + deleteFunctionBody(TNOF); // Function is now external in this module! } // Remove the Safe functions from the Test module for (Function &I : *New) if (!TestFunctions.count(&I)) - DeleteFunctionBody(&I); + deleteFunctionBody(&I); // Try to split the global initializers evenly for (GlobalVariable &I : M->globals()) { @@ -348,17 +342,17 @@ llvm::SplitFunctionsOutOfModule(Module *M, const std::vector<Function *> &F, << TestFn->getName() << "'.\n"; exit(1); } - DeleteGlobalInitializer(&I); // Delete the initializer to make it external + deleteGlobalInitializer(&I); // Delete the initializer to make it external } else { // If we keep it in the safe module, then delete it in the test module - DeleteGlobalInitializer(GV); + deleteGlobalInitializer(GV); } } // Make sure that there is a global ctor/dtor array in both halves of the // module if they both have static ctor/dtor functions. - SplitStaticCtorDtor("llvm.global_ctors", M, New.get(), NewVMap); - SplitStaticCtorDtor("llvm.global_dtors", M, New.get(), NewVMap); + splitStaticCtorDtor("llvm.global_ctors", M, New.get(), NewVMap); + splitStaticCtorDtor("llvm.global_dtors", M, New.get(), NewVMap); return New; } @@ -375,7 +369,7 @@ BugDriver::extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs, outs() << "*** Basic Block extraction failed!\n"; errs() << "Error creating temporary file: " << toString(Temp.takeError()) << "\n"; - EmitProgressBitcode(*M, "basicblockextractfail", true); + emitProgressBitcode(*M, "basicblockextractfail", true); return nullptr; } DiscardTemp Discard{*Temp}; @@ -399,7 +393,7 @@ BugDriver::extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs, OS.flush(); if (OS.has_error()) { errs() << "Error writing list of blocks to not extract\n"; - EmitProgressBitcode(*M, "basicblockextractfail", true); + emitProgressBitcode(*M, "basicblockextractfail", true); OS.clear_error(); return nullptr; } @@ -413,7 +407,7 @@ BugDriver::extractMappedBlocksFromModule(const std::vector<BasicBlock *> &BBs, if (!Ret) { outs() << "*** Basic Block extraction failed, please report a bug!\n"; - EmitProgressBitcode(*M, "basicblockextractfail", true); + emitProgressBitcode(*M, "basicblockextractfail", true); } return Ret; } diff --git a/llvm/tools/bugpoint/Miscompilation.cpp b/llvm/tools/bugpoint/Miscompilation.cpp index 4cf7de3..a7f1643 100644 --- a/llvm/tools/bugpoint/Miscompilation.cpp +++ b/llvm/tools/bugpoint/Miscompilation.cpp @@ -33,16 +33,16 @@ extern cl::opt<std::string> OutputPrefix; extern cl::list<std::string> InputArgv; } // end namespace llvm -namespace { -static llvm::cl::opt<bool> DisableLoopExtraction( +static cl::opt<bool> DisableLoopExtraction( "disable-loop-extraction", cl::desc("Don't extract loops when searching for miscompilations"), cl::init(false)); -static llvm::cl::opt<bool> DisableBlockExtraction( +static cl::opt<bool> DisableBlockExtraction( "disable-block-extraction", cl::desc("Don't extract blocks when searching for miscompilations"), cl::init(false)); +namespace { class ReduceMiscompilingPasses : public ListReducer<std::string> { BugDriver &BD; @@ -71,7 +71,7 @@ ReduceMiscompilingPasses::doTest(std::vector<std::string> &Prefix, errs() << " Error running this sequence of passes" << " on the input program!\n"; BD.setPassesToRun(Suffix); - BD.EmitProgressBitcode(BD.getProgram(), "pass-error", false); + BD.emitProgressBitcode(BD.getProgram(), "pass-error", false); // TODO: This should propagate the error instead of exiting. if (Error E = BD.debugOptimizerCrash()) exit(1); @@ -113,7 +113,7 @@ ReduceMiscompilingPasses::doTest(std::vector<std::string> &Prefix, errs() << " Error running this sequence of passes" << " on the input program!\n"; BD.setPassesToRun(Prefix); - BD.EmitProgressBitcode(BD.getProgram(), "pass-error", false); + BD.emitProgressBitcode(BD.getProgram(), "pass-error", false); // TODO: This should propagate the error instead of exiting. if (Error E = BD.debugOptimizerCrash()) exit(1); @@ -158,7 +158,7 @@ ReduceMiscompilingPasses::doTest(std::vector<std::string> &Prefix, errs() << " Error running this sequence of passes" << " on the input program!\n"; BD.setPassesToRun(Suffix); - BD.EmitProgressBitcode(BD.getProgram(), "pass-error", false); + BD.emitProgressBitcode(BD.getProgram(), "pass-error", false); // TODO: This should propagate the error instead of exiting. if (Error E = BD.debugOptimizerCrash()) exit(1); @@ -253,7 +253,7 @@ ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function *> &Funcs) { << (Funcs.size() == 1 ? "this function is" : "these functions are") << " run through the pass" << (BD.getPassesToRun().size() == 1 ? "" : "es") << ":"; - PrintFunctionList(Funcs); + printFunctionList(Funcs); outs() << '\n'; // Create a clone for two reasons: @@ -277,7 +277,7 @@ ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function *> &Funcs) { VMap.clear(); std::unique_ptr<Module> ToNotOptimize = CloneModule(BD.getProgram(), VMap); std::unique_ptr<Module> ToOptimize = - SplitFunctionsOutOfModule(ToNotOptimize.get(), FuncsOnClone, VMap); + splitFunctionsOutOfModule(ToNotOptimize.get(), FuncsOnClone, VMap); Expected<bool> Broken = TestFn(BD, std::move(ToOptimize), std::move(ToNotOptimize)); @@ -314,7 +314,7 @@ ExtractLoops(BugDriver &BD, ValueToValueMapTy VMap; std::unique_ptr<Module> ToNotOptimize = CloneModule(BD.getProgram(), VMap); - std::unique_ptr<Module> ToOptimize = SplitFunctionsOutOfModule( + std::unique_ptr<Module> ToOptimize = splitFunctionsOutOfModule( ToNotOptimize.get(), MiscompiledFunctions, VMap); std::unique_ptr<Module> ToOptimizeLoopExtracted = BD.extractLoop(ToOptimize.get()); @@ -517,7 +517,7 @@ ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock *> &BBs) { std::unique_ptr<Module> ToNotOptimize = CloneModule(BD.getProgram(), VMap); std::unique_ptr<Module> ToOptimize = - SplitFunctionsOutOfModule(ToNotOptimize.get(), FuncsOnClone, VMap); + splitFunctionsOutOfModule(ToNotOptimize.get(), FuncsOnClone, VMap); // Try the extraction. If it doesn't work, then the block extractor crashed // or something, in which case bugpoint can't chase down this possibility. @@ -572,7 +572,7 @@ ExtractBlocks(BugDriver &BD, ValueToValueMapTy VMap; std::unique_ptr<Module> ProgClone = CloneModule(BD.getProgram(), VMap); std::unique_ptr<Module> ToExtract = - SplitFunctionsOutOfModule(ProgClone.get(), MiscompiledFunctions, VMap); + splitFunctionsOutOfModule(ProgClone.get(), MiscompiledFunctions, VMap); std::unique_ptr<Module> Extracted = BD.extractMappedBlocksFromModule(Blocks, ToExtract.get()); if (!Extracted) { @@ -638,7 +638,7 @@ static Expected<std::vector<Function *>> DebugAMiscompilation( outs() << "\n*** The following function" << (MiscompiledFunctions.size() == 1 ? " is" : "s are") << " being miscompiled: "; - PrintFunctionList(MiscompiledFunctions); + printFunctionList(MiscompiledFunctions); outs() << '\n'; // See if we can rip any loops out of the miscompiled functions and still @@ -663,7 +663,7 @@ static Expected<std::vector<Function *>> DebugAMiscompilation( outs() << "\n*** The following function" << (MiscompiledFunctions.size() == 1 ? " is" : "s are") << " being miscompiled: "; - PrintFunctionList(MiscompiledFunctions); + printFunctionList(MiscompiledFunctions); outs() << '\n'; } } @@ -686,7 +686,7 @@ static Expected<std::vector<Function *>> DebugAMiscompilation( outs() << "\n*** The following function" << (MiscompiledFunctions.size() == 1 ? " is" : "s are") << " being miscompiled: "; - PrintFunctionList(MiscompiledFunctions); + printFunctionList(MiscompiledFunctions); outs() << '\n'; } } @@ -708,7 +708,7 @@ static Expected<bool> TestOptimizer(BugDriver &BD, std::unique_ptr<Module> Test, if (!Optimized) { errs() << " Error running this sequence of passes" << " on the input program!\n"; - BD.EmitProgressBitcode(*Test, "pass-error", false); + BD.emitProgressBitcode(*Test, "pass-error", false); BD.setNewProgram(std::move(Test)); if (Error E = BD.debugOptimizerCrash()) return std::move(E); @@ -750,7 +750,7 @@ Error BugDriver::debugMiscompilation() { outs() << "\n*** Found miscompiling pass" << (getPassesToRun().size() == 1 ? "" : "es") << ": " << getPassesString(getPassesToRun()) << '\n'; - EmitProgressBitcode(*Program, "passinput"); + emitProgressBitcode(*Program, "passinput"); Expected<std::vector<Function *>> MiscompiledFunctions = DebugAMiscompilation(*this, TestOptimizer); @@ -762,15 +762,15 @@ Error BugDriver::debugMiscompilation() { ValueToValueMapTy VMap; Module *ToNotOptimize = CloneModule(getProgram(), VMap).release(); Module *ToOptimize = - SplitFunctionsOutOfModule(ToNotOptimize, *MiscompiledFunctions, VMap) + splitFunctionsOutOfModule(ToNotOptimize, *MiscompiledFunctions, VMap) .release(); outs() << " Non-optimized portion: "; - EmitProgressBitcode(*ToNotOptimize, "tonotoptimize", true); + emitProgressBitcode(*ToNotOptimize, "tonotoptimize", true); delete ToNotOptimize; // Delete hacked module. outs() << " Portion that is input to optimizer: "; - EmitProgressBitcode(*ToOptimize, "tooptimize"); + emitProgressBitcode(*ToOptimize, "tooptimize"); delete ToOptimize; // Delete hacked module. return Error::success(); @@ -1028,7 +1028,7 @@ Error BugDriver::debugCodeGenerator() { ValueToValueMapTy VMap; std::unique_ptr<Module> ToNotCodeGen = CloneModule(getProgram(), VMap); std::unique_ptr<Module> ToCodeGen = - SplitFunctionsOutOfModule(ToNotCodeGen.get(), *Funcs, VMap); + splitFunctionsOutOfModule(ToNotCodeGen.get(), *Funcs, VMap); // Condition the modules ToCodeGen = diff --git a/llvm/tools/bugpoint/OptimizerDriver.cpp b/llvm/tools/bugpoint/OptimizerDriver.cpp index 3daacfd..bf2e8c0 100644 --- a/llvm/tools/bugpoint/OptimizerDriver.cpp +++ b/llvm/tools/bugpoint/OptimizerDriver.cpp @@ -82,7 +82,7 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, /// This function is used to output the current Program to a file named /// "bugpoint-ID.bc". -void BugDriver::EmitProgressBitcode(const Module &M, const std::string &ID, +void BugDriver::emitProgressBitcode(const Module &M, const std::string &ID, bool NoFlyer) const { // Output the input to the current pass to a bitcode file, emit a message // telling the user how to reproduce it: opt -foo blah.bc diff --git a/llvm/tools/bugpoint/ToolRunner.cpp b/llvm/tools/bugpoint/ToolRunner.cpp index f2f5966a..c67695f 100644 --- a/llvm/tools/bugpoint/ToolRunner.cpp +++ b/llvm/tools/bugpoint/ToolRunner.cpp @@ -25,29 +25,25 @@ using namespace llvm; #define DEBUG_TYPE "toolrunner" -namespace llvm { -cl::opt<bool> SaveTemps("save-temps", cl::init(false), - cl::desc("Save temporary files")); -} +cl::opt<bool> llvm::SaveTemps("save-temps", cl::init(false), + cl::desc("Save temporary files")); -namespace { -cl::opt<std::string> +static cl::opt<std::string> RemoteClient("remote-client", cl::desc("Remote execution client (rsh/ssh)")); -cl::opt<std::string> RemoteHost("remote-host", - cl::desc("Remote execution (rsh/ssh) host")); +static cl::opt<std::string> + RemoteHost("remote-host", cl::desc("Remote execution (rsh/ssh) host")); -cl::opt<std::string> RemotePort("remote-port", - cl::desc("Remote execution (rsh/ssh) port")); +static cl::opt<std::string> + RemotePort("remote-port", cl::desc("Remote execution (rsh/ssh) port")); -cl::opt<std::string> RemoteUser("remote-user", - cl::desc("Remote execution (rsh/ssh) user id")); +static cl::opt<std::string> + RemoteUser("remote-user", cl::desc("Remote execution (rsh/ssh) user id")); -cl::opt<std::string> +static cl::opt<std::string> RemoteExtra("remote-extra-options", cl::desc("Remote execution (rsh/ssh) extra options")); -} /// RunProgramWithTimeout - This function provides an alternate interface /// to the sys::Program::ExecuteAndWait interface. @@ -160,7 +156,7 @@ public: const std::vector<std::string> &SharedLibs = std::vector<std::string>(), unsigned Timeout = 0, unsigned MemoryLimit = 0) override; }; -} +} // namespace Expected<int> LLI::ExecuteProgram(const std::string &Bitcode, const std::vector<std::string> &Args, @@ -258,7 +254,7 @@ public: inconvertibleErrorCode()); } }; -} +} // namespace Error CustomCompiler::compileProgram(const std::string &Bitcode, unsigned Timeout, unsigned MemoryLimit) { @@ -301,7 +297,7 @@ public: const std::vector<std::string> &SharedLibs = std::vector<std::string>(), unsigned Timeout = 0, unsigned MemoryLimit = 0) override; }; -} +} // namespace Expected<int> CustomExecutor::ExecuteProgram( const std::string &Bitcode, const std::vector<std::string> &Args, @@ -541,7 +537,7 @@ public: const std::vector<std::string> &SharedLibs = std::vector<std::string>(), unsigned Timeout = 0, unsigned MemoryLimit = 0) override; }; -} +} // namespace Expected<int> JIT::ExecuteProgram(const std::string &Bitcode, const std::vector<std::string> &Args, diff --git a/llvm/tools/bugpoint/bugpoint.cpp b/llvm/tools/bugpoint/bugpoint.cpp index 87581e80a..52ed135 100644 --- a/llvm/tools/bugpoint/bugpoint.cpp +++ b/llvm/tools/bugpoint/bugpoint.cpp @@ -90,7 +90,7 @@ public: D.addPass(std::string(PI->getPassArgument())); } }; -} +} // namespace #define HANDLE_EXTENSION(Ext) \ llvm::PassPluginLibraryInfo get##Ext##PluginInfo(); diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 731d648..b7f898f 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -623,8 +623,9 @@ public: }); } - char *prepare(ExecutorAddr Addr, size_t ContentSize) override { - return InProcessMemoryMapper::prepare(Addr - DeltaAddr, ContentSize); + char *prepare(jitlink::LinkGraph &G, ExecutorAddr Addr, + size_t ContentSize) override { + return InProcessMemoryMapper::prepare(G, Addr - DeltaAddr, ContentSize); } void initialize(AllocInfo &AI, OnInitializedFunction OnInitialized) override { |