Skip to content

Commit af90743

Browse files
authored
Merge branch 'main' into users/yafet-a/boolean-optimisation
2 parents 02807e3 + f925ecb commit af90743

File tree

173 files changed

+6783
-2145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+6783
-2145
lines changed

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,16 @@ TARGET_BUILTIN(__builtin_amdgcn_global_load_monitor_b128, "V4iV4i*1Ii", "nc", "g
651651
TARGET_BUILTIN(__builtin_amdgcn_flat_load_monitor_b32, "ii*0Ii", "nc", "gfx1250-insts")
652652
TARGET_BUILTIN(__builtin_amdgcn_flat_load_monitor_b64, "V2iV2i*0Ii", "nc", "gfx1250-insts")
653653
TARGET_BUILTIN(__builtin_amdgcn_flat_load_monitor_b128, "V4iV4i*0Ii", "nc", "gfx1250-insts")
654+
TARGET_BUILTIN(__builtin_amdgcn_global_load_async_to_lds_b8, "vc*1c*3IiIi", "nc", "gfx1250-insts")
655+
TARGET_BUILTIN(__builtin_amdgcn_global_load_async_to_lds_b32, "vi*1i*3IiIi", "nc", "gfx1250-insts")
656+
TARGET_BUILTIN(__builtin_amdgcn_global_load_async_to_lds_b64, "vV2i*1V2i*3IiIi", "nc", "gfx1250-insts")
657+
TARGET_BUILTIN(__builtin_amdgcn_global_load_async_to_lds_b128, "vV4i*1V4i*3IiIi", "nc", "gfx1250-insts")
658+
TARGET_BUILTIN(__builtin_amdgcn_global_store_async_from_lds_b8, "vc*1c*3IiIi", "nc", "gfx1250-insts")
659+
TARGET_BUILTIN(__builtin_amdgcn_global_store_async_from_lds_b32, "vi*1i*3IiIi", "nc", "gfx1250-insts")
660+
TARGET_BUILTIN(__builtin_amdgcn_global_store_async_from_lds_b64, "vV2i*1V2i*3IiIi", "nc", "gfx1250-insts")
661+
TARGET_BUILTIN(__builtin_amdgcn_global_store_async_from_lds_b128, "vV4i*1V4i*3IiIi", "nc", "gfx1250-insts")
662+
TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_async_barrier_arrive_b64, "vLi*3", "nc", "gfx1250-insts")
663+
TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_barrier_arrive_rtn_b64, "LiLi*3Li", "nc", "gfx1250-insts")
654664

655665
TARGET_BUILTIN(__builtin_amdgcn_tensor_load_to_lds, "vV4iV8iV4iV4iIi", "nc", "gfx1250-insts")
656666
TARGET_BUILTIN(__builtin_amdgcn_tensor_load_to_lds_d2, "vV4iV8iIi", "nc", "gfx1250-insts")
@@ -670,9 +680,6 @@ TARGET_BUILTIN(__builtin_amdgcn_ds_load_tr16_b128_v8i16, "V8sV8s*3", "nc", "gfx1
670680
TARGET_BUILTIN(__builtin_amdgcn_ds_load_tr16_b128_v8f16, "V8hV8h*3", "nc", "gfx1250-insts,wavefrontsize32")
671681
TARGET_BUILTIN(__builtin_amdgcn_ds_load_tr16_b128_v8bf16, "V8yV8y*3", "nc", "gfx1250-insts,wavefrontsize32")
672682

673-
TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_async_barrier_arrive_b64, "vLi*3", "nc", "gfx1250-insts")
674-
TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_barrier_arrive_rtn_b64, "LiLi*3Li", "nc", "gfx1250-insts")
675-
676683
TARGET_BUILTIN(__builtin_amdgcn_s_setprio_inc_wg, "vIs", "n", "setprio-inc-wg-inst")
677684
TARGET_BUILTIN(__builtin_amdgcn_s_monitor_sleep, "vIs", "n", "gfx1250-insts")
678685

clang/include/clang/Basic/FileManager.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,6 @@ class FileManager : public RefCountedBase<FileManager> {
237237
FileEntryRef getVirtualFileRef(StringRef Filename, off_t Size,
238238
time_t ModificationTime);
239239

240-
LLVM_DEPRECATED("Functions returning FileEntry are deprecated.",
241-
"getVirtualFileRef()")
242-
const FileEntry *getVirtualFile(StringRef Filename, off_t Size,
243-
time_t ModificationTime);
244-
245240
/// Retrieve a FileEntry that bypasses VFE, which is expected to be a virtual
246241
/// file entry, to access the real file. The returned FileEntry will have
247242
/// the same filename as FE but a different identity and its own stat.

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
7575
return getConstant(loc, cir::IntAttr::get(ty, value));
7676
}
7777

78+
mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits) {
79+
auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/true);
80+
return getConstAPInt(loc, type,
81+
llvm::APInt(numBits, val, /*isSigned=*/true));
82+
}
83+
7884
mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val,
7985
unsigned numBits) {
8086
auto type = cir::IntType::get(getContext(), numBits, /*isSigned=*/false);

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ def CIR_ConditionOp : CIR_Op<"condition", [
607607
//===----------------------------------------------------------------------===//
608608

609609
defvar CIR_YieldableScopes = [
610-
"ArrayCtor", "CaseOp", "DoWhileOp", "ForOp", "IfOp", "ScopeOp", "SwitchOp",
611-
"TernaryOp", "WhileOp"
610+
"ArrayCtor", "ArrayDtor", "CaseOp", "DoWhileOp", "ForOp", "IfOp", "ScopeOp",
611+
"SwitchOp", "TernaryOp", "WhileOp"
612612
];
613613

614614
def CIR_YieldOp : CIR_Op<"yield", [
@@ -1946,6 +1946,10 @@ def CIR_FuncOp : CIR_Op<"func", [
19461946
The function linkage information is specified by `linkage`, as defined by
19471947
`GlobalLinkageKind` attribute.
19481948

1949+
The `no_proto` keyword is used to identify functions that were declared
1950+
without a prototype and, consequently, may contain calls with invalid
1951+
arguments and undefined behavior.
1952+
19491953
Example:
19501954

19511955
```mlir
@@ -1964,6 +1968,7 @@ def CIR_FuncOp : CIR_Op<"func", [
19641968
let arguments = (ins SymbolNameAttr:$sym_name,
19651969
CIR_VisibilityAttr:$global_visibility,
19661970
TypeAttrOf<CIR_FuncType>:$function_type,
1971+
UnitAttr:$no_proto,
19671972
UnitAttr:$dso_local,
19681973
DefaultValuedAttr<CIR_GlobalLinkageKind,
19691974
"cir::GlobalLinkageKind::ExternalLinkage">:$linkage,
@@ -2005,13 +2010,6 @@ def CIR_FuncOp : CIR_Op<"func", [
20052010
return getFunctionType().getReturnTypes();
20062011
}
20072012

2008-
// TODO(cir): this should be an operand attribute, but for now we just hard-
2009-
// wire this as a function. Will later add a $no_proto argument to this op.
2010-
bool getNoProto() {
2011-
assert(!cir::MissingFeatures::opFuncNoProto());
2012-
return false;
2013-
}
2014-
20152013
//===------------------------------------------------------------------===//
20162014
// SymbolOpInterface Methods
20172015
//===------------------------------------------------------------------===//
@@ -2229,7 +2227,7 @@ def CIR_TrapOp : CIR_Op<"trap", [Terminator]> {
22292227
}
22302228

22312229
//===----------------------------------------------------------------------===//
2232-
// ArrayCtor
2230+
// ArrayCtor & ArrayDtor
22332231
//===----------------------------------------------------------------------===//
22342232

22352233
class CIR_ArrayInitDestroy<string mnemonic> : CIR_Op<mnemonic> {
@@ -2260,7 +2258,9 @@ def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
22602258
let description = [{
22612259
Initialize each array element using the same C++ constructor. This
22622260
operation has one region, with one single block. The block has an
2263-
incoming argument for the current array index to initialize.
2261+
incoming argument for the current array element to initialize.
2262+
2263+
Example:
22642264

22652265
```mlir
22662266
cir.array.ctor(%0 : !cir.ptr<!cir.array<!rec_S x 42>>) {
@@ -2272,6 +2272,25 @@ def CIR_ArrayCtor : CIR_ArrayInitDestroy<"array.ctor"> {
22722272
}];
22732273
}
22742274

2275+
def CIR_ArrayDtor : CIR_ArrayInitDestroy<"array.dtor"> {
2276+
let summary = "Destroy array elements with C++ dtors";
2277+
let description = [{
2278+
Destroy each array element using the same C++ destructor. This
2279+
operation has one region, with one single block. The block has an
2280+
incoming argument for the current array element to destruct.
2281+
2282+
Example:
2283+
2284+
```mlir
2285+
cir.array.dtor(%0 : !cir.ptr<!cir.array<!rec_S x 42>>) {
2286+
^bb0(%arg0: !cir.ptr<!rec_S>):
2287+
cir.call @some_dtor(%arg0) : (!cir.ptr<!rec_S>) -> ()
2288+
cir.yield
2289+
}
2290+
```
2291+
}];
2292+
}
2293+
22752294
//===----------------------------------------------------------------------===//
22762295
// VecCreate
22772296
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ struct MissingFeatures {
7373
// FuncOp handling
7474
static bool opFuncOpenCLKernelMetadata() { return false; }
7575
static bool opFuncAstDeclAttr() { return false; }
76+
static bool opFuncAttributesForDefinition() { return false; }
7677
static bool opFuncCallingConv() { return false; }
77-
static bool opFuncExtraAttrs() { return false; }
78-
static bool opFuncNoProto() { return false; }
7978
static bool opFuncCPUAndFeaturesAttributes() { return false; }
80-
static bool opFuncSection() { return false; }
81-
static bool opFuncMultipleReturnVals() { return false; }
82-
static bool opFuncAttributesForDefinition() { return false; }
79+
static bool opFuncExceptions() { return false; }
80+
static bool opFuncExtraAttrs() { return false; }
8381
static bool opFuncMaybeHandleStaticInExternC() { return false; }
82+
static bool opFuncMultipleReturnVals() { return false; }
83+
static bool opFuncOperandBundles() { return false; }
84+
static bool opFuncParameterAttributes() { return false; }
85+
static bool opFuncSection() { return false; }
8486
static bool setLLVMFunctionFEnvAttributes() { return false; }
8587
static bool setFunctionAttributes() { return false; }
8688

@@ -96,7 +98,6 @@ struct MissingFeatures {
9698
static bool opCallReturn() { return false; }
9799
static bool opCallArgEvaluationOrder() { return false; }
98100
static bool opCallCallConv() { return false; }
99-
static bool opCallNoPrototypeFunc() { return false; }
100101
static bool opCallMustTail() { return false; }
101102
static bool opCallVirtual() { return false; }
102103
static bool opCallInAlloca() { return false; }
@@ -109,6 +110,7 @@ struct MissingFeatures {
109110
static bool opCallCIRGenFuncInfoExtParamInfo() { return false; }
110111
static bool opCallLandingPad() { return false; }
111112
static bool opCallContinueBlock() { return false; }
113+
static bool opCallChain() { return false; }
112114

113115
// CXXNewExpr
114116
static bool exprNewNullCheck() { return false; }
@@ -224,7 +226,6 @@ struct MissingFeatures {
224226
static bool moduleNameHash() { return false; }
225227
static bool msabi() { return false; }
226228
static bool needsGlobalCtorDtor() { return false; }
227-
static bool nonFineGrainedBitfields() { return false; }
228229
static bool objCBlocks() { return false; }
229230
static bool objCGC() { return false; }
230231
static bool objCLifetime() { return false; }

clang/lib/Basic/FileManager.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,6 @@ void FileManager::trackVFSUsage(bool Active) {
368368
});
369369
}
370370

371-
const FileEntry *FileManager::getVirtualFile(StringRef Filename, off_t Size,
372-
time_t ModificationTime) {
373-
return &getVirtualFileRef(Filename, Size, ModificationTime).getFileEntry();
374-
}
375-
376371
FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
377372
time_t ModificationTime) {
378373
++NumFileLookups;

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,11 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
266266

267267
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
268268
CUMode = !(GPUFeatures & llvm::AMDGPU::FEATURE_WGP);
269-
for (auto F : {"image-insts", "gws", "vmem-to-lds-load-insts"})
270-
ReadOnlyFeatures.insert(F);
269+
270+
for (auto F : {"image-insts", "gws", "vmem-to-lds-load-insts"}) {
271+
if (GPUKind != llvm::AMDGPU::GK_NONE)
272+
ReadOnlyFeatures.insert(F);
273+
}
271274
HalfArgsAndReturns = true;
272275
}
273276

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
582582
cir::FuncOp directFuncOp;
583583
if (auto fnOp = dyn_cast<cir::FuncOp>(calleePtr)) {
584584
directFuncOp = fnOp;
585+
} else if (auto getGlobalOp = mlir::dyn_cast<cir::GetGlobalOp>(calleePtr)) {
586+
// FIXME(cir): This peephole optimization avoids indirect calls for
587+
// builtins. This should be fixed in the builtin declaration instead by
588+
// not emitting an unecessary get_global in the first place.
589+
// However, this is also used for no-prototype functions.
590+
mlir::Operation *globalOp = cgm.getGlobalValue(getGlobalOp.getName());
591+
assert(globalOp && "undefined global function");
592+
directFuncOp = mlir::cast<cir::FuncOp>(globalOp);
585593
} else {
586594
[[maybe_unused]] mlir::ValueTypeRange<mlir::ResultRange> resultTypes =
587595
calleePtr->getResultTypes();

clang/lib/CIR/CodeGen/CIRGenCall.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ class CIRGenCallee {
116116
assert(isOrdinary());
117117
return reinterpret_cast<mlir::Operation *>(kindOrFunctionPtr);
118118
}
119+
120+
void setFunctionPointer(mlir::Operation *functionPtr) {
121+
assert(isOrdinary());
122+
kindOrFunctionPtr = SpecialKind(reinterpret_cast<uintptr_t>(functionPtr));
123+
}
119124
};
120125

121126
/// Type for representing both the decl and type of parameters to a function.

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,38 @@ void CIRGenFunction::emitNullabilityCheck(LValue lhs, mlir::Value rhs,
649649
assert(!cir::MissingFeatures::sanitizers());
650650
}
651651

652+
/// Destroys all the elements of the given array, beginning from last to first.
653+
/// The array cannot be zero-length.
654+
///
655+
/// \param begin - a type* denoting the first element of the array
656+
/// \param end - a type* denoting one past the end of the array
657+
/// \param elementType - the element type of the array
658+
/// \param destroyer - the function to call to destroy elements
659+
void CIRGenFunction::emitArrayDestroy(mlir::Value begin, mlir::Value end,
660+
QualType elementType,
661+
CharUnits elementAlign,
662+
Destroyer *destroyer) {
663+
assert(!elementType->isArrayType());
664+
665+
// Differently from LLVM traditional codegen, use a higher level
666+
// representation instead of lowering directly to a loop.
667+
mlir::Type cirElementType = convertTypeForMem(elementType);
668+
cir::PointerType ptrToElmType = builder.getPointerTo(cirElementType);
669+
670+
// Emit the dtor call that will execute for every array element.
671+
cir::ArrayDtor::create(
672+
builder, *currSrcLoc, begin, [&](mlir::OpBuilder &b, mlir::Location loc) {
673+
auto arg = b.getInsertionBlock()->addArgument(ptrToElmType, loc);
674+
Address curAddr = Address(arg, cirElementType, elementAlign);
675+
assert(!cir::MissingFeatures::dtorCleanups());
676+
677+
// Perform the actual destruction there.
678+
destroyer(*this, curAddr, elementType);
679+
680+
cir::YieldOp::create(builder, loc);
681+
});
682+
}
683+
652684
/// Immediately perform the destruction of the given object.
653685
///
654686
/// \param addr - the address of the object; a type*
@@ -658,10 +690,34 @@ void CIRGenFunction::emitNullabilityCheck(LValue lhs, mlir::Value rhs,
658690
/// elements
659691
void CIRGenFunction::emitDestroy(Address addr, QualType type,
660692
Destroyer *destroyer) {
661-
if (getContext().getAsArrayType(type))
662-
cgm.errorNYI("emitDestroy: array type");
693+
const ArrayType *arrayType = getContext().getAsArrayType(type);
694+
if (!arrayType)
695+
return destroyer(*this, addr, type);
696+
697+
mlir::Value length = emitArrayLength(arrayType, type, addr);
698+
699+
CharUnits elementAlign = addr.getAlignment().alignmentOfArrayElement(
700+
getContext().getTypeSizeInChars(type));
701+
702+
auto constantCount = length.getDefiningOp<cir::ConstantOp>();
703+
if (!constantCount) {
704+
assert(!cir::MissingFeatures::vlas());
705+
cgm.errorNYI("emitDestroy: variable length array");
706+
return;
707+
}
708+
709+
auto constIntAttr = mlir::dyn_cast<cir::IntAttr>(constantCount.getValue());
710+
// If it's constant zero, we can just skip the entire thing.
711+
if (constIntAttr && constIntAttr.getUInt() == 0)
712+
return;
713+
714+
mlir::Value begin = addr.getPointer();
715+
mlir::Value end; // This will be used for future non-constant counts.
716+
emitArrayDestroy(begin, end, type, elementAlign, destroyer);
663717

664-
return destroyer(*this, addr, type);
718+
// If the array destroy didn't use the length op, we can erase it.
719+
if (constantCount.use_empty())
720+
constantCount.erase();
665721
}
666722

667723
CIRGenFunction::Destroyer *

0 commit comments

Comments
 (0)