OpenASIP  2.0
MachineDCE.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012-2020 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file MachineDCE.hh
26  *
27  * Declaration of MachineDCE class.
28  *
29  * @author Mikael Lepistö
30  */
31 
32 #include "CompilerWarnings.hh"
33 
34 IGNORE_COMPILER_WARNING("-Wunused-parameter")
35 IGNORE_COMPILER_WARNING("-Wcomment")
36 
37 #include "llvm/Analysis/CFG.h"
38 #include "llvm/CodeGen/Passes.h"
39 #include "tce_config.h"
40 #include "llvm/IR/Module.h"
41 #include "llvm/IR/Constant.h"
42 #include "llvm/IR/Constants.h"
43 #include "llvm/IR/Instructions.h"
44 #include "llvm/IR/Function.h"
45 #include "llvm/IR/Type.h"
46 #include "llvm/Pass.h"
47 #include "llvm/CodeGen/MachineFunctionPass.h"
48 #include "llvm/CodeGen/MachineRegisterInfo.h"
49 
50 #include "llvm/Support/Compiler.h"
51 #include "llvm/CodeGen/TargetInstrInfo.h"
52 #include "llvm/ADT/DepthFirstIterator.h"
53 #include "llvm/Analysis/CallGraph.h"
54 #include "llvm/Analysis/AliasAnalysis.h"
55 #include "llvm/Analysis/Passes.h"
56 #include "llvm/Support/Debug.h"
57 #include "llvm/Support/raw_ostream.h"
58 
59 #include "llvm/ADT/StringMap.h"
60 
62 
63 #include <map>
64 
65 namespace llvm {
66  struct MachineDCE : public MachineFunctionPass {
67  static char ID;
68  MachineDCE() : MachineFunctionPass(ID) {}
69  typedef std::map<std::string, MachineFunction*> FunctionMap;
70  typedef std::set<std::string> UserList;
71  typedef std::map<std::string, UserList> UserRelations;
72  typedef std::set<const std::string*> AvoidRecursionSet;
73 
74  /// Function name to MachineFunction map.
76 
77  /// List of users of a symbol.
79 
80  /// If users are traced to this list it means that function
81  /// cannot be eliminated.
83 
84  virtual bool doInitialization(Module &M) override;
85  virtual bool runOnMachineFunction(MachineFunction &F) override;
86  virtual bool doFinalization(Module &M) override;
87 
88  virtual StringRef getPassName() const override {
89  return "TCE deadcode elimination of unused emulation functions";
90  }
91 
92  bool canFindStart(const std::string& user, AvoidRecursionSet& avoid_recursion);
93  void addInitializer(const Constant* init, std::string& name);
94 
95  public:
96  typedef std::set<std::string> UnusedFunctionsList;
98  };
99 }
llvm::MachineDCE::doFinalization
virtual bool doFinalization(Module &M) override
Definition: MachineDCE.cc:185
llvm
Definition: InlineAsmParser.hh:49
llvm::MachineDCE::ID
static char ID
Definition: MachineDCE.hh:67
llvm::MachineDCE::baseUsers_
UserList baseUsers_
If users are traced to this list it means that function cannot be eliminated.
Definition: MachineDCE.hh:82
llvm::MachineDCE::UserRelations
std::map< std::string, UserList > UserRelations
Definition: MachineDCE.hh:71
llvm::MachineDCE::canFindStart
bool canFindStart(const std::string &user, AvoidRecursionSet &avoid_recursion)
Definition: MachineDCE.cc:62
llvm::MachineDCE::functionMappings_
FunctionMap functionMappings_
Function name to MachineFunction map.
Definition: MachineDCE.hh:75
llvm::MachineDCE::runOnMachineFunction
virtual bool runOnMachineFunction(MachineFunction &F) override
Definition: MachineDCE.cc:153
llvm::MachineDCE::getPassName
virtual StringRef getPassName() const override
Definition: MachineDCE.hh:88
llvm::MachineDCE::FunctionMap
std::map< std::string, MachineFunction * > FunctionMap
Definition: MachineDCE.hh:69
llvm::MachineDCE::AvoidRecursionSet
std::set< const std::string * > AvoidRecursionSet
Definition: MachineDCE.hh:72
llvm::MachineDCE::UnusedFunctionsList
std::set< std::string > UnusedFunctionsList
Definition: MachineDCE.hh:96
llvm::MachineDCE
Definition: MachineDCE.hh:66
llvm::MachineDCE::addInitializer
void addInitializer(const Constant *init, std::string &name)
Definition: MachineDCE.cc:85
llvm::MachineDCE::MachineDCE
MachineDCE()
Definition: MachineDCE.hh:68
IGNORE_COMPILER_WARNING
#define IGNORE_COMPILER_WARNING(X)
Definition: CompilerWarnings.hh:51
POP_COMPILER_DIAGS
#define POP_COMPILER_DIAGS
Definition: CompilerWarnings.hh:68
llvm::MachineDCE::usersOfValue_
UserRelations usersOfValue_
List of users of a symbol.
Definition: MachineDCE.hh:78
llvm::MachineDCE::doInitialization
virtual bool doInitialization(Module &M) override
Definition: MachineDCE.cc:111
llvm::MachineDCE::removeableFunctions
UnusedFunctionsList removeableFunctions
Definition: MachineDCE.hh:97
llvm::MachineDCE::UserList
std::set< std::string > UserList
Definition: MachineDCE.hh:70
CompilerWarnings.hh