OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
llvm::LLVMTCERISCVIntrinsicsLowering Class Reference

#include <LLVMTCERISCVIntrinsicsLowering.hh>

Inheritance diagram for llvm::LLVMTCERISCVIntrinsicsLowering:
Inheritance graph
Collaboration diagram for llvm::LLVMTCERISCVIntrinsicsLowering:
Collaboration graph

Public Member Functions

 LLVMTCERISCVIntrinsicsLowering ()
 
virtual ~LLVMTCERISCVIntrinsicsLowering ()
 
virtual bool runOnMachineFunction (MachineFunction &MF)
 

Static Public Attributes

static char ID = 0
 

Private Member Functions

InstructionFormatfindRFormat ()
 
std::string findRegs (const std::string &s) const
 
std::string findOperationName (const std::string &s) const
 
std::vector< int > findRegIndexes (const MachineBasicBlock::iterator &it) const
 
int constructEncoding (const std::string &opName, const std::vector< int > &regIdxs) const
 
virtual bool doInitialization (Module &m)
 

Private Attributes

TTAMachine::Machinemach_
 
BinaryEncodingbem_
 
InstructionFormatrFormat_
 

Detailed Description

Definition at line 42 of file LLVMTCERISCVIntrinsicsLowering.hh.

Constructor & Destructor Documentation

◆ LLVMTCERISCVIntrinsicsLowering()

llvm::LLVMTCERISCVIntrinsicsLowering::LLVMTCERISCVIntrinsicsLowering ( )

Definition at line 58 of file LLVMTCERISCVIntrinsicsLowering.cc.

59 : MachineFunctionPass(ID) {
60 auto* option = static_cast<llvm::cl::opt<std::string>*>(
61 llvm::cl::getRegisteredOptions().lookup("adf"));
62 const std::string adf = option->getValue();
63 try {
65 } catch (const Exception& e) {
67 << "TCE: unable to load the ADF:" << std::endl
68 << e.errorMessage() << std::endl
69 << "Make sure you give the"
70 << " correct adf with the -adf switch to llc";
71 }
72 bem_ = BEMGenerator(*mach_).generate();
74}
static std::ostream & logStream()
BinaryEncoding * generate()
std::string errorMessage() const
Definition Exception.cc:123
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899

References bem_, Exception::errorMessage(), findRFormat(), BEMGenerator::generate(), TTAMachine::Machine::loadFromADF(), Application::logStream(), mach_, and rFormat_.

Here is the call graph for this function:

◆ ~LLVMTCERISCVIntrinsicsLowering()

virtual llvm::LLVMTCERISCVIntrinsicsLowering::~LLVMTCERISCVIntrinsicsLowering ( )
inlinevirtual

Definition at line 46 of file LLVMTCERISCVIntrinsicsLowering.hh.

46{}

Member Function Documentation

◆ constructEncoding()

int llvm::LLVMTCERISCVIntrinsicsLowering::constructEncoding ( const std::string &  opName,
const std::vector< int > &  regIdxs 
) const
private

Definition at line 182 of file LLVMTCERISCVIntrinsicsLowering.cc.

183 {
184 const int fu3Mask = 0b1110000000;
185 const int fu7Mask = 0b11111110000000000;
186 const int opcodeMask = 0b1111111;
187 int encoding = rFormat_->encoding(opName);
188 const int fu3Enc = ((encoding & fu3Mask) >> 7);
189 const int fu7Enc = ((encoding & fu7Mask) >> 10);
190 const int opcodeEnc = encoding & opcodeMask;
191 const int shiftedEnc = (fu7Enc << 25) + (fu3Enc << 12) + opcodeEnc;
192
193 encoding = shiftedEnc + (regIdxs.at(0) << 7) + (regIdxs.at(1) << 15) +
194 (regIdxs.at(2) << 20);
195
196 return encoding;
197}
int encoding(const std::string &op) const

References InstructionFormat::encoding(), and rFormat_.

Referenced by runOnMachineFunction().

Here is the call graph for this function:

◆ doInitialization()

bool llvm::LLVMTCERISCVIntrinsicsLowering::doInitialization ( Module &  m)
privatevirtual

Definition at line 77 of file LLVMTCERISCVIntrinsicsLowering.cc.

77 {
78 return false;
79}

◆ findOperationName()

std::string llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName ( const std::string &  s) const
private

Definition at line 119 of file LLVMTCERISCVIntrinsicsLowering.cc.

120 {
121 std::vector<TCEString> asmSubStrings = StringTools::chopString(s, " ");
122 std::string opName = "";
123 for (TCEString i : asmSubStrings) {
124 std::string ss = static_cast<std::string>(i);
125 if (StringTools::containsChar(ss, '/')) {
126 ss = StringTools::replaceAllOccurrences(ss, "//", "");
128 if (rFormat_->hasOperation(ss)) {
129 opName = ss;
130 } else {
131 std::string msg = "Machine does not have operation: " + ss;
132 throw InvalidData(__FILE__, __LINE__, __func__, msg);
133 }
134 }
135 }
136 if (opName == "") {
137 const std::string msg =
138 "Warning: Failed to find operation name from: \"" + s + "\"";
139 std::cerr << msg << std::endl;
140 //std::string msg = "Failed to find operation name from: " + s;
141 //throw InvalidData(__FILE__, __LINE__, __func__, msg);
142 }
143 return opName;
144}
#define __func__
bool hasOperation(const std::string &op) const
static bool containsChar(const std::string &source, char ch, bool caseSensitive=true)
static std::string stringToLower(const std::string &source)
static std::vector< TCEString > chopString(const std::string &source, const std::string &delimiters)
static std::string replaceAllOccurrences(const std::string &source, const std::string &occurrence, const std::string &newString)

References __func__, StringTools::chopString(), StringTools::containsChar(), InstructionFormat::hasOperation(), StringTools::replaceAllOccurrences(), rFormat_, and StringTools::stringToLower().

Referenced by runOnMachineFunction().

Here is the call graph for this function:

◆ findRegIndexes()

std::vector< int > llvm::LLVMTCERISCVIntrinsicsLowering::findRegIndexes ( const MachineBasicBlock::iterator &  it) const
private

Definition at line 147 of file LLVMTCERISCVIntrinsicsLowering.cc.

148 {
149 const unsigned OpIdx = 0;
150 std::vector<int> regIdxs;
151 const std::string asmString =
152 std::string(it->getOperand(OpIdx).getSymbolName());
153 for (unsigned o = 0; o < it->getNumOperands(); o++) {
154 const MachineOperand& mo = it->getOperand(o);
155 if (mo.isReg()) {
156 // TODO: Fix this virtual to physical reg mapping
157#ifdef LLVM_OLDER_THAN_17
158 const int magicNumber = 40;
159#else
160 const int magicNumber = 41;
161#endif
162 int idx = mo.getReg() - magicNumber;
163 regIdxs.push_back(idx);
164 if (idx < 0 && idx > 31) {
165 std::string msg =
166 "Invalid register index: " + std::to_string(idx) +
167 " in instruction: " + asmString;
168 throw InvalidData(__FILE__, __LINE__, __func__, msg);
169 };
170 }
171 }
172 if (regIdxs.size() != 3) {
173 std::string msg = "3 reg operands required, found " +
174 std::to_string(regIdxs.size()) +
175 " in instruction: " + asmString;
176 throw InvalidData(__FILE__, __LINE__, __func__, msg);
177 }
178 return regIdxs;
179}

References __func__.

Referenced by runOnMachineFunction().

◆ findRegs()

std::string llvm::LLVMTCERISCVIntrinsicsLowering::findRegs ( const std::string &  s) const
private

Definition at line 98 of file LLVMTCERISCVIntrinsicsLowering.cc.

98 {
99 std::vector<TCEString> asmSubStrings = StringTools::chopString(s, " ");
100 std::string regs = "";
101 int foundRegs = 0;
102 for (TCEString i : asmSubStrings) {
103 std::string ss = static_cast<std::string>(i);
104 if (StringTools::containsChar(ss, '$')) {
105 regs += " " + ss;
106 foundRegs++;
107 }
108 }
109 if (foundRegs != 3) {
110 std::string msg =
111 "Invalid amount of register operands, 3 required, found " +
112 std::to_string(foundRegs);
113 throw InvalidData(__FILE__, __LINE__, __func__, msg);
114 }
115 return regs;
116}

References __func__, StringTools::chopString(), and StringTools::containsChar().

Referenced by runOnMachineFunction().

Here is the call graph for this function:

◆ findRFormat()

InstructionFormat * llvm::LLVMTCERISCVIntrinsicsLowering::findRFormat ( )
private

Definition at line 82 of file LLVMTCERISCVIntrinsicsLowering.cc.

82 {
83 InstructionFormat* format = NULL;
84 for (int f = 0; f < bem_->instructionFormatCount(); f++) {
86 format = &bem_->instructionFormat(f);
87 break;
88 }
89 }
90 if (format == NULL) {
91 std::string msg = "BEM does not identify R format ";
92 throw InvalidData(__FILE__, __LINE__, __func__, msg);
93 }
94 return format;
95}
int instructionFormatCount() const
InstructionFormat & instructionFormat(int index) const
std::string name() const
const std::string RISCV_R_TYPE_NAME

References __func__, bem_, BinaryEncoding::instructionFormat(), BinaryEncoding::instructionFormatCount(), InstructionFormat::name(), and RISCVFields::RISCV_R_TYPE_NAME.

Referenced by LLVMTCERISCVIntrinsicsLowering().

Here is the call graph for this function:

◆ runOnMachineFunction()

bool llvm::LLVMTCERISCVIntrinsicsLowering::runOnMachineFunction ( MachineFunction &  MF)
virtual

Definition at line 200 of file LLVMTCERISCVIntrinsicsLowering.cc.

200 {
201 for (MachineFunction::iterator i = MF.begin(); i != MF.end(); i++) {
202 for (MachineBasicBlock::iterator j = i->begin(); j != i->end(); j++) {
203 if (j->isInlineAsm()) {
204 const unsigned OpIdx = 0;
205 std::string asmString =
206 std::string(j->getOperand(OpIdx).getSymbolName());
207 const std::string opName = findOperationName(asmString);
208 if (opName == "") {
209 continue;
210 }
211 const std::string regs = findRegs(asmString);
212 const std::vector<int> regIdxs = findRegIndexes(j);
213
214 int encoding = constructEncoding(opName, regIdxs);
215 std::string* cName = new std::string(
216 ".long " + std::to_string(encoding) + "; #" + opName +
217 regs);
218 j->getOperand(OpIdx).ChangeToES(
219 cName->c_str(), j->getOperand(OpIdx).getTargetFlags());
220 }
221 }
222 }
223 return false;
224}
std::string findRegs(const std::string &s) const
std::string findOperationName(const std::string &s) const
std::vector< int > findRegIndexes(const MachineBasicBlock::iterator &it) const
int constructEncoding(const std::string &opName, const std::vector< int > &regIdxs) const

References constructEncoding(), findOperationName(), findRegIndexes(), and findRegs().

Here is the call graph for this function:

Member Data Documentation

◆ bem_

BinaryEncoding* llvm::LLVMTCERISCVIntrinsicsLowering::bem_
private

◆ ID

char llvm::LLVMTCERISCVIntrinsicsLowering::ID = 0
static

Definition at line 44 of file LLVMTCERISCVIntrinsicsLowering.hh.

◆ mach_

TTAMachine::Machine* llvm::LLVMTCERISCVIntrinsicsLowering::mach_
private

Definition at line 60 of file LLVMTCERISCVIntrinsicsLowering.hh.

Referenced by LLVMTCERISCVIntrinsicsLowering().

◆ rFormat_

InstructionFormat* llvm::LLVMTCERISCVIntrinsicsLowering::rFormat_
private

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