[Function] Clean up {prefix,prologue} data routines (NFC)

Factor out some common code used to get+set function prefix/prologue
data. This may come in handy if we ever decide to store personality
functions in the same way we store prefix/prologue data.

Differential Revision: http://reviews.llvm.org/D13120

Reviewed-by: bogner
llvm-svn: 249460
This commit is contained in:
Vedant Kumar 2015-10-06 20:31:57 +00:00
parent 2b56f86dab
commit 1ab5ea564f
2 changed files with 39 additions and 40 deletions

View File

@ -929,12 +929,36 @@ bool Function::callsFunctionThatReturnsTwice() const {
return false;
}
static Constant *
getFunctionData(const Function *F,
const LLVMContextImpl::FunctionDataMapTy &Map) {
const auto &Entry = Map.find(F);
assert(Entry != Map.end());
return cast<Constant>(Entry->second->getReturnValue());
}
/// setFunctionData - Set "Map[F] = Data". Return an updated SubclassData value
/// in which Bit is low iff Data is null.
static unsigned setFunctionData(Function *F,
LLVMContextImpl::FunctionDataMapTy &Map,
Constant *Data, unsigned SCData, unsigned Bit) {
ReturnInst *&Holder = Map[F];
if (Data) {
if (Holder)
Holder->setOperand(0, Data);
else
Holder = ReturnInst::Create(F->getContext(), Data);
return SCData | (1 << Bit);
} else {
delete Holder;
Map.erase(F);
return SCData & ~(1 << Bit);
}
}
Constant *Function::getPrefixData() const {
assert(hasPrefixData());
const LLVMContextImpl::PrefixDataMapTy &PDMap =
getContext().pImpl->PrefixDataMap;
assert(PDMap.find(this) != PDMap.end());
return cast<Constant>(PDMap.find(this)->second->getReturnValue());
return getFunctionData(this, getContext().pImpl->PrefixDataMap);
}
void Function::setPrefixData(Constant *PrefixData) {
@ -942,49 +966,24 @@ void Function::setPrefixData(Constant *PrefixData) {
return;
unsigned SCData = getSubclassDataFromValue();
LLVMContextImpl::PrefixDataMapTy &PDMap = getContext().pImpl->PrefixDataMap;
ReturnInst *&PDHolder = PDMap[this];
if (PrefixData) {
if (PDHolder)
PDHolder->setOperand(0, PrefixData);
else
PDHolder = ReturnInst::Create(getContext(), PrefixData);
SCData |= (1<<1);
} else {
delete PDHolder;
PDMap.erase(this);
SCData &= ~(1<<1);
}
SCData = setFunctionData(this, getContext().pImpl->PrefixDataMap, PrefixData,
SCData, /*Bit=*/1);
setValueSubclassData(SCData);
}
Constant *Function::getPrologueData() const {
assert(hasPrologueData());
const LLVMContextImpl::PrologueDataMapTy &SOMap =
getContext().pImpl->PrologueDataMap;
assert(SOMap.find(this) != SOMap.end());
return cast<Constant>(SOMap.find(this)->second->getReturnValue());
return getFunctionData(this, getContext().pImpl->PrologueDataMap);
}
void Function::setPrologueData(Constant *PrologueData) {
if (!PrologueData && !hasPrologueData())
return;
unsigned PDData = getSubclassDataFromValue();
LLVMContextImpl::PrologueDataMapTy &PDMap = getContext().pImpl->PrologueDataMap;
ReturnInst *&PDHolder = PDMap[this];
if (PrologueData) {
if (PDHolder)
PDHolder->setOperand(0, PrologueData);
else
PDHolder = ReturnInst::Create(getContext(), PrologueData);
PDData |= (1<<2);
} else {
delete PDHolder;
PDMap.erase(this);
PDData &= ~(1<<2);
}
setValueSubclassData(PDData);
unsigned SCData = getSubclassDataFromValue();
SCData = setFunctionData(this, getContext().pImpl->PrologueDataMap,
PrologueData, SCData, /*Bit=*/2);
setValueSubclassData(SCData);
}
void Function::setEntryCount(uint64_t Count) {

View File

@ -972,16 +972,16 @@ public:
/// instructions in different blocks at the same location.
DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
typedef DenseMap<const Function *, ReturnInst *> FunctionDataMapTy;
/// \brief Mapping from a function to its prefix data, which is stored as the
/// operand of an unparented ReturnInst so that the prefix data has a Use.
typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
PrefixDataMapTy PrefixDataMap;
FunctionDataMapTy PrefixDataMap;
/// \brief Mapping from a function to its prologue data, which is stored as
/// the operand of an unparented ReturnInst so that the prologue data has a
/// Use.
typedef DenseMap<const Function *, ReturnInst *> PrologueDataMapTy;
PrologueDataMapTy PrologueDataMap;
FunctionDataMapTy PrologueDataMap;
int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);