OpenASIP  2.0
Functions
LLVMUtilities.cc File Reference
#include "LLVMUtilities.hh"
#include "TCEString.hh"
#include "tce_config.h"
#include "CompilerWarnings.hh"
#include <llvm/CodeGen/MachineInstr.h>
#include <llvm/CodeGen/MachineOperand.h>
#include <llvm/IR/DebugLoc.h>
#include <llvm/IR/DebugInfo.h>
Include dependency graph for LLVMUtilities.cc:

Go to the source code of this file.

Functions

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

Detailed Description

Implementations of LLVM utilities.

Author
Henry Linjamäki 2017 (henry.linjamaki-no.spam-tut.fi)
Note
reting: red

Declarations of LLVM utilities.

Author
Henry Linjamäki 2017 (henry.linjamaki-no.spam-tut.fi)
Note
reting: red

Definition in file LLVMUtilities.cc.

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()

POP_COMPILER_DIAGS 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