95 changes: 48 additions & 47 deletions clang/lib/CodeGen/CGObjCMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ class CGObjCMac : public CGObjCCommonMac {
/// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
/// for the given selector.
llvm::Value *EmitSelector(CodeGenFunction &CGF, Selector Sel);
Address EmitSelectorAddr(Selector Sel);
ConstantAddress EmitSelectorAddr(Selector Sel);

public:
CGObjCMac(CodeGen::CodeGenModule &cgm);
Expand Down Expand Up @@ -1538,7 +1538,7 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
/// EmitSelector - Return a Value*, of type ObjCTypes.SelectorPtrTy,
/// for the given selector.
llvm::Value *EmitSelector(CodeGenFunction &CGF, Selector Sel);
Address EmitSelectorAddr(Selector Sel);
ConstantAddress EmitSelectorAddr(Selector Sel);

/// GetInterfaceEHType - Get the cached ehtype for the given Objective-C
/// interface. The return value has type EHTypePtrTy.
Expand Down Expand Up @@ -2064,9 +2064,8 @@ CGObjCMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
const ObjCMethodDecl *Method) {
// Create and init a super structure; this is a (receiver, class)
// pair we will pass to objc_msgSendSuper.
Address ObjCSuper =
CGF.CreateTempAlloca(ObjCTypes.SuperTy, CGF.getPointerAlign(),
"objc_super");
RawAddress ObjCSuper = CGF.CreateTempAlloca(
ObjCTypes.SuperTy, CGF.getPointerAlign(), "objc_super");
llvm::Value *ReceiverAsObject =
CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy);
CGF.Builder.CreateStore(ReceiverAsObject,
Expand Down Expand Up @@ -4259,7 +4258,7 @@ namespace {

CGF.EmitBlock(FinallyCallExit);
CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionTryExitFn(),
ExceptionData.getPointer());
ExceptionData.emitRawPointer(CGF));

CGF.EmitBlock(FinallyNoCallExit);

Expand Down Expand Up @@ -4425,7 +4424,9 @@ void FragileHazards::emitHazardsInNewBlocks() {
}

static void addIfPresent(llvm::DenseSet<llvm::Value*> &S, Address V) {
if (V.isValid()) S.insert(V.getPointer());
if (V.isValid())
if (llvm::Value *Ptr = V.getBasePointer())
S.insert(Ptr);
}

void FragileHazards::collectLocals() {
Expand Down Expand Up @@ -4628,13 +4629,13 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
// - Call objc_exception_try_enter to push ExceptionData on top of
// the EH stack.
CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionTryEnterFn(),
ExceptionData.getPointer());
ExceptionData.emitRawPointer(CGF));

// - Call setjmp on the exception data buffer.
llvm::Constant *Zero = llvm::ConstantInt::get(CGF.Builder.getInt32Ty(), 0);
llvm::Value *GEPIndexes[] = { Zero, Zero, Zero };
llvm::Value *SetJmpBuffer = CGF.Builder.CreateGEP(
ObjCTypes.ExceptionDataTy, ExceptionData.getPointer(), GEPIndexes,
ObjCTypes.ExceptionDataTy, ExceptionData.emitRawPointer(CGF), GEPIndexes,
"setjmp_buffer");
llvm::CallInst *SetJmpResult = CGF.EmitNounwindRuntimeCall(
ObjCTypes.getSetJmpFn(), SetJmpBuffer, "setjmp_result");
Expand Down Expand Up @@ -4673,9 +4674,9 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
} else {
// Retrieve the exception object. We may emit multiple blocks but
// nothing can cross this so the value is already in SSA form.
llvm::CallInst *Caught =
CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionExtractFn(),
ExceptionData.getPointer(), "caught");
llvm::CallInst *Caught = CGF.EmitNounwindRuntimeCall(
ObjCTypes.getExceptionExtractFn(), ExceptionData.emitRawPointer(CGF),
"caught");

// Push the exception to rethrow onto the EH value stack for the
// benefit of any @throws in the handlers.
Expand All @@ -4698,7 +4699,7 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
// Enter a new exception try block (in case a @catch block
// throws an exception).
CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionTryEnterFn(),
ExceptionData.getPointer());
ExceptionData.emitRawPointer(CGF));

llvm::CallInst *SetJmpResult =
CGF.EmitNounwindRuntimeCall(ObjCTypes.getSetJmpFn(),
Expand Down Expand Up @@ -4829,9 +4830,9 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
// Extract the new exception and save it to the
// propagating-exception slot.
assert(PropagatingExnVar.isValid());
llvm::CallInst *NewCaught =
CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionExtractFn(),
ExceptionData.getPointer(), "caught");
llvm::CallInst *NewCaught = CGF.EmitNounwindRuntimeCall(
ObjCTypes.getExceptionExtractFn(), ExceptionData.emitRawPointer(CGF),
"caught");
CGF.Builder.CreateStore(NewCaught, PropagatingExnVar);

// Don't pop the catch handler; the throw already did.
Expand Down Expand Up @@ -4861,9 +4862,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,

// Otherwise, just look in the buffer for the exception to throw.
} else {
llvm::CallInst *Caught =
CGF.EmitNounwindRuntimeCall(ObjCTypes.getExceptionExtractFn(),
ExceptionData.getPointer());
llvm::CallInst *Caught = CGF.EmitNounwindRuntimeCall(
ObjCTypes.getExceptionExtractFn(), ExceptionData.emitRawPointer(CGF));
PropagatingExn = Caught;
}

Expand Down Expand Up @@ -4906,7 +4906,7 @@ llvm::Value * CGObjCMac::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
Address AddrWeakObj) {
llvm::Type* DestTy = AddrWeakObj.getElementType();
llvm::Value *AddrWeakObjVal = CGF.Builder.CreateBitCast(
AddrWeakObj.getPointer(), ObjCTypes.PtrObjectPtrTy);
AddrWeakObj.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy);
llvm::Value *read_weak =
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcReadWeakFn(),
AddrWeakObjVal, "weakread");
Expand All @@ -4928,8 +4928,8 @@ void CGObjCMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = { src, dstVal };
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignWeakFn(),
args, "weakassign");
Expand All @@ -4950,8 +4950,8 @@ void CGObjCMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal};
if (!threadlocal)
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignGlobalFn(),
Expand All @@ -4977,8 +4977,8 @@ void CGObjCMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal, ivarOffset};
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignIvarFn(), args);
}
Expand All @@ -4997,8 +4997,8 @@ void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal};
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignStrongCastFn(),
args, "strongassign");
Expand All @@ -5007,7 +5007,8 @@ void CGObjCMac::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
void CGObjCMac::EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
Address DestPtr, Address SrcPtr,
llvm::Value *size) {
llvm::Value *args[] = { DestPtr.getPointer(), SrcPtr.getPointer(), size };
llvm::Value *args[] = {DestPtr.emitRawPointer(CGF),
SrcPtr.emitRawPointer(CGF), size};
CGF.EmitNounwindRuntimeCall(ObjCTypes.GcMemmoveCollectableFn(), args);
}

Expand Down Expand Up @@ -5243,7 +5244,7 @@ llvm::Value *CGObjCMac::EmitSelector(CodeGenFunction &CGF, Selector Sel) {
return CGF.Builder.CreateLoad(EmitSelectorAddr(Sel));
}

Address CGObjCMac::EmitSelectorAddr(Selector Sel) {
ConstantAddress CGObjCMac::EmitSelectorAddr(Selector Sel) {
CharUnits Align = CGM.getPointerAlign();

llvm::GlobalVariable *&Entry = SelectorReferences[Sel];
Expand All @@ -5254,7 +5255,7 @@ Address CGObjCMac::EmitSelectorAddr(Selector Sel) {
Entry->setExternallyInitialized(true);
}

return Address(Entry, ObjCTypes.SelectorPtrTy, Align);
return ConstantAddress(Entry, ObjCTypes.SelectorPtrTy, Align);
}

llvm::Constant *CGObjCCommonMac::GetClassName(StringRef RuntimeName) {
Expand Down Expand Up @@ -7323,7 +7324,7 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF,
ObjCTypes.MessageRefTy, CGF.getPointerAlign());

// Update the message ref argument.
args[1].setRValue(RValue::get(mref.getPointer()));
args[1].setRValue(RValue::get(mref, CGF));

// Load the function to call from the message ref table.
Address calleeAddr = CGF.Builder.CreateStructGEP(mref, 0);
Expand Down Expand Up @@ -7552,9 +7553,8 @@ CGObjCNonFragileABIMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
// ...
// Create and init a super structure; this is a (receiver, class)
// pair we will pass to objc_msgSendSuper.
Address ObjCSuper =
CGF.CreateTempAlloca(ObjCTypes.SuperTy, CGF.getPointerAlign(),
"objc_super");
RawAddress ObjCSuper = CGF.CreateTempAlloca(
ObjCTypes.SuperTy, CGF.getPointerAlign(), "objc_super");

llvm::Value *ReceiverAsObject =
CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy);
Expand Down Expand Up @@ -7594,7 +7594,7 @@ llvm::Value *CGObjCNonFragileABIMac::EmitSelector(CodeGenFunction &CGF,
return LI;
}

Address CGObjCNonFragileABIMac::EmitSelectorAddr(Selector Sel) {
ConstantAddress CGObjCNonFragileABIMac::EmitSelectorAddr(Selector Sel) {
llvm::GlobalVariable *&Entry = SelectorReferences[Sel];
CharUnits Align = CGM.getPointerAlign();
if (!Entry) {
Expand All @@ -7610,7 +7610,7 @@ Address CGObjCNonFragileABIMac::EmitSelectorAddr(Selector Sel) {
CGM.addCompilerUsedGlobal(Entry);
}

return Address(Entry, ObjCTypes.SelectorPtrTy, Align);
return ConstantAddress(Entry, ObjCTypes.SelectorPtrTy, Align);
}

/// EmitObjCIvarAssign - Code gen for assigning to a __strong object.
Expand All @@ -7629,8 +7629,8 @@ void CGObjCNonFragileABIMac::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal, ivarOffset};
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignIvarFn(), args);
}
Expand All @@ -7650,8 +7650,8 @@ void CGObjCNonFragileABIMac::EmitObjCStrongCastAssign(
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal};
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignStrongCastFn(),
args, "weakassign");
Expand All @@ -7660,7 +7660,8 @@ void CGObjCNonFragileABIMac::EmitObjCStrongCastAssign(
void CGObjCNonFragileABIMac::EmitGCMemmoveCollectable(
CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr,
llvm::Value *Size) {
llvm::Value *args[] = { DestPtr.getPointer(), SrcPtr.getPointer(), Size };
llvm::Value *args[] = {DestPtr.emitRawPointer(CGF),
SrcPtr.emitRawPointer(CGF), Size};
CGF.EmitNounwindRuntimeCall(ObjCTypes.GcMemmoveCollectableFn(), args);
}

Expand All @@ -7672,7 +7673,7 @@ llvm::Value * CGObjCNonFragileABIMac::EmitObjCWeakRead(
Address AddrWeakObj) {
llvm::Type *DestTy = AddrWeakObj.getElementType();
llvm::Value *AddrWeakObjVal = CGF.Builder.CreateBitCast(
AddrWeakObj.getPointer(), ObjCTypes.PtrObjectPtrTy);
AddrWeakObj.emitRawPointer(CGF), ObjCTypes.PtrObjectPtrTy);
llvm::Value *read_weak =
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcReadWeakFn(),
AddrWeakObjVal, "weakread");
Expand All @@ -7694,8 +7695,8 @@ void CGObjCNonFragileABIMac::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal};
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignWeakFn(),
args, "weakassign");
Expand All @@ -7716,8 +7717,8 @@ void CGObjCNonFragileABIMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
src = CGF.Builder.CreateIntToPtr(src, ObjCTypes.Int8PtrTy);
}
src = CGF.Builder.CreateBitCast(src, ObjCTypes.ObjectPtrTy);
llvm::Value *dstVal =
CGF.Builder.CreateBitCast(dst.getPointer(), ObjCTypes.PtrObjectPtrTy);
llvm::Value *dstVal = CGF.Builder.CreateBitCast(dst.emitRawPointer(CGF),
ObjCTypes.PtrObjectPtrTy);
llvm::Value *args[] = {src, dstVal};
if (!threadlocal)
CGF.EmitNounwindRuntimeCall(ObjCTypes.getGcAssignGlobalFn(),
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CGObjCRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, V, Offset, "add.ptr");

if (!Ivar->isBitField()) {
LValue LV = CGF.MakeNaturalAlignAddrLValue(V, IvarTy);
LValue LV = CGF.MakeNaturalAlignRawAddrLValue(V, IvarTy);
return LV;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
llvm::Instruction *CPICandidate = Handler.Block->getFirstNonPHI();
if (auto *CPI = dyn_cast_or_null<llvm::CatchPadInst>(CPICandidate)) {
CGF.CurrentFuncletPad = CPI;
CPI->setOperand(2, CGF.getExceptionSlot().getPointer());
CPI->setOperand(2, CGF.getExceptionSlot().emitRawPointer(CGF));
CGF.EHStack.pushCleanup<CatchRetScope>(NormalCleanup, CPI);
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ bool CGObjCRuntime::canMessageReceiverBeNull(CodeGenFunction &CGF,
auto self = curMethod->getSelfDecl();
if (self->getType().isConstQualified()) {
if (auto LI = dyn_cast<llvm::LoadInst>(receiver->stripPointerCasts())) {
llvm::Value *selfAddr = CGF.GetAddrOfLocalVar(self).getPointer();
llvm::Value *selfAddr = CGF.GetAddrOfLocalVar(self).emitRawPointer(CGF);
if (selfAddr == LI->getPointerOperand()) {
return false;
}
Expand Down
194 changes: 102 additions & 92 deletions clang/lib/CodeGen/CGOpenMPRuntime.cpp

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions clang/lib/CodeGen/CGOpenMPRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,12 @@ class CGOpenMPRuntime {
/// \param Loc Location of the reference to threadprivate var.
/// \return Address of the threadprivate variable for the current thread.
virtual Address getAddrOfThreadPrivate(CodeGenFunction &CGF,
const VarDecl *VD,
Address VDAddr,
const VarDecl *VD, Address VDAddr,
SourceLocation Loc);

/// Returns the address of the variable marked as declare target with link
/// clause OR as declare target with to clause and unified memory.
virtual Address getAddrOfDeclareTargetVar(const VarDecl *VD);
virtual ConstantAddress getAddrOfDeclareTargetVar(const VarDecl *VD);

/// Emit a code for initialization of threadprivate variable. It emits
/// a call to runtime library which adds initial value to the newly created
Expand Down
76 changes: 39 additions & 37 deletions clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,8 @@ void CGOpenMPRuntimeGPU::emitGenericVarsProlog(CodeGenFunction &CGF,
llvm::PointerType *VarPtrTy = CGF.ConvertTypeForMem(VarTy)->getPointerTo();
llvm::Value *CastedVoidPtr = Bld.CreatePointerBitCastOrAddrSpaceCast(
VoidPtr, VarPtrTy, VD->getName() + "_on_stack");
LValue VarAddr = CGF.MakeNaturalAlignAddrLValue(CastedVoidPtr, VarTy);
LValue VarAddr =
CGF.MakeNaturalAlignPointeeRawAddrLValue(CastedVoidPtr, VarTy);
Rec.second.PrivateAddr = VarAddr.getAddress(CGF);
Rec.second.GlobalizedVal = VoidPtr;

Expand Down Expand Up @@ -1206,16 +1207,16 @@ void CGOpenMPRuntimeGPU::emitTeamsCall(CodeGenFunction &CGF,

bool IsBareKernel = D.getSingleClause<OMPXBareClause>();

Address ZeroAddr = CGF.CreateDefaultAlignTempAlloca(CGF.Int32Ty,
/*Name=*/".zero.addr");
RawAddress ZeroAddr = CGF.CreateDefaultAlignTempAlloca(CGF.Int32Ty,
/*Name=*/".zero.addr");
CGF.Builder.CreateStore(CGF.Builder.getInt32(/*C*/ 0), ZeroAddr);
llvm::SmallVector<llvm::Value *, 16> OutlinedFnArgs;
// We don't emit any thread id function call in bare kernel, but because the
// outlined function has a pointer argument, we emit a nullptr here.
if (IsBareKernel)
OutlinedFnArgs.push_back(llvm::ConstantPointerNull::get(CGM.VoidPtrTy));
else
OutlinedFnArgs.push_back(emitThreadIDAddress(CGF, Loc).getPointer());
OutlinedFnArgs.push_back(emitThreadIDAddress(CGF, Loc).emitRawPointer(CGF));
OutlinedFnArgs.push_back(ZeroAddr.getPointer());
OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end());
emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs);
Expand Down Expand Up @@ -1289,7 +1290,7 @@ void CGOpenMPRuntimeGPU::emitParallelCall(CodeGenFunction &CGF,
llvm::ConstantInt::get(CGF.Int32Ty, -1),
FnPtr,
ID,
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.getPointer(),
Bld.CreateBitOrPointerCast(CapturedVarsAddrs.emitRawPointer(CGF),
CGF.VoidPtrPtrTy),
llvm::ConstantInt::get(CGM.SizeTy, CapturedVars.size())};
CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
Expand Down Expand Up @@ -1503,17 +1504,18 @@ static void shuffleAndStore(CodeGenFunction &CGF, Address SrcAddr,
CGF.EmitBlock(PreCondBB);
llvm::PHINode *PhiSrc =
Bld.CreatePHI(Ptr.getType(), /*NumReservedValues=*/2);
PhiSrc->addIncoming(Ptr.getPointer(), CurrentBB);
PhiSrc->addIncoming(Ptr.emitRawPointer(CGF), CurrentBB);
llvm::PHINode *PhiDest =
Bld.CreatePHI(ElemPtr.getType(), /*NumReservedValues=*/2);
PhiDest->addIncoming(ElemPtr.getPointer(), CurrentBB);
PhiDest->addIncoming(ElemPtr.emitRawPointer(CGF), CurrentBB);
Ptr = Address(PhiSrc, Ptr.getElementType(), Ptr.getAlignment());
ElemPtr =
Address(PhiDest, ElemPtr.getElementType(), ElemPtr.getAlignment());
llvm::Value *PtrEndRaw = PtrEnd.emitRawPointer(CGF);
llvm::Value *PtrRaw = Ptr.emitRawPointer(CGF);
llvm::Value *PtrDiff = Bld.CreatePtrDiff(
CGF.Int8Ty, PtrEnd.getPointer(),
Bld.CreatePointerBitCastOrAddrSpaceCast(Ptr.getPointer(),
CGF.VoidPtrTy));
CGF.Int8Ty, PtrEndRaw,
Bld.CreatePointerBitCastOrAddrSpaceCast(PtrRaw, CGF.VoidPtrTy));
Bld.CreateCondBr(Bld.CreateICmpSGT(PtrDiff, Bld.getInt64(IntSize - 1)),
ThenBB, ExitBB);
CGF.EmitBlock(ThenBB);
Expand All @@ -1528,8 +1530,8 @@ static void shuffleAndStore(CodeGenFunction &CGF, Address SrcAddr,
TBAAAccessInfo());
Address LocalPtr = Bld.CreateConstGEP(Ptr, 1);
Address LocalElemPtr = Bld.CreateConstGEP(ElemPtr, 1);
PhiSrc->addIncoming(LocalPtr.getPointer(), ThenBB);
PhiDest->addIncoming(LocalElemPtr.getPointer(), ThenBB);
PhiSrc->addIncoming(LocalPtr.emitRawPointer(CGF), ThenBB);
PhiDest->addIncoming(LocalElemPtr.emitRawPointer(CGF), ThenBB);
CGF.EmitBranch(PreCondBB);
CGF.EmitBlock(ExitBB);
} else {
Expand Down Expand Up @@ -1676,10 +1678,10 @@ static void emitReductionListCopy(
// scope and that of functions it invokes (i.e., reduce_function).
// RemoteReduceData[i] = (void*)&RemoteElem
if (UpdateDestListPtr) {
CGF.EmitStoreOfScalar(Bld.CreatePointerBitCastOrAddrSpaceCast(
DestElementAddr.getPointer(), CGF.VoidPtrTy),
DestElementPtrAddr, /*Volatile=*/false,
C.VoidPtrTy);
CGF.EmitStoreOfScalar(
Bld.CreatePointerBitCastOrAddrSpaceCast(
DestElementAddr.emitRawPointer(CGF), CGF.VoidPtrTy),
DestElementPtrAddr, /*Volatile=*/false, C.VoidPtrTy);
}

++Idx;
Expand Down Expand Up @@ -1830,7 +1832,7 @@ static llvm::Value *emitInterWarpCopyFunction(CodeGenModule &CGM,
// elemptr = ((CopyType*)(elemptrptr)) + I
Address ElemPtr(ElemPtrPtr, CopyType, Align);
if (NumIters > 1)
ElemPtr = Bld.CreateGEP(ElemPtr, Cnt);
ElemPtr = Bld.CreateGEP(CGF, ElemPtr, Cnt);

// Get pointer to location in transfer medium.
// MediumPtr = &medium[warp_id]
Expand Down Expand Up @@ -1894,7 +1896,7 @@ static llvm::Value *emitInterWarpCopyFunction(CodeGenModule &CGM,
TargetElemPtrPtr, /*Volatile=*/false, C.VoidPtrTy, Loc);
Address TargetElemPtr(TargetElemPtrVal, CopyType, Align);
if (NumIters > 1)
TargetElemPtr = Bld.CreateGEP(TargetElemPtr, Cnt);
TargetElemPtr = Bld.CreateGEP(CGF, TargetElemPtr, Cnt);

// *TargetElemPtr = SrcMediumVal;
llvm::Value *SrcMediumValue =
Expand Down Expand Up @@ -2105,9 +2107,9 @@ static llvm::Function *emitShuffleAndReduceFunction(
CGF.EmitBlock(ThenBB);
// reduce_function(LocalReduceList, RemoteReduceList)
llvm::Value *LocalReduceListPtr = Bld.CreatePointerBitCastOrAddrSpaceCast(
LocalReduceList.getPointer(), CGF.VoidPtrTy);
LocalReduceList.emitRawPointer(CGF), CGF.VoidPtrTy);
llvm::Value *RemoteReduceListPtr = Bld.CreatePointerBitCastOrAddrSpaceCast(
RemoteReduceList.getPointer(), CGF.VoidPtrTy);
RemoteReduceList.emitRawPointer(CGF), CGF.VoidPtrTy);
CGM.getOpenMPRuntime().emitOutlinedFunctionCall(
CGF, Loc, ReduceFn, {LocalReduceListPtr, RemoteReduceListPtr});
Bld.CreateBr(MergeBB);
Expand Down Expand Up @@ -2218,9 +2220,9 @@ static llvm::Value *emitListToGlobalCopyFunction(
llvm::Value *BufferPtr =
Bld.CreateInBoundsGEP(LLVMReductionsBufferTy, BufferArrPtr, Idxs);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferPtr, StaticTy), FD);
CGF.MakeNaturalAlignRawAddrLValue(BufferPtr, StaticTy), FD);
Address GlobAddr = GlobLVal.getAddress(CGF);
GlobLVal.setAddress(Address(GlobAddr.getPointer(),
GlobLVal.setAddress(Address(GlobAddr.emitRawPointer(CGF),
CGF.ConvertTypeForMem(Private->getType()),
GlobAddr.getAlignment()));
switch (CGF.getEvaluationKind(Private->getType())) {
Expand Down Expand Up @@ -2304,7 +2306,7 @@ static llvm::Value *emitListToGlobalReduceFunction(

// 1. Build a list of reduction variables.
// void *RedList[<n>] = {<ReductionVars>[0], ..., <ReductionVars>[<n>-1]};
Address ReductionList =
RawAddress ReductionList =
CGF.CreateMemTemp(ReductionArrayTy, ".omp.reduction.red_list");
auto IPriv = Privates.begin();
llvm::Value *Idxs[] = {CGF.EmitLoadOfScalar(CGF.GetAddrOfLocalVar(&IdxArg),
Expand All @@ -2319,10 +2321,10 @@ static llvm::Value *emitListToGlobalReduceFunction(
llvm::Value *BufferPtr =
Bld.CreateInBoundsGEP(LLVMReductionsBufferTy, BufferArrPtr, Idxs);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferPtr, StaticTy), FD);
CGF.MakeNaturalAlignRawAddrLValue(BufferPtr, StaticTy), FD);
Address GlobAddr = GlobLVal.getAddress(CGF);
CGF.EmitStoreOfScalar(GlobAddr.getPointer(), Elem, /*Volatile=*/false,
C.VoidPtrTy);
CGF.EmitStoreOfScalar(GlobAddr.emitRawPointer(CGF), Elem,
/*Volatile=*/false, C.VoidPtrTy);
if ((*IPriv)->getType()->isVariablyModifiedType()) {
// Store array size.
++Idx;
Expand Down Expand Up @@ -2425,9 +2427,9 @@ static llvm::Value *emitGlobalToListCopyFunction(
llvm::Value *BufferPtr =
Bld.CreateInBoundsGEP(LLVMReductionsBufferTy, BufferArrPtr, Idxs);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferPtr, StaticTy), FD);
CGF.MakeNaturalAlignRawAddrLValue(BufferPtr, StaticTy), FD);
Address GlobAddr = GlobLVal.getAddress(CGF);
GlobLVal.setAddress(Address(GlobAddr.getPointer(),
GlobLVal.setAddress(Address(GlobAddr.emitRawPointer(CGF),
CGF.ConvertTypeForMem(Private->getType()),
GlobAddr.getAlignment()));
switch (CGF.getEvaluationKind(Private->getType())) {
Expand Down Expand Up @@ -2526,10 +2528,10 @@ static llvm::Value *emitGlobalToListReduceFunction(
llvm::Value *BufferPtr =
Bld.CreateInBoundsGEP(LLVMReductionsBufferTy, BufferArrPtr, Idxs);
LValue GlobLVal = CGF.EmitLValueForField(
CGF.MakeNaturalAlignAddrLValue(BufferPtr, StaticTy), FD);
CGF.MakeNaturalAlignRawAddrLValue(BufferPtr, StaticTy), FD);
Address GlobAddr = GlobLVal.getAddress(CGF);
CGF.EmitStoreOfScalar(GlobAddr.getPointer(), Elem, /*Volatile=*/false,
C.VoidPtrTy);
CGF.EmitStoreOfScalar(GlobAddr.emitRawPointer(CGF), Elem,
/*Volatile=*/false, C.VoidPtrTy);
if ((*IPriv)->getType()->isVariablyModifiedType()) {
// Store array size.
++Idx;
Expand All @@ -2545,7 +2547,7 @@ static llvm::Value *emitGlobalToListReduceFunction(
}

// Call reduce_function(ReduceList, GlobalReduceList)
llvm::Value *GlobalReduceList = ReductionList.getPointer();
llvm::Value *GlobalReduceList = ReductionList.emitRawPointer(CGF);
Address AddrReduceListArg = CGF.GetAddrOfLocalVar(&ReduceListArg);
llvm::Value *ReducedPtr = CGF.EmitLoadOfScalar(
AddrReduceListArg, /*Volatile=*/false, C.VoidPtrTy, Loc);
Expand Down Expand Up @@ -2876,7 +2878,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
}

llvm::Value *RL = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
ReductionList.getPointer(), CGF.VoidPtrTy);
ReductionList.emitRawPointer(CGF), CGF.VoidPtrTy);
llvm::Function *ReductionFn = emitReductionFunction(
CGF.CurFn->getName(), Loc, CGF.ConvertTypeForMem(ReductionArrayTy),
Privates, LHSExprs, RHSExprs, ReductionOps);
Expand Down Expand Up @@ -3106,15 +3108,15 @@ llvm::Function *CGOpenMPRuntimeGPU::createParallelDataSharingWrapper(
// Get the array of arguments.
SmallVector<llvm::Value *, 8> Args;

Args.emplace_back(CGF.GetAddrOfLocalVar(&WrapperArg).getPointer());
Args.emplace_back(ZeroAddr.getPointer());
Args.emplace_back(CGF.GetAddrOfLocalVar(&WrapperArg).emitRawPointer(CGF));
Args.emplace_back(ZeroAddr.emitRawPointer(CGF));

CGBuilderTy &Bld = CGF.Builder;
auto CI = CS.capture_begin();

// Use global memory for data sharing.
// Handle passing of global args to workers.
Address GlobalArgs =
RawAddress GlobalArgs =
CGF.CreateDefaultAlignTempAlloca(CGF.VoidPtrPtrTy, "global_args");
llvm::Value *GlobalArgsPtr = GlobalArgs.getPointer();
llvm::Value *DataSharingArgs[] = {GlobalArgsPtr};
Expand Down Expand Up @@ -3400,7 +3402,7 @@ void CGOpenMPRuntimeGPU::adjustTargetSpecificDataForLambdas(
VDAddr = CGF.EmitLoadOfReferenceLValue(VDAddr,
VD->getType().getCanonicalType())
.getAddress(CGF);
CGF.EmitStoreOfScalar(VDAddr.getPointer(), VarLVal);
CGF.EmitStoreOfScalar(VDAddr.emitRawPointer(CGF), VarLVal);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ std::pair<llvm::Value*, llvm::Type *> CodeGenFunction::EmitAsmInputLValue(

Address Addr = InputValue.getAddress(*this);
ConstraintStr += '*';
return {Addr.getPointer(), Addr.getElementType()};
return {InputValue.getPointer(*this), Addr.getElementType()};
}

std::pair<llvm::Value *, llvm::Type *>
Expand Down Expand Up @@ -2701,7 +2701,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {

ArgTypes.push_back(DestAddr.getType());
ArgElemTypes.push_back(DestAddr.getElementType());
Args.push_back(DestAddr.getPointer());
Args.push_back(DestAddr.emitRawPointer(*this));
Constraints += "=*";
Constraints += OutputConstraint;
ReadOnly = ReadNone = false;
Expand Down Expand Up @@ -3076,8 +3076,8 @@ CodeGenFunction::GenerateCapturedStmtFunction(const CapturedStmt &S) {
CapturedStmtInfo->setContextValue(Builder.CreateLoad(DeclPtr));

// Initialize variable-length arrays.
LValue Base = MakeNaturalAlignAddrLValue(CapturedStmtInfo->getContextValue(),
Ctx.getTagDeclType(RD));
LValue Base = MakeNaturalAlignRawAddrLValue(
CapturedStmtInfo->getContextValue(), Ctx.getTagDeclType(RD));
for (auto *FD : RD->fields()) {
if (FD->hasCapturedVLAType()) {
auto *ExprArg =
Expand Down
87 changes: 45 additions & 42 deletions clang/lib/CodeGen/CGStmtOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ void CodeGenFunction::GenerateOpenMPCapturedVars(
LValue DstLV = MakeAddrLValue(DstAddr, Ctx.getUIntPtrType());

llvm::Value *SrcAddrVal = EmitScalarConversion(
DstAddr.getPointer(), Ctx.getPointerType(Ctx.getUIntPtrType()),
DstAddr.emitRawPointer(*this),
Ctx.getPointerType(Ctx.getUIntPtrType()),
Ctx.getPointerType(CurField->getType()), CurCap->getLocation());
LValue SrcLV =
MakeNaturalAlignAddrLValue(SrcAddrVal, CurField->getType());
Expand All @@ -364,7 +365,8 @@ void CodeGenFunction::GenerateOpenMPCapturedVars(
CapturedVars.push_back(CV);
} else {
assert(CurCap->capturesVariable() && "Expected capture by reference.");
CapturedVars.push_back(EmitLValue(*I).getAddress(*this).getPointer());
CapturedVars.push_back(
EmitLValue(*I).getAddress(*this).emitRawPointer(*this));
}
}
}
Expand All @@ -375,8 +377,9 @@ static Address castValueFromUintptr(CodeGenFunction &CGF, SourceLocation Loc,
ASTContext &Ctx = CGF.getContext();

llvm::Value *CastedPtr = CGF.EmitScalarConversion(
AddrLV.getAddress(CGF).getPointer(), Ctx.getUIntPtrType(),
AddrLV.getAddress(CGF).emitRawPointer(CGF), Ctx.getUIntPtrType(),
Ctx.getPointerType(DstType), Loc);
// FIXME: should the pointee type (DstType) be passed?
Address TmpAddr =
CGF.MakeNaturalAlignAddrLValue(CastedPtr, DstType).getAddress(CGF);
return TmpAddr;
Expand Down Expand Up @@ -702,8 +705,8 @@ void CodeGenFunction::EmitOMPAggregateAssign(
llvm::Value *NumElements = emitArrayLength(ArrayTy, ElementTy, DestAddr);
SrcAddr = SrcAddr.withElementType(DestAddr.getElementType());

llvm::Value *SrcBegin = SrcAddr.getPointer();
llvm::Value *DestBegin = DestAddr.getPointer();
llvm::Value *SrcBegin = SrcAddr.emitRawPointer(*this);
llvm::Value *DestBegin = DestAddr.emitRawPointer(*this);
// Cast from pointer to array type to pointer to single element.
llvm::Value *DestEnd = Builder.CreateInBoundsGEP(DestAddr.getElementType(),
DestBegin, NumElements);
Expand Down Expand Up @@ -1007,10 +1010,10 @@ bool CodeGenFunction::EmitOMPCopyinClause(const OMPExecutableDirective &D) {
CopyBegin = createBasicBlock("copyin.not.master");
CopyEnd = createBasicBlock("copyin.not.master.end");
// TODO: Avoid ptrtoint conversion.
auto *MasterAddrInt =
Builder.CreatePtrToInt(MasterAddr.getPointer(), CGM.IntPtrTy);
auto *PrivateAddrInt =
Builder.CreatePtrToInt(PrivateAddr.getPointer(), CGM.IntPtrTy);
auto *MasterAddrInt = Builder.CreatePtrToInt(
MasterAddr.emitRawPointer(*this), CGM.IntPtrTy);
auto *PrivateAddrInt = Builder.CreatePtrToInt(
PrivateAddr.emitRawPointer(*this), CGM.IntPtrTy);
Builder.CreateCondBr(
Builder.CreateICmpNE(MasterAddrInt, PrivateAddrInt), CopyBegin,
CopyEnd);
Expand Down Expand Up @@ -1666,7 +1669,7 @@ Address CodeGenFunction::OMPBuilderCBHelpers::getAddrOfThreadPrivate(

llvm::Type *VarTy = VDAddr.getElementType();
llvm::Value *Data =
CGF.Builder.CreatePointerCast(VDAddr.getPointer(), CGM.Int8PtrTy);
CGF.Builder.CreatePointerCast(VDAddr.emitRawPointer(CGF), CGM.Int8PtrTy);
llvm::ConstantInt *Size = CGM.getSize(CGM.GetTargetTypeStoreSize(VarTy));
std::string Suffix = getNameWithSeparators({"cache", ""});
llvm::Twine CacheName = Twine(CGM.getMangledName(VD)).concat(Suffix);
Expand Down Expand Up @@ -2045,7 +2048,7 @@ void CodeGenFunction::EmitOMPCanonicalLoop(const OMPCanonicalLoop *S) {
->getParam(0)
->getType()
.getNonReferenceType();
Address CountAddr = CreateMemTemp(LogicalTy, ".count.addr");
RawAddress CountAddr = CreateMemTemp(LogicalTy, ".count.addr");
emitCapturedStmtCall(*this, DistanceClosure, {CountAddr.getPointer()});
llvm::Value *DistVal = Builder.CreateLoad(CountAddr, ".count");

Expand All @@ -2061,7 +2064,7 @@ void CodeGenFunction::EmitOMPCanonicalLoop(const OMPCanonicalLoop *S) {
LValue LCVal = EmitLValue(LoopVarRef);
Address LoopVarAddress = LCVal.getAddress(*this);
emitCapturedStmtCall(*this, LoopVarClosure,
{LoopVarAddress.getPointer(), IndVar});
{LoopVarAddress.emitRawPointer(*this), IndVar});

RunCleanupsScope BodyScope(*this);
EmitStmt(BodyStmt);
Expand Down Expand Up @@ -4795,15 +4798,15 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
ParamTypes.push_back(PrivatesPtr->getType());
for (const Expr *E : Data.PrivateVars) {
const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
Address PrivatePtr = CGF.CreateMemTemp(
RawAddress PrivatePtr = CGF.CreateMemTemp(
CGF.getContext().getPointerType(E->getType()), ".priv.ptr.addr");
PrivatePtrs.emplace_back(VD, PrivatePtr);
CallArgs.push_back(PrivatePtr.getPointer());
ParamTypes.push_back(PrivatePtr.getType());
}
for (const Expr *E : Data.FirstprivateVars) {
const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
Address PrivatePtr =
RawAddress PrivatePtr =
CGF.CreateMemTemp(CGF.getContext().getPointerType(E->getType()),
".firstpriv.ptr.addr");
PrivatePtrs.emplace_back(VD, PrivatePtr);
Expand All @@ -4813,7 +4816,7 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
}
for (const Expr *E : Data.LastprivateVars) {
const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
Address PrivatePtr =
RawAddress PrivatePtr =
CGF.CreateMemTemp(CGF.getContext().getPointerType(E->getType()),
".lastpriv.ptr.addr");
PrivatePtrs.emplace_back(VD, PrivatePtr);
Expand All @@ -4826,7 +4829,7 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
Ty = CGF.getContext().getPointerType(Ty);
if (isAllocatableDecl(VD))
Ty = CGF.getContext().getPointerType(Ty);
Address PrivatePtr = CGF.CreateMemTemp(
RawAddress PrivatePtr = CGF.CreateMemTemp(
CGF.getContext().getPointerType(Ty), ".local.ptr.addr");
auto Result = UntiedLocalVars.insert(
std::make_pair(VD, std::make_pair(PrivatePtr, Address::invalid())));
Expand Down Expand Up @@ -4859,7 +4862,7 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
if (auto *DI = CGF.getDebugInfo())
if (CGF.CGM.getCodeGenOpts().hasReducedDebugInfo())
(void)DI->EmitDeclareOfAutoVariable(
Pair.first, Pair.second.getPointer(), CGF.Builder,
Pair.first, Pair.second.getBasePointer(), CGF.Builder,
/*UsePointerValue*/ true);
}
// Adjust mapping for internal locals by mapping actual memory instead of
Expand Down Expand Up @@ -4912,14 +4915,14 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
RedCG, Cnt);
Address Replacement = CGF.CGM.getOpenMPRuntime().getTaskReductionItem(
CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt));
Replacement =
Address(CGF.EmitScalarConversion(
Replacement.getPointer(), CGF.getContext().VoidPtrTy,
CGF.getContext().getPointerType(
Data.ReductionCopies[Cnt]->getType()),
Data.ReductionCopies[Cnt]->getExprLoc()),
CGF.ConvertTypeForMem(Data.ReductionCopies[Cnt]->getType()),
Replacement.getAlignment());
Replacement = Address(
CGF.EmitScalarConversion(Replacement.emitRawPointer(CGF),
CGF.getContext().VoidPtrTy,
CGF.getContext().getPointerType(
Data.ReductionCopies[Cnt]->getType()),
Data.ReductionCopies[Cnt]->getExprLoc()),
CGF.ConvertTypeForMem(Data.ReductionCopies[Cnt]->getType()),
Replacement.getAlignment());
Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement);
Scope.addPrivate(RedCG.getBaseDecl(Cnt), Replacement);
}
Expand Down Expand Up @@ -4970,7 +4973,7 @@ void CodeGenFunction::EmitOMPTaskBasedDirective(
CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt));
Replacement = Address(
CGF.EmitScalarConversion(
Replacement.getPointer(), CGF.getContext().VoidPtrTy,
Replacement.emitRawPointer(CGF), CGF.getContext().VoidPtrTy,
CGF.getContext().getPointerType(InRedPrivs[Cnt]->getType()),
InRedPrivs[Cnt]->getExprLoc()),
CGF.ConvertTypeForMem(InRedPrivs[Cnt]->getType()),
Expand Down Expand Up @@ -5089,7 +5092,7 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective(
// If there is no user-defined mapper, the mapper array will be nullptr. In
// this case, we don't need to privatize it.
if (!isa_and_nonnull<llvm::ConstantPointerNull>(
InputInfo.MappersArray.getPointer())) {
InputInfo.MappersArray.emitRawPointer(*this))) {
MVD = createImplicitFirstprivateForType(
getContext(), Data, BaseAndPointerAndMapperType, CD, S.getBeginLoc());
TargetScope.addPrivate(MVD, InputInfo.MappersArray);
Expand All @@ -5115,7 +5118,7 @@ void CodeGenFunction::EmitOMPTargetTaskBasedDirective(
ParamTypes.push_back(PrivatesPtr->getType());
for (const Expr *E : Data.FirstprivateVars) {
const auto *VD = cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl());
Address PrivatePtr =
RawAddress PrivatePtr =
CGF.CreateMemTemp(CGF.getContext().getPointerType(E->getType()),
".firstpriv.ptr.addr");
PrivatePtrs.emplace_back(VD, PrivatePtr);
Expand Down Expand Up @@ -5194,14 +5197,14 @@ void CodeGenFunction::processInReduction(const OMPExecutableDirective &S,
RedCG, Cnt);
Address Replacement = CGF.CGM.getOpenMPRuntime().getTaskReductionItem(
CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt));
Replacement =
Address(CGF.EmitScalarConversion(
Replacement.getPointer(), CGF.getContext().VoidPtrTy,
CGF.getContext().getPointerType(
Data.ReductionCopies[Cnt]->getType()),
Data.ReductionCopies[Cnt]->getExprLoc()),
CGF.ConvertTypeForMem(Data.ReductionCopies[Cnt]->getType()),
Replacement.getAlignment());
Replacement = Address(
CGF.EmitScalarConversion(Replacement.emitRawPointer(CGF),
CGF.getContext().VoidPtrTy,
CGF.getContext().getPointerType(
Data.ReductionCopies[Cnt]->getType()),
Data.ReductionCopies[Cnt]->getExprLoc()),
CGF.ConvertTypeForMem(Data.ReductionCopies[Cnt]->getType()),
Replacement.getAlignment());
Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement);
Scope.addPrivate(RedCG.getBaseDecl(Cnt), Replacement);
}
Expand Down Expand Up @@ -5247,7 +5250,7 @@ void CodeGenFunction::processInReduction(const OMPExecutableDirective &S,
CGF, S.getBeginLoc(), ReductionsPtr, RedCG.getSharedLValue(Cnt));
Replacement = Address(
CGF.EmitScalarConversion(
Replacement.getPointer(), CGF.getContext().VoidPtrTy,
Replacement.emitRawPointer(CGF), CGF.getContext().VoidPtrTy,
CGF.getContext().getPointerType(InRedPrivs[Cnt]->getType()),
InRedPrivs[Cnt]->getExprLoc()),
CGF.ConvertTypeForMem(InRedPrivs[Cnt]->getType()),
Expand Down Expand Up @@ -5394,7 +5397,7 @@ void CodeGenFunction::EmitOMPDepobjDirective(const OMPDepobjDirective &S) {
Dependencies.DepExprs.append(DC->varlist_begin(), DC->varlist_end());
Address DepAddr = CGM.getOpenMPRuntime().emitDepobjDependClause(
*this, Dependencies, DC->getBeginLoc());
EmitStoreOfScalar(DepAddr.getPointer(), DOLVal);
EmitStoreOfScalar(DepAddr.emitRawPointer(*this), DOLVal);
return;
}
if (const auto *DC = S.getSingleClause<OMPDestroyClause>()) {
Expand Down Expand Up @@ -6471,21 +6474,21 @@ static void emitOMPAtomicCompareExpr(
D->getType()->hasSignedIntegerRepresentation());

llvm::OpenMPIRBuilder::AtomicOpValue XOpVal{
XAddr.getPointer(), XAddr.getElementType(),
XAddr.emitRawPointer(CGF), XAddr.getElementType(),
X->getType()->hasSignedIntegerRepresentation(),
X->getType().isVolatileQualified()};
llvm::OpenMPIRBuilder::AtomicOpValue VOpVal, ROpVal;
if (V) {
LValue LV = CGF.EmitLValue(V);
Address Addr = LV.getAddress(CGF);
VOpVal = {Addr.getPointer(), Addr.getElementType(),
VOpVal = {Addr.emitRawPointer(CGF), Addr.getElementType(),
V->getType()->hasSignedIntegerRepresentation(),
V->getType().isVolatileQualified()};
}
if (R) {
LValue LV = CGF.EmitLValue(R);
Address Addr = LV.getAddress(CGF);
ROpVal = {Addr.getPointer(), Addr.getElementType(),
ROpVal = {Addr.emitRawPointer(CGF), Addr.getElementType(),
R->getType()->hasSignedIntegerRepresentation(),
R->getType().isVolatileQualified()};
}
Expand Down Expand Up @@ -7029,7 +7032,7 @@ void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) {
std::tie(NumDependences, DependenciesArray) =
CGM.getOpenMPRuntime().emitDependClause(*this, Data.Dependences,
S.getBeginLoc());
DependenceList = DependenciesArray.getPointer();
DependenceList = DependenciesArray.emitRawPointer(*this);
}
Data.HasNowaitClause = S.hasClausesOfKind<OMPNowaitClause>();

Expand Down
9 changes: 4 additions & 5 deletions clang/lib/CodeGen/CGVTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ CodeGenFunction::GenerateVarArgsThunk(llvm::Function *Fn,

// Find the first store of "this", which will be to the alloca associated
// with "this".
Address ThisPtr =
Address(&*AI, ConvertTypeForMem(MD->getFunctionObjectParameterType()),
CGM.getClassPointerAlignment(MD->getParent()));
Address ThisPtr = makeNaturalAddressForPointer(
&*AI, MD->getFunctionObjectParameterType(),
CGM.getClassPointerAlignment(MD->getParent()));
llvm::BasicBlock *EntryBB = &Fn->front();
llvm::BasicBlock::iterator ThisStore =
llvm::find_if(*EntryBB, [&](llvm::Instruction &I) {
return isa<llvm::StoreInst>(I) &&
I.getOperand(0) == ThisPtr.getPointer();
return isa<llvm::StoreInst>(I) && I.getOperand(0) == &*AI;
});
assert(ThisStore != EntryBB->end() &&
"Store of this should be in entry block?");
Expand Down
250 changes: 125 additions & 125 deletions clang/lib/CodeGen/CGValue.h

Large diffs are not rendered by default.

71 changes: 42 additions & 29 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,35 @@ CodeGenFunction::CGFPOptionsRAII::~CGFPOptionsRAII() {
CGF.Builder.setDefaultConstrainedRounding(OldRounding);
}

LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
static LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T,
bool ForPointeeType,
CodeGenFunction &CGF) {
LValueBaseInfo BaseInfo;
TBAAAccessInfo TBAAInfo;
CharUnits Alignment = CGM.getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo);
Address Addr(V, ConvertTypeForMem(T), Alignment);
return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
CharUnits Alignment =
CGF.CGM.getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo, ForPointeeType);
Address Addr = Address(V, CGF.ConvertTypeForMem(T), Alignment);
return CGF.MakeAddrLValue(Addr, T, BaseInfo, TBAAInfo);
}

LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
return ::MakeNaturalAlignAddrLValue(V, T, /*ForPointeeType*/ false, *this);
}

/// Given a value of type T* that may not be to a complete object,
/// construct an l-value with the natural pointee alignment of T.
LValue
CodeGenFunction::MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T) {
LValueBaseInfo BaseInfo;
TBAAAccessInfo TBAAInfo;
CharUnits Align = CGM.getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo,
/* forPointeeType= */ true);
Address Addr(V, ConvertTypeForMem(T), Align);
return MakeAddrLValue(Addr, T, BaseInfo, TBAAInfo);
return ::MakeNaturalAlignAddrLValue(V, T, /*ForPointeeType*/ true, *this);
}

LValue CodeGenFunction::MakeNaturalAlignRawAddrLValue(llvm::Value *V,
QualType T) {
return ::MakeNaturalAlignAddrLValue(V, T, /*ForPointeeType*/ false, *this);
}

LValue CodeGenFunction::MakeNaturalAlignPointeeRawAddrLValue(llvm::Value *V,
QualType T) {
return ::MakeNaturalAlignAddrLValue(V, T, /*ForPointeeType*/ true, *this);
}

llvm::Type *CodeGenFunction::ConvertTypeForMem(QualType T) {
return CGM.getTypes().ConvertTypeForMem(T);
Expand Down Expand Up @@ -525,7 +534,8 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
ReturnBlock.getBlock()->eraseFromParent();
}
if (ReturnValue.isValid()) {
auto *RetAlloca = dyn_cast<llvm::AllocaInst>(ReturnValue.getPointer());
auto *RetAlloca =
dyn_cast<llvm::AllocaInst>(ReturnValue.emitRawPointer(*this));
if (RetAlloca && RetAlloca->use_empty()) {
RetAlloca->eraseFromParent();
ReturnValue = Address::invalid();
Expand Down Expand Up @@ -1122,13 +1132,14 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
auto AI = CurFn->arg_begin();
if (CurFnInfo->getReturnInfo().isSRetAfterThis())
++AI;
ReturnValue =
Address(&*AI, ConvertType(RetTy),
CurFnInfo->getReturnInfo().getIndirectAlign(), KnownNonNull);
ReturnValue = makeNaturalAddressForPointer(
&*AI, RetTy, CurFnInfo->getReturnInfo().getIndirectAlign(), false,
nullptr, nullptr, KnownNonNull);
if (!CurFnInfo->getReturnInfo().getIndirectByVal()) {
ReturnValuePointer = CreateDefaultAlignTempAlloca(
ReturnValue.getPointer()->getType(), "result.ptr");
Builder.CreateStore(ReturnValue.getPointer(), ReturnValuePointer);
ReturnValuePointer =
CreateDefaultAlignTempAlloca(ReturnValue.getType(), "result.ptr");
Builder.CreateStore(ReturnValue.emitRawPointer(*this),
ReturnValuePointer);
}
} else if (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::InAlloca &&
!hasScalarEvaluationKind(CurFnInfo->getReturnType())) {
Expand Down Expand Up @@ -1189,8 +1200,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
// or contains the address of the enclosing object).
LValue ThisFieldLValue = EmitLValueForLambdaField(LambdaThisCaptureField);
if (!LambdaThisCaptureField->getType()->isPointerType()) {
// If the enclosing object was captured by value, just use its address.
CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer();
// If the enclosing object was captured by value, just use its
// address. Sign this pointer.
CXXThisValue = ThisFieldLValue.getPointer(*this);
} else {
// Load the lvalue pointed to by the field, since '*this' was captured
// by reference.
Expand Down Expand Up @@ -2012,8 +2024,9 @@ static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType,
= llvm::ConstantInt::get(CGF.IntPtrTy, baseSize.getQuantity());

Address begin = dest.withElementType(CGF.Int8Ty);
llvm::Value *end = Builder.CreateInBoundsGEP(
begin.getElementType(), begin.getPointer(), sizeInChars, "vla.end");
llvm::Value *end = Builder.CreateInBoundsGEP(begin.getElementType(),
begin.emitRawPointer(CGF),
sizeInChars, "vla.end");

llvm::BasicBlock *originBB = CGF.Builder.GetInsertBlock();
llvm::BasicBlock *loopBB = CGF.createBasicBlock("vla-init.loop");
Expand All @@ -2024,7 +2037,7 @@ static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType,
CGF.EmitBlock(loopBB);

llvm::PHINode *cur = Builder.CreatePHI(begin.getType(), 2, "vla.cur");
cur->addIncoming(begin.getPointer(), originBB);
cur->addIncoming(begin.emitRawPointer(CGF), originBB);

CharUnits curAlign =
dest.getAlignment().alignmentOfArrayElement(baseSize);
Expand Down Expand Up @@ -2217,10 +2230,10 @@ llvm::Value *CodeGenFunction::emitArrayLength(const ArrayType *origArrayType,
addr = addr.withElementType(baseType);
} else {
// Create the actual GEP.
addr = Address(Builder.CreateInBoundsGEP(
addr.getElementType(), addr.getPointer(), gepIndices, "array.begin"),
ConvertTypeForMem(eltType),
addr.getAlignment());
addr = Address(Builder.CreateInBoundsGEP(addr.getElementType(),
addr.emitRawPointer(*this),
gepIndices, "array.begin"),
ConvertTypeForMem(eltType), addr.getAlignment());
}

baseType = eltType;
Expand Down Expand Up @@ -2561,7 +2574,7 @@ void CodeGenFunction::EmitVarAnnotations(const VarDecl *D, llvm::Value *V) {
Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
Address Addr) {
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
llvm::Value *V = Addr.getPointer();
llvm::Value *V = Addr.emitRawPointer(*this);
llvm::Type *VTy = V->getType();
auto *PTy = dyn_cast<llvm::PointerType>(VTy);
unsigned AS = PTy ? PTy->getAddressSpace() : 0;
Expand Down
257 changes: 186 additions & 71 deletions clang/lib/CodeGen/CodeGenFunction.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7267,7 +7267,7 @@ void CodeGenFunction::EmitDeclMetadata() {

for (auto &I : LocalDeclMap) {
const Decl *D = I.first;
llvm::Value *Addr = I.second.getPointer();
llvm::Value *Addr = I.second.emitRawPointer(*this);
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(Addr)) {
llvm::Value *DAddr = GetPointerConstant(getLLVMContext(), D);
Alloca->setMetadata(
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/CodeGen/CodeGenPGO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,8 @@ void CodeGenPGO::emitMCDCParameters(CGBuilderTy &Builder) {

void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
const Expr *S,
Address MCDCCondBitmapAddr) {
Address MCDCCondBitmapAddr,
CodeGenFunction &CGF) {
if (!canEmitMCDCCoverage(Builder) || !RegionMCDCState)
return;

Expand All @@ -1262,7 +1263,7 @@ void CodeGenPGO::emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder,
Builder.getInt64(FunctionHash),
Builder.getInt32(RegionMCDCState->BitmapBytes),
Builder.getInt32(MCDCTestVectorBitmapOffset),
MCDCCondBitmapAddr.getPointer()};
MCDCCondBitmapAddr.emitRawPointer(CGF)};
Builder.CreateCall(
CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_tvbitmap_update), Args);
}
Expand All @@ -1283,7 +1284,8 @@ void CodeGenPGO::emitMCDCCondBitmapReset(CGBuilderTy &Builder, const Expr *S,

void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
Address MCDCCondBitmapAddr,
llvm::Value *Val) {
llvm::Value *Val,
CodeGenFunction &CGF) {
if (!canEmitMCDCCoverage(Builder) || !RegionMCDCState)
return;

Expand Down Expand Up @@ -1312,7 +1314,7 @@ void CodeGenPGO::emitMCDCCondBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
llvm::Value *Args[5] = {llvm::ConstantExpr::getBitCast(FuncNameVar, I8PtrTy),
Builder.getInt64(FunctionHash),
Builder.getInt32(Branch.ID),
MCDCCondBitmapAddr.getPointer(), Val};
MCDCCondBitmapAddr.emitRawPointer(CGF), Val};
Builder.CreateCall(
CGM.getIntrinsic(llvm::Intrinsic::instrprof_mcdc_condbitmap_update),
Args);
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/CodeGen/CodeGenPGO.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ class CodeGenPGO {
void emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S,
llvm::Value *StepV);
void emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
Address MCDCCondBitmapAddr);
Address MCDCCondBitmapAddr,
CodeGenFunction &CGF);
void emitMCDCParameters(CGBuilderTy &Builder);
void emitMCDCCondBitmapReset(CGBuilderTy &Builder, const Expr *S,
Address MCDCCondBitmapAddr);
void emitMCDCCondBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
Address MCDCCondBitmapAddr, llvm::Value *Val);
Address MCDCCondBitmapAddr, llvm::Value *Val,
CodeGenFunction &CGF);

/// Return the region count for the counter at the given index.
uint64_t getRegionCount(const Stmt *S) {
Expand Down
52 changes: 22 additions & 30 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ class ItaniumCXXABI : public CodeGen::CGCXXABI {
CodeGenFunction &CGF, const CXXRecordDecl *VTableClass,
BaseSubobject Base, const CXXRecordDecl *NearestVBase);

llvm::Constant *
getVTableAddressPointForConstExpr(BaseSubobject Base,
const CXXRecordDecl *VTableClass) override;

llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
CharUnits VPtrOffset) override;

Expand Down Expand Up @@ -646,7 +642,7 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(

// Apply the adjustment and cast back to the original struct type
// for consistency.
llvm::Value *This = ThisAddr.getPointer();
llvm::Value *This = ThisAddr.emitRawPointer(CGF);
This = Builder.CreateInBoundsGEP(Builder.getInt8Ty(), This, Adj);
ThisPtrForCall = This;

Expand Down Expand Up @@ -850,7 +846,7 @@ llvm::Value *ItaniumCXXABI::EmitMemberDataPointerAddress(
CGBuilderTy &Builder = CGF.Builder;

// Apply the offset, which we assume is non-null.
return Builder.CreateInBoundsGEP(CGF.Int8Ty, Base.getPointer(), MemPtr,
return Builder.CreateInBoundsGEP(CGF.Int8Ty, Base.emitRawPointer(CGF), MemPtr,
"memptr.offset");
}

Expand Down Expand Up @@ -1245,7 +1241,7 @@ void ItaniumCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
CGF.getPointerAlign());

// Apply the offset.
llvm::Value *CompletePtr = Ptr.getPointer();
llvm::Value *CompletePtr = Ptr.emitRawPointer(CGF);
CompletePtr =
CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, CompletePtr, Offset);

Expand Down Expand Up @@ -1482,7 +1478,8 @@ llvm::Value *ItaniumCXXABI::emitDynamicCastCall(
computeOffsetHint(CGF.getContext(), SrcDecl, DestDecl).getQuantity());

// Emit the call to __dynamic_cast.
llvm::Value *Args[] = {ThisAddr.getPointer(), SrcRTTI, DestRTTI, OffsetHint};
llvm::Value *Args[] = {ThisAddr.emitRawPointer(CGF), SrcRTTI, DestRTTI,
OffsetHint};
llvm::Value *Value =
CGF.EmitNounwindRuntimeCall(getItaniumDynamicCastFn(CGF), Args);

Expand Down Expand Up @@ -1571,7 +1568,7 @@ llvm::Value *ItaniumCXXABI::emitExactDynamicCast(
VPtr, CGM.getTBAAVTablePtrAccessInfo(CGF.VoidPtrPtrTy));
llvm::Value *Success = CGF.Builder.CreateICmpEQ(
VPtr, getVTableAddressPoint(BaseSubobject(SrcDecl, *Offset), DestDecl));
llvm::Value *Result = ThisAddr.getPointer();
llvm::Value *Result = ThisAddr.emitRawPointer(CGF);
if (!Offset->isZero())
Result = CGF.Builder.CreateInBoundsGEP(
CGF.CharTy, Result,
Expand Down Expand Up @@ -1611,7 +1608,7 @@ llvm::Value *ItaniumCXXABI::emitDynamicCastToVoid(CodeGenFunction &CGF,
PtrDiffLTy, OffsetToTop, CGF.getPointerAlign(), "offset.to.top");
}
// Finally, add the offset to the pointer.
return CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ThisAddr.getPointer(),
return CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ThisAddr.emitRawPointer(CGF),
OffsetToTop);
}

Expand Down Expand Up @@ -1792,8 +1789,8 @@ void ItaniumCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
else
Callee = CGCallee::forDirect(CGM.getAddrOfCXXStructor(GD), GD);

CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy, VTT, VTTTy,
nullptr);
CGF.EmitCXXDestructorCall(GD, Callee, CGF.getAsNaturalPointerTo(This, ThisTy),
ThisTy, VTT, VTTTy, nullptr);
}

void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT,
Expand Down Expand Up @@ -1952,11 +1949,6 @@ llvm::Value *ItaniumCXXABI::getVTableAddressPointInStructorWithVTT(
CGF.getPointerAlign());
}

llvm::Constant *ItaniumCXXABI::getVTableAddressPointForConstExpr(
BaseSubobject Base, const CXXRecordDecl *VTableClass) {
return getVTableAddressPoint(Base, VTableClass);
}

llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
CharUnits VPtrOffset) {
assert(VPtrOffset.isZero() && "Itanium ABI only supports zero vptr offsets");
Expand Down Expand Up @@ -2088,8 +2080,8 @@ llvm::Value *ItaniumCXXABI::EmitVirtualDestructorCall(
ThisTy = D->getDestroyedType();
}

CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy, nullptr,
QualType(), nullptr);
CGF.EmitCXXDestructorCall(GD, Callee, This.emitRawPointer(CGF), ThisTy,
nullptr, QualType(), nullptr);
return nullptr;
}

Expand Down Expand Up @@ -2162,7 +2154,7 @@ static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
int64_t VirtualAdjustment,
bool IsReturnAdjustment) {
if (!NonVirtualAdjustment && !VirtualAdjustment)
return InitialPtr.getPointer();
return InitialPtr.emitRawPointer(CGF);

Address V = InitialPtr.withElementType(CGF.Int8Ty);

Expand Down Expand Up @@ -2195,10 +2187,10 @@ static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
CGF.getPointerAlign());
}
// Adjust our pointer.
ResultPtr = CGF.Builder.CreateInBoundsGEP(
V.getElementType(), V.getPointer(), Offset);
ResultPtr = CGF.Builder.CreateInBoundsGEP(V.getElementType(),
V.emitRawPointer(CGF), Offset);
} else {
ResultPtr = V.getPointer();
ResultPtr = V.emitRawPointer(CGF);
}

// In a derived-to-base conversion, the non-virtual adjustment is
Expand Down Expand Up @@ -2284,7 +2276,7 @@ Address ItaniumCXXABI::InitializeArrayCookie(CodeGenFunction &CGF,
llvm::FunctionType::get(CGM.VoidTy, NumElementsPtr.getType(), false);
llvm::FunctionCallee F =
CGM.CreateRuntimeFunction(FTy, "__asan_poison_cxx_array_cookie");
CGF.Builder.CreateCall(F, NumElementsPtr.getPointer());
CGF.Builder.CreateCall(F, NumElementsPtr.emitRawPointer(CGF));
}

// Finally, compute a pointer to the actual data buffer by skipping
Expand Down Expand Up @@ -2315,7 +2307,7 @@ llvm::Value *ItaniumCXXABI::readArrayCookieImpl(CodeGenFunction &CGF,
llvm::FunctionType::get(CGF.SizeTy, CGF.UnqualPtrTy, false);
llvm::FunctionCallee F =
CGM.CreateRuntimeFunction(FTy, "__asan_load_cxx_array_cookie");
return CGF.Builder.CreateCall(F, numElementsPtr.getPointer());
return CGF.Builder.CreateCall(F, numElementsPtr.emitRawPointer(CGF));
}

CharUnits ARMCXXABI::getArrayCookieSizeImpl(QualType elementType) {
Expand Down Expand Up @@ -2627,7 +2619,7 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF,

// Call __cxa_guard_release. This cannot throw.
CGF.EmitNounwindRuntimeCall(getGuardReleaseFn(CGM, guardPtrTy),
guardAddr.getPointer());
guardAddr.emitRawPointer(CGF));
} else if (D.isLocalVarDecl()) {
// For local variables, store 1 into the first byte of the guard variable
// after the object initialization completes so that initialization is
Expand Down Expand Up @@ -3120,10 +3112,10 @@ LValue ItaniumCXXABI::EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,

LValue LV;
if (VD->getType()->isReferenceType())
LV = CGF.MakeNaturalAlignAddrLValue(CallVal, LValType);
LV = CGF.MakeNaturalAlignRawAddrLValue(CallVal, LValType);
else
LV = CGF.MakeAddrLValue(CallVal, LValType,
CGF.getContext().getDeclAlign(VD));
LV = CGF.MakeRawAddrLValue(CallVal, LValType,
CGF.getContext().getDeclAlign(VD));
// FIXME: need setObjCGCLValueClass?
return LV;
}
Expand Down Expand Up @@ -4604,7 +4596,7 @@ static void InitCatchParam(CodeGenFunction &CGF,
CGF.Builder.CreateStore(Casted, ExnPtrTmp);

// Bind the reference to the temporary.
AdjustedExn = ExnPtrTmp.getPointer();
AdjustedExn = ExnPtrTmp.emitRawPointer(CGF);
}
}

Expand Down
58 changes: 23 additions & 35 deletions clang/lib/CodeGen/MicrosoftCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ class MicrosoftCXXABI : public CGCXXABI {
CodeGenFunction &CGF, const CXXRecordDecl *VTableClass,
BaseSubobject Base, const CXXRecordDecl *NearestVBase) override;

llvm::Constant *
getVTableAddressPointForConstExpr(BaseSubobject Base,
const CXXRecordDecl *VTableClass) override;

llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
CharUnits VPtrOffset) override;

Expand Down Expand Up @@ -937,7 +933,7 @@ void MicrosoftCXXABI::emitBeginCatch(CodeGenFunction &CGF,
}

CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam);
CPI->setArgOperand(2, var.getObjectAddress(CGF).getPointer());
CPI->setArgOperand(2, var.getObjectAddress(CGF).emitRawPointer(CGF));
CGF.EHStack.pushCleanup<CatchRetScope>(NormalCleanup, CPI);
CGF.EmitAutoVarCleanups(var);
}
Expand Down Expand Up @@ -974,7 +970,7 @@ MicrosoftCXXABI::performBaseAdjustment(CodeGenFunction &CGF, Address Value,
llvm::Value *Offset =
GetVirtualBaseClassOffset(CGF, Value, SrcDecl, PolymorphicBase);
llvm::Value *Ptr = CGF.Builder.CreateInBoundsGEP(
Value.getElementType(), Value.getPointer(), Offset);
Value.getElementType(), Value.emitRawPointer(CGF), Offset);
CharUnits VBaseAlign =
CGF.CGM.getVBaseAlignment(Value.getAlignment(), SrcDecl, PolymorphicBase);
return std::make_tuple(Address(Ptr, CGF.Int8Ty, VBaseAlign), Offset,
Expand Down Expand Up @@ -1011,7 +1007,7 @@ llvm::Value *MicrosoftCXXABI::EmitTypeid(CodeGenFunction &CGF,
llvm::Type *StdTypeInfoPtrTy) {
std::tie(ThisPtr, std::ignore, std::ignore) =
performBaseAdjustment(CGF, ThisPtr, SrcRecordTy);
llvm::CallBase *Typeid = emitRTtypeidCall(CGF, ThisPtr.getPointer());
llvm::CallBase *Typeid = emitRTtypeidCall(CGF, ThisPtr.emitRawPointer(CGF));
return CGF.Builder.CreateBitCast(Typeid, StdTypeInfoPtrTy);
}

Expand All @@ -1033,7 +1029,7 @@ llvm::Value *MicrosoftCXXABI::emitDynamicCastCall(
llvm::Value *Offset;
std::tie(This, Offset, std::ignore) =
performBaseAdjustment(CGF, This, SrcRecordTy);
llvm::Value *ThisPtr = This.getPointer();
llvm::Value *ThisPtr = This.emitRawPointer(CGF);
Offset = CGF.Builder.CreateTrunc(Offset, CGF.Int32Ty);

// PVOID __RTDynamicCast(
Expand Down Expand Up @@ -1065,7 +1061,7 @@ llvm::Value *MicrosoftCXXABI::emitDynamicCastToVoid(CodeGenFunction &CGF,
llvm::FunctionCallee Function = CGF.CGM.CreateRuntimeFunction(
llvm::FunctionType::get(CGF.Int8PtrTy, ArgTypes, false),
"__RTCastToVoid");
llvm::Value *Args[] = {Value.getPointer()};
llvm::Value *Args[] = {Value.emitRawPointer(CGF)};
return CGF.EmitRuntimeCall(Function, Args);
}

Expand Down Expand Up @@ -1493,7 +1489,7 @@ Address MicrosoftCXXABI::adjustThisArgumentForVirtualFunctionCall(
llvm::Value *VBaseOffset =
GetVirtualBaseClassOffset(CGF, Result, Derived, VBase);
llvm::Value *VBasePtr = CGF.Builder.CreateInBoundsGEP(
Result.getElementType(), Result.getPointer(), VBaseOffset);
Result.getElementType(), Result.emitRawPointer(CGF), VBaseOffset);
CharUnits VBaseAlign =
CGF.CGM.getVBaseAlignment(Result.getAlignment(), Derived, VBase);
Result = Address(VBasePtr, CGF.Int8Ty, VBaseAlign);
Expand Down Expand Up @@ -1660,7 +1656,8 @@ void MicrosoftCXXABI::EmitDestructorCall(CodeGenFunction &CGF,
llvm::Value *Implicit =
getCXXDestructorImplicitParam(CGF, DD, Type, ForVirtualBase,
Delegating); // = nullptr
CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy,
CGF.EmitCXXDestructorCall(GD, Callee, CGF.getAsNaturalPointerTo(This, ThisTy),
ThisTy,
/*ImplicitParam=*/Implicit,
/*ImplicitParamTy=*/QualType(), nullptr);
if (BaseDtorEndBB) {
Expand Down Expand Up @@ -1791,13 +1788,6 @@ MicrosoftCXXABI::getVTableAddressPoint(BaseSubobject Base,
return VFTablesMap[ID];
}

llvm::Constant *MicrosoftCXXABI::getVTableAddressPointForConstExpr(
BaseSubobject Base, const CXXRecordDecl *VTableClass) {
llvm::Constant *VFTable = getVTableAddressPoint(Base, VTableClass);
assert(VFTable && "Couldn't find a vftable for the given base?");
return VFTable;
}

llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
CharUnits VPtrOffset) {
// getAddrOfVTable may return 0 if asked to get an address of a vtable which
Expand Down Expand Up @@ -2013,8 +2003,9 @@ llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall(
}

This = adjustThisArgumentForVirtualFunctionCall(CGF, GD, This, true);
RValue RV = CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy,
ImplicitParam, Context.IntTy, CE);
RValue RV =
CGF.EmitCXXDestructorCall(GD, Callee, This.emitRawPointer(CGF), ThisTy,
ImplicitParam, Context.IntTy, CE);
return RV.getScalarVal();
}

Expand Down Expand Up @@ -2212,13 +2203,13 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
Address This,
const ThisAdjustment &TA) {
if (TA.isEmpty())
return This.getPointer();
return This.emitRawPointer(CGF);

This = This.withElementType(CGF.Int8Ty);

llvm::Value *V;
if (TA.Virtual.isEmpty()) {
V = This.getPointer();
V = This.emitRawPointer(CGF);
} else {
assert(TA.Virtual.Microsoft.VtordispOffset < 0);
// Adjust the this argument based on the vtordisp value.
Expand All @@ -2227,7 +2218,7 @@ llvm::Value *MicrosoftCXXABI::performThisAdjustment(CodeGenFunction &CGF,
CharUnits::fromQuantity(TA.Virtual.Microsoft.VtordispOffset));
VtorDispPtr = VtorDispPtr.withElementType(CGF.Int32Ty);
llvm::Value *VtorDisp = CGF.Builder.CreateLoad(VtorDispPtr, "vtordisp");
V = CGF.Builder.CreateGEP(This.getElementType(), This.getPointer(),
V = CGF.Builder.CreateGEP(This.getElementType(), This.emitRawPointer(CGF),
CGF.Builder.CreateNeg(VtorDisp));

// Unfortunately, having applied the vtordisp means that we no
Expand Down Expand Up @@ -2264,11 +2255,11 @@ llvm::Value *
MicrosoftCXXABI::performReturnAdjustment(CodeGenFunction &CGF, Address Ret,
const ReturnAdjustment &RA) {
if (RA.isEmpty())
return Ret.getPointer();
return Ret.emitRawPointer(CGF);

Ret = Ret.withElementType(CGF.Int8Ty);

llvm::Value *V = Ret.getPointer();
llvm::Value *V = Ret.emitRawPointer(CGF);
if (RA.Virtual.Microsoft.VBIndex) {
assert(RA.Virtual.Microsoft.VBIndex > 0);
int32_t IntSize = CGF.getIntSize().getQuantity();
Expand Down Expand Up @@ -2583,7 +2574,7 @@ struct ResetGuardBit final : EHScopeStack::Cleanup {

struct CallInitThreadAbort final : EHScopeStack::Cleanup {
llvm::Value *Guard;
CallInitThreadAbort(Address Guard) : Guard(Guard.getPointer()) {}
CallInitThreadAbort(RawAddress Guard) : Guard(Guard.getPointer()) {}

void Emit(CodeGenFunction &CGF, Flags flags) override {
// Calling _Init_thread_abort will reset the guard's state.
Expand Down Expand Up @@ -3123,8 +3114,8 @@ MicrosoftCXXABI::GetVBaseOffsetFromVBPtr(CodeGenFunction &CGF,
llvm::Value **VBPtrOut) {
CGBuilderTy &Builder = CGF.Builder;
// Load the vbtable pointer from the vbptr in the instance.
llvm::Value *VBPtr = Builder.CreateInBoundsGEP(CGM.Int8Ty, This.getPointer(),
VBPtrOffset, "vbptr");
llvm::Value *VBPtr = Builder.CreateInBoundsGEP(
CGM.Int8Ty, This.emitRawPointer(CGF), VBPtrOffset, "vbptr");
if (VBPtrOut)
*VBPtrOut = VBPtr;

Expand Down Expand Up @@ -3203,7 +3194,7 @@ llvm::Value *MicrosoftCXXABI::AdjustVirtualBase(
Builder.CreateBr(SkipAdjustBB);
CGF.EmitBlock(SkipAdjustBB);
llvm::PHINode *Phi = Builder.CreatePHI(CGM.Int8PtrTy, 2, "memptr.base");
Phi->addIncoming(Base.getPointer(), OriginalBB);
Phi->addIncoming(Base.emitRawPointer(CGF), OriginalBB);
Phi->addIncoming(AdjustedBase, VBaseAdjustBB);
return Phi;
}
Expand Down Expand Up @@ -3238,7 +3229,7 @@ llvm::Value *MicrosoftCXXABI::EmitMemberDataPointerAddress(
Addr = AdjustVirtualBase(CGF, E, RD, Base, VirtualBaseAdjustmentOffset,
VBPtrOffset);
} else {
Addr = Base.getPointer();
Addr = Base.emitRawPointer(CGF);
}

// Apply the offset, which we assume is non-null.
Expand Down Expand Up @@ -3526,7 +3517,7 @@ CGCallee MicrosoftCXXABI::EmitLoadOfMemberFunctionPointer(
ThisPtrForCall = AdjustVirtualBase(CGF, E, RD, This,
VirtualBaseAdjustmentOffset, VBPtrOffset);
} else {
ThisPtrForCall = This.getPointer();
ThisPtrForCall = This.emitRawPointer(CGF);
}

if (NonVirtualBaseAdjustment)
Expand Down Expand Up @@ -4445,10 +4436,7 @@ void MicrosoftCXXABI::emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) {
llvm::GlobalVariable *TI = getThrowInfo(ThrowType);

// Call into the runtime to throw the exception.
llvm::Value *Args[] = {
AI.getPointer(),
TI
};
llvm::Value *Args[] = {AI.emitRawPointer(CGF), TI};
CGF.EmitNoreturnRuntimeCallOrInvoke(getThrowFn(), Args);
}

Expand Down
5 changes: 5 additions & 0 deletions clang/lib/CodeGen/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ class TargetCodeGenInfo {
/// Get the AST address space for alloca.
virtual LangAS getASTAllocaAddressSpace() const { return LangAS::Default; }

Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr,
LangAS SrcAddr, LangAS DestAddr,
llvm::Type *DestTy,
bool IsNonNull = false) const;

/// Perform address space cast of an expression of pointer type.
/// \param V is the LLVM value to be casted to another address space.
/// \param SrcAddr is the language address space of \p V.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/Targets/NVPTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
LValue Src) {
llvm::Value *Handle = nullptr;
llvm::Constant *C =
llvm::dyn_cast<llvm::Constant>(Src.getAddress(CGF).getPointer());
llvm::dyn_cast<llvm::Constant>(Src.getAddress(CGF).emitRawPointer(CGF));
// Lookup `addrspacecast` through the constant pointer if any.
if (auto *ASC = llvm::dyn_cast_or_null<llvm::AddrSpaceCastOperator>(C))
C = llvm::cast<llvm::Constant>(ASC->getPointerOperand());
Expand Down
11 changes: 6 additions & 5 deletions clang/lib/CodeGen/Targets/PPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,10 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
CharUnits RegSize = CharUnits::fromQuantity((isInt || IsSoftFloatABI) ? 4 : 8);
llvm::Value *RegOffset =
Builder.CreateMul(NumRegs, Builder.getInt8(RegSize.getQuantity()));
RegAddr = Address(
Builder.CreateInBoundsGEP(CGF.Int8Ty, RegAddr.getPointer(), RegOffset),
DirectTy, RegAddr.getAlignment().alignmentOfArrayElement(RegSize));
RegAddr = Address(Builder.CreateInBoundsGEP(
CGF.Int8Ty, RegAddr.emitRawPointer(CGF), RegOffset),
DirectTy,
RegAddr.getAlignment().alignmentOfArrayElement(RegSize));

// Increase the used-register count.
NumRegs =
Expand Down Expand Up @@ -551,7 +552,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,
// Round up address of argument to alignment
CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
if (Align > OverflowAreaAlign) {
llvm::Value *Ptr = OverflowArea.getPointer();
llvm::Value *Ptr = OverflowArea.emitRawPointer(CGF);
OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
OverflowArea.getElementType(), Align);
}
Expand All @@ -560,7 +561,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAList,

// Increase the overflow area.
OverflowArea = Builder.CreateConstInBoundsByteGEP(OverflowArea, Size);
Builder.CreateStore(OverflowArea.getPointer(), OverflowAreaAddr);
Builder.CreateStore(OverflowArea.emitRawPointer(CGF), OverflowAreaAddr);
CGF.EmitBranch(Cont);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/Targets/Sparc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ Address SparcV9ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,

// Update VAList.
Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
Builder.CreateStore(NextPtr.emitRawPointer(CGF), VAListAddr);

return ArgAddr.withElementType(ArgTy);
}
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/CodeGen/Targets/SystemZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Address SystemZABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,

// Update overflow_arg_area_ptr pointer
llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
OverflowArgArea.getElementType(), OverflowArgArea.getPointer(),
OverflowArgArea.getElementType(), OverflowArgArea.emitRawPointer(CGF),
PaddedSizeV, "overflow_arg_area");
CGF.Builder.CreateStore(NewOverflowArgArea, OverflowArgAreaPtr);

Expand Down Expand Up @@ -382,10 +382,9 @@ Address SystemZABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
Address MemAddr = RawMemAddr.withElementType(DirectTy);

// Update overflow_arg_area_ptr pointer
llvm::Value *NewOverflowArgArea =
CGF.Builder.CreateGEP(OverflowArgArea.getElementType(),
OverflowArgArea.getPointer(), PaddedSizeV,
"overflow_arg_area");
llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
OverflowArgArea.getElementType(), OverflowArgArea.emitRawPointer(CGF),
PaddedSizeV, "overflow_arg_area");
CGF.Builder.CreateStore(NewOverflowArgArea, OverflowArgAreaPtr);
CGF.EmitBranch(ContBlock);

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/Targets/XCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Address XCoreABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
// Increment the VAList.
if (!ArgSize.isZero()) {
Address APN = Builder.CreateConstInBoundsByteGEP(AP, ArgSize);
Builder.CreateStore(APN.getPointer(), VAListAddr);
Builder.CreateStore(APN.emitRawPointer(CGF), VAListAddr);
}

return Val;
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,11 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
if (i + 1 != Changes.size())
Changes[i + 1].PreviousEndOfTokenColumn += Shift;

// If PointerAlignment is PAS_Right, keep *s or &s next to the token
// If PointerAlignment is PAS_Right, keep *s or &s next to the token,
// except if the token is equal, then a space is needed.
if ((Style.PointerAlignment == FormatStyle::PAS_Right ||
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
CurrentChange.Spaces != 0) {
CurrentChange.Spaces != 0 && CurrentChange.Tok->isNot(tok::equal)) {
const bool ReferenceNotRightAligned =
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;
Expand Down
31 changes: 0 additions & 31 deletions clang/lib/Headers/hlsl/hlsl_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -1147,19 +1147,6 @@ float4 pow(float4, float4);
/// \param Val The input value.

#ifdef __HLSL_ENABLE_16_BIT
_HLSL_AVAILABILITY(shadermodel, 6.2)
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int16_t reversebits(int16_t);
_HLSL_AVAILABILITY(shadermodel, 6.2)
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int16_t2 reversebits(int16_t2);
_HLSL_AVAILABILITY(shadermodel, 6.2)
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int16_t3 reversebits(int16_t3);
_HLSL_AVAILABILITY(shadermodel, 6.2)
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int16_t4 reversebits(int16_t4);

_HLSL_AVAILABILITY(shadermodel, 6.2)
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
uint16_t reversebits(uint16_t);
Expand All @@ -1174,15 +1161,6 @@ _HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
uint16_t4 reversebits(uint16_t4);
#endif

_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int reversebits(int);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int2 reversebits(int2);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int3 reversebits(int3);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int4 reversebits(int4);

_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
uint reversebits(uint);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
Expand All @@ -1192,15 +1170,6 @@ uint3 reversebits(uint3);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
uint4 reversebits(uint4);

_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int64_t reversebits(int64_t);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int64_t2 reversebits(int64_t2);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int64_t3 reversebits(int64_t3);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
int64_t4 reversebits(int64_t4);

_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
uint64_t reversebits(uint64_t);
_HLSL_BUILTIN_ALIAS(__builtin_elementwise_bitreverse)
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5541,6 +5541,14 @@ bool CheckNoDoubleVectors(Sema *S, CallExpr *TheCall) {
checkDoubleVector);
}

bool CheckUnsignedIntRepresentation(Sema *S, CallExpr *TheCall) {
auto checkAllUnsignedTypes = [](clang::QualType PassedType) -> bool {
return !PassedType->hasUnsignedIntegerRepresentation();
};
return CheckArgsTypesAreCorrect(S, TheCall, S->Context.UnsignedIntTy,
checkAllUnsignedTypes);
}

void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall,
QualType ReturnType) {
auto *VecTyA = TheCall->getArg(0)->getType()->getAs<VectorType>();
Expand Down Expand Up @@ -5628,6 +5636,11 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
}
// Note these are llvm builtins that we want to catch invalid intrinsic
// generation. Normal handling of these builitns will occur elsewhere.
case Builtin::BI__builtin_elementwise_bitreverse: {
if (CheckUnsignedIntRepresentation(this, TheCall))
return true;
break;
}
case Builtin::BI__builtin_elementwise_cos:
case Builtin::BI__builtin_elementwise_sin:
case Builtin::BI__builtin_elementwise_log:
Expand Down
90 changes: 90 additions & 0 deletions clang/test/C/C99/digraphs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// RUN: %clang_cc1 -verify -ffreestanding %s

/* WG14 ???: yes
* restricted character set support via digraphs and <iso646.h>
*
* NB: I cannot find a definitive document number associated with the feature,
* which was pulled from the editor's report in the C99 front matter. However,
* based on discussion in the C99 rationale document, I believe this is
* referring to features added by AMD1 to support ISO 646 and digraphs.
*/

// Validate that we provide iso646.h in freestanding mode.
#include <iso646.h>

// Validate that we define all the expected macros and their expected
// expansions (when suitable for a constant expression) as well.
#ifndef and
#error "missing and"
#else
_Static_assert((1 and 1) == (1 && 1), "");
#endif

#ifndef and_eq
#error "missing and_eq"
#endif

#ifndef bitand
#error "missing bitand"
#else
_Static_assert((1 bitand 3) == (1 & 3), "");
#endif

#ifndef bitor
#error "missing bitor"
#else
_Static_assert((1 bitor 2) == (1 | 2), "");
#endif

#ifndef compl
#error "missing compl"
#else
_Static_assert((compl 0) == (~0), "");
#endif

#ifndef not
#error "missing not"
#else
_Static_assert((not 12) == (!12), "");
#endif

#ifndef not_eq
#error "missing not_eq"
#else
_Static_assert((0 not_eq 12) == (0 != 12), "");
#endif

#ifndef or
#error "missing or"
#else
// This intentionally diagnoses use of '||' only, because the user likely did
// not confuse the operator when using 'or' instead.
_Static_assert((0 or 12) == (0 || 12), ""); // expected-warning {{use of logical '||' with constant operand}} \
expected-note {{use '|' for a bitwise operation}}
#endif

#ifndef or_eq
#error "missing or_eq"
#endif

#ifndef xor
#error "missing xor"
#else
_Static_assert((1 xor 3) == (1 ^ 3), "");
#endif

#ifndef xor_eq
#error "missing xor_eq"
#endif

// Validate that digraphs behave the same as their expected counterparts. The
// definition should match the declaration in every way except spelling.
#define DI_NAME(f, b) f %:%: b
#define STD_NAME(f, b) f ## b
void DI_NAME(foo, bar)(int (*array)<: 0 :>);
void STD_NAME(foo, bar)(int (*array)[0]) {}

#define DI_STR(f) %:f
#define STD_STR(f) #f
_Static_assert(__builtin_strcmp(DI_STR(testing), STD_STR(testing)) == 0, "");

155 changes: 0 additions & 155 deletions clang/test/CodeGenHLSL/builtins/bitreverse.hlsl

This file was deleted.

75 changes: 0 additions & 75 deletions clang/test/CodeGenHLSL/builtins/reversebits.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@
// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s

#ifdef __HLSL_ENABLE_16_BIT
// CHECK: define noundef i16 @
// CHECK: call i16 @llvm.bitreverse.i16(
int16_t test_bitreverse_short(int16_t p0)
{
return reversebits(p0);
}
// CHECK: define noundef <2 x i16> @
// CHECK: call <2 x i16> @llvm.bitreverse.v2i16(
int16_t2 test_bitreverse_short2(int16_t2 p0)
{
return reversebits(p0);
}
// CHECK: define noundef <3 x i16> @
// CHECK: call <3 x i16> @llvm.bitreverse.v3i16
int16_t3 test_bitreverse_short3(int16_t3 p0)
{
return reversebits(p0);
}
// CHECK: define noundef <4 x i16> @
// CHECK: call <4 x i16> @llvm.bitreverse.v4i16
int16_t4 test_bitreverse_short4(int16_t4 p0)
{
return reversebits(p0);
}

// CHECK: define noundef i16 @
// CHECK: call i16 @llvm.bitreverse.i16(
uint16_t test_bitreverse_ushort(uint16_t p0)
Expand All @@ -54,31 +29,6 @@ uint16_t4 test_bitreverse_ushort4(uint16_t4 p0)
}
#endif

// CHECK: define noundef i32 @
// CHECK: call i32 @llvm.bitreverse.i32(
int test_bitreverse_int(int p0)
{
return reversebits(p0);
}
// CHECK: define noundef <2 x i32> @
// CHECK: call <2 x i32> @llvm.bitreverse.v2i32
int2 test_bitreverse_int2(int2 p0)
{
return reversebits(p0);
}
// CHECK: define noundef <3 x i32> @
// CHECK: call <3 x i32> @llvm.bitreverse.v3i32
int3 test_bitreverse_int3(int3 p0)
{
return reversebits(p0);
}
// CHECK: define noundef <4 x i32> @
// CHECK: call <4 x i32> @llvm.bitreverse.v4i32
int4 test_bitreverse_int4(int4 p0)
{
return reversebits(p0);
}

// CHECK: define noundef i32 @
// CHECK: call i32 @llvm.bitreverse.i32(
int test_bitreverse_uint(uint p0)
Expand All @@ -104,31 +54,6 @@ uint4 test_bitreverse_uint4(uint4 p0)
return reversebits(p0);
}

// CHECK: define noundef i64 @
// CHECK: call i64 @llvm.bitreverse.i64(
int64_t test_bitreverse_long(int64_t p0)
{
return reversebits(p0);
}
// CHECK: define noundef <2 x i64> @
// CHECK: call <2 x i64> @llvm.bitreverse.v2i64
int64_t2 test_bitreverse_long2(int64_t2 p0)
{
return reversebits(p0);
}
// CHECK: define noundef <3 x i64> @
// CHECK: call <3 x i64> @llvm.bitreverse.v3i64
int64_t3 test_bitreverse_long3(int64_t3 p0)
{
return reversebits(p0);
}
// CHECK: define noundef <4 x i64> @
// CHECK: call <4 x i64> @llvm.bitreverse.v4i64
int64_t4 test_bitreverse_long4(int64_t4 p0)
{
return reversebits(p0);
}

// CHECK: define noundef i64 @
// CHECK: call i64 @llvm.bitreverse.i64(
uint64_t test_bitreverse_long(uint64_t p0)
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Driver/linker-wrapper-image.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
// OPENMP: @.omp_offloading.device_image = internal unnamed_addr constant [[[SIZE:[0-9]+]] x i8] c"\10\FF\10\AD{{.*}}", section ".llvm.offloading", align 8
// OPENMP-NEXT: @.omp_offloading.device_images = internal unnamed_addr constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr getelementptr inbounds ([[[BEGIN:[0-9]+]] x i8], ptr @.omp_offloading.device_image, i64 1, i64 0), ptr getelementptr inbounds ([[[END:[0-9]+]] x i8], ptr @.omp_offloading.device_image, i64 1, i64 0), ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
// OPENMP-NEXT: @.omp_offloading.descriptor = internal constant %__tgt_bin_desc { i32 1, ptr @.omp_offloading.device_images, ptr @__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }
// OPENMP-NEXT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @.omp_offloading.descriptor_reg, ptr null }]
// OPENMP-NEXT: @llvm.global_dtors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @.omp_offloading.descriptor_unreg, ptr null }]
// OPENMP-NEXT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 101, ptr @.omp_offloading.descriptor_reg, ptr null }]

// OPENMP: define internal void @.omp_offloading.descriptor_reg() section ".text.startup" {
// OPENMP-NEXT: entry:
// OPENMP-NEXT: %0 = call i32 @atexit(ptr @.omp_offloading.descriptor_unreg)
// OPENMP-NEXT: call void @__tgt_register_lib(ptr @.omp_offloading.descriptor)
// OPENMP-NEXT: ret void
// OPENMP-NEXT: }
Expand Down Expand Up @@ -62,7 +62,7 @@
// CUDA-NEXT: @.fatbin_wrapper = internal constant %fatbin_wrapper { i32 1180844977, i32 1, ptr @.fatbin_image, ptr null }, section ".nvFatBinSegment", align 8
// CUDA-NEXT: @.cuda.binary_handle = internal global ptr null

// CUDA: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @.cuda.fatbin_reg, ptr null }]
// CUDA: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 101, ptr @.cuda.fatbin_reg, ptr null }]

// CUDA: define internal void @.cuda.fatbin_reg() section ".text.startup" {
// CUDA-NEXT: entry:
Expand Down Expand Up @@ -162,7 +162,7 @@
// HIP-NEXT: @.fatbin_wrapper = internal constant %fatbin_wrapper { i32 1212764230, i32 1, ptr @.fatbin_image, ptr null }, section ".hipFatBinSegment", align 8
// HIP-NEXT: @.hip.binary_handle = internal global ptr null

// HIP: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @.hip.fatbin_reg, ptr null }]
// HIP: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 101, ptr @.hip.fatbin_reg, ptr null }]

// HIP: define internal void @.hip.fatbin_reg() section ".text.startup" {
// HIP-NEXT: entry:
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaHLSL/BuiltIns/reversebits-errors.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -verify


double2 test_int_builtin(double2 p0) {
return __builtin_elementwise_bitreverse(p0);
// expected-error@-1 {{1st argument must be a vector of integers (was 'double2' (aka 'vector<double, 2>'))}}
}

int2 test_int_builtin(int2 p0) {
return __builtin_elementwise_bitreverse(p0);
// expected-error@-1 {{passing 'int2' (aka 'vector<int, 2>') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}}
}
20 changes: 20 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19066,6 +19066,11 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
verifyFormat("int a(int x);\n"
"double b();",
Alignment);
verifyFormat("int a(const Test & = Test());\n"
"int a1(int &foo, const Test & = Test());\n"
"int a2(int &foo, const Test &name = Test());\n"
"double b();",
Alignment);
verifyFormat("struct Test {\n"
" Test(const Test &) = default;\n"
" ~Test() = default;\n"
Expand Down Expand Up @@ -19102,6 +19107,13 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" int x,\n"
" bool y);",
Alignment);
// Set ColumnLimit low so that we break the argument list in multiple lines.
Alignment.ColumnLimit = 35;
verifyFormat("int a3(SomeTypeName1 &x,\n"
" SomeTypeName2 &y,\n"
" const Test & = Test());\n"
"double b();",
Alignment);
Alignment.ColumnLimit = OldColumnLimit;
// Ensure function pointers don't screw up recursive alignment
verifyFormat("int a(int x, void (*fp)(int y));\n"
Expand Down Expand Up @@ -19287,6 +19299,10 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
"int foobar;",
AlignmentLeft);

verifyFormat("int a(SomeType& foo, const Test& = Test());\n"
"double b();",
AlignmentLeft);

// PAS_Middle
FormatStyle AlignmentMiddle = Alignment;
AlignmentMiddle.PointerAlignment = FormatStyle::PAS_Middle;
Expand Down Expand Up @@ -19347,6 +19363,10 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
"int foobar;",
AlignmentMiddle);

verifyFormat("int a(SomeType & foo, const Test & = Test());\n"
"double b();",
AlignmentMiddle);

Alignment.AlignConsecutiveAssignments.Enabled = false;
Alignment.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
verifyFormat("#define A \\\n"
Expand Down
2 changes: 1 addition & 1 deletion clang/utils/TableGen/MveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class BuiltinArgResult : public Result {
// Emit code to generate this result as a Value *.
std::string asValue() override {
if (AddressType)
return "(" + varname() + ".getPointer())";
return "(" + varname() + ".emitRawPointer(*this))";
return Result::asValue();
}
bool hasIntegerValue() const override { return Immediate; }
Expand Down
2 changes: 1 addition & 1 deletion clang/www/c_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h2 id="c99">C99 implementation status</h2>
<tr>
<td>restricted character set support via digraphs and &lt;iso646.h&gt;</td>
<td>Unknown</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr>
<td>more precise aliasing rules via effective type</td>
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/scudo/standalone/tests/strings_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TEST(ScudoStringsTest, CapacityIncreaseFails) {

rlimit Limit = {};
EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit));
rlimit EmptyLimit = {.rlim_max = Limit.rlim_max};
rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max};
EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));

// Test requires that the default length is at least 6 characters.
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/scudo/standalone/tests/vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST(ScudoVectorTest, ReallocateFails) {
rlimit Limit = {};
EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit));

rlimit EmptyLimit = {.rlim_max = Limit.rlim_max};
rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max};
EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));

V.resize(capacity);
Expand Down
6 changes: 3 additions & 3 deletions compiler-rt/lib/scudo/standalone/tsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ template <class Allocator> struct alignas(SCUDO_CACHE_LINE_SIZE) TSD {
return true;
}
if (atomic_load_relaxed(&Precedence) == 0)
atomic_store_relaxed(&Precedence,
static_cast<uptr>(getMonotonicTimeFast() >>
FIRST_32_SECOND_64(16, 0)));
atomic_store_relaxed(
&Precedence,
static_cast<uptr>(getMonotonicTime() >> FIRST_32_SECOND_64(16, 0)));
return false;
}
inline void lock() NO_THREAD_SAFETY_ANALYSIS {
Expand Down
22 changes: 16 additions & 6 deletions libcxx/include/__chrono/tzdb_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,29 @@ class _LIBCPP_AVAILABILITY_TZDB tzdb_list {

using const_iterator = forward_list<tzdb>::const_iterator;

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const tzdb& front() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept { return __front(); }

_LIBCPP_EXPORTED_FROM_ABI const_iterator erase_after(const_iterator __p);
_LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) { return __erase_after(__p); }

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator begin() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator end() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __begin(); }
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __end(); }

_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator cbegin() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_EXPORTED_FROM_ABI const_iterator cend() const noexcept;
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return __cbegin(); }
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return __cend(); }

[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __impl& __implementation() { return *__impl_; }

private:
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const tzdb& __front() const noexcept;

_LIBCPP_EXPORTED_FROM_ABI const_iterator __erase_after(const_iterator __p);

[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __begin() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __end() const noexcept;

[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cbegin() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cend() const noexcept;

__impl* __impl_;
};

Expand Down
11 changes: 4 additions & 7 deletions libcxx/src/include/tzdb/tzdb_list_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class tzdb_list::__impl {

using const_iterator = tzdb_list::const_iterator;

const tzdb& front() const noexcept {
const tzdb& __front() const noexcept {
#ifndef _LIBCPP_HAS_NO_THREADS
shared_lock __lock{__mutex_};
#endif
return __tzdb_.front();
}

const_iterator erase_after(const_iterator __p) {
const_iterator __erase_after(const_iterator __p) {
#ifndef _LIBCPP_HAS_NO_THREADS
unique_lock __lock{__mutex_};
#endif
Expand All @@ -70,20 +70,17 @@ class tzdb_list::__impl {
return __tzdb_.erase_after(__p);
}

const_iterator begin() const noexcept {
const_iterator __begin() const noexcept {
#ifndef _LIBCPP_HAS_NO_THREADS
shared_lock __lock{__mutex_};
#endif
return __tzdb_.begin();
}
const_iterator end() const noexcept {
const_iterator __end() const noexcept {
// forward_list<T>::end does not access the list, so no need to take a lock.
return __tzdb_.end();
}

const_iterator cbegin() const noexcept { return begin(); }
const_iterator cend() const noexcept { return end(); }

private:
// Loads the tzdbs
// pre: The caller ensures the locking, if needed, is done.
Expand Down
Loading