Make code more readable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12305 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Misha Brukman
2004-03-12 00:58:41 +00:00
parent ec85af16a0
commit 56c0fa69a3
2 changed files with 62 additions and 70 deletions

View File

@ -53,7 +53,7 @@ namespace llvm {
struct ModRefTable { struct ModRefTable {
typedef hash_map<Instruction*, ModRefInfo> ModRefMap; typedef hash_map<Instruction*, ModRefInfo> ModRefMap;
typedef ModRefMap::const_iterator const_map_iterator; typedef ModRefMap::const_iterator const_map_iterator;
typedef ModRefMap:: iterator map_iterator; typedef ModRefMap:: iterator map_iterator;
typedef std::vector<Instruction*>::const_iterator const_ref_iterator; typedef std::vector<Instruction*>::const_iterator const_ref_iterator;
typedef std::vector<Instruction*>:: iterator ref_iterator; typedef std::vector<Instruction*>:: iterator ref_iterator;
@ -131,9 +131,9 @@ class ModRefInfoBuilder : public InstVisitor<ModRefInfoBuilder> {
void operator=(const ModRefInfoBuilder&); // DO NOT IMPLEMENT void operator=(const ModRefInfoBuilder&); // DO NOT IMPLEMENT
public: public:
/*ctor*/ ModRefInfoBuilder(const DSGraph& _funcGraph, ModRefInfoBuilder(const DSGraph& _funcGraph,
const FunctionModRefInfo& _funcModRef, const FunctionModRefInfo& _funcModRef,
ModRefTable& _modRefTable) ModRefTable& _modRefTable)
: funcGraph(_funcGraph), funcModRef(_funcModRef), modRefTable(_modRefTable) : funcGraph(_funcGraph), funcModRef(_funcModRef), modRefTable(_modRefTable)
{ {
} }
@ -142,15 +142,15 @@ public:
// Add the call to the defs list if it modifies any nodes and to the uses // Add the call to the defs list if it modifies any nodes and to the uses
// list if it refs any nodes. // list if it refs any nodes.
// //
void visitCallInst (CallInst& callInst) { void visitCallInst(CallInst& callInst) {
ModRefInfo safeModRef(funcGraph.getGraphSize()); ModRefInfo safeModRef(funcGraph.getGraphSize());
const ModRefInfo* callModRef = funcModRef.getModRefInfo(callInst); const ModRefInfo* callModRef = funcModRef.getModRefInfo(callInst);
if (callModRef == NULL) if (callModRef == NULL) {
{ // call to external/unknown function: mark all nodes as Mod and Ref // call to external/unknown function: mark all nodes as Mod and Ref
safeModRef.getModSet().set(); safeModRef.getModSet().set();
safeModRef.getRefSet().set(); safeModRef.getRefSet().set();
callModRef = &safeModRef; callModRef = &safeModRef;
} }
modRefTable.modRefMap.insert(std::make_pair(&callInst, modRefTable.modRefMap.insert(std::make_pair(&callInst,
ModRefInfo(*callModRef))); ModRefInfo(*callModRef)));
@ -163,40 +163,36 @@ public:
// At a store instruction, add to the mod set the single node pointed to // At a store instruction, add to the mod set the single node pointed to
// by the pointer argument of the store. Interestingly, if there is no // by the pointer argument of the store. Interestingly, if there is no
// such node, that would be a null pointer reference! // such node, that would be a null pointer reference!
void visitStoreInst (StoreInst& storeInst) { void visitStoreInst(StoreInst& storeInst) {
const DSNodeHandle& ptrNode = const DSNodeHandle& ptrNode =
funcGraph.getNodeForValue(storeInst.getPointerOperand()); funcGraph.getNodeForValue(storeInst.getPointerOperand());
if (const DSNode* target = ptrNode.getNode()) if (const DSNode* target = ptrNode.getNode()) {
{ unsigned nodeId = funcModRef.getNodeId(target);
unsigned nodeId = funcModRef.getNodeId(target); ModRefInfo& minfo =
ModRefInfo& minfo = modRefTable.modRefMap.insert(
modRefTable.modRefMap.insert( std::make_pair(&storeInst,
std::make_pair(&storeInst, ModRefInfo(funcGraph.getGraphSize()))).first->second;
ModRefInfo(funcGraph.getGraphSize()))).first->second; minfo.setNodeIsMod(nodeId);
minfo.setNodeIsMod(nodeId); modRefTable.AddDef(&storeInst);
modRefTable.AddDef(&storeInst); } else
}
else
std::cerr << "Warning: Uninitialized pointer reference!\n"; std::cerr << "Warning: Uninitialized pointer reference!\n";
} }
// At a load instruction, add to the ref set the single node pointed to // At a load instruction, add to the ref set the single node pointed to
// by the pointer argument of the load. Interestingly, if there is no // by the pointer argument of the load. Interestingly, if there is no
// such node, that would be a null pointer reference! // such node, that would be a null pointer reference!
void visitLoadInst (LoadInst& loadInst) { void visitLoadInst(LoadInst& loadInst) {
const DSNodeHandle& ptrNode = const DSNodeHandle& ptrNode =
funcGraph.getNodeForValue(loadInst.getPointerOperand()); funcGraph.getNodeForValue(loadInst.getPointerOperand());
if (const DSNode* target = ptrNode.getNode()) if (const DSNode* target = ptrNode.getNode()) {
{ unsigned nodeId = funcModRef.getNodeId(target);
unsigned nodeId = funcModRef.getNodeId(target); ModRefInfo& minfo =
ModRefInfo& minfo = modRefTable.modRefMap.insert(
modRefTable.modRefMap.insert( std::make_pair(&loadInst,
std::make_pair(&loadInst, ModRefInfo(funcGraph.getGraphSize()))).first->second;
ModRefInfo(funcGraph.getGraphSize()))).first->second; minfo.setNodeIsRef(nodeId);
minfo.setNodeIsRef(nodeId); modRefTable.AddUse(&loadInst);
modRefTable.AddUse(&loadInst); } else
}
else
std::cerr << "Warning: Uninitialized pointer reference!\n"; std::cerr << "Warning: Uninitialized pointer reference!\n";
} }
}; };

View File

@ -53,7 +53,7 @@ namespace llvm {
struct ModRefTable { struct ModRefTable {
typedef hash_map<Instruction*, ModRefInfo> ModRefMap; typedef hash_map<Instruction*, ModRefInfo> ModRefMap;
typedef ModRefMap::const_iterator const_map_iterator; typedef ModRefMap::const_iterator const_map_iterator;
typedef ModRefMap:: iterator map_iterator; typedef ModRefMap:: iterator map_iterator;
typedef std::vector<Instruction*>::const_iterator const_ref_iterator; typedef std::vector<Instruction*>::const_iterator const_ref_iterator;
typedef std::vector<Instruction*>:: iterator ref_iterator; typedef std::vector<Instruction*>:: iterator ref_iterator;
@ -131,9 +131,9 @@ class ModRefInfoBuilder : public InstVisitor<ModRefInfoBuilder> {
void operator=(const ModRefInfoBuilder&); // DO NOT IMPLEMENT void operator=(const ModRefInfoBuilder&); // DO NOT IMPLEMENT
public: public:
/*ctor*/ ModRefInfoBuilder(const DSGraph& _funcGraph, ModRefInfoBuilder(const DSGraph& _funcGraph,
const FunctionModRefInfo& _funcModRef, const FunctionModRefInfo& _funcModRef,
ModRefTable& _modRefTable) ModRefTable& _modRefTable)
: funcGraph(_funcGraph), funcModRef(_funcModRef), modRefTable(_modRefTable) : funcGraph(_funcGraph), funcModRef(_funcModRef), modRefTable(_modRefTable)
{ {
} }
@ -142,15 +142,15 @@ public:
// Add the call to the defs list if it modifies any nodes and to the uses // Add the call to the defs list if it modifies any nodes and to the uses
// list if it refs any nodes. // list if it refs any nodes.
// //
void visitCallInst (CallInst& callInst) { void visitCallInst(CallInst& callInst) {
ModRefInfo safeModRef(funcGraph.getGraphSize()); ModRefInfo safeModRef(funcGraph.getGraphSize());
const ModRefInfo* callModRef = funcModRef.getModRefInfo(callInst); const ModRefInfo* callModRef = funcModRef.getModRefInfo(callInst);
if (callModRef == NULL) if (callModRef == NULL) {
{ // call to external/unknown function: mark all nodes as Mod and Ref // call to external/unknown function: mark all nodes as Mod and Ref
safeModRef.getModSet().set(); safeModRef.getModSet().set();
safeModRef.getRefSet().set(); safeModRef.getRefSet().set();
callModRef = &safeModRef; callModRef = &safeModRef;
} }
modRefTable.modRefMap.insert(std::make_pair(&callInst, modRefTable.modRefMap.insert(std::make_pair(&callInst,
ModRefInfo(*callModRef))); ModRefInfo(*callModRef)));
@ -163,40 +163,36 @@ public:
// At a store instruction, add to the mod set the single node pointed to // At a store instruction, add to the mod set the single node pointed to
// by the pointer argument of the store. Interestingly, if there is no // by the pointer argument of the store. Interestingly, if there is no
// such node, that would be a null pointer reference! // such node, that would be a null pointer reference!
void visitStoreInst (StoreInst& storeInst) { void visitStoreInst(StoreInst& storeInst) {
const DSNodeHandle& ptrNode = const DSNodeHandle& ptrNode =
funcGraph.getNodeForValue(storeInst.getPointerOperand()); funcGraph.getNodeForValue(storeInst.getPointerOperand());
if (const DSNode* target = ptrNode.getNode()) if (const DSNode* target = ptrNode.getNode()) {
{ unsigned nodeId = funcModRef.getNodeId(target);
unsigned nodeId = funcModRef.getNodeId(target); ModRefInfo& minfo =
ModRefInfo& minfo = modRefTable.modRefMap.insert(
modRefTable.modRefMap.insert( std::make_pair(&storeInst,
std::make_pair(&storeInst, ModRefInfo(funcGraph.getGraphSize()))).first->second;
ModRefInfo(funcGraph.getGraphSize()))).first->second; minfo.setNodeIsMod(nodeId);
minfo.setNodeIsMod(nodeId); modRefTable.AddDef(&storeInst);
modRefTable.AddDef(&storeInst); } else
}
else
std::cerr << "Warning: Uninitialized pointer reference!\n"; std::cerr << "Warning: Uninitialized pointer reference!\n";
} }
// At a load instruction, add to the ref set the single node pointed to // At a load instruction, add to the ref set the single node pointed to
// by the pointer argument of the load. Interestingly, if there is no // by the pointer argument of the load. Interestingly, if there is no
// such node, that would be a null pointer reference! // such node, that would be a null pointer reference!
void visitLoadInst (LoadInst& loadInst) { void visitLoadInst(LoadInst& loadInst) {
const DSNodeHandle& ptrNode = const DSNodeHandle& ptrNode =
funcGraph.getNodeForValue(loadInst.getPointerOperand()); funcGraph.getNodeForValue(loadInst.getPointerOperand());
if (const DSNode* target = ptrNode.getNode()) if (const DSNode* target = ptrNode.getNode()) {
{ unsigned nodeId = funcModRef.getNodeId(target);
unsigned nodeId = funcModRef.getNodeId(target); ModRefInfo& minfo =
ModRefInfo& minfo = modRefTable.modRefMap.insert(
modRefTable.modRefMap.insert( std::make_pair(&loadInst,
std::make_pair(&loadInst, ModRefInfo(funcGraph.getGraphSize()))).first->second;
ModRefInfo(funcGraph.getGraphSize()))).first->second; minfo.setNodeIsRef(nodeId);
minfo.setNodeIsRef(nodeId); modRefTable.AddUse(&loadInst);
modRefTable.AddUse(&loadInst); } else
}
else
std::cerr << "Warning: Uninitialized pointer reference!\n"; std::cerr << "Warning: Uninitialized pointer reference!\n";
} }
}; };