diff --git a/binaryfile.h b/binaryfile.h index f2205abd9..e5baecac7 100644 --- a/binaryfile.h +++ b/binaryfile.h @@ -98,36 +98,32 @@ struct Endianess { template struct Endianess { static uint64_t read(const uint8_t *Buf) { - return llvm::support::endian::read(Buf); + using namespace llvm::support; + return endian::read(Buf); } }; template struct Endianess { static uint64_t read(const uint8_t *Buf) { - return llvm::support::endian::read(Buf); + using namespace llvm::support; + return endian::read(Buf); } }; template struct Endianess { static uint64_t read(const uint8_t *Buf) { - return llvm::support::endian::read(Buf); + using namespace llvm::support; + return endian::read(Buf); } }; template struct Endianess { static uint64_t read(const uint8_t *Buf) { - return llvm::support::endian::read(Buf); + using namespace llvm::support; + return endian::read(Buf); } }; diff --git a/codegenerator.cpp b/codegenerator.cpp index 39bcfdf25..be8ea410a 100644 --- a/codegenerator.cpp +++ b/codegenerator.cpp @@ -270,10 +270,11 @@ public: char CpuLoopFunctionPass::ID = 0; -static RegisterPass X("cpu-loop", - "cpu_loop FunctionPass", - false, - false); +using RegisterCLF = RegisterPass; +static RegisterCLF X("cpu-loop", + "cpu_loop FunctionPass", + false, + false); void CpuLoopFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); @@ -379,10 +380,11 @@ private: char CpuLoopExitPass::ID = 0; -static RegisterPass Y("cpu-loop-exit", - "cpu_loop_exit Pass", - false, - false); +using RegisterCLE = RegisterPass; +static RegisterCLE Y("cpu-loop-exit", + "cpu_loop_exit Pass", + false, + false); static void purgeNoReturn(Function *F) { auto &Context = F->getParent()->getContext(); @@ -966,9 +968,8 @@ void CodeGenerator::translate(uint64_t VirtualAddress) { if (DetectFunctionBoundaries) { legacy::FunctionPassManager FPM(&*TheModule); - FPM.add(new FunctionBoundariesDetectionPass(&JumpTargets, - "", - UseDebugSymbols)); + using FBDP = FunctionBoundariesDetectionPass; + FPM.add(new FBDP(&JumpTargets, "", UseDebugSymbols)); FPM.run(*MainFunction); } diff --git a/collectcfg.h b/collectcfg.h index eb445c102..0a34a3231 100644 --- a/collectcfg.h +++ b/collectcfg.h @@ -41,10 +41,15 @@ private: bool isNewInstruction(llvm::BasicBlock *BB); private: - std::map, - CompareByName> Result; - std::set BlackList; + using BasicBlock = llvm::BasicBlock; + + template + using SmallVector = llvm::SmallVector; + + using Comparer = CompareByName; + std::map, Comparer> Result; + std::set BlackList; + }; #endif // _COLLECTCFG_H diff --git a/collectnoreturn.cpp b/collectnoreturn.cpp index ae717f83d..c506b4845 100644 --- a/collectnoreturn.cpp +++ b/collectnoreturn.cpp @@ -24,10 +24,11 @@ struct CompareByName { }; char CollectNoreturn::ID = 0; -static RegisterPass X("cnoreturn", - "Collect noreturn Pass", - true, - true); +using RegisterCNR = RegisterPass; +static RegisterCNR X("cnoreturn", + "Collect noreturn Pass", + true, + true); void CollectNoreturn::serialize(std::ostream &Output) { Output << "noreturn\n"; diff --git a/debughelper.cpp b/debughelper.cpp index 92bc2cc3a..2d898ed71 100644 --- a/debughelper.cpp +++ b/debughelper.cpp @@ -82,8 +82,9 @@ static void addModuleFlag(Module *TheModule, StringRef Flag, uint32_t Value) { } } -DebugAnnotationWriter::DebugAnnotationWriter(LLVMContext& Context, - bool DebugInfo) : +using DAW = DebugAnnotationWriter; + +DAW::DebugAnnotationWriter(LLVMContext &Context, bool DebugInfo) : Context(Context), DebugInfo(DebugInfo) { @@ -92,8 +93,8 @@ DebugAnnotationWriter::DebugAnnotationWriter(LLVMContext& Context, DbgMDKind = Context.getMDKindID("dbg"); } -void DebugAnnotationWriter::emitInstructionAnnot(const Instruction *Instr, - formatted_raw_ostream &Output) { +void DAW::emitInstructionAnnot(const Instruction *Instr, + formatted_raw_ostream &Output) { DISubprogram *Subprogram = Instr->getParent()->getParent()->getSubprogram(); // Ignore whatever is outside the root and the isolated functions @@ -272,8 +273,7 @@ bool DebugHelper::copySource() { return false; } -DebugAnnotationWriter *DebugHelper::annotator(bool DebugInfo) { - Annotator.reset(new DebugAnnotationWriter(TheModule->getContext(), - DebugInfo)); +DAW *DebugHelper::annotator(bool DebugInfo) { + Annotator.reset(new DAW(TheModule->getContext(), DebugInfo)); return Annotator.get(); } diff --git a/functionboundariesdetection.cpp b/functionboundariesdetection.cpp index 750fe5547..4f9cb68f0 100644 --- a/functionboundariesdetection.cpp +++ b/functionboundariesdetection.cpp @@ -46,10 +46,11 @@ using interval_set = boost::icl::interval_set; using interval = boost::icl::interval; char FBDP::ID = 0; -static RegisterPass X("fbdp", - "Function Boundaries Detection Pass", - true, - true); +using RegisterFBDP = RegisterPass; +static RegisterFBDP X("fbdp", + "Function Boundaries Detection Pass", + true, + true); class FunctionBoundariesDetectionImpl { public: diff --git a/generatedcodebasicinfo.cpp b/generatedcodebasicinfo.cpp index f53287866..ada286b7d 100644 --- a/generatedcodebasicinfo.cpp +++ b/generatedcodebasicinfo.cpp @@ -21,10 +21,11 @@ using namespace llvm; char GeneratedCodeBasicInfo::ID = 0; -static RegisterPass X("gcbi", - "Generated Code Basic Info", - true, - true); +using RegisterGCBI = RegisterPass; +static RegisterGCBI X("gcbi", + "Generated Code Basic Info", + true, + true); bool GeneratedCodeBasicInfo::runOnFunction(llvm::Function &F) { DBG("passes", { dbg << "Starting GeneratedCodeBasicInfo\n"; }); diff --git a/include/revng/StackAnalysis/functionssummary.h b/include/revng/StackAnalysis/functionssummary.h index 0e6de0fbb..dba4ac7af 100644 --- a/include/revng/StackAnalysis/functionssummary.h +++ b/include/revng/StackAnalysis/functionssummary.h @@ -426,8 +426,13 @@ public: llvm::Instruction *Call; llvm::BasicBlock *Callee; - std::map RegisterSlots; + + using GlobalVariable = llvm::GlobalVariable; + + template + using map = std::map; + + map RegisterSlots; }; struct FunctionDescription { diff --git a/instructiontranslator.cpp b/instructiontranslator.cpp index f162d32fc..083b57550 100644 --- a/instructiontranslator.cpp +++ b/instructiontranslator.cpp @@ -46,11 +46,13 @@ namespace PTC { Const }; + template + using RAI = RandomAccessIterator; + template class InstructionArgumentsIterator : - public RandomAccessIterator, - false> { + public RAI, false> { + public: using base = RandomAccessIterator; +using RBasicBlockIterator = llvm::BasicBlock::reverse_iterator; +using RBasicBlockRange = llvm::iterator_range; using RVisitorFunction = std::function; /// Performs a breadth-first visit of the instructions before \p I and in the diff --git a/jumptargetmanager.cpp b/jumptargetmanager.cpp index 7fb7a2594..7fb0c2453 100644 --- a/jumptargetmanager.cpp +++ b/jumptargetmanager.cpp @@ -1414,5 +1414,6 @@ void JumpTargetManager::harvest() { } -const JumpTargetManager::BlockWithAddress JumpTargetManager::NoMoreTargets = - JumpTargetManager::BlockWithAddress(0, nullptr); +using BlockWithAddress = JumpTargetManager::BlockWithAddress; +using JTM = JumpTargetManager; +const BlockWithAddress JTM::NoMoreTargets = BlockWithAddress(0, nullptr); diff --git a/lazysmallbitvector.h b/lazysmallbitvector.h index 361ddae41..1966242b0 100644 --- a/lazysmallbitvector.h +++ b/lazysmallbitvector.h @@ -35,9 +35,12 @@ static unsigned requiredBits(T Value) { } template -using enable_if_either = typename std::enable_if::value - || std::is_same::value, - T>::type; +constexpr bool is_either() { + return std::is_same::value || std::is_same::value; +} + +template +using enable_if_either = typename std::enable_if(), T>::type; template using enable_if_int = enable_if_either; @@ -675,21 +678,25 @@ inline void LazySmallBitVectorIterator::increment() { NextBitIndex = BitVector->findNext(NextBitIndex); } -template inline -LazySmallBitVectorIterator::LazySmallBitVectorIterator(LSBV *BitVector) - : BitVector(BitVector), NextBitIndex(0) { +#define LSBVI LazySmallBitVectorIterator + +template +inline +LSBVI::LSBVI(LSBV *BitVector) : BitVector(BitVector), NextBitIndex(0) { assert(BitVector != nullptr); if (!BitVector->isZero()) increment(); } -template inline -LazySmallBitVectorIterator::LazySmallBitVectorIterator(LSBV *BitVector, - unsigned Index) - : BitVector(BitVector), NextBitIndex(Index) { - +template +inline +LSBVI::LSBVI(LSBV *BitVector, unsigned Index) : + BitVector(BitVector), + NextBitIndex(Index) { assert(BitVector != nullptr); } +#undef LSBVI + #endif // _LAZYSMALLBITVECTOR_H diff --git a/lib/StackAnalysis/abiir.h b/lib/StackAnalysis/abiir.h index 1ce25c25c..3aef29b20 100644 --- a/lib/StackAnalysis/abiir.h +++ b/lib/StackAnalysis/abiir.h @@ -294,8 +294,9 @@ public: /// \brief The ABI IR, a container of ABIIRBasicBlocks class ABIFunction { public: - using calls_container = std::vector>; + template + using VectorOfPairs = std::vector>; + using calls_container = VectorOfPairs; using calls_iterator = calls_container::iterator; using calls_range = llvm::iterator_range; diff --git a/lib/StackAnalysis/functionabi.cpp b/lib/StackAnalysis/functionabi.cpp index c037ed54c..be40a9354 100644 --- a/lib/StackAnalysis/functionabi.cpp +++ b/lib/StackAnalysis/functionabi.cpp @@ -25,6 +25,9 @@ using ABIIRBB = ABIIRBasicBlock; static ASID CPU = ASID::cpuID(); +template +using MapOfMaps = DefaultMap, N1>; + /// \brief A set of helper functions related to DefaultMap namespace MapHelpers { @@ -83,8 +86,8 @@ unsigned cmpWithModule(const DefaultMap &This, template unsigned -nestedCmpWithModule(const DefaultMap, N2> &This, - const DefaultMap, N2> &Other, +nestedCmpWithModule(const MapOfMaps &This, + const MapOfMaps &Other, ASID ID, const Module *M) { LoggerIndent<> Y(SaDiffLog); @@ -209,7 +212,7 @@ inline void dump(const Module *M, template inline void dump(const Module *M, T &Output, - const DefaultMap, N2> &D, + const MapOfMaps &D, ASID ID, const char *Prefix) { std::string Longer(Prefix); @@ -586,9 +589,7 @@ private: /// function call // TODO: We could have as well have a vector here, considering calls are // relatively rare - DefaultMap, - 5> FunctionCallRegisterAnalyses; + MapOfMaps FunctionCallRegisterAnalyses; public: Element() {} @@ -635,15 +636,16 @@ public: // TODO: review template unsigned cmp(const Element &Other, const Module *M = nullptr) const { + using namespace MapHelpers; LoggerIndent<> Y(SaDiffLog); unsigned Result = 0; - auto registerCmp = MapHelpers::cmpWithModule; + auto registerCmp = cmpWithModule; ROA((registerCmp(RegisterAnalyses, Other.RegisterAnalyses, CPU, M)), { SaDiffLog << "RegisterAnalyses" << DoLog; }); - auto X = MapHelpers::nestedCmpWithModule; + auto X = nestedCmpWithModule; ROA((X(FunctionCallRegisterAnalyses, Other.FunctionCallRegisterAnalyses, CPU, @@ -743,17 +745,13 @@ private: /// \tparam Tuple the tuple to wrap. template