Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
ElimAvailExtern.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "elim-avail-extern"

Functions

 STATISTIC (NumRemovals, "Number of functions removed")
 STATISTIC (NumFunctionsConverted, "Number of functions converted")
 STATISTIC (NumGlobalVariablesConverted, "Number of global variables converted")
 STATISTIC (NumVariables, "Number of global variables removed")
void deleteFunction (Function &F)
static std::string getNewName (Module &M, const GlobalValue &GV)
static void convertToLocalCopy (Module &M, Function &F)
 Create a copy of the thinlto import, mark it local, and redirect direct calls to the copy.
static void convertToLocalCopy (Module &M, GlobalVariable &GV)
 Similar to the function above, this is to convert an externally available global variable to local.
static bool eliminateAvailableExternally (Module &M, bool Convert)

Variables

static cl::opt< boolConvertToLocal ("avail-extern-to-local", cl::Hidden, cl::desc("Convert available_externally into locals, renaming them " "to avoid link-time clashes."))
static cl::opt< unsignedConvertGlobalVariableInAddrSpace ("avail-extern-gv-in-addrspace-to-local", cl::Hidden, cl::desc("Convert available_externally global variables into locals if they are " "in specificed addrspace, renaming them to avoid link-time clashes."))

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "elim-avail-extern"

Definition at line 31 of file ElimAvailExtern.cpp.

Function Documentation

◆ convertToLocalCopy() [1/2]

void convertToLocalCopy ( Module & M,
Function & F )
static

Create a copy of the thinlto import, mark it local, and redirect direct calls to the copy.

Only direct calls are replaced, so that e.g. indirect call function pointer tests would use the global identity of the function.

Currently, Value Profiling ("VP") MD_prof data isn't updated to refer to the clone's GUID (which will be different, because the name and linkage is different), under the assumption that the last consumer of this data is upstream the pipeline (e.g. ICP).

Definition at line 71 of file ElimAvailExtern.cpp.

References assert(), llvm::Function::Create(), deleteFunction(), llvm::GlobalValue::ExternalLinkage, F, llvm::find_if(), llvm::MDString::get(), getNewName(), llvm::GlobalValue::InternalLinkage, and llvm::isa().

Referenced by eliminateAvailableExternally().

◆ convertToLocalCopy() [2/2]

void convertToLocalCopy ( Module & M,
GlobalVariable & GV )
static

Similar to the function above, this is to convert an externally available global variable to local.

Definition at line 108 of file ElimAvailExtern.cpp.

References assert(), getNewName(), llvm::GlobalValue::hasAvailableExternallyLinkage(), llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::setLinkage(), and llvm::Value::setName().

◆ deleteFunction()

void deleteFunction ( Function & F)

Definition at line 53 of file ElimAvailExtern.cpp.

References F.

Referenced by convertToLocalCopy(), and eliminateAvailableExternally().

◆ eliminateAvailableExternally()

◆ getNewName()

std::string getNewName ( Module & M,
const GlobalValue & GV )
static

◆ STATISTIC() [1/4]

STATISTIC ( NumFunctionsConverted ,
"Number of functions converted"  )

◆ STATISTIC() [2/4]

STATISTIC ( NumGlobalVariablesConverted ,
"Number of global variables converted"  )

◆ STATISTIC() [3/4]

STATISTIC ( NumRemovals ,
"Number of functions removed"  )

◆ STATISTIC() [4/4]

STATISTIC ( NumVariables ,
"Number of global variables removed"  )

Variable Documentation

◆ ConvertGlobalVariableInAddrSpace

cl::opt< unsigned > ConvertGlobalVariableInAddrSpace("avail-extern-gv-in-addrspace-to-local", cl::Hidden, cl::desc( "Convert available_externally global variables into locals if they are " "in specificed addrspace, renaming them to avoid link-time clashes.")) ( "avail-extern-gv-in-addrspace-to-local" ,
cl::Hidden ,
cl::desc( "Convert available_externally global variables into locals if they are " "in specificed addrspace, renaming them to avoid link-time clashes.")  )
static

◆ ConvertToLocal

cl::opt< bool > ConvertToLocal("avail-extern-to-local", cl::Hidden, cl::desc("Convert available_externally into locals, renaming them " "to avoid link-time clashes.")) ( "avail-extern-to-local" ,
cl::Hidden ,
cl::desc("Convert available_externally into locals, renaming them " "to avoid link-time clashes.")  )
static