[Lldb-commits] [lldb] adfb23c - [NFC] Cleanup: Remove Function::getBasicBlockList() when not required.

2022-12-13 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2022-12-13T11:46:29-08:00
New Revision: adfb23c607ce35f090cf3e29fba9d382b22c3a50

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

LOG: [NFC] Cleanup: Remove Function::getBasicBlockList() when not required.

This is part of a series of patches that aim at making 
Function::getBasicBlockList() private.

Differential Revision: https://reviews.llvm.org/D139910

Added: 


Modified: 
clang/lib/CodeGen/CGVTables.cpp

lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp
llvm/lib/ExecutionEngine/Orc/SpeculateAnalyses.cpp
llvm/lib/Target/AArch64/SMEABIPass.cpp
llvm/lib/Transforms/CFGuard/CFGuard.cpp
llvm/lib/Transforms/IPO/InlineSimple.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/lib/Transforms/Utils/FunctionComparator.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/unittests/FuzzMutate/StrategiesTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 85acebeeaec9b..354a3f901ff1e 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -128,7 +128,7 @@ static void resolveTopLevelMetadata(llvm::Function *Fn,
 
   // Find all llvm.dbg.declare intrinsics and resolve the DILocalVariable nodes
   // they are referencing.
-  for (auto &BB : Fn->getBasicBlockList()) {
+  for (auto &BB : *Fn) {
 for (auto &I : BB) {
   if (auto *DII = dyn_cast(&I)) {
 auto *DILocal = DII->getVariable();

diff  --git 
a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp
 
b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp
index ec8f8d83c4b37..917242e9b287b 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptx86ABIFixups.cpp
@@ -122,7 +122,7 @@ findRSCallSites(llvm::Module &module, 
std::set &rs_callsites,
   bool found = false;
 
   for (auto &func : module.getFunctionList())
-for (auto &block : func.getBasicBlockList())
+for (auto &block : func)
   for (auto &inst : block) {
 llvm::CallInst *call_inst =
 llvm::dyn_cast_or_null(&inst);

diff  --git a/llvm/lib/ExecutionEngine/Orc/SpeculateAnalyses.cpp 
b/llvm/lib/ExecutionEngine/Orc/SpeculateAnalyses.cpp
index 0076267f933e7..42e2a24940127 100644
--- a/llvm/lib/ExecutionEngine/Orc/SpeculateAnalyses.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/SpeculateAnalyses.cpp
@@ -136,7 +136,7 @@ SequenceBBQuery::BlockListTy
 SequenceBBQuery::rearrangeBB(const Function &F, const BlockListTy &BBList) {
   BlockListTy RearrangedBBSet;
 
-  for (auto &Block : F.getBasicBlockList())
+  for (auto &Block : F)
 if (llvm::is_contained(BBList, &Block))
   RearrangedBBSet.push_back(&Block);
 

diff  --git a/llvm/lib/Target/AArch64/SMEABIPass.cpp 
b/llvm/lib/Target/AArch64/SMEABIPass.cpp
index a56f8e052d1c9..83010017c761f 100644
--- a/llvm/lib/Target/AArch64/SMEABIPass.cpp
+++ b/llvm/lib/Target/AArch64/SMEABIPass.cpp
@@ -113,7 +113,7 @@ bool SMEABI::updateNewZAFunctions(Module *M, Function *F,
   Builder.CreateCall(EnableZAIntr->getFunctionType(), EnableZAIntr);
 
   // Before returning, disable pstate.za
-  for (BasicBlock &BB : F->getBasicBlockList()) {
+  for (BasicBlock &BB : *F) {
 Instruction *T = BB.getTerminator();
 if (!T || !isa(T))
   continue;

diff  --git a/llvm/lib/Transforms/CFGuard/CFGuard.cpp 
b/llvm/lib/Transforms/CFGuard/CFGuard.cpp
index 55ef7c214fc84..bebaa6cb59699 100644
--- a/llvm/lib/Transforms/CFGuard/CFGuard.cpp
+++ b/llvm/lib/Transforms/CFGuard/CFGuard.cpp
@@ -272,7 +272,7 @@ bool CFGuard::runOnFunction(Function &F) {
   // instructions. Make a separate list of pointers to indirect
   // call/invoke/callbr instructions because the original instructions will be
   // deleted as the checks are added.
-  for (BasicBlock &BB : F.getBasicBlockList()) {
+  for (BasicBlock &BB : F) {
 for (Instruction &I : BB) {
   auto *CB = dyn_cast(&I);
   if (CB && CB->isIndirectCall() && !CB->hasFnAttr("guard_nocf")) {

diff  --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp 
b/llvm/lib/Transforms/IPO/InlineSimple.cpp
index 2143e39d488dc..eba0d6636d6c0 100644
--- a/llvm/lib/Transforms/IPO/InlineSimple.cpp
+++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp
@@ -50,7 +50,7 @@ class SimpleInliner : public LegacyInlinerBase {
 TargetTransformInfo &TTI = TTIWP->getTTI(*Callee);
 
 bool RemarksEnabled = false;
-

[Lldb-commits] [lldb] b64f7d0 - [NFC][IR] Make Module::getAliasList() private

2023-02-13 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2023-02-13T18:45:12-08:00
New Revision: b64f7d028bdcaf679130afeed9518c09663f6dc8

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

LOG: [NFC][IR] Make Module::getAliasList() private

This patch adds several missing AliasList modifier functions, like
removeAlias(), eraseAlias() and insertAlias().
There is no longer need to access the list directly so it also makes
getAliaList() private.

Differential Revision: https://reviews.llvm.org/D143958

Added: 


Modified: 
lldb/source/Expression/IRExecutionUnit.cpp
llvm/include/llvm/IR/Module.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/unittests/IR/ModuleTest.cpp

Removed: 




diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index c8068eca5c1b5..1a7373d0cbb8a 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -410,7 +410,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 RegisterOneValue(global_var);
   }
 
-  for (llvm::GlobalAlias &global_alias : m_module->getAliasList()) {
+  for (llvm::GlobalAlias &global_alias : m_module->getAliases()) {
 RegisterOneValue(global_alias);
   }
 

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index e86880406b7ea..920729f806660 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -563,6 +563,16 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 return &Module::FunctionList;
   }
 
+  /// Detach \p Alias from the list but don't delete it.
+  void removeAlias(GlobalAlias *Alias) { AliasList.remove(Alias); }
+  /// Remove \p Alias from the list and delete it.
+  void eraseAlias(GlobalAlias *Alias) { AliasList.erase(Alias); }
+  /// Insert \p Alias at the end of the alias list and take ownership.
+  void insertAlias(GlobalAlias *Alias) { AliasList.insert(AliasList.end(), 
Alias); }
+  // Use alias_size() to get the size of AliasList.
+  // Use aliases() to get a range of all Alias objects in AliasList.
+
+private: // Please use functions like insertAlias(), removeAlias() etc.
   /// Get the Module's list of aliases (constant).
   const AliasListType&getAliasList() const{ return AliasList; }
   /// Get the Module's list of aliases.
@@ -571,7 +581,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   static AliasListType Module::*getSublistAccess(GlobalAlias*) {
 return &Module::AliasList;
   }
+  friend class llvm::SymbolTableListTraits;
 
+public:
   /// Get the Module's list of ifuncs (constant).
   const IFuncListType&getIFuncList() const{ return IFuncList; }
   /// Get the Module's list of ifuncs.

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 077b290fe0e00..2db5e7dc140aa 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -1141,7 +1141,7 @@ bool LLParser::parseAliasOrIFunc(const std::string &Name, 
LocTy NameLoc,
 
   // Insert into the module, we know its name won't collide now.
   if (IsAlias)
-M->getAliasList().push_back(GA.release());
+M->insertAlias(GA.release());
   else
 M->getIFuncList().push_back(GI.release());
   assert(GV->getName() == Name && "Should not be a name conflict!");

diff  --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index a7c45730ff46c..7cf812c36984d 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -514,7 +514,7 @@ GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, 
LinkageTypes Link,
   AddressSpace) {
   setAliasee(Aliasee);
   if (ParentModule)
-ParentModule->getAliasList().push_back(this);
+ParentModule->insertAlias(this);
 }
 
 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
@@ -546,11 +546,11 @@ GlobalAlias *GlobalAlias::create(const Twine &Name, 
GlobalValue *Aliasee) {
 }
 
 void GlobalAlias::removeFromParent() {
-  getParent()->getAliasList().remove(getIterator());
+  getParent()->removeAlias(this);
 }
 
 void GlobalAlias::eraseFromParent() {
-  getParent()->getAliasList().erase(getIterator());
+  getParent()->eraseAlias(this);
 }
 
 void GlobalAlias::setAliasee(Constant *Aliasee) {

diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp 
b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 0317a8bcb6bc7..040701e243ce5 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2360,7 +2360,7 @@ OptimizeGlobalAliases(Module &M,
   continue;
 
 // Delete the alias.
-M.getAliasList().erase(&J);
+M.eraseAlias(&J);
 ++NumAliasesRemoved;
 Changed = true;
   }

diff  --git a/llvm/unittests/IR/ModuleTest.cpp 
b/llvm/unittest

[Lldb-commits] [lldb] 6d4a674 - Revert "[NFC][IR] Make Module::getAliasList() private"

2023-02-13 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2023-02-13T19:12:30-08:00
New Revision: 6d4a674acbc56458bb084878d82d16e393d45a6b

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

LOG: Revert "[NFC][IR] Make Module::getAliasList() private"

This reverts commit b64f7d028bdcaf679130afeed9518c09663f6dc8.

Added: 


Modified: 
lldb/source/Expression/IRExecutionUnit.cpp
llvm/include/llvm/IR/Module.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/unittests/IR/ModuleTest.cpp

Removed: 




diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index 1a7373d0cbb8a..c8068eca5c1b5 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -410,7 +410,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 RegisterOneValue(global_var);
   }
 
-  for (llvm::GlobalAlias &global_alias : m_module->getAliases()) {
+  for (llvm::GlobalAlias &global_alias : m_module->getAliasList()) {
 RegisterOneValue(global_alias);
   }
 

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 920729f806660..e86880406b7ea 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -563,16 +563,6 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 return &Module::FunctionList;
   }
 
-  /// Detach \p Alias from the list but don't delete it.
-  void removeAlias(GlobalAlias *Alias) { AliasList.remove(Alias); }
-  /// Remove \p Alias from the list and delete it.
-  void eraseAlias(GlobalAlias *Alias) { AliasList.erase(Alias); }
-  /// Insert \p Alias at the end of the alias list and take ownership.
-  void insertAlias(GlobalAlias *Alias) { AliasList.insert(AliasList.end(), 
Alias); }
-  // Use alias_size() to get the size of AliasList.
-  // Use aliases() to get a range of all Alias objects in AliasList.
-
-private: // Please use functions like insertAlias(), removeAlias() etc.
   /// Get the Module's list of aliases (constant).
   const AliasListType&getAliasList() const{ return AliasList; }
   /// Get the Module's list of aliases.
@@ -581,9 +571,7 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   static AliasListType Module::*getSublistAccess(GlobalAlias*) {
 return &Module::AliasList;
   }
-  friend class llvm::SymbolTableListTraits;
 
-public:
   /// Get the Module's list of ifuncs (constant).
   const IFuncListType&getIFuncList() const{ return IFuncList; }
   /// Get the Module's list of ifuncs.

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 2db5e7dc140aa..077b290fe0e00 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -1141,7 +1141,7 @@ bool LLParser::parseAliasOrIFunc(const std::string &Name, 
LocTy NameLoc,
 
   // Insert into the module, we know its name won't collide now.
   if (IsAlias)
-M->insertAlias(GA.release());
+M->getAliasList().push_back(GA.release());
   else
 M->getIFuncList().push_back(GI.release());
   assert(GV->getName() == Name && "Should not be a name conflict!");

diff  --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 7cf812c36984d..a7c45730ff46c 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -514,7 +514,7 @@ GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, 
LinkageTypes Link,
   AddressSpace) {
   setAliasee(Aliasee);
   if (ParentModule)
-ParentModule->insertAlias(this);
+ParentModule->getAliasList().push_back(this);
 }
 
 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
@@ -546,11 +546,11 @@ GlobalAlias *GlobalAlias::create(const Twine &Name, 
GlobalValue *Aliasee) {
 }
 
 void GlobalAlias::removeFromParent() {
-  getParent()->removeAlias(this);
+  getParent()->getAliasList().remove(getIterator());
 }
 
 void GlobalAlias::eraseFromParent() {
-  getParent()->eraseAlias(this);
+  getParent()->getAliasList().erase(getIterator());
 }
 
 void GlobalAlias::setAliasee(Constant *Aliasee) {

diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp 
b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 040701e243ce5..0317a8bcb6bc7 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2360,7 +2360,7 @@ OptimizeGlobalAliases(Module &M,
   continue;
 
 // Delete the alias.
-M.eraseAlias(&J);
+M.getAliasList().erase(&J);
 ++NumAliasesRemoved;
 Changed = true;
   }

diff  --git a/llvm/unittests/IR/ModuleTest.cpp 
b/llvm/unittests/IR/ModuleTest.cpp
index f9d682d87e7d1..4e2e394a92504 100644
--- a/llvm/unittests/IR/ModuleTest.cpp
+++ b/llvm/unittests/IR/ModuleTest.cpp
@@ -159,44 +159,4 @@ TEST(ModuleTest, setPartialSamp

[Lldb-commits] [lldb] afad153 - Recommit: [NFC][IR] Make Module::getAliasList() private

2023-02-13 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2023-02-13T20:07:56-08:00
New Revision: afad153a0890aadd1d239a4f8b94d201863c18f6

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

LOG: Recommit: [NFC][IR] Make Module::getAliasList() private

This reverts commit 6d4a674acbc56458bb084878d82d16e393d45a6b.

Added: 


Modified: 
lldb/source/Expression/IRExecutionUnit.cpp
llvm/include/llvm/IR/Module.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/unittests/IR/ModuleTest.cpp

Removed: 




diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index c8068eca5c1b5..73a49e552e3d2 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -410,7 +410,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 RegisterOneValue(global_var);
   }
 
-  for (llvm::GlobalAlias &global_alias : m_module->getAliasList()) {
+  for (llvm::GlobalAlias &global_alias : m_module->aliases()) {
 RegisterOneValue(global_alias);
   }
 

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index e86880406b7ea..920729f806660 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -563,6 +563,16 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 return &Module::FunctionList;
   }
 
+  /// Detach \p Alias from the list but don't delete it.
+  void removeAlias(GlobalAlias *Alias) { AliasList.remove(Alias); }
+  /// Remove \p Alias from the list and delete it.
+  void eraseAlias(GlobalAlias *Alias) { AliasList.erase(Alias); }
+  /// Insert \p Alias at the end of the alias list and take ownership.
+  void insertAlias(GlobalAlias *Alias) { AliasList.insert(AliasList.end(), 
Alias); }
+  // Use alias_size() to get the size of AliasList.
+  // Use aliases() to get a range of all Alias objects in AliasList.
+
+private: // Please use functions like insertAlias(), removeAlias() etc.
   /// Get the Module's list of aliases (constant).
   const AliasListType&getAliasList() const{ return AliasList; }
   /// Get the Module's list of aliases.
@@ -571,7 +581,9 @@ class LLVM_EXTERNAL_VISIBILITY Module {
   static AliasListType Module::*getSublistAccess(GlobalAlias*) {
 return &Module::AliasList;
   }
+  friend class llvm::SymbolTableListTraits;
 
+public:
   /// Get the Module's list of ifuncs (constant).
   const IFuncListType&getIFuncList() const{ return IFuncList; }
   /// Get the Module's list of ifuncs.

diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 077b290fe0e00..2db5e7dc140aa 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -1141,7 +1141,7 @@ bool LLParser::parseAliasOrIFunc(const std::string &Name, 
LocTy NameLoc,
 
   // Insert into the module, we know its name won't collide now.
   if (IsAlias)
-M->getAliasList().push_back(GA.release());
+M->insertAlias(GA.release());
   else
 M->getIFuncList().push_back(GI.release());
   assert(GV->getName() == Name && "Should not be a name conflict!");

diff  --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index a7c45730ff46c..7cf812c36984d 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -514,7 +514,7 @@ GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, 
LinkageTypes Link,
   AddressSpace) {
   setAliasee(Aliasee);
   if (ParentModule)
-ParentModule->getAliasList().push_back(this);
+ParentModule->insertAlias(this);
 }
 
 GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
@@ -546,11 +546,11 @@ GlobalAlias *GlobalAlias::create(const Twine &Name, 
GlobalValue *Aliasee) {
 }
 
 void GlobalAlias::removeFromParent() {
-  getParent()->getAliasList().remove(getIterator());
+  getParent()->removeAlias(this);
 }
 
 void GlobalAlias::eraseFromParent() {
-  getParent()->getAliasList().erase(getIterator());
+  getParent()->eraseAlias(this);
 }
 
 void GlobalAlias::setAliasee(Constant *Aliasee) {

diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp 
b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 0317a8bcb6bc7..040701e243ce5 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2360,7 +2360,7 @@ OptimizeGlobalAliases(Module &M,
   continue;
 
 // Delete the alias.
-M.getAliasList().erase(&J);
+M.eraseAlias(&J);
 ++NumAliasesRemoved;
 Changed = true;
   }

diff  --git a/llvm/unittests/IR/ModuleTest.cpp 
b/llvm/unittests/IR/ModuleTest.cpp
index 4e2e394a92504..f9d682d87e7d1 100644
--- a/llvm/unittests/IR/ModuleTest.cpp
+++ b/llvm/unittests/IR/ModuleTest.cpp
@@ -159,4 +159,44 @@ TEST(ModuleTest, setPartialSample

[Lldb-commits] [lldb] ed3e3ee - [NFC][IR] Make Module::getGlobalList() private

2023-02-14 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2023-02-14T14:25:10-08:00
New Revision: ed3e3ee9e30dfbffd2170a770a49b36a7f444916

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

LOG: [NFC][IR] Make Module::getGlobalList() private

This patch adds several missing GlobalList modifier functions, like
removeGlobalVariable(), eraseGlobalVariable() and insertGlobalVariable().
There is no longer need to access the list directly so it also makes
getGlobalList() private.

Differential Revision: https://reviews.llvm.org/D144027

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGObjCMac.cpp
lldb/source/Expression/IRExecutionUnit.cpp
llvm/docs/ProgrammersManual.rst
llvm/include/llvm/IR/Module.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/Linker/IRMover.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/lib/Transforms/IPO/SCCP.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/lib/Transforms/Utils/CtorUtils.cpp
llvm/unittests/IR/ModuleTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5882f491d5972..e9fa273f21cc8 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -175,7 +175,7 @@ void CGHLSLRuntime::finishCodeGen() {
   for (auto &Buf : Buffers) {
 layoutBuffer(Buf, DL);
 GlobalVariable *GV = replaceBuffer(Buf);
-M.getGlobalList().push_back(GV);
+M.insertGlobalVariable(GV);
 llvm::hlsl::ResourceClass RC = Buf.IsCBuffer
? llvm::hlsl::ResourceClass::CBuffer
: llvm::hlsl::ResourceClass::SRV;

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index c739d3742f801..5f4cdc6d91f1d 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -7431,7 +7431,7 @@ CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name,
   GV->eraseFromParent();
 }
 GV = NewGV;
-CGM.getModule().getGlobalList().push_back(GV);
+CGM.getModule().insertGlobalVariable(GV);
   }
 
   assert(GV->getLinkage() == L);

diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index 73a49e552e3d2..f3cf0f623d24f 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -406,7 +406,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 }
   };
 
-  for (llvm::GlobalVariable &global_var : m_module->getGlobalList()) {
+  for (llvm::GlobalVariable &global_var : m_module->globals()) {
 RegisterOneValue(global_var);
   }
 

diff  --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst
index 00d51a5a05b85..71298f4a87828 100644
--- a/llvm/docs/ProgrammersManual.rst
+++ b/llvm/docs/ProgrammersManual.rst
@@ -3429,17 +3429,14 @@ Important Public Members of the ``Module`` class
 
 * | ``Module::global_iterator`` - Typedef for global variable list iterator
   | ``Module::const_global_iterator`` - Typedef for const_iterator.
+  | ``Module::insertGlobalVariable()`` - Inserts a global variable to the list.
+  | ``Module::removeGlobalVariable()`` - Removes a global variable frome the 
list.
+  | ``Module::eraseGlobalVariable()`` - Removes a global variable frome the 
list and deletes it.
   | ``global_begin()``, ``global_end()``, ``global_size()``, ``global_empty()``
 
   These are forwarding methods that make it easy to access the contents of a
   ``Module`` object's GlobalVariable_ list.
 
-* ``Module::GlobalListType &getGlobalList()``
-
-  Returns the list of GlobalVariable_\ s.  This is necessary to use when you
-  need to update the list or perform a complex action that doesn't have a
-  forwarding method.
-
 
 
 * ``SymbolTable *getSymbolTable()``

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index dbd3eae0f134c..aacdbbf08b945 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -542,6 +542,24 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 
   llvm::Error materializeMetadata();
 
+  /// Detach global variable \p GV from the list but don't delete it.
+  void removeGlobalVariable(GlobalVariable *GV) { GlobalList.remove(GV); }
+  /// Remove global variable \p GV from the list and delete it.
+  void eraseGlobalVariable(GlobalVariable *GV) { GlobalList.erase(GV); }
+  /// Insert global variable \p GV at the end of the global variable list and
+  /// take ownership.
+  void insertGlobalVariable(GlobalVariable *GV) {
+insertGlobalVariable(GlobalList.end(), GV);
+  }

[Lldb-commits] [lldb] cb5f239 - Revert "[NFC][IR] Make Module::getGlobalList() private"

2023-02-14 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2023-02-14T14:29:42-08:00
New Revision: cb5f239363a3c94db5425c105fcd45e77d2a16a9

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

LOG: Revert "[NFC][IR] Make Module::getGlobalList() private"

This reverts commit ed3e3ee9e30dfbffd2170a770a49b36a7f444916.

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGObjCMac.cpp
lldb/source/Expression/IRExecutionUnit.cpp
llvm/docs/ProgrammersManual.rst
llvm/include/llvm/IR/Module.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/Linker/IRMover.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/lib/Transforms/IPO/SCCP.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/lib/Transforms/Utils/CtorUtils.cpp
llvm/unittests/IR/ModuleTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index e9fa273f21cc8..5882f491d5972 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -175,7 +175,7 @@ void CGHLSLRuntime::finishCodeGen() {
   for (auto &Buf : Buffers) {
 layoutBuffer(Buf, DL);
 GlobalVariable *GV = replaceBuffer(Buf);
-M.insertGlobalVariable(GV);
+M.getGlobalList().push_back(GV);
 llvm::hlsl::ResourceClass RC = Buf.IsCBuffer
? llvm::hlsl::ResourceClass::CBuffer
: llvm::hlsl::ResourceClass::SRV;

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 5f4cdc6d91f1d..c739d3742f801 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -7431,7 +7431,7 @@ CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name,
   GV->eraseFromParent();
 }
 GV = NewGV;
-CGM.getModule().insertGlobalVariable(GV);
+CGM.getModule().getGlobalList().push_back(GV);
   }
 
   assert(GV->getLinkage() == L);

diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index f3cf0f623d24f..73a49e552e3d2 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -406,7 +406,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 }
   };
 
-  for (llvm::GlobalVariable &global_var : m_module->globals()) {
+  for (llvm::GlobalVariable &global_var : m_module->getGlobalList()) {
 RegisterOneValue(global_var);
   }
 

diff  --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst
index 71298f4a87828..00d51a5a05b85 100644
--- a/llvm/docs/ProgrammersManual.rst
+++ b/llvm/docs/ProgrammersManual.rst
@@ -3429,14 +3429,17 @@ Important Public Members of the ``Module`` class
 
 * | ``Module::global_iterator`` - Typedef for global variable list iterator
   | ``Module::const_global_iterator`` - Typedef for const_iterator.
-  | ``Module::insertGlobalVariable()`` - Inserts a global variable to the list.
-  | ``Module::removeGlobalVariable()`` - Removes a global variable frome the 
list.
-  | ``Module::eraseGlobalVariable()`` - Removes a global variable frome the 
list and deletes it.
   | ``global_begin()``, ``global_end()``, ``global_size()``, ``global_empty()``
 
   These are forwarding methods that make it easy to access the contents of a
   ``Module`` object's GlobalVariable_ list.
 
+* ``Module::GlobalListType &getGlobalList()``
+
+  Returns the list of GlobalVariable_\ s.  This is necessary to use when you
+  need to update the list or perform a complex action that doesn't have a
+  forwarding method.
+
 
 
 * ``SymbolTable *getSymbolTable()``

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index aacdbbf08b945..dbd3eae0f134c 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -542,24 +542,6 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 
   llvm::Error materializeMetadata();
 
-  /// Detach global variable \p GV from the list but don't delete it.
-  void removeGlobalVariable(GlobalVariable *GV) { GlobalList.remove(GV); }
-  /// Remove global variable \p GV from the list and delete it.
-  void eraseGlobalVariable(GlobalVariable *GV) { GlobalList.erase(GV); }
-  /// Insert global variable \p GV at the end of the global variable list and
-  /// take ownership.
-  void insertGlobalVariable(GlobalVariable *GV) {
-insertGlobalVariable(GlobalList.end(), GV);
-  }
-  /// Insert global variable \p GV into the global variable list before \p
-  /// Where and take ownership.
-  void insertGlobalVariable(GlobalListType::iterator Where, GlobalVariable 
*GV) {
-GlobalList.insert(Where,

[Lldb-commits] [lldb] 823186b - Recommit: [NFC][IR] Make Module::getGlobalList() private

2023-02-14 Thread Vasileios Porpodas via lldb-commits

Author: Vasileios Porpodas
Date: 2023-02-14T15:12:51-08:00
New Revision: 823186b14dc97c950a808f6f4b434d399da9a220

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

LOG: Recommit: [NFC][IR] Make Module::getGlobalList() private

This reverts commit cb5f239363a3c94db5425c105fcd45e77d2a16a9.

Added: 


Modified: 
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGObjCMac.cpp
lldb/source/Expression/IRExecutionUnit.cpp
llvm/docs/ProgrammersManual.rst
llvm/include/llvm/IR/Module.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/IR/Globals.cpp
llvm/lib/Linker/IRMover.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/lib/Transforms/IPO/SCCP.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/lib/Transforms/Utils/CtorUtils.cpp
llvm/unittests/IR/ModuleTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 5882f491d5972..e9fa273f21cc8 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -175,7 +175,7 @@ void CGHLSLRuntime::finishCodeGen() {
   for (auto &Buf : Buffers) {
 layoutBuffer(Buf, DL);
 GlobalVariable *GV = replaceBuffer(Buf);
-M.getGlobalList().push_back(GV);
+M.insertGlobalVariable(GV);
 llvm::hlsl::ResourceClass RC = Buf.IsCBuffer
? llvm::hlsl::ResourceClass::CBuffer
: llvm::hlsl::ResourceClass::SRV;

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index c739d3742f801..5f4cdc6d91f1d 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -7431,7 +7431,7 @@ CGObjCNonFragileABIMac::GetClassGlobal(StringRef Name,
   GV->eraseFromParent();
 }
 GV = NewGV;
-CGM.getModule().getGlobalList().push_back(GV);
+CGM.getModule().insertGlobalVariable(GV);
   }
 
   assert(GV->getLinkage() == L);

diff  --git a/lldb/source/Expression/IRExecutionUnit.cpp 
b/lldb/source/Expression/IRExecutionUnit.cpp
index 73a49e552e3d2..f3cf0f623d24f 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -406,7 +406,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, 
lldb::addr_t &func_addr,
 }
   };
 
-  for (llvm::GlobalVariable &global_var : m_module->getGlobalList()) {
+  for (llvm::GlobalVariable &global_var : m_module->globals()) {
 RegisterOneValue(global_var);
   }
 

diff  --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst
index 00d51a5a05b85..71298f4a87828 100644
--- a/llvm/docs/ProgrammersManual.rst
+++ b/llvm/docs/ProgrammersManual.rst
@@ -3429,17 +3429,14 @@ Important Public Members of the ``Module`` class
 
 * | ``Module::global_iterator`` - Typedef for global variable list iterator
   | ``Module::const_global_iterator`` - Typedef for const_iterator.
+  | ``Module::insertGlobalVariable()`` - Inserts a global variable to the list.
+  | ``Module::removeGlobalVariable()`` - Removes a global variable frome the 
list.
+  | ``Module::eraseGlobalVariable()`` - Removes a global variable frome the 
list and deletes it.
   | ``global_begin()``, ``global_end()``, ``global_size()``, ``global_empty()``
 
   These are forwarding methods that make it easy to access the contents of a
   ``Module`` object's GlobalVariable_ list.
 
-* ``Module::GlobalListType &getGlobalList()``
-
-  Returns the list of GlobalVariable_\ s.  This is necessary to use when you
-  need to update the list or perform a complex action that doesn't have a
-  forwarding method.
-
 
 
 * ``SymbolTable *getSymbolTable()``

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index dbd3eae0f134c..aacdbbf08b945 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -542,6 +542,24 @@ class LLVM_EXTERNAL_VISIBILITY Module {
 
   llvm::Error materializeMetadata();
 
+  /// Detach global variable \p GV from the list but don't delete it.
+  void removeGlobalVariable(GlobalVariable *GV) { GlobalList.remove(GV); }
+  /// Remove global variable \p GV from the list and delete it.
+  void eraseGlobalVariable(GlobalVariable *GV) { GlobalList.erase(GV); }
+  /// Insert global variable \p GV at the end of the global variable list and
+  /// take ownership.
+  void insertGlobalVariable(GlobalVariable *GV) {
+insertGlobalVariable(GlobalList.end(), GV);
+  }
+  /// Insert global variable \p GV into the global variable list before \p
+  /// Where and take ownership.
+  void insertGlobalVariable(GlobalListType::iterator Where, GlobalVariable 
*GV) {
+GlobalList.insert(Where