Go to the documentation of this file.
33 #ifndef LLVM_TCE_BUILDER_H
34 #define LLVM_TCE_BUILDER_H
38 #include <llvm/CodeGen/MachineFunctionPass.h>
39 #include <llvm/CodeGen/MachineConstantPool.h>
40 #include <llvm/CodeGen/MachineOperand.h>
41 #include <llvm/CodeGen/MachineInstr.h>
42 #include <llvm/CodeGen/MachineBasicBlock.h>
44 #include "tce_config.h"
45 #include <llvm/IR/Mangler.h>
46 #include <llvm/IR/Constant.h>
47 #include <llvm/Transforms/IPO.h>
69 class TerminalRegister;
70 class TerminalInstructionAddress;
71 class InstructionReferenceManager;
72 class TerminalProgramOperation;
96 class ConstantDataSequential;
97 class TCETargetMachine;
110 const TargetMachine& tm,
113 bool functionAtATime=
false);
120 const llvm::BasicBlock* bb) {
126 AU.addRequired<AAResultsWrapperPass>();
129 MachineFunctionPass::getAnalysisUsage(AU);
154 const MachineOperand& src,
const MachineOperand& dst,
172 const MachineOperand&)
const {
177 std::string
mbbName(
const MachineBasicBlock& mbb);
182 const std::string& rfName,
int index);
185 const MachineOperand& mo,
int bitLimit = 0);
196 const MachineOperand& mo);
199 const MachineOperand& mo);
202 const MachineOperand& mo);
212 bool conditional=
false,
bool trueGuard=
true);
215 const MachineFunction& mf,
216 const MachineInstr* mi,
236 static bool isInlineAsm(
const MachineInstr& instr);
245 const llvm::TargetMachine*
tm_;
288 const llvm::Constant*
value =
nullptr;
294 const llvm::Constant*
value)
298 typedef std::map<TTAMachine::AddressSpace*, TTAProgram::DataMemory*>
308 bool forceInitialize=
false,
unsigned forceAlignment=0);
312 bool isPointer =
false);
329 const MachineOperand& base,
const MachineOperand& offset);
344 const std::string op,
345 const MachineInstr* mi,
399 std::shared_ptr<TTAProgram::Move> m,
413 const std::vector<TTAProgram::Instruction*>& operandMoves,
448 std::map<std::string, TTAProgram::Instruction*>
mbbs_;
451 std::map<const llvm::BasicBlock*, TTAProgram::Instruction*>
bbIndex_;
458 std::map<TTAProgram::TerminalInstructionAddress*, std::string>
479 std::map<TTAMachine::AddressSpace*, unsigned>
dataEnds_;
502 const llvm::DataLayout*
dl_;
virtual TTAProgram::Terminal * createSymbolReference(const MachineOperand &mo)
unsigned & dataEnd(TTAMachine::AddressSpace &aSpace)
std::string getAsmString(const MachineInstr &mi) const
static unsigned MAU_BITS
Target architechture MAU size in bits.
bool doFinalization(Module &M)
TTAProgram::Instruction * emitInstruction(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
const llvm::DataLayout * dl_
The data layout for the machine.
TTAProgram::Program * prog_
Current program being built.
bool multiDataMemMachine_
Set to true in case this machine has more than one data address spaces.
void createExprDataDefinition(int addressSpaceId, unsigned &addr, const ConstantExpr *gv, int offset=0)
TTAProgram::DataMemory & dataMemoryForAddressSpace(TTAMachine::AddressSpace &aSpace)
TTAProgram::Program * result()
virtual TTAProgram::Instruction * emitMove(const MachineInstr *mi, TTAProgram::CodeSnippet *proc, bool conditional=false, bool trueGuard=true)
std::vector< MachineFunction * > functions_
List of machine functions collected from runForMachineFunction.
void addCandidateLSUAnnotations(unsigned asNum, TTAProgram::Move &move)
Data definition structure for global values.
std::map< TTAProgram::TerminalInstructionAddress *, std::string > codeLabelReferences_
Dummy code label references that have to be fixed after all instrutions have been built.
TTAProgram::Instruction * firstInstructionOfBasicBlock(const llvm::BasicBlock *bb)
std::set< std::string > opset_
The operations supported by the current target machine.
LLVMTCECmdLineOptions * options_
The compiler options.
TTAProgram::Instruction * emitComparisonForBranch(TCEString firstOp, const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
void addPointerAnnotations(const llvm::MachineInstr *mi, TTAProgram::Move &move)
TTAProgram::Instruction * emitSpecialInlineAsm(const std::string op, const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
TTAProgram::Terminal * createAddrTerminal(const MachineOperand &base, const MachineOperand &offset)
void createGlobalValueDataDefinition(int addressSpaceId, unsigned &addr, const GlobalValue *gv, int offset=0)
const llvm::TargetMachine * tm_
Target machine description.
TTAMachine::AddressSpace * defaultDataAddressSpace_
The default data memory address space (address space 0).
MachineFrameInfo * curFrameInfo_
static unsigned POINTER_SIZE_32
Target architecture pointer size in maus.
std::vector< DataDef > udata_
TTAProgram::Instruction * emitOperationMacro(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
bool noAliasFound_
set to true in case at least one 'noalias' attribute (from the use of 'restricted' pointers) has been...
void createSPInitLoad(TTAProgram::CodeSnippet &target, TTAProgram::Terminal &src, TTAProgram::Terminal &dst)
TTAProgram::Instruction * emitReturnTo(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
TTAMachine::Machine * mach_
Machine for building the program.
TTAProgram::Instruction * emitWriteSP(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
unsigned initialStackPointerValue_
void fixProgramOperationReferences()
std::map< std::string, TTAProgram::Instruction * > mbbs_
Machine basic block -> first instruction in the BB map.
std::map< std::string, unsigned > dataLabels_
Data labels.
TTAProgram::Terminal * createTerminal(const MachineOperand &mo, int bitLimit=0)
llvm::Mangler * mang_
Mangler for mangling label strings.
void createIntDataDefinition(int addressSpaceId, unsigned &addr, const llvm::ConstantInt *ci, bool isPointer=false)
std::vector< ConstantDataDef > cpData_
void emitConstantPool(const llvm::MachineConstantPool &cp)
std::map< const llvm::BasicBlock *, TTAProgram::Instruction * > bbIndex_
Basic Block -> first instruction in the BB map.
bool multiAddrSpacesFound_
set to true in case at least one non-default address space memory access has been found in the genera...
std::shared_ptr< ProgramOperation > ProgramOperationPtr
std::vector< std::shared_ptr< TTAProgram::Move > > endReferences_
Dummy references to the _end symbol.
bool isInitialized(const Constant *cv)
virtual void emitSPInitialization()
ConstantDataDef(unsigned addr, unsigned align, unsigned size, const llvm::Constant *value)
void copyFUAnnotations(const std::vector< TTAProgram::Instruction * > &operandMoves, TTAProgram::Move &move) const
void emitDataDef(const DataDef &def)
virtual void createMoveNode(ProgramOperationPtr &, std::shared_ptr< TTAProgram::Move > m, bool)
TTAProgram::TerminalRegister * createTerminalRegister(const std::string &rfName, int index)
virtual void getAnalysisUsage(AnalysisUsage &AU) const
TTAProgram::MoveGuard * createGuard(const TTAProgram::Terminal *guardReg, bool trueOrFalse)
virtual int registerIndex(unsigned llvmRegNum) const =0
virtual unsigned raPortDRegNum() const =0
TTAProgram::Instruction * emitSelect(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
TTAProgram::Instruction * emitLoad(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
std::map< const llvm::Constant *, unsigned > globalCP_
Global constant pool for all constants gathered from machine functions. Map key is unique constant an...
TTAProgram::Instruction * emitLongjmp(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
TTAMachine::AddressSpace * instrAddressSpace_
static bool isInlineAsm(const MachineInstr &instr)
virtual ~LLVMTCEBuilder()
TCEString registerName(unsigned llvmRegNum) const
virtual TCEString operationName(const MachineInstr &mi) const =0
TTAProgram::Instruction * emitSetjmp(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
std::set< TTAProgram::TerminalProgramOperation * > symbolicPORefs_
std::map< unsigned, unsigned > currentFnCP_
Constant pool for the current machine function. Map key is constant pool index and the value is addre...
virtual TTAProgram::Terminal * createMBBReference(const MachineOperand &mo)
TTAProgram::Instruction * emitReadSP(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
std::vector< DataDef > data_
Data definitions.
virtual TTAProgram::Terminal * createFUTerminal(const MachineOperand &) const
std::map< TTAProgram::TerminalInstructionAddress *, std::string > mbbReferences_
Dummy basic block references that have to be fixed after all basic blocks have been built.
std::map< TCEString, ProgramOperationPtr > labeledPOs_
bool isBaseOffsetMemOperation(const Operation &operation) const
std::map< TTAMachine::AddressSpace *, unsigned > dataEnds_
The first position after the last data in the given address space.
virtual TTAProgram::Terminal * createProgramOperationReference(const MachineOperand &mo)
const TTAMachine::HWOperation & getHWOperation(std::string opName)
bool isProgramUsingRestrictedPointers() const
bool doInitialization(Module &M)
virtual unsigned spDRegNum() const =0
const llvm::Constant * value
void padToAlignment(int addressSpaceId, unsigned &addr, unsigned align)
static unsigned POINTER_SIZE_64
bool hasAmbiguousASpaceRefs(const TTAProgram::Instruction &instr) const
bool runOnMachineFunction(MachineFunction &MF)
TTAProgram::Instruction * emitReturn(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
TTAMachine::AddressSpace & addressSpaceById(unsigned id)
Data definition structure for constant pool values.
virtual bool writeMachineFunction(MachineFunction &MF)
std::map< std::string, TTAProgram::Instruction * > codeLabels_
Code labels.
PRegionMarkerAnalyzer * pregions_
void setInitialStackPointerValue(unsigned value)
void debugDataToAnnotations(const llvm::MachineInstr *mi, TTAProgram::Move &move)
void createFPDataDefinition(int addressSpaceId, unsigned &addr, const llvm::ConstantFP *cfp)
std::map< TTAMachine::AddressSpace *, TTAProgram::DataMemory * > DataMemIndex
TTAProgram::Instruction * emitGlobalXXtructorCalls(const MachineInstr *mi, TTAProgram::CodeSnippet *proc, bool constructors)
virtual TCEString registerFileName(unsigned llvmRegNum) const =0
unsigned addressSpaceId(TTAMachine::AddressSpace &aSpace) const
unsigned createDataDefinition(int addressSpaceId, unsigned &addr, const Constant *cv, bool forceInitialize=false, unsigned forceAlignment=0)
void clearFunctionBookkeeping()
TTAProgram::Instruction * emitStore(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
const TargetMachine & targetMachine() const
void addLabelForProgramOperation(TCEString label, ProgramOperationPtr po)
void deleteDeadProcedures()
TTAProgram::Instruction * emitRemaingingBrach(TCEString opName, const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
TTAProgram::Instruction * emitInlineAsm(const MachineFunction &mf, const MachineInstr *mi, TTAProgram::BasicBlock *bb, TTAProgram::InstructionReferenceManager &irm)
virtual bool isTTATarget() const
std::string mbbName(const MachineBasicBlock &mbb)
TTAProgram::Instruction * handleMemoryCategoryInfo(const MachineInstr *mi, TTAProgram::CodeSnippet *proc)
std::shared_ptr< TTAProgram::Move > createMove(const MachineOperand &src, const MachineOperand &dst, TTAProgram::MoveGuard *guard)