From dac9131e281a2e7032aa2520d32336a25b947b1d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 21 Oct 2003 14:49:19 +0000 Subject: [PATCH] Preselection is _not_ a basicblock pass, because it adds global variables to the module. This change converts it from being a basic block pass to being a simple pass. This allows elimination of the annotation and simplification of the logic for moving constants into global variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9320 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/SparcV9/SparcV9PreSelection.cpp | 123 ++++----------------- 1 file changed, 22 insertions(+), 101 deletions(-) diff --git a/lib/Target/SparcV9/SparcV9PreSelection.cpp b/lib/Target/SparcV9/SparcV9PreSelection.cpp index 6f17b52b0a0..1ab71b66f58 100644 --- a/lib/Target/SparcV9/SparcV9PreSelection.cpp +++ b/lib/Target/SparcV9/SparcV9PreSelection.cpp @@ -27,125 +27,48 @@ #include "llvm/iOther.h" #include "llvm/DerivedTypes.h" #include "llvm/Pass.h" -#include "Support/CommandLine.h" #include namespace { - //===--------------------------------------------------------------------===// - // SelectDebugLevel - Allow command line control over debugging. - // - enum PreSelectDebugLevel_t { - PreSelect_NoDebugInfo, - PreSelect_PrintOutput, - }; - - // Enable Debug Options to be specified on the command line - cl::opt - PreSelectDebugLevel("dpreselect", cl::Hidden, - cl::desc("debug information for target-dependent pre-selection"), - cl::values( - clEnumValN(PreSelect_NoDebugInfo, "n", "disable debug output (default)"), - clEnumValN(PreSelect_PrintOutput, "y", "print generated machine code"), - /* default level = */ PreSelect_NoDebugInfo)); - //===--------------------------------------------------------------------===// - // class ConstantPoolForModule: - // - // The pool of constants that must be emitted for a module. - // This is a single pool for the entire module and is shared by - // all invocations of the PreSelection pass for this module by putting - // this as an annotation on the Module object. - // A single GlobalVariable is created for each constant in the pool - // representing the memory for that constant. + // PreSelection Pass - Specialize LLVM code for the current target machine. // - AnnotationID CPFM_AID( - AnnotationManager::getID("CodeGen::ConstantPoolForModule")); + class PreSelection : public Pass, public InstVisitor { + const TargetInstrInfo &instrInfo; + Module *TheModule; - class ConstantPoolForModule : private Annotation { - Module* myModule; std::map gvars; - std::map origGVars; - ConstantPoolForModule(Module* M); // called only by annotation builder - ConstantPoolForModule(); // DO NOT IMPLEMENT - void operator=(const ConstantPoolForModule&); // DO NOT IMPLEMENT - public: - static ConstantPoolForModule& get(Module* M) { - ConstantPoolForModule* cpool = - (ConstantPoolForModule*) M->getAnnotation(CPFM_AID); - if (cpool == NULL) // create a new annotation and add it to the Module - M->addAnnotation(cpool = new ConstantPoolForModule(M)); - return *cpool; - } GlobalVariable* getGlobalForConstant(Constant* CV) { std::map::iterator I = gvars.find(CV); - if (I != gvars.end()) - return I->second; // global exists so return it - return addToConstantPool(CV); // create a new global and return it - } + if (I != gvars.end()) return I->second; // global exists so return it - GlobalVariable* addToConstantPool(Constant* CV) { - GlobalVariable*& GV = gvars[CV]; // handle to global var entry in map - if (GV == NULL) - { // check if a global constant already existed; otherwise create one - std::map::iterator PI = - origGVars.find(CV); - if (PI != origGVars.end()) - GV = PI->second; // put in map - else - { - GV = new GlobalVariable(CV->getType(), true, //put in map - GlobalValue::InternalLinkage, CV); - myModule->getGlobalList().push_back(GV); // GV owned by module now - } - } - return GV; + return I->second = new GlobalVariable(CV->getType(), true, + GlobalValue::InternalLinkage, CV, + "immcst", TheModule); } - }; - /* ctor */ - ConstantPoolForModule::ConstantPoolForModule(Module* M) - : Annotation(CPFM_AID), myModule(M) - { - // Build reverse map for pre-existing global constants so we can find them - for (Module::giterator GI = M->gbegin(), GE = M->gend(); GI != GE; ++GI) - if (GI->hasInitializer() && GI->isConstant()) - origGVars[GI->getInitializer()] = GI; - } + public: + PreSelection(const TargetMachine &T) + : instrInfo(T.getInstrInfo()), TheModule(0) {} - //===--------------------------------------------------------------------===// - // PreSelection Pass - Specialize LLVM code for the current target machine. - // - class PreSelection : public BasicBlockPass, public InstVisitor - { - const TargetMachine ⌖ - const TargetInstrInfo &instrInfo; - Function* function; + // runOnBasicBlock - apply this pass to each BB + bool run(Module &M) { + TheModule = &M; - GlobalVariable* getGlobalForConstant(Constant* CV) { - Module* M = function->getParent(); - return ConstantPoolForModule::get(M).getGlobalForConstant(CV); - } + // Build reverse map for pre-existing global constants so we can find them + for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I) + if (I->hasInitializer() && I->isConstant()) + gvars[I->getInitializer()] = I; - public: - PreSelection (const TargetMachine &T): - target(T), instrInfo(T.getInstrInfo()), function(NULL) {} + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + visit(*I); - // runOnBasicBlock - apply this pass to each BB - bool runOnBasicBlock(BasicBlock &BB) { - function = BB.getParent(); - this->visit(BB); + gvars.clear(); return true; } - bool doFinalization(Function &F) { - if (PreSelectDebugLevel >= PreSelect_PrintOutput) - std::cerr << "\n\n*** LLVM code after pre-selection for function " - << F.getName() << ":\n\n" << F; - return false; - } - // These methods do the actual work of specializing code void visitInstruction(Instruction &I); // common work for every instr. void visitGetElementPtrInst(GetElementPtrInst &I); @@ -357,9 +280,7 @@ PreSelection::visitCallInst(CallInst &I) // createPreSelectionPass - Public entrypoint for pre-selection pass // and this file as a whole... // -Pass* -createPreSelectionPass(TargetMachine &T) -{ +Pass* createPreSelectionPass(TargetMachine &T) { return new PreSelection(T); } -- 2.34.1