[llvm] r187098 - Make these methods const correct.
Rafael Espindola
rafael.espindola at gmail.com
Wed Jul 24 19:50:08 PDT 2013
Author: rafael
Date: Wed Jul 24 21:50:08 2013
New Revision: 187098
URL: http://llvm.org/viewvc/llvm-project?rev=187098&view=rev
Log:
Make these methods const correct.
Thanks to Nick Lewycky for noticing it.
Modified:
llvm/trunk/include/llvm/IR/Module.h
llvm/trunk/lib/IR/Module.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Modified: llvm/trunk/include/llvm/IR/Module.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Module.h?rev=187098&r1=187097&r2=187098&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Module.h (original)
+++ llvm/trunk/include/llvm/IR/Module.h Wed Jul 24 21:50:08 2013
@@ -352,15 +352,22 @@ public:
/// symbol table. If it does not exist, return null. If AllowInternal is set
/// to true, this function will return types that have InternalLinkage. By
/// default, these types are not returned.
- GlobalVariable *getGlobalVariable(StringRef Name,
- bool AllowInternal = false) const;
+ const GlobalVariable *getGlobalVariable(StringRef Name,
+ bool AllowInternal = false) const {
+ return const_cast<Module *>(this)->getGlobalVariable(Name, AllowInternal);
+ }
+
+ GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal = false);
/// getNamedGlobal - Return the global variable in the module with the
/// specified name, of arbitrary type. This method returns null if a global
/// with the specified name is not found.
- GlobalVariable *getNamedGlobal(StringRef Name) const {
+ GlobalVariable *getNamedGlobal(StringRef Name) {
return getGlobalVariable(Name, true);
}
+ const GlobalVariable *getNamedGlobal(StringRef Name) const {
+ return const_cast<Module *>(this)->getNamedGlobal(Name);
+ }
/// getOrInsertGlobal - Look up the specified global in the module symbol
/// table.
Modified: llvm/trunk/lib/IR/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Module.cpp?rev=187098&r1=187097&r2=187098&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Module.cpp (original)
+++ llvm/trunk/lib/IR/Module.cpp Wed Jul 24 21:50:08 2013
@@ -233,8 +233,7 @@ Function *Module::getFunction(StringRef
/// If AllowLocal is set to true, this function will return types that
/// have an local. By default, these types are not returned.
///
-GlobalVariable *Module::getGlobalVariable(StringRef Name,
- bool AllowLocal) const {
+GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) {
if (GlobalVariable *Result =
dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
if (AllowLocal || !Result->hasLocalLinkage())
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=187098&r1=187097&r2=187098&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Wed Jul 24 21:50:08 2013
@@ -3043,7 +3043,7 @@ bool GlobalOpt::OptimizeGlobalCtorsList(
/// \brief Given "llvm.used" or "llvm.compiler.used" as a global name, collect
/// the initializer elements of that global in Set and return the global itself.
static GlobalVariable *
-collectUsedGlobalVariables(const Module &M, const char *Name,
+collectUsedGlobalVariables(Module &M, const char *Name,
SmallPtrSet<GlobalValue *, 8> &Set) {
GlobalVariable *GV = M.getGlobalVariable(Name);
if (!GV || !GV->hasInitializer())
@@ -3106,7 +3106,7 @@ class LLVMUsed {
GlobalVariable *CompilerUsedV;
public:
- LLVMUsed(const Module &M) {
+ LLVMUsed(Module &M) {
UsedV = collectUsedGlobalVariables(M, "llvm.used", Used);
CompilerUsedV =
collectUsedGlobalVariables(M, "llvm.compiler.used", CompilerUsed);
More information about the llvm-commits
mailing list