9 #ifndef IR_SEG_SEGCALLSITE_H
10 #define IR_SEG_SEGCALLSITE_H
12 #include <llvm/IR/BasicBlock.h>
13 #include <llvm/IR/CallSite.h>
14 #include <llvm/IR/Function.h>
15 #include <llvm/IR/Instructions.h>
16 #include <llvm/IR/Value.h>
21 #include "IR/SEG/SEGCallSitePseudoInputNode.h"
22 #include "IR/SEG/SymbolicExprGraph.h"
37 : InputNode(N), InputIndex(I), IsCommonInput(C) {}
41 std::vector<SEGCallSiteInputStruct> PseudoInputs;
42 std::vector<SEGCallSitePseudoOutputNode *> PseudoOutputs;
43 bool IsBackEdge =
false;
44 bool IsExpanded =
false;
47 namespace FalconPlus {
52 friend class SEGSerializer;
56 std::set<const SEGNodeBase *> CommonInputNodes;
58 std::vector<SEGCallSiteInputStruct> CommonInputs;
61 std::map<Function *, SideEffectIO> SideEffectMap;
68 kvec<SEGCallSiteArgumentSummaryNode *> InputSummaryNodes;
69 kvec<SEGOperandNode *> OutputSummaryNodes;
73 friend class IntraFalcon;
74 friend class FalconPlus::IntraFalcon;
75 friend class MantaIntraFalcon;
89 void addCallee(Function *Callee) {
90 if (getCalledFunction()) {
91 assert(getCalledFunction() == Callee);
93 SideEffectMap[Callee];
97 void setInputSummaryNode(
int APDepth,
99 void setOutputSummaryNode(
int APDepth,
SEGOperandNode *SummaryNode);
102 void setBackEdge(Function *Callee) {
103 SideEffectMap[Callee].IsBackEdge =
true;
106 bool isBackEdge(Function *Callee)
const {
107 if (SideEffectMap.count(Callee)) {
108 return SideEffectMap.at(Callee).IsBackEdge;
113 void setExpanded(Function *Callee) {
114 SideEffectMap[Callee].IsExpanded =
true;
117 bool isExpanded(Function *Callee)
const {
118 if (Callee && SideEffectMap.count(Callee)) {
119 return SideEffectMap.at(Callee).IsExpanded;
126 const SEGOperandNode *getPseudoInput(Function *,
size_t Index)
const;
133 bool hasCommonOutput()
const;
135 bool isCommonInput(
const SEGNodeBase *Node)
const {
136 return this->CommonInputNodes.count(Node);
139 size_t getNumOutputs(Function *)
const;
141 size_t getNumPseudoOutputs(Function *)
const;
143 size_t getNumInputs(Function *)
const;
145 size_t getNumCommonInputs()
const;
147 size_t getNumPseudoInputs(Function *)
const;
149 size_t getInputIndex(
const SEGNodeBase *Input)
const;
151 bool hasCallee(Function *Func)
const {
return SideEffectMap.count(Func); }
153 Function *getCalledFunction()
const {
154 return this->getLLVMCallSite().getCalledFunction();
157 static bool classof(
const SEGObject *N) {
158 return N->getKind() == SEGOBJK_CallSite;
165 std::map<Function *, SideEffectIO>::const_iterator It;
168 CalleeIterator(
bool End,
const std::map<Function *, SideEffectIO> &M) {
196 Function *operator*() {
return It->first; }
198 bool operator==(
const CalleeIterator &CIt) {
return It == CIt.It; }
200 bool operator!=(
const CalleeIterator &CIt) {
return It != CIt.It; }
207 const std::vector<SEGCallSiteInputStruct> &CommonIns;
208 const std::vector<SEGCallSiteInputStruct> &PseudoIns;
211 InputIterator(
bool End,
const std::vector<SEGCallSiteInputStruct> &CI,
212 const std::vector<SEGCallSiteInputStruct> &PI)
213 : I(End ? CI.size() + PI.size() : 0), CommonIns(CI), PseudoIns(PI) {}
216 : I(It.I), CommonIns(It.CommonIns), PseudoIns(It.PseudoIns) {}
230 return I < CommonIns.size() ? CommonIns[I]
231 : PseudoIns[I - CommonIns.size()];
234 bool operator==(
const InputIterator &It) {
return I == It.I; }
236 bool operator!=(
const InputIterator &It) {
return I != It.I; }
244 const std::vector<SEGCallSitePseudoOutputNode *> &PseudoOuts;
248 const std::vector<SEGCallSitePseudoOutputNode *> &POs)
249 : I(End ? (POs.size() + (CO ? 1 : 0)) : 0), CommonOut(CO),
253 : I(It.I), CommonOut(It.CommonOut), PseudoOuts(It.PseudoOuts) {}
288 CalleeIterator callee_end()
const {
289 return CalleeIterator(
true, SideEffectMap);
292 size_t callee_size()
const {
return SideEffectMap.size(); }
294 InputIterator input_begin(Function *Callee)
const {
295 auto It = SideEffectMap.find(Callee);
296 assert(It != SideEffectMap.end());
297 auto &PseudoInputsVec = It->second.PseudoInputs;
298 return InputIterator(
false, CommonInputs, PseudoInputsVec);
301 InputIterator input_end(Function *Callee)
const {
302 auto It = SideEffectMap.find(Callee);
303 assert(It != SideEffectMap.end());
304 auto &PseudoInputsVec = It->second.PseudoInputs;
305 return InputIterator(
true, CommonInputs, PseudoInputsVec);
308 std::vector<SEGCallSiteInputStruct>::const_iterator
309 common_input_begin()
const {
310 return CommonInputs.begin();
313 std::vector<SEGCallSiteInputStruct>::const_iterator common_input_end()
const {
314 return CommonInputs.end();
317 OutputIterator output_begin(Function *Callee)
const {
318 auto It = SideEffectMap.find(Callee);
319 assert(It != SideEffectMap.end());
320 auto &PseudoOutputsVec = It->second.PseudoOutputs;
321 return OutputIterator(
false, CommonOutput, PseudoOutputsVec);
324 OutputIterator output_end(Function *Callee)
const {
325 auto It = SideEffectMap.find(Callee);
326 assert(It != SideEffectMap.end());
327 auto &PseudoOutputsVec = It->second.PseudoOutputs;
328 return OutputIterator(
true, CommonOutput, PseudoOutputsVec);