OpenASIP  2.0
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 53 of file LLVMTCERISCVIntrinsicsLowering.cc.

54  : MachineFunctionPass(ID) {
55  auto* option = static_cast<llvm::cl::opt<std::string>*>(
56  llvm::cl::getRegisteredOptions().lookup("adf"));
57  const std::string adf = option->getValue();
58  try {
60  } catch (const Exception& e) {
62  << "TCE: unable to load the ADF:" << std::endl
63  << e.errorMessage() << std::endl
64  << "Make sure you give the"
65  << " correct adf with the -adf switch to llc";
66  }
67  bem_ = BEMGenerator(*mach_).generate();
69 }

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 171 of file LLVMTCERISCVIntrinsicsLowering.cc.

172  {
173  const int fu3Mask = 0b1110000000;
174  const int fu7Mask = 0b11111110000000000;
175  const int opcodeMask = 0b1111111;
176  int encoding = rFormat_->encoding(opName);
177  const int fu3Enc = ((encoding & fu3Mask) >> 7);
178  const int fu7Enc = ((encoding & fu7Mask) >> 10);
179  const int opcodeEnc = encoding & opcodeMask;
180  const int shiftedEnc = (fu7Enc << 25) + (fu3Enc << 12) + opcodeEnc;
181 
182  encoding = shiftedEnc + (regIdxs.at(0) << 7) + (regIdxs.at(1) << 15) +
183  (regIdxs.at(2) << 20);
184 
185  return encoding;
186 }

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 72 of file LLVMTCERISCVIntrinsicsLowering.cc.

72  {
73  return false;
74 }

◆ findOperationName()

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

Definition at line 114 of file LLVMTCERISCVIntrinsicsLowering.cc.

115  {
116  std::vector<TCEString> asmSubStrings = StringTools::chopString(s, " ");
117  std::string opName = "";
118  for (TCEString i : asmSubStrings) {
119  std::string ss = static_cast<std::string>(i);
120  if (StringTools::containsChar(ss, '/')) {
121  ss = StringTools::replaceAllOccurrences(ss, "//", "");
123  if (rFormat_->hasOperation(ss)) {
124  opName = ss;
125  } else {
126  std::string msg = "Machine does not have operation: " + ss;
127  throw InvalidData(__FILE__, __LINE__, __func__, msg);
128  }
129  }
130  }
131  if (opName == "") {
132  const std::string msg =
133  "Warning: Failed to find operation name from: \"" + s + "\"";
134  std::cerr << msg << std::endl;
135  //std::string msg = "Failed to find operation name from: " + s;
136  //throw InvalidData(__FILE__, __LINE__, __func__, msg);
137  }
138  return opName;
139 }

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 142 of file LLVMTCERISCVIntrinsicsLowering.cc.

143  {
144  const unsigned OpIdx = 0;
145  std::vector<int> regIdxs;
146  const std::string asmString =
147  std::string(it->getOperand(OpIdx).getSymbolName());
148  for (unsigned o = 0; o < it->getNumOperands(); o++) {
149  const MachineOperand& mo = it->getOperand(o);
150  if (mo.isReg()) {
151  int idx = mo.getReg() - 40;
152  regIdxs.push_back(idx);
153  if (idx < 0 && idx > 31) {
154  std::string msg =
155  "Invalid register index: " + std::to_string(idx) +
156  " in instruction: " + asmString;
157  throw InvalidData(__FILE__, __LINE__, __func__, msg);
158  };
159  }
160  }
161  if (regIdxs.size() != 3) {
162  std::string msg = "3 reg operands required, found " +
163  std::to_string(regIdxs.size()) +
164  " in instruction: " + asmString;
165  throw InvalidData(__FILE__, __LINE__, __func__, msg);
166  }
167  return regIdxs;
168 }

References __func__.

Referenced by runOnMachineFunction().

◆ findRegs()

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

Definition at line 93 of file LLVMTCERISCVIntrinsicsLowering.cc.

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

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 77 of file LLVMTCERISCVIntrinsicsLowering.cc.

77  {
78  InstructionFormat* format = NULL;
79  for (int f = 0; f < bem_->instructionFormatCount(); f++) {
80  if (bem_->instructionFormat(f).name() == "riscv_r_type") {
81  format = &bem_->instructionFormat(f);
82  break;
83  }
84  }
85  if (format == NULL) {
86  std::string msg = "BEM does not identify R format ";
87  throw InvalidData(__FILE__, __LINE__, __func__, msg);
88  }
89  return format;
90 }

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

Referenced by LLVMTCERISCVIntrinsicsLowering().

Here is the call graph for this function:

◆ runOnMachineFunction()

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

Definition at line 189 of file LLVMTCERISCVIntrinsicsLowering.cc.

189  {
190  for (MachineFunction::iterator i = MF.begin(); i != MF.end(); i++) {
191  for (MachineBasicBlock::iterator j = i->begin(); j != i->end(); j++) {
192  if (j->isInlineAsm()) {
193  const unsigned OpIdx = 0;
194  std::string asmString =
195  std::string(j->getOperand(OpIdx).getSymbolName());
196  const std::string opName = findOperationName(asmString);
197  if (opName == "") {
198  continue;
199  }
200  const std::string regs = findRegs(asmString);
201  const std::vector<int> regIdxs = findRegIndexes(j);
202 
203  int encoding = constructEncoding(opName, regIdxs);
204  std::string* cName = new std::string(
205  ".long " + std::to_string(encoding) + "; #" + opName +
206  regs);
207  j->getOperand(OpIdx).ChangeToES(
208  cName->c_str(), j->getOperand(OpIdx).getTargetFlags());
209  }
210  }
211  }
212  return false;
213 }

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:
BinaryEncoding::instructionFormat
InstructionFormat & instructionFormat(int index) const
Definition: BinaryEncoding.cc:521
llvm::LLVMTCERISCVIntrinsicsLowering::constructEncoding
int constructEncoding(const std::string &opName, const std::vector< int > &regIdxs) const
Definition: LLVMTCERISCVIntrinsicsLowering.cc:171
InstructionFormat::name
std::string name() const
Definition: InstructionFormat.cc:115
StringTools::containsChar
static bool containsChar(const std::string &source, char ch, bool caseSensitive=true)
Definition: StringTools.cc:101
llvm::LLVMTCERISCVIntrinsicsLowering::rFormat_
InstructionFormat * rFormat_
Definition: LLVMTCERISCVIntrinsicsLowering.hh:62
llvm::LLVMTCERISCVIntrinsicsLowering::findRegIndexes
std::vector< int > findRegIndexes(const MachineBasicBlock::iterator &it) const
Definition: LLVMTCERISCVIntrinsicsLowering.cc:142
llvm::LLVMTCERISCVIntrinsicsLowering::findRFormat
InstructionFormat * findRFormat()
Definition: LLVMTCERISCVIntrinsicsLowering.cc:77
llvm::LLVMTCERISCVIntrinsicsLowering::mach_
TTAMachine::Machine * mach_
Definition: LLVMTCERISCVIntrinsicsLowering.hh:60
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
StringTools::replaceAllOccurrences
static std::string replaceAllOccurrences(const std::string &source, const std::string &occurrence, const std::string &newString)
Definition: StringTools.cc:295
BEMGenerator
Definition: BEMGenerator.hh:61
InvalidData
Definition: Exception.hh:149
llvm::LLVMTCERISCVIntrinsicsLowering::findRegs
std::string findRegs(const std::string &s) const
Definition: LLVMTCERISCVIntrinsicsLowering.cc:93
__func__
#define __func__
Definition: Application.hh:67
Exception
Definition: Exception.hh:54
llvm::LLVMTCERISCVIntrinsicsLowering::bem_
BinaryEncoding * bem_
Definition: LLVMTCERISCVIntrinsicsLowering.hh:61
InstructionFormat::hasOperation
bool hasOperation(const std::string &op) const
Definition: InstructionFormat.cc:104
InstructionFormat
Definition: InstructionFormat.hh:46
BinaryEncoding::instructionFormatCount
int instructionFormatCount() const
Definition: BinaryEncoding.cc:488
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TCEString
Definition: TCEString.hh:53
StringTools::chopString
static std::vector< TCEString > chopString(const std::string &source, const std::string &delimiters)
Definition: StringTools.cc:181
llvm::LLVMTCERISCVIntrinsicsLowering::ID
static char ID
Definition: LLVMTCERISCVIntrinsicsLowering.hh:44
InstructionFormat::encoding
int encoding(const std::string &op) const
Definition: InstructionFormat.cc:200
llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName
std::string findOperationName(const std::string &s) const
Definition: LLVMTCERISCVIntrinsicsLowering.cc:114
BEMGenerator::generate
BinaryEncoding * generate()
Definition: BEMGenerator.cc:104
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160
TTAMachine::Machine::loadFromADF
static Machine * loadFromADF(const std::string &adfFileName)
Definition: Machine.cc:905