MCPcopy Create free account
hub / github.com/beefytech/Beef / DoTLSSetup

Method DoTLSSetup

IDEHelper/Backend/BeMCContext.cpp:7240–7291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7238}
7239
7240void BeMCContext::DoTLSSetup()
7241{
7242 // Perform at the end of the 'entry' block
7243
7244 if (mTLSVRegIdx == -1)
7245 return;
7246
7247 auto mcBlock = mBlocks[0];
7248 mActiveBlock = mcBlock;
7249
7250 for (int instIdx = 0; instIdx < (int)mcBlock->mInstructions.size(); instIdx++)
7251 {
7252 auto inst = mcBlock->mInstructions[instIdx];
7253
7254 // Skip past param setup
7255 if (inst->mKind == BeMCInstKind_Def)
7256 continue;
7257 if ((inst->mKind == BeMCInstKind_Mov) && (inst->mArg1.IsNativeReg()))
7258 continue;
7259
7260 auto int32Type = mModule->mContext->GetPrimitiveType(BeTypeCode_Int32);
7261 auto intType = mModule->mContext->GetPrimitiveType(BeTypeCode_Int64);
7262 auto intPtrType = mModule->mContext->GetPointerTo(intType);
7263
7264 auto mcTlsIndex = AllocVirtualReg(intType);
7265 CreateDefineVReg(mcTlsIndex, instIdx++);
7266
7267 auto sym = mCOFFObject->GetSymbolRef("_tls_index");
7268 if (sym->mType == NULL)
7269 sym->mType = int32Type;
7270 AllocInst(BeMCInstKind_Mov, mcTlsIndex, BeMCOperand::FromSymbol(sym->mIdx), instIdx++);
7271
7272 AllocInst(BeMCInstKind_Def, BeMCOperand::FromVReg(mTLSVRegIdx), instIdx++);
7273 AllocInst(BeMCInstKind_TLSSetup, BeMCOperand::FromVReg(mTLSVRegIdx), BeMCOperand::FromImmediate(0), instIdx++);
7274
7275 auto mcTlsVal = AllocVirtualReg(intPtrType);
7276 CreateDefineVReg(mcTlsVal, instIdx++);
7277 auto tlsValInfo = GetVRegInfo(mcTlsVal);
7278 tlsValInfo->mIsExpr = true;
7279 tlsValInfo->mRelTo = BeMCOperand::FromVReg(mTLSVRegIdx);
7280 tlsValInfo->mRelOffset = mcTlsIndex;
7281 tlsValInfo->mRelOffsetScale = 8;
7282
7283 auto mcLoadVal = mcTlsVal;
7284 mcLoadVal.mKind = BeMCOperandKind_VRegLoad;
7285 AllocInst(BeMCInstKind_Mov, BeMCOperand::FromVReg(mTLSVRegIdx), mcLoadVal, instIdx++);
7286
7287 break;
7288 }
7289
7290 mActiveBlock = NULL;
7291}
7292
7293void BeMCContext::DoChainedBlockMerge()
7294{

Callers

nothing calls this directly

Calls 5

IsNativeRegMethod · 0.80
GetSymbolRefMethod · 0.80
sizeMethod · 0.45
GetPrimitiveTypeMethod · 0.45
GetPointerToMethod · 0.45

Tested by

no test coverage detected