[llvm] ef7d537 - [llvm] minor cleanup in GenericSSAContext

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 23:31:24 PDT 2023


Author: Sameer Sahasrabuddhe
Date: 2023-07-18T12:01:11+05:30
New Revision: ef7d53731bba8c4131f519d7a4dd8cd774cfe539

URL: https://github.com/llvm/llvm-project/commit/ef7d53731bba8c4131f519d7a4dd8cd774cfe539
DIFF: https://github.com/llvm/llvm-project/commit/ef7d53731bba8c4131f519d7a4dd8cd774cfe539.diff

LOG: [llvm] minor cleanup in GenericSSAContext

- update comments to reflect actual state
- use (implicitly inline) constexpr for a const static member

Added: 
    

Modified: 
    llvm/include/llvm/ADT/GenericSSAContext.h
    llvm/include/llvm/CodeGen/MachineSSAContext.h
    llvm/include/llvm/IR/SSAContext.h
    llvm/lib/CodeGen/MachineSSAContext.cpp
    llvm/lib/IR/SSAContext.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/GenericSSAContext.h b/llvm/include/llvm/ADT/GenericSSAContext.h
index 40b2be7c34c316..929fd1442750fb 100644
--- a/llvm/include/llvm/ADT/GenericSSAContext.h
+++ b/llvm/include/llvm/ADT/GenericSSAContext.h
@@ -31,13 +31,26 @@ template <typename _FunctionT> class GenericSSAContext {
   // equivalent of a ValueT.
   //
   // using ValueRefT = ...
+  //
+  // The ConstValueRefT is needed to work with "const Value *", where const
+  // needs to bind to the pointee and not the pointer.
+  //
+  // using ConstValueRefT = ...
+  //
+  // The null value for ValueRefT.
+  //
+  // static constexpr ValueRefT ValueRefNull;
+
+  // An InstructionT usually defines one or more ValueT objects.
+  //
+  // using InstructionT = ... must be a subclass of Value
 
-  // An InstT is a subclass of ValueT that itself defines one or more ValueT
-  // objects.
+  // A UseT represents a data-edge from the defining instruction to the using
+  // instruction.
   //
-  // using InstT = ... must be a subclass of Value
+  // using UseT = ...
 
-  // A BlockT is a sequence of InstT, and forms a node of the CFG. It
+  // A BlockT is a sequence of InstructionT, and forms a node of the CFG. It
   // has global methods predecessors() and successors() that return
   // the list of incoming CFG edges and outgoing CFG edges
   // respectively.
@@ -53,10 +66,10 @@ template <typename _FunctionT> class GenericSSAContext {
   // indicated by the compiler.
   using FunctionT = typename _FunctionT::invalidTemplateInstanceError;
 
-  // A UseT represents a data-edge from the defining instruction to the using
-  // instruction.
+  // A dominator tree provides the dominance relation between basic blocks in
+  // a given funciton.
   //
-  // using UseT = ...
+  // using DominatorTreeT = ...
 
   // Initialize the SSA context with information about the FunctionT being
   // processed.
@@ -75,19 +88,19 @@ template <typename _FunctionT> class GenericSSAContext {
   // static void appendBlockDefs(SmallVectorImpl<const ValueRefT> &defs,
   //                             const BlockT &block);
 
-  // static void appendBlockTerms(SmallVectorImpl<InstT *> &terms,
+  // static void appendBlockTerms(SmallVectorImpl<InstructionT *> &terms,
   //                              BlockT &block);
-  // static void appendBlockTerms(SmallVectorImpl<const InstT *> &terms,
+  // static void appendBlockTerms(SmallVectorImpl<const InstructionT *> &terms,
   //                              const BlockT &block);
   //
-  // static bool comesBefore(const InstT *lhs, const InstT *rhs);
-  // static bool isConstantOrUndefValuePhi(const InstT &Instr);
+  // static bool comesBefore(const InstructionT *lhs, const InstructionT *rhs);
+  // static bool isConstantOrUndefValuePhi(const InstructionT &Instr);
   // const BlockT *getDefBlock(const ValueRefT value) const;
 
   // Methods to print various objects.
   //
   // Printable print(BlockT *block) const;
-  // Printable print(InstT *inst) const;
+  // Printable print(InstructionT *inst) const;
   // Printable print(ValueRefT value) const;
 };
 } // namespace llvm

diff  --git a/llvm/include/llvm/CodeGen/MachineSSAContext.h b/llvm/include/llvm/CodeGen/MachineSSAContext.h
index 3bf0f728907eca..2409c83071e16c 100644
--- a/llvm/include/llvm/CodeGen/MachineSSAContext.h
+++ b/llvm/include/llvm/CodeGen/MachineSSAContext.h
@@ -44,10 +44,11 @@ template <> class GenericSSAContext<MachineFunction> {
   using InstructionT = MachineInstr;
   using ValueRefT = Register;
   using ConstValueRefT = Register;
-  static const Register ValueRefNull;
   using UseT = MachineOperand;
   using DominatorTreeT = DominatorTreeBase<BlockT, false>;
 
+  static constexpr Register ValueRefNull = 0;
+
   void setFunction(MachineFunction &Fn);
   MachineFunction *getFunction() const { return MF; }
 

diff  --git a/llvm/include/llvm/IR/SSAContext.h b/llvm/include/llvm/IR/SSAContext.h
index 5180c92d65565f..557ec752c21645 100644
--- a/llvm/include/llvm/IR/SSAContext.h
+++ b/llvm/include/llvm/IR/SSAContext.h
@@ -43,10 +43,11 @@ template <> class GenericSSAContext<Function> {
   using InstructionT = Instruction;
   using ValueRefT = Value *;
   using ConstValueRefT = const Value *;
-  static Value *ValueRefNull;
   using UseT = Use;
   using DominatorTreeT = DominatorTreeBase<BlockT, false>;
 
+  static constexpr Value *ValueRefNull = nullptr;
+
   void setFunction(Function &Fn);
   Function *getFunction() const { return F; }
 

diff  --git a/llvm/lib/CodeGen/MachineSSAContext.cpp b/llvm/lib/CodeGen/MachineSSAContext.cpp
index f7d43a510a58de..324084fb9c3237 100644
--- a/llvm/lib/CodeGen/MachineSSAContext.cpp
+++ b/llvm/lib/CodeGen/MachineSSAContext.cpp
@@ -21,8 +21,6 @@
 
 using namespace llvm;
 
-const Register MachineSSAContext::ValueRefNull{};
-
 void MachineSSAContext::setFunction(MachineFunction &Fn) {
   MF = &Fn;
   RegInfo = &MF->getRegInfo();

diff  --git a/llvm/lib/IR/SSAContext.cpp b/llvm/lib/IR/SSAContext.cpp
index bb31c967c65402..4790d19b74b51a 100644
--- a/llvm/lib/IR/SSAContext.cpp
+++ b/llvm/lib/IR/SSAContext.cpp
@@ -22,8 +22,6 @@
 
 using namespace llvm;
 
-Value *SSAContext::ValueRefNull = nullptr;
-
 void SSAContext::setFunction(Function &Fn) { F = &Fn; }
 
 BasicBlock *SSAContext::getEntryBlock(Function &F) {


        


More information about the llvm-commits mailing list