OpenASIP  2.0
LLVMTCEIRBuilder.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2015 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 LLVMTCEIRBuilder.hh
26  *
27  * This builder builds a CFG and DDG from the new LLVM TTA backend format.
28  *
29  * @author Heikki Kultala 2011
30  * @author Pekka Jääskeläinen 2011,2015
31  * @note reting: red
32  */
33 
34 #ifndef LLVM_TCE_IR_BUILDER_H
35 #define LLVM_TCE_IR_BUILDER_H
36 
37 #include <llvm/CodeGen/MachineFunctionPass.h>
38 #include <llvm/Analysis/AliasAnalysis.h>
39 
40 #include "LLVMTCEBuilder.hh"
43 
44 class InterPassData;
49 struct InnerLoopFinder;
50 
51 namespace TTAMachine {
52  class Machine;
53 }
54 
55 namespace llvm {
56 
57  FunctionPass* createLLVMTCECFGBuilderPass(
58  TCETargetMachine& tm, TTAMachine::Machine* mach, InterPassData& ipd);
59 
61  public:
62  static char ID;
63 
65  const TargetMachine& tm, TTAMachine::Machine* mach,
66  InterPassData& ipd, AliasAnalysis* AA,
67  bool functionAtATime=false, bool modifyMF=false);
68 
69  bool writeMachineFunction(MachineFunction& mf);
70 
71  virtual ~LLVMTCEIRBuilder();
72 
73  virtual bool doInitialization(Module& m );
74  virtual bool doFinalization(Module& m );
75 
76  virtual void emitSPInitialization() {}
77 
78  void getAnalysisUsage(AnalysisUsage &AU) const;
79 
80  virtual StringRef getPassName() const {
81  return "TCE: build TCE scheduler IR from MachineFunctions";
82  }
83 
84  void setInnerLoopFinder(InnerLoopFinder* loopFinder) {
85  loopFinder_ = loopFinder; }
86 
87  protected:
88 
89  // TODO: copy-paste from LLVMPomBuilder.hh
90  virtual unsigned spDRegNum() const {
91  return dynamic_cast<const TCETargetMachine&>(
93  }
94 
95  // the return address register's llvm reg number
96  virtual unsigned raPortDRegNum() const {
97  if (isTTATarget()) {
98  return dynamic_cast<const TCETargetMachine&>(
100  } else {
101  abortWithError("Unimplemented for non-TTA targets.");
102  }
103  }
104 
105  // the ADF register file name of the llvm reg number
106  virtual TCEString registerFileName(unsigned llvmRegNum) const;
107 
108  // the ADF register index of the llvm reg number
109  virtual int registerIndex(unsigned llvmRegNum) const;
110 
111  // operation name from a LLVM MachineInstr or OSAL Operation
112  virtual TCEString operationName(const MachineInstr& mi) const;
113 
115  const MachineOperand&) const {
116  // no FU terminals in the RISC-style backend, always through GPRs
117  return NULL;
118  }
119 
121  const MachineOperand& mo);
122 
124  const TCEString& symbolName);
125 
126  virtual void createMoveNode(
128  std::shared_ptr<TTAProgram::Move> m,
129  bool isDestination) override;
130 
131  private:
132 
133  bool isHotFunction(llvm::MachineFunction& mf) const;
134  bool isRealInstruction(const MachineInstr& instr) const;
135  bool hasRealInstructions(
136  MachineBasicBlock::const_iterator i,
137  const MachineBasicBlock& mbb);
138 
140  const TTAProgram::Procedure& proc,
141  llvm::MachineFunction& mf);
142 
143  void compileFast(ControlFlowGraph& cfg);
144  void compileOptimized(
145  ControlFlowGraph& cfg,
146  llvm::AliasAnalysis* llvmAA);
147 
148  bool isExplicitReturn(const llvm::MachineInstr& mi) const;
149 
152 
153  ControlFlowGraph* buildTCECFG(llvm::MachineFunction& mf);
155  llvm::MachineFunction& mf,
156  ControlFlowGraph& cfg);
158  llvm::MachineFunction& mf,
159  ControlFlowGraph& cfg);
160 
162  // TODO: how to get these?
163  std::set<TCEString> allParamRegs_;
164 
165  // todo: information about sp and param regs, how to give?
167 
168  std::map<const MachineBasicBlock*,BasicBlockNode*> bbMapping_;
169 
170  std::vector<std::vector<BasicBlockNode*> > jumpTableRecord_;
171 
173 
174  // write back the scheduled instructions to the machine function?
175  bool modifyMF_;
176 
177  std::map<const MachineBasicBlock*, BasicBlockNode*> skippedBBs_;
178 
180 
184 
186  };
187 }
188 
189 #endif
llvm::LLVMTCEIRBuilder::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const
Definition: LLVMTCEIRBuilder.cc:131
llvm
Definition: InlineAsmParser.hh:49
llvm::LLVMTCEIRBuilder::registerIndex
virtual int registerIndex(unsigned llvmRegNum) const
Definition: LLVMTCEIRBuilder.cc:1186
llvm::LLVMTCEIRBuilder::doFinalization
virtual bool doFinalization(Module &m)
Definition: LLVMTCEIRBuilder.cc:1124
llvm::LLVMTCEIRBuilder::createMBBReference
virtual TTAProgram::Terminal * createMBBReference(const MachineOperand &mo)
Definition: LLVMTCEIRBuilder.cc:994
CopyingDelaySlotFiller.hh
CycleLookBackSoftwareBypasser
Definition: CycleLookBackSoftwareBypasser.hh:52
llvm::LLVMTCEIRBuilder::bbMapping_
std::map< const MachineBasicBlock *, BasicBlockNode * > bbMapping_
Definition: LLVMTCEIRBuilder.hh:168
llvm::LLVMTCEIRBuilder::isHotFunction
bool isHotFunction(llvm::MachineFunction &mf) const
Definition: LLVMTCEIRBuilder.cc:257
llvm::LLVMTCEIRBuilder::hasRealInstructions
bool hasRealInstructions(MachineBasicBlock::const_iterator i, const MachineBasicBlock &mbb)
Definition: LLVMTCEIRBuilder.cc:1106
llvm::LLVMTCEIRBuilder::AA_
AliasAnalysis * AA_
Definition: LLVMTCEIRBuilder.hh:172
llvm::LLVMTCEIRBuilder::ipData_
InterPassData * ipData_
Definition: LLVMTCEIRBuilder.hh:161
llvm::LLVMTCEIRBuilder::createFUTerminal
virtual TTAProgram::Terminal * createFUTerminal(const MachineOperand &) const
Definition: LLVMTCEIRBuilder.hh:114
llvm::createLLVMTCECFGBuilderPass
FunctionPass * createLLVMTCECFGBuilderPass(TCETargetMachine &tm, TTAMachine::Machine *mach, InterPassData &ipd)
llvm::LLVMTCEIRBuilder::delaySlotFiller
CopyingDelaySlotFiller & delaySlotFiller()
Definition: LLVMTCEIRBuilder.cc:904
llvm::LLVMTCEIRBuilder::fixJumpTableDestinations
void fixJumpTableDestinations(llvm::MachineFunction &mf, ControlFlowGraph &cfg)
Definition: LLVMTCEIRBuilder.cc:1234
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
llvm::LLVMTCEIRBuilder::LLVMTCEIRBuilder
LLVMTCEIRBuilder(const TargetMachine &tm, TTAMachine::Machine *mach, InterPassData &ipd, AliasAnalysis *AA, bool functionAtATime=false, bool modifyMF=false)
Definition: LLVMTCEIRBuilder.cc:103
llvm::LLVMTCEIRBuilder::createSymbolReference
virtual TTAProgram::Terminal * createSymbolReference(const TCEString &symbolName)
Definition: LLVMTCEIRBuilder.cc:1066
DataDependenceGraphBuilder.hh
InnerLoopFinder
Definition: InnerLoopFinder.hh:28
llvm::LLVMTCEIRBuilder::allParamRegs_
std::set< TCEString > allParamRegs_
Definition: LLVMTCEIRBuilder.hh:163
llvm::LLVMTCEIRBuilder::scheduler
BBSchedulerController & scheduler()
Definition: LLVMTCEIRBuilder.cc:889
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
llvm::LLVMTCEIRBuilder::raPortDRegNum
virtual unsigned raPortDRegNum() const
Definition: LLVMTCEIRBuilder.hh:96
llvm::LLVMTCEIRBuilder::compileOptimized
void compileOptimized(ControlFlowGraph &cfg, llvm::AliasAnalysis *llvmAA)
Definition: LLVMTCEIRBuilder.cc:911
llvm::LLVMTCEIRBuilder::ddgBuilder_
DataDependenceGraphBuilder ddgBuilder_
Definition: LLVMTCEIRBuilder.hh:166
llvm::LLVMTCEIRBuilder::modifyMF_
bool modifyMF_
Definition: LLVMTCEIRBuilder.hh:175
CopyingDelaySlotFiller
Definition: CopyingDelaySlotFiller.hh:71
llvm::LLVMTCEIRBuilder::isRealInstruction
bool isRealInstruction(const MachineInstr &instr) const
Definition: LLVMTCEIRBuilder.cc:1071
llvm::LLVMTCEIRBuilder
Definition: LLVMTCEIRBuilder.hh:60
InterPassData
Definition: InterPassData.hh:48
llvm::LLVMTCEIRBuilder::jumpTableRecord_
std::vector< std::vector< BasicBlockNode * > > jumpTableRecord_
Definition: LLVMTCEIRBuilder.hh:170
llvm::LLVMTCEIRBuilder::markJumpTableDestinations
void markJumpTableDestinations(llvm::MachineFunction &mf, ControlFlowGraph &cfg)
Definition: LLVMTCEIRBuilder.cc:1203
llvm::LLVMTCEIRBuilder::emitSPInitialization
virtual void emitSPInitialization()
Definition: LLVMTCEIRBuilder.hh:76
llvm::LLVMTCEIRBuilder::createMoveNode
virtual void createMoveNode(ProgramOperationPtr &po, std::shared_ptr< TTAProgram::Move > m, bool isDestination) override
Definition: LLVMTCEIRBuilder.cc:1264
LLVMTCECmdLineOptions
Definition: LLVMTCECmdLineOptions.hh:48
llvm::LLVMTCEIRBuilder::compileFast
void compileFast(ControlFlowGraph &cfg)
Definition: LLVMTCEIRBuilder.cc:883
llvm::LLVMTCEIRBuilder::setInnerLoopFinder
void setInnerLoopFinder(InnerLoopFinder *loopFinder)
Definition: LLVMTCEIRBuilder.hh:84
llvm::LLVMTCEIRBuilder::bypasser_
CycleLookBackSoftwareBypasser * bypasser_
Definition: LLVMTCEIRBuilder.hh:183
llvm::LLVMTCEIRBuilder::writeMachineFunction
bool writeMachineFunction(MachineFunction &mf)
Definition: LLVMTCEIRBuilder.cc:136
llvm::LLVMTCEIRBuilder::dsf_
CopyingDelaySlotFiller * dsf_
Definition: LLVMTCEIRBuilder.hh:182
llvm::LLVMTCEIRBuilder::delaySlotFilling_
bool delaySlotFilling_
Definition: LLVMTCEIRBuilder.hh:179
llvm::LLVMTCEIRBuilder::convertProcedureToMachineFunction
void convertProcedureToMachineFunction(const TTAProgram::Procedure &proc, llvm::MachineFunction &mf)
llvm::LLVMTCEIRBuilder::isExplicitReturn
bool isExplicitReturn(const llvm::MachineInstr &mi) const
Definition: LLVMTCEIRBuilder.cc:855
llvm::LLVMTCEIRBuilder::spDRegNum
virtual unsigned spDRegNum() const
Definition: LLVMTCEIRBuilder.hh:90
DataDependenceGraphBuilder
Definition: DataDependenceGraphBuilder.hh:70
TCEString
Definition: TCEString.hh:53
llvm::LLVMTCEIRBuilder::ID
static char ID
Definition: LLVMTCEIRBuilder.hh:62
llvm::LLVMTCEIRBuilder::skippedBBs_
std::map< const MachineBasicBlock *, BasicBlockNode * > skippedBBs_
Definition: LLVMTCEIRBuilder.hh:177
llvm::TCETargetMachine
Definition: TCETargetMachine.hh:106
TTAProgram::Terminal
Definition: Terminal.hh:60
llvm::LLVMTCEIRBuilder::scheduler_
BBSchedulerController * scheduler_
Definition: LLVMTCEIRBuilder.hh:181
llvm::LLVMTCEIRBuilder::doInitialization
virtual bool doInitialization(Module &m)
Definition: LLVMTCEIRBuilder.cc:1118
TTAMachine
Definition: Assembler.hh:48
llvm::LLVMTCEIRBuilder::loopFinder_
InnerLoopFinder * loopFinder_
Definition: LLVMTCEIRBuilder.hh:185
llvm::LLVMTCEIRBuilder::operationName
virtual TCEString operationName(const MachineInstr &mi) const
Definition: LLVMTCEIRBuilder.cc:1147
llvm::LLVMTCEIRBuilder::registerFileName
virtual TCEString registerFileName(unsigned llvmRegNum) const
Definition: LLVMTCEIRBuilder.cc:1161
TTAProgram::Procedure
Definition: Procedure.hh:55
llvm::LLVMTCEBuilder
Definition: LLVMTCEBuilder.hh:102
llvm::LLVMTCEBuilder::targetMachine
const TargetMachine & targetMachine() const
Definition: LLVMTCEBuilder.hh:157
llvm::LLVMTCEIRBuilder::getPassName
virtual StringRef getPassName() const
Definition: LLVMTCEIRBuilder.hh:80
llvm::AliasAnalysis
AAResults AliasAnalysis
Definition: DataDependenceGraphBuilder.hh:45
llvm::LLVMTCEIRBuilder::~LLVMTCEIRBuilder
virtual ~LLVMTCEIRBuilder()
Definition: LLVMTCEIRBuilder.cc:1285
llvm::LLVMTCEIRBuilder::buildTCECFG
ControlFlowGraph * buildTCECFG(llvm::MachineFunction &mf)
Definition: LLVMTCEIRBuilder.cc:273
LLVMTCEBuilder.hh
ControlFlowGraph
Definition: ControlFlowGraph.hh:100
BBSchedulerController
Definition: BBSchedulerController.hh:62
TTAMachine::Machine
Definition: Machine.hh:73
llvm::LLVMTCEBuilder::isTTATarget
virtual bool isTTATarget() const
Definition: LLVMTCEBuilder.hh:132