|
12 | 12 | //===----------------------------------------------------------------------===// |
13 | 13 |
|
14 | 14 | #include "CIRGenCall.h" |
15 | | -#include "CIRGenConstantEmitter.h" |
16 | 15 | #include "CIRGenFunction.h" |
17 | 16 | #include "CIRGenModule.h" |
18 | 17 | #include "CIRGenValue.h" |
|
22 | 21 | #include "clang/AST/Expr.h" |
23 | 22 | #include "clang/AST/GlobalDecl.h" |
24 | 23 | #include "clang/Basic/Builtins.h" |
| 24 | +#include "clang/CIR/Dialect/IR/CIRTypes.h" |
25 | 25 | #include "clang/CIR/MissingFeatures.h" |
26 | 26 | #include "llvm/Support/ErrorHandling.h" |
27 | 27 |
|
@@ -58,24 +58,6 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const CallExpr *e, |
58 | 58 | return RValue::get(result); |
59 | 59 | } |
60 | 60 |
|
61 | | -// Initialize the alloca with the given size and alignment according to the lang |
62 | | -// opts. Supporting only the trivial non-initialization for now. |
63 | | -static void initializeAlloca(CIRGenFunction &cgf, |
64 | | - [[maybe_unused]] mlir::Value allocaAddr, |
65 | | - [[maybe_unused]] mlir::Value size, |
66 | | - [[maybe_unused]] CharUnits alignmentInBytes) { |
67 | | - |
68 | | - switch (cgf.getLangOpts().getTrivialAutoVarInit()) { |
69 | | - case LangOptions::TrivialAutoVarInitKind::Uninitialized: |
70 | | - // Nothing to initialize. |
71 | | - return; |
72 | | - case LangOptions::TrivialAutoVarInitKind::Zero: |
73 | | - case LangOptions::TrivialAutoVarInitKind::Pattern: |
74 | | - cgf.cgm.errorNYI("trivial auto var init"); |
75 | | - return; |
76 | | - } |
77 | | -} |
78 | | - |
79 | 61 | RValue CIRGenFunction::emitRotate(const CallExpr *e, bool isRotateLeft) { |
80 | 62 | mlir::Value input = emitScalarExpr(e->getArg(0)); |
81 | 63 | mlir::Value amount = emitScalarExpr(e->getArg(1)); |
@@ -190,28 +172,34 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, |
190 | 172 | builder.getUInt8Ty(), "bi_alloca", suitableAlignmentInBytes, size); |
191 | 173 |
|
192 | 174 | // Initialize the allocated buffer if required. |
193 | | - if (builtinID != Builtin::BI__builtin_alloca_uninitialized) |
194 | | - initializeAlloca(*this, allocaAddr, size, suitableAlignmentInBytes); |
| 175 | + if (builtinID != Builtin::BI__builtin_alloca_uninitialized) { |
| 176 | + |
| 177 | + switch (getLangOpts().getTrivialAutoVarInit()) { |
| 178 | + case LangOptions::TrivialAutoVarInitKind::Uninitialized: |
| 179 | + // Nothing to initialize. |
| 180 | + break; |
| 181 | + case LangOptions::TrivialAutoVarInitKind::Zero: |
| 182 | + case LangOptions::TrivialAutoVarInitKind::Pattern: |
| 183 | + cgm.errorNYI("trivial auto var init"); |
| 184 | + break; |
| 185 | + } |
| 186 | + } |
195 | 187 |
|
196 | 188 | // An alloca will always return a pointer to the alloca (stack) address |
197 | 189 | // space. This address space need not be the same as the AST / Language |
198 | 190 | // default (e.g. in C / C++ auto vars are in the generic address space). At |
199 | 191 | // the AST level this is handled within CreateTempAlloca et al., but for the |
200 | 192 | // builtin / dynamic alloca we have to handle it here. |
201 | 193 |
|
202 | | - LangAS allocaAddrSpace = clang::LangAS::Default; |
203 | | - if (getCIRAllocaAddressSpace()) { |
204 | | - allocaAddrSpace = clang::getLangASFromTargetAS( |
205 | | - getCIRAllocaAddressSpace().getValue().getUInt()); |
206 | | - } |
207 | | - LangAS exprAddrSpace = e->getType()->getPointeeType().getAddressSpace(); |
208 | | - if (exprAddrSpace != allocaAddrSpace) { |
| 194 | + if (!cir::isMatchingAddressSpace( |
| 195 | + getCIRAllocaAddressSpace(), |
| 196 | + e->getType()->getPointeeType().getAddressSpace())) { |
209 | 197 | cgm.errorNYI(e->getSourceRange(), "Non-default address space for alloca"); |
210 | 198 | } |
211 | 199 |
|
212 | 200 | // Bitcast the alloca to the expected type. |
213 | 201 | return RValue::get(builder.createBitcast( |
214 | | - allocaAddr, builder.getVoidPtrTy(allocaAddrSpace))); |
| 202 | + allocaAddr, builder.getVoidPtrTy(getCIRAllocaAddressSpace()))); |
215 | 203 | } |
216 | 204 |
|
217 | 205 | case Builtin::BIcos: |
|
0 commit comments