OpenASIP  2.0
Namespaces | Typedefs | Functions
LLVMUtilities.hh File Reference
#include <string>
#include <tuple>
#include <map>
#include <vector>
#include "llvm/IR/InlineAsm.h"
Include dependency graph for LLVMUtilities.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 llvm
 

Typedefs

using AsmOperands = std::tuple< unsigned, std::vector< const llvm::MachineOperand * > >
 First = Inline asm kind defined in llvm/IR/InlineAsm.h Second = The associated operands. More...
 
using AsmPosition = unsigned
 Inline assembly operand position. The numbers are matched to template strings in inline asm texts - e.g. 2 => "$2". More...
 
using AsmOperandMap = std::map< AsmPosition, AsmOperands >
 

Functions

std::tuple< std::string, size_t > getSourceLocationInfo (const llvm::MachineInstr &mi)
 
std::string getSourceLocationString (const llvm::MachineInstr &mi)
 
AsmOperandMap getInlineAsmOperands (const llvm::MachineInstr &mi)
 

Typedef Documentation

◆ AsmOperandMap

Definition at line 60 of file LLVMUtilities.hh.

◆ AsmOperands

using AsmOperands = std::tuple< unsigned, std::vector<const llvm::MachineOperand*> >

First = Inline asm kind defined in llvm/IR/InlineAsm.h Second = The associated operands.

Definition at line 56 of file LLVMUtilities.hh.

◆ AsmPosition

using AsmPosition = unsigned

Inline assembly operand position. The numbers are matched to template strings in inline asm texts - e.g. 2 => "$2".

Definition at line 59 of file LLVMUtilities.hh.

Function Documentation

◆ getInlineAsmOperands()

AsmOperandMap getInlineAsmOperands ( const llvm::MachineInstr &  mi)

Decodes operands of INLINEASM instruction into more manageable struct.

Definition at line 92 of file LLVMUtilities.cc.

92  {
93  using namespace llvm;
94  AsmOperandMap result;
95 
96  unsigned asmOpdPos = 0;
97  unsigned endPos = mi.getNumOperands();
98  unsigned i = InlineAsm::MIOp_FirstOperand;
99 
100  while (i < endPos) {
101  const MachineOperand& mo = mi.getOperand(i);
102  if (mo.isMetadata()) {
103  i++;
104  continue;
105  }
106  unsigned opdKind = InlineAsm::getKind(mo.getImm());
107  unsigned numAsmOpds = InlineAsm::getNumOperandRegisters(mo.getImm());
108  unsigned flagOpdBegin = i + 1;
109  unsigned flagOpdEnd = flagOpdBegin + numAsmOpds;
110  std::vector<const llvm::MachineOperand*> flagOps;
111  for (unsigned opdIdx = flagOpdBegin; opdIdx < flagOpdEnd; opdIdx++) {
112  flagOps.push_back(&mi.getOperand(opdIdx));
113  }
114  result.insert({asmOpdPos, std::make_tuple(opdKind, flagOps)});
115 
116  i += numAsmOpds + 1;
117  asmOpdPos += 1;
118  }
119 
120  return result;
121 }

Referenced by InlineAsmParser::addLiveRangeData(), llvm::LLVMTCEBuilder::emitInlineAsm(), and InlineAsmParser::substituteAsmString().

◆ getSourceLocationInfo()

std::tuple<std::string, size_t> getSourceLocationInfo ( const llvm::MachineInstr &  mi)

Extracts source location info from the instruction.

If the instruction does not have debug info returns ("", 0);

Definition at line 54 of file LLVMUtilities.cc.

54  {
55  using namespace llvm;
56  DebugLoc dl = mi.getDebugLoc();
57  if (!dl) return std::make_tuple("", 0);
58 
59  bool hasDebugInfo = false;
60  hasDebugInfo = dl.getScope() != NULL;
61  if (!hasDebugInfo) return std::make_tuple("", 0);
62 
63  size_t sourceLineNumber = 0;
64  TCEString sourceFileName = "";
65 
66  // inspired from lib/codegen/MachineInstr.cpp
67  sourceLineNumber = dl.getLine();
68  sourceFileName = static_cast<TCEString>(
69  cast<DIScope>(dl.getScope())->getFilename().str());
70  return std::make_tuple(sourceFileName, sourceLineNumber);
71 }

Referenced by InlineAsmParser::addDebugInfoToInlineAsmBB(), llvm::LLVMTCEBuilder::emitInlineAsm(), getSourceLocationString(), and InlineAsmParser::substituteAsmString().

◆ getSourceLocationString()

std::string getSourceLocationString ( const llvm::MachineInstr &  mi)

Returns source location as "<src-file>:<src-line>: " string if available.

Otherwise return empty string.

Definition at line 78 of file LLVMUtilities.cc.

78  {
79  std::string srcFile;
80  unsigned srcLine;
81  std::tie(srcFile, srcLine) = getSourceLocationInfo(mi);
82  if (!srcFile.empty()) {
83  return srcFile + ":" + std::to_string(srcLine) + ": ";
84  }
85  return "";
86 }

References getSourceLocationInfo().

Referenced by llvm::LLVMTCEBuilder::emitInlineAsm().

Here is the call graph for this function:
getSourceLocationInfo
POP_COMPILER_DIAGS std::tuple< std::string, size_t > getSourceLocationInfo(const llvm::MachineInstr &mi)
Definition: LLVMUtilities.cc:54
llvm
Definition: InlineAsmParser.hh:49
AsmOperandMap
std::map< AsmPosition, AsmOperands > AsmOperandMap
Definition: LLVMUtilities.hh:60
TCEString
Definition: TCEString.hh:53