|
69 | 69 | #include "llvm/Support/MathExtras.h"
|
70 | 70 | #include "llvm/Support/SHA1.h"
|
71 | 71 | #include "llvm/Support/raw_ostream.h"
|
72 |
| -#include "llvm/Transforms/Utils/ModuleUtils.h" |
73 | 72 | #include <algorithm>
|
74 | 73 | #include <cassert>
|
75 | 74 | #include <cstddef>
|
@@ -4975,6 +4974,39 @@ void llvm::EmbedBitcodeInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
|
4975 | 4974 | NewUsed->setSection("llvm.metadata");
|
4976 | 4975 | }
|
4977 | 4976 |
|
| 4977 | +static void appendToCompilerUsed(Module &M, ArrayRef<GlobalValue *> Values) { |
| 4978 | + GlobalVariable *GV = M.getGlobalVariable("llvm.compiler.used"); |
| 4979 | + SmallPtrSet<Constant *, 16> InitAsSet; |
| 4980 | + SmallVector<Constant *, 16> Init; |
| 4981 | + if (GV) { |
| 4982 | + if (GV->hasInitializer()) { |
| 4983 | + auto *CA = cast<ConstantArray>(GV->getInitializer()); |
| 4984 | + for (auto &Op : CA->operands()) { |
| 4985 | + Constant *C = cast_or_null<Constant>(Op); |
| 4986 | + if (InitAsSet.insert(C).second) |
| 4987 | + Init.push_back(C); |
| 4988 | + } |
| 4989 | + } |
| 4990 | + GV->eraseFromParent(); |
| 4991 | + } |
| 4992 | + |
| 4993 | + Type *Int8PtrTy = llvm::Type::getInt8PtrTy(M.getContext()); |
| 4994 | + for (auto *V : Values) { |
| 4995 | + Constant *C = ConstantExpr::getPointerBitCastOrAddrSpaceCast(V, Int8PtrTy); |
| 4996 | + if (InitAsSet.insert(C).second) |
| 4997 | + Init.push_back(C); |
| 4998 | + } |
| 4999 | + |
| 5000 | + if (Init.empty()) |
| 5001 | + return; |
| 5002 | + |
| 5003 | + ArrayType *ATy = ArrayType::get(Int8PtrTy, Init.size()); |
| 5004 | + GV = new llvm::GlobalVariable(M, ATy, false, GlobalValue::AppendingLinkage, |
| 5005 | + ConstantArray::get(ATy, Init), |
| 5006 | + "llvm.compiler.used"); |
| 5007 | + GV->setSection("llvm.metadata"); |
| 5008 | +} |
| 5009 | + |
4978 | 5010 | void llvm::EmbedBufferInModule(llvm::Module &M, llvm::MemoryBufferRef Buf,
|
4979 | 5011 | StringRef SectionName) {
|
4980 | 5012 | ArrayRef<char> ModuleData =
|
|
0 commit comments