diff options
author | Gordon Henriksen <gordonhenriksen@mac.com> | 2007-12-10 03:18:06 +0000 |
---|---|---|
committer | Gordon Henriksen <gordonhenriksen@mac.com> | 2007-12-10 03:18:06 +0000 |
commit | 13fe5e35f69016557bde1eb0fd2229fa3b762a7a (patch) | |
tree | b17b6964d35ffeaa66a62793e9cb123e67b69310 /lib/Bitcode | |
parent | c8ddfa60b8711b95e3c46a73257cab15b3f7bbed (diff) | |
download | external_llvm-13fe5e35f69016557bde1eb0fd2229fa3b762a7a.zip external_llvm-13fe5e35f69016557bde1eb0fd2229fa3b762a7a.tar.gz external_llvm-13fe5e35f69016557bde1eb0fd2229fa3b762a7a.tar.bz2 |
Adding a collector name attribute to Function in the IR. These
methods are new to Function:
bool hasCollector() const;
const std::string &getCollector() const;
void setCollector(const std::string &);
void clearCollector();
The assembly representation is as such:
define void @f() gc "shadow-stack" { ...
The implementation uses an on-the-side table to map Functions to
collector names, such that there is no overhead. A StringPool is
further used to unique collector names, which are extremely
likely to be unique per process.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44769 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 15 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 33 |
2 files changed, 37 insertions, 11 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index c405feb..fd3ec9e 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -849,6 +849,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) { SmallVector<uint64_t, 64> Record; std::vector<std::string> SectionTable; + std::vector<std::string> CollectorTable; // Read all the records for this module. while (!Stream.AtEndOfStream()) { @@ -974,6 +975,13 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) { SectionTable.push_back(S); break; } + case bitc::MODULE_CODE_COLLECTORNAME: { // SECTIONNAME: [strchr x N] + std::string S; + if (ConvertToString(Record, 0, S)) + return Error("Invalid MODULE_CODE_COLLECTORNAME record"); + CollectorTable.push_back(S); + break; + } // GLOBALVAR: [type, isconst, initid, // linkage, alignment, section, visibility, threadlocal] case bitc::MODULE_CODE_GLOBALVAR: { @@ -1016,7 +1024,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) { break; } // FUNCTION: [type, callingconv, isproto, linkage, paramattr, - // alignment, section, visibility] + // alignment, section, visibility, collector] case bitc::MODULE_CODE_FUNCTION: { if (Record.size() < 8) return Error("Invalid MODULE_CODE_FUNCTION record"); @@ -1044,6 +1052,11 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) { Func->setSection(SectionTable[Record[6]-1]); } Func->setVisibility(GetDecodedVisibility(Record[7])); + if (Record.size() > 8 && Record[8]) { + if (Record[8]-1 > CollectorTable.size()) + return Error("Invalid collector ID"); + Func->setCollector(CollectorTable[Record[8]-1].c_str()); + } ValueList.push_back(Func); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 6d111fa..612d893 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -297,9 +297,10 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, WriteStringRecord(bitc::MODULE_CODE_ASM, M->getModuleInlineAsm(), 0/*TODO*/, Stream); - // Emit information about sections, computing how many there are. Also - // compute the maximum alignment value. + // Emit information about sections and collectors, computing how many there + // are. Also compute the maximum alignment value. std::map<std::string, unsigned> SectionMap; + std::map<std::string, unsigned> CollectorMap; unsigned MaxAlignment = 0; unsigned MaxGlobalType = 0; for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); @@ -317,13 +318,24 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, } for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { MaxAlignment = std::max(MaxAlignment, F->getAlignment()); - if (!F->hasSection()) continue; - // Give section names unique ID's. - unsigned &Entry = SectionMap[F->getSection()]; - if (Entry != 0) continue; - WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, F->getSection(), - 0/*TODO*/, Stream); - Entry = SectionMap.size(); + if (F->hasSection()) { + // Give section names unique ID's. + unsigned &Entry = SectionMap[F->getSection()]; + if (!Entry) { + WriteStringRecord(bitc::MODULE_CODE_SECTIONNAME, F->getSection(), + 0/*TODO*/, Stream); + Entry = SectionMap.size(); + } + } + if (F->hasCollector()) { + // Same for collector names. + unsigned &Entry = CollectorMap[F->getCollector()]; + if (!Entry) { + WriteStringRecord(bitc::MODULE_CODE_COLLECTORNAME, F->getCollector(), + 0/*TODO*/, Stream); + Entry = CollectorMap.size(); + } + } } // Emit abbrev for globals, now that we know # sections and max alignment. @@ -383,7 +395,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, // Emit the function proto information. for (Module::const_iterator F = M->begin(), E = M->end(); F != E; ++F) { // FUNCTION: [type, callingconv, isproto, paramattr, - // linkage, alignment, section, visibility] + // linkage, alignment, section, visibility, collector] Vals.push_back(VE.getTypeID(F->getType())); Vals.push_back(F->getCallingConv()); Vals.push_back(F->isDeclaration()); @@ -392,6 +404,7 @@ static void WriteModuleInfo(const Module *M, const ValueEnumerator &VE, Vals.push_back(Log2_32(F->getAlignment())+1); Vals.push_back(F->hasSection() ? SectionMap[F->getSection()] : 0); Vals.push_back(getEncodedVisibility(F)); + Vals.push_back(F->hasCollector() ? CollectorMap[F->getCollector()] : 0); unsigned AbbrevToUse = 0; Stream.EmitRecord(bitc::MODULE_CODE_FUNCTION, Vals, AbbrevToUse); |