1919#include " llvm/Support/Allocator.h"
2020#include " llvm/Support/Compiler.h"
2121#include " llvm/Support/SourceMgr.h"
22- #include " gmock/gmock.h"
2322#include " gtest/gtest.h"
2423
2524using namespace llvm ;
2625using namespace IRSimilarity ;
2726
28- using testing::SizeIs;
29-
3027static std::unique_ptr<Module> makeLLVMModule (LLVMContext &Context,
3128 StringRef ModuleStr) {
3229 SMDiagnostic Err;
@@ -52,6 +49,9 @@ void getSimilarities(
5249 SimilarityCandidates = Identifier.findSimilarity (M);
5350}
5451
52+ // TODO: All these tests could probably become IR LIT tests like
53+ // IROutliner/outlining-special-state.ll
54+
5555// Checks that different opcodes are mapped to different values
5656TEST (IRInstructionMapper, OpcodeDifferentiation) {
5757 StringRef ModuleString = R"(
@@ -733,162 +733,6 @@ TEST(IRInstructionMapper, StoreDifferentAtomic) {
733733 ASSERT_TRUE (UnsignedVec[0 ] != UnsignedVec[1 ]);
734734}
735735
736- // Checks that atomicrmw that have the different types are mapped to
737- // different unsigned integers.
738- TEST (IRInstructionMapper, AtomicRMWDifferentType) {
739- StringRef ModuleString = R"(
740- define i32 @f(ptr %a, ptr %b) {
741- bb0:
742- %1 = atomicrmw add ptr %a, i32 1 acquire
743- %2 = atomicrmw add ptr %b, i64 1 acquire
744- ret i32 0
745- })" ;
746- LLVMContext Context;
747- std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleString);
748-
749- std::vector<IRInstructionData *> InstrList;
750- std::vector<unsigned > UnsignedVec;
751-
752- SpecificBumpPtrAllocator<IRInstructionData> InstDataAllocator;
753- SpecificBumpPtrAllocator<IRInstructionDataList> IDLAllocator;
754- IRInstructionMapper Mapper (&InstDataAllocator, &IDLAllocator);
755- getVectors (*M, Mapper, InstrList, UnsignedVec);
756-
757- ASSERT_EQ (InstrList.size (), UnsignedVec.size ());
758- ASSERT_THAT (UnsignedVec, SizeIs (3 ));
759- EXPECT_NE (UnsignedVec[0 ], UnsignedVec[1 ]);
760- }
761-
762- // Checks that atomicrmw that have the different aligns are mapped to different
763- // unsigned integers.
764- TEST (IRInstructionMapper, AtomicRMWDifferentAlign) {
765- StringRef ModuleString = R"(
766- define i32 @f(ptr %a, ptr %b) {
767- bb0:
768- %1 = atomicrmw add ptr %a, i32 1 acquire, align 4
769- %2 = atomicrmw add ptr %b, i32 1 acquire, align 8
770- ret i32 0
771- })" ;
772- LLVMContext Context;
773- std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleString);
774-
775- std::vector<IRInstructionData *> InstrList;
776- std::vector<unsigned > UnsignedVec;
777-
778- SpecificBumpPtrAllocator<IRInstructionData> InstDataAllocator;
779- SpecificBumpPtrAllocator<IRInstructionDataList> IDLAllocator;
780- IRInstructionMapper Mapper (&InstDataAllocator, &IDLAllocator);
781- getVectors (*M, Mapper, InstrList, UnsignedVec);
782-
783- ASSERT_EQ (InstrList.size (), UnsignedVec.size ());
784- ASSERT_THAT (UnsignedVec, SizeIs (3 ));
785- EXPECT_NE (UnsignedVec[0 ], UnsignedVec[1 ]);
786- }
787-
788- // Checks that atomicrmw that have the different volatile settings are mapped to
789- // different unsigned integers.
790- TEST (IRInstructionMapper, AtomicRMWDifferentVolatile) {
791- StringRef ModuleString = R"(
792- define i32 @f(ptr %a, ptr %b) {
793- bb0:
794- %1 = atomicrmw volatile add ptr %a, i32 1 acquire
795- %2 = atomicrmw add ptr %b, i32 1 acquire
796- ret i32 0
797- })" ;
798- LLVMContext Context;
799- std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleString);
800-
801- std::vector<IRInstructionData *> InstrList;
802- std::vector<unsigned > UnsignedVec;
803-
804- SpecificBumpPtrAllocator<IRInstructionData> InstDataAllocator;
805- SpecificBumpPtrAllocator<IRInstructionDataList> IDLAllocator;
806- IRInstructionMapper Mapper (&InstDataAllocator, &IDLAllocator);
807- getVectors (*M, Mapper, InstrList, UnsignedVec);
808-
809- ASSERT_EQ (InstrList.size (), UnsignedVec.size ());
810- ASSERT_THAT (UnsignedVec, SizeIs (3 ));
811- EXPECT_NE (UnsignedVec[0 ], UnsignedVec[1 ]);
812- }
813-
814- // Checks that cmpxchg that have the different types are mapped to
815- // different unsigned integers.
816- TEST (IRInstructionMapper, AtomicCmpXchgDifferentType) {
817- StringRef ModuleString = R"(
818- define i32 @f(ptr %a, ptr %b) {
819- bb0:
820- %1 = cmpxchg ptr %a, i32 0, i32 1 monotonic monotonic
821- %2 = cmpxchg ptr %b, i64 0, i64 1 monotonic monotonic
822- ret i32 0
823- })" ;
824- LLVMContext Context;
825- std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleString);
826-
827- std::vector<IRInstructionData *> InstrList;
828- std::vector<unsigned > UnsignedVec;
829-
830- SpecificBumpPtrAllocator<IRInstructionData> InstDataAllocator;
831- SpecificBumpPtrAllocator<IRInstructionDataList> IDLAllocator;
832- IRInstructionMapper Mapper (&InstDataAllocator, &IDLAllocator);
833- getVectors (*M, Mapper, InstrList, UnsignedVec);
834-
835- ASSERT_EQ (InstrList.size (), UnsignedVec.size ());
836- ASSERT_THAT (UnsignedVec, SizeIs (3 ));
837- EXPECT_NE (UnsignedVec[0 ], UnsignedVec[1 ]);
838- }
839-
840- // Checks that cmpxchg that have the different aligns are mapped to different
841- // unsigned integers.
842- TEST (IRInstructionMapper, AtomicCmpXchgDifferentAlign) {
843- StringRef ModuleString = R"(
844- define i32 @f(ptr %a, ptr %b) {
845- bb0:
846- %1 = cmpxchg ptr %a, i32 0, i32 1 monotonic monotonic, align 4
847- %2 = cmpxchg ptr %b, i32 0, i32 1 monotonic monotonic, align 8
848- ret i32 0
849- })" ;
850- LLVMContext Context;
851- std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleString);
852-
853- std::vector<IRInstructionData *> InstrList;
854- std::vector<unsigned > UnsignedVec;
855-
856- SpecificBumpPtrAllocator<IRInstructionData> InstDataAllocator;
857- SpecificBumpPtrAllocator<IRInstructionDataList> IDLAllocator;
858- IRInstructionMapper Mapper (&InstDataAllocator, &IDLAllocator);
859- getVectors (*M, Mapper, InstrList, UnsignedVec);
860-
861- ASSERT_EQ (InstrList.size (), UnsignedVec.size ());
862- ASSERT_THAT (UnsignedVec, SizeIs (3 ));
863- EXPECT_NE (UnsignedVec[0 ], UnsignedVec[1 ]);
864- }
865-
866- // Checks that cmpxchg that have the different volatile settings are mapped to
867- // different unsigned integers.
868- TEST (IRInstructionMapper, AtomicCmpXchgDifferentVolatile) {
869- StringRef ModuleString = R"(
870- define i32 @f(ptr %a, ptr %b) {
871- bb0:
872- %1 = cmpxchg volatile ptr %a, i32 0, i32 1 monotonic monotonic
873- %2 = cmpxchg ptr %b, i32 0, i32 1 monotonic monotonic
874- ret i32 0
875- })" ;
876- LLVMContext Context;
877- std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleString);
878-
879- std::vector<IRInstructionData *> InstrList;
880- std::vector<unsigned > UnsignedVec;
881-
882- SpecificBumpPtrAllocator<IRInstructionData> InstDataAllocator;
883- SpecificBumpPtrAllocator<IRInstructionDataList> IDLAllocator;
884- IRInstructionMapper Mapper (&InstDataAllocator, &IDLAllocator);
885- getVectors (*M, Mapper, InstrList, UnsignedVec);
886-
887- ASSERT_EQ (InstrList.size (), UnsignedVec.size ());
888- ASSERT_THAT (UnsignedVec, SizeIs (3 ));
889- EXPECT_NE (UnsignedVec[0 ], UnsignedVec[1 ]);
890- }
891-
892736// Checks that the branch is mapped to legal when the option is set.
893737TEST (IRInstructionMapper, BranchLegal) {
894738 StringRef ModuleString = R"(
0 commit comments