OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RISCVTDGen Class Reference

#include <RISCVTDGen.hh>

Inheritance diagram for RISCVTDGen:
Inheritance graph
Collaboration diagram for RISCVTDGen:
Collaboration graph

Public Member Functions

 RISCVTDGen (const TTAMachine::Machine &mach)
 
virtual ~RISCVTDGen ()=default
 
virtual void generateBackend (const std::string &path) const
 
virtual std::string generateBackend () const
 
- Public Member Functions inherited from TDGen
 TDGen (const TTAMachine::Machine &mach, bool initialize=true)
 
virtual ~TDGen ()
 

Protected Member Functions

virtual void initializeBackendContents ()
 
InstructionFormatfindFormat (const std::string name) const
 
void findCustomOps ()
 
void writeInstructionDeclarations (std::ostream &o) const
 
void writePatternDefinition (std::ostream &o, Operation &op)
 
void writePatternDefinitions (std::ostream &o)
 
void writeInstructionDeclaration (std::ostream &o, const std::string &name, const int encoding) const
 
std::string transformTCEPattern (std::string pattern, const unsigned numIns) const
 
void dumpClassDefinitions (std::ostream &) const
 
std::string getFormatType (const std::string &opName) const
 
std::string decimalsToHex (const std::string &pattern) const
 
- Protected Member Functions inherited from TDGen
bool writeRegisterInfo (std::ostream &o)
 
void writeStartOfRegisterInfo (std::ostream &o)
 
void writeOperandDefs (std::ostream &o)
 
void writeIntegerImmediateDefs (std::ostream &o, const ImmInfo &iivis)
 
void writeMoveImmediateDefs (std::ostream &o)
 
void writeInstrInfo (std::ostream &o)
 
void writeBackendCode (std::ostream &o)
 
void writeTopLevelTD (std::ostream &o)
 
void writeInstrFormats (std::ostream &o)
 
bool checkRequiredRegisters ()
 
void analyzeRegisters ()
 
void analyzeRegisterFileClasses ()
 
void analyzeRegisters (RegsToProcess regsToProcess)
 
void gatherAllMachineOperations ()
 
void analyzeMachineVectorRegisterClasses ()
 
void analyzeMachineRegisters ()
 
void associateRegistersWithVectorRegisterClasses ()
 
void orderEqualWidthRegistersToRoundRobin ()
 
void verbose (const TCEString &msg) const
 
bool isVectorLoadOperation (const Operation &op) const
 
bool isVectorStoreOperation (const Operation &op) const
 
bool isWrongEndianessVectorOp (const Operation &op) const
 
bool isVectorBitwiseOperation (const Operation &op) const
 
bool hasRawOperands (const Operation &op) const
 
int subwordWidthOfRawData (const Operation &op) const
 
bool hasRegisterClassSupport (const Operation &op) const
 
bool hasRegisterClassSupport (const TDGenerator::ValueType &vt) const
 
TCEString associatedVectorRegisterClass (const Operand &operand) const
 
void writePatternReplacement (std::ostream &o, const TCEString &origPat, const TCEString &replacerPat) const
 
void writeOperationDefUsingGivenOperandTypes (std::ostream &o, Operation &op, bool skipPattern, std::vector< TDGenerator::ValueType > inputs, std::vector< TDGenerator::ValueType > outputs, TCEString instrSuffix="")
 
void writeRegisterDef (std::ostream &o, const RegInfo &reg, const std::string regName, const std::string regTemplate, const std::string aliases, RegType type)
 
void write64bitRegisterInfo (std::ostream &o)
 
void write32bitRegisterInfo (std::ostream &o)
 
void write16bitRegisterInfo (std::ostream &o)
 
void write8bitRegisterInfo (std::ostream &o)
 
void write1bitRegisterInfo (std::ostream &o)
 
void writeRARegisterInfo (std::ostream &o)
 
void writeGuardRegisterClassInfo (std::ostream &o)
 
void writeVectorRegisterBaseClasses (std::ostream &o) const
 
void writeVectorRegisterNames (std::ostream &o)
 
void writeVectorRegisterClasses (std::ostream &o) const
 
void writeVectorOperationDefs (std::ostream &o, Operation &op, bool skipPattern)
 
void writeVectorOperationDef (std::ostream &o, Operation &op, TCEString valueTypes, const TCEString &attributes, bool skipPattern)
 
void saveAdditionalVectorOperationInfo (const Operation &op, const TCEString &valueTypes, bool isRegisterOp)
 
void writeVectorMemoryOperationDefs (std::ostream &o, Operation &op, bool skipPattern)
 
void writeVectorBitwiseOperationDefs (std::ostream &o, Operation &op, bool skipPattern)
 
void writeVectorRegisterMoveDefs (std::ostream &o)
 
void writeVectorTruncStoreDefs (std::ostream &o) const
 
void writeScalarToVectorDefs (std::ostream &o) const
 
void writeVectorBitConversions (std::ostream &o) const
 
void writeScalarOperationExploitations (std::ostream &o)
 
void writeVectorLoadStoreOperationExploitations (std::ostream &o)
 
void writeWiderVectorOperationExploitations (std::ostream &o)
 
void genGeneratedTCEPlugin_getStore (std::ostream &o) const
 
void genGeneratedTCEPlugin_getLoad (std::ostream &o) const
 
void genGeneratedTCEPlugin_isVectorRegisterMove (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorValueType (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorBroadcastOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorPackOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorSelectOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorShuffle1Opcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorShuffle2Opcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getConstantVectorShuffleOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getExtractElemOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorShlSameOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorShrSameOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorShruSameOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorAndSameOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorIorSameOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorXorSameOpcode (std::ostream &o) const
 
void genTCETargetLoweringSIMD_addVectorRegisterClasses (std::ostream &o) const
 
void genTCETargetLoweringSIMD_associatedVectorRegClass (std::ostream &o) const
 
void genTCETargetLoweringSIMD_getSetCCResultVT (std::ostream &o) const
 
void genTCEInstrInfoSIMD_copyPhysVectorReg (std::ostream &o) const
 
void genGeneratedTCEPlugin_getVectorImmediateOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getGatherOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getLoadOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getAddOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getShlOpcode (std::ostream &o) const
 
void genGeneratedTCEPlugin_getIorOpcode (std::ostream &o) const
 
void writeVectorImmediateWriteDefs (std::ostream &instrInfoTD)
 
void createMinMaxDef (const TCEString &opName, const TCEString &valueName, std::ostream &os)
 
void createVectorMinMaxDef (const TCEString &opName, int bits, char llvmTypeChar, const TCEString &postFix, std::ostream &os)
 
void writeOperationDefs (std::ostream &o, Operation &op, bool skipPattern)
 
void writeOperationDef (std::ostream &o, Operation &op, const std::string &operandTypes, const std::string &attrs, bool skipPattern, std::string backendPrefix="")
 
std::string emulatingOpNodeLLVMName (const Operation &op, const OperationDAG &dag, const OperationNode &node, const std::string &operandTypes)
 
void writeEmulationPattern (std::ostream &o, const Operation &op, const OperationDAG &dag)
 
void write64bitMoveDefs (std::ostream &o)
 
void writeControlFlowInstrDefs (std::ostream &os)
 
void writeCondBranchDefs (std::ostream &os)
 
void writeCallDef (std::ostream &o)
 
void writeHWLoopDef (std::ostream &o)
 
virtual void writeCallDefRegs (std::ostream &o)
 
void writeRegisterClasses (std::ostream &o)
 
virtual TCEString llvmOperationPattern (const Operation &op, char operandType=' ') const
 
virtual TCEString llvmOperationName (const TCEString &opName) const
 
bool operationCanBeMatched (const Operation &op, std::set< std::string > *recursionCycleCheck=NULL, bool recursionHasStore=false)
 
bool operationDAGCanBeMatched (const OperationDAG &op, std::set< std::string > *recursionCycleCheck=NULL, bool recursionHasStore=false)
 
const OperationDAGgetMatchableOperationDAG (const Operation &op)
 
const std::vector< OperationDAG * > getMatchableOperationDAGs (const Operation &op)
 
std::string tceOperationPattern (const Operation &op)
 
std::string patOutputs (const Operation &op, const std::string &oprTypes)
 
std::string patInputs (const Operation &op, const std::string &oprTypes)
 
virtual std::string operandToString (const Operand &operand, bool match, char operandType, const std::string &immDefName="")
 
std::string operationNodeToString (const Operation &op, const OperationDAG &dag, const OperationNode &node, bool emulationPattern, const std::string &operandTypes)
 
std::string constantNodeString (const Operation &op, const OperationDAG &dag, const ConstantNode &node, const std::string &operandTypes, const OperationDAGNode *successor=nullptr)
 
std::string dagNodeToString (const Operation &op, const OperationDAG &dag, const OperationDAGNode &node, bool emulationPattern, const std::string &operandTypes, const Operation *emulatingOp=nullptr, const OperationDAGNode *successor=nullptr)
 
std::string operationPattern (const Operation &op, const OperationDAG &dag, const std::string &operandTypes)
 
virtual char operandChar (Operand &operand)
 
std::string createDefaultOperandTypeString (const Operation &op)
 
void writeVectorStoreDefs (std::ostream &o, const TCEString &opName, const TCEString &opNameSuffix, bool addrImm, const TCEString &dataType, bool writePredicatedVersions)
 
void genTCEInstrInfo_copyPhys64bitReg (std::ostream &o) const
 
void writeArgRegsArray (std::ostream &os)
 
virtual void createSelectPatterns (std::ostream &os)
 
void writeAddressingModeDefs (std::ostream &o)
 
void createByteExtLoadPatterns (std::ostream &os)
 
void createShortExtLoadPatterns (std::ostream &os)
 
void create32BitExtLoadPatterns (std::ostream &os)
 
void createEndiannesQuery (std::ostream &os)
 
void createConstantMaterializationQuery (std::ostream &os)
 
void createConstShiftPatterns (std::ostream &os)
 
void writeOperationDefs (std::ostream &o, Operation &op, const std::string &operandTypes, const std::string &attrs, bool skipPattern, std::string backendPrefix="")
 
void writeVectorStoreDefs (std::ostream &o, Operation &op, int vectorLen)
 
void writeVectorTruncStoreDefs (std::ostream &o, Operation &op, int bitsize, int vectorLen)
 
void createGetMaxMemoryAlignment (std::ostream &os) const
 
void writeVectorAnyextPattern (std::ostream &o, Operation &op, const TCEString &loadPatternName, int vectorLen)
 
void writeVectorLoadDefs (std::ostream &o, const TCEString &opName, const TCEString &opNameSuffix, bool addrImm, const TCEString &resultType, const TCEString &loadPatternName, bool writePredicatedVersions)
 
virtual void writeImmediateDef (std::ostream &o, const std::string &defName, const std::string &operandType, const std::string &predicate)
 
void writeInstrDef (std::ostream &o, const std::string &instrDefName, const std::string &outs, const std::string &ins, const std::string &asmString, const std::string &pattern)
 
void writeVectorLoadDefs (std::ostream &o, Operation &op, const TCEString &loadPatternName, int vectorLen)
 
void writeBooleanStorePatterns (std::ostream &os)
 
std::string immediatePredicate (int64_t lowerBoundInclusive, uint64_t upperBoundInclusive)
 
std::string immediateOperandNameForEmulatedOperation (const OperationDAG &, const Operand &operand)
 
bool areImmediateOperandsLegal (const Operation &operation, const std::string &operandTypes) const
 
void writeBroadcastDefs (std::ostream &o, Operation &op, int vectorLen)
 
bool writePortGuardedJumpDefPair (std::ostream &os, const TCEString &tceop1, const TCEString &tceop2, bool fp=false)
 
std::string subPattern (const Operation &op, const OperationDAG &dag)
 
OperationDAGcreateTrivialDAG (Operation &op)
 
bool canBeImmediate (const OperationDAG &dag, const TerminalNode &node)
 
virtual void createMinMaxGenerator (std::ostream &os)
 
void writeCallSeqStart (std::ostream &os)
 
void writeMiscPatterns (std::ostream &o)
 
void generateLoadStoreCopyGenerator (std::ostream &os)
 
void createParamDRegNums (std::ostream &os)
 
virtual void createVectorRVDRegNums (std::ostream &os)
 
void writeCallingConv (std::ostream &os)
 
void writeCallingConvLicenceText (std::ostream &os)
 
void writeConstShiftPat (std::ostream &os, const TCEString &nodeName, const TCEString &opNameBase, int i)
 
void createBoolAndHalfLoadPatterns (std::ostream &os)
 
virtual void createConstantMaterializationPatterns (std::ostream &os)
 
void createBranchAnalysis (std::ostream &os)
 
void genTCERegisterInfo_setReservedVectorRegs (std::ostream &os) const
 
void writeGetPointerAdjustmentQuery (std::ostream &os) const
 
bool canBePredicated (Operation &op, const std::string &operandTypes)
 
TCEString getLLVMPatternWithConstants (const Operation &op, const std::string &operandTypes, const std::string &operand0, const std::string &operand1) const
 
std::string operandTypesToRegisters (const std::string &opdTypes) const
 
char operandTypeToRegister (const char &opdType) const
 
TCEString getMovePattern (const char &opdType, const std::string &inputPattern) const
 
void initializeBackendContents ()
 

Protected Attributes

BinaryEncodingbem_
 
std::map< std::string, int > customOps_
 
std::string declarationStr_
 
std::string patternStr_
 
- Protected Attributes inherited from TDGen
std::map< ImmInfoKey, std::string > immOperandDefs_
 Maps (operation, operand) pairs to i32 immediate operand definition names.
 
const TTAMachine::Machinemach_
 
ImmInfoimmInfo_
 
unsigned dregNum_
 
std::string registerInfo_
 
std::string addressingModeDefs_
 
std::string operandDefs_
 
std::string instrInfo_
 
std::string instrFormats_
 
std::string callingConv_
 
std::string argRegsArray_
 
std::string backendCode_
 
std::string topLevelTD_
 
OperationDAGSelector::OperationSet allOpNames_
 Contains all operation names in upper case.
 
std::map< TCEString, Operation * > scalarOps_
 Contains all scalar operations (<Name, Operation>).
 
std::map< TCEString, Operation * > vectorOps_
 Contains all vector operations (<Name, Operation>).
 
std::map< int, TCEStringbaseClasses_
 Contains vector base classes for register files (<Width, Name>).
 
std::map< int, std::vector< TDGenerator::RegisterInfo > > registers_
 Contains registers fit for being vector registers (<Width, Registers>).
 
std::map< TCEString, TDGenerator::RegisterClassvRegClasses_
 Contains required vector register classes (<ValueType, RegClass>).
 
std::map< TCEString, TDGenerator::InstructionInforegisterStores_
 All register store operations (<ValueType, InstrInfo>).
 
std::map< TCEString, TDGenerator::InstructionInforegisterLoads_
 All register load operations (<ValueType, InstrInfo>).
 
std::map< TCEString, TDGenerator::InstructionInfoimmediateStores_
 All immediate store operations (<ValueType, InstrInfo>).
 
std::map< TCEString, TDGenerator::InstructionInfoimmediateLoads_
 All immediate load operations (<ValueType, InstrInfo>).
 
std::map< TCEString, TCEStringpackOperations_
 Contains machine's PACK instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringvbcastOperations_
 Contains machine's VBCAST instructions (<ValueType, InstrName>).
 
std::vector< std::pair< const Operation *, TCEString > > truncOperations_
 Contains machine's TRUNCxx/CFH instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringvselectOperations_
 Contains machine's VSELECT instructions (<instrName, ValueType>).
 
std::map< TCEString, TCEStringvshuffle1Operations_
 Contains machine's VSHUFFLE1 instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringvshuffle2Operations_
 Contains machine's VSHUFFLE2 instructions (<ValueType, InstrName>).
 
std::map< std::pair< TCEString, std::vector< int > >, TCEStringvcshuffleOperations_
 Contains machine's VCSHUFFLE instructions (<<ValueType, ConstantSelects>, InstrName>).
 
std::map< TCEString, TCEStringextractElemOperations_
 Contains machine's EXTRACTELEM instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringshlSameOperations_
 Contains machine's SHLSAME instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringshrSameOperations_
 Contains machine's SHRSAME instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringshruSameOperations_
 Contains machine's SHRUSAME instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringandSameOperations_
 Contains machine's ANDSAME instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringiorSameOperations_
 Contains machine's IORSAME instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringxorSameOperations_
 Contains machine's XORSAME instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringgatherOperations_
 Contains machine's GATHER instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringaddOperations_
 Contains machine's add instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringshlOperations_
 Contains machine's shl instructions (<ValueType, InstrName>).
 
std::map< TCEString, TCEStringiorOperations_
 Contains machine's shl instructions (<ValueType, InstrName>).
 
std::set< TCEStringmovOperations_
 Contains all moves between register classes (<InstrName>).
 
std::vector< RegInforegs1bit_
 
std::vector< RegInforegs8bit_
 
std::vector< RegInforegs16bit_
 
std::vector< RegInforegs32bit_
 
std::vector< RegInforegs64bit_
 
std::vector< std::string > llvmGuardRegs_
 The LLVM register defs used as guards.
 
std::map< std::string, RegInforegs_
 Map of generated llvm register names to physical register in the machine.
 
std::vector< std::string > argRegNames_
 
std::vector< std::string > resRegNames_
 
std::vector< std::string > gprRegNames_
 
std::map< std::string, std::string > opNames_
 
std::map< std::string, std::string > truePredOps_
 
std::map< std::string, std::string > falsePredOps_
 
int maxVectorSize_
 
int highestLaneInt_
 
int highestLaneBool_
 
bool hasExBoolRegs_
 
bool hasExIntRegs_
 
bool hasSelect_
 
bool hasConditionalMoves_
 
int maxScalarWidth_
 
bool littleEndian_
 
unsigned int argRegCount_
 
unsigned int requiredI32Regs_
 Minimum number of 32 bit registers.
 
unsigned int requiredI64Regs_
 
bool prebypassStackIndeces_
 
bool use64bitForFP_
 
std::set< RegInfoguardedRegs_
 List of register that are associated with a guard on a bus.
 
std::set< const TTAMachine::RegisterFile *, TTAMachine::MachinePart::ComparatortempRegFiles_
 Register files whose last reg reserved for temp reg copies.
 
RegClassMap regsInClasses_
 All registers in certain group.
 
RegClassMap regsInRFClasses_
 
std::vector< std::string > constantMaterializationPredicates_
 All predicates used in constant materialization patterns.
 

Additional Inherited Members

- Static Public Attributes inherited from TDGen
static const char OT_REG_BOOL = 'b'
 
static const char OT_REG_INT = 'r'
 
static const char OT_REG_LONG = 's'
 
static const char OT_REG_FP = 'f'
 
static const char OT_REG_HFP = 'h'
 
static const char OT_REG_DOUBLE = 'd'
 
static const char OT_IMM_BOOL = 'j'
 
static const char OT_IMM_INT = 'i'
 
static const char OT_IMM_FP = 'k'
 
static const char OT_IMM_HFP = 'l'
 
static const char OT_IMM_LONG = 'a'
 
static const char OT_VREG_BOOL = 'a'
 
static const char OT_VREG_INT8 = 'q'
 
static const char OT_VREG_INT16 = 't'
 
static const char OT_VREG_INT32 = 'u'
 
static const char OT_VREG_FP = 'e'
 
static const char OT_VREG_HFP = 'g'
 
- Protected Types inherited from TDGen
enum  RegType { GPR = 0 , RESERVED , ARGUMENT , RESULT }
 
enum  RegsToProcess { ALL_REGISTERS , ONLY_EXTRAS , ONLY_LANES , ONLY_NORMAL }
 
typedef std::map< std::string, std::vector< std::string > > RegClassMap
 
- Static Protected Member Functions inherited from TDGen
static std::vector< std::string > supportedStackAccessOperations (const TTAMachine::Machine &mach)
 
- Static Protected Attributes inherited from TDGen
static const int FP_SUBW_WIDTH
 Float type subword width.
 
static const int HFP_SUBW_WIDTH
 Half float type subword width.
 
static const int BOOL_SUBW_WIDTH
 Bool type subword width.
 
static const int MAX_SCALAR_WIDTH = 64
 Distincts wide vs scalar registers.
 
static const int MAX_SUBW_COUNT = SIMD_WORD_WIDTH / BYTE_BITWIDTH
 Maximum number of subwords that any SIMD operation can have.
 
static const bool EXPLOIT_BIGGER_REGISTERS = true
 If set to true, smaller vector value types can be stored to larger register files, e.g. v4i8 vectors can be stored to registers that are over 32 bits in size.
 
static const std::map< TCEString, TCEStringOPERATION_PATTERNS_
 Contains <BaseOpName, OpPattern> key-value pairs.
 
static const std::string guardRegTemplateName = "Guard"
 

Detailed Description

Definition at line 42 of file RISCVTDGen.hh.

Constructor & Destructor Documentation

◆ RISCVTDGen()

RISCVTDGen::RISCVTDGen ( const TTAMachine::Machine mach)

Definition at line 52 of file RISCVTDGen.cc.

53 : TDGen(mach, false), bem_(NULL) {
54 bem_ = BEMGenerator(mach).generate();
55 assert(bem_ != NULL);
58}
#define assert(condition)
BinaryEncoding * generate()
void findCustomOps()
virtual void initializeBackendContents()
BinaryEncoding * bem_
Definition RISCVTDGen.hh:69
Definition TDGen.hh:77

References assert, bem_, findCustomOps(), BEMGenerator::generate(), and initializeBackendContents().

Here is the call graph for this function:

◆ ~RISCVTDGen()

virtual RISCVTDGen::~RISCVTDGen ( )
virtualdefault

Member Function Documentation

◆ decimalsToHex()

std::string RISCVTDGen::decimalsToHex ( const std::string &  pattern) const
protected

OpenASIP converts hex numbers to unsigned by default. The converted number might not fit into i32. This function transforms the given instruction pattern to use hex encoding.

Parameters
patternThe instruction pattern.
Returns
The instruction pattern in hex format.

Definition at line 69 of file RISCVTDGen.cc.

69 {
70 std::regex patternRegex(R"((i32\s)(-?\d+))");
71 std::smatch match;
72 std::string modifiedPattern = pattern;
73
74 auto start = modifiedPattern.cbegin();
75 while (std::regex_search(
76 start, modifiedPattern.cend(), match, patternRegex)) {
77 try {
78 std::string numStr = match[2].str();
79 std::string hexStr;
80
81 if (numStr[0] == '-') {
82 int num = std::stoi(numStr);
83 hexStr = TCEString::intToHexString(num);
84 } else {
85 unsigned long num = std::stoul(numStr);
87 }
88
89 // Calculate the actual start position in the modified string
90 size_t matchPos = match.position(2) + std::distance(
91 modifiedPattern.cbegin(), start);
92 modifiedPattern.replace(matchPos, match.length(2), hexStr);
93 // Move start past the replaced part
94 start = modifiedPattern.cbegin() + matchPos + hexStr.length();
95 } catch (const std::invalid_argument& e) {
96 std::cerr << "Invalid argument: " << e.what() << std::endl;
97 break;
98 } catch (const std::out_of_range& e) {
99 std::cerr << "Out of range error: " << e.what() << std::endl;
100 break;
101 }
102 }
103
104 return modifiedPattern;
105}
static std::string intToHexString(int num)
Definition TCEString.cc:288
static std::string unsignedToHexString(unsigned num)
Definition TCEString.cc:295

References TCEString::intToHexString(), and TCEString::unsignedToHexString().

Referenced by transformTCEPattern().

Here is the call graph for this function:

◆ dumpClassDefinitions()

void RISCVTDGen::dumpClassDefinitions ( std::ostream &  o) const
protected

Definition at line 313 of file RISCVTDGen.cc.

313 {
314 o << "/*\n";
315 o << " * Generated by OpenASIP\n";
316 /* These are not needed since the target contents would be different
317 between versions if necessary. */
318 o << " * OpenASIP version: " << Application::TCEVersionString() << "\n";
319 o << " * LLVM version: " << LLVM_VERSION << "\n";
320 o << " */\n";
321 o << "\n";
322 o << "class OARVInstR1<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode,\n";
323 o << " dag outs, dag ins, string opcodestr, string argstr>\n";
324 o << " : RVInst<outs, ins, opcodestr, argstr, [], InstFormatOther> {\n";
325 o << " bits<5> rs1;\n";
326 o << "\n";
327 o << " let Inst{31-25} = funct7;\n";
328 o << " let Inst{24-20} = 0;\n";
329 o << " let Inst{19-15} = rs1;\n";
330 o << " let Inst{14-12} = funct3;\n";
331 o << " let Inst{11-7} = 0;\n";
332 o << " let Inst{6-0} = opcode.Value;\n";
333 o << "}\n";
334 o << "\n";
335 o << "class OARVInstR1R<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode,\n";
336 o << " dag outs, dag ins, string opcodestr, string argstr>\n";
337 o << " : RVInst<outs, ins, opcodestr, argstr, [], InstFormatOther> {\n";
338 o << " bits<5> rs1;\n";
339 o << " bits<5> rd;\n";
340 o << "\n";
341 o << " let Inst{31-25} = funct7;\n";
342 o << " let Inst{24-20} = 0;\n";
343 o << " let Inst{19-15} = rs1;\n";
344 o << " let Inst{14-12} = funct3;\n";
345 o << " let Inst{11-7} = rd;\n";
346 o << " let Inst{6-0} = opcode.Value;\n";
347 o << "}\n";
348 o << "\n";
349 o << "let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in\n";
350 o << "class OARVR2R<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode, string\n";
351 o << " opcodestr, bit Commutable = 0>\n";
352 o << " : RVInstR<funct7, funct3, opcode, (outs GPR:$rd), (ins GPR:$rs1,\n";
353 o << " GPR:$rs2), opcodestr, \"$rd, $rs1, $rs2\"> {\n";
354 o << " let isCommutable = Commutable;\n";
355 o << "}\n";
356 o << "\n";
357 o << "let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in\n";
358 o << "class OARVR3R<bits<2> funct2, bits<3> funct3, RISCVOpcode opcode, string\n";
359 o << " opcodestr, bit Commutable = 0>\n";
360 o << " : RVInstR4<funct2, funct3, opcode, (outs GPR:$rd), (ins GPR:$rs1,\n";
361 o << " GPR:$rs2, GPR:$rs3), opcodestr, \"$rd, $rs1, $rs2, $rs3\"> {\n";
362 o << " let isCommutable = Commutable;\n";
363 o << "}\n";
364 o << "\n";
365 o << "let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in\n";
366 o << "class OARVR1R<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode, string\n";
367 o << " opcodestr>\n";
368 o << " : OARVInstR1R<funct7, funct3, opcode, (outs GPR:$rd), (ins GPR:$rs1),\n";
369 o << " opcodestr, \"$rd, $rs1\"> {\n";
370 o << "}\n";
371 o << "\n";
372 o << "let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in\n";
373 o << "class OARVR1<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode, string\n";
374 o << " opcodestr>\n";
375 o << " : OARVInstR1<funct7, funct3, opcode, (outs), (ins GPR:$rs1),\n";
376 o << " opcodestr, \"$rs1\"> {\n";
377 o << "}\n";
378}
static std::string TCEVersionString()

References Application::TCEVersionString().

Referenced by writeInstructionDeclarations().

Here is the call graph for this function:

◆ findCustomOps()

void RISCVTDGen::findCustomOps ( )
protected

Definition at line 109 of file RISCVTDGen.cc.

109 {
110 customOps_.clear();
111 const std::vector<std::string> formatsToSearch = {
116 };
117 for (const std::string& fName : formatsToSearch) {
118 InstructionFormat* format = bem_->instructionFormat(fName);
119 if (format == NULL) {
120 continue;
121 }
122 for (int i = 0; i < format->operationCount(); i++) {
123 const std::string op = format->operationAtIndex(i);
125 customOps_.insert({op, format->encoding(op)});
126 }
127 }
128 }
129}
InstructionFormat & instructionFormat(int index) const
std::string operationAtIndex(const int index) const
int encoding(const std::string &op) const
static bool containsKey(const MapType &aMap, const KeyType &aKey)
std::map< std::string, int > customOps_
Definition RISCVTDGen.hh:70
const std::string RISCV_R1R_TYPE_NAME
const std::string RISCV_R3R_TYPE_NAME
const std::string RISCV_R_TYPE_NAME
const std::string RISCV_R1_TYPE_NAME
const std::map< std::string, int > RISCVRTypeOperations
Definition RISCVFields.hh:8

References bem_, MapTools::containsKey(), customOps_, InstructionFormat::encoding(), BinaryEncoding::instructionFormat(), InstructionFormat::operationAtIndex(), InstructionFormat::operationCount(), RISCVFields::RISCV_R1_TYPE_NAME, RISCVFields::RISCV_R1R_TYPE_NAME, RISCVFields::RISCV_R3R_TYPE_NAME, RISCVFields::RISCV_R_TYPE_NAME, and RISCVFields::RISCVRTypeOperations.

Referenced by RISCVTDGen().

Here is the call graph for this function:

◆ findFormat()

InstructionFormat * RISCVTDGen::findFormat ( const std::string  name) const
protected

◆ generateBackend() [1/2]

std::string RISCVTDGen::generateBackend ( ) const
virtual

Writes tce backend plugin code into a single string. Used for hash generation.

Reimplemented from TDGen.

Definition at line 308 of file RISCVTDGen.cc.

308 {
309 return declarationStr_;
310}
std::string declarationStr_
Definition RISCVTDGen.hh:71

References declarationStr_.

◆ generateBackend() [2/2]

void RISCVTDGen::generateBackend ( const std::string &  path) const
virtual

Generates all files required to build a tce backend plugin (excluding static plugin code included from include/llvm/TCE/).

Reimplemented from TDGen.

Definition at line 299 of file RISCVTDGen.cc.

299 {
300 std::ofstream customInstrInfoTD;
301 customInstrInfoTD.open((path + "/RISCVInstrInfoOpenASIP.td").c_str());
302 customInstrInfoTD << declarationStr_;
303 customInstrInfoTD << patternStr_;
304 customInstrInfoTD.close();
305}
std::string patternStr_
Definition RISCVTDGen.hh:72

References declarationStr_, and patternStr_.

Referenced by main().

◆ getFormatType()

std::string RISCVTDGen::getFormatType ( const std::string &  opName) const
protected

Definition at line 134 of file RISCVTDGen.cc.

134 {
135 OperationPool opPool;
136 Operation& op = opPool.operation(opName.c_str());
137 const unsigned numIns = op.numberOfInputs();
138 const unsigned numOuts = op.numberOfOutputs();
139 if (numIns == 3 && numOuts == 1) {
140 return "OARVR3R";
141 } else if (numIns == 2 && numOuts == 1) {
142 return "OARVR2R";
143 } else if (numIns == 1 && numOuts == 1) {
144 return "OARVR1R";
145 } else if (numIns == 1 && numOuts == 0) {
146 return "OARVR1";
147 } else {
148 std::cerr << "Error: cannot find format type for operation "
149 << op.name() << " with numIns=" << numIns << " numOuts="
150 << numOuts << std::endl;
151 std::cerr << "Legal configurations: " << std::endl;
152 std::cerr << " numIns=3, numOuts=1" << std::endl;
153 std::cerr << " numIns=2, numOuts=1" << std::endl;
154 std::cerr << " numIns=1, numOuts=1" << std::endl;
155 std::cerr << " numIns=1, numOuts=0" << std::endl;
156 assert(false);
157 }
158 return "";
159}
Operation & operation(const char *name)
virtual TCEString name() const
Definition Operation.cc:93
virtual int numberOfInputs() const
Definition Operation.cc:192
virtual int numberOfOutputs() const
Definition Operation.cc:202

References assert, Operation::name(), Operation::numberOfInputs(), Operation::numberOfOutputs(), and OperationPool::operation().

Referenced by writeInstructionDeclaration().

Here is the call graph for this function:

◆ initializeBackendContents()

void RISCVTDGen::initializeBackendContents ( )
protectedvirtual

Definition at line 284 of file RISCVTDGen.cc.

284 {
285 std::ostringstream tdDeclarationBuffer;
286 std::ostringstream tdPatternBuffer;
287 writeInstructionDeclarations(tdDeclarationBuffer);
288 declarationStr_ = tdDeclarationBuffer.str();
289 writePatternDefinitions(tdPatternBuffer);
290 patternStr_ = tdPatternBuffer.str();
291
292#ifdef DEBUG_RISCV_TDGEN
293 std::cout << declarationStr_;
294 std::cout << patternStr_;
295#endif
296}
void writeInstructionDeclarations(std::ostream &o) const
void writePatternDefinitions(std::ostream &o)

References declarationStr_, patternStr_, writeInstructionDeclarations(), and writePatternDefinitions().

Referenced by RISCVTDGen().

Here is the call graph for this function:

◆ transformTCEPattern()

std::string RISCVTDGen::transformTCEPattern ( std::string  pattern,
const unsigned  numIns 
) const
protected

OpenASIP uses different reg declarations and pattern structure than the upstream RISC-V BE. This method transforms the TDGen generated patterns to the RISC-V one.

Parameters
patternThe pattern generated by TDGen
Returns
The RISC-V target pattern

Definition at line 200 of file RISCVTDGen.cc.

201 {
202 assert(numIns == 3 || numIns == 2 || numIns == 1);
203 // Remove the output specifier
204 size_t pos = pattern.find(',');
205 if (pos != std::string::npos) {
206 pattern = pattern.substr(pos + 2);
207 }
208 // Replace register specifiers
209 TCEString patTCEStr = TCEString(pattern);
210 patTCEStr.replaceString("R32IRegs:$op1", "(XLenVT GPR:$rs1)");
211 if (numIns == 3) {
212 patTCEStr.replaceString("R32IRegs:$op2", "(XLenVT GPR:$rs2)");
213 patTCEStr.replaceString("R32IRegs:$op3", "(XLenVT GPR:$rs3)");
214 patTCEStr.replaceString("R32IRegs:$op4", "(XLenVT GPR:$rd)");
215 } else if (numIns == 2) {
216 patTCEStr.replaceString("R32IRegs:$op2", "(XLenVT GPR:$rs2)");
217 patTCEStr.replaceString("R32IRegs:$op3", "(XLenVT GPR:$rd)");
218 } else {
219 patTCEStr.replaceString("R32IRegs:$op2", "(XLenVT GPR:$rd)");
220 }
221 patTCEStr.replaceString("\n", "");
222 patTCEStr = decimalsToHex(patTCEStr);
223 return patTCEStr;
224}
std::string decimalsToHex(const std::string &pattern) const
Definition RISCVTDGen.cc:69
TCEString & replaceString(const std::string &old, const std::string &newString)
Definition TCEString.cc:94

References assert, decimalsToHex(), and TCEString::replaceString().

Referenced by writePatternDefinition().

Here is the call graph for this function:

◆ writeInstructionDeclaration()

void RISCVTDGen::writeInstructionDeclaration ( std::ostream &  o,
const std::string &  name,
const int  encoding 
) const
protected

Definition at line 162 of file RISCVTDGen.cc.

164 {
165 const TCEString opName = TCEString(name);
166 const std::string f3 = RISCVTools::getFunc3Str(encoding);
167 std::string f7 = RISCVTools::getFunc7Str(encoding);
168 const std::string fType = getFormatType(name);
169 assert(fType != "");
170 std::string opc = "OPC_CUSTOM_0";
171 if (fType == "OARVR3R") {
172 std::string opc = "OPC_CUSTOM_1";
173 // rs3 takes 5 bits from f7
174 f7 = RISCVTools::getFunc2Str(encoding);
175 } else {
176 f7 = RISCVTools::getFunc7Str(encoding);
177 }
178 o << "def " << "OA_" + opName.upper() << " : " << fType << "<" << f7
179 <<", " << f3 << ", " << opc << ", \"" << "oa_" + name << "\">;";
180 o << "\n";
181}
std::string getFormatType(const std::string &opName) const
static std::string getFunc2Str(const int encoding)
static std::string getFunc3Str(const int encoding)
static std::string getFunc7Str(const int encoding)
TCEString upper() const
Definition TCEString.cc:86

References assert, getFormatType(), RISCVTools::getFunc2Str(), RISCVTools::getFunc3Str(), RISCVTools::getFunc7Str(), and TCEString::upper().

Referenced by writeInstructionDeclarations().

Here is the call graph for this function:

◆ writeInstructionDeclarations()

void RISCVTDGen::writeInstructionDeclarations ( std::ostream &  o) const
protected

Definition at line 184 of file RISCVTDGen.cc.

184 {
186 for (auto op : customOps_) {
187 writeInstructionDeclaration(o, op.first, op.second);
188 }
189}
void dumpClassDefinitions(std::ostream &) const
void writeInstructionDeclaration(std::ostream &o, const std::string &name, const int encoding) const

References customOps_, dumpClassDefinitions(), and writeInstructionDeclaration().

Referenced by initializeBackendContents().

Here is the call graph for this function:

◆ writePatternDefinition()

void RISCVTDGen::writePatternDefinition ( std::ostream &  o,
Operation op 
)
protected

Definition at line 227 of file RISCVTDGen.cc.

227 {
228 const unsigned numIns = op.numberOfInputs();
229 const unsigned numOuts = op.numberOfOutputs();
230 if (!operationCanBeMatched(op) || numIns > 3 || numIns < 1 ||
231 numOuts != 1) {
232 std::cout << "Skipping pattern for " << op.name() << std::endl;
233 return;
234 }
235 std::string pattern;
236 const std::string operandTypes =
237 mach_.is64bit() ? std::string(numIns + numOuts, OT_REG_LONG)
238 : std::string(numIns + numOuts, OT_REG_INT);
239
240 std::vector<OperationDAG*> dags;
241 OperationDAG* trivialDag = NULL;
243
245 op.dagCount() == 0) {
246 trivialDag = createTrivialDAG(op);
247 dags.push_back(trivialDag);
248 } else {
249 const std::vector<OperationDAG*> matchableDAGs =
251 dags.insert(dags.end(), matchableDAGs.begin(), matchableDAGs.end());
252 }
253 for (const OperationDAG* dag : dags) {
254 pattern = operationPattern(op, *dag, operandTypes);
255 o << "def : Pat<(XLenVT ";
256 o << transformTCEPattern(pattern, numIns);
257 o << ", (" << "OA_" + op.name().upper();
258 if (numIns == 3) {
259 o << " GPR:$rs1, GPR:$rs2, GPR:$rs3)>;\n";
260 } else if (numIns == 2) {
261 o << " GPR:$rs1, GPR:$rs2)>;\n";
262 } else {
263 o << " GPR:$rs1)>;\n";
264 }
265 }
266 if (trivialDag != NULL) {
267 delete trivialDag;
268 }
269}
virtual int dagCount() const
Definition Operation.cc:134
std::string transformTCEPattern(std::string pattern, const unsigned numIns) const
static const char OT_REG_LONG
Definition TDGen.hh:499
const std::vector< OperationDAG * > getMatchableOperationDAGs(const Operation &op)
Definition TDGen.cc:5391
OperationDAG * createTrivialDAG(Operation &op)
Definition TDGen.cc:6093
const TTAMachine::Machine & mach_
Definition TDGen.hh:463
virtual TCEString llvmOperationPattern(const Operation &op, char operandType=' ') const
Definition TDGen.cc:4895
virtual char operandChar(Operand &operand)
Definition TDGen.cc:4755
bool operationCanBeMatched(const Operation &op, std::set< std::string > *recursionCycleCheck=NULL, bool recursionHasStore=false)
Definition TDGen.cc:5281
std::string operationPattern(const Operation &op, const OperationDAG &dag, const std::string &operandTypes)
Definition TDGen.cc:5421
static const char OT_REG_INT
Definition TDGen.hh:498
bool is64bit() const
Definition Machine.hh:260

References TDGen::createTrivialDAG(), Operation::dagCount(), TDGen::getMatchableOperationDAGs(), TTAMachine::Machine::is64bit(), TDGen::llvmOperationPattern(), TDGen::mach_, Operation::name(), Operation::numberOfInputs(), Operation::numberOfOutputs(), TDGen::operandChar(), TDGen::operationCanBeMatched(), TDGen::operationPattern(), TDGen::OT_REG_INT, TDGen::OT_REG_LONG, transformTCEPattern(), and TCEString::upper().

Referenced by writePatternDefinitions().

Here is the call graph for this function:

◆ writePatternDefinitions()

void RISCVTDGen::writePatternDefinitions ( std::ostream &  o)
protected

Definition at line 272 of file RISCVTDGen.cc.

272 {
273 OperationPool opPool;
274 // o << "// ---- Instruction pattern defs start ----\n\n";
275 for (auto customOp : customOps_) {
276 const std::string opName = customOp.first;
277 Operation& op = opPool.operation(opName.c_str());
279 }
280 // o << "// ---- Instruction pattern defs end ----\n\n";
281}
void writePatternDefinition(std::ostream &o, Operation &op)

References customOps_, OperationPool::operation(), and writePatternDefinition().

Referenced by initializeBackendContents().

Here is the call graph for this function:

Member Data Documentation

◆ bem_

BinaryEncoding* RISCVTDGen::bem_
protected

Definition at line 69 of file RISCVTDGen.hh.

Referenced by findCustomOps(), and RISCVTDGen().

◆ customOps_

std::map<std::string, int> RISCVTDGen::customOps_
protected

◆ declarationStr_

std::string RISCVTDGen::declarationStr_
protected

Definition at line 71 of file RISCVTDGen.hh.

Referenced by generateBackend(), generateBackend(), and initializeBackendContents().

◆ patternStr_

std::string RISCVTDGen::patternStr_
protected

Definition at line 72 of file RISCVTDGen.hh.

Referenced by generateBackend(), and initializeBackendContents().


The documentation for this class was generated from the following files: