[llvm] r249460 - [Function] Clean up {prefix, prologue} data routines (NFC)
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 13:31:57 PDT 2015
Author: vedantk
Date: Tue Oct 6 15:31:57 2015
New Revision: 249460
URL: http://llvm.org/viewvc/llvm-project?rev=249460&view=rev
Log:
[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
Modified:
llvm/trunk/lib/IR/Function.cpp
llvm/trunk/lib/IR/LLVMContextImpl.h
Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=249460&r1=249459&r2=249460&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Tue Oct 6 15:31:57 2015
@@ -929,12 +929,36 @@ bool Function::callsFunctionThatReturnsT
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 *P
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) {
Modified: llvm/trunk/lib/IR/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=249460&r1=249459&r2=249460&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.h Tue Oct 6 15:31:57 2015
@@ -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);
More information about the llvm-commits
mailing list