]> granicus.if.org Git - llvm/commitdiff
[RegisterBankInfo] Avoid heap allocation in most cases.
authorQuentin Colombet <qcolombet@apple.com>
Mon, 19 Sep 2016 17:33:55 +0000 (17:33 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Mon, 19 Sep 2016 17:33:55 +0000 (17:33 +0000)
The OperandsMapper class is used heavy in RegBankSelect and each
instantiation triggered a heap allocation for the array of operands.
Instead, use a SmallVector with a big enough size such that most of the
cases do not have to use dynamically allocated memory.

This improves the compile time of the RegBankSelect pass.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281916 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

index d075d7ab10ad778a2deee47e3a373374b1e85153..77c0a8cb48eb0deb922ded2ffa1fb9a812c825fc 100644 (file)
@@ -193,7 +193,8 @@ public:
   class OperandsMapper {
     /// The OpIdx-th cell contains the index in NewVRegs where the VRegs of the
     /// OpIdx-th operand starts. -1 means we do not have such mapping yet.
-    std::unique_ptr<int[]> OpToNewVRegIdx;
+    /// Note: We use a SmallVector to avoid heap allocation for most cases.
+    SmallVector<int, 8> OpToNewVRegIdx;
     /// Hold the registers that will be used to map MI with InstrMapping.
     SmallVector<unsigned, 8> NewVRegs;
     /// Current MachineRegisterInfo, used to create new virtual registers.
index 91681fb7a4091665ac0d1029fd5da530584b7bb0..ca9e8e615528dc75f09cc85d2243a98884dd841c 100644 (file)
@@ -513,7 +513,7 @@ RegisterBankInfo::OperandsMapper::OperandsMapper(
     MachineRegisterInfo &MRI)
     : MRI(MRI), MI(MI), InstrMapping(InstrMapping) {
   unsigned NumOpds = MI.getNumOperands();
-  OpToNewVRegIdx.reset(new int[NumOpds]);
+  OpToNewVRegIdx.resize(NumOpds);
   std::fill(&OpToNewVRegIdx[0], &OpToNewVRegIdx[NumOpds],
             OperandsMapper::DontKnowIdx);
   assert(InstrMapping.verify(MI) && "Invalid mapping for MI");