OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
LLVMAliasAnalyzer Class Reference

#include <LLVMAliasAnalyzer.hh>

Inheritance diagram for LLVMAliasAnalyzer:
Inheritance graph
Collaboration diagram for LLVMAliasAnalyzer:
Collaboration graph

Public Member Functions

 LLVMAliasAnalyzer ()
 
virtual bool isAddressTraceable (DataDependenceGraph &ddg, const ProgramOperation &pop)
 
virtual AliasingResult analyze (DataDependenceGraph &ddg, const ProgramOperation &pop1, const ProgramOperation &pop2, MoveNodeUse::BBRelation bbInfo)
 
virtual void setLLVMAA (llvm::AliasAnalysis *AA)
 
 ~LLVMAliasAnalyzer ()
 
- Public Member Functions inherited from MemoryAliasAnalyzer
virtual void initProcedure (TTAProgram::Procedure &)
 
virtual ~MemoryAliasAnalyzer ()
 

Private Attributes

llvm::AliasAnalysisAA_
 

Additional Inherited Members

- Public Types inherited from MemoryAliasAnalyzer
enum  AliasingResult { ALIAS_FALSE = 0, ALIAS_TRUE = 1, ALIAS_UNKNOWN = 2, ALIAS_PARTIAL = 3 }
 
- Protected Member Functions inherited from MemoryAliasAnalyzer
AliasingResult compareIndeces (int index1, int index2, const ProgramOperation &pop1, const ProgramOperation &pop2)
 
- Static Protected Member Functions inherited from MemoryAliasAnalyzer
static const MoveNodeaddressOperandMove (const ProgramOperation &po)
 
static TwoPartAddressOperandDetection findTwoPartAddressOperands (const ProgramOperation &po)
 
static const MoveNodesearchLoopIndexBasedIncrement (DataDependenceGraph &ddg, const MoveNode &mn, long &loopIncrement)
 
static const MoveNodefindIncrement (const MoveNode &mn, long &increment)
 
static const MoveNodedetectConstantScale (const MoveNode &mn, int &shiftAmount)
 

Detailed Description

Definition at line 54 of file LLVMAliasAnalyzer.hh.

Constructor & Destructor Documentation

◆ LLVMAliasAnalyzer()

LLVMAliasAnalyzer::LLVMAliasAnalyzer ( )

Definition at line 68 of file LLVMAliasAnalyzer.cc.

68  {
69  AA_ = NULL;
70 }

◆ ~LLVMAliasAnalyzer()

LLVMAliasAnalyzer::~LLVMAliasAnalyzer ( )

Definition at line 161 of file LLVMAliasAnalyzer.cc.

161 {}

Member Function Documentation

◆ analyze()

MemoryAliasAnalyzer::AliasingResult LLVMAliasAnalyzer::analyze ( DataDependenceGraph ddg,
const ProgramOperation pop1,
const ProgramOperation pop2,
MoveNodeUse::BBRelation  bbInfo 
)
virtual

Given two program operation, aswer question if memory accesed by those operations aliases.

If both POs access same memory returns true, if is sure the memory is not same, returns false. Returns unknown in case memory accesses may alias, or if there is partial alias.

Implements MemoryAliasAnalyzer.

Definition at line 96 of file LLVMAliasAnalyzer.cc.

100  {
101 
102  if (bbInfo) {
103  return ALIAS_UNKNOWN;
104  }
105 
106  if (!isAddressTraceable(ddg, pop1) ||
107  !isAddressTraceable(ddg, pop2) ||
108  AA_ == NULL) {
109  return ALIAS_UNKNOWN;
110  }
111 
112  const llvm::MachineInstr* instr1 = pop1.machineInstr();
113  const llvm::MachineInstr* instr2 = pop2.machineInstr();
114 
115  llvm::MachineInstr::mmo_iterator begin1 =
116  instr1->memoperands_begin();
117  // Machine instruction could in theory have several memory operands.
118  // In practice it is usually just one.
120  while (begin1 != instr1->memoperands_end()) {
121  const llvm::Value* val1 = (*begin1)->getValue();
122  uint64_t size1 = (*begin1)->getSize();
123  llvm::MachineInstr::mmo_iterator begin2 =
124  instr2->memoperands_begin();
125 
126  while (begin2 != instr2->memoperands_end()) {
127  const llvm::Value* val2 = (*begin2)->getValue();
128  uint64_t size2 = (*begin2)->getSize();
129  if (val1 && val2) {
130 
131  AliasResult res =
132  AA_->alias(val1, size1, val2, size2);
133 
134  if (res == MayAlias || res == PartialAlias) {
135  result = ALIAS_UNKNOWN;
136  }
137  if (res == MustAlias) {
138  result = ALIAS_TRUE;
139  }
140  if (res == NoAlias) {
141  result = ALIAS_FALSE;
142  }
143  } else {
144  result = ALIAS_UNKNOWN;
145  }
146  begin2++;
147  }
148  begin1++;
149  }
150  return result;
151 }

References ProgramOperation::machineInstr(), MayAlias, MustAlias, NoAlias, and PartialAlias.

Here is the call graph for this function:

◆ isAddressTraceable()

bool LLVMAliasAnalyzer::isAddressTraceable ( DataDependenceGraph ddg,
const ProgramOperation pop 
)
virtual

Checks whether the analyzer knows anything about the address.

ie. if it can return true or false to some query concerning this address.

Returns
true if analyzer can know something about the address.

Implements MemoryAliasAnalyzer.

Definition at line 73 of file LLVMAliasAnalyzer.cc.

75  {
76  // If the ProgramOperation has access to it's originating LLVM MachineInstr
77  // and MachineInstr have some memory operands we can try tracing memory
78  // accessed.
79  const llvm::MachineInstr* instr = po.machineInstr();
80  if (instr && !instr->memoperands_empty()) {
81  return true;
82  } else {
83  return false;
84  }
85 }

References ProgramOperation::machineInstr().

Here is the call graph for this function:

◆ setLLVMAA()

void LLVMAliasAnalyzer::setLLVMAA ( llvm::AliasAnalysis AA)
virtual

Sets active Alias Analyzer picked from LLVM.

Definition at line 157 of file LLVMAliasAnalyzer.cc.

157  {
158  AA_ = AA;
159 }

Referenced by DataDependenceGraphBuilder::build().

Member Data Documentation

◆ AA_

llvm::AliasAnalysis* LLVMAliasAnalyzer::AA_
private

Definition at line 68 of file LLVMAliasAnalyzer.hh.


The documentation for this class was generated from the following files:
MayAlias
#define MayAlias
Definition: LLVMAliasAnalyzer.cc:63
MemoryAliasAnalyzer::ALIAS_UNKNOWN
@ ALIAS_UNKNOWN
Definition: MemoryAliasAnalyzer.hh:54
AliasResult
llvm::AliasResult AliasResult
Definition: LLVMAliasAnalyzer.hh:52
MustAlias
#define MustAlias
Definition: LLVMAliasAnalyzer.cc:65
MemoryAliasAnalyzer::ALIAS_FALSE
@ ALIAS_FALSE
Definition: MemoryAliasAnalyzer.hh:50
LLVMAliasAnalyzer::isAddressTraceable
virtual bool isAddressTraceable(DataDependenceGraph &ddg, const ProgramOperation &pop)
Definition: LLVMAliasAnalyzer.cc:73
ProgramOperation::machineInstr
const llvm::MachineInstr * machineInstr() const
Definition: ProgramOperation.hh:136
LLVMAliasAnalyzer::AA_
llvm::AliasAnalysis * AA_
Definition: LLVMAliasAnalyzer.hh:68
MemoryAliasAnalyzer::AliasingResult
AliasingResult
Definition: MemoryAliasAnalyzer.hh:50
MemoryAliasAnalyzer::ALIAS_TRUE
@ ALIAS_TRUE
Definition: MemoryAliasAnalyzer.hh:53
NoAlias
#define NoAlias
Definition: LLVMAliasAnalyzer.cc:66
PartialAlias
#define PartialAlias
Definition: LLVMAliasAnalyzer.cc:64