003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/Transforms/IPO
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
Transforms
/
IPO
/
📁
..
📄
AlwaysInliner.cpp
(6.51 KB)
📄
ArgumentPromotion.cpp
(44.76 KB)
📄
Attributor.cpp
(81.04 KB)
📄
AttributorAttributes.cpp
(269.7 KB)
📄
BarrierNoopPass.cpp
(1.67 KB)
📄
BlockExtractor.cpp
(8.17 KB)
📄
CalledValuePropagation.cpp
(17.71 KB)
📄
ConstantMerge.cpp
(9.59 KB)
📄
CrossDSOCFI.cpp
(5.98 KB)
📄
DeadArgumentElimination.cpp
(42.84 KB)
📄
ElimAvailExtern.cpp
(3.14 KB)
📄
ExtractGV.cpp
(5.2 KB)
📄
ForceFunctionAttrs.cpp
(4.79 KB)
📄
FunctionAttrs.cpp
(55.56 KB)
📄
FunctionImport.cpp
(55.28 KB)
📄
GlobalDCE.cpp
(15.55 KB)
📄
GlobalOpt.cpp
(119.78 KB)
📄
GlobalSplit.cpp
(6.92 KB)
📄
HotColdSplitting.cpp
(26.27 KB)
📄
IPConstantPropagation.cpp
(10.68 KB)
📄
IPO.cpp
(4.94 KB)
📄
InferFunctionAttrs.cpp
(2.89 KB)
📄
InlineSimple.cpp
(4.21 KB)
📄
Inliner.cpp
(44.77 KB)
📄
Internalize.cpp
(9.52 KB)
📄
LoopExtractor.cpp
(7.14 KB)
📄
LowerTypeTests.cpp
(83.98 KB)
📄
MergeFunctions.cpp
(34.12 KB)
📄
OpenMPOpt.cpp
(52.75 KB)
📄
PartialInlining.cpp
(55.67 KB)
📄
PassManagerBuilder.cpp
(49.21 KB)
📄
PruneEH.cpp
(9.54 KB)
📄
SCCP.cpp
(3.22 KB)
📄
SampleProfile.cpp
(77.15 KB)
📄
StripDeadPrototypes.cpp
(2.73 KB)
📄
StripSymbols.cpp
(11.7 KB)
📄
SyntheticCountsPropagation.cpp
(5.64 KB)
📄
ThinLTOBitcodeWriter.cpp
(20.16 KB)
📄
WholeProgramDevirt.cpp
(85.02 KB)
Editing: ExtractGV.cpp
//===-- ExtractGV.cpp - Global Value extraction pass ----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This pass extracts global values // //===----------------------------------------------------------------------===// #include "llvm/ADT/SetVector.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Pass.h" #include "llvm/Transforms/IPO.h" #include <algorithm> using namespace llvm; /// Make sure GV is visible from both modules. Delete is true if it is /// being deleted from this module. /// This also makes sure GV cannot be dropped so that references from /// the split module remain valid. static void makeVisible(GlobalValue &GV, bool Delete) { bool Local = GV.hasLocalLinkage(); if (Local || Delete) { GV.setLinkage(GlobalValue::ExternalLinkage); if (Local) GV.setVisibility(GlobalValue::HiddenVisibility); return; } if (!GV.hasLinkOnceLinkage()) { assert(!GV.isDiscardableIfUnused()); return; } // Map linkonce* to weak* so that llvm doesn't drop this GV. switch(GV.getLinkage()) { default: llvm_unreachable("Unexpected linkage"); case GlobalValue::LinkOnceAnyLinkage: GV.setLinkage(GlobalValue::WeakAnyLinkage); return; case GlobalValue::LinkOnceODRLinkage: GV.setLinkage(GlobalValue::WeakODRLinkage); return; } } namespace { /// A pass to extract specific global values and their dependencies. class GVExtractorPass : public ModulePass { SetVector<GlobalValue *> Named; bool deleteStuff; bool keepConstInit; public: static char ID; // Pass identification, replacement for typeid /// If deleteS is true, this pass deletes the specified global values. /// Otherwise, it deletes as much of the module as possible, except for the /// global values specified. explicit GVExtractorPass(std::vector<GlobalValue*> &GVs, bool deleteS = true, bool keepConstInit = false) : ModulePass(ID), Named(GVs.begin(), GVs.end()), deleteStuff(deleteS), keepConstInit(keepConstInit) {} bool runOnModule(Module &M) override { if (skipModule(M)) return false; // Visit the global inline asm. if (!deleteStuff) M.setModuleInlineAsm(""); // For simplicity, just give all GlobalValues ExternalLinkage. A trickier // implementation could figure out which GlobalValues are actually // referenced by the Named set, and which GlobalValues in the rest of // the module are referenced by the NamedSet, and get away with leaving // more internal and private things internal and private. But for now, // be conservative and simple. // Visit the GlobalVariables. for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { bool Delete = deleteStuff == (bool)Named.count(&*I) && !I->isDeclaration() && (!I->isConstant() || !keepConstInit); if (!Delete) { if (I->hasAvailableExternallyLinkage()) continue; if (I->getName() == "llvm.global_ctors") continue; } makeVisible(*I, Delete); if (Delete) { // Make this a declaration and drop it's comdat. I->setInitializer(nullptr); I->setComdat(nullptr); } } // Visit the Functions. for (Function &F : M) { bool Delete = deleteStuff == (bool)Named.count(&F) && !F.isDeclaration(); if (!Delete) { if (F.hasAvailableExternallyLinkage()) continue; } makeVisible(F, Delete); if (Delete) { // Make this a declaration and drop it's comdat. F.deleteBody(); F.setComdat(nullptr); } } // Visit the Aliases. for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) { Module::alias_iterator CurI = I; ++I; bool Delete = deleteStuff == (bool)Named.count(&*CurI); makeVisible(*CurI, Delete); if (Delete) { Type *Ty = CurI->getValueType(); CurI->removeFromParent(); llvm::Value *Declaration; if (FunctionType *FTy = dyn_cast<FunctionType>(Ty)) { Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, CurI->getAddressSpace(), CurI->getName(), &M); } else { Declaration = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, nullptr, CurI->getName()); } CurI->replaceAllUsesWith(Declaration); delete &*CurI; } } return true; } }; char GVExtractorPass::ID = 0; } ModulePass *llvm::createGVExtractionPass(std::vector<GlobalValue *> &GVs, bool deleteFn, bool keepConstInit) { return new GVExtractorPass(GVs, deleteFn, keepConstInit); }
Upload File
Create Folder