MCPcopy Create free account
hub / github.com/AdaptiveCpp/AdaptiveCpp / getAlignment

Function getAlignment

src/compiler/cbs/VectorShape.cpp:25–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace {
24
25align_t getAlignment(const Constant *c) {
26 assert(c);
27
28 if (isa<BasicBlock>(c) || isa<Function>(c))
29 return 1;
30
31 // An undef value is never aligned.
32 if (isa<UndefValue>(c))
33 return 1;
34
35 if (const ConstantInt *cint = dyn_cast<ConstantInt>(c)) {
36 return static_cast<align_t>(std::abs(cint->getSExtValue()));
37 }
38
39 // Other than that, only integer vector constants can be aligned.
40 if (!c->getType()->isVectorTy())
41 return 1;
42
43 // A zero-vector is aligned.
44 if (isa<ConstantAggregateZero>(c))
45 return 0;
46
47 if (const ConstantDataVector *cdv = dyn_cast<ConstantDataVector>(c)) {
48 if (!cdv->getElementType()->isIntegerTy())
49 return 1;
50
51 const int intValue = (align_t)cast<ConstantInt>(cdv->getAggregateElement(0U))->getZExtValue();
52
53 return static_cast<align_t>(std::abs(intValue));
54 }
55
56 assert(isa<ConstantVector>(c));
57 const ConstantVector *cv = cast<ConstantVector>(c);
58
59 if (!cv->getType()->getElementType()->isIntegerTy())
60 return 1;
61
62 assert(isa<ConstantInt>(cv->getOperand(0)));
63 const ConstantInt *celem = cast<ConstantInt>(cv->getOperand(0));
64 const int intValue = (align_t)celem->getZExtValue();
65
66 // The vector is aligned if its first element is aligned
67 return static_cast<align_t>(std::abs(intValue));
68}
69
70} // namespace
71

Callers 1

fromConstantMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected