[llvm-commits] [llvm] r122264 - in /llvm/trunk: include/llvm/InitializePasses.h include/llvm/LinkAllPasses.h include/llvm/Transforms/Scalar.h lib/Transforms/Utils/CMakeLists.txt lib/Transforms/Utils/Utils.cpp
Nick Lewycky
nicholas at mxc.ca
Mon Dec 20 19:26:37 PST 2010
Duncan Sands wrote:
> Author: baldrick
> Date: Mon Dec 20 14:54:37 2010
> New Revision: 122264
>
> URL: http://llvm.org/viewvc/llvm-project?rev=122264&view=rev
> Log:
> Add a new convenience pass for testing InstructionSimplify. Previously
> it could only be tested indirectly, via instcombine, gvn or some other
> pass that makes use of InstructionSimplify, which means that testcases
> had to be carefully contrived to dance around any other transformations
> that that pass did.
If you're interested, you could also test it with the unit testing
framework by making calls to SimplifyInstruction. It would look
something like:
TEST(InstructionSimplify, AddTest) {
LLVMContext context;
Argument *A = new Argument(Type::Int64Ty);
Instruction *I = BinaryOperator::CreateNeg(
BinaryOperator::CreateSub(
ConstantInt::get(Type::Int64Ty, -1),
A
)
);
Instruction *J = SimplifyInstruction(I);
EXPECT_EQ(J->getOpcode(), Instruction::Add);
EXPECT_EQ(J->getOperand(0), A);
EXPECT_EQ(J->getOperand(1), ConstantInt::get(Type::Int64Ty), 1));
}
Since the C++ API is bulky, you can also use ParseAssemblyString to
produce a Module from inline .ll, see
unittests/ExecutionEngine/JIT/JITTest.cpp for inspiration.
Nick
>
> Modified:
> llvm/trunk/include/llvm/InitializePasses.h
> llvm/trunk/include/llvm/LinkAllPasses.h
> llvm/trunk/include/llvm/Transforms/Scalar.h
> llvm/trunk/lib/Transforms/Utils/CMakeLists.txt
> llvm/trunk/lib/Transforms/Utils/Utils.cpp
>
> Modified: llvm/trunk/include/llvm/InitializePasses.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=122264&r1=122263&r2=122264&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/InitializePasses.h (original)
> +++ llvm/trunk/include/llvm/InitializePasses.h Mon Dec 20 14:54:37 2010
> @@ -217,6 +217,7 @@
> void initializeUnreachableMachineBlockElimPass(PassRegistry&);
> void initializeVerifierPass(PassRegistry&);
> void initializeVirtRegMapPass(PassRegistry&);
> +void initializeInstSimplifierPass(PassRegistry&);
>
> }
>
>
> Modified: llvm/trunk/include/llvm/LinkAllPasses.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=122264&r1=122263&r2=122264&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/LinkAllPasses.h (original)
> +++ llvm/trunk/include/llvm/LinkAllPasses.h Mon Dec 20 14:54:37 2010
> @@ -147,6 +147,7 @@
> (void) llvm::createLowerAtomicPass();
> (void) llvm::createCorrelatedValuePropagationPass();
> (void) llvm::createMemDepPrinter();
> + (void) llvm::createInstructionSimplifierPass();
>
> (void)new llvm::IntervalPartition();
> (void)new llvm::FindUsedTypes();
>
> Modified: llvm/trunk/include/llvm/Transforms/Scalar.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar.h?rev=122264&r1=122263&r2=122264&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Scalar.h (original)
> +++ llvm/trunk/include/llvm/Transforms/Scalar.h Mon Dec 20 14:54:37 2010
> @@ -322,6 +322,13 @@
> //
> Pass *createCorrelatedValuePropagationPass();
>
> +//===----------------------------------------------------------------------===//
> +//
> +// InstructionSimplifier - Remove redundant instructions.
> +//
> +FunctionPass *createInstructionSimplifierPass();
> +extern char&InstructionSimplifierID;
> +
> } // End llvm namespace
>
> #endif
>
> Modified: llvm/trunk/lib/Transforms/Utils/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CMakeLists.txt?rev=122264&r1=122263&r2=122264&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/CMakeLists.txt (original)
> +++ llvm/trunk/lib/Transforms/Utils/CMakeLists.txt Mon Dec 20 14:54:37 2010
> @@ -21,6 +21,7 @@
> PromoteMemoryToRegister.cpp
> SSAUpdater.cpp
> SimplifyCFG.cpp
> + SimplifyInstructions.cpp
> UnifyFunctionExitNodes.cpp
> Utils.cpp
> ValueMapper.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/Utils.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Utils.cpp?rev=122264&r1=122263&r2=122264&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/Utils.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/Utils.cpp Mon Dec 20 14:54:37 2010
> @@ -28,6 +28,7 @@
> initializeLowerSwitchPass(Registry);
> initializePromotePassPass(Registry);
> initializeUnifyFunctionExitNodesPass(Registry);
> + initializeInstSimplifierPass(Registry);
> }
>
> /// LLVMInitializeTransformUtils - C binding for initializeTransformUtilsPasses.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list