From ffe695c29915cf8605b2fb807cd083cdcc769d47 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 18 Jul 2017 16:04:19 +0100 Subject: Replace assertions of types on LLVM instructions in the Executor with a pass that checks these assertions. This improves several things. * This pass provides more friendly messages than assertions in that it just emits a warning and carries on checking the rest of the instructions. * The takes the checks outside of the Executor's hot path and so avoids checking the same instruction multiple times. Now each instruction is only checked once just before execution starts. The disadvantage of this approach is the check for invariants we expect to hold have been pulled far away from where we expect them to hold. After discussion with @ccadar and @MartinNowack it was decided we will take this hit to readability for better performance and simpler code in the Executor. --- lib/Module/Passes.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/Module/Passes.h') diff --git a/lib/Module/Passes.h b/lib/Module/Passes.h index 293766c1..2ac57b9b 100644 --- a/lib/Module/Passes.h +++ b/lib/Module/Passes.h @@ -189,6 +189,23 @@ private: llvm::FunctionPass *createScalarizerPass(); #endif +/// InstructionOperandTypeCheckPass - Type checks the types of instruction +/// operands to check that they conform to invariants expected by the Executor. +/// +/// This is a ModulePass because other pass types are not meant to maintain +/// state between calls. +class InstructionOperandTypeCheckPass : public llvm::ModulePass { +private: + bool instructionOperandsConform; + +public: + static char ID; + InstructionOperandTypeCheckPass() + : llvm::ModulePass(ID), instructionOperandsConform(true) {} + // TODO: Add `override` when we switch to C++11 + bool runOnModule(llvm::Module &M); + bool checkPassed() const { return instructionOperandsConform; } +}; } #endif -- cgit 1.4.1