Skip to content

Commit 98182f4

Browse files
authored
Move CodeGenFunction::EmitScalarOrConstFoldImmArg; NFC (llvm#170286)
This function is called from various .cpp files under `TargetBuiltins/`, and was moved unintentionally into `AMDGPU.cpp` in PR llvm#132252. Move it to a common place.
1 parent e6110cb commit 98182f4

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,23 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
21582158
}
21592159
}
21602160

2161+
llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
2162+
unsigned Idx,
2163+
const CallExpr *E) {
2164+
llvm::Value *Arg = nullptr;
2165+
if ((ICEArguments & (1 << Idx)) == 0) {
2166+
Arg = EmitScalarExpr(E->getArg(Idx));
2167+
} else {
2168+
// If this is required to be a constant, constant fold it so that we
2169+
// know that the generated intrinsic gets a ConstantInt.
2170+
std::optional<llvm::APSInt> Result =
2171+
E->getArg(Idx)->getIntegerConstantExpr(getContext());
2172+
assert(Result && "Expected argument to be a constant");
2173+
Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
2174+
}
2175+
return Arg;
2176+
}
2177+
21612178
/// ErrorUnsupported - Print out an error that codegen doesn't support the
21622179
/// specified stmt yet.
21632180
void CodeGenFunction::ErrorUnsupported(const Stmt *S, const char *Type) {

clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,6 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value *Order, Value *Scope,
343343
SSID = getLLVMContext().getOrInsertSyncScopeID(SSN);
344344
}
345345

346-
llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
347-
unsigned Idx,
348-
const CallExpr *E) {
349-
llvm::Value *Arg = nullptr;
350-
if ((ICEArguments & (1 << Idx)) == 0) {
351-
Arg = EmitScalarExpr(E->getArg(Idx));
352-
} else {
353-
// If this is required to be a constant, constant fold it so that we
354-
// know that the generated intrinsic gets a ConstantInt.
355-
std::optional<llvm::APSInt> Result =
356-
E->getArg(Idx)->getIntegerConstantExpr(getContext());
357-
assert(Result && "Expected argument to be a constant");
358-
Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
359-
}
360-
return Arg;
361-
}
362-
363346
void CodeGenFunction::AddAMDGPUFenceAddressSpaceMMRA(llvm::Instruction *Inst,
364347
const CallExpr *E) {
365348
constexpr const char *Tag = "amdgpu-synchronize-as";

0 commit comments

Comments
 (0)