diff --git a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h --- a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h +++ b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h @@ -46,6 +46,8 @@ namespace llvm { namespace IRSimilarity { +struct IRInstructionDataList; + /// This represents what is and is not supported when finding similarity in /// Instructions. /// @@ -112,7 +114,7 @@ /// operands. This extra information allows for similarity matching to make /// assertions that allow for more flexibility when checking for whether an /// Instruction performs the same operation. - IRInstructionData(Instruction &I, bool Legality); + IRInstructionData(Instruction &I, bool Legality, IRInstructionDataList &IDL); /// Hashes \p Value based on its opcode, types, and operand types. /// Two IRInstructionData instances produce the same hash when they perform @@ -147,8 +149,12 @@ hash_value(Value.Inst->getType()), hash_combine_range(Value.OperTypes.begin(), Value.OperTypes.end())); } + + IRInstructionDataList *IDL = nullptr; }; +struct IRInstructionDataList : simple_ilist {}; + /// Compare one IRInstructionData class to another IRInstructionData class for /// whether they are performing a the same operation, and can mapped to the /// same value. For regular instructions if the hash value is the same, then @@ -256,6 +262,8 @@ /// with the information. BumpPtrAllocator *InstDataAllocator = nullptr; + IRInstructionDataList *IDL = nullptr; + /// Maps the Instructions in a BasicBlock \p BB to legal or illegal integers /// determined by \p InstrType. Two Instructions are mapped to the same value /// if they are close as defined by the InstructionData class above. @@ -289,24 +297,16 @@ BasicBlock::iterator &It, std::vector &UnsignedVecForBB, std::vector &InstrListForBB, bool End = false); - IRInstructionMapper(){ - // Make sure that the implementation of DenseMapInfo hasn't - // changed. - assert(DenseMapInfo::getEmptyKey() == (unsigned)-1 && - "DenseMapInfo's empty key isn't -1!"); - assert(DenseMapInfo::getTombstoneKey() == (unsigned)-2 && - "DenseMapInfo's tombstone key isn't -2!"); - } - - IRInstructionMapper(BumpPtrAllocator *IDA) - : InstDataAllocator(IDA){ + IRInstructionMapper(BumpPtrAllocator *IDA) : InstDataAllocator(IDA){ // Make sure that the implementation of DenseMapInfo hasn't // changed. assert(DenseMapInfo::getEmptyKey() == (unsigned)-1 && "DenseMapInfo's empty key isn't -1!"); assert(DenseMapInfo::getTombstoneKey() == (unsigned)-2 && "DenseMapInfo's tombstone key isn't -2!"); - } + IDL = new (InstDataAllocator->Allocate()) + IRInstructionDataList(); + }; /// Custom InstVisitor to classify different instructions for whether it can /// be analyzed for similarity. @@ -359,4 +359,4 @@ } // end namespace IRSimilarity } // end namespace llvm -#endif // LLVM_ANALYSIS_IRSIMILARITYIDENTIFIER_H \ No newline at end of file +#endif // LLVM_ANALYSIS_IRSIMILARITYIDENTIFIER_H diff --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp --- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp +++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp @@ -20,8 +20,9 @@ using namespace llvm; using namespace IRSimilarity; -IRInstructionData::IRInstructionData(Instruction &I, bool Legality) - : Inst(&I), Legal(Legality) { +IRInstructionData::IRInstructionData(Instruction &I, bool Legality, + IRInstructionDataList &IDList) + : Inst(&I), Legal(Legality), IDL(&IDList) { // Here we collect the operands and their types for determining whether // the structure of the operand use matches between two different candidates. for (Use &OI : I.operands()) { @@ -71,6 +72,9 @@ if (HaveLegalRange) { mapToIllegalUnsigned(It, UnsignedVecForBB, InstrListForBB, true); + for_each(InstrListForBB, [this](IRInstructionData *ID){ + this->IDL->push_back(*ID); + }); InstrList.insert(InstrList.end(), InstrListForBB.begin(), InstrListForBB.end()); UnsignedVec.insert(UnsignedVec.end(), UnsignedVecForBB.begin(), @@ -96,7 +100,7 @@ // Get the integer for this instruction or give it the current // LegalInstrNumber. IRInstructionData *ID = new (InstDataAllocator->Allocate()) - IRInstructionData(*It, true); + IRInstructionData(*It, true, *IDL); InstrListForBB.push_back(ID); // Add to the instruction list @@ -140,7 +144,7 @@ IRInstructionData *ID = nullptr; if (!End) ID = new (InstDataAllocator->Allocate()) - IRInstructionData(*It, false); + IRInstructionData(*It, false, *IDL); InstrListForBB.push_back(ID); // Remember that we added an illegal number last time. @@ -158,4 +162,4 @@ "IllegalInstrNumber cannot be DenseMap tombstone or empty key!"); return INumber; -} \ No newline at end of file +}