[llvm] [CodeGen] Use std::bitset for MachineFunctionProperties (PR #94627)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 08:02:17 PDT 2024


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/94627

The size of the properties is fixed, so no need for a SmallVector. Assigning small, fixed-size bitsets is faster.

It's a minor performance improvement, see [here](http://llvm-compile-time-tracker.com/compare.php?from=24a39f364dbef7e18d36be3919eacde32125df5e&to=c780e20ea770070dd6c21c4e181987c0b481c92c&stat=instructions:u).

>From 5a40e1be82fb0ae735ba6f6974b02a10bb8318b4 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Thu, 6 Jun 2024 16:14:06 +0200
Subject: [PATCH] [CodeGen] Use bitset for MachineFunctionProperties

The size of the properties is fixed, so no need for a SmallVector.

At most a minor improvement, though.
---
 llvm/include/llvm/CodeGen/MachineFunction.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 9f8e846cac45b..6e7292abeddbb 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -18,7 +18,6 @@
 #define LLVM_CODEGEN_MACHINEFUNCTION_H
 
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/ADT/SmallVector.h"
@@ -34,6 +33,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Recycler.h"
 #include "llvm/Target/TargetOptions.h"
+#include <bitset>
 #include <cassert>
 #include <cstdint>
 #include <memory>
@@ -217,22 +217,21 @@ class MachineFunctionProperties {
   }
 
   MachineFunctionProperties &reset(const MachineFunctionProperties &MFP) {
-    Properties.reset(MFP.Properties);
+    Properties &= ~MFP.Properties;
     return *this;
   }
 
   // Returns true if all properties set in V (i.e. required by a pass) are set
   // in this.
   bool verifyRequiredProperties(const MachineFunctionProperties &V) const {
-    return !V.Properties.test(Properties);
+    return (Properties | ~V.Properties).all();
   }
 
   /// Print the MachineFunctionProperties in human-readable form.
   void print(raw_ostream &OS) const;
 
 private:
-  BitVector Properties =
-      BitVector(static_cast<unsigned>(Property::LastProperty)+1);
+  std::bitset<static_cast<unsigned>(Property::LastProperty) + 1> Properties;
 };
 
 struct SEHHandler {



More information about the llvm-commits mailing list