/// DisambiguateGlobalSymbols - Mangle symbols to guarantee uniqueness by /// modifying predominantly internal symbols rather than external ones. /// static void DisambiguateGlobalSymbols(Module *M) { // Try not to cause collisions by minimizing chances of renaming an // already-external symbol, so take in external globals and functions as-is. // The code should work correctly without disambiguation (assuming the same // mangler is used by the two code generators), but having symbols with the // same name causes warnings to be emitted by the code generator. Mangler Mang(*M); // Agree with the CBE on symbol naming Mang.markCharUnacceptable('.'); for (Module::global_iterator I = M->global_begin(), E = M->global_end(); I != E; ++I) { // Don't mangle asm names. if (!I->hasName() || I->getName()[0] != 1) I->setName(Mang.getMangledName(I)); } for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { // Don't mangle asm names or intrinsics. if ((!I->hasName() || I->getName()[0] != 1) && I->getIntrinsicID() == 0) I->setName(Mang.getMangledName(I)); } }
void IntrinsicLowering::AddPrototypes(Module &M) { LLVMContext &Context = M.getContext(); for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) if (I->isDeclaration() && !I->use_empty()) switch (I->getIntrinsicID()) { default: break; case Intrinsic::setjmp: EnsureFunctionExists(M, "setjmp", I->arg_begin(), I->arg_end(), Type::getInt32Ty(M.getContext())); break; case Intrinsic::longjmp: EnsureFunctionExists(M, "longjmp", I->arg_begin(), I->arg_end(), Type::getVoidTy(M.getContext())); break; case Intrinsic::siglongjmp: EnsureFunctionExists(M, "abort", I->arg_end(), I->arg_end(), Type::getVoidTy(M.getContext())); break; case Intrinsic::memcpy: M.getOrInsertFunction("memcpy", Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context), DL.getIntPtrType(Context), nullptr); break; case Intrinsic::memmove: M.getOrInsertFunction("memmove", Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context), DL.getIntPtrType(Context), nullptr); break; case Intrinsic::memset: M.getOrInsertFunction("memset", Type::getInt8PtrTy(Context), Type::getInt8PtrTy(Context), Type::getInt32Ty(M.getContext()), DL.getIntPtrType(Context), nullptr); break; case Intrinsic::sqrt: EnsureFPIntrinsicsExist(M, I, "sqrtf", "sqrt", "sqrtl"); break; case Intrinsic::sin: EnsureFPIntrinsicsExist(M, I, "sinf", "sin", "sinl"); break; case Intrinsic::cos: EnsureFPIntrinsicsExist(M, I, "cosf", "cos", "cosl"); break; case Intrinsic::pow: EnsureFPIntrinsicsExist(M, I, "powf", "pow", "powl"); break; case Intrinsic::log: EnsureFPIntrinsicsExist(M, I, "logf", "log", "logl"); break; case Intrinsic::log2: EnsureFPIntrinsicsExist(M, I, "log2f", "log2", "log2l"); break; case Intrinsic::log10: EnsureFPIntrinsicsExist(M, I, "log10f", "log10", "log10l"); break; case Intrinsic::exp: EnsureFPIntrinsicsExist(M, I, "expf", "exp", "expl"); break; case Intrinsic::exp2: EnsureFPIntrinsicsExist(M, I, "exp2f", "exp2", "exp2l"); break; } }